File:  [LON-CAPA] / loncom / publisher / lonpubdir.pm
Revision 1.68: download - view: text, annotated - select for diffs
Thu Dec 2 19:45:39 2004 UTC (19 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Fixing a number of small errors. Some compaction to conserve screen area.  Removed some unneeded javascript functions - getcurrseed(), getproblemtype().

    1: # The LearningOnline Network with CAPA
    2: # Construction Space Directory Lister
    3: #
    4: # $Id: lonpubdir.pm,v 1.68 2004/12/02 19:45:39 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:   if ($ENV{'environment.remote'} eq 'off') {
   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 .= &Apache::loncommon::help_open_menu('','','','',3,'Authoring').
  199:         '<font face="Arial, Helvetica, sans-serif" size="+1"><b>Construction Space</b>:</font>&nbsp;'.
  200:         '<form name="dirs" method="post" action="'.$formaction.
  201:         '" target="_parent"><tt><b>'.
  202:         &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />".
  203:         &Apache::lonhtmlcommon::select_recent('construct','recent',
  204:                  'this.form.action=this.form.recent.value;this.form.submit()').
  205:               '</form>';
  206:     &Apache::lonhtmlcommon::store_recent('construct',$formaction,$formaction);
  207:     if ($ENV{'environment.remote'} eq 'off') {
  208: 	$ENV{'request.noversionuri'}=$currdir.'/';
  209: 	$r->print(&Apache::loncommon::bodytag('Construction Space',undef,undef,undef,undef,undef,$pagetitle));
  210:     } else {
  211: 	$r->print($pagetitle);
  212:     }
  213:     my $pubdirscript=(<<ENDPUBDIRSCRIPT);
  214: <script>
  215: // Store directory location for menu bar to find
  216: 
  217: parent.lastknownpriv='/~$uname$thisdisfn/';
  218: 
  219: // Confirmation dialogues
  220: 
  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:             top.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:   
  239:     function pubdir(theform) {
  240: 	if (confirm('Publish complete directory?')) {
  241:             forcepub(theform)
  242: 	    theform.submit();
  243:         }
  244:     }
  245:     function pubrecdir(theform) {
  246: 	if (confirm('Publish directory and all subdirectories?')) {
  247:             forcepub(theform);
  248:             theform.pubrec.value='1';
  249: 	    theform.submit();
  250:         }
  251:     }
  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:             top.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:             top.location=theform.filename.value+'default.meta'
  280:         }
  281:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "printdir") {
  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:           var pubform = document.pubresource
  307:           pubform.filename.value = theform.filename.value
  308:           alert("You will be taken to the publication page.\\nCheck the 'Obsolete' checkbox at the bottom of the page, and click 'Finalize Publication'.")
  309:           pubform.submit()
  310:       }
  311:       if (activity == 'print') {
  312:           document.printresource.postdata.value = theform.filename.value
  313:           document.printresource.submit()
  314:       }
  315:       if (activity == 'retrieve') {
  316:           document.retrieveres.filename.value = theform.filename.value
  317:           document.retrieveres.submit()
  318:       }
  319:       return
  320:     }
  321:     function changename(theform,activity) {
  322:         var newname=prompt('New Name');
  323:         if (newname == "" || !newname)  {
  324:             return
  325:         }
  326:         document.moveresource.newfilename.value = newname
  327:         document.moveresource.filename.value = theform.filename.value
  328:         document.moveresource.action.value = activity
  329:         document.moveresource.submit();
  330:     }
  331: </script>
  332: ENDPUBDIRSCRIPT
  333:     $r->print($pubdirscript);
  334: 
  335:     if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
  336: 	$r->print('<h3>'.&mt('Co-Author').': '.$uname.' at '.$udom.
  337: 		  '</h3>');
  338:     }
  339: }
  340: 
  341: sub dircontrols {
  342:     my ($r,$uname,$udom,$thisdisfn) = @_;
  343:     $r->print(<<END);
  344:         <table cellspacing="4" cellpadding="4" width="100%">
  345:          <tr>
  346:           <td bgcolor="#DDDDDD" align="middle"><font face="Arial, Helvetica, sans-serif" size="-1"><b>Actions for current directory</b></font></td>
  347:           <td bgcolor="#DDDDDD" align="middle"><font face="Arial, Helvetica, sans-serif" size="-1"><b>Upload a new document</b></font></td>
  348:           <td bgcolor="#DDDDDD" align="middle"><font face="Arial, Helvetica, sans-serif" size="-1"><b>Create a new directory or LON-CAPA document</b></font></td>
  349:         </tr>
  350:         <tr>
  351:          <td bgcolor="#ccddaa" valign="top" align="center">
  352:           <form name="curractions" method="post" action="">
  353:            <select name="dirtask" onChange="currdiract(this.form)">
  354:             <option>Select action</option>
  355:             <option value="publish">Publish directory</option>
  356:             <option value="publishsub">Publish with subdirectories</option>
  357:             <option value="editcat">Edit catalog information</option>
  358:             <option value="printdir">Print contents of directory</option>
  359:            </select>
  360:            <input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
  361:           </form>
  362:           <form name="publishdir" method="post" action="/adm/publish" target="_parent">
  363:            <input type="hidden" name="pubrec" value="" />
  364:            <input type="hidden" name="filename" value="" />
  365:            <input type="hidden" name="forcerepub" value="NO" />
  366:           </form>
  367:           <form name="printdir" method="post" action="/adm/printout" target="_parent">
  368:            <input type="hidden" name="postdata" value="" />
  369:           </form>
  370:          </td>
  371:          <td bgcolor="#ccddaa" valign="top" align="center">
  372: 	    <form name="upublisher" enctype="multipart/form-data" method="post" action="/adm/upload" target="_parent">
  373: 	      <input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
  374: 	      <input type="file" name="upfile" size="20" />
  375: 	      <input type="button" value="Upload file"  onclick="checkUpload(this.form)" />
  376: 	    </form>
  377: 	 </td>
  378: 	 <td bgcolor="#ccddaa" align="center">
  379: 	    <form name="fileaction" method="post" action="/adm/cfile" target="_parent">
  380: 	      <nobr>
  381: 		<input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
  382: 		  <select name="action">
  383: 		    <option>Select action</option>
  384: 		    <option value="newfile">New file:</option>
  385: 		    <option value="newhtmlfile">New HTML file:</option>
  386: 		    <option value="newproblemfile">New problem:</option>
  387:                     <option value="newpagefile">New assembled page:</option>
  388:                     <option value="newsequencefile">New assembled sequence:</option>
  389:                     <option value="newrightsfile">New custom rights file:</option>
  390:                     <option value="newstyfile">New style file:</option>
  391: 		    <option value="newdir">New subdirectory:</option>
  392: 		  </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()" />
  393: 		 </nobr>
  394: 		</form>
  395: 	  </td>
  396:          </tr>
  397:         </table>
  398: END
  399: }
  400: 
  401: sub resourceactions {
  402:     my ($r,$uname,$udom,$thisdisfn) = @_;
  403:     $r->print(<<END);
  404:        <form name="moveresource" action="/adm/cfile" target="_parent" method="post">
  405:          <input type="hidden" name="filename" value="" />
  406:          <input type="hidden" name="newfilename" value="" />
  407:          <input type="hidden" name="action" value="" />
  408:        </form>
  409:        <form name="delresource" action="/adm/cfile" target="_parent" method="post">
  410:          <input type="hidden" name="filename" value="" />
  411:          <input type="hidden" name="action" value="delete" />
  412:        </form>
  413:        <form name="pubresource" action="/adm/publish" target="_parent" method="post">
  414:          <input type="hidden" name="pubrec" value="" />
  415:          <input type="hidden" name="filename" value="" />
  416:          <input type="hidden" name="forcerepub" value="NO" />
  417:        </form>
  418:        <form name="printresource" action="/adm/printout" target="_parent" method="post">
  419:            <input type="hidden" name="postdata" value="" />
  420:        </form>
  421:        <form name="retrieveres" action="/adm/retrieve" target="_parent" method="post">
  422:            <input type="hidden" name="filename" value="" />
  423:        </form>
  424: END
  425: }
  426: 
  427: #
  428: #   Get the title string or "[untitled]" if the file has no title metadata:
  429: #   Without the latter substitution, it's impossible to examine metadata for
  430: #   untitled resources.  Resources may be legitimately untitled, to prevent
  431: #   searches from locating them.
  432: #
  433: #   $str = getTitleString($fullname);
  434: #       $fullname - Fully qualified filename to check.
  435: #
  436: sub getTitleString {
  437:     my $fullname = shift;
  438:     my $title    = &Apache::lonnet::metadata($fullname, 'title');
  439: 
  440:     unless ($title) {
  441: 	$title = "[".&mt('untitled')."]";
  442:     }
  443:     return $title;
  444: }
  445: 
  446: sub getCopyRightString {
  447:     my $fullname = shift;
  448:     return &Apache::lonnet::metadata($fullname, 'copyright');
  449: }
  450: 
  451: sub getSourceRightString {
  452:     my $fullname = shift;
  453:     return &Apache::lonnet::metadata($fullname, 'sourceavail');
  454: }
  455: #
  456: #  Put out a directory table row:
  457: #    putdirectory(r, base, here, dirname, modtime)
  458: #      r       - Apache request object.
  459: #      reqfile - File in request.
  460: #      here    - Where we are in directory tree.
  461: #      dirname - Name of directory special file.
  462: #      modtime - Encoded modification time.
  463: # 
  464: sub putdirectory {
  465:     my ($r, $reqfile, $here, $dirname, $modtime, $resdir, $bombs, $numdir) = @_;
  466:     # construct the display filename: the directory name unless ..:
  467:     
  468:     my $disfilename = $dirname;
  469:     if ($dirname eq '..') {
  470: 	$disfilename = '<i>'.&mt('Parent Directory').'</i>';
  471:     }
  472:     unless ( (($dirname eq '..') && ($reqfile eq '')) || ($dirname eq '.')) {
  473: 	my $kaputt=0;
  474: 	foreach (keys %{$bombs}) {
  475: 	    if ($_=~m:^\Q$resdir\E/\Q$disfilename\E/:) { $kaputt=1; last; }
  476: 	}
  477: 	%Apache::lonpublisher::metadatafields=();
  478: 	%Apache::lonpublisher::metadatakeys=();
  479: 	my $construct=$here;
  480: 	$construct=~s:^/priv/(\w+)$:/home/$1/public_html:;
  481:         my $dirpath = $here;
  482:         $dirpath=~s:^/priv/:/~:;
  483: 	&Apache::lonpublisher::metaeval(&Apache::lonnet::getfile(
  484:        				 $construct.'/'.$dirname.'/default.meta'
  485: 								 ));
  486:         my $actionitem = '';
  487:         if ($dirname eq '..') {
  488:             $actionitem = 'Go to ...';
  489:         } else {
  490:             $actionitem = 
  491:                     '<form name="dirselect_'.$$numdir.
  492:                     '" action="/adm/publish" target="_parent">'.
  493:                     '<select name="diraction" onChange="SetPubDir(this.form,document)">'.
  494:                       '<option selected="selected">'.&mt('Select action').'</option>'.
  495:                       '<option value="open">'.&mt('Open').'</option>'.
  496:                       '<option value="publish">'.&mt('Publish').'</option>'.
  497:                       '<option value="publishsub">'.&mt('Publish with subdirectories').'</option>'.
  498:                       '<option value="editcat">'.&mt('Edit catalog information').'</option>'.
  499:                       '<option value="printdir">'.&mt('Print directory').
  500:                     '</select>'.
  501:                      '<input type="hidden" name="filename" value="'.$dirpath.'/'.$dirname.'/" />'.
  502:                      '<input type="hidden" name="pubrec" value="" />'.
  503:                      '<input type="hidden" name="forcerepub" value="" />'.
  504:                      '<input type="hidden" name="postdata" value="" />'.
  505:                    '</form>';
  506:             $$numdir ++;
  507:         }
  508: 	$r->print('<tr bgcolor="#CCCCFF">'.
  509: 		  '<td><img src="'.
  510: 		  $Apache::lonnet::perlvar{'lonIconsURL'}.'/folder_closed.gif" /></td>'.
  511: 		  '<td>'.$actionitem.'</td>'.
  512: 		  '<td><font face="arial"><a href="'.$here.'/'.$dirname.'/" target="_parent">'.
  513: 		  $disfilename.'</a></font></td>'.
  514: 		        '<td colspan="2">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($resdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'}.' <i>'.
  515: 		  $Apache::lonpublisher::metadatafields{'subject'}.'</i> '.
  516: 		  $Apache::lonpublisher::metadatafields{'keywords'}.'</td>'.
  517: 		  '<td>'.&Apache::lonlocal::locallocaltime($modtime).'</td>'.
  518: 		  "</tr>\n");
  519:     }
  520:     return OK;
  521: }
  522: #
  523: #   Put a table row for a file resource.
  524: #
  525: sub putresource {
  526:     my ($r, $udom, $uname, $filename, $thisdisfn, 
  527: 	$resdir, $targetdir, $linkdir,
  528: 	$cmtime,$bombs,$numres) = @_;
  529:     my $pubstatus = 'unpublished';
  530:     my $status=&mt('Unpublished');
  531:     my $bgcolor='#FFAA99';
  532:     my $title='&nbsp;';
  533:     my $publish_button=&mt('Publish');
  534: #    my $action_buttons=
  535: #        '<br /><a target="_parent" href="/adm/cfile?action=delete&filename=/~'.
  536: #	$uname.'/'.$thisdisfn.'/'.$filename.'">'.
  537: #	&mt('Delete').'</a>';
  538:     if (-e $resdir.'/'.$filename) {
  539: 	my ($rdev,$rino,$rmode,$rnlink,
  540: 	    $ruid,$rgid,$rrdev,$rsize,
  541: 	    $ratime,$rmtime,$rctime,
  542: 	    $rblksize,$rblocks)=stat($resdir.'/'.$filename);
  543: 	$publish_button=&mt('Re-publish');
  544: 	if ($rmtime>=$cmtime) {
  545:             $pubstatus = 'published';
  546: 	    $status=&mt('Published').'<br />'.
  547: 		&mt(&getCopyRightString($targetdir.'/'.$filename)).' '.
  548: 		&mt(&getSourceRightString($targetdir.'/'.$filename));
  549: 	    $bgcolor='#CCFF88';
  550: 	    if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
  551:                 $pubstatus = 'obsolete';
  552: 		$status=&mt('Obsolete');
  553:                 $bgcolor='#AAAAAA';
  554:             }
  555: #	    } else {
  556: #		$action_buttons='';
  557: #	    }
  558: 	    $title='<a href="/res/'.$targetdir.'/'.$filename.
  559: 		'.meta" target=cat>'.
  560: 		&getTitleString($targetdir.'/'.$filename).'</a>';
  561: 	} else {
  562:             $pubstatus = 'modified';
  563: 	    $status=&mt('Modified').'<br />'.
  564: 		&mt(&getCopyRightString($targetdir.'/'.$filename)).' '.
  565: 		&mt(&getSourceRightString($targetdir.'/'.$filename));
  566:             $bgcolor='#FFFF77';
  567: #	    $action_buttons='';
  568: 	    $title='<a href="/res/'.$targetdir.'/'.$filename.'.meta" target=cat>'.
  569: 		&getTitleString($targetdir.'/'.$filename).'</a>';
  570: 	    if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
  571: 		$status.='<br /><a href="/adm/diff?filename=/~'.$uname.
  572: 		    $thisdisfn.'/'.$filename.
  573: 		    '&versiontwo=priv" target=cat>'.&mt('Diffs').'</a>';
  574: 	    }
  575: 	}
  576: 	$title.='<br /><a href="/~'.$uname.$thisdisfn.'/'.$filename.'.meta">'. 
  577: 	    ($$bombs{$targetdir.'/'.$filename}?'<img src="/adm/lonMisc/bomb.gif" border="0" />':'Edit Metadata').'</a>';
  578: 	$status.='<br><a href="/adm/retrieve?filename=/~'.$uname.
  579: 	    $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Retrieve').'</a>';
  580:     }
  581:     my $editlink='';
  582:     my $editlink2='';
  583:     if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty)$/) {
  584: 	$editlink=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('Edit').'</a>)';
  585:     }
  586:     if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
  587: 	$editlink=' (<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('EditXML').'</a>)';
  588: 	$editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceColoredit=1" target="_parent">'.&mt('Edit').'</a>)';
  589:     }
  590:     if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
  591: 	$editlink=' (<a target="_parent" href="/adm/cfile?decompress=/~'.
  592: 	      $uname.$thisdisfn.'/'.$filename.'">'.&mt('Decompress').'</a>)';
  593:     }
  594:     my $pub_select = '';
  595:     &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres);
  596:     $r->print('<tr bgcolor="'.$bgcolor.'">'.
  597: 	      '<td>'.($filename=~/[\#\~]$/?'&nbsp;':
  598: 		      '<img src="'.&Apache::loncommon::icon($filename).'" /></td>').
  599:               '<td>'.$pub_select.'</td>'.
  600: 	      '<td><font face="arial">'.
  601: 	      '<a href="'.$linkdir.'/'.$filename.'" target="_parent">'.
  602:                $filename.'</a></font>'.$editlink2.$editlink.
  603: 	      '</td>'.
  604: 	      '<td>'.$title.'</td>'.
  605: 	      '<td>'.$status.'</td>'.
  606: 	      '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'.
  607: 	      "</tr>\n");
  608:     return OK;
  609: }
  610: 
  611: sub create_pubselect {
  612:     my ($r,$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres) = @_;
  613:     $$pub_select = '
  614: <form name="resselect_'.$$numres.'" action="">
  615: <select name="reschoice"  onChange="SetResChoice(this.form)">
  616: <option>'.&mt('Select action').
  617: '<option value="copy"/>'.&mt('Copy');
  618:     if ($pubstatus eq 'obsolete' || $pubstatus eq 'unpublished') {
  619:         $$pub_select .= 
  620: '<option value="rename"/>'.&mt('Rename').
  621: '<option value="move"/>'.&mt('Move').
  622: '<option value="delete"/>'.&mt('Delete');
  623:     } else {
  624:         $$pub_select .= '
  625: <option value="obsolete"/>'.&mt('Mark obsolete');
  626:     }
  627: # check for versions
  628:     my $versions = &check_for_versions($r,'/'.$filename,$udom,$uname);
  629:     if ($versions > 0) {
  630:         $$pub_select .='
  631: <option value="retrieve"/>'.&mt('Retrieve old version');
  632:     }
  633:     $$pub_select .= '
  634: <option value="publish"/>'.$publish_button.
  635: '<option value="print"/>'.&mt('Print').
  636: '</select>
  637: <input type="hidden" name="filename" value="/~'.
  638:  $uname.$thisdisfn.'/'.$filename.'"></form>';
  639:     $$numres ++;
  640: }
  641: 
  642: sub check_for_versions {
  643:     my ($r,$fn,$udom,$uname) = @_;
  644:     my $versions = 0;
  645:     my $docroot=$r->dir_config('lonDocRoot');
  646:     my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
  647:     my $resdir=$resfn;
  648:     $resdir=~s/\/[^\/]+$/\//;
  649:     $fn=~/\/([^\/]+)\.(\w+)$/;
  650:     my $main=$1;
  651:     my $suffix=$2;
  652:     opendir(DIR,$resdir);
  653:     while (my $filename=readdir(DIR)) {
  654:         if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
  655:             $versions ++;        
  656:         }
  657:     }
  658:     return $versions;
  659: }
  660: 
  661: #
  662: #   Categorize files in the directory.
  663: #   For each file in a list of files in a file directory, 
  664: #   the  file categorized as one of:
  665: #    - directory  
  666: #    - sequence
  667: #    - problem 
  668: #    - Other resource.
  669: #
  670: #   For each file the modification date is determined as well.
  671: #   Returned is a list of sublists:
  672: #    (directories, sequences, problems, other)
  673: #   each of the sublists contains entries of the following form (sorted by
  674: #   filename):
  675: #     (filename, typecode, lastmodtime)
  676: #
  677: #   $list = CategorizeFiles($location, $files)
  678: #       $location   - Directory in which the files live (relative to our
  679: #                     execution.
  680: #       $files      - list of files.
  681: #
  682: sub CategorizeFiles {
  683:     my $location = shift;
  684:     my $files    = shift;
  685: }
  686: 
  687: 1;
  688: __END__
  689: 
  690: =head1 NAME
  691: 
  692: Apache::lonpubdir - Construction space directory lister
  693: 
  694: =head1 SYNOPSIS
  695: 
  696: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
  697: 
  698:  <LocationMatch "^/\~.*/$">
  699:  PerlAccessHandler       Apache::loncacc
  700:  SetHandler perl-script
  701:  PerlHandler Apache::lonpubdir
  702:  ErrorDocument     403 /adm/login
  703:  ErrorDocument     404 /adm/notfound.html
  704:  ErrorDocument     406 /adm/unauthorized.html
  705:  ErrorDocument	  500 /adm/errorhandler
  706:  </LocationMatch>
  707: 
  708:  <Location /adm/pubdir>
  709:  PerlAccessHandler       Apache::lonacc
  710:  SetHandler perl-script
  711:  PerlHandler Apache::lonpubdir
  712:  ErrorDocument     403 /adm/login
  713:  ErrorDocument     404 /adm/notfound.html
  714:  ErrorDocument     406 /adm/unauthorized.html
  715:  ErrorDocument	  500 /adm/errorhandler
  716:  </Location>
  717: 
  718: =head1 INTRODUCTION
  719: 
  720: This module publishes a directory of files.
  721: 
  722: This is part of the LearningOnline Network with CAPA project
  723: described at http://www.lon-capa.org.
  724: 
  725: =head1 HANDLER SUBROUTINE
  726: 
  727: This routine is called by Apache and mod_perl.
  728: 
  729: =over 4
  730: 
  731: =item *
  732: 
  733: read in information
  734: 
  735: =item *
  736: 
  737: start page output
  738: 
  739: =item *
  740: 
  741: run through list of files and attempt to publish unhidden files
  742: 
  743: =back
  744: 
  745: =cut

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