File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.541:
download - view:
text,
annotated -
select for diffs
Tue Apr 2 00:07:08 2013 UTC (11 years, 4 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 4900.
- alert pop-up if "Paste selected" or "Clear selected" buttons pressed
and no items selected in clipboard.
- display error messages if read or store of map fails during paste
from clipboard.
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.541 2013/04/02 00:07:08 raeburn Exp $
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/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
36: use Apache::lonhtmlcommon;
37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
42: use Apache::lonnavdisplay();
43: use Apache::lonextresedit();
44: use HTML::Entities;
45: use HTML::TokeParser;
46: use GDBM_File;
47: use Apache::lonlocal;
48: use Cwd;
49: use LONCAPA qw(:DEFAULT :match);
50:
51: my $iconpath;
52:
53: my %hash;
54:
55: my $hashtied;
56: my %alreadyseen=();
57:
58: my $hadchanges;
59:
60:
61: my %help=();
62:
63:
64: sub mapread {
65: my ($coursenum,$coursedom,$map)=@_;
66: return
67: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
68: $map);
69: }
70:
71: sub storemap {
72: my ($coursenum,$coursedom,$map,$contentchg)=@_;
73: my $report;
74: if (($contentchg) && ($map =~ /^default/)) {
75: $report = 1;
76: }
77: my ($outtext,$errtext)=
78: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
79: $map,1,$report);
80: if ($errtext) { return ($errtext,2); }
81:
82: $hadchanges=1;
83: return ($errtext,0);
84: }
85:
86:
87:
88: sub authorhosts {
89: my %outhash=();
90: my $home=0;
91: my $other=0;
92: foreach my $key (keys(%env)) {
93: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
94: my $role=$1;
95: my $realm=$2;
96: my ($start,$end)=split(/\./,$env{$key});
97: if (($start) && ($start>time)) { next; }
98: if (($end) && (time>$end)) { next; }
99: my ($ca,$cd);
100: if ($1 eq 'au') {
101: $ca=$env{'user.name'};
102: $cd=$env{'user.domain'};
103: } else {
104: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
105: }
106: my $allowed=0;
107: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
108: my @ids=&Apache::lonnet::current_machine_ids();
109: foreach my $id (@ids) {
110: if ($id eq $myhome) {
111: $allowed=1;
112: last;
113: }
114: }
115: if ($allowed) {
116: $home++;
117: $outhash{'home_'.$ca.':'.$cd}=1;
118: } else {
119: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
120: $other++;
121: }
122: }
123: }
124: return ($home,$other,%outhash);
125: }
126:
127:
128: sub clean {
129: my ($title)=@_;
130: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
131: return $title;
132: }
133:
134:
135:
136: sub dumpcourse {
137: my ($r) = @_;
138: my $crstype = &Apache::loncommon::course_type();
139: $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Content to Authoring Space')."\n".
140: &Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' Content to Authoring Space')."\n");
141: $r->print(&startContentScreen('tools'));
142: my ($home,$other,%outhash)=&authorhosts();
143: unless ($home) {
144: $r->print(&endContentScreen());
145: return '';
146: }
147: my $origcrsid=$env{'request.course.id'};
148: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
149: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
150: # Do the dumping
151: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
152: $r->print(&endContentScreen());
153: return '';
154: }
155: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
156: $r->print('<h3>'.&mt('Copying Files').'</h3>');
157: my $title=$env{'form.authorfolder'};
158: $title=&clean($title);
159: my %replacehash=();
160: foreach my $key (keys(%env)) {
161: if ($key=~/^form\.namefor\_(.+)/) {
162: $replacehash{$1}=$env{$key};
163: }
164: }
165: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
166: $crs=~s/\_/\//g;
167: foreach my $item (keys(%replacehash)) {
168: my $newfilename=$title.'/'.$replacehash{$item};
169: $newfilename=~s/\.(\w+)$//;
170: my $ext=$1;
171: $newfilename=&clean($newfilename);
172: $newfilename.='.'.$ext;
173: my @dirs=split(/\//,$newfilename);
174: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
175: my $makepath=$path;
176: my $fail=0;
177: for (my $i=0;$i<$#dirs;$i++) {
178: $makepath.='/'.$dirs[$i];
179: unless (-e $makepath) {
180: unless(mkdir($makepath,0777)) { $fail=1; }
181: }
182: }
183: $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
184: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
185: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
186: print $fh &Apache::lonclonecourse::rewritefile(
187: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
188: (%replacehash,$crs => '')
189: );
190: } else {
191: print $fh
192: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
193: }
194: $fh->close();
195: } else {
196: $fail=1;
197: }
198: if ($fail) {
199: $r->print('<span class="LC_error">'.&mt('fail').'</span>');
200: } else {
201: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
202: }
203: }
204: } else {
205: $r->print(&mt('Searching ...').'<br />');
206: $r->rflush();
207: # Input form
208: $r->print('<form name="dumpdoc" action="" method="post">'."\n");
209: unless ($home==1) {
210: $r->print('<div class="LC_left_float">'.
211: '<fieldset><legend>'.
212: &mt('Select the Authoring Space').
213: '</legend><select name="authorspace">');
214: }
215: foreach my $key (sort(keys(%outhash))) {
216: if ($key=~/^home_(.+)$/) {
217: if ($home==1) {
218: $r->print(
219: '<input type="hidden" name="authorspace" value="'.$1.'" />');
220: } else {
221: $r->print('<option value="'.$1.'">'.$1.' - '.
222: &Apache::loncommon::plainname(split(/\:/,$1)).'</option>');
223: }
224: }
225: }
226: unless ($home==1) {
227: $r->print('</select></fieldset></div>'."\n");
228: }
229: my $title=$origcrsdata{'description'};
230: $title=~s/[\/\s]+/\_/gs;
231: $title=&clean($title);
232: $r->print('<div class="LC_left_float">'.
233: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
234: '<input type="text" size="50" name="authorfolder" value="'.
235: $title.'" />'.
236: '</fieldset></div><br clear="all" />'."\n");
237: &tiehash();
238: $r->print('<h4>'.&mt('Filenames in Authoring Space').'</h4>'
239: .&Apache::loncommon::start_data_table()
240: .&Apache::loncommon::start_data_table_header_row()
241: .'<th>'.&mt('Internal Filename').'</th>'
242: .'<th>'.&mt('Title').'</th>'
243: .'<th>'.&mt('Save as ...').'</th>'
244: .&Apache::loncommon::end_data_table_header_row());
245: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
246: $r->print(&Apache::loncommon::start_data_table_row()
247: .'<td>'.$file.'</td>');
248: my ($ext)=($file=~/\.(\w+)$/);
249: my $title=$hash{'title_'.$hash{
250: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
251: $r->print('<td>'.($title?$title:' ').'</td>');
252: if (!$title) {
253: $title=$file;
254: } else {
255: $title=~s|/|_|g;
256: }
257: $title=~s/\.(\w+)$//;
258: $title=&clean($title);
259: $title.='.'.$ext;
260: $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
261: .&Apache::loncommon::end_data_table_row());
262: }
263: $r->print(&Apache::loncommon::end_data_table());
264: &untiehash();
265: $r->print(
266: '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype Content").'" /></p></form>');
267: }
268: $r->print(&endContentScreen());
269: }
270:
271: sub group_import {
272: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
273: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
274: %removeparam,$importuploaded,$fixuperrors);
275: $allmaps = {};
276: while (@files) {
277: my ($name, $url, $residx) = @{ shift(@files) };
278: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
279: && ($caller eq 'londocs')
280: && (!&Apache::lonnet::stat_file($url))) {
281:
282: my $errtext = '';
283: my $fatal = 0;
284: my $newmapstr = '<map>'."\n".
285: '<resource id="1" src="" type="start"></resource>'."\n".
286: '<link from="1" to="2" index="1"></link>'."\n".
287: '<resource id="2" src="" type="finish"></resource>'."\n".
288: '</map>';
289: $env{'form.output'}=$newmapstr;
290: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
291: 'output',$1.$2);
292: if ($result !~ m{^/uploaded/}) {
293: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
294: $fatal = 2;
295: }
296: if ($fatal) {
297: return ($errtext,$fatal);
298: }
299: }
300: if ($url) {
301: if (($caller eq 'londocs') &&
302: ($folder =~ /^default/)) {
303: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
304: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
305: my $cid = $coursedom.'_'.$coursenum;
306: $allmaps =
307: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
308: $chome,$cid);
309: $donechk = 1;
310: }
311: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
312: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
313: \%addedmaps,\%hierarchy,\%titles,$allmaps);
314: $importuploaded = 1;
315: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
316: next if ($allmaps->{$url});
317: }
318: }
319: if (!$residx
320: || defined($LONCAPA::map::zombies[$residx])) {
321: $residx = &LONCAPA::map::getresidx($url,$residx);
322: push(@LONCAPA::map::order, $residx);
323: }
324: my $ext = 'false';
325: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
326: $name = &LONCAPA::map::qtunescape($name);
327: if ($name eq '') {
328: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
329: }
330: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
331: my $filepath = $1;
332: my $fname = $name;
333: if ($fname =~ /^\W+$/) {
334: $fname = 'web';
335: } else {
336: $fname =~ s/\W/_/g;
337: }
338: if (length($fname > 15)) {
339: $fname = substr($fname,0,14);
340: }
341: my $initialtext = &mt('Replace with your own content.');
342: my $newhtml = <<END;
343: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
344: <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
345: <head>
346: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
347: <title>$name</title>
348: </head>
349: <body bgcolor="#ffffff">
350: $initialtext
351: </body>
352: </html>
353: END
354: $env{'form.output'}=$newhtml;
355: my $result =
356: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
357: 'output',
358: "$filepath/$residx/$fname.html");
359: if ($result =~ m{^/uploaded/}) {
360: $url = $result;
361: if ($filepath =~ /^supplemental/) {
362: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
363: $env{'user.domain'}.'___&&&___'.$name;
364: }
365: } else {
366: return (&mt('Failed to save new web page.'),1);
367: }
368: }
369: $url = &LONCAPA::map::qtunescape($url);
370: $LONCAPA::map::resources[$residx] =
371: join(':', ($name, $url, $ext, 'normal', 'res'));
372: }
373: }
374: if ($importuploaded) {
375: my %import_errors;
376: my %updated = (
377: removefrommap => \%removefrommap,
378: removeparam => \%removeparam,
379: );
380: my ($result,$msgsarray,$lockerror) =
381: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
382: if (keys(%import_errors) > 0) {
383: $fixuperrors =
384: '<p span class="LC_warning">'."\n".
385: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
386: '<ul>'."\n";
387: foreach my $key (sort(keys(%import_errors))) {
388: $fixuperrors .= '<li>'.$key.'</li>'."\n";
389: }
390: $fixuperrors .= '</ul></p>'."\n";
391: }
392: if (ref($msgsarray) eq 'ARRAY') {
393: if (@{$msgsarray} > 0) {
394: $fixuperrors .= '<p class="LC_info">'.
395: join('<br />',@{$msgsarray}).
396: '</p>';
397: }
398: }
399: if ($lockerror) {
400: $fixuperrors .= '<p class="LC_error">'.
401: $lockerror.
402: '</p>';
403: }
404: }
405: my ($errtext,$fatal) =
406: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
407: return ($errtext,$fatal,$fixuperrors);
408: }
409:
410: sub log_docs {
411: return &Apache::lonnet::write_log('course','docslog',@_);
412: }
413:
414: {
415: my @oldresources=();
416: my @oldorder=();
417: my $parmidx;
418: my %parmaction=();
419: my %parmvalue=();
420: my $changedflag;
421:
422: sub snapshotbefore {
423: @oldresources=@LONCAPA::map::resources;
424: @oldorder=@LONCAPA::map::order;
425: $parmidx=undef;
426: %parmaction=();
427: %parmvalue=();
428: $changedflag=0;
429: }
430:
431: sub remember_parms {
432: my ($idx,$parameter,$action,$value)=@_;
433: $parmidx=$idx;
434: $parmaction{$parameter}=$action;
435: $parmvalue{$parameter}=$value;
436: $changedflag=1;
437: }
438:
439: sub log_differences {
440: my ($plain)=@_;
441: my %storehash=('folder' => $plain,
442: 'currentfolder' => $env{'form.folder'});
443: if ($parmidx) {
444: $storehash{'parameter_res'}=$oldresources[$parmidx];
445: foreach my $parm (keys(%parmaction)) {
446: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
447: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
448: }
449: }
450: my $maxidx=$#oldresources;
451: if ($#LONCAPA::map::resources>$#oldresources) {
452: $maxidx=$#LONCAPA::map::resources;
453: }
454: for (my $idx=0; $idx<=$maxidx; $idx++) {
455: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
456: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
457: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
458: $changedflag=1;
459: }
460: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
461: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
462: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
463: $changedflag=1;
464: }
465: }
466: $storehash{'maxidx'}=$maxidx;
467: if ($changedflag) { &log_docs(\%storehash); }
468: }
469: }
470:
471: sub docs_change_log {
472: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_;
473: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
474: my $js = '<script type="text/javascript">'."\n".
475: '// <![CDATA['."\n".
476: &Apache::loncommon::display_filter_js('docslog')."\n".
477: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag)."\n".
478: &history_tab_js()."\n".
479: &Apache::lonratedt::editscript('simple')."\n".
480: '// ]]>'."\n".
481: '</script>'."\n";
482: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
483: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
484: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
485: my %orderhash;
486: my $container='sequence';
487: my $pathitem;
488: if ($env{'form.folderpath'} =~ /\:1$/) {
489: $container='page';
490: }
491: my $folderpath=$env{'form.folderpath'};
492: if ($folderpath eq '') {
493: $folderpath = 'default&'.&escape(&mt('Main '.$crstype.' Content').':::::');
494: }
495: $pathitem = '<input type="hidden" name="folderpath" value="'.
496: &HTML::Entities::encode($folderpath,'<>&"').'" />';
497: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
498: my $jumpto = $readfile;
499: $jumpto =~ s{^/}{};
500: my $tid = 1;
501: if ($supplementalflag) {
502: $tid = 2;
503: }
504: my ($breadcrumbtrail) =
505: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
506: $r->print($breadcrumbtrail.
507: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
508: $readfile));
509: my %docslog=&Apache::lonnet::dump('nohist_docslog',
510: $env{'course.'.$env{'request.course.id'}.'.domain'},
511: $env{'course.'.$env{'request.course.id'}.'.num'});
512:
513: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
514:
515: my %saveable_parameters = ('show' => 'scalar',);
516: &Apache::loncommon::store_course_settings('docs_log',
517: \%saveable_parameters);
518: &Apache::loncommon::restore_course_settings('docs_log',
519: \%saveable_parameters);
520: if (!$env{'form.show'}) { $env{'form.show'}=10; }
521: # FIXME: internationalization seems wrong here
522: my %lt=('hiddenresource' => 'Resources hidden',
523: 'encrypturl' => 'URL hidden',
524: 'randompick' => 'Randomly pick',
525: 'randomorder' => 'Randomly ordered',
526: 'set' => 'set to',
527: 'del' => 'deleted');
528: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
529: $pathitem."\n".
530: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
531: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
532: $r->print('<div class="LC_left_float">'.
533: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
534: &makedocslogform($filter,1).
535: '</fieldset></div><br clear="all" />');
536: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
537: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
538: &mt('After').'</th>'.
539: &Apache::loncommon::end_data_table_header_row());
540: my $shown=0;
541: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
542: if ($env{'form.displayfilter'} eq 'currentfolder') {
543: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
544: }
545: my @changes=keys(%{$docslog{$id}{'logentry'}});
546: if ($env{'form.displayfilter'} eq 'containing') {
547: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
548: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
549: foreach my $key (@changes) {
550: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
551: }
552: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
553: }
554: my $count = 0;
555: my $time =
556: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
557: my $plainname =
558: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
559: $docslog{$id}{'exe_udom'});
560: my $about_me_link =
561: &Apache::loncommon::aboutmewrapper($plainname,
562: $docslog{$id}{'exe_uname'},
563: $docslog{$id}{'exe_udom'});
564: my $send_msg_link='';
565: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
566: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
567: $send_msg_link ='<br />'.
568: &Apache::loncommon::messagewrapper(&mt('Send message'),
569: $docslog{$id}{'exe_uname'},
570: $docslog{$id}{'exe_udom'});
571: }
572: $r->print(&Apache::loncommon::start_data_table_row());
573: $r->print('<td>'.$time.'</td>
574: <td>'.$about_me_link.
575: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
576: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
577: $send_msg_link.'</td><td>'.
578: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
579: my $is_supp = 0;
580: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
581: $is_supp = 1;
582: }
583: # Before
584: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
585: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
586: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
587: if ($oldname ne $newname) {
588: my $shown = &LONCAPA::map::qtescape($oldname);
589: if ($is_supp) {
590: $shown = &Apache::loncommon::parse_supplemental_title($shown);
591: }
592: $r->print($shown);
593: }
594: }
595: $r->print('<ul>');
596: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
597: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
598: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
599: if ($is_supp) {
600: $shown = &Apache::loncommon::parse_supplemental_title($shown);
601: }
602: $r->print('<li>'.$shown.'</li>');
603: }
604: }
605: $r->print('</ul>');
606: # After
607: $r->print('</td><td>');
608:
609: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
610: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
611: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
612: if ($oldname ne '' && $oldname ne $newname) {
613: my $shown = &LONCAPA::map::qtescape($newname);
614: if ($is_supp) {
615: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
616: }
617: $r->print($shown);
618: }
619: }
620: $r->print('<ul>');
621: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
622: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
623: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
624: if ($is_supp) {
625: $shown = &Apache::loncommon::parse_supplemental_title($shown);
626: }
627: $r->print('<li>'.$shown.'</li>');
628: }
629: }
630: $r->print('</ul>');
631: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
632: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
633: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
634: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
635: # FIXME: internationalization seems wrong here
636: $r->print('<li>'.
637: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
638: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
639: .'</li>');
640: }
641: }
642: $r->print('</ul>');
643: }
644: # End
645: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
646: $shown++;
647: if (!($env{'form.show'} eq &mt('all')
648: || $shown<=$env{'form.show'})) { last; }
649: }
650: $r->print(&Apache::loncommon::end_data_table()."\n".
651: &makesimpleeditform($pathitem)."\n".
652: '</div></div>');
653: $r->print(&endContentScreen());
654: }
655:
656: sub update_paste_buffer {
657: my ($coursenum,$coursedom,$folder) = @_;
658: my (@possibles,%removals,%cuts);
659: if ($env{'form.multiremove'}) {
660: $env{'form.multiremove'} =~ s/,$//;
661: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
662: }
663: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
664: if ($env{'form.multicut'}) {
665: $env{'form.multicut'} =~ s/,$//;
666: foreach my $item (split(/,/,$env{'form.multicut'})) {
667: unless ($removals{$item}) {
668: $cuts{$item} = 1;
669: push(@possibles,$item.':cut');
670: }
671: }
672: }
673: if ($env{'form.multicopy'}) {
674: $env{'form.multicopy'} =~ s/,$//;
675: foreach my $item (split(/,/,$env{'form.multicopy'})) {
676: unless ($removals{$item} || $cuts{$item}) {
677: push(@possibles,$item.':copy');
678: }
679: }
680: }
681: } elsif ($env{'form.markcopy'}) {
682: @possibles = split(/,/,$env{'form.markcopy'});
683: }
684:
685: return if (@possibles == 0);
686: return if (!defined($env{'form.copyfolder'}));
687:
688: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
689: $env{'form.copyfolder'});
690: return if ($fatal);
691:
692: my %curr_groups = &Apache::longroup::coursegroups();
693:
694: # Retrieve current paste buffer suffixes.
695: my @currpaste = split(/,/,$env{'docs.markedcopies'});
696: my (%pasteurls,@newpaste);
697:
698: # Construct identifiers for current contents of user's paste buffer
699: if (@currpaste) {
700: foreach my $suffix (@currpaste) {
701: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
702: my $url = $env{'docs.markedcopy_url_'.$suffix};
703: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
704: ($url ne '')) {
705: $pasteurls{$cid.'_'.$url};
706: }
707: }
708: }
709:
710: # Mark items for copying (skip any items already in user's paste buffer)
711: my %addtoenv;
712:
713: foreach my $item (@possibles) {
714: my ($orderidx,$cmd) = split(/:/,$item);
715: next if ($orderidx =~ /\D/);
716: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
717: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
718: my %denied = &action_restrictions($coursenum,$coursedom,
719: &LONCAPA::map::qtescape($url),
720: $env{'form.folderpath'},\%curr_groups);
721: next if ($denied{'copy'});
722: $url=~s{http(:|:)//https(:|:)//}{https$2//};
723: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
724: my ($suffix,$errortxt,$locknotfreed) =
725: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
726: push(@newpaste,$suffix);
727: if ($locknotfreed) {
728: return $locknotfreed;
729: last;
730: }
731: if (&is_supplemental_title($title)) {
732: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
733: ($title) = &Apache::loncommon::parse_supplemental_title($title);
734: }
735:
736: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
737: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
738: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
739: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
740:
741: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
742: my $prefix = $1;
743: my $subdir =$2;
744: if ($subdir eq '') {
745: $subdir = $prefix;
746: }
747: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
748: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
749: \%hierarchy,\%titles,\%allmaps);
750: if (ref($hierarchy{$url}) eq 'HASH') {
751: my ($nested,$nestednames);
752: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
753: $nested =~ s/\&$//;
754: $nestednames =~ s/\Q___&&&___\E$//;
755: if ($nested ne '') {
756: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
757: }
758: if ($nestednames ne '') {
759: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
760: }
761: }
762: }
763: }
764: if (@newpaste) {
765: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
766: }
767: &Apache::lonnet::appenv(\%addtoenv);
768: delete($env{'form.markcopy'});
769: }
770:
771: sub recurse_uploaded_maps {
772: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
773: if (ref($hierarchy->{$url}) eq 'HASH') {
774: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
775: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
776: my (@uploaded,@names,%shorter);
777: for (my $i=0; $i<@maps; $i++) {
778: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
779: if ($inner ne '') {
780: push(@uploaded,$inner);
781: push(@names,&escape($titles[$i]));
782: $shorter{$maps[$i]} = $inner;
783: }
784: }
785: $$nestref .= "$dir:".join(',',@uploaded).'&';
786: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
787: foreach my $map (@maps) {
788: if ($shorter{$map} ne '') {
789: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
790: }
791: }
792: }
793: return;
794: }
795:
796: sub print_paste_buffer {
797: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
798: return if (!defined($env{'docs.markedcopies'}));
799:
800: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
801: return if ($env{'docs.markedcopies'} eq '');
802: }
803:
804: my @currpaste = split(/,/,$env{'docs.markedcopies'});
805: my ($pasteitems,@pasteable);
806:
807: # Construct identifiers for current contents of user's paste buffer
808: foreach my $suffix (@currpaste) {
809: next if ($suffix =~ /\D/);
810: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
811: my $url = $env{'docs.markedcopy_url_'.$suffix};
812: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
813: ($url ne '')) {
814: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
815: $canpaste,$nopaste,$othercrs,$areachange);
816: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
817: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
818: $is_external = 1;
819: }
820: if ($folder =~ /^supplemental/) {
821: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
822: unless ($canpaste) {
823: $nopaste = &mt('Paste into Supplemental Content unavailable.');
824: }
825: } else {
826: $canpaste = 1;
827: }
828: if ($canpaste) {
829: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
830: my $srcdom = $1;
831: my $srcnum = $2;
832: my $rem = $3;
833: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
834: $othercourse = 1;
835: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
836: if ($canpaste) {
837: $othercrs = '<br />'.&mt('(from another course)');
838: }
839: } else {
840: $canpaste = 0;
841: $nopaste = &mt('Paste from another course unavailable.');
842: }
843: }
844: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
845: my $prefix = $1;
846: $parent = $2;
847: if ($folder !~ /^\Q$prefix\E/) {
848: $areachange = 1;
849: }
850: $is_uploaded_map = 1;
851: }
852: }
853: }
854: if ($canpaste) {
855: push(@pasteable,$suffix);
856: }
857: my $buffer;
858: if ($is_external) {
859: $buffer = &mt('External Resource').': '.
860: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
861: &LONCAPA::map::qtescape($url).')';
862: } else {
863: my $icon = &Apache::loncommon::icon($extension);
864: if ($extension eq 'sequence' &&
865: $url =~ m{/default_\d+\.sequence$}x) {
866: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
867: $icon .= '/navmap.folder.closed.gif';
868: }
869: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
870: ': '.
871: &Apache::loncommon::parse_supplemental_title(
872: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}));
873: }
874: $pasteitems .= '<div class="LC_left_float">';
875: my ($options,$onclick);
876: if (($canpaste) && (!$areachange) && (!$othercourse) &&
877: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
878: if (($is_uploaded_map) ||
879: ($url =~ /(bulletinboard|smppg)$/) ||
880: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
881: $options = &paste_options($suffix,$is_uploaded_map,$parent);
882: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
883: }
884: }
885: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
886: if ($nopaste) {
887: $pasteitems .= $nopaste;
888: } else {
889: if ($othercrs) {
890: $pasteitems .= $othercrs;
891: }
892: if ($options) {
893: $pasteitems .= $options;
894: }
895: }
896: $pasteitems .= '</div>';
897: }
898: }
899: if ($pasteitems eq '') {
900: &Apache::lonnet::delenv('docs.markedcopies');
901: }
902: my ($pasteform,$form_start,$buttons,$form_end);
903: if ($pasteitems) {
904: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
905: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
906: if (@pasteable) {
907: $buttons = '<input type="submit" name="pastemarked" value="'.&mt('Paste selected').'" />'.(' 'x2);
908: }
909: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Clear selected').'" />'.
910: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
911: $form_end = '</form>';
912: } else {
913: $pasteitems = &mt('Clipboard is empty');
914: }
915: $r->print($form_start
916: .'<fieldset>'
917: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
918: .$pasteitems
919: .'</fieldset>'
920: .$form_end);
921: }
922:
923: sub paste_options {
924: my ($suffix,$is_uploaded_map,$parent) = @_;
925: my ($copytext,$movetext);
926: if ($is_uploaded_map) {
927: $copytext = &mt('Copy to new folder');
928: $movetext = &mt('Move old');
929: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
930: $copytext = &mt('Copy to new board');
931: $movetext = &mt('Move (not posts)');
932: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
933: $copytext = &mt('Copy to new page');
934: $movetext = &mt('Move');
935: } else {
936: $copytext = &mt('Copy to new file');
937: $movetext = &mt('Move');
938: }
939: my $output = '<br />'.
940: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
941: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
942: '<label>'.
943: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
944: $copytext.'</label></span>'.(' 'x2).' '.
945: '<span class="LC_nobreak"><label>'.
946: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
947: $movetext.'</label></span>';
948: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
949: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
950: '</legend><table border="0">';
951: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
952: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
953: my $lastdir = $parent;
954: my %depths = (
955: $lastdir => 0,
956: );
957: my (%display,%deps);
958: for (my $i=0; $i<@pastemaps; $i++) {
959: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
960: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
961: my @subfolders = split(/,/,$subfolderstr);
962: $deps{$lastdir} = \@subfolders;
963: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
964: my $depth = $depths{$lastdir} + 1;
965: my $offset = int($depth * 4);
966: my $indent = (' ' x $offset);
967: for (my $j=0; $j<@subfolders; $j++) {
968: $depths{$subfolders[$j]} = $depth;
969: $display{$subfolders[$j]} =
970: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
971: '<td><label>'.
972: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
973: '<label>'.
974: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
975: &mt('Move old').'</label>'.
976: '</td></tr>';
977: }
978: }
979: &recurse_print(\$output,$parent,\%deps,\%display);
980: $output .= '</table></fieldset>';
981: }
982: $output .= '</div>';
983: return $output;
984: }
985:
986: sub recurse_print {
987: my ($outputref,$dir,$deps,$display) = @_;
988: $$outputref .= $display->{$dir}."\n";
989: if (ref($deps->{$dir}) eq 'ARRAY') {
990: foreach my $subdir (@{$deps->{$dir}}) {
991: &recurse_print($outputref,$subdir,$deps,$display);
992: }
993: }
994: }
995:
996: sub supp_pasteable {
997: my ($url) = @_;
998: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
999: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1000: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1001: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1002: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
1003: return 1;
1004: }
1005: return;
1006: }
1007:
1008: sub paste_popup_js {
1009: my %lt = &Apache::lonlocal::texthash(
1010: show => 'Show Options',
1011: hide => 'Hide Options',
1012: none => 'No items selected from clipboard.',
1013: );
1014: return <<"END";
1015:
1016: function showPasteOptions(suffix) {
1017: document.getElementById('pasteoptions_'+suffix).style.display='block';
1018: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$lt{'hide'}</a>';
1019: return;
1020: }
1021:
1022: function hidePasteOptions(suffix) {
1023: document.getElementById('pasteoptions_'+suffix).style.display='none';
1024: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$lt{'show'}</a>';
1025: return;
1026: }
1027:
1028: function showOptions(caller,suffix) {
1029: if (document.getElementById('pasteoptionstext_'+suffix)) {
1030: if (caller.checked) {
1031: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$lt{'show'}</a>';
1032: } else {
1033: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1034: }
1035: if (document.getElementById('pasteoptions_'+suffix)) {
1036: document.getElementById('pasteoptions_'+suffix).style.display='none';
1037: }
1038: }
1039: return;
1040: }
1041:
1042: function validateClipboard() {
1043: var numchk = 0;
1044: if (document.pasteform.pasting.length > 1) {
1045: for (var i=0; i<document.pasteform.pasting.length; i++) {
1046: if (document.pasteform.pasting[i].checked) {
1047: numchk ++;
1048: }
1049: }
1050: } else {
1051: if (document.pasteform.pasting.type == 'checkbox') {
1052: if (document.pasteform.pasting.checked) {
1053: numchk ++;
1054: }
1055: }
1056: }
1057: if (numchk > 0) {
1058: return true;
1059: } else {
1060: alert("$lt{'none'}");
1061: return false;
1062: }
1063: }
1064:
1065: END
1066:
1067: }
1068:
1069:
1070: sub do_paste_from_buffer {
1071: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1072:
1073: # Array of items in paste buffer
1074: my (@currpaste,%pastebuffer,%allerrors);
1075: @currpaste = split(/,/,$env{'docs.markedcopies'});
1076:
1077: # Early out if paste buffer is empty
1078: if (@currpaste == 0) {
1079: return ();
1080: }
1081: map { $pastebuffer{$_} = 1; } @currpaste;
1082:
1083: # Array of items selected items to paste
1084: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1085:
1086: # Early out if nothing selected to paste
1087: if (@reqpaste == 0) {
1088: return();
1089: }
1090: my @topaste;
1091: foreach my $suffix (@reqpaste) {
1092: next if ($suffix =~ /\D/);
1093: next unless (exists($pastebuffer{$suffix}));
1094: push(@topaste,$suffix);
1095: }
1096:
1097: # Early out if nothing available to paste
1098: if (@topaste == 0) {
1099: return();
1100: }
1101:
1102: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1103: %prefixchg,%srcdom,%srcnum,%marktomove,$save_err,$lockerrors,$allresult,
1104: %msgs);
1105:
1106: foreach my $suffix (@topaste) {
1107: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1108: # Supplemental content may only include certain types of content
1109: # Early out if pasted content is not supported in Supplemental area
1110: if ($folder =~ /^supplemental/) {
1111: unless (&supp_pasteable($url)) {
1112: $notinsupp{$suffix} = 1;
1113: next;
1114: }
1115: }
1116: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1117: my $srcd = $1;
1118: my $srcn = $2;
1119: # When paste buffer was populated using an active role in a different course
1120: # check for mdc privilege in the course from which the resource was pasted
1121: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1122: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1123: $notincrs{$suffix} = 1;
1124: next;
1125: }
1126: }
1127: $srcdom{$suffix} = $srcd;
1128: $srcnum{$suffix} = $srcn;
1129: }
1130:
1131: push(@dopaste,$suffix);
1132: if ($url=~/\.(page|sequence)$/) {
1133: $is_map{$suffix} = 1;
1134: }
1135:
1136: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1137: my $oldprefix = $1;
1138: # When pasting content from Main Content to Supplemental Content and vice versa
1139: # URLs will contain different paths (which depend on whether pasted item is
1140: # a folder/page or a document.
1141: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1142: $prefixchg{$suffix} = 'docstosupp';
1143: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1144: $prefixchg{$suffix} = 'supptodocs';
1145: }
1146:
1147: # If pasting an uploaded map, get list of contained uploaded maps.
1148: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1149: my @nested;
1150: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1151: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1152: my @deps = map { /\d+:([\d,]+$)/ } @items;
1153: foreach my $dep (@deps) {
1154: if ($dep =~ /,/) {
1155: push(@nested,split(/,/,$dep));
1156: } else {
1157: push(@nested,$dep);
1158: }
1159: }
1160: foreach my $item (@nested) {
1161: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1162: push(@{$marktomove{$suffix}},$type.'_'.$item);
1163: }
1164: }
1165: }
1166: }
1167: }
1168:
1169: # Early out if nothing available to paste
1170: if (@dopaste == 0) {
1171: return ();
1172: }
1173:
1174: # Populate message hash and hashes used for main content <=> supplemental content
1175: # changes
1176:
1177: %msgs = &Apache::lonlocal::texthash (
1178: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1179: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1180: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1181: );
1182:
1183: %before = (
1184: docstosupp => {
1185: map => 'default',
1186: doc => 'docs',
1187: },
1188: supptodocs => {
1189: map => 'supplemental',
1190: doc => 'supplemental',
1191: },
1192: );
1193:
1194: %after = (
1195: docstosupp => {
1196: map => 'supplemental',
1197: doc => 'supplemental'
1198: },
1199: supptodocs => {
1200: map => 'default',
1201: doc => 'docs',
1202: },
1203: );
1204:
1205: # Retrieve information about all course maps in main content area
1206:
1207: my $allmaps = {};
1208: if ($folder =~ /^default/) {
1209: $allmaps =
1210: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1211: $env{"course.$env{'request.course.id'}.home"},
1212: $env{'request.course.id'});
1213: }
1214:
1215: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1216:
1217: # Loop over the items to paste
1218: foreach my $suffix (@dopaste) {
1219: # Maps need to be copied first
1220: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1221: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1222: %newurls,%tomove);
1223: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1224: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1225: }
1226: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1227: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1228: my $oldurl = $url;
1229: if ($is_map{$suffix}) {
1230: # If pasting a map, check if map contains other maps
1231: my (%hierarchy,%titles);
1232: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1233: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1234: if ($url=~ m{^/uploaded/}) {
1235: my $newurl;
1236: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1237: ($newurl,my $error) =
1238: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1239: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1240: \$title,$allmaps,\%newurls);
1241: if ($error) {
1242: $allerrors{$suffix} = $error;
1243: next;
1244: }
1245: if ($newurl ne '') {
1246: if ($newurl ne $url) {
1247: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1248: $newsubdir{$url} = $1;
1249: }
1250: $mapchanges{$url} = 1;
1251: }
1252: }
1253: }
1254: if (($srcdom{$suffix} ne $coursedom) ||
1255: ($srcnum{$suffix} ne $coursenum) ||
1256: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1257: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1258: $coursedom,$coursenum,$srcdom{$suffix},
1259: $srcnum{$suffix},$allmaps,\%rewrites,
1260: \%retitles,\%copies,\%dbcopies,
1261: \%zombies,\%params,\%mapmoves,
1262: \%mapchanges,\%tomove,\%newsubdir,
1263: \%newurls)) {
1264: $mapmoves{$url} = 1;
1265: }
1266: $url = $newurl;
1267: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1268: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1269: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1270: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1271: \%zombies,\%params,\%mapmoves,\%mapchanges,
1272: \%tomove,\%newsubdir,\%newurls);
1273: }
1274: } elsif ($url=~m {^/res/}) {
1275: # published map can only exists once, so remove from paste buffer when done
1276: push(@toclear,$suffix);
1277: # if pasting published map (main content area only) check map not already in course
1278: if ($folder =~ /^default/) {
1279: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1280: $duplicate{$suffix} = 1;
1281: next;
1282: }
1283: }
1284: }
1285: }
1286: if ($url=~ m{/(bulletinboard|smppg)$}) {
1287: my $prefix = $1;
1288: #need to copy the db contents to a new one, unless this is a move.
1289: my %info = (
1290: src => $url,
1291: cdom => $coursedom,
1292: cnum => $coursenum,
1293: );
1294: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1295: my (%lockerr,$msg);
1296: my ($newurl,$result,$errtext) =
1297: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1298: if ($result eq 'ok') {
1299: $url = $newurl;
1300: $title=&mt('Copy of').' '.$title;
1301: } else {
1302: if ($prefix eq 'smppg') {
1303: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1304: } elsif ($prefix eq 'bulletinboard') {
1305: $msg = &mt('Paste failed: An error occurred when copying the bulletin board.').' '.$errtext;
1306: }
1307: $results{$suffix} = $result;
1308: $msgerrs{$suffix} = $msg;
1309: $lockerrs{$suffix} = $lockerr{$prefix};
1310: next;
1311: }
1312: if ($lockerr{$prefix}) {
1313: $lockerrs{$suffix} = $lockerr{$prefix};
1314: }
1315: }
1316: }
1317: $title = &LONCAPA::map::qtunescape($title);
1318: my $ext='false';
1319: if ($url=~m{^http(|s)://}) { $ext='true'; }
1320: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1321: if ($folder !~ /^supplemental/) {
1322: (undef,undef,$title) =
1323: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1324: }
1325: } else {
1326: if ($folder=~/^supplemental/) {
1327: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1328: $env{'user.domain'}.'___&&&___'.$title;
1329: }
1330: }
1331:
1332: # For uploaded files (excluding pages/sequences) path in copied file is changed
1333: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1334: # courses.
1335:
1336: unless ($is_map{$suffix}) {
1337: my $newidx;
1338: # Now insert the URL at the bottom
1339: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1340: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1341: my $relpath = $1;
1342: if ($relpath ne '') {
1343: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1344: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1345: my $newprefix = $newloc;
1346: if ($newloc eq 'default') {
1347: $newprefix = 'docs';
1348: }
1349: if ($newdocsdir eq '') {
1350: $newdocsdir = 'default';
1351: }
1352: if (($prefixchg{$suffix}) ||
1353: ($srcdom{$suffix} ne $coursedom) ||
1354: ($srcnum{$suffix} ne $coursenum) ||
1355: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1356: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1357: $url =
1358: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1359: &Apache::lonnet::getfile($oldurl));
1360: if ($url eq '/adm/notfound.html') {
1361: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1362: next;
1363: } else {
1364: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1365: $newsubpath =~ s{/+$}{/};
1366: $docmoves{$oldurl} = $newsubpath;
1367: }
1368: }
1369: }
1370: }
1371: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1372: ':'.$ext.':normal:res';
1373: push(@LONCAPA::map::order,$newidx);
1374: # Store the result
1375: my ($errtext,$fatal) =
1376: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1377: if ($fatal) {
1378: $save_err .= $errtext;
1379: $allresult = 'fail';
1380: }
1381: }
1382:
1383: # Apply any changes to maps, or copy dependencies for uploaded HTML pages
1384: unless ($allresult eq 'fail') {
1385: my %updated = (
1386: rewrites => \%rewrites,
1387: zombies => \%zombies,
1388: removefrommap => \%removefrommap,
1389: removeparam => \%removeparam,
1390: dbcopies => \%dbcopies,
1391: retitles => \%retitles,
1392: );
1393: my %info = (
1394: newsubdir => \%newsubdir,
1395: params => \%params,
1396: );
1397: if ($prefixchg{$suffix}) {
1398: $info{'before'} = $before{$prefixchg{$suffix}};
1399: $info{'after'} = $after{$prefixchg{$suffix}};
1400: }
1401: my %moves = (
1402: copies => \%copies,
1403: docmoves => \%docmoves,
1404: mapmoves => \%mapmoves,
1405: );
1406: (my $result,$msgs{$suffix},my $lockerror) =
1407: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1408: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1409: $url,'paste');
1410: $lockerrors .= $lockerror;
1411: if ($result eq 'ok') {
1412: if ($is_map{$suffix}) {
1413: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1414: $folder.'.'.$container);
1415: if ($fatal) {
1416: $allresult = 'failread';
1417: } else {
1418: if ($#LONCAPA::map::order<1) {
1419: my $idx=&LONCAPA::map::getresidx();
1420: if ($idx<=0) { $idx=1; }
1421: $LONCAPA::map::order[0]=$idx;
1422: $LONCAPA::map::resources[$idx]='';
1423: }
1424: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1425: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1426: ':'.$ext.':normal:res';
1427: push(@LONCAPA::map::order,$newidx);
1428:
1429: # Store the result
1430: my ($errtext,$fatal) =
1431: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1432: if ($fatal) {
1433: $save_err .= $errtext;
1434: $allresult = 'failstore';
1435: }
1436: }
1437: }
1438: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1439: push(@toclear,$suffix);
1440: }
1441: }
1442: }
1443: }
1444: &clear_from_buffer(\@toclear,\@currpaste);
1445: my $msgsarray;
1446: foreach my $suffix (keys(%msgs)) {
1447: if (ref($msgs{$suffix}) eq 'ARRAY') {
1448: $msgsarray .= join(',',@{$msgs{$suffix}});
1449: }
1450: }
1451: return ($allresult,$save_err,$msgsarray,$lockerrors);
1452: }
1453:
1454: sub do_buffer_empty {
1455: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1456: if (@currpaste == 0) {
1457: return &mt('Clipboard is already empty');
1458: }
1459: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1460: if (@toclear == 0) {
1461: return &mt('Nothing selected to clear from clipboard');
1462: }
1463: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1464: if ($numdel) {
1465: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1466: } else {
1467: return &mt('Clipboard unchanged');
1468: }
1469: return;
1470: }
1471:
1472: sub clear_from_buffer {
1473: my ($toclear,$currpaste) = @_;
1474: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1475: my %pastebuffer;
1476: map { $pastebuffer{$_} = 1; } @{$currpaste};
1477: my $numdel = 0;
1478: foreach my $suffix (@{$toclear}) {
1479: next if ($suffix =~ /\D/);
1480: next unless (exists($pastebuffer{$suffix}));
1481: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1482: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1483: delete($pastebuffer{$suffix});
1484: $numdel ++;
1485: }
1486: }
1487: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1488: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1489: return $numdel;
1490: }
1491:
1492: sub get_newmap_url {
1493: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
1494: $titleref,$allmaps,$newurls) = @_;
1495: my $newurl;
1496: if ($url=~ m{^/uploaded/}) {
1497: $$titleref=&mt('Copy of').' '.$$titleref;
1498: }
1499: my $now = time;
1500: my $suffix=$$.int(rand(100)).$now;
1501: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1502: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
1503: my $path = $1;
1504: my $prefix = $2;
1505: my $ancestor = $3;
1506: if (length($ancestor) > 10) {
1507: $ancestor = substr($ancestor,-10,10);
1508: }
1509: my $newid;
1510: if ($prefixchg) {
1511: if ($folder =~ /^supplemental/) {
1512: $prefix =~ s/^default/supplemental/;
1513: } else {
1514: $prefix =~ s/^supplemental/default/;
1515: }
1516: }
1517: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1518: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1519: } else {
1520: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
1521: }
1522: my $counter = 0;
1523: my $is_unique = &uniqueness_check($newurl);
1524: if ($folder =~ /^default/) {
1525: if ($allmaps->{$newurl}) {
1526: $is_unique = 0;
1527: }
1528: }
1529: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
1530: $counter ++;
1531: $suffix ++;
1532: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1533: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1534: } else {
1535: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
1536: }
1537: $is_unique = &uniqueness_check($newurl);
1538: }
1539: if ($is_unique) {
1540: $newurls->{$newurl} = 1;
1541: } else {
1542: if ($url=~/\.page$/) {
1543: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
1544: } else {
1545: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
1546: }
1547: }
1548: }
1549: return ($newurl);
1550: }
1551:
1552: sub dbcopy {
1553: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
1554: my ($url,$result,$errtext);
1555: my $url = $dbref->{'src'};
1556: if (ref($dbref) eq 'HASH') {
1557: if ($url =~ m{/(smppg|bulletinboard)$}) {
1558: my $prefix = $1;
1559: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
1560: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
1561: my $db_name;
1562: my $marker = (split(m{/},$url))[4];
1563: $marker=~s/\D//g;
1564: if ($dbref->{'src'} =~ m{/smppg$}) {
1565: $db_name =
1566: &Apache::lonsimplepage::get_db_name($url,$marker,
1567: $dbref->{'cdom'},
1568: $dbref->{'cnum'});
1569: } else {
1570: $db_name = 'bulletinpage_'.$marker;
1571: }
1572: my ($suffix,$freedlock,$error) =
1573: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
1574: $coursedom,$coursenum,
1575: 'concat');
1576: if (!$suffix) {
1577: if ($prefix eq 'smppg') {
1578: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1579: } else {
1580: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a bulletin board [_1].',$url);
1581: }
1582: if ($error) {
1583: $errtext .= '<br />'.$error;
1584: }
1585: } else {
1586: #need to copy the db contents to a new one.
1587: my %contents=&Apache::lonnet::dump($db_name,
1588: $dbref->{'cdom'},
1589: $dbref->{'cnum'});
1590: if (exists($contents{'uploaded.photourl'})) {
1591: my $photo = $contents{'uploaded.photourl'};
1592: my ($subdir,$fname) =
1593: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1594: my $newphoto;
1595: if ($fname ne '') {
1596: my $content = &Apache::lonnet::getfile($photo);
1597: unless ($content eq '-1') {
1598: $env{'form.'.$suffix.'.photourl'} = $content;
1599: $newphoto =
1600: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
1601: delete($env{'form.'.$suffix.'.photourl'});
1602: }
1603: }
1604: if ($newphoto =~ m{^/uploaded/}) {
1605: $contents{'uploaded.photourl'} = $newphoto;
1606: }
1607: }
1608: $db_name =~ s{_\d*$ }{_$suffix}x;
1609: $result=&Apache::lonnet::put($db_name,\%contents,
1610: $coursedom,$coursenum);
1611: if ($result eq 'ok') {
1612: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
1613: }
1614: }
1615: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1616: $lockerrorsref->{$prefix} =
1617: '<div class="LC_error">'.
1618: &mt('There was a problem removing a lockfile.');
1619: if ($prefix eq 'smppg') {
1620: $lockerrorsref->{$prefix} .=
1621: &mt('This will prevent creation of additional simple pages in this course.');
1622: } else {
1623: $lockerrorsref->{$prefix} .= &mt('This will prevent creation of additional bulletin boards in this course.');
1624: }
1625: $lockerrorsref->{$prefix} .= &mt('Please contact the domain coordinator for your LON-CAPA domain.').'</div>';
1626: }
1627: }
1628: } elsif ($url =~ m{/syllabus$}) {
1629: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
1630: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
1631: if (($dbref->{'cdom'} ne $coursedom) ||
1632: ($dbref->{'cnum'} ne $coursenum)) {
1633: my %contents=&Apache::lonnet::dump('syllabus',
1634: $dbref->{'cdom'},
1635: $dbref->{'cnum'});
1636: $result=&Apache::lonnet::put('syllabus',\%contents,
1637: $coursedom,$coursenum);
1638: }
1639: }
1640: }
1641: }
1642: return ($url,$result,$errtext);
1643: }
1644:
1645: sub uniqueness_check {
1646: my ($newurl) = @_;
1647: my $unique = 1;
1648: foreach my $res (@LONCAPA::map::order) {
1649: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1650: $url=&LONCAPA::map::qtescape($url);
1651: if ($newurl eq $url) {
1652: $unique = 0;
1653: last;
1654: }
1655: }
1656: return $unique;
1657: }
1658:
1659: sub contained_map_check {
1660: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
1661: $allmaps) = @_;
1662: my $content = &Apache::lonnet::getfile($url);
1663: unless ($content eq '-1') {
1664: my $parser = HTML::TokeParser->new(\$content);
1665: $parser->attr_encoded(1);
1666: while (my $token = $parser->get_token) {
1667: next if ($token->[0] ne 'S');
1668: if ($token->[1] eq 'resource') {
1669: next if ($token->[2]->{'type'} eq 'zombie');
1670: my $ressrc = $token->[2]->{'src'};
1671: if ($folder =~ /^supplemental/) {
1672: unless (&supp_pasteable($ressrc)) {
1673: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1674: next;
1675: }
1676: }
1677: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
1678: if ($1 eq 'uploaded') {
1679: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
1680: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1681: } else {
1682: if ($allmaps->{$ressrc}) {
1683: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1684: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
1685: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1686: } else {
1687: $addedmaps->{$ressrc} = [$url];
1688: }
1689: }
1690: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
1691: $addedmaps,$hierarchy,$titles,$allmaps);
1692: }
1693: } elsif ($token->[1] eq 'param') {
1694: if ($folder =~ /^supplemental/) {
1695: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
1696: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
1697: } else {
1698: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1699: }
1700: }
1701: }
1702: }
1703: }
1704: return;
1705: }
1706:
1707: sub url_paste_fixups {
1708: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
1709: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1710: $mapchanges,$tomove,$newsubdir,$newurls) = @_;
1711: my $checktitle;
1712: if (($prefixchg) &&
1713: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1714: $checktitle = 1;
1715: }
1716: my $skip;
1717: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
1718: my $mapid = $1.$2;
1719: if ($tomove->{$mapid}) {
1720: $skip = 1;
1721: }
1722: }
1723: my $file = &Apache::lonnet::getfile($oldurl);
1724: return if ($file eq '-1');
1725: my $parser = HTML::TokeParser->new(\$file);
1726: $parser->attr_encoded(1);
1727: my $changed = 0;
1728: while (my $token = $parser->get_token) {
1729: next if ($token->[0] ne 'S');
1730: if ($token->[1] eq 'resource') {
1731: my $ressrc = $token->[2]->{'src'};
1732: next if ($ressrc eq '');
1733: my $id = $token->[2]->{'id'};
1734: my $title = $token->[2]->{'title'};
1735: if ($checktitle) {
1736: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1737: $retitles->{$oldurl}{$id} = $ressrc;
1738: }
1739: }
1740: next if ($token->[2]->{'type'} eq 'external');
1741: if ($token->[2]->{'type'} eq 'zombie') {
1742: next if ($skip);
1743: $zombies->{$oldurl}{$id} = $ressrc;
1744: $changed = 1;
1745: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1746: my $srcdom = $1;
1747: my $srcnum = $2;
1748: my $rem = $3;
1749: my $newurl;
1750: my $mapname;
1751: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1752: my $prefix = $1;
1753: $mapname = $prefix.$2;
1754: if ($tomove->{$mapname}) {
1755: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
1756: $srcdom,$srcnum,$allmaps,$rewrites,
1757: $retitles,$copies,$dbcopies,$zombies,
1758: $params,$mapmoves,$mapchanges,$tomove,
1759: $newsubdir,$newurls);
1760: next;
1761: } else {
1762: ($newurl,my $error) =
1763: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
1764: $srcdom,$srcnum,\$title,$allmaps,$newurls);
1765: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
1766: $newsubdir->{$ressrc} = $1;
1767: }
1768: if ($error) {
1769: next;
1770: }
1771: }
1772: }
1773: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
1774: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1775:
1776: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1777: $rewrites->{$oldurl}{$id} = $ressrc;
1778: $mapchanges->{$ressrc} = 1;
1779: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
1780: $cnum,$srcdom,$srcnum,$allmaps,
1781: $rewrites,$retitles,$copies,$dbcopies,
1782: $zombies,$params,$mapmoves,$mapchanges,
1783: $tomove,$newsubdir,$newurls)) {
1784: $mapmoves->{$ressrc} = 1;
1785: }
1786: $changed = 1;
1787: } else {
1788: $rewrites->{$oldurl}{$id} = $ressrc;
1789: $copies->{$oldurl}{$ressrc} = $id;
1790: $changed = 1;
1791: }
1792: }
1793: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1794: next if ($skip);
1795: my $srcdom = $1;
1796: my $srcnum = $2;
1797: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1798: $rewrites->{$oldurl}{$id} = $ressrc;
1799: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
1800: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
1801: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1802: $changed = 1;
1803: }
1804: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
1805: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
1806: ($env{'form.docs.markedcopy_options'} ne 'move')) {
1807: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
1808: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
1809: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1810: $changed = 1;
1811: }
1812: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1813: next if ($skip);
1814: my $srcdom = $1;
1815: my $srcnum = $2;
1816: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1817: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
1818: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
1819: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1820: $changed = 1;
1821: }
1822: }
1823: } elsif ($token->[1] eq 'param') {
1824: next if ($skip);
1825: my $to = $token->[2]->{'to'};
1826: if ($to ne '') {
1827: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1828: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1829: } else {
1830: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
1831: }
1832: }
1833: }
1834: }
1835: return $changed;
1836: }
1837:
1838: sub apply_fixups {
1839: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
1840: $oldurl,$url,$caller) = @_;
1841: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1842: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1843: %lockerrors,$lockmsg);
1844: if (ref($updated) eq 'HASH') {
1845: if (ref($updated->{'rewrites'}) eq 'HASH') {
1846: %rewrites = %{$updated->{'rewrites'}};
1847: }
1848: if (ref($updated->{'zombies'}) eq 'HASH') {
1849: %zombies = %{$updated->{'zombies'}};
1850: }
1851: if (ref($updated->{'removefrommap'}) eq 'HASH') {
1852: %removefrommap = %{$updated->{'removefrommap'}};
1853: }
1854: if (ref($updated->{'removeparam'}) eq 'HASH') {
1855: %removeparam = %{$updated->{'removeparam'}};
1856: }
1857: if (ref($updated->{'dbcopies'}) eq 'HASH') {
1858: %dbcopies = %{$updated->{'dbcopies'}};
1859: }
1860: if (ref($updated->{'retitles'}) eq 'HASH') {
1861: %retitles = %{$updated->{'retitles'}};
1862: }
1863: }
1864: if (ref($info) eq 'HASH') {
1865: if (ref($info->{'newsubdir'}) eq 'HASH') {
1866: %newsubdir = %{$info->{'newsubdir'}};
1867: }
1868: if (ref($info->{'params'}) eq 'HASH') {
1869: %params = %{$info->{'params'}};
1870: }
1871: if (ref($info->{'before'}) eq 'HASH') {
1872: %before = %{$info->{'before'}};
1873: }
1874: if (ref($info->{'after'}) eq 'HASH') {
1875: %after = %{$info->{'after'}};
1876: }
1877: }
1878: if (ref($moves) eq 'HASH') {
1879: if (ref($moves->{'copies'}) eq 'HASH') {
1880: %copies = %{$moves->{'copies'}};
1881: }
1882: if (ref($moves->{'docmoves'}) eq 'HASH') {
1883: %docmoves = %{$moves->{'docmoves'}};
1884: }
1885: if (ref($moves->{'mapmoves'}) eq 'HASH') {
1886: %mapmoves = %{$moves->{'mapmoves'}};
1887: }
1888: }
1889: foreach my $key (keys(%copies),keys(%docmoves)) {
1890: my @allcopies;
1891: if (exists($copies{$key})) {
1892: if (ref($copies{$key}) eq 'HASH') {
1893: my %added;
1894: foreach my $innerkey (keys(%{$copies{$key}})) {
1895: if (($innerkey ne '') && (!$added{$innerkey})) {
1896: push(@allcopies,$innerkey);
1897: $added{$innerkey} = 1;
1898: }
1899: }
1900: undef(%added);
1901: }
1902: }
1903: if ($key eq $oldurl) {
1904: if ((exists($docmoves{$key}))) {
1905: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1906: push(@allcopies,$oldurl);
1907: }
1908: }
1909: }
1910: if (@allcopies > 0) {
1911: foreach my $item (@allcopies) {
1912: my ($relpath,$oldsubdir,$fname) =
1913: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1914: if ($fname ne '') {
1915: my $content = &Apache::lonnet::getfile($item);
1916: unless ($content eq '-1') {
1917: my $storefn;
1918: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
1919: $storefn = $docmoves{$key};
1920: } else {
1921: $storefn = $relpath;
1922: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1923: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
1924: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1925: }
1926: if ($newsubdir{$key}) {
1927: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1928: }
1929: }
1930: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1931: my $copyurl =
1932: &Apache::lonclonecourse::writefile($env{'request.course.id'},
1933: $storefn.$fname,$content);
1934: if ($copyurl eq '/adm/notfound.html') {
1935: if (exists($docmoves{$oldurl})) {
1936: return &mt('Paste failed: an error occurred copying the file.');
1937: } elsif (ref($errors) eq 'HASH') {
1938: $errors->{$item} = 1;
1939: }
1940: }
1941: }
1942: }
1943: }
1944: }
1945: }
1946: foreach my $key (keys(%mapmoves)) {
1947: my $storefn=$key;
1948: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1949: if ($prefixchg && $before{'map'} && $after{'map'}) {
1950: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1951: }
1952: if ($newsubdir{$key}) {
1953: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1954: }
1955: my $mapcontent = &Apache::lonnet::getfile($key);
1956: if ($mapcontent eq '-1') {
1957: if (ref($errors) eq 'HASH') {
1958: $errors->{$key} = 1;
1959: }
1960: } else {
1961: my $newmap =
1962: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
1963: $mapcontent);
1964: if ($newmap eq '/adm/notfound.html') {
1965: if (ref($errors) eq 'HASH') {
1966: $errors->{$key} = 1;
1967: }
1968: }
1969: }
1970: }
1971: my %updates;
1972: if ($is_map) {
1973: if (ref($updated) eq 'HASH') {
1974: foreach my $type (keys(%{$updated})) {
1975: if (ref($updated->{$type}) eq 'HASH') {
1976: foreach my $key (keys(%{$updated->{$type}})) {
1977: $updates{$key} = 1;
1978: }
1979: }
1980: }
1981: }
1982: foreach my $key (keys(%updates)) {
1983: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1984: if (ref($rewrites{$key}) eq 'HASH') {
1985: %torewrite = %{$rewrites{$key}};
1986: }
1987: if (ref($retitles{$key}) eq 'HASH') {
1988: %toretitle = %{$retitles{$key}};
1989: }
1990: if (ref($removefrommap{$key}) eq 'HASH') {
1991: %toremove = %{$removefrommap{$key}};
1992: }
1993: if (ref($removeparam{$key}) eq 'HASH') {
1994: %remparam = %{$removeparam{$key}};
1995: }
1996: if (ref($zombies{$key}) eq 'HASH') {
1997: %zombie = %{$zombies{$key}};
1998: }
1999: if (ref($dbcopies{$key}) eq 'HASH') {
2000: foreach my $idx (keys(%{$dbcopies{$key}})) {
2001: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2002: my ($newurl,$result,$errtext) =
2003: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2004: if ($result eq 'ok') {
2005: $newdb{$idx} = $newurl;
2006: } elsif (ref($errors) eq 'HASH') {
2007: $errors->{$key} = 1;
2008: }
2009: push(@msgs,$errtext);
2010: }
2011: }
2012: }
2013: if (ref($params{$key}) eq 'HASH') {
2014: %currparam = %{$params{$key}};
2015: }
2016: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2017: if ($fatal) {
2018: return ($errtext);
2019: }
2020: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2021: if (defined($LONCAPA::map::zombies[$i])) {
2022: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
2023: if ($zombie{$i} eq $src) {
2024: undef($LONCAPA::map::zombies[$i]);
2025: }
2026: }
2027: }
2028: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2029: my $idx = $LONCAPA::map::order[$i];
2030: if (defined($LONCAPA::map::resources[$idx])) {
2031: my $changed;
2032: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
2033: if ((exists($toremove{$idx})) &&
2034: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
2035: splice(@LONCAPA::map::order,$i,1);
2036: if (ref($currparam{$idx}) eq 'ARRAY') {
2037: foreach my $name (@{$currparam{$idx}}) {
2038: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
2039: }
2040: }
2041: next;
2042: }
2043: my $origsrc = $src;
2044: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
2045: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2046: $changed = 1;
2047: }
2048: }
2049: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
2050: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2051: if ($origsrc =~ m{^/uploaded/}) {
2052: if ($prefixchg && $before{'map'} && $after{'map'}) {
2053: if ($src =~ /\.(page|sequence)$/) {
2054: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
2055: } else {
2056: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
2057: }
2058: }
2059: if ($origsrc =~ /\.(page|sequence)$/) {
2060: if ($newsubdir{$origsrc}) {
2061: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
2062: }
2063: } elsif ($newsubdir{$key}) {
2064: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
2065: }
2066: }
2067: $changed = 1;
2068: } elsif ($newdb{$idx} ne '') {
2069: $src = $newdb{$idx};
2070: $changed = 1;
2071: }
2072: if ($changed) {
2073: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
2074: }
2075: }
2076: }
2077: foreach my $idx (keys(%remparam)) {
2078: if (ref($remparam{$idx}) eq 'ARRAY') {
2079: foreach my $name (@{$remparam{$idx}}) {
2080: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
2081: }
2082: }
2083: }
2084: if (values(%lockerrors) > 0) {
2085: $lockmsg = join('<br />',values(%lockerrors));
2086: }
2087: my $storefn;
2088: if ($key eq $oldurl) {
2089: $storefn = $url;
2090: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2091: } else {
2092: $storefn = $key;
2093: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2094: if ($prefixchg && $before{'map'} && $after{'map'}) {
2095: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2096: }
2097: if ($newsubdir{$key}) {
2098: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2099: }
2100: }
2101: my $report;
2102: if ($folder !~ /^supplemental/) {
2103: $report = 1;
2104: }
2105: (my $outtext,$errtext) =
2106: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2107: if ($errtext) {
2108: if ($caller eq 'paste') {
2109: return (&mt('Paste failed: an error occurred saving the folder or page.'));
2110: }
2111: }
2112: }
2113: }
2114: return ('ok',\@msgs,$lockmsg);
2115: }
2116:
2117: sub copy_dependencies {
2118: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2119: my $content;
2120: if (ref($contentref)) {
2121: $content = $$contentref;
2122: } else {
2123: $content = &Apache::lonnet::getfile($item);
2124: }
2125: unless ($content eq '-1') {
2126: my $mm = new File::MMagic;
2127: my $mimetype = $mm->checktype_contents($content);
2128: if ($mimetype eq 'text/html') {
2129: my (%allfiles,%codebase,$state);
2130: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2131: if ($res eq 'ok') {
2132: my ($numexisting,$numpathchanges,$existing);
2133: (undef,$numexisting,$numpathchanges,$existing) =
2134: &Apache::loncommon::ask_for_embedded_content(
2135: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2136: {'error_on_invalid_names' => 1,
2137: 'ignore_remote_references' => 1,
2138: 'docs_url' => $item,
2139: 'context' => 'paste'});
2140: if ($numexisting > 0) {
2141: if (ref($existing) eq 'HASH') {
2142: foreach my $dep (keys(%{$existing})) {
2143: my $depfile = $dep;
2144: unless ($depfile =~ m{^\Q$relpath\E}) {
2145: $depfile = $relpath.$dep;
2146: }
2147: my $depcontent = &Apache::lonnet::getfile($depfile);
2148: unless ($depcontent eq '-1') {
2149: my $storedep = $dep;
2150: $storedep =~ s{^\Q$relpath\E}{};
2151: my $dep_url =
2152: &Apache::lonclonecourse::writefile(
2153: $env{'request.course.id'},
2154: $storefn.$storedep,$depcontent);
2155: if ($dep_url eq '/adm/notfound.html') {
2156: if (ref($errors) eq 'HASH') {
2157: $errors->{$depfile} = 1;
2158: }
2159: } else {
2160: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2161: }
2162: }
2163: }
2164: }
2165: }
2166: }
2167: }
2168: }
2169: return;
2170: }
2171:
2172: my %parameter_type = ( 'randompick' => 'int_pos',
2173: 'hiddenresource' => 'string_yesno',
2174: 'encrypturl' => 'string_yesno',
2175: 'randomorder' => 'string_yesno',);
2176: my $valid_parameters_re = join('|',keys(%parameter_type));
2177: # set parameters
2178: sub update_parameter {
2179: if ($env{'form.changeparms'} eq 'all') {
2180: my (@allidx,@allmapidx,%allchecked,%currchecked);
2181: %allchecked = (
2182: 'hiddenresource' => {},
2183: 'encrypturl' => {},
2184: 'randompick' => {},
2185: 'randomorder' => {},
2186: );
2187: foreach my $which (keys(%allchecked)) {
2188: $env{'form.all'.$which} =~ s/,$//;
2189: if ($which eq 'randompick') {
2190: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2191: my ($res,$value) = split(/:/,$item);
2192: if ($value =~ /^\d+$/) {
2193: $allchecked{$which}{$res} = $value;
2194: }
2195: }
2196: } else {
2197: if ($env{'form.all'.$which}) {
2198: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2199: }
2200: }
2201: }
2202: my $haschanges = 0;
2203: foreach my $res (@LONCAPA::map::order) {
2204: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2205: $name=&LONCAPA::map::qtescape($name);
2206: $url=&LONCAPA::map::qtescape($url);
2207: next unless ($name && $url);
2208: my $is_map;
2209: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2210: $is_map = 1;
2211: }
2212: foreach my $which (keys(%allchecked)) {
2213: if (($which eq 'randompick' || $which eq 'randomorder')) {
2214: next if (!$is_map);
2215: }
2216: my $oldvalue = 0;
2217: my $newvalue = 0;
2218: if ($allchecked{$which}{$res}) {
2219: $newvalue = $allchecked{$which}{$res};
2220: }
2221: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2222: if ($which eq 'randompick') {
2223: if ($current =~ /^(\d+)$/) {
2224: $oldvalue = $1;
2225: }
2226: } else {
2227: if ($current =~ /^yes$/i) {
2228: $oldvalue = 1;
2229: }
2230: }
2231: if ($oldvalue ne $newvalue) {
2232: $haschanges = 1;
2233: if ($newvalue) {
2234: my $storeval = 'yes';
2235: if ($which eq 'randompick') {
2236: $storeval = $newvalue;
2237: }
2238: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2239: $storeval,
2240: $parameter_type{$which});
2241: &remember_parms($res,$which,'set',$storeval);
2242: } elsif ($oldvalue) {
2243: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2244: &remember_parms($res,$which,'del');
2245: }
2246: }
2247: }
2248: }
2249: return $haschanges;
2250: } else {
2251: return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
2252:
2253: my $which = $env{'form.changeparms'};
2254: my $idx = $env{'form.setparms'};
2255: if ($env{'form.'.$which.'_'.$idx}) {
2256: my $value = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2257: : 'yes';
2258: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
2259: $parameter_type{$which});
2260: &remember_parms($idx,$which,'set',$value);
2261: } else {
2262: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2263:
2264: &remember_parms($idx,$which,'del');
2265: }
2266: return 1;
2267: }
2268: }
2269:
2270:
2271: sub handle_edit_cmd {
2272: my ($coursenum,$coursedom) =@_;
2273: return if ($env{'form.cmd'} eq '');
2274: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2275:
2276: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2277: my ($title, $url, @rrest) = split(':', $ratstr);
2278:
2279: if ($cmd eq 'remove') {
2280: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
2281: ($url!~/$LONCAPA::assess_page_seq_re/)) {
2282: &Apache::lonnet::removeuploadedurl($url);
2283: } else {
2284: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2285: }
2286: splice(@LONCAPA::map::order, $idx, 1);
2287:
2288: } elsif ($cmd eq 'cut') {
2289: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2290: splice(@LONCAPA::map::order, $idx, 1);
2291:
2292: } elsif ($cmd eq 'up'
2293: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2294: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2295:
2296: } elsif ($cmd eq 'down'
2297: && defined($LONCAPA::map::order[$idx+1])) {
2298: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2299:
2300: } elsif ($cmd eq 'rename') {
2301: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2302: if ($comment=~/\S/) {
2303: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2304: $comment.':'.join(':', $url, @rrest);
2305: }
2306: # Devalidate title cache
2307: my $renamed_url=&LONCAPA::map::qtescape($url);
2308: &Apache::lonnet::devalidate_title_cache($renamed_url);
2309:
2310: } else {
2311: return 0;
2312: }
2313: return 1;
2314: }
2315:
2316: sub editor {
2317: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
2318: $supplementalflag,$orderhash,$iconpath,$pathitem)=@_;
2319: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
2320: if ($allowed) {
2321: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2322: $is_random_order,$container) =
2323: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2324: $r->print($breadcrumbtrail);
2325: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2326: $container = 'page';
2327: } else {
2328: $container = 'sequence';
2329: }
2330:
2331: my $jumpto;
2332:
2333: unless ($supplementalflag) {
2334: $jumpto = "'uploaded/$coursedom/$coursenum/$folder.$container'";
2335: }
2336:
2337: unless ($allowed) {
2338: $randompick = -1;
2339: }
2340:
2341: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2342: $folder.'.'.$container);
2343: return $errtext if ($fatal);
2344:
2345: if ($#LONCAPA::map::order<1) {
2346: my $idx=&LONCAPA::map::getresidx();
2347: if ($idx<=0) { $idx=1; }
2348: $LONCAPA::map::order[0]=$idx;
2349: $LONCAPA::map::resources[$idx]='';
2350: }
2351:
2352: # ------------------------------------------------------------ Process commands
2353:
2354: # ---------------- if they are for this folder and user allowed to make changes
2355: if (($allowed) && ($env{'form.folder'} eq $folder)) {
2356: # set parameters and change order
2357: &snapshotbefore();
2358:
2359: if (&update_parameter()) {
2360: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
2361: return $errtext if ($fatal);
2362: }
2363:
2364: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
2365: # change order
2366: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
2367: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
2368:
2369: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
2370: return $errtext if ($fatal);
2371: }
2372:
2373: if ($env{'form.pastemarked'}) {
2374: my %paste_errors;
2375: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
2376: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
2377: \%paste_errors);
2378: if (ref($pastemsgarray) eq 'ARRAY') {
2379: if (@{$pastemsgarray} > 0) {
2380: $r->print('<p class="LC_info">'.
2381: join('<br />',@{$pastemsgarray}).
2382: '</p>');
2383: }
2384: }
2385: if ($lockerror) {
2386: $r->print('<p class="LC_error">'.
2387: $lockerror.
2388: '</p>');
2389: }
2390: if ($save_error ne '') {
2391: return $save_error;
2392: }
2393: if ($paste_res) {
2394: my %errortext = &Apache::lonlocal::texthash (
2395: fail => 'Storage of folder contents failed',
2396: failread => 'Reading folder contents failed',
2397: failstore => 'Storage of folder contents failed',
2398: );
2399: if ($errortext{$paste_res}) {
2400: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
2401: }
2402: }
2403: if (keys(%paste_errors) > 0) {
2404: $r->print('<p class="LC_warning">'."\n".
2405: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page which could not be copied during the paste operation:')."\n".
2406: '<ul>'."\n");
2407: foreach my $key (sort(keys(%paste_errors))) {
2408: $r->print('<li>'.$key.'</li>'."\n");
2409: }
2410: $r->print('</ul></p>'."\n");
2411: }
2412: } elsif ($env{'form.clearmarked'}) {
2413: my $output = &do_buffer_empty();
2414: if ($output) {
2415: $r->print('<p class="LC_info">'.$output.'</p>');
2416: }
2417: }
2418:
2419: $r->print($upload_output);
2420:
2421: # Rename, cut, copy or remove a single resource
2422: if (&handle_edit_cmd()) {
2423: my $contentchg;
2424: if ($env{'form.cmd'} =~ m{^(del|cut)_}) {
2425: $contentchg = 1;
2426: }
2427: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
2428: return $errtext if ($fatal);
2429: }
2430:
2431: # Cut, copy and/or remove multiple resources
2432: if ($env{'form.multichange'}) {
2433: my %allchecked = (
2434: cut => {},
2435: remove => {},
2436: );
2437: my $needsupdate;
2438: foreach my $which (keys(%allchecked)) {
2439: $env{'form.multi'.$which} =~ s/,$//;
2440: if ($env{'form.multi'.$which}) {
2441: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
2442: if (ref($allchecked{$which}) eq 'HASH') {
2443: $needsupdate += scalar(keys(%{$allchecked{$which}}));
2444: }
2445: }
2446: }
2447: if ($needsupdate) {
2448: my $haschanges = 0;
2449: my %curr_groups = &Apache::longroup::coursegroups();
2450: my $total = scalar(@LONCAPA::map::order) - 1;
2451: for (my $i=$total; $i>=0; $i--) {
2452: my $res = $LONCAPA::map::order[$i];
2453: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2454: $name=&LONCAPA::map::qtescape($name);
2455: $url=&LONCAPA::map::qtescape($url);
2456: next unless ($name && $url);
2457: my %denied =
2458: &action_restrictions($coursenum,$coursedom,$url,
2459: $env{'form.folderpath'},\%curr_groups);
2460: foreach my $which (keys(%allchecked)) {
2461: next if ($denied{$which});
2462: next unless ($allchecked{$which}{$res});
2463: if ($which eq 'remove') {
2464: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
2465: ($url!~/$LONCAPA::assess_page_seq_re/)) {
2466: &Apache::lonnet::removeuploadedurl($url);
2467: } else {
2468: &LONCAPA::map::makezombie($res);
2469: }
2470: splice(@LONCAPA::map::order,$i,1);
2471: $haschanges ++;
2472: } elsif ($which eq 'cut') {
2473: &LONCAPA::map::makezombie($res);
2474: splice(@LONCAPA::map::order,$i,1);
2475: $haschanges ++;
2476: }
2477: }
2478: }
2479: if ($haschanges) {
2480: ($errtext,$fatal) =
2481: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2482: return $errtext if ($fatal);
2483: }
2484: }
2485: }
2486:
2487: # Group import/search
2488: if ($env{'form.importdetail'}) {
2489: my @imports;
2490: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
2491: if (defined($item)) {
2492: my ($name,$url,$residx)=
2493: map { &unescape($_); } split(/\=/,$item);
2494: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
2495: my ($suffix,$errortxt,$locknotfreed) =
2496: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
2497: if ($locknotfreed) {
2498: $r->print($locknotfreed);
2499: }
2500: if ($suffix) {
2501: $url =~ s/_new\./_$suffix./;
2502: } else {
2503: return $errortxt;
2504: }
2505: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
2506: my $type = $1;
2507: my ($suffix,$errortxt,$locknotfreed) =
2508: &new_timebased_suffix($coursedom,$coursenum,$type);
2509: if ($locknotfreed) {
2510: $r->print($locknotfreed);
2511: }
2512: if ($suffix) {
2513: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
2514: } else {
2515: return $errortxt;
2516: }
2517: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
2518: if ($supplementalflag) {
2519: next unless ($1 eq 'supplemental');
2520: if ($folder eq 'supplemental') {
2521: next unless ($2 eq 'default');
2522: } else {
2523: next unless ($folder eq 'supplemental_'.$2);
2524: }
2525: } else {
2526: next unless ($1 eq 'docs');
2527: if ($folder eq 'default') {
2528: next unless ($2 eq 'default');
2529: } else {
2530: next unless ($folder eq 'default_'.$2);
2531: }
2532: }
2533: }
2534: push(@imports, [$name, $url, $residx]);
2535: }
2536: }
2537: ($errtext,$fatal,my $fixuperrors) =
2538: &group_import($coursenum, $coursedom, $folder,$container,
2539: 'londocs',@imports);
2540: return $errtext if ($fatal);
2541: if ($fixuperrors) {
2542: $r->print($fixuperrors);
2543: }
2544: }
2545: # Loading a complete map
2546: if ($env{'form.loadmap'}) {
2547: if ($env{'form.importmap'}=~/\w/) {
2548: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
2549: my ($title,$url,$ext,$type)=split(/\:/,$res);
2550: my $idx=&LONCAPA::map::getresidx($url);
2551: $LONCAPA::map::resources[$idx]=$res;
2552: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
2553: }
2554: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
2555: $folder.'.'.$container,1);
2556: return $errtext if ($fatal);
2557: } else {
2558: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
2559:
2560: }
2561: }
2562: &log_differences($plain);
2563: }
2564: # ---------------------------------------------------------------- End commands
2565: # ---------------------------------------------------------------- Print screen
2566: my $idx=0;
2567: my $shown=0;
2568: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
2569: $r->print('<div class="LC_Box">'.
2570: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
2571: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
2572: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
2573: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
2574: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
2575: '</ol>');
2576: if ($randompick>=0) {
2577: $r->print('<p class="LC_warning">'
2578: .&mt('Caution: this folder is set to randomly pick a subset'
2579: .' of resources. Adding or removing resources from this'
2580: .' folder will change the set of resources that the'
2581: .' students see, resulting in spurious or missing credit'
2582: .' for completed problems, not limited to ones you'
2583: .' modify. Do not modify the contents of this folder if'
2584: .' it is in active student use.')
2585: .'</p>'
2586: );
2587: }
2588: if ($is_random_order) {
2589: $r->print('<p class="LC_warning">'
2590: .&mt('Caution: this folder is set to randomly order its'
2591: .' contents. Adding or removing resources from this folder'
2592: .' will change the order of resources shown.')
2593: .'</p>'
2594: );
2595: }
2596: $r->print('</div>');
2597: }
2598:
2599: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
2600: %filters = (
2601: canremove => [],
2602: cancut => [],
2603: cancopy => [],
2604: );
2605: %curr_groups = &Apache::longroup::coursegroups();
2606: &Apache::loncommon::start_data_table_count(); #setup a row counter
2607: foreach my $res (@LONCAPA::map::order) {
2608: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2609: $name=&LONCAPA::map::qtescape($name);
2610: $url=&LONCAPA::map::qtescape($url);
2611: unless ($name) { $name=(split(/\//,$url))[-1]; }
2612: unless ($name) { $idx++; next; }
2613: push(@allidx,$res);
2614: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2615: push(@allmapidx,$res);
2616: }
2617: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
2618: $coursenum,$coursedom,$crstype,
2619: $pathitem,$supplementalflag,$container,
2620: \%filters,\%curr_groups);
2621: $idx++;
2622: $shown++;
2623: }
2624: &Apache::loncommon::end_data_table_count();
2625:
2626: my $need_save;
2627: if (($allowed) || ($supplementalflag && $folder eq 'supplemental')) {
2628: my $toolslink = '<table><tr><td>'
2629: .&Apache::loncommon::help_open_menu('Navigation Screen',
2630: 'Navigation_Screen',undef,'RAT')
2631: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
2632: .'<td align="left"><ul id="LC_toolbar">'
2633: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
2634: .'id="LC_content_toolbar_edittoplevel" '
2635: .'class="LC_toolbarItem" '
2636: .'title="'.&mt('Supplemental Content Editor').'">'
2637: .'</a></li></ul></td></tr></table><br />';
2638: if ($shown) {
2639: if ($allowed) {
2640: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
2641: .&Apache::loncommon::start_data_table(undef,'contentlist')
2642: .&Apache::loncommon::start_data_table_header_row()
2643: .'<th colspan="2">'.&mt('Move').'</th>'
2644: .'<th colspan="2">'.&mt('Actions').'</th>'
2645: .'<th>'.&mt('Document').'</th>';
2646: if ($folder !~ /^supplemental/) {
2647: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
2648: }
2649: $to_show .= &Apache::loncommon::end_data_table_header_row();
2650: if ($folder !~ /^supplemental/) {
2651: $lists{'canhide'} = join(',',@allidx);
2652: $lists{'canrandomlyorder'} = join(',',@allmapidx);
2653: foreach my $item ('canremove','cancut','cancopy') {
2654: if (ref($filters{$item}) eq 'ARRAY') {
2655: $lists{$item} = join(',',@{$filters{$item}});
2656: }
2657: }
2658: if (@allidx > 0) {
2659: my $path;
2660: if ($env{'form.folderpath'}) {
2661: $path =
2662: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
2663: }
2664: if (@allidx > 1) {
2665: $to_show .=
2666: &Apache::loncommon::continue_data_table_row().
2667: '<td colspan="2"> </td>'.
2668: '<td>'.
2669: &multiple_check_form('actions',\%lists).
2670: '</td>'.
2671: '<td> </td>'.
2672: '<td> </td>'.
2673: '<td colspan="4">'.
2674: &multiple_check_form('settings',\%lists).
2675: '</td>'.
2676: &Apache::loncommon::end_data_table_row();
2677: $need_save = 1;
2678: }
2679: }
2680: }
2681: $to_show .= $output.' '
2682: .&Apache::loncommon::end_data_table()
2683: .'<br style="line-height:2px;" />'
2684: .&Apache::loncommon::end_scrollbox();
2685: } else {
2686: $to_show .= $toolslink
2687: .&Apache::loncommon::start_data_table('LC_tableOfContent')
2688: .$output.' '
2689: .&Apache::loncommon::end_data_table();
2690: }
2691: } else {
2692: if (!$allowed) {
2693: $to_show .= $toolslink;
2694: }
2695: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
2696: .'<div class="LC_info" id="contentlist">'
2697: .&mt('Currently no documents.')
2698: .'</div>'
2699: .&Apache::loncommon::end_scrollbox();
2700: }
2701: } else {
2702: if ($shown) {
2703: $to_show = '<div>'
2704: .&Apache::loncommon::start_data_table('LC_tableOfContent')
2705: .$output
2706: .&Apache::loncommon::end_data_table()
2707: .'</div>';
2708: } else {
2709: $to_show = '<div class="LC_info" id="contentlist">'
2710: .&mt('Currently no documents.')
2711: .'</div>'
2712: }
2713: }
2714: my $tid = 1;
2715: if ($supplementalflag) {
2716: $tid = 2;
2717: }
2718: if ($allowed) {
2719: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
2720: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
2721: $jumpto,$readfile,$need_save,"$folder.$container"));
2722: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
2723: } else {
2724: $r->print($to_show);
2725: }
2726: return;
2727: }
2728:
2729: sub multiple_check_form {
2730: my ($caller,$listsref) = @_;
2731: return unless (ref($listsref) eq 'HASH');
2732: my $output =
2733: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
2734: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
2735: '<label><input type="radio" name="showmultpick" value="0" onclick="javascript:togglePick('."'$caller','0'".');" checked="checked" />'.&mt('one').'</label>'.(' 'x2).'<label><input type="radio" name="showmultpick" value="1" onclick="javascript:togglePick('."'$caller','1'".');" />'.&mt('multiple').'</label></span><span id="more'.$caller.'" class="LC_nobreak LC_docs_ext_edit"></span></form>'.
2736: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
2737: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
2738: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
2739: if ($caller eq 'settings') {
2740: $output .=
2741: '<table><tr>'.
2742: '<td class="LC_docs_entry_parameter">'.
2743: '<span class="LC_nobreak"><label>'.
2744: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')" />'.&mt('Hidden').
2745: '</label></span></td>'.
2746: '<td class="LC_docs_entry_parameter">'.
2747: '<span class="LC_nobreak"><label><input type="checkbox" name="randompickall" id="randompickall" onclick="updatePick(this.form,'."'all','check'".');propagateState(this.form,'."'randompick'".');propagateState(this.form,'."'rpicknum'".');" />'.&mt('Randomly Pick').'</label><span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" />'.
2748: '</span></td>'.
2749: '</tr>'."\n".
2750: '<tr>'.
2751: '<td class="LC_docs_entry_parameter">'.
2752: '<span class="LC_nobreak"><label><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')" />'.&mt('URL hidden').'</label></span></td><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><label><input type="checkbox" name="randomorderall" id="randomorderall" onclick="propagateState(this.form,'."'randomorder'".')" />'.&mt('Random Order').
2753: '</label></span>'.
2754: '</td></tr></table>'."\n";
2755: } else {
2756: $output .=
2757: '<table><tr>'.
2758: '<td class="LC_docs_entry_parameter">'.
2759: '<span class="LC_nobreak LC_docs_remove">'.
2760: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')" />'.&mt('Remove').
2761: '</label></span></td>'.
2762: '<td class="LC_docs_entry_parameter">'.
2763: '<span class="LC_nobreak LC_docs_cut">'.
2764: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');" />'.&mt('Cut').
2765: '</label></span></td>'."\n".
2766: '<td class="LC_docs_entry_parameter">'.
2767: '<span class="LC_nobreak LC_docs_copy">'.
2768: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')" />'.&mt('Copy').
2769: '</label></span></td>'.
2770: '</tr></table>'."\n";
2771: }
2772: $output .=
2773: '</fieldset>'.
2774: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
2775: if ($caller eq 'settings') {
2776: $output .=
2777: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />';
2778: } elsif ($caller eq 'actions') {
2779: $output .=
2780: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
2781: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
2782: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
2783: }
2784: $output .=
2785: '</form>'.
2786: '</div>';
2787: return $output;
2788: }
2789:
2790: sub process_file_upload {
2791: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
2792: # upload a file, if present
2793: my ($parseaction,$showupload,$nextphase,$mimetype);
2794: if ($env{'form.parserflag'}) {
2795: $parseaction = 'parse';
2796: }
2797: my $folder=$env{'form.folder'};
2798: if ($folder eq '') {
2799: $folder='default';
2800: }
2801: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
2802: my $errtext='';
2803: my $fatal=0;
2804: my $container='sequence';
2805: if ($env{'form.folderpath'} =~ /:1$/) {
2806: $container='page';
2807: }
2808: ($errtext,$fatal)=
2809: &mapread($coursenum,$coursedom,$folder.'.'.$container);
2810: if ($#LONCAPA::map::order<1) {
2811: $LONCAPA::map::order[0]=1;
2812: $LONCAPA::map::resources[1]='';
2813: }
2814: my $destination = 'docs/';
2815: if ($folder =~ /^supplemental/) {
2816: $destination = 'supplemental/';
2817: }
2818: if (($folder eq 'default') || ($folder eq 'supplemental')) {
2819: $destination .= 'default/';
2820: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
2821: $destination .= $2.'/';
2822: }
2823: if ($fatal) {
2824: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'</div>';
2825: return;
2826: }
2827: # this is for a course, not a user, so set context to coursedoc.
2828: my $newidx=&LONCAPA::map::getresidx();
2829: $destination .= $newidx;
2830: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
2831: $parseaction,$allfiles,
2832: $codebase,undef,undef,undef,undef,
2833: undef,undef,\$mimetype);
2834: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
2835: my $stored = $1;
2836: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
2837: $stored.'</span>').'</p>';
2838: } else {
2839: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
2840:
2841: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
2842: return;
2843: }
2844: my $ext='false';
2845: if ($url=~m{^http://}) { $ext='true'; }
2846: $url = &LONCAPA::map::qtunescape($url);
2847: my $comment=$env{'form.comment'};
2848: $comment = &LONCAPA::map::qtunescape($comment);
2849: if ($folder=~/^supplemental/) {
2850: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2851: $env{'user.domain'}.'___&&&___'.$comment;
2852: }
2853:
2854: $LONCAPA::map::resources[$newidx]=
2855: $comment.':'.$url.':'.$ext.':normal:res';
2856: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
2857: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
2858: $folder.'.'.$container,1);
2859: if ($fatal) {
2860: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
2861: return;
2862: } else {
2863: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
2864: $$upload_output = $showupload;
2865: my $total_embedded = scalar(keys(%{$allfiles}));
2866: if ($total_embedded > 0) {
2867: my $uploadphase = 'upload_embedded';
2868: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
2869: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
2870: my ($embedded,$num) =
2871: &Apache::loncommon::ask_for_embedded_content(
2872: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
2873: if ($embedded) {
2874: if ($num) {
2875: $$upload_output .=
2876: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
2877: $nextphase = $uploadphase;
2878: } else {
2879: $$upload_output .= $embedded;
2880: }
2881: } else {
2882: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
2883: }
2884: } else {
2885: $$upload_output .= &mt('No embedded items identified').'<br />';
2886: }
2887: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
2888: } elsif (&Apache::loncommon::is_archive_file($mimetype)) {
2889: $nextphase = 'decompress_uploaded';
2890: my $position = scalar(@LONCAPA::map::order)-1;
2891: my $noextract = &return_to_editor();
2892: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
2893: my %archiveitems = (
2894: folderpath => $env{'form.folderpath'},
2895: cmd => $nextphase,
2896: newidx => $newidx,
2897: position => $position,
2898: phase => $nextphase,
2899: comment => $comment,
2900: );
2901: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
2902: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
2903: $$upload_output = $showupload.
2904: &Apache::loncommon::decompress_form($mimetype,
2905: $archiveurl,'/adm/coursedocs',$noextract,
2906: \%archiveitems,\@current);
2907: }
2908: }
2909: }
2910: return $nextphase;
2911: }
2912:
2913: sub get_dir_list {
2914: my ($url,$coursenum,$coursedom,$newidx) = @_;
2915: my ($destination,$dir_root) = &embedded_destination();
2916: my ($dirlistref,$listerror) =
2917: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
2918: my @dir_lines;
2919: my $dirptr=16384;
2920: if (ref($dirlistref) eq 'ARRAY') {
2921: foreach my $dir_line (sort
2922: {
2923: my ($afile)=split('&',$a,2);
2924: my ($bfile)=split('&',$b,2);
2925: return (lc($afile) cmp lc($bfile));
2926: } (@{$dirlistref})) {
2927: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
2928: $filename =~ s/\s+$//;
2929: next if ($filename =~ /^\.\.?$/);
2930: my $isdir = 0;
2931: if ($dirptr&$testdir) {
2932: $isdir = 1;
2933: }
2934: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
2935: }
2936: }
2937: return @dir_lines;
2938: }
2939:
2940: sub is_supplemental_title {
2941: my ($title) = @_;
2942: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
2943: }
2944:
2945: # --------------------------------------------------------------- An entry line
2946:
2947: sub entryline {
2948: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
2949: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups)=@_;
2950: my ($foldertitle,$renametitle);
2951: if (&is_supplemental_title($title)) {
2952: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
2953: } else {
2954: $title=&HTML::Entities::encode($title,'"<>&\'');
2955: $renametitle=$title;
2956: $foldertitle=$title;
2957: }
2958:
2959: my $orderidx=$LONCAPA::map::order[$index];
2960:
2961: $renametitle=~s/\\/\\\\/g;
2962: $renametitle=~s/\"\;/\\\"/g;
2963: $renametitle=~s/ /%20/g;
2964: my $line=&Apache::loncommon::start_data_table_row();
2965: my ($form_start,$form_end,$form_common,$form_param);
2966: # Edit commands
2967: my ($esc_path, $path, $symb);
2968: if ($env{'form.folderpath'}) {
2969: $esc_path=&escape($env{'form.folderpath'});
2970: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
2971: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
2972: }
2973: my $isexternal;
2974: if ($residx) {
2975: my $currurl = $url;
2976: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
2977: if ($currurl =~ m{^/adm/wrapper/ext/}) {
2978: $isexternal = 1;
2979: }
2980: if (!$supplementalflag) {
2981: my $path = 'uploaded/'.
2982: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
2983: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
2984: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
2985: $residx,
2986: &Apache::lonnet::declutter($currurl));
2987: }
2988: }
2989: my ($renamelink,%lt,$ishash);
2990: if (ref($filtersref) eq 'HASH') {
2991: $ishash = 1;
2992: }
2993:
2994: if ($allowed) {
2995: $form_start = '
2996: <form action="/adm/coursedocs" method="post">
2997: ';
2998: $form_common=(<<END);
2999: <input type="hidden" name="folderpath" value="$path" />
3000: <input type="hidden" name="symb" value="$symb" />
3001: END
3002: $form_param=(<<END);
3003: <input type="hidden" name="setparms" value="$orderidx" />
3004: <input type="hidden" name="changeparms" value="0" />
3005: END
3006: $form_end = '</form>';
3007:
3008: my $incindex=$index+1;
3009: my $selectbox='';
3010: if (($#LONCAPA::map::order>0) &&
3011: ((split(/\:/,
3012: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3013: ne '') &&
3014: ((split(/\:/,
3015: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
3016: ne '')) {
3017: $selectbox=
3018: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
3019: '<select name="newpos" onchange="this.form.submit()">';
3020: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3021: if ($i==$incindex) {
3022: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
3023: } else {
3024: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3025: }
3026: }
3027: $selectbox.='</select>';
3028: }
3029: %lt=&Apache::lonlocal::texthash(
3030: 'up' => 'Move Up',
3031: 'dw' => 'Move Down',
3032: 'rm' => 'Remove',
3033: 'ct' => 'Cut',
3034: 'rn' => 'Rename',
3035: 'cp' => 'Copy',
3036: 'ex' => 'External Resource',
3037: 'ed' => 'Edit',
3038: 'pr' => 'Preview',
3039: 'sv' => 'Save',
3040: 'ul' => 'URL',
3041: 'ti' => 'Title',
3042: );
3043: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3044: $env{'form.folderpath'},
3045: $currgroups);
3046: my ($copylink,$cutlink,$removelink);
3047: my $skip_confirm = 0;
3048: if ( $folder =~ /^supplemental/
3049: || ($url =~ m{( /smppg$
3050: |/syllabus$
3051: |/aboutme$
3052: |/navmaps$
3053: |/bulletinboard$
3054: |\.html$)}x)
3055: || $isexternal) {
3056: $skip_confirm = 1;
3057: }
3058:
3059: if ($denied{'copy'}) {
3060: $copylink=(<<ENDCOPY);
3061: <span style="visibility: hidden;">$lt{'cp'}</span>
3062: ENDCOPY
3063: } else {
3064: my $formname = 'edit_copy_'.$orderidx;
3065: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
3066: $copylink=(<<ENDCOPY);
3067: <form name="$formname" method="post" action="/adm/coursedocs">
3068: $form_common
3069: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
3070: $form_end
3071: ENDCOPY
3072: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3073: push(@{$filtersref->{'cancopy'}},$orderidx);
3074: }
3075: }
3076: if ($denied{'cut'}) {
3077: $cutlink=(<<ENDCUT);
3078: <span style="visibility: hidden;">$lt{'ct'}</span>
3079: ENDCUT
3080: } else {
3081: my $formname = 'edit_cut_'.$orderidx;
3082: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
3083: $cutlink=(<<ENDCUT);
3084: <form name="$formname" method="post" action="/adm/coursedocs">
3085: $form_common
3086: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
3087: $form_end
3088: ENDCUT
3089: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3090: push(@{$filtersref->{'cancut'}},$orderidx);
3091: }
3092: }
3093: if ($denied{'remove'}) {
3094: $removelink=(<<ENDREM);
3095: <span style="visibility: hidden;">$lt{'rm'}</a>
3096: ENDREM
3097: } else {
3098: my $formname = 'edit_remove_'.$orderidx;
3099: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm);";
3100: $removelink=(<<ENDREM);
3101: <form name="$formname" method="post" action="/adm/coursedocs">
3102: $form_common
3103: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
3104: $form_end
3105: ENDREM
3106: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3107: push(@{$filtersref->{'canremove'}},$orderidx);
3108: }
3109: }
3110: unless ($isexternal) {
3111: $renamelink=(<<ENDREN);
3112: <a href='javascript:changename("$esc_path","$index","$renametitle");' class="LC_docs_rename">$lt{'rn'}</a>
3113: ENDREN
3114: }
3115: $line.=(<<END);
3116: <td>
3117: <div class="LC_docs_entry_move">
3118: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb'>
3119: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
3120: </a>
3121: </div>
3122: <div class="LC_docs_entry_move">
3123: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb'>
3124: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
3125: </a>
3126: </div>
3127: </td>
3128: <td>
3129: $form_start
3130: $form_param
3131: $form_common
3132: $selectbox
3133: $form_end
3134: </td>
3135: <td class="LC_docs_entry_commands LC_nobreak">
3136: $removelink
3137: $cutlink
3138: $copylink
3139: </td>
3140: END
3141: }
3142: # Figure out what kind of a resource this is
3143: my ($extension)=($url=~/\.(\w+)$/);
3144: my $uploaded=($url=~/^\/*uploaded\//);
3145: my $icon=&Apache::loncommon::icon($url);
3146: my $isfolder;
3147: my $ispage;
3148: my $containerarg;
3149: if ($uploaded) {
3150: if (($extension eq 'sequence') || ($extension eq 'page')) {
3151: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
3152: $containerarg = $1;
3153: if ($extension eq 'sequence') {
3154: $icon=$iconpath.'navmap.folder.closed.gif';
3155: $isfolder=1;
3156: } else {
3157: $icon=$iconpath.'page.gif';
3158: $ispage=1;
3159: }
3160: if ($allowed) {
3161: $url='/adm/coursedocs?';
3162: } else {
3163: $url='/adm/supplemental?';
3164: }
3165: } else {
3166: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3167: }
3168: }
3169:
3170: my ($editlink,$extresform);
3171: my $orig_url = $url;
3172: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
3173: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
3174: if (!$supplementalflag && $residx && $symb) {
3175: if ((!$isfolder) && (!$ispage)) {
3176: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3177: $url=&Apache::lonnet::clutter($url);
3178: if ($url=~/^\/*uploaded\//) {
3179: $url=~/\.(\w+)$/;
3180: my $embstyle=&Apache::loncommon::fileembstyle($1);
3181: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3182: $url='/adm/wrapper'.$url;
3183: } elsif ($embstyle eq 'ssi') {
3184: #do nothing with these
3185: } elsif ($url!~/\.(sequence|page)$/) {
3186: $url='/adm/coursedocs/showdoc'.$url;
3187: }
3188: } elsif ($url=~m|^/ext/|) {
3189: $url='/adm/wrapper'.$url;
3190: }
3191: if (&Apache::lonnet::symbverify($symb,$url)) {
3192: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
3193: } else {
3194: $url='';
3195: }
3196: }
3197: }
3198: my ($rand_pick_text,$rand_order_text);
3199: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
3200: my $foldername=&escape($foldertitle);
3201: my $folderpath=$env{'form.folderpath'};
3202: if ($folderpath) { $folderpath.='&' };
3203: if (!$allowed && $supplementalflag) {
3204: $folderpath.=$containerarg.'&'.$foldername;
3205: $url.='folderpath='.&escape($folderpath);
3206: } else {
3207: # Append randompick number, hidden, and encrypted with ":" to foldername,
3208: # so it gets transferred between levels
3209: $folderpath.=$containerarg.'&'.$foldername.
3210: ':'.(&LONCAPA::map::getparameter($orderidx,
3211: 'parameter_randompick'))[0]
3212: .':'.((&LONCAPA::map::getparameter($orderidx,
3213: 'parameter_hiddenresource'))[0]=~/^yes$/i)
3214: .':'.((&LONCAPA::map::getparameter($orderidx,
3215: 'parameter_encrypturl'))[0]=~/^yes$/i)
3216: .':'.((&LONCAPA::map::getparameter($orderidx,
3217: 'parameter_randomorder'))[0]=~/^yes$/i)
3218: .':'.$ispage;
3219: $url.='folderpath='.&escape($folderpath);
3220: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
3221: 'parameter_randompick'))[0];
3222: my $rpckchk;
3223: if ($rpicknum) {
3224: $rpckchk = ' checked="checked"';
3225: }
3226: my $formname = 'edit_randompick_'.$orderidx;
3227: $rand_pick_text =
3228: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
3229: $form_param."\n".
3230: $form_common."\n".
3231: '<span class="LC_nobreak"><label><input type="checkbox" name="randompick_'.$orderidx.'" id="randompick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="rpicknum_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" /><span id="randompicknum_'.$orderidx.'">';
3232: if ($rpicknum ne '') {
3233: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
3234: }
3235: $rand_pick_text .= '</span></span>'.
3236: $form_end;
3237: my $ro_set=
3238: ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
3239: my $formname = 'edit_rorder_'.$orderidx;
3240: $rand_order_text =
3241: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
3242: $form_param."\n".
3243: $form_common."\n".
3244: '<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder','settings'".');" '.$ro_set.' /> '.&mt('Random Order').' </label></span>'.
3245: $form_end;
3246: }
3247: } elsif ($supplementalflag && !$allowed) {
3248: $url .= ($url =~ /\?/) ? '&':'?';
3249: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
3250: if ($title) {
3251: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
3252: }
3253: if ($isexternal && $orderidx) {
3254: $url .= '&idx='.$orderidx;
3255: }
3256: }
3257: my ($tdalign,$tdwidth);
3258: if ($allowed) {
3259: my $fileloc =
3260: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
3261: if ($isexternal) {
3262: ($editlink,$extresform) =
3263: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem);
3264: } elsif (!$isfolder && !$ispage) {
3265: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
3266: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
3267: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
3268: my $jscall =
3269: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
3270: $switchserver,
3271: $forceedit,
3272: undef,$symb,
3273: &escape($env{'form.folderpath'}),
3274: $renametitle,'','',1);
3275: if ($jscall) {
3276: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
3277: $jscall.'" >'.&mt('Edit').'</a> '."\n";
3278: }
3279: }
3280: }
3281: $tdalign = ' align="right" valign="top"';
3282: $tdwidth = ' width="80%"';
3283: }
3284: my $reinit;
3285: if ($crstype eq 'Community') {
3286: $reinit = &mt('(re-initialize community to access)');
3287: } else {
3288: $reinit = &mt('(re-initialize course to access)');
3289: }
3290: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
3291: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
3292: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
3293: } elsif ($url) {
3294: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
3295: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
3296: } else {
3297: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
3298: }
3299: $line.='</span></td><td'.$tdwidth.'>';
3300: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
3301: $line.='<a href="'.$url.'">'.$title.'</a>';
3302: } elsif ($url) {
3303: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
3304: $title,600,500);
3305: } else {
3306: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
3307: }
3308: $line.="$extresform</td>";
3309: $rand_pick_text = ' ' if ($rand_pick_text eq '');
3310: $rand_order_text = ' ' if ($rand_order_text eq '');
3311: if (($allowed) && ($folder!~/^supplemental/)) {
3312: my %lt=&Apache::lonlocal::texthash(
3313: 'hd' => 'Hidden',
3314: 'ec' => 'URL hidden');
3315: my $enctext=
3316: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
3317: my $hidtext=
3318: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
3319: my $formhidden = 'edit_hiddenresource_'.$orderidx;
3320: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
3321: $line.=(<<ENDPARMS);
3322: <td class="LC_docs_entry_parameter">
3323: <form action="/adm/coursedocs" method="post" name="$formhidden">
3324: $form_param
3325: $form_common
3326: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext /> $lt{'hd'}</label>
3327: $form_end
3328: <br />
3329: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
3330: $form_param
3331: $form_common
3332: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext /> $lt{'ec'}</label>
3333: $form_end
3334: </td>
3335: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
3336: $rand_order_text</td>
3337: ENDPARMS
3338: }
3339: $line.=&Apache::loncommon::end_data_table_row();
3340: return $line;
3341: }
3342:
3343: sub action_restrictions {
3344: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
3345: my %denied = (
3346: cut => 0,
3347: copy => 0,
3348: remove => 0,
3349: );
3350: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
3351: # no copy for published maps
3352: $denied{'copy'} = 1;
3353: } elsif ($url=~m{^/res/lib/templates/}) {
3354: $denied{'copy'} = 1;
3355: $denied{'cut'} = 1;
3356: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
3357: if ($folderpath =~ /^default&[^\&]+$/) {
3358: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
3359: $denied{'remove'} = 1;
3360: }
3361: $denied{'cut'} = 1;
3362: $denied{'copy'} = 1;
3363: }
3364: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
3365: my $group = $1;
3366: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
3367: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
3368: $denied{'remove'} = 1;
3369: }
3370: }
3371: $denied{'cut'} = 1;
3372: $denied{'copy'} = 1;
3373: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
3374: my $group = $1;
3375: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
3376: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
3377: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
3378: if (keys(%groupsettings) > 0) {
3379: $denied{'remove'} = 1;
3380: }
3381: $denied{'cut'} = 1;
3382: $denied{'copy'} = 1;
3383: }
3384: }
3385: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
3386: my $group = $1;
3387: if ($url =~ /group_boards_\Q$group\E/) {
3388: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
3389: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
3390: if (keys(%groupsettings) > 0) {
3391: if (ref($groupsettings{'functions'}) eq 'HASH') {
3392: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
3393: $denied{'remove'} = 1;
3394: }
3395: }
3396: }
3397: $denied{'cut'} = 1;
3398: $denied{'copy'} = 1;
3399: }
3400: }
3401: }
3402: return %denied;
3403: }
3404:
3405: sub new_timebased_suffix {
3406: my ($dom,$num,$type,$area,$container) = @_;
3407: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
3408: if ($type eq 'paste') {
3409: $prefix = $type;
3410: $namespace = 'courseeditor';
3411: } elsif ($type eq 'map') {
3412: $prefix = 'docs';
3413: if ($area eq 'supplemental') {
3414: $prefix = 'supp';
3415: }
3416: $prefix .= $container;
3417: $namespace = 'uploadedmaps';
3418: } else {
3419: $prefix = $type;
3420: $namespace = 'templated';
3421: }
3422: $idtype = 'concat';
3423: my ($suffix,$freedlock,$error) =
3424: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num);
3425: if (!$suffix) {
3426: if ($type eq 'paste') {
3427: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
3428: } elsif ($type eq 'map') {
3429: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
3430: } elsif ($type eq 'smppg') {
3431: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
3432: } else {
3433: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new bulletin board.');
3434: }
3435: if ($error) {
3436: $errtext .= '<br />'.$error;
3437: }
3438: }
3439: if ($freedlock ne 'ok') {
3440: $locknotfreed =
3441: '<div class="LC_error">'.
3442: &mt('There was a problem removing a lockfile.').' ';
3443: if ($type eq 'paste') {
3444: &mt('This will prevent use of the paste buffer until th next log-in.');
3445: } elsif ($type eq 'map') {
3446: &mt('This will prevent creation of additional folders or composite pages in this course.');
3447: } elsif ($type eq 'smppg') {
3448: $locknotfreed .=
3449: &mt('This will prevent creation of additional simple pages in this course.');
3450: } else {
3451: $locknotfreed .=
3452: &mt('This will prevent creation of additional bulletin boards in this course.');
3453: }
3454: unless ($type eq 'paste') {
3455: $locknotfreed .=
3456: ' '.&mt('Please contact the domain coordinator for your LON-CAPA domain.');
3457: }
3458: $locknotfreed .= '</div>';
3459: }
3460: return ($suffix,$errtext,$locknotfreed);
3461: }
3462:
3463: =pod
3464:
3465: =item tiehash()
3466:
3467: tie the hash
3468:
3469: =cut
3470:
3471: sub tiehash {
3472: my ($mode)=@_;
3473: $hashtied=0;
3474: if ($env{'request.course.fn'}) {
3475: if ($mode eq 'write') {
3476: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
3477: &GDBM_WRCREAT(),0640)) {
3478: $hashtied=2;
3479: }
3480: } else {
3481: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
3482: &GDBM_READER(),0640)) {
3483: $hashtied=1;
3484: }
3485: }
3486: }
3487: }
3488:
3489: sub untiehash {
3490: if ($hashtied) { untie %hash; }
3491: $hashtied=0;
3492: return OK;
3493: }
3494:
3495:
3496:
3497:
3498: sub checkonthis {
3499: my ($r,$url,$level,$title)=@_;
3500: $url=&unescape($url);
3501: $alreadyseen{$url}=1;
3502: $r->rflush();
3503: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
3504: $r->print("\n<br />");
3505: if ($level==0) {
3506: $r->print("<br />");
3507: }
3508: for (my $i=0;$i<=$level*5;$i++) {
3509: $r->print(' ');
3510: }
3511: $r->print('<a href="'.$url.'" target="cat">'.
3512: ($title?$title:$url).'</a> ');
3513: if ($url=~/^\/res\//) {
3514: my $result=&Apache::lonnet::repcopy(
3515: &Apache::lonnet::filelocation('',$url));
3516: if ($result eq 'ok') {
3517: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
3518: $r->rflush();
3519: &Apache::lonnet::countacc($url);
3520: $url=~/\.(\w+)$/;
3521: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
3522: $r->print('<br />');
3523: $r->rflush();
3524: for (my $i=0;$i<=$level*5;$i++) {
3525: $r->print(' ');
3526: }
3527: $r->print('- '.&mt('Rendering:').' ');
3528: my ($errorcount,$warningcount)=split(/:/,
3529: &Apache::lonnet::ssi_body($url,
3530: ('grade_target'=>'web',
3531: 'return_only_error_and_warning_counts' => 1)));
3532: if (($errorcount) ||
3533: ($warningcount)) {
3534: if ($errorcount) {
3535: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
3536: &mt('[quant,_1,error]',$errorcount).'</span>');
3537: }
3538: if ($warningcount) {
3539: $r->print('<span class="LC_warning">'.
3540: &mt('[quant,_1,warning]',$warningcount).'</span>');
3541: }
3542: } else {
3543: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
3544: }
3545: $r->rflush();
3546: }
3547: my $dependencies=
3548: &Apache::lonnet::metadata($url,'dependencies');
3549: foreach my $dep (split(/\,/,$dependencies)) {
3550: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
3551: &checkonthis($r,$dep,$level+1);
3552: }
3553: }
3554: } elsif ($result eq 'unavailable') {
3555: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
3556: } elsif ($result eq 'not_found') {
3557: unless ($url=~/\$/) {
3558: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
3559: } else {
3560: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
3561: }
3562: } else {
3563: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
3564: }
3565: }
3566: }
3567: }
3568:
3569:
3570:
3571: =pod
3572:
3573: =item list_symbs()
3574:
3575: List Content Identifiers
3576:
3577: =cut
3578:
3579: sub list_symbs {
3580: my ($r) = @_;
3581:
3582: my $crstype = &Apache::loncommon::course_type();
3583: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
3584: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
3585: $r->print(&startContentScreen('tools'));
3586: my $navmap = Apache::lonnavmaps::navmap->new();
3587: if (!defined($navmap)) {
3588: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
3589: '<div class="LC_error">'.
3590: &mt('Unable to retrieve information about course contents').
3591: '</div>');
3592: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
3593: } else {
3594: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
3595: &Apache::loncommon::start_data_table().
3596: &Apache::loncommon::start_data_table_header_row().
3597: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
3598: &Apache::loncommon::end_data_table_header_row()."\n");
3599: my $count;
3600: foreach my $res ($navmap->retrieveResources()) {
3601: $r->print(&Apache::loncommon::start_data_table_row().
3602: '<td>'.$res->compTitle().'</td>'.
3603: '<td>'.$res->symb().'</td>'.
3604: &Apache::loncommon::end_data_table_row());
3605: $count ++;
3606: }
3607: if (!$count) {
3608: $r->print(&Apache::loncommon::start_data_table_row().
3609: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
3610: &Apache::loncommon::end_data_table_row());
3611: }
3612: $r->print(&Apache::loncommon::end_data_table());
3613: }
3614: $r->print(&endContentScreen());
3615: }
3616:
3617:
3618: sub verifycontent {
3619: my ($r) = @_;
3620: my $crstype = &Apache::loncommon::course_type();
3621: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Documents'));
3622: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Documents'));
3623: $r->print(&startContentScreen('tools'));
3624: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
3625: $hashtied=0;
3626: undef %alreadyseen;
3627: %alreadyseen=();
3628: &tiehash();
3629:
3630: foreach my $key (keys(%hash)) {
3631: if ($hash{$key}=~/\.(page|sequence)$/) {
3632: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
3633: $r->print('<hr /><span class="LC_error">'.
3634: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
3635: &unescape($hash{$key}).'</span><br />'.
3636: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
3637: }
3638: }
3639: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
3640: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
3641: }
3642: }
3643: &untiehash();
3644: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
3645: $r->print(&endContentScreen());
3646: }
3647:
3648:
3649: sub devalidateversioncache {
3650: my $src=shift;
3651: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
3652: &Apache::lonnet::clutter($src));
3653: }
3654:
3655: sub checkversions {
3656: my ($r) = @_;
3657: my $crstype = &Apache::loncommon::course_type();
3658: $r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
3659: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
3660: $r->print(&startContentScreen('tools'));
3661:
3662: my $header='';
3663: my $startsel='';
3664: my $monthsel='';
3665: my $weeksel='';
3666: my $daysel='';
3667: my $allsel='';
3668: my %changes=();
3669: my $starttime=0;
3670: my $haschanged=0;
3671: my %setversions=&Apache::lonnet::dump('resourceversions',
3672: $env{'course.'.$env{'request.course.id'}.'.domain'},
3673: $env{'course.'.$env{'request.course.id'}.'.num'});
3674:
3675: $hashtied=0;
3676: &tiehash();
3677: my %newsetversions=();
3678: if ($env{'form.setmostrecent'}) {
3679: $haschanged=1;
3680: foreach my $key (keys(%hash)) {
3681: if ($key=~/^ids\_(\/res\/.+)$/) {
3682: $newsetversions{$1}='mostrecent';
3683: &devalidateversioncache($1);
3684: }
3685: }
3686: } elsif ($env{'form.setcurrent'}) {
3687: $haschanged=1;
3688: foreach my $key (keys(%hash)) {
3689: if ($key=~/^ids\_(\/res\/.+)$/) {
3690: my $getvers=&Apache::lonnet::getversion($1);
3691: if ($getvers>0) {
3692: $newsetversions{$1}=$getvers;
3693: &devalidateversioncache($1);
3694: }
3695: }
3696: }
3697: } elsif ($env{'form.setversions'}) {
3698: $haschanged=1;
3699: foreach my $key (keys(%env)) {
3700: if ($key=~/^form\.set_version_(.+)$/) {
3701: my $src=$1;
3702: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
3703: $newsetversions{$src}=$env{$key};
3704: &devalidateversioncache($src);
3705: }
3706: }
3707: }
3708: }
3709: if ($haschanged) {
3710: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
3711: $env{'course.'.$env{'request.course.id'}.'.domain'},
3712: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
3713: $r->print(&Apache::loncommon::confirmwrapper(
3714: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
3715: } else {
3716: $r->print(&Apache::loncommon::confirmwrapper(
3717: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
3718: }
3719: &mark_hash_old();
3720: }
3721: &changewarning($r,'');
3722: if ($env{'form.timerange'} eq 'all') {
3723: # show all documents
3724: $header=&mt('All Documents in '.$crstype);
3725: $allsel=' selected="selected"';
3726: foreach my $key (keys(%hash)) {
3727: if ($key=~/^ids\_(\/res\/.+)$/) {
3728: my $src=$1;
3729: $changes{$src}=1;
3730: }
3731: }
3732: } else {
3733: # show documents which changed
3734: %changes=&Apache::lonnet::dump
3735: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
3736: $env{'course.'.$env{'request.course.id'}.'.num'});
3737: my $firstkey=(keys(%changes))[0];
3738: unless ($firstkey=~/^error\:/) {
3739: unless ($env{'form.timerange'}) {
3740: $env{'form.timerange'}=604800;
3741: }
3742: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
3743: .&mt('seconds');
3744: if ($env{'form.timerange'}==-1) {
3745: $seltext='since start of course';
3746: $startsel=' selected="selected"';
3747: $env{'form.timerange'}=time;
3748: }
3749: $starttime=time-$env{'form.timerange'};
3750: if ($env{'form.timerange'}==2592000) {
3751: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
3752: $monthsel=' selected="selected"';
3753: } elsif ($env{'form.timerange'}==604800) {
3754: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
3755: $weeksel=' selected="selected"';
3756: } elsif ($env{'form.timerange'}==86400) {
3757: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
3758: $daysel=' selected="selected"';
3759: }
3760: $header=&mt('Content changed').' '.$seltext;
3761: } else {
3762: $header=&mt('No content modifications yet.');
3763: }
3764: }
3765: %setversions=&Apache::lonnet::dump('resourceversions',
3766: $env{'course.'.$env{'request.course.id'}.'.domain'},
3767: $env{'course.'.$env{'request.course.id'}.'.num'});
3768: my %lt=&Apache::lonlocal::texthash
3769: ('st' => 'Version changes since start of '.$crstype,
3770: 'lm' => 'Version changes since last Month',
3771: 'lw' => 'Version changes since last Week',
3772: 'sy' => 'Version changes since Yesterday',
3773: 'al' => 'All Resources (possibly large output)',
3774: 'cd' => 'Change display',
3775: 'sd' => 'Display',
3776: 'fi' => 'File',
3777: 'md' => 'Modification Date',
3778: 'mr' => 'Most recently published Version',
3779: 've' => 'Version used in '.$crstype,
3780: 'vu' => 'Set Version to be used in '.$crstype,
3781: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
3782: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
3783: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
3784: 'di' => 'Differences',
3785: 'save' => 'Save changes',
3786: 'vers' => 'Version choice(s) for specific resources',
3787: 'act' => 'Actions');
3788: $r->print(<<ENDHEADERS);
3789: <h4 class="LC_info">$header</h4>
3790: <form action="/adm/coursedocs" method="post">
3791: <input type="hidden" name="versions" value="1" />
3792: <div class="LC_left_float">
3793: <fieldset>
3794: <legend>$lt{'cd'}</legend>
3795: <select name="timerange">
3796: <option value='all'$allsel>$lt{'al'}</option>
3797: <option value="-1"$startsel>$lt{'st'}</option>
3798: <option value="2592000"$monthsel>$lt{'lm'}</option>
3799: <option value="604800"$weeksel>$lt{'lw'}</option>
3800: <option value="86400"$daysel>$lt{'sy'}</option>
3801: </select>
3802: <input type="submit" name="display" value="$lt{'sd'}" />
3803: </fieldset>
3804: </div>
3805: <div class="LC_left_float">
3806: <fieldset>
3807: <legend>$lt{'act'}</legend>
3808: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" /><br />
3809: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" />
3810: </fieldset>
3811: </div>
3812: <br clear="all" />
3813: <hr />
3814: <h4>$lt{'vers'}</h4>
3815: <input type="submit" name="setversions" value="$lt{'save'}" />
3816: ENDHEADERS
3817: #number of columns for version history
3818: $r->print(
3819: &Apache::loncommon::start_data_table().
3820: &Apache::loncommon::start_data_table_header_row().
3821: '<th>'.&mt('Resources').'</th>'.
3822: "<th>$lt{'mr'}</th>".
3823: "<th>$lt{'ve'}</th>".
3824: "<th>$lt{'vu'}</th>".
3825: '<th>'.&mt('History').'</th>'.
3826: &Apache::loncommon::end_data_table_header_row()
3827: );
3828: foreach my $key (sort(keys(%changes))) {
3829: #excludes not versionable problems from resource version history:
3830: next unless ($changes{$key}>$starttime && $key !~ /^\/res\/lib\/templates/);
3831: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
3832: my $currentversion=&Apache::lonnet::getversion($key);
3833: if ($currentversion<0) {
3834: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
3835: }
3836: my $linkurl=&Apache::lonnet::clutter($key);
3837: $r->print(
3838: &Apache::loncommon::start_data_table_row().
3839: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
3840: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
3841: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
3842: &Apache::lonlocal::locallocaltime(&Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate')).')</span></td>'.
3843: '<td align="right">'
3844: );
3845: # Used in course
3846: my $usedversion=$hash{'version_'.$linkurl};
3847: if (($usedversion) && ($usedversion ne 'mostrecent')) {
3848: if ($usedversion != $currentversion) {
3849: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
3850: } else {
3851: $r->print($usedversion);
3852: }
3853: } else {
3854: $r->print($currentversion);
3855: }
3856: $r->print('</td><td title="'.$lt{'vu'}.'">');
3857: # Set version
3858: $r->print(&Apache::loncommon::select_form(
3859: $setversions{$linkurl},
3860: 'set_version_'.$linkurl,
3861: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
3862: '' => '',
3863: 'mostrecent' => &mt('most recent'),
3864: map {$_,$_} (1..$currentversion)}));
3865: my $lastold=1;
3866: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
3867: my $url=$root.'.'.$prevvers.'.'.$extension;
3868: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
3869: $lastold=$prevvers;
3870: }
3871: }
3872: $r->print('</td>');
3873: # List all available versions
3874: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
3875: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
3876: my $url=$root.'.'.$prevvers.'.'.$extension;
3877: $r->print(
3878: '<span class="LC_nobreak">'
3879: .'<a href="'.&Apache::lonnet::clutter($url).'">'
3880: .&mt('Version [_1]',$prevvers).'</a>'
3881: .' ('.&Apache::lonlocal::locallocaltime(
3882: &Apache::lonnet::metadata($url,'lastrevisiondate'))
3883: .')');
3884: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
3885: $r->print(
3886: ' <a href="/adm/diff?filename='.
3887: &Apache::lonnet::clutter($root.'.'.$extension).
3888: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
3889: '" target="diffs">'.&mt('Diffs').'</a>');
3890: }
3891: $r->print('</span><br />');
3892: }
3893: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
3894: }
3895: $r->print(
3896: &Apache::loncommon::end_data_table().
3897: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />'.
3898: '</form>'
3899: );
3900:
3901: &untiehash();
3902: $r->print(&endContentScreen());
3903: }
3904:
3905: sub mark_hash_old {
3906: my $retie_hash=0;
3907: if ($hashtied) {
3908: $retie_hash=1;
3909: &untiehash();
3910: }
3911: &tiehash('write');
3912: $hash{'old'}=1;
3913: &untiehash();
3914: if ($retie_hash) { &tiehash(); }
3915: }
3916:
3917: sub is_hash_old {
3918: my $untie_hash=0;
3919: if (!$hashtied) {
3920: $untie_hash=1;
3921: &tiehash();
3922: }
3923: my $return=$hash{'old'};
3924: if ($untie_hash) { &untiehash(); }
3925: return $return;
3926: }
3927:
3928: sub changewarning {
3929: my ($r,$postexec,$message,$url)=@_;
3930: if (!&is_hash_old()) { return; }
3931: my $pathvar='folderpath';
3932: my $path=&escape($env{'form.folderpath'});
3933: if (!defined($url)) {
3934: $url='/adm/coursedocs?'.$pathvar.'='.$path;
3935: }
3936: my $course_type = &Apache::loncommon::course_type();
3937: if (!defined($message)) {
3938: $message='Changes will become active for your current session after [_1], or the next time you log in.';
3939: }
3940: $r->print("\n\n".
3941: '<script type="text/javascript">'."\n".
3942: '// <![CDATA['."\n".
3943: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
3944: '// ]]>'."\n".
3945: '</script>'."\n".
3946: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
3947: '<input type="hidden" name="orgurl" value="'.$url.
3948: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
3949: &mt($message,' <input type="hidden" name="'.
3950: $env{'request.role'}.'" value="1" /><input type="button" value="'.
3951: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
3952: $help{'Caching'}.'</p></form>'."\n\n");
3953: }
3954:
3955:
3956: sub init_breadcrumbs {
3957: my ($form,$text)=@_;
3958: &Apache::lonhtmlcommon::clear_breadcrumbs();
3959: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
3960: text=>&Apache::loncommon::course_type().' Editor',
3961: faq=>273,
3962: bug=>'Instructor Interface',
3963: help => 'Docs_Adding_Course_Doc'});
3964: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
3965: text=>$text,
3966: faq=>273,
3967: bug=>'Instructor Interface'});
3968: }
3969:
3970: # subroutine to list form elements
3971: sub create_list_elements {
3972: my @formarr = @_;
3973: my $list = '';
3974: foreach my $button (@formarr){
3975: foreach my $picture (keys(%{$button})) {
3976: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
3977: }
3978: }
3979: return $list;
3980: }
3981:
3982: # subroutine to create ul from list elements
3983: sub create_form_ul {
3984: my $list = shift;
3985: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
3986: return $ul;
3987: }
3988:
3989: #
3990: # Start tabs
3991: #
3992:
3993: sub startContentScreen {
3994: my ($mode) = @_;
3995: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
3996: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
3997: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
3998: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
3999: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
4000: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4001: } else {
4002: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Content Editor').' </b></a></li>'."\n";
4003: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4004: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4005: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4006: }
4007: $output .= "\n".'</ul>'."\n";
4008: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4009: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4010: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4011: return $output;
4012: }
4013:
4014: #
4015: # End tabs
4016: #
4017:
4018: sub endContentScreen {
4019: return '</div></div></div>';
4020: }
4021:
4022: sub supplemental_base {
4023: return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Content'));
4024: }
4025:
4026: sub handler {
4027: my $r = shift;
4028: &Apache::loncommon::content_type($r,'text/html');
4029: $r->send_http_header;
4030: return OK if $r->header_only;
4031:
4032: # get course data
4033: my $crstype = &Apache::loncommon::course_type();
4034: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4035: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4036:
4037: # graphics settings
4038: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
4039:
4040: #
4041: # --------------------------------------------- Initialize help topics for this
4042: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4043: 'Adding_External_Resource','Navigate_Content',
4044: 'Adding_Folders','Docs_Overview', 'Load_Map',
4045: 'Supplemental','Score_Upload_Form','Adding_Pages',
4046: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
4047: 'Uploading_From_Harddrive',
4048: 'Check_Resource_Versions','Verify_Content') {
4049: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4050: }
4051: # Composite help files
4052: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4053: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4054: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4055: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4056: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
4057: 'Option_Response_Simple');
4058: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4059: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
4060: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
4061: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
4062: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
4063: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
4064: $help{'Course Roster'} = &Apache::loncommon::help_open_topic('Docs_Course_Roster');
4065: $help{'Web Page'} = &Apache::loncommon::help_open_topic('Docs_Web_Page');
4066:
4067: my $allowed;
4068: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4069: unless ($r->uri eq '/adm/supplemental') {
4070: # does this user have privileges to modify content.
4071: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
4072: }
4073:
4074: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
4075: 'inhibitmenu']);
4076: if ($allowed && $env{'form.chooseserver'}) {
4077: &choose_dump_server($r);
4078: return OK;
4079: } elsif ($allowed && $env{'form.verify'}) {
4080: &init_breadcrumbs('verify','Verify Content');
4081: &verifycontent($r);
4082: } elsif ($allowed && $env{'form.listsymbs'}) {
4083: &init_breadcrumbs('listsymbs','List Content IDs');
4084: &list_symbs($r);
4085: } elsif ($allowed && $env{'form.docslog'}) {
4086: &init_breadcrumbs('docslog','Show Log');
4087: my $folder = $env{'form.folder'};
4088: if ($folder eq '') {
4089: $folder='default';
4090: }
4091: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
4092: } elsif ($allowed && $env{'form.versions'}) {
4093: &init_breadcrumbs('versions','Check/Set Resource Versions');
4094: &checkversions($r);
4095: } elsif ($allowed && $env{'form.dumpcourse'}) {
4096: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Content to Authoring Space');
4097: &dumpcourse($r);
4098: } elsif ($allowed && $env{'form.exportcourse'}) {
4099: &init_breadcrumbs('exportcourse','IMS Export');
4100: &Apache::imsexport::exportcourse($r);
4101: } else {
4102: #
4103: # Done catching special calls
4104: # The whole rest is for course and supplemental documents and utilities menu
4105: # Get the parameters that may be needed
4106: #
4107: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4108: ['folderpath',
4109: 'forcesupplement','forcestandard',
4110: 'tools','symb','command','supppath']);
4111:
4112: # standard=1: this is a "new-style" course with an uploaded map as top level
4113: # standard=2: this is a "old-style" course, and there is nothing we can do
4114:
4115: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
4116:
4117: # Decide whether this should display supplemental or main content or utilities
4118: # supplementalflag=1: show supplemental documents
4119: # supplementalflag=0: show standard documents
4120: # toolsflag=1: show utilities
4121:
4122: $env{'form.folderpath'} = &unescape($env{'form.folderpath'});
4123: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
4124: if (($env{'form.folderpath'}=~/^default/) || ($env{'form.folderpath'} eq "")) {
4125: $supplementalflag=0;
4126: }
4127: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
4128: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
4129: unless ($allowed) { $supplementalflag=1; }
4130: unless ($standard) { $supplementalflag=1; }
4131: my $toolsflag=0;
4132: if ($env{'form.tools'}) { $toolsflag=1; }
4133:
4134: my $script='';
4135: my $showdoc=0;
4136: my $addentries = {};
4137: my $container;
4138: my $containertag;
4139: my $pathitem;
4140:
4141: # Do we directly jump somewhere?
4142:
4143: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
4144: if ($env{'form.symb'} ne '') {
4145: $env{'form.folderpath'}=
4146: &Apache::loncommon::symb_to_docspath($env{'form.symb'});
4147: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
4148: $env{'form.command'}.'_'.$env{'form.symb'}});
4149: } elsif ($env{'form.supppath'} ne '') {
4150: $env{'form.folderpath'}=$env{'form.supppath'};
4151: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
4152: $env{'form.command'}.'_'.$env{'form.supppath'}});
4153: }
4154: } elsif ($env{'form.command'} eq 'editdocs') {
4155: $env{'form.folderpath'} = 'default&'.
4156: &escape(&mt('Main '.$crstype.' Content').':::::');
4157: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
4158: } elsif ($env{'form.command'} eq 'editsupp') {
4159: $env{'form.folderpath'} = 'supplemental&'.
4160: &escape('Supplemental Content');
4161: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
4162: } elsif ($env{'form.command'} eq 'contents') {
4163: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
4164: } elsif ($env{'form.command'} eq 'home') {
4165: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
4166: }
4167:
4168:
4169: # Where do we store these for when we come back?
4170: my $stored_folderpath='docs_folderpath';
4171: if ($supplementalflag) {
4172: $stored_folderpath='docs_sup_folderpath';
4173: }
4174:
4175: # No folderpath, and in edit mode, see if we have something stored
4176: if ((!$env{'form.folderpath'}) && $allowed) {
4177: &Apache::loncommon::restore_course_settings($stored_folderpath,
4178: {'folderpath' => 'scalar'});
4179: unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
4180: undef($env{'form.folderpath'});
4181: }
4182: }
4183:
4184: # If we are not allowed to make changes, all we can see are supplemental docs
4185: if (!$allowed) {
4186: unless ($env{'form.folderpath'} =~ /^supplemental/) {
4187: $env{'form.folderpath'} = &supplemental_base();
4188: }
4189: }
4190: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
4191: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
4192: $env{'form.folderpath'} = &supplemental_base()
4193: .'&'.
4194: $env{'form.folderpath'};
4195: }
4196: # If after all of this, we still don't have any paths, make them
4197: unless ($env{'form.folderpath'}) {
4198: if ($supplementalflag) {
4199: $env{'form.folderpath'}=&supplemental_base();
4200: } else {
4201: $env{'form.folderpath'}='default'.&escape(&mt('Main '.$crstype.' Content').
4202: ':::::');
4203: }
4204: }
4205:
4206: # Store this
4207: unless ($toolsflag) {
4208: if ($allowed) {
4209: &Apache::loncommon::store_course_settings($stored_folderpath,
4210: {'folderpath' => 'scalar'});
4211: }
4212: my $folderpath;
4213: if ($env{'form.folderpath'}) {
4214: $folderpath = $env{'form.folderpath'};
4215: my (@folders)=split('&',$env{'form.folderpath'});
4216: $env{'form.foldername'}=&unescape(pop(@folders));
4217: if ($env{'form.foldername'} =~ /\:1$/) {
4218: $container = 'page';
4219: } else {
4220: $container = 'sequence';
4221: }
4222: $env{'form.folder'}=pop(@folders);
4223: } else {
4224: if ($env{'form.folder'} eq '' ||
4225: $env{'form.folder'} eq 'supplemental') {
4226: $folderpath='default&'.
4227: &escape(&mt('Main '.$crstype.' Content').':::::');
4228: }
4229: }
4230: $containertag = '<input type="hidden" name="folderpath" value="" />';
4231: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
4232: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
4233: $showdoc='/'.$1;
4234: }
4235: if ($showdoc) { # got called in sequence from course
4236: $allowed=0;
4237: } else {
4238: if ($allowed) {
4239: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
4240: $script=&Apache::lonratedt::editscript('simple');
4241: }
4242: }
4243: }
4244:
4245: # get personal data
4246: my $uname=$env{'user.name'};
4247: my $udom=$env{'user.domain'};
4248: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
4249:
4250: if ($allowed) {
4251: if ($toolsflag) {
4252: $script .= &inject_data_js();
4253: my ($home,$other,%outhash)=&authorhosts();
4254: if (!$home && $other) {
4255: my @hosts;
4256: foreach my $aurole (keys(%outhash)) {
4257: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
4258: push(@hosts,$outhash{$aurole});
4259: }
4260: }
4261: $script .= &dump_switchserver_js(@hosts);
4262: }
4263: } else {
4264: my @tabids;
4265: if ($supplementalflag) {
4266: @tabids = ('002','ee2','ff2');
4267: } else {
4268: @tabids = ('aa1','bb1','cc1','ff1');
4269: unless ($env{'form.folderpath'} =~ /\:1$/) {
4270: unshift(@tabids,'001');
4271: push(@tabids,('dd1','ee1'));
4272: }
4273: }
4274: my $tabidstr = join("','",@tabids);
4275: $script .= &editing_js($udom,$uname,$supplementalflag).
4276: &history_tab_js().
4277: &inject_data_js().
4278: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr).
4279: &Apache::lonextresedit::extedit_javascript();
4280: $addentries = {
4281: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
4282: };
4283: }
4284: $script .= &paste_popup_js();
4285: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
4286: &mt('Switch server?');
4287:
4288:
4289: }
4290: # -------------------------------------------------------------------- Body tag
4291: $script = '<script type="text/javascript">'."\n"
4292: .'// <![CDATA['."\n"
4293: .$script."\n"
4294: .'// ]]>'."\n"
4295: .'</script>'."\n";
4296:
4297: # Breadcrumbs
4298: &Apache::lonhtmlcommon::clear_breadcrumbs();
4299:
4300: if ($showdoc) {
4301: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
4302: {'force_register' => $showdoc,}));
4303: } elsif ($r->uri eq '/adm/supplemental') {
4304: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
4305: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
4306: {'bread_crumbs' => $brcrum,}));
4307: } else {
4308: &Apache::lonhtmlcommon::add_breadcrumb({
4309: href=>"/adm/coursedocs",text=>"$crstype Contents"});
4310: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
4311: {'add_entries' => $addentries}
4312: )
4313: .&Apache::loncommon::help_open_menu('','',273,'RAT')
4314: .&Apache::lonhtmlcommon::breadcrumbs(
4315: 'Editing '.$crstype.' Contents',
4316: 'Docs_Adding_Course_Doc')
4317: );
4318: }
4319:
4320: my %allfiles = ();
4321: my %codebase = ();
4322: my ($upload_result,$upload_output,$uploadphase);
4323: if ($allowed) {
4324: if (($env{'form.uploaddoc.filename'}) &&
4325: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
4326: my $context = $1;
4327: # Process file upload - phase one - upload and parse primary file.
4328: undef($hadchanges);
4329: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
4330: \%allfiles,\%codebase,$context);
4331: if ($hadchanges) {
4332: &mark_hash_old();
4333: }
4334: $r->print($upload_output);
4335: } elsif ($env{'form.phase'} eq 'upload_embedded') {
4336: # Process file upload - phase two - upload embedded objects
4337: $uploadphase = 'check_embedded';
4338: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
4339: my $state = &embedded_form_elems($uploadphase,$primaryurl,
4340: $env{'form.newidx'});
4341: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4342: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4343: my ($destination,$dir_root) = &embedded_destination();
4344: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
4345: my $actionurl = '/adm/coursedocs';
4346: my ($result,$flag) =
4347: &Apache::loncommon::upload_embedded('coursedoc',$destination,
4348: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
4349: $actionurl);
4350: $r->print($result.&return_to_editor());
4351: } elsif ($env{'form.phase'} eq 'check_embedded') {
4352: # Process file upload - phase three - modify references in HTML file
4353: $uploadphase = 'modified_orightml';
4354: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4355: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4356: my ($destination,$dir_root) = &embedded_destination();
4357: my $result =
4358: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
4359: $docuname,$docudom,undef,
4360: $dir_root);
4361: $r->print($result.&return_to_editor());
4362: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
4363: $uploadphase = 'decompress_phase_one';
4364: $r->print(&decompression_phase_one().
4365: &return_to_editor());
4366: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
4367: $uploadphase = 'decompress_phase_two';
4368: $r->print(&decompression_phase_two().
4369: &return_to_editor());
4370: }
4371: }
4372:
4373: if ($allowed && $toolsflag) {
4374: $r->print(&startContentScreen('tools'));
4375: $r->print(&generate_admin_menu($crstype));
4376: $r->print(&endContentScreen());
4377: } elsif ((!$showdoc) && (!$uploadphase)) {
4378: # -----------------------------------------------------------------------------
4379: my %lt=&Apache::lonlocal::texthash(
4380: 'copm' => 'All documents out of a published map into this folder',
4381: 'upfi' => 'Upload File',
4382: 'upld' => 'Import Content',
4383: 'srch' => 'Search',
4384: 'impo' => 'Import',
4385: 'lnks' => 'Import from Stored Links',
4386: 'impm' => 'Import from Assembled Map',
4387: 'selm' => 'Select Map',
4388: 'load' => 'Load Map',
4389: 'newf' => 'New Folder',
4390: 'newp' => 'New Composite Page',
4391: 'syll' => 'Syllabus',
4392: 'navc' => 'Table of Contents',
4393: 'sipa' => 'Simple Course Page',
4394: 'sipr' => 'Simple Problem',
4395: 'webp' => 'Blank Web Page (editable)',
4396: 'drbx' => 'Drop Box',
4397: 'scuf' => 'External Scores (handgrade, upload, clicker)',
4398: 'bull' => 'Discussion Board',
4399: 'mypi' => 'My Personal Information Page',
4400: 'grpo' => 'Group Portfolio',
4401: 'rost' => 'Course Roster',
4402: 'abou' => 'Personal Information Page for a User',
4403: 'imsf' => 'IMS Import',
4404: 'imsl' => 'Import IMS package',
4405: 'cms' => 'Origin of IMS package',
4406: 'se' => 'Select',
4407: 'file' => 'File',
4408: 'title' => 'Title',
4409: 'comment' => 'Comment',
4410: 'parse' => 'Upload embedded images/multimedia files if HTML file',
4411: );
4412: # -----------------------------------------------------------------------------
4413: my $fileupload=(<<FIUP);
4414: $lt{'file'}:<br />
4415: <input type="file" name="uploaddoc" size="40" />
4416: FIUP
4417:
4418: my $checkbox=(<<CHBO);
4419: <!-- <label>$lt{'parse'}?
4420: <input type="checkbox" name="parserflag" />
4421: </label> -->
4422: <label>
4423: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
4424: </label>
4425: CHBO
4426: my $imsfolder = $env{'form.folder'};
4427: if ($imsfolder eq '') {
4428: $imsfolder = 'default';
4429: }
4430: my $imspform=(<<IMSFORM);
4431: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
4432: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
4433: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
4434: <fieldset id="uploadimsform" style="display: none;">
4435: <legend>$lt{'imsf'}</legend>
4436: $fileupload
4437: <br />
4438: <p>
4439: $lt{'cms'}:
4440: <select name="source">
4441: <option value="-1" selected="selected">$lt{'se'}</option>
4442: <option value="bb5">Blackboard 5</option>
4443: <option value="bb6">Blackboard 6</option>
4444: <option value="angel5">ANGEL 5.5</option>
4445: <option value="webctce4">WebCT 4 Campus Edition</option>
4446: </select>
4447: <input type="hidden" name="folder" value="$imsfolder" />
4448: </p>
4449: <input type="hidden" name="phase" value="one" />
4450: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" />
4451: </fieldset>
4452: </form>
4453: IMSFORM
4454:
4455: my $fileuploadform=(<<FUFORM);
4456: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
4457: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
4458: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
4459: <fieldset id="uploaddocform" style="display: none;">
4460: <legend>$lt{'upfi'}</legend>
4461: <input type="hidden" name="active" value="aa" />
4462: $fileupload
4463: <br />
4464: $lt{'title'}:<br />
4465: <input type="text" size="60" name="comment" />
4466: $pathitem
4467: <input type="hidden" name="cmd" value="upload_default" />
4468: <br />
4469: <span class="LC_nobreak" style="float:left">
4470: $checkbox
4471: </span>
4472: <br clear="all" />
4473: <input type="submit" value="$lt{'upld'}" />
4474: </fieldset>
4475: </form>
4476: FUFORM
4477:
4478: my $importpubform=(<<SEDFFORM);
4479: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
4480: $lt{'impm'}</a>$help{'Load_Map'}
4481: <form action="/adm/coursedocs" method="post" name="mapimportform">
4482: <fieldset id="importmapform" style="display: none;">
4483: <legend>$lt{'impm'}</legend>
4484: <input type="hidden" name="active" value="bb" />
4485: $lt{'copm'}<br />
4486: <span class="LC_nobreak">
4487: <input type="text" name="importmap" size="40" value=""
4488: onfocus="this.blur();openbrowser('mapimportform','importmap','sequence,page','');" />
4489: <a href="javascript:openbrowser('mapimportform','importmap','sequence,page','');">$lt{'selm'}</a></span><br />
4490: <input type="submit" name="loadmap" value="$lt{'load'}" />
4491: </fieldset>
4492: </form>
4493:
4494: SEDFFORM
4495: my @importpubforma = (
4496: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'" onclick="javascript:groupsearch()" />' => $pathitem."<a class='LC_menubuttons_link' href='javascript:groupsearch()'>$lt{'srch'}</a>" },
4497: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'" onclick="javascript:groupimport();"/>' => "<a class='LC_menubuttons_link' href='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
4498: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:open_StoredLinks_Import();" />' => "<a class='LC_menubuttons_link' href='javascript:open_StoredLinks_Import();'>$lt{'lnks'}</a>" },
4499: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
4500: );
4501: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
4502: my $extresourcesform =
4503: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
4504: $help{'Adding_External_Resource'});
4505: if ($allowed) {
4506: my $folder = $env{'form.folder'};
4507: if ($folder eq '') {
4508: $folder='default';
4509: }
4510: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
4511: if ($output) {
4512: $r->print($output);
4513: }
4514: $r->print(<<HIDDENFORM);
4515: <form name="renameform" method="post" action="/adm/coursedocs">
4516: <input type="hidden" name="title" />
4517: <input type="hidden" name="cmd" />
4518: <input type="hidden" name="markcopy" />
4519: <input type="hidden" name="copyfolder" />
4520: $containertag
4521: </form>
4522:
4523: HIDDENFORM
4524: $r->print(&makesimpleeditform($pathitem)."\n".
4525: &makedocslogform($pathitem."\n".
4526: '<input type="hidden" name="folder" value="'.
4527: $env{'form.folder'}.'" />'."\n"));
4528: }
4529:
4530: # Generate the tabs
4531: my ($mode,$needs_end);
4532: if (($supplementalflag) && (!$allowed)) {
4533: my @folders = split('&',$env{'form.folderpath'});
4534: unless (@folders > 2) {
4535: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
4536: $needs_end = 1;
4537: }
4538: } else {
4539: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
4540: $needs_end = 1;
4541: }
4542:
4543: #
4544:
4545: my $savefolderpath;
4546:
4547: if ($allowed) {
4548: my $folder=$env{'form.folder'};
4549: if ($folder eq '' || $supplementalflag) {
4550: $folder='default';
4551: $savefolderpath = $env{'form.folderpath'};
4552: $env{'form.folderpath'}='default&'.&escape(&mt('Content'));
4553: $pathitem = '<input type="hidden" name="folderpath" value="'.
4554: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
4555: }
4556: my $postexec='';
4557: if ($folder eq 'default') {
4558: $r->print('<script type="text/javascript">'."\n"
4559: .'// <![CDATA['."\n"
4560: .'this.window.name="loncapaclient";'."\n"
4561: .'// ]]>'."\n"
4562: .'</script>'."\n"
4563: );
4564: } else {
4565: #$postexec='self.close();';
4566: }
4567: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
4568: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
4569: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
4570:
4571: my $newnavform=(<<NNFORM);
4572: <form action="/adm/coursedocs" method="post" name="newnav">
4573: <input type="hidden" name="active" value="cc" />
4574: $pathitem
4575: <input type="hidden" name="importdetail"
4576: value="$lt{'navc'}=/adm/navmaps" />
4577: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
4578: $help{'Navigate_Content'}
4579: </form>
4580: NNFORM
4581: my $newsmppageform=(<<NSPFORM);
4582: <form action="/adm/coursedocs" method="post" name="newsmppg">
4583: <input type="hidden" name="active" value="cc" />
4584: $pathitem
4585: <input type="hidden" name="importdetail" value="" />
4586: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
4587: $help{'Simple Page'}
4588: </form>
4589: NSPFORM
4590:
4591: my $newsmpproblemform=(<<NSPROBFORM);
4592: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
4593: <input type="hidden" name="active" value="cc" />
4594: $pathitem
4595: <input type="hidden" name="importdetail" value="" />
4596: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
4597: $help{'Simple Problem'}
4598: </form>
4599:
4600: NSPROBFORM
4601:
4602: my $newdropboxform=(<<NDBFORM);
4603: <form action="/adm/coursedocs" method="post" name="newdropbox">
4604: <input type="hidden" name="active" value="cc" />
4605: $pathitem
4606: <input type="hidden" name="importdetail" value="" />
4607: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
4608: </form>
4609: NDBFORM
4610:
4611: my $newexuploadform=(<<NEXUFORM);
4612: <form action="/adm/coursedocs" method="post" name="newexamupload">
4613: <input type="hidden" name="active" value="cc" />
4614: $pathitem
4615: <input type="hidden" name="importdetail" value="" />
4616: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
4617: $help{'Score_Upload_Form'}
4618: </form>
4619: NEXUFORM
4620:
4621: my $newbulform=(<<NBFORM);
4622: <form action="/adm/coursedocs" method="post" name="newbul">
4623: <input type="hidden" name="active" value="cc" />
4624: $pathitem
4625: <input type="hidden" name="importdetail" value="" />
4626: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
4627: $help{'Bulletin Board'}
4628: </form>
4629: NBFORM
4630:
4631: my $newaboutmeform=(<<NAMFORM);
4632: <form action="/adm/coursedocs" method="post" name="newaboutme">
4633: <input type="hidden" name="active" value="cc" />
4634: $pathitem
4635: <input type="hidden" name="importdetail"
4636: value="$plainname=/adm/$udom/$uname/aboutme" />
4637: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
4638: $help{'My Personal Information Page'}
4639: </form>
4640: NAMFORM
4641:
4642: my $newaboutsomeoneform=(<<NASOFORM);
4643: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
4644: <input type="hidden" name="active" value="cc" />
4645: $pathitem
4646: <input type="hidden" name="importdetail" value="" />
4647: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
4648: </form>
4649: NASOFORM
4650:
4651: my $newrosterform=(<<NROSTFORM);
4652: <form action="/adm/coursedocs" method="post" name="newroster">
4653: <input type="hidden" name="active" value="cc" />
4654: $pathitem
4655: <input type="hidden" name="importdetail"
4656: value="$lt{'rost'}=/adm/viewclasslist" />
4657: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
4658: $help{'Course Roster'}
4659: </form>
4660: NROSTFORM
4661:
4662: my $newwebpage;
4663: if ($folder =~ /^default_?(\d*)$/) {
4664: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
4665: if ($1) {
4666: $newwebpage .= $1;
4667: } else {
4668: $newwebpage .= 'default';
4669: }
4670: $newwebpage .= '/new.html';
4671: }
4672: my $newwebpageform =(<<NWEBFORM);
4673: <form action="/adm/coursedocs" method="post" name="newwebpage">
4674: <input type="hidden" name="active" value="cc" />
4675: $pathitem
4676: <input type="hidden" name="importdetail" value="$newwebpage" />
4677: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
4678: $help{'Web Page'}
4679: </form>
4680: NWEBFORM
4681:
4682:
4683: my $specialdocumentsform;
4684: my @specialdocumentsforma;
4685: my $gradingform;
4686: my @gradingforma;
4687: my $communityform;
4688: my @communityforma;
4689: my $newfolderform;
4690: my $newfolderb;
4691:
4692: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4693:
4694: my $newpageform=(<<NPFORM);
4695: <form action="/adm/coursedocs" method="post" name="newpage">
4696: <input type="hidden" name="folderpath" value="$path" />
4697: <input type="hidden" name="importdetail" value="" />
4698: <input type="hidden" name="active" value="cc" />
4699: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
4700: $help{'Adding_Pages'}
4701: </form>
4702: NPFORM
4703:
4704:
4705: $newfolderform=(<<NFFORM);
4706: <form action="/adm/coursedocs" method="post" name="newfolder">
4707: $pathitem
4708: <input type="hidden" name="importdetail" value="" />
4709: <input type="hidden" name="active" value="aa" />
4710: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
4711: </form>
4712: NFFORM
4713:
4714: my $newsylform=(<<NSYLFORM);
4715: <form action="/adm/coursedocs" method="post" name="newsyl">
4716: <input type="hidden" name="active" value="cc" />
4717: $pathitem
4718: <input type="hidden" name="importdetail"
4719: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
4720: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
4721: $help{'Syllabus'}
4722:
4723: </form>
4724: NSYLFORM
4725:
4726: my $newgroupfileform=(<<NGFFORM);
4727: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
4728: <input type="hidden" name="active" value="cc" />
4729: $pathitem
4730: <input type="hidden" name="importdetail"
4731: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
4732: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
4733: $help{'Group Portfolio'}
4734: </form>
4735: NGFFORM
4736: @specialdocumentsforma=(
4737: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
4738: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
4739: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
4740: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
4741: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
4742: );
4743: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
4744:
4745:
4746: my @importdoc = (
4747: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
4748: );
4749: unless ($container eq 'page') {
4750: push(@importdoc,
4751: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
4752: );
4753: }
4754: push(@importdoc,
4755: {'<img class="LC_noBorder_LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
4756: );
4757: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
4758:
4759: @gradingforma=(
4760: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
4761: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
4762: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
4763:
4764: );
4765: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
4766:
4767: @communityforma=(
4768: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
4769: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
4770: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
4771: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
4772: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
4773: );
4774: $communityform = &create_form_ul(&create_list_elements(@communityforma));
4775:
4776: my %orderhash = (
4777: 'aa' => ['Import Content',$fileuploadform],
4778: 'bb' => ['Published Content',$importpubform],
4779: 'cc' => ['Grading Resources',$gradingform],
4780: );
4781: unless ($container eq 'page') {
4782: $orderhash{'00'} = ['Newfolder',$newfolderform];
4783: $orderhash{'dd'} = ['Collaboration',$communityform];
4784: $orderhash{'ee'} = ['Special Pages',$specialdocumentsform];
4785: }
4786:
4787: $hadchanges=0;
4788: unless (($supplementalflag || $toolsflag)) {
4789: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
4790: $supplementalflag,\%orderhash,$iconpath,$pathitem);
4791: if ($error) {
4792: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
4793: }
4794: if ($hadchanges) {
4795: &mark_hash_old();
4796: }
4797:
4798: &changewarning($r,'');
4799: }
4800: }
4801:
4802: # Supplemental documents start here
4803:
4804: my $folder=$env{'form.folder'};
4805: unless ($supplementalflag) {
4806: $folder='supplemental';
4807: }
4808: if ($folder =~ /^supplemental$/ &&
4809: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
4810: $env{'form.folderpath'} = &supplemental_base();
4811: } elsif ($allowed) {
4812: $env{'form.folderpath'} = $savefolderpath;
4813: }
4814: $pathitem = '<input type="hidden" name="folderpath" value="'.
4815: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
4816: if ($allowed) {
4817: my $folderseq=
4818: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
4819:
4820: my $supupdocform=(<<SUPDOCFORM);
4821: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
4822: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
4823: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
4824: <fieldset id="uploadsuppdocform" style="display: none;">
4825: <legend>$lt{'upfi'}</legend>
4826: <input type="hidden" name="active" value="ee" />
4827: $fileupload
4828: <br />
4829: <br />
4830: <span class="LC_nobreak">
4831: $checkbox
4832: </span>
4833: <br /><br />
4834: $lt{'comment'}:<br />
4835: <textarea cols="50" rows="4" name="comment"></textarea>
4836: <br />
4837: $pathitem
4838: <input type="hidden" name="cmd" value="upload_supplemental" />
4839: <input type='submit' value="$lt{'upld'}" />
4840: </form>
4841: SUPDOCFORM
4842:
4843: my $supnewfolderform=(<<SNFFORM);
4844: <form action="/adm/coursedocs" method="post" name="supnewfolder">
4845: <input type="hidden" name="active" value="ee" />
4846: $pathitem
4847: <input type="hidden" name="importdetail" value="" />
4848: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
4849: $help{'Adding_Folders'}
4850: </form>
4851: SNFFORM
4852:
4853: my $supextform =
4854: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
4855: $help{'Adding_External_Resource'});
4856:
4857: my $supnewsylform=(<<SNSFORM);
4858: <form action="/adm/coursedocs" method="post" name="supnewsyl">
4859: <input type="hidden" name="active" value="ff" />
4860: $pathitem
4861: <input type="hidden" name="importdetail"
4862: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
4863: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
4864: $help{'Syllabus'}
4865: </form>
4866: SNSFORM
4867:
4868: my $supnewaboutmeform=(<<SNAMFORM);
4869: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
4870: <input type="hidden" name="active" value="ff" />
4871: $pathitem
4872: <input type="hidden" name="importdetail"
4873: value="$plainname=/adm/$udom/$uname/aboutme" />
4874: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
4875: $help{'My Personal Information Page'}
4876: </form>
4877: SNAMFORM
4878:
4879: my $supwebpage;
4880: if ($folder =~ /^supplemental_?(\d*)$/) {
4881: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
4882: if ($1) {
4883: $supwebpage .= $1;
4884: } else {
4885: $supwebpage .= 'default';
4886: }
4887: $supwebpage .= '/new.html';
4888: }
4889: my $supwebpageform =(<<SWEBFORM);
4890: <form action="/adm/coursedocs" method="post" name="supwebpage">
4891: <input type="hidden" name="active" value="cc" />
4892: $pathitem
4893: <input type="hidden" name="importdetail" value="$supwebpage" />
4894: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
4895: $help{'Web Page'}
4896: </form>
4897: SWEBFORM
4898:
4899:
4900: my @specialdocs = (
4901: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
4902: =>$supnewsylform},
4903: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
4904: =>$supnewaboutmeform},
4905: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
4906:
4907: );
4908: my @supimportdoc = (
4909: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
4910: =>$supextform},
4911: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
4912: =>$supupdocform},
4913: );
4914:
4915: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
4916: my %suporderhash = (
4917: '00' => ['Supnewfolder', $supnewfolderform],
4918: 'ee' => ['Import Content',$supupdocform],
4919: 'ff' => ['Special Pages',&create_form_ul(&create_list_elements(@specialdocs))]
4920: );
4921: if ($supplementalflag) {
4922: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
4923: $supplementalflag,\%suporderhash,$iconpath,$pathitem);
4924: if ($error) {
4925: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
4926: }
4927: }
4928: } elsif ($supplementalflag) {
4929: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
4930: $supplementalflag,'',$iconpath,$pathitem);
4931: if ($error) {
4932: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
4933: }
4934: }
4935:
4936: if ($needs_end) {
4937: $r->print(&endContentScreen());
4938: }
4939:
4940: if ($allowed) {
4941: $r->print('
4942: <form method="post" name="extimport" action="/adm/coursedocs">
4943: <input type="hidden" name="title" />
4944: <input type="hidden" name="url" />
4945: <input type="hidden" name="useform" />
4946: <input type="hidden" name="residx" />
4947: </form>');
4948: }
4949: } elsif ($showdoc) {
4950: # -------------------------------------------------------- This is showdoc mode
4951: $r->print("<h1>".&mt('Uploaded Document').' - '.
4952: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
4953: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
4954: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
4955: }
4956: }
4957: $r->print(&Apache::loncommon::end_page());
4958: return OK;
4959: }
4960:
4961: sub embedded_form_elems {
4962: my ($phase,$primaryurl,$newidx) = @_;
4963: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4964: return <<STATE;
4965: <input type="hidden" name="folderpath" value="$folderpath" />
4966: <input type="hidden" name="cmd" value="upload_embedded" />
4967: <input type="hidden" name="newidx" value="$newidx" />
4968: <input type="hidden" name="phase" value="$phase" />
4969: <input type="hidden" name="primaryurl" value="$primaryurl" />
4970: STATE
4971: }
4972:
4973: sub embedded_destination {
4974: my $folder=$env{'form.folder'};
4975: my $destination = 'docs/';
4976: if ($folder =~ /^supplemental/) {
4977: $destination = 'supplemental/';
4978: }
4979: if (($folder eq 'default') || ($folder eq 'supplemental')) {
4980: $destination .= 'default/';
4981: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
4982: $destination .= $2.'/';
4983: }
4984: $destination .= $env{'form.newidx'};
4985: my $dir_root = '/userfiles';
4986: return ($destination,$dir_root);
4987: }
4988:
4989: sub return_to_editor {
4990: my $actionurl = '/adm/coursedocs';
4991: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
4992: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
4993: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
4994: '</a></p>';
4995: }
4996:
4997: sub decompression_info {
4998: my ($destination,$dir_root) = &embedded_destination();
4999: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
5000: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5001: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5002: my $container='sequence';
5003: my ($pathitem,$hiddenelem);
5004: my @hiddens = ('newidx','comment','position','folderpath');
5005: if ($env{'form.folderpath'} =~ /\:1$/) {
5006: $container='page';
5007: }
5008: unshift(@hiddens,$pathitem);
5009: foreach my $item (@hiddens) {
5010: if ($env{'form.'.$item}) {
5011: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
5012: $env{'form.'.$item}.'" />'."\n";
5013: }
5014: }
5015: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
5016: $hiddenelem);
5017: }
5018:
5019: sub decompression_phase_one {
5020: my ($dir,$file,$warning,$error,$output);
5021: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5022: &decompression_info();
5023: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
5024: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
5025: } else {
5026: my $file = $1;
5027: $output =
5028: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
5029: $destination,$dir_root,
5030: $hiddenelem);
5031: if ($env{'form.autoextract_camtasia'}) {
5032: $output .= &remove_archive($docudom,$docuname,$container);
5033: }
5034: }
5035: if ($error) {
5036: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
5037: $error.'</p>'."\n";
5038: }
5039: if ($warning) {
5040: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
5041: }
5042: return $output;
5043: }
5044:
5045: sub decompression_phase_two {
5046: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5047: &decompression_info();
5048: my $output;
5049: if ($env{'form.archivedelete'}) {
5050: $output = &remove_archive($docudom,$docuname,$container);
5051: }
5052: $output .=
5053: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
5054: $destination,$dir_root,$hiddenelem);
5055: return $output;
5056: }
5057:
5058: sub remove_archive {
5059: my ($docudom,$docuname,$container) = @_;
5060: my $map = $env{'form.folder'}.'.'.$container;
5061: my ($output,$delwarning,$delresult,$url);
5062: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
5063: if ($fatal) {
5064: if ($container eq 'page') {
5065: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
5066: } else {
5067: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
5068: }
5069: $delwarning .= &mt('As a result the archive file has not been removed.');
5070: } else {
5071: my $currcmd = $env{'form.cmd'};
5072: my $position = $env{'form.position'};
5073: if ($position > 0) {
5074: $env{'form.cmd'} = 'del_'.$position;
5075: my ($title,$url,@rrest) =
5076: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
5077: if (&handle_edit_cmd($docuname,$docudom)) {
5078: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
5079: if ($fatal) {
5080: if ($container eq 'page') {
5081: $delwarning = &mt('An error occurred updating the contents of the current page.');
5082: } else {
5083: $delwarning = &mt('An error occurred updating the contents of the current folder.');
5084: }
5085: } else {
5086: $delresult = &mt('Archive file removed.');
5087: }
5088: }
5089: }
5090: $env{'form.cmd'} = $currcmd;
5091: }
5092: if ($delwarning) {
5093: $output = '<p class="LC_warning">'.
5094: $delwarning.
5095: '</p>';
5096: }
5097: if ($delresult) {
5098: $output .= '<p class="LC_info">'.
5099: $delresult.
5100: '</p>';
5101: }
5102: return $output;
5103: }
5104:
5105: sub generate_admin_menu {
5106: my ($crstype) = @_;
5107: my $lc_crstype = lc($crstype);
5108: my ($home,$other,%outhash)=&authorhosts();
5109: my %lt=&Apache::lonlocal::texthash (
5110: 'vc' => 'Verify Content',
5111: 'cv' => 'Check/Set Resource Versions',
5112: 'ls' => 'List Resource Identifiers',
5113: 'imse' => 'Export contents to IMS Archive',
5114: 'dcd' => "Dump $crstype Content to Authoring Space",
5115: );
5116: my ($candump,$dumpurl);
5117: if ($home + $other > 0) {
5118: $candump = 'F';
5119: if ($home) {
5120: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
5121: } else {
5122: my @hosts;
5123: foreach my $aurole (keys(%outhash)) {
5124: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5125: push(@hosts,$outhash{$aurole});
5126: }
5127: }
5128: if (@hosts == 1) {
5129: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
5130: '&role='.
5131: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
5132: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
5133: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
5134: } else {
5135: $dumpurl = "javascript:choose_switchserver_window()";
5136: }
5137: }
5138: }
5139: my @menu=
5140: ({ categorytitle=>'Administration',
5141: items =>[
5142: { linktext => $lt{'vc'},
5143: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
5144: permission => 'F',
5145: help => 'Verify_Content',
5146: icon => 'verify.png',
5147: linktitle => 'Verify contents can be retrieved/rendered',
5148: },
5149: { linktext => $lt{'cv'},
5150: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
5151: permission => 'F',
5152: help => 'Check_Resource_Versions',
5153: icon => 'resversion.png',
5154: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
5155: },
5156: { linktext => $lt{'ls'},
5157: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
5158: permission => 'F',
5159: #help => '',
5160: icon => 'symbs.png',
5161: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
5162: },
5163: ]
5164: },
5165: { categorytitle=>'Export',
5166: items =>[
5167: { linktext => $lt{'imse'},
5168: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
5169: permission => 'F',
5170: help => 'Docs_Export_Course_Docs',
5171: icon => 'imsexport.png',
5172: linktitle => $lt{'imse'},
5173: },
5174: { linktext => $lt{'dcd'},
5175: url => $dumpurl,
5176: permission => $candump,
5177: #help => '',
5178: icon => 'dump.png',
5179: linktitle => $lt{'dcd'},
5180: },
5181: ]
5182: });
5183: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
5184: '<input type="hidden" id="dummy" />'."\n".
5185: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
5186: '</form>';
5187: }
5188:
5189: sub generate_edit_table {
5190: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
5191: $need_save,$copyfolder) = @_;
5192: return unless(ref($orderhash_ref) eq 'HASH');
5193: my %orderhash = %{$orderhash_ref};
5194: my $form;
5195: my $activetab;
5196: my $active;
5197: if (($env{'form.active'} ne '') && ($env{'form.active'} ne 'aa')) {
5198: $activetab = $env{'form.active'};
5199: }
5200: my $backicon = $iconpath.'clickhere.gif';
5201: my $backtext = &mt('Exit Editor');
5202: $form = '<div class="LC_Box" style="margin:0;">'.
5203: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
5204: '<li class="goback">'.
5205: '<a href="javascript:toContents('.$jumpto.');">'.
5206: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
5207: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
5208: '<li>'.
5209: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
5210: &mt('Undo Delete').'</a></li>'."\n";
5211: if ($env{'form.docslog'}) {
5212: $form .= '<li class="active">';
5213: } else {
5214: $form .= '<li>';
5215: }
5216: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
5217: &mt('History').'</a></li>'."\n";
5218: if ($env{'form.docslog'}) {
5219: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
5220: &mt('Edit').'</a></li>'."\n";
5221: }
5222: foreach my $name (reverse(sort(keys(%orderhash)))) {
5223: if($name ne '00'){
5224: if($activetab eq '' || $activetab ne $name){
5225: $active = '';
5226: }elsif($activetab eq $name){
5227: $active = 'class="active"';
5228: }
5229: $form .= '<li style="float:right" '.$active
5230: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
5231: } else {
5232: $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
5233:
5234: }
5235: }
5236: $form .= '</ul>'."\n";
5237: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
5238:
5239: if ($to_show ne '') {
5240: my $saveform;
5241: if ($need_save) {
5242: my $button = &mt('Make changes');
5243: my $path;
5244: if ($env{'form.folderpath'}) {
5245: $path =
5246: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5247: }
5248: $saveform = <<"END";
5249: <div id="multisave" style="display:none; clear:both;" >
5250: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
5251: <input type="hidden" name="folderpath" value="$path" />
5252: <input type="hidden" name="symb" value="$env{'form.symb'}" />
5253: <input type="hidden" name="allhiddenresource" value="" />
5254: <input type="hidden" name="allencrypturl" value="" />
5255: <input type="hidden" name="allrandompick" value="" />
5256: <input type="hidden" name="allrandomorder" value="" />
5257: <input type="hidden" name="changeparms" value="" />
5258: <input type="hidden" name="multiremove" value="" />
5259: <input type="hidden" name="multicut" value="" />
5260: <input type="hidden" name="multicopy" value="" />
5261: <input type="hidden" name="multichange" value="" />
5262: <input type="hidden" name="copyfolder" value="$copyfolder" />
5263: <input type="submit" name="savemultiples" value="$button" />
5264: </form>
5265: </div>
5266: END
5267: }
5268: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
5269: }
5270: foreach my $field (keys(%orderhash)){
5271: if($field ne '00'){
5272: if($activetab eq '' || $activetab ne $field){
5273: $active = 'style="display: none;float:left"';
5274: }elsif($activetab eq $field){
5275: $active = 'style="display:block;float:left"';
5276: }
5277: $form .= '<div id="'.$field.$tid.'"'
5278: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
5279: .'</div>'."\n";
5280: }
5281: }
5282: unless ($env{'form.docslog'}) {
5283: $form .= '</div></div>'."\n";
5284: }
5285: return $form;
5286: }
5287:
5288: sub editing_js {
5289: my ($udom,$uname,$supplementalflag) = @_;
5290: my %lt = &Apache::lonlocal::texthash(
5291: p_mnf => 'Name of New Folder',
5292: t_mnf => 'New Folder',
5293: p_mnp => 'Name of New Page',
5294: t_mnp => 'New Page',
5295: p_mxu => 'Title for the External Score',
5296: p_msp => 'Name of Simple Course Page',
5297: p_msb => 'Title for the Problem',
5298: p_mdb => 'Title for the Drop Box',
5299: p_mbb => 'Title for the Discussion Board',
5300: p_mwp => 'Title for Web Page',
5301: p_mab => "Enter user:domain for User's Personal Information Page",
5302: p_mab2 => 'Personal Information Page of ',
5303: p_mab_alrt1 => 'Not a valid user:domain',
5304: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
5305: p_chn => 'New Title',
5306: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
5307: p_rmr2a => 'Remove[_99]',
5308: p_rmr2b => '?[_99]',
5309: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
5310: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
5311: p_ctr2a => 'Cut[_98]',
5312: p_ctr2b => '?[_98]',
5313: rpck => 'Enter number to pick (e.g., 3)',
5314: imsfile => 'You must choose an IMS package for import',
5315: imscms => 'You must select which Course Management System was the source of the IMS package',
5316: invurl => 'Invalid URL',
5317: titbl => 'Title is blank',
5318: more => '(More ...)',
5319: less => '(Less ...)',
5320: );
5321:
5322: my $crstype = &Apache::loncommon::course_type();
5323: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
5324: my $main_container_page;
5325: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
5326: $main_container_page = 1;
5327: }
5328: my $toplevelmain =
5329: &escape(&mt('Main '.$crstype.' Content').':::::');
5330: my $toplevelsupp = &supplemental_base();
5331:
5332: my $backtourl;
5333: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
5334: my $caller = $1;
5335: if ($caller =~ /^supplemental/) {
5336: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
5337: } else {
5338: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
5339: $res = &Apache::lonnet::clutter($res);
5340: if (&Apache::lonnet::is_on_map($res)) {
5341: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($res),'<>&"').'?symb='.
5342: &HTML::Entities::encode($caller,'<>&"');
5343: }
5344: }
5345: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
5346: $backtourl = '/adm/menu';
5347: } elsif ($supplementalflag) {
5348: $backtourl = '/adm/supplemental';
5349: } else {
5350: $backtourl = '/adm/navmaps';
5351: }
5352:
5353: my $fieldsets = "'ext','doc'";
5354: unless ($main_container_page) {
5355: $fieldsets .=",'ims'";
5356: }
5357: if ($supplementalflag) {
5358: $fieldsets = "'suppext','suppdoc'";
5359: }
5360:
5361: return <<ENDNEWSCRIPT;
5362: function makenewfolder(targetform,folderseq) {
5363: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
5364: if (foldername) {
5365: targetform.importdetail.value=escape(foldername)+"="+folderseq;
5366: targetform.submit();
5367: }
5368: }
5369:
5370: function makenewpage(targetform,folderseq) {
5371: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
5372: if (pagename) {
5373: targetform.importdetail.value=escape(pagename)+"="+folderseq;
5374: targetform.submit();
5375: }
5376: }
5377:
5378: function makeexamupload() {
5379: var title=prompt('$lt{"p_mxu"}');
5380: if (title) {
5381: this.document.forms.newexamupload.importdetail.value=
5382: escape(title)+'=/res/lib/templates/examupload.problem';
5383: this.document.forms.newexamupload.submit();
5384: }
5385: }
5386:
5387: function makesmppage() {
5388: var title=prompt('$lt{"p_msp"}');
5389: if (title) {
5390: this.document.forms.newsmppg.importdetail.value=
5391: escape(title)+'=/adm/$udom/$uname/new/smppg';
5392: this.document.forms.newsmppg.submit();
5393: }
5394: }
5395:
5396: function makewebpage(type) {
5397: var title=prompt('$lt{"p_mwp"}');
5398: var formname;
5399: if (type == 'supp') {
5400: formname = this.document.forms.supwebpage;
5401: } else {
5402: formname = this.document.forms.newwebpage;
5403: }
5404: if (title) {
5405: var webpage = formname.importdetail.value;
5406: formname.importdetail.value = escape(title)+'='+webpage;
5407: formname.submit();
5408: }
5409: }
5410:
5411: function makesmpproblem() {
5412: var title=prompt('$lt{"p_msb"}');
5413: if (title) {
5414: this.document.forms.newsmpproblem.importdetail.value=
5415: escape(title)+'=/res/lib/templates/simpleproblem.problem';
5416: this.document.forms.newsmpproblem.submit();
5417: }
5418: }
5419:
5420: function makedropbox() {
5421: var title=prompt('$lt{"p_mdb"}');
5422: if (title) {
5423: this.document.forms.newdropbox.importdetail.value=
5424: escape(title)+'=/res/lib/templates/DropBox.problem';
5425: this.document.forms.newdropbox.submit();
5426: }
5427: }
5428:
5429: function makebulboard() {
5430: var title=prompt('$lt{"p_mbb"}');
5431: if (title) {
5432: this.document.forms.newbul.importdetail.value=
5433: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
5434: this.document.forms.newbul.submit();
5435: }
5436: }
5437:
5438: function makeabout() {
5439: var user=prompt("$lt{'p_mab'}");
5440: if (user) {
5441: var comp=new Array();
5442: comp=user.split(':');
5443: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
5444: if ((comp[0]) && (comp[1])) {
5445: this.document.forms.newaboutsomeone.importdetail.value=
5446: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
5447: this.document.forms.newaboutsomeone.submit();
5448: } else {
5449: alert("$lt{'p_mab_alrt1'}");
5450: }
5451: } else {
5452: alert("$lt{'p_mab_alrt2'}");
5453: }
5454: }
5455: }
5456:
5457: function toggleUpload(caller) {
5458: var blocks = Array($fieldsets);
5459: for (var i=0; i<blocks.length; i++) {
5460: var disp = 'none';
5461: if (caller == blocks[i]) {
5462: var curr = document.getElementById('upload'+caller+'form').style.display;
5463: if (curr == 'none') {
5464: disp='block';
5465: }
5466: }
5467: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
5468: }
5469: resize_scrollbox('contentscroll','1','1');
5470: return;
5471: }
5472:
5473: function toggleMap(caller) {
5474: var disp = 'none';
5475: if (document.getElementById('importmapform')) {
5476: if (caller == 'map') {
5477: var curr = document.getElementById('importmapform').style.display;
5478: if (curr == 'none') {
5479: disp='block';
5480: }
5481: }
5482: document.getElementById('importmapform').style.display=disp;
5483: resize_scrollbox('contentscroll','1','1');
5484: }
5485: return;
5486: }
5487:
5488: function makeims(imsform) {
5489: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
5490: alert("$lt{'imsfile'}");
5491: return;
5492: }
5493: if (imsform.source.selectedIndex == 0) {
5494: alert("$lt{'imscms'}");
5495: return;
5496: }
5497: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
5498: imsform.submit();
5499: }
5500:
5501: function changename(folderpath,index,oldtitle) {
5502: var title=prompt('$lt{"p_chn"}',oldtitle);
5503: if (title) {
5504: this.document.forms.renameform.markcopy.value='';
5505: this.document.forms.renameform.title.value=title;
5506: this.document.forms.renameform.cmd.value='rename_'+index;
5507: this.document.forms.renameform.folderpath.value=folderpath;
5508: this.document.forms.renameform.submit();
5509: }
5510: }
5511:
5512: function updatePick(targetform,index,caller) {
5513: var pickitem;
5514: var picknumitem;
5515: var picknumtext;
5516: if (index == 'all') {
5517: pickitem = document.getElementById('randompickall');
5518: picknumitem = document.getElementById('rpicknumall');
5519: picknumtext = document.getElementById('rpicktextall');
5520: } else {
5521: pickitem = document.getElementById('randompick_'+index);
5522: picknumitem = document.getElementById('rpicknum_'+index);
5523: picknumtext = document.getElementById('randompicknum_'+index);
5524: }
5525: if (pickitem.checked) {
5526: var picknum=prompt('$lt{"rpck"}',picknumitem.value);
5527: if (picknum == '' || picknum == null) {
5528: if (caller == 'check') {
5529: pickitem.checked=false;
5530: if (index == 'all') {
5531: picknumtext.innerHTML = '';
5532: if (caller == 'link') {
5533: propagateState(targetform,'rpicknum');
5534: }
5535: } else {
5536: checkForSubmit(targetform,'randompick','settings');
5537: }
5538: }
5539: } else {
5540: picknum.toString();
5541: var regexdigit=/^\\d+\$/;
5542: if (regexdigit.test(picknum)) {
5543: picknumitem.value = picknum;
5544: if (index == 'all') {
5545: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
5546: if (caller == 'link') {
5547: propagateState(targetform,'rpicknum');
5548: }
5549: } else {
5550: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
5551: checkForSubmit(targetform,'randompick','settings');
5552: }
5553: } else {
5554: if (caller == 'check') {
5555: if (index == 'all') {
5556: picknumtext.innerHTML = '';
5557: if (caller == 'link') {
5558: propagateState(targetform,'rpicknum');
5559: }
5560: } else {
5561: pickitem.checked=false;
5562: checkForSubmit(targetform,'randompick','settings');
5563: }
5564: }
5565: return;
5566: }
5567: }
5568: } else {
5569: picknumitem.value = '';
5570: picknumtext.innerHTML = '';
5571: if (index == 'all') {
5572: if (caller == 'link') {
5573: propagateState(targetform,'rpicknum');
5574: }
5575: } else {
5576: checkForSubmit(targetform,'randompick','settings');
5577: }
5578: }
5579: }
5580:
5581: function propagateState(form,param) {
5582: if (document.getElementById(param+'all')) {
5583: var setcheck = 0;
5584: var rpick = 0;
5585: if (param == 'rpicknum') {
5586: if (document.getElementById('randompickall')) {
5587: if (document.getElementById('randompickall').checked) {
5588: if (document.getElementById('rpicknumall')) {
5589: rpick = document.getElementById('rpicknumall').value;
5590: }
5591: }
5592: }
5593: } else {
5594: if (document.getElementById(param+'all').checked) {
5595: setcheck = 1;
5596: }
5597: }
5598: var allidxlist;
5599: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
5600: if (document.getElementById('all'+param+'idx')) {
5601: allidxlist = document.getElementById('all'+param+'idx').value;
5602: }
5603: var actions = new Array ('remove','cut','copy');
5604: for (var i=0; i<actions.length; i++) {
5605: if (actions[i] != param) {
5606: if (document.getElementById(actions[i]+'all')) {
5607: document.getElementById(actions[i]+'all').checked = false;
5608: }
5609: }
5610: }
5611: }
5612: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
5613: allidxlist = form.allidx.value;
5614: }
5615: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
5616: allidxlist = form.allmapidx.value;
5617: }
5618: if ((allidxlist != '') && (allidxlist != null)) {
5619: var allidxs = allidxlist.split(',');
5620: if (allidxs.length > 1) {
5621: for (var i=0; i<allidxs.length; i++) {
5622: if (document.getElementById(param+'_'+allidxs[i])) {
5623: if (param == 'rpicknum') {
5624: if (document.getElementById('randompick_'+allidxs[i])) {
5625: if (document.getElementById('randompick_'+allidxs[i]).checked) {
5626: document.getElementById(param+'_'+allidxs[i]).value = rpick;
5627: if (rpick > 0) {
5628: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
5629: } else {
5630: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
5631: }
5632: }
5633: }
5634: } else {
5635: if (setcheck == 1) {
5636: document.getElementById(param+'_'+allidxs[i]).checked = true;
5637: } else {
5638: document.getElementById(param+'_'+allidxs[i]).checked = false;
5639: if (param == 'randompick') {
5640: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
5641: }
5642: }
5643: }
5644: }
5645: }
5646: if (setcheck == 1) {
5647: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
5648: var actions = new Array('copy','cut','remove');
5649: for (var i=0; i<actions.length; i++) {
5650: var otheractions;
5651: var otheridxs;
5652: if (actions[i] === param) {
5653: continue;
5654: } else {
5655: if (document.getElementById('all'+actions[i]+'idx')) {
5656: otheractions = document.getElementById('all'+actions[i]+'idx').value;
5657: otheridxs = otheractions.split(',');
5658: if (otheridxs.length > 1) {
5659: for (var j=0; j<otheridxs.length; j++) {
5660: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
5661: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
5662: }
5663: }
5664: }
5665: }
5666: }
5667: }
5668: }
5669: }
5670: }
5671: }
5672: }
5673: return;
5674: }
5675:
5676: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder) {
5677: var dosettings;
5678: var doaction;
5679: var control = document.togglemultsettings;
5680: if (context == 'actions') {
5681: control = document.togglemultactions;
5682: doaction = 1;
5683: } else {
5684: dosettings = 1;
5685: }
5686: if (control) {
5687: if (control.showmultpick.length) {
5688: for (var i=0; i<control.showmultpick.length; i++) {
5689: if (control.showmultpick[i].checked) {
5690: if (control.showmultpick[i].value == 1) {
5691: if (context == 'settings') {
5692: dosettings = 0;
5693: } else {
5694: doaction = 0;
5695: }
5696: }
5697: }
5698: }
5699: }
5700: }
5701: if (context == 'settings') {
5702: if (dosettings == 1) {
5703: targetform.changeparms.value=param;
5704: targetform.submit();
5705: }
5706: }
5707: if (context == 'actions') {
5708: if (doaction == 1) {
5709: targetform.cmd.value=param+'_'+index;
5710: targetform.folderpath.value=folderpath;
5711: targetform.markcopy.value=idx+':'+param;
5712: targetform.copyfolder.value=folder+'.'+container;
5713: if (param == 'remove') {
5714: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
5715: targetform.markcopy.value='';
5716: targetform.copyfolder.value='';
5717: targetform.submit();
5718: }
5719: }
5720: if (param == 'cut') {
5721: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
5722: targetform.submit();
5723: return;
5724: }
5725: }
5726: if (param == 'copy') {
5727: targetform.submit();
5728: return;
5729: }
5730: targetform.markcopy.value='';
5731: targetform.copyfolder.value='';
5732: targetform.cmd.value='';
5733: targetform.folderpath.value='';
5734: return;
5735: } else {
5736: if (document.getElementById(param+'_'+idx)) {
5737: item = document.getElementById(param+'_'+idx);
5738: if (item.type == 'checkbox') {
5739: if (item.checked) {
5740: item.checked = false;
5741: } else {
5742: item.checked = true;
5743: singleCheck(item,idx,param);
5744: }
5745: }
5746: }
5747: }
5748: }
5749: return;
5750: }
5751:
5752: function singleCheck(caller,idx,action) {
5753: actions = new Array('cut','copy','remove');
5754: if (caller.checked) {
5755: for (var i=0; i<actions.length; i++) {
5756: if (actions[i] != action) {
5757: if (document.getElementById(actions[i]+'_'+idx)) {
5758: if (document.getElementById(actions[i]+'_'+idx).checked) {
5759: document.getElementById(actions[i]+'_'+idx).checked = false;
5760: }
5761: }
5762: }
5763: }
5764: }
5765: return;
5766: }
5767:
5768: function unselectInactive(nav) {
5769: currentNav = document.getElementById(nav);
5770: currentLis = currentNav.getElementsByTagName('LI');
5771: for (i = 0; i < currentLis.length; i++) {
5772: if (currentLis[i].className == 'goback') {
5773: currentLis[i].className = 'goback';
5774: } else {
5775: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
5776: currentLis[i].className = 'right';
5777: } else {
5778: currentLis[i].className = 'i';
5779: }
5780: }
5781: }
5782: }
5783:
5784: function hideAll(current, nav, data) {
5785: unselectInactive(nav);
5786: if(current.className == 'right'){
5787: current.className = 'right active'
5788: }else{
5789: current.className = 'active';
5790: }
5791: currentData = document.getElementById(data);
5792: currentDivs = currentData.getElementsByTagName('DIV');
5793: for (i = 0; i < currentDivs.length; i++) {
5794: if(currentDivs[i].className == 'LC_ContentBox'){
5795: currentDivs[i].style.display = 'none';
5796: }
5797: }
5798: }
5799:
5800: function openTabs(pageId) {
5801: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
5802: if(tabnav.length > 2 ){
5803: currentNav = document.getElementById(tabnav[1].id);
5804: currentLis = currentNav.getElementsByTagName('LI');
5805: for(i = 0; i< currentLis.length; i++){
5806: if(currentLis[i].className == 'active') {
5807: funcString = currentLis[i].onclick.toString();
5808: tab = funcString.split('"');
5809: if(tab.length < 2) {
5810: tab = funcString.split("'");
5811: }
5812: currentData = document.getElementById(tab[1]);
5813: currentData.style.display = 'block';
5814: }
5815: }
5816: }
5817: }
5818:
5819: function showPage(current, pageId, nav, data) {
5820: hideAll(current, nav, data);
5821: openTabs(pageId);
5822: unselectInactive(nav);
5823: current.className = 'active';
5824: currentData = document.getElementById(pageId);
5825: currentData.style.display = 'block';
5826: activeTab = pageId;
5827: toggleUpload();
5828: toggleMap();
5829: if (nav == 'mainnav') {
5830: var storedpath = "$docs_folderpath";
5831: var storedpage = "$main_container_page";
5832: var reg = new RegExp("^supplemental");
5833: if (pageId == 'mainCourseDocuments') {
5834: if (storedpage == 1) {
5835: document.simpleedit.folderpath.value = '';
5836: document.uploaddocument.folderpath.value = '';
5837: } else {
5838: if (reg.test(storedpath)) {
5839: document.simpleedit.folderpath.value = '$toplevelmain';
5840: document.uploaddocument.folderpath.value = '$toplevelmain';
5841: document.newext.folderpath.value = '$toplevelmain';
5842: } else {
5843: document.simpleedit.folderpath.value = storedpath;
5844: document.uploaddocument.folderpath.value = storedpath;
5845: document.newext.folderpath.value = storedpath;
5846: }
5847: }
5848: } else {
5849: if (reg.test(storedpath)) {
5850: document.simpleedit.folderpath.value = storedpath;
5851: document.supuploaddocument.folderpath.value = storedpath;
5852: document.supnewext.folderpath.value = storedpath;
5853: } else {
5854: document.simpleedit.folderpath.value = '$toplevelsupp';
5855: document.supuploaddocument.folderpath.value = '$toplevelsupp';
5856: document.supnewext.folderpath.value = '$toplevelsupp';
5857: }
5858: }
5859: }
5860: resize_scrollbox('contentscroll','1','0');
5861: return false;
5862: }
5863:
5864: function toContents(jumpto) {
5865: var newurl = '$backtourl';
5866: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
5867: newurl = newurl+'?postdata='+jumpto;
5868: }
5869: location.href=newurl;
5870: }
5871:
5872: function togglePick(caller,value) {
5873: var disp = 'none';
5874: if (document.getElementById('multi'+caller)) {
5875: var curr = document.getElementById('multi'+caller).style.display;
5876: if (value == 1) {
5877: disp='block';
5878: }
5879: if (curr == disp) {
5880: return;
5881: }
5882: document.getElementById('multi'+caller).style.display=disp;
5883: if (value == 1) {
5884: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$lt{'more'}</a>';
5885: } else {
5886: document.getElementById('more'+caller).innerHTML = '';
5887: }
5888: if (caller == 'actions') {
5889: setClass(value);
5890: setBoxes(value);
5891: }
5892: }
5893: var showButton = multiSettings();
5894: if (showButton != 1) {
5895: showButton = multiActions();
5896: }
5897: if (document.getElementById('multisave')) {
5898: if (showButton == 1) {
5899: document.getElementById('multisave').style.display='block';
5900: } else {
5901: document.getElementById('multisave').style.display='none';
5902: }
5903: }
5904: resize_scrollbox('contentscroll','1','1');
5905: return;
5906: }
5907:
5908: function toggleCheckUncheck(caller,more) {
5909: if (more == 1) {
5910: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$lt{'less'}</a>';
5911: document.getElementById('allfields'+caller).style.display='block';
5912: } else {
5913: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$lt{'more'}</a>';
5914: document.getElementById('allfields'+caller).style.display='none';
5915: }
5916: resize_scrollbox('contentscroll','1','1');
5917: }
5918:
5919: function multiSettings() {
5920: var inuse = 0;
5921: var settingsform = document.togglemultsettings;
5922: if (settingsform.showmultpick.length > 1) {
5923: for (var i=0; i<settingsform.showmultpick.length; i++) {
5924: if (settingsform.showmultpick[i].checked) {
5925: if (settingsform.showmultpick[i].value == 1) {
5926: inuse = 1;
5927: }
5928: }
5929: }
5930: }
5931: return inuse;
5932: }
5933:
5934: function multiActions() {
5935: var inuse = 0;
5936: var actionsform = document.togglemultactions;
5937: if (actionsform.showmultpick.length > 1) {
5938: for (var i=0; i<actionsform.showmultpick.length; i++) {
5939: if (actionsform.showmultpick[i].checked) {
5940: if (actionsform.showmultpick[i].value == 1) {
5941: inuse = 1;
5942: }
5943: }
5944: }
5945: }
5946: return inuse;
5947: }
5948:
5949: function checkSubmits() {
5950: var numchanges = 0;
5951: var form = document.saveactions;
5952: var doactions = multiActions();
5953: if (doactions == 1) {
5954: var remidxlist = document.cumulativeactions.allremoveidx.value;
5955: if ((remidxlist != '') && (remidxlist != null)) {
5956: var remidxs = remidxlist.split(',');
5957: for (var i=0; i<remidxs.length; i++) {
5958: if (document.getElementById('remove_'+remidxs[i])) {
5959: if (document.getElementById('remove_'+remidxs[i]).checked) {
5960: form.multiremove.value += remidxs[i]+',';
5961: numchanges ++;
5962: }
5963: }
5964: }
5965: }
5966: var cutidxlist = document.cumulativeactions.allcutidx.value;
5967: if ((cutidxlist != '') && (cutidxlist != null)) {
5968: var cutidxs = cutidxlist.split(',');
5969: for (var i=0; i<cutidxs.length; i++) {
5970: if (document.getElementById('cut_'+cutidxs[i])) {
5971: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
5972: form.multicut.value += cutidxs[i]+',';
5973: numchanges ++;
5974: }
5975: }
5976: }
5977: }
5978: var copyidxlist = document.cumulativeactions.allcopyidx.value;
5979: if ((copyidxlist != '') && (copyidxlist != null)) {
5980: var copyidxs = copyidxlist.split(',');
5981: for (var i=0; i<copyidxs.length; i++) {
5982: if (document.getElementById('copy_'+copyidxs[i])) {
5983: if (document.getElementById('copy_'+copyidxs[i]).checked) {
5984: form.multicopy.value += copyidxs[i]+',';
5985: numchanges ++;
5986: }
5987: }
5988: }
5989: }
5990: if (numchanges > 0) {
5991: form.multichange.value = numchanges;
5992: }
5993: }
5994: var dosettings = multiSettings();
5995: if (dosettings == 1) {
5996: form.allencrypturl.value = '';
5997: form.allhiddenresource.value = '';
5998: form.changeparms.value = 'all';
5999: var allidxlist = document.cumulativesettings.allidx.value;
6000: if ((allidxlist != '') && (allidxlist != null)) {
6001: var allidxs = allidxlist.split(',');
6002: if (allidxs.length > 1) {
6003: for (var i=0; i<allidxs.length; i++) {
6004: if (document.getElementById('hiddenresource_'+allidxs[i])) {
6005: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
6006: form.allhiddenresource.value += allidxs[i]+',';
6007: }
6008: }
6009: if (document.getElementById('encrypturl_'+allidxs[i])) {
6010: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
6011: form.allencrypturl.value += allidxs[i]+',';
6012: }
6013: }
6014: }
6015: }
6016: }
6017: form.allrandompick.value = '';
6018: form.allrandomorder.value = '';
6019: var allmapidxlist = document.cumulativesettings.allmapidx.value;
6020: if ((allmapidxlist != '') && (allmapidxlist != null)) {
6021: var allmapidxs = allmapidxlist.split(',');
6022: for (var i=0; i<allmapidxs.length; i++) {
6023: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
6024: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
6025: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
6026: if ((randompick.checked) && (rpicknum.value != '')) {
6027: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
6028: }
6029: if (randorder.checked) {
6030: form.allrandomorder.value += allmapidxs[i]+',';
6031: }
6032: }
6033: }
6034: }
6035: if ((numchanges > 0) || (dosettings == 1)) {
6036: form.submit();
6037: return true;
6038: }
6039: return false;
6040: }
6041:
6042: function setClass(value) {
6043: var cutclass = 'LC_docs_cut';
6044: var copyclass = 'LC_docs_copy';
6045: var removeclass = 'LC_docs_remove';
6046: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
6047: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
6048: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
6049: var links = document.getElementsByTagName('a');
6050: for (var i=0; i<links.length; i++) {
6051: var classes = links[i].className;
6052: if (cutreg.test(classes)) {
6053: links[i].className = cutclass;
6054: if (value == 1) {
6055: links[i].className += " LC_menubuttons_link";
6056: }
6057: } else {
6058: if (copyreg.test(classes)) {
6059: links[i].className = copyclass;
6060: if (value == 1) {
6061: links[i].className += " LC_menubuttons_link";
6062: }
6063: } else {
6064: if (removereg.test(classes)) {
6065: links[i].className = removeclass;
6066: if (value == 1) {
6067: links[i].className += " LC_menubuttons_link";
6068: }
6069: }
6070: }
6071: }
6072: }
6073: return;
6074: }
6075:
6076: function setBoxes(value) {
6077: var remidxlist = document.cumulativeactions.allremoveidx.value;
6078: if ((remidxlist != '') && (remidxlist != null)) {
6079: var remidxs = remidxlist.split(',');
6080: for (var i=0; i<remidxs.length; i++) {
6081: if (document.getElementById('remove_'+remidxs[i])) {
6082: var item = document.getElementById('remove_'+remidxs[i]);
6083: if (value == 1) {
6084: item.className = 'LC_docs_remove';
6085: } else {
6086: item.className = 'LC_hidden';
6087: }
6088: }
6089: }
6090: }
6091: var cutidxlist = document.cumulativeactions.allcutidx.value;
6092: if ((cutidxlist != '') && (cutidxlist != null)) {
6093: var cutidxs = cutidxlist.split(',');
6094: for (var i=0; i<cutidxs.length; i++) {
6095: if (document.getElementById('cut_'+cutidxs[i])) {
6096: var item = document.getElementById('cut_'+cutidxs[i]);
6097: if (value == 1) {
6098: item.className = 'LC_docs_cut';
6099: } else {
6100: item.className = 'LC_hidden';
6101: }
6102: }
6103: }
6104: }
6105: var copyidxlist = document.cumulativeactions.allcopyidx.value;
6106: if ((copyidxlist != '') && (copyidxlist != null)) {
6107: var copyidxs = copyidxlist.split(',');
6108: for (var i=0; i<copyidxs.length; i++) {
6109: if (document.getElementById('copy_'+copyidxs[i])) {
6110: var item = document.getElementById('copy_'+copyidxs[i]);
6111: if (value == 1) {
6112: item.className = 'LC_docs_copy';
6113: } else {
6114: item.className = 'LC_hidden';
6115: }
6116: }
6117: }
6118: }
6119: return;
6120: }
6121:
6122: ENDNEWSCRIPT
6123: }
6124:
6125: sub history_tab_js {
6126: return <<"ENDHIST";
6127: function toggleHistoryDisp(choice) {
6128: document.docslogform.docslog.value = choice;
6129: document.docslogform.submit();
6130: return;
6131: }
6132:
6133: ENDHIST
6134: }
6135:
6136: sub inject_data_js {
6137: return <<ENDINJECT;
6138:
6139: function injectData(current, hiddenField, name, value) {
6140: currentElement = document.getElementById(hiddenField);
6141: currentElement.name = name;
6142: currentElement.value = value;
6143: current.submit();
6144: }
6145:
6146: ENDINJECT
6147: }
6148:
6149: sub dump_switchserver_js {
6150: my @hosts = @_;
6151: my %lt = &Apache::lonlocal::texthash(
6152: dump => 'Dumping to Authoring Space requires switching server.',
6153: swit => 'Switch server?',
6154: duco => 'Dump content to Authoring Space',
6155: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
6156: chos => 'Choose server',
6157: );
6158: my $role = $env{'request.role'};
6159: my $js = <<"ENDSWJS";
6160: <script type="text/javascript">
6161: function write_switchserver() {
6162: var server;
6163: if (document.setserver.posshosts.length > 0) {
6164: for (var i=0; i<document.setserver.posshosts.length; i++) {
6165: if (document.setserver.posshosts[i].checked) {
6166: server = document.setserver.posshosts[i].value;
6167: }
6168: }
6169: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
6170: }
6171: window.close();
6172: }
6173: </script>
6174:
6175: ENDSWJS
6176:
6177: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
6178: {'only_body' => 1,
6179: 'js_ready' => 1,});
6180: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
6181:
6182: my $hostpicker;
6183: my $count = 0;
6184: foreach my $host (sort(@hosts)) {
6185: my $checked;
6186: if ($count == 0) {
6187: $checked = ' checked="checked"';
6188: }
6189: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
6190: $host.'"'.$checked.' />'.$host.'</label> ';
6191: $count++;
6192: }
6193:
6194: return <<"ENDSWITCHJS";
6195:
6196: function dump_needs_switchserver(url) {
6197: if (url!='' && url!= null) {
6198: if (confirm("$lt{'dump'}\\n$lt{'swit'}")) {
6199: go(url);
6200: }
6201: }
6202: return;
6203: }
6204:
6205: function choose_switchserver_window() {
6206: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
6207: newWindow.document.open();
6208: newWindow.document.writeln('$startpage');
6209: newWindow.document.write('<h3>$lt{'duco'}<\\/h3>\\n'+
6210: '<p>$lt{'yone'}<\\/p>\\n'+
6211: '<div class="LC_left_float"><fieldset><legend>$lt{'chos'}<\\/legend>\\n'+
6212: '<form name="setserver" method="post" action="" \\/>\\n'+
6213: '$hostpicker\\n'+
6214: '<br \\/><br \\/>\\n'+
6215: '<input type="button" name="makeswitch" value="$lt{'swit'}" '+
6216: 'onclick="write_switchserver();" \\/>\\n'+
6217: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
6218: newWindow.document.writeln('$endpage');
6219: newWindow.document.close();
6220: newWindow.focus();
6221: }
6222:
6223: ENDSWITCHJS
6224: }
6225:
6226: sub makedocslogform {
6227: my ($formelems,$docslog) = @_;
6228: return <<"LOGSFORM";
6229: <form action="/adm/coursedocs" method="post" name="docslogform">
6230: <input type="hidden" name="docslog" value="$docslog" />
6231: $formelems
6232: </form>
6233: LOGSFORM
6234: }
6235:
6236: sub makesimpleeditform {
6237: my ($formelems) = @_;
6238: return <<"SIMPFORM";
6239: <form name="simpleedit" method="post" action="/adm/coursedocs">
6240: <input type="hidden" name="importdetail" value="" />
6241: $formelems
6242: </form>
6243: SIMPFORM
6244: }
6245:
6246: 1;
6247: __END__
6248:
6249:
6250: =head1 NAME
6251:
6252: Apache::londocs.pm
6253:
6254: =head1 SYNOPSIS
6255:
6256: This is part of the LearningOnline Network with CAPA project
6257: described at http://www.lon-capa.org.
6258:
6259: =head1 SUBROUTINES
6260:
6261: =over
6262:
6263: =item %help=()
6264:
6265: Available help topics
6266:
6267: =item mapread()
6268:
6269: Mapread read maps into LONCAPA::map:: global arrays
6270: @order and @resources, determines status
6271: sets @order - pointer to resources in right order
6272: sets @resources - array with the resources with correct idx
6273:
6274: =item authorhosts()
6275:
6276: Return hash with valid author names
6277:
6278: =item clean()
6279:
6280: =item dumpcourse()
6281:
6282: Actually dump course
6283:
6284: =item group_import()
6285:
6286: Imports the given (name, url) resources into the course
6287: coursenum, coursedom, and folder must precede the list
6288:
6289: =item breadcrumbs()
6290:
6291: =item log_docs()
6292:
6293: =item docs_change_log()
6294:
6295: =item update_paste_buffer()
6296:
6297: =item print_paste_buffer()
6298:
6299: =item do_paste_from_buffer()
6300:
6301: =item do_buffer_empty()
6302:
6303: =item clear_from_buffer()
6304:
6305: =item get_newmap_url()
6306:
6307: =item dbcopy()
6308:
6309: =item uniqueness_check()
6310:
6311: =item contained_map_check()
6312:
6313: =item url_paste_fixups()
6314:
6315: =item apply_fixups()
6316:
6317: =item copy_dependencies()
6318:
6319: =item update_parameter()
6320:
6321: =item handle_edit_cmd()
6322:
6323: =item editor()
6324:
6325: =item process_file_upload()
6326:
6327: =item process_secondary_uploads()
6328:
6329: =item is_supplemental_title()
6330:
6331: =item entryline()
6332:
6333: =item tiehash()
6334:
6335: =item untiehash()
6336:
6337: =item checkonthis()
6338:
6339: check on this
6340:
6341: =item verifycontent()
6342:
6343: Verify Content
6344:
6345: =item devalidateversioncache() & checkversions()
6346:
6347: Check Versions
6348:
6349: =item mark_hash_old()
6350:
6351: =item is_hash_old()
6352:
6353: =item changewarning()
6354:
6355: =item init_breadcrumbs()
6356:
6357: Breadcrumbs for special functions
6358:
6359: =item create_list_elements()
6360:
6361: =item create_form_ul()
6362:
6363: =item startContentScreen()
6364:
6365: =item endContentScreen()
6366:
6367: =item supplemental_base()
6368:
6369: =item embedded_form_elems()
6370:
6371: =item embedded_destination()
6372:
6373: =item return_to_editor()
6374:
6375: =item decompression_info()
6376:
6377: =item decompression_phase_one()
6378:
6379: =item decompression_phase_two()
6380:
6381: =item remove_archive()
6382:
6383: =item generate_admin_menu()
6384:
6385: =item generate_edit_table()
6386:
6387: =item editing_js()
6388:
6389: =item history_tab_js()
6390:
6391: =item inject_data_js()
6392:
6393: =item dump_switchserver_js()
6394:
6395: =item resize_scrollbox_js()
6396:
6397: =item makedocslogform()
6398:
6399: =item makesimpleeditform()
6400:
6401: =back
6402:
6403: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>