Diff for /loncom/interface/lonsyllabus.pm between versions 1.122 and 1.123

version 1.122, 2013/05/10 17:49:11 version 1.123, 2013/05/14 14:30:15
Line 1059  sub save_changes { Line 1059  sub save_changes {
         $syllabus->{'uploaded.lastmodified'} = $now;          $syllabus->{'uploaded.lastmodified'} = $now;
         my $putres = &Apache::lonnet::put('syllabus',$syllabus,$cdom,$cnum);          my $putres = &Apache::lonnet::put('syllabus',$syllabus,$cdom,$cnum);
         if ($putres eq 'ok') {          if ($putres eq 'ok') {
             my %storehash;              ($uploaded,$minimal,$external) = 
             if ($courseenv->{'uploadedsyllabus'}) {                  &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
                 &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');                                       $minimal,$external);
                 $storehash{'uploadedsyllabus'} = '';  
             }  
             if ($courseenv->{'externalsyllabus'}) {  
                 &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');  
                 $storehash{'externalsyllabus'} = '';  
             }  
             if ($courseenv->{'minimalsyllabus'}) {  
                 &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.minimalsyllabus');  
                 $storehash{'minimalsyllabus'} = '';  
             }  
             $storehash{'updatedsyllabus'} = $now;  
             &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);  
             &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.updatedsyllabus' => $now});  
             if (($courseenv->{'externalsyllabus'} || $courseenv->{'uploadedsyllabus'}) ||  
                 ($courseenv->{'minimalsyllabus'})) {  
                 undef($uploaded);  
                 undef($external);  
                 undef($minimal);  
             }  
             $output = '<div>'.              $output = '<div>'.
                       &Apache::lonhtmlcommon::confirm_success(&mt('Template saved.')).                        &Apache::lonhtmlcommon::confirm_success(&mt('Template saved.')).
                       '</div>';                        '</div>';
Line 1095  sub save_changes { Line 1076  sub save_changes {
                 $output = '<div class="LC_info">'.                  $output = '<div class="LC_info">'.
                           &mt('External URL unchanged.').                            &mt('External URL unchanged.').
                           '</div>';                            '</div>';
                 if ($uploaded) {                  ($uploaded,$minimal,$external) =
                     my $prefix;                      &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
                     my $home=&Apache::lonnet::homeserver($cnum,$cdom);                                           $minimal,$external);
                     if ($home ne 'no_host') {  
                         my $protocol = $Apache::lonnet::protocol{$home};  
                         $protocol = 'http' if ($protocol ne 'https');  
                         $prefix = $protocol.'://'.&Apache::lonnet::hostname($home);  
                     }  
                     unless ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {  
                         &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');  
                         &Apache::lonnet::put('environment',{uploadedsyllabus => ''},  
                                              $cdom,$cnum);  
                         undef($uploaded);  
                     }  
                 }  
             } else {              } else {
                 $external=$env{'form.externalsyllabus'};                  $external=$env{'form.externalsyllabus'};
                 $external =~ s/(`)//g;                  $external =~ s/(`)//g;
Line 1121  sub save_changes { Line 1090  sub save_changes {
                     $output = '<div>'.                      $output = '<div>'.
                               &Apache::lonhtmlcommon::confirm_success(&mt('External URL saved.')).                                &Apache::lonhtmlcommon::confirm_success(&mt('External URL saved.')).
                              '</div>';                               '</div>';
                     if ($uploaded) {                      ($uploaded,$minimal,$external) =
                         my $prefix;                          &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
                         my $home=&Apache::lonnet::homeserver($cnum,$cdom);                                               $minimal,$external);
                         if ($home ne 'no_host') {  
                             my $protocol = $Apache::lonnet::protocol{$home};  
                             $protocol = 'http' if ($protocol ne 'https');  
                             $prefix = $protocol.'://'.&Apache::lonnet::hostname($home);  
                         }  
                         unless ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {  
                             &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');  
                             &Apache::lonnet::put('environment',{uploadedsyllabus => ''},  
                                                  $cdom,$cnum);  
                             undef($uploaded);  
                         }  
                     }  
                 } else {                  } else {
                     $output = '<div class="LC_error">'.                      $output = '<div class="LC_error">'.
                               &mt('An error occurred storing the external URL: [_1]',$putres).                                &mt('An error occurred storing the external URL: [_1]',$putres).
Line 1187  END Line 1144  END
                                                        'portfolio/syllabus/loncapa.html');                                                         'portfolio/syllabus/loncapa.html');
         }          }
         if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/[^/]+$}) {          if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/[^/]+$}) {
             my $exturl;              my $exturl = &home_http_host($cdom,$cnum);
             my $home=&Apache::lonnet::homeserver($cnum,$cdom);              if ($exturl) {
             if ($home ne 'no_host') {                  $exturl .= $url;
                 my $protocol = $Apache::lonnet::protocol{$home};  
                 $protocol = 'http' if ($protocol ne 'https');  
                 $exturl = $protocol.'://'.&Apache::lonnet::hostname($home).$url;  
             }              }
             my %storehash;              my %storehash;
             if ($env{'form.choice'} eq 'minimal') {              if ($env{'form.choice'} eq 'minimal') {
Line 1224  END Line 1178  END
                     $output .= &return_to_editor($cdom,$cnum);                      $output .= &return_to_editor($cdom,$cnum);
                     $earlyout = 1;                      $earlyout = 1;
                 }                  }
                   ($uploaded,$minimal,$external) =
                       &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
                                            $minimal,$external);
             } else {              } else {
                 $error = 1;                  $error = 1;
                 $errormsg = $putres;                  $errormsg = $putres;
Line 1273  END Line 1230  END
     return ($earlyout,$uploaded,$external,$minimal,$output);      return ($earlyout,$uploaded,$external,$minimal,$output);
 }  }
   
   sub update_syllabus_env {
       my ($cdom,$cnum,$courseenv,$saved,$uploaded,$minimal,$external);
       return unless(ref($courseenv) eq 'HASH');
       my $now = time;
       my (@envkeys,%storehash);
       if ($saved eq 'template') {
           if ($uploaded) {
               push(@envkeys,'uploaded');
           }
           if ($minimal) {
               push(@envkeys,'minimal');
           }
           if ($external) {
               push(@envkeys,'external');
           }
           $storehash{'updatedsyllabus'} = $now;
           &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.updatedsyllabus' => $now
   });
   
       } elsif ($saved eq 'url') {
           my $prefix = &home_http_host($cdom,$cnum);
           if ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus/\E(.+)$}) {
               my $file = $1;
               if ($file eq 'loncapa.html') {
                   if ($uploaded) {
                       push(@envkeys,'uploaded');
                   }
               } elsif ($minimal) {
                   push(@envkeys,'minimal');
               }
           } else {
               if ($uploaded) {
                   push(@envkeys,'uploaded');
               }
               if ($minimal) {
                   push(@envkeys,'minimal');
               }
           }
       } elsif ($saved eq 'file') {
           if ($minimal) {
               push(@envkeys,'minimal');
           }
       } elsif ($saved eq 'minimal') {
           if ($uploaded) {
               push(@envkeys,'uploaded');
           }
       }
       if (@envkeys > 0) {
           foreach my $item (@envkeys) {
               my $key = $item.'syllabus';
               if ($courseenv->{$key}) {
                   &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
                   $storehash{$key} = '';
               }
               if ($item eq 'uploaded') {
                   undef($uploaded);
               }
               if ($item eq 'external') {
                   undef($external);
               }
               if ($item eq 'minimal') {
                   undef($minimal);
               }
           }
       }
       if (keys(%storehash) > 0) {
           &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
       }
       return ($uploaded,$minimal,$external);
   }
   
   sub home_http_host {
       my ($cdom,$cnum) = @_;
       my $home=&Apache::lonnet::homeserver($cnum,$cdom);
       if ($home ne 'no_host') {
           my $protocol = $Apache::lonnet::protocol{$home};
           $protocol = 'http' if ($protocol ne 'https');
           return $protocol.'//'.$home;
       }
       return;
   }
   
 sub process_upload {  sub process_upload {
     my ($upload_output,$cnum,$cdom,$allfiles,$codebase) = @_;      my ($upload_output,$cnum,$cdom,$allfiles,$codebase) = @_;
     my ($parseaction,$showupload,$mimetype);      my ($parseaction,$showupload,$mimetype);

Removed from v.1.122  
changed lines
  Added in v.1.123


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>