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

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

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