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

1.1       www         1: # The LearningOnline Network with CAPA
1.32      www         2: # Construction Space Directory Lister
1.16      albertel    3: #
1.141   ! www         4: # $Id: lonpubdir.pm,v 1.140 2011/12/23 17:21:18 www 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.91      www        39: use Apache::londiff();
1.39      www        40: use Apache::lonlocal;
1.50      www        41: use Apache::lonmsg;
1.64      raeburn    42: use Apache::lonmenu;
                     43: use Apache::lonnet;
1.98      albertel   44: use LONCAPA;
1.1       www        45: 
                     46: sub handler {
                     47: 
                     48:   my $r=shift;
                     49: 
1.23      foxr       50:   # Validate access to the construction space and get username@domain.
1.6       www        51: 
                     52:   my $uname;
                     53:   my $udom;
                     54: 
1.127     www        55:   ($uname,$udom)=&Apache::loncacc::constructaccess($r->uri); 
1.9       www        56:   unless (($uname) && ($udom)) {
1.6       www        57:      return HTTP_NOT_ACCEPTABLE;
                     58:   }
1.23      foxr       59: 
1.127     www        60: # ----------------------------------------------------------- Start page output
1.23      foxr       61: 
1.127     www        62:   my $fn=$r->filename;
1.128     www        63:   $fn=~s/\/$//;
1.1       www        64: 
1.127     www        65:   my $thisdisfn=$fn;
                     66:   my $docroot=$r->dir_config('lonDocRoot');     # Apache  londocument root.
                     67:   $thisdisfn=~s/^\Q$docroot\E\/priv//;
1.1       www        68: 
1.127     www        69:   my $resdir=$docroot.'/res'.$thisdisfn; # Resource directory
                     70:   my $targetdir='/res'.$thisdisfn; # Publication target directory.
                     71:   my $linkdir='/priv'.$thisdisfn;      # Full URL name of constr space.
1.1       www        72: 
1.50      www        73:   my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
1.1       www        74: 
1.26      www        75:   &startpage($r, $uname, $udom, $thisdisfn);   # Put out the start of page.
1.126     droeschl   76:   &dircontrols($r,$uname,$udom,$thisdisfn);    # Put out actions for directory, 
1.64      raeburn    77:                                                # browse/upload + new file page.
                     78:   &resourceactions($r,$uname,$udom,$thisdisfn); #Put out form used for printing/deletion etc.
                     79: 
                     80:   my $numdir = 0;
                     81:   my $numres = 0;
1.6       www        82:   
1.50      www        83:   # Start off the directory table.
1.115     bisitz     84:   $r->print(&Apache::loncommon::start_data_table()
                     85:            .&Apache::loncommon::start_data_table_header_row()
                     86:            .'<th>'.&mt('Type').'</th>'
                     87:            .'<th>'.&mt('Actions').'</th>'
                     88:            .'<th>'.&mt('Name').'</th>'
                     89:            .'<th>'.&mt('Title').'</th>'
                     90:            .'<th colspan="2">'.&mt('Status').'</th>'
                     91:            .'<th>'.&mt('Last Modified').'</th>'
                     92:            .&Apache::loncommon::end_data_table_header_row()
                     93:   );
1.1       www        94: 
1.2       www        95:   my $filename;
1.23      foxr       96:   my $dirptr=16384;		# Mask indicating a directory in stat.cmode.
1.1       www        97: 
1.2       www        98:   opendir(DIR,$fn);
1.44      albertel   99:   my @files=sort {uc($a) cmp uc($b)} (readdir(DIR));
1.11      albertel  100:   foreach my $filename (@files) {
1.2       www       101:      my ($cdev,$cino,$cmode,$cnlink,
                    102:          $cuid,$cgid,$crdev,$csize,
                    103:          $catime,$cmtime,$cctime,
                    104:          $cblksize,$cblocks)=stat($fn.'/'.$filename);
1.12      www       105: 
1.10      albertel  106:      my $extension='';
                    107:      if ($filename=~/\.(\w+)$/) { $extension=$1; }
1.15      matthew   108:      if ($cmode&$dirptr) {
1.129     www       109: 	 &putdirectory($r, $thisdisfn, $linkdir, $filename, $cmtime,$targetdir,\%bombs,\$numdir);
1.17      harris41  110:      } elsif (&Apache::loncommon::fileembstyle($extension) ne 'hdn') {
1.129     www       111: 	 &putresource($r, $udom, $uname, $filename, $thisdisfn, $resdir, 
1.64      raeburn   112: 		     $targetdir, $linkdir, $cmtime,\%bombs,\$numres);
1.14      albertel  113:      } else {
1.15      matthew   114: 	# "hidden" extension and not a directory, so hide it away.
1.2       www       115:      }
                    116:   }
                    117:   closedir(DIR);
                    118: 
1.115     bisitz    119:   $r->print(&Apache::loncommon::end_data_table()
                    120:            .&Apache::loncommon::end_page()
                    121:   );
1.1       www       122:   return OK;  
                    123: }
