Annotation of loncom/publisher/lonpubdir.pm, revision 1.65

1.1       www         1: # The LearningOnline Network with CAPA
1.32      www         2: # Construction Space Directory Lister
1.16      albertel    3: #
1.65    ! albertel    4: # $Id: lonpubdir.pm,v 1.64 2004/10/29 18:40:40 raeburn Exp $
1.16      albertel    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/
1.1       www        27: #
1.17      harris41   28: ###
1.1       www        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);
1.6       www        36: use Apache::loncacc;
1.17      harris41   37: use Apache::loncommon();
1.48      www        38: use Apache::lonhtmlcommon();
1.39      www        39: use Apache::lonlocal;
1.50      www        40: use Apache::lonmsg;
1.64      raeburn    41: use Apache::lonmenu;
                     42: use Apache::lonnet;
1.1       www        43: 
                     44: sub handler {
                     45: 
                     46:   my $r=shift;
                     47: 
                     48:   my $fn;
                     49: 
1.23      foxr       50: 
                     51: 
                     52:   $fn = getEffectiveUrl($r);
                     53: 
                     54:   # Validate access to the construction space and get username@domain.
1.6       www        55: 
                     56:   my $uname;
                     57:   my $udom;
                     58: 
1.9       www        59:   ($uname,$udom)=
1.6       www        60:     &Apache::loncacc::constructaccess(
1.9       www        61:              $fn,$r->dir_config('lonDefDomain')); 
                     62:   unless (($uname) && ($udom)) {
1.6       www        63:      $r->log_reason($uname.' at '.$udom.
1.32      www        64:          ' trying to list directory '.$ENV{'form.filename'}.
1.6       www        65:          ' ('.$fn.') - not authorized', 
                     66:          $r->filename); 
                     67:      return HTTP_NOT_ACCEPTABLE;
                     68:   }
1.23      foxr       69: 
1.32      www        70:   # Remove trailing / from directory name.
1.23      foxr       71: 
1.3       www        72:   $fn=~s/\/$//;
1.1       www        73: 
                     74:   unless ($fn) { 
                     75:      $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
1.2       www        76:          ' trying to list empty directory', $r->filename); 
1.1       www        77:      return HTTP_NOT_FOUND;
                     78:   } 
                     79: 
                     80: # ----------------------------------------------------------- Start page output
                     81: 
1.23      foxr       82:   my $thisdisfn=$fn;
                     83:   $thisdisfn=~s/^\/home\/$uname\/public_html//;	# subdirectory part of
                     84:                                                 # construction space. 
                     85:   my $docroot=$r->dir_config('lonDocRoot');     # Apache  londocument root.
1.1       www        86: 
1.23      foxr       87:   my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn; # Resource directory
                     88:   my $targetdir=$udom.'/'.$uname.$thisdisfn; # Publiction target directory.
1.25      www        89:   my $linkdir='/priv/'.$uname.$thisdisfn;      # Full URL name of constr space.
1.1       www        90: 
1.50      www        91:   my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
1.1       www        92: 
1.26      www        93:   &startpage($r, $uname, $udom, $thisdisfn);   # Put out the start of page.
1.65    ! albertel   94:   if ($ENV{'environment.remote'} eq 'off') {
        !            95:       &dircontrols($r,$uname,$udom,$thisdisfn);    # Put out actions for directory, 
1.64      raeburn    96:                                                # browse/upload + new file page.
1.65    ! albertel   97:   }
1.64      raeburn    98:   &resourceactions($r,$uname,$udom,$thisdisfn); #Put out form used for printing/deletion etc.
                     99: 
                    100:   my $numdir = 0;
                    101:   my $numres = 0;
