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

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

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