1.127     www       124: 
1.23      foxr      125: #
                    126: #   Output the header of the page.  This includes:
                    127: #   - The HTML header 
                    128: #   - The H1/H3  stuff which includes the directory.
                    129: #
                    130: #     startpage($r, $uame, $udom, $thisdisfn);
                    131: #      $r     - The apache request object.
                    132: #      $uname - User name.
                    133: #      $udom  - Domain name the user is logged in under.
                    134: #      $thisdisfn - Displayable version of the filename.
1.26      www       135: 
1.23      foxr      136: sub startpage {
                    137:     my ($r, $uname, $udom, $thisdisfn) = @_;
1.39      www       138:     &Apache::loncommon::content_type($r,'text/html');
1.23      foxr      139:     $r->send_http_header;
1.64      raeburn   140: 
1.132     www       141:     my $formaction='/priv'.$thisdisfn.'/';
1.89      albertel  142:     $formaction=~s|/+|/|g;
1.66      raeburn   143:     &Apache::lonhtmlcommon::store_recent('construct',$formaction,$formaction);
1.121     bisitz    144: 
1.125     droeschl  145:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    146:     &Apache::lonhtmlcommon::add_breadcrumb({
                    147:         'text'  => 'Construction Space',
1.137     raeburn   148:         'href'  => &Apache::loncommon::authorspace($formaction),
1.125     droeschl  149:     });
                    150:     # breadcrumbs (and tools) will be created 
                    151:     # in start_page->bodytag->innerregister
                    152: 
1.132     www       153:     $env{'request.noversionuri'}=$formaction;
1.126     droeschl  154:     $r->print(&Apache::loncommon::start_page('Construction Space',undef));
1.90      albertel  155: 
1.121     bisitz    156:     $r->print(&Apache::loncommon::head_subbox(
1.135     raeburn   157:                 &Apache::loncommon::CSTR_pageheader()));
1.121     bisitz    158: 
1.101     albertel  159:     my $esc_thisdisfn = &Apache::loncommon::escape_single($thisdisfn);
1.108     raeburn   160:     my $doctitle = 'LON-CAPA '.&mt('Construction Space');
1.109     bisitz    161:     my $newname = &mt('New Name');
1.29      www       162:     my $pubdirscript=(<<ENDPUBDIRSCRIPT);
1.77      albertel  163: <script type="text/javascript">
1.107     bisitz    164: top.document.title = '$esc_thisdisfn/ - $doctitle';
1.37      www       165: // Store directory location for menu bar to find
                    166: 
1.132     www       167: parent.lastknownpriv='/priv$esc_thisdisfn/';
1.37      www       168: 
                    169: // Confirmation dialogues
                    170: 
1.64      raeburn   171:     function currdiract(theform) {
                    172:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publish') {
1.79      www       173:             document.publishdir.filename.value = theform.filename.value;
                    174: 	    document.publishdir.submit();
1.64      raeburn   175:         }
1.113     schafran  176:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editmeta') {
1.66      raeburn   177:             top.location=theform.filename.value+'default.meta'
1.64      raeburn   178:         }
                    179:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) {
                    180:             document.printdir.postdata.value=theform.filename.value
                    181:             document.printdir.submit();
                    182:         }
1.88      raeburn   183:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == "delete") {
                    184:               var delform = document.delresource
                    185:               delform.filename.value = theform.filename.value
                    186:               delform.submit()
                    187:         }
1.64      raeburn   188:     }
                    189:   
                    190:     function checkUpload(theform) {
                    191:         if (theform.file == '') {
                    192:             alert("Please use 'Browse..' to choose a file first, before uploading")
                    193:             return 
                    194:         }
                    195:         theform.submit()  
                    196:     }
                    197: 
                    198:     function SetPubDir(theform,printForm) {
                    199:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "open") {
1.75      albertel  200:             top.location = theform.openname.value
1.64      raeburn   201:             return
                    202:         }
                    203:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "publish") {
1.79      www       204:             theform.submit();
1.64      raeburn   205:         }
1.113     schafran  206:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "editmeta") {
1.66      raeburn   207:             top.location=theform.filename.value+'default.meta'
1.64      raeburn   208:         }
1.68      raeburn   209:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "printdir") {
1.64      raeburn   210:             theform.action = '/adm/printout'
                    211:             theform.postdata.value = theform.filename.value
                    212:             theform.submit()
                    213:         }
1.88      raeburn   214:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "delete") {
                    215:               var delform = document.delresource
                    216:               delform.filename.value = theform.filename.value
                    217:               delform.submit()
                    218:         }
