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

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.3! (raeburn    4:: # $Id: lonpubdir.pm,v 1.160.2.5.2.2 2023/12/29 21:36:23 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.121     bisitz    357:     $r->print(&Apache::loncommon::head_subbox(
1.147     raeburn   358:                      '<div style="float:right;padding-top:0;margin-top;0">'
1.160.2.1  raeburn   359:                     .&Apache::lonhtmlcommon::display_usage($current_disk_usage,
                    360:                                                            $disk_quota,'authoring')
1.147     raeburn   361:                     .'</div>'
                    362:                     .&Apache::loncommon::CSTR_pageheader()));
1.121     bisitz    363: 
1.101     albertel  364:     my $esc_thisdisfn = &Apache::loncommon::escape_single($thisdisfn);
1.145     raeburn   365:     my $doctitle = 'LON-CAPA '.&mt('Authoring Space');
1.109     bisitz    366:     my $newname = &mt('New Name');
1.29      www       367:     my $pubdirscript=(<<ENDPUBDIRSCRIPT);
1.77      albertel  368: <script type="text/javascript">
1.107     bisitz    369: top.document.title = '$esc_thisdisfn/ - $doctitle';
1.37      www       370: // Store directory location for menu bar to find
                    371: 
1.132     www       372: parent.lastknownpriv='/priv$esc_thisdisfn/';
1.37      www       373: 
                    374: // Confirmation dialogues
                    375: 
1.64      raeburn   376:     function currdiract(theform) {
                    377:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publish') {
1.79      www       378:             document.publishdir.filename.value = theform.filename.value;
                    379: 	    document.publishdir.submit();
1.64      raeburn   380:         }
1.113     schafran  381:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editmeta') {
1.66      raeburn   382:             top.location=theform.filename.value+'default.meta'
1.64      raeburn   383:         }
                    384:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) {
                    385:             document.printdir.postdata.value=theform.filename.value
                    386:             document.printdir.submit();
                    387:         }
1.88      raeburn   388:         if (theform.dirtask.options[theform.dirtask.selectedIndex].value == "delete") {
                    389:               var delform = document.delresource
                    390:               delform.filename.value = theform.filename.value
                    391:               delform.submit()
                    392:         }
1.64      raeburn   393:     }
                    394:   
                    395:     function checkUpload(theform) {
                    396:         if (theform.file == '') {
                    397:             alert("Please use 'Browse..' to choose a file first, before uploading")
                    398:             return 
                    399:         }
                    400:         theform.submit()  
                    401:     }
                    402: 
                    403:     function SetPubDir(theform,printForm) {
                    404:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "open") {
1.75      albertel  405:             top.location = theform.openname.value
1.64      raeburn   406:             return
                    407:         }
                    408:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "publish") {
1.79      www       409:             theform.submit();
1.64      raeburn   410:         }
1.113     schafran  411:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "editmeta") {
1.66      raeburn   412:             top.location=theform.filename.value+'default.meta'
1.64      raeburn   413:         }
1.68      raeburn   414:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "printdir") {
1.64      raeburn   415:             theform.action = '/adm/printout'
                    416:             theform.postdata.value = theform.filename.value
                    417:             theform.submit()
                    418:         }
1.88      raeburn   419:         if (theform.diraction.options[theform.diraction.selectedIndex].value == "delete") {
                    420:               var delform = document.delresource
                    421:               delform.filename.value = theform.filename.value
                    422:               delform.submit()
                    423:         }
1.64      raeburn   424:         return
                    425:     }
                    426:     function SetResChoice(theform) {
                    427:       var activity = theform.reschoice.options[theform.reschoice.selectedIndex].value
                    428:       if ((activity == 'rename') || (activity == 'copy') || (activity == 'move')) {
                    429:           changename(theform,activity)
                    430:       }
                    431:       if (activity == 'publish') {
                    432:           var pubform = document.pubresource
                    433:           pubform.filename.value = theform.filename.value
                    434:           pubform.submit()
                    435:       }
                    436:       if (activity == 'delete') {
                    437:           var delform = document.delresource
                    438:           delform.filename.value = theform.filename.value
1.71      raeburn   439:           delform.submit()
1.64      raeburn   440:       }
                    441:       if (activity == 'obsolete') {
1.68      raeburn   442:           var pubform = document.pubresource
                    443:           pubform.filename.value = theform.filename.value
1.80      www       444:           pubform.makeobsolete.value=1;
1.68      raeburn   445:           pubform.submit()
1.64      raeburn   446:       }
                    447:       if (activity == 'print') {
1.68      raeburn   448:           document.printresource.postdata.value = theform.filename.value
1.64      raeburn   449:           document.printresource.submit()
                    450:       }
                    451:       if (activity == 'retrieve') {
1.68      raeburn   452:           document.retrieveres.filename.value = theform.filename.value
                    453:           document.retrieveres.submit()
1.64      raeburn   454:       }
1.82      www       455:       if (activity == 'cleanup') {
                    456:           document.cleanup.filename.value = theform.filename.value
                    457:           document.cleanup.submit()
                    458:       }
1.64      raeburn   459:       return
                    460:     }
                    461:     function changename(theform,activity) {
1.96      banghart  462:         var oldname=theform.dispfilename.value;
1.109     bisitz    463:         var newname=prompt('$newname',oldname);
1.97      banghart  464:         if (newname == "" || !newname || newname == oldname)  {
1.64      raeburn   465:             return
                    466:         }
                    467:         document.moveresource.newfilename.value = newname
                    468:         document.moveresource.filename.value = theform.filename.value
                    469:         document.moveresource.action.value = activity
                    470:         document.moveresource.submit();
                    471:     }
