+ 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;
+ }