Annotation of loncom/interface/portfolio.pm, revision 1.71

1.3       banghart    1: # Copyright Michigan State University Board of Trustees
                      2: #
                      3: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      4: #
                      5: # LON-CAPA is free software; you can redistribute it and/or modify
                      6: # it under the terms of the GNU General Public License as published by
                      7: # the Free Software Foundation; either version 2 of the License, or 
                      8: # (at your option) any later version.
                      9: #
                     10: # LON-CAPA is distributed in the hope that it will be useful,
                     11: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     13: # GNU General Public License for more details.
                     14: #
                     15: # You should have received a copy of the GNU General Public License
                     16: # along with LON-CAPA; if not, write to the Free Software
                     17: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     18: #
                     19: # /home/httpd/html/adm/gpl.txt
                     20: #
                     21: # http://www.lon-capa.org/
                     22: #
                     23: 
1.1       banghart   24: package Apache::portfolio;
                     25: use strict;
                     26: use Apache::Constants qw(:common :http);
1.2       banghart   27: use Apache::loncommon;
1.1       banghart   28: use Apache::lonnet;
1.2       banghart   29: use Apache::lontexconvert;
                     30: use Apache::lonfeedback;
                     31: use Apache::lonlocal;
1.16      banghart   32: 
                     33: # receives a file name and path stub from username/userfiles/portfolio/
                     34: # returns an anchor tag consisting encoding filename and currentpath
1.23      albertel   35: sub make_anchor {
1.57      banghart   36:     my ($filename, $current_path, $current_mode, $field_name) = @_;
                     37:     my $anchor = '<a href="/adm/portfolio?selectfile='.$filename.'&currentpath='.$current_path.'&mode='.$current_mode.'&fieldname='.$field_name.'">'.$filename.'</a>';
1.8       albertel   38:     return $anchor;
1.6       banghart   39: }
1.24      albertel   40: my $dirptr=16384;
1.48      banghart   41: sub display_common {
1.30      banghart   42:     my ($r,$current_path,$is_empty,$dir_list)=@_;
1.18      banghart   43:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.20      banghart   44:     $r->print('<table border="0" cellspacing="2" cellpadding="2"><tr valign="middle">');
                     45:     $r->print('<td bgcolor="#ccddaa" align="center">');
                     46:     my $displayOut = '<form method="post" enctype="multipart/form-data">';
1.50      banghart   47:     $displayOut .= '<input name="uploaddoc" type="file" />'.
1.24      albertel   48:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
1.50      banghart   49:         '<input type="hidden" name="action" value="'.$ENV{"form.action"}.'" />'.
                     50:         '<input type="hidden" name="fieldname" value="'.$ENV{"form.fieldname"}.'" />'.
1.57      banghart   51:         '<input type="hidden" name="mode" value="'.$ENV{"form.mode"}.'" />'. 
1.20      banghart   52:         '<input type="submit" name="storeupl" value="Upload" />'.
                     53:         '</form>';
                     54:     $r->print($displayOut);
1.22      albertel   55:     $r->print('</td></tr><tr><td bgcolor="#ccddaa" align="center">');
1.24      albertel   56:     $displayOut = '<form method="post">';
                     57:     $displayOut .= '<input name="newdir" type="input" />'.
                     58:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
1.50      banghart   59:         '<input type="hidden" name="action" value="'.$ENV{"form.action"}.'" />'.
                     60:         '<input type="hidden" name="fieldname" value="'.$ENV{"form.fieldname"}.'" />'.
1.57      banghart   61:         '<input type="hidden" name="mode" value="'.$ENV{"form.mode"}.'" />'. 
1.22      albertel   62:         '<input type="submit" name="createdir" value="'.&mt("Create Directory").'" />'.
                     63:         '</form>';
                     64:     $r->print($displayOut);
                     65:     $r->print('</td></tr></table>');
1.24      albertel   66:     my @tree = split (/\//,$current_path);
1.57      banghart   67:     $r->print('<font size="+2">'.&make_anchor('portfolio','/',$ENV{"form.mode"},$ENV{"form.fieldname"}).'/');
1.19      banghart   68:     if (@tree > 1){
                     69:         my $newCurrentPath = '';
                     70:         for (my $i = 1; $i< @tree; $i++){
                     71:             $newCurrentPath .= $tree[$i].'/';
1.57      banghart   72:             $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath, $ENV{"form.mode"},$ENV{"form.fieldname"}).'/');
1.19      banghart   73:         }
                     74:     }
                     75:     $r->print('</font>');
1.24      albertel   76:     &Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path);
1.58      banghart   77:     $r->print('<br /><form method=post action="/adm/portfolio?mode='.$ENV{"form.mode"}.'&fieldname='.$ENV{"form.fieldname"}.'">'.
1.22      albertel   78: 	      &Apache::lonhtmlcommon::select_recent('portfolio','currentpath',
                     79: 						    'this.form.submit();'));
