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

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

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