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

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.