1.29      www       472: </script>
                    473: ENDPUBDIRSCRIPT
1.64      raeburn   474:     $r->print($pubdirscript);
                    475: }
                    476: 
                    477: sub dircontrols {
1.160.2.4  raeburn   478:     my ($r,$uname,$udom,$thisdisfn, $current_disk_usage, $disk_quota) = @_;
1.84      www       479:     my %lt=&Apache::lonlocal::texthash(
                    480:                                        cnpd => 'Cannot publish directory',
                    481:                                        cnrd => 'Cannot retrieve directory',
                    482:                                        mcdi => 'Must create new subdirectory inside a directory',
                    483:                                        pubr => 'Publish this Resource',
                    484:                                        pubd => 'Publish this Directory',
1.88      raeburn   485:                                        dedr => 'Delete Directory',
1.84      www       486:                                        rtrv => 'Retrieve Old Version',
                    487:                                        list => 'List Directory',
                    488:                                        uplo => 'Upload file',  
                    489:                                        dele => 'Delete',
1.113     schafran  490:                                        edit => 'Edit Metadata', 
1.84      www       491:                                        sela => 'Select Action',
                    492:                                        nfil => 'New file',
                    493:                                        nhtm => 'New HTML file',
                    494:                                        nprb => 'New problem',
                    495:                                        npag => 'New assembled page',
                    496:                                        nseq => 'New assembled sequence',
                    497:                                        ncrf => 'New custom rights file',
                    498:                                        nsty => 'New style file',
                    499:                                        nlib => 'New library file',
1.103     albertel  500:                                        nbt  => 'New bridgetask file',
1.84      www       501:                                        nsub => 'New subdirectory',
                    502:                                        renm => 'Rename current file to',
                    503:                                        move => 'Move current file to',
                    504:                                        copy => 'Copy current file to',
                    505:                                        type => 'Type Name Here',
1.105     albertel  506:                                        go   => 'Go',
1.84      www       507:                                        prnt => 'Print contents of directory',
                    508:                                        crea => 'Create a new directory or LON-CAPA document',
                    509: 				       acti => 'Actions for current directory',
1.105     albertel  510: 				       updc => 'Upload a new document',
                    511: 				       pick => 'Please select an action to perform using the new filename',
1.84      www       512:                                       );
1.106     bisitz    513:     my $mytype = $lt{'type'}; # avoid conflict with " and ' in javascript
1.160.2.4  raeburn   514:     # Calculate free space in bytes.
                    515:     # $disk_quota is in MB and $current_disk_usage is in kB
                    516:     my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.64      raeburn   517:     $r->print(<<END);
1.117     harmsja   518: <div class="LC_columnSection">
1.116     bisitz    519:   <div>
                    520:     <form name="curractions" method="post" action="">
                    521:       <fieldset>
                    522:         <legend>$lt{'acti'}</legend>
                    523:         <select name="dirtask" onchange="currdiract(this.form)">
1.84      www       524:             <option>$lt{'sela'}</option>
                    525:             <option value="publish">$lt{'pubd'}</option>
1.113     schafran  526:             <option value="editmeta">$lt{'edit'}</option>
1.84      www       527:             <option value="printdir">$lt{'prnt'}</option>
1.88      raeburn   528:             <option value="delete">$lt{'dedr'}</option>
1.116     bisitz    529:         </select>
1.132     www       530:         <input type="hidden" name="filename" value="/priv$thisdisfn/" />
1.116     bisitz    531:       </fieldset>
                    532:     </form>
1.160.2.5.2.1  (raeburn  533::     <form name="publishdir" method="post" action="/adm/publish">
1.116     bisitz    534:       <input type="hidden" name="pubrec" value="" />
                    535:       <input type="hidden" name="filename" value="" />
                    536:     </form>
1.160.2.5.2.1  (raeburn  537::     <form name="printdir" method="post" action="/adm/printout">
1.116     bisitz    538:       <input type="hidden" name="postdata" value="" />
                    539:     </form>
                    540:   </div>
                    541: 
1.160.2.3  raeburn   542:   <div style="padding-bottom: 2px">
1.160.2.5.2.1  (raeburn  543::     <form name="upublisher" enctype="multipart/form-data" method="post" action="/adm/upload">
1.116     bisitz    544:       <fieldset>
                    545:         <legend>$lt{'updc'}</legend>
1.132     www       546:         <input type="hidden" name="filename" value="/priv$thisdisfn/" />
1.160.2.4  raeburn   547:         <input type="file" name="upfile" class="LC_flUpload" size="20" />
                    548:         <input type="hidden" id="LC_free_space" value="$free_space" />
1.116     bisitz    549:         <input type="button" value="$lt{'uplo'}"  onclick="checkUpload(this.form)" />
                    550:       </fieldset>
                    551:     </form>
                    552:   </div>
                    553: 
                    554:   <div>
1.160.2.5.2.1  (raeburn  555::     <form name="fileaction" method="post" action="/adm/cfile">
1.116     bisitz    556:       <fieldset>
                    557:               <legend>$lt{'crea'}</legend>
                    558: 	      <span class="LC_nobreak">
1.132     www       559: 		<input type="hidden" name="filename" value="/priv$thisdisfn/" />
1.105     albertel  560:                   <script type="text/javascript">
                    561:                     function validate_go() {
                    562:                         var selected = document.fileaction.action.selectedIndex;
                    563:                         if (selected == 0) {
                    564:                             alert('$lt{'pick'}');
                    565:                         } else {
                    566:                             document.fileaction.submit();
                    567:                         }
                    568:                     }
                    569:                   </script>
                    570: 		  <select name="action">
                    571: 		    <option value="none">$lt{'sela'}</option>
                    572: 		    <option value="newfile">$lt{'nfil'}:</option>
                    573: 		    <option value="newhtmlfile">$lt{'nhtm'}:</option>
                    574: 		    <option value="newproblemfile">$lt{'nprb'}:</option>
                    575:                     <option value="newpagefile">$lt{'npag'}:</option>
                    576:                     <option value="newsequencefile">$lt{'nseq'}:</option>
                    577:                     <option value="newrightsfile">$lt{'ncrf'}:</option>
                    578:                     <option value="newstyfile">$lt{'nsty'}:</option>
                    579:                     <option value="newtaskfile">$lt{'nbt'}:</option>
                    580:                     <option value="newlibraryfile">$lt{'nlib'}:</option>
                    581: 	            <option value="newdir">$lt{'nsub'}:</option>
1.160.2.2  raeburn   582: 		  </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();" />
                    583:                 <br />
                    584:                 <span>Quickactions:
                    585:                  <input type="hidden" name="mode"/>
                    586:                  <a href="javascript:void(0)" onclick="javascript:validate_action('blank')">
                    587:                     <img src="/adm/lonIcons/unknown.gif" title="Create blank problem file"></a>
                    588:                  <a href="javascript:void(0)" onclick="javascript:validate_action('problemtempl')">
                    589:                     <img src="/adm/lonIcons/problem.gif" title="Create new problem from template"></a>
                    590:                  <a href="javascript:void(0)" onclick="javascript:validate_action('blankhtml')">
                    591:                     <img src="/adm/lonIcons/html.gif" title="Create new blank HTML file"></a>
                    592:                  <a href="javascript:void(0)" onclick="javascript:validate_action('folder')">
                    593:                     <img src="/adm/lonIcons/navmap.folder.closed.gif" title="Create new subdirectory"></a>
                    594:                 </span>
                    595:                  <script type="text/javascript">
                    596:                      function validate_action(action){
                    597: 
                    598:                          if (document.getElementsByName(\'newfilename\')[0].value != \'\'){
                    599:                              if (action == "blank") {
                    600:                                                                  document.fileaction.action.value=\'newproblemfile\';
                    601:                                                                  document.fileaction.mode.value=\'blank\';
                    602:                                                          } else if (action == "problemtempl") {
                    603:                                                                  document.fileaction.action.value=\'newproblemfile\';
                    604:                                  validate_go();
                    605:                              } else if (action == "blankhtml") {
                    606:                                  document.fileaction.action.value=\'newhtmlfile\';
                    607:                                  validate_go();
                    608:                              } else if (action == "folder") {
                    609:                                  document.fileaction.action.value=\'newdir\';
                    610:                                  document.fileaction.mode.value=\'folder\';
                    611:                              }
                    612:                              fileaction.submit();
                    613:                          } else {
                    614:                              alert(\'Please specify file name.\');
                    615:                              // TODO: ask for filename? if so, do some refactoring
                    616: 
                    617:                          }
                    618:                      }
                    619:                  </script>
1.92      albertel  620: 		 </span>
1.116     bisitz    621:       </fieldset>
                    622:     </form>
                    623:   </div>
                    624: </div>
1.64      raeburn   625: END
                    626: }
                    627: 
                    628: sub resourceactions {
                    629:     my ($r,$uname,$udom,$thisdisfn) = @_;
                    630:     $r->print(<<END);
1.160.2.5.2.1  (raeburn  631::        <form name="moveresource" action="/adm/cfile" method="post">
1.64      raeburn   632:          <input type="hidden" name="filename" value="" />
                    633:          <input type="hidden" name="newfilename" value="" />
                    634:          <input type="hidden" name="action" value="" />
                    635:        </form>
1.160.2.5.2.1  (raeburn  636::        <form name="delresource" action="/adm/cfile" method="post">
1.64      raeburn   637:          <input type="hidden" name="filename" value="" />
                    638:          <input type="hidden" name="action" value="delete" />
                    639:        </form>
1.160.2.5.2.1  (raeburn  640::        <form name="pubresource" action="/adm/publish" method="post">
1.64      raeburn   641:          <input type="hidden" name="filename" value="" />
1.80      www       642:          <input type="hidden" name="makeobsolete" value="0" />
1.64      raeburn   643:        </form>
1.160.2.5.2.1  (raeburn  644::        <form name="printresource" action="/adm/printout" method="post">
1.64      raeburn   645:            <input type="hidden" name="postdata" value="" />
                    646:        </form>
1.160.2.5.2.1  (raeburn  647::        <form name="retrieveres" action="/adm/retrieve" method="post">
1.64      raeburn   648:            <input type="hidden" name="filename" value="" />
                    649:        </form>
1.160.2.5.2.1  (raeburn  650::        <form name="cleanup" action="/adm/cleanup" method="post">
1.82      www       651:            <input type="hidden" name="filename" value="" />
                    652:        </form>
1.64      raeburn   653: END
1.23      foxr      654: }
                    655: 
                    656: #
                    657: #   Get the title string or "[untitled]" if the file has no title metadata:
                    658: #   Without the latter substitution, it's impossible to examine metadata for
                    659: #   untitled resources.  Resources may be legitimately untitled, to prevent
                    660: #   searches from locating them.
                    661: #
                    662: #   $str = getTitleString($fullname);
                    663: #       $fullname - Fully qualified filename to check.
                    664: #
                    665: sub getTitleString {
                    666:     my $fullname = shift;
                    667:     my $title    = &Apache::lonnet::metadata($fullname, 'title');
                    668: 
                    669:     unless ($title) {
1.40      www       670: 	$title = "[".&mt('untitled')."]";
1.23      foxr      671:     }
                    672:     return $title;
                    673: }
                    674: 
1.55      www       675: sub getCopyRightString {
                    676:     my $fullname = shift;
                    677:     return &Apache::lonnet::metadata($fullname, 'copyright');
                    678: }
1.61      www       679: 
                    680: sub getSourceRightString {
                    681:     my $fullname = shift;
                    682:     return &Apache::lonnet::metadata($fullname, 'sourceavail');
                    683: }
1.23      foxr      684: #
1.21      foxr      685: #  Put out a directory table row:
1.134     raeburn   686: #    putdirectory(r, base, here, dirname, modtime, targetdir, bombs, numdir)
                    687: #      r         - Apache request object.
                    688: #      reqfile   - File in request.
                    689: #      here      - Where we are in directory tree.
                    690: #      dirname   - Name of directory special file.
                    691: #      modtime   - Encoded modification time.
                    692: #      targetdir - Publication target directory.
                    693: #      bombs     - Reference to hash of URLs with runtime error messages.
                    694: #      numdir    - Reference to scalar used to track number of sub-directories
                    695: #                  in directory (used in form name for each "actions" dropdown).
                    696: #
1.21      foxr      697: sub putdirectory {
1.134     raeburn   698:     my ($r, $reqfile, $here, $dirname, $modtime, $targetdir, $bombs, $numdir) = @_;
1.129     www       699: 
                    700: # construct the display filename: the directory name unless ..:
1.133     www       701:    
                    702:     my $actionitem;
                    703:  
1.21      foxr      704:     my $disfilename = $dirname;
1.130     www       705: # Don't display directory itself, and there is no way up from root directory
1.133     www       706:     unless ((($dirname eq '..') && ($reqfile=~/^\/[^\/]+\/[^\/]+$/)) || ($dirname eq '.')) {
1.143     bisitz    707:         my $kaputt=0;
1.134     raeburn   708:         if (ref($bombs) eq 'HASH') {
1.143     bisitz    709:             foreach my $key (keys(%{$bombs})) {
                    710:                 my $currentdir = &Apache::lonnet::declutter("$targetdir/$disfilename");
                    711:                 if (($key) =~ m{^\Q$currentdir\E/}) { $kaputt=1; last; }
                    712:             }
1.134     raeburn   713:         }
1.129     www       714: #
                    715: # Get the metadata from that directory's default.meta to display titles
                    716: #
1.52      www       717: 	%Apache::lonpublisher::metadatafields=();
                    718: 	%Apache::lonpublisher::metadatakeys=();
1.129     www       719: 	&Apache::lonpublisher::metaeval(
                    720:                  &Apache::lonnet::getfile($r->dir_config('lonDocRoot').$here.'/'.$dirname.'/default.meta')
                    721:                                        );
1.133     www       722:         if ($dirname eq '..') {
1.109     bisitz    723:             $actionitem = &mt('Go to ...');
1.133     www       724:             $disfilename = '<i>'.&mt('Parent Directory').'</i>';
1.64      raeburn   725:         } else {
                    726:             $actionitem = 
                    727:                     '<form name="dirselect_'.$$numdir.
1.160.2.5.2.1  (raeburn  728::                     '" action="/adm/publish">'.
1.85      albertel  729:                     '<select name="diraction" onchange="SetPubDir(this.form,document)">'.
1.64      raeburn   730:                       '<option selected="selected">'.&mt('Select action').'</option>'.
                    731:                       '<option value="open">'.&mt('Open').'</option>'.
                    732:                       '<option value="publish">'.&mt('Publish').'</option>'.
1.113     schafran  733:                       '<option value="editmeta">'.&mt('Edit Metadata').'</option>'.
1.77      albertel  734:                       '<option value="printdir">'.&mt('Print directory').'</option>'.
1.88      raeburn   735:                       '<option value="delete">'.&mt('Delete directory').'</option>'.
1.64      raeburn   736:                     '</select>'.
1.129     www       737:                      '<input type="hidden" name="filename" value="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" />'.
1.75      albertel  738:                      '<input type="hidden" name="openname" value="'.$here.'/'.$dirname.'/" />'.
1.64      raeburn   739:                      '<input type="hidden" name="postdata" value="" />'.
                    740:                    '</form>';
                    741:             $$numdir ++;
                    742:         }
1.92      albertel  743: 	$r->print('<tr class="LC_browser_folder">'.
1.53      www       744: 		  '<td><img src="'.
1.123     bisitz    745: 		  $Apache::lonnet::perlvar{'lonIconsURL'}.'/navmap.folder.closed.gif" alt="folder" /></td>'.
1.64      raeburn   746: 		  '<td>'.$actionitem.'</td>'.
1.160.2.5.2.1  (raeburn  747:: 		  '<td><span class="LC_filename"><a href="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/">'.
1.92      albertel  748: 		  $disfilename.'</a></span></td>'.
1.134     raeburn   749: 		        '<td colspan="3">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($targetdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'});
1.92      albertel  750: 	if ($Apache::lonpublisher::metadatafields{'subject'} ne '') {
                    751: 	    $r->print(' <i>'.
                    752: 		      $Apache::lonpublisher::metadatafields{'subject'}.
                    753: 		      '</i> ');
                    754: 	}
                    755: 	$r->print($Apache::lonpublisher::metadatafields{'keywords'}.'</td>'.
1.42      www       756: 		  '<td>'.&Apache::lonlocal::locallocaltime($modtime).'</td>'.
1.152     musolffc  757: 	          '<td></td>'.
1.25      www       758: 		  "</tr>\n");
1.64      raeburn   759:     }
1.154     raeburn   760:     return;
1.21      foxr      761: }
1.152     musolffc  762: 
                    763: sub getTitle {
                    764:     my ($resdir, $targetdir, $filename, $linkfilename, $meta_same, $bombs) = @_;
                    765:     my $title='';
                    766:     my $titleString = &getTitleString($targetdir.'/'.$filename);
                    767:     if (-e $resdir.'/'.$filename) {
                    768: 	$title = '<a href="'.$targetdir.'/'.$filename.
                    769: 	    '.meta" target="cat">'.$titleString.'</a>';
                    770:         if (!$meta_same) {
                    771: 	    $title = &mt('Metadata Modified').'<br />'.$title.
                    772: 		'<br />'.
                    773:                 &Apache::loncommon::modal_link(
                    774:                     '/adm/diff?filename='.$linkfilename.'.meta'.'&amp;versiontwo=priv',
                    775:                     &mt('Metadata Diffs'),600,500);
                    776: 	    $title.="\n".'<br />'.
                    777:                 &Apache::loncommon::modal_link(
                    778:                     '/adm/retrieve?filename='.$linkfilename.'.meta&amp;inhibitmenu=yes&amp;add_modal=yes',
                    779:                     &mt('Retrieve Metadata'),600,500);
                    780:         } 
                    781:     }
                    782:     # Allow editing metadata of published and unpublished resources
                    783:     $title .= "\n".'<br />' if ($title);
                    784:     $title .= '<a href="'.$linkfilename.'.meta">'.
                    785:               ($$bombs{&Apache::lonnet::declutter($targetdir.'/'.$filename)}?
                    786:                   '<img src="/adm/lonMisc/bomb.gif" border="0" alt="'.&mt('bomb').'" />':
                    787:                   &mt('Edit Metadata')).
                    788:               '</a>';
                    789: 
                    790:     return ($title, $titleString);
                    791: }
                    792: 
                    793: 
                    794: sub isMetaSame {
                    795:     my ($cstr_dir, $resdir, $filename) = @_;
                    796:     my $meta_cmtime = (stat($cstr_dir.'/'.$filename.'.meta'))[9];
                    797:     my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
                    798:     return (&Apache::londiff::are_different_files($resdir.'/'.$filename.'.meta',
                    799:             $cstr_dir.'/'.$filename.'.meta') && $meta_rmtime < $meta_cmtime) 
                    800:         ? 0 : 1;
                    801: }
                    802:     
                    803: 
                    804: sub getStatus {    
                    805:     my ($resdir, $targetdir, $cstr_dir, $filename,  
                    806:             $linkfilename, $cmtime, $meta_same) = @_;
1.64      raeburn   807:     my $pubstatus = 'unpublished';
1.152     musolffc  808:     my $status = &mt('Unpublished');
1.129     www       809: 
1.22      foxr      810:     if (-e $resdir.'/'.$filename) {
1.152     musolffc  811:         my $same = 0;
                    812:         if ((stat($resdir.'/'.$filename))[9] >= $cmtime) {
                    813:             $same = 1;
1.91      www       814:         } else {
                    815:            if (&Apache::londiff::are_different_files($resdir.'/'.$filename,
1.95      albertel  816: 						     $cstr_dir.'/'.$filename)) {
1.152     musolffc  817:               $same = 0;
1.91      www       818:            } else {
1.152     musolffc  819:               $same = 1;
1.91      www       820:            }
                    821:         }
1.124     bisitz    822: 
                    823:         my $rights_status =
                    824:             &mt(&getCopyRightString($targetdir.'/'.$filename)).', ';
                    825: 
                    826:         my %lt_SourceRight = &Apache::lonlocal::texthash(
                    827:                'open'   => 'Source: open',
                    828:                'closed' => 'Source: closed',
                    829:         );
                    830:         $rights_status .=
                    831:             $lt_SourceRight{&getSourceRightString($targetdir.'/'.$filename)};
                    832: 
1.91      www       833: 	if ($same) {
1.40      www       834: 	    if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
1.64      raeburn   835:                 $pubstatus = 'obsolete';
1.41      www       836: 		$status=&mt('Obsolete');
1.95      albertel  837:             } else {
                    838: 		if (!$meta_same) {
                    839: 		    $pubstatus = 'metamodified';
                    840: 		} else {
                    841: 		    $pubstatus = 'published';
                    842: 		}
                    843: 		$status=&mt('Published').
                    844: 		    '<br />'. $rights_status;
                    845: 	    }
1.22      foxr      846: 	} else {
1.64      raeburn   847:             $pubstatus = 'modified';
1.95      albertel  848: 	    $status=&mt('Modified').
                    849: 		'<br />'. $rights_status;
1.22      foxr      850: 	    if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
1.139     www       851: 		$status.='<br />'.
                    852:                          &Apache::loncommon::modal_link(
                    853:                              '/adm/diff?filename='.$linkfilename.'&amp;versiontwo=priv',
                    854:                              &mt('Diffs'),600,500);
1.22      foxr      855: 	    }
1.95      albertel  856: 	} 
1.152     musolffc  857: 
1.140     www       858: 	$status.="\n".'<br />'.
                    859:              &Apache::loncommon::modal_link(
                    860:                  '/adm/retrieve?filename='.$linkfilename.'&amp;inhibitmenu=yes&amp;add_modal=yes',&mt('Retrieve'),600,500);
1.22      foxr      861:     }
1.152     musolffc  862: 
                    863:     return ($status, $pubstatus);
                    864: }
                    865: 
                    866: 
                    867: #
                    868: #   Put a table row for a file resource.
                    869: #
                    870: sub putresource {
                    871:     my ($r, $udom, $uname, $filename, $thisdisfn, $resdir, $targetdir, 
                    872:             $linkdir, $cmtime, $size, $numres, $linkfilename, $title, 
1.160.2.5.2.3! (raeburn  873::             $status, $pubstatus, $editors) = @_;
1.152     musolffc  874:     &Apache::lonnet::devalidate_cache_new('meta',$targetdir.'/'.$filename);
1.143     bisitz    875: 
1.33      www       876:     my $editlink='';
1.38      taceyjo1  877:     my $editlink2='';
1.160.2.5.2.2  (raeburn  878::     if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty|txt|css|js)$/) {
1.146     raeburn   879: 	$editlink=' <br />(<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&amp;problemmode=edit">'.&mt('Edit').'</a>)';
1.34      www       880:     }
1.136     www       881:     if ($filename=~/$LONCAPA::assess_re/) {
1.160.2.5.2.3! (raeburn  882::         if ($editors->{'xml'}) {
        !           883:: 	    $editlink=' (<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&amp;problemmode=editxml">'.&mt('EditXML').'</a>)';
        !           884::         }
        !           885::         if ($editors->{'edit'}) {
        !           886:: 	    $editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&amp;problemmode=edit">'.&mt('Edit').'</a>)';
        !           887::         }
        !           888::     }
        !           889::     if ($filename=~/\.(xml|html|htm|xhtml|xhtm)$/ || $filename=~/$LONCAPA::assess_re/) {
        !           890::         if (($editors->{'daxe'}) &&
        !           891::             ($env{'browser.type'} ne 'explorer' || $env{'browser.version'} > 9)) {
        !           892::             my $daxeurl = '/daxepage'.$linkdir.'/'.$filename;
        !           893::             $editlink .= ' (<a href="'.$daxeurl.'">Daxe</a>)';
        !           894::         }
1.43      taceyjo1  895:     }
1.82      www       896:     if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) {
1.160.2.5.2.1  (raeburn  897:: 	$editlink.=' (<a href="/adm/cleanup?filename='.$linkfilename.'">'.&mt('Clean Up').')</a>';
1.82      www       898:     }
1.43      taceyjo1  899:     if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.160.2.5.2.1  (raeburn  900:: 	$editlink=' (<a href="/adm/cfile?decompress='.$linkfilename.'">'.&mt('Decompress').'</a>)';
1.33      www       901:     }
1.152     musolffc  902:     my $publish_button = (-e $resdir.'/'.$filename) ? &mt('Re-publish') : &mt('Publish');
1.64      raeburn   903:     my $pub_select = '';
                    904:     &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres);
1.115     bisitz    905:     $r->print(&Apache::loncommon::start_data_table_row().
1.53      www       906: 	      '<td>'.($filename=~/[\#\~]$/?'&nbsp;':
1.86      albertel  907: 		      '<img src="'.&Apache::loncommon::icon($filename).'" alt="" />').'</td>'.
1.64      raeburn   908:               '<td>'.$pub_select.'</td>'.
1.104     albertel  909: 	      '<td><span class="LC_filename">'.
1.160.2.5.2.1  (raeburn  910:: 	      '<a href="'.$linkdir.'/'.$filename.'">'.
1.92      albertel  911:                $filename.'</a></span>'.$editlink2.$editlink.
1.22      foxr      912: 	      '</td>'.
                    913: 	      '<td>'.$title.'</td>'.
1.115     bisitz    914:               '<td class="LC_browser_file_'.$pubstatus.'">&nbsp;&nbsp;</td>'. # Display publication status
                    915:               '<td>'.$status.'</td>'.
1.42      www       916: 	      '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'.
1.153     raeburn   917: 	      '<td>'.sprintf("%.1f",$size).'</td>'.
1.115     bisitz    918: 	      &Apache::loncommon::end_data_table_row()
                    919:     );
1.154     raeburn   920:     return;
1.23      foxr      921: }
1.64      raeburn   922: 
                    923: sub create_pubselect {
                    924:     my ($r,$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres) = @_;
                    925:     $$pub_select = '
                    926: <form name="resselect_'.$$numres.'" action="">
1.85      albertel  927: <select name="reschoice"  onchange="SetResChoice(this.form)">
1.77      albertel  928: <option>'.&mt('Select action').'</option>'.
                    929: '<option value="copy">'.&mt('Copy').'</option>';
1.68      raeburn   930:     if ($pubstatus eq 'obsolete' || $pubstatus eq 'unpublished') {
                    931:         $$pub_select .= 
1.77      albertel  932: '<option value="rename">'.&mt('Rename').'</option>'.
                    933: '<option value="move">'.&mt('Move').'</option>'.
                    934: '<option value="delete">'.&mt('Delete').'</option>';
1.64      raeburn   935:     } else {
                    936:         $$pub_select .= '
1.77      albertel  937: <option value="obsolete">'.&mt('Mark obsolete').'</option>';
1.64      raeburn   938:     }
                    939: # check for versions
                    940:     my $versions = &check_for_versions($r,'/'.$filename,$udom,$uname);
                    941:     if ($versions > 0) {
                    942:         $$pub_select .='
1.77      albertel  943: <option value="retrieve">'.&mt('Retrieve old version').'</option>';
1.64      raeburn   944:     }
                    945:     $$pub_select .= '
1.77      albertel  946: <option value="publish">'.$publish_button.'</option>'.
1.82      www       947: '<option value="cleanup">'.&mt('Clean up').'</option>'.
1.77      albertel  948: '<option value="print">'.&mt('Print').'</option>'.
1.68      raeburn   949: '</select>
1.131     www       950: <input type="hidden" name="filename" value="/priv'.
                    951:  &HTML::Entities::encode($thisdisfn.'/'.$filename,'<>&"').'" />
1.96      banghart  952:  <input type="hidden" name="dispfilename" value="'.
1.99      albertel  953:  &HTML::Entities::encode($filename).'" /></form>';
1.64      raeburn   954:     $$numres ++;
                    955: }
                    956: 
                    957: sub check_for_versions {
                    958:     my ($r,$fn,$udom,$uname) = @_;
                    959:     my $versions = 0;
                    960:     my $docroot=$r->dir_config('lonDocRoot');
                    961:     my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
                    962:     my $resdir=$resfn;
                    963:     $resdir=~s/\/[^\/]+$/\//;
                    964:     $fn=~/\/([^\/]+)\.(\w+)$/;
                    965:     my $main=$1;
                    966:     my $suffix=$2;
                    967:     opendir(DIR,$resdir);
                    968:     while (my $filename=readdir(DIR)) {
                    969:         if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
                    970:             $versions ++;        
                    971:         }
                    972:     }
1.154     raeburn   973:     closedir(DIR);
1.64      raeburn   974:     return $versions;
                    975: }
                    976: 
1.4       www       977: 1;
                    978: __END__
1.17      harris41  979: 
                    980: 
1.114     jms       981: =head1 NAME
                    982: 
1.145     raeburn   983: Apache::lonpubdir - Authoring space directory lister
1.114     jms       984: 
                    985: =head1 SYNOPSIS
                    986: 
                    987: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
                    988: 
1.134     raeburn   989:  <LocationMatch "^/+priv.*/$">
1.114     jms       990:  PerlAccessHandler       Apache::loncacc
                    991:  SetHandler perl-script
                    992:  PerlHandler Apache::lonpubdir
                    993:  ErrorDocument     403 /adm/login
                    994:  ErrorDocument     404 /adm/notfound.html
                    995:  ErrorDocument     406 /adm/unauthorized.html
                    996:  ErrorDocument	  500 /adm/errorhandler
                    997:  </LocationMatch>
                    998: 
                    999:  <Location /adm/pubdir>
                   1000:  PerlAccessHandler       Apache::lonacc
                   1001:  SetHandler perl-script
                   1002:  PerlHandler Apache::lonpubdir
                   1003:  ErrorDocument     403 /adm/login
                   1004:  ErrorDocument     404 /adm/notfound.html
                   1005:  ErrorDocument     406 /adm/unauthorized.html
                   1006:  ErrorDocument	  500 /adm/errorhandler
                   1007:  </Location>
                   1008: 
                   1009: =head1 INTRODUCTION
                   1010: 
                   1011: This module publishes a directory of files.
                   1012: 
                   1013: This is part of the LearningOnline Network with CAPA project
                   1014: described at http://www.lon-capa.org.
                   1015: 
                   1016: =head1 HANDLER SUBROUTINE
                   1017: 
                   1018: This routine is called by Apache and mod_perl.
                   1019: 
                   1020: =over 4
                   1021: 
                   1022: =item *
                   1023: 
                   1024: read in information
                   1025: 
                   1026: =item *
                   1027: 
                   1028: start page output
                   1029: 
                   1030: =item *
                   1031: 
                   1032: run through list of files and attempt to publish unhidden files
                   1033: 
                   1034: =back
                   1035: 
                   1036: =head1 SUBROUTINES:
                   1037: 
                   1038: =over
                   1039: 
                   1040: =item startpage($r, $uame, $udom, $thisdisfn)
                   1041: 
                   1042: Output the header of the page.  This includes:
                   1043:  - The HTML header 
                   1044:  - The H1/H3  stuff which includes the directory.
                   1045:  
                   1046:     startpage($r, $uame, $udom, $thisdisfn);
                   1047:         $r     - The apache request object.
                   1048:         $uname - User name.
                   1049:         $udom  - Domain name the user is logged in under.
                   1050:         $thisdisfn - Displayable version of the filename.
                   1051: 
                   1052: =item getTitleString($fullname)
                   1053: 
                   1054:     Get the title string or "[untitled]" if the file has no title metadata:
                   1055:     Without the latter substitution, it's impossible to examine metadata for
                   1056:     untitled resources.  Resources may be legitimately untitled, to prevent
                   1057:     searches from locating them.
                   1058:     
                   1059:     $str = getTitleString($fullname);
                   1060:         $fullname - Fully qualified filename to check.
                   1061: 
1.134     raeburn  1062: =item putdirectory($r, $base, $here, $dirname, $modtime, $targetdir, $bombs,
                   1063:                    $numdir)
1.114     jms      1064: 
                   1065:     Put out a directory table row:
                   1066:     
1.134     raeburn  1067:         $r        - Apache request object.
                   1068:         $reqfile  - File in request.
                   1069:         $here     - Where we are in directory tree.
                   1070:         $dirname  - Name of directory special file.
                   1071:         $modtime  - Encoded modification time.
                   1072:         targetdir - Publication target directory.
                   1073:         bombs     - Reference to hash of URLs with runtime error messages.
                   1074:         numdir    - Reference to scalar used to track number of sub-directories
                   1075:                     in directory (used in form name for each "actions" dropdown).
1.114     jms      1076: 
                   1077: =back
                   1078: 
                   1079: =cut

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