From: Rob H. <for...@us...> - 2002-02-24 05:28:04
|
Update of /cvsroot/sandweb/sandweb/bin In directory usw-pr-cvs1:/tmp/cvs-serv27898/bin Modified Files: sandweb.cgi Log Message: moved edit_file into it's own subroutine Index: sandweb.cgi =================================================================== RCS file: /cvsroot/sandweb/sandweb/bin/sandweb.cgi,v retrieving revision 1.208 retrieving revision 1.209 diff -U2 -r1.208 -r1.209 --- sandweb.cgi 24 Feb 2002 05:03:31 -0000 1.208 +++ sandweb.cgi 24 Feb 2002 05:28:02 -0000 1.209 @@ -244,4 +244,25 @@ ); } + elsif ( $action eq 'edit_file' ) { + # called file editor + + if ($submit) { + edit_file_commit( + ck_auth => $ck_auth, + filename => CGI::param('filename'), + module_name => $module_name, + repo_name => $repo_name, + location => CGI::param('location'), + ) + } else { + edit_file_menu( + ck_auth => $ck_auth, + filename => CGI::param('filename'), + module_name => $module_name, + repo_name => $repo_name, + location => CGI::param('location'), + ); + } + } elsif ( $action eq 'repository' ) { if ($submit) { @@ -896,4 +917,67 @@ } +sub edit_file_menu { + my %args = @_; + + my $ck_auth = $args{'ck_auth'}; + if (! load_config()) { + # no existing user config, forward to prefs menu + preferences_menu( ck_auth => $ck_auth ); + } + + my $location = $args{'location'}; + my $message = CGI::param('message'); + my $username = $auth->get_username(); + my $template_dir = $config->{'paths'}->{'template_dir'}; + my $users_dir = $config->{'paths'}->{'users_dir'}; + my $repo_name = $args{'repo_name'}; + my $module_name = $args{'module_name'}; + my $filename = $args{'filename'}; + + $log->debug("viewing file : $filename"); + + $log->debug("creating File object: $filename"); + my $file = SandWeb::File->new( + 'config_obj' => $config, + 'log_obj' => $log, + 'filename' => $filename, + 'location' => "$users_dir/$username/$module_name$location", + ); + if ( $file->get_file_type() ne "Text" ) { + $log->debug("User wants to edit non-text file : $filename"); + set_error("This does not appear to be a text file."); + view_file_menu( + ck_auth => $ck_auth, + file_command => "view", + filename => $filename, + location => $location, + ); + } + $log->debug("reading $users_dir/$username/$module_name$location/$filename"); + + my $content = $file->file_read(); + + $log->debug("closing $users_dir/$username/$module_name$location/$filename"); + $content = $ui->get_menu( + MENU => 'edit_file', + PROGNAME => $progname, + MODULE_NAME => $module_name, + CONTENT => $content, + LOCATION => $location, + FILENAME => $filename, + ); + + print CGI::header( -cookie => $ck_auth ); + $ui->print_screen( + TITLE=> 'SandWeb : edit file', + MENU_TITLE => 'SandWeb', + SUBMENU_TITLE => 'edit file', + FILENAME => $filename, + LOCATION => $location, + FOOTER => '', + CONTENT => $content, + ERROR => $error, + ); +} @@ -1026,65 +1110,5 @@ } - if ( $file_command eq 'edit' ) { - $log->debug("editing file : $filename"); - if ($Submit) { - my $file_content = CGI::param('data'), - my $filename = $file->get_filename(); - $log->debug("saving edited file : $filename"); - - $log->debug("editing $users_dir/$username/$module_name$location/$filename"); - $file->file_write( - 'location' => "$location", - 'filename' => "$filename", - 'contents' => $file_content, - ); - - view_file_menu( - ck_auth => $ck_auth, - file_command => "view", - filename => $filename, - module_name => $module_name, - repo_name => $repo_name, - location => CGI::param('location'), - ); - } - if ( $file->get_file_type() ne "Text" ) { - $log->debug("User wants to edit non-text file : $filename"); - set_error("This does not appear to be a text file."); - view_file_menu( - ck_auth => $ck_auth, - file_command => "view", - filename => $filename, - location => $location, - ); - } - $log->debug("reading $users_dir/$username/$module_name$location/$filename"); - - my $content = $file->file_read(); - - $log->debug("closing $users_dir/$username/$module_name$location/$filename"); - $content = $ui->get_menu( - MENU => 'edit_file', - PROGNAME => $progname, - MODULE_NAME => $module_name, - CONTENT => $content, - LOCATION => $location, - FILENAME => $filename, - ); - - print CGI::header( -cookie => $ck_auth ); - $ui->print_screen( - TITLE=> 'SandWeb : edit file', - MENU_TITLE => 'SandWeb', - SUBMENU_TITLE => 'edit file', - FILENAME => $filename, - LOCATION => $location, - FOOTER => '', - CONTENT => $content, - ERROR => $error, - ); - exit 0; - } - elsif ( $file_command eq 'create_file' ) { + if ( $file_command eq 'create_file' ) { if ($file) { $file->create_file(); @@ -1200,4 +1224,53 @@ ); } +} + +sub edit_file_commit { + my %args = @_; + + my $ck_auth = $args{'ck_auth'}; + if (! load_config()) { + # no existing user config, forward to prefs menu + preferences_menu( ck_auth => $ck_auth ); + } + + my $location = $args{'location'}; + my $message = CGI::param('message'); + my $username = $auth->get_username(); + my $template_dir = $config->{'paths'}->{'template_dir'}; + my $users_dir = $config->{'paths'}->{'users_dir'}; + my $repo_name = $args{'repo_name'}; + my $module_name = $args{'module_name'}; + my $filename = $args{'filename'}; + + $log->debug("viewing file : $filename"); + + $log->debug("creating File object: $filename"); + my $file = SandWeb::File->new( + 'config_obj' => $config, + 'log_obj' => $log, + 'filename' => $filename, + 'location' => "$users_dir/$username/$module_name$location", + ); + $log->debug("editing file : $filename"); + my $file_content = CGI::param('data'), + $filename = $file->get_filename(); + $log->debug("saving edited file : $filename"); + + $log->debug("editing $users_dir/$username/$module_name$location/$filename"); + $file->file_write( + 'location' => "$location", + 'filename' => "$filename", + 'contents' => $file_content, + ); + + view_file_menu( + ck_auth => $ck_auth, + file_command => "view", + filename => $filename, + module_name => $module_name, + repo_name => $repo_name, + location => CGI::param('location'), + ); } |