1.64      raeburn   219:         return
                    220:     }
                    221:     function SetResChoice(theform) {
                    222:       var activity = theform.reschoice.options[theform.reschoice.selectedIndex].value
                    223:       if ((activity == 'rename') || (activity == 'copy') || (activity == 'move')) {
                    224:           changename(theform,activity)
                    225:       }
                    226:       if (activity == 'publish') {
                    227:           var pubform = document.pubresource
                    228:           pubform.filename.value = theform.filename.value
                    229:           pubform.submit()
                    230:       }
                    231:       if (activity == 'delete') {
                    232:           var delform = document.delresource
                    233:           delform.filename.value = theform.filename.value
1.71      raeburn   234:           delform.submit()
1.64      raeburn   235:       }
                    236:       if (activity == 'obsolete') {
1.68      raeburn   237:           var pubform = document.pubresource
                    238:           pubform.filename.value = theform.filename.value
1.80      www       239:           pubform.makeobsolete.value=1;
1.68      raeburn   240:           pubform.submit()
1.64      raeburn   241:       }
                    242:       if (activity == 'print') {
1.68      raeburn   243:           document.printresource.postdata.value = theform.filename.value
1.64      raeburn   244:           document.printresource.submit()
                    245:       }
                    246:       if (activity == 'retrieve') {
1.68      raeburn   247:           document.retrieveres.filename.value = theform.filename.value
                    248:           document.retrieveres.submit()
1.64      raeburn   249:       }
1.82      www       250:       if (activity == 'cleanup') {
                    251:           document.cleanup.filename.value = theform.filename.value
                    252:           document.cleanup.submit()
                    253:       }
1.64      raeburn   254:       return
                    255:     }
                    256:     function changename(theform,activity) {
1.96      banghart  257:         var oldname=theform.dispfilename.value;
1.109     bisitz    258:         var newname=prompt('$newname',oldname);
1.97      banghart  259:         if (newname == "" || !newname || newname == oldname)  {
1.64      raeburn   260:             return
                    261:         }
                    262:         document.moveresource.newfilename.value = newname
                    263:         document.moveresource.filename.value = theform.filename.value
                    264:         document.moveresource.action.value = activity
                    265:         document.moveresource.submit();
                    266:     }
1.29      www       267: </script>
                    268: ENDPUBDIRSCRIPT
