Diff for /loncom/interface/portfolio.pm between versions 1.172 and 1.184

version 1.172, 2006/11/09 22:33:32 version 1.184, 2007/06/11 21:29:44
Line 101  sub display_common { Line 101  sub display_common {
  # FIXME: This line should be deleted once Portfolio uses breadcrumbs   # FIXME: This line should be deleted once Portfolio uses breadcrumbs
  $r->print(&Apache::loncommon::help_open_topic('Portfolio About', 'Help on the portfolio'));   $r->print(&Apache::loncommon::help_open_topic('Portfolio About', 'Help on the portfolio'));
   
   
         $r->print(<<"TABLE");           $r->print(<<"TABLE"); 
 <table id="LC_portfolio_actions">  <table id="LC_portfolio_actions">
   <tr id="LC_portfolio_upload">    <tr id="LC_portfolio_upload">
Line 148  TABLE Line 147  TABLE
     );      );
     $r->print('<span class="LC_current_location">'.&make_anchor($url,\%anchor_fields,$port_path).'/');      $r->print('<span class="LC_current_location">'.&make_anchor($url,\%anchor_fields,$port_path).'/');
     if (@tree > 1){      if (@tree > 1){
         my $newCurrentPath = '';          my $newCurrentPath = '/';
         for (my $i = 1; $i< @tree; $i++){          for (my $i = 1; $i< @tree; $i++){
             $newCurrentPath .= $tree[$i].'/';              $newCurrentPath .= $tree[$i].'/';
             my %anchor_fields = (              my %anchor_fields = (
                 'selectfile' => $tree[$i],                  'selectfile' => $tree[$i],
                 'currentpath' => '/',                  'currentpath' => $newCurrentPath,
                 'mode' => $env{"form.mode"},                  'mode' => $env{"form.mode"},
                 'fieldname' => $env{"form.fieldname"},                  'fieldname' => $env{"form.fieldname"},
                 'continue' => $env{"form.continue"}                  'continue' => $env{"form.continue"}
Line 568  sub delete_confirmed { Line 567  sub delete_confirmed {
        $delete_file);         $delete_file);
         if ($result ne 'ok') {          if ($result ne 'ok') {
     $r->print('<span class="LC_error">'.      $r->print('<span class="LC_error">'.
                      &mt('An error occured ([_1]) while trying to delete                        &mt('An error occurred ([_1]) while trying to delete 
                          [_2].',$result,&display_file(undef, $delete_file)).                           [_2].',$result,&display_file(undef, $delete_file)).
                       '</span><br /><br />');                        '</span><br /><br />');
         } else {          } else {
Line 589  sub delete_confirmed { Line 588  sub delete_confirmed {
                     &Apache::lonnet::modify_access_controls($file_name,\%changes,                      &Apache::lonnet::modify_access_controls($file_name,\%changes,
                                                             $udom,$uname);                                                              $udom,$uname);
                     if ($outcome ne 'ok') {                      if ($outcome ne 'ok') {
                            $r->print('<br />'.&mt("An error occured ([_1]) while ".                             $r->print('<br />'.&mt("An error occurred ([_1]) while ".
                                "trying to delete access controls for the file.",$outcome).                                 "trying to delete access controls for the file.",$outcome).
                                '</span><br /><br />');                                 '</span><br /><br />');
                     } else {                      } else {
Line 597  sub delete_confirmed { Line 596  sub delete_confirmed {
                             $r->print('<br />'.&mt('Access controls also deleted for the file.').'<br /><br />');                              $r->print('<br />'.&mt('Access controls also deleted for the file.').'<br /><br />');
                         } else {                          } else {
                             $r->print('<span class="LC_error">'.'<br />'.                              $r->print('<span class="LC_error">'.'<br />'.
                                &mt("An error occured ([_1]) while ".                                 &mt("An error occurred ([_1]) while ".
                                    "trying to delete access controls for the file.",$deloutcome).                                     "trying to delete access controls for the file.",$deloutcome).
                                    '</span><br /><br />');                                     '</span><br /><br />');
                         }                          }
Line 627  sub delete_dir_confirmed { Line 626  sub delete_dir_confirmed {
        $directory_name);         $directory_name);
                 
     if ($result ne 'ok') {      if ($result ne 'ok') {
  $r->print('<span class="LC_error"> An error occured (dir) ('.$result.   $r->print('<span class="LC_error"> An error occurred (dir) ('.$result.
   ') while trying to delete '.$directory_name.'</span><br />');    ') while trying to delete '.$directory_name.'</span><br />');
     } else {      } else {
         # now remove from recent          # now remove from recent
Line 682  sub rename_confirmed { Line 681  sub rename_confirmed {
         $chg_access = &access_for_renamed($filenewname,$group,$udom,$uname);          $chg_access = &access_for_renamed($filenewname,$group,$udom,$uname);
     } else {            } else {      
  $r->print('<span class="LC_error">'.   $r->print('<span class="LC_error">'.
   &mt('An error occured ([_1]) while trying to rename [_2]'    &mt('An error occurred ([_1]) while trying to rename [_2]'
       .' to [_3]',$result,&display_file(),        .' to [_3]',$result,&display_file(),
       &display_file('',$filenewname)).'</span><br />');        &display_file('',$filenewname)).'</span><br />');
         return;          return;
Line 719  sub access_for_renamed { Line 718  sub access_for_renamed {
             &Apache::lonnet::modify_access_controls($oldfile,\%change_old,              &Apache::lonnet::modify_access_controls($oldfile,\%change_old,
     $udom,$uname);      $udom,$uname);
         if ($outcome ne 'ok') {          if ($outcome ne 'ok') {
             $chg_text ='<br /><br />'.&mt("An error occured ([_1]) while ".              $chg_text ='<br /><br />'.&mt("An error occurred ([_1]) while ".
                 "trying to delete access control records for the old name.",$outcome).                  "trying to delete access control records for the old name.",$outcome).
                 '</span><br />';                  '</span><br />';
         } else {          } else {
             if ($deloutcome ne 'ok') {              if ($deloutcome ne 'ok') {
                 $chg_text = '<br /><br /><span class="LC_error"><br />'.                  $chg_text = '<br /><br /><span class="LC_error"><br />'.
     &mt("An error occured ([_1]) while ".      &mt("An error occurred ([_1]) while ".
  "trying to delete access control records for the old name.",$deloutcome).   "trying to delete access control records for the old name.",$deloutcome).
  '</span><br />';   '</span><br />';
             }              }
Line 735  sub access_for_renamed { Line 734  sub access_for_renamed {
                                                     $udom,$uname);                                                      $udom,$uname);
         if ($outcome ne 'ok') {          if ($outcome ne 'ok') {
             $chg_text .= '<br /><br />'.              $chg_text .= '<br /><br />'.
  &mt("An error occured ([_1]) while ".   &mt("An error occurred ([_1]) while ".
                 "trying to update access control records for the new name.",$outcome).                  "trying to update access control records for the new name.",$outcome).
                 '</span><br />';                  '</span><br />';
         }          }
Line 762  sub display_access { Line 761  sub display_access {
         $info .= '<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.');          $info .= '<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.');
         $info .= '</li><li>'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.');          $info .= '</li><li>'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.');
         $info .= '</li><li>'.&explain_conditionals();          $info .= '</li><li>'.&explain_conditionals();
         $info .= '</li></ul>';          $info .= '</li></ul>'.
                     &mt('A listing of files viewable without log-in is available at: ')."<a href=\"/adm/$udom/$uname/aboutme/portfolio\">http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme/portfolio</a>.<br />";
         if ($group eq '') {          if ($group eq '') {
             $info .= (&mt("A listing of files viewable without log-in is available at: <a href='/adm/$udom/$uname/aboutme/portfolio'>http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme/portfolio</a>.<br />For logged in users a 'Display file listing' link will also appear (when there are viewable files) on your personal information page:<br /><a href='/adm/$udom/$uname/aboutme'>http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme</a><br />"));              $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on your personal information page:");
           } else {
               $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on the course information page:");
           }
           $info .= "<br /><a href=\"/adm/$udom/$uname/aboutme\">http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme</a><br />";
           if ($group ne '') {
               $info .= &mt("Users with privileges to edit course contents may add a course information page to a course using the 'Course Info' button in DOCS").'<br />';
         }          }
     } else {      } else {
         $header = '<h3>'.&mt('Conditional access controls for file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>'.          $header = '<h3>'.&mt('Conditional access controls for file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>'.
Line 1008  sub update_access { Line 1014  sub update_access {
         } else {          } else {
             if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {              if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
                 $errors .= '<span class="LC_error">'.                  $errors .= '<span class="LC_error">'.
     &mt('A problem occurred storing access control settings: [_1]',$outcome).      &mt('A problem occurred saving access control settings: [_1]',$outcome).
     '</span>';      '</span>';
             }              }
         }          }
Line 1341  sub display_access_row { Line 1347  sub display_access_row {
                       '</th>');                        '</th>');
             $colspan ++;              $colspan ++;
         } elsif ($type eq 'domains') {          } elsif ($type eq 'domains') {
             @all_doms = &Apache::loncommon::get_domains();              @all_doms = sort(&Apache::lonnet::all_domains());
         }          }
         $r->print(&Apache::loncommon::end_data_table_header_row());          $r->print(&Apache::loncommon::end_data_table_header_row());
         foreach my $key (@{$items}) {          foreach my $key (@{$items}) {
Line 1744  ENDSMP Line 1750  ENDSMP
     }      }
 }  }
   
 sub upload {  
     my ($r,$url,$group)=@_;  
     my $fname=$env{'form.uploaddoc.filename'};  
     my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)  
     my $disk_quota = 20000; # expressed in k  
     if (defined($group)) {  
         my $grp_quota = &get_group_quota($group); # quota expressed in k   
         if ($grp_quota ne '') {  
             $disk_quota = $grp_quota;  
         } else {  
             $disk_quota = 0;  
         }  
     }  
     $fname=&Apache::lonnet::clean_filename($fname);  
   
     my $portfolio_root=&get_portfolio_root();  sub check_for_upload {
     my ($uname,$udom) = &get_name_dom();      my ($path,$fname,$group,$element) = @_;
       my $disk_quota = &get_quota($group);
       my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
   
       my $portfolio_root = &get_portfolio_root();
     my $port_path = &get_port_path();      my $port_path = &get_port_path();
       my ($uname,$udom) = &get_name_dom();
     # Fixme --- Move the checking for existing file to LOND error return      # Fixme --- Move the checking for existing file to LOND error return
     my @dir_list=&get_dir_list($portfolio_root);      my @dir_list=&get_dir_list($portfolio_root,$path);
     my $found_file = 0;      my $found_file = 0;
     my $locked_file = 0;      my $locked_file = 0;
     foreach my $line (@dir_list) {      foreach my $line (@dir_list) {
         my ($file_name)=split(/\&/,$line,2);          my ($file_name)=split(/\&/,$line,2);
         if ($file_name eq $fname){          if ($file_name eq $fname){
             $file_name = $env{'form.currentpath'}.$file_name;              $file_name = $path.$file_name;
             $file_name = &prepend_group($file_name);              $file_name = &prepend_group($file_name);
             $found_file = 1;              $found_file = 1;
             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {              if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
Line 1778  sub upload { Line 1775  sub upload {
         }          }
     }      }
     my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);      my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
   
     if (($current_disk_usage + $filesize) > $disk_quota){      if (($current_disk_usage + $filesize) > $disk_quota){
         $r->print('<span class="LC_error">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.</span>'.          my $msg = '<span class="LC_error">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.</span>'.
                   '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');      '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.';
         $r->print(&done('Back',$url));   return ('will_exceed_quota',$msg);
     }       } elsif ($found_file) {
     elsif ($found_file){          if ($locked_file) {
         if ($locked_file){              my $msg = '<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>'.$port_path.$path.'</strong></span>'.
             $r->print('<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></span>'.   '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.';
                   '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');      return ('file_locked',$msg);
             $r->print(&done('Back',$url));         } else {
         } else {                 my $msg = '<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$port_path.$path.'</strong></span>'.
             $r->print('<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></span>'.   '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$path;
                   '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});      return ('file_exists',$msg);
             $r->print(&done('Back',$url));   }
         }  
     } else {  
         my $result=&Apache::lonnet::userfileupload('uploaddoc','',  
          $port_path.$env{'form.currentpath'});  
         if ($result !~ m|^/uploaded/|) {  
             $r->print('<span class="LC_error">'.'An errror occured ('.$result.  
               ') while trying to upload '.&display_file().'</span><br />');  
     $r->print(&done('Back',$url));  
         } else {  
             $r->print(&done(undef,$url));  
         }  
     }      }
 }  }
   
   sub upload {
       my ($r,$url,$group)=@_;
       my $fname=&Apache::lonnet::clean_filename($env{'form.uploaddoc.filename'});
   
       my ($state,$msg) = &check_for_upload($env{'form.currentpath'},
    $fname,$group,'uploaddoc');
   
       if ($state eq 'will_exceed_quota'
    || $state eq 'file_locked'
    || $state eq 'file_exists' ) {
    $r->print($msg.&done('Back',$url));
    return;
       }
   
       my $port_path = &get_port_path();
       my (%allfiles,%codebase,$mode);
       if ($env{'form.uploaddoc.filename'} =~ m/(\.htm|\.html|\.shtml)$/i) {
    $mode = 'parse';
   
       }
       my $result=
    &Apache::lonnet::userfileupload('uploaddoc','',
    $port_path.$env{'form.currentpath'},
    $mode,\%allfiles,\%codebase);
       if ($result !~ m|^/uploaded/|) {
    $r->print('<span class="LC_error">'.'An error occurred ('.$result.
     ') while trying to upload '.&display_file().'</span><br />');
    $r->print(&done('Back',$url));
       } else {
    if (%allfiles) {
       my $state = <<STATE;
       <input type="hidden" name="action"      value="upload_embedded" />
       <input type="hidden" name="currentpath" value="$env{'form.currentpath'}" />
       <input type="hidden" name="fieldname"   value="$env{'form.fieldname'}" />
       <input type="hidden" name="mode"        value="$env{'form.mode'}" />
   STATE
               $r->print("<h2>".&mt("Reference Warning")."</h2>");
               $r->print("<p>".&mt("Completed upload of the file. This file contained references to other files. You must upload the referenced files or else the uploaded file may not work properly.")."</p>");
               $r->print("<p>".&mt("Please select the locations from which the referenced files are to be uploaded.")."</p>");
       $r->print(&Apache::londocs::ask_for_embedded_content('/adm/portfolio',$state,\%allfiles,\%codebase,
         {'error_on_invalid_names'   => 1,
          'ignore_remote_references' => 1,}));
       $r->print('<p>Or '.&done('Return to directory listing',$url).'</p>');
    } else {
       $r->print(&done(undef,$url));
    }
       }
   }
   
   sub upload_embedded {
       my ($r,$url,$group)=@_;
       for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
    next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
    my $orig_uploaded_filename = 
       $env{'form.embedded_item_'.$i.'.filename'};
   
    $env{'form.embedded_orig_'.$i} = 
       &unescape($env{'form.embedded_orig_'.$i});
    my ($path,$fname) = 
       ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
    # no path, whole string is fname
    if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
   
    $path = $env{'form.currentpath'}.$path;
    $fname = &Apache::lonnet::clean_filename($fname);
   
    my ($state,$msg) = &check_for_upload($path,$fname,$group,
        'embedded_item_'.$i);
   
    if ($state eq 'will_exceed_quota'
       || $state eq 'file_locked'
       || $state eq 'file_exists' ) {
       $r->print($msg);
       next;
    }
   
    my $port_path = &get_port_path();
    my $src_path = $env{'form.embedded_orig_'.$i};
    $env{'form.embedded_item_'.$i.'.filename'}=$fname;
   
    my $result=
       &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
       $port_path.$path);
    if ($result !~ m|^/uploaded/|) {
       $r->print('<span class="LC_error">'.'An error occurred ('.$result.
         ') while trying to upload '.$orig_uploaded_filename.' for embedded element '.$env{'form.embedded_orig_'.$i}.'</span><br />');
       next;
    } else {
       $r->print("<p> Uploaded ".
         &display_file($port_path.$path,$fname).'</p>');
    }
       }
       $r->print(&done(undef,$url));
   }
   
 sub lock_info {  sub lock_info {
     my ($r,$url,$group) = @_;      my ($r,$url,$group) = @_;
     my ($uname,$udom) = &get_name_dom();      my ($uname,$udom) = &get_name_dom();
Line 1878  sub createdir { Line 1960  sub createdir {
         my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,          my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
          $port_path.$env{'form.currentpath'}.$newdir);           $port_path.$env{'form.currentpath'}.$newdir);
         if ($result ne 'ok') {          if ($result ne 'ok') {
        $r->print('<span class="LC_error">'.'An errror occured ('.$result.         $r->print('<span class="LC_error">'.'An error occurred ('.$result.
           ') while trying to create a new directory '.&display_file().'</span><br />');            ') while trying to create a new directory '.&display_file().'</span><br />');
         }          }
     }      }
Line 1923  sub get_group_quota { Line 2005  sub get_group_quota {
 }   } 
   
 sub get_dir_list {  sub get_dir_list {
     my ($portfolio_root) = @_;      my ($portfolio_root,$path) = @_;
       $path ||= $env{'form.currentpath'};
     my ($uname,$udom) = &get_name_dom();      my ($uname,$udom) = &get_name_dom();
     return &Apache::lonnet::dirlist($env{'form.currentpath'},      return &Apache::lonnet::dirlist($path,$udom,$uname,$portfolio_root);
                                           $udom,$uname,$portfolio_root);  
 }  }
   
 sub get_name_dom {  sub get_name_dom {
Line 2022  sub coursegrp_portfolio_header { Line 2104  sub coursegrp_portfolio_header {
     return $output;      return $output;
 }  }
   
   sub get_quota {
       my ($group) = @_;
       my $disk_quota;
       if (defined($group)) {
           my $grp_quota = &get_group_quota($group); # quota expressed in k
           if ($grp_quota ne '') {
               $disk_quota = $grp_quota;
           } else {
               $disk_quota = 0;
           }
       } else {
           $disk_quota = &Apache::loncommon::get_user_quota($env{'user.name'},
                                       $env{'user.domain'}); #expressed in Mb
           $disk_quota = 1000 * $disk_quota; # convert from Mb to kb
       }
       return $disk_quota;
   }
   
 sub handler {  sub handler {
     # this handles file management      # this handles file management
Line 2118  sub handler { Line 2217  sub handler {
         $r->print(&Apache::loncommon::start_page($title));          $r->print(&Apache::loncommon::start_page($title));
     }      }
     $r->rflush();      $r->rflush();
       my ($blocked,$blocktext) = 
           &Apache::loncommon::blocking_status('port',$uname,$udom);
       if ($blocked) {
            $r->print($blocktext);
            $r->print(&Apache::loncommon::end_page());
            return OK;
       }
  if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){   if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
        $r->print('<span class="LC_error">'.         $r->print('<span class="LC_error">'.
       'No file was selected to upload.'.        'No file was selected to upload.'.
Line 2140  sub handler { Line 2246  sub handler {
         } else {          } else {
             &missing_priv($r,$url,'upload');              &missing_priv($r,$url,'upload');
         }          }
       } elsif ($env{'form.action'} eq 'upload_embedded') {
    if ($can_upload) {
       &upload_embedded($r,$url,$group);
           } else {
               &missing_priv($r,$url,'upload');
           }
     } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {      } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
         if ($can_delete) {          if ($can_delete) {
     &delete_confirmed($r,$url,$group);      &delete_confirmed($r,$url,$group);

Removed from v.1.172  
changed lines
  Added in v.1.184


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