--- loncom/publisher/lonpubdir.pm 2008/11/10 14:11:08 1.112 +++ loncom/publisher/lonpubdir.pm 2009/05/19 22:52:29 1.121 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Construction Space Directory Lister # -# $Id: lonpubdir.pm,v 1.112 2008/11/10 14:11:08 jms Exp $ +# $Id: lonpubdir.pm,v 1.121 2009/05/19 22:52:29 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,118 +27,6 @@ # ### -=head1 NAME - -Apache::lonpubdir - Construction space directory lister - -=head1 SYNOPSIS - -Invoked (for various locations) by /etc/httpd/conf/srm.conf: - - <LocationMatch "^/\~.*/$"> - PerlAccessHandler Apache::loncacc - SetHandler perl-script - PerlHandler Apache::lonpubdir - ErrorDocument 403 /adm/login - ErrorDocument 404 /adm/notfound.html - ErrorDocument 406 /adm/unauthorized.html - ErrorDocument 500 /adm/errorhandler - </LocationMatch> - - <Location /adm/pubdir> - PerlAccessHandler Apache::lonacc - SetHandler perl-script - PerlHandler Apache::lonpubdir - ErrorDocument 403 /adm/login - ErrorDocument 404 /adm/notfound.html - ErrorDocument 406 /adm/unauthorized.html - ErrorDocument 500 /adm/errorhandler - </Location> - -=head1 INTRODUCTION - -This module publishes a directory of files. - -This is part of the LearningOnline Network with CAPA project -described at http://www.lon-capa.org. - -=head1 HANDLER SUBROUTINE - -This routine is called by Apache and mod_perl. - -=over 4 - -=item * - -read in information - -=item * - -start page output - -=item * - -run through list of files and attempt to publish unhidden files - -=back - -=head2 OTHER SUBROUTINES: - -=head3 startpage($r, $uame, $udom, $thisdisfn) - -Output the header of the page. This includes: - - The HTML header - - The H1/H3 stuff which includes the directory. - - startpage($r, $uame, $udom, $thisdisfn); - $r - The apache request object. - $uname - User name. - $udom - Domain name the user is logged in under. - $thisdisfn - Displayable version of the filename. - -=head3 getTitleString($fullname) - - Get the title string or "[untitled]" if the file has no title metadata: - Without the latter substitution, it's impossible to examine metadata for - untitled resources. Resources may be legitimately untitled, to prevent - searches from locating them. - - $str = getTitleString($fullname); - $fullname - Fully qualified filename to check. - -=head3 putdirectory(r, base, here, dirname, modtime) - - Put out a directory table row: - - putdirectory($r, $base, $here, $dirname, $modtime) - $r - Apache request object. - $reqfile - File in request. - $here - Where we are in directory tree. - $dirname - Name of directory special file. - $modtime - Encoded modification time. - -=head3 CategorizeFiles($location, $files) - - Categorize files in the directory. - For each file in a list of files in a file directory, - the file categorized as one of: - - directory - - sequence - - problem - - Other resource. - - For each file the modification date is determined as well. - Returned is a list of sublists: - (directories, sequences, problems, other) - each of the sublists contains entries of the following form (sorted by filename): - (filename, typecode, lastmodtime) - - $list = CategorizeFiles($location, $files) - $location - Directory in which the files live (relative to our execution) - $files - list of files. - -=cut - package Apache::lonpubdir; use strict; @@ -174,7 +62,7 @@ sub handler { &Apache::loncacc::constructaccess( $fn,$r->dir_config('lonDefDomain')); unless (($uname) && ($udom)) { - $r->log_reason($uname.' at '.$udom. + $r->log_reason($uname.':'.$udom. ' trying to list directory '.$env{'form.filename'}. ' ('.$fn.') - not authorized', $r->filename); @@ -186,7 +74,7 @@ sub handler { $fn=~s/\/$//; unless ($fn) { - $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}. + $r->log_reason($env{'user.name'}.':'.$env{'user.domain'}. ' trying to list empty directory', $r->filename); return HTTP_NOT_FOUND; } @@ -217,15 +105,16 @@ sub handler { my $numres = 0; # Start off the directory table. - $r->print('<h3>'.&mt('Directory Contents:').'</h3>'); - $r->print('<table id="LC_browser"><tr>'. - '<th>'.&mt('Type').'</th>'. - '<th>'.&mt('Actions').'</th>'. - '<th>'.&mt('Name').'</th>'. - '<th>'.&mt('Title').'</th>'. - '<th>'.&mt('Status').'</th>'. - '<th>'.&mt('Last Modified'). - '</th></tr>'."\n"); + $r->print(&Apache::loncommon::start_data_table() + .&Apache::loncommon::start_data_table_header_row() + .'<th>'.&mt('Type').'</th>' + .'<th>'.&mt('Actions').'</th>' + .'<th>'.&mt('Name').'</th>' + .'<th>'.&mt('Title').'</th>' + .'<th colspan="2">'.&mt('Status').'</th>' + .'<th>'.&mt('Last Modified').'</th>' + .&Apache::loncommon::end_data_table_header_row() + ); my $filename; my $dirptr=16384; # Mask indicating a directory in stat.cmode. @@ -251,7 +140,9 @@ sub handler { } closedir(DIR); - $r->print('</table>'.&Apache::loncommon::end_page()); + $r->print(&Apache::loncommon::end_data_table() + .&Apache::loncommon::end_page() + ); return OK; } # @@ -268,7 +159,7 @@ sub getEffectiveUrl { # Replace the ~username of the URL with /home/username/public_html # so that we don't have to worry about ~ expansion internally. # - $fn=~s/^http\:\/\/[^\/]+\///; + $fn=~s/^https?\:\/\/[^\/]+\///; $fn=~s/^\///; $fn=~s{~($LONCAPA::username_re)}{/home/$1/public_html}; @@ -308,26 +199,21 @@ sub startpage { my $formaction='/priv/'.$uname.$thisdisfn.'/'; $formaction=~s|/+|/|g; - my $pagetitle .= &Apache::loncommon::help_open_menu('','',3,'Authoring'). - '<font face="Arial, Helvetica, sans-serif" size="+1"><b>'.&mt('Construction Space').'</b>:</font> '. - '<form name="dirs" method="post" action="'.$formaction. - '" target="_parent"><tt><b>'. - &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />". - &Apache::lonhtmlcommon::select_recent('construct','recent', - 'this.form.action=this.form.recent.value;this.form.submit()'). - '</form>'; &Apache::lonhtmlcommon::store_recent('construct',$formaction,$formaction); + if ($env{'environment.remote'} eq 'off') { - $env{'request.noversionuri'}=$currdir.'/'; - $r->print(&Apache::loncommon::start_page('Construction Space',undef, - {'body_title' => - $pagetitle,})); + $env{'request.noversionuri'}=$currdir.'/'; + $r->print(&Apache::loncommon::start_page('Construction Space',undef)); } else { - $r->print(&Apache::loncommon::start_page('Construction Space',undef, - { 'only_body' => 1,})); - $r->print($pagetitle); + $r->print(&Apache::loncommon::start_page('Construction Space',undef, + { 'only_body' => 1,})); } + $r->print(&Apache::lonhtmlcommon::breadcrumbs()); # FIXME add breadcrumbs + + $r->print(&Apache::loncommon::head_subbox( + &Apache::loncommon::CSTR_pageheader(1))); + my $esc_thisdisfn = &Apache::loncommon::escape_single($thisdisfn); my $doctitle = 'LON-CAPA '.&mt('Construction Space'); my $newname = &mt('New Name'); @@ -345,7 +231,7 @@ parent.lastknownpriv='/~$uname$esc_thisd document.publishdir.filename.value = theform.filename.value; document.publishdir.submit(); } - if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editcat') { + if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'editmeta') { top.location=theform.filename.value+'default.meta' } if (theform.dirtask.options[theform.dirtask.selectedIndex].value == 'printdir' ) { @@ -375,7 +261,7 @@ parent.lastknownpriv='/~$uname$esc_thisd if (theform.diraction.options[theform.diraction.selectedIndex].value == "publish") { theform.submit(); } - if (theform.diraction.options[theform.diraction.selectedIndex].value == "editcat") { + if (theform.diraction.options[theform.diraction.selectedIndex].value == "editmeta") { top.location=theform.filename.value+'default.meta' } if (theform.diraction.options[theform.diraction.selectedIndex].value == "printdir") { @@ -442,8 +328,7 @@ ENDPUBDIRSCRIPT if ((($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) && $env{'environment.remote'} ne 'off') { - $r->print('<h3>'.&mt('Co-Author').': '.$uname.' at '.$udom. - '</h3>'); + $r->print('<h3>'.&mt('Co-Author [_1]',$uname.':'.$udom).'</h3>'); } } @@ -460,7 +345,7 @@ sub dircontrols { list => 'List Directory', uplo => 'Upload file', dele => 'Delete', - edit => 'Edit Catalog Information', + edit => 'Edit Metadata', sela => 'Select Action', nfil => 'New file', nhtm => 'New HTML file', @@ -485,42 +370,46 @@ sub dircontrols { ); my $mytype = $lt{'type'}; # avoid conflict with " and ' in javascript $r->print(<<END); - <table id="LC_cstr_controls"> - <tr> - <th>$lt{'acti'}</th> - <th>$lt{'updc'}</th> - <th>$lt{'crea'}</th> - </tr> - <tr> - <td> - <form name="curractions" method="post" action=""> - <select name="dirtask" onchange="currdiract(this.form)"> +<div class="LC_columnSection"> + <div> + <form name="curractions" method="post" action=""> + <fieldset> + <legend>$lt{'acti'}</legend> + <select name="dirtask" onchange="currdiract(this.form)"> <option>$lt{'sela'}</option> <option value="publish">$lt{'pubd'}</option> - <option value="editcat">$lt{'edit'}</option> + <option value="editmeta">$lt{'edit'}</option> <option value="printdir">$lt{'prnt'}</option> <option value="delete">$lt{'dedr'}</option> - </select> - <input type="hidden" name="filename" value="/~$uname$thisdisfn/" /> - </form> - <form name="publishdir" method="post" action="/adm/publish" target="_parent"> - <input type="hidden" name="pubrec" value="" /> - <input type="hidden" name="filename" value="" /> - </form> - <form name="printdir" method="post" action="/adm/printout" target="_parent"> - <input type="hidden" name="postdata" value="" /> - </form> - </td> - <td> - <form name="upublisher" enctype="multipart/form-data" method="post" action="/adm/upload" target="_parent"> - <input type="hidden" name="filename" value="/~$uname$thisdisfn/" /> - <input type="file" name="upfile" size="20" /> - <input type="button" value="$lt{'uplo'}" onclick="checkUpload(this.form)" /> - </form> - </td> - <td> - <form name="fileaction" method="post" action="/adm/cfile" target="_parent"> - <span style="white-space: nowrap"> + </select> + <input type="hidden" name="filename" value="/~$uname$thisdisfn/" /> + </fieldset> + </form> + <form name="publishdir" method="post" action="/adm/publish" target="_parent"> + <input type="hidden" name="pubrec" value="" /> + <input type="hidden" name="filename" value="" /> + </form> + <form name="printdir" method="post" action="/adm/printout" target="_parent"> + <input type="hidden" name="postdata" value="" /> + </form> + </div> + + <div> + <form name="upublisher" enctype="multipart/form-data" method="post" action="/adm/upload" target="_parent"> + <fieldset> + <legend>$lt{'updc'}</legend> + <input type="hidden" name="filename" value="/~$uname$thisdisfn/" /> + <input type="file" name="upfile" size="20" /> + <input type="button" value="$lt{'uplo'}" onclick="checkUpload(this.form)" /> + </fieldset> + </form> + </div> + + <div> + <form name="fileaction" method="post" action="/adm/cfile" target="_parent"> + <fieldset> + <legend>$lt{'crea'}</legend> + <span class="LC_nobreak"> <input type="hidden" name="filename" value="/~$uname$thisdisfn/" /> <script type="text/javascript"> function validate_go() { @@ -546,10 +435,10 @@ sub dircontrols { <option value="newdir">$lt{'nsub'}:</option> </select> <input type="text" name="newfilename" value="$lt{'type'}" onfocus="if (this.value == '$mytype') this.value=''" /> <input type="button" value="Go" onclick="validate_go();" /> </span> - </form> - </td> - </tr> - </table> + </fieldset> + </form> + </div> +</div> END } @@ -561,7 +450,7 @@ sub pubbuttons { '<input type="submit" value="'.&mt('Publish Directory').'" /></td><td>'. '<input type="button" onclick="window.location='."'/~". $uname.$thisdisfn."/default.meta'".'" value="'. -&mt('Edit Directory Catalog Information').'" /></td></tr></table></form>'); +&mt('Edit Directory Metadata').'" /></td></tr></table></form>'); } sub resourceactions { @@ -662,7 +551,7 @@ sub putdirectory { '<option selected="selected">'.&mt('Select action').'</option>'. '<option value="open">'.&mt('Open').'</option>'. '<option value="publish">'.&mt('Publish').'</option>'. - '<option value="editcat">'.&mt('Edit catalog information').'</option>'. + '<option value="editmeta">'.&mt('Edit Metadata').'</option>'. '<option value="printdir">'.&mt('Print directory').'</option>'. '<option value="delete">'.&mt('Delete directory').'</option>'. '</select>'. @@ -678,7 +567,7 @@ sub putdirectory { '<td>'.$actionitem.'</td>'. '<td><span class="LC_filename"><a href="'.&HTML::Entities::encode($here.'/'.$dirname,'<>&"').'/" target="_parent">'. $disfilename.'</a></span></td>'. - '<td colspan="2">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($resdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'}); + '<td colspan="3">'.($kaputt?&Apache::lonhtmlcommon::authorbombs($resdir.'/'.$disfilename.'/'):'').$Apache::lonpublisher::metadatafields{'title'}); if ($Apache::lonpublisher::metadatafields{'subject'} ne '') { $r->print(' <i>'. $Apache::lonpublisher::metadatafields{'subject'}. @@ -800,7 +689,7 @@ sub putresource { } my $pub_select = ''; &create_pubselect($r,\$pub_select,$udom,$uname,$thisdisfn,$filename,$resdir,$pubstatus,$publish_button,$numres); - $r->print('<tr class="LC_browser_file_'.$pubstatus.'">'. + $r->print(&Apache::loncommon::start_data_table_row(). '<td>'.($filename=~/[\#\~]$/?' ': '<img src="'.&Apache::loncommon::icon($filename).'" alt="" />').'</td>'. '<td>'.$pub_select.'</td>'. @@ -809,9 +698,11 @@ sub putresource { $filename.'</a></span>'.$editlink2.$editlink. '</td>'. '<td>'.$title.'</td>'. - '<td>'.$status.'</td>'. + '<td class="LC_browser_file_'.$pubstatus.'"> </td>'. # Display publication status + '<td>'.$status.'</td>'. '<td>'.&Apache::lonlocal::locallocaltime($cmtime).'</td>'. - "</tr>\n"); + &Apache::loncommon::end_data_table_row() + ); return OK; } @@ -898,3 +789,119 @@ sub CategorizeFiles { __END__ +=head1 NAME + +Apache::lonpubdir - Construction space directory lister + +=head1 SYNOPSIS + +Invoked (for various locations) by /etc/httpd/conf/srm.conf: + + <LocationMatch "^/\~.*/$"> + PerlAccessHandler Apache::loncacc + SetHandler perl-script + PerlHandler Apache::lonpubdir + ErrorDocument 403 /adm/login + ErrorDocument 404 /adm/notfound.html + ErrorDocument 406 /adm/unauthorized.html + ErrorDocument 500 /adm/errorhandler + </LocationMatch> + + <Location /adm/pubdir> + PerlAccessHandler Apache::lonacc + SetHandler perl-script + PerlHandler Apache::lonpubdir + ErrorDocument 403 /adm/login + ErrorDocument 404 /adm/notfound.html + ErrorDocument 406 /adm/unauthorized.html + ErrorDocument 500 /adm/errorhandler + </Location> + +=head1 INTRODUCTION + +This module publishes a directory of files. + +This is part of the LearningOnline Network with CAPA project +described at http://www.lon-capa.org. + +=head1 HANDLER SUBROUTINE + +This routine is called by Apache and mod_perl. + +=over 4 + +=item * + +read in information + +=item * + +start page output + +=item * + +run through list of files and attempt to publish unhidden files + +=back + +=head1 SUBROUTINES: + +=over + +=item startpage($r, $uame, $udom, $thisdisfn) + +Output the header of the page. This includes: + - The HTML header + - The H1/H3 stuff which includes the directory. + + startpage($r, $uame, $udom, $thisdisfn); + $r - The apache request object. + $uname - User name. + $udom - Domain name the user is logged in under. + $thisdisfn - Displayable version of the filename. + +=item getTitleString($fullname) + + Get the title string or "[untitled]" if the file has no title metadata: + Without the latter substitution, it's impossible to examine metadata for + untitled resources. Resources may be legitimately untitled, to prevent + searches from locating them. + + $str = getTitleString($fullname); + $fullname - Fully qualified filename to check. + +=item putdirectory(r, base, here, dirname, modtime) + + Put out a directory table row: + + putdirectory($r, $base, $here, $dirname, $modtime) + $r - Apache request object. + $reqfile - File in request. + $here - Where we are in directory tree. + $dirname - Name of directory special file. + $modtime - Encoded modification time. + +=item CategorizeFiles($location, $files) + + Categorize files in the directory. + For each file in a list of files in a file directory, + the file categorized as one of: + - directory + - sequence + - problem + - Other resource. + + For each file the modification date is determined as well. + Returned is a list of sublists: + (directories, sequences, problems, other) + each of the sublists contains entries of the following form (sorted by filename): + (filename, typecode, lastmodtime) + + $list = CategorizeFiles($location, $files) + $location - Directory in which the files live (relative to our execution) + $files - list of files. + +=back + +=cut +