1.21      banghart   80:     $r->print("</form>");
1.48      banghart   81: }
                     82: sub display_directory {
                     83:     my ($r,$current_path,$is_empty,$dir_list)=@_;
                     84:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
                     85:     my $display_out;
1.64      banghart   86:     my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash ($ENV{'user.domain'},$ENV{'user.name'});
1.45      banghart   87:     if ($is_empty && ($current_path ne '/')) {
1.48      banghart   88:         $display_out = '<form method="post" action="/adm/portfolio">'.
1.30      banghart   89:         '<input type="hidden" name="action" value="deletedir" />'.
                     90:         '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
                     91:         '<input type="hidden" name="selectfile" value="" />'.
                     92:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
                     93:         '</form>';
                     94:         
1.48      banghart   95:         $r->print($display_out);
1.31      albertel   96: 	return;
                     97:     }
1.18      banghart   98:     $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
1.70      banghart   99:             '<tr><th colspan="2">Actions</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
1.39      banghart  100:     my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path";
1.64      banghart  101:     $r->print('<form method="post" action="/adm/portfolio">');
1.26      albertel  102:     foreach my $line (sort 
                    103: 		      { 
                    104: 			  my ($afile)=split('&',$a,2);
                    105: 			  my ($bfile)=split('&',$b,2);
                    106: 			  return (lc($afile) cmp lc($bfile));
                    107: 		      } (@$dir_list)) {
1.18      banghart  108:     	#$strip holds directory/file name
                    109:     	#$dom 
1.23      albertel  110:     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
                    111:     	if (($filename ne '.') && ($filename ne '..')) {
                    112:             if ($dirptr&$testdir) {
1.70      banghart  113:                 $r->print('<tr bgcolor="#FFAA99"><td colspan="2"><img src="'.$iconpath.'folder_closed.gif"></td>');
1.19      banghart  114:                 $r->print('<td>Go to ...</td>');
1.57      banghart  115:                 $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/',$ENV{'form.mode'},$ENV{"form.fieldname"}).'</td>'); 
1.19      banghart  116:                 $r->print('</tr>'); 
1.23      albertel  117:             } else {
1.22      albertel  118:                 $r->print('<tr bgcolor="#CCCCFF">');
1.64      banghart  119:                 if (exists $locked_files{$current_path.$filename}){
1.70      banghart  120:                     $r->print('<td colspan="2">Locked</td>');
1.64      banghart  121:                 } else {
1.70      banghart  122:                     $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'" />
                    123:                         <a href="/adm/portfolio?rename='.$filename.'&amp;currentpath='.$current_path.'">Rename</a></td>
                    124:                         <td><a href="/adm/portfolio?meta='.$filename.'&amp;currentpath='.$current_path.'">Meta</a>
1.64      banghart  125:                         </td>');
                    126:                 }
1.22      albertel  127:                 $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
1.23      albertel  128:                 $r->print('<td><a href="'.$href_location.$filename.'">'.
1.39      banghart  129: 			    $filename.'</a></td>'); 
1.22      albertel  130:                 $r->print('<td>'.$size.'</td>');
                    131:                 $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
1.19      banghart  132:                 $r->print('</tr>'); 
                    133:             }
1.18      banghart  134:         }
                    135:     }
                    136: #   <tr bgcolor="#FFAA99"> pink bg 
                    137: #   <tr bgcolor="#CCCCFF"> blue bg            
1.24      albertel  138: #   $r->print(&display_directory($current_path, $currentFile, @dir_list));
1.18      banghart  139: #    $r->print('</td>><td>');
1.24      albertel  140: #   $r->print(&display_actions($current_path, $currentFile, $isEmpty));
1.64      banghart  141:     $r->print('</table>
                    142:     <input type="submit" name="doit" value="Delete Checked Files" />
                    143:     <input type="hidden" name="action" value="delete" />
                    144:     <input type="hidden" name="currentpath" value="'.$current_path.'" />
                    145:     </form>');
1.24      albertel  146: }
1.47      banghart  147: sub display_file_select {
                    148:     my ($r,$current_path,$is_empty,$dir_list)=@_;
                    149:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.48      banghart  150:     my $display_out;
1.61      banghart  151:     my $checked_files = &Apache::lonnet::files_in_path($ENV{'user.name'}, $ENV{'form.currentpath'});
1.47      banghart  152:     if ($is_empty && ($current_path ne '/')) {
1.48      banghart  153:         $display_out = '<form method="post" action="/adm/portfolio">'.
1.47      banghart  154:         '<input type="hidden" name="action" value="deletedir" />'.
                    155:         '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
                    156:         '<input type="hidden" name="selectfile" value="" />'.
                    157:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
1.48      banghart  158: 
1.47      banghart  159:         '</form>';
                    160:         
1.48      banghart  161:         $r->print($display_out);
1.47      banghart  162: 	return;
                    163:     }
                    164:     $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
                    165:             '<tr><th>Select</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
                    166:     my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path";
1.48      banghart  167:     $r->print('<form method="post" name="checkselect" action="/adm/portfolio">');
1.47      banghart  168:     foreach my $line (sort 
                    169: 		      { 
                    170: 			  my ($afile)=split('&',$a,2);
                    171: 			  my ($bfile)=split('&',$b,2);
                    172: 			  return (lc($afile) cmp lc($bfile));
                    173: 		      } (@$dir_list)) {
                    174:     	#$strip holds directory/file name
                    175:     	#$dom 
                    176:     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
1.61      banghart  177:     	$filename =~ s/\s+$//;
1.47      banghart  178:     	if (($filename ne '.') && ($filename ne '..')) {
                    179:             if ($dirptr&$testdir) {
                    180:                 $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
                    181:                 $r->print('<td>Go to ...</td>');
1.57      banghart  182:                 $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/',$ENV{'form.mode'},$ENV{"form.fieldname"}).'</td>'); 
1.47      banghart  183:                 $r->print('</tr>'); 
                    184:             } else {
                    185:                 $r->print('<tr bgcolor="#CCCCFF">');
1.65      banghart  186:                 $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'"'); 
1.61      banghart  187:                 if ($$checked_files{$filename} eq 'selected') {
                    188:                     $r->print("CHECKED");
                    189:                 }
                    190:                 $r->print('></td>');
1.47      banghart  191:                 $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
                    192:                 $r->print('<td><a href="'.$href_location.$filename.'">'.
                    193: 			    $filename.'</a></td>'); 
                    194:                 $r->print('<td>'.$size.'</td>');
                    195:                 $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
                    196:                 $r->print('</tr>'); 
                    197:             }
                    198:         }
                    199:     }
1.48      banghart  200:     $r->print('</table>
1.60      banghart  201:             <input type="hidden" name="continue" value="true">
                    202:             <input type="hidden" name="fieldname" value="'.$ENV{'form.fieldname'}.'">
                    203:             <input type="hidden" name="mode" value="selectfile">
                    204:             <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
1.48      banghart  205:             <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
                    206:             <input type="hidden" name="currentpath" value="'.$current_path.'" />
                    207:     </form>');
1.47      banghart  208: }
1.71    ! banghart  209: sub prettyinput {
        !           210:     my ($type,$value,$fieldname,$formname,
        !           211: 	$relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
        !           212:     if (! defined($size)) {
        !           213:         $size = 80;
        !           214:     }
        !           215:     # Language
        !           216:     if ($type eq 'language') {
        !           217: 	return &Apache::lonmeta::selectbox($fieldname,
        !           218: 			  $value,
        !           219: 			  \&Apache::loncommon::languagedescription,
        !           220: 			  (&Apache::loncommon::languageids)).
        !           221:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
        !           222:     }
        !           223:     # Copyright
        !           224:     if ($type eq 'copyright') {
        !           225: 	return &Apache::lonmeta::selectbox($fieldname,
        !           226: 			  $value,
        !           227: 			  \&Apache::loncommon::copyrightdescription,
        !           228: 			  (&Apache::loncommon::copyrightids)).
        !           229:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
        !           230:     }
        !           231:     # Source Copyright
        !           232:     if ($type eq 'sourceavail') {
        !           233: 	return &Apache::lonmeta::selectbox($fieldname,
        !           234: 			  $value,
        !           235: 			  \&Apache::loncommon::source_copyrightdescription,
        !           236: 			  (&Apache::loncommon::source_copyrightids)).
        !           237:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
        !           238:     }
        !           239:     # Gradelevels
        !           240:     if (($type eq 'lowestgradelevel') ||
        !           241: 	($type eq 'highestgradelevel')) {
        !           242: 	return &Apache::loncommon::select_level_form($value,$fieldname).
        !           243:             &relatedfield(0,$relatedsearchflag,$relatedsep);
        !           244:     }
        !           245:     # Obsolete
        !           246:     if ($type eq 'obsolete') {
        !           247: 	return '<input type="checkbox" name="'.$fieldname.'"'.
        !           248: 	    ($value?' checked="1"':'').' />'.
        !           249:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
        !           250:     }
        !           251:     # Obsolete replacement file
        !           252:     if ($type eq 'obsoletereplacement') {
        !           253: 	return '<input type="text" name="'.$fieldname.
        !           254: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
        !           255: 	    "('".$formname."','".$fieldname."'".
        !           256: 	    ",'')\">".&mt('Select').'</a>'.
        !           257:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
        !           258:     }
        !           259:     # Customdistribution file
        !           260:     if ($type eq 'customdistributionfile') {
        !           261: 	return '<input type="text" name="'.$fieldname.
        !           262: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
        !           263: 	    "('".$formname."','".$fieldname."'".
        !           264: 	    ",'rights')\">".&mt('Select').'</a>'.
        !           265:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
        !           266:     }
        !           267:     # Source Customdistribution file
        !           268:     if ($type eq 'sourcerights') {
        !           269: 	return '<input type="text" name="'.$fieldname.
        !           270: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
        !           271: 	    "('".$formname."','".$fieldname."'".
        !           272: 	    ",'rights')\">".&mt('Select').'</a>'.
        !           273:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
        !           274:     }
        !           275:     # Dates
        !           276:     if (($type eq 'creationdate') ||
        !           277: 	($type eq 'lastrevisiondate')) {
        !           278: 	return 
        !           279:             &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
        !           280:             &relatedfield(0,$relatedsearchflag,$relatedsep);
        !           281:     }
        !           282:     # No pretty input found
        !           283:     $value=~s/^\s+//gs;
        !           284:     $value=~s/\s+$//gs;
        !           285:     $value=~s/\s+/ /gs;
        !           286:     $value=~s/\"/\&quot\;/gs;
        !           287:     return 
        !           288:         '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
        !           289:         'value="'.$value.'" />'.
        !           290:         &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
        !           291:                       $relatedvalue); 
        !           292: }
        !           293: 
        !           294: sub relatedfield {
        !           295:     my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
        !           296:     if (! $relatedsearchflag) { 
        !           297:         return '';
        !           298:     }
        !           299:     if (! defined($relatedsep)) {
        !           300:         $relatedsep=' ';
        !           301:     }
        !           302:     if (! $show) {
        !           303:         return $relatedsep.'&nbsp;';
        !           304:     }
        !           305:     return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
        !           306: 	($relatedvalue?' checked="1"':'').' />';
        !           307: }
        !           308: 
        !           309: 
        !           310: # The field names
        !           311: sub fieldnames {
        !           312:     return &Apache::lonlocal::texthash
        !           313:         (
        !           314:          'title' => 'Title',
        !           315:          'author' =>'Author(s)',
        !           316:          'authorspace' => 'Author Space',
        !           317:          'modifyinguser' => 'Last Modifying User',
        !           318:          'subject' => 'Subject',
        !           319:          'keywords' => 'Keyword(s)',
        !           320:          'notes' => 'Notes',
        !           321:          'abstract' => 'Abstract',
        !           322:          'lowestgradelevel' => 'Lowest Grade Level',
        !           323:          'highestgradelevel' => 'Highest Grade Level',
        !           324:          'standards' => 'Standards',
        !           325:          'mime' => 'MIME Type',
        !           326:          'language' => 'Language',
        !           327:          'creationdate' => 'Creation Date',
        !           328:          'lastrevisiondate' => 'Last Revision Date',
        !           329:          'owner' => 'Publisher/Owner',
        !           330:          'copyright' => 'Copyright/Distribution',
        !           331:          'customdistributionfile' => 'Custom Distribution File',
        !           332:          'sourceavail' => 'Source Available',
        !           333:          'sourcerights' => 'Source Custom Distribution File',
        !           334:          'obsolete' => 'Obsolete',
        !           335:          'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
        !           336:          'count'      => 'Network-wide number of accesses (hits)',
        !           337:          'course'     => 'Network-wide number of courses using resource',
        !           338:          'course_list' => 'Network-wide courses using resource',
        !           339:          'sequsage'      => 'Number of resources using or importing resource',
        !           340:          'sequsage_list' => 'Resources using or importing resource',
        !           341:          'goto'       => 'Number of resources that follow this resource in maps',
        !           342:          'goto_list'  => 'Resources that follow this resource in maps',
        !           343:          'comefrom'   => 'Number of resources that lead up to this resource in maps',
        !           344:          'comefrom_list' => 'Resources that lead up to this resource in maps',
        !           345:          'clear'      => 'Material presented in clear way',
        !           346:          'depth'      => 'Material covered with sufficient depth',
        !           347:          'helpful'    => 'Material is helpful',
        !           348:          'correct'    => 'Material appears to be correct',
        !           349:          'technical'  => 'Resource is technically correct', 
        !           350:          'avetries'   => 'Average number of tries till solved',
        !           351:          'stdno'      => 'Total number of students who have worked on this problem',
        !           352:          'difficulty' => 'Degree of difficulty',
        !           353:          'disc'       => 'Degree of discrimination',
        !           354: 	 'dependencies' => 'Resources used by this resource',
        !           355:          );
        !           356: }
        !           357: 
        !           358: sub edit_meta_data {
        !           359:     my ($r,$uri) = @_;
        !           360:     # Construction Space Call
        !           361:     # Header
        !           362:     my $disuri=$uri;
        !           363:     my $fn=&Apache::lonnet::filelocation('',$uri);
        !           364:     $disuri=~s/^\/\~/\/priv\//;
        !           365:     $disuri=~s/\.meta$//;
        !           366:     my $target=$uri;
        !           367:     $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
        !           368:     $target=~s/\.meta$//;
        !           369:         $r->print('<script language="JavaScript">'.
        !           370:                   &Apache::loncommon::browser_and_searcher_javascript().
        !           371:                   '</script>');
        !           372:         my %lt=&fieldnames();
        !           373: 	my $output;
        !           374:     foreach ('author','title','subject','keywords','abstract','notes',
        !           375:              'copyright','customdistributionfile','language',
        !           376:              'standards',
        !           377:              'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
        !           378:              'obsolete','obsoletereplacement') {
        !           379:         if (defined($ENV{'form.new_'.$_})) {
        !           380:             $Apache::lonpublisher::metadatafields{$_}=
        !           381:                 $ENV{'form.new_'.$_};
        !           382:         }
        !           383:         if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
        !           384:             $Apache::lonpublisher::metadatafields{'copyright'}=
        !           385:                 'default';
        !           386:         }
        !           387:         $output.=('<p>'.$lt{$_}.': '.
        !           388:                   &prettyinput($_,
        !           389: 			   $Apache::lonpublisher::metadatafields{$_},
        !           390: 			   'new_'.$_,'defaultmeta').'</p>');
        !           391:     }
        !           392:     return $output;
        !           393: }
