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