![]() ![]() | ![]() |
- BUG#4292, quota calculation was incorrect
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: 24: package Apache::portfolio; 25: use strict; 26: use Apache::Constants qw(:common :http); 27: use Apache::loncommon; 28: use Apache::lonnet; 29: use Apache::lontexconvert; 30: use Apache::lonfeedback; 31: use Apache::lonlocal; 32: use Apache::lonnet; 33: 34: # receives a file name and path stub from username/userfiles/portfolio/ 35: # returns an anchor tag consisting encoding filename and currentpath 36: sub make_anchor { 37: my ($filename, $current_path, $current_mode, $field_name, $continue_select) = @_; 38: if ($continue_select ne 'true') {$continue_select = 'false'}; 39: my $anchor = '<a href="/adm/portfolio?selectfile='.$filename.'¤tpath='.$current_path.'&mode='.$current_mode.'&continue='.$continue_select.'&fieldname='.$field_name.'">'.$filename.'</a>'; 40: return $anchor; 41: } 42: my $dirptr=16384; 43: sub display_common { 44: my ($r,$current_path,$is_empty,$dir_list)=@_; 45: my $iconpath= $r->dir_config('lonIconsURL') . "/"; 46: $r->print('<table border="0" cellspacing="2" cellpadding="2"><tr valign="middle">'); 47: $r->print('<td bgcolor="#ccddaa" align="center">'); 48: my $displayOut = '<form method="post" enctype="multipart/form-data">'; 49: $displayOut .= '<input name="uploaddoc" type="file" />'. 50: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'. 51: '<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'. 52: '<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'. 53: '<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'. 54: '<input type="submit" name="storeupl" value="Upload" />'. 55: '</form>'; 56: $r->print($displayOut); 57: $r->print('</td></tr><tr><td bgcolor="#ccddaa" align="center">'); 58: $displayOut = '<form method="post">'; 59: $displayOut .= '<input name="newdir" type="input" />'. 60: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'. 61: '<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'. 62: '<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'. 63: '<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'. 64: '<input type="submit" name="createdir" value="'.&mt("Create Directory").'" />'. 65: '</form>'; 66: $r->print($displayOut); 67: $r->print('</td></tr></table>'); 68: my @tree = split (/\//,$current_path); 69: $r->print('<font size="+2">'.&make_anchor('portfolio','/',$env{"form.mode"},$env{"form.fieldname"},$env{"form.continue"}).'/'); 70: if (@tree > 1){ 71: my $newCurrentPath = ''; 72: for (my $i = 1; $i< @tree; $i++){ 73: $newCurrentPath .= $tree[$i].'/'; 74: $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath, $env{"form.mode"},$env{"form.fieldname"}, $env{"form.continue"}).'/'); 75: } 76: } 77: $r->print('</font>'); 78: &Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path); 79: $r->print('<br /><form method=post action="/adm/portfolio?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"}.'">'. 80: &Apache::lonhtmlcommon::select_recent('portfolio','currentpath', 81: 'this.form.submit();')); 82: $r->print("</form>"); 83: } 84: sub display_directory { 85: my ($r,$current_path,$is_empty,$dir_list)=@_; 86: my $iconpath= $r->dir_config('lonIconsURL') . "/"; 87: my $display_out; 88: my $select_mode; 89: my $checked_files; 90: my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash ($env{'user.domain'},$env{'user.name'}); 91: if ($env{"form.mode"} eq 'selectfile'){ 92: &select_files($r); 93: $checked_files =&Apache::lonnet::files_in_path($env{'user.name'},$env{'form.currentpath'}); 94: $select_mode = 'true'; 95: } 96: if ($is_empty && ($current_path ne '/')) { 97: $display_out = '<form method="post" action="/adm/portfolio">'. 98: '<input type="hidden" name="action" value="deletedir" />'. 99: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'. 100: '<input type="hidden" name="selectfile" value="" />'. 101: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'. 102: '</form>'; 103: 104: $r->print($display_out); 105: return; 106: } 107: if ($select_mode eq 'true') { 108: $r->print('<table border="0" cellspacing="2" cellpadding="2">'. 109: '<tr><th>Select</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>'); 110: $r->print('<form method="post" name="checkselect" action="/adm/portfolio">'); 111: } else { 112: $r->print('<table border="0" cellspacing="2" cellpadding="2">'. 113: '<tr><th colspan="2">Actions</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>'); 114: $r->print('<form method="post" action="/adm/portfolio">'); 115: } 116: my $href_location="/uploaded/$env{'user.domain'}/$env{'user.name'}/portfolio$current_path"; 117: my $href_edit_location="/editupload/$env{'user.domain'}/$env{'user.name'}/portfolio$current_path"; 118: foreach my $line (sort 119: { 120: my ($afile)=split('&',$a,2); 121: my ($bfile)=split('&',$b,2); 122: return (lc($afile) cmp lc($bfile)); 123: } (@$dir_list)) { 124: #$strip holds directory/file name 125: #$dom 126: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 127: $filename =~ s/\s+$//; 128: if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(.*)\.(.*)/)) { 129: if ($dirptr&$testdir) { 130: if ($select_mode eq 'true'){ 131: $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>'); 132: } else { 133: $r->print('<tr bgcolor="#FFAA99"><td colspan="2"><img src="'.$iconpath.'folder_closed.gif"></td>'); 134: } 135: $r->print('<td>Go to ...</td>'); 136: $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/',$env{'form.mode'},$env{"form.fieldname"},$env{'form.continue'}).'</td>'); 137: $r->print('</tr>'); 138: } else { 139: $r->print('<tr bgcolor="#CCCCFF">'); 140: if ($select_mode eq 'true'){ 141: $r->print('<td><input type="checkbox" name="checkfile" value="'.$filename.'"'); 142: if ($$checked_files{$filename} eq 'selected') { 143: $r->print("CHECKED"); 144: } 145: $r->print('></td>'); 146: } else { 147: if (exists $locked_files{$current_path.$filename}){ 148: $r->print('<td colspan="2"><a href="portfolio?lockinfo='.$current_path.$filename.'">Locked</a></td>'); 149: } else { 150: $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'" /> 151: <a href="/adm/portfolio?rename='.$filename.'&currentpath='.$current_path.'">Rename</a></td> 152: <td><a href="'.$href_edit_location.$filename.'.meta">Meta</a> 153: </td>'); 154: } 155: } 156: $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>'); 157: $r->print('<td><a href="'.$href_location.$filename.'">'. 158: $filename.'</a></td>'); 159: $r->print('<td>'.$size.'</td>'); 160: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>'); 161: $r->print('</tr>'); 162: } 163: } 164: } 165: if ($select_mode eq 'true') { 166: $r->print('</table> 167: <input type="hidden" name="continue" value="true"> 168: <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'"> 169: <input type="hidden" name="mode" value="selectfile"> 170: <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br /> 171: <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" /> 172: <input type="hidden" name="currentpath" value="'.$current_path.'" /> 173: </form>'); 174: } else { 175: $r->print('</table> 176: <input type="submit" name="doit" value="Delete Checked Files" /> 177: <input type="hidden" name="action" value="delete" /> 178: <input type="hidden" name="currentpath" value="'.$current_path.'" /> 179: </form>'); 180: } 181: } 182: 183: sub open_form { 184: my ($r)=@_; 185: my @files=&Apache::loncommon::get_env_multiple('form.selectfile'); 186: $r->print('<form method="post" action="/adm/portfolio">'); 187: $r->print('<input type="hidden" name="action" value="'. 188: $env{'form.action'}.'" />'); 189: $r->print('<input type="hidden" name="confirmed" value="1" />'); 190: foreach (@files) { 191: $r->print('<input type="hidden" name="selectfile" value="'. 192: $_.'" />'); 193: } 194: $r->print('<input type="hidden" name="currentpath" value="'. 195: $env{'form.currentpath'}.'" />'); 196: } 197: 198: sub close_form { 199: my ($r)=@_; 200: $r->print('<p><input type="submit" value="'.&mt('Continue'). 201: '" /></p></form>'); 202: $r->print('<form action="/adm/portfolio" method="POST"> 203: <p> 204: <input type="hidden" name="currentpath" value="'. 205: $env{'form.currentpath'}.'" /> 206: <input type="submit" value="'.&mt('Cancel').'" /> 207: </p></form>'); 208: 209: } 210: 211: sub display_file { 212: my ($path,$filename)=@_; 213: my $display_file_text; 214: if (!defined($path)) { $path=$env{'form.currentpath'}; } 215: if (!defined($filename)) { 216: $filename=$env{'form.selectfile'}; 217: $display_file_text = '<tt>'.$path.$filename.'</tt>'; 218: } elsif (ref($filename) eq "ARRAY") { 219: foreach (@$filename) { 220: $display_file_text .= '<tt>'.$path.$_.'</tt><br />'; 221: } 222: } elsif (ref($filename) eq "SCALAR") { 223: $display_file_text = '<tt>'.$path.$filename.'</tt>'; 224: } 225: return $display_file_text; 226: } 227: 228: sub done { 229: my ($message)=@_; 230: unless (defined $message) { 231: $message='Done'; 232: } 233: return ('<h3><a href="/adm/portfolio?currentpath='. 234: $env{'form.currentpath'}. 235: '&fieldname='.$env{'form.fieldname'}. 236: '&mode='.$env{'form.mode'}. 237: '">'.&mt($message).'</a></h3>'); 238: } 239: 240: sub delete { 241: my ($r)=@_; 242: my @check; 243: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'}; 244: my @files=&Apache::loncommon::get_env_multiple('form.selectfile'); 245: 246: if (&Apache::lonnet::is_locked($file_name,$env{'user.domain'},$env{'user.name'} ) eq 'true') { 247: $r->print ("The file is locked and cannot be deleted.<br />"); 248: $r->print(&done('Back')); 249: } else { 250: if (scalar(@files)) { 251: &open_form($r); 252: $r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>'); 253: &close_form($r); 254: } else { 255: $r->print("No file was checked to delete.<br />"); 256: $r->print(&done()); 257: } 258: } 259: } 260: 261: sub delete_confirmed { 262: my ($r)=@_; 263: my @files=&Apache::loncommon::get_env_multiple('form.selectfile'); 264: my $result; 265: foreach my $delete_file (@files) { 266: $result=&Apache::lonnet::removeuserfile($env{'user.name'}, 267: $env{'user.domain'},'portfolio'. 268: $env{'form.currentpath'}. 269: $delete_file); 270: if ($result ne 'ok') { 271: $r->print('<font color="red"> An error occured ('.$result. 272: ') while trying to delete '.&display_file(undef, $delete_file).'</font><br />'); 273: } 274: } 275: $r->print(&done()); 276: } 277: 278: sub delete_dir { 279: my ($r)=@_; 280: &open_form($r); 281: $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>'); 282: &close_form($r); 283: } 284: 285: sub delete_dir_confirmed { 286: my ($r)=@_; 287: my $directory_name = $env{'form.currentpath'}; 288: $directory_name =~ s|/$||; # remove any trailing slash 289: my $result=&Apache::lonnet::removeuserfile($env{'user.name'}, 290: $env{'user.domain'},'portfolio'. 291: $directory_name); 292: 293: if ($result ne 'ok') { 294: $r->print('<font color="red"> An error occured (dir) ('.$result. 295: ') while trying to delete '.$directory_name.'</font><br />'); 296: } else { 297: # now remove from recent 298: # $r->print('<br /> removing '.$directory_name.'<br /'); 299: &Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']); 300: my @dirs = split m!/!, $directory_name; 301: 302: # $directory_name =~ m/^(\/*\/)(\/*.)$/; 303: $directory_name='/'; 304: for (my $i=1; $i < (@dirs - 1); $i ++){ 305: $directory_name .= $dirs[$i].'/'; 306: } 307: $env{'form.currentpath'} = $directory_name; 308: } 309: $r->print(&done()); 310: } 311: 312: sub rename { 313: my ($r)=@_; 314: my $file_name = $env{'form.currentpath'}.$env{'form.rename'}; 315: if (&Apache::lonnet::is_locked($file_name,$env{'user.domain'},$env{'user.name'}) eq 'true') { 316: $r->print ("The file is locked and cannot be renamed.<br />"); 317: $r->print(&done()); 318: } else { 319: &open_form($r); 320: $r->print('<p>'.&mt('Rename').' '.&display_file().' to 321: <input name="filenewname" type="input" size="50" />?</p>'); 322: &close_form($r); 323: } 324: } 325: 326: sub rename_confirmed { 327: my ($r)=@_; 328: my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'}); 329: if ($filenewname eq '') { 330: $r->print('<font color="red">'. 331: &mt("Error: no valid filename was provided to rename to."). 332: '</font><br />'); 333: $r->print(&done()); 334: return; 335: } 336: my $result= 337: &Apache::lonnet::renameuserfile($env{'user.name'},$env{'user.domain'}, 338: 'portfolio'.$env{'form.currentpath'}.$env{'form.selectfile'}, 339: 'portfolio'.$env{'form.currentpath'}.$filenewname); 340: if ($result ne 'ok') { 341: $r->print('<font color="red"> An errror occured ('.$result. 342: ') while trying to rename '.&display_file().' to '. 343: &display_file(undef,$filenewname).'</font><br />'); 344: } 345: if ($filenewname ne $env{'form.filenewname'}) { 346: $r->print("The new file name was changed from:<br /><strong>".$env{'form.filenewname'}."</strong> to <strong>$filenewname </strong>"); 347: } 348: $r->print(&done()); 349: } 350: sub select_files { 351: my ($r)=@_; 352: if ($env{'form.continue'} eq 'true') { 353: # here we update the selections for the currentpath 354: # eventually, have to handle removing those not checked, but . . . 355: my @items=&Apache::loncommon::get_env_multiple('form.checkfile'); 356: if (scalar(@items)){ 357: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items); 358: } 359: } else { 360: #empty the file for a fresh start 361: &Apache::lonnet::clear_selected_files($env{'user.name'}); 362: } 363: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'}); 364: my $java_files = join ",", @files; 365: if ($java_files) { 366: $java_files.=','; 367: } 368: my $javascript =(<<ENDSMP); 369: <script language='javascript'> 370: function finishSelect() { 371: ENDSMP 372: $javascript .= 'fileList = "'.$java_files.'";'; 373: $javascript .= (<<ENDSMP); 374: for (i=0;i<document.forms.checkselect.length;i++) { 375: if (document.forms.checkselect[i].checked){ 376: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ; 377: } 378: } 379: opener.document.forms.lonhomework. 380: ENDSMP 381: $javascript .= $env{'form.fieldname'}; 382: $javascript .= (<<ENDSMP); 383: .value=fileList; 384: self.close(); 385: } 386: </script> 387: ENDSMP 388: $r->print($javascript); 389: $r->print("<h1>Select portfolio files</h1> 390: Check as many as you wish in response to the essay problem.<br />"); 391: $r->print("<strong>Files selected from other directories:</strong><br />"); 392: foreach (&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'})) { 393: $r->print($_."<br />"); 394: } 395: } 396: sub upload { 397: my ($r)=@_; 398: my $fname=$env{'form.uploaddoc.filename'}; 399: my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?) 400: my $disk_quota = 20000; # expressed in k 401: $fname=&Apache::lonnet::clean_filename($fname); 402: my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'}, 403: $env{'user.name'}). 404: '/userfiles/portfolio'; 405: # Fixme --- Move the checking for existing file to LOND error return 406: my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'}, 407: $env{'user.domain'}, 408: $env{'user.name'},$portfolio_root); 409: my $found_file = 0; 410: my $locked_file = 0; 411: foreach my $line (@dir_list) { 412: my ($file_name)=split(/\&/,$line,2); 413: if ($file_name eq $fname){ 414: $found_file = 1; 415: if (&Apache::lonnet::is_locked($env{'form.currentpath'}.$file_name,$env{'user.domain'},$env{'user.name'} ) eq 'true') { 416: $locked_file = 1; 417: } 418: } 419: } 420: my $current_disk_usage = &Apache::lonnet::diskusage($env{'user.domain'}, $env{'user.name'},$portfolio_root); 421: if ((($current_disk_usage) + $filesize/1000) > $disk_quota){ 422: $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.'. 423: '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.'); 424: $r->print(&done('Back')); 425: } 426: elsif ($found_file){ 427: if ($locked_file){ 428: $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>portfolio'.$env{'form.currentpath'}.'</strong></font>'. 429: '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.'); 430: $r->print(&done('Back')); 431: } else { 432: $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>portfolio'.$env{'form.currentpath'}.'</strong></font>'. 433: '<br />To upload, rename or delete existing '.$fname.' in portfolio'.$env{'form.currentpath'}); 434: $r->print(&done('Back')); 435: } 436: } else { 437: my $result=&Apache::lonnet::userfileupload('uploaddoc','', 438: 'portfolio'.$env{'form.currentpath'}); 439: if ($result !~ m|^/uploaded/|) { 440: $r->print('<font color="red"> An errror occured ('.$result. 441: ') while trying to upload '.&display_file().'</font><br />'); 442: $r->print(&done('Back')); 443: } else { 444: $r->print(&done()); 445: } 446: } 447: } 448: sub lock_info { 449: my ($r) = @_; 450: my %current_permissions = &Apache::lonnet::dump('file_permissions',$env{'user.domain'},$env{'user.name'}); 451: my $file_name = $env{'form.lockinfo'}; 452: foreach my $key(keys(%current_permissions)) { 453: if ($file_name eq $key) { 454: foreach my $array_item (@{$current_permissions{$key}}) { 455: if (ref($array_item)) { 456: $r->print('<strong>'.$key.'</strong> was submitted in response to problem: <strong>'. 457: &Apache::lonnet::gettitle($$array_item[0]).'</strong><br />'); 458: my %course_description = &Apache::lonnet::coursedescription($$array_item[1]); 459: $r->print('In the course: <strong>'.$course_description{'description'}.'</strong><br />'); 460: # $r->print('the third is '.$$array_item[2].'<br>'); 461: # $r->print("item is $$array_item[0]<br> and $$array_item[0]"); 462: } 463: } 464: } 465: } 466: $r->print(&done('Back')); 467: return 'ok'; 468: } 469: sub createdir { 470: my ($r)=@_; 471: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'}); 472: if ($newdir eq '') { 473: $r->print('<font color="red">'. 474: &mt("Error: no directory name was provided."). 475: '</font><br />'); 476: $r->print(&done()); 477: return; 478: } 479: my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'}, 480: $env{'user.name'}). 481: '/userfiles/portfolio'; 482: my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'}, 483: $env{'user.domain'}, 484: $env{'user.name'},$portfolio_root); 485: my $found_file = 0; 486: foreach my $line (@dir_list) { 487: my ($filename)=split(/\&/,$line,2); 488: if ($filename eq $newdir){ 489: $found_file = 1; 490: } 491: } 492: if ($found_file){ 493: $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir. 494: ' </strong>a file or directory by that name already exists.</font><br />'); 495: } else { 496: my $result=&Apache::lonnet::mkdiruserfile($env{'user.name'}, 497: $env{'user.domain'},'portfolio'.$env{'form.currentpath'}.$newdir); 498: if ($result ne 'ok') { 499: $r->print('<font color="red"> An errror occured ('.$result. 500: ') while trying to create a new directory '.&display_file().'</font><br />'); 501: } 502: } 503: if ($newdir ne $env{'form.newdir'}) { 504: $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>"); 505: } 506: $r->print(&done()); 507: } 508: 509: sub handler { 510: # this handles file management 511: my $r = shift; 512: my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'}, 513: $env{'user.name'}). 514: '/userfiles/portfolio'; 515: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, 516: ['selectfile','currentpath','meta','lockinfo', 517: 'currentfile','action','fieldname','mode','rename','continue']); 518: &Apache::loncommon::no_cache($r); 519: &Apache::loncommon::content_type($r,'text/html'); 520: $r->send_http_header; 521: # Give the LON-CAPA page header 522: my $html=&Apache::lonxml::xmlbegin(); 523: $r->print($html.'<head><title>'. 524: &mt('Portfolio Manager'). 525: "</title></head>\n"); 526: if ($env{"form.mode"} eq 'selectfile'){ 527: $r->print(&Apache::loncommon::bodytag('Portfolio Manager',undef,undef,1)); 528: } else { 529: $r->print(&Apache::loncommon::bodytag('Portfolio Manager')); 530: } 531: $r->rflush(); 532: if (($env{'form.storeupl'} eq 'Upload') & (!$env{'form.uploaddoc.filename'})){ 533: $r->print('<font color="red"> No file was selected to upload.'. 534: 'To upload a file, click <strong>Browse...</strong>'. 535: ', select a file, then click <strong>Upload</strong>,</font>'); 536: } 537: if ($env{'form.meta'}) { 538: &open_form($r); 539: # $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'})); 540: $r->print('Edit the meta data<br />'); 541: &close_form($r); 542: } 543: if ($env{'form.store'}) { 544: } 545: 546: if ($env{'form.uploaddoc.filename'}) { 547: &upload($r); 548: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) { 549: &delete_confirmed($r); 550: } elsif ($env{'form.action'} eq 'delete') { 551: &delete($r); 552: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) { 553: &delete_dir_confirmed($r); 554: } elsif ($env{'form.action'} eq 'deletedir'){ 555: &delete_dir($r); 556: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) { 557: &rename_confirmed($r); 558: } elsif ($env{'form.rename'}) { 559: $env{'form.selectfile'} = $env{'form.rename'}; 560: $env{'form.action'} = 'rename'; 561: &rename($r); 562: } elsif ($env{'form.createdir'}) { 563: &createdir($r); 564: } elsif ($env{'form.lockinfo'}) { 565: &lock_info($r); 566: } else { 567: my $current_path='/'; 568: if ($env{'form.currentpath'}) { 569: $current_path = $env{'form.currentpath'}; 570: } 571: my @dir_list=&Apache::lonnet::dirlist($current_path, 572: $env{'user.domain'}, 573: $env{'user.name'},$portfolio_root); 574: if ($dir_list[0] eq 'no_such_dir'){ 575: # two main reasons for this: 576: # 1) never been here, so directory structure not created 577: # 2) back-button navigation after deleting a directory 578: if ($current_path eq '/'){ 579: &Apache::lonnet::mkdiruserfile($env{'user.name'}, 580: $env{'user.domain'},'portfolio'); 581: } else { 582: # some directory that snuck in get rid of the directory 583: # from the recent pulldown, just in case 584: &Apache::lonhtmlcommon::remove_recent('portfolio', 585: [$current_path]); 586: $current_path = '/'; # force it back to the root 587: } 588: # now grab the directory list again, for the first time 589: @dir_list=&Apache::lonnet::dirlist($current_path, 590: $env{'user.domain'}, 591: $env{'user.name'},$portfolio_root); 592: } 593: # need to know if directory is empty so it can be removed if desired 594: my $is_empty=(@dir_list == 2); 595: &display_common($r,$current_path,$is_empty,\@dir_list); 596: &display_directory($r,$current_path,$is_empty,\@dir_list); 597: $r->print("</body>\n</html>\n"); 598: return OK; 599: } 600: } 601: 1; 602: __END__