1.24      albertel  394: sub open_form {
                    395:     my ($r)=@_;
1.65      banghart  396:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.24      albertel  397:     $r->print('<form method="post" action="/adm/portfolio">');
                    398:     $r->print('<input type="hidden" name="action" value="'.
                    399: 	      $ENV{'form.action'}.'" />');
                    400:     $r->print('<input type="hidden" name="confirmed" value="1" />');
1.65      banghart  401:     foreach (@files) {
                    402:         $r->print('<input type="hidden" name="selectfile" value="'.
                    403: 	      $_.'" />');
                    404:     }
1.24      albertel  405:     $r->print('<input type="hidden" name="currentpath" value="'.
                    406: 	      $ENV{'form.currentpath'}.'" />');
                    407: }
                    408: 
                    409: sub close_form {
                    410:     my ($r)=@_;
                    411:     $r->print('<p><input type="submit" value="'.&mt('Continue').
                    412: 	      '" /></p></form>');
                    413:     $r->print('<form action="/adm/portfolio" method="POST">
                    414:                <p>
                    415:               <input type="hidden" name="currentpath" value="'.
                    416: 	      $ENV{'form.currentpath'}.'" />
                    417:                  <input type="submit" value="'.&mt('Cancel').'" />
                    418:                </p></form>');
                    419: 
                    420: }
                    421: 
                    422: sub display_file {
1.27      albertel  423:     my ($path,$filename)=@_;
1.65      banghart  424:     my $display_file_text;
1.27      albertel  425:     if (!defined($path)) { $path=$ENV{'form.currentpath'}; }
1.65      banghart  426:     if (!defined($filename)) { 
                    427:         $filename=$ENV{'form.selectfile'};
                    428:         $display_file_text = '<tt>'.$path.$filename.'</tt>';
                    429:     } elsif (ref($filename) eq "ARRAY") {
                    430:         foreach (@$filename) {
1.66      banghart  431:             $display_file_text .= '<tt>'.$path.$_.'</tt><br />';
1.65      banghart  432:         }
                    433:     } elsif (ref($filename) eq "SCALAR") {
                    434:         $display_file_text = '<tt>'.$path.$filename.'</tt>';        
                    435:     }
                    436:     return $display_file_text;
1.24      albertel  437: }
                    438: 
                    439: sub done {
1.25      albertel  440:     return ('<h3><a href="/adm/portfolio?currentpath='.
1.50      banghart  441: 	    $ENV{'form.currentpath'}.
                    442: 	    '&fieldname='.$ENV{'form.fieldname'}.
1.57      banghart  443: 	    '&mode='.$ENV{'form.mode'}.
1.50      banghart  444: 	    '">'.&mt('Done').'</a></h3>');
1.24      albertel  445: }
                    446: 
                    447: sub delete {
                    448:     my ($r)=@_;
1.55      banghart  449:     my @check;
                    450:     my $file_name = $ENV{'form.currentpath'}.$ENV{'form.selectfile'};
1.65      banghart  451:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.66      banghart  452: 
1.56      banghart  453:     if (&Apache::lonnet::is_locked($file_name,$ENV{'user.domain'},$ENV{'user.name'} ) eq 'true') {
1.55      banghart  454:         $r->print ("The file is locked and cannot be deleted.<br />");
                    455:         $r->print(&done());
                    456:     } else {
1.66      banghart  457:         if (scalar(@files)) {
                    458:             &open_form($r);
                    459:             $r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>');
                    460:             &close_form($r);
                    461:         } else {
                    462:             $r->print("No file was checked to delete.<br />");
                    463:             $r->print(&done());
                    464:         }
1.55      banghart  465:     }
1.24      albertel  466: } 
                    467: 
                    468: sub delete_confirmed {
                    469:     my ($r)=@_;
1.65      banghart  470:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
                    471:     my $result;
                    472:     foreach my $delete_file (@files) {
                    473:         $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
1.24      albertel  474: 					       $ENV{'user.domain'},'portfolio'.
                    475: 					       $ENV{'form.currentpath'}.
1.65      banghart  476: 					       $delete_file);
                    477:         if ($result ne 'ok') {
1.30      banghart  478: 	$r->print('<font color="red"> An error occured ('.$result.
1.65      banghart  479: 		  ') while trying to delete '.&display_file(undef, $delete_file).'</font><br />');
                    480:         }
1.24      albertel  481:     }
                    482:     $r->print(&done());
                    483: }
                    484: 