1.64      raeburn   269:     $r->print($pubdirscript);
                    270: }
                    271: 
                    272: sub dircontrols {
                    273:     my ($r,$uname,$udom,$thisdisfn) = @_;
1.84      www       274:     my %lt=&Apache::lonlocal::texthash(
                    275:                                        cnpd => 'Cannot publish directory',
                    276:                                        cnrd => 'Cannot retrieve directory',
                    277:                                        mcdi => 'Must create new subdirectory inside a directory',
                    278:                                        pubr => 'Publish this Resource',
                    279:                                        pubd => 'Publish this Directory',
1.88      raeburn   280:                                        dedr => 'Delete Directory',
1.84      www       281:                                        rtrv => 'Retrieve Old Version',
                    282:                                        list => 'List Directory',
                    283:                                        uplo => 'Upload file',  
                    284:                                        dele => 'Delete',
1.113     schafran  285:                                        edit => 'Edit Metadata', 
1.84      www       286:                                        sela => 'Select Action',
                    287:                                        nfil => 'New file',
                    288:                                        nhtm => 'New HTML file',
                    289:                                        nprb => 'New problem',
                    290:                                        npag => 'New assembled page',
                    291:                                        nseq => 'New assembled sequence',
                    292:                                        ncrf => 'New custom rights file',
                    293:                                        nsty => 'New style file',
                    294:                                        nlib => 'New library file',
1.103     albertel  295:                                        nbt  => 'New bridgetask file',
1.84      www       296:                                        nsub => 'New subdirectory',
                    297:                                        renm => 'Rename current file to',
                    298:                                        move => 'Move current file to',
                    299:                                        copy => 'Copy current file to',
                    300:                                        type => 'Type Name Here',
1.105     albertel  301:                                        go   => 'Go',
1.84      www       302:                                        prnt => 'Print contents of directory',
                    303:                                        crea => 'Create a new directory or LON-CAPA document',
                    304: 				       acti => 'Actions for current directory',
1.105     albertel  305: 				       updc => 'Upload a new document',
                    306: 				       pick => 'Please select an action to perform using the new filename',
1.84      www       307:                                       );
1.106     bisitz    308:     my $mytype = $lt{'type'}; # avoid conflict with " and ' in javascript
1.64      raeburn   309:     $r->print(<<END);
1.117     harmsja   310: <div class="LC_columnSection">
1.116     bisitz    311:   <div>
                    312:     <form name="curractions" method="post" action="">
                    313:       <fieldset>
                    314:         <legend>$lt{'acti'}</legend>
                    315:         <select name="dirtask" onchange="currdiract(this.form)">
1.84      www       316:             <option>$lt{'sela'}</option>
                    317:             <option value="publish">$lt{'pubd'}</option>
1.113     schafran  318:             <option value="editmeta">$lt{'edit'}</option>
1.84      www       319:             <option value="printdir">$lt{'prnt'}</option>
1.88      raeburn   320:             <option value="delete">$lt{'dedr'}</option>
1.116     bisitz    321:         </select>
1.132     www       322:         <input type="hidden" name="filename" value="/priv$thisdisfn/" />
1.116     bisitz    323:       </fieldset>
                    324:     </form>
                    325:     <form name="publishdir" method="post" action="/adm/publish" target="_parent">
                    326:       <input type="hidden" name="pubrec" value="" />
                    327:       <input type="hidden" name="filename" value="" />
                    328:     </form>
                    329:     <form name="printdir" method="post" action="/adm/printout" target="_parent">
                    330:       <input type="hidden" name="postdata" value="" />
                    331:     </form>
                    332:   </div>
                    333: 
                    334:   <div>
                    335:     <form name="upublisher" enctype="multipart/form-data" method="post" action="/adm/upload" target="_parent">
                    336:       <fieldset>
                    337:         <legend>$lt{'updc'}</legend>
1.132     www       338:         <input type="hidden" name="filename" value="/priv$thisdisfn/" />
1.116     bisitz    339:         <input type="file" name="upfile" size="20" />
                    340:         <input type="button" value="$lt{'uplo'}"  onclick="checkUpload(this.form)" />
                    341:       </fieldset>
                    342:     </form>
                    343:   </div>
                    344: 
                    345:   <div>
                    346:     <form name="fileaction" method="post" action="/adm/cfile" target="_parent">
                    347:       <fieldset>
                    348:               <legend>$lt{'crea'}</legend>
                    349: 	      <span class="LC_nobreak">
1.132     www       350: 		<input type="hidden" name="filename" value="/priv$thisdisfn/" />
1.105     albertel  351:                   <script type="text/javascript">
                    352:                     function validate_go() {
                    353:                         var selected = document.fileaction.action.selectedIndex;
                    354:                         if (selected == 0) {
                    355:                             alert('$lt{'pick'}');
                    356:                         } else {
                    357:                             document.fileaction.submit();
                    358:                         }
                    359:                     }
                    360:                   </script>
                    361: 		  <select name="action">
                    362: 		    <option value="none">$lt{'sela'}</option>
                    363: 		    <option value="newfile">$lt{'nfil'}:</option>
                    364: 		    <option value="newhtmlfile">$lt{'nhtm'}:</option>
                    365: 		    <option value="newproblemfile">$lt{'nprb'}:</option>
                    366:                     <option value="newpagefile">$lt{'npag'}:</option>
                    367:                     <option value="newsequencefile">$lt{'nseq'}:</option>
                    368:                     <option value="newrightsfile">$lt{'ncrf'}:</option>
                    369:                     <option value="newstyfile">$lt{'nsty'}:</option>
                    370:                     <option value="newtaskfile">$lt{'nbt'}:</option>
                    371:                     <option value="newlibraryfile">$lt{'nlib'}:</option>
                    372: 	            <option value="newdir">$lt{'nsub'}:</option>
1.106     bisitz    373: 		  </select>&nbsp;<input type="text" name="newfilename" value="$lt{'type'}" onfocus="if (this.value == '$mytype') this.value=''" />&nbsp;<input type="button" value="Go" onclick="validate_go();" />
1.92      albertel  374: 		 </span>
1.116     bisitz    375:       </fieldset>
                    376:     </form>
                    377:   </div>
                    378: </div>
1.64      raeburn   379: END
                    380: }
                    381: 
                    382: sub resourceactions {
                    383:     my ($r,$uname,$udom,$thisdisfn) = @_;
                    384:     $r->print(<<END);
                    385:        <form name="moveresource" action="/adm/cfile" target="_parent" method="post">
                    386:          <input type="hidden" name="filename" value="" />
                    387:          <input type="hidden" name="newfilename" value="" />
                    388:          <input type="hidden" name="action" value="" />
                    389:        </form>
                    390:        <form name="delresource" action="/adm/cfile" target="_parent" method="post">
                    391:          <input type="hidden" name="filename" value="" />
                    392:          <input type="hidden" name="action" value="delete" />
                    393:        </form>
                    394:        <form name="pubresource" action="/adm/publish" target="_parent" method="post">
                    395:          <input type="hidden" name="filename" value="" />
1.80      www       396:          <input type="hidden" name="makeobsolete" value="0" />
1.64      raeburn   397:        </form>
                    398:        <form name="printresource" action="/adm/printout" target="_parent" method="post">
                    399:            <input type="hidden" name="postdata" value="" />
                    400:        </form>
                    401:        <form name="retrieveres" action="/adm/retrieve" target="_parent" method="post">
                    402:            <input type="hidden" name="filename" value="" />
                    403:        </form>
1.82      www       404:        <form name="cleanup" action="/adm/cleanup" target="_parent" method="post">
                    405:            <input type="hidden" name="filename" value="" />
                    406:        </form>
1.64      raeburn   407: END
1.23      foxr      408: }
                    409: 
                    410: #
                    411: #   Get the title string or "[untitled]" if the file has no title metadata:
                    412: #   Without the latter substitution, it's impossible to examine metadata for
                    413: #   untitled resources.  Resources may be legitimately untitled, to prevent
                    414: #   searches from locating them.
                    415: #
                    416: #   $str = getTitleString($fullname);
                    417: #       $fullname - Fully qualified filename to check.
                    418: #
                    419: sub getTitleString {
                    420:     my $fullname = shift;
                    421:     my $title    = &Apache::lonnet::metadata($fullname, 'title');
                    422: 
                    423:     unless ($title) {
1.40      www       424: 	$title = "[".&mt('untitled')."]";
1.23      foxr      425:     }
                    426:     return $title;
                    427: }
                    428: 
1.55      www       429: sub getCopyRightString {
                    430:     my $fullname = shift;
                    431:     return &Apache::lonnet::metadata($fullname, 'copyright');
                    432: }
1.61      www       433: 
                    434: sub getSourceRightString {
                    435:     my $fullname = shift;
                    436:     return &Apache::lonnet::metadata($fullname, 'sourceavail');
                    437: }
1.23      foxr      438: #
1.21      foxr      439: #  Put out a directory table row:
1.134     raeburn   440: #    putdirectory(r, base, here, dirname, modtime, targetdir, bombs, numdir)
                    441: #      r         - Apache request object.
                    442: #      reqfile   - File in request.
                    443: #      here      - Where we are in directory tree.
                    444: #      dirname   - Name of directory special file.
                    445: #      modtime   - Encoded modification time.
                    446: #      targetdir - Publication target directory.
                    447: #      bombs     - Reference to hash of URLs with runtime error messages.
                    448: #      numdir    - Reference to scalar used to track number of sub-directories
                    449: #                  in directory (used in form name for each "actions" dropdown).
                    450: #
1.21      foxr      451: sub putdirectory {
1.134     raeburn   452:     my ($r, $reqfile, $here, $dirname, $modtime, $targetdir, $bombs, $numdir) = @_;
1.129     www       453: 
                    454: # construct the display filename: the directory name unless ..:
1.133     www       455:    
                    456:     my $actionitem;
                    457:  
1.21      foxr      458:     my $disfilename = $dirname;
1.130     www       459: # Don't display directory itself, and there is no way up from root directory
1.133     www       460:     unless ((($dirname eq '..') && ($reqfile=~/^\/[^\/]+\/[^\/]+$/)) || ($dirname eq '.')) {
1.50      www       461: 	my $kaputt=0;
1.134     raeburn   462:         if (ref($bombs) eq 'HASH') {
                    463: 	    foreach my $key (keys(%{$bombs})) {
                    464: 	        if ($key =~ m{^\Q$targetdir/$disfilename\E/}) { $kaputt=1; last; }
                    465: 	    }
                    466:         }
1.129     www       467: #
                    468: # Get the metadata from that directory's default.meta to display titles
                    469: #
1.52      www       470: 	%Apache::lonpublisher::metadatafields=();
                    471: 	%Apache::lonpublisher::metadatakeys=();
1.129     www       472: 	&Apache::lonpublisher::metaeval(
                    473:                  &Apache::lonnet::getfile($r->dir_config('lonDocRoot').$here.'/'.$dirname.'/default.meta')
                    474:                                        );
1.133     www       475:         if ($dirname eq '..') {
1.109     bisitz    476:             $actionitem = &mt('Go to ...');
1.133     www       477:             $disfilename = '<i>'.&mt('Parent Directory').'</i>';
1.64      raeburn   478:         } else {
                    479:             $actionitem = 
                    480:                     '<form name="dirselect_'.$$numdir.
                    481:                     '" action="/adm/publish" target="_parent">'.
1.85      albertel  482:                     '<select name="diraction" onchange="SetPubDir(this.form,document)">'.
1.64      raeburn   483:                       '<option selected="selected">'.&mt('Select action').'</option>'.
                    484:                       '<option value="open">'.&mt('Open').'</option>'.
                    485:                       '<option value="publish">'.&mt('Publish').'</option>'.
1.113     schafran  486:                       '<option value="editmeta">'.&mt('Edit Metadata').'</option>'.
1.77      albertel  487:                       '<option value="printdir">'.&mt('Print directory').'</option>'.
1.88      raeburn   488:                       '<option value="delete">'.&mt('Delete directory').'</option>'.
1.64      raeburn   489:                     '</select>'.
1.129     www       490:                      '<input type="hidden" name="filename" value="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" />'.
1.75      albertel  491:                      '<input type="hidden" name="openname" value="'.$here.'/'.$dirname.'/" />'.
1.64      raeburn   492:                      '<input type="hidden" name="postdata" value="" />'.
                    493:                    '</form>';
                    494:             $$numdir ++;
                    495:         }
1.92      albertel  496: 	$r->print('<tr class="LC_browser_folder">'.
1.53      www       497: 		  '<td><img src="'.
1.123     bisitz    498: 		  $Apache::lonnet::perlvar{'lonIconsURL'}.'/navmap.folder.closed.gif" alt="folder" /></td>'.
1.64      raeburn   499: 		  '<td>'.$actionitem.'</td>'.
1.92      albertel  500: 		  '<td><span class="LC_filename"><a href="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" target="_parent">'.
                    501: 		  $disfilename.'</a></span></td>'.
1.134     raeburn   502: 		        '<td colspan="3">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($targetdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'});
1.92      albertel  503: 	if ($Apache::lonpublisher::metadatafields{'subject'} ne '') {
                    504: 	    $r->print(' <i>'.
                    505: 		      $Apache::lonpublisher::metadatafields{'subject'}.
                    506: 		      '</i> ');
                    507: 	}
                    508: 	$r->print($Apache::lonpublisher::metadatafields{'keywords'}.'</td>'.
1.42      www       509: 		  '<td>'.&Apache::lonlocal::locallocaltime($modtime).'</td>'.
1.25      www       510: 		  "</tr>\n");
1.64      raeburn   511:     }
1.21      foxr      512:     return OK;
                    513: }
1.22      foxr      514: #
                    515: #   Put a table row for a file resource.
                    516: #
                    517: sub putresource {
1.64      raeburn   518:     my ($r, $udom, $uname, $filename, $thisdisfn, 
1.22      foxr      519: 	$resdir, $targetdir, $linkdir,
1.64      raeburn   520: 	$cmtime,$bombs,$numres) = @_;
1.81      www       521:     &Apache::lonnet::devalidate_cache_new('meta',$targetdir.'/'.$filename);
1.64      raeburn   522:     my $pubstatus = 'unpublished';
1.47      sakharuk  523:     my $status=&mt('Unpublished');
1.92      albertel  524:     my $css_class='LC_browser_file';
1.22      foxr      525:     my $title='&nbsp;';
1.60      albertel  526:     my $publish_button=&mt('Publish');
1.141   ! www       527:     my $cstr_dir = $r->dir_config('lonDocRoot').'/priv'.$thisdisfn;
1.131     www       528:     my $linkfilename=&HTML::Entities::encode('/priv'.$thisdisfn.'/'.$filename,'<>&"');
1.129     www       529: 
1.22      foxr      530:     if (-e $resdir.'/'.$filename) {
1.91      www       531:         my $same=0;
1.22      foxr      532: 	my ($rdev,$rino,$rmode,$rnlink,
                    533: 	    $ruid,$rgid,$rrdev,$rsize,
                    534: 	    $ratime,$rmtime,$rctime,
                    535: 	    $rblksize,$rblocks)=stat($resdir.'/'.$filename);
1.91      www       536:         if ($rmtime>=$cmtime) {
                    537:            $same=1;
                    538:         } else {
                    539:            if (&Apache::londiff::are_different_files($resdir.'/'.$filename,
1.95      albertel  540: 						     $cstr_dir.'/'.$filename)) {
1.91      www       541:               $same=0;
                    542:            } else {
                    543:               $same=1;
                    544:            }
                    545:         }
1.95      albertel  546: 	my $meta_cmtime = (stat($cstr_dir.'/'.$filename.'.meta'))[9];
                    547: 	my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
                    548: 	my $meta_same = 1;
                    549: 	if ($meta_rmtime < $meta_cmtime
                    550: 	    && &Apache::londiff::are_different_files($resdir.'/'.$filename.'.meta',
                    551: 						     $cstr_dir.'/'.$filename.'.meta')) {
                    552: 	    $meta_same = 0;
                    553: 	}
1.64      raeburn   554: 	$publish_button=&mt('Re-publish');
1.124     bisitz    555: 
                    556:         my $rights_status =
                    557:             &mt(&getCopyRightString($targetdir.'/'.$filename)).', ';
                    558: 
                    559:         my %lt_SourceRight = &Apache::lonlocal::texthash(
                    560:                'open'   => 'Source: open',
                    561:                'closed' => 'Source: closed',
                    562:         );
                    563:         $rights_status .=
                    564:             $lt_SourceRight{&getSourceRightString($targetdir.'/'.$filename)};
                    565: 
1.134     raeburn   566: 	$title = '<a href="'.$targetdir.'/'.$filename.
1.95      albertel  567: 	    '.meta" target="cat">'.
                    568: 	    &getTitleString($targetdir.'/'.$filename).'</a>';
1.91      www       569: 	if ($same) {
1.40      www       570: 	    if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
1.64      raeburn   571:                 $pubstatus = 'obsolete';
1.41      www       572: 		$status=&mt('Obsolete');
1.95      albertel  573:             } else {
                    574: 		if (!$meta_same) {
                    575: 		    $pubstatus = 'metamodified';
                    576: 		} else {
                    577: 		    $pubstatus = 'published';
                    578: 		}
                    579: 		$status=&mt('Published').
                    580: 		    '<br />'. $rights_status;
                    581: 	    }
1.22      foxr      582: 	} else {
1.64      raeburn   583:             $pubstatus = 'modified';
1.95      albertel  584: 	    $status=&mt('Modified').
                    585: 		'<br />'. $rights_status;
1.22      foxr      586: 	    if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
1.139     www       587: 		$status.='<br />'.
                    588:                          &Apache::loncommon::modal_link(
                    589:                              '/adm/diff?filename='.$linkfilename.'&amp;versiontwo=priv',
                    590:                              &mt('Diffs'),600,500);
1.22      foxr      591: 	    }
1.95      albertel  592: 	} 
                    593: 
1.129     www       594: 	$title.="\n".'<br /><a href="'.$linkfilename.'.meta">'. 
1.110     bisitz    595: 	    ($$bombs{$targetdir.'/'.$filename}?'<img src="/adm/lonMisc/bomb.gif" border="0" alt="'.&mt('bomb').'" />':&mt('Edit Metadata')).'</a>';
1.95      albertel  596: 
                    597: 	if (!$meta_same) {
                    598: 	    $title = &mt('Metadata Modified').'<br />'.$title.
1.140     www       599: 		'<br />'.
                    600:                 &Apache::loncommon::modal_link(
1.141   ! www       601:                     '/adm/diff?filename='.$linkfilename.'.meta'.'&amp;versiontwo=priv',
1.140     www       602:                     &mt('Metadata Diffs'),600,500);
                    603: 	    $title.="\n".'<br />'.
                    604:                 &Apache::loncommon::modal_link(
                    605:                     '/adm/retrieve?filename='.$linkfilename.'.meta&amp;inhibitmenu=yes&amp;add_modal=yes',
                    606:                     &mt('Retrieve Metadata'),600,500);
1.95      albertel  607: 	}
1.140     www       608: 	$status.="\n".'<br />'.
                    609:              &Apache::loncommon::modal_link(
                    610:                  '/adm/retrieve?filename='.$linkfilename.'&amp;inhibitmenu=yes&amp;add_modal=yes',&mt('Retrieve'),600,500);
1.22      foxr      611:     }
1.33      www       612:     my $editlink='';
1.38      taceyjo1  613:     my $editlink2='';
1.36      www       614:     if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty)$/) {
1.138     raeburn   615: 	$editlink=' <br />(<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&problemmode=edit">'.&mt('Edit').'</a>)';
1.34      www       616:     }
1.136     www       617:     if ($filename=~/$LONCAPA::assess_re/) {
1.138     raeburn   618: 	$editlink=' (<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&problemmode=editxml">'.&mt('EditXML').'</a>)';
                    619: 	$editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&problemmode=edit">'.&mt('Edit').'</a>)';
1.43      taceyjo1  620:     }
1.82      www       621:     if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) {
1.129     www       622: 	$editlink.=' (<a href="/adm/cleanup?filename='.$linkfilename.'" target="_parent">'.&mt('Clean Up').')</a>';
1.82      www       623:     }
1.43      taceyjo1  624:     if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.129     www       625: 	$editlink=' (<a target="_parent" href="/adm/cfile?decompress='.$linkfilename.'">'.&mt('Decompress').'</a>)';
1.33      www       626:     }
1.64      raeburn   627:     my $pub_select = '';
                    628:     &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres);
1.115     bisitz    629:     $r->print(&Apache::loncommon::start_data_table_row().
1.53      www       630: 	      '<td>'.($filename=~/[\#\~]$/?'&nbsp;':
1.86      albertel  631: 		      '<img src="'.&Apache::loncommon::icon($filename).'" alt="" />').'</td>'.
1.64      raeburn   632:               '<td>'.$pub_select.'</td>'.
1.104     albertel  633: 	      '<td><span class="LC_filename">'.
1.64      raeburn   634: 	      '<a href="'.$linkdir.'/'.$filename.'" target="_parent">'.
1.92      albertel  635:                $filename.'</a></span>'.$editlink2.$editlink.
1.22      foxr      636: 	      '</td>'.
                    637: 	      '<td>'.$title.'</td>'.
1.115     bisitz    638:               '<td class="LC_browser_file_'.$pubstatus.'">&nbsp;&nbsp;</td>'. # Display publication status
                    639:               '<td>'.$status.'</td>'.
1.42      www       640: 	      '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'.
1.115     bisitz    641: 	      &Apache::loncommon::end_data_table_row()
                    642:     );
1.22      foxr      643:     return OK;
1.23      foxr      644: }
1.64      raeburn   645: 
                    646: sub create_pubselect {
                    647:     my ($r,$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres) = @_;
                    648:     $$pub_select = '
                    649: <form name="resselect_'.$$numres.'" action="">
1.85      albertel  650: <select name="reschoice"  onchange="SetResChoice(this.form)">
1.77      albertel  651: <option>'.&mt('Select action').'</option>'.
                    652: '<option value="copy">'.&mt('Copy').'</option>';
1.68      raeburn   653:     if ($pubstatus eq 'obsolete' || $pubstatus eq 'unpublished') {
                    654:         $$pub_select .= 
1.77      albertel  655: '<option value="rename">'.&mt('Rename').'</option>'.
                    656: '<option value="move">'.&mt('Move').'</option>'.
                    657: '<option value="delete">'.&mt('Delete').'</option>';
1.64      raeburn   658:     } else {
                    659:         $$pub_select .= '
1.77      albertel  660: <option value="obsolete">'.&mt('Mark obsolete').'</option>';
1.64      raeburn   661:     }
                    662: # check for versions
                    663:     my $versions = &check_for_versions($r,'/'.$filename,$udom,$uname);
                    664:     if ($versions > 0) {
                    665:         $$pub_select .='
1.77      albertel  666: <option value="retrieve">'.&mt('Retrieve old version').'</option>';
1.64      raeburn   667:     }
                    668:     $$pub_select .= '
1.77      albertel  669: <option value="publish">'.$publish_button.'</option>'.
1.82      www       670: '<option value="cleanup">'.&mt('Clean up').'</option>'.
1.77      albertel  671: '<option value="print">'.&mt('Print').'</option>'.
1.68      raeburn   672: '</select>
1.131     www       673: <input type="hidden" name="filename" value="/priv'.
                    674:  &HTML::Entities::encode($thisdisfn.'/'.$filename,'<>&"').'" />
1.96      banghart  675:  <input type="hidden" name="dispfilename" value="'.
1.99      albertel  676:  &HTML::Entities::encode($filename).'" /></form>';
1.64      raeburn   677:     $$numres ++;
                    678: }
                    679: 
                    680: sub check_for_versions {
                    681:     my ($r,$fn,$udom,$uname) = @_;
                    682:     my $versions = 0;
                    683:     my $docroot=$r->dir_config('lonDocRoot');
                    684:     my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
                    685:     my $resdir=$resfn;
                    686:     $resdir=~s/\/[^\/]+$/\//;
                    687:     $fn=~/\/([^\/]+)\.(\w+)$/;
                    688:     my $main=$1;
                    689:     my $suffix=$2;
                    690:     opendir(DIR,$resdir);
                    691:     while (my $filename=readdir(DIR)) {
                    692:         if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
                    693:             $versions ++;        
                    694:         }
                    695:     }
                    696:     return $versions;
                    697: }
                    698: 
