Annotation of loncom/publisher/lonpubdir.pm, revision 1.163
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.163 ! golterma 589: </select> <input type="text" name="newfilename" placeholder="$lt{'type'}" value="" onfocus="if (this.value == is.empty()) this.value=''" /> <input type="button" value="Go" onclick="validate_go();" />
! 590: <br />
! 591: <span>Quickactions:
! 592: <input type="hidden" name="mode"/>
! 593: <a href="javascript:void(0)" onclick="javascript:validate_action('blank')">
! 594: <img src="/adm/lonIcons/unknown.gif" title="Create blank problem file"></a>
! 595: <a href="javascript:void(0)" onclick="javascript:validate_action('problemtempl')">
! 596: <img src="/adm/lonIcons/problem.gif" title="Create new problem from template"></a>
! 597: <a href="javascript:void(0)" onclick="javascript:validate_action('blankhtml')">
! 598: <img src="/adm/lonIcons/html.gif" title="Create new blank HTML file"></a>
! 599: <a href="javascript:void(0)" onclick="javascript:validate_action('folder')">
! 600: <img src="/adm/lonIcons/navmap.folder.closed.gif" title="Create new subdirectory"></a>
! 601: </span>
! 602: <script type="text/javascript">
! 603: function validate_action(action){
! 604:
! 605: if (document.getElementsByName(\'newfilename\')[0].value != \'\'){
! 606: if (action == "blank") {
! 607: document.fileaction.action.value=\'newproblemfile\';
! 608: document.fileaction.mode.value=\'blank\';
! 609: } else if (action == "problemtempl") {
! 610: document.fileaction.action.value=\'newproblemfile\';
! 611: validate_go();
! 612: } else if (action == "blankhtml") {
! 613: document.fileaction.action.value=\'newhtmlfile\';
! 614: validate_go();
! 615: } else if (action == "folder") {
! 616: document.fileaction.action.value=\'newdir\';
! 617: document.fileaction.mode.value=\'folder\';
! 618: }
! 619: fileaction.submit();
! 620: } else {
! 621: alert(\'Please specify file name.\');
! 622: // TODO: ask for filename? if so, do some refactoring
! 623:
! 624: }
! 625: }
! 626: </script>
1.92 albertel 627: </span>
1.116 bisitz 628: </fieldset>
629: </form>
1.161 golterma 630: </div>
631: <div>
1.162 golterma 632: <fieldset style="display:inline">
633: <legend>$lt{'qs'}</legend>
634: <script type="text/javascript" src="/adm/quicksearch/quicksearch.js"></script>
635: <input type="text" id="quickfilter" placeholder="Enter search term" onkeyup="applyFilter()"/>
636: <input type="button" value="Clear" onclick="document.getElementById(\'quickfilter\').value=\'\'; applyFilter()" />
637: %s
638: <br />
639: <label><input type="checkbox" id="casesens" onchange="applyFilter()"/>$lt{'cs'} </label>
640: <label><input type="checkbox" id="regex" onchange="applyFilter()"/>$lt{'re'} </label>
641: </fieldset>
1.116 bisitz 642: </div>
643: </div>
1.64 raeburn 644: END
645: }
646:
647: sub resourceactions {
648: my ($r,$uname,$udom,$thisdisfn) = @_;
649: $r->print(<<END);
650: <form name="moveresource" action="/adm/cfile" target="_parent" method="post">
651: <input type="hidden" name="filename" value="" />
652: <input type="hidden" name="newfilename" value="" />
653: <input type="hidden" name="action" value="" />
654: </form>
655: <form name="delresource" action="/adm/cfile" target="_parent" method="post">
656: <input type="hidden" name="filename" value="" />
657: <input type="hidden" name="action" value="delete" />
658: </form>
659: <form name="pubresource" action="/adm/publish" target="_parent" method="post">
660: <input type="hidden" name="filename" value="" />
1.80 www 661: <input type="hidden" name="makeobsolete" value="0" />
1.64 raeburn 662: </form>
663: <form name="printresource" action="/adm/printout" target="_parent" method="post">
664: <input type="hidden" name="postdata" value="" />
665: </form>
666: <form name="retrieveres" action="/adm/retrieve" target="_parent" method="post">
667: <input type="hidden" name="filename" value="" />
668: </form>
1.82 www 669: <form name="cleanup" action="/adm/cleanup" target="_parent" method="post">
670: <input type="hidden" name="filename" value="" />
671: </form>
1.64 raeburn 672: END
1.23 foxr 673: }
674:
675: #
676: # Get the title string or "[untitled]" if the file has no title metadata:
677: # Without the latter substitution, it's impossible to examine metadata for
678: # untitled resources. Resources may be legitimately untitled, to prevent
679: # searches from locating them.
680: #
681: # $str = getTitleString($fullname);
682: # $fullname - Fully qualified filename to check.
683: #
684: sub getTitleString {
685: my $fullname = shift;
686: my $title = &Apache::lonnet::metadata($fullname, 'title');
687:
688: unless ($title) {
1.40 www 689: $title = "[".&mt('untitled')."]";
1.23 foxr 690: }
691: return $title;
692: }
693:
1.55 www 694: sub getCopyRightString {
695: my $fullname = shift;
696: return &Apache::lonnet::metadata($fullname, 'copyright');
697: }
1.61 www 698:
699: sub getSourceRightString {
700: my $fullname = shift;
701: return &Apache::lonnet::metadata($fullname, 'sourceavail');
702: }
1.23 foxr 703: #
1.21 foxr 704: # Put out a directory table row:
1.134 raeburn 705: # putdirectory(r, base, here, dirname, modtime, targetdir, bombs, numdir)
706: # r - Apache request object.
707: # reqfile - File in request.
708: # here - Where we are in directory tree.
709: # dirname - Name of directory special file.
710: # modtime - Encoded modification time.
711: # targetdir - Publication target directory.
712: # bombs - Reference to hash of URLs with runtime error messages.
713: # numdir - Reference to scalar used to track number of sub-directories
714: # in directory (used in form name for each "actions" dropdown).
715: #
1.21 foxr 716: sub putdirectory {
1.134 raeburn 717: my ($r, $reqfile, $here, $dirname, $modtime, $targetdir, $bombs, $numdir) = @_;
1.129 www 718:
719: # construct the display filename: the directory name unless ..:
1.133 www 720:
721: my $actionitem;
722:
1.21 foxr 723: my $disfilename = $dirname;
1.130 www 724: # Don't display directory itself, and there is no way up from root directory
1.133 www 725: unless ((($dirname eq '..') && ($reqfile=~/^\/[^\/]+\/[^\/]+$/)) || ($dirname eq '.')) {
1.143 bisitz 726: my $kaputt=0;
1.134 raeburn 727: if (ref($bombs) eq 'HASH') {
1.143 bisitz 728: foreach my $key (keys(%{$bombs})) {
729: my $currentdir = &Apache::lonnet::declutter("$targetdir/$disfilename");
730: if (($key) =~ m{^\Q$currentdir\E/}) { $kaputt=1; last; }
731: }
1.134 raeburn 732: }
1.129 www 733: #
734: # Get the metadata from that directory's default.meta to display titles
735: #
1.52 www 736: %Apache::lonpublisher::metadatafields=();
737: %Apache::lonpublisher::metadatakeys=();
1.129 www 738: &Apache::lonpublisher::metaeval(
739: &Apache::lonnet::getfile($r->dir_config('lonDocRoot').$here.'/'.$dirname.'/default.meta')
740: );
1.133 www 741: if ($dirname eq '..') {
1.109 bisitz 742: $actionitem = &mt('Go to ...');
1.133 www 743: $disfilename = '<i>'.&mt('Parent Directory').'</i>';
1.64 raeburn 744: } else {
745: $actionitem =
746: '<form name="dirselect_'.$$numdir.
747: '" action="/adm/publish" target="_parent">'.
1.85 albertel 748: '<select name="diraction" onchange="SetPubDir(this.form,document)">'.
1.64 raeburn 749: '<option selected="selected">'.&mt('Select action').'</option>'.
750: '<option value="open">'.&mt('Open').'</option>'.
751: '<option value="publish">'.&mt('Publish').'</option>'.
1.113 schafran 752: '<option value="editmeta">'.&mt('Edit Metadata').'</option>'.
1.77 albertel 753: '<option value="printdir">'.&mt('Print directory').'</option>'.
1.88 raeburn 754: '<option value="delete">'.&mt('Delete directory').'</option>'.
1.64 raeburn 755: '</select>'.
1.129 www 756: '<input type="hidden" name="filename" value="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" />'.
1.75 albertel 757: '<input type="hidden" name="openname" value="'.$here.'/'.$dirname.'/" />'.
1.64 raeburn 758: '<input type="hidden" name="postdata" value="" />'.
759: '</form>';
760: $$numdir ++;
761: }
1.92 albertel 762: $r->print('<tr class="LC_browser_folder">'.
1.53 www 763: '<td><img src="'.
1.123 bisitz 764: $Apache::lonnet::perlvar{'lonIconsURL'}.'/navmap.folder.closed.gif" alt="folder" /></td>'.
1.64 raeburn 765: '<td>'.$actionitem.'</td>'.
1.92 albertel 766: '<td><span class="LC_filename"><a href="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" target="_parent">'.
767: $disfilename.'</a></span></td>'.
1.134 raeburn 768: '<td colspan="3">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($targetdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'});
1.92 albertel 769: if ($Apache::lonpublisher::metadatafields{'subject'} ne '') {
770: $r->print(' <i>'.
771: $Apache::lonpublisher::metadatafields{'subject'}.
772: '</i> ');
773: }
774: $r->print($Apache::lonpublisher::metadatafields{'keywords'}.'</td>'.
1.42 www 775: '<td>'.&Apache::lonlocal::locallocaltime($modtime).'</td>'.
1.152 musolffc 776: '<td></td>'.
1.25 www 777: "</tr>\n");
1.64 raeburn 778: }
1.154 raeburn 779: return;
1.21 foxr 780: }
1.152 musolffc 781:
782: sub getTitle {
783: my ($resdir, $targetdir, $filename, $linkfilename, $meta_same, $bombs) = @_;
784: my $title='';
785: my $titleString = &getTitleString($targetdir.'/'.$filename);
786: if (-e $resdir.'/'.$filename) {
787: $title = '<a href="'.$targetdir.'/'.$filename.
788: '.meta" target="cat">'.$titleString.'</a>';
789: if (!$meta_same) {
790: $title = &mt('Metadata Modified').'<br />'.$title.
791: '<br />'.
792: &Apache::loncommon::modal_link(
793: '/adm/diff?filename='.$linkfilename.'.meta'.'&versiontwo=priv',
794: &mt('Metadata Diffs'),600,500);
795: $title.="\n".'<br />'.
796: &Apache::loncommon::modal_link(
797: '/adm/retrieve?filename='.$linkfilename.'.meta&inhibitmenu=yes&add_modal=yes',
798: &mt('Retrieve Metadata'),600,500);
799: }
800: }
801: # Allow editing metadata of published and unpublished resources
802: $title .= "\n".'<br />' if ($title);
803: $title .= '<a href="'.$linkfilename.'.meta">'.
804: ($$bombs{&Apache::lonnet::declutter($targetdir.'/'.$filename)}?
805: '<img src="/adm/lonMisc/bomb.gif" border="0" alt="'.&mt('bomb').'" />':
806: &mt('Edit Metadata')).
807: '</a>';
808:
809: return ($title, $titleString);
810: }
811:
812:
813: sub isMetaSame {
814: my ($cstr_dir, $resdir, $filename) = @_;
815: my $meta_cmtime = (stat($cstr_dir.'/'.$filename.'.meta'))[9];
816: my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
817: return (&Apache::londiff::are_different_files($resdir.'/'.$filename.'.meta',
818: $cstr_dir.'/'.$filename.'.meta') && $meta_rmtime < $meta_cmtime)
819: ? 0 : 1;
820: }
821:
822:
823: sub getStatus {
824: my ($resdir, $targetdir, $cstr_dir, $filename,
825: $linkfilename, $cmtime, $meta_same) = @_;
1.64 raeburn 826: my $pubstatus = 'unpublished';
1.152 musolffc 827: my $status = &mt('Unpublished');
1.129 www 828:
1.22 foxr 829: if (-e $resdir.'/'.$filename) {
1.152 musolffc 830: my $same = 0;
831: if ((stat($resdir.'/'.$filename))[9] >= $cmtime) {
832: $same = 1;
1.91 www 833: } else {
834: if (&Apache::londiff::are_different_files($resdir.'/'.$filename,
1.95 albertel 835: $cstr_dir.'/'.$filename)) {
1.152 musolffc 836: $same = 0;
1.91 www 837: } else {
1.152 musolffc 838: $same = 1;
1.91 www 839: }
840: }
1.124 bisitz 841:
842: my $rights_status =
843: &mt(&getCopyRightString($targetdir.'/'.$filename)).', ';
844:
845: my %lt_SourceRight = &Apache::lonlocal::texthash(
846: 'open' => 'Source: open',
847: 'closed' => 'Source: closed',
848: );
849: $rights_status .=
850: $lt_SourceRight{&getSourceRightString($targetdir.'/'.$filename)};
851:
1.91 www 852: if ($same) {
1.40 www 853: if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
1.64 raeburn 854: $pubstatus = 'obsolete';
1.41 www 855: $status=&mt('Obsolete');
1.95 albertel 856: } else {
857: if (!$meta_same) {
858: $pubstatus = 'metamodified';
859: } else {
860: $pubstatus = 'published';
861: }
862: $status=&mt('Published').
863: '<br />'. $rights_status;
864: }
1.22 foxr 865: } else {
1.64 raeburn 866: $pubstatus = 'modified';
1.95 albertel 867: $status=&mt('Modified').
868: '<br />'. $rights_status;
1.22 foxr 869: if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
1.139 www 870: $status.='<br />'.
871: &Apache::loncommon::modal_link(
872: '/adm/diff?filename='.$linkfilename.'&versiontwo=priv',
873: &mt('Diffs'),600,500);
1.22 foxr 874: }
1.95 albertel 875: }
1.152 musolffc 876:
1.140 www 877: $status.="\n".'<br />'.
878: &Apache::loncommon::modal_link(
879: '/adm/retrieve?filename='.$linkfilename.'&inhibitmenu=yes&add_modal=yes',&mt('Retrieve'),600,500);
1.22 foxr 880: }
1.152 musolffc 881:
882: return ($status, $pubstatus);
883: }
884:
885:
886: #
887: # Put a table row for a file resource.
888: #
889: sub putresource {
890: my ($r, $udom, $uname, $filename, $thisdisfn, $resdir, $targetdir,
891: $linkdir, $cmtime, $size, $numres, $linkfilename, $title,
892: $status, $pubstatus) = @_;
893: &Apache::lonnet::devalidate_cache_new('meta',$targetdir.'/'.$filename);
1.143 bisitz 894:
1.33 www 895: my $editlink='';
1.38 taceyjo1 896: my $editlink2='';
1.36 www 897: if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty)$/) {
1.146 raeburn 898: $editlink=' <br />(<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&problemmode=edit">'.&mt('Edit').'</a>)';
1.34 www 899: }
1.136 www 900: if ($filename=~/$LONCAPA::assess_re/) {
1.146 raeburn 901: $editlink=' (<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&problemmode=editxml">'.&mt('EditXML').'</a>)';
902: $editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?editmode=Edit&problemmode=edit">'.&mt('Edit').'</a>)';
1.43 taceyjo1 903: }
1.82 www 904: if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) {
1.129 www 905: $editlink.=' (<a href="/adm/cleanup?filename='.$linkfilename.'" target="_parent">'.&mt('Clean Up').')</a>';
1.82 www 906: }
1.43 taceyjo1 907: if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.129 www 908: $editlink=' (<a target="_parent" href="/adm/cfile?decompress='.$linkfilename.'">'.&mt('Decompress').'</a>)';
1.33 www 909: }
1.152 musolffc 910: my $publish_button = (-e $resdir.'/'.$filename) ? &mt('Re-publish') : &mt('Publish');
1.64 raeburn 911: my $pub_select = '';
912: &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres);
1.115 bisitz 913: $r->print(&Apache::loncommon::start_data_table_row().
1.53 www 914: '<td>'.($filename=~/[\#\~]$/?' ':
1.86 albertel 915: '<img src="'.&Apache::loncommon::icon($filename).'" alt="" />').'</td>'.
1.64 raeburn 916: '<td>'.$pub_select.'</td>'.
1.104 albertel 917: '<td><span class="LC_filename">'.
1.64 raeburn 918: '<a href="'.$linkdir.'/'.$filename.'" target="_parent">'.
1.92 albertel 919: $filename.'</a></span>'.$editlink2.$editlink.
1.22 foxr 920: '</td>'.
921: '<td>'.$title.'</td>'.
1.115 bisitz 922: '<td class="LC_browser_file_'.$pubstatus.'"> </td>'. # Display publication status
923: '<td>'.$status.'</td>'.
1.42 www 924: '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'.
1.153 raeburn 925: '<td>'.sprintf("%.1f",$size).'</td>'.
1.115 bisitz 926: &Apache::loncommon::end_data_table_row()
927: );
1.154 raeburn 928: return;
1.23 foxr 929: }
1.64 raeburn 930:
931: sub create_pubselect {
932: my ($r,$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres) = @_;
933: $$pub_select = '
934: <form name="resselect_'.$$numres.'" action="">
1.85 albertel 935: <select name="reschoice" onchange="SetResChoice(this.form)">
1.77 albertel 936: <option>'.&mt('Select action').'</option>'.
937: '<option value="copy">'.&mt('Copy').'</option>';
1.68 raeburn 938: if ($pubstatus eq 'obsolete' || $pubstatus eq 'unpublished') {
939: $$pub_select .=
1.77 albertel 940: '<option value="rename">'.&mt('Rename').'</option>'.
941: '<option value="move">'.&mt('Move').'</option>'.
942: '<option value="delete">'.&mt('Delete').'</option>';
1.64 raeburn 943: } else {
944: $$pub_select .= '
1.77 albertel 945: <option value="obsolete">'.&mt('Mark obsolete').'</option>';
1.64 raeburn 946: }
947: # check for versions
948: my $versions = &check_for_versions($r,'/'.$filename,$udom,$uname);
949: if ($versions > 0) {
950: $$pub_select .='
1.77 albertel 951: <option value="retrieve">'.&mt('Retrieve old version').'</option>';
1.64 raeburn 952: }
953: $$pub_select .= '
1.77 albertel 954: <option value="publish">'.$publish_button.'</option>'.
1.82 www 955: '<option value="cleanup">'.&mt('Clean up').'</option>'.
1.77 albertel 956: '<option value="print">'.&mt('Print').'</option>'.
1.68 raeburn 957: '</select>
1.131 www 958: <input type="hidden" name="filename" value="/priv'.
959: &HTML::Entities::encode($thisdisfn.'/'.$filename,'<>&"').'" />
1.96 banghart 960: <input type="hidden" name="dispfilename" value="'.
1.99 albertel 961: &HTML::Entities::encode($filename).'" /></form>';
1.64 raeburn 962: $$numres ++;
963: }
964:
965: sub check_for_versions {
966: my ($r,$fn,$udom,$uname) = @_;
967: my $versions = 0;
968: my $docroot=$r->dir_config('lonDocRoot');
969: my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
970: my $resdir=$resfn;
971: $resdir=~s/\/[^\/]+$/\//;
972: $fn=~/\/([^\/]+)\.(\w+)$/;
973: my $main=$1;
974: my $suffix=$2;
975: opendir(DIR,$resdir);
976: while (my $filename=readdir(DIR)) {
977: if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
978: $versions ++;
979: }
980: }
1.154 raeburn 981: closedir(DIR);
1.64 raeburn 982: return $versions;
983: }
984:
1.161 golterma 985: sub prepareJsonTranslations {
986: my $json =
987: '{"translations":{'.
988: '"edit":"'.&mt('Edit').'",'.
989: '"editxml":"'.&mt('EditXML').'",'.
990: '"editmeta":"'.&mt('Edit Metadata').'",'.
991: '"obsolete":"'.&mt('Obsolete').'",'.
992: '"modified":"'.&mt('Modified').'",'.
993: '"published":"'.&mt('Published').'",'.
994: '"unpublished":"'.&mt('Unpublished').'",'.
995: '"diff":"'.&mt('Diff').'",'.
996: '"retrieve":"'.&mt('Retrieve').'",'.
997: '"directory":"'.&mt('Directory').'",'.
998: '"results":"'.&mt('Show results for keyword:').'"'.
999: '}}';
1000: }
1001:
1002: # gathers all files in the working directory except the ones that are already on screen
1003: sub prepareJsonData {
1004: my ($uname, $udom, $pathToSkip) = @_;
1005: my $path = "/home/httpd/html/priv/$udom/$uname/";
1006:
1007: # maximum number of entries, to limit workload and required storage space
1008: my $entries = 100;
1009: my $firstfile = 1;
1010: my $firstdir = 1;
1011:
1012: my $json = '{"resources":[';
1013: $json .= &prepareJsonData_rec($path, \$entries, \$firstfile, \$firstdir, $pathToSkip);
1014: $json .= ']}';
1015:
1016: # if the json string is invalid the whole search breaks.
1017: # so we want to make sure that the string is valid in any case.
1018: $json =~ s/,\s*,/,/g;
1019: $json =~ s/\}\s*\{/\},\{/g;
1020: $json =~ s/\}\s*,\s*\]/\}\]/g;
1021: return $json;
1022: }
1023:
1024: # recursive part of json file gathering
1025: sub prepareJsonData_rec {
1026: my ($path, $entries, $firstfile, $firstdir, $pathToSkip) = @_;
1027: my $json;
1028: my $skipThisFolder = $path =~ m/$pathToSkip\/$/?1:0;
1029:
1030: my @dirs;
1031: my @resources;
1032: my @ignored = qw(bak log meta save . ..);
1033:
1034: # Phase 1: Gathering
1035: opendir(DIR,$path);
1036: my @files=sort {uc($a) cmp uc($b)} (readdir(DIR));
1037: foreach my $filename (@files) {
1038: next if ($filename eq '.DS_Store');
1039:
1040: # gather all resources
1041: if ($filename !~ /\./) {
1042: # its a folder
1043: push(@dirs, $filename);
1044: } else {
1045: # only push files we dont want to ignore
1046: next if ($skipThisFolder);
1047:
1048: $filename =~ /\.(\w+?)$/;
1049: unless (grep /$1/, @ignored) {
1050: push(@resources, $filename);
1051: }
1052: }
1053: }
1054: closedir(DIR);
1055: # nothing to do here if both lists are empty
1056: return unless ( @dirs || @resources );
1057:
1058: # Phase 2: Working
1059: $$firstfile = 1;
1060:
1061: foreach (@dirs) {
1062: $json .= '{"name":"'.$_.'",'.
1063: '"path":"'.$path.$_.'",'.
1064: '"title":"",'.
1065: '"status":"",'.
1066: '"cmtime":""},';
1067: }
1068:
1069: foreach (@resources) {
1070: last if ($$entries < 1);
1071: my $title = &getTitleString($path.$_);
1072:
1073: my $privpath = $path.$_;
1074: my $respath = $privpath;
1075: $respath =~ s/httpd\/html\/priv\//httpd\/html\/res\//;
1076:
1077: my $cmtime = (stat($privpath))[9];
1078: my $rmtime = (stat($respath))[9];
1079:
1080: unless ($$firstfile) { $json .= ','; } else { $$firstfile = 0; }
1081:
1082: my $status = 'unpublished';
1083:
1084: # if a resource is published, the published version (/html/res/filepath) gets its own modification time
1085: # this is newer or equal then the version in your authoring space (/html/priv/filepath)
1086: if ($rmtime >= $cmtime) {
1087: # obsolete
1088: if (&Apache::lonnet::metadata($respath, 'obsolete')) {
1089: $status = 'obsolete';
1090: }else{
1091: $status = 'published';
1092: }
1093: } else {
1094: $status = 'modified';
1095: }
1096:
1097: $json .= '{"name":"'.$_.'",'.
1098: '"path":"'.$path.'",'.
1099: '"title":"'.$title.'",'.
1100: '"status":"'.$status.'",'.
1101: '"cmtime":"'.&Apache::lonlocal::locallocaltime($cmtime).'"}';
1102: $$entries--;
1103: }
1104:
1105: foreach(@dirs) {
1106: next if ($$entries < 1);
1107: $json .= ',';
1108: $json .= &prepareJsonData_rec
1109: ($path.$_.'/', $entries, $firstfile, $firstdir, $pathToSkip);
1110: }
1111: return $json;
1112: }
1.4 www 1113: 1;
1114: __END__
1.17 harris41 1115:
1116:
1.114 jms 1117: =head1 NAME
1118:
1.145 raeburn 1119: Apache::lonpubdir - Authoring space directory lister
1.114 jms 1120:
1121: =head1 SYNOPSIS
1122:
1123: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
1124:
1.134 raeburn 1125: <LocationMatch "^/+priv.*/$">
1.114 jms 1126: PerlAccessHandler Apache::loncacc
1127: SetHandler perl-script
1128: PerlHandler Apache::lonpubdir
1129: ErrorDocument 403 /adm/login
1130: ErrorDocument 404 /adm/notfound.html
1131: ErrorDocument 406 /adm/unauthorized.html
1132: ErrorDocument 500 /adm/errorhandler
1133: </LocationMatch>
1134:
1135: <Location /adm/pubdir>
1136: PerlAccessHandler Apache::lonacc
1137: SetHandler perl-script
1138: PerlHandler Apache::lonpubdir
1139: ErrorDocument 403 /adm/login
1140: ErrorDocument 404 /adm/notfound.html
1141: ErrorDocument 406 /adm/unauthorized.html
1142: ErrorDocument 500 /adm/errorhandler
1143: </Location>
1144:
1145: =head1 INTRODUCTION
1146:
1147: This module publishes a directory of files.
1148:
1149: This is part of the LearningOnline Network with CAPA project
1150: described at http://www.lon-capa.org.
1151:
1152: =head1 HANDLER SUBROUTINE
1153:
1154: This routine is called by Apache and mod_perl.
1155:
1156: =over 4
1157:
1158: =item *
1159:
1160: read in information
1161:
1162: =item *
1163:
1164: start page output
1165:
1166: =item *
1167:
1168: run through list of files and attempt to publish unhidden files
1169:
1170: =back
1171:
1172: =head1 SUBROUTINES:
1173:
1174: =over
1175:
1176: =item startpage($r, $uame, $udom, $thisdisfn)
1177:
1178: Output the header of the page. This includes:
1179: - The HTML header
1180: - The H1/H3 stuff which includes the directory.
1181:
1182: startpage($r, $uame, $udom, $thisdisfn);
1183: $r - The apache request object.
1184: $uname - User name.
1185: $udom - Domain name the user is logged in under.
1186: $thisdisfn - Displayable version of the filename.
1187:
1188: =item getTitleString($fullname)
1189:
1190: Get the title string or "[untitled]" if the file has no title metadata:
1191: Without the latter substitution, it's impossible to examine metadata for
1192: untitled resources. Resources may be legitimately untitled, to prevent
1193: searches from locating them.
1194:
1195: $str = getTitleString($fullname);
1196: $fullname - Fully qualified filename to check.
1197:
1.134 raeburn 1198: =item putdirectory($r, $base, $here, $dirname, $modtime, $targetdir, $bombs,
1199: $numdir)
1.114 jms 1200:
1201: Put out a directory table row:
1202:
1.134 raeburn 1203: $r - Apache request object.
1204: $reqfile - File in request.
1205: $here - Where we are in directory tree.
1206: $dirname - Name of directory special file.
1207: $modtime - Encoded modification time.
1208: targetdir - Publication target directory.
1209: bombs - Reference to hash of URLs with runtime error messages.
1210: numdir - Reference to scalar used to track number of sub-directories
1211: in directory (used in form name for each "actions" dropdown).
1.114 jms 1212:
1213: =back
1214:
1215: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>