1.30      banghart  485: sub delete_dir {
                    486:     my ($r)=@_;
                    487:     &open_form($r);
                    488:     $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
                    489:     &close_form($r);
                    490: } 
                    491: 
                    492: sub delete_dir_confirmed {
                    493:     my ($r)=@_;
                    494:     my $directory_name = $ENV{'form.currentpath'};
                    495:     $directory_name =~ m/\/$/;
                    496:     $directory_name = $`;
                    497:     my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
                    498: 					       $ENV{'user.domain'},'portfolio'.
                    499: 					       $directory_name);
1.32      banghart  500: 					       
1.30      banghart  501:     if ($result ne 'ok') {
                    502: 	$r->print('<font color="red"> An error occured (dir) ('.$result.
                    503: 		  ') while trying to delete '.$directory_name.'</font><br />');
1.32      banghart  504:     } else {
1.41      banghart  505:         # now remove from recent
                    506: #        $r->print('<br /> removing '.$directory_name.'<br /');
1.42      banghart  507:         &Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']);
1.32      banghart  508:         my @dirs = split m!/!, $directory_name;
                    509:         
                    510: #        $directory_name =~ m/^(\/*\/)(\/*.)$/;
                    511:         $directory_name='/';
                    512:         for (my $i=1; $i < (@dirs - 1); $i ++){
                    513:             $directory_name .= $dirs[$i].'/';
                    514:         }
                    515:         $ENV{'form.currentpath'} = $directory_name;
1.30      banghart  516:     }
                    517:     $r->print(&done());
                    518: }
                    519: 
1.24      albertel  520: sub rename {
                    521:     my ($r)=@_;
1.64      banghart  522:     my $file_name = $ENV{'form.currentpath'}.$ENV{'form.rename'};
1.56      banghart  523:     if (&Apache::lonnet::is_locked($file_name,$ENV{'user.domain'},$ENV{'user.name'}) eq 'true') {
1.55      banghart  524:         $r->print ("The file is locked and cannot be renamed.<br />");
                    525:         $r->print(&done());
                    526:     } else {
                    527:         &open_form($r);
                    528:         $r->print('<p>'.&mt('Rename').' '.&display_file().' to 
                    529:                    <input name="filenewname" type="input" size="50" />?</p>');
                    530:         &close_form($r);
                    531:     }
1.24      albertel  532: }
                    533: 
                    534: sub rename_confirmed {
                    535:     my ($r)=@_;
1.27      albertel  536:     my $filenewname=&Apache::lonnet::clean_filename($ENV{'form.filenewname'});
                    537:     if ($filenewname eq '') {
                    538: 	$r->print('<font color="red">'.
                    539: 		  &mt("Error: no valid filename was provided to rename to.").
                    540: 		  '</font><br />');
                    541: 	$r->print(&done());
                    542: 	return;
                    543:     } 
                    544:     my $result=
                    545: 	&Apache::lonnet::renameuserfile($ENV{'user.name'},$ENV{'user.domain'},
                    546:             'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.selectfile'},
1.59      banghart  547:             'portfolio'.$ENV{'form.currentpath'}.$filenewname);
1.27      albertel  548:     if ($result ne 'ok') {
                    549: 	$r->print('<font color="red"> An errror occured ('.$result.
                    550: 		  ') while trying to rename '.&display_file().' to '.
                    551: 		  &display_file(undef,$filenewname).'</font><br />');
                    552:     }
1.66      banghart  553:     if ($filenewname ne $ENV{'form.filenewname'}) {
                    554:         $r->print("The new file name was changed from:<br /><strong>".$ENV{'form.filenewname'}."</strong> to <strong>$filenewname </strong>");
                    555:     }
1.27      albertel  556:     $r->print(&done());
                    557: }
1.47      banghart  558: sub select_files {
                    559:     my ($r)=@_;
1.60      banghart  560:     if ($ENV{'form.continue'} eq 'true') {
                    561:         # here we update the selections for the currentpath
                    562:         # eventually, have to handle removing those not checked, but . . . 
1.65      banghart  563:         my @items=&Apache::loncommon::get_env_multiple('form.selectfile');
1.60      banghart  564:         &Apache::lonnet::save_selected_files($ENV{'user.name'}, $ENV{'form.currentpath'}, @items);
1.62      banghart  565:     } else {
                    566:         if ($ENV{'form.currentpath'} eq '/') {
                    567:             #empty the file for a fresh start
                    568:             # &Apache::lonnet::clear_selected_files($ENV{'user.name'});
                    569:         }
                    570:     }
                    571:     my @files = &Apache::lonnet::files_not_in_path($ENV{'user.name'}, $ENV{'form.currentpath'});
                    572:     my $java_files = join ",", @files;
                    573:     if ($java_files) {
                    574:         $java_files.=',';
1.60      banghart  575:     }
1.63      banghart  576:     my $javascript =(<<ENDSMP);
1.48      banghart  577:         <script language='javascript'>
                    578:         function finishSelect() {
1.62      banghart  579: ENDSMP
1.63      banghart  580:     $javascript .= 'fileList = "'.$java_files.'";';
                    581:     $javascript .= (<<ENDSMP);
1.49      banghart  582:             for (i=0;i<document.forms.checkselect.length;i++) { 
                    583:                 if (document.forms.checkselect[i].checked){
1.54      banghart  584:                     fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49      banghart  585:                 }
                    586:             }
                    587:             opener.document.forms.lonhomework.
                    588: ENDSMP
1.63      banghart  589:     $javascript .= $ENV{'form.fieldname'};
                    590:     $javascript .= (<<ENDSMP);
1.49      banghart  591:         .value=fileList;
1.48      banghart  592:             self.close();
                    593:         }
                    594:         </script>
                    595: ENDSMP
1.63      banghart  596:     $r->print($javascript);
1.47      banghart  597:     $r->print("<h1>Select portfolio files</h1>
                    598:                 Check as many as you wish in response to the essay problem.<br />");
1.61      banghart  599:     $r->print("<strong>Files selected from other directories:</strong><br />");
1.60      banghart  600:     foreach (&Apache::lonnet::files_not_in_path($ENV{'user.name'}, $ENV{'form.currentpath'})) {
                    601:         $r->print($_."<br />");
                    602:     }
1.47      banghart  603: }
1.24      albertel  604: sub upload {
                    605:     my ($r)=@_;
1.33      banghart  606:     my $fname=$ENV{'form.uploaddoc.filename'};
1.38      banghart  607:     my $filesize = (length($ENV{'form.uploaddoc'})) / 1000; #express in k (1024?)
                    608:     my $disk_quota = 20000; # expressed in k
1.34      banghart  609:     $fname=&Apache::lonnet::clean_filename($fname);
                    610:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
1.33      banghart  611: 						 $ENV{'user.name'}).
                    612: 						'/userfiles/portfolio';
1.38      banghart  613:     # Fixme --- Move the checking for existing file to LOND error return
1.34      banghart  614:     my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
                    615: 					  $ENV{'user.domain'},
                    616: 					  $ENV{'user.name'},$portfolio_root);
                    617:     my $found_file = 0;
1.33      banghart  618:     foreach my $line (@dir_list) {
1.34      banghart  619:         my ($filename)=split(/\&/,$line,2);
1.33      banghart  620:         if ($filename eq $fname){
                    621:             $found_file = 1;
                    622:         }
                    623:     }
1.38      banghart  624:     my $current_disk_usage = &Apache::lonnet::diskusage($ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root);
1.69      banghart  625:     if ((($current_disk_usage/1000) + $filesize) > $disk_quota){
1.38      banghart  626:         $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes</strong>. Disk quota will be exceeded.'.
                    627:                   '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
                    628:     } 
                    629:     elsif ($found_file){   
1.33      banghart  630:         $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$ENV{'form.currentpath'}.'</strong></font>'.
                    631:                   '<br />To upload, rename or delete existing '.$fname.' in '.$ENV{'form.currentpath'});
                    632:     } else {
                    633:         my $result=&Apache::lonnet::userfileupload('uploaddoc','',
                    634: 	        	 'portfolio'.$ENV{'form.currentpath'});
                    635:         if ($result !~ m|^/uploaded/|) {
1.34      banghart  636:             $r->print('<font color="red"> An errror occured ('.$result.
                    637: 	              ') while trying to upload '.&display_file().'</font><br />');
1.33      banghart  638:         }
1.25      albertel  639:     }
                    640:     $r->print(&done());
                    641: }
                    642: 
                    643: sub createdir {
                    644:     my ($r)=@_;
1.28      albertel  645:     my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'});
                    646:     if ($newdir eq '') {
1.37      banghart  647:     	$r->print('<font color="red">'.
                    648: 	    	  &mt("Error: no directory name was provided.").
                    649: 		      '</font><br />');
                    650: 	    $r->print(&done());
                    651: 	    return;
1.28      albertel  652:     } 
1.37      banghart  653:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
                    654: 						 $ENV{'user.name'}).
                    655: 						'/userfiles/portfolio';
                    656:     my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
                    657: 					  $ENV{'user.domain'},
                    658: 					  $ENV{'user.name'},$portfolio_root);
                    659:     my $found_file = 0;
                    660:     foreach my $line (@dir_list) {
                    661:         my ($filename)=split(/\&/,$line,2);
                    662:         if ($filename eq $newdir){
                    663:             $found_file = 1;
                    664:         }
                    665:     }
                    666:     if ($found_file){
                    667:     	    $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
                    668:     	            ' </strong>a file or directory by that name already exists.</font><br />');
                    669:     } else {
                    670:         my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'},
                    671: 	         $ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir);
                    672:         if ($result ne 'ok') {
                    673:     	    $r->print('<font color="red"> An errror occured ('.$result.
                    674: 	    	      ') while trying to create a new directory '.&display_file().'</font><br />');
                    675:         }
1.24      albertel  676:     }
1.67      banghart  677:     if ($newdir ne $ENV{'form.newdir'}) {
                    678:         $r->print("The new directory name was changed from:<br /><strong>".$ENV{'form.newdir'}."</strong> to <strong>$newdir </strong>");  
                    679:     }
1.24      albertel  680:     $r->print(&done());
                    681: }
                    682: 
                    683: sub handler {
                    684:     # this handles file management
                    685:     my $r = shift;
1.47      banghart  686:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
1.33      banghart  687: 							 $ENV{'user.name'}).
                    688: 							'/userfiles/portfolio';
1.24      albertel  689:     &Apache::loncommon::no_cache($r);
                    690:     &Apache::loncommon::content_type($r,'text/html');
                    691:     $r->send_http_header;
                    692:     # Give the LON-CAPA page header
                    693:     $r->print('<html><head><title>'.
                    694:               &mt('Portfolio Manager').
                    695:               "</title></head>\n".
                    696:               &Apache::loncommon::bodytag('Portfolio Manager'));
                    697:     $r->rflush();
                    698:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.70      banghart  699:                                             ['selectfile','currentpath','meta',
1.64      banghart  700: 					     'currentfile','action','fieldname','mode','rename']);
1.40      banghart  701: 	if (($ENV{'form.storeupl'} eq 'Upload') & (!$ENV{'form.uploaddoc.filename'})){
                    702:    	    $r->print('<font color="red"> No file was selected to upload.'.
                    703:    	            'To upload a file, click <strong>Browse...</strong>'.
                    704:    	            ', select a file, then click <strong>Upload</strong>,</font>');
                    705: 	}
1.70      banghart  706:     if ($ENV{'form.meta'}) {
                    707:         &open_form($r);
1.71    ! banghart  708:         $r->print(&edit_meta_data($r, $ENV{'form.currentpath'}.$ENV{'form.selectfile'}));
1.70      banghart  709:         $r->print('Edit the meta data<br />');
                    710:         &close_form($r);
                    711:     }
                    712:     if ($ENV{'form.store'}) {
                    713:     }
                    714: 
1.24      albertel  715:     if ($ENV{'form.uploaddoc.filename'}) {
                    716: 	&upload($r);
1.27      albertel  717:     } elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) {
                    718: 	&delete_confirmed($r);
1.24      albertel  719:     } elsif ($ENV{'form.action'} eq 'delete') {
1.27      albertel  720: 	&delete($r);
1.30      banghart  721:     } elsif ($ENV{'form.action'} eq 'deletedir' && $ENV{'form.confirmed'}) {
1.31      albertel  722: 	&delete_dir_confirmed($r);
1.30      banghart  723:     } elsif ($ENV{'form.action'} eq 'deletedir'){
1.31      albertel  724: 	&delete_dir($r);
1.27      albertel  725:     } elsif ($ENV{'form.action'} eq 'rename' && $ENV{'form.confirmed'}) {
                    726: 	&rename_confirmed($r);
1.64      banghart  727:     } elsif ($ENV{'form.rename'}) {
                    728:         $ENV{'form.selectfile'} = $ENV{'form.rename'};
                    729:         $ENV{'form.action'} = 'rename';
1.24      albertel  730: 	&rename($r);
1.25      albertel  731:     } elsif ($ENV{'form.createdir'}) {
                    732: 	&createdir($r);
1.24      albertel  733:     } else {
                    734: 	my $current_path='/';
                    735: 	if ($ENV{'form.currentpath'}) {
                    736: 	    $current_path = $ENV{'form.currentpath'};
                    737: 	}
1.43      banghart  738: 	my @dir_list=&Apache::lonnet::dirlist($current_path,
1.27      albertel  739: 					    $ENV{'user.domain'},
                    740: 					    $ENV{'user.name'},$portfolio_root);
1.46      albertel  741: 	if ($dir_list[0] eq 'no_such_dir'){
                    742: 	    # two main reasons for this:
                    743:             #    1) never been here, so directory structure not created
                    744: 	    #    2) back-button navigation after deleting a directory
                    745: 	    if ($current_path eq '/'){
1.43      banghart  746: 	        &Apache::lonnet::mkdiruserfile($ENV{'user.name'},
1.46      albertel  747: 					       $ENV{'user.domain'},'portfolio');
                    748: 	    } else {
                    749:                 # some directory that snuck in get rid of the directory
                    750:                 # from the recent pulldown, just in case
                    751: 		&Apache::lonhtmlcommon::remove_recent('portfolio',
                    752: 						      [$current_path]);
                    753: 		$current_path = '/'; # force it back to the root        
                    754: 	    }
                    755: 	    # now grab the directory list again, for the first time
                    756: 	    @dir_list=&Apache::lonnet::dirlist($current_path,
                    757: 					    $ENV{'user.domain'},
                    758: 					    $ENV{'user.name'},$portfolio_root);
1.43      banghart  759:         }
1.46      albertel  760: 	# need to know if directory is empty so it can be removed if desired
                    761: 	my $is_empty=(@dir_list == 2);
1.48      banghart  762: 	&display_common($r,$current_path,$is_empty,\@dir_list);
1.51      matthew   763: 	if ($ENV{"form.mode"} eq 'selectfile'){
1.50      banghart  764: 	    &select_files($r);
                    765:             &display_file_select($r,$current_path,$is_empty,\@dir_list);
                    766: 	} else {
                    767: 	    &display_directory($r,$current_path,$is_empty,\@dir_list);
                    768: 	}
1.46      albertel  769: 	$r->print("</body>\n</html>\n");
                    770: 	return OK;
1.30      banghart  771:     }
1.2       banghart  772: }
1.1       banghart  773: 1;
                    774: __END__

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