1.6       www       102:   
1.50      www       103:   # Start off the directory table.
1.64      raeburn   104:   $r->print('<h3>Directory Contents:</h3>');
                    105:   $r->print('<table border="0" cellspacing="2" cellpadding="2"><tr>'.
                    106:             '<th bgcolor="#DDDDDD">'.&mt('Type').'</th>'.
                    107:             '<th bgcolor="#DDDDDD">'.&mt('Actions').'</th>'.
                    108:             '<th bgcolor="#DDDDDD">'.&mt('Name').'</th>'.
                    109:             '<th bgcolor="#DDDDDD">'.&mt('Title').'</th>'.
                    110: 	    '<th bgcolor="#DDDDDD">'.&mt('Status').'</th>'.
                    111:             '<th bgcolor="#DDDDDD">'.&mt('Last Modified').
1.39      www       112: 	    '</th></tr>');
1.1       www       113: 
1.2       www       114:   my $filename;
1.23      foxr      115:   my $dirptr=16384;		# Mask indicating a directory in stat.cmode.
1.1       www       116: 
1.2       www       117:   opendir(DIR,$fn);
1.44      albertel  118:   my @files=sort {uc($a) cmp uc($b)} (readdir(DIR));
1.11      albertel  119:   foreach my $filename (@files) {
1.2       www       120:      my ($cdev,$cino,$cmode,$cnlink,
                    121:          $cuid,$cgid,$crdev,$csize,
                    122:          $catime,$cmtime,$cctime,
                    123:          $cblksize,$cblocks)=stat($fn.'/'.$filename);
1.12      www       124: 
1.10      albertel  125:      my $extension='';
                    126:      if ($filename=~/\.(\w+)$/) { $extension=$1; }
1.15      matthew   127:      if ($cmode&$dirptr) {
1.64      raeburn   128: 	 putdirectory($r, $thisdisfn, $linkdir, $filename, $cmtime,$targetdir,\%bombs,\$numdir);
1.17      harris41  129:      } elsif (&Apache::loncommon::fileembstyle($extension) ne 'hdn') {
1.64      raeburn   130: 	 putresource($r, $udom, $uname, $filename, $thisdisfn, $resdir, 
                    131: 		     $targetdir, $linkdir, $cmtime,\%bombs,\$numres);
1.14      albertel  132:      } else {
1.15      matthew   133: 	# "hidden" extension and not a directory, so hide it away.
1.2       www       134:      }
                    135:   }
                    136:   closedir(DIR);
                    137: 
                    138:   $r->print('</table></body></html>');
1.1       www       139:   return OK;  
                    140: }
1.21      foxr      141: #
1.23      foxr      142: #  Gets the effective URL of the request and returns it:
                    143: #    $effn = getEffectiveUrl($r);
                    144: #       $r  - The Apache Request object.
                    145: sub getEffectiveUrl {
                    146:     my $r = shift;
                    147:     my $fn;
                    148:     
                    149:     if ($ENV{'form.filename'}) {	# If a form filename is defined.
                    150: 	$fn=$ENV{'form.filename'};
                    151: 	#
                    152: 	#   Replace the ~username of the URL with /home/username/public_html
                    153: 	#   so that we don't have to worry about ~ expansion internally.
                    154: 	#
1.32      www       155: 	$fn=~s/^http\:\/\/[^\/]+\///;
                    156:         $fn=~s/^\///;
                    157:         $fn=~s/\~(\w+)/\/home\/$1\/public_html/;
1.23      foxr      158: 	
                    159: 	#  Remove trailing / strings (?) 
                    160: 	
                    161: 	$fn=~s/\/[^\/]+$//;
1.24      albertel  162:     } else {
                    163: 	#   If no form is defined, use request filename.
                    164: 	$fn = $r->filename();
                    165: 	my $lonDocRoot=$r->dir_config('lonDocRoot');
                    166: 	if ( $fn =~ /$lonDocRoot/ ) {
                    167: 	    #internal authentication, needs fixup.
                    168: 	    $fn = $r->uri(); # non users do not get the full path request
                    169:                              # through SCRIPT_FILENAME
                    170: 	    $fn=~s|^/~(\w+)|/home/$1/public_html|;
                    171: 	}
1.23      foxr      172:     }
1.37      www       173:     $fn=~s/\/+/\//g;
1.23      foxr      174:     return $fn;
                    175: }
                    176: #
                    177: #   Output the header of the page.  This includes:
                    178: #   - The HTML header 
                    179: #   - The H1/H3  stuff which includes the directory.
                    180: #
                    181: #     startpage($r, $uame, $udom, $thisdisfn);
                    182: #      $r     - The apache request object.
                    183: #      $uname - User name.
                    184: #      $udom  - Domain name the user is logged in under.
                    185: #      $thisdisfn - Displayable version of the filename.
