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