Annotation of loncom/publisher/lonpubdir.pm, revision 1.128
1.1 www 1: # The LearningOnline Network with CAPA
1.32 www 2: # Construction Space Directory Lister
1.16 albertel 3: #
1.128 ! www 4: # $Id: lonpubdir.pm,v 1.127 2011/10/21 17:51:23 www 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.6 www 36: use Apache::loncacc;
1.17 harris41 37: use Apache::loncommon();
1.48 www 38: use Apache::lonhtmlcommon();
1.91 www 39: use Apache::londiff();
1.39 www 40: use Apache::lonlocal;
1.50 www 41: use Apache::lonmsg;
1.64 raeburn 42: use Apache::lonmenu;
43: use Apache::lonnet;
1.98 albertel 44: use LONCAPA;
1.1 www 45:
46: sub handler {
47:
48: my $r=shift;
49:
1.23 foxr 50: # Validate access to the construction space and get username@domain.
1.6 www 51:
52: my $uname;
53: my $udom;
54:
1.127 www 55: ($uname,$udom)=&Apache::loncacc::constructaccess($r->uri);
1.9 www 56: unless (($uname) && ($udom)) {
1.6 www 57: return HTTP_NOT_ACCEPTABLE;
58: }
1.23 foxr 59:
1.127 www 60: # ----------------------------------------------------------- Start page output
1.23 foxr 61:
1.127 www 62: my $fn=$r->filename;
1.128 ! www 63: $fn=~s/\/$//;
1.1 www 64:
1.127 www 65: my $thisdisfn=$fn;
66: my $docroot=$r->dir_config('lonDocRoot'); # Apache londocument root.
67: $thisdisfn=~s/^\Q$docroot\E\/priv//;
1.1 www 68:
1.127 www 69: my $resdir=$docroot.'/res'.$thisdisfn; # Resource directory
70: my $targetdir='/res'.$thisdisfn; # Publication target directory.
71: my $linkdir='/priv'.$thisdisfn; # Full URL name of constr space.
1.1 www 72:
1.50 www 73: my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
1.1 www 74:
1.26 www 75: &startpage($r, $uname, $udom, $thisdisfn); # Put out the start of page.
1.126 droeschl 76: &dircontrols($r,$uname,$udom,$thisdisfn); # Put out actions for directory,
1.64 raeburn 77: # browse/upload + new file page.
78: &resourceactions($r,$uname,$udom,$thisdisfn); #Put out form used for printing/deletion etc.
79:
80: my $numdir = 0;
81: my $numres = 0;
1.6 www 82:
1.50 www 83: # Start off the directory table.
1.115 bisitz 84: $r->print(&Apache::loncommon::start_data_table()
85: .&Apache::loncommon::start_data_table_header_row()
86: .'<th>'.&mt('Type').'</th>'
87: .'<th>'.&mt('Actions').'</th>'
88: .'<th>'.&mt('Name').'</th>'
89: .'<th>'.&mt('Title').'</th>'
90: .'<th colspan="2">'.&mt('Status').'</th>'
91: .'<th>'.&mt('Last Modified').'</th>'
92: .&Apache::loncommon::end_data_table_header_row()
93: );
1.1 www 94:
1.2 www 95: my $filename;
1.23 foxr 96: my $dirptr=16384; # Mask indicating a directory in stat.cmode.
1.1 www 97:
1.2 www 98: opendir(DIR,$fn);
1.44 albertel 99: my @files=sort {uc($a) cmp uc($b)} (readdir(DIR));
1.11 albertel 100: foreach my $filename (@files) {
1.2 www 101: my ($cdev,$cino,$cmode,$cnlink,
102: $cuid,$cgid,$crdev,$csize,
103: $catime,$cmtime,$cctime,
104: $cblksize,$cblocks)=stat($fn.'/'.$filename);
1.12 www 105:
1.10 albertel 106: my $extension='';
107: if ($filename=~/\.(\w+)$/) { $extension=$1; }
1.15 matthew 108: if ($cmode&$dirptr) {
1.64 raeburn 109: putdirectory($r, $thisdisfn, $linkdir, $filename, $cmtime,$targetdir,\%bombs,\$numdir);
1.17 harris41 110: } elsif (&Apache::loncommon::fileembstyle($extension) ne 'hdn') {
1.64 raeburn 111: putresource($r, $udom, $uname, $filename, $thisdisfn, $resdir,
112: $targetdir, $linkdir, $cmtime,\%bombs,\$numres);
1.14 albertel 113: } else {
1.15 matthew 114: # "hidden" extension and not a directory, so hide it away.
1.2 www 115: }
116: }
117: closedir(DIR);
118:
1.115 bisitz 119: $r->print(&Apache::loncommon::end_data_table()
120: .&Apache::loncommon::end_page()
121: );
1.1 www 122: return OK;
123: }
1.127 www 124:
1.23 foxr 125: #
126: # Output the header of the page. This includes:
127: # - The HTML header
128: # - The H1/H3 stuff which includes the directory.
129: #
130: # startpage($r, $uame, $udom, $thisdisfn);
131: # $r - The apache request object.
132: # $uname - User name.
133: # $udom - Domain name the user is logged in under.
134: # $thisdisfn - Displayable version of the filename.
1.26 www 135:
1.23 foxr 136: sub startpage {
137: my ($r, $uname, $udom, $thisdisfn) = @_;
1.64 raeburn 138: my $currdir = '/priv/'.$uname.$thisdisfn;
1.39 www 139: &Apache::loncommon::content_type($r,'text/html');
1.23 foxr 140: $r->send_http_header;
1.64 raeburn 141:
1.68 raeburn 142: my $formaction='/priv/'.$uname.$thisdisfn.'/';
1.89 albertel 143: $formaction=~s|/+|/|g;
1.66 raeburn 144: &Apache::lonhtmlcommon::store_recent('construct',$formaction,$formaction);
1.121 bisitz 145:
1.125 droeschl 146: &Apache::lonhtmlcommon::clear_breadcrumbs();
147: &Apache::lonhtmlcommon::add_breadcrumb({
148: 'text' => 'Construction Space',
149: 'href' => &Apache::loncommon::authorspace(),
150: });
151: # breadcrumbs (and tools) will be created
152: # in start_page->bodytag->innerregister
153:
1.126 droeschl 154: $env{'request.noversionuri'}=$currdir.'/';
155: $r->print(&Apache::loncommon::start_page('Construction Space',undef));
1.90 albertel 156:
1.121 bisitz 157: $r->print(&Apache::loncommon::head_subbox(
158: &Apache::loncommon::CSTR_pageheader(1)));
159:
1.101 albertel 160: my $esc_thisdisfn = &Apache::loncommon::escape_single($thisdisfn);
1.108 raeburn 161: my $doctitle = 'LON-CAPA '.&mt('Construction Space');
1.109 bisitz 162: my $newname = &mt('New Name');
1.29 www 163: my $pubdirscript=(<<ENDPUBDIRSCRIPT);
1.77 albertel 164: <script type="text/javascript">
1.107 bisitz 165: top.document.title = '$esc_thisdisfn/ - $doctitle';
1.37 www 166: // Store directory location for menu bar to find
167:
1.101 albertel 168: parent.lastknownpriv='/~$uname$esc_thisdisfn/';
1.37 www 169:
170: // Confirmation dialogues
171:
1.64 raeburn 172: function currdiract(theform) {
173: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'publish') {
1.79 www 174: document.publishdir.filename.value = theform.filename.value;
175: document.publishdir.submit();
1.64 raeburn 176: }
1.113 schafran 177: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editmeta') {
1.66 raeburn 178: top.location=theform.filename.value+'default.meta'
1.64 raeburn 179: }
180: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) {
181: document.printdir.postdata.value=theform.filename.value
182: document.printdir.submit();
183: }
1.88 raeburn 184: if (theform.dirtask.options[theform.dirtask.selectedIndex].value == "delete") {
185: var delform = document.delresource
186: delform.filename.value = theform.filename.value
187: delform.submit()
188: }
1.64 raeburn 189: }
190:
191: function checkUpload(theform) {
192: if (theform.file == '') {
193: alert("Please use 'Browse..' to choose a file first, before uploading")
194: return
195: }
196: theform.submit()
197: }
198:
199: function SetPubDir(theform,printForm) {
200: if (theform.diraction.options[theform.diraction.selectedIndex].value == "open") {
1.75 albertel 201: top.location = theform.openname.value
1.64 raeburn 202: return
203: }
204: if (theform.diraction.options[theform.diraction.selectedIndex].value == "publish") {
1.79 www 205: theform.submit();
1.64 raeburn 206: }
1.113 schafran 207: if (theform.diraction.options[theform.diraction.selectedIndex].value == "editmeta") {
1.66 raeburn 208: top.location=theform.filename.value+'default.meta'
1.64 raeburn 209: }
1.68 raeburn 210: if (theform.diraction.options[theform.diraction.selectedIndex].value == "printdir") {
1.64 raeburn 211: theform.action = '/adm/printout'
212: theform.postdata.value = theform.filename.value
213: theform.submit()
214: }
1.88 raeburn 215: if (theform.diraction.options[theform.diraction.selectedIndex].value == "delete") {
216: var delform = document.delresource
217: delform.filename.value = theform.filename.value
218: delform.submit()
219: }
1.64 raeburn 220: return
221: }
222: function SetResChoice(theform) {
223: var activity = theform.reschoice.options[theform.reschoice.selectedIndex].value
224: if ((activity == 'rename') || (activity == 'copy') || (activity == 'move')) {
225: changename(theform,activity)
226: }
227: if (activity == 'publish') {
228: var pubform = document.pubresource
229: pubform.filename.value = theform.filename.value
230: pubform.submit()
231: }
232: if (activity == 'delete') {
233: var delform = document.delresource
234: delform.filename.value = theform.filename.value
1.71 raeburn 235: delform.submit()
1.64 raeburn 236: }
237: if (activity == 'obsolete') {
1.68 raeburn 238: var pubform = document.pubresource
239: pubform.filename.value = theform.filename.value
1.80 www 240: pubform.makeobsolete.value=1;
1.68 raeburn 241: pubform.submit()
1.64 raeburn 242: }
243: if (activity == 'print') {
1.68 raeburn 244: document.printresource.postdata.value = theform.filename.value
1.64 raeburn 245: document.printresource.submit()
246: }
247: if (activity == 'retrieve') {
1.68 raeburn 248: document.retrieveres.filename.value = theform.filename.value
249: document.retrieveres.submit()
1.64 raeburn 250: }
1.82 www 251: if (activity == 'cleanup') {
252: document.cleanup.filename.value = theform.filename.value
253: document.cleanup.submit()
254: }
1.64 raeburn 255: return
256: }
257: function changename(theform,activity) {
1.96 banghart 258: var oldname=theform.dispfilename.value;
1.109 bisitz 259: var newname=prompt('$newname',oldname);
1.97 banghart 260: if (newname == "" || !newname || newname == oldname) {
1.64 raeburn 261: return
262: }
263: document.moveresource.newfilename.value = newname
264: document.moveresource.filename.value = theform.filename.value
265: document.moveresource.action.value = activity
266: document.moveresource.submit();
267: }
1.29 www 268: </script>
269: ENDPUBDIRSCRIPT
1.64 raeburn 270: $r->print($pubdirscript);
271: }
272:
273: sub dircontrols {
274: my ($r,$uname,$udom,$thisdisfn) = @_;
1.84 www 275: my %lt=&Apache::lonlocal::texthash(
276: cnpd => 'Cannot publish directory',
277: cnrd => 'Cannot retrieve directory',
278: mcdi => 'Must create new subdirectory inside a directory',
279: pubr => 'Publish this Resource',
280: pubd => 'Publish this Directory',
1.88 raeburn 281: dedr => 'Delete Directory',
1.84 www 282: rtrv => 'Retrieve Old Version',
283: list => 'List Directory',
284: uplo => 'Upload file',
285: dele => 'Delete',
1.113 schafran 286: edit => 'Edit Metadata',
1.84 www 287: sela => 'Select Action',
288: nfil => 'New file',
289: nhtm => 'New HTML file',
290: nprb => 'New problem',
291: npag => 'New assembled page',
292: nseq => 'New assembled sequence',
293: ncrf => 'New custom rights file',
294: nsty => 'New style file',
295: nlib => 'New library file',
1.103 albertel 296: nbt => 'New bridgetask file',
1.84 www 297: nsub => 'New subdirectory',
298: renm => 'Rename current file to',
299: move => 'Move current file to',
300: copy => 'Copy current file to',
301: type => 'Type Name Here',
1.105 albertel 302: go => 'Go',
1.84 www 303: prnt => 'Print contents of directory',
304: crea => 'Create a new directory or LON-CAPA document',
305: acti => 'Actions for current directory',
1.105 albertel 306: updc => 'Upload a new document',
307: pick => 'Please select an action to perform using the new filename',
1.84 www 308: );
1.106 bisitz 309: my $mytype = $lt{'type'}; # avoid conflict with " and ' in javascript
1.64 raeburn 310: $r->print(<<END);
1.117 harmsja 311: <div class="LC_columnSection">
1.116 bisitz 312: <div>
313: <form name="curractions" method="post" action="">
314: <fieldset>
315: <legend>$lt{'acti'}</legend>
316: <select name="dirtask" onchange="currdiract(this.form)">
1.84 www 317: <option>$lt{'sela'}</option>
318: <option value="publish">$lt{'pubd'}</option>
1.113 schafran 319: <option value="editmeta">$lt{'edit'}</option>
1.84 www 320: <option value="printdir">$lt{'prnt'}</option>
1.88 raeburn 321: <option value="delete">$lt{'dedr'}</option>
1.116 bisitz 322: </select>
323: <input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
324: </fieldset>
325: </form>
326: <form name="publishdir" method="post" action="/adm/publish" target="_parent">
327: <input type="hidden" name="pubrec" value="" />
328: <input type="hidden" name="filename" value="" />
329: </form>
330: <form name="printdir" method="post" action="/adm/printout" target="_parent">
331: <input type="hidden" name="postdata" value="" />
332: </form>
333: </div>
334:
335: <div>
336: <form name="upublisher" enctype="multipart/form-data" method="post" action="/adm/upload" target="_parent">
337: <fieldset>
338: <legend>$lt{'updc'}</legend>
339: <input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
340: <input type="file" name="upfile" size="20" />
341: <input type="button" value="$lt{'uplo'}" onclick="checkUpload(this.form)" />
342: </fieldset>
343: </form>
344: </div>
345:
346: <div>
347: <form name="fileaction" method="post" action="/adm/cfile" target="_parent">
348: <fieldset>
349: <legend>$lt{'crea'}</legend>
350: <span class="LC_nobreak">
1.64 raeburn 351: <input type="hidden" name="filename" value="/~$uname$thisdisfn/" />
1.105 albertel 352: <script type="text/javascript">
353: function validate_go() {
354: var selected = document.fileaction.action.selectedIndex;
355: if (selected == 0) {
356: alert('$lt{'pick'}');
357: } else {
358: document.fileaction.submit();
359: }
360: }
361: </script>
362: <select name="action">
363: <option value="none">$lt{'sela'}</option>
364: <option value="newfile">$lt{'nfil'}:</option>
365: <option value="newhtmlfile">$lt{'nhtm'}:</option>
366: <option value="newproblemfile">$lt{'nprb'}:</option>
367: <option value="newpagefile">$lt{'npag'}:</option>
368: <option value="newsequencefile">$lt{'nseq'}:</option>
369: <option value="newrightsfile">$lt{'ncrf'}:</option>
370: <option value="newstyfile">$lt{'nsty'}:</option>
371: <option value="newtaskfile">$lt{'nbt'}:</option>
372: <option value="newlibraryfile">$lt{'nlib'}:</option>
373: <option value="newdir">$lt{'nsub'}:</option>
1.106 bisitz 374: </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 375: </span>
1.116 bisitz 376: </fieldset>
377: </form>
378: </div>
379: </div>
1.64 raeburn 380: END
381: }
382:
383: sub resourceactions {
384: my ($r,$uname,$udom,$thisdisfn) = @_;
385: $r->print(<<END);
386: <form name="moveresource" action="/adm/cfile" target="_parent" method="post">
387: <input type="hidden" name="filename" value="" />
388: <input type="hidden" name="newfilename" value="" />
389: <input type="hidden" name="action" value="" />
390: </form>
391: <form name="delresource" action="/adm/cfile" target="_parent" method="post">
392: <input type="hidden" name="filename" value="" />
393: <input type="hidden" name="action" value="delete" />
394: </form>
395: <form name="pubresource" action="/adm/publish" target="_parent" method="post">
396: <input type="hidden" name="filename" value="" />
1.80 www 397: <input type="hidden" name="makeobsolete" value="0" />
1.64 raeburn 398: </form>
399: <form name="printresource" action="/adm/printout" target="_parent" method="post">
400: <input type="hidden" name="postdata" value="" />
401: </form>
402: <form name="retrieveres" action="/adm/retrieve" target="_parent" method="post">
403: <input type="hidden" name="filename" value="" />
404: </form>
1.82 www 405: <form name="cleanup" action="/adm/cleanup" target="_parent" method="post">
406: <input type="hidden" name="filename" value="" />
407: </form>
1.64 raeburn 408: END
1.23 foxr 409: }
410:
411: #
412: # Get the title string or "[untitled]" if the file has no title metadata:
413: # Without the latter substitution, it's impossible to examine metadata for
414: # untitled resources. Resources may be legitimately untitled, to prevent
415: # searches from locating them.
416: #
417: # $str = getTitleString($fullname);
418: # $fullname - Fully qualified filename to check.
419: #
420: sub getTitleString {
421: my $fullname = shift;
422: my $title = &Apache::lonnet::metadata($fullname, 'title');
423:
424: unless ($title) {
1.40 www 425: $title = "[".&mt('untitled')."]";
1.23 foxr 426: }
427: return $title;
428: }
429:
1.55 www 430: sub getCopyRightString {
431: my $fullname = shift;
432: return &Apache::lonnet::metadata($fullname, 'copyright');
433: }
1.61 www 434:
435: sub getSourceRightString {
436: my $fullname = shift;
437: return &Apache::lonnet::metadata($fullname, 'sourceavail');
438: }
1.23 foxr 439: #
1.21 foxr 440: # Put out a directory table row:
441: # putdirectory(r, base, here, dirname, modtime)
442: # r - Apache request object.
443: # reqfile - File in request.
444: # here - Where we are in directory tree.
445: # dirname - Name of directory special file.
446: # modtime - Encoded modification time.
447: #
448: sub putdirectory {
1.64 raeburn 449: my ($r, $reqfile, $here, $dirname, $modtime, $resdir, $bombs, $numdir) = @_;
1.21 foxr 450: # construct the display filename: the directory name unless ..:
451:
452: my $disfilename = $dirname;
453: if ($dirname eq '..') {
1.39 www 454: $disfilename = '<i>'.&mt('Parent Directory').'</i>';
1.21 foxr 455: }
1.64 raeburn 456: unless ( (($dirname eq '..') && ($reqfile eq '')) || ($dirname eq '.')) {
1.50 www 457: my $kaputt=0;
458: foreach (keys %{$bombs}) {
1.56 albertel 459: if ($_=~m:^\Q$resdir\E/\Q$disfilename\E/:) { $kaputt=1; last; }
1.50 www 460: }
1.52 www 461: %Apache::lonpublisher::metadatafields=();
462: %Apache::lonpublisher::metadatakeys=();
463: my $construct=$here;
1.98 albertel 464: $construct=~s{^/priv/($LONCAPA::username_re)$}{/home/$1/public_html};
1.67 raeburn 465: my $dirpath = $here;
1.98 albertel 466: $dirpath=~s{^/priv/}{/~};
1.52 www 467: &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile(
468: $construct.'/'.$dirname.'/default.meta'
469: ));
1.64 raeburn 470: my $actionitem = '';
471: if ($dirname eq '..') {
1.109 bisitz 472: $actionitem = &mt('Go to ...');
1.64 raeburn 473: } else {
474: $actionitem =
475: '<form name="dirselect_'.$$numdir.
476: '" action="/adm/publish" target="_parent">'.
1.85 albertel 477: '<select name="diraction" onchange="SetPubDir(this.form,document)">'.
1.64 raeburn 478: '<option selected="selected">'.&mt('Select action').'</option>'.
479: '<option value="open">'.&mt('Open').'</option>'.
480: '<option value="publish">'.&mt('Publish').'</option>'.
1.113 schafran 481: '<option value="editmeta">'.&mt('Edit Metadata').'</option>'.
1.77 albertel 482: '<option value="printdir">'.&mt('Print directory').'</option>'.
1.88 raeburn 483: '<option value="delete">'.&mt('Delete directory').'</option>'.
1.64 raeburn 484: '</select>'.
1.86 albertel 485: '<input type="hidden" name="filename" value="'.&HTML::Entities::encode($dirpath.'/'.$dirname,'<>&"').'/" />'.
1.75 albertel 486: '<input type="hidden" name="openname" value="'.$here.'/'.$dirname.'/" />'.
1.64 raeburn 487: '<input type="hidden" name="postdata" value="" />'.
488: '</form>';
489: $$numdir ++;
490: }
1.92 albertel 491: $r->print('<tr class="LC_browser_folder">'.
1.53 www 492: '<td><img src="'.
1.123 bisitz 493: $Apache::lonnet::perlvar{'lonIconsURL'}.'/navmap.folder.closed.gif" alt="folder" /></td>'.
1.64 raeburn 494: '<td>'.$actionitem.'</td>'.
1.92 albertel 495: '<td><span class="LC_filename"><a href="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" target="_parent">'.
496: $disfilename.'</a></span></td>'.
1.115 bisitz 497: '<td colspan="3">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($resdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'});
1.92 albertel 498: if ($Apache::lonpublisher::metadatafields{'subject'} ne '') {
499: $r->print(' <i>'.
500: $Apache::lonpublisher::metadatafields{'subject'}.
501: '</i> ');
502: }
503: $r->print($Apache::lonpublisher::metadatafields{'keywords'}.'</td>'.
1.42 www 504: '<td>'.&Apache::lonlocal::locallocaltime($modtime).'</td>'.
1.25 www 505: "</tr>\n");
1.64 raeburn 506: }
1.21 foxr 507: return OK;
508: }
1.22 foxr 509: #
510: # Put a table row for a file resource.
511: #
512: sub putresource {
1.64 raeburn 513: my ($r, $udom, $uname, $filename, $thisdisfn,
1.22 foxr 514: $resdir, $targetdir, $linkdir,
1.64 raeburn 515: $cmtime,$bombs,$numres) = @_;
1.81 www 516: &Apache::lonnet::devalidate_cache_new('meta',$targetdir.'/'.$filename);
1.64 raeburn 517: my $pubstatus = 'unpublished';
1.47 sakharuk 518: my $status=&mt('Unpublished');
1.92 albertel 519: my $css_class='LC_browser_file';
1.22 foxr 520: my $title=' ';
1.60 albertel 521: my $publish_button=&mt('Publish');
1.95 albertel 522: my $cstr_dir = '/home/'.$uname.'/public_html/'.$thisdisfn.'/';
1.64 raeburn 523: # my $action_buttons=
524: # '<br /><a target="_parent" href="/adm/cfile?action=delete&filename=/~'.
525: # $uname.'/'.$thisdisfn.'/'.$filename.'">'.
526: # &mt('Delete').'</a>';
1.22 foxr 527: if (-e $resdir.'/'.$filename) {
1.91 www 528: my $same=0;
1.22 foxr 529: my ($rdev,$rino,$rmode,$rnlink,
530: $ruid,$rgid,$rrdev,$rsize,
531: $ratime,$rmtime,$rctime,
532: $rblksize,$rblocks)=stat($resdir.'/'.$filename);
1.91 www 533: if ($rmtime>=$cmtime) {
534: $same=1;
535: } else {
536: if (&Apache::londiff::are_different_files($resdir.'/'.$filename,
1.95 albertel 537: $cstr_dir.'/'.$filename)) {
1.91 www 538: $same=0;
539: } else {
540: $same=1;
541: }
542: }
1.95 albertel 543: my $meta_cmtime = (stat($cstr_dir.'/'.$filename.'.meta'))[9];
544: my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
545: my $meta_same = 1;
546: if ($meta_rmtime < $meta_cmtime
547: && &Apache::londiff::are_different_files($resdir.'/'.$filename.'.meta',
548: $cstr_dir.'/'.$filename.'.meta')) {
549: $meta_same = 0;
550: }
1.64 raeburn 551: $publish_button=&mt('Re-publish');
1.124 bisitz 552:
553: my $rights_status =
554: &mt(&getCopyRightString($targetdir.'/'.$filename)).', ';
555:
556: my %lt_SourceRight = &Apache::lonlocal::texthash(
557: 'open' => 'Source: open',
558: 'closed' => 'Source: closed',
559: );
560: $rights_status .=
561: $lt_SourceRight{&getSourceRightString($targetdir.'/'.$filename)};
562:
1.95 albertel 563: $title = '<a href="/res/'.$targetdir.'/'.$filename.
564: '.meta" target="cat">'.
565: &getTitleString($targetdir.'/'.$filename).'</a>';
1.91 www 566: if ($same) {
1.40 www 567: if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
1.64 raeburn 568: $pubstatus = 'obsolete';
1.41 www 569: $status=&mt('Obsolete');
1.95 albertel 570: } else {
571: if (!$meta_same) {
572: $pubstatus = 'metamodified';
573: } else {
574: $pubstatus = 'published';
575: }
576: $status=&mt('Published').
577: '<br />'. $rights_status;
578: }
1.64 raeburn 579: # } else {
580: # $action_buttons='';
581: # }
1.22 foxr 582: } else {
1.64 raeburn 583: $pubstatus = 'modified';
1.95 albertel 584: $status=&mt('Modified').
585: '<br />'. $rights_status;
1.64 raeburn 586: # $action_buttons='';
1.22 foxr 587: if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
1.57 www 588: $status.='<br /><a href="/adm/diff?filename=/~'.$uname.
1.22 foxr 589: $thisdisfn.'/'.$filename.
1.77 albertel 590: '&versiontwo=priv" target="cat">'.&mt('Diffs').'</a>';
1.22 foxr 591: }
1.95 albertel 592: }
593:
1.77 albertel 594: $title.="\n".'<br /><a href="/~'.$uname.$thisdisfn.'/'.$filename.'.meta">'.
1.110 bisitz 595: ($$bombs{$targetdir.'/'.$filename}?'<img src="/adm/lonMisc/bomb.gif" border="0" alt="'.&mt('bomb').'" />':&mt('Edit Metadata')).'</a>';
1.95 albertel 596:
597: if (!$meta_same) {
598: $title = &mt('Metadata Modified').'<br />'.$title.
599: '<br /><a href="/adm/diff?filename=/~'.$uname.
600: $thisdisfn.'/'.$filename.'.meta'.
601: '&versiontwo=priv" target="cat">'.&mt('Metadata Diffs').'</a>';
602: $title.="\n".'<br /><a href="/adm/retrieve?filename=/~'.$uname.
603: $thisdisfn.'/'.$filename.'.meta" target="_parent">'.&mt('Retrieve Metadata').'</a>';
604: }
1.77 albertel 605: $status.="\n".'<br /><a href="/adm/retrieve?filename=/~'.$uname.
1.64 raeburn 606: $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Retrieve').'</a>';
1.22 foxr 607: }
1.33 www 608: my $editlink='';
1.38 taceyjo1 609: my $editlink2='';
1.36 www 610: if ($filename=~/\.(xml|html|htm|xhtml|xhtm|sty)$/) {
1.64 raeburn 611: $editlink=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('Edit').'</a>)';
1.34 www 612: }
613: if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
1.64 raeburn 614: $editlink=' (<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('EditXML').'</a>)';
615: $editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceColoredit=1" target="_parent">'.&mt('Edit').'</a>)';
1.43 taceyjo1 616: }
1.82 www 617: if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) {
1.83 www 618: $editlink.=' (<a href="/adm/cleanup?filename=/~'.$uname.
619: $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Clean Up').')</a>';
1.82 www 620: }
1.43 taceyjo1 621: if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.46 taceyjo1 622: $editlink=' (<a target="_parent" href="/adm/cfile?decompress=/~'.
623: $uname.$thisdisfn.'/'.$filename.'">'.&mt('Decompress').'</a>)';
1.33 www 624: }
1.64 raeburn 625: my $pub_select = '';
626: &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres);
1.115 bisitz 627: $r->print(&Apache::loncommon::start_data_table_row().
1.53 www 628: '<td>'.($filename=~/[\#\~]$/?' ':
1.86 albertel 629: '<img src="'.&Apache::loncommon::icon($filename).'" alt="" />').'</td>'.
1.64 raeburn 630: '<td>'.$pub_select.'</td>'.
1.104 albertel 631: '<td><span class="LC_filename">'.
1.64 raeburn 632: '<a href="'.$linkdir.'/'.$filename.'" target="_parent">'.
1.92 albertel 633: $filename.'</a></span>'.$editlink2.$editlink.
1.22 foxr 634: '</td>'.
635: '<td>'.$title.'</td>'.
1.115 bisitz 636: '<td class="LC_browser_file_'.$pubstatus.'"> </td>'. # Display publication status
637: '<td>'.$status.'</td>'.
1.42 www 638: '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'.
1.115 bisitz 639: &Apache::loncommon::end_data_table_row()
640: );
1.22 foxr 641: return OK;
1.23 foxr 642: }
1.64 raeburn 643:
644: sub create_pubselect {
645: my ($r,$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres) = @_;
646: $$pub_select = '
647: <form name="resselect_'.$$numres.'" action="">
1.85 albertel 648: <select name="reschoice" onchange="SetResChoice(this.form)">
1.77 albertel 649: <option>'.&mt('Select action').'</option>'.
650: '<option value="copy">'.&mt('Copy').'</option>';
1.68 raeburn 651: if ($pubstatus eq 'obsolete' || $pubstatus eq 'unpublished') {
652: $$pub_select .=
1.77 albertel 653: '<option value="rename">'.&mt('Rename').'</option>'.
654: '<option value="move">'.&mt('Move').'</option>'.
655: '<option value="delete">'.&mt('Delete').'</option>';
1.64 raeburn 656: } else {
657: $$pub_select .= '
1.77 albertel 658: <option value="obsolete">'.&mt('Mark obsolete').'</option>';
1.64 raeburn 659: }
660: # check for versions
661: my $versions = &check_for_versions($r,'/'.$filename,$udom,$uname);
662: if ($versions > 0) {
663: $$pub_select .='
1.77 albertel 664: <option value="retrieve">'.&mt('Retrieve old version').'</option>';
1.64 raeburn 665: }
666: $$pub_select .= '
1.77 albertel 667: <option value="publish">'.$publish_button.'</option>'.
1.82 www 668: '<option value="cleanup">'.&mt('Clean up').'</option>'.
1.77 albertel 669: '<option value="print">'.&mt('Print').'</option>'.
1.68 raeburn 670: '</select>
1.64 raeburn 671: <input type="hidden" name="filename" value="/~'.
1.96 banghart 672: &HTML::Entities::encode($uname.$thisdisfn.'/'.$filename,'<>&"').'" />
673: <input type="hidden" name="dispfilename" value="'.
1.99 albertel 674: &HTML::Entities::encode($filename).'" /></form>';
1.64 raeburn 675: $$numres ++;
676: }
677:
678: sub check_for_versions {
679: my ($r,$fn,$udom,$uname) = @_;
680: my $versions = 0;
681: my $docroot=$r->dir_config('lonDocRoot');
682: my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn;
683: my $resdir=$resfn;
684: $resdir=~s/\/[^\/]+$/\//;
685: $fn=~/\/([^\/]+)\.(\w+)$/;
686: my $main=$1;
687: my $suffix=$2;
688: opendir(DIR,$resdir);
689: while (my $filename=readdir(DIR)) {
690: if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
691: $versions ++;
692: }
693: }
694: return $versions;
695: }
696:
1.23 foxr 697: #
698: # Categorize files in the directory.
699: # For each file in a list of files in a file directory,
700: # the file categorized as one of:
701: # - directory
702: # - sequence
703: # - problem
704: # - Other resource.
705: #
706: # For each file the modification date is determined as well.
707: # Returned is a list of sublists:
708: # (directories, sequences, problems, other)
709: # each of the sublists contains entries of the following form (sorted by
710: # filename):
711: # (filename, typecode, lastmodtime)
712: #
713: # $list = CategorizeFiles($location, $files)
714: # $location - Directory in which the files live (relative to our
715: # execution.
716: # $files - list of files.
717: #
718: sub CategorizeFiles {
719: my $location = shift;
720: my $files = shift;
1.22 foxr 721: }
722:
1.4 www 723: 1;
724: __END__
1.17 harris41 725:
726:
1.114 jms 727: =head1 NAME
728:
729: Apache::lonpubdir - Construction space directory lister
730:
731: =head1 SYNOPSIS
732:
733: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
734:
735: <LocationMatch "^/\~.*/$">
736: PerlAccessHandler Apache::loncacc
737: SetHandler perl-script
738: PerlHandler Apache::lonpubdir
739: ErrorDocument 403 /adm/login
740: ErrorDocument 404 /adm/notfound.html
741: ErrorDocument 406 /adm/unauthorized.html
742: ErrorDocument 500 /adm/errorhandler
743: </LocationMatch>
744:
745: <Location /adm/pubdir>
746: PerlAccessHandler Apache::lonacc
747: SetHandler perl-script
748: PerlHandler Apache::lonpubdir
749: ErrorDocument 403 /adm/login
750: ErrorDocument 404 /adm/notfound.html
751: ErrorDocument 406 /adm/unauthorized.html
752: ErrorDocument 500 /adm/errorhandler
753: </Location>
754:
755: =head1 INTRODUCTION
756:
757: This module publishes a directory of files.
758:
759: This is part of the LearningOnline Network with CAPA project
760: described at http://www.lon-capa.org.
761:
762: =head1 HANDLER SUBROUTINE
763:
764: This routine is called by Apache and mod_perl.
765:
766: =over 4
767:
768: =item *
769:
770: read in information
771:
772: =item *
773:
774: start page output
775:
776: =item *
777:
778: run through list of files and attempt to publish unhidden files
779:
780: =back
781:
782: =head1 SUBROUTINES:
783:
784: =over
785:
786: =item startpage($r, $uame, $udom, $thisdisfn)
787:
788: Output the header of the page. This includes:
789: - The HTML header
790: - The H1/H3 stuff which includes the directory.
791:
792: startpage($r, $uame, $udom, $thisdisfn);
793: $r - The apache request object.
794: $uname - User name.
795: $udom - Domain name the user is logged in under.
796: $thisdisfn - Displayable version of the filename.
797:
798: =item getTitleString($fullname)
799:
800: Get the title string or "[untitled]" if the file has no title metadata:
801: Without the latter substitution, it's impossible to examine metadata for
802: untitled resources. Resources may be legitimately untitled, to prevent
803: searches from locating them.
804:
805: $str = getTitleString($fullname);
806: $fullname - Fully qualified filename to check.
807:
808: =item putdirectory(r, base, here, dirname, modtime)
809:
810: Put out a directory table row:
811:
812: putdirectory($r, $base, $here, $dirname, $modtime)
813: $r - Apache request object.
814: $reqfile - File in request.
815: $here - Where we are in directory tree.
816: $dirname - Name of directory special file.
817: $modtime - Encoded modification time.
818:
819: =item CategorizeFiles($location, $files)
820:
821: Categorize files in the directory.
822: For each file in a list of files in a file directory,
823: the file categorized as one of:
824: - directory
825: - sequence
826: - problem
827: - Other resource.
828:
829: For each file the modification date is determined as well.
830: Returned is a list of sublists:
831: (directories, sequences, problems, other)
832: each of the sublists contains entries of the following form (sorted by filename):
833: (filename, typecode, lastmodtime)
834:
835: $list = CategorizeFiles($location, $files)
836: $location - Directory in which the files live (relative to our execution)
837: $files - list of files.
838:
839: =back
840:
841: =cut
842:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>