1.26      www       186: 
1.23      foxr      187: sub startpage {
                    188:     my ($r, $uname, $udom, $thisdisfn) = @_;
1.64      raeburn   189:     my $currdir = '/priv/'.$uname.$thisdisfn;
1.39      www       190:     &Apache::loncommon::content_type($r,'text/html');
1.23      foxr      191:     $r->send_http_header;
1.64      raeburn   192: 
1.23      foxr      193:     $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
1.64      raeburn   194: 
                    195:     my $pagetitle; 
                    196:     my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                    197:     $formaction=~s/\/+/\//g;
                    198:     $pagetitle .= ('<form name="dirs" method="post" action="'.$formaction
                    199:               .'" target="_parent">'.
                    200:         '<font face="Arial, Helvetica, sans-serif"><b>Construction Space</b>:</font>&nbsp;'.
                    201:         &Apache::lonhtmlcommon::crumbs($uname.'/'.$thisdisfn,'top','/priv','','-1').
                    202:         &Apache::lonhtmlcommon::select_recent('construct','recent',
                    203:                  'this.form.action=this.form.recent.value;this.form.submit()').
                    204:               '</form>');
                    205:      &Apache::lonhtmlcommon::store_recent('construct',$formaction,$formaction);
1.65    ! albertel  206:     if ($ENV{'environment.remote'} eq 'off') {
        !           207: 	$ENV{'request.noversionuri'}=$currdir;
        !           208: 	$r->print(&Apache::loncommon::bodytag('Construction Space',undef,undef,undef,undef,undef,$pagetitle));
        !           209:     } else {
        !           210: 	$r->print($pagetitle);
        !           211:     }
1.64      raeburn   212:     $r->print(&Apache::loncommon::help_open_menu('','','','',3,'Authoring'));
1.29      www       213:     my $pubdirscript=(<<ENDPUBDIRSCRIPT);
                    214: <script>
1.37      www       215: // Store directory location for menu bar to find
                    216: 
                    217: parent.lastknownpriv='/~$uname/$thisdisfn/';
                    218: 
                    219: // Confirmation dialogues
                    220: 
1.64      raeburn   221:     function currdiract(theform) {
                    222:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publish') {
                    223:             document.publishdir.filename.value = theform.filename.value
                    224:             pubdir(document.publishdir)
                    225:         }
                    226:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publishsub') {
                    227:             document.publishdir.filename.value = theform.filename.value
                    228:             pubrecdir(document.publishdir)
                    229:         }
                    230:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editcat') {
                    231:             window.location=theform.filename.value+'default.meta'
                    232:         }
                    233:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) {
                    234:             document.printdir.postdata.value=theform.filename.value
                    235:             document.printdir.submit();
                    236:         }
                    237:     }
                    238:   
1.29      www       239:     function pubdir(theform) {
                    240: 	if (confirm('Publish complete directory?')) {
1.64      raeburn   241:             forcepub(theform)
1.29      www       242: 	    theform.submit();
                    243:         }
                    244:     }
1.64      raeburn   245:     function pubrecdir(theform) {
1.29      www       246: 	if (confirm('Publish directory and all subdirectories?')) {
1.64      raeburn   247:             forcepub(theform);
1.29      www       248:             theform.pubrec.value='1';
                    249: 	    theform.submit();
                    250:         }
                    251:     }
1.64      raeburn   252: 
                    253:     function forcepub(theform) {
                    254:         if (confirm('Force publication of unmodified files? - OK=yes; Cancel=No.')) {
                    255:             theform.forcerepub.value="ON";
                    256:         } 
                    257:     }
                    258: 
                    259:     function checkUpload(theform) {
                    260:         if (theform.file == '') {
                    261:             alert("Please use 'Browse..' to choose a file first, before uploading")
                    262:             return 
                    263:         }
                    264:         theform.submit()  
                    265:     }
                    266: 
                    267:     function SetPubDir(theform,printForm) {
                    268:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "open") {
                    269:             window.location = theform.filename.value
                    270:             return
                    271:         }
                    272:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "publish") {
                    273:             pubdir(theform)
                    274:         }
                    275:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "publishsub") {
                    276:             pubrecdir(theform)
                    277:         }
                    278:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "editcat") {
                    279:             window.location=theform.filename.value+'default.meta'
                    280:         }
                    281:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "print") {
                    282:             theform.action = '/adm/printout'
                    283:             theform.postdata.value = theform.filename.value
                    284:             theform.submit()
                    285:         }
                    286:         return
                    287:     }
                    288:     function SetResChoice(theform) {
                    289:       var activity = theform.reschoice.options[theform.reschoice.selectedIndex].value
                    290:       if ((activity == 'rename') || (activity == 'copy') || (activity == 'move')) {
                    291:           changename(theform,activity)
                    292:       }
                    293:       if (activity == 'publish') {
                    294:           var pubform = document.pubresource
                    295:           pubform.filename.value = theform.filename.value
                    296:           pubform.submit()
                    297:       }
                    298:       if (activity == 'delete') {
                    299:           var delform = document.delresource
                    300:           delform.filename.value = theform.filename.value
                    301:           if (confirm("Are you sure you want to delete "+theform.filename.value+"?")) {
                    302:               delform.submit()
                    303:           }
                    304:       }
                    305:       if (activity == 'obsolete') {
                    306:           alert("Mark as obsolete - still to be implemented") 
                    307:       }
                    308:       if (activity == 'print') {
                    309:           document.printresource.postdata = theform.filename.value
                    310:           document.printresource.curseed = getcurseed()
                    311:           document.printresource.problemtype = getproblemtype()
                    312:           document.printresource.submit()
                    313:       }
                    314:       if (activity == 'retrieve') {
                    315:           retrieveres.filename.value = theform.filename.value
                    316:           retrieveres.submit()
                    317:       }
                    318:       return
                    319:     }
                    320:     function changename(theform,activity) {
                    321:         var newname=prompt('New Name');
                    322:         if (newname == "" || !newname)  {
                    323:             return
                    324:         }
                    325:         document.moveresource.newfilename.value = newname
                    326:         document.moveresource.filename.value = theform.filename.value
                    327:         document.moveresource.action.value = activity
                    328:         document.moveresource.submit();
                    329:     }
                    330: 
                    331:     function getcurseed() {
                    332:       if (parent.document.lonhomework
                    333:            &&
                    334:           parent.document.lonhomework.rndseed
                    335:            &&
                    336:           parent.document.lonhomework.rndseed.value) {
                    337:               return parent.document.lonhomework.rndseed.value;
                    338:       }
                    339:       return 0;
                    340:     }
                    341:                                                                                                       
                    342:     function getproblemtype() {
                    343:         if (parent.document.lonhomework) {
                    344:             var optionelement;
                    345:             var valueIndex=0;
                    346:             for (var optionIndex=0;
                    347:                 optionIndex < parent.document.lonhomework.problemtype.options.length;
                    348:                 optionIndex++)
                    349:             {
                    350:                 optionElement=parent.document.lonhomework.problemtype.options[optionIndex];
                    351:                 if (optionElement.selected) {
                    352:                     return optionElement.value;
                    353:                 }
                    354:             }
                    355:         }
                    356:         return 0;
                    357:     }