1.4       www       699: 1;
                    700: __END__
1.17      harris41  701: 
                    702: 
1.114     jms       703: =head1 NAME
                    704: 
                    705: Apache::lonpubdir - Construction space directory lister
                    706: 
                    707: =head1 SYNOPSIS
                    708: 
                    709: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
                    710: 
1.134     raeburn   711:  <LocationMatch "^/+priv.*/$">
1.114     jms       712:  PerlAccessHandler       Apache::loncacc
                    713:  SetHandler perl-script
                    714:  PerlHandler Apache::lonpubdir
                    715:  ErrorDocument     403 /adm/login
                    716:  ErrorDocument     404 /adm/notfound.html
                    717:  ErrorDocument     406 /adm/unauthorized.html
                    718:  ErrorDocument	  500 /adm/errorhandler
                    719:  </LocationMatch>
                    720: 
                    721:  <Location /adm/pubdir>
                    722:  PerlAccessHandler       Apache::lonacc
                    723:  SetHandler perl-script
                    724:  PerlHandler Apache::lonpubdir
                    725:  ErrorDocument     403 /adm/login
                    726:  ErrorDocument     404 /adm/notfound.html
                    727:  ErrorDocument     406 /adm/unauthorized.html
                    728:  ErrorDocument	  500 /adm/errorhandler
                    729:  </Location>
                    730: 
                    731: =head1 INTRODUCTION
                    732: 
                    733: This module publishes a directory of files.
                    734: 
                    735: This is part of the LearningOnline Network with CAPA project
                    736: described at http://www.lon-capa.org.
                    737: 
                    738: =head1 HANDLER SUBROUTINE
                    739: 
                    740: This routine is called by Apache and mod_perl.
                    741: 
                    742: =over 4
                    743: 
                    744: =item *
                    745: 
                    746: read in information
                    747: 
                    748: =item *
                    749: 
                    750: start page output
                    751: 
                    752: =item *
                    753: 
                    754: run through list of files and attempt to publish unhidden files
                    755: 
                    756: =back
                    757: 
                    758: =head1 SUBROUTINES:
                    759: 
                    760: =over
                    761: 
                    762: =item startpage($r, $uame, $udom, $thisdisfn)
                    763: 
                    764: Output the header of the page.  This includes:
                    765:  - The HTML header 
                    766:  - The H1/H3  stuff which includes the directory.
                    767:  
                    768:     startpage($r, $uame, $udom, $thisdisfn);
                    769:         $r     - The apache request object.
                    770:         $uname - User name.
                    771:         $udom  - Domain name the user is logged in under.
                    772:         $thisdisfn - Displayable version of the filename.
                    773: 
                    774: =item getTitleString($fullname)
                    775: 
                    776:     Get the title string or "[untitled]" if the file has no title metadata:
                    777:     Without the latter substitution, it's impossible to examine metadata for
                    778:     untitled resources.  Resources may be legitimately untitled, to prevent
                    779:     searches from locating them.
                    780:     
                    781:     $str = getTitleString($fullname);
                    782:         $fullname - Fully qualified filename to check.
                    783: 
1.134     raeburn   784: =item putdirectory($r, $base, $here, $dirname, $modtime, $targetdir, $bombs,
                    785:                    $numdir)
1.114     jms       786: 
                    787:     Put out a directory table row:
                    788:     
1.134     raeburn   789:         $r        - Apache request object.
                    790:         $reqfile  - File in request.
                    791:         $here     - Where we are in directory tree.
                    792:         $dirname  - Name of directory special file.
                    793:         $modtime  - Encoded modification time.
                    794:         targetdir - Publication target directory.
                    795:         bombs     - Reference to hash of URLs with runtime error messages.
                    796:         numdir    - Reference to scalar used to track number of sub-directories
                    797:                     in directory (used in form name for each "actions" dropdown).
1.114     jms       798: 
                    799: =back
                    800: 
                    801: =cut
                    802: 

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