+ my $new_virtual = $data->{'new_virtual'};
+ my $dir = upper_path($new_virtual);
+ $new_virtual = encode_entities($new_virtual);
-
+ if(-e $new_physical)
+ {
+ if(-d $new_physical)
+ {
+ return error("A directory called '$new_virtual' already exists. You cannot replace a directory by a file!",$dir);
+ }
+ elsif(not $data->{'cgi'}->param('confirmed'))
+ {
+ my $tpl = new Template;
+ $tpl->read_file($config->{'tpl_confirm_replace'});
+
+ $tpl->fillin("FILE",$virtual);
+ $tpl->fillin("NEW_FILE",$new_virtual);
+ $tpl->fillin("NEW_FILENAME",file_name($new_virtual));
+ $tpl->fillin("NEW_DIR",$dir);
+ $tpl->fillin("DIR",upper_path($virtual));
+ $tpl->fillin("COMMAND","copy");
+ $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
+ $tpl->fillin("SCRIPT",$script);
+
+ my $output = header(-type => "text/html");
+ $output .= $tpl->get_template;
+
+ return \$output;
+ }
+ }
-
Delete
+ if($data->{'uselist'}->in_use($data->{'new_virtual'}))
+ {
+ return error("The target file '$new_virtual' already exists and it is edited by someone else.",$dir);
+ }
-
-END
+ copy($physical,$new_physical) or return error("Could not copy '$virtual' to '$new_virtual'",upper_path($virtual));
+ return devedit_reload({command => 'show', file => $dir});
}
else
{
- $output .= <Unlock file
+ my $tpl = new Template;
+ $tpl->read_file($config->{'tpl_copyfile'});
-
Someone else is currently editing this file. At least, the file is marked so. Maybe, someone who was editing the file, has forgotten to unlock it. In this case (and only in this case) you can unlock the file using this button:
+ $tpl->fillin("FILE",$virtual);
+ $tpl->fillin("DIR",upper_path($virtual));
+ $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
+ $tpl->fillin("SCRIPT",$script);
-
-END
- }
-
- $output .= "\n";
- $output .= htmlfoot;
-
- return \$output;
-}
+ my $output = header(-type => "text/html");
+ $output .= $tpl->get_template;
-# exec_copy()
-#
-# Copy a file and return to directory view
-#
-# Params: 1. Reference to user input hash
-# 2. Reference to config hash
-#
-# Return: Output of the command (Scalar Reference)
-
-sub exec_copy($$)
-{
- 1;
+ return \$output;
+ }
}
# exec_rename()
@@ -418,12 +461,77 @@ sub exec_copy($$)
sub exec_rename($$)
{
- 1;
+ my ($data,$config) = @_;
+ my $physical = $data->{'physical'};
+ my $virtual = $data->{'virtual'};
+ my $new_physical = $data->{'new_physical'};
+ my $new_virtual = $data->{'new_virtual'};
+ my $dir = upper_path($new_virtual);
+ $new_virtual = encode_entities($new_virtual);
+
+ return error_in_use($virtual) if($data->{'uselist'}->in_use($virtual));
+
+ if($new_physical)
+ {
+ my $new_virtual = $data->{'new_virtual'};
+ my $dir = upper_path($new_virtual);
+ $new_virtual = encode_entities($new_virtual);
+
+ if(-e $new_physical)
+ {
+ if(-d $new_physical)
+ {
+ return error("A directory called '$new_virtual' already exists. You cannot replace a directory by a file!",$dir);
+ }
+ elsif(not $data->{'cgi'}->param('confirmed'))
+ {
+ my $tpl = new Template;
+ $tpl->read_file($config->{'tpl_confirm_replace'});
+
+ $tpl->fillin("FILE",$virtual);
+ $tpl->fillin("NEW_FILE",$new_virtual);
+ $tpl->fillin("NEW_FILENAME",file_name($new_virtual));
+ $tpl->fillin("NEW_DIR",$dir);
+ $tpl->fillin("DIR",upper_path($virtual));
+ $tpl->fillin("COMMAND","rename");
+ $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
+ $tpl->fillin("SCRIPT",$script);
+
+ my $output = header(-type => "text/html");
+ $output .= $tpl->get_template;
+
+ return \$output;
+ }
+ }
+
+ if($data->{'uselist'}->in_use($data->{'new_virtual'}))
+ {
+ return error("The target file '$new_virtual' already exists and it is edited by someone else.",$dir);
+ }
+
+ rename($physical,$new_physical) or return error("Could not move/rename '$virtual' to '$new_virtual'",upper_path($virtual));
+ return devedit_reload({command => 'show', file => $dir});
+ }
+ else
+ {
+ my $tpl = new Template;
+ $tpl->read_file($config->{'tpl_renamefile'});
+
+ $tpl->fillin("FILE",$virtual);
+ $tpl->fillin("DIR",upper_path($virtual));
+ $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
+ $tpl->fillin("SCRIPT",$script);
+
+ my $output = header(-type => "text/html");
+ $output .= $tpl->get_template;
+
+ return \$output;
+ }
}
# exec_remove()
#
-# Remove a file and return to directory view
+# Remove a file or a directory and return to directory view
#
# Params: 1. Reference to user input hash
# 2. Reference to config hash
@@ -436,14 +544,58 @@ sub exec_remove($$)
my $physical = $data->{'physical'};
my $virtual = $data->{'virtual'};
- return error_in_use($virtual) if($data->{'uselist'}->in_use($virtual));
+ if(-d $physical)
+ {
+ # Remove a directory
+
+ if($data->{'cgi'}->param('confirmed'))
+ {
+ rmtree($physical);
+ return devedit_reload({command => 'show', file => upper_path($virtual)});
+ }
+ else
+ {
+ my $tpl = new Template;
+ $tpl->read_file($config->{'tpl_confirm_rmdir'});
- my $dir = upper_path($virtual);
+ $tpl->fillin("DIR",$virtual);
+ $tpl->fillin("UPPER_DIR",upper_path($virtual));
+ $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
+ $tpl->fillin("SCRIPT",$script);
- unlink($physical);
+ my $output = header(-type => "text/html");
+ $output .= $tpl->get_template;
- my $output = redirect("http://$ENV{'HTTP_HOST'}$script?command=show&file=$dir");
- return \$output;
+ return \$output;
+ }
+ }
+ else
+ {
+ # Remove a file
+
+ return error_in_use($virtual) if($data->{'uselist'}->in_use($virtual));
+
+ if($data->{'cgi'}->param('confirmed'))
+ {
+ unlink($physical) or return error($config->{'err_editfailed'},upper_path($virtual),{FILE => $virtual});
+ return devedit_reload({command => 'show', file => upper_path($virtual)});
+ }
+ else
+ {
+ my $tpl = new Template;
+ $tpl->read_file($config->{'tpl_confirm_rmfile'});
+
+ $tpl->fillin("FILE",$virtual);
+ $tpl->fillin("DIR",upper_path($virtual));
+ $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
+ $tpl->fillin("SCRIPT",$script);
+
+ my $output = header(-type => "text/html");
+ $output .= $tpl->get_template;
+
+ return \$output;
+ }
+ }
}
# exec_unlock()
@@ -459,17 +611,29 @@ sub exec_remove($$)
sub exec_unlock($$)
{
my ($data,$config) = @_;
- my $physical = $data->{'physical'};
my $virtual = $data->{'virtual'};
my $uselist = $data->{'uselist'};
- my $dir = upper_path($virtual);
+ if($data->{'cgi'}->param('confirmed'))
+ {
+ file_unlock($uselist,$virtual);
+ return devedit_reload({command => 'show', file => upper_path($virtual)});
+ }
+ else
+ {
+ my $tpl = new Template;
+ $tpl->read_file($config->{'tpl_confirm_unlock'});
- $uselist->remove_file($virtual);
- $uselist->save;
+ $tpl->fillin("FILE",$virtual);
+ $tpl->fillin("DIR",upper_path($virtual));
+ $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
+ $tpl->fillin("SCRIPT",$script);
- my $output = redirect("http://$ENV{'HTTP_HOST'}$script?command=show&file=$dir");
- return \$output;
+ my $output = header(-type => "text/html");
+ $output .= $tpl->get_template;
+
+ return \$output;
+ }
}
# it's true, baby ;-)