![]() ![]() | ![]() |
Use new folder icon Credits: Juliane Wenzel
1: # The LearningOnline Network with CAPA 2: # Construction Space Directory Lister 3: # 4: # $Id: lonpubdir.pm,v 1.123 2009/07/14 12:27:57 bisitz Exp $ 5: # 6: # Copyright Michigan State University Board of Trustees 7: # 8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA). 9: # 10: # LON-CAPA is free software; you can redistribute it and/or modify 11: # it under the terms of the GNU General Public License as published by 12: # the Free Software Foundation; either version 2 of the License, or 13: # (at your option) any later version. 14: # 15: # LON-CAPA is distributed in the hope that it will be useful, 16: # but WITHOUT ANY WARRANTY; without even the implied warranty of 17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18: # GNU General Public License for more details. 19: # 20: # You should have received a copy of the GNU General Public License 21: # along with LON-CAPA; if not, write to the Free Software 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23: # 24: # /home/httpd/html/adm/gpl.txt 25: # 26: # http://www.lon-capa.org/ 27: # 28: ### 29: 30: package Apache::lonpubdir; 31: 32: use strict; 33: use Apache::File; 34: use File::Copy; 35: use Apache::Constants qw(:common :http :methods); 36: use Apache::loncacc; 37: use Apache::loncommon(); 38: use Apache::lonhtmlcommon(); 39: use Apache::londiff(); 40: use Apache::lonlocal; 41: use Apache::lonmsg; 42: use Apache::lonmenu; 43: use Apache::lonnet; 44: use LONCAPA; 45: 46: sub handler { 47: 48: my $r=shift; 49: 50: my $fn; 51: 52: 53: 54: $fn = getEffectiveUrl($r); 55: 56: # Validate access to the construction space and get username@domain. 57: 58: my $uname; 59: my $udom; 60: 61: ($uname,$udom)= 62: &Apache::loncacc::constructaccess( 63: $fn,$r->dir_config('lonDefDomain')); 64: unless (($uname) && ($udom)) { 65: $r->log_reason($uname.':'.$udom. 66: ' trying to list directory '.$env{'form.filename'}. 67: ' ('.$fn.') - not authorized', 68: $r->filename); 69: return HTTP_NOT_ACCEPTABLE; 70: } 71: 72: # Remove trailing / from directory name. 73: 74: $fn=~s/\/$//; 75: 76: unless ($fn) { 77: $r->log_reason($env{'user.name'}.':'.$env{'user.domain'}. 78: ' trying to list empty directory', $r->filename); 79: return HTTP_NOT_FOUND; 80: } 81: 82: # ----------------------------------------------------------- Start page output 83: 84: my $thisdisfn=$fn; 85: $thisdisfn=~s/^\/home\/$uname\/public_html//; # subdirectory part of 86: # construction space. 87: my $docroot=$r->dir_config('lonDocRoot'); # Apache londocument root. 88: 89: my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn; # Resource directory 90: my $targetdir=$udom.'/'.$uname.$thisdisfn; # Publiction target directory. 91: my $linkdir='/priv/'.$uname.$thisdisfn; # Full URL name of constr space. 92: 93: my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom); 94: 95: &startpage($r, $uname, $udom, $thisdisfn); # Put out the start of page. 96: if ($env{'environment.remote'} eq 'off') { 97: &dircontrols($r,$uname,$udom,$thisdisfn); # Put out actions for directory, 98: # browse/upload + new file page. 99: } else { 100: &pubbuttons($r,$uname,$thisdisfn); 101: } 102: &resourceactions($r,$uname,$udom,$thisdisfn); #Put out form used for printing/deletion etc. 103: 104: my $numdir = 0; 105: my $numres = 0; 106: 107: # Start off the directory table. 108: $r->print(&Apache::loncommon::start_data_table() 109: .&Apache::loncommon::start_data_table_header_row() 110: .'<th>'.&mt('Type').'</th>' 111: .'<th>'.&mt('Actions').'</th>' 112: .'<th>'.&mt('Name').'</th>' 113: .'<th>'.&mt('Title').'</th>' 114: .'<th colspan="2">'.&mt('Status').'</th>' 115: .'<th>'.&mt('Last Modified').'</th>' 116: .&Apache::loncommon::end_data_table_header_row() 117: ); 118: 119: my $filename; 120: my $dirptr=16384; # Mask indicating a directory in stat.cmode. 121: 122: opendir(DIR,$fn); 123: my @files=sort {uc($a) cmp uc($b)} (readdir(DIR)); 124: foreach my $filename (@files) { 125: my ($cdev,$cino,$cmode,$cnlink, 126: $cuid,$cgid,$crdev,$csize, 127: $catime,$cmtime,$cctime, 128: $cblksize,$cblocks)=stat($fn.'/'.$filename); 129: 130: my $extension=''; 131: if ($filename=~/\.(\w+)$/) { $extension=$1; } 132: if ($cmode&$dirptr) { 133: putdirectory($r, $thisdisfn, $linkdir, $filename, $cmtime,$targetdir,\%bombs,\$numdir); 134: } elsif (&Apache::loncommon::fileembstyle($extension) ne 'hdn') { 135: putresource($r, $udom, $uname, $filename, $thisdisfn, $resdir, 136: $targetdir, $linkdir, $cmtime,\%bombs,\$numres); 137: } else { 138: # "hidden" extension and not a directory, so hide it away. 139: } 140: } 141: closedir(DIR); 142: 143: $r->print(&Apache::loncommon::end_data_table() 144: .&Apache::loncommon::end_page() 145: ); 146: return OK; 147: } 148: # 149: # Gets the effective URL of the request and returns it: 150: # $effn = getEffectiveUrl($r); 151: # $r - The Apache Request object. 152: sub getEffectiveUrl { 153: my $r = shift; 154: my $fn; 155: 156: if ($env{'form.filename'}) { # If a form filename is defined. 157: $fn=$env{'form.filename'}; 158: # 159: # Replace the ~username of the URL with /home/username/public_html 160: # so that we don't have to worry about ~ expansion internally. 161: # 162: $fn=~s/^https?\:\/\/[^\/]+\///; 163: $fn=~s/^\///; 164: $fn=~s{~($LONCAPA::username_re)}{/home/$1/public_html}; 165: 166: # Remove trailing / strings (?) 167: 168: $fn=~s/\/[^\/]+$//; 169: } else { 170: # If no form is defined, use request filename. 171: $fn = $r->filename(); 172: my $lonDocRoot=$r->dir_config('lonDocRoot'); 173: if ( $fn =~ /$lonDocRoot/ ) { 174: #internal authentication, needs fixup. 175: $fn = $r->uri(); # non users do not get the full path request 176: # through SCRIPT_FILENAME 177: $fn=~s{^/~($LONCAPA::username_re)}{/home/$1/public_html}; 178: } 179: } 180: $fn=~s/\/+/\//g; 181: return $fn; 182: } 183: # 184: # Output the header of the page. This includes: 185: # - The HTML header 186: # - The H1/H3 stuff which includes the directory. 187: # 188: # startpage($r, $uame, $udom, $thisdisfn); 189: # $r - The apache request object. 190: # $uname - User name. 191: # $udom - Domain name the user is logged in under. 192: # $thisdisfn - Displayable version of the filename. 193: 194: sub startpage { 195: my ($r, $uname, $udom, $thisdisfn) = @_; 196: my $currdir = '/priv/'.$uname.$thisdisfn; 197: &Apache::loncommon::content_type($r,'text/html'); 198: $r->send_http_header; 199: 200: my $formaction='/priv/'.$uname.$thisdisfn.'/'; 201: $formaction=~s|/+|/|g; 202: &Apache::lonhtmlcommon::store_recent('construct',$formaction,$formaction); 203: 204: if ($env{'environment.remote'} eq 'off') { 205: $env{'request.noversionuri'}=$currdir.'/'; 206: $r->print(&Apache::loncommon::start_page('Construction Space',undef)); 207: } else { 208: $r->print(&Apache::loncommon::start_page('Construction Space',undef, 209: { 'only_body' => 1,})); 210: } 211: 212: # Breadcrumbs 213: &Apache::lonhtmlcommon::clear_breadcrumbs(); 214: &Apache::lonhtmlcommon::add_breadcrumb({ 215: 'text' => 'Construction Space', 216: 'href' => &Apache::loncommon::authorspace(), 217: }); 218: 219: $r->print(&Apache::lonhtmlcommon::breadcrumbs()); 220: 221: $r->print(&Apache::loncommon::head_subbox( 222: &Apache::loncommon::CSTR_pageheader(1))); 223: 224: my $esc_thisdisfn = &Apache::loncommon::escape_single($thisdisfn); 225: my $doctitle = 'LON-CAPA '.&mt('Construction Space'); 226: my $newname = &mt('New Name'); 227: my $pubdirscript=(<<ENDPUBDIRSCRIPT); 228: <script type="text/javascript"> 229: top.document.title = '$esc_thisdisfn/ - $doctitle'; 230: // Store directory location for menu bar to find 231: 232: parent.lastknownpriv='/~$uname$esc_thisdisfn/'; 233: 234: // Confirmation dialogues 235: 236: function currdiract(theform) { 237: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publish') { 238: document.publishdir.filename.value = theform.filename.value; 239: document.publishdir.submit(); 240: } 241: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editmeta') { 242: top.location=theform.filename.value+'default.meta' 243: } 244: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) { 245: document.printdir.postdata.value=theform.filename.value 246: document.printdir.submit(); 247: } 248: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == "delete") { 249: var delform = document.delresource 250: delform.filename.value = theform.filename.value 251: delform.submit() 252: } 253: } 254: 255: function checkUpload(theform) { 256: if (theform.file == '') { 257: alert("Please use 'Browse..' to choose a file first, before uploading") 258: return 259: } 260: theform.submit() 261: } 262: 263: function SetPubDir(theform,printForm) { 264: if (theform.diraction.options[theform.diraction.selectedIndex].value == "open") { 265: top.location = theform.openname.value 266: return 267: } 268: if (theform.diraction.options[theform.diraction.selectedIndex].value == "publish") { 269: theform.submit(); 270: } 271: if (theform.diraction.options[theform.diraction.selectedIndex].value == "editmeta") { 272: top.location=theform.filename.value+'default.meta' 273: } 274: if (theform.diraction.options[theform.diraction.selectedIndex].value == "printdir") { 275: theform.action = '/adm/printout' 276: theform.postdata.value = theform.filename.value 277: theform.submit() 278: } 279: if (theform.diraction.options[theform.diraction.selectedIndex].value == "delete") { 280: var delform = document.delresource 281: delform.filename.value = theform.filename.value 282: delform.submit() 283: } 284: return 285: } 286: function SetResChoice(theform) { 287: var activity = theform.reschoice.options[theform.reschoice.selectedIndex].value 288: if ((activity == 'rename') || (activity == 'copy') || (activity == 'move')) { 289: changename(theform,activity) 290: } 291: if (activity == 'publish') { 292: var pubform = document.pubresource 293: pubform.filename.value = theform.filename.value 294: pubform.submit() 295: } 296: if (activity == 'delete') { 297: var delform = document.delresource 298: delform.filename.value = theform.filename.value 299: delform.submit() 300: } 301: if (activity == 'obsolete') { 302: var pubform = document.pubresource 303: pubform.filename.value = theform.filename.value 304: pubform.makeobsolete.value=1; 305: pubform.submit() 306: } 307: if (activity == 'print') { 308: document.printresource.postdata.value = theform.filename.value 309: document.printresource.submit() 310: } 311: if (activity == 'retrieve') { 312: document.retrieveres.filename.value = theform.filename.value 313: document.retrieveres.submit() 314: } 315: if (activity == 'cleanup') { 316: document.cleanup.filename.value = theform.filename.value 317: document.cleanup.submit() 318: } 319: return 320: } 321: function changename(theform,activity) { 322: var oldname=theform.dispfilename.value; 323: var newname=prompt('$newname',oldname); 324: if (newname == "" || !newname || newname == oldname) { 325: return 326: } 327: document.moveresource.newfilename.value = newname 328: document.moveresource.filename.value = theform.filename.value 329: document.moveresource.action.value = activity 330: document.moveresource.submit(); 331: } 332: </script> 333: ENDPUBDIRSCRIPT 334: $r->print($pubdirscript); 335: 336: if ((($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) && 337: $env{'environment.remote'} ne 'off') { 338: $r->print('<h3>'.&mt('Co-Author [_1]',$uname.':'.$udom).'</h3>'); 339: } 340: } 341: 342: sub dircontrols { 343: my ($r,$uname,$udom,$thisdisfn) = @_; 344: my %lt=&Apache::lonlocal::texthash( 345: cnpd => 'Cannot publish directory', 346: cnrd => 'Cannot retrieve directory', 347: mcdi => 'Must create new subdirectory inside a directory', 348: pubr => 'Publish this Resource', 349: pubd => 'Publish this Directory', 350: dedr => 'Delete Directory', 351: rtrv => 'Retrieve Old Version', 352: list => 'List Directory', 353: uplo => 'Upload file', 354: dele => 'Delete', 355: edit => 'Edit Metadata', 356: sela => 'Select Action', 357: nfil => 'New file', 358: nhtm => 'New HTML file', 359: nprb => 'New problem', 360: npag => 'New assembled page', 361: nseq => 'New assembled sequence', 362: ncrf => 'New custom rights file', 363: nsty => 'New style file', 364: nlib => 'New library file', 365: nbt => 'New bridgetask file', 366: nsub => 'New subdirectory', 367: renm => 'Rename current file to', 368: move => 'Move current file to', 369: copy => 'Copy current file to', 370: type => 'Type Name Here', 371: go => 'Go', 372: prnt => 'Print contents of directory', 373: crea => 'Create a new directory or LON-CAPA document', 374: acti => 'Actions for current directory', 375: updc => 'Upload a new document', 376: pick => 'Please select an action to perform using the new filename', 377: ); 378: my $mytype = $lt{'type'}; # avoid conflict with " and ' in javascript 379: $r->print(<<END); 380: <div class="LC_columnSection"> 381: <div> 382: <form name="curractions" method="post" action=""> 383: <fieldset> 384: <legend>$lt{'acti'}</legend> 385: <select name="dirtask" onchange="currdiract(this.form)"> 386: <option>$lt{'sela'}</option> 387: <option value="publish">$lt{'pubd'}</option> 388: <option value="editmeta">$lt{'edit'}</option> 389: <option value="printdir">$lt{'prnt'}</option> 390: <option value="delete">$lt{'dedr'}</option> 391: </select> 392: <input type="hidden" name="filename" value="/~$uname$thisdisfn/" /> 393: </fieldset> 394: </form> 395: <form name="publishdir" method="post" action="/adm/publish" target="_parent"> 396: <input type="hidden" name="pubrec" value="" /> 397: <input type="hidden" name="filename" value="" /> 398: </form> 399: <form name="printdir" method="post" action="/adm/printout" target="_parent"> 400: <input type="hidden" name="postdata" value="" /> 401: </form> 402: </div> 403: 404: <div> 405: <form name="upublisher" enctype="multipart/form-data" method="post" action="/adm/upload" target="_parent"> 406: <fieldset> 407: <legend>$lt{'updc'}</legend> 408: <input type="hidden" name="filename" value="/~$uname$thisdisfn/" /> 409: <input type="file" name="upfile" size="20" /> 410: <input type="button" value="$lt{'uplo'}" onclick="checkUpload(this.form)" /> 411: </fieldset> 412: </form> 413: </div> 414: 415: <div> 416: <form name="fileaction" method="post" action="/adm/cfile" target="_parent"> 417: <fieldset> 418: <legend>$lt{'crea'}</legend> 419: <span class="LC_nobreak"> 420: <input type="hidden" name="filename" value="/~$uname$thisdisfn/" /> 421: <script type="text/javascript"> 422: function validate_go() { 423: var selected = document.fileaction.action.selectedIndex; 424: if (selected == 0) { 425: alert('$lt{'pick'}'); 426: } else { 427: document.fileaction.submit(); 428: } 429: } 430: </script> 431: <select name="action"> 432: <option value="none">$lt{'sela'}</option> 433: <option value="newfile">$lt{'nfil'}:</option> 434: <option value="newhtmlfile">$lt{'nhtm'}:</option> 435: <option value="newproblemfile">$lt{'nprb'}:</option> 436: <option value="newpagefile">$lt{'npag'}:</option> 437: <option value="newsequencefile">$lt{'nseq'}:</option> 438: <option value="newrightsfile">$lt{'ncrf'}:</option> 439: <option value="newstyfile">$lt{'nsty'}:</option> 440: <option value="newtaskfile">$lt{'nbt'}:</option> 441: <option value="newlibraryfile">$lt{'nlib'}:</option> 442: <option value="newdir">$lt{'nsub'}:</option> 443: </select> <input type="text" name="newfilename" value="$lt{'type'}" onfocus="if (this.value == '$mytype') this.value=''" /> <input type="button" value="Go" onclick="validate_go();" /> 444: </span> 445: </fieldset> 446: </form> 447: </div> 448: </div> 449: END 450: } 451: 452: sub pubbuttons { 453: my ($r,$uname,$thisdisfn) = @_; 454: $r->print('<form method="post" action="/adm/publish" target="_parent">'. 455: '<table><tr><td><input type="hidden" name="filename" value="/~'. 456: $uname.$thisdisfn.'/" />'. 457: '<input type="submit" value="'.&mt('Publish Directory').'" /></td><td>'. 458: '<input type="button" onclick="window.location='."'/~". 459: $uname.$thisdisfn."/default.meta'".'" value="'. 460: &mt('Edit Directory Metadata').'" /></td></tr></table></form>'); 461: } 462: 463: sub resourceactions { 464: my ($r,$uname,$udom,$thisdisfn) = @_; 465: $r->print(<<END); 466: <form name="moveresource" action="/adm/cfile" target="_parent" method="post"> 467: <input type="hidden" name="filename" value="" /> 468: <input type="hidden" name="newfilename" value="" /> 469: <input type="hidden" name="action" value="" /> 470: </form> 471: <form name="delresource" action="/adm/cfile" target="_parent" method="post"> 472: <input type="hidden" name="filename" value="" /> 473: <input type="hidden" name="action" value="delete" /> 474: </form> 475: <form name="pubresource" action="/adm/publish" target="_parent" method="post"> 476: <input type="hidden" name="filename" value="" /> 477: <input type="hidden" name="makeobsolete" value="0" /> 478: </form> 479: <form name="printresource" action="/adm/printout" target="_parent" method="post"> 480: <input type="hidden" name="postdata" value="" /> 481: </form> 482: <form name="retrieveres" action="/adm/retrieve" target="_parent" method="post"> 483: <input type="hidden" name="filename" value="" /> 484: </form> 485: <form name="cleanup" action="/adm/cleanup" target="_parent" method="post"> 486: <input type="hidden" name="filename" value="" /> 487: </form> 488: END 489: } 490: 491: # 492: # Get the title string or "[untitled]" if the file has no title metadata: 493: # Without the latter substitution, it's impossible to examine metadata for 494: # untitled resources. Resources may be legitimately untitled, to prevent 495: # searches from locating them. 496: # 497: # $str = getTitleString($fullname); 498: # $fullname - Fully qualified filename to check. 499: # 500: sub getTitleString { 501: my $fullname = shift; 502: my $title = &Apache::lonnet::metadata($fullname, 'title'); 503: 504: unless ($title) { 505: $title = "[".&mt('untitled')."]"; 506: } 507: return $title; 508: } 509: 510: sub getCopyRightString { 511: my $fullname = shift; 512: return &Apache::lonnet::metadata($fullname, 'copyright'); 513: } 514: 515: sub getSourceRightString { 516: my $fullname = shift; 517: return &Apache::lonnet::metadata($fullname, 'sourceavail'); 518: } 519: # 520: # Put out a directory table row: 521: # putdirectory(r, base, here, dirname, modtime) 522: # r - Apache request object. 523: # reqfile - File in request. 524: # here - Where we are in directory tree. 525: # dirname - Name of directory special file. 526: # modtime - Encoded modification time. 527: # 528: sub putdirectory { 529: my ($r, $reqfile, $here, $dirname, $modtime, $resdir, $bombs, $numdir) = @_; 530: # construct the display filename: the directory name unless ..: 531: 532: my $disfilename = $dirname; 533: if ($dirname eq '..') { 534: $disfilename = '<i>'.&mt('Parent Directory').'</i>'; 535: } 536: unless ( (($dirname eq '..') && ($reqfile eq '')) || ($dirname eq '.')) { 537: my $kaputt=0; 538: foreach (keys %{$bombs}) { 539: if ($_=~m:^\Q$resdir\E/\Q$disfilename\E/:) { $kaputt=1; last; } 540: } 541: %Apache::lonpublisher::metadatafields=(); 542: %Apache::lonpublisher::metadatakeys=(); 543: my $construct=$here; 544: $construct=~s{^/priv/($LONCAPA::username_re)$}{/home/$1/public_html}; 545: my $dirpath = $here; 546: $dirpath=~s{^/priv/}{/~}; 547: &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile( 548: $construct.'/'.$dirname.'/default.meta' 549: )); 550: my $actionitem = ''; 551: if ($dirname eq '..') { 552: $actionitem = &mt('Go to ...'); 553: } else { 554: $actionitem = 555: '<form name="dirselect_'.$$numdir. 556: '" action="/adm/publish" target="_parent">'. 557: '<select name="diraction" onchange="SetPubDir(this.form,document)">'. 558: '<option selected="selected">'.&mt('Select action').'</option>'. 559: '<option value="open">'.&mt('Open').'</option>'. 560: '<option value="publish">'.&mt('Publish').'</option>'. 561: '<option value="editmeta">'.&mt('Edit Metadata').'</option>'. 562: '<option value="printdir">'.&mt('Print directory').'</option>'. 563: '<option value="delete">'.&mt('Delete directory').'</option>'. 564: '</select>'. 565: '<input type="hidden" name="filename" value="'.&HTML::Entities::encode($dirpath.'/'.$dirname,'<>&"').'/" />'. 566: '<input type="hidden" name="openname" value="'.$here.'/'.$dirname.'/" />'. 567: '<input type="hidden" name="postdata" value="" />'. 568: '</form>'; 569: $$numdir ++; 570: } 571: $r->print('<tr class="LC_browser_folder">'. 572: '<td><img src="'. 573: $Apache::lonnet::perlvar{'lonIconsURL'}.'/navmap.folder.closed.gif" alt="folder" /></td>'. 574: '<td>'.$actionitem.'</td>'. 575: '<td><span class="LC_filename"><a href="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" target="_parent">'. 576: $disfilename.'</a></span></td>'. 577: '<td colspan="3">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($resdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'}); 578: if ($Apache::lonpublisher::metadatafields{'subject'} ne '') { 579: $r->print(' <i>'. 580: $Apache::lonpublisher::metadatafields{'subject'}. 581: '</i> '); 582: } 583: $r->print($Apache::lonpublisher::metadatafields{'keywords'}.'</td>'. 584: '<td>'.&Apache::lonlocal::locallocaltime($modtime).'</td>'. 585: "</tr>\n"); 586: } 587: return OK; 588: } 589: # 590: # Put a table row for a file resource. 591: # 592: sub putresource { 593: my ($r, $udom, $uname, $filename, $thisdisfn, 594: $resdir, $targetdir, $linkdir, 595: $cmtime,$bombs,$numres) = @_; 596: &Apache::lonnet::devalidate_cache_new('meta',$targetdir.'/'.$filename); 597: my $pubstatus = 'unpublished'; 598: my $status=&mt('Unpublished'); 599: my $css_class='LC_browser_file'; 600: my $title=' '; 601: my $publish_button=&mt('Publish'); 602: my $cstr_dir = '/home/'.$uname.'/public_html/'.$thisdisfn.'/'; 603: # my $action_buttons= 604: # '<br /><a target="_parent" href="/adm/cfile?action=delete&filename=/~'. 605: # $uname.'/'.$thisdisfn.'/'.$filename.'">'. 606: # &mt('Delete').'</a>'; 607: if (-e $resdir.'/'.$filename) { 608: my $same=0; 609: my ($rdev,$rino,$rmode,$rnlink, 610: $ruid,$rgid,$rrdev,$rsize, 611: $ratime,$rmtime,$rctime, 612: $rblksize,$rblocks)=stat($resdir.'/'.$filename); 613: if ($rmtime>=$cmtime) { 614: $same=1; 615: } else { 616: if (&Apache::londiff::are_different_files($resdir.'/'.$filename, 617: $cstr_dir.'/'.$filename)) { 618: $same=0; 619: } else { 620: $same=1; 621: } 622: } 623: my $meta_cmtime = (stat($cstr_dir.'/'.$filename.'.meta'))[9]; 624: my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9]; 625: my $meta_same = 1; 626: if ($meta_rmtime < $meta_cmtime 627: && &Apache::londiff::are_different_files($resdir.'/'.$filename.'.meta', 628: $cstr_dir.'/'.$filename.'.meta')) { 629: $meta_same = 0; 630: } 631: $publish_button=&mt('Re-publish'); 632: my $rights_status = 633: &mt(&getCopyRightString($targetdir.'/'.$filename)).' '. 634: &mt(&getSourceRightString($targetdir.'/'.$filename)); 635: $title = '<a href="/res/'.$targetdir.'/'.$filename. 636: '.meta" target="cat">'. 637: &getTitleString($targetdir.'/'.$filename).'</a>'; 638: if ($same) { 639: if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) { 640: $pubstatus = 'obsolete'; 641: $status=&mt('Obsolete'); 642: } else { 643: if (!$meta_same) { 644: $pubstatus = 'metamodified'; 645: } else { 646: $pubstatus = 'published'; 647: } 648: $status=&mt('Published'). 649: '<br />'. $rights_status; 650: } 651: # } else { 652: # $action_buttons=''; 653: # } 654: } else { 655: $pubstatus = 'modified'; 656: $status=&mt('Modified'). 657: '<br />'. $rights_status; 658: # $action_buttons=''; 659: if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') { 660: $status.='<br /><a href="/adm/diff?filename=/~'.$uname. 661: $thisdisfn.'/'.$filename. 662: '&versiontwo=priv" target="cat">'.&mt('Diffs').'</a>'; 663: } 664: } 665: 666: $title.="\n".'<br /><a href="/~'.$uname.$thisdisfn.'/'.$filename.'.meta">'. 667: ($$bombs{$targetdir.'/'.$filename}?'<img src="/adm/lonMisc/bomb.gif" border="0" alt="'.&mt('bomb').'" />':&mt('Edit Metadata')).'</a>'; 668: 669: if (!$meta_same) { 670: $title = &mt('Metadata Modified').'<br />'.$title. 671: '<br /><a href="/adm/diff?filename=/~'.$uname. 672: $thisdisfn.'/'.$filename.'.meta'. 673: '&versiontwo=priv" target="cat">'.&mt('Metadata Diffs').'</a>'; 674: $title.="\n".'<br /><a href="/adm/retrieve?filename=/~'.$uname. 675: $thisdisfn.'/'.$filename.'.meta" target="_parent">'.&mt('Retrieve Metadata').'</a>'; 676: } 677: $status.="\n".'<br /><a href="/adm/retrieve?filename=/~'.$uname. 678: $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Retrieve').'</a>'; 679: } 680: my $editlink=''; 681: my $editlink2=''; 682: if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty)$/) { 683: $editlink=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('Edit').'</a>)'; 684: } 685: if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library)$/) { 686: $editlink=' (<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('EditXML').'</a>)'; 687: $editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceColoredit=1" target="_parent">'.&mt('Edit').'</a>)'; 688: } 689: if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) { 690: $editlink.=' (<a href="/adm/cleanup?filename=/~'.$uname. 691: $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Clean Up').')</a>'; 692: } 693: if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) { 694: $editlink=' (<a target="_parent" href="/adm/cfile?decompress=/~'. 695: $uname.$thisdisfn.'/'.$filename.'">'.&mt('Decompress').'</a>)'; 696: } 697: my $pub_select = ''; 698: &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres); 699: $r->print(&Apache::loncommon::start_data_table_row(). 700: '<td>'.($filename=~/[\#\~]$/?' ': 701: '<img src="'.&Apache::loncommon::icon($filename).'" alt="" />').'</td>'. 702: '<td>'.$pub_select.'</td>'. 703: '<td><span class="LC_filename">'. 704: '<a href="'.$linkdir.'/'.$filename.'" target="_parent">'. 705: $filename.'</a></span>'.$editlink2.$editlink. 706: '</td>'. 707: '<td>'.$title.'</td>'. 708: '<td class="LC_browser_file_'.$pubstatus.'"> </td>'. # Display publication status 709: '<td>'.$status.'</td>'. 710: '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'. 711: &Apache::loncommon::end_data_table_row() 712: ); 713: return OK; 714: } 715: 716: sub create_pubselect { 717: my ($r,$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres) = @_; 718: $$pub_select = ' 719: <form name="resselect_'.$$numres.'" action=""> 720: <select name="reschoice" onchange="SetResChoice(this.form)"> 721: <option>'.&mt('Select action').'</option>'. 722: '<option value="copy">'.&mt('Copy').'</option>'; 723: if ($pubstatus eq 'obsolete' || $pubstatus eq 'unpublished') { 724: $$pub_select .= 725: '<option value="rename">'.&mt('Rename').'</option>'. 726: '<option value="move">'.&mt('Move').'</option>'. 727: '<option value="delete">'.&mt('Delete').'</option>'; 728: } else { 729: $$pub_select .= ' 730: <option value="obsolete">'.&mt('Mark obsolete').'</option>'; 731: } 732: # check for versions 733: my $versions = &check_for_versions($r,'/'.$filename,$udom,$uname); 734: if ($versions > 0) { 735: $$pub_select .=' 736: <option value="retrieve">'.&mt('Retrieve old version').'</option>'; 737: } 738: $$pub_select .= ' 739: <option value="publish">'.$publish_button.'</option>'. 740: '<option value="cleanup">'.&mt('Clean up').'</option>'. 741: '<option value="print">'.&mt('Print').'</option>'. 742: '</select> 743: <input type="hidden" name="filename" value="/~'. 744: &HTML::Entities::encode($uname.$thisdisfn.'/'.$filename,'<>&"').'" /> 745: <input type="hidden" name="dispfilename" value="'. 746: &HTML::Entities::encode($filename).'" /></form>'; 747: $$numres ++; 748: } 749: 750: sub check_for_versions { 751: my ($r,$fn,$udom,$uname) = @_; 752: my $versions = 0; 753: my $docroot=$r->dir_config('lonDocRoot'); 754: my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn; 755: my $resdir=$resfn; 756: $resdir=~s/\/[^\/]+$/\//; 757: $fn=~/\/([^\/]+)\.(\w+)$/; 758: my $main=$1; 759: my $suffix=$2; 760: opendir(DIR,$resdir); 761: while (my $filename=readdir(DIR)) { 762: if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) { 763: $versions ++; 764: } 765: } 766: return $versions; 767: } 768: 769: # 770: # Categorize files in the directory. 771: # For each file in a list of files in a file directory, 772: # the file categorized as one of: 773: # - directory 774: # - sequence 775: # - problem 776: # - Other resource. 777: # 778: # For each file the modification date is determined as well. 779: # Returned is a list of sublists: 780: # (directories, sequences, problems, other) 781: # each of the sublists contains entries of the following form (sorted by 782: # filename): 783: # (filename, typecode, lastmodtime) 784: # 785: # $list = CategorizeFiles($location, $files) 786: # $location - Directory in which the files live (relative to our 787: # execution. 788: # $files - list of files. 789: # 790: sub CategorizeFiles { 791: my $location = shift; 792: my $files = shift; 793: } 794: 795: 1; 796: __END__ 797: 798: 799: =head1 NAME 800: 801: Apache::lonpubdir - Construction space directory lister 802: 803: =head1 SYNOPSIS 804: 805: Invoked (for various locations) by /etc/httpd/conf/srm.conf: 806: 807: <LocationMatch "^/\~.*/$"> 808: PerlAccessHandler Apache::loncacc 809: SetHandler perl-script 810: PerlHandler Apache::lonpubdir 811: ErrorDocument 403 /adm/login 812: ErrorDocument 404 /adm/notfound.html 813: ErrorDocument 406 /adm/unauthorized.html 814: ErrorDocument 500 /adm/errorhandler 815: </LocationMatch> 816: 817: <Location /adm/pubdir> 818: PerlAccessHandler Apache::lonacc 819: SetHandler perl-script 820: PerlHandler Apache::lonpubdir 821: ErrorDocument 403 /adm/login 822: ErrorDocument 404 /adm/notfound.html 823: ErrorDocument 406 /adm/unauthorized.html 824: ErrorDocument 500 /adm/errorhandler 825: </Location> 826: 827: =head1 INTRODUCTION 828: 829: This module publishes a directory of files. 830: 831: This is part of the LearningOnline Network with CAPA project 832: described at http://www.lon-capa.org. 833: 834: =head1 HANDLER SUBROUTINE 835: 836: This routine is called by Apache and mod_perl. 837: 838: =over 4 839: 840: =item * 841: 842: read in information 843: 844: =item * 845: 846: start page output 847: 848: =item * 849: 850: run through list of files and attempt to publish unhidden files 851: 852: =back 853: 854: =head1 SUBROUTINES: 855: 856: =over 857: 858: =item startpage($r, $uame, $udom, $thisdisfn) 859: 860: Output the header of the page. This includes: 861: - The HTML header 862: - The H1/H3 stuff which includes the directory. 863: 864: startpage($r, $uame, $udom, $thisdisfn); 865: $r - The apache request object. 866: $uname - User name. 867: $udom - Domain name the user is logged in under. 868: $thisdisfn - Displayable version of the filename. 869: 870: =item getTitleString($fullname) 871: 872: Get the title string or "[untitled]" if the file has no title metadata: 873: Without the latter substitution, it's impossible to examine metadata for 874: untitled resources. Resources may be legitimately untitled, to prevent 875: searches from locating them. 876: 877: $str = getTitleString($fullname); 878: $fullname - Fully qualified filename to check. 879: 880: =item putdirectory(r, base, here, dirname, modtime) 881: 882: Put out a directory table row: 883: 884: putdirectory($r, $base, $here, $dirname, $modtime) 885: $r - Apache request object. 886: $reqfile - File in request. 887: $here - Where we are in directory tree. 888: $dirname - Name of directory special file. 889: $modtime - Encoded modification time. 890: 891: =item CategorizeFiles($location, $files) 892: 893: Categorize files in the directory. 894: For each file in a list of files in a file directory, 895: the file categorized as one of: 896: - directory 897: - sequence 898: - problem 899: - Other resource. 900: 901: For each file the modification date is determined as well. 902: Returned is a list of sublists: 903: (directories, sequences, problems, other) 904: each of the sublists contains entries of the following form (sorted by filename): 905: (filename, typecode, lastmodtime) 906: 907: $list = CategorizeFiles($location, $files) 908: $location - Directory in which the files live (relative to our execution) 909: $files - list of files. 910: 911: =back 912: 913: =cut 914: