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

1.1       www         1: # The LearningOnline Network with CAPA
1.145     raeburn     2: # Authoring Space Directory Lister
1.16      albertel    3: #
1.160.2.2! raeburn     4: # $Id: lonpubdir.pm,v 1.160.2.1 2016/08/07 20:23:42 raeburn Exp $
1.16      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
1.1       www        27: #
1.17      harris41   28: ###
1.1       www        29: 
                     30: package Apache::lonpubdir;
                     31: 
                     32: use strict;
                     33: use Apache::File;
                     34: use File::Copy;
                     35: use Apache::Constants qw(:common :http :methods);
1.17      harris41   36: use Apache::loncommon();
1.48      www        37: use Apache::lonhtmlcommon();
1.91      www        38: use Apache::londiff();
1.39      www        39: use Apache::lonlocal;
1.50      www        40: use Apache::lonmsg;
1.64      raeburn    41: use Apache::lonmenu;
                     42: use Apache::lonnet;
1.154     raeburn    43: use LONCAPA qw(:DEFAULT :match);
1.1       www        44: 
                     45: sub handler {
                     46: 
1.152     musolffc   47:     my $r=shift;
1.1       www        48: 
1.152     musolffc   49:     # Validate access to the construction space and get username:domain.
1.6       www        50: 
1.153     raeburn    51:     my ($uname,$udom)=&Apache::lonnet::constructaccess($r->uri); 
1.152     musolffc   52:     unless (($uname) && ($udom)) {
                     53:         return HTTP_NOT_ACCEPTABLE;
                     54:     }
1.23      foxr       55: 
1.127     www        56: # ----------------------------------------------------------- Start page output
1.23      foxr       57: 
1.152     musolffc   58:     my $fn=$r->filename;
                     59:     $fn=~s/\/$//;
                     60:     my $thisdisfn=$fn;
1.1       www        61: 
1.152     musolffc   62:     my $docroot=$r->dir_config('lonDocRoot');     # Apache  londocument root.
1.155     raeburn    63:     if ($thisdisfn eq "$docroot/priv/$udom") {
                     64:         if ((-d "/home/$uname/public_html/") && (!-e "$docroot/priv/$udom/$uname")) {
                     65:             my ($version) = ($r->dir_config('lonVersion') =~ /^\'?(\d+\.\d+)\./);
                     66:             &Apache::loncommon::content_type($r,'text/html');
                     67:             $r->send_http_header;
                     68: 
                     69:             &Apache::lonhtmlcommon::clear_breadcrumbs();
                     70:             $r->print(&Apache::loncommon::start_page('Authoring Space').
                     71:                       '<div class="LC_error">'.
                     72:                       '<br /><p>'.
                     73:                       &mt('Your Authoring Space is currently in the location used by LON-CAPA version 2.10 and older, but your domain is using a newer LON-CAPA version ([_1]).',$version).'</p>'.
                     74:                       '<p>'.
                     75:                       &mt('Please ask your Domain Coordinator to move your Authoring Space to the new location.').
                     76:                       '</p>'.
                     77:                       '</div>'.
                     78:                       &Apache::loncommon::end_page());
                     79:             return OK;
                     80:         }
                     81:     }
1.152     musolffc   82:     $thisdisfn=~s/^\Q$docroot\E\/priv//;
                     83:     
                     84:     my $resdir=$docroot.'/res'.$thisdisfn; # Resource directory
                     85:     my $targetdir='/res'.$thisdisfn; # Publication target directory.
                     86:     my $linkdir='/priv'.$thisdisfn;      # Full URL name of constr space.
                     87: 
                     88:     my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
                     89: 
                     90:     &startpage($r, $uname, $udom, $thisdisfn);  # Put out the start of page.
1.157     raeburn    91: 
                     92:     if (!-d $fn) {
                     93:         if (-e $fn) {
                     94:             $r->print('<p class="LC_info">'.&mt('Requested item is a file not a directory.').'</p>');
                     95:         } else {
                     96:             $r->print('<p class="LC_info">'.&mt('The requested subdirectory does not exist.').'</p>');
                     97:         }
                     98:         $r->print(&Apache::loncommon::end_page());
                     99:         return OK;
                    100:     }
                    101:     my @files;
                    102:     if (opendir(DIR,$fn)) {
1.158     raeburn   103:         @files = grep(!/^\.+$/,readdir(DIR));
1.157     raeburn   104:         closedir(DIR);
                    105:     } else {
                    106:         $r->print('<p class="LC_error">'.&mt('Could not open directory.').'</p>');
                    107:         $r->print(&Apache::loncommon::end_page());
                    108:         return OK;
                    109:     }
                    110: 
1.152     musolffc  111:     &dircontrols($r,$uname,$udom,$thisdisfn);   # Put out actions for directory, 
                    112:                                                 # browse/upload + new file page.
                    113:     &resourceactions($r,$uname,$udom,$thisdisfn); # Put out form used for printing/deletion etc.
1.64      raeburn   114: 
1.152     musolffc  115:     my $numdir = 0;
                    116:     my $numres = 0;
1.6       www       117:   
1.160     musolffc  118:     if ((@files == 0) && ($thisdisfn =~ m{^/$match_domain/$match_username})) {
                    119:         if ($thisdisfn =~ m{^/$match_domain/$match_username$}) {
                    120:             $r->print('<p class="LC_info">'.&mt('This Authoring Space is currently empty.').'</p>');
                    121:         } else {
                    122:             $r->print('<p class="LC_info">'.&mt('This subdirectory is currently empty.').'</p>');
                    123:         }
                    124:         $r->print(&Apache::loncommon::end_page());
                    125:         return OK;
                    126:     }
                    127: 
1.152     musolffc  128:     # Retrieving value for "sortby" and "sortorder" from QUERY_STRING
                    129:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    130:         ['sortby','sortorder']);
                    131: 
                    132:     # Sort by name as default, not reversed
                    133:     if (! exists($env{'form.sortby'})) { $env{'form.sortby'} = 'filename' }
                    134:     if (! exists($env{'form.sortorder'})) { $env{'form.sortorder'} = '' }
                    135:     my $sortby = $env{'form.sortby'};
                    136:     my $sortorder = $env{'form.sortorder'};
                    137: 
1.160     musolffc  138:     # Order in which columns are displayed from left to right
                    139:     my @order = ('filetype','actions','filename','title',
                    140:                     'pubstatus','cmtime','size');
                    141: 
                    142:     # Up and down arrows to indicate sort order
                    143:     my @arrows = ('&nbsp;&#9650;','&nbsp;&#9660;','');
                    144: 
                    145:     # Default sort order and column title
                    146:     my %columns = (
                    147:         filetype =>     {
                    148:                             order => 'ascending',
                    149:                             text  => &mt('Type'),
                    150:                         },
                    151:         actions =>      {
                    152:                             # Not sortable
                    153:                             text  => &mt('Actions'),
                    154:                         },
                    155:         filename =>     {
                    156:                             order => 'ascending',
                    157:                             text  => &mt('Name'),
                    158:                         },
                    159:         title =>        {
                    160:                             order => 'ascending',
                    161:                             text  => &mt('Title'),
                    162:                         },
                    163:         pubstatus =>    {
                    164:                             order => 'ascending',
                    165:                             text  => &mt('Status'),
                    166:                             colspan => '2',
                    167:                         },
                    168:         cmtime =>       {
                    169:                             order => 'descending',
                    170:                             text  => &mt('Last Modified'),
                    171:                         },
                    172:         size =>         {
                    173:                             order => 'ascending',
                    174:                             text  => &mt('Size').' (kB)',
                    175:                         },
                    176:     ); 
                    177: 
                    178:     # Print column headers
                    179:     my $output = '';
                    180:     foreach my $key (@order) {
                    181:         my $idx;
                    182:         # Append an up or down arrow to sorted column
                    183:         if ($sortby eq $key) {
                    184:             $idx = ($columns{$key}{order} eq 'ascending') ? 0:1;
                    185:             if ($sortorder eq 'rev') { $idx ++; }
                    186:             $idx = $idx%2;
                    187:         } else { $idx = 2; } # No arrow if column is not sorted
                    188:         $output .= (($columns{$key}{order}) ?
                    189:             '<th'.($columns{$key}{colspan} ? ' colspan="'.$columns{$key}{colspan}.'"' : '')
                    190:             .'><a href="'.$linkdir.'/?sortby='.$key.'&sortorder='
                    191:             .((($sortby eq $key) && ($sortorder ne 'rev')) ? 'rev' : '').'">'
                    192:             .$columns{$key}{text}.$arrows[$idx].'</a></th>' :
                    193:             '<th>'.$columns{$key}{text}.'</th>');
1.154     raeburn   194:     }
1.152     musolffc  195:     $r->print(&Apache::loncommon::start_data_table()
1.160     musolffc  196:         .&Apache::loncommon::start_data_table_header_row() . $output
1.152     musolffc  197:         .&Apache::loncommon::end_data_table_header_row()
                    198:     );
                    199: 
                    200:     my $dirptr=16384;		# Mask indicating a directory in stat.cmode.
                    201:     my $filehash = {};
                    202:     foreach my $filename (@files) {
1.159     musolffc  203:         # Skip .DS_Store, .DAV and hidden files
1.152     musolffc  204:         my ($extension) = ($filename=~/\.(\w+)$/);
1.156     raeburn   205:         next if (($filename eq '.DS_Store')
1.159     musolffc  206:                 || ($filename eq '.DAV')
1.156     raeburn   207:                 || (&Apache::loncommon::fileembstyle($extension) eq 'hdn')
                    208:                 || ($filename =~ /^\._/));
1.152     musolffc  209: 
                    210:         my ($cmode,$csize,$cmtime)=(stat($fn.'/'.$filename))[2,7,9];
                    211:         my $linkfilename = &HTML::Entities::encode('/priv'.$thisdisfn.'/'.$filename,'<>&"');
                    212:         # Identify type of file according to icon used
                    213:         my ($filetype) = (&Apache::loncommon::icon($filename) =~ m{/(\w+).gif$}); 
                    214:         my $cstr_dir = $r->dir_config('lonDocRoot').'/priv'.$thisdisfn;
                    215:         my $meta_same = &isMetaSame($cstr_dir, $resdir, $filename);
                    216:         
                    217:         # Store size, title, and status for files but not directories
                    218:         my $size = (!($cmode&$dirptr)) ? $csize/1024. : 0;
                    219:         my ($status, $pubstatus, $title, $fulltitle);
                    220:         if (!($cmode&$dirptr)) {
                    221:             ($status, $pubstatus) = &getStatus($resdir, $targetdir, $cstr_dir, 
                    222:                 $filename, $linkfilename, $cmtime, $meta_same);
                    223:             ($fulltitle, $title) = &getTitle($resdir, $targetdir, $filename, 
                    224:                                         $linkfilename, $meta_same, \%bombs);
                    225:         } else {
                    226:             ($status, $pubstatus) = ('','');
                    227:             ($fulltitle, $title) = ('','');
                    228:         }
1.150     musolffc  229: 
1.152     musolffc  230:         # This hash will allow sorting
                    231:         $filehash->{ $filename } = {
                    232:             "cmtime"            => $cmtime,
                    233:             "size"              => $size,
                    234:             "cmode"             => $cmode,
                    235:             "filetype"          => $filetype,
                    236:             "title"             => $title,
                    237:             "fulltitle"         => $fulltitle,
                    238:             "status"            => $status,
                    239:             "pubstatus"         => $pubstatus,
                    240:             "linkfilename"      => $linkfilename,
                    241:         }
                    242:     }
                    243:    
                    244:     my @sorted_files;
                    245:     # Sorting by something other than "Name".  Name is the secondary key.
                    246:     if ($sortby =~ m{cmtime|size}) {    # Numeric fields
                    247:         # First check if order should be reversed
                    248:         if ($sortorder eq "rev") {
                    249:             @sorted_files = sort {
                    250:                 $filehash->{$a}->{$sortby} <=> $filehash->{$b}->{$sortby}
                    251:                     or
                    252:                 uc($a) cmp uc($b)
                    253:             } (keys(%{$filehash}));
                    254:         } else {
                    255:             @sorted_files = sort {
                    256:                 $filehash->{$b}->{$sortby} <=> $filehash->{$a}->{$sortby}
                    257:                     or
                    258:                 uc($a) cmp uc($b)
                    259:             } (keys(%{$filehash}));
                    260:         }
                    261:     } elsif ($sortby =~ m{filetype|title|status}) {     # String fields
                    262:         if ($sortorder eq "rev") {
                    263:             @sorted_files = sort {
                    264:                 $filehash->{$b}->{$sortby} cmp $filehash->{$a}->{$sortby}
                    265:                     or
                    266:                 uc($a) cmp uc($b)
                    267:             } (keys(%{$filehash}));
                    268:         } else {
                    269:             @sorted_files = sort {
                    270:                 $filehash->{$a}->{$sortby} cmp $filehash->{$b}->{$sortby}
                    271:                     or
                    272:                 uc($a) cmp uc($b)
                    273:             } (keys(%{$filehash}));
                    274:         }
                    275: 
                    276:     # Sort by "Name" is the default
                    277:     } else { 
                    278:         if ($sortorder eq "rev") {
                    279:             @sorted_files = sort {uc($b) cmp uc($a)} (keys(%{$filehash}));
                    280:         } else {
                    281:             @sorted_files = sort {uc($a) cmp uc($b)} (keys(%{$filehash}));
                    282:         }
                    283:     }
                    284: 
                    285:     # Print the sorted resources
                    286:     foreach my $filename (@sorted_files) {
                    287:         if ($filehash->{$filename}->{"cmode"}&$dirptr) {        # Directories
                    288:             &putdirectory($r, $thisdisfn, $linkdir, $filename, 
                    289:                 $filehash->{$filename}->{"cmtime"}, 
                    290:                 $targetdir, \%bombs, \$numdir);
                    291:         } else {                                                # Files
                    292:             &putresource($r, $udom, $uname, $filename, $thisdisfn, $resdir,
                    293:                 $targetdir, $linkdir, $filehash->{$filename}->{"cmtime"}, 
                    294:                 $filehash->{$filename}->{"size"}, \$numres, 
                    295:                 $filehash->{$filename}->{"linkfilename"},
                    296:                 $filehash->{$filename}->{"fulltitle"},
                    297:                 $filehash->{$filename}->{"status"},
                    298:                 $filehash->{$filename}->{"pubstatus"});
                    299:         }
                    300:     }
                    301: 
                    302:     $r->print( &Apache::loncommon::end_data_table()
                    303:         .&Apache::loncommon::end_page() );
1.2       www       304: 
1.154     raeburn   305:     return OK;
1.1       www       306: }
1.127     www       307: 
1.152     musolffc  308: 
                    309: 
1.23      foxr      310: #   Output the header of the page.  This includes:
                    311: #   - The HTML header 
                    312: #   - The H1/H3  stuff which includes the directory.
                    313: #
                    314: #     startpage($r, $uame, $udom, $thisdisfn);
                    315: #      $r     - The apache request object.
                    316: #      $uname - User name.
                    317: #      $udom  - Domain name the user is logged in under.
                    318: #      $thisdisfn - Displayable version of the filename.
1.26      www       319: 
1.23      foxr      320: sub startpage {
                    321:     my ($r, $uname, $udom, $thisdisfn) = @_;
1.39      www       322:     &Apache::loncommon::content_type($r,'text/html');
1.23      foxr      323:     $r->send_http_header;
1.64      raeburn   324: 
1.132     www       325:     my $formaction='/priv'.$thisdisfn.'/';
1.89      albertel  326:     $formaction=~s|/+|/|g;
1.66      raeburn   327:     &Apache::lonhtmlcommon::store_recent('construct',$formaction,$formaction);
1.121     bisitz    328: 
1.125     droeschl  329:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    330:     &Apache::lonhtmlcommon::add_breadcrumb({
1.145     raeburn   331:         'text'  => 'Authoring Space',
1.137     raeburn   332:         'href'  => &Apache::loncommon::authorspace($formaction),
1.125     droeschl  333:     });
                    334:     # breadcrumbs (and tools) will be created 
                    335:     # in start_page->bodytag->innerregister
                    336: 
1.132     www       337:     $env{'request.noversionuri'}=$formaction;
1.153     raeburn   338:     $r->print(&Apache::loncommon::start_page('Authoring Space'));
1.90      albertel  339: 
1.147     raeburn   340:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                    341:     my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
1.153     raeburn   342:     my $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author'); #expressed in MB
                    343:     $disk_quota = 1000 * $disk_quota; # convert from MB to kB
1.147     raeburn   344: 
1.121     bisitz    345:     $r->print(&Apache::loncommon::head_subbox(
1.147     raeburn   346:                      '<div style="float:right;padding-top:0;margin-top;0">'
1.160.2.1  raeburn   347:                     .&Apache::lonhtmlcommon::display_usage($current_disk_usage,
                    348:                                                            $disk_quota,'authoring')
1.147     raeburn   349:                     .'</div>'
                    350:                     .&Apache::loncommon::CSTR_pageheader()));
1.121     bisitz    351: 
1.101     albertel  352:     my $esc_thisdisfn = &Apache::loncommon::escape_single($thisdisfn);
1.145     raeburn   353:     my $doctitle = 'LON-CAPA '.&mt('Authoring Space');
1.109     bisitz    354:     my $newname = &mt('New Name');
1.29      www       355:     my $pubdirscript=(<<ENDPUBDIRSCRIPT);
1.77      albertel  356: <script type="text/javascript">
1.107     bisitz    357: top.document.title = '$esc_thisdisfn/ - $doctitle';
1.37      www       358: // Store directory location for menu bar to find
                    359: 
1.132     www       360: parent.lastknownpriv='/priv$esc_thisdisfn/';
1.37      www       361: 
                    362: // Confirmation dialogues
                    363: 
1.64      raeburn   364:     function currdiract(theform) {
                    365:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publish') {
1.79      www       366:             document.publishdir.filename.value = theform.filename.value;
                    367: 	    document.publishdir.submit();
1.64      raeburn   368:         }
1.113     schafran  369:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editmeta') {
1.66      raeburn   370:             top.location=theform.filename.value+'default.meta'
1.64      raeburn   371:         }
                    372:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) {
                    373:             document.printdir.postdata.value=theform.filename.value
                    374:             document.printdir.submit();
                    375:         }
1.88      raeburn   376:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == "delete") {
                    377:               var delform = document.delresource
                    378:               delform.filename.value = theform.filename.value
                    379:               delform.submit()
                    380:         }
1.64      raeburn   381:     }
                    382:   
                    383:     function checkUpload(theform) {
                    384:         if (theform.file == '') {
                    385:             alert("Please use 'Browse..' to choose a file first, before uploading")
                    386:             return 
                    387:         }
                    388:         theform.submit()  
                    389:     }
                    390: 
                    391:     function SetPubDir(theform,printForm) {
                    392:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "open") {
1.75      albertel  393:             top.location = theform.openname.value
1.64      raeburn   394:             return
                    395:         }
                    396:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "publish") {
1.79      www       397:             theform.submit();
1.64      raeburn   398:         }
1.113     schafran  399:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "editmeta") {
1.66      raeburn   400:             top.location=theform.filename.value+'default.meta'
1.64      raeburn   401:         }
1.68      raeburn   402:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "printdir") {
1.64      raeburn   403:             theform.action = '/adm/printout'
                    404:             theform.postdata.value = theform.filename.value
                    405:             theform.submit()
                    406:         }
1.88      raeburn   407:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "delete") {
                    408:               var delform = document.delresource
                    409:               delform.filename.value = theform.filename.value
                    410:               delform.submit()
                    411:         }
1.64      raeburn   412:         return
                    413:     }
                    414:     function SetResChoice(theform) {
                    415:       var activity = theform.reschoice.options[theform.reschoice.selectedIndex].value
                    416:       if ((activity == 'rename') || (activity == 'copy') || (activity == 'move')) {
                    417:           changename(theform,activity)
                    418:       }
                    419:       if (activity == 'publish') {
                    420:           var pubform = document.pubresource
                    421:           pubform.filename.value = theform.filename.value
                    422:           pubform.submit()
                    423:       }
                    424:       if (activity == 'delete') {
                    425:           var delform = document.delresource
                    426:           delform.filename.value = theform.filename.value
1.71      raeburn   427:           delform.submit()
1.64      raeburn   428:       }
                    429:       if (activity == 'obsolete') {
1.68      raeburn   430:           var pubform = document.pubresource
                    431:           pubform.filename.value = theform.filename.value
1.80      www       432:           pubform.makeobsolete.value=1;
1.68      raeburn   433:           pubform.submit()
1.64      raeburn   434:       }
                    435:       if (activity == 'print') {
1.68      raeburn   436:           document.printresource.postdata.value = theform.filename.value
1.64      raeburn   437:           document.printresource.submit()
                    438:       }
                    439:       if (activity == 'retrieve') {
1.68      raeburn   440:           document.retrieveres.filename.value = theform.filename.value
                    441:           document.retrieveres.submit()
1.64      raeburn   442:       }
1.82      www       443:       if (activity == 'cleanup') {
                    444:           document.cleanup.filename.value = theform.filename.value
                    445:           document.cleanup.submit()
                    446:       }
1.64      raeburn   447:       return
                    448:     }
                    449:     function changename(theform,activity) {
1.96      banghart  450:         var oldname=theform.dispfilename.value;
1.109     bisitz    451:         var newname=prompt('$newname',oldname);
1.97      banghart  452:         if (newname == "" || !newname || newname == oldname)  {
1.64      raeburn   453:             return
                    454:         }
                    455:         document.moveresource.newfilename.value = newname
                    456:         document.moveresource.filename.value = theform.filename.value
                    457:         document.moveresource.action.value = activity
                    458:         document.moveresource.submit();
                    459:     }
1.29      www       460: </script>
                    461: ENDPUBDIRSCRIPT
1.64      raeburn   462:     $r->print($pubdirscript);
                    463: }
                    464: 
                    465: sub dircontrols {
                    466:     my ($r,$uname,$udom,$thisdisfn) = @_;
1.84      www       467:     my %lt=&Apache::lonlocal::texthash(
                    468:                                        cnpd => 'Cannot publish directory',
                    469:                                        cnrd => 'Cannot retrieve directory',
                    470:                                        mcdi => 'Must create new subdirectory inside a directory',
                    471:                                        pubr => 'Publish this Resource',
                    472:                                        pubd => 'Publish this Directory',
1.88      raeburn   473:                                        dedr => 'Delete Directory',
1.84      www       474:                                        rtrv => 'Retrieve Old Version',
                    475:                                        list => 'List Directory',
                    476:                                        uplo => 'Upload file',  
                    477:                                        dele => 'Delete',
1.113     schafran  478:                                        edit => 'Edit Metadata', 
1.84      www       479:                                        sela => 'Select Action',
                    480:                                        nfil => 'New file',
                    481:                                        nhtm => 'New HTML file',
                    482:                                        nprb => 'New problem',
                    483:                                        npag => 'New assembled page',
                    484:                                        nseq => 'New assembled sequence',
                    485:                                        ncrf => 'New custom rights file',
                    486:                                        nsty => 'New style file',
                    487:                                        nlib => 'New library file',
1.103     albertel  488:                                        nbt  => 'New bridgetask file',
1.84      www       489:                                        nsub => 'New subdirectory',
                    490:                                        renm => 'Rename current file to',
                    491:                                        move => 'Move current file to',
                    492:                                        copy => 'Copy current file to',
                    493:                                        type => 'Type Name Here',
1.105     albertel  494:                                        go   => 'Go',
1.84      www       495:                                        prnt => 'Print contents of directory',
                    496:                                        crea => 'Create a new directory or LON-CAPA document',
                    497: 				       acti => 'Actions for current directory',
1.105     albertel  498: 				       updc => 'Upload a new document',
                    499: 				       pick => 'Please select an action to perform using the new filename',
1.84      www       500:                                       );
1.106     bisitz    501:     my $mytype = $lt{'type'}; # avoid conflict with " and ' in javascript
1.64      raeburn   502:     $r->print(<<END);
1.117     harmsja   503: <div class="LC_columnSection">
1.116     bisitz    504:   <div>
                    505:     <form name="curractions" method="post" action="">
                    506:       <fieldset>
                    507:         <legend>$lt{'acti'}</legend>
                    508:         <select name="dirtask" onchange="currdiract(this.form)">
1.84      www       509:             <option>$lt{'sela'}</option>
                    510:             <option value="publish">$lt{'pubd'}</option>
1.113     schafran  511:             <option value="editmeta">$lt{'edit'}</option>
1.84      www       512:             <option value="printdir">$lt{'prnt'}</option>
1.88      raeburn   513:             <option value="delete">$lt{'dedr'}</option>
1.116     bisitz    514:         </select>
1.132     www       515:         <input type="hidden" name="filename" value="/priv$thisdisfn/" />
1.116     bisitz    516:       </fieldset>
                    517:     </form>
                    518:     <form name="publishdir" method="post" action="/adm/publish" target="_parent">
                    519:       <input type="hidden" name="pubrec" value="" />
                    520:       <input type="hidden" name="filename" value="" />
                    521:     </form>
                    522:     <form name="printdir" method="post" action="/adm/printout" target="_parent">
                    523:       <input type="hidden" name="postdata" value="" />
                    524:     </form>
                    525:   </div>
                    526: 
                    527:   <div>
                    528:     <form name="upublisher" enctype="multipart/form-data" method="post" action="/adm/upload" target="_parent">
                    529:       <fieldset>
                    530:         <legend>$lt{'updc'}</legend>
1.132     www       531:         <input type="hidden" name="filename" value="/priv$thisdisfn/" />
1.116     bisitz    532:         <input type="file" name="upfile" size="20" />
                    533:         <input type="button" value="$lt{'uplo'}"  onclick="checkUpload(this.form)" />
                    534:       </fieldset>
                    535:     </form>
                    536:   </div>
                    537: 
                    538:   <div>
                    539:     <form name="fileaction" method="post" action="/adm/cfile" target="_parent">
                    540:       <fieldset>
                    541:               <legend>$lt{'crea'}</legend>
                    542: 	      <span class="LC_nobreak">
1.132     www       543: 		<input type="hidden" name="filename" value="/priv$thisdisfn/" />
1.105     albertel  544:                   <script type="text/javascript">
                    545:                     function validate_go() {
                    546:                         var selected = document.fileaction.action.selectedIndex;
                    547:                         if (selected == 0) {
                    548:                             alert('$lt{'pick'}');
                    549:                         } else {
                    550:                             document.fileaction.submit();
                    551:                         }
                    552:                     }
                    553:                   </script>
                    554: 		  <select name="action">
                    555: 		    <option value="none">$lt{'sela'}</option>
                    556: 		    <option value="newfile">$lt{'nfil'}:</option>
                    557: 		    <option value="newhtmlfile">$lt{'nhtm'}:</option>
                    558: 		    <option value="newproblemfile">$lt{'nprb'}:</option>
                    559:                     <option value="newpagefile">$lt{'npag'}:</option>
                    560:                     <option value="newsequencefile">$lt{'nseq'}:</option>
                    561:                     <option value="newrightsfile">$lt{'ncrf'}:</option>
                    562:                     <option value="newstyfile">$lt{'nsty'}:</option>
                    563:                     <option value="newtaskfile">$lt{'nbt'}:</option>
                    564:                     <option value="newlibraryfile">$lt{'nlib'}:</option>
                    565: 	            <option value="newdir">$lt{'nsub'}:</option>
1.160.2.2! raeburn   566: 		  </select>&nbsp;<input type="text" name="newfilename" placeholder="$lt{'type'}" value="" onfocus="if (this.value == is.empty()) this.value=''" />&nbsp;<input type="button" value="Go" onclick="validate_go();" />
        !           567:                 <br />
        !           568:                 <span>Quickactions:
        !           569:                  <input type="hidden" name="mode"/>
        !           570:                  <a href="javascript:void(0)" onclick="javascript:validate_action('blank')">
        !           571:                     <img src="/adm/lonIcons/unknown.gif" title="Create blank problem file"></a>
        !           572:                  <a href="javascript:void(0)" onclick="javascript:validate_action('problemtempl')">
        !           573:                     <img src="/adm/lonIcons/problem.gif" title="Create new problem from template"></a>
        !           574:                  <a href="javascript:void(0)" onclick="javascript:validate_action('blankhtml')">
        !           575:                     <img src="/adm/lonIcons/html.gif" title="Create new blank HTML file"></a>
        !           576:                  <a href="javascript:void(0)" onclick="javascript:validate_action('folder')">
        !           577:                     <img src="/adm/lonIcons/navmap.folder.closed.gif" title="Create new subdirectory"></a>
        !           578:                 </span>
        !           579:                  <script type="text/javascript">
        !           580:                      function validate_action(action){
        !           581: 
        !           582:                          if (document.getElementsByName(\'newfilename\')[0].value != \'\'){
        !           583:                              if (action == "blank") {
        !           584:                                                                  document.fileaction.action.value=\'newproblemfile\';
        !           585:                                                                  document.fileaction.mode.value=\'blank\';
        !           586:                                                          } else if (action == "problemtempl") {
        !           587:                                                                  document.fileaction.action.value=\'newproblemfile\';
        !           588:                                  validate_go();
        !           589:                              } else if (action == "blankhtml") {
        !           590:                                  document.fileaction.action.value=\'newhtmlfile\';
        !           591:                                  validate_go();
        !           592:                              } else if (action == "folder") {
        !           593:                                  document.fileaction.action.value=\'newdir\';
        !           594:                                  document.fileaction.mode.value=\'folder\';
        !           595:                              }
        !           596:                              fileaction.submit();
        !           597:                          } else {
        !           598:                              alert(\'Please specify file name.\');
        !           599:                              // TODO: ask for filename? if so, do some refactoring
        !           600: 
        !           601:                          }
        !           602:                      }
        !           603:                  </script>
1.92      albertel  604: 		 </span>
1.116     bisitz    605:       </fieldset>
                    606:     </form>
                    607:   </div>
                    608: </div>
1.64      raeburn   609: END
                    610: }
                    611: 
                    612: sub resourceactions {
                    613:     my ($r,$uname,$udom,$thisdisfn) = @_;
                    614:     $r->print(<<END);
                    615:        <form name="moveresource" action="/adm/cfile" target="_parent" method="post">
                    616:          <input type="hidden" name="filename" value="" />
                    617:          <input type="hidden" name="newfilename" value="" />
                    618:          <input type="hidden" name="action" value="" />
                    619:        </form>
                    620:        <form name="delresource" action="/adm/cfile" target="_parent" method="post">
                    621:          <input type="hidden" name="filename" value="" />
                    622:          <input type="hidden" name="action" value="delete" />
                    623:        </form>
                    624:        <form name="pubresource" action="/adm/publish" target="_parent" method="post">
                    625:          <input type="hidden" name="filename" value="" />
1.80      www       626:          <input type="hidden" name="makeobsolete" value="0" />
1.64      raeburn   627:        </form>
                    628:        <form name="printresource" action="/adm/printout" target="_parent" method="post">
                    629:            <input type="hidden" name="postdata" value="" />
                    630:        </form>
                    631:        <form name="retrieveres" action="/adm/retrieve" target="_parent" method="post">
                    632:            <input type="hidden" name="filename" value="" />
                    633:        </form>
1.82      www       634:        <form name="cleanup" action="/adm/cleanup" target="_parent" method="post">
                    635:            <input type="hidden" name="filename" value="" />
                    636:        </form>
1.64      raeburn   637: END
1.23      foxr      638: }
                    639: 
                    640: #
                    641: #   Get the title string or "[untitled]" if the file has no title metadata:
                    642: #   Without the latter substitution, it's impossible to examine metadata for
                    643: #   untitled resources.  Resources may be legitimately untitled, to prevent
                    644: #   searches from locating them.
                    645: #
                    646: #   $str = getTitleString($fullname);
                    647: #       $fullname - Fully qualified filename to check.
                    648: #
                    649: sub getTitleString {
                    650:     my $fullname = shift;
                    651:     my $title    = &Apache::lonnet::metadata($fullname, 'title');
                    652: 
                    653:     unless ($title) {
1.40      www       654: 	$title = "[".&mt('untitled')."]";
1.23      foxr      655:     }
                    656:     return $title;
                    657: }
                    658: 
1.55      www       659: sub getCopyRightString {
                    660:     my $fullname = shift;
                    661:     return &Apache::lonnet::metadata($fullname, 'copyright');
                    662: }
1.61      www       663: 
                    664: sub getSourceRightString {
                    665:     my $fullname = shift;
                    666:     return &Apache::lonnet::metadata($fullname, 'sourceavail');
                    667: }
1.23      foxr      668: #
1.21      foxr      669: #  Put out a directory table row:
1.134     raeburn   670: #    putdirectory(r, base, here, dirname, modtime, targetdir, bombs, numdir)
                    671: #      r         - Apache request object.
                    672: #      reqfile   - File in request.
                    673: #      here      - Where we are in directory tree.
                    674: #      dirname   - Name of directory special file.
                    675: #      modtime   - Encoded modification time.
                    676: #      targetdir - Publication target directory.
                    677: #      bombs     - Reference to hash of URLs with runtime error messages.
                    678: #      numdir    - Reference to scalar used to track number of sub-directories
                    679: #                  in directory (used in form name for each "actions" dropdown).
                    680: #
1.21      foxr      681: sub putdirectory {
1.134     raeburn   682:     my ($r, $reqfile, $here, $dirname, $modtime, $targetdir, $bombs, $numdir) = @_;
1.129     www       683: 
                    684: # construct the display filename: the directory name unless ..:
1.133     www       685:    
                    686:     my $actionitem;
                    687:  
1.21      foxr      688:     my $disfilename = $dirname;
1.130     www       689: # Don't display directory itself, and there is no way up from root directory
1.133     www       690:     unless ((($dirname eq '..') && ($reqfile=~/^\/[^\/]+\/[^\/]+$/)) || ($dirname eq '.')) {
1.143     bisitz    691:         my $kaputt=0;
1.134     raeburn   692:         if (ref($bombs) eq 'HASH') {
1.143     bisitz    693:             foreach my $key (keys(%{$bombs})) {
                    694:                 my $currentdir = &Apache::lonnet::declutter("$targetdir/$disfilename");
                    695:                 if (($key) =~ m{^\Q$currentdir\E/}) { $kaputt=1; last; }
                    696:             }
1.134     raeburn   697:         }
1.129     www       698: #
                    699: # Get the metadata from that directory's default.meta to display titles
                    700: #
1.52      www       701: 	%Apache::lonpublisher::metadatafields=();
                    702: 	%Apache::lonpublisher::metadatakeys=();
1.129     www       703: 	&Apache::lonpublisher::metaeval(
                    704:                  &Apache::lonnet::getfile($r->dir_config('lonDocRoot').$here.'/'.$dirname.'/default.meta')
                    705:                                        );
1.133     www       706:         if ($dirname eq '..') {
1.109     bisitz    707:             $actionitem = &mt('Go to ...');
1.133     www       708:             $disfilename = '<i>'.&mt('Parent Directory').'</i>';
1.64      raeburn   709:         } else {
                    710:             $actionitem = 
                    711:                     '<form name="dirselect_'.$$numdir.
                    712:                     '" action="/adm/publish" target="_parent">'.
1.85      albertel  713:                     '<select name="diraction" onchange="SetPubDir(this.form,document)">'.
1.64      raeburn   714:                       '<option selected="selected">'.&mt('Select action').'</option>'.
                    715:                       '<option value="open">'.&mt('Open').'</option>'.
                    716:                       '<option value="publish">'.&mt('Publish').'</option>'.
1.113     schafran  717:                       '<option value="editmeta">'.&mt('Edit Metadata').'</option>'.
1.77      albertel  718:                       '<option value="printdir">'.&mt('Print directory').'</option>'.
1.88      raeburn   719:                       '<option value="delete">'.&mt('Delete directory').'</option>'.
1.64      raeburn   720:                     '</select>'.
1.129     www       721:                      '<input type="hidden" name="filename" value="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" />'.
1.75      albertel  722:                      '<input type="hidden" name="openname" value="'.$here.'/'.$dirname.'/" />'.
1.64      raeburn   723:                      '<input type="hidden" name="postdata" value="" />'.
                    724:                    '</form>';
                    725:             $$numdir ++;
                    726:         }
1.92      albertel  727: 	$r->print('<tr class="LC_browser_folder">'.
1.53      www       728: 		  '<td><img src="'.
1.123     bisitz    729: 		  $Apache::lonnet::perlvar{'lonIconsURL'}.'/navmap.folder.closed.gif" alt="folder" /></td>'.
1.64      raeburn   730: 		  '<td>'.$actionitem.'</td>'.
1.92      albertel  731: 		  '<td><span class="LC_filename"><a href="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" target="_parent">'.
                    732: 		  $disfilename.'</a></span></td>'.
1.134     raeburn   733: 		        '<td colspan="3">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($targetdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'});
1.92      albertel  734: 	if ($Apache::lonpublisher::metadatafields{'subject'} ne '') {
                    735: 	    $r->print(' <i>'.
                    736: 		      $Apache::lonpublisher::metadatafields{'subject'}.
                    737: 		      '</i> ');
                    738: 	}
                    739: 	$r->print($Apache::lonpublisher::metadatafields{'keywords'}.'</td>'.
1.42      www       740: 		  '<td>'.&Apache::lonlocal::locallocaltime($modtime).'</td>'.
1.152     musolffc  741: 	          '<td></td>'.
1.25      www       742: 		  "</tr>\n");
1.64      raeburn   743:     }
1.154     raeburn   744:     return;
1.21      foxr      745: }
1.152     musolffc  746: 
                    747: sub getTitle {
                    748:     my ($resdir, $targetdir, $filename, $linkfilename, $meta_same, $bombs) = @_;
                    749:     my $title='';
                    750:     my $titleString = &getTitleString($targetdir.'/'.$filename);
                    751:     if (-e $resdir.'/'.$filename) {
                    752: 	$title = '<a href="'.$targetdir.'/'.$filename.
                    753: 	    '.meta" target="cat">'.$titleString.'</a>';
                    754:         if (!$meta_same) {
                    755: 	    $title = &mt('Metadata Modified').'<br />'.$title.
                    756: 		'<br />'.
                    757:                 &Apache::loncommon::modal_link(
                    758:                     '/adm/diff?filename='.$linkfilename.'.meta'.'&amp;versiontwo=priv',
                    759:                     &mt('Metadata Diffs'),600,500);
                    760: 	    $title.="\n".'<br />'.
                    761:                 &Apache::loncommon::modal_link(
                    762:                     '/adm/retrieve?filename='.$linkfilename.'.meta&amp;inhibitmenu=yes&amp;add_modal=yes',
                    763:                     &mt('Retrieve Metadata'),600,500);
                    764:         } 
                    765:     }
                    766:     # Allow editing metadata of published and unpublished resources
                    767:     $title .= "\n".'<br />' if ($title);
                    768:     $title .= '<a href="'.$linkfilename.'.meta">'.
                    769:               ($$bombs{&Apache::lonnet::declutter($targetdir.'/'.$filename)}?
                    770:                   '<img src="/adm/lonMisc/bomb.gif" border="0" alt="'.&mt('bomb').'" />':
                    771:                   &mt('Edit Metadata')).
                    772:               '</a>';
                    773: 
                    774:     return ($title, $titleString);
                    775: }
                    776: 
                    777: 
                    778: sub isMetaSame {
                    779:     my ($cstr_dir, $resdir, $filename) = @_;
                    780:     my $meta_cmtime = (stat($cstr_dir.'/'.$filename.'.meta'))[9];
                    781:     my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
                    782:     return (&Apache::londiff::are_different_files($resdir.'/'.$filename.'.meta',
                    783:             $cstr_dir.'/'.$filename.'.meta') && $meta_rmtime < $meta_cmtime) 
                    784:         ? 0 : 1;
                    785: }
                    786:     
                    787: 
                    788: sub getStatus {    
                    789:     my ($resdir, $targetdir, $cstr_dir, $filename,  
                    790:             $linkfilename, $cmtime, $meta_same) = @_;
1.64      raeburn   791:     my $pubstatus = 'unpublished';
1.152     musolffc  792:     my $status = &mt('Unpublished');
1.129     www       793: 
1.22      foxr      794:     if (-e $resdir.'/'.$filename) {
1.152     musolffc  795:         my $same = 0;
                    796:         if ((stat($resdir.'/'.$filename))[9] >= $cmtime) {
                    797:             $same = 1;
1.91      www       798:         } else {
                    799:            if (&Apache::londiff::are_different_files($resdir.'/'.$filename,
1.95      albertel  800: 						     $cstr_dir.'/'.$filename)) {
1.152     musolffc  801:               $same = 0;
1.91      www       802:            } else {
1.152     musolffc  803:               $same = 1;
1.91      www       804:            }
                    805:         }
1.124     bisitz    806: 
                    807:         my $rights_status =
                    808:             &mt(&getCopyRightString($targetdir.'/'.$filename)).', ';
                    809: 
                    810:         my %lt_SourceRight = &Apache::lonlocal::texthash(
                    811:                'open'   => 'Source: open',
                    812:                'closed' => 'Source: closed',
                    813:         );
                    814:         $rights_status .=
                    815:             $lt_SourceRight{&getSourceRightString($targetdir.'/'.$filename)};
                    816: 
1.91      www       817: 	if ($same) {
1.40      www       818: 	    if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
1.64      raeburn   819:                 $pubstatus = 'obsolete';
1.41      www       820: 		$status=&mt('Obsolete');
1.95      albertel  821:             } else {
                    822: 		if (!$meta_same) {
                    823: 		    $pubstatus = 'metamodified';
                    824: 		} else {
                    825: 		    $pubstatus = 'published';
                    826: 		}
                    827: 		$status=&mt('Published').
                    828: 		    '<br />'. $rights_status;
                    829: 	    }
1.22      foxr      830: 	} else {
1.64      raeburn   831:             $pubstatus = 'modified';
1.95      albertel  832: 	    $status=&mt('Modified').
                    833: 		'<br />'. $rights_status;
1.22      foxr      834: 	    if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
1.139     www       835: 		$status.='<br />'.
                    836:                          &Apache::loncommon::modal_link(
                    837:                              '/adm/diff?filename='.$linkfilename.'&amp;versiontwo=priv',
                    838:                              &mt('Diffs'),600,500);
1.22      foxr      839: 	    }
1.95      albertel  840: 	} 
1.152     musolffc  841: 
1.140     www       842: 	$status.="\n".'<br />'.
                    843:              &Apache::loncommon::modal_link(
                    844:                  '/adm/retrieve?filename='.$linkfilename.'&amp;inhibitmenu=yes&amp;add_modal=yes',&mt('Retrieve'),600,500);
1.22      foxr      845:     }
1.152     musolffc  846: 
                    847:     return ($status, $pubstatus);
                    848: }
                    849: 
                    850: 
                    851: #
                    852: #   Put a table row for a file resource.
                    853: #
                    854: sub putresource {
                    855:     my ($r, $udom, $uname, $filename, $thisdisfn, $resdir, $targetdir, 
                    856:             $linkdir, $cmtime, $size, $numres, $linkfilename, $title, 
                    857:             $status, $pubstatus) = @_;
                    858:     &Apache::lonnet::devalidate_cache_new('meta',$targetdir.'/'.$filename);
1.143     bisitz    859: 
1.33      www       860:     my $editlink='';
1.38      taceyjo1  861:     my $editlink2='';
1.36      www       862:     if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty)$/) {
1.146     raeburn   863: 	$editlink=' <br />(<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&amp;problemmode=edit">'.&mt('Edit').'</a>)';
1.34      www       864:     }
1.136     www       865:     if ($filename=~/$LONCAPA::assess_re/) {
1.146     raeburn   866: 	$editlink=' (<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&amp;problemmode=editxml">'.&mt('EditXML').'</a>)';
                    867: 	$editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&amp;problemmode=edit">'.&mt('Edit').'</a>)';
1.43      taceyjo1  868:     }
1.82      www       869:     if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) {
1.129     www       870: 	$editlink.=' (<a href="/adm/cleanup?filename='.$linkfilename.'" target="_parent">'.&mt('Clean Up').')</a>';
1.82      www       871:     }
1.43      taceyjo1  872:     if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.129     www       873: 	$editlink=' (<a target="_parent" href="/adm/cfile?decompress='.$linkfilename.'">'.&mt('Decompress').'</a>)';
1.33      www       874:     }
1.152     musolffc  875:     my $publish_button = (-e $resdir.'/'.$filename) ? &mt('Re-publish') : &mt('Publish');
1.64      raeburn   876:     my $pub_select = '';
                    877:     &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres);
1.115     bisitz    878:     $r->print(&Apache::loncommon::start_data_table_row().
1.53      www       879: 	      '<td>'.($filename=~/[\#\~]$/?'&nbsp;':
1.86      albertel  880: 		      '<img src="'.&Apache::loncommon::icon($filename).'" alt="" />').'</td>'.
1.64      raeburn   881:               '<td>'.$pub_select.'</td>'.
1.104     albertel  882: 	      '<td><span class="LC_filename">'.
1.64      raeburn   883: 	      '<a href="'.$linkdir.'/'.$filename.'" target="_parent">'.
1.92      albertel  884:                $filename.'</a></span>'.$editlink2.$editlink.
1.22      foxr      885: 	      '</td>'.
                    886: 	      '<td>'.$title.'</td>'.
1.115     bisitz    887:               '<td class="LC_browser_file_'.$pubstatus.'">&nbsp;&nbsp;</td>'. # Display publication status
                    888:               '<td>'.$status.'</td>'.
1.42      www       889: 	      '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'.
1.153     raeburn   890: 	      '<td>'.sprintf("%.1f",$size).'</td>'.
1.115     bisitz    891: 	      &Apache::loncommon::end_data_table_row()
                    892:     );
1.154     raeburn   893:     return;
1.23      foxr      894: }
1.64      raeburn   895: 
                    896: sub create_pubselect {
                    897:     my ($r,$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres) = @_;
                    898:     $$pub_select = '
                    899: <form name="resselect_'.$$numres.'" action="">
1.85      albertel  900: <select name="reschoice"  onchange="SetResChoice(this.form)">
1.77      albertel  901: <option>'.&mt('Select action').'</option>'.
                    902: '<option value="copy">'.&mt('Copy').'</option>';
1.68      raeburn   903:     if ($pubstatus eq 'obsolete' || $pubstatus eq 'unpublished') {
                    904:         $$pub_select .= 
1.77      albertel  905: '<option value="rename">'.&mt('Rename').'</option>'.
                    906: '<option value="move">'.&mt('Move').'</option>'.
                    907: '<option value="delete">'.&mt('Delete').'</option>';
1.64      raeburn   908:     } else {
                    909:         $$pub_select .= '
1.77      albertel  910: <option value="obsolete">'.&mt('Mark obsolete').'</option>';
1.64      raeburn   911:     }
                    912: # check for versions
                    913:     my $versions = &check_for_versions($r,'/'.$filename,$udom,$uname);
                    914:     if ($versions > 0) {
                    915:         $$pub_select .='
1.77      albertel  916: <option value="retrieve">'.&mt('Retrieve old version').'</option>';
1.64      raeburn   917:     }
                    918:     $$pub_select .= '
1.77      albertel  919: <option value="publish">'.$publish_button.'</option>'.
1.82      www       920: '<option value="cleanup">'.&mt('Clean up').'</option>'.
1.77      albertel  921: '<option value="print">'.&mt('Print').'</option>'.
1.68      raeburn   922: '</select>
1.131     www       923: <input type="hidden" name="filename" value="/priv'.
                    924:  &HTML::Entities::encode($thisdisfn.'/'.$filename,'<>&"').'" />
1.96      banghart  925:  <input type="hidden" name="dispfilename" value="'.
1.99      albertel  926:  &HTML::Entities::encode($filename).'" /></form>';
1.64      raeburn   927:     $$numres ++;
                    928: }
                    929: 
                    930: sub check_for_versions {
                    931:     my ($r,$fn,$udom,$uname) = @_;
                    932:     my $versions = 0;
                    933:     my $docroot=$r->dir_config('lonDocRoot');
                    934:     my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
                    935:     my $resdir=$resfn;
                    936:     $resdir=~s/\/[^\/]+$/\//;
                    937:     $fn=~/\/([^\/]+)\.(\w+)$/;
                    938:     my $main=$1;
                    939:     my $suffix=$2;
                    940:     opendir(DIR,$resdir);
                    941:     while (my $filename=readdir(DIR)) {
                    942:         if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
                    943:             $versions ++;        
                    944:         }
                    945:     }
1.154     raeburn   946:     closedir(DIR);
1.64      raeburn   947:     return $versions;
                    948: }
                    949: 
1.4       www       950: 1;
                    951: __END__
1.17      harris41  952: 
                    953: 
1.114     jms       954: =head1 NAME
                    955: 
1.145     raeburn   956: Apache::lonpubdir - Authoring space directory lister
1.114     jms       957: 
                    958: =head1 SYNOPSIS
                    959: 
                    960: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
                    961: 
1.134     raeburn   962:  <LocationMatch "^/+priv.*/$">
1.114     jms       963:  PerlAccessHandler       Apache::loncacc
                    964:  SetHandler perl-script
                    965:  PerlHandler Apache::lonpubdir
                    966:  ErrorDocument     403 /adm/login
                    967:  ErrorDocument     404 /adm/notfound.html
                    968:  ErrorDocument     406 /adm/unauthorized.html
                    969:  ErrorDocument	  500 /adm/errorhandler
                    970:  </LocationMatch>
                    971: 
                    972:  <Location /adm/pubdir>
                    973:  PerlAccessHandler       Apache::lonacc
                    974:  SetHandler perl-script
                    975:  PerlHandler Apache::lonpubdir
                    976:  ErrorDocument     403 /adm/login
                    977:  ErrorDocument     404 /adm/notfound.html
                    978:  ErrorDocument     406 /adm/unauthorized.html
                    979:  ErrorDocument	  500 /adm/errorhandler
                    980:  </Location>
                    981: 
                    982: =head1 INTRODUCTION
                    983: 
                    984: This module publishes a directory of files.
                    985: 
                    986: This is part of the LearningOnline Network with CAPA project
                    987: described at http://www.lon-capa.org.
                    988: 
                    989: =head1 HANDLER SUBROUTINE
                    990: 
                    991: This routine is called by Apache and mod_perl.
                    992: 
                    993: =over 4
                    994: 
                    995: =item *
                    996: 
                    997: read in information
                    998: 
                    999: =item *
                   1000: 
                   1001: start page output
                   1002: 
                   1003: =item *
                   1004: 
                   1005: run through list of files and attempt to publish unhidden files
                   1006: 
                   1007: =back
                   1008: 
                   1009: =head1 SUBROUTINES:
                   1010: 
                   1011: =over
                   1012: 
                   1013: =item startpage($r, $uame, $udom, $thisdisfn)
                   1014: 
                   1015: Output the header of the page.  This includes:
                   1016:  - The HTML header 
                   1017:  - The H1/H3  stuff which includes the directory.
                   1018:  
                   1019:     startpage($r, $uame, $udom, $thisdisfn);
                   1020:         $r     - The apache request object.
                   1021:         $uname - User name.
                   1022:         $udom  - Domain name the user is logged in under.
                   1023:         $thisdisfn - Displayable version of the filename.
                   1024: 
                   1025: =item getTitleString($fullname)
                   1026: 
                   1027:     Get the title string or "[untitled]" if the file has no title metadata:
                   1028:     Without the latter substitution, it's impossible to examine metadata for
                   1029:     untitled resources.  Resources may be legitimately untitled, to prevent
                   1030:     searches from locating them.
                   1031:     
                   1032:     $str = getTitleString($fullname);
                   1033:         $fullname - Fully qualified filename to check.
                   1034: 
1.134     raeburn  1035: =item putdirectory($r, $base, $here, $dirname, $modtime, $targetdir, $bombs,
                   1036:                    $numdir)
1.114     jms      1037: 
                   1038:     Put out a directory table row:
                   1039:     
1.134     raeburn  1040:         $r        - Apache request object.
                   1041:         $reqfile  - File in request.
                   1042:         $here     - Where we are in directory tree.
                   1043:         $dirname  - Name of directory special file.
                   1044:         $modtime  - Encoded modification time.
                   1045:         targetdir - Publication target directory.
                   1046:         bombs     - Reference to hash of URLs with runtime error messages.
                   1047:         numdir    - Reference to scalar used to track number of sub-directories
                   1048:                     in directory (used in form name for each "actions" dropdown).
1.114     jms      1049: 
                   1050: =back
                   1051: 
                   1052: =cut

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