1.29      www       358: </script>
                    359: ENDPUBDIRSCRIPT
1.64      raeburn   360:     $r->print($pubdirscript);
1.29      www       361: 
1.23      foxr      362:     if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
1.39      www       363: 	$r->print('<h3>'.&mt('Co-Author').': '.$uname.' at '.$udom.
1.23      foxr      364: 		  '</h3>');
                    365:     }
1.64      raeburn   366: }
                    367: 
                    368: sub dircontrols {
                    369:     my ($r,$uname,$udom,$thisdisfn) = @_;
                    370:     $r->print(<<END);
                    371:         <table cellspacing="4" cellpadding="4" width="100%">
                    372:          <tr>
                    373:           <th bgcolor="#DDDDDD">Actions for current directory</th>
                    374:           <th bgcolor="#DDDDDD">Upload a new document</th>
                    375:           <th bgcolor="#DDDDDD">Create a new directory or LON-CAPA document</th>
                    376:         </tr>
                    377:         <tr>
                    378:          <td bgcolor="#ccddaa" valign="top" align="center">
                    379:           <form name="curractions" method="post" action="">
                    380:            <select name="dirtask" onChange="currdiract(this.form)">
                    381:             <option>Select action</option>
                    382:             <option value="publish">Publish directory</option>
                    383:             <option value="publishsub">Publish with subdirectories</option>
                    384:             <option value="editcat">Edit catalog information</option>
                    385:             <option value="printdir">Print contents of directory</option>
                    386:            </select>
                    387:            <input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
                    388:           </form>
                    389:           <form name="publishdir" method="post" action="/adm/publish" target="_parent">
                    390:            <input type="hidden" name="pubrec" value="" />
                    391:            <input type="hidden" name="filename" value="" />
                    392:            <input type="hidden" name="forcerepub" value="NO" />
                    393:           </form>
                    394:           <form name="printdir" method="post" action="/adm/printout" target="_parent">
                    395:            <input type="hidden" name="postdata" value="" />
                    396:            <input type="hidden" name="curseed" value="0" />
                    397:            <input type="hidden" name="problemtype" value="0" />
                    398:           </form>
                    399:          </td>
                    400:          <td bgcolor="#ccddaa" valign="top" align="center">
                    401: 	    <form name="upublisher" enctype="multipart/form-data" method="post" action="/adm/upload" target="_parent">
                    402: 	      <input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
                    403: 	      <input type="file" name="upfile" size="20" />
                    404: 	      <input type="button" value="Upload file"  onclick="checkUpload(this.form)" />
                    405: 	    </form>
                    406: 	 </td>
                    407: 	 <td bgcolor="#ccddaa" align="center">
                    408: 	    <form name="fileaction" method="post" action="/adm/cfile" target="_parent">
                    409: 	      <nobr>
                    410: 		<input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
                    411: 		  <select name="action">
                    412: 		    <option>Select action</option>
                    413: 		    <option value="newfile">New file:</option>
                    414: 		    <option value="newhtmlfile">New HTML file:</option>
                    415: 		    <option value="newproblemfile">New problem:</option>
                    416:                     <option value="newpagefile">New assembled page:</option>
                    417:                     <option value="newsequencefile">New assembled sequence:</option>
                    418:                     <option value="newrightsfile">New custom rights file:</option>
                    419:                     <option value="newstyfile">New style file:</option>
                    420: 		    <option value="newdir">New subdirectory:</option>
                    421: 		  </select>&nbsp;<input type="text" name="newfilename" value="Type Name Here" onfocus="if (this.value == 'Type Name Here') this.value=''" />&nbsp;<input type="button" value="Go" onclick="document.fileaction.submit()" />
                    422: 		 </nobr>
                    423: 		</form>
                    424: 	  </td>
                    425:          </tr>
                    426:         </table>
                    427:         <br />
                    428:         <br />
                    429: END
                    430: }
                    431: 
                    432: sub resourceactions {
                    433:     my ($r,$uname,$udom,$thisdisfn) = @_;
                    434:     $r->print(<<END);
                    435:        <form name="moveresource" action="/adm/cfile" target="_parent" method="post">
                    436:          <input type="hidden" name="filename" value="" />
                    437:          <input type="hidden" name="newfilename" value="" />
                    438:          <input type="hidden" name="action" value="" />
                    439:        </form>
                    440:        <form name="delresource" action="/adm/cfile" target="_parent" method="post">
                    441:          <input type="hidden" name="filename" value="" />
                    442:          <input type="hidden" name="action" value="delete" />
                    443:        </form>
                    444:        <form name="pubresource" action="/adm/publish" target="_parent" method="post">
                    445:          <input type="hidden" name="pubrec" value="" />
                    446:          <input type="hidden" name="filename" value="" />
                    447:          <input type="hidden" name="forcerepub" value="NO" />
                    448:        </form>
                    449:        <form name="printresource" action="/adm/printout" target="_parent" method="post">
                    450:            <input type="hidden" name="postdata" value="" />
                    451:            <input type="hidden" name="curseed" value="" />
                    452:            <input type="hidden" name="problemtype" value="" />
                    453:        </form>
                    454:        <form name="retrieveres" action="/adm/retrieve" target="_parent" method="post">
                    455:            <input type="hidden" name="filename" value="" />
                    456:        </form>
                    457: END
1.23      foxr      458: }
                    459: 
                    460: #
                    461: #   Get the title string or "[untitled]" if the file has no title metadata:
                    462: #   Without the latter substitution, it's impossible to examine metadata for
                    463: #   untitled resources.  Resources may be legitimately untitled, to prevent
                    464: #   searches from locating them.
                    465: #
                    466: #   $str = getTitleString($fullname);
                    467: #       $fullname - Fully qualified filename to check.
                    468: #
                    469: sub getTitleString {
                    470:     my $fullname = shift;
                    471:     my $title    = &Apache::lonnet::metadata($fullname, 'title');
                    472: 
                    473:     unless ($title) {
1.40      www       474: 	$title = "[".&mt('untitled')."]";
1.23      foxr      475:     }
                    476:     return $title;
                    477: }
                    478: 
