Annotation of loncom/publisher/lonpubmenu.pm, revision 1.7
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Construction Space Buttons for Top Frame
3: #
1.7 ! damieng 4: # $Id: lonpubmenu.pm,v 1.6 2009/02/26 16:10:49 schafran Exp $
1.5 bisitz 5: #
1.1 raeburn 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/
27: #
28: ###
29:
30: package Apache::lonpubmenu;
31: use Apache::lonlocal;
1.3 albertel 32: use Apache::lonnet;
1.1 raeburn 33: use Apache::loncommon;
34:
35: sub handler {
36: my $r = shift;
1.7 ! damieng 37: my %js_lt=&Apache::lonlocal::texthash(
1.1 raeburn 38: cnpd => 'Cannot publish directory',
39: cnrd => 'Cannot retrieve directory',
40: mcdi => 'Must create new subdirectory inside a directory',
1.7 ! damieng 41: );
! 42: &js_escape(\%js_lt);
! 43: my %html_lt=&Apache::lonlocal::texthash(
1.1 raeburn 44: pubr => 'Publish this Resource',
45: pubd => 'Publish this Directory',
46: rtrv => 'Retrieve Old Version',
47: pubs => 'Publish with Subdirectories',
48: list => 'List Directory',
49: uplo => 'Upload file',
50: dele => 'Delete',
1.6 schafran 51: edit => 'Edit Metadata',
1.1 raeburn 52: sela => 'Select Action',
53: nfil => 'New file',
54: nhtm => 'New HTML file',
55: nprb => 'New problem',
56: npag => 'New assembled page',
57: nseq => 'New assembled sequence',
58: ncrf => 'New custom rights file',
59: nsty => 'New style file',
1.2 www 60: nlib => 'New library file',
1.1 raeburn 61: nsub => 'New subdirectory',
62: renm => 'Rename current file to',
63: move => 'Move current file to',
64: copy => 'Copy current file to',
65: type => 'Type Name Here',
66: go => 'Go',
67: prnt => 'Print'
68: );
1.7 ! damieng 69: &html_escape(\%html_lt);
1.1 raeburn 70: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['disp']);
1.3 albertel 71: my $disp = $env{'form.disp'};
1.1 raeburn 72: # set defaults for parent directory in case frameloc is unable to determine directory
1.3 albertel 73: my $defaultdir = '/priv/'.$env{'user.name'}.'/';
74: if ($env{'request.role'} =~ m#^ca\./[^/]+/([^/]+)#) {
1.1 raeburn 75: $defaultdir = '/priv/'.$1.'/';
76: }
1.4 albertel 77: my $js=
1.1 raeburn 78: <script type="text/javascript">
79: //<!--
80: function frameloc() {
81: if (parent.LONCAPAToBePublished.location.pathname.indexOf("/~")!=-1) {
82: parent.lastknownpriv=parent.LONCAPAToBePublished.location.pathname;
83: }
84: // alert ('We are at '+parent.lastknownpriv);
85: return unescape(parent.lastknownpriv);
86: }
87:
88: function getdfilename() {
89: var currloc = frameloc();
90: var currdir;
91: if (currloc.indexOf("/") != -1) {
92: var loclength = currloc.length;
93: var lastslash = currloc.lastIndexOf("/");
94: if (loclength == lastslash+1) {
95: return;
96: }
97: else {
98: currdir = currloc.substring(0,lastslash+1);
99: if (currdir.indexOf("~") != -1) {
100: currdir = currdir.substring(currdir.indexOf("~")+1,currdir.length);
101: currdir = "/priv/"+currdir
102: top.location=currdir
103: return;
104: }
105: }
106: }
107: top.location="$defaultdir";
108: }
109:
110: function getufilename() {
111: document.upublisher.filename.value=frameloc();
112: if (document.upublisher.filename.value.indexOf('/adm/pubdir')!=-1) {
113: document.upublisher.filename.value=document.dpublisher.filename.value;
114: }
115: document.upublisher.submit();
116: }
117:
118: function getactionfilename() {
119: document.fileaction.filename.value=frameloc();
120: var test=document.fileaction.action.selectedIndex;
121: if (test == 8) { // trying to create a directory
122: if (document.fileaction.filename.value.indexOf('/adm/pubdir')!=-1) {
123: document.fileaction.filename.value=document.dpublisher.filename.value;
124: }
125: if ((document.fileaction.filename.value.charAt(
126: document.fileaction.filename.value.length-1)!='/') &&
127: (document.fileaction.filename.value.indexOf('/adm/pubdir')==-1)) {
1.7 ! damieng 128: alert('$js_lt{'mcdi'}');
1.1 raeburn 129: return;
130: }
131: }
132: document.fileaction.submit();
133: }
134:
135: function getcurseed() {
136: if (parent.LONCAPAToBePublished.document.lonhomework
137: &&
138: parent.LONCAPAToBePublished.document.lonhomework.rndseed
139: &&
140: parent.LONCAPAToBePublished.document.lonhomework.rndseed.value) {
141: return parent.LONCAPAToBePublished.document.lonhomework.rndseed.value;
142: }
143: return 0;
144: }
145:
146: function getproblemtype() {
147: if (parent.LONCAPAToBePublished.document.lonhomework) {
148: var optionelement;
149: var valueIndex=0;
150: for (var optionIndex=0;
151: optionIndex < parent.LONCAPAToBePublished.document.lonhomework.problemtype.options.length;
152: optionIndex++)
153: {
154: optionElement=parent.LONCAPAToBePublished.document.lonhomework.problemtype.options[optionIndex];
155: if (optionElement.selected) {
156: return optionElement.value;
157: }
158: }
159: }
160: return 0;
161: }
162:
163: function getpostdata() {
164: document.printout.postdata.value=frameloc();
165: document.printout.curseed.value=getcurseed();
166: document.printout.problemtype.value=getproblemtype();
167: document.printout.submit();
168: }
169: ENDONE
170:
171: if ($disp eq 'dir') {
1.4 albertel 172: $js .= <<"ENDDIR";
1.1 raeburn 173: function getdirname() {
174: document.publishdir.filename.value=frameloc();
175: pubdir(document.publishdir)
176: }
177:
178: function getsubdirname() {
179: document.publishsubdir.filename.value=frameloc();
180: pubrecdir(document.publishsubdir)
181: }
182:
183: function geteditcat() {
184: top.location=frameloc()+'default.meta'
185: }
186:
187: function pubdir(theform) {
188: if (confirm('Publish complete directory?')) {
189: forcepub(theform)
190: theform.submit();
191: }
192: }
193: function pubrecdir(theform) {
194: if (confirm('Publish directory and all subdirectories?')) {
195: forcepub(theform);
196: theform.submit();
197: }
198: }
199:
200: function forcepub(theform) {
201: if (confirm('Force publication of unmodified files? - OK=yes; Cancel=No.')) {
202: theform.forcerepub.value="ON";
203: }
204: }
205: ENDDIR
206: } else {
1.4 albertel 207: $js.=<<"ENDRES";
1.1 raeburn 208: function getfilename() {
209: document.publisher.filename.value=frameloc();
210: if ((document.publisher.filename.value.charAt(
211: document.publisher.filename.value.length-1)!='/') &&
212: (document.publisher.filename.value.indexOf('/adm/pubdir')==-1)) {
213: document.publisher.submit();
214: } else {
1.7 ! damieng 215: alert('$js_lt{'cnpd'}');
1.1 raeburn 216: }
217: }
218:
219: function getrfilename() {
220: document.rpublisher.filename.value=frameloc();
221: if ((document.rpublisher.filename.value.charAt(
222: document.rpublisher.filename.value.length-1)!='/') &&
223: (document.rpublisher.filename.value.indexOf('/adm/pubdir')==-1)) {
224: document.rpublisher.submit();
225: } else {
1.7 ! damieng 226: alert('$js_lt{'cnrd'}');
1.1 raeburn 227: }
228: }
229:
230: function getdelfilename() {
231: document.del.filename.value=frameloc();
232: document.del.submit();
233: }
234: ENDRES
235: }
1.4 albertel 236: my $start_page =
237: &Apache::loncommon::start_page('Publishing Frame',$js,
238: {'only_body' => 1,});
239: my $end_page =
240: &Apache::loncommon::end_page();
1.1 raeburn 241: $r->print(<<"END");
1.4 albertel 242: $start_page
1.1 raeburn 243: <table border="0" align="center"><tr><th bgcolor="#004400" height="20">
244: <table border="0" cellspacing="2" cellpadding="2"><tr valign="middle">
245: <td bgcolor="#ccddaa" align="center">
246: END
247: if ($disp eq 'dir') {
248: $r->print('
249: <form name="publishdir" action="/adm/publish" target="_parent" method="post">
250: <input type="hidden" name="filename" value="" />
251: <input type="hidden" name="forcerepub" value="NO" />
1.7 ! damieng 252: <input type="button" value="'.$html_lt{'pubd'}.'" onclick="getdirname();" />
1.1 raeburn 253: </form>
254: ');
255: } else {
256: $r->print('
257: <form name="publisher" action="/adm/publish" target="_parent" method="post">
258: <input type="hidden" name="filename" value="" />
1.7 ! damieng 259: <input type="button" value="'.$html_lt{'pubr'}.'" onclick="getfilename();" />
1.1 raeburn 260: </form>
261: ');
262: }
263: $r->print(<<"ENDTWO");
264: </form>
265: </td>
266: <td bgcolor="#ccddaa" align="center">
267: <form name="dpublisher" action="/adm/pubdir" target="LONCAPAToBePublished" method="post">
268: <input type="hidden" name="filename" value="" />
1.7 ! damieng 269: <input type="button" value="$html_lt{'list'}" onclick="getdfilename();" />
1.1 raeburn 270: </form>
271: </td>
272: <td bgcolor="#ccddaa" valign="top" align="center">
273: <form name="upublisher" action="/adm/upload" target="_parent"
274: method="post" enctype="multipart/form-data">
275: <input type="hidden" name="filename" value="" />
276: <input type="file" name="upfile" size="20" />
1.7 ! damieng 277: <input type="button" value="$html_lt{'uplo'}" onclick="getufilename();" />
1.1 raeburn 278: </form>
279: </td>
280: <td rowspan="2" bgcolor="#ccddaa" align="center">
281: <form name="printout" target="_parent" action="/adm/printout" method="post" onsubmit="getpostdata();">
282: <input type="hidden" name="postdata" value="" />
283: <input type="hidden" name="curseed" value="" />
284: <input type="hidden" name="problemtype" value="" />
1.7 ! damieng 285: <input type="button" value="$html_lt{'prnt'}" onclick="getpostdata();" />
1.1 raeburn 286: </form>
287: </td>
288: </tr>
289: <tr valign="middle">
290: ENDTWO
291: if ($disp eq 'dir') {
292: $r->print(<<"ENDDIR");
293: <td bgcolor="#ccddaa" align="center">
294: <form name="publishsubdir" action="/adm/publish" target="_parent" method="post">
295: <input type="hidden" name="filename" value="" />
296: <input type="hidden" name="forcerepub" value="NO" />
297: <input type="hidden" name="pubrec" value="1" />
1.7 ! damieng 298: <input type="button" value="$html_lt{'pubs'}" onclick="getsubdirname();" />
1.1 raeburn 299: </form>
300: </td>
301: <td bgcolor="#ccddaa">
302: <form name="editcat" action="/adm/cfile" target="_parent" method="post">
303: <input type="hidden" name="filename" value="" />
1.7 ! damieng 304: <input type="button" value="$html_lt{'edit'}" onclick="geteditcat();" />
1.1 raeburn 305: </form>
306: </td>
307: ENDDIR
308: } else {
309: $r->print(<<"ENDFILE");
310: <td bgcolor="#ccddaa" align="center">
311: <form name="rpublisher" action="/adm/retrieve" target="_parent" method="post">
312: <input type="hidden" name="filename" value="" />
1.7 ! damieng 313: <input type="button" value="$html_lt{'rtrv'}" onclick="getrfilename();" />
1.1 raeburn 314: </form>
315: </td>
316: <td bgcolor="#ccddaa">
317: <form name="del" action="/adm/cfile" target="_parent" method="post">
318: <input type="hidden" name="filename" value="" />
319: <input type="hidden" name="action" value="delete" />
1.7 ! damieng 320: <input type="button" value="$html_lt{'dele'}" onclick="getdelfilename();" />
1.1 raeburn 321: </form>
322: </td>
323: ENDFILE
324: }
325: $r->print(<<"ENDOPTIONS");
326: <td bgcolor="#ccddaa" align="center">
327: <form name="fileaction" action="/adm/cfile" target="_parent" method="post" onsubmit="getactionfilename();">
328: <nobr>
329: <input type="hidden" name="filename" value="" />
330: <select name="action">
1.7 ! damieng 331: <option value="Select Action">$html_lt{'sela'}</option>
! 332: <option value="newfile">$html_lt{'nfil'}:</option>
! 333: <option value="newhtmlfile">$html_lt{'nhtm'}:</option>
! 334: <option value="newproblemfile">$html_lt{'nprb'}:</option>
! 335: <option value="newpagefile">$html_lt{'npag'}:</option>
! 336: <option value="newsequencefile">$html_lt{'nseq'}:</option>
! 337: <option value="newrightsfile">$html_lt{'ncrf'}:</option>
! 338: <option value="newstyfile">$html_lt{'nsty'}:</option>
! 339: <option value="newlibraryfile">$html_lt{'nlib'}:</option>
! 340: <option value="newdir">$html_lt{'nsub'}:</option>
1.1 raeburn 341: ENDOPTIONS
342: if ($disp ne 'dir') {
343: $r->print(<<"ENDPROBOPS");
1.7 ! damieng 344: <option value="rename">$html_lt{'renm'}:</option>
! 345: <option value="move">$html_lt{'move'}:</option>
! 346: <option value="copy">$html_lt{'copy'}:</option>
1.1 raeburn 347: ENDPROBOPS
348: }
349: $r->print(<<"ENDPAGE");
1.7 ! damieng 350: </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();" />
1.1 raeburn 351: </nobr>
352: </form>
353: </td>
354: </tr>
355: </table>
356: </th>
357: </tr>
358: </table>
1.4 albertel 359: $end_page
1.1 raeburn 360: ENDPAGE
361: }
362:
363: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>