File:
[LON-CAPA] /
loncom /
publisher /
lonpubmenu.pm
Revision
1.7:
download - view:
text,
annotated -
select for diffs
Tue Jun 9 21:23:27 2015 UTC (9 years, 5 months ago) by
damieng
Branches:
MAIN
CVS tags:
version_2_12_X,
version_2_11_X,
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
HEAD
fixed bug 6782, and escaped most localized messages used in Javascript blocks to make sure bugs like that do not happen again
# The LearningOnline Network with CAPA
# Construction Space Buttons for Top Frame
#
# $Id: lonpubmenu.pm,v 1.7 2015/06/09 21:23:27 damieng Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
###
package Apache::lonpubmenu;
use Apache::lonlocal;
use Apache::lonnet;
use Apache::loncommon;
sub handler {
my $r = shift;
my %js_lt=&Apache::lonlocal::texthash(
cnpd => 'Cannot publish directory',
cnrd => 'Cannot retrieve directory',
mcdi => 'Must create new subdirectory inside a directory',
);
&js_escape(\%js_lt);
my %html_lt=&Apache::lonlocal::texthash(
pubr => 'Publish this Resource',
pubd => 'Publish this Directory',
rtrv => 'Retrieve Old Version',
pubs => 'Publish with Subdirectories',
list => 'List Directory',
uplo => 'Upload file',
dele => 'Delete',
edit => 'Edit Metadata',
sela => 'Select Action',
nfil => 'New file',
nhtm => 'New HTML file',
nprb => 'New problem',
npag => 'New assembled page',
nseq => 'New assembled sequence',
ncrf => 'New custom rights file',
nsty => 'New style file',
nlib => 'New library file',
nsub => 'New subdirectory',
renm => 'Rename current file to',
move => 'Move current file to',
copy => 'Copy current file to',
type => 'Type Name Here',
go => 'Go',
prnt => 'Print'
);
&html_escape(\%html_lt);
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['disp']);
my $disp = $env{'form.disp'};
# set defaults for parent directory in case frameloc is unable to determine directory
my $defaultdir = '/priv/'.$env{'user.name'}.'/';
if ($env{'request.role'} =~ m#^ca\./[^/]+/([^/]+)#) {
$defaultdir = '/priv/'.$1.'/';
}
my $js=
<script type="text/javascript">
//<!--
function frameloc() {
if (parent.LONCAPAToBePublished.location.pathname.indexOf("/~")!=-1) {
parent.lastknownpriv=parent.LONCAPAToBePublished.location.pathname;
}
// alert ('We are at '+parent.lastknownpriv);
return unescape(parent.lastknownpriv);
}
function getdfilename() {
var currloc = frameloc();
var currdir;
if (currloc.indexOf("/") != -1) {
var loclength = currloc.length;
var lastslash = currloc.lastIndexOf("/");
if (loclength == lastslash+1) {
return;
}
else {
currdir = currloc.substring(0,lastslash+1);
if (currdir.indexOf("~") != -1) {
currdir = currdir.substring(currdir.indexOf("~")+1,currdir.length);
currdir = "/priv/"+currdir
top.location=currdir
return;
}
}
}
top.location="$defaultdir";
}
function getufilename() {
document.upublisher.filename.value=frameloc();
if (document.upublisher.filename.value.indexOf('/adm/pubdir')!=-1) {
document.upublisher.filename.value=document.dpublisher.filename.value;
}
document.upublisher.submit();
}
function getactionfilename() {
document.fileaction.filename.value=frameloc();
var test=document.fileaction.action.selectedIndex;
if (test == 8) { // trying to create a directory
if (document.fileaction.filename.value.indexOf('/adm/pubdir')!=-1) {
document.fileaction.filename.value=document.dpublisher.filename.value;
}
if ((document.fileaction.filename.value.charAt(
document.fileaction.filename.value.length-1)!='/') &&
(document.fileaction.filename.value.indexOf('/adm/pubdir')==-1)) {
alert('$js_lt{'mcdi'}');
return;
}
}
document.fileaction.submit();
}
function getcurseed() {
if (parent.LONCAPAToBePublished.document.lonhomework
&&
parent.LONCAPAToBePublished.document.lonhomework.rndseed
&&
parent.LONCAPAToBePublished.document.lonhomework.rndseed.value) {
return parent.LONCAPAToBePublished.document.lonhomework.rndseed.value;
}
return 0;
}
function getproblemtype() {
if (parent.LONCAPAToBePublished.document.lonhomework) {
var optionelement;
var valueIndex=0;
for (var optionIndex=0;
optionIndex < parent.LONCAPAToBePublished.document.lonhomework.problemtype.options.length;
optionIndex++)
{
optionElement=parent.LONCAPAToBePublished.document.lonhomework.problemtype.options[optionIndex];
if (optionElement.selected) {
return optionElement.value;
}
}
}
return 0;
}
function getpostdata() {
document.printout.postdata.value=frameloc();
document.printout.curseed.value=getcurseed();
document.printout.problemtype.value=getproblemtype();
document.printout.submit();
}
ENDONE
if ($disp eq 'dir') {
$js .= <<"ENDDIR";
function getdirname() {
document.publishdir.filename.value=frameloc();
pubdir(document.publishdir)
}
function getsubdirname() {
document.publishsubdir.filename.value=frameloc();
pubrecdir(document.publishsubdir)
}
function geteditcat() {
top.location=frameloc()+'default.meta'
}
function pubdir(theform) {
if (confirm('Publish complete directory?')) {
forcepub(theform)
theform.submit();
}
}
function pubrecdir(theform) {
if (confirm('Publish directory and all subdirectories?')) {
forcepub(theform);
theform.submit();
}
}
function forcepub(theform) {
if (confirm('Force publication of unmodified files? - OK=yes; Cancel=No.')) {
theform.forcerepub.value="ON";
}
}
ENDDIR
} else {
$js.=<<"ENDRES";
function getfilename() {
document.publisher.filename.value=frameloc();
if ((document.publisher.filename.value.charAt(
document.publisher.filename.value.length-1)!='/') &&
(document.publisher.filename.value.indexOf('/adm/pubdir')==-1)) {
document.publisher.submit();
} else {
alert('$js_lt{'cnpd'}');
}
}
function getrfilename() {
document.rpublisher.filename.value=frameloc();
if ((document.rpublisher.filename.value.charAt(
document.rpublisher.filename.value.length-1)!='/') &&
(document.rpublisher.filename.value.indexOf('/adm/pubdir')==-1)) {
document.rpublisher.submit();
} else {
alert('$js_lt{'cnrd'}');
}
}
function getdelfilename() {
document.del.filename.value=frameloc();
document.del.submit();
}
ENDRES
}
my $start_page =
&Apache::loncommon::start_page('Publishing Frame',$js,
{'only_body' => 1,});
my $end_page =
&Apache::loncommon::end_page();
$r->print(<<"END");
$start_page
<table border="0" align="center"><tr><th bgcolor="#004400" height="20">
<table border="0" cellspacing="2" cellpadding="2"><tr valign="middle">
<td bgcolor="#ccddaa" align="center">
END
if ($disp eq 'dir') {
$r->print('
<form name="publishdir" action="/adm/publish" target="_parent" method="post">
<input type="hidden" name="filename" value="" />
<input type="hidden" name="forcerepub" value="NO" />
<input type="button" value="'.$html_lt{'pubd'}.'" onclick="getdirname();" />
</form>
');
} else {
$r->print('
<form name="publisher" action="/adm/publish" target="_parent" method="post">
<input type="hidden" name="filename" value="" />
<input type="button" value="'.$html_lt{'pubr'}.'" onclick="getfilename();" />
</form>
');
}
$r->print(<<"ENDTWO");
</form>
</td>
<td bgcolor="#ccddaa" align="center">
<form name="dpublisher" action="/adm/pubdir" target="LONCAPAToBePublished" method="post">
<input type="hidden" name="filename" value="" />
<input type="button" value="$html_lt{'list'}" onclick="getdfilename();" />
</form>
</td>
<td bgcolor="#ccddaa" valign="top" align="center">
<form name="upublisher" action="/adm/upload" target="_parent"
method="post" enctype="multipart/form-data">
<input type="hidden" name="filename" value="" />
<input type="file" name="upfile" size="20" />
<input type="button" value="$html_lt{'uplo'}" onclick="getufilename();" />
</form>
</td>
<td rowspan="2" bgcolor="#ccddaa" align="center">
<form name="printout" target="_parent" action="/adm/printout" method="post" onsubmit="getpostdata();">
<input type="hidden" name="postdata" value="" />
<input type="hidden" name="curseed" value="" />
<input type="hidden" name="problemtype" value="" />
<input type="button" value="$html_lt{'prnt'}" onclick="getpostdata();" />
</form>
</td>
</tr>
<tr valign="middle">
ENDTWO
if ($disp eq 'dir') {
$r->print(<<"ENDDIR");
<td bgcolor="#ccddaa" align="center">
<form name="publishsubdir" action="/adm/publish" target="_parent" method="post">
<input type="hidden" name="filename" value="" />
<input type="hidden" name="forcerepub" value="NO" />
<input type="hidden" name="pubrec" value="1" />
<input type="button" value="$html_lt{'pubs'}" onclick="getsubdirname();" />
</form>
</td>
<td bgcolor="#ccddaa">
<form name="editcat" action="/adm/cfile" target="_parent" method="post">
<input type="hidden" name="filename" value="" />
<input type="button" value="$html_lt{'edit'}" onclick="geteditcat();" />
</form>
</td>
ENDDIR
} else {
$r->print(<<"ENDFILE");
<td bgcolor="#ccddaa" align="center">
<form name="rpublisher" action="/adm/retrieve" target="_parent" method="post">
<input type="hidden" name="filename" value="" />
<input type="button" value="$html_lt{'rtrv'}" onclick="getrfilename();" />
</form>
</td>
<td bgcolor="#ccddaa">
<form name="del" action="/adm/cfile" target="_parent" method="post">
<input type="hidden" name="filename" value="" />
<input type="hidden" name="action" value="delete" />
<input type="button" value="$html_lt{'dele'}" onclick="getdelfilename();" />
</form>
</td>
ENDFILE
}
$r->print(<<"ENDOPTIONS");
<td bgcolor="#ccddaa" align="center">
<form name="fileaction" action="/adm/cfile" target="_parent" method="post" onsubmit="getactionfilename();">
<nobr>
<input type="hidden" name="filename" value="" />
<select name="action">
<option value="Select Action">$html_lt{'sela'}</option>
<option value="newfile">$html_lt{'nfil'}:</option>
<option value="newhtmlfile">$html_lt{'nhtm'}:</option>
<option value="newproblemfile">$html_lt{'nprb'}:</option>
<option value="newpagefile">$html_lt{'npag'}:</option>
<option value="newsequencefile">$html_lt{'nseq'}:</option>
<option value="newrightsfile">$html_lt{'ncrf'}:</option>
<option value="newstyfile">$html_lt{'nsty'}:</option>
<option value="newlibraryfile">$html_lt{'nlib'}:</option>
<option value="newdir">$html_lt{'nsub'}:</option>
ENDOPTIONS
if ($disp ne 'dir') {
$r->print(<<"ENDPROBOPS");
<option value="rename">$html_lt{'renm'}:</option>
<option value="move">$html_lt{'move'}:</option>
<option value="copy">$html_lt{'copy'}:</option>
ENDPROBOPS
}
$r->print(<<"ENDPAGE");
</select> <input type="text" name="newfilename" value="$html_lt{'type'}" onfocus="if (this.value == '$html_lt{'type'}') this.value=''" /> <input type="button" value="$html_lt{'go'}" onclick="getactionfilename();" />
</nobr>
</form>
</td>
</tr>
</table>
</th>
</tr>
</table>
$end_page
ENDPAGE
}
1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>