1.55      www       479: sub getCopyRightString {
                    480:     my $fullname = shift;
                    481:     return &Apache::lonnet::metadata($fullname, 'copyright');
                    482: }
1.61      www       483: 
                    484: sub getSourceRightString {
                    485:     my $fullname = shift;
                    486:     return &Apache::lonnet::metadata($fullname, 'sourceavail');
                    487: }
1.23      foxr      488: #
1.21      foxr      489: #  Put out a directory table row:
                    490: #    putdirectory(r, base, here, dirname, modtime)
                    491: #      r       - Apache request object.
                    492: #      reqfile - File in request.
                    493: #      here    - Where we are in directory tree.
                    494: #      dirname - Name of directory special file.
                    495: #      modtime - Encoded modification time.
                    496: # 
                    497: sub putdirectory {
1.64      raeburn   498:     my ($r, $reqfile, $here, $dirname, $modtime, $resdir, $bombs, $numdir) = @_;
1.21      foxr      499:     # construct the display filename: the directory name unless ..:
                    500:     
                    501:     my $disfilename = $dirname;
                    502:     if ($dirname eq '..') {
1.39      www       503: 	$disfilename = '<i>'.&mt('Parent Directory').'</i>';
1.21      foxr      504:     }
1.64      raeburn   505:     unless ( (($dirname eq '..') && ($reqfile eq '')) || ($dirname eq '.')) {
1.50      www       506: 	my $kaputt=0;
                    507: 	foreach (keys %{$bombs}) {
1.56      albertel  508: 	    if ($_=~m:^\Q$resdir\E/\Q$disfilename\E/:) { $kaputt=1; last; }
1.50      www       509: 	}
1.52      www       510: 	%Apache::lonpublisher::metadatafields=();
                    511: 	%Apache::lonpublisher::metadatakeys=();
                    512: 	my $construct=$here;
1.56      albertel  513: 	$construct=~s:^/priv/(\w+)$:/home/$1/public_html:;
1.52      www       514: 	&Apache::lonpublisher::metaeval(&Apache::lonnet::getfile(
                    515:        				 $construct.'/'.$dirname.'/default.meta'
                    516: 								 ));
1.64      raeburn   517:         my $actionitem = '';
                    518:         if ($dirname eq '..') {
                    519:             $actionitem = 'Go to ...';
                    520:         } else {
                    521:             $actionitem = 
                    522:                     '<form name="dirselect_'.$$numdir.
                    523:                     '" action="/adm/publish" target="_parent">'.
                    524:                     '<select name="diraction" onChange="SetPubDir(this.form,document)">'.
                    525:                       '<option selected="selected">'.&mt('Select action').'</option>'.
                    526:                       '<option value="open">'.&mt('Open').'</option>'.
                    527:                       '<option value="publish">'.&mt('Publish').'</option>'.
                    528:                       '<option value="publishsub">'.&mt('Publish with subdirectories').'</option>'.
                    529:                       '<option value="editcat">'.&mt('Edit catalog information').'</option>'.
                    530:                       '<option value="printdir">'.&mt('Print directory').
                    531:                     '</select>'.
                    532:                      '<input type="hidden" name="filename" value="'.$here.'/'.$dirname.'" />'.
                    533:                      '<input type="hidden" name="pubrec" value="" />'.
                    534:                      '<input type="hidden" name="forcerepub" value="" />'.
                    535:                      '<input type="hidden" name="curseed" value="0" />'.
                    536:                      '<input type="hidden" name="problemtype" value="0" />'.
                    537:                      '<input type="hidden" name="postdata" value="" />'.
                    538:                    '</form>';
                    539:             $$numdir ++;
                    540:         }
1.25      www       541: 	$r->print('<tr bgcolor="#CCCCFF">'.
1.53      www       542: 		  '<td><img src="'.
                    543: 		  $Apache::lonnet::perlvar{'lonIconsURL'}.'/folder_closed.gif" /></td>'.
1.64      raeburn   544: 		  '<td>'.$actionitem.'</td>'.
                    545: 		  '<td><font face="arial"><a href="'.$here.'/'.$dirname.'/" target="_parent">'.
1.54      www       546: 		  $disfilename.'</a></font></td>'.
1.58      www       547: 		        '<td colspan="2">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($resdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'}.' <i>'.
1.53      www       548: 		  $Apache::lonpublisher::metadatafields{'subject'}.'</i> '.
1.52      www       549: 		  $Apache::lonpublisher::metadatafields{'keywords'}.'</td>'.
1.42      www       550: 		  '<td>'.&Apache::lonlocal::locallocaltime($modtime).'</td>'.
1.25      www       551: 		  "</tr>\n");
1.64      raeburn   552:     }
1.21      foxr      553:     return OK;
                    554: }
