+ my $md5 = new Digest::MD5;
+ $md5->addfile(*FILE);
+
+ my $md5file = $md5->hexdigest;
+ my $md5data = md5_hex($content);
+
+ if($md5file ne $md5sum && $md5data ne $md5file && not $cgi->param('saveas'))
+ {
+ # The file changed meanwhile
+
+ my $tpl = new Template;
+ $tpl->read_file($config->{'templates'}->{'editfile'});
+
+ $tpl->fillin('ERROR',$config->{'errors'}->{'edit_file_changed'});
+
+ $tpl->fillin('FILE',encode_html($virtual));
+ $tpl->fillin('FILE_URL',escape($virtual));
+ $tpl->fillin('DIR',encode_html($dir));
+ $tpl->fillin('DIR_URL',escape($dir));
+ $tpl->fillin('URL',encode_html(equal_url($config->{'httproot'},$virtual)));
+ $tpl->fillin('SCRIPT',$script);
+ $tpl->fillin('MD5SUM',$md5file);
+ $tpl->fillin('CONTENT',encode_html($content));
+
+ $tpl->parse_if_block('error',1);
+
+ my $data = header(-type => 'text/html');
+ $data .= $tpl->get_template;
+
+ $output = \$data;
+ }
+ else
+ {
+ if($md5data ne $md5file)
+ {
+ seek(FILE,0,0);
+ truncate(FILE,0);
+
+ print FILE $content;
+ }
+
+ $output = ($cgi->param('continue'))
+ ? devedit_reload({command => 'beginedit', file => $virtual})
+ : devedit_reload({command => 'show', file => $dir});
+ }
+
+ close(FILE);
+
+ return $output;