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

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

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