1.22      foxr      555: #
                    556: #   Put a table row for a file resource.
                    557: #
                    558: sub putresource {
1.64      raeburn   559:     my ($r, $udom, $uname, $filename, $thisdisfn, 
1.22      foxr      560: 	$resdir, $targetdir, $linkdir,
1.64      raeburn   561: 	$cmtime,$bombs,$numres) = @_;
                    562:     my $pubstatus = 'unpublished';
1.47      sakharuk  563:     my $status=&mt('Unpublished');
1.53      www       564:     my $bgcolor='#FFAA99';
1.22      foxr      565:     my $title='&nbsp;';
1.60      albertel  566:     my $publish_button=&mt('Publish');
1.64      raeburn   567: #    my $action_buttons=
                    568: #        '<br /><a target="_parent" href="/adm/cfile?action=delete&filename=/~'.
                    569: #	$uname.'/'.$thisdisfn.'/'.$filename.'">'.
                    570: #	&mt('Delete').'</a>';
1.22      foxr      571:     if (-e $resdir.'/'.$filename) {
                    572: 	my ($rdev,$rino,$rmode,$rnlink,
                    573: 	    $ruid,$rgid,$rrdev,$rsize,
                    574: 	    $ratime,$rmtime,$rctime,
                    575: 	    $rblksize,$rblocks)=stat($resdir.'/'.$filename);
1.64      raeburn   576: 	$publish_button=&mt('Re-publish');
1.22      foxr      577: 	if ($rmtime>=$cmtime) {
1.64      raeburn   578:             $pubstatus = 'published';
1.55      www       579: 	    $status=&mt('Published').'<br />'.
1.61      www       580: 		&mt(&getCopyRightString($targetdir.'/'.$filename)).' '.
                    581: 		&mt(&getSourceRightString($targetdir.'/'.$filename));
1.60      albertel  582: 	    $bgcolor='#CCFF88';
1.40      www       583: 	    if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
1.64      raeburn   584:                 $pubstatus = 'obsolete';
1.41      www       585: 		$status=&mt('Obsolete');
1.40      www       586:                 $bgcolor='#AAAAAA';
1.64      raeburn   587:             }
                    588: #	    } else {
                    589: #		$action_buttons='';
                    590: #	    }
1.23      foxr      591: 	    $title='<a href="/res/'.$targetdir.'/'.$filename.
                    592: 		'.meta" target=cat>'.
1.55      www       593: 		&getTitleString($targetdir.'/'.$filename).'</a>';
1.22      foxr      594: 	} else {
1.64      raeburn   595:             $pubstatus = 'modified';
1.55      www       596: 	    $status=&mt('Modified').'<br />'.
1.61      www       597: 		&mt(&getCopyRightString($targetdir.'/'.$filename)).' '.
                    598: 		&mt(&getSourceRightString($targetdir.'/'.$filename));
1.53      www       599:             $bgcolor='#FFFF77';
1.64      raeburn   600: #	    $action_buttons='';
1.22      foxr      601: 	    $title='<a href="/res/'.$targetdir.'/'.$filename.'.meta" target=cat>'.
1.55      www       602: 		&getTitleString($targetdir.'/'.$filename).'</a>';
1.22      foxr      603: 	    if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
1.57      www       604: 		$status.='<br /><a href="/adm/diff?filename=/~'.$uname.
1.22      foxr      605: 		    $thisdisfn.'/'.$filename.
1.41      www       606: 		    '&versiontwo=priv" target=cat>'.&mt('Diffs').'</a>';
1.22      foxr      607: 	    }
1.51      www       608: 	}
                    609: 	$title.='<br /><a href="/~'.$uname.$thisdisfn.'/'.$filename.'.meta">'. 
1.53      www       610: 	    ($$bombs{$targetdir.'/'.$filename}?'<img src="/adm/lonMisc/bomb.gif" border="0" />':'Edit Metadata').'</a>';
1.22      foxr      611: 	$status.='<br><a href="/adm/retrieve?filename=/~'.$uname.
1.64      raeburn   612: 	    $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Retrieve').'</a>';
1.22      foxr      613:     }
1.33      www       614:     my $editlink='';
1.38      taceyjo1  615:     my $editlink2='';
1.36      www       616:     if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty)$/) {
1.64      raeburn   617: 	$editlink=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('Edit').'</a>)';
1.34      www       618:     }
                    619:     if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
1.64      raeburn   620: 	$editlink=' (<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('EditXML').'</a>)';
                    621: 	$editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceColoredit=1" target="_parent">'.&mt('Edit').'</a>)';
1.43      taceyjo1  622:     }
                    623:     if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.46      taceyjo1  624: 	$editlink=' (<a target="_parent" href="/adm/cfile?decompress=/~'.
                    625: 	      $uname.$thisdisfn.'/'.$filename.'">'.&mt('Decompress').'</a>)';
1.33      www       626:     }
1.64      raeburn   627:     my $pub_select = '';
                    628:     &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres);
1.25      www       629:     $r->print('<tr bgcolor="'.$bgcolor.'">'.
1.53      www       630: 	      '<td>'.($filename=~/[\#\~]$/?'&nbsp;':
                    631: 		      '<img src="'.&Apache::loncommon::icon($filename).'" /></td>').
1.64      raeburn   632:               '<td>'.$pub_select.'</td>'.
1.57      www       633: 	      '<td><font face="arial">'.
1.64      raeburn   634: 	      '<a href="'.$linkdir.'/'.$filename.'" target="_parent">'.
1.54      www       635:                $filename.'</a></font>'.$editlink2.$editlink.
1.22      foxr      636: 	      '</td>'.
                    637: 	      '<td>'.$title.'</td>'.
1.41      www       638: 	      '<td>'.$status.'</td>'.
1.42      www       639: 	      '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'.
1.25      www       640: 	      "</tr>\n");
1.22      foxr      641:     return OK;
1.23      foxr      642: }
1.64      raeburn   643: 
                    644: sub create_pubselect {
                    645:     my ($r,$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres) = @_;
                    646:     $$pub_select = '
                    647: <form name="resselect_'.$$numres.'" action="">
                    648: <select name="reschoice"  onChange="SetResChoice(this.form)">
                    649: <option>'.&mt('Select action').
                    650: '<option value="rename"/>'.&mt('Rename').
                    651: '<option value="move"/>'.&mt('Move').
                    652: '<option value="copy"/>'.&mt('Copy').
                    653: '<option value="publish"/>'.$publish_button;
                    654:     if ($pubstatus eq 'obsolete' || $pubstatus eq 'unpublished') {
                    655:         $$pub_select .= '
                    656: <option value="delete"/>'.&mt('Delete');
                    657:     } else {
                    658:         $$pub_select .= '
                    659: <option value="obsolete"/>'.&mt('Mark obsolete');
                    660:     }
                    661:     $$pub_select .= '
                    662: <option value="print"/>'.&mt('Print');
                    663: 
                    664: # check for versions
                    665:     my $versions = &check_for_versions($r,'/'.$filename,$udom,$uname);
                    666:     if ($versions > 0) {
                    667:         $$pub_select .='
                    668: <option value="retrieve"/>'.&mt('Retrieve old version');
                    669:     }
                    670:     $$pub_select .= '
                    671: </select>
                    672: <input type="hidden" name="filename" value="/~'.
                    673:  $uname.'/'.$thisdisfn.'/'.$filename.'"></form>';
                    674:     $$numres ++;
                    675: }
                    676: 
                    677: sub check_for_versions {
                    678:     my ($r,$fn,$udom,$uname) = @_;
                    679:     my $versions = 0;
                    680:     my $docroot=$r->dir_config('lonDocRoot');
                    681:     my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
                    682:     my $resdir=$resfn;
                    683:     $resdir=~s/\/[^\/]+$/\//;
                    684:     $fn=~/\/([^\/]+)\.(\w+)$/;
                    685:     my $main=$1;
                    686:     my $suffix=$2;
                    687:     opendir(DIR,$resdir);
                    688:     while (my $filename=readdir(DIR)) {
                    689:         if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
                    690:             $versions ++;        
                    691:         }
                    692:     }
                    693:     return $versions;
                    694: }
                    695: 
1.23      foxr      696: #
                    697: #   Categorize files in the directory.
                    698: #   For each file in a list of files in a file directory, 
                    699: #   the  file categorized as one of:
                    700: #    - directory  
                    701: #    - sequence
                    702: #    - problem 
                    703: #    - Other resource.
                    704: #
                    705: #   For each file the modification date is determined as well.
                    706: #   Returned is a list of sublists:
                    707: #    (directories, sequences, problems, other)
                    708: #   each of the sublists contains entries of the following form (sorted by
                    709: #   filename):
                    710: #     (filename, typecode, lastmodtime)
                    711: #
                    712: #   $list = CategorizeFiles($location, $files)
                    713: #       $location   - Directory in which the files live (relative to our
                    714: #                     execution.
                    715: #       $files      - list of files.
                    716: #
                    717: sub CategorizeFiles {
                    718:     my $location = shift;
                    719:     my $files    = shift;
1.22      foxr      720: }
                    721: 
1.4       www       722: 1;
                    723: __END__
1.17      harris41  724: 
                    725: =head1 NAME
                    726: 
1.32      www       727: Apache::lonpubdir - Construction space directory lister
1.17      harris41  728: 
                    729: =head1 SYNOPSIS
                    730: 
                    731: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
                    732: 
1.18      harris41  733:  <LocationMatch "^/\~.*/$">
                    734:  PerlAccessHandler       Apache::loncacc
                    735:  SetHandler perl-script
                    736:  PerlHandler Apache::lonpubdir
                    737:  ErrorDocument     403 /adm/login
                    738:  ErrorDocument     404 /adm/notfound.html
                    739:  ErrorDocument     406 /adm/unauthorized.html
                    740:  ErrorDocument	  500 /adm/errorhandler
                    741:  </LocationMatch>
                    742: 
                    743:  <Location /adm/pubdir>
                    744:  PerlAccessHandler       Apache::lonacc
                    745:  SetHandler perl-script
                    746:  PerlHandler Apache::lonpubdir
                    747:  ErrorDocument     403 /adm/login
                    748:  ErrorDocument     404 /adm/notfound.html
                    749:  ErrorDocument     406 /adm/unauthorized.html
                    750:  ErrorDocument	  500 /adm/errorhandler
                    751:  </Location>
1.17      harris41  752: 
                    753: =head1 INTRODUCTION
                    754: 
1.18      harris41  755: This module publishes a directory of files.
1.17      harris41  756: 
                    757: This is part of the LearningOnline Network with CAPA project
                    758: described at http://www.lon-capa.org.
                    759: 
                    760: =head1 HANDLER SUBROUTINE
                    761: 
                    762: This routine is called by Apache and mod_perl.
                    763: 
                    764: =over 4
                    765: 
                    766: =item *
                    767: 
                    768: read in information
                    769: 
                    770: =item *
                    771: 
                    772: start page output
                    773: 
                    774: =item *
                    775: 
                    776: run through list of files and attempt to publish unhidden files
                    777: 
                    778: =back
                    779: 
                    780: =cut

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