File:  [LON-CAPA] / loncom / publisher / lonpubdir.pm
Revision 1.91: download - view: text, annotated - select for diffs
Wed May 17 13:41:45 2006 UTC (18 years ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #1431: if the file did not change, maintain the publication status

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

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