File:  [LON-CAPA] / loncom / publisher / lonpubdir.pm
Revision 1.64: download - view: text, annotated - select for diffs
Fri Oct 29 18:40:40 2004 UTC (19 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Changes to allow construction space operations without need for Remote Control.  The top frame - publisher.html is not used in inline mode.  Work in progress.

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

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