File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.684:
download - view:
text,
annotated -
select for diffs
Sat Oct 22 17:24:54 2022 UTC (22 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 6975
Code to trigger updates of cached Supplemental Content information for a
course moved from londocs.pm to lonnet.pm to facilitate reuse, and called
after uploading file and/or extracting archive file using Course Editor.
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.684 2022/10/22 17:24:54 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 Apache::lontemplate();
45: use Apache::lonsimplepage();
46: use Apache::lonhomework();
47: use Apache::lonpublisher();
48: use Apache::lonparmset();
49: use Apache::loncourserespicker();
50: use HTML::Entities;
51: use HTML::TokeParser;
52: use GDBM_File;
53: use File::MMagic;
54: use File::Copy;
55: use Apache::lonlocal;
56: use Cwd;
57: use UUID::Tiny ':std';
58: use LONCAPA qw(:DEFAULT :match);
59:
60: my $iconpath;
61:
62: my %hash;
63:
64: my $hashtied;
65: my %alreadyseen=();
66:
67: my $hadchanges;
68: my $suppchanges;
69:
70:
71: my %help=();
72:
73:
74: sub mapread {
75: my ($coursenum,$coursedom,$map)=@_;
76: return
77: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
78: $map);
79: }
80:
81: sub storemap {
82: my ($coursenum,$coursedom,$map,$contentchg)=@_;
83: my $report;
84: if (($contentchg) && ($map =~ /^default/)) {
85: $report = 1;
86: }
87: my ($outtext,$errtext)=
88: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
89: $map,1,$report);
90: if ($errtext) { return ($errtext,2); }
91:
92: if ($map =~ /^default/) {
93: $hadchanges=1;
94: } elsif ($contentchg) {
95: $suppchanges=1;
96: }
97: return ($errtext,0);
98: }
99:
100:
101:
102: sub authorhosts {
103: my %outhash=();
104: my $home=0;
105: my $other=0;
106: foreach my $key (keys(%env)) {
107: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
108: my $role=$1;
109: my $realm=$2;
110: my ($start,$end)=split(/\./,$env{$key});
111: if (($start) && ($start>time)) { next; }
112: if (($end) && (time>$end)) { next; }
113: my ($ca,$cd);
114: if ($1 eq 'au') {
115: $ca=$env{'user.name'};
116: $cd=$env{'user.domain'};
117: } else {
118: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
119: }
120: my $allowed=0;
121: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
122: my @ids=&Apache::lonnet::current_machine_ids();
123: foreach my $id (@ids) {
124: if ($id eq $myhome) {
125: $allowed=1;
126: last;
127: }
128: }
129: if ($allowed) {
130: $home++;
131: $outhash{'home_'.$ca.':'.$cd}=1;
132: } else {
133: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
134: $other++;
135: }
136: }
137: }
138: return ($home,$other,%outhash);
139: }
140:
141:
142: sub clean {
143: my ($title)=@_;
144: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
145: return $title;
146: }
147:
148: sub default_folderpath {
149: my ($coursenum,$coursedom,$navmapref) = @_;
150: return unless ($coursenum && $coursedom && ref($navmapref));
151: # Check if entire course is hidden and/or encrypted
152: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
153: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
154: unless (ref($$navmapref)) {
155: $$navmapref = Apache::lonnavmaps::navmap->new();
156: }
157: if (ref($$navmapref)) {
158: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
159: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
160: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
161: unless (@resources) {
162: $hiddenmap = 1;
163: unless ($env{'request.role.adv'}) {
164: $hiddentop = 1;
165: if ($env{'form.folder'}) {
166: undef($env{'form.folder'});
167: }
168: }
169: }
170: }
171: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
172: $encryptmap = 1;
173: }
174: }
175: unless ($hiddentop) {
176: $folderpath='default&'.&escape(&mt('Main Content')).
177: '::'.$hiddenmap.':'.$encryptmap.'::';
178: }
179: if (wantarray) {
180: return ($folderpath,$hiddentop);
181: } else {
182: return $folderpath;
183: }
184: }
185:
186: sub validate_folderpath {
187: my ($supplementalflag) = @_;
188: if ($env{'form.folderpath'} ne '') {
189: my @items = split(/\&/,$env{'form.folderpath'});
190: my $badpath;
191: for (my $i=0; $i<@items; $i++) {
192: my $odd = $i%2;
193: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
194: $badpath = 1;
195: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
196: $badpath = 1;
197: }
198: last if ($badpath);
199: }
200: if ($badpath) {
201: delete($env{'form.folderpath'});
202: }
203: }
204: return;
205: }
206:
207: sub validate_suppath {
208: if ($env{'form.supppath'} ne '') {
209: my @items = split(/\&/,$env{'form.supppath'});
210: my $badpath;
211: for (my $i=0; $i<@items; $i++) {
212: my $odd = $i%2;
213: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
214: $badpath = 1;
215: }
216: last if ($badpath);
217: }
218: if ($badpath) {
219: delete($env{'form.supppath'});
220: }
221: }
222: return;
223: }
224:
225: sub dumpcourse {
226: my ($r) = @_;
227: my $crstype = &Apache::loncommon::course_type();
228: my ($starthash,$js);
229: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
230: $js = <<"ENDJS";
231: <script type="text/javascript">
232: // <![CDATA[
233:
234: function hide_searching() {
235: if (document.getElementById('searching')) {
236: document.getElementById('searching').style.display = 'none';
237: }
238: return;
239: }
240:
241: // ]]>
242: </script>
243: ENDJS
244: $starthash = {
245: add_entries => {'onload' => "hide_searching();"},
246: };
247: }
248: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
249: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
250: $r->print(&startContentScreen('tools'));
251: my ($home,$other,%outhash)=&authorhosts();
252: unless ($home) {
253: $r->print(&endContentScreen());
254: return '';
255: }
256: my $origcrsid=$env{'request.course.id'};
257: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
258: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
259: # Do the dumping
260: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
261: $r->print(&endContentScreen());
262: return '';
263: }
264: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
265: $r->print('<h3>'.&mt('Copying Files').'</h3>');
266: my $title=$env{'form.authorfolder'};
267: $title=&clean($title);
268: my ($navmap,$errormsg) =
269: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
270: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
271: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
272: my (%maps,%resources,%titles);
273: if (!ref($navmap)) {
274: $r->print($errormsg.
275: &endContentScreen());
276: return '';
277: } else {
278: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
279: 'dumpdocs',$cdom,$cnum);
280: }
281: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
282: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
283: %newcontent,%has_simpleprobs);
284: foreach my $item (sort {$a <=> $b} (@todump)) {
285: my $name = $env{'form.namefor_'.$item};
286: if ($resources{$item}) {
287: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
288: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
289: $tocopy{$1} = $name;
290: $display{$item} = $1;
291: $lookup{$1} = $item;
292: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
293: $simpleproblems{$item} = {
294: symb => $resources{$item},
295: name => $name,
296: };
297: $display{$item} = 'simpleproblem_'.$name;
298: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
299: $has_simpleprobs{$1}{$id} = $item;
300: }
301: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
302: my $marker = $1;
303: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
304: $simplepages{$item} = {
305: res => $res,
306: title => $titles{$item},
307: db => $db_name,
308: marker => $marker,
309: symb => $resources{$item},
310: name => $name,
311: };
312: $display{$item} = '/'.$res;
313: }
314: } elsif ($maps{$item}) {
315: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
316: $tocopy{$1} = $name;
317: $display{$item} = $1;
318: $lookup{$1} = $item;
319: }
320: } else {
321: next;
322: }
323: }
324: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
325: $crs=~s/\_/\//g;
326: my $mm = new File::MMagic;
327: my $prefix = "/uploaded/$cdom/$cnum/";
328: %replacehash = %tocopy;
329: foreach my $item (sort(keys(%simpleproblems))) {
330: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
331: $newcontent{$display{$item}} = $content;
332: }
333: my $gateway = Apache::lonhtmlgateway->new('web');
334: foreach my $item (sort(keys(%simplepages))) {
335: if (ref($simplepages{$item}) eq 'HASH') {
336: my $pagetitle = $simplepages{$item}{'title'};
337: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
338: my %contents;
339: foreach my $field (keys(%fields)) {
340: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
341: my $name = $1;
342: my $msg = $fields{$field};
343: if ($name eq 'webreferences') {
344: if ($msg =~ m{^https?://}) {
345: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
346: }
347: } else {
348: $msg = &Encode::decode('utf8',$msg);
349: $msg = $gateway->process_outgoing_html($msg,1);
350: $contents{$name} = $msg;
351: }
352: } elsif ($field eq 'uploaded.photourl') {
353: my $marker = $simplepages{$item}{marker};
354: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
355: my $filepath = $1;
356: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
357: if ($fname ne '') {
358: $fname=~s/\.(\w+)$//;
359: my $ext=$1;
360: $fname = &clean($fname);
361: $fname.='.'.$ext;
362: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
363: $replacehash{$filepath} = $relpath.$fname;
364: $deps{$item}{$filepath} = 1;
365: }
366: }
367: }
368: }
369: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
370: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
371: my $content = '
372: <html>
373: <head>
374: <title>'.$pagetitle.'</title>
375: </head>
376: <body bgcolor="#ffffff">';
377: if ($contents{title}) {
378: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
379: }
380: if ($contents{image}) {
381: $content .= "\n".$contents{image};
382: }
383: if ($contents{content}) {
384: $content .= '
385: <div class="LC_Box">
386: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
387: $contents{content}.'
388: </div>';
389: }
390: if ($contents{webreferences}) {
391: $content .= '
392: <div class="LC_Box">
393: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
394: $contents{webreferences}.'
395: </div>';
396: }
397: $content .= '
398: </body>
399: </html>
400: ';
401: $newcontent{'/'.$simplepages{$item}{res}} = $content;
402: }
403: }
404: foreach my $item (keys(%tocopy)) {
405: unless ($item=~/\.(sequence|page)$/) {
406: my $currurlpath = $prefix.$item;
407: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
408: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
409: }
410: }
411: foreach my $num (sort {$a <=> $b} (@todump)) {
412: my $src = $display{$num};
413: next if ($src eq '');
414: my @needcopy = ();
415: if ($replacehash{$src}) {
416: push(@needcopy,$src);
417: if (ref($deps{$num}) eq 'HASH') {
418: foreach my $dep (sort(keys(%{$deps{$num}}))) {
419: if ($replacehash{$dep}) {
420: push(@needcopy,$dep);
421: }
422: }
423: }
424: } elsif ($src =~ /^simpleproblem_/) {
425: push(@needcopy,$src);
426: }
427: next if (@needcopy == 0);
428: my ($result,$depresult);
429: for (my $i=0; $i<@needcopy; $i++) {
430: my $item = $needcopy[$i];
431: my $newfilename;
432: if ($simpleproblems{$num}) {
433: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
434: } else {
435: $newfilename=$title.'/'.$replacehash{$item};
436: }
437: $newfilename=~s/\.(\w+)$//;
438: my $ext=$1;
439: $newfilename=&clean($newfilename);
440: $newfilename.='.'.$ext;
441: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
442: if ($newrelpath ne $replacehash{$item}) {
443: $replacehash{$item} = $newrelpath;
444: }
445: my @dirs=split(/\//,$newfilename);
446: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
447: my $makepath=$path;
448: my $fail;
449: my $origin;
450: for (my $i=0;$i<$#dirs;$i++) {
451: $makepath.='/'.$dirs[$i];
452: unless (-e $makepath) {
453: unless(mkdir($makepath,0755)) {
454: $fail = &mt('Directory creation failed.');
455: }
456: }
457: }
458: if ($i == 0) {
459: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
460: } else {
461: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
462: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
463: &mt('(dependency)').'</span>: ';
464: }
465: if (-e $path.'/'.$newfilename) {
466: $fail = &mt('Destination already exists -- not overwriting.');
467: } else {
468: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
469: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
470: ($item =~ /^simpleproblem_/)) {
471: print $fh $newcontent{$item};
472: } else {
473: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
474: if (-e $fileloc) {
475: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
476: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
477: (ref($has_simpleprobs{$item}) eq 'HASH')) {
478: my %changes = %{$has_simpleprobs{$item}};
479: my $content = &Apache::lonclonecourse::rewritefile(
480: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
481: (%replacehash,$crs => '')
482: );
483: my $updatedcontent = '';
484: my $parser = HTML::TokeParser->new(\$content);
485: $parser->attr_encoded(1);
486: while (my $token = $parser->get_token) {
487: if ($token->[0] eq 'S') {
488: if (($token->[1] eq 'resource') &&
489: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
490: ($changes{$token->[2]->{'id'}})) {
491: my $id = $token->[2]->{'id'};
492: $updatedcontent .= '<'.$token->[1];
493: foreach my $attrib (@{$token->[3]}) {
494: next unless ($attrib =~ /^(src|type|title|id)$/);
495: if ($attrib eq 'src') {
496: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
497: if ($file) {
498: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
499: } else {
500: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
501: }
502: } else {
503: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
504: }
505: }
506: $updatedcontent .= ' />'."\n";
507: } else {
508: $updatedcontent .= $token->[4]."\n";
509: }
510: } else {
511: $updatedcontent .= $token->[2];
512: }
513: }
514: print $fh $updatedcontent;
515: } else {
516: print $fh &Apache::lonclonecourse::rewritefile(
517: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
518: (%replacehash,$crs => '')
519: );
520: }
521: } else {
522: print $fh
523: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
524: }
525: } else {
526: $fail = &mt('Source does not exist.');
527: }
528: }
529: $fh->close();
530: } else {
531: $fail = &mt('Could not write to destination.');
532: }
533: }
534: my $text;
535: if ($fail) {
536: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
537: } else {
538: $text = '<span class="LC_success">'.&mt('ok').'</span>';
539: }
540: if ($i == 0) {
541: $result .= $text;
542: } else {
543: $depresult .= $text.'</li>';
544: }
545: }
546: $r->print($result);
547: if ($depresult) {
548: $r->print('<ul>'.$depresult.'</ul>');
549: }
550: }
551: } else {
552: my ($navmap,$errormsg) =
553: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
554: if (!ref($navmap)) {
555: $r->print($errormsg);
556: } else {
557: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
558: $r->rflush();
559: my ($preamble,$formname);
560: $formname = 'dumpdoc';
561: unless ($home==1) {
562: $preamble = '<div class="LC_left_float">'.
563: '<fieldset><legend>'.
564: &mt('Select the Authoring Space').
565: '</legend><select name="authorspace">';
566: }
567: my @orderspaces = ();
568: foreach my $key (sort(keys(%outhash))) {
569: if ($key=~/^home_(.+)$/) {
570: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
571: unshift(@orderspaces,$1);
572: } else {
573: push(@orderspaces,$1);
574: }
575: }
576: }
577: if ($home>1) {
578: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
579: }
580: foreach my $user (@orderspaces) {
581: if ($home==1) {
582: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
583: } else {
584: $preamble .= '<option value="'.$user.'">'.$user.' - '.
585: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
586: }
587: }
588: unless ($home==1) {
589: $preamble .= '</select></fieldset></div>'."\n";
590: }
591: my $title=$origcrsdata{'description'};
592: $title=~s/[\/\s]+/\_/gs;
593: $title=&clean($title);
594: $preamble .= '<div class="LC_left_float">'.
595: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
596: '<input type="text" size="50" name="authorfolder" value="'.
597: $title.'" />'.
598: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
599: my %uploadedfiles;
600: &tiehash();
601: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
602: my ($ext)=($file=~/\.(\w+)$/);
603: # FIXME Check supplemental here
604: my $title=$hash{'title_'.$hash{
605: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
606: if (!$title) {
607: $title=$file;
608: } else {
609: $title=~s|/|_|g;
610: }
611: $title=~s/\.(\w+)$//;
612: $title=&clean($title);
613: $title.='.'.$ext;
614: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
615: $uploadedfiles{$file} = $title;
616: }
617: &untiehash();
618: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
619: undef,undef,$preamble,$home,\%uploadedfiles));
620: }
621: }
622: $r->print(&endContentScreen());
623: }
624:
625: sub recurse_html {
626: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
627: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
628: my (%allfiles,%codebase);
629: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
630: if (keys(%allfiles)) {
631: foreach my $dependency (keys(%allfiles)) {
632: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
633: my ($depurl,$relfile,$newcontainer);
634: if ($dependency =~ m{^/}) {
635: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
636: $relfile = $1;
637: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
638: $newcontainer = $1;
639: next if ($replacehash->{$newcontainer});
640: }
641: $depurl = $dependency;
642: } else {
643: next;
644: }
645: } else {
646: $relfile = $dependency;
647: $depurl = $currurlpath;
648: $depurl =~ s{[^/]+$}{};
649: $depurl .= $dependency;
650: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
651: }
652: next if ($relfile eq '');
653: my $newname = $replacehash->{$container};
654: $newname =~ s{[^/]+$}{};
655: $replacehash->{$newcontainer} = $newname.$relfile;
656: $deps->{$item}{$newcontainer} = 1;
657: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
658: my $depfile = &Apache::lonnet::filelocation('',$depurl);
659: my $type = $mm->checktype_filename($depfile);
660: if ($type eq 'text/html') {
661: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
662: }
663: }
664: }
665: }
666: return;
667: }
668:
669: sub group_import {
670: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
671: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
672: %removeparam,$importuploaded,$fixuperrors);
673: $allmaps = {};
674: while (@files) {
675: my ($name, $url, $residx) = @{ shift(@files) };
676: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
677: && ($caller eq 'londocs')
678: && (!&Apache::lonnet::stat_file($url))) {
679:
680: my $errtext = '';
681: my $fatal = 0;
682: my $newmapstr = '<map>'."\n".
683: '<resource id="1" src="" type="start"></resource>'."\n".
684: '<link from="1" to="2" index="1"></link>'."\n".
685: '<resource id="2" src="" type="finish"></resource>'."\n".
686: '</map>';
687: $env{'form.output'}=$newmapstr;
688: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
689: 'output',$1.$2);
690: if ($result !~ m{^/uploaded/}) {
691: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
692: $fatal = 2;
693: }
694: if ($fatal) {
695: return ($errtext,$fatal);
696: }
697: }
698: if ($url) {
699: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
700: $url = $1;
701: my $marker = $2;
702: my $info = $3;
703: my ($toolid,%toolhash,%toolsettings);
704: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
705: my @toolinfo = split(/:/,$info);
706: if ($residx) {
707: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
708: $toolid = $toolsettings{'id'};
709: } else {
710: $toolid = shift(@toolinfo);
711: }
712: $toolid =~ s/\D//g;
713: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
714: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
715: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
716: foreach my $item (@extras) {
717: $toolhash{$item} = &unescape($toolhash{$item});
718: }
719: if ($folder =~ /^supplemental/) {
720: delete($toolhash{'gradable'});
721: } else {
722: $toolhash{'gradable'} =~ s/\D+//g;
723: }
724: if (ref($ltitoolsref) eq 'HASH') {
725: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
726: my @deleted;
727: $toolhash{'id'} = $toolid;
728: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
729: ($toolhash{'target'} eq 'window')) {
730: if ($toolhash{'target'} eq 'window') {
731: foreach my $item ('width','height') {
732: $toolhash{$item} =~ s/^\s+//;
733: $toolhash{$item} =~ s/\s+$//;
734: if ($toolhash{$item} =~ /\D/) {
735: delete($toolhash{$item});
736: if ($residx) {
737: if ($toolsettings{$item}) {
738: push(@deleted,$item);
739: }
740: }
741: }
742: }
743: }
744: } elsif ($residx) {
745: $toolhash{'target'} = $toolsettings{'target'};
746: if ($toolhash{'target'} eq 'window') {
747: foreach my $item ('width','height') {
748: $toolhash{$item} = $toolsettings{$item};
749: }
750: }
751: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
752: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
753: if ($toolhash{'target'} eq 'window') {
754: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
755: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
756: }
757: }
758: if ($toolhash{'target'} eq 'iframe') {
759: foreach my $item ('width','height','linktext','explanation') {
760: delete($toolhash{$item});
761: if ($residx) {
762: if ($toolsettings{$item}) {
763: push(@deleted,$item);
764: }
765: }
766: }
767: } elsif ($toolhash{'target'} eq 'tab') {
768: foreach my $item ('width','height') {
769: delete($toolhash{$item});
770: if ($residx) {
771: if ($toolsettings{$item}) {
772: push(@deleted,$item);
773: }
774: }
775: }
776: }
777: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
778: foreach my $item ('label','title','linktext','explanation') {
779: my $crsitem;
780: if (($item eq 'label') || ($item eq 'title')) {
781: $crsitem = 'crs'.$item;
782: } else {
783: $crsitem = $item;
784: }
785: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
786: $toolhash{$crsitem} =~ s/^\s+//;
787: $toolhash{$crsitem} =~ s/\s+$//;
788: if ($toolhash{$crsitem} eq '') {
789: delete($toolhash{$crsitem});
790: }
791: } else {
792: delete($toolhash{$crsitem});
793: }
794: if (($residx) && (exists($toolsettings{$crsitem}))) {
795: unless (exists($toolhash{$crsitem})) {
796: push(@deleted,$crsitem);
797: }
798: }
799: }
800: }
801: if ($toolhash{'passback'}) {
802: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
803: $toolhash{'gradesecret'} = $gradesecret;
804: $toolhash{'gradesecretdate'} = time;
805: }
806: if ($toolhash{'roster'}) {
807: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
808: $toolhash{'rostersecret'} = $rostersecret;
809: $toolhash{'rostersecretdate'} = time;
810: }
811: my $changegradable;
812: if (($residx) && ($folder =~ /^default/)) {
813: if ($toolsettings{'gradable'}) {
814: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
815: push(@deleted,'gradable');
816: $changegradable = 1;
817: }
818: } elsif ($toolhash{'gradable'}) {
819: $changegradable = 1;
820: }
821: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
822: $changegradable = 1;
823: if ($toolsettings{'gradable'}) {
824: $toolhash{'gradable'} = 1;
825: }
826: }
827: }
828: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
829: if ($putres eq 'ok') {
830: if (@deleted) {
831: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
832: }
833: if (($changegradable) && ($folder =~ /^default/)) {
834: my $val;
835: if ($toolhash{'gradable'}) {
836: $val = 'yes';
837: } else {
838: $val = 'no';
839: }
840: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
841: 'string_yesno');
842: &remember_parms($residx,'gradable','set',$val);
843: }
844: } else {
845: return (&mt('Failed to save update to external tool.'),1);
846: }
847: }
848: }
849: }
850: if (($caller eq 'londocs') &&
851: ($folder =~ /^default/)) {
852: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
853: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
854: my $cid = $coursedom.'_'.$coursenum;
855: $allmaps =
856: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
857: $chome,$cid);
858: $donechk = 1;
859: }
860: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
861: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
862: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
863: $importuploaded = 1;
864: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
865: next if ($allmaps->{$url});
866: }
867: }
868: if (!$residx
869: || defined($LONCAPA::map::zombies[$residx])) {
870: $residx = &LONCAPA::map::getresidx($url,$residx);
871: push(@LONCAPA::map::order, $residx);
872: }
873: my $ext = 'false';
874: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
875: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
876: my $filepath = $1;
877: my $fname;
878: if ($name eq '') {
879: $name = &mt('Web Page');
880: $fname = 'web';
881: } else {
882: $fname = $name;
883: $fname=&Apache::lonnet::clean_filename($fname);
884: if ($fname eq '') {
885: $fname = 'web';
886: } elsif (length($fname) > 15) {
887: $fname = substr($fname,0,14);
888: }
889: }
890: my $title = &Apache::loncommon::cleanup_html($name);
891: my $initialtext = &mt('Replace with your own content.');
892: my $newhtml = <<END;
893: <html>
894: <head>
895: <title>$title</title>
896: </head>
897: <body bgcolor="#ffffff">
898: $initialtext
899: </body>
900: </html>
901: END
902: $env{'form.output'}=$newhtml;
903: my $result =
904: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
905: 'output',
906: "$filepath/$residx/$fname.html");
907: if ($result =~ m{^/uploaded/}) {
908: $url = $result;
909: if ($filepath =~ /^supplemental/) {
910: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
911: $env{'user.domain'}.'___&&&___'.$name;
912: }
913: } else {
914: return (&mt('Failed to save new web page.'),1);
915: }
916: }
917: $name = &LONCAPA::map::qtunescape($name);
918: $url = &LONCAPA::map::qtunescape($url);
919: $LONCAPA::map::resources[$residx] =
920: join(':', ($name, $url, $ext, 'normal', 'res'));
921: }
922: }
923: if ($importuploaded) {
924: my %import_errors;
925: my %updated = (
926: removefrommap => \%removefrommap,
927: removeparam => \%removeparam,
928: );
929: my ($result,$msgsarray,$lockerror) =
930: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
931: if (keys(%import_errors) > 0) {
932: $fixuperrors =
933: '<p span class="LC_warning">'."\n".
934: &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".
935: '<ul>'."\n";
936: foreach my $key (sort(keys(%import_errors))) {
937: $fixuperrors .= '<li>'.$key.'</li>'."\n";
938: }
939: $fixuperrors .= '</ul></p>'."\n";
940: }
941: if (ref($msgsarray) eq 'ARRAY') {
942: if (@{$msgsarray} > 0) {
943: $fixuperrors .= '<p class="LC_info">'.
944: join('<br />',@{$msgsarray}).
945: '</p>';
946: }
947: }
948: if ($lockerror) {
949: $fixuperrors .= '<p class="LC_error">'.
950: $lockerror.
951: '</p>';
952: }
953: }
954: my ($errtext,$fatal) =
955: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
956: unless ($fatal) {
957: if ($folder =~ /^supplemental/) {
958: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
959: $folder.'.'.$container);
960: }
961: }
962: return ($errtext,$fatal,$fixuperrors);
963: }
964:
965: sub log_docs {
966: return &Apache::lonnet::write_log('course','docslog',@_);
967: }
968:
969: {
970: my @oldresources=();
971: my @oldorder=();
972: my $parmidx;
973: my %parmaction=();
974: my %parmvalue=();
975: my $changedflag;
976:
977: sub snapshotbefore {
978: @oldresources=@LONCAPA::map::resources;
979: @oldorder=@LONCAPA::map::order;
980: $parmidx=undef;
981: %parmaction=();
982: %parmvalue=();
983: $changedflag=0;
984: }
985:
986: sub remember_parms {
987: my ($idx,$parameter,$action,$value)=@_;
988: $parmidx=$idx;
989: $parmaction{$parameter}=$action;
990: $parmvalue{$parameter}=$value;
991: $changedflag=1;
992: }
993:
994: sub log_differences {
995: my ($plain)=@_;
996: my %storehash=('folder' => $plain,
997: 'currentfolder' => $env{'form.folder'});
998: if ($parmidx) {
999: $storehash{'parameter_res'}=$oldresources[$parmidx];
1000: foreach my $parm (keys(%parmaction)) {
1001: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1002: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1003: }
1004: }
1005: my $maxidx=$#oldresources;
1006: if ($#LONCAPA::map::resources>$#oldresources) {
1007: $maxidx=$#LONCAPA::map::resources;
1008: }
1009: for (my $idx=0; $idx<=$maxidx; $idx++) {
1010: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1011: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1012: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1013: $changedflag=1;
1014: }
1015: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1016: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1017: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1018: $changedflag=1;
1019: }
1020: }
1021: $storehash{'maxidx'}=$maxidx;
1022: if ($changedflag) { &log_docs(\%storehash); }
1023: }
1024: }
1025:
1026: sub docs_change_log {
1027: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1028: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1029: my $navmap;
1030: my $js = '<script type="text/javascript">'."\n".
1031: '// <![CDATA['."\n".
1032: &Apache::loncommon::display_filter_js('docslog')."\n".
1033: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1034: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1035: &history_tab_js()."\n".
1036: &Apache::lonratedt::editscript('simple')."\n".
1037: '// ]]>'."\n".
1038: '</script>'."\n";
1039: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1040: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1041: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1042: my %orderhash;
1043: my $container='sequence';
1044: my $pathitem;
1045: if ($env{'form.folderpath'} =~ /\:1$/) {
1046: $container='page';
1047: }
1048: my $folderpath=$env{'form.folderpath'};
1049: if ($folderpath eq '') {
1050: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1051: }
1052: undef($navmap);
1053: $pathitem = '<input type="hidden" name="folderpath" value="'.
1054: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1055: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1056: my $jumpto = $readfile;
1057: $jumpto =~ s{^/}{};
1058: my $tid = 1;
1059: if ($supplementalflag) {
1060: $tid = 2;
1061: }
1062: my ($breadcrumbtrail) =
1063: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1064: $r->print($breadcrumbtrail.
1065: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1066: $readfile));
1067: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1068: $env{'course.'.$env{'request.course.id'}.'.domain'},
1069: $env{'course.'.$env{'request.course.id'}.'.num'});
1070:
1071: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1072:
1073: my %saveable_parameters = ('show' => 'scalar',);
1074: &Apache::loncommon::store_course_settings('docs_log',
1075: \%saveable_parameters);
1076: &Apache::loncommon::restore_course_settings('docs_log',
1077: \%saveable_parameters);
1078: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1079: # FIXME: internationalization seems wrong here
1080: my %lt=('hiddenresource' => 'Resources hidden',
1081: 'encrypturl' => 'URL hidden',
1082: 'randompick' => 'Randomly pick',
1083: 'randomorder' => 'Randomly ordered',
1084: 'gradable' => 'Grade can be assigned to External Tool',
1085: 'set' => 'set to',
1086: 'del' => 'deleted');
1087: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1088: $pathitem."\n".
1089: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1090: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1091: $r->print('<div class="LC_left_float">'.
1092: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1093: &makedocslogform($filter,1).
1094: '</fieldset></div><br clear="all" />');
1095: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1096: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1097: &mt('After').'</th>'.
1098: &Apache::loncommon::end_data_table_header_row());
1099: my $shown=0;
1100: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1101: if ($env{'form.displayfilter'} eq 'currentfolder') {
1102: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1103: }
1104: my @changes=keys(%{$docslog{$id}{'logentry'}});
1105: if ($env{'form.displayfilter'} eq 'containing') {
1106: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1107: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1108: foreach my $key (@changes) {
1109: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1110: }
1111: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1112: }
1113: my $count = 0;
1114: my $time =
1115: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1116: my $plainname =
1117: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1118: $docslog{$id}{'exe_udom'});
1119: my $about_me_link =
1120: &Apache::loncommon::aboutmewrapper($plainname,
1121: $docslog{$id}{'exe_uname'},
1122: $docslog{$id}{'exe_udom'});
1123: my $send_msg_link='';
1124: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1125: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1126: $send_msg_link ='<br />'.
1127: &Apache::loncommon::messagewrapper(&mt('Send message'),
1128: $docslog{$id}{'exe_uname'},
1129: $docslog{$id}{'exe_udom'});
1130: }
1131: $r->print(&Apache::loncommon::start_data_table_row());
1132: $r->print('<td>'.$time.'</td>
1133: <td>'.$about_me_link.
1134: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1135: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1136: $send_msg_link.'</td><td>'.
1137: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1138: my $is_supp = 0;
1139: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1140: $is_supp = 1;
1141: }
1142: # Before
1143: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1144: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1145: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1146: if ($oldname ne $newname) {
1147: my $shown = &LONCAPA::map::qtescape($oldname);
1148: if ($is_supp) {
1149: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1150: }
1151: $r->print($shown);
1152: }
1153: }
1154: $r->print('<ul>');
1155: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1156: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1157: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1158: if ($is_supp) {
1159: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1160: }
1161: $r->print('<li>'.$shown.'</li>');
1162: }
1163: }
1164: $r->print('</ul>');
1165: # After
1166: $r->print('</td><td>');
1167:
1168: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1169: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1170: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1171: if ($oldname ne '' && $oldname ne $newname) {
1172: my $shown = &LONCAPA::map::qtescape($newname);
1173: if ($is_supp) {
1174: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1175: }
1176: $r->print($shown);
1177: }
1178: }
1179: $r->print('<ul>');
1180: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1181: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1182: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1183: if ($is_supp) {
1184: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1185: }
1186: $r->print('<li>'.$shown.'</li>');
1187: }
1188: }
1189: $r->print('</ul>');
1190: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1191: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1192: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1193: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1194: # FIXME: internationalization seems wrong here
1195: $r->print('<li>'.
1196: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1197: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1198: .'</li>');
1199: }
1200: }
1201: $r->print('</ul>');
1202: }
1203: # End
1204: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1205: $shown++;
1206: if (!($env{'form.show'} eq &mt('all')
1207: || $shown<=$env{'form.show'})) { last; }
1208: }
1209: $r->print(&Apache::loncommon::end_data_table()."\n".
1210: &makesimpleeditform($pathitem)."\n".
1211: '</div></div>');
1212: $r->print(&endContentScreen());
1213: }
1214:
1215: sub update_paste_buffer {
1216: my ($coursenum,$coursedom,$folder) = @_;
1217: my (@possibles,%removals,%cuts,$output);
1218: if ($env{'form.multiremove'}) {
1219: $env{'form.multiremove'} =~ s/,$//;
1220: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1221: }
1222: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1223: if ($env{'form.multicut'}) {
1224: $env{'form.multicut'} =~ s/,$//;
1225: foreach my $item (split(/,/,$env{'form.multicut'})) {
1226: unless ($removals{$item}) {
1227: $cuts{$item} = 1;
1228: push(@possibles,$item.':cut');
1229: }
1230: }
1231: }
1232: if ($env{'form.multicopy'}) {
1233: $env{'form.multicopy'} =~ s/,$//;
1234: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1235: unless ($removals{$item} || $cuts{$item}) {
1236: push(@possibles,$item.':copy');
1237: }
1238: }
1239: }
1240: } elsif ($env{'form.markcopy'}) {
1241: @possibles = split(/,/,$env{'form.markcopy'});
1242: }
1243:
1244: return if (@possibles == 0);
1245: return if (!defined($env{'form.copyfolder'}));
1246:
1247: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1248: $env{'form.copyfolder'});
1249: return if ($fatal);
1250:
1251: my %curr_groups = &Apache::longroup::coursegroups();
1252:
1253: # Retrieve current paste buffer suffixes.
1254: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1255: my (%pasteurls,@newpaste);
1256:
1257: # Construct identifiers for current contents of user's paste buffer
1258: if (@currpaste) {
1259: foreach my $suffix (@currpaste) {
1260: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1261: my $url = $env{'docs.markedcopy_url_'.$suffix};
1262: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1263: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1264: ($url ne '')) {
1265: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1266: $pasteurls{$cid.'_'.$mapidx} = 1;
1267: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1268: $pasteurls{$url} = 1;
1269: } else {
1270: $pasteurls{$cid.'_'.$url} = 1;
1271: }
1272: }
1273: }
1274: }
1275:
1276: # Mark items for copying (skip any items already in user's paste buffer)
1277: my %addtoenv;
1278:
1279: my @pathitems = split(/\&/,$env{'form.folderpath'});
1280: my @folderconf = split(/\:/,$pathitems[-1]);
1281: my $ispage = $folderconf[5];
1282:
1283: foreach my $item (@possibles) {
1284: my ($orderidx,$cmd) = split(/:/,$item);
1285: next if ($orderidx =~ /\D/);
1286: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1287: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1288: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1289: my %denied = &action_restrictions($coursenum,$coursedom,
1290: &LONCAPA::map::qtescape($url),
1291: $env{'form.folderpath'},\%curr_groups);
1292: next if ($denied{'copy'});
1293: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1294: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1295: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1296: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1297: next if (exists($pasteurls{$url}));
1298: } else {
1299: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1300: }
1301: my ($suffix,$errortxt,$locknotfreed) =
1302: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1303: if ($suffix ne '') {
1304: push(@newpaste,$suffix);
1305: } else {
1306: if ($locknotfreed) {
1307: return $locknotfreed;
1308: }
1309: }
1310: if (&is_supplemental_title($title)) {
1311: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1312: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1313: }
1314:
1315: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1316: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1317: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1318: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1319: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1320: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1321: my $prefix = $1;
1322: my $subdir =$2;
1323: if ($subdir eq '') {
1324: $subdir = $prefix;
1325: }
1326: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1327: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1328: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1329: if (ref($hierarchy{$url}) eq 'HASH') {
1330: my ($nested,$nestednames);
1331: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1332: $nested =~ s/\&$//;
1333: $nestednames =~ s/\Q___&&&___\E$//;
1334: if ($nested ne '') {
1335: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1336: }
1337: if ($nestednames ne '') {
1338: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1339: }
1340: }
1341: }
1342: if ($locknotfreed) {
1343: $output = $locknotfreed;
1344: last;
1345: }
1346: }
1347: if (@newpaste) {
1348: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1349: }
1350: &Apache::lonnet::appenv(\%addtoenv);
1351: delete($env{'form.markcopy'});
1352: return $output;
1353: }
1354:
1355: sub recurse_uploaded_maps {
1356: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1357: if (ref($hierarchy->{$url}) eq 'HASH') {
1358: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1359: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1360: my (@uploaded,@names,%shorter);
1361: for (my $i=0; $i<@maps; $i++) {
1362: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1363: if ($inner ne '') {
1364: push(@uploaded,$inner);
1365: push(@names,&escape($titles[$i]));
1366: $shorter{$maps[$i]} = $inner;
1367: }
1368: }
1369: $$nestref .= "$dir:".join(',',@uploaded).'&';
1370: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1371: foreach my $map (@maps) {
1372: if ($shorter{$map} ne '') {
1373: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1374: }
1375: }
1376: }
1377: return;
1378: }
1379:
1380: sub print_paste_buffer {
1381: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1382: return if (!defined($env{'docs.markedcopies'}));
1383:
1384: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1385: return if ($env{'docs.markedcopies'} eq '');
1386: }
1387:
1388: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1389: my ($pasteitems,@pasteable);
1390: my $clipboardcount = 0;
1391:
1392: # Construct identifiers for current contents of user's paste buffer
1393: foreach my $suffix (@currpaste) {
1394: next if ($suffix =~ /\D/);
1395: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1396: my $url = $env{'docs.markedcopy_url_'.$suffix};
1397: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1398: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1399: ($url ne '')) {
1400: $clipboardcount ++;
1401: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1402: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1403: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1404: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1405: $is_external = 1;
1406: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1407: $is_exttool = 1;
1408: }
1409: if ($folder =~ /^supplemental/) {
1410: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1411: unless ($canpaste) {
1412: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1413: }
1414: } else {
1415: $canpaste = 1;
1416: }
1417: if ($canpaste) {
1418: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1419: my $srcdom = $1;
1420: my $srcnum = $2;
1421: my $rem = $3;
1422: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1423: $othercourse = 1;
1424: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1425: $othercrs = '<br />'.&mt('(from another course)');
1426: } else {
1427: $canpaste = 0;
1428: $nopaste = &mt('Paste from another course unavailable.');
1429: }
1430: }
1431: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1432: my $prefix = $1;
1433: $parent = $2;
1434: if ($folder !~ /^\Q$prefix\E/) {
1435: $areachange = 1;
1436: }
1437: $is_uploaded_map = 1;
1438: }
1439: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1440: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1441: if ($cid ne $env{'request.course.id'}) {
1442: my ($srcdom,$srcnum) = split(/_/,$cid);
1443: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1444: if (($is_exttool) && ($srcdom ne $coursedom)) {
1445: $canpaste = 0;
1446: $nopaste = &mt('Paste from another domain unavailable.');
1447: } else {
1448: $othercrs = '<br />'.&mt('(from another course)');
1449: }
1450: } else {
1451: $canpaste = 0;
1452: $nopaste = &mt('Paste from another course unavailable.');
1453: }
1454: }
1455: }
1456: if ($canpaste) {
1457: push(@pasteable,$suffix);
1458: }
1459: }
1460: my $buffer;
1461: if ($is_external) {
1462: $buffer = &mt('External Resource').': '.
1463: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1464: &LONCAPA::map::qtescape($url).')';
1465: } elsif ($is_exttool) {
1466: $buffer = &mt('External Tool').': '.
1467: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1468: } else {
1469: my $icon = &Apache::loncommon::icon($extension);
1470: if ($extension eq 'sequence' &&
1471: $url =~ m{/default_\d+\.sequence$}x) {
1472: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1473: $icon .= '/navmap.folder.closed.gif';
1474: }
1475: my $title = $env{'docs.markedcopy_title_'.$suffix};
1476: if ($title eq '') {
1477: ($title) = ($url =~ m{/([^/]+)$});
1478: }
1479: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1480: ': '.
1481: &Apache::loncommon::parse_supplemental_title(
1482: &LONCAPA::map::qtescape($title));
1483: }
1484: $pasteitems .= '<div class="LC_left_float">';
1485: my ($options,$onclick);
1486: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1487: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1488: if (($is_uploaded_map) ||
1489: ($url =~ /(bulletinboard|smppg)$/) ||
1490: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1491: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1492: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1493: }
1494: }
1495: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1496: if ($nopaste) {
1497: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1498: } else {
1499: if ($othercrs) {
1500: $pasteitems .= $othercrs;
1501: }
1502: if ($options) {
1503: $pasteitems .= $options;
1504: }
1505: }
1506: $pasteitems .= '</div>';
1507: }
1508: }
1509: if ($pasteitems eq '') {
1510: &Apache::lonnet::delenv('docs.markedcopies');
1511: }
1512: my ($pasteform,$form_start,$buttons,$form_end);
1513: if ($pasteitems) {
1514: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1515: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1516: if (@pasteable) {
1517: my $value = &mt('Paste to current folder');
1518: if ($container eq 'page') {
1519: $value = &mt('Paste to current page');
1520: }
1521: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1522: }
1523: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1524: if ($clipboardcount > 1) {
1525: $buttons .=
1526: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1527: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1528: (' 'x2).
1529: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1530: (' 'x2);
1531: }
1532: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1533: '</form>';
1534: } else {
1535: $pasteitems = &mt('Clipboard is empty');
1536: }
1537: $r->print($form_start
1538: .'<fieldset>'
1539: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1540: .$pasteitems
1541: .'</fieldset>'
1542: .$form_end);
1543: }
1544:
1545: sub paste_options {
1546: my ($suffix,$is_uploaded_map,$parent) = @_;
1547: my ($copytext,$movetext);
1548: if ($is_uploaded_map) {
1549: $copytext = &mt('Copy to new folder');
1550: $movetext = &mt('Move old');
1551: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1552: $copytext = &mt('Copy to new board');
1553: $movetext = &mt('Move (not posts)');
1554: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1555: $copytext = &mt('Copy to new page');
1556: $movetext = &mt('Move');
1557: } else {
1558: $copytext = &mt('Copy to new file');
1559: $movetext = &mt('Move');
1560: }
1561: my $output = '<br />'.
1562: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1563: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1564: '<label>'.
1565: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1566: $copytext.'</label></span>'.(' 'x2).' '.
1567: '<span class="LC_nobreak"><label>'.
1568: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1569: $movetext.'</label></span>';
1570: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1571: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1572: '</legend><table border="0">';
1573: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1574: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1575: my $lastdir = $parent;
1576: my %depths = (
1577: $lastdir => 0,
1578: );
1579: my (%display,%deps);
1580: for (my $i=0; $i<@pastemaps; $i++) {
1581: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1582: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1583: my @subfolders = split(/,/,$subfolderstr);
1584: $deps{$lastdir} = \@subfolders;
1585: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1586: my $depth = $depths{$lastdir} + 1;
1587: my $offset = int($depth * 4);
1588: my $indent = (' ' x $offset);
1589: for (my $j=0; $j<@subfolders; $j++) {
1590: $depths{$subfolders[$j]} = $depth;
1591: $display{$subfolders[$j]} =
1592: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1593: '<td><label>'.
1594: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1595: '<label>'.
1596: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1597: &mt('Move old').'</label>'.
1598: '</td></tr>';
1599: }
1600: }
1601: &recurse_print(\$output,$parent,\%deps,\%display);
1602: $output .= '</table></fieldset>';
1603: }
1604: $output .= '</div>';
1605: return $output;
1606: }
1607:
1608: sub recurse_print {
1609: my ($outputref,$dir,$deps,$display) = @_;
1610: $$outputref .= $display->{$dir}."\n";
1611: if (ref($deps->{$dir}) eq 'ARRAY') {
1612: foreach my $subdir (@{$deps->{$dir}}) {
1613: &recurse_print($outputref,$subdir,$deps,$display);
1614: }
1615: }
1616: }
1617:
1618: sub supp_pasteable {
1619: my ($url) = @_;
1620: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1621: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1622: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1623: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1624: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1625: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1626: return 1;
1627: }
1628: return;
1629: }
1630:
1631: sub paste_popup_js {
1632: my %html_js_lt = &Apache::lonlocal::texthash(
1633: show => 'Show Options',
1634: hide => 'Hide Options',
1635: );
1636: my %js_lt = &Apache::lonlocal::texthash(
1637: none => 'No items selected from clipboard.',
1638: );
1639: &html_escape(\%html_js_lt);
1640: &js_escape(\%html_js_lt);
1641: &js_escape(\%js_lt);
1642: return <<"END";
1643:
1644: function showPasteOptions(suffix) {
1645: document.getElementById('pasteoptions_'+suffix).style.display='block';
1646: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1647: return;
1648: }
1649:
1650: function hidePasteOptions(suffix) {
1651: document.getElementById('pasteoptions_'+suffix).style.display='none';
1652: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1653: return;
1654: }
1655:
1656: function showOptions(caller,suffix) {
1657: if (document.getElementById('pasteoptionstext_'+suffix)) {
1658: if (caller.checked) {
1659: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1660: } else {
1661: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1662: }
1663: if (document.getElementById('pasteoptions_'+suffix)) {
1664: document.getElementById('pasteoptions_'+suffix).style.display='none';
1665: }
1666: }
1667: return;
1668: }
1669:
1670: function validateClipboard() {
1671: var numchk = 0;
1672: if (document.pasteform.pasting.length > 1) {
1673: for (var i=0; i<document.pasteform.pasting.length; i++) {
1674: if (document.pasteform.pasting[i].checked) {
1675: numchk ++;
1676: }
1677: }
1678: } else {
1679: if (document.pasteform.pasting.type == 'checkbox') {
1680: if (document.pasteform.pasting.checked) {
1681: numchk ++;
1682: }
1683: }
1684: }
1685: if (numchk > 0) {
1686: return true;
1687: } else {
1688: alert("$js_lt{'none'}");
1689: return false;
1690: }
1691: }
1692:
1693: function checkClipboard() {
1694: if (document.pasteform.pasting.length > 1) {
1695: for (var i=0; i<document.pasteform.pasting.length; i++) {
1696: document.pasteform.pasting[i].checked = true;
1697: }
1698: }
1699: return;
1700: }
1701:
1702: function uncheckClipboard() {
1703: if (document.pasteform.pasting.length >1) {
1704: for (var i=0; i<document.pasteform.pasting.length; i++) {
1705: document.pasteform.pasting[i].checked = false;
1706: }
1707: }
1708: return;
1709: }
1710:
1711: END
1712:
1713: }
1714:
1715: sub do_paste_from_buffer {
1716: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1717:
1718: # Array of items in paste buffer
1719: my (@currpaste,%pastebuffer,%allerrors);
1720: @currpaste = split(/,/,$env{'docs.markedcopies'});
1721:
1722: # Early out if paste buffer is empty
1723: if (@currpaste == 0) {
1724: return ();
1725: }
1726: map { $pastebuffer{$_} = 1; } @currpaste;
1727:
1728: # Array of items selected items to paste
1729: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1730:
1731: # Early out if nothing selected to paste
1732: if (@reqpaste == 0) {
1733: return();
1734: }
1735: my @topaste;
1736: foreach my $suffix (@reqpaste) {
1737: next if ($suffix =~ /\D/);
1738: next unless (exists($pastebuffer{$suffix}));
1739: push(@topaste,$suffix);
1740: }
1741:
1742: # Early out if nothing available to paste
1743: if (@topaste == 0) {
1744: return();
1745: }
1746:
1747: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1748: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1749:
1750: foreach my $suffix (@topaste) {
1751: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1752: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1753: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1754: # Supplemental content may only include certain types of content
1755: # Early out if pasted content is not supported in Supplemental area
1756: if ($folder =~ /^supplemental/) {
1757: unless (&supp_pasteable($url)) {
1758: $notinsupp{$suffix} = 1;
1759: next;
1760: }
1761: }
1762: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1763: my $srcd = $1;
1764: my $srcn = $2;
1765: # When paste buffer was populated using an active role in a different course
1766: # check for mdc privilege in the course from which the resource was pasted
1767: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1768: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1769: $notincrs{$suffix} = 1;
1770: next;
1771: }
1772: }
1773: $srcdom{$suffix} = $srcd;
1774: $srcnum{$suffix} = $srcn;
1775: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1776: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1777: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1778: my ($srcd,$srcn) = split(/_/,$cid);
1779: # When paste buffer was populated using an active role in a different course
1780: # check for mdc privilege in the course from which the resource was pasted
1781: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1782: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1783: $notincrs{$suffix} = 1;
1784: next;
1785: }
1786: }
1787: # When buffer was populated using an active role in a different course
1788: # disallow pasting of External Tool if course is in a different domain.
1789: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1790: $notindom{$suffix} = 1;
1791: next;
1792: }
1793: $srcdom{$suffix} = $srcd;
1794: $srcnum{$suffix} = $srcn;
1795: }
1796: $srcmapidx{$suffix} = $mapidx;
1797: push(@dopaste,$suffix);
1798: if ($url=~/\.(page|sequence)$/) {
1799: $is_map{$suffix} = 1;
1800: }
1801: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1802: my $oldprefix = $1;
1803: # When pasting content from Main Content to Supplemental Content and vice versa
1804: # URLs will contain different paths (which depend on whether pasted item is
1805: # a folder/page or a document).
1806: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1807: $prefixchg{$suffix} = 'docstosupp';
1808: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1809: $prefixchg{$suffix} = 'supptodocs';
1810: }
1811:
1812: # If pasting an uploaded map, get list of contained uploaded maps.
1813: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1814: my @nested;
1815: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1816: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1817: my @deps = map { /\d+:([\d,]+$)/ } @items;
1818: foreach my $dep (@deps) {
1819: if ($dep =~ /,/) {
1820: push(@nested,split(/,/,$dep));
1821: } else {
1822: push(@nested,$dep);
1823: }
1824: }
1825: foreach my $item (@nested) {
1826: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1827: push(@{$marktomove{$suffix}},$type.'_'.$item);
1828: }
1829: }
1830: }
1831: }
1832: }
1833:
1834: # Early out if nothing available to paste
1835: if (@dopaste == 0) {
1836: return ();
1837: }
1838:
1839: # Populate message hash and hashes used for main content <=> supplemental content
1840: # changes
1841:
1842: %msgs = &Apache::lonlocal::texthash (
1843: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1844: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1845: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1846: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1847: );
1848:
1849: %before = (
1850: docstosupp => {
1851: map => 'default',
1852: doc => 'docs',
1853: },
1854: supptodocs => {
1855: map => 'supplemental',
1856: doc => 'supplemental',
1857: },
1858: );
1859:
1860: %after = (
1861: docstosupp => {
1862: map => 'supplemental',
1863: doc => 'supplemental'
1864: },
1865: supptodocs => {
1866: map => 'default',
1867: doc => 'docs',
1868: },
1869: );
1870:
1871: # Retrieve information about all course maps in main content area
1872:
1873: my $allmaps = {};
1874: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1875:
1876: # Loop over the items to paste
1877: foreach my $suffix (@dopaste) {
1878: # Maps need to be copied first
1879: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1880: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1881: %newurls,%tomove,%resdatacopy);
1882: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1883: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1884: }
1885: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1886: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1887: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1888: my $oldurl = $url;
1889: if ($is_map{$suffix}) {
1890: # If pasting a map, check if map contains other maps
1891: my (%hierarchy,%titles);
1892: if (($folder =~ /^default/) && (!$donechk)) {
1893: $allmaps =
1894: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1895: $env{"course.$env{'request.course.id'}.home"},
1896: $env{'request.course.id'});
1897: $donechk = 1;
1898: }
1899: &contained_map_check($url,$folder,$coursenum,$coursedom,
1900: \%removefrommap,\%removeparam,\%addedmaps,
1901: \%hierarchy,\%titles,$allmaps);
1902: if ($url=~ m{^/uploaded/}) {
1903: my $newurl;
1904: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1905: ($newurl,my $error) =
1906: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1907: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1908: \$title,$allmaps,\%newurls);
1909: if ($error) {
1910: $allerrors{$suffix} = $error;
1911: next;
1912: }
1913: if ($newurl ne '') {
1914: if ($newurl ne $url) {
1915: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1916: $newsubdir{$url} = $1;
1917: }
1918: $mapchanges{$url} = 1;
1919: }
1920: }
1921: }
1922: if (($srcdom{$suffix} ne $coursedom) ||
1923: ($srcnum{$suffix} ne $coursenum) ||
1924: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1925: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1926: $coursedom,$coursenum,$srcdom{$suffix},
1927: $srcnum{$suffix},$allmaps,\%rewrites,
1928: \%retitles,\%copies,\%dbcopies,
1929: \%zombies,\%params,\%mapmoves,
1930: \%mapchanges,\%tomove,\%newsubdir,
1931: \%newurls,\%resdatacopy)) {
1932: $mapmoves{$url} = 1;
1933: }
1934: $url = $newurl;
1935: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1936: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1937: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1938: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1939: \%zombies,\%params,\%mapmoves,\%mapchanges,
1940: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1941: }
1942: } elsif ($url=~m {^/res/}) {
1943: # published map can only exist once, so remove from paste buffer when done
1944: push(@toclear,$suffix);
1945: # if pasting published map (main content area only) check map not already in course
1946: if ($folder =~ /^default/) {
1947: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1948: $duplicate{$suffix} = 1;
1949: next;
1950: }
1951: }
1952: }
1953: }
1954: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1955: my $prefix = $1;
1956: my $fromothercrs;
1957: #need to copy the db contents to a new one, unless this is a move.
1958: my %info = (
1959: src => $url,
1960: cdom => $coursedom,
1961: cnum => $coursenum,
1962: );
1963: if ($prefix eq 'ext.tool') {
1964: if ($prefixchg{$suffix} eq 'docstosupp') {
1965: $info{'delgradable'} = 1;
1966: }
1967: }
1968: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1969: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1970: $fromothercrs = 1;
1971: $info{'cdom'} = $srcdom{$suffix};
1972: $info{'cnum'} = $srcnum{$suffix};
1973: }
1974: }
1975: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1976: my (%lockerr,$msg);
1977: my ($newurl,$result,$errtext) =
1978: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1979: if ($result eq 'ok') {
1980: $url = $newurl;
1981: $title=&mt('Copy of').' '.$title;
1982: } else {
1983: if ($prefix eq 'smppg') {
1984: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1985: } elsif ($prefix eq 'bulletinboard') {
1986: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1987: } elsif ($prefix eq 'ext.tool') {
1988: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1989: }
1990: $results{$suffix} = $result;
1991: $msgerrs{$suffix} = $msg;
1992: $lockerrs{$suffix} = $lockerr{$prefix};
1993: next;
1994: }
1995: if ($lockerr{$prefix}) {
1996: $lockerrs{$suffix} = $lockerr{$prefix};
1997: }
1998: }
1999: }
2000: $title = &LONCAPA::map::qtunescape($title);
2001: my $ext='false';
2002: if ($url=~m{^http(|s)://}) { $ext='true'; }
2003: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2004: if ($folder !~ /^supplemental/) {
2005: (undef,undef,$title) =
2006: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2007: }
2008: } else {
2009: if ($folder=~/^supplemental/) {
2010: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2011: $env{'user.domain'}.'___&&&___'.$title;
2012: }
2013: }
2014:
2015: # For uploaded files (excluding pages/sequences) path in copied file is changed
2016: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2017: # courses.
2018:
2019: unless ($is_map{$suffix}) {
2020: my $newidx;
2021: # Now insert the URL at the bottom
2022: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2023: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2024: my $relpath = $1;
2025: if ($relpath ne '') {
2026: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2027: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2028: my $newprefix = $newloc;
2029: if ($newloc eq 'default') {
2030: $newprefix = 'docs';
2031: }
2032: if ($newdocsdir eq '') {
2033: $newdocsdir = 'default';
2034: }
2035: if (($prefixchg{$suffix}) ||
2036: ($srcdom{$suffix} ne $coursedom) ||
2037: ($srcnum{$suffix} ne $coursenum) ||
2038: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2039: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2040: $url =
2041: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2042: &Apache::lonnet::getfile($oldurl));
2043: if ($url eq '/adm/notfound.html') {
2044: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2045: next;
2046: } else {
2047: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2048: $newsubpath =~ s{/+$}{/};
2049: $docmoves{$oldurl} = $newsubpath;
2050: }
2051: }
2052: }
2053: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2054: my $template = $1;
2055: if ($newidx) {
2056: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2057: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2058: }
2059: } elsif ($url =~ /ext\.tool$/) {
2060: if (($newidx) && ($folder=~/^default/)) {
2061: my $marker = (split(m{/},$url))[4];
2062: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2063: my $val = 'no';
2064: if ($toolsettings{'gradable'}) {
2065: $val = 'yes';
2066: }
2067: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2068: 'string_yesno');
2069: &remember_parms($newidx,'gradable','set',$val);
2070: }
2071: }
2072: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2073: ':'.$ext.':normal:res';
2074: push(@LONCAPA::map::order,$newidx);
2075: # Store the result
2076: my ($errtext,$fatal) =
2077: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2078: if ($fatal) {
2079: $save_err .= $errtext;
2080: $allresult = 'fail';
2081: }
2082: }
2083:
2084: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2085: # resourcedata for simpleproblems copied from another course
2086: unless ($allresult eq 'fail') {
2087: my %updated = (
2088: rewrites => \%rewrites,
2089: zombies => \%zombies,
2090: removefrommap => \%removefrommap,
2091: removeparam => \%removeparam,
2092: dbcopies => \%dbcopies,
2093: resdatacopy => \%resdatacopy,
2094: retitles => \%retitles,
2095: );
2096: my %info = (
2097: newsubdir => \%newsubdir,
2098: params => \%params,
2099: );
2100: if ($prefixchg{$suffix}) {
2101: $info{'before'} = $before{$prefixchg{$suffix}};
2102: $info{'after'} = $after{$prefixchg{$suffix}};
2103: }
2104: my %moves = (
2105: copies => \%copies,
2106: docmoves => \%docmoves,
2107: mapmoves => \%mapmoves,
2108: );
2109: (my $result,$msgs{$suffix},my $lockerror) =
2110: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2111: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2112: $url,'paste');
2113: $lockerrors .= $lockerror;
2114: if ($result eq 'ok') {
2115: if ($is_map{$suffix}) {
2116: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2117: $folder.'.'.$container);
2118: if ($fatal) {
2119: $allresult = 'failread';
2120: } else {
2121: if ($#LONCAPA::map::order<1) {
2122: my $idx=&LONCAPA::map::getresidx();
2123: if ($idx<=0) { $idx=1; }
2124: $LONCAPA::map::order[0]=$idx;
2125: $LONCAPA::map::resources[$idx]='';
2126: }
2127: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2128: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2129: ':'.$ext.':normal:res';
2130: push(@LONCAPA::map::order,$newidx);
2131:
2132: # Store the result
2133: my ($errtext,$fatal) =
2134: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2135: if ($fatal) {
2136: $save_err .= $errtext;
2137: $allresult = 'failstore';
2138: }
2139: }
2140: }
2141: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2142: push(@toclear,$suffix);
2143: }
2144: }
2145: }
2146: }
2147: &clear_from_buffer(\@toclear,\@currpaste);
2148: my $msgsarray;
2149: foreach my $suffix (keys(%msgs)) {
2150: if (ref($msgs{$suffix}) eq 'ARRAY') {
2151: $msgsarray .= join(',',@{$msgs{$suffix}});
2152: }
2153: }
2154: return ($allresult,$save_err,$msgsarray,$lockerrors);
2155: }
2156:
2157: sub do_buffer_empty {
2158: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2159: if (@currpaste == 0) {
2160: return &mt('Clipboard is already empty');
2161: }
2162: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2163: if (@toclear == 0) {
2164: return &mt('Nothing selected to clear from clipboard');
2165: }
2166: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2167: if ($numdel) {
2168: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2169: } else {
2170: return &mt('Clipboard unchanged');
2171: }
2172: return;
2173: }
2174:
2175: sub clear_from_buffer {
2176: my ($toclear,$currpaste) = @_;
2177: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2178: my %pastebuffer;
2179: map { $pastebuffer{$_} = 1; } @{$currpaste};
2180: my $numdel = 0;
2181: foreach my $suffix (@{$toclear}) {
2182: next if ($suffix =~ /\D/);
2183: next unless (exists($pastebuffer{$suffix}));
2184: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2185: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2186: delete($pastebuffer{$suffix});
2187: $numdel ++;
2188: }
2189: }
2190: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2191: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2192: return $numdel;
2193: }
2194:
2195: sub get_newmap_url {
2196: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2197: $titleref,$allmaps,$newurls) = @_;
2198: my $newurl;
2199: if ($url=~ m{^/uploaded/}) {
2200: $$titleref=&mt('Copy of').' '.$$titleref;
2201: }
2202: my $now = time;
2203: my $suffix=$$.int(rand(100)).$now;
2204: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2205: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2206: my $path = $1;
2207: my $prefix = $2;
2208: my $ancestor = $3;
2209: if (length($ancestor) > 10) {
2210: $ancestor = substr($ancestor,-10,10);
2211: }
2212: my $newid;
2213: if ($prefixchg) {
2214: if ($folder =~ /^supplemental/) {
2215: $prefix =~ s/^default/supplemental/;
2216: } else {
2217: $prefix =~ s/^supplemental/default/;
2218: }
2219: }
2220: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2221: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2222: } else {
2223: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2224: }
2225: my $counter = 0;
2226: my $is_unique = &uniqueness_check($newurl);
2227: if ($folder =~ /^default/) {
2228: if ($allmaps->{$newurl}) {
2229: $is_unique = 0;
2230: }
2231: }
2232: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2233: $counter ++;
2234: $suffix ++;
2235: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2236: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2237: } else {
2238: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2239: }
2240: $is_unique = &uniqueness_check($newurl);
2241: }
2242: if ($is_unique) {
2243: $newurls->{$newurl} = 1;
2244: } else {
2245: if ($url=~/\.page$/) {
2246: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2247: } else {
2248: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2249: }
2250: }
2251: }
2252: return ($newurl);
2253: }
2254:
2255: sub dbcopy {
2256: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2257: my ($url,$result,$errtext);
2258: if (ref($dbref) eq 'HASH') {
2259: $url = $dbref->{'src'};
2260: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
2261: my $prefix = $1;
2262: if ($prefix eq 'ext.tool') {
2263: $prefix = 'exttool';
2264: }
2265: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2266: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2267: my $db_name;
2268: my $marker = (split(m{/},$url))[4];
2269: $marker=~s/\D//g;
2270: if ($dbref->{'src'} =~ m{/smppg$}) {
2271: $db_name =
2272: &Apache::lonsimplepage::get_db_name($url,$marker,
2273: $dbref->{'cdom'},
2274: $dbref->{'cnum'});
2275: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2276: $db_name = 'exttool_'.$marker;
2277: } else {
2278: $db_name = 'bulletinpage_'.$marker;
2279: }
2280: my ($suffix,$freedlock,$error) =
2281: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2282: $coursedom,$coursenum,
2283: 'concat');
2284: if (!$suffix) {
2285: if ($prefix eq 'smppg') {
2286: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2287: } elsif ($prefix eq 'exttool') {
2288: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
2289: } else {
2290: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
2291: }
2292: if ($error) {
2293: $errtext .= '<br />'.$error;
2294: }
2295: } else {
2296: #need to copy the db contents to a new one.
2297: my %contents=&Apache::lonnet::dump($db_name,
2298: $dbref->{'cdom'},
2299: $dbref->{'cnum'});
2300: if (exists($contents{'uploaded.photourl'})) {
2301: my $photo = $contents{'uploaded.photourl'};
2302: my ($subdir,$fname) =
2303: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2304: my $newphoto;
2305: if ($fname ne '') {
2306: my $content = &Apache::lonnet::getfile($photo);
2307: unless ($content eq '-1') {
2308: $env{'form.'.$suffix.'.photourl'} = $content;
2309: $newphoto =
2310: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2311: delete($env{'form.'.$suffix.'.photourl'});
2312: }
2313: }
2314: if ($newphoto =~ m{^/uploaded/}) {
2315: $contents{'uploaded.photourl'} = $newphoto;
2316: }
2317: }
2318: $db_name =~ s{_\d*$ }{_$suffix}x;
2319: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2320: delete($contents{'gradable'});
2321: }
2322: $result=&Apache::lonnet::put($db_name,\%contents,
2323: $coursedom,$coursenum);
2324: if ($result eq 'ok') {
2325: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
2326: }
2327: }
2328: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2329: $lockerrorsref->{$prefix} =
2330: '<div class="LC_error">'.
2331: &mt('There was a problem removing a lockfile.');
2332: if ($prefix eq 'smppg') {
2333: $lockerrorsref->{$prefix} .=
2334: ' '.&mt('This will prevent creation of additional simple pages in this course.');
2335: } elsif ($prefix eq 'exttool') {
2336: $lockerrorsref->{$prefix} .=
2337: ' '.&mt('This will prevent addition of more external tools to this course.');
2338: } else {
2339: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
2340: }
2341: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2342: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2343: '</div>';
2344: }
2345: }
2346: } elsif ($url =~ m{/syllabus$}) {
2347: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2348: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2349: if (($dbref->{'cdom'} ne $coursedom) ||
2350: ($dbref->{'cnum'} ne $coursenum)) {
2351: my %contents=&Apache::lonnet::dump('syllabus',
2352: $dbref->{'cdom'},
2353: $dbref->{'cnum'});
2354: $result=&Apache::lonnet::put('syllabus',\%contents,
2355: $coursedom,$coursenum);
2356: }
2357: }
2358: }
2359: }
2360: return ($url,$result,$errtext);
2361: }
2362:
2363: sub copy_templated_files {
2364: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2365: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2366: my $srccontainer = 'sequence';
2367: if ($srcwaspage) {
2368: $srccontainer = 'page';
2369: }
2370: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2371: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2372: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2373: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2374: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2375: $template.'.problem';
2376: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2377: if ($template eq 'simpleproblem') {
2378: $srcprefix .= '.0.';
2379: my $weightprefix = $newprefix;
2380: $newprefix .= '.0.';
2381: my @simpleprobqtypes = qw(radio option string essay numerical);
2382: my $qtype=$srcparms{$srcprefix.'questiontype'};
2383: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2384: my %newdata = (
2385: $newprefix.'questiontype' => $qtype,
2386: );
2387: foreach my $type (@simpleprobqtypes) {
2388: if ($type eq $qtype) {
2389: $newdata{"$weightprefix.$type.weight"}=1;
2390: } else {
2391: $newdata{"$weightprefix.$type.weight"}=0;
2392: }
2393: }
2394: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2395: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2396: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2397: if ($qtype eq 'numerical') {
2398: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2399: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2400: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2401: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2402: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2403: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2404: unless (defined($maxfoils)) { $maxfoils=10; }
2405: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2406: if ($maxfoils<=0) { $maxfoils=10; }
2407: my $randomize=$srcparms{$srcprefix.'randomize'};
2408: unless (defined($randomize)) { $randomize='yes'; }
2409: unless ($randomize eq 'no') { $randomize='yes'; }
2410: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2411: $newdata{$newprefix.'randomize'} = $randomize;
2412: if ($qtype eq 'option') {
2413: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2414: }
2415: for (my $i=1; $i<=10; $i++) {
2416: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2417: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2418: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2419: }
2420:
2421: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2422: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2423: unless (defined($maxfoils)) { $maxfoils=10; }
2424: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2425: if ($maxfoils<=0) { $maxfoils=10; }
2426: my $randomize=$srcparms{$srcprefix.'randomize'};
2427: unless (defined($randomize)) { $randomize='yes'; }
2428: unless ($randomize eq 'no') { $randomize='yes'; }
2429: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2430: $newdata{$newprefix.'randomize'} = $randomize;
2431: if ($qtype eq 'option') {
2432: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2433: }
2434: for (my $i=1; $i<=10; $i++) {
2435: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2436: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2437: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2438: }
2439: } elsif ($qtype eq 'string') {
2440: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2441: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2442: }
2443: if (keys(%newdata)) {
2444: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2445: $coursenum);
2446: if ($putres eq 'ok') {
2447: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2448: }
2449: }
2450: }
2451: }
2452: }
2453:
2454: sub uniqueness_check {
2455: my ($newurl) = @_;
2456: my $unique = 1;
2457: foreach my $res (@LONCAPA::map::order) {
2458: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2459: $url=&LONCAPA::map::qtescape($url);
2460: if ($newurl eq $url) {
2461: $unique = 0;
2462: last;
2463: }
2464: }
2465: return $unique;
2466: }
2467:
2468: sub contained_map_check {
2469: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2470: $hierarchy,$titles,$allmaps) = @_;
2471: my $content = &Apache::lonnet::getfile($url);
2472: unless ($content eq '-1') {
2473: my $parser = HTML::TokeParser->new(\$content);
2474: $parser->attr_encoded(1);
2475: while (my $token = $parser->get_token) {
2476: next if ($token->[0] ne 'S');
2477: if ($token->[1] eq 'resource') {
2478: next if ($token->[2]->{'type'} eq 'zombie');
2479: my $ressrc = $token->[2]->{'src'};
2480: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2481: my $srcdom = $1;
2482: unless ($srcdom eq $coursedom) {
2483: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2484: next;
2485: }
2486: } elsif ($folder =~ /^supplemental/) {
2487: unless (&supp_pasteable($ressrc)) {
2488: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2489: next;
2490: }
2491: }
2492: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2493: if ($1 eq 'uploaded') {
2494: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2495: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2496: } else {
2497: if ($allmaps->{$ressrc}) {
2498: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2499: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2500: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2501: } else {
2502: $addedmaps->{$ressrc} = [$url];
2503: }
2504: }
2505: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2506: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
2507: }
2508: } elsif ($token->[1] eq 'param') {
2509: if ($folder =~ /^supplemental/) {
2510: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2511: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2512: } else {
2513: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2514: }
2515: }
2516: }
2517: }
2518: }
2519: return;
2520: }
2521:
2522: sub url_paste_fixups {
2523: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2524: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
2525: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
2526: my $checktitle;
2527: if (($prefixchg) &&
2528: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2529: $checktitle = 1;
2530: }
2531: my $skip;
2532: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2533: my $mapid = $1.$2;
2534: if ($tomove->{$mapid}) {
2535: $skip = 1;
2536: }
2537: }
2538: my $file = &Apache::lonnet::getfile($oldurl);
2539: return if ($file eq '-1');
2540: my $parser = HTML::TokeParser->new(\$file);
2541: $parser->attr_encoded(1);
2542: my $changed = 0;
2543: while (my $token = $parser->get_token) {
2544: next if ($token->[0] ne 'S');
2545: if ($token->[1] eq 'resource') {
2546: my $ressrc = $token->[2]->{'src'};
2547: next if ($ressrc eq '');
2548: my $id = $token->[2]->{'id'};
2549: my $title = $token->[2]->{'title'};
2550: if ($checktitle) {
2551: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2552: $retitles->{$oldurl}{$id} = $ressrc;
2553: }
2554: }
2555: next if ($token->[2]->{'type'} eq 'external');
2556: if ($token->[2]->{'type'} eq 'zombie') {
2557: next if ($skip);
2558: $zombies->{$oldurl}{$id} = $ressrc;
2559: $changed = 1;
2560: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2561: my $srcdom = $1;
2562: my $srcnum = $2;
2563: my $rem = $3;
2564: my $newurl;
2565: my $mapname;
2566: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2567: my $prefix = $1;
2568: $mapname = $prefix.$2;
2569: if ($tomove->{$mapname}) {
2570: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2571: $srcdom,$srcnum,$allmaps,$rewrites,
2572: $retitles,$copies,$dbcopies,$zombies,
2573: $params,$mapmoves,$mapchanges,$tomove,
2574: $newsubdir,$newurls,$resdatacopy);
2575: next;
2576: } else {
2577: ($newurl,my $error) =
2578: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2579: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2580: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2581: $newsubdir->{$ressrc} = $1;
2582: }
2583: if ($error) {
2584: next;
2585: }
2586: }
2587: }
2588: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2589: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2590:
2591: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2592: $rewrites->{$oldurl}{$id} = $ressrc;
2593: $mapchanges->{$ressrc} = 1;
2594: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2595: $cnum,$srcdom,$srcnum,$allmaps,
2596: $rewrites,$retitles,$copies,$dbcopies,
2597: $zombies,$params,$mapmoves,$mapchanges,
2598: $tomove,$newsubdir,$newurls,$resdatacopy)) {
2599: $mapmoves->{$ressrc} = 1;
2600: }
2601: $changed = 1;
2602: } else {
2603: $rewrites->{$oldurl}{$id} = $ressrc;
2604: $copies->{$oldurl}{$ressrc} = $id;
2605: $changed = 1;
2606: }
2607: }
2608: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
2609: next if ($skip);
2610: my $srcdom = $1;
2611: my $srcnum = $2;
2612: my $rem = $3;
2613: my ($is_exttool,$exttoolchg);
2614: if ($rem =~ m{\d+/ext\.tool$}) {
2615: $is_exttool = 1;
2616: }
2617: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2618: $rewrites->{$oldurl}{$id} = $ressrc;
2619: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2620: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2621: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2622: $changed = 1;
2623: if ($is_exttool) {
2624: $exttoolchg = 1;
2625: }
2626: } elsif (($rem =~ m{\d+/ext\.tool$}) &&
2627: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2628: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2629: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2630: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2631: $changed = 1;
2632: $exttoolchg = 1;
2633: }
2634: if (($is_exttool) && ($prefixchg)) {
2635: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2636: if ($exttoolchg) {
2637: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2638: }
2639: }
2640: }
2641: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2642: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2643: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2644: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2645: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2646: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
2647: $changed = 1;
2648: }
2649: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2650: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2651: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2652: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2653: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2654: }
2655: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2656: next if ($skip);
2657: my $srcdom = $1;
2658: my $srcnum = $2;
2659: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2660: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2661: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2662: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2663: $changed = 1;
2664: }
2665: }
2666: } elsif ($token->[1] eq 'param') {
2667: next if ($skip);
2668: my $to = $token->[2]->{'to'};
2669: if ($to ne '') {
2670: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2671: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2672: } else {
2673: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2674: }
2675: }
2676: }
2677: }
2678: return $changed;
2679: }
2680:
2681: sub apply_fixups {
2682: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2683: $oldurl,$url,$caller) = @_;
2684: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
2685: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
2686: %resdatacopy,%lockerrors,$lockmsg);
2687: if (ref($updated) eq 'HASH') {
2688: if (ref($updated->{'rewrites'}) eq 'HASH') {
2689: %rewrites = %{$updated->{'rewrites'}};
2690: }
2691: if (ref($updated->{'zombies'}) eq 'HASH') {
2692: %zombies = %{$updated->{'zombies'}};
2693: }
2694: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2695: %removefrommap = %{$updated->{'removefrommap'}};
2696: }
2697: if (ref($updated->{'removeparam'}) eq 'HASH') {
2698: %removeparam = %{$updated->{'removeparam'}};
2699: }
2700: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2701: %dbcopies = %{$updated->{'dbcopies'}};
2702: }
2703: if (ref($updated->{'retitles'}) eq 'HASH') {
2704: %retitles = %{$updated->{'retitles'}};
2705: }
2706: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2707: %resdatacopy = %{$updated->{'resdatacopy'}};
2708: }
2709: }
2710: if (ref($info) eq 'HASH') {
2711: if (ref($info->{'newsubdir'}) eq 'HASH') {
2712: %newsubdir = %{$info->{'newsubdir'}};
2713: }
2714: if (ref($info->{'params'}) eq 'HASH') {
2715: %params = %{$info->{'params'}};
2716: }
2717: if (ref($info->{'before'}) eq 'HASH') {
2718: %before = %{$info->{'before'}};
2719: }
2720: if (ref($info->{'after'}) eq 'HASH') {
2721: %after = %{$info->{'after'}};
2722: }
2723: }
2724: if (ref($moves) eq 'HASH') {
2725: if (ref($moves->{'copies'}) eq 'HASH') {
2726: %copies = %{$moves->{'copies'}};
2727: }
2728: if (ref($moves->{'docmoves'}) eq 'HASH') {
2729: %docmoves = %{$moves->{'docmoves'}};
2730: }
2731: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2732: %mapmoves = %{$moves->{'mapmoves'}};
2733: }
2734: }
2735: foreach my $key (keys(%copies),keys(%docmoves)) {
2736: my @allcopies;
2737: if (exists($copies{$key})) {
2738: if (ref($copies{$key}) eq 'HASH') {
2739: my %added;
2740: foreach my $innerkey (keys(%{$copies{$key}})) {
2741: if (($innerkey ne '') && (!$added{$innerkey})) {
2742: push(@allcopies,$innerkey);
2743: $added{$innerkey} = 1;
2744: }
2745: }
2746: undef(%added);
2747: }
2748: }
2749: if ($key eq $oldurl) {
2750: if ((exists($docmoves{$key}))) {
2751: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
2752: push(@allcopies,$oldurl);
2753: }
2754: }
2755: }
2756: if (@allcopies > 0) {
2757: foreach my $item (@allcopies) {
2758: my ($relpath,$oldsubdir,$fname) =
2759: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2760: if ($fname ne '') {
2761: my $content = &Apache::lonnet::getfile($item);
2762: unless ($content eq '-1') {
2763: my $storefn;
2764: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2765: $storefn = $docmoves{$key};
2766: } else {
2767: $storefn = $relpath;
2768: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
2769: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2770: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
2771: }
2772: if ($newsubdir{$key}) {
2773: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
2774: }
2775: }
2776: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2777: my $copyurl =
2778: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2779: $storefn.$fname,$content);
2780: if ($copyurl eq '/adm/notfound.html') {
2781: if (exists($docmoves{$oldurl})) {
2782: return &mt('Paste failed: an error occurred copying the file.');
2783: } elsif (ref($errors) eq 'HASH') {
2784: $errors->{$item} = 1;
2785: }
2786: }
2787: }
2788: }
2789: }
2790: }
2791: }
2792: foreach my $key (keys(%mapmoves)) {
2793: my $storefn=$key;
2794: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2795: if ($prefixchg && $before{'map'} && $after{'map'}) {
2796: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2797: }
2798: if ($newsubdir{$key}) {
2799: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2800: }
2801: my $mapcontent = &Apache::lonnet::getfile($key);
2802: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
2803: ($after{'map'} eq 'default') &&
2804: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
2805: $mapcontent = '<map>'."\n".
2806: '<resource id="1" src="" type="start" />'."\n".
2807: '<link from="1" to="2" index="1" />'."\n".
2808: '<resource id="2" src="" type="finish" />'."\n".
2809: '</map>';
2810: }
2811: if ($mapcontent eq '-1') {
2812: if (ref($errors) eq 'HASH') {
2813: $errors->{$key} = 1;
2814: }
2815: } else {
2816: my $newmap =
2817: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2818: $mapcontent);
2819: if ($newmap eq '/adm/notfound.html') {
2820: if (ref($errors) eq 'HASH') {
2821: $errors->{$key} = 1;
2822: }
2823: }
2824: }
2825: }
2826: my %updates;
2827: if ($is_map) {
2828: if (ref($updated) eq 'HASH') {
2829: foreach my $type (keys(%{$updated})) {
2830: if (ref($updated->{$type}) eq 'HASH') {
2831: foreach my $key (keys(%{$updated->{$type}})) {
2832: $updates{$key} = 1;
2833: }
2834: }
2835: }
2836: }
2837: foreach my $key (keys(%updates)) {
2838: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
2839: if (ref($rewrites{$key}) eq 'HASH') {
2840: %torewrite = %{$rewrites{$key}};
2841: }
2842: if (ref($retitles{$key}) eq 'HASH') {
2843: %toretitle = %{$retitles{$key}};
2844: }
2845: if (ref($removefrommap{$key}) eq 'HASH') {
2846: %toremove = %{$removefrommap{$key}};
2847: }
2848: if (ref($removeparam{$key}) eq 'HASH') {
2849: %remparam = %{$removeparam{$key}};
2850: }
2851: if (ref($zombies{$key}) eq 'HASH') {
2852: %zombie = %{$zombies{$key}};
2853: }
2854: if (ref($dbcopies{$key}) eq 'HASH') {
2855: foreach my $idx (keys(%{$dbcopies{$key}})) {
2856: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2857: my ($newurl,$result,$errtext) =
2858: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2859: if ($result eq 'ok') {
2860: $newdb{$idx} = $newurl;
2861: } elsif (ref($errors) eq 'HASH') {
2862: $errors->{$key} = 1;
2863: }
2864: push(@msgs,$errtext);
2865: }
2866: }
2867: }
2868: if (ref($resdatacopy{$key}) eq 'HASH') {
2869: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2870: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2871: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2872: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2873: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2874: my $template = $1;
2875: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2876: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2877: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2878: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2879: unless ($gotnewmapname) {
2880: ($newmapname) = ($key =~ m{/([^/]+)$});
2881: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2882: if ($newsubdir{$key}) {
2883: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2884: }
2885: $gotnewmapname = 1;
2886: }
2887: my $srcmapinfo = $srcfolder.':'.$idx;
2888: if ($srccontainer eq 'page') {
2889: $srcmapinfo .= ':1';
2890: }
2891: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2892: $cnum,$template,$idx,$newmapname);
2893: }
2894: }
2895: }
2896: }
2897: }
2898: if (ref($params{$key}) eq 'HASH') {
2899: %currparam = %{$params{$key}};
2900: }
2901: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2902: if ($fatal) {
2903: return ($errtext);
2904: }
2905: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2906: if (defined($LONCAPA::map::zombies[$i])) {
2907: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
2908: if ($zombie{$i} eq $src) {
2909: undef($LONCAPA::map::zombies[$i]);
2910: }
2911: }
2912: }
2913: my $total = scalar(@LONCAPA::map::order) - 1;
2914: for (my $i=$total; $i>=0; $i--) {
2915: my $idx = $LONCAPA::map::order[$i];
2916: if (defined($LONCAPA::map::resources[$idx])) {
2917: my $changed;
2918: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
2919: if ((exists($toremove{$idx})) &&
2920: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
2921: splice(@LONCAPA::map::order,$i,1);
2922: if (ref($currparam{$idx}) eq 'ARRAY') {
2923: foreach my $name (@{$currparam{$idx}}) {
2924: &LONCAPA::map::delparameter($idx,$name);
2925: }
2926: }
2927: next;
2928: }
2929: my $origsrc = $src;
2930: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
2931: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2932: $changed = 1;
2933: }
2934: }
2935: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
2936: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2937: if ($origsrc =~ m{^/uploaded/}) {
2938: if ($prefixchg && $before{'map'} && $after{'map'}) {
2939: if ($src =~ /\.(page|sequence)$/) {
2940: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
2941: } else {
2942: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
2943: }
2944: }
2945: if ($origsrc =~ /\.(page|sequence)$/) {
2946: if ($newsubdir{$origsrc}) {
2947: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
2948: }
2949: } elsif ($newsubdir{$key}) {
2950: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
2951: }
2952: }
2953: $changed = 1;
2954: } elsif ($newdb{$idx} ne '') {
2955: $src = $newdb{$idx};
2956: $changed = 1;
2957: }
2958: if ($changed) {
2959: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
2960: }
2961: }
2962: }
2963: foreach my $idx (keys(%remparam)) {
2964: if (ref($remparam{$idx}) eq 'ARRAY') {
2965: foreach my $name (@{$remparam{$idx}}) {
2966: &LONCAPA::map::delparameter($idx,$name);
2967: }
2968: }
2969: }
2970: if (values(%lockerrors) > 0) {
2971: $lockmsg = join('<br />',values(%lockerrors));
2972: }
2973: my $storefn;
2974: if ($key eq $oldurl) {
2975: $storefn = $url;
2976: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2977: } else {
2978: $storefn = $key;
2979: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2980: if ($prefixchg && $before{'map'} && $after{'map'}) {
2981: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2982: }
2983: if ($newsubdir{$key}) {
2984: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2985: }
2986: }
2987: my $report;
2988: if ($folder !~ /^supplemental/) {
2989: $report = 1;
2990: }
2991: (my $outtext,$errtext) =
2992: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2993: if ($errtext) {
2994: if ($caller eq 'paste') {
2995: return (&mt('Paste failed: an error occurred saving the folder or page.'));
2996: }
2997: }
2998: }
2999: }
3000: return ('ok',\@msgs,$lockmsg);
3001: }
3002:
3003: sub copy_dependencies {
3004: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3005: my $content;
3006: if (ref($contentref)) {
3007: $content = $$contentref;
3008: } else {
3009: $content = &Apache::lonnet::getfile($item);
3010: }
3011: unless ($content eq '-1') {
3012: my $mm = new File::MMagic;
3013: my $mimetype = $mm->checktype_contents($content);
3014: if ($mimetype eq 'text/html') {
3015: my (%allfiles,%codebase,$state);
3016: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3017: if ($res eq 'ok') {
3018: my ($numexisting,$numpathchanges,$existing);
3019: (undef,$numexisting,$numpathchanges,$existing) =
3020: &Apache::loncommon::ask_for_embedded_content(
3021: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3022: {'error_on_invalid_names' => 1,
3023: 'ignore_remote_references' => 1,
3024: 'docs_url' => $item,
3025: 'context' => 'paste'});
3026: if ($numexisting > 0) {
3027: if (ref($existing) eq 'HASH') {
3028: foreach my $dep (keys(%{$existing})) {
3029: my $depfile = $dep;
3030: unless ($depfile =~ m{^\Q$relpath\E}) {
3031: $depfile = $relpath.$dep;
3032: }
3033: my $depcontent = &Apache::lonnet::getfile($depfile);
3034: unless ($depcontent eq '-1') {
3035: my $storedep = $dep;
3036: $storedep =~ s{^\Q$relpath\E}{};
3037: my $dep_url =
3038: &Apache::lonclonecourse::writefile(
3039: $env{'request.course.id'},
3040: $storefn.$storedep,$depcontent);
3041: if ($dep_url eq '/adm/notfound.html') {
3042: if (ref($errors) eq 'HASH') {
3043: $errors->{$depfile} = 1;
3044: }
3045: } else {
3046: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3047: }
3048: }
3049: }
3050: }
3051: }
3052: }
3053: }
3054: }
3055: return;
3056: }
3057:
3058: my %parameter_type = ( 'randompick' => 'int_pos',
3059: 'hiddenresource' => 'string_yesno',
3060: 'encrypturl' => 'string_yesno',
3061: 'randomorder' => 'string_yesno',);
3062: my $valid_parameters_re = join('|',keys(%parameter_type));
3063: # set parameters
3064: sub update_parameter {
3065: if ($env{'form.changeparms'} eq 'all') {
3066: my (@allidx,@allmapidx,%allchecked,%currchecked);
3067: %allchecked = (
3068: 'hiddenresource' => {},
3069: 'encrypturl' => {},
3070: 'randompick' => {},
3071: 'randomorder' => {},
3072: );
3073: foreach my $which (keys(%allchecked)) {
3074: $env{'form.all'.$which} =~ s/,$//;
3075: if ($which eq 'randompick') {
3076: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3077: my ($res,$value) = split(/:/,$item);
3078: if ($value =~ /^\d+$/) {
3079: $allchecked{$which}{$res} = $value;
3080: }
3081: }
3082: } else {
3083: if ($env{'form.all'.$which}) {
3084: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3085: }
3086: }
3087: }
3088: my $haschanges = 0;
3089: foreach my $res (@LONCAPA::map::order) {
3090: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3091: $name=&LONCAPA::map::qtescape($name);
3092: $url=&LONCAPA::map::qtescape($url);
3093: next unless ($name && $url);
3094: my $is_map;
3095: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3096: $is_map = 1;
3097: }
3098: foreach my $which (keys(%allchecked)) {
3099: if (($which eq 'randompick' || $which eq 'randomorder')) {
3100: next if (!$is_map);
3101: }
3102: my $oldvalue = 0;
3103: my $newvalue = 0;
3104: if ($allchecked{$which}{$res}) {
3105: $newvalue = $allchecked{$which}{$res};
3106: }
3107: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3108: if ($which eq 'randompick') {
3109: if ($current =~ /^(\d+)$/) {
3110: $oldvalue = $1;
3111: }
3112: } else {
3113: if ($current =~ /^yes$/i) {
3114: $oldvalue = 1;
3115: }
3116: }
3117: if ($oldvalue ne $newvalue) {
3118: $haschanges = 1;
3119: if ($newvalue) {
3120: my $storeval = 'yes';
3121: if ($which eq 'randompick') {
3122: $storeval = $newvalue;
3123: }
3124: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3125: $storeval,
3126: $parameter_type{$which});
3127: &remember_parms($res,$which,'set',$storeval);
3128: } elsif ($oldvalue) {
3129: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3130: &remember_parms($res,$which,'del');
3131: }
3132: }
3133: }
3134: }
3135: return $haschanges;
3136: } else {
3137: my $haschanges = 0;
3138: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
3139:
3140: my $which = $env{'form.changeparms'};
3141: my $idx = $env{'form.setparms'};
3142: my $oldvalue = 0;
3143: my $newvalue = 0;
3144: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3145: if ($which eq 'randompick') {
3146: if ($current =~ /^(\d+)$/) {
3147: $oldvalue = $1;
3148: }
3149: } elsif ($current =~ /^yes$/i) {
3150: $oldvalue = 1;
3151: }
3152: if ($env{'form.'.$which.'_'.$idx}) {
3153: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3154: : 1;
3155: }
3156: if ($oldvalue ne $newvalue) {
3157: $haschanges = 1;
3158: if ($newvalue) {
3159: my $storeval = 'yes';
3160: if ($which eq 'randompick') {
3161: $storeval = $newvalue;
3162: }
3163: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3164: $parameter_type{$which});
3165: &remember_parms($idx,$which,'set',$storeval);
3166: } else {
3167: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3168: &remember_parms($idx,$which,'del');
3169: }
3170: }
3171: return $haschanges;
3172: }
3173: }
3174:
3175: sub handle_edit_cmd {
3176: my ($coursenum,$coursedom) =@_;
3177: my $haschanges = 0;
3178: if ($env{'form.cmd'} eq '') {
3179: return $haschanges;
3180: }
3181: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3182:
3183: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3184: my ($title, $url, @rrest) = split(':', $ratstr);
3185:
3186: if ($cmd eq 'remove') {
3187: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3188: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3189: &Apache::lonnet::removeuploadedurl($url);
3190: } else {
3191: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3192: }
3193: splice(@LONCAPA::map::order, $idx, 1);
3194: $haschanges = 1;
3195: } elsif ($cmd eq 'cut') {
3196: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3197: splice(@LONCAPA::map::order, $idx, 1);
3198: $haschanges = 1;
3199: } elsif ($cmd eq 'up'
3200: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3201: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3202: $haschanges = 1;
3203: } elsif ($cmd eq 'down'
3204: && defined($LONCAPA::map::order[$idx+1])) {
3205: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3206: $haschanges = 1;
3207: } elsif ($cmd eq 'rename') {
3208: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3209: if ($comment=~/\S/) {
3210: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3211: $comment.':'.join(':', $url, @rrest);
3212: }
3213: # Devalidate title cache
3214: my $renamed_url=&LONCAPA::map::qtescape($url);
3215: &Apache::lonnet::devalidate_title_cache($renamed_url);
3216: $haschanges = 1;
3217: } elsif ($cmd eq 'setalias') {
3218: my $newvalue = $env{'form.alias'};
3219: if ($newvalue ne '') {
3220: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3221: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3222: 'string');
3223: &remember_parms($idx,'mapalias','set',$newvalue);
3224: $haschanges = 1;
3225: }
3226: }
3227: } elsif ($cmd eq 'delalias') {
3228: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3229: if ($current ne '') {
3230: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3231: &remember_parms($idx,'mapalias','del');
3232: $haschanges = 1;
3233: }
3234: }
3235: return $haschanges;
3236: }
3237:
3238: sub editor {
3239: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
3240: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3241: $canedit,$hostname,$navmapref,$hiddentop)=@_;
3242: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3243: if ($allowed) {
3244: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3245: $is_random_order,$container) =
3246: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3247: $r->print($breadcrumbtrail);
3248: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3249: $container = 'page';
3250: } else {
3251: $container = 'sequence';
3252: }
3253:
3254: my $jumpto;
3255:
3256: unless ($supplementalflag) {
3257: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
3258: }
3259:
3260: unless ($allowed) {
3261: $randompick = -1;
3262: }
3263:
3264: my ($errtext,$fatal);
3265: if (($folder eq '') && (!$supplementalflag)) {
3266: if (@LONCAPA::map::order) {
3267: undef(@LONCAPA::map::order);
3268: undef(@LONCAPA::map::resources);
3269: undef(@LONCAPA::map::resparms);
3270: undef(@LONCAPA::map::zombies);
3271: }
3272: $folder = 'default';
3273: $container = 'sequence';
3274: } else {
3275: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3276: $folder.'.'.$container);
3277: return $errtext if ($fatal);
3278: }
3279:
3280: my (%supphidden,%suppids,$suppmapid);
3281:
3282: if ($#LONCAPA::map::order<1) {
3283: my $idx=&LONCAPA::map::getresidx();
3284: if ($idx<=0) { $idx=1; }
3285: $LONCAPA::map::order[0]=$idx;
3286: $LONCAPA::map::resources[$idx]='';
3287: } elsif ($supplementalflag && !$allowed) {
3288: my ($supplemental) = &Apache::lonnet::get_supplemental($coursenum,$coursedom);
3289: if (ref($supplemental) eq 'HASH') {
3290: if (ref($supplemental->{'hidden'}) eq 'HASH') {
3291: %supphidden = %{$supplemental->{'hidden'}};
3292: }
3293: if (ref($supplemental->{'ids'}) eq 'HASH') {
3294: %suppids = %{$supplemental->{'ids'}};
3295: }
3296: }
3297: if ($folder eq 'supplemental') {
3298: $suppmapid = 0;
3299: } elsif ($folder =~ /^supplemental_(\d+)$/) {
3300: $suppmapid = $1;
3301: }
3302: }
3303:
3304: # ------------------------------------------------------------ Process commands
3305:
3306: # ---------------- if they are for this folder and user allowed to make changes
3307: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
3308: # set parameters and change order
3309: &snapshotbefore();
3310:
3311: if (&update_parameter()) {
3312: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3313: return $errtext if ($fatal);
3314: }
3315:
3316: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3317: # change order
3318: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3319: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3320:
3321: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3322: return $errtext if ($fatal);
3323: }
3324:
3325: if ($env{'form.pastemarked'}) {
3326: my %paste_errors;
3327: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
3328: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3329: \%paste_errors);
3330: if (ref($pastemsgarray) eq 'ARRAY') {
3331: if (@{$pastemsgarray} > 0) {
3332: $r->print('<p class="LC_info">'.
3333: join('<br />',@{$pastemsgarray}).
3334: '</p>');
3335: }
3336: }
3337: if ($lockerror) {
3338: $r->print('<p class="LC_error">'.
3339: $lockerror.
3340: '</p>');
3341: }
3342: if ($save_error ne '') {
3343: return $save_error;
3344: }
3345: if ($paste_res) {
3346: my %errortext = &Apache::lonlocal::texthash (
3347: fail => 'Storage of folder contents failed',
3348: failread => 'Reading folder contents failed',
3349: failstore => 'Storage of folder contents failed',
3350: );
3351: if ($errortext{$paste_res}) {
3352: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
3353: }
3354: }
3355: if (keys(%paste_errors) > 0) {
3356: $r->print('<p class="LC_warning">'."\n".
3357: &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".
3358: '<ul>'."\n");
3359: foreach my $key (sort(keys(%paste_errors))) {
3360: $r->print('<li>'.$key.'</li>'."\n");
3361: }
3362: $r->print('</ul></p>'."\n");
3363: }
3364: } elsif ($env{'form.clearmarked'}) {
3365: my $output = &do_buffer_empty();
3366: if ($output) {
3367: $r->print('<p class="LC_info">'.$output.'</p>');
3368: }
3369: }
3370:
3371: $r->print($upload_output);
3372:
3373: # Rename, cut, copy or remove a single resource
3374: if (&handle_edit_cmd($coursenum,$coursedom)) {
3375: my $contentchg;
3376: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
3377: $contentchg = 1;
3378: }
3379: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
3380: return $errtext if ($fatal);
3381: }
3382:
3383: # Cut, copy and/or remove multiple resources
3384: if ($env{'form.multichange'}) {
3385: my %allchecked = (
3386: cut => {},
3387: remove => {},
3388: );
3389: my $needsupdate;
3390: foreach my $which (keys(%allchecked)) {
3391: $env{'form.multi'.$which} =~ s/,$//;
3392: if ($env{'form.multi'.$which}) {
3393: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3394: if (ref($allchecked{$which}) eq 'HASH') {
3395: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3396: }
3397: }
3398: }
3399: if ($needsupdate) {
3400: my $haschanges = 0;
3401: my %curr_groups = &Apache::longroup::coursegroups();
3402: my $total = scalar(@LONCAPA::map::order) - 1;
3403: for (my $i=$total; $i>=0; $i--) {
3404: my $res = $LONCAPA::map::order[$i];
3405: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3406: $name=&LONCAPA::map::qtescape($name);
3407: $url=&LONCAPA::map::qtescape($url);
3408: next unless $url;
3409: my %denied =
3410: &action_restrictions($coursenum,$coursedom,$url,
3411: $env{'form.folderpath'},\%curr_groups);
3412: foreach my $which (keys(%allchecked)) {
3413: next if ($denied{$which});
3414: next unless ($allchecked{$which}{$res});
3415: if ($which eq 'remove') {
3416: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3417: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3418: &Apache::lonnet::removeuploadedurl($url);
3419: } else {
3420: &LONCAPA::map::makezombie($res);
3421: }
3422: splice(@LONCAPA::map::order,$i,1);
3423: $haschanges ++;
3424: } elsif ($which eq 'cut') {
3425: &LONCAPA::map::makezombie($res);
3426: splice(@LONCAPA::map::order,$i,1);
3427: $haschanges ++;
3428: }
3429: }
3430: }
3431: if ($haschanges) {
3432: ($errtext,$fatal) =
3433: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3434: return $errtext if ($fatal);
3435: }
3436: }
3437: }
3438:
3439: # Group import/search
3440: if ($env{'form.importdetail'}) {
3441: my @imports;
3442: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3443: if (defined($item)) {
3444: my ($name,$url,$residx)=
3445: map { &unescape($_); } split(/\=/,$item);
3446: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3447: my ($suffix,$errortxt,$locknotfreed) =
3448: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
3449: if ($locknotfreed) {
3450: $r->print($locknotfreed);
3451: }
3452: if ($suffix) {
3453: $url =~ s/_new\./_$suffix./;
3454: } else {
3455: return $errortxt;
3456: }
3457: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3458: my $type = $1;
3459: my ($suffix,$errortxt,$locknotfreed) =
3460: &new_timebased_suffix($coursedom,$coursenum,$type);
3461: if ($locknotfreed) {
3462: $r->print($locknotfreed);
3463: }
3464: if ($suffix) {
3465: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3466: } else {
3467: return $errortxt;
3468: }
3469: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3470: my ($suffix,$errortxt,$locknotfreed) =
3471: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3472: if ($locknotfreed) {
3473: $r->print($locknotfreed);
3474: }
3475: if ($suffix) {
3476: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3477: } else {
3478: return $errortxt;
3479: }
3480: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3481: if ($supplementalflag) {
3482: next unless ($1 eq 'supplemental');
3483: if ($folder eq 'supplemental') {
3484: next unless ($2 eq 'default');
3485: } else {
3486: next unless ($folder eq 'supplemental_'.$2);
3487: }
3488: } else {
3489: next unless ($1 eq 'docs');
3490: if ($folder eq 'default') {
3491: next unless ($2 eq 'default');
3492: } else {
3493: next unless ($folder eq 'default_'.$2);
3494: }
3495: }
3496: }
3497: push(@imports, [$name, $url, $residx]);
3498: }
3499: }
3500: ($errtext,$fatal,my $fixuperrors) =
3501: &group_import($coursenum, $coursedom, $folder,$container,
3502: 'londocs',$ltitoolsref,@imports);
3503: return $errtext if ($fatal);
3504: if ($fixuperrors) {
3505: $r->print($fixuperrors);
3506: }
3507: }
3508: # Loading a complete map
3509: if ($env{'form.loadmap'}) {
3510: if ($env{'form.importmap'}=~/\w/) {
3511: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3512: my ($title,$url,$ext,$type)=split(/\:/,$res);
3513: my $idx=&LONCAPA::map::getresidx($url);
3514: $LONCAPA::map::resources[$idx]=$res;
3515: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3516: }
3517: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3518: $folder.'.'.$container,1);
3519: return $errtext if ($fatal);
3520: } else {
3521: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
3522:
3523: }
3524: }
3525: &log_differences($plain);
3526: }
3527: # ---------------------------------------------------------------- End commands
3528: # ---------------------------------------------------------------- Print screen
3529: my $idx=0;
3530: my $shown=0;
3531: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
3532: $r->print('<div class="LC_Box">'.
3533: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3534: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3535: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3536: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3537: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
3538: '</ol>');
3539: if ($randompick>=0) {
3540: $r->print('<p class="LC_warning">'
3541: .&mt('Caution: this folder is set to randomly pick a subset'
3542: .' of resources. Adding or removing resources from this'
3543: .' folder will change the set of resources that the'
3544: .' students see, resulting in spurious or missing credit'
3545: .' for completed problems, not limited to ones you'
3546: .' modify. Do not modify the contents of this folder if'
3547: .' it is in active student use.')
3548: .'</p>'
3549: );
3550: }
3551: if ($is_random_order) {
3552: $r->print('<p class="LC_warning">'
3553: .&mt('Caution: this folder is set to randomly order its'
3554: .' contents. Adding or removing resources from this folder'
3555: .' will change the order of resources shown.')
3556: .'</p>'
3557: );
3558: }
3559: $r->print('</div>');
3560: }
3561:
3562: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3563: %filters = (
3564: canremove => [],
3565: cancut => [],
3566: cancopy => [],
3567: hiddenresource => [],
3568: encrypturl => [],
3569: randomorder => [],
3570: randompick => [],
3571: );
3572: %curr_groups = &Apache::longroup::coursegroups();
3573: &Apache::loncommon::start_data_table_count(); #setup a row counter
3574: foreach my $res (@LONCAPA::map::order) {
3575: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3576: $name=&LONCAPA::map::qtescape($name);
3577: $url=&LONCAPA::map::qtescape($url);
3578: unless ($name) { $name=(split(/\//,$url))[-1]; }
3579: unless ($name) { $idx++; next; }
3580: push(@allidx,$res);
3581: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3582: push(@allmapidx,$res);
3583: }
3584:
3585: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
3586: next if ($supphidden{$suppmapid.':'.$res});
3587: }
3588: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
3589: $coursenum,$coursedom,$crstype,
3590: $pathitem,$supplementalflag,$container,
3591: \%filters,\%curr_groups,$ltitoolsref,$canedit,
3592: $isencrypted,$navmapref,$hostname,
3593: \%supphidden,\%suppids,$suppmapid);
3594: $idx++;
3595: $shown++;
3596: }
3597: &Apache::loncommon::end_data_table_count();
3598:
3599: my $need_save;
3600: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
3601: my $toolslink;
3602: if ($allowed || $canedit) {
3603: my $helpitem = 'Navigation_Screen';
3604: if (!$allowed) {
3605: $helpitem = 'Supplemental_Navigation';
3606: }
3607: $toolslink = '<table><tr><td>'
3608: .&Apache::loncommon::help_open_menu('Navigation Screen',
3609: $helpitem,undef,'RAT')
3610: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3611: .'<td align="left"><ul id="LC_toolbar">'
3612: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
3613: .'id="LC_content_toolbar_edittoplevel" '
3614: .'class="LC_toolbarItem" '
3615: .'title="'.&mt('Supplemental Content Editor').'">'
3616: .'</a></li></ul></td></tr></table><br />';
3617: }
3618: if ($shown) {
3619: if ($allowed) {
3620: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3621: .&Apache::loncommon::start_data_table(undef,'contentlist')
3622: .&Apache::loncommon::start_data_table_header_row()
3623: .'<th colspan="2">'.&mt('Move').'</th>'
3624: .'<th colspan="3">'.&mt('Actions').'</th>'
3625: .'<th>'.&mt('Document').'</th>'
3626: .'<th colspan="2">'.&mt('Settings').'</th>'
3627: .&Apache::loncommon::end_data_table_header_row();
3628: if ($folder !~ /^supplemental/) {
3629: $lists{'canhide'} = join(',',@allidx);
3630: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3631: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3632: 'randomorder','randompick');
3633: foreach my $item (@possfilters) {
3634: if (ref($filters{$item}) eq 'ARRAY') {
3635: if (@{$filters{$item}} > 0) {
3636: $lists{$item} = join(',',@{$filters{$item}});
3637: }
3638: }
3639: }
3640: if (@allidx > 0) {
3641: my $path;
3642: if ($env{'form.folderpath'}) {
3643: $path =
3644: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3645: }
3646: if (@allidx > 1) {
3647: $to_show .=
3648: &Apache::loncommon::continue_data_table_row().
3649: '<td colspan="2"> </td>'.
3650: '<td>'.
3651: &multiple_check_form('actions',\%lists,$canedit).
3652: '</td>'.
3653: '<td colspan="3"> </td>'.
3654: '<td colspan="2">'.
3655: &multiple_check_form('settings',\%lists,$canedit).
3656: '</td>'.
3657: &Apache::loncommon::end_data_table_row();
3658: $need_save = 1;
3659: }
3660: }
3661: }
3662: $to_show .= $output.' '
3663: .&Apache::loncommon::end_data_table()
3664: .'<br style="line-height:2px;" />'
3665: .&Apache::loncommon::end_scrollbox();
3666: } else {
3667: $to_show .= $toolslink
3668: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3669: .$output.' '
3670: .&Apache::loncommon::end_data_table();
3671: }
3672: } else {
3673: if (!$allowed) {
3674: $to_show .= $toolslink;
3675: }
3676: my $noresmsg;
3677: if ($allowed && $hiddentop && !$supplementalflag) {
3678: $noresmsg = &mt('Main Content Hidden');
3679: } else {
3680: $noresmsg = &mt('Currently empty');
3681: }
3682: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3683: .'<div class="LC_info" id="contentlist">'
3684: .$noresmsg
3685: .'</div>'
3686: .&Apache::loncommon::end_scrollbox();
3687: }
3688: } else {
3689: if ($shown) {
3690: $to_show = '<div>'
3691: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3692: .$output
3693: .&Apache::loncommon::end_data_table()
3694: .'</div>';
3695: } else {
3696: $to_show = '<div class="LC_info" id="contentlist">'
3697: .&mt('Currently empty')
3698: .'</div>'
3699: }
3700: }
3701: my $tid = 1;
3702: if ($supplementalflag) {
3703: $tid = 2;
3704: }
3705: if ($allowed) {
3706: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
3707: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
3708: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3709: if ($canedit) {
3710: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3711: }
3712: } else {
3713: $r->print($to_show);
3714: }
3715: return;
3716: }
3717:
3718: sub multiple_check_form {
3719: my ($caller,$listsref,$canedit) = @_;
3720: return unless (ref($listsref) eq 'HASH');
3721: my $disabled;
3722: unless ($canedit) {
3723: $disabled = 'disabled="disabled"';
3724: }
3725: my $output =
3726: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3727: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3728: '<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>'.
3729: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3730: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3731: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3732: if ($caller eq 'settings') {
3733: $output .=
3734: '<table><tr>'.
3735: '<td class="LC_docs_entry_parameter">'.
3736: '<span class="LC_nobreak"><label>'.
3737: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
3738: '</label></span></td>'.
3739: '<td class="LC_docs_entry_parameter">'.
3740: '<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'".');"'.$disabled.' />'.&mt('Randomly Pick').'</label><span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" />'.
3741: '</span></td>'.
3742: '</tr>'."\n".
3743: '<tr>'.
3744: '<td class="LC_docs_entry_parameter">'.
3745: '<span class="LC_nobreak"><label><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')"'.$disabled.' />'.&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'".')"'.$disabled.' />'.&mt('Random Order').
3746: '</label></span>'.
3747: '</td></tr></table>'."\n";
3748: } else {
3749: $output .=
3750: '<table><tr>'.
3751: '<td class="LC_docs_entry_parameter">'.
3752: '<span class="LC_nobreak LC_docs_remove">'.
3753: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
3754: '</label></span></td>'.
3755: '<td class="LC_docs_entry_parameter">'.
3756: '<span class="LC_nobreak LC_docs_cut">'.
3757: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
3758: '</label></span></td>'."\n".
3759: '<td class="LC_docs_entry_parameter">'.
3760: '<span class="LC_nobreak LC_docs_copy">'.
3761: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
3762: '</label></span></td>'.
3763: '</tr></table>'."\n";
3764: }
3765: $output .=
3766: '</fieldset>'.
3767: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3768: if ($caller eq 'settings') {
3769: $output .=
3770: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3771: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3772: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3773: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3774: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3775: } elsif ($caller eq 'actions') {
3776: $output .=
3777: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3778: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3779: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3780: }
3781: $output .=
3782: '</form>'.
3783: '</div>';
3784: return $output;
3785: }
3786:
3787: sub process_file_upload {
3788: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
3789: # upload a file, if present
3790: my $filesize = length($env{'form.uploaddoc'});
3791: if (!$filesize) {
3792: $$upload_output = '<div class="LC_error">'.
3793: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3794: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3795: $filesize).'<br />'.
3796: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3797: '</div>';
3798: return;
3799: }
3800: my $quotatype = 'unofficial';
3801: if ($crstype eq 'Community') {
3802: $quotatype = 'community';
3803: } elsif ($crstype eq 'Placement') {
3804: $quotatype = 'placement';
3805: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
3806: $quotatype = 'official';
3807: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3808: $quotatype = 'textbook';
3809: }
3810: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3811: $filesize = int($filesize/1000); #expressed in kb
3812: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
3813: $env{'form.uploaddoc.filename'},$filesize,
3814: 'upload',$quotatype);
3815: return if ($$upload_output);
3816: }
3817: my ($parseaction,$showupload,$nextphase,$mimetype);
3818: if ($env{'form.parserflag'}) {
3819: $parseaction = 'parse';
3820: }
3821: my $folder=$env{'form.folder'};
3822: if ($folder eq '') {
3823: $folder='default';
3824: }
3825: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3826: my $errtext='';
3827: my $fatal=0;
3828: my $container='sequence';
3829: if ($env{'form.folderpath'} =~ /:1$/) {
3830: $container='page';
3831: }
3832: ($errtext,$fatal)=
3833: &mapread($coursenum,$coursedom,$folder.'.'.$container);
3834: if ($#LONCAPA::map::order<1) {
3835: $LONCAPA::map::order[0]=1;
3836: $LONCAPA::map::resources[1]='';
3837: }
3838: my $destination = 'docs/';
3839: if ($folder =~ /^supplemental/) {
3840: $destination = 'supplemental/';
3841: }
3842: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3843: $destination .= 'default/';
3844: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3845: $destination .= $2.'/';
3846: }
3847: if ($fatal) {
3848: $$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>';
3849: return;
3850: }
3851: # this is for a course, not a user, so set context to coursedoc.
3852: my $newidx=&LONCAPA::map::getresidx();
3853: $destination .= $newidx;
3854: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
3855: $parseaction,$allfiles,
3856: $codebase,undef,undef,undef,undef,
3857: undef,undef,\$mimetype);
3858: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3859: my $stored = $1;
3860: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3861: $stored.'</span>').'</p>';
3862: } else {
3863: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3864:
3865: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
3866: return;
3867: }
3868: my $ext='false';
3869: if ($url=~m{^http://}) { $ext='true'; }
3870: $url = &LONCAPA::map::qtunescape($url);
3871: my $comment=$env{'form.comment'};
3872: $comment = &LONCAPA::map::qtunescape($comment);
3873: if ($folder=~/^supplemental/) {
3874: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3875: $env{'user.domain'}.'___&&&___'.$comment;
3876: }
3877:
3878: $LONCAPA::map::resources[$newidx]=
3879: $comment.':'.$url.':'.$ext.':normal:res';
3880: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3881: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3882: $folder.'.'.$container,1);
3883: if ($fatal) {
3884: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
3885: return;
3886: } else {
3887: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3888: $$upload_output = $showupload;
3889: my $total_embedded = scalar(keys(%{$allfiles}));
3890: if ($total_embedded > 0) {
3891: my $uploadphase = 'upload_embedded';
3892: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3893: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3894: my ($embedded,$num) =
3895: &Apache::loncommon::ask_for_embedded_content(
3896: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3897: if ($embedded) {
3898: if ($num) {
3899: $$upload_output .=
3900: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3901: $nextphase = $uploadphase;
3902: } else {
3903: $$upload_output .= $embedded;
3904: }
3905: } else {
3906: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3907: }
3908: } else {
3909: $$upload_output .= &mt('No embedded items identified').'<br />';
3910: }
3911: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
3912: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3913: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
3914: $nextphase = 'decompress_uploaded';
3915: my $position = scalar(@LONCAPA::map::order)-1;
3916: my $noextract = &return_to_editor();
3917: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3918: my %archiveitems = (
3919: folderpath => $env{'form.folderpath'},
3920: cmd => $nextphase,
3921: newidx => $newidx,
3922: position => $position,
3923: phase => $nextphase,
3924: comment => $comment,
3925: );
3926: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3927: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
3928: $$upload_output = $showupload.
3929: &Apache::loncommon::decompress_form($mimetype,
3930: $archiveurl,'/adm/coursedocs',$noextract,
3931: \%archiveitems,\@current);
3932: }
3933: }
3934: }
3935: return $nextphase;
3936: }
3937:
3938: sub get_dir_list {
3939: my ($url,$coursenum,$coursedom,$newidx) = @_;
3940: my ($destination,$dir_root) = &embedded_destination();
3941: my ($dirlistref,$listerror) =
3942: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3943: my @dir_lines;
3944: my $dirptr=16384;
3945: if (ref($dirlistref) eq 'ARRAY') {
3946: foreach my $dir_line (sort
3947: {
3948: my ($afile)=split('&',$a,2);
3949: my ($bfile)=split('&',$b,2);
3950: return (lc($afile) cmp lc($bfile));
3951: } (@{$dirlistref})) {
3952: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3953: $filename =~ s/\s+$//;
3954: next if ($filename =~ /^\.\.?$/);
3955: my $isdir = 0;
3956: if ($dirptr&$testdir) {
3957: $isdir = 1;
3958: }
3959: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3960: }
3961: }
3962: return @dir_lines;
3963: }
3964:
3965: sub is_supplemental_title {
3966: my ($title) = @_;
3967: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3968: }
3969:
3970: # --------------------------------------------------------------- An entry line
3971:
3972: sub entryline {
3973: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
3974: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
3975: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname,
3976: $supphidden,$suppids,$suppmapid)=@_;
3977: my ($foldertitle,$renametitle,$oldtitle);
3978: if (&is_supplemental_title($title)) {
3979: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
3980: } else {
3981: $title=&HTML::Entities::encode($title,'"<>&\'');
3982: $renametitle=$title;
3983: $foldertitle=$title;
3984: }
3985:
3986: my ($disabled,$readonly,$js_lt);
3987: unless ($canedit) {
3988: $disabled = 'disabled="disabled"';
3989: $readonly = 1;
3990: }
3991:
3992: my $orderidx=$LONCAPA::map::order[$index];
3993:
3994: $renametitle=~s/\\/\\\\/g;
3995: $renametitle=~s/\"\;/\\\"/g;
3996: $renametitle=~s/"/%22/g;
3997: $renametitle=~s/ /%20/g;
3998: $oldtitle = $renametitle;
3999: $renametitle=~s/\'/\\\'/g;
4000: my $line=&Apache::loncommon::start_data_table_row();
4001: my ($form_start,$form_end,$form_common,$form_param);
4002: # Edit commands
4003: my ($esc_path, $path, $symb, $shownsymb, $curralias);
4004: if ($env{'form.folderpath'}) {
4005: $esc_path=&escape($env{'form.folderpath'});
4006: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4007: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4008: }
4009: my $isexternal;
4010: if ($residx) {
4011: my $currurl = $url;
4012: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4013: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4014: $isexternal = 1;
4015: }
4016: if (!$supplementalflag) {
4017: my $path = 'uploaded/'.
4018: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4019: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4020: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4021: $residx,
4022: &Apache::lonnet::declutter($currurl));
4023: }
4024: }
4025: my ($renamelink,%lt,$ishash);
4026: if (ref($filtersref) eq 'HASH') {
4027: $ishash = 1;
4028: }
4029:
4030: if ($allowed) {
4031: $form_start = '
4032: <form action="/adm/coursedocs" method="post">
4033: ';
4034: $form_common=(<<END);
4035: <input type="hidden" name="folderpath" value="$path" />
4036: <input type="hidden" name="symb" value="$symb" />
4037: END
4038: $form_param=(<<END);
4039: <input type="hidden" name="setparms" value="$orderidx" />
4040: <input type="hidden" name="changeparms" value="0" />
4041: END
4042: $form_end = '</form>';
4043:
4044: my $incindex=$index+1;
4045: my $selectbox='';
4046: if (($#LONCAPA::map::order>0) &&
4047: ((split(/\:/,
4048: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4049: ne '') &&
4050: ((split(/\:/,
4051: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
4052: ne '')) {
4053: $selectbox=
4054: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
4055: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
4056: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4057: if ($i==$incindex) {
4058: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
4059: } else {
4060: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4061: }
4062: }
4063: $selectbox.='</select>';
4064: }
4065: %lt=&Apache::lonlocal::texthash(
4066: 'up' => 'Move Up',
4067: 'dw' => 'Move Down',
4068: 'rm' => 'Remove',
4069: 'ct' => 'Cut',
4070: 'rn' => 'Rename',
4071: 'cp' => 'Copy',
4072: 'da' => 'Unset alias',
4073: 'sa' => 'Set alias',
4074: 'ex' => 'External Resource',
4075: 'et' => 'External Tool',
4076: 'ed' => 'Edit',
4077: 'pr' => 'Preview',
4078: 'sv' => 'Save',
4079: 'ul' => 'URL',
4080: 'ti' => 'Title',
4081: 'er' => 'Editing rights unavailable for your current role.',
4082: );
4083: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4084: $env{'form.folderpath'},
4085: $currgroups);
4086: my ($copylink,$cutlink,$removelink);
4087: my $skip_confirm = 0;
4088: my $confirm_removal = 0;
4089: if ( $folder =~ /^supplemental/
4090: || ($url =~ m{( /smppg$
4091: |/syllabus$
4092: |/aboutme$
4093: |/navmaps$
4094: |/bulletinboard$
4095: |/ext\.tool$
4096: |\.html$)}x)
4097: || $isexternal) {
4098: $skip_confirm = 1;
4099: }
4100: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4101: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4102: $confirm_removal = 1;
4103: }
4104: if ($url =~ /$LONCAPA::assess_re/) {
4105: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4106: }
4107:
4108: if ($denied{'copy'}) {
4109: $copylink=(<<ENDCOPY)
4110: <span style="visibility: hidden;">$lt{'cp'}</span>
4111: ENDCOPY
4112: } else {
4113: my $formname = 'edit_copy_'.$orderidx;
4114: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
4115: $copylink=(<<ENDCOPY);
4116: <form name="$formname" method="post" action="/adm/coursedocs">
4117: $form_common
4118: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
4119: $form_end
4120: ENDCOPY
4121: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4122: push(@{$filtersref->{'cancopy'}},$orderidx);
4123: }
4124: }
4125: if ($denied{'cut'}) {
4126: $cutlink=(<<ENDCUT);
4127: <span style="visibility: hidden;">$lt{'ct'}</span>
4128: ENDCUT
4129: } else {
4130: my $formname = 'edit_cut_'.$orderidx;
4131: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
4132: $cutlink=(<<ENDCUT);
4133: <form name="$formname" method="post" action="/adm/coursedocs">
4134: $form_common
4135: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
4136: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
4137: $form_end
4138: ENDCUT
4139: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4140: push(@{$filtersref->{'cancut'}},$orderidx);
4141: }
4142: }
4143: if ($denied{'remove'}) {
4144: $removelink=(<<ENDREM);
4145: <span style="visibility: hidden;">$lt{'rm'}</a>
4146: ENDREM
4147: } else {
4148: my $formname = 'edit_remove_'.$orderidx;
4149: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
4150: $removelink=(<<ENDREM);
4151: <form name="$formname" method="post" action="/adm/coursedocs">
4152: $form_common
4153: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
4154: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
4155: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
4156: $form_end
4157: ENDREM
4158: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4159: push(@{$filtersref->{'canremove'}},$orderidx);
4160: }
4161: }
4162: $renamelink=(<<ENDREN);
4163: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
4164: ENDREN
4165: my ($uplink,$downlink);
4166: if ($canedit) {
4167: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4168: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4169: } else {
4170: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4171: $downlink = $uplink;
4172: }
4173: $line.=(<<END);
4174: <td>
4175: <div class="LC_docs_entry_move">
4176: <a href="$uplink">
4177: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
4178: </a>
4179: </div>
4180: <div class="LC_docs_entry_move">
4181: <a href="$downlink">
4182: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
4183: </a>
4184: </div>
4185: </td>
4186: <td>
4187: $form_start
4188: $form_param
4189: $form_common
4190: $selectbox
4191: $form_end
4192: </td>
4193: <td class="LC_docs_entry_commands LC_nobreak">
4194: $removelink
4195: $cutlink
4196: $copylink
4197: </td>
4198: END
4199: }
4200: # Figure out what kind of a resource this is
4201: my ($extension)=($url=~/\.(\w+)$/);
4202: my $uploaded=($url=~/^\/*uploaded\//);
4203: my $icon=&Apache::loncommon::icon($url);
4204: my $isfolder;
4205: my $ispage;
4206: my $containerarg;
4207: my $folderurl;
4208: if ($uploaded) {
4209: if (($extension eq 'sequence') || ($extension eq 'page')) {
4210: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
4211: $containerarg = $1;
4212: if ($extension eq 'sequence') {
4213: $icon=$iconpath.'navmap.folder.closed.gif';
4214: $isfolder=1;
4215: } else {
4216: $icon=$iconpath.'page.gif';
4217: $ispage=1;
4218: }
4219: $folderurl = &Apache::lonnet::declutter($url);
4220: if ($allowed) {
4221: $url='/adm/coursedocs?';
4222: } else {
4223: $url='/adm/supplemental?';
4224: }
4225: } else {
4226: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4227: }
4228: }
4229:
4230: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
4231: my $orig_url = $url;
4232: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
4233: if ($container eq 'page') {
4234: $url=~s{^http(|s)(:|:)//}{/ext/};
4235: } else {
4236: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4237: }
4238: if (!$supplementalflag && $residx && $symb) {
4239: if ((!$isfolder) && (!$ispage)) {
4240: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
4241: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4242: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4243: } else {
4244: $url=&Apache::lonnet::clutter($url);
4245: }
4246: if ($url=~/^\/*uploaded\//) {
4247: $url=~/\.(\w+)$/;
4248: my $embstyle=&Apache::loncommon::fileembstyle($1);
4249: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4250: $url='/adm/wrapper'.$url;
4251: } elsif ($embstyle eq 'ssi') {
4252: #do nothing with these
4253: } elsif ($url!~/\.(sequence|page)$/) {
4254: $url='/adm/coursedocs/showdoc'.$url;
4255: }
4256: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4257: my $wrapped = $1;
4258: my $exturl = $2;
4259: if (($wrapped eq '') && ($container ne 'page')) {
4260: $url='/adm/wrapper'.$url;
4261: }
4262: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4263: $nomodal = 1;
4264: }
4265: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4266: $url='/adm/wrapper'.$url;
4267: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4268: if (($ENV{'SERVER_PORT'} == 443) &&
4269: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4270: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
4271: $url .= '?usehttp=1';
4272: }
4273: $nomodal = 1;
4274: }
4275: }
4276: my ($checkencrypt,$shownurl);
4277: if (!$env{'request.role.adv'}) {
4278: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4279: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4280: $checkencrypt = 1;
4281: } elsif (ref($navmapref)) {
4282: unless (ref($$navmapref)) {
4283: $$navmapref = Apache::lonnavmaps::navmap->new();
4284: }
4285: if (ref($$navmapref)) {
4286: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4287: $checkencrypt = 1;
4288: }
4289: }
4290: }
4291: }
4292: if ($checkencrypt) {
4293: my $currenc = $env{'request.enc'};
4294: $env{'request.enc'} = 1;
4295: $shownsymb = &Apache::lonenc::encrypted($symb);
4296: $shownurl = &Apache::lonenc::encrypted($url);
4297: if (&Apache::lonnet::symbverify($symb,$url)) {
4298: $url = $shownurl;
4299: } else {
4300: $url = '';
4301: }
4302: $env{'request.enc'} = $currenc;
4303: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4304: $shownsymb = $symb;
4305: if ($isexternal) {
4306: $url =~ s/\#[^#]+$//;
4307: if ($container eq 'page') {
4308: $url = &Apache::lonnet::clutter($url);
4309: }
4310: }
4311: $shownurl = $url;
4312: }
4313: unless ($env{'request.role.adv'}) {
4314: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4315: $url = '';
4316: }
4317: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4318: $url = '';
4319: $hiddenres = 1;
4320: }
4321: }
4322: if ($url ne '') {
4323: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
4324: }
4325: }
4326: } elsif ($supplementalflag) {
4327: if ($isexternal) {
4328: if ($url =~ /^([^#]+)#([^#]+)$/) {
4329: $url = $1;
4330: $anchor = $2;
4331: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4332: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
4333: if ($hostname ne '') {
4334: $url = 'http://'.$hostname.$url;
4335: }
4336: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4337: }
4338: $nomodal = 1;
4339: }
4340: }
4341: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4342: if (($ENV{'SERVER_PORT'} == 443) &&
4343: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4344: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
4345: if ($hostname ne '') {
4346: $url = 'http://'.$hostname.$url;
4347: }
4348: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4349: }
4350: $nomodal = 1;
4351: }
4352: }
4353: }
4354: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4355: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
4356: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
4357: my $foldername=&escape($foldertitle);
4358: my $folderpath=$env{'form.folderpath'};
4359: if ($folderpath) { $folderpath.='&' };
4360: if (!$allowed && $supplementalflag) {
4361: $folderpath.=$containerarg.'&'.$foldername;
4362: $url.='folderpath='.&escape($folderpath);
4363: if (ref($supphidden) eq 'HASH') {
4364: if ($supphidden->{$suppmapid.':'.$residx}) {
4365: $hiddenfolder = 1;
4366: }
4367: }
4368: } else {
4369: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4370: 'parameter_randompick'))[0];
4371: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4372: 'parameter_randomorder'))[0]=~/^yes$/i);
4373: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4374: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4375: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4376: 'parameter_encrypturl'))[0]=~/^yes$/i);
4377: unless ($hiddenmap) {
4378: if (ref($navmapref)) {
4379: unless (ref($$navmapref)) {
4380: $$navmapref = Apache::lonnavmaps::navmap->new();
4381: }
4382: if (ref($$navmapref)) {
4383: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4384: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4385: unless (@resources) {
4386: $hiddenmap = 1;
4387: unless ($env{'request.role.adv'}) {
4388: $url = '';
4389: $hiddenfolder = 1;
4390: }
4391: }
4392: }
4393: }
4394: }
4395: }
4396: unless ($encryptmap) {
4397: if ((ref($navmapref)) && (ref($$navmapref))) {
4398: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4399: $encryptmap = 1;
4400: }
4401: }
4402: }
4403:
4404: # Append randompick number, hidden, and encrypted with ":" to foldername,
4405: # so it gets transferred between levels
4406: $folderpath.=$containerarg.'&'.$foldername.
4407: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4408: unless ($url eq '') {
4409: $url.='folderpath='.&escape($folderpath);
4410: }
4411: my $rpckchk;
4412: if ($rpicknum) {
4413: $rpckchk = ' checked="checked"';
4414: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4415: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4416: }
4417: }
4418: my $formname = 'edit_randompick_'.$orderidx;
4419: $rand_pick_text =
4420: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4421: $form_param."\n".
4422: $form_common."\n".
4423: '<span class="LC_nobreak"><label><input type="checkbox" name="randompick_'.$orderidx.'" id="randompick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.$disabled.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="rpicknum_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" /><span id="randompicknum_'.$orderidx.'">';
4424: if ($rpicknum ne '') {
4425: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4426: }
4427: $rand_pick_text .= '</span></span>'.
4428: $form_end;
4429: my $ro_set;
4430: if ($randorder) {
4431: $ro_set = 'checked="checked"';
4432: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4433: push(@{$filtersref->{'randomorder'}},$orderidx);
4434: }
4435: }
4436: $formname = 'edit_rorder_'.$orderidx;
4437: $rand_order_text =
4438: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4439: $form_param."\n".
4440: $form_common."\n".
4441: '<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder','settings'".');" '.$ro_set.$disabled.' /> '.&mt('Random Order').' </label></span>'.
4442: $form_end;
4443: }
4444: } elsif ($supplementalflag && !$allowed) {
4445: my $isexttool;
4446: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4447: $url='/adm/wrapper'.$url;
4448: $isexttool = 1;
4449: }
4450: $url .= ($url =~ /\?/) ? '&':'?';
4451: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
4452: if ($title) {
4453: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4454: }
4455: if ((($isexternal) || ($isexttool)) && $orderidx) {
4456: $url .= '&idx='.$orderidx;
4457: }
4458: if ($anchor ne '') {
4459: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4460: }
4461: if (ref($supphidden) eq 'HASH') {
4462: if ($supphidden->{$suppmapid.':'.$residx}) {
4463: $hiddenres = 1;
4464: }
4465: }
4466: }
4467: my ($tdalign,$tdwidth);
4468: if ($allowed) {
4469: my $fileloc =
4470: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
4471: if ($isexternal) {
4472: ($editlink,$extresform) =
4473: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4474: undef,undef,undef,undef,undef,undef,
4475: undef,$disabled);
4476: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4477: ($editlink,$extresform) =
4478: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4479: undef,undef,undef,'tool',$coursedom,
4480: $coursenum,$ltitoolsref,$disabled);
4481: } elsif (!$isfolder && !$ispage) {
4482: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4483: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
4484: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
4485: my $suppanchor;
4486: if ($supplementalflag) {
4487: $suppanchor = $anchor;
4488: }
4489: my $jscall =
4490: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4491: $switchserver,
4492: $forceedit,
4493: undef,$symb,$shownsymb,
4494: &escape($env{'form.folderpath'}),
4495: $renametitle,$hostname,
4496: '','',1,$suppanchor);
4497: if ($jscall) {
4498: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4499: $jscall.'" >'.&mt('Edit').'</a> '."\n";
4500: }
4501: }
4502: }
4503: $tdalign = ' align="right" valign="top"';
4504: $tdwidth = ' width="80%"';
4505: }
4506: my $reinit;
4507: if ($crstype eq 'Community') {
4508: $reinit = &mt('(re-initialize community to access)');
4509: } else {
4510: $reinit = &mt('(re-initialize course to access)');
4511: }
4512: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
4513: if ($orig_url =~ /$LONCAPA::assess_re/) {
4514: $line.= '<br />';
4515: if ($curralias ne '') {
4516: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4517: $lt{'da'}.'</a></span>';
4518: } else {
4519: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4520: $lt{'sa'}.'</a></span>';
4521: }
4522: }
4523: $line.='</td><td>';
4524: my $link;
4525: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4526: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4527: } elsif ($url) {
4528: if ($anchor ne '') {
4529: if ($supplementalflag) {
4530: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4531: } else {
4532: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4533: }
4534: }
4535: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4536: $link = 'http://'.$hostname.$url;
4537: } else {
4538: $link = $url;
4539: }
4540: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
4541: if ($nomodal) {
4542: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4543: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4544: } else {
4545: $line.=&Apache::loncommon::modal_link($link,
4546: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4547: }
4548: } else {
4549: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4550: }
4551: $line.='</span></td><td'.$tdwidth.'>';
4552: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4553: $line.='<a href="'.$url.'">'.$title.'</a>';
4554: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4555: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4556: my $editurl = $url;
4557: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4558: $line .= ' '.'<a href="'.$editurl.'">'.
4559: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4560: '</a>';
4561: }
4562: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4563: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4564: }
4565: } elsif ($url) {
4566: if ($nomodal) {
4567: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4568: $title.'</a>';
4569: } else {
4570: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4571: }
4572: } elsif (($hiddenfolder) || ($hiddenres)) {
4573: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
4574: } else {
4575: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4576: }
4577: if (($allowed) && ($curralias ne '')) {
4578: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4579: } else {
4580: $line .= $extresform;
4581: }
4582: $line .= '</td>';
4583: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4584: $rand_order_text = ' ' if ($rand_order_text eq '');
4585: if ($allowed) {
4586: my %lt=&Apache::lonlocal::texthash(
4587: 'hd' => 'Hidden',
4588: 'ec' => 'URL hidden');
4589: my ($enctext,$hidtext,$formhidden,$formurlhidden);
4590: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4591: $hidtext = ' checked="checked"';
4592: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4593: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4594: }
4595: }
4596: $formhidden = 'edit_hiddenresource_'.$orderidx;
4597: $line.=(<<ENDPARMS);
4598: <td class="LC_docs_entry_parameter">
4599: <form action="/adm/coursedocs" method="post" name="$formhidden">
4600: $form_param
4601: $form_common
4602: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
4603: $form_end
4604: ENDPARMS
4605: if ($folder =~/^supplemental/) {
4606: $line.= "\n <td>";
4607: } else {
4608: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4609: $enctext = ' checked="checked"';
4610: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4611: push(@{$filtersref->{'encrypturl'}},$orderidx);
4612: }
4613: }
4614: $formurlhidden = 'edit_encrypturl_'.$orderidx;
4615: $line.=(<<ENDPARMS);
4616: <br />
4617: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
4618: $form_param
4619: $form_common
4620: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
4621: $form_end
4622: </td>
4623: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4624: $rand_order_text</td>
4625: ENDPARMS
4626: }
4627: }
4628: $line.=&Apache::loncommon::end_data_table_row();
4629: return $line;
4630: }
4631:
4632: sub action_restrictions {
4633: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4634: my %denied = (
4635: cut => 0,
4636: copy => 0,
4637: remove => 0,
4638: );
4639: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4640: # no copy for published maps
4641: $denied{'copy'} = 1;
4642: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4643: unless ($1 eq 'simpleproblem') {
4644: $denied{'copy'} = 1;
4645: }
4646: $denied{'cut'} = 1;
4647: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4648: if ($folderpath =~ /^default&[^\&]+$/) {
4649: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4650: $denied{'remove'} = 1;
4651: }
4652: $denied{'cut'} = 1;
4653: $denied{'copy'} = 1;
4654: }
4655: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4656: my $group = $1;
4657: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4658: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4659: $denied{'remove'} = 1;
4660: }
4661: }
4662: $denied{'cut'} = 1;
4663: $denied{'copy'} = 1;
4664: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4665: my $group = $1;
4666: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4667: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4668: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4669: if (keys(%groupsettings) > 0) {
4670: $denied{'remove'} = 1;
4671: }
4672: $denied{'cut'} = 1;
4673: $denied{'copy'} = 1;
4674: }
4675: }
4676: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4677: my $group = $1;
4678: if ($url =~ /group_boards_\Q$group\E/) {
4679: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4680: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4681: if (keys(%groupsettings) > 0) {
4682: if (ref($groupsettings{'functions'}) eq 'HASH') {
4683: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4684: $denied{'remove'} = 1;
4685: }
4686: }
4687: }
4688: $denied{'cut'} = 1;
4689: $denied{'copy'} = 1;
4690: }
4691: }
4692: }
4693: return %denied;
4694: }
4695:
4696: sub new_timebased_suffix {
4697: my ($dom,$num,$type,$area,$container) = @_;
4698: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
4699: if ($type eq 'paste') {
4700: $prefix = $type;
4701: $namespace = 'courseeditor';
4702: $idtype = 'addcode';
4703: } elsif ($type eq 'map') {
4704: $prefix = 'docs';
4705: if ($area eq 'supplemental') {
4706: $prefix = 'supp';
4707: }
4708: $prefix .= $container;
4709: $namespace = 'uploadedmaps';
4710: } else {
4711: $prefix = $type;
4712: $namespace = 'templated';
4713: }
4714: my ($suffix,$freedlock,$error) =
4715: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
4716: if (!$suffix) {
4717: if ($type eq 'paste') {
4718: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4719: } elsif ($type eq 'map') {
4720: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4721: } elsif ($type eq 'smppg') {
4722: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4723: } elsif ($type eq 'exttool') {
4724: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
4725: } else {
4726: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
4727: }
4728: if ($error) {
4729: $errtext .= '<br />'.$error;
4730: }
4731: }
4732: if ($freedlock ne 'ok') {
4733: $locknotfreed =
4734: '<div class="LC_error">'.
4735: &mt('There was a problem removing a lockfile.').' ';
4736: if ($type eq 'paste') {
4737: if ($freedlock eq 'nolock') {
4738: $locknotfreed =
4739: '<div class="LC_error">'.
4740: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4741:
4742: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
4743: } else {
4744: $locknotfreed .=
4745: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4746: }
4747: } elsif ($type eq 'map') {
4748: $locknotfreed .=
4749: &mt('This will prevent creation of additional folders or composite pages in this course.');
4750: } elsif ($type eq 'smppg') {
4751: $locknotfreed .=
4752: &mt('This will prevent creation of additional simple pages in this course.');
4753: } elsif ($type eq 'exttool') {
4754: $locknotfreed .=
4755: &mt('This will prevent creation of additional external tools in this course.');
4756: } else {
4757: $locknotfreed .=
4758: &mt('This will prevent creation of additional discussion boards in this course.');
4759: }
4760: unless ($type eq 'paste') {
4761: $locknotfreed .=
4762: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4763: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
4764: }
4765: $locknotfreed .= '</div>';
4766: }
4767: return ($suffix,$errtext,$locknotfreed);
4768: }
4769:
4770: =pod
4771:
4772: =item tiehash()
4773:
4774: tie the hash
4775:
4776: =cut
4777:
4778: sub tiehash {
4779: my ($mode)=@_;
4780: $hashtied=0;
4781: if ($env{'request.course.fn'}) {
4782: if ($mode eq 'write') {
4783: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4784: &GDBM_WRCREAT(),0640)) {
4785: $hashtied=2;
4786: }
4787: } else {
4788: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4789: &GDBM_READER(),0640)) {
4790: $hashtied=1;
4791: }
4792: }
4793: }
4794: }
4795:
4796: sub untiehash {
4797: if ($hashtied) { untie %hash; }
4798: $hashtied=0;
4799: return OK;
4800: }
4801:
4802:
4803:
4804:
4805: sub checkonthis {
4806: my ($r,$url,$level,$title,$checkstale)=@_;
4807: $url=&unescape($url);
4808: $alreadyseen{$url}=1;
4809: $r->rflush();
4810: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4811: $r->print("\n<br />");
4812: if ($level==0) {
4813: $r->print("<br />");
4814: }
4815: for (my $i=0;$i<=$level*5;$i++) {
4816: $r->print(' ');
4817: }
4818: $r->print('<a href="'.$url.'" target="cat">'.
4819: ($title?$title:$url).'</a> ');
4820: if ($url=~/^\/res\//) {
4821: my $updated;
4822: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4823: ($url !~ /\.\d+\.\w+$/)) {
4824: $updated = &Apache::lonnet::remove_stale_resfile($url);
4825: }
4826: my $result=&Apache::lonnet::repcopy(
4827: &Apache::lonnet::filelocation('',$url));
4828: if ($result eq 'ok') {
4829: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4830: if ($updated) {
4831: $r->print('<br />');
4832: for (my $i=0;$i<=$level*5;$i++) {
4833: $r->print(' ');
4834: }
4835: $r->print('- '.&mt('Outdated copy removed'));
4836: }
4837: $r->rflush();
4838: &Apache::lonnet::countacc($url);
4839: $url=~/\.(\w+)$/;
4840: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4841: $r->print('<br />');
4842: $r->rflush();
4843: for (my $i=0;$i<=$level*5;$i++) {
4844: $r->print(' ');
4845: }
4846: $r->print('- '.&mt('Rendering:').' ');
4847: my ($errorcount,$warningcount)=split(/:/,
4848: &Apache::lonnet::ssi_body($url,
4849: ('grade_target'=>'web',
4850: 'return_only_error_and_warning_counts' => 1)));
4851: if (($errorcount) ||
4852: ($warningcount)) {
4853: if ($errorcount) {
4854: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
4855: &mt('[quant,_1,error]',$errorcount).'</span>');
4856: }
4857: if ($warningcount) {
4858: $r->print('<span class="LC_warning">'.
4859: &mt('[quant,_1,warning]',$warningcount).'</span>');
4860: }
4861: } else {
4862: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4863: }
4864: $r->rflush();
4865: }
4866: my $dependencies=
4867: &Apache::lonnet::metadata($url,'dependencies');
4868: foreach my $dep (split(/\,/,$dependencies)) {
4869: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4870: &checkonthis($r,$dep,$level+1,'',$checkstale);
4871: }
4872: }
4873: } elsif ($result eq 'unavailable') {
4874: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4875: } elsif ($result eq 'not_found') {
4876: unless ($url=~/\$/) {
4877: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
4878: } else {
4879: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
4880: }
4881: } else {
4882: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4883: }
4884: if (($updated) && ($result ne 'ok')) {
4885: $r->print('<br />'.&mt('Outdated copy removed'));
4886: }
4887: }
4888: }
4889: }
4890:
4891:
4892:
4893: =pod
4894:
4895: =item list_symbs()
4896:
4897: List Content Identifiers
4898:
4899: =cut
4900:
4901: sub list_symbs {
4902: my ($r) = @_;
4903:
4904: my $crstype = &Apache::loncommon::course_type();
4905: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4906: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4907: $r->print(&startContentScreen('tools'));
4908: my $navmap = Apache::lonnavmaps::navmap->new();
4909: if (!defined($navmap)) {
4910: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4911: '<div class="LC_error">'.
4912: &mt('Unable to retrieve information about course contents').
4913: '</div>');
4914: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
4915: } else {
4916: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4917: &Apache::loncommon::start_data_table().
4918: &Apache::loncommon::start_data_table_header_row().
4919: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4920: &Apache::loncommon::end_data_table_header_row()."\n");
4921: my $count;
4922: foreach my $res ($navmap->retrieveResources()) {
4923: $r->print(&Apache::loncommon::start_data_table_row().
4924: '<td>'.$res->compTitle().'</td>'.
4925: '<td>'.$res->symb().'</td>'.
4926: &Apache::loncommon::end_data_table_row());
4927: $count ++;
4928: }
4929: if (!$count) {
4930: $r->print(&Apache::loncommon::start_data_table_row().
4931: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4932: &Apache::loncommon::end_data_table_row());
4933: }
4934: $r->print(&Apache::loncommon::end_data_table());
4935: }
4936: $r->print(&endContentScreen());
4937: }
4938:
4939: sub short_urls {
4940: my ($r,$canedit) = @_;
4941: my $crstype = &Apache::loncommon::course_type();
4942: my $formname = 'shortenurl';
4943: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4944: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4945: $r->print(&startContentScreen('tools'));
4946: my ($navmap,$errormsg) =
4947: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4948: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4949: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4950: my (%maps,%resources,%titles);
4951: if (!ref($navmap)) {
4952: $r->print($errormsg.
4953: &endContentScreen());
4954: return '';
4955: } else {
4956: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
4957: $r->rflush();
4958: my $readonly;
4959: if ($canedit) {
4960: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
4961: if ($numnew) {
4962: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4963: }
4964: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4965: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4966: foreach my $error (@{$errors}) {
4967: $r->print('<li>'.$error.'</li>');
4968: }
4969: $r->print('</ul><br />');
4970: }
4971: } else {
4972: $readonly = 1;
4973: }
4974: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4975: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4976: undef,undef,undef,undef,undef,\%currtiny,$readonly));
4977: }
4978: $r->print(&endContentScreen());
4979: }
4980:
4981: sub contentverifyform {
4982: my ($r) = @_;
4983: my $crstype = &Apache::loncommon::course_type();
4984: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4985: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4986: $r->print(&startContentScreen('tools'));
4987: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4988: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4989: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4990: ' <span class="LC_nobreak">'.
4991: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4992: &mt('No').'</label>'.(' 'x2).
4993: '<label><input type="radio" name="checkstale" value="1" />'.
4994: &mt('Yes').'</label></span></p><p>'.
4995: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
4996: '<input type="hidden" value="1" name="tools" />'.
4997: '<input type="hidden" value="1" name="verify" /></p></form>');
4998: $r->print(&endContentScreen());
4999: return;
5000: }
5001:
5002: sub verifycontent {
5003: my ($r,$checkstale) = @_;
5004: my $crstype = &Apache::loncommon::course_type();
5005: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5006: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5007: $r->print(&startContentScreen('tools'));
5008: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5009: $hashtied=0;
5010: undef %alreadyseen;
5011: %alreadyseen=();
5012: &tiehash();
5013:
5014: foreach my $key (keys(%hash)) {
5015: if ($hash{$key}=~/\.(page|sequence)$/) {
5016: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5017: $r->print('<hr /><span class="LC_error">'.
5018: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
5019: &unescape($hash{$key}).'</span><br />'.
5020: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
5021: }
5022: }
5023: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
5024: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
5025: }
5026: }
5027: &untiehash();
5028: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
5029: $r->print(&endContentScreen());
5030: }
5031:
5032: sub devalidateversioncache {
5033: my $src=shift;
5034: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5035: &Apache::lonnet::clutter($src));
5036: }
5037:
5038: sub checkversions {
5039: my ($r,$canedit) = @_;
5040: my $crstype = &Apache::loncommon::course_type();
5041: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5042: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
5043: $r->print(&startContentScreen('tools'));
5044:
5045: my $header='';
5046: my $startsel='';
5047: my $monthsel='';
5048: my $weeksel='';
5049: my $daysel='';
5050: my $allsel='';
5051: my %changes=();
5052: my $starttime=0;
5053: my $haschanged=0;
5054: my %setversions=&Apache::lonnet::dump('resourceversions',
5055: $env{'course.'.$env{'request.course.id'}.'.domain'},
5056: $env{'course.'.$env{'request.course.id'}.'.num'});
5057:
5058: $hashtied=0;
5059: &tiehash();
5060: if ($canedit) {
5061: my %newsetversions=();
5062: if ($env{'form.setmostrecent'}) {
5063: $haschanged=1;
5064: foreach my $key (keys(%hash)) {
5065: if ($key=~/^ids\_(\/res\/.+)$/) {
5066: $newsetversions{$1}='mostrecent';
5067: &devalidateversioncache($1);
5068: }
5069: }
5070: } elsif ($env{'form.setcurrent'}) {
5071: $haschanged=1;
5072: foreach my $key (keys(%hash)) {
5073: if ($key=~/^ids\_(\/res\/.+)$/) {
5074: my $getvers=&Apache::lonnet::getversion($1);
5075: if ($getvers>0) {
5076: $newsetversions{$1}=$getvers;
5077: &devalidateversioncache($1);
5078: }
5079: }
5080: }
5081: } elsif ($env{'form.setversions'}) {
5082: $haschanged=1;
5083: foreach my $key (keys(%env)) {
5084: if ($key=~/^form\.set_version_(.+)$/) {
5085: my $src=$1;
5086: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5087: $newsetversions{$src}=$env{$key};
5088: &devalidateversioncache($src);
5089: }
5090: }
5091: }
5092: }
5093: if ($haschanged) {
5094: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5095: $env{'course.'.$env{'request.course.id'}.'.domain'},
5096: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5097: $r->print(&Apache::loncommon::confirmwrapper(
5098: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5099: } else {
5100: $r->print(&Apache::loncommon::confirmwrapper(
5101: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
5102: }
5103: &mark_hash_old();
5104: }
5105: &changewarning($r,'');
5106: }
5107: if ($env{'form.timerange'} eq 'all') {
5108: # show all documents
5109: $header=&mt('All content in '.$crstype);
5110: $allsel=' selected="selected"';
5111: foreach my $key (keys(%hash)) {
5112: if ($key=~/^ids\_(\/res\/.+)$/) {
5113: my $src=$1;
5114: $changes{$src}=1;
5115: }
5116: }
5117: } else {
5118: # show documents which changed
5119: %changes=&Apache::lonnet::dump
5120: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5121: $env{'course.'.$env{'request.course.id'}.'.num'});
5122: my $firstkey=(keys(%changes))[0];
5123: unless ($firstkey=~/^error\:/) {
5124: unless ($env{'form.timerange'}) {
5125: $env{'form.timerange'}=604800;
5126: }
5127: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5128: .&mt('seconds');
5129: if ($env{'form.timerange'}==-1) {
5130: $seltext='since start of course';
5131: $startsel=' selected="selected"';
5132: $env{'form.timerange'}=time;
5133: }
5134: $starttime=time-$env{'form.timerange'};
5135: if ($env{'form.timerange'}==2592000) {
5136: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5137: $monthsel=' selected="selected"';
5138: } elsif ($env{'form.timerange'}==604800) {
5139: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5140: $weeksel=' selected="selected"';
5141: } elsif ($env{'form.timerange'}==86400) {
5142: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5143: $daysel=' selected="selected"';
5144: }
5145: $header=&mt('Content changed').' '.$seltext;
5146: } else {
5147: $header=&mt('No content modifications yet.');
5148: }
5149: }
5150: %setversions=&Apache::lonnet::dump('resourceversions',
5151: $env{'course.'.$env{'request.course.id'}.'.domain'},
5152: $env{'course.'.$env{'request.course.id'}.'.num'});
5153: my %lt=&Apache::lonlocal::texthash
5154: ('st' => 'Version changes since start of '.$crstype,
5155: 'lm' => 'Version changes since last Month',
5156: 'lw' => 'Version changes since last Week',
5157: 'sy' => 'Version changes since Yesterday',
5158: 'al' => 'All Resources (possibly large output)',
5159: 'cd' => 'Change display',
5160: 'sd' => 'Display',
5161: 'fi' => 'File',
5162: 'md' => 'Modification Date',
5163: 'mr' => 'Most recently published Version',
5164: 've' => 'Version used in '.$crstype,
5165: 'vu' => 'Set Version to be used in '.$crstype,
5166: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
5167: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5168: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
5169: 'di' => 'Differences',
5170: 'save' => 'Save changes',
5171: 'vers' => 'Version choice(s) for specific resources',
5172: 'act' => 'Actions');
5173: my ($disabled,$readonly);
5174: unless ($canedit) {
5175: $disabled = 'disabled="disabled"';
5176: $readonly = 1;
5177: }
5178: $r->print(<<ENDHEADERS);
5179: <h4 class="LC_info">$header</h4>
5180: <form action="/adm/coursedocs" method="post">
5181: <input type="hidden" name="versions" value="1" />
5182: <div class="LC_left_float">
5183: <fieldset>
5184: <legend>$lt{'cd'}</legend>
5185: <select name="timerange">
5186: <option value='all'$allsel>$lt{'al'}</option>
5187: <option value="-1"$startsel>$lt{'st'}</option>
5188: <option value="2592000"$monthsel>$lt{'lm'}</option>
5189: <option value="604800"$weeksel>$lt{'lw'}</option>
5190: <option value="86400"$daysel>$lt{'sy'}</option>
5191: </select>
5192: <input type="submit" name="display" value="$lt{'sd'}" />
5193: </fieldset>
5194: </div>
5195: <div class="LC_left_float">
5196: <fieldset>
5197: <legend>$lt{'act'}</legend>
5198: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5199: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
5200: </fieldset>
5201: </div>
5202: <br clear="all" />
5203: <hr />
5204: <h4>$lt{'vers'}</h4>
5205: ENDHEADERS
5206: #number of columns for version history
5207: my %changedbytime;
5208: foreach my $key (keys(%changes)) {
5209: #excludes not versionable problems from resource version history:
5210: next if ($key =~ /^\/res\/lib\/templates/);
5211: my $chg;
5212: if ($env{'form.timerange'} eq 'all') {
5213: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5214: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5215: } else {
5216: $chg = $changes{$key};
5217: next if ($chg < $starttime);
5218: }
5219: push(@{$changedbytime{$chg}},$key);
5220: }
5221: if (keys(%changedbytime) == 0) {
5222: &untiehash();
5223: $r->print(&mt('No content changes in imported content in specified time frame').
5224: &endContentScreen());
5225: return;
5226: }
5227: $r->print(
5228: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
5229: &Apache::loncommon::start_data_table().
5230: &Apache::loncommon::start_data_table_header_row().
5231: '<th>'.&mt('Resources').'</th>'.
5232: "<th>$lt{'mr'}</th>".
5233: "<th>$lt{'ve'}</th>".
5234: "<th>$lt{'vu'}</th>".
5235: '<th>'.&mt('History').'</th>'.
5236: &Apache::loncommon::end_data_table_header_row()
5237: );
5238: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5239: foreach my $key (sort(@{$changedbytime{$chg}})) {
5240: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5241: my $currentversion=&Apache::lonnet::getversion($key);
5242: if ($currentversion<0) {
5243: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5244: }
5245: my $linkurl=&Apache::lonnet::clutter($key);
5246: $r->print(
5247: &Apache::loncommon::start_data_table_row().
5248: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5249: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5250: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5251: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5252: '<td align="right">'
5253: );
5254: # Used in course
5255: my $usedversion=$hash{'version_'.$linkurl};
5256: if (($usedversion) && ($usedversion ne 'mostrecent')) {
5257: if ($usedversion != $currentversion) {
5258: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
5259: } else {
5260: $r->print($usedversion);
5261: }
5262: } else {
5263: $r->print($currentversion);
5264: }
5265: $r->print('</td><td title="'.$lt{'vu'}.'">');
5266: # Set version
5267: $r->print(&Apache::loncommon::select_form(
5268: $setversions{$linkurl},
5269: 'set_version_'.$linkurl,
5270: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5271: '' => '',
5272: 'mostrecent' => &mt('most recent'),
5273: map {$_,$_} (1..$currentversion)},'',$readonly));
5274: my $lastold=1;
5275: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5276: my $url=$root.'.'.$prevvers.'.'.$extension;
5277: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5278: $lastold=$prevvers;
5279: }
5280: }
5281: $r->print('</td>');
5282: # List all available versions
5283: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5284: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5285: my $url=$root.'.'.$prevvers.'.'.$extension;
5286: $r->print(
5287: '<span class="LC_nobreak">'
5288: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5289: .&mt('Version [_1]',$prevvers).'</a>'
5290: .' ('.&Apache::lonlocal::locallocaltime(
5291: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5292: .')');
5293: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5294: $r->print(
5295: ' <a href="/adm/diff?filename='.
5296: &Apache::lonnet::clutter($root.'.'.$extension).
5297: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5298: '" target="diffs">'.&mt('Diffs').'</a>');
5299: }
5300: $r->print('</span><br />');
5301: }
5302: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
5303: }
5304: }
5305: $r->print(
5306: &Apache::loncommon::end_data_table().
5307: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
5308: '</form>'
5309: );
5310:
5311: &untiehash();
5312: $r->print(&endContentScreen());
5313: return;
5314: }
5315:
5316: sub mark_hash_old {
5317: my $retie_hash=0;
5318: if ($hashtied) {
5319: $retie_hash=1;
5320: &untiehash();
5321: }
5322: &tiehash('write');
5323: $hash{'old'}=1;
5324: &untiehash();
5325: if ($retie_hash) { &tiehash(); }
5326: }
5327:
5328: sub is_hash_old {
5329: my $untie_hash=0;
5330: if (!$hashtied) {
5331: $untie_hash=1;
5332: &tiehash();
5333: }
5334: my $return=$hash{'old'};
5335: if ($untie_hash) { &untiehash(); }
5336: return $return;
5337: }
5338:
5339: sub changewarning {
5340: my ($r,$postexec,$message,$url)=@_;
5341: if (!&is_hash_old()) { return; }
5342: my $pathvar='folderpath';
5343: my $path=&escape($env{'form.folderpath'});
5344: if (!defined($url)) {
5345: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5346: }
5347: my $course_type = &Apache::loncommon::course_type();
5348: if (!defined($message)) {
5349: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5350: }
5351: my $windowname = 'loncapaclient';
5352: if ($env{'request.lti.login'}) {
5353: $windowname .= 'lti';
5354: }
5355: $r->print("\n\n".
5356: '<script type="text/javascript">'."\n".
5357: '// <![CDATA['."\n".
5358: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5359: '// ]]>'."\n".
5360: '</script>'."\n".
5361: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
5362: '<input type="hidden" name="orgurl" value="'.$url.
5363: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
5364: &mt($message,' <input type="hidden" name="'.
5365: $env{'request.role'}.'" value="1" /><input type="button" value="'.
5366: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
5367: $help{'Caching'}.'</p></form>'."\n\n");
5368: }
5369:
5370:
5371: sub init_breadcrumbs {
5372: my ($form,$text,$help)=@_;
5373: &Apache::lonhtmlcommon::clear_breadcrumbs();
5374: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
5375: text=>&Apache::loncommon::course_type().' Editor',
5376: faq=>273,
5377: bug=>'Instructor Interface',
5378: help => $help});
5379: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5380: text=>$text,
5381: faq=>273,
5382: bug=>'Instructor Interface'});
5383: }
5384:
5385: # subroutine to list form elements
5386: sub create_list_elements {
5387: my @formarr = @_;
5388: my $list = '';
5389: foreach my $button (@formarr){
5390: foreach my $picture (keys(%{$button})) {
5391: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
5392: }
5393: }
5394: return $list;
5395: }
5396:
5397: # subroutine to create ul from list elements
5398: sub create_form_ul {
5399: my $list = shift;
5400: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5401: return $ul;
5402: }
5403:
5404: #
5405: # Start tabs
5406: #
5407:
5408: sub startContentScreen {
5409: my ($mode) = @_;
5410: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
5411: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
5412: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5413: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5414: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5415: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5416: } else {
5417: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n";
5418: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5419: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5420: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5421: }
5422: $output .= "\n".'</ul>'."\n";
5423: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5424: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5425: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5426: return $output;
5427: }
5428:
5429: #
5430: # End tabs
5431: #
5432:
5433: sub endContentScreen {
5434: return '</div></div></div>';
5435: }
5436:
5437: sub supplemental_base {
5438: return 'supplemental&'.&escape(&mt('Supplemental Content'));
5439: }
5440:
5441: sub handler {
5442: my $r = shift;
5443: &Apache::loncommon::content_type($r,'text/html');
5444: $r->send_http_header;
5445: return OK if $r->header_only;
5446:
5447: # get course data
5448: my $crstype = &Apache::loncommon::course_type();
5449: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5450: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5451:
5452: # get docroot
5453: my $londocroot = $r->dir_config('lonDocRoot');
5454:
5455: # graphics settings
5456: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
5457:
5458: #
5459: # --------------------------------------------- Initialize help topics for this
5460: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5461: 'Adding_External_Resource','Adding_External_Tool',
5462: 'Navigate_Content','Adding_Folders','Docs_Overview',
5463: 'Load_Map','Supplemental','Score_Upload_Form',
5464: 'Adding_Pages','Importing_LON-CAPA_Resource',
5465: 'Importing_IMS_Course','Uploading_From_Harddrive',
5466: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
5467: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5468: }
5469: # Composite help files
5470: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5471: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5472: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5473: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5474: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5475: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
5476: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
5477: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
5478: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
5479: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
5480:
5481: my ($allowed,$canedit,$canview,$noendpage,$disabled);
5482: # does this user have privileges to modify content.
5483: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5484: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5485: unless ($r->uri eq '/adm/supplemental') {
5486: $allowed = 1;
5487: }
5488: $canedit = 1;
5489: $canview = 1;
5490: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5491: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5492: unless ($r->uri eq '/adm/supplemental') {
5493: $allowed = 1;
5494: }
5495: $canview = 1;
5496: }
5497: unless ($canedit) {
5498: $disabled = ' disabled="disabled"';
5499: }
5500: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5501: if ($env{'form.inhibitmenu'}) {
5502: unless ($env{'form.inhibitmenu'} eq 'yes') {
5503: delete($env{'form.inhibitmenu'});
5504: }
5505: }
5506:
5507: if ($allowed && $env{'form.verify'}) {
5508: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
5509: if (!$canedit) {
5510: &verifycontent($r);
5511: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5512: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5513: text=>'Results',
5514: faq=>273,
5515: bug=>'Instructor Interface'});
5516: &verifycontent($r,$env{'form.checkstale'});
5517: } else {
5518: &contentverifyform($r);
5519: }
5520: } elsif ($allowed && $env{'form.listsymbs'}) {
5521: &init_breadcrumbs('listsymbs','List Content IDs');
5522: &list_symbs($r);
5523: } elsif ($allowed && $env{'form.shorturls'}) {
5524: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5525: &short_urls($r,$canedit);
5526: } elsif ($allowed && $env{'form.docslog'}) {
5527: &init_breadcrumbs('docslog','Show Log');
5528: my $folder = $env{'form.folder'};
5529: if ($folder eq '') {
5530: $folder='default';
5531: }
5532: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
5533: } elsif ($allowed && $env{'form.versions'}) {
5534: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
5535: &checkversions($r,$canedit);
5536: } elsif ($canedit && $env{'form.dumpcourse'}) {
5537: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
5538: &dumpcourse($r);
5539: } elsif ($canedit && $env{'form.exportcourse'}) {
5540: &init_breadcrumbs('exportcourse','IMS Export');
5541: &Apache::imsexport::exportcourse($r);
5542: } else {
5543: if ($canedit && $env{'form.authorrole'}) {
5544: $noendpage = 1;
5545: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5546: if ($redirect) {
5547: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5548: my $container = 'sequence';
5549: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5550: $is_random_order,$container) =
5551: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5552: my (@folders)=split('&',$env{'form.folderpath'});
5553: $env{'form.foldername'}=&unescape(pop(@folders));
5554: my $folder=pop(@folders);
5555: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5556: $folder.'.'.$container);
5557: my $warning;
5558: if ($fatal) {
5559: if ($container eq 'page') {
5560: $warning = &mt('An error occurred retrieving the contents of the current page.');
5561: } else {
5562: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5563: }
5564: } else {
5565: my $url = $redirect;
5566: my $srcfile = $londocroot.$url;
5567: $url =~ s{^/priv/}{/res/};
5568: my $targetfile = $londocroot.$url;
5569: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5570: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5571: $env{'form.folder'} = $folder;
5572: &snapshotbefore();
5573: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5574: my $ext = 'false';
5575: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5576: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5577: ':'.$ext.':normal:res';
5578: push(@LONCAPA::map::order,$newidx);
5579: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5580: 'string_yesno');
5581: &remember_parms($newidx,'hiddenresource','set','yes');
5582: ($errtext,$fatal) =
5583: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5584: &log_differences($plain);
5585: &mark_hash_old();
5586: $r->internal_redirect($redirect);
5587: return OK;
5588: }
5589: } else {
5590: $r->internal_redirect($redirect);
5591: }
5592: }
5593: }
5594: #
5595: # Done catching special calls
5596: # The whole rest is for course and supplemental documents and utilities menu
5597: # Get the parameters that may be needed
5598: #
5599: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
5600: ['folderpath','title',
5601: 'forcesupplement','forcestandard',
5602: 'tools','symb','command','supppath']);
5603:
5604: foreach my $item ('forcesupplement','forcestandard','tools') {
5605: next if ($env{'form.'.$item} eq '');
5606: unless ($env{'form.'.$item} eq '1') {
5607: delete($env{'form.'.$item});
5608: }
5609: }
5610:
5611: if ($env{'form.command'}) {
5612: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5613: delete($env{'form.command'});
5614: }
5615: }
5616:
5617: if ($env{'form.symb'}) {
5618: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5619: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5620: delete($env{'form.symb'});
5621: }
5622: }
5623:
5624: # standard=1: this is a "new-style" course with an uploaded map as top level
5625: # standard=2: this is a "old-style" course, and there is nothing we can do
5626:
5627: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
5628:
5629: # Decide whether this should display supplemental or main content or utilities
5630: # supplementalflag=1: show supplemental documents
5631: # supplementalflag=0: show standard documents
5632: # toolsflag=1: show utilities
5633:
5634: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5635: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5636: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
5637: $supplementalflag=0;
5638: }
5639: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5640: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5641: unless ($allowed) { $supplementalflag=1; }
5642: unless ($standard) { $supplementalflag=1; }
5643: my $toolsflag=0;
5644: if ($env{'form.tools'}) { $toolsflag=1; }
5645:
5646: if ($env{'form.folderpath'} ne '') {
5647: &validate_folderpath($supplementalflag);
5648: }
5649:
5650: if ($env{'form.supppath'} ne '') {
5651: &validate_suppath();
5652: }
5653:
5654: my $script='';
5655: my $showdoc=0;
5656: my $addentries = {};
5657: my $container;
5658: my $containertag;
5659: my $pathitem;
5660: my %ltitools;
5661: my $hiddentop;
5662: my $navmap;
5663: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
5664:
5665: # Do we directly jump somewhere?
5666: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
5667: if ($env{'form.symb'} ne '') {
5668: $env{'form.folderpath'}=
5669: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
5670: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5671: $env{'form.command'}.'_'.$env{'form.symb'}});
5672: } elsif ($env{'form.supppath'} ne '') {
5673: $env{'form.folderpath'}=$env{'form.supppath'};
5674: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5675: $env{'form.command'}.'_'.$env{'form.supppath'}});
5676: }
5677: } elsif ($env{'form.command'} eq 'editdocs') {
5678: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
5679: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
5680: } elsif ($env{'form.command'} eq 'editsupp') {
5681: $env{'form.folderpath'} = &supplemental_base();
5682: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5683: } elsif ($env{'form.command'} eq 'contents') {
5684: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5685: } elsif ($env{'form.command'} eq 'home') {
5686: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
5687: }
5688:
5689:
5690: # Where do we store these for when we come back?
5691: my $stored_folderpath='docs_folderpath';
5692: if ($supplementalflag) {
5693: $stored_folderpath='docs_sup_folderpath';
5694: }
5695:
5696: # No folderpath, and in edit mode, see if we have something stored
5697: if ((!$env{'form.folderpath'}) && $allowed) {
5698: &Apache::loncommon::restore_course_settings($stored_folderpath,
5699: {'folderpath' => 'scalar'});
5700:
5701: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5702: if ($supplementalflag) {
5703: undef($env{'form.folderpath'}) if ($1 eq 'default');
5704: } else {
5705: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5706: }
5707: } else {
5708: undef($env{'form.folderpath'});
5709: }
5710: if ($env{'form.folderpath'} ne '') {
5711: &validate_folderpath($supplementalflag);
5712: }
5713: }
5714:
5715: # If we are not allowed to make changes, all we can see are supplemental docs
5716: if (!$allowed) {
5717: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5718: $env{'form.folderpath'} = &supplemental_base();
5719: }
5720: }
5721: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
5722: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
5723: $env{'form.folderpath'} = &supplemental_base()
5724: .'&'.
5725: $env{'form.folderpath'};
5726: }
5727: # If allowed and user's role is not advanced check folderpath is not hidden
5728: if (($allowed) && (!$env{'request.role.adv'}) &&
5729: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5730: my $folderurl;
5731: my @pathitems = split(/\&/,$env{'form.folderpath'});
5732: my $folder = $pathitems[-2];
5733: if ($folder eq '') {
5734: undef($env{'form.folderpath'});
5735: } else {
5736: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
5737: if ((split(/\:/,$pathitems[-1]))[5]) {
5738: $folderurl .= '.page';
5739: } else {
5740: $folderurl .= '.sequence';
5741: }
5742: unless (ref($navmap)) {
5743: $navmap = Apache::lonnavmaps::navmap->new();
5744: }
5745: if (ref($navmap)) {
5746: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5747: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5748: unless (@resources) {
5749: undef($env{'form.folderpath'});
5750: }
5751: }
5752: }
5753: }
5754: }
5755:
5756:
5757: # If after all of this, we still don't have any paths, make them
5758: unless ($env{'form.folderpath'}) {
5759: if ($supplementalflag) {
5760: $env{'form.folderpath'}=&supplemental_base();
5761: } elsif ($allowed) {
5762: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
5763: }
5764: }
5765:
5766: # Store this
5767: unless ($toolsflag) {
5768: if (($allowed) && ($env{'form.folderpath'} ne '')) {
5769: &Apache::loncommon::store_course_settings($stored_folderpath,
5770: {'folderpath' => 'scalar'});
5771: }
5772: my $folderpath;
5773: if ($env{'form.folderpath'}) {
5774: $folderpath = $env{'form.folderpath'};
5775: my (@folders)=split('&',$env{'form.folderpath'});
5776: $env{'form.foldername'}=&unescape(pop(@folders));
5777: if ($env{'form.foldername'} =~ /\:1$/) {
5778: $container = 'page';
5779: } else {
5780: $container = 'sequence';
5781: }
5782: $env{'form.folder'}=pop(@folders);
5783: } else {
5784: if ($env{'form.folder'} eq '' ||
5785: $env{'form.folder'} eq 'supplemental') {
5786: if ($env{'form.folder'} eq 'supplemental') {
5787: $folderpath=&supplemental_base();
5788: } elsif (!$hiddentop) {
5789: $folderpath='default&'.
5790: &escape(&mt('Main Content').':::::');
5791: }
5792: }
5793: }
5794: $containertag = '<input type="hidden" name="folderpath" value="" />';
5795: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
5796: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5797: $showdoc='/'.$1;
5798: }
5799: if ($showdoc) { # got called in sequence from course
5800: $allowed=0;
5801: } else {
5802: if ($canedit) {
5803: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5804: $script=&Apache::lonratedt::editscript('simple');
5805: }
5806: }
5807: }
5808:
5809: # get personal data
5810: my $uname=$env{'user.name'};
5811: my $udom=$env{'user.domain'};
5812: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5813:
5814: if ($allowed) {
5815: if ($toolsflag) {
5816: $script .= &inject_data_js();
5817: my ($home,$other,%outhash)=&authorhosts();
5818: if (!$home && $other) {
5819: my @hosts;
5820: foreach my $aurole (keys(%outhash)) {
5821: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5822: push(@hosts,$outhash{$aurole});
5823: }
5824: }
5825: $script .= &dump_switchserver_js(@hosts);
5826: }
5827: } else {
5828: my $tid = 1;
5829: my @tabids;
5830: if ($supplementalflag) {
5831: @tabids = ('002','dd2','ee2','ff2');
5832: $tid = 2;
5833: } else {
5834: @tabids = ('aa1','bb1','cc1','ff1');
5835: unless ($env{'form.folderpath'} =~ /\:1$/) {
5836: unshift(@tabids,'001');
5837: push(@tabids,('dd1','ee1'));
5838: }
5839: }
5840: my $tabidstr = join("','",@tabids);
5841: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
5842: my $posslti = keys(%ltitools);
5843: my $hostname = $r->hostname();
5844: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
5845: $londocroot,$canedit,$hostname,\$navmap).
5846: &history_tab_js().
5847: &inject_data_js().
5848: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
5849: &Apache::lonextresedit::extedit_javascript(\%ltitools);
5850: $addentries = {
5851: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
5852: };
5853: }
5854: $script .= &paste_popup_js();
5855: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5856: &mt('Switch server?');
5857:
5858:
5859: }
5860: # -------------------------------------------------------------------- Body tag
5861: $script = '<script type="text/javascript">'."\n"
5862: .'// <![CDATA['."\n"
5863: .$script."\n"
5864: .'// ]]>'."\n"
5865: .'</script>'."\n"
5866: .'<script type="text/javascript"
5867: src="/res/adm/includes/file_upload.js"></script>'."\n";
5868:
5869: # Breadcrumbs
5870: &Apache::lonhtmlcommon::clear_breadcrumbs();
5871:
5872: if ($showdoc) {
5873: my $args;
5874: if ($supplementalflag) {
5875: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$env{'form.title'},1);
5876: $args = {'bread_crumbs' => $brcrum};
5877: } else {
5878: $args = {'force_register' => $showdoc};
5879: }
5880: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
5881: } elsif ($toolsflag) {
5882: my ($breadtext,$breadtitle);
5883: $breadtext = "$crstype Editor";
5884: if ($canedit) {
5885: $breadtitle = 'Editing '.$crstype.' Contents';
5886: } else {
5887: $breadtext .= ' (View-only mode)';
5888: $breadtitle = 'Viewing '.$crstype.' Contents';
5889: }
5890: &Apache::lonhtmlcommon::add_breadcrumb({
5891: href=>"/adm/coursedocs",text=>$breadtext});
5892: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5893: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5894: .&Apache::lonhtmlcommon::breadcrumbs(
5895: $breadtitle)
5896: );
5897: } elsif ($r->uri eq '/adm/supplemental') {
5898: unless ($env{'request.role.adv'}) {
5899: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
5900: $r->internal_redirect('/adm/navmaps');
5901: return OK;
5902: }
5903: }
5904: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5905: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5906: {'bread_crumbs' => $brcrum,}));
5907: } else {
5908: my ($breadtext,$breadtitle,$helpitem);
5909: $breadtext = "$crstype Editor";
5910: if ($canedit) {
5911: $breadtitle = 'Editing '.$crstype.' Contents';
5912: $helpitem = 'Docs_Adding_Course_Doc';
5913: } else {
5914: $breadtext .= ' (View-only mode)';
5915: $breadtitle = 'Viewing '.$crstype.' Contents';
5916: $helpitem = 'Docs_Viewing_Course_Doc';
5917: }
5918: &Apache::lonhtmlcommon::add_breadcrumb({
5919: href=>"/adm/coursedocs",text=>$breadtext});
5920: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
5921: {'add_entries' => $addentries}
5922: )
5923: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5924: .&Apache::lonhtmlcommon::breadcrumbs(
5925: $breadtitle,
5926: $helpitem)
5927: );
5928: }
5929:
5930: my %allfiles = ();
5931: my %codebase = ();
5932: my ($upload_result,$upload_output,$uploadphase);
5933: if ($canedit) {
5934: undef($suppchanges);
5935: if (($env{'form.uploaddoc.filename'}) &&
5936: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
5937: my $context = $1;
5938: # Process file upload - phase one - upload and parse primary file.
5939: undef($hadchanges);
5940: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
5941: \%allfiles,\%codebase,$context,$crstype);
5942: undef($navmap);
5943: if ($hadchanges) {
5944: &mark_hash_old();
5945: }
5946: if ($suppchanges) {
5947: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
5948: undef($suppchanges);
5949: }
5950: $r->print($upload_output);
5951: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5952: # Process file upload - phase two - upload embedded objects
5953: $uploadphase = 'check_embedded';
5954: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5955: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5956: $env{'form.newidx'});
5957: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5958: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5959: my ($destination,$dir_root) = &embedded_destination();
5960: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5961: my $actionurl = '/adm/coursedocs';
5962: my ($result,$flag) =
5963: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5964: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5965: $actionurl);
5966: $r->print($result.&return_to_editor());
5967: } elsif ($env{'form.phase'} eq 'check_embedded') {
5968: # Process file upload - phase three - modify references in HTML file
5969: $uploadphase = 'modified_orightml';
5970: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5971: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5972: my ($destination,$dir_root) = &embedded_destination();
5973: my $result =
5974: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5975: $docuname,$docudom,undef,
5976: $dir_root);
5977: $r->print($result.&return_to_editor());
5978: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5979: $uploadphase = 'decompress_phase_one';
5980: $r->print(&decompression_phase_one().
5981: &return_to_editor());
5982: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5983: $uploadphase = 'decompress_phase_two';
5984: $r->print(&decompression_phase_two().
5985: &return_to_editor());
5986: }
5987: }
5988:
5989: if ($allowed && $toolsflag) {
5990: $r->print(&startContentScreen('tools'));
5991: $r->print(&generate_admin_menu($crstype,$canedit));
5992: $r->print(&endContentScreen());
5993: } elsif ((!$showdoc) && (!$uploadphase)) {
5994: # -----------------------------------------------------------------------------
5995: my %lt=&Apache::lonlocal::texthash(
5996: 'copm' => 'All documents out of a published map into this folder',
5997: 'upfi' => 'Upload File',
5998: 'upld' => 'Upload Content',
5999: 'srch' => 'Search',
6000: 'impo' => 'Import',
6001: 'lnks' => 'Import from Stored Links',
6002: 'impm' => 'Import from Assembled Map',
6003: 'imcr' => 'Import from Course Resources',
6004: 'extr' => 'External Resource',
6005: 'extt' => 'External Tool',
6006: 'selm' => 'Select Map',
6007: 'load' => 'Load Map',
6008: 'newf' => 'New Folder',
6009: 'newp' => 'New Composite Page',
6010: 'syll' => 'Syllabus',
6011: 'navc' => 'Table of Contents',
6012: 'sipa' => 'Simple Course Page',
6013: 'sipr' => 'Simple Problem',
6014: 'webp' => 'Blank Web Page (editable)',
6015: 'stpr' => 'Standard Problem',
6016: 'news' => 'New sub-directory',
6017: 'crpr' => 'Create Problem',
6018: 'drbx' => 'Drop Box',
6019: 'scuf' => 'External Scores (handgrade, upload, clicker)',
6020: 'bull' => 'Discussion Board',
6021: 'mypi' => 'My Personal Information Page',
6022: 'grpo' => 'Group Portfolio',
6023: 'rost' => 'Course Roster',
6024: 'abou' => 'Personal Information Page for a User',
6025: 'imsf' => 'IMS Upload',
6026: 'imsl' => 'Upload IMS package',
6027: 'cms' => 'Origin of IMS package',
6028: 'se' => 'Select',
6029: 'file' => 'File',
6030: 'title' => 'Title',
6031: 'addp' => 'Add Placeholder to course?',
6032: 'uste' => 'Use Template?',
6033: 'fnam' => 'File Name:',
6034: 'loca' => 'Location:',
6035: 'dire' => 'Directory:',
6036: 'cate' => 'Category:',
6037: 'tmpl' => 'Template:',
6038: 'comment' => 'Comment',
6039: 'parse' => 'Upload embedded images/multimedia files if HTML file',
6040: 'bb5' => 'Blackboard 5',
6041: 'bb6' => 'Blackboard 6',
6042: 'angel5' => 'ANGEL 5.5',
6043: 'webctce4' => 'WebCT 4 Campus Edition',
6044: 'yes' => 'Yes',
6045: 'no' => 'No',
6046: 'er' => 'Editing rights unavailable for your current role.',
6047: );
6048: # -----------------------------------------------------------------------------
6049:
6050: # Calculate free quota space for a user or course. A javascript function checks
6051: # file size to determine if upload should be allowed.
6052: my $quotatype = 'unofficial';
6053: if ($crstype eq 'Community') {
6054: $quotatype = 'community';
6055: } elsif ($crstype eq 'Placement') {
6056: $quotatype = 'placement';
6057: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6058: $quotatype = 'official';
6059: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6060: $quotatype = 'textbook';
6061: }
6062: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6063: 'course',$quotatype); # expressed in MB
6064: my $current_disk_usage = 0;
6065: foreach my $subdir ('docs','supplemental') {
6066: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6067: "userfiles/$subdir",1); # expressed in kB
6068: }
6069: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
6070: my $usage = $current_disk_usage/1024; # in MB
6071: my $quota = $disk_quota;
6072: my $percent;
6073: if ($disk_quota == 0) {
6074: $percent = 100.0;
6075: } else {
6076: $percent = 100*($usage/$disk_quota);
6077: }
6078: $usage = sprintf("%.2f",$usage);
6079: $quota = sprintf("%.2f",$quota);
6080: $percent = sprintf("%.0f",$percent);
6081: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6082: $percent.'%',$quota.' MB').'</p>';
6083:
6084: my $fileupload=(<<FIUP);
6085: $quotainfo
6086: $lt{'file'}:<br />
6087: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
6088: <input type="hidden" id="LC_free_space" value="$free_space" />
6089: FIUP
6090:
6091: my $checkbox=(<<CHBO);
6092: <!-- <label>$lt{'parse'}?
6093: <input type="checkbox" name="parserflag" />
6094: </label> -->
6095: <label>
6096: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
6097: </label>
6098: CHBO
6099: my $imsfolder = $env{'form.folder'};
6100: if ($imsfolder eq '') {
6101: $imsfolder = 'default';
6102: }
6103: my $imspform=(<<IMSFORM);
6104: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6105: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6106: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
6107: <fieldset id="uploadimsform" style="display: none;">
6108: <legend>$lt{'imsf'}</legend>
6109: $fileupload
6110: <br />
6111: <p>
6112: $lt{'cms'}:
6113: <select name="source" $disabled>
6114: <option value="-1" selected="selected">$lt{'se'}</option>
6115: <option value="bb5">$lt{'bb5'}</option>
6116: <option value="bb6">$lt{'bb6'}</option>
6117: <option value="angel5">$lt{'angel5'}</option>
6118: <option value="webctce4">$lt{'webctce4'}</option>
6119: </select>
6120: <input type="hidden" name="folder" value="$imsfolder" />
6121: </p>
6122: <input type="hidden" name="phase" value="one" />
6123: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
6124: </fieldset>
6125: </form>
6126: IMSFORM
6127:
6128: my $fileuploadform=(<<FUFORM);
6129: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6130: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6131: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
6132: <fieldset id="uploaddocform" style="display: none;">
6133: <legend>$lt{'upfi'}</legend>
6134: <input type="hidden" name="active" value="aa" />
6135: $fileupload
6136: <br />
6137: $lt{'title'}:<br />
6138: <input type="text" size="60" name="comment" $disabled />
6139: $pathitem
6140: <input type="hidden" name="cmd" value="upload_default" />
6141: <br />
6142: <span class="LC_nobreak" style="float:left">
6143: $checkbox
6144: </span>
6145: <br clear="all" />
6146: <input type="submit" value="$lt{'upld'}" $disabled />
6147: </fieldset>
6148: </form>
6149: FUFORM
6150:
6151: my $mapimportjs;
6152: if ($canedit) {
6153: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6154: } else {
6155: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6156: }
6157: my $importpubform=(<<SEDFFORM);
6158: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
6159: $lt{'impm'}</a>$help{'Load_Map'}
6160: <form action="/adm/coursedocs" method="post" name="mapimportform">
6161: <fieldset id="importmapform" style="display: none;">
6162: <legend>$lt{'impm'}</legend>
6163: <input type="hidden" name="active" value="bb" />
6164: $lt{'copm'}<br />
6165: <span class="LC_nobreak">
6166: <input type="text" name="importmap" size="40" value=""
6167: onfocus="this.blur();$mapimportjs" $disabled />
6168: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6169: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
6170: </fieldset>
6171: </form>
6172:
6173: SEDFFORM
6174: my $importcrsresform;
6175: my ($numdirs,$pickfile) =
6176: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
6177: "resize_scrollbox('contentscroll','1','0');",
6178: undef,'res');
6179: if ($pickfile) {
6180: $importcrsresform=(<<CRSFORM);
6181: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
6182: $lt{'imcr'}</a>$help{'Course_Resources'}
6183: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6184: <fieldset id="importcrsresform" style="display: none;">
6185: <legend>$lt{'imcr'}</legend>
6186: <input type="hidden" name="active" value="bb" />
6187: $pickfile
6188: <p>
6189: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
6190: </p>
6191: <input type="hidden" name="importdetail" value="" />
6192: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
6193: </fieldset>
6194: </form>
6195: CRSFORM
6196: }
6197:
6198: my $fromstoredjs;
6199: if ($canedit) {
6200: $fromstoredjs = 'open_StoredLinks_Import()';
6201: } else {
6202: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6203: }
6204:
6205: my @importpubforma = (
6206: { '<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>" },
6207: { '<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'}" },
6208: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:'.$fromstoredjs.';" />' => '<a class="LC_menubuttons_link" href="javascript:'.$fromstoredjs.';">'.$lt{'lnks'}.'</a>' },
6209: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6210: );
6211: if ($pickfile) {
6212: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
6213: }
6214: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
6215: my $extresourcesform =
6216: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6217: $help{'Adding_External_Resource'},
6218: undef,undef,undef,undef,undef,undef,$disabled);
6219: my $exttoolform =
6220: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6221: $help{'Adding_External_Tool'},undef,
6222: undef,'tool',$coursedom,$coursenum,
6223: \%ltitools,$disabled);
6224: if ($allowed) {
6225: my $folder = $env{'form.folder'};
6226: if ($folder eq '') {
6227: $folder='default';
6228: }
6229: if ($canedit) {
6230: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6231: if ($output) {
6232: $r->print($output);
6233: }
6234: }
6235: $r->print(<<HIDDENFORM);
6236: <form name="renameform" method="post" action="/adm/coursedocs">
6237: <input type="hidden" name="title" />
6238: <input type="hidden" name="cmd" />
6239: <input type="hidden" name="markcopy" />
6240: <input type="hidden" name="copyfolder" />
6241: $containertag
6242: </form>
6243: <form name="aliasform" method="post" action="/adm/coursedocs">
6244: <input type="hidden" name="alias" />
6245: <input type="hidden" name="cmd" />
6246: $containertag
6247: </form>
6248:
6249: HIDDENFORM
6250: $r->print(&makesimpleeditform($pathitem)."\n".
6251: &makedocslogform($pathitem."\n".
6252: '<input type="hidden" name="folder" value="'.
6253: $env{'form.folder'}.'" />'."\n"));
6254: }
6255:
6256: # Generate the tabs
6257: my ($mode,$needs_end);
6258: if (($supplementalflag) && (!$allowed)) {
6259: my @folders = split('&',$env{'form.folderpath'});
6260: unless (@folders > 2) {
6261: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6262: $needs_end = 1;
6263: }
6264: } else {
6265: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
6266: $needs_end = 1;
6267: }
6268:
6269: #
6270: my $hostname = $r->hostname();
6271: my $savefolderpath;
6272:
6273: if ($allowed) {
6274: my $folder=$env{'form.folder'};
6275: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
6276: $folder='default';
6277: $savefolderpath = $env{'form.folderpath'};
6278: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
6279: $pathitem = '<input type="hidden" name="folderpath" value="'.
6280: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6281: }
6282: my $postexec='';
6283: if ($folder eq 'default') {
6284: my $windowname = 'loncapaclient';
6285: if ($env{'request.lti.login'}) {
6286: $windowname .= 'lti';
6287: }
6288: $r->print('<script type="text/javascript">'."\n"
6289: .'// <![CDATA['."\n"
6290: .'this.window.name="'.$windowname.'";'."\n"
6291: .'// ]]>'."\n"
6292: .'</script>'."\n"
6293: );
6294: } else {
6295: #$postexec='self.close();';
6296: }
6297: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6298: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
6299: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6300:
6301: my $newnavform=(<<NNFORM);
6302: <form action="/adm/coursedocs" method="post" name="newnav">
6303: <input type="hidden" name="active" value="ff" />
6304: $pathitem
6305: <input type="hidden" name="importdetail"
6306: value="$lt{'navc'}=/adm/navmaps" />
6307: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
6308: $help{'Navigate_Content'}
6309: </form>
6310: NNFORM
6311: my $newsmppageform=(<<NSPFORM);
6312: <form action="/adm/coursedocs" method="post" name="newsmppg">
6313: <input type="hidden" name="active" value="ff" />
6314: $pathitem
6315: <input type="hidden" name="importdetail" value="" />
6316: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
6317: $help{'Simple Page'}
6318: </form>
6319: NSPFORM
6320:
6321: my $newsmpproblemform=(<<NSPROBFORM);
6322: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
6323: <input type="hidden" name="active" value="dd" />
6324: $pathitem
6325: <input type="hidden" name="importdetail" value="" />
6326: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
6327: $help{'Simple_Problem'}
6328: </form>
6329:
6330: NSPROBFORM
6331:
6332: my $newdropboxform=(<<NDBFORM);
6333: <form action="/adm/coursedocs" method="post" name="newdropbox">
6334: <input type="hidden" name="active" value="dd" />
6335: $pathitem
6336: <input type="hidden" name="importdetail" value="" />
6337: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
6338: $help{'Dropbox'}
6339: </form>
6340: NDBFORM
6341:
6342: my $newexuploadform=(<<NEXUFORM);
6343: <form action="/adm/coursedocs" method="post" name="newexamupload">
6344: <input type="hidden" name="active" value="dd" />
6345: $pathitem
6346: <input type="hidden" name="importdetail" value="" />
6347: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
6348: $help{'Score_Upload_Form'}
6349: </form>
6350: NEXUFORM
6351:
6352: my $newbulform=(<<NBFORM);
6353: <form action="/adm/coursedocs" method="post" name="newbul">
6354: <input type="hidden" name="active" value="ee" />
6355: $pathitem
6356: <input type="hidden" name="importdetail" value="" />
6357: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
6358: $help{'Bulletin Board'}
6359: </form>
6360: NBFORM
6361:
6362: my $newaboutmeform=(<<NAMFORM);
6363: <form action="/adm/coursedocs" method="post" name="newaboutme">
6364: <input type="hidden" name="active" value="ee" />
6365: $pathitem
6366: <input type="hidden" name="importdetail"
6367: value="$plainname=/adm/$udom/$uname/aboutme" />
6368: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
6369: $help{'My Personal Information Page'}
6370: </form>
6371: NAMFORM
6372:
6373: my $newaboutsomeoneform=(<<NASOFORM);
6374: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
6375: <input type="hidden" name="active" value="ee" />
6376: $pathitem
6377: <input type="hidden" name="importdetail" value="" />
6378: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
6379: </form>
6380: NASOFORM
6381:
6382: my $newrosterform=(<<NROSTFORM);
6383: <form action="/adm/coursedocs" method="post" name="newroster">
6384: <input type="hidden" name="active" value="ee" />
6385: $pathitem
6386: <input type="hidden" name="importdetail"
6387: value="$lt{'rost'}=/adm/viewclasslist" />
6388: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
6389: $help{'Course_Roster'}
6390: </form>
6391: NROSTFORM
6392:
6393: my $newwebpage;
6394: if ($folder =~ /^default_?(\d*)$/) {
6395: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6396: if ($1) {
6397: $newwebpage .= $1;
6398: } else {
6399: $newwebpage .= 'default';
6400: }
6401: $newwebpage .= '/new.html';
6402: }
6403: my $newwebpageform =(<<NWEBFORM);
6404: <form action="/adm/coursedocs" method="post" name="newwebpage">
6405: <input type="hidden" name="active" value="ff" />
6406: $pathitem
6407: <input type="hidden" name="importdetail" value="$newwebpage" />
6408: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
6409: $help{'Web_Page'}
6410: </form>
6411: NWEBFORM
6412:
6413: my @ids=&Apache::lonnet::current_machine_ids();
6414: my %select_menus;
6415: my $numauthor = 0;
6416: my $numcrsdirs = 0;
6417: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
6418: if ($env{'user.author'}) {
6419: $numauthor ++;
6420: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6421: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6422: my $is_home = 1;
6423: my %subdirs;
6424: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6425: $select_menus{'author'}->{'default'} = '/';
6426: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6427: my @ordered = ('/');
6428: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6429: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6430: push(@ordered,$relpath);
6431: }
6432: $select_menus{'author'}->{'order'} = \@ordered;
6433: } else {
6434: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6435: $select_menus{'author'}->{'default'} = 'switch';
6436: $select_menus{'author'}->{'order'} = ['switch'];
6437: }
6438: }
6439: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6440: ['active'],['ca','aa']);
6441: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6442: my %by_roletype;
6443: if (keys(%roleshash)) {
6444: foreach my $entry (keys(%roleshash)) {
6445: my ($auname,$audom,$roletype) = split(/:/,$entry);
6446: my $key = $entry;
6447: $key =~ s/:/___/g;
6448: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6449: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6450: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6451: if (grep(/^\Q$rolehome\E$/,@ids)) {
6452: my $is_home = 1;
6453: my (%subdirs,@ordered);
6454: my $toppath="/priv/$audom/$auname";
6455: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6456: $select_menus{$key}->{'default'} = '/';
6457: $select_menus{$key}->{'select2'}->{'/'} = '/';
6458: my @ordered = ('/');
6459: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6460: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6461: push(@ordered,$relpath);
6462: }
6463: $select_menus{$key}->{'order'} = \@ordered;
6464: } else {
6465: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6466: $select_menus{$key}->{'default'} = 'switch';
6467: $select_menus{$key}->{'order'} = ['switch'];
6468: }
6469: $numauthor ++;
6470: }
6471: }
6472: my ($pickdir,$showtitle);
6473: if ($numauthor) {
6474: my @order;
6475: my $defrole;
6476: if ($env{'user.author'}) {
6477: push(@order,'author');
6478: $defrole = 'author';
6479: }
6480: if (keys(%by_roletype)) {
6481: foreach my $possrole ('ca','aa') {
6482: if (ref($by_roletype{$possrole}) eq 'HASH') {
6483: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6484: unless ($defrole) {
6485: $defrole = $author;
6486: }
6487: push(@order,$author.'___'.$possrole);
6488: }
6489: }
6490: }
6491: }
6492: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6493: if (grep(/^\Q$crshome\E$/,@ids)) {
6494: my $is_home = 1;
6495: my %subdirs;
6496: my $toppath="/priv/$coursedom/$coursenum";
6497: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6498: $numcrsdirs = keys(%subdirs);
6499: $select_menus{'course'}->{'default'} = '/';
6500: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6501: my @ordered = ('/');
6502: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6503: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6504: push(@ordered,$relpath);
6505: }
6506: $select_menus{'course'}->{'order'} = \@ordered;
6507: } else {
6508: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6509: $select_menus{'course'}->{'default'} = 'switch';
6510: $select_menus{'course'}->{'order'} = ['switch'];
6511: }
6512: push(@order,'course');
6513: $pickdir = $lt{'loca'}.
6514: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6515: $defrole,'authorrole','authorpath',
6516: \%select_menus,\@order,'toggleCrsResTitle();',
6517: '','priv').'<br />';
6518: $showtitle = 'none';
6519: } else {
6520: my $is_home;
6521: $showtitle = 'inline';
6522: if (grep(/^\Q$crshome\E$/,@ids)) {
6523: $is_home = 1;
6524: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6525: my $toppath="/priv/$coursedom/$coursenum'}";
6526: my %subdirs;
6527: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6528: $numcrsdirs = keys(%subdirs);
6529: if ($numcrsdirs) {
6530: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6531: '<option value="/">/</option>'."\n";
6532: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6533: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
6534: }
6535: $pickdir .= '</select>';
6536: } else {
6537: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6538: }
6539: }
6540: }
6541:
6542: my %seltemplate_menus;
6543: my @files = &Apache::lonhomework::get_template_list('problem');
6544: my @noexamplelink = ('blank.problem','blank.library','script.library');
6545: my $currentcategory = '';
6546: my @ordered = ('');
6547: my %templatehelp;
6548: my $defcategory = '';
6549: my @catorder = ($defcategory);
6550: $seltemplate_menus{$defcategory}->{'order'} = [''];
6551: $seltemplate_menus{$defcategory}->{'text'} = '';
6552: foreach my $file (@files) {
6553: if (ref($file) eq 'ARRAY') {
6554: my ($path,$title,$category,$help) = @{$file};
6555: next if ($title !~ /\S/);
6556: if (&js_escape($category) ne $currentcategory) {
6557: $currentcategory = &js_escape($category);
6558: push(@catorder,&js_escape($currentcategory));
6559: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6560: $seltemplate_menus{$currentcategory}->{'default'} = '';
6561: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6562: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6563: }
6564: if ($path) {
6565: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6566: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6567: if ($help) {
6568: $templatehelp{$path} = $help;
6569: }
6570: }
6571: }
6572: }
6573:
6574: my $templates = $lt{'cate'}.' '.
6575: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6576: $defcategory,'tempcategory','template',
6577: \%seltemplate_menus,\@catorder,
6578: "resize_scrollbox('contentscroll','1','0');",
6579: "toggleExampleText();",'template').'<br />';
6580: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6581: '<span id="newresexample">'.&mt('Example').'<span></a>';
6582: my $crsresform=(<<RESFORM);
6583: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6584: $lt{'stpr'}</a>$help{'Course_Resource'}
6585: <form action="/adm/coursedocs" method="post" name="courseresform">
6586: <fieldset id="crsresform" style="display:none;">
6587: <legend>$lt{'stpr'}</legend>
6588: <input type="hidden" name="active" value="bb" />
6589: <p>
6590: $pickdir
6591: <span class="LC_nobreak">$lt{'news'}?
6592: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
6593:
6594: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
6595: </span><span id="newsubdir"></span>
6596: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6597: </p>
6598: $lt{'fnam'}
6599: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
6600: <p>
6601: <div id="newresource" style="display:$showtitle">
6602: $lt{'addp'}
6603: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
6604: $lt{'no'}</label>
6605: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
6606: $lt{'yes'}</label>
6607: <span id="newrestitle"></span>
6608: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
6609: </div>
6610: </p>
6611: <p>
6612: $lt{'uste'}
6613: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
6614: $lt{'no'}</label>
6615: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
6616: $lt{'yes'}</label>
6617: <div id="newrestemplate" style="display:none">
6618: $templates
6619: $templatepreview
6620: </div>
6621: </p>
6622: <span class="LC_nobreak">
6623: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
6624: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
6625: </span>
6626: </fieldset>
6627: </form>
6628:
6629: RESFORM
6630:
6631: my $specialdocumentsform;
6632: my @specialdocumentsforma;
6633: my $gradingform;
6634: my @gradingforma;
6635: my $communityform;
6636: my @communityforma;
6637: my $newfolderform;
6638: my $newfolderb;
6639:
6640: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6641:
6642: my $newpageform=(<<NPFORM);
6643: <form action="/adm/coursedocs" method="post" name="newpage">
6644: <input type="hidden" name="folderpath" value="$path" />
6645: <input type="hidden" name="importdetail" value="" />
6646: <input type="hidden" name="active" value="ee" />
6647: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
6648: $help{'Adding_Pages'}
6649: </form>
6650: NPFORM
6651:
6652:
6653: $newfolderform=(<<NFFORM);
6654: <form action="/adm/coursedocs" method="post" name="newfolder">
6655: $pathitem
6656: <input type="hidden" name="importdetail" value="" />
6657: <input type="hidden" name="active" value="" />
6658: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
6659: </form>
6660: NFFORM
6661:
6662: my $newsylform=(<<NSYLFORM);
6663: <form action="/adm/coursedocs" method="post" name="newsyl">
6664: <input type="hidden" name="active" value="ee" />
6665: $pathitem
6666: <input type="hidden" name="importdetail"
6667: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
6668: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
6669: $help{'Syllabus'}
6670:
6671: </form>
6672: NSYLFORM
6673:
6674: my $newgroupfileform=(<<NGFFORM);
6675: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
6676: <input type="hidden" name="active" value="ee" />
6677: $pathitem
6678: <input type="hidden" name="importdetail"
6679: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
6680: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
6681: $help{'Group Portfolio'}
6682: </form>
6683: NGFFORM
6684: if ($container eq 'page') {
6685: @specialdocumentsforma=(
6686: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6687: );
6688: } else {
6689: @specialdocumentsforma=(
6690: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
6691: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6692: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
6693: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
6694: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6695: );
6696: }
6697: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6698:
6699: my @external = (
6700: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
6701: );
6702: if (keys(%ltitools)) {
6703: push(@external,
6704: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6705: );
6706: }
6707: my $externalform = &create_form_ul(&create_list_elements(@external));
6708:
6709: my @importdoc = ();
6710: unless ($container eq 'page') {
6711: push(@importdoc,
6712: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6713: );
6714: }
6715: push(@importdoc,
6716: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
6717: );
6718: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
6719:
6720: @gradingforma=(
6721: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6722: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6723: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6724: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform},
6725: );
6726: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6727:
6728: @communityforma=(
6729: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6730: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6731: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
6732: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6733: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
6734: );
6735: $communityform = &create_form_ul(&create_list_elements(@communityforma));
6736:
6737: my %orderhash = (
6738: 'aa' => ['Upload',$fileuploadform],
6739: 'bb' => ['Import',$importpubform],
6740: 'cc' => ['External',$externalform],
6741: 'dd' => ['Grading',$gradingform],
6742: 'ff' => ['Other',$specialdocumentsform],
6743: );
6744: unless ($container eq 'page') {
6745: $orderhash{'00'} = ['Newfolder',$newfolderform];
6746: $orderhash{'ee'} = ['Collaboration',$communityform];
6747: }
6748:
6749: $hadchanges=0;
6750: unless (($supplementalflag || $toolsflag)) {
6751: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6752: $supplementalflag,\%orderhash,$iconpath,$pathitem,
6753: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
6754: undef($navmap);
6755: if ($error) {
6756: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6757: }
6758: if ($hadchanges) {
6759: unless (&is_hash_old()) {
6760: &mark_hash_old();
6761: }
6762: }
6763:
6764: &changewarning($r,'');
6765: }
6766: }
6767:
6768: # Supplemental documents start here
6769:
6770: my $folder=$env{'form.folder'};
6771: unless ($supplementalflag) {
6772: $folder='supplemental';
6773: }
6774: if ($folder =~ /^supplemental$/ &&
6775: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
6776: $env{'form.folderpath'} = &supplemental_base();
6777: } elsif ($allowed) {
6778: $env{'form.folderpath'} = $savefolderpath;
6779: }
6780: $pathitem = '<input type="hidden" name="folderpath" value="'.
6781: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6782: if ($allowed) {
6783: my $folderseq=
6784: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
6785:
6786: my $supupdocform=(<<SUPDOCFORM);
6787: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6788: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6789: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
6790: <fieldset id="uploadsuppdocform" style="display: none;">
6791: <legend>$lt{'upfi'}</legend>
6792: <input type="hidden" name="active" value="ee" />
6793: $fileupload
6794: <br />
6795: <br />
6796: <span class="LC_nobreak">
6797: $checkbox
6798: </span>
6799: <br /><br />
6800: $lt{'comment'}:<br />
6801: <textarea cols="50" rows="4" name="comment"></textarea>
6802: <br />
6803: $pathitem
6804: <input type="hidden" name="cmd" value="upload_supplemental" />
6805: <input type='submit' value="$lt{'upld'}" />
6806: </form>
6807: SUPDOCFORM
6808:
6809: my $supnewfolderform=(<<SNFFORM);
6810: <form action="/adm/coursedocs" method="post" name="supnewfolder">
6811: <input type="hidden" name="active" value="" />
6812: $pathitem
6813: <input type="hidden" name="importdetail" value="" />
6814: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
6815: $help{'Adding_Folders'}
6816: </form>
6817: SNFFORM
6818:
6819: my $supextform =
6820: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6821: $help{'Adding_External_Resource'},
6822: undef,undef,undef,undef,undef,undef,
6823: $disabled);
6824:
6825: my $supexttoolform =
6826: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6827: $help{'Adding_External_Tool'},
6828: undef,undef,'tool',$coursedom,
6829: $coursenum,\%ltitools,$disabled);
6830:
6831: my $supnewsylform=(<<SNSFORM);
6832: <form action="/adm/coursedocs" method="post" name="supnewsyl">
6833: <input type="hidden" name="active" value="ff" />
6834: $pathitem
6835: <input type="hidden" name="importdetail"
6836: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
6837: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
6838: $help{'Syllabus'}
6839: </form>
6840: SNSFORM
6841:
6842: my $supnewaboutmeform=(<<SNAMFORM);
6843: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
6844: <input type="hidden" name="active" value="ff" />
6845: $pathitem
6846: <input type="hidden" name="importdetail"
6847: value="$plainname=/adm/$udom/$uname/aboutme" />
6848: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
6849: $help{'My Personal Information Page'}
6850: </form>
6851: SNAMFORM
6852:
6853: my $supwebpage;
6854: if ($folder =~ /^supplemental_?(\d*)$/) {
6855: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6856: if ($1) {
6857: $supwebpage .= $1;
6858: } else {
6859: $supwebpage .= 'default';
6860: }
6861: $supwebpage .= '/new.html';
6862: }
6863: my $supwebpageform =(<<SWEBFORM);
6864: <form action="/adm/coursedocs" method="post" name="supwebpage">
6865: <input type="hidden" name="active" value="cc" />
6866: $pathitem
6867: <input type="hidden" name="importdetail" value="$supwebpage" />
6868: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
6869: $help{'Web_Page'}
6870: </form>
6871: SWEBFORM
6872:
6873:
6874: my @specialdocs = (
6875: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
6876: =>$supnewsylform},
6877: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
6878: =>$supnewaboutmeform},
6879: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6880:
6881: );
6882: my @supexternal = (
6883: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
6884: =>$supextform});
6885: if (keys(%ltitools)) {
6886: push(@supexternal,
6887: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
6888: =>$supexttoolform});
6889: }
6890: my @supimportdoc = (
6891: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6892: =>$supupdocform},
6893: );
6894:
6895: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
6896: my %suporderhash = (
6897: '00' => ['Supnewfolder', $supnewfolderform],
6898: 'dd' => ['Upload',$supupdocform],
6899: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
6900: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
6901: );
6902: if ($supplementalflag) {
6903: $suppchanges = 0;
6904: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6905: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
6906: \%ltitools,$canedit,$hostname);
6907: if ($error) {
6908: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6909: }
6910: if ($suppchanges) {
6911: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6912: undef($suppchanges);
6913: }
6914: }
6915: } elsif ($supplementalflag) {
6916: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6917: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
6918: $hostname);
6919: if ($error) {
6920: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6921: }
6922: }
6923:
6924: if ($needs_end) {
6925: $r->print(&endContentScreen());
6926: }
6927:
6928: if ($allowed) {
6929: $r->print('
6930: <form method="post" name="extimport" action="/adm/coursedocs">
6931: <input type="hidden" name="title" />
6932: <input type="hidden" name="url" />
6933: <input type="hidden" name="useform" />
6934: <input type="hidden" name="residx" />
6935: </form>');
6936: }
6937: } elsif ($showdoc) {
6938: # -------------------------------------------------------- This is showdoc mode
6939: $r->print("<h1>".&mt('Uploaded Document').' - '.
6940: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
6941: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
6942: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
6943: }
6944: }
6945: unless ($noendpage) {
6946: $r->print(&Apache::loncommon::end_page());
6947: }
6948: return OK;
6949: }
6950:
6951: sub embedded_form_elems {
6952: my ($phase,$primaryurl,$newidx) = @_;
6953: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6954: $newidx =~s /\D+//g;
6955: return <<STATE;
6956: <input type="hidden" name="folderpath" value="$folderpath" />
6957: <input type="hidden" name="cmd" value="upload_embedded" />
6958: <input type="hidden" name="newidx" value="$newidx" />
6959: <input type="hidden" name="phase" value="$phase" />
6960: <input type="hidden" name="primaryurl" value="$primaryurl" />
6961: STATE
6962: }
6963:
6964: sub embedded_destination {
6965: my $folder=$env{'form.folder'};
6966: my $destination = 'docs/';
6967: if ($folder =~ /^supplemental/) {
6968: $destination = 'supplemental/';
6969: }
6970: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6971: $destination .= 'default/';
6972: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6973: $destination .= $2.'/';
6974: }
6975: my $newidx = $env{'form.newidx'};
6976: $newidx =~s /\D+//g;
6977: if ($newidx) {
6978: $destination .= $newidx;
6979: }
6980: my $dir_root = '/userfiles';
6981: return ($destination,$dir_root);
6982: }
6983:
6984: sub return_to_editor {
6985: my $actionurl = '/adm/coursedocs';
6986: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6987: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6988: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6989: '</a></p>';
6990: }
6991:
6992: sub decompression_info {
6993: my ($destination,$dir_root) = &embedded_destination();
6994: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6995: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6996: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6997: my $container='sequence';
6998: my ($pathitem,$hiddenelem);
6999: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
7000: if ($env{'form.folderpath'} =~ /\:1$/) {
7001: $container='page';
7002: }
7003: unshift(@hiddens,$pathitem);
7004: foreach my $item (@hiddens) {
7005: if ($item eq 'newidx') {
7006: next if ($env{'form.'.$item} =~ /\D/);
7007: }
7008: if ($env{'form.'.$item}) {
7009: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
7010: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
7011: }
7012: }
7013: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7014: $hiddenelem);
7015: }
7016:
7017: sub decompression_phase_one {
7018: my ($dir,$file,$warning,$error,$output);
7019: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7020: &decompression_info();
7021: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
7022: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7023: } else {
7024: my $file = $1;
7025: $output =
7026: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7027: $destination,$dir_root,
7028: $hiddenelem);
7029: if ($env{'form.autoextract_camtasia'}) {
7030: $output .= &remove_archive($docudom,$docuname,$container);
7031: }
7032: }
7033: if ($error) {
7034: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7035: $error.'</p>'."\n";
7036: }
7037: if ($warning) {
7038: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7039: }
7040: return $output;
7041: }
7042:
7043: sub decompression_phase_two {
7044: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7045: &decompression_info();
7046: my $output;
7047: if ($env{'form.archivedelete'}) {
7048: $output = &remove_archive($docudom,$docuname,$container);
7049: }
7050: $output .=
7051: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
7052: $destination,$dir_root,$hiddenelem);
7053: return $output;
7054: }
7055:
7056: sub remove_archive {
7057: my ($docudom,$docuname,$container) = @_;
7058: my $map = $env{'form.folder'}.'.'.$container;
7059: my ($output,$delwarning,$delresult,$url);
7060: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7061: if ($fatal) {
7062: if ($container eq 'page') {
7063: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7064: } else {
7065: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7066: }
7067: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
7068: } else {
7069: my $currcmd = $env{'form.cmd'};
7070: my $position = $env{'form.position'};
7071: my $archiveidx = $position;
7072: if ($position > 0) {
7073: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7074: $archiveidx = $position-1;
7075: }
7076: $env{'form.cmd'} = 'remove_'.$archiveidx;
7077: my ($title,$url,@rrest) =
7078: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7079: if ($url eq $env{'form.archiveurl'}) {
7080: if (&handle_edit_cmd($docuname,$docudom)) {
7081: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
7082: if ($suppchanges) {
7083: &Apache::lonnet::update_supp_caches($docudom,$docuname);
7084: undef($suppchanges);
7085: }
7086: if ($fatal) {
7087: if ($container eq 'page') {
7088: $delwarning = &mt('An error occurred updating the contents of the current page.');
7089: } else {
7090: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7091: }
7092: } else {
7093: $delresult = &mt('Archive file removed.');
7094: }
7095: }
7096: } else {
7097: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7098: ' '.&mt('As a result the archive file has not been removed.');
7099: }
7100: }
7101: $env{'form.cmd'} = $currcmd;
7102: }
7103: if ($delwarning) {
7104: $output = '<p class="LC_warning">'.
7105: $delwarning.
7106: '</p>';
7107: }
7108: if ($delresult) {
7109: $output .= '<p class="LC_info">'.
7110: $delresult.
7111: '</p>';
7112: }
7113: return $output;
7114: }
7115:
7116: sub generate_admin_menu {
7117: my ($crstype,$canedit) = @_;
7118: my $lc_crstype = lc($crstype);
7119: my ($home,$other,%outhash)=&authorhosts();
7120: my %lt= ( # do not translate here
7121: 'vc' => 'Verify Content',
7122: 'cv' => 'Check/Set Resource Versions',
7123: 'ls' => 'List Resource Identifiers',
7124: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
7125: 'imse' => 'Export contents to IMS Archive',
7126: 'dcd' => "Copy $crstype Content to Authoring Space",
7127: );
7128: my ($candump,$dumpurl);
7129: if ($home + $other > 0) {
7130: $candump = 'F';
7131: if ($home) {
7132: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7133: } else {
7134: my @hosts;
7135: foreach my $aurole (keys(%outhash)) {
7136: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7137: push(@hosts,$outhash{$aurole});
7138: }
7139: }
7140: if (@hosts == 1) {
7141: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7142: '&role='.
7143: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7144: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7145: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7146: } else {
7147: $dumpurl = "javascript:choose_switchserver_window()";
7148: }
7149: }
7150: }
7151: my @menu=
7152: ({ categorytitle=>'Administration',
7153: items =>[
7154: { linktext => $lt{'vc'},
7155: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7156: permission => 'F',
7157: help => 'Docs_Verify_Content',
7158: icon => 'verify.png',
7159: linktitle => 'Verify contents can be retrieved/rendered',
7160: },
7161: { linktext => $lt{'cv'},
7162: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7163: permission => 'F',
7164: help => 'Docs_Check_Resource_Versions',
7165: icon => 'resversion.png',
7166: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7167: },
7168: { linktext => $lt{'ls'},
7169: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7170: permission => 'F',
7171: #help => '',
7172: icon => 'symbs.png',
7173: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7174: },
7175: { linktext => $lt{'ct'},
7176: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7177: permission => 'F',
7178: help => 'Docs_Short_URLs',
7179: icon => 'shorturls.png',
7180: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7181: },
7182: ]
7183: });
7184: if ($canedit) {
7185: push(@menu,
7186: { categorytitle=>'Export',
7187: items =>[
7188: { linktext => $lt{'imse'},
7189: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7190: permission => 'F',
7191: help => 'Docs_Export_Course_Docs',
7192: icon => 'imsexport.png',
7193: linktitle => $lt{'imse'},
7194: },
7195: { linktext => $lt{'dcd'},
7196: url => $dumpurl,
7197: permission => $candump,
7198: help => 'Docs_Dump_Course_Docs',
7199: icon => 'dump.png',
7200: linktitle => $lt{'dcd'},
7201: },
7202: ]
7203: });
7204: }
7205: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7206: '<input type="hidden" id="dummy" />'."\n".
7207: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7208: '</form>';
7209: }
7210:
7211: sub generate_edit_table {
7212: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
7213: $need_save,$copyfolder,$canedit) = @_;
7214: return unless(ref($orderhash_ref) eq 'HASH');
7215: my %orderhash = %{$orderhash_ref};
7216: my ($form, $activetab, $active, $disabled);
7217: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
7218: $activetab = $env{'form.active'};
7219: }
7220: unless ($canedit) {
7221: $disabled = ' disabled="disabled"';
7222: }
7223: my $backicon = $iconpath.'clickhere.gif';
7224: my $backtext = &mt('Exit Editor');
7225: $form = '<div class="LC_Box" style="margin:0;">'.
7226: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7227: '<li class="goback">'.
7228: '<a href="javascript:toContents('."'$jumpto'".');">'.
7229: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7230: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7231: '<li>'.
7232: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7233: &mt('Undo Delete').'</a></li>'."\n";
7234: if ($env{'form.docslog'}) {
7235: $form .= '<li class="active">';
7236: } else {
7237: $form .= '<li>';
7238: }
7239: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7240: &mt('History').'</a></li>'."\n";
7241: if ($env{'form.docslog'}) {
7242: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7243: &mt('Edit').'</a></li>'."\n";
7244: }
7245: foreach my $name (reverse(sort(keys(%orderhash)))) {
7246: if($name ne '00'){
7247: if($activetab eq '' || $activetab ne $name){
7248: $active = '';
7249: }elsif($activetab eq $name){
7250: $active = 'class="active"';
7251: }
7252: $form .= '<li style="float:right" '.$active
7253: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
7254: } else {
7255: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
7256:
7257: }
7258: }
7259: $form .= '</ul>'."\n";
7260: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
7261:
7262: if ($to_show ne '') {
7263: my $saveform;
7264: if ($need_save) {
7265: my $button = &mt('Make changes');
7266: my $path;
7267: if ($env{'form.folderpath'}) {
7268: $path =
7269: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7270: }
7271: $saveform = <<"END";
7272: <div id="multisave" style="display:none; clear:both;" >
7273: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7274: <input type="hidden" name="folderpath" value="$path" />
7275: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7276: <input type="hidden" name="allhiddenresource" value="" />
7277: <input type="hidden" name="allencrypturl" value="" />
7278: <input type="hidden" name="allrandompick" value="" />
7279: <input type="hidden" name="allrandomorder" value="" />
7280: <input type="hidden" name="changeparms" value="" />
7281: <input type="hidden" name="multiremove" value="" />
7282: <input type="hidden" name="multicut" value="" />
7283: <input type="hidden" name="multicopy" value="" />
7284: <input type="hidden" name="multichange" value="" />
7285: <input type="hidden" name="copyfolder" value="$copyfolder" />
7286: <input type="submit" name="savemultiples" value="$button" $disabled />
7287: </form>
7288: </div>
7289: END
7290: }
7291: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
7292: }
7293: foreach my $field (keys(%orderhash)){
7294: if($field ne '00'){
7295: if($activetab eq '' || $activetab ne $field){
7296: $active = 'style="display: none;float:left"';
7297: }elsif($activetab eq $field){
7298: $active = 'style="display:block;float:left"';
7299: }
7300: $form .= '<div id="'.$field.$tid.'"'
7301: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
7302: .'</div>'."\n";
7303: }
7304: }
7305: unless ($env{'form.docslog'}) {
7306: $form .= '</div></div>'."\n";
7307: }
7308: return $form;
7309: }
7310:
7311: sub editing_js {
7312: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7313: $londocroot,$canedit,$hostname,$navmapref) = @_;
7314: my %js_lt = &Apache::lonlocal::texthash(
7315: p_mnf => 'Name of New Folder',
7316: t_mnf => 'New Folder',
7317: p_mnp => 'Name of New Page',
7318: t_mnp => 'New Page',
7319: p_mxu => 'Title for the External Score',
7320: p_msp => 'Name of Simple Course Page',
7321: p_msb => 'Title for the Problem',
7322: p_mdb => 'Title for the Drop Box',
7323: p_mbb => 'Title for the Discussion Board',
7324: p_mwp => 'Title for Web Page',
7325: p_mnr => 'Title for the Resource',
7326: p_mab => "Enter user:domain for User's Personal Information Page",
7327: p_mab2 => 'Personal Information Page of ',
7328: p_mab_alrt1 => 'Not a valid user:domain',
7329: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7330: p_chn => 'New Title',
7331: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
7332: p_rmr2a => 'Remove',
7333: p_rmr2b => '?',
7334: p_rmr3a => 'Remove those',
7335: p_rmr3b => 'items?',
7336: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7337: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
7338: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7339: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
7340: p_ctr2a => 'Cut',
7341: p_ctr2b => '?',
7342: p_ctr3a => 'Cut those',
7343: p_ctr3b => 'items?',
7344: setal => 'Enter a (unique) alias',
7345: delal => 'Are you sure you want to eliminate the alias?',
7346: rpck => 'Enter number to pick (e.g., 3)',
7347: imsfile => 'You must choose an IMS package for import',
7348: imscms => 'You must select which Course Management System was the source of the IMS package',
7349: invurl => 'Invalid URL',
7350: titbl => 'Title is blank',
7351: more => '(More ...)',
7352: less => '(Less ...)',
7353: noor => 'No actions selected or changes to settings specified.',
7354: noch => 'No changes to settings specified.',
7355: noac => 'No actions selected.',
7356: nofi => 'No file selected',
7357: tinc => 'Title in course',
7358: sunm => 'Sub-directory name',
7359: edri => 'Editing rights unavailable for your current role.',
7360: );
7361: &js_escape(\%js_lt);
7362: my $crstype = &Apache::loncommon::course_type();
7363: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7364: my $main_container_page;
7365: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7366: $main_container_page = 1;
7367: }
7368: my $backtourl;
7369: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
7370: my $toplevelsupp = &supplemental_base();
7371:
7372: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7373: my $caller = $1;
7374: if ($caller =~ /^supplemental/) {
7375: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7376: } else {
7377: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7378: $res = &Apache::lonnet::clutter($res);
7379: if (&Apache::lonnet::is_on_map($res)) {
7380: my ($url,$anchor);
7381: if ($res =~ /^([^#]+)#([^#]+)$/) {
7382: $url = $1;
7383: $anchor = $2;
7384: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7385: $caller = $1.&escape('#').$anchor;
7386: }
7387: } else {
7388: $url = $res;
7389: }
7390: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7391: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7392: $backtourl .= '?navmap=1';
7393: } else {
7394: $backtourl .= '?symb='.
7395: &HTML::Entities::encode($caller,'<>&"');
7396: }
7397: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7398: if (($ENV{'SERVER_PORT'} == 443) &&
7399: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
7400: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
7401: if ($hostname ne '') {
7402: $backtourl = 'http://'.$hostname.$backtourl;
7403: }
7404: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7405: }
7406: }
7407: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7408: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
7409: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
7410: if ($hostname ne '') {
7411: $backtourl = 'http://'.$hostname.$backtourl;
7412: }
7413: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7414: }
7415: }
7416: }
7417: if ($anchor ne '') {
7418: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7419: }
7420: $backtourl = &Apache::loncommon::escape_single($backtourl);
7421: } else {
7422: $backtourl = '/adm/navmaps';
7423: }
7424: }
7425: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7426: $backtourl = '/adm/menu';
7427: } elsif ($supplementalflag) {
7428: if (($env{'request.role.adv'}) ||
7429: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7430: $backtourl = '/adm/supplemental';
7431: } else {
7432: $backtourl = '/adm/navmaps';
7433: }
7434: } else {
7435: $backtourl = '/adm/navmaps';
7436: }
7437:
7438: my $fieldsets = "'doc'";
7439: unless ($main_container_page) {
7440: $fieldsets .=",'ims'";
7441: }
7442: my $extfieldsets = "'ext'";
7443: if ($posslti) {
7444: $extfieldsets .= ",'tool'";
7445: }
7446: if ($supplementalflag) {
7447: $fieldsets = "'suppdoc'";
7448: $extfieldsets = "'suppext'";
7449: if ($posslti) {
7450: $extfieldsets .= ",'supptool'";
7451: }
7452: }
7453:
7454: my $jsmakefunctions;
7455: if ($canedit) {
7456: $jsmakefunctions = <<ENDNEWSCRIPT;
7457: function makenewfolder(targetform,folderseq) {
7458: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
7459: if (foldername) {
7460: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
7461: targetform.submit();
7462: }
7463: }
7464:
7465: function makenewpage(targetform,folderseq) {
7466: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
7467: if (pagename) {
7468: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
7469: targetform.submit();
7470: }
7471: }
7472:
7473: function makeexamupload() {
7474: var title=prompt('$js_lt{"p_mxu"}');
7475: if (title) {
7476: this.document.forms.newexamupload.importdetail.value=
7477: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
7478: this.document.forms.newexamupload.submit();
7479: }
7480: }
7481:
7482: function makesmppage() {
7483: var title=prompt('$js_lt{"p_msp"}');
7484: if (title) {
7485: this.document.forms.newsmppg.importdetail.value=
7486: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
7487: this.document.forms.newsmppg.submit();
7488: }
7489: }
7490:
7491: function makewebpage(type) {
7492: var title=prompt('$js_lt{"p_mwp"}');
7493: var formname;
7494: if (type == 'supp') {
7495: formname = this.document.forms.supwebpage;
7496: } else {
7497: formname = this.document.forms.newwebpage;
7498: }
7499: if (title) {
7500: var webpage = formname.importdetail.value;
7501: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
7502: formname.submit();
7503: }
7504: }
7505:
7506: function makesmpproblem() {
7507: var title=prompt('$js_lt{"p_msb"}');
7508: if (title) {
7509: this.document.forms.newsmpproblem.importdetail.value=
7510: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
7511: this.document.forms.newsmpproblem.submit();
7512: }
7513: }
7514:
7515: function makedropbox() {
7516: var title=prompt('$js_lt{"p_mdb"}');
7517: if (title) {
7518: this.document.forms.newdropbox.importdetail.value=
7519: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
7520: this.document.forms.newdropbox.submit();
7521: }
7522: }
7523:
7524: function makebulboard() {
7525: var title=prompt('$js_lt{"p_mbb"}');
7526: if (title) {
7527: this.document.forms.newbul.importdetail.value=
7528: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
7529: this.document.forms.newbul.submit();
7530: }
7531: }
7532:
7533: function makeabout() {
7534: var user=prompt("$js_lt{'p_mab'}");
7535: if (user) {
7536: var comp=new Array();
7537: comp=user.split(':');
7538: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7539: if ((comp[0]) && (comp[1])) {
7540: this.document.forms.newaboutsomeone.importdetail.value=
7541: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
7542: this.document.forms.newaboutsomeone.submit();
7543: } else {
7544: alert("$js_lt{'p_mab_alrt1'}");
7545: }
7546: } else {
7547: alert("$js_lt{'p_mab_alrt2'}");
7548: }
7549: }
7550: }
7551:
7552: function makenew(targetform) {
7553: targetform.submit();
7554: }
7555:
7556: function changename(folderpath,index,oldtitle) {
7557: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7558: if (title) {
7559: this.document.forms.renameform.markcopy.value='';
7560: this.document.forms.renameform.title.value=title;
7561: this.document.forms.renameform.cmd.value='rename_'+index;
7562: this.document.forms.renameform.folderpath.value=folderpath;
7563: this.document.forms.renameform.submit();
7564: }
7565: }
7566:
7567: function setalias(folderpath,index) {
7568: var alias = prompt('$js_lt{"setal"}');
7569: if ((alias != null) && (alias != '')) {
7570: this.document.forms.aliasform.alias.value=alias;
7571: this.document.forms.aliasform.cmd.value='setalias_'+index;
7572: this.document.forms.aliasform.folderpath.value=folderpath;
7573: this.document.forms.aliasform.submit();
7574: }
7575: }
7576:
7577: function delalias(folderpath,index) {
7578: if (confirm('$js_lt{"delal"}')) {
7579: this.document.forms.aliasform.cmd.value='delalias_'+index;
7580: this.document.forms.aliasform.folderpath.value=folderpath;
7581: this.document.forms.aliasform.submit();
7582: }
7583: }
7584:
7585: ENDNEWSCRIPT
7586: } else {
7587: $jsmakefunctions = <<ENDNEWSCRIPT;
7588:
7589: function makenewfolder() {
7590: alert("$js_lt{'edri'}");
7591: }
7592:
7593: function makenewpage() {
7594: alert("$js_lt{'edri'}");
7595: }
7596:
7597: function makeexamupload() {
7598: alert("$js_lt{'edri'}");
7599: }
7600:
7601: function makesmppage() {
7602: alert("$js_lt{'edri'}");
7603: }
7604:
7605: function makewebpage(type) {
7606: alert("$js_lt{'edri'}");
7607: }
7608:
7609: function makesmpproblem() {
7610: alert("$js_lt{'edri'}");
7611: }
7612:
7613: function makedropbox() {
7614: alert("$js_lt{'edri'}");
7615: }
7616:
7617: function makebulboard() {
7618: alert("$js_lt{'edri'}");
7619: }
7620:
7621: function makeabout() {
7622: alert("$js_lt{'edri'}");
7623: }
7624:
7625: function changename() {
7626: alert("$js_lt{'edri'}");
7627: }
7628:
7629: function setalias() {
7630: alert("$js_lt{'edri'}");
7631: }
7632:
7633: function delalias() {
7634: alert("$js_lt{'edri'}");
7635: }
7636:
7637: function makenew() {
7638: alert("$js_lt{'edri'}");
7639: }
7640:
7641: function groupimport() {
7642: alert("$js_lt{'edri'}");
7643: }
7644:
7645: function groupsearch() {
7646: alert("$js_lt{'edri'}");
7647: }
7648:
7649: function groupopen(url,recover) {
7650: var options="scrollbars=1,resizable=1,menubar=0";
7651: idxflag=1;
7652: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7653: idx.focus();
7654: }
7655:
7656: ENDNEWSCRIPT
7657:
7658: }
7659: return <<ENDSCRIPT;
7660:
7661: $jsmakefunctions
7662:
7663: function toggleUpload(caller) {
7664: var blocks = Array($fieldsets);
7665: for (var i=0; i<blocks.length; i++) {
7666: var disp = 'none';
7667: if (caller == blocks[i]) {
7668: var curr = document.getElementById('upload'+caller+'form').style.display;
7669: if (curr == 'none') {
7670: disp='block';
7671: }
7672: }
7673: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
7674: }
7675: resize_scrollbox('contentscroll','1','1');
7676: return;
7677: }
7678:
7679: function toggleExternal(caller) {
7680: var blocks = Array($extfieldsets);
7681: for (var i=0; i<blocks.length; i++) {
7682: var disp = 'none';
7683: if (caller == blocks[i]) {
7684: var curr = document.getElementById('external'+caller+'form').style.display;
7685: if (curr == 'none') {
7686: disp='block';
7687: }
7688: }
7689: document.getElementById('external'+blocks[i]+'form').style.display=disp;
7690: if ((caller == 'tool') || (caller == 'supptool')) {
7691: if (disp == 'block') {
7692: if (document.getElementById('LC_exttoolid')) {
7693: var toolselector = document.getElementById('LC_exttoolid');
7694: var suppflag = 0;
7695: if (caller == 'supptool') {
7696: suppflag = 1;
7697: }
7698: currForm = document.getElementById('new'+caller);
7699: updateExttool(toolselector,currForm,suppflag);
7700: }
7701: }
7702: }
7703: }
7704: resize_scrollbox('contentscroll','1','1');
7705: return;
7706: }
7707:
7708: function toggleMap(caller) {
7709: var disp = 'none';
7710: if (document.getElementById('importmapform')) {
7711: if (caller == 'map') {
7712: var curr = document.getElementById('importmapform').style.display;
7713: if (curr == 'none') {
7714: disp='block';
7715: }
7716: }
7717: document.getElementById('importmapform').style.display=disp;
7718: resize_scrollbox('contentscroll','1','1');
7719: }
7720: return;
7721: }
7722:
7723: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7724: var disp = 'none';
7725: if (document.getElementById('crsresform')) {
7726: if (caller == 'res') {
7727: var curr = document.getElementById('crsresform').style.display;
7728: if (curr == 'none') {
7729: disp='block';
7730: numauthor = parseInt(numauthorrole);
7731: if (numauthor > 0) {
7732: document.courseresform.authorrole.selectedIndex = 0;
7733: select1priv_changed();
7734: document.courseresform.authorpath.selectedIndex = 0;
7735: document.courseresform.newresourceadd.selectedIndex = 0;
7736: toggleNewInCourse(document.courseresform);
7737: if (document.getElementById('newresource')) {
7738: document.getElementById('newresource').style.display = 'none';
7739: }
7740: } else {
7741: if (numcrsdirs) {
7742: document.courseresform.authorpath.selectedIndex = 0;
7743: }
7744: }
7745: if (document.courseresform.newresusetemp.length) {
7746: document.courseresform.newresusetemp[0].checked = true;
7747: toggleWithTemplate(document.courseresform);
7748: }
7749: document.courseresform.newresourcename.value = '';
7750: }
7751: }
7752: if (document.courseresform.newsubdir.length) {
7753: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7754: if (document.courseresform.newsubdir[j].value == 0) {
7755: document.courseresform.newsubdir[j].checked = true;
7756: }
7757: break;
7758: }
7759: if (document.getElementById('newsubdirname')) {
7760: document.getElementById('newsubdirname').type = "hidden";
7761: document.getElementById('newsubdirname').value = "";
7762: }
7763: if (document.getElementById('newsubdir')) {
7764: document.getElementById('newsubdir').innerHTML = "";
7765: }
7766: }
7767: document.getElementById('crsresform').style.display=disp;
7768: resize_scrollbox('contentscroll','1','0');
7769: }
7770: return;
7771: }
7772:
7773: function toggleNewsubdir(form) {
7774: if (form.newsubdir.length) {
7775: for (var j=0; j<form.newsubdir.length; j++) {
7776: if (form.newsubdir[j].checked) {
7777: if (document.getElementById('newsubdirname')) {
7778: if (form.newsubdir[j].value == '1') {
7779: document.getElementById('newsubdirname').type = "text";
7780: if (document.getElementById('newsubdir')) {
7781: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7782: }
7783: } else {
7784: document.getElementById('newsubdirname').type = "hidden";
7785: document.getElementById('newsubdirname').value = "";
7786: document.getElementById('newsubdir').innerHTML = "";
7787: }
7788: }
7789: break;
7790: }
7791: }
7792: }
7793: }
7794:
7795: function toggleCrsResTitle() {
7796: if (document.getElementById('newresource')) {
7797: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7798: document.getElementById('newresource').style.display = 'inline';
7799: document.courseresform.newresourceadd[0].checked = true;
7800: toggleNewInCourse(document.courseresform);
7801: } else {
7802: document.getElementById('newresource').style.display = 'none';
7803: }
7804: }
7805: }
7806:
7807: function toggleNewInCourse(form) {
7808: if (form.newresourceadd.length) {
7809: for (var i=0; i<form.newresourceadd.length; i++) {
7810: if (form.newresourceadd[i].checked) {
7811: if (document.getElementById('newresourcetitle')) {
7812: if (form.newresourceadd[i].value == '1') {
7813: document.getElementById('newresourcetitle').type = 'text';
7814: if (document.getElementById('newrestitle')) {
7815: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7816: }
7817: } else {
7818: document.getElementById('newresourcetitle').type = 'hidden';
7819: document.getElementById('newresourcetitle').value = '';
7820: if (document.getElementById('newrestitle')) {
7821: document.getElementById('newrestitle').innerHTML = '';
7822: }
7823: }
7824: }
7825: break;
7826: }
7827: }
7828: }
7829: }
7830:
7831: function toggleWithTemplate(form) {
7832: if (form.newresusetemp.length) {
7833: for (var i=0; i<form.newresusetemp.length; i++) {
7834: if (form.newresusetemp[i].checked) {
7835: if (document.getElementById('newrestemplate')) {
7836: if (form.newresusetemp[i].value == '1') {
7837: document.getElementById('newrestemplate').style.display = 'inline';
7838: toggleExampleText();
7839: } else {
7840: form.tempcategory.selectedIndex = 0;
7841: select1template_changed();
7842: document.getElementById('newrestemplate').style.display = 'none';
7843: }
7844: }
7845: }
7846: }
7847: }
7848: }
7849:
7850: function toggleExampleText() {
7851: if (document.getElementById('newresexample')) {
7852: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7853: if (url == '') {
7854: document.getElementById('newresexample').style.fontWeight = 'normal';
7855: } else {
7856: document.getElementById('newresexample').style.fontWeight = 'bold';
7857: }
7858: }
7859: }
7860:
7861: function getExample(width,height,scrolling,transparency) {
7862: var url;
7863: if (document.courseresform.newresusetemp.length) {
7864: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7865: if (document.courseresform.newresusetemp[i].checked) {
7866: if (document.courseresform.newresusetemp[i].value == '1') {
7867: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7868: if (url == '') {
7869: alert('Pick a category and template');
7870: } else {
7871: url = url.replace("$londocroot","");
7872: url += '?inhibitmenu=yes';
7873: }
7874: }
7875: break;
7876: }
7877: }
7878: }
7879: if (url != '') {
7880: openMyModal(url,width,height,scrolling,transparency,'');
7881: }
7882: }
7883:
7884: function toggleImportCrsres(caller,dircount) {
7885: var disp = 'none';
7886: if (document.getElementById('importcrsresform')) {
7887: if (caller == 'res') {
7888: var numdirs = parseInt(dircount);
7889: var curr = document.getElementById('importcrsresform').style.display;
7890: if (curr == 'none') {
7891: disp='block';
7892: if (numdirs > 1) {
7893: select1res_changed();
7894: }
7895: }
7896: }
7897: document.getElementById('importcrsresform').style.display=disp;
7898: resize_scrollbox('contentscroll','1','0');
7899: }
7900: return;
7901: }
7902:
7903: function makeims(imsform) {
7904: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
7905: alert("$js_lt{'imsfile'}");
7906: return;
7907: }
7908: if (imsform.source.selectedIndex == 0) {
7909: alert("$js_lt{'imscms'}");
7910: return;
7911: }
7912: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7913: imsform.submit();
7914: }
7915:
7916: function updatePick(targetform,index,caller) {
7917: var pickitem;
7918: var picknumitem;
7919: var picknumtext;
7920: if (index == 'all') {
7921: pickitem = document.getElementById('randompickall');
7922: picknumitem = document.getElementById('rpicknumall');
7923: picknumtext = document.getElementById('rpicktextall');
7924: } else {
7925: pickitem = document.getElementById('randompick_'+index);
7926: picknumitem = document.getElementById('rpicknum_'+index);
7927: picknumtext = document.getElementById('randompicknum_'+index);
7928: }
7929: if (pickitem.checked) {
7930: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
7931: if (picknum == '' || picknum == null) {
7932: if (caller == 'check') {
7933: pickitem.checked=false;
7934: if (index == 'all') {
7935: picknumtext.innerHTML = '';
7936: if (caller == 'link') {
7937: propagateState(targetform,'rpicknum');
7938: }
7939: } else {
7940: checkForSubmit(targetform,'randompick','settings');
7941: }
7942: }
7943: } else {
7944: picknum.toString();
7945: var regexdigit=/^\\d+\$/;
7946: if (regexdigit.test(picknum)) {
7947: picknumitem.value = picknum;
7948: if (index == 'all') {
7949: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
7950: if (caller == 'link') {
7951: propagateState(targetform,'rpicknum');
7952: }
7953: } else {
7954: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
7955: checkForSubmit(targetform,'randompick','settings');
7956: }
7957: } else {
7958: if (caller == 'check') {
7959: if (index == 'all') {
7960: picknumtext.innerHTML = '';
7961: if (caller == 'link') {
7962: propagateState(targetform,'rpicknum');
7963: }
7964: } else {
7965: pickitem.checked=false;
7966: checkForSubmit(targetform,'randompick','settings');
7967: }
7968: }
7969: return;
7970: }
7971: }
7972: } else {
7973: picknumitem.value = '';
7974: picknumtext.innerHTML = '';
7975: if (index == 'all') {
7976: if (caller == 'link') {
7977: propagateState(targetform,'rpicknum');
7978: }
7979: } else {
7980: checkForSubmit(targetform,'randompick','settings');
7981: }
7982: }
7983: }
7984:
7985: function propagateState(form,param) {
7986: if (document.getElementById(param+'all')) {
7987: var setcheck = 0;
7988: var rpick = 0;
7989: if (param == 'rpicknum') {
7990: if (document.getElementById('randompickall')) {
7991: if (document.getElementById('randompickall').checked) {
7992: if (document.getElementById('rpicknumall')) {
7993: rpick = document.getElementById('rpicknumall').value;
7994: }
7995: }
7996: }
7997: } else {
7998: if (document.getElementById(param+'all').checked) {
7999: setcheck = 1;
8000: }
8001: }
8002: var allidxlist;
8003: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8004: if (document.getElementById('all'+param+'idx')) {
8005: allidxlist = document.getElementById('all'+param+'idx').value;
8006: }
8007: var actions = new Array ('remove','cut','copy');
8008: for (var i=0; i<actions.length; i++) {
8009: if (actions[i] != param) {
8010: if (document.getElementById(actions[i]+'all')) {
8011: document.getElementById(actions[i]+'all').checked = false;
8012: }
8013: }
8014: }
8015: }
8016: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
8017: allidxlist = form.allidx.value;
8018: }
8019: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
8020: allidxlist = form.allmapidx.value;
8021: }
8022: if ((allidxlist != '') && (allidxlist != null)) {
8023: var allidxs = allidxlist.split(',');
8024: if (allidxs.length > 1) {
8025: for (var i=0; i<allidxs.length; i++) {
8026: if (document.getElementById(param+'_'+allidxs[i])) {
8027: if (param == 'rpicknum') {
8028: if (document.getElementById('randompick_'+allidxs[i])) {
8029: if (document.getElementById('randompick_'+allidxs[i]).checked) {
8030: document.getElementById(param+'_'+allidxs[i]).value = rpick;
8031: if (rpick > 0) {
8032: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
8033: } else {
8034: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8035: }
8036: }
8037: }
8038: } else {
8039: if (setcheck == 1) {
8040: document.getElementById(param+'_'+allidxs[i]).checked = true;
8041: } else {
8042: document.getElementById(param+'_'+allidxs[i]).checked = false;
8043: if (param == 'randompick') {
8044: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8045: }
8046: }
8047: }
8048: }
8049: }
8050: if (setcheck == 1) {
8051: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8052: var actions = new Array('copy','cut','remove');
8053: for (var i=0; i<actions.length; i++) {
8054: var otheractions;
8055: var otheridxs;
8056: if (actions[i] === param) {
8057: continue;
8058: } else {
8059: if (document.getElementById('all'+actions[i]+'idx')) {
8060: otheractions = document.getElementById('all'+actions[i]+'idx').value;
8061: otheridxs = otheractions.split(',');
8062: if (otheridxs.length > 1) {
8063: for (var j=0; j<otheridxs.length; j++) {
8064: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
8065: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
8066: }
8067: }
8068: }
8069: }
8070: }
8071: }
8072: }
8073: }
8074: }
8075: }
8076: }
8077: return;
8078: }
8079:
8080: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
8081: var canedit = '$canedit';
8082: if (canedit == '') {
8083: alert("$js_lt{'edri'}");
8084: return;
8085: }
8086: var dosettings;
8087: var doaction;
8088: var control = document.togglemultsettings;
8089: if (context == 'actions') {
8090: control = document.togglemultactions;
8091: doaction = 1;
8092: } else {
8093: dosettings = 1;
8094: }
8095: if (control) {
8096: if (control.showmultpick.length) {
8097: for (var i=0; i<control.showmultpick.length; i++) {
8098: if (control.showmultpick[i].checked) {
8099: if (control.showmultpick[i].value == 1) {
8100: if (context == 'settings') {
8101: dosettings = 0;
8102: } else {
8103: doaction = 0;
8104: }
8105: }
8106: }
8107: }
8108: }
8109: }
8110: if (context == 'settings') {
8111: if (dosettings == 1) {
8112: targetform.changeparms.value=param;
8113: targetform.submit();
8114: }
8115: }
8116: if (context == 'actions') {
8117: if (doaction == 1) {
8118: targetform.cmd.value=param+'_'+index;
8119: targetform.folderpath.value=folderpath;
8120: targetform.markcopy.value=idx+':'+param;
8121: targetform.copyfolder.value=folder+'.'+container;
8122: if (param == 'remove') {
8123: var doremove = 0;
8124: if (skip_confirm) {
8125: if (confirm_removal) {
8126: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8127: doremove = 1;
8128: }
8129: } else {
8130: doremove = 1;
8131: }
8132: } else {
8133: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8134: doremove = 1;
8135: }
8136: }
8137: if (doremove) {
8138: targetform.markcopy.value='';
8139: targetform.copyfolder.value='';
8140: targetform.submit();
8141: }
8142: }
8143: if (param == 'cut') {
8144: if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) {
8145: targetform.submit();
8146: return;
8147: }
8148: }
8149: if (param == 'copy') {
8150: targetform.submit();
8151: return;
8152: }
8153: targetform.markcopy.value='';
8154: targetform.copyfolder.value='';
8155: targetform.cmd.value='';
8156: targetform.folderpath.value='';
8157: return;
8158: } else {
8159: if (document.getElementById(param+'_'+idx)) {
8160: item = document.getElementById(param+'_'+idx);
8161: if (item.type == 'checkbox') {
8162: if (item.checked) {
8163: item.checked = false;
8164: } else {
8165: item.checked = true;
8166: singleCheck(item,idx,param);
8167: }
8168: }
8169: }
8170: }
8171: }
8172: return;
8173: }
8174:
8175: function singleCheck(caller,idx,action) {
8176: actions = new Array('cut','copy','remove');
8177: if (caller.checked) {
8178: for (var i=0; i<actions.length; i++) {
8179: if (actions[i] != action) {
8180: if (document.getElementById(actions[i]+'_'+idx)) {
8181: if (document.getElementById(actions[i]+'_'+idx).checked) {
8182: document.getElementById(actions[i]+'_'+idx).checked = false;
8183: }
8184: }
8185: }
8186: }
8187: }
8188: return;
8189: }
8190:
8191: function unselectInactive(nav) {
8192: currentNav = document.getElementById(nav);
8193: currentLis = currentNav.getElementsByTagName('LI');
8194: for (i = 0; i < currentLis.length; i++) {
8195: if (currentLis[i].className == 'goback') {
8196: currentLis[i].className = 'goback';
8197: } else {
8198: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
8199: currentLis[i].className = 'right';
8200: } else {
8201: currentLis[i].className = 'i';
8202: }
8203: }
8204: }
8205: }
8206:
8207: function hideAll(current, nav, data) {
8208: unselectInactive(nav);
8209: if (current) {
8210: if (current.className == 'right'){
8211: current.className = 'right active'
8212: } else {
8213: current.className = 'active';
8214: }
8215: }
8216: currentData = document.getElementById(data);
8217: currentDivs = currentData.getElementsByTagName('DIV');
8218: for (i = 0; i < currentDivs.length; i++) {
8219: if(currentDivs[i].className == 'LC_ContentBox'){
8220: currentDivs[i].style.display = 'none';
8221: }
8222: }
8223: }
8224:
8225: function openTabs(pageId) {
8226: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
8227: if(tabnav.length > 2 ){
8228: currentNav = document.getElementById(tabnav[1].id);
8229: currentLis = currentNav.getElementsByTagName('LI');
8230: for(i = 0; i< currentLis.length; i++){
8231: if(currentLis[i].className == 'active') {
8232: funcString = currentLis[i].onclick.toString();
8233: tab = funcString.split('"');
8234: if(tab.length < 2) {
8235: tab = funcString.split("'");
8236: }
8237: currentData = document.getElementById(tab[1]);
8238: currentData.style.display = 'block';
8239: }
8240: }
8241: }
8242: }
8243:
8244: function showPage(current, pageId, nav, data) {
8245: currstate = current.className;
8246: hideAll(current, nav, data);
8247: openTabs(pageId);
8248: unselectInactive(nav);
8249: if ((currstate == 'active') || (currstate == 'right active')) {
8250: if (currstate == 'active') {
8251: current.className = '';
8252: } else {
8253: current.className = 'right';
8254: }
8255: activeTab = '';
8256: toggleExternal();
8257: toggleUpload();
8258: toggleMap();
8259: toggleCrsRes();
8260: toggleImportCrsres();
8261: resize_scrollbox('contentscroll','1','0');
8262: return;
8263: } else {
8264: current.className = 'active';
8265: }
8266: currentData = document.getElementById(pageId);
8267: currentData.style.display = 'block';
8268: activeTab = pageId;
8269: toggleExternal();
8270: toggleUpload();
8271: toggleMap();
8272: toggleCrsRes();
8273: toggleImportCrsres();
8274: if (nav == 'mainnav') {
8275: var storedpath = "$docs_folderpath";
8276: var storedpage = "$main_container_page";
8277: var reg = new RegExp("^supplemental");
8278: if (pageId == 'mainCourseDocuments') {
8279: if (storedpage == 1) {
8280: document.simpleedit.folderpath.value = '';
8281: document.uploaddocument.folderpath.value = '';
8282: } else {
8283: if (reg.test(storedpath)) {
8284: document.simpleedit.folderpath.value = '$toplevelmain';
8285: document.uploaddocument.folderpath.value = '$toplevelmain';
8286: document.newext.folderpath.value = '$toplevelmain';
8287: } else {
8288: document.simpleedit.folderpath.value = storedpath;
8289: document.uploaddocument.folderpath.value = storedpath;
8290: document.newext.folderpath.value = storedpath;
8291: }
8292: }
8293: } else {
8294: if (reg.test(storedpath)) {
8295: document.simpleedit.folderpath.value = storedpath;
8296: document.supuploaddocument.folderpath.value = storedpath;
8297: document.supnewext.folderpath.value = storedpath;
8298: } else {
8299: document.simpleedit.folderpath.value = '$toplevelsupp';
8300: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8301: document.supnewext.folderpath.value = '$toplevelsupp';
8302: }
8303: }
8304: }
8305: resize_scrollbox('contentscroll','1','0');
8306: return false;
8307: }
8308:
8309: function toContents(jumpto) {
8310: var newurl = '$backtourl';
8311: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
8312: newurl = newurl+'?postdata='+jumpto;
8313: }
8314: location.href=newurl;
8315: }
8316:
8317: function togglePick(caller,value) {
8318: var disp = 'none';
8319: if (document.getElementById('multi'+caller)) {
8320: var curr = document.getElementById('multi'+caller).style.display;
8321: if (value == 1) {
8322: disp='block';
8323: }
8324: if (curr == disp) {
8325: return;
8326: }
8327: document.getElementById('multi'+caller).style.display=disp;
8328: if (value == 1) {
8329: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
8330: } else {
8331: document.getElementById('more'+caller).innerHTML = '';
8332: }
8333: if (caller == 'actions') {
8334: setClass(value);
8335: setBoxes(value);
8336: }
8337: }
8338: var showButton = multiSettings();
8339: if (showButton != 1) {
8340: showButton = multiActions();
8341: }
8342: if (document.getElementById('multisave')) {
8343: if (showButton == 1) {
8344: document.getElementById('multisave').style.display='block';
8345: } else {
8346: document.getElementById('multisave').style.display='none';
8347: }
8348: }
8349: resize_scrollbox('contentscroll','1','1');
8350: return;
8351: }
8352:
8353: function toggleCheckUncheck(caller,more) {
8354: if (more == 1) {
8355: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
8356: document.getElementById('allfields'+caller).style.display='block';
8357: } else {
8358: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
8359: document.getElementById('allfields'+caller).style.display='none';
8360: }
8361: resize_scrollbox('contentscroll','1','1');
8362: }
8363:
8364: function multiSettings() {
8365: var inuse = 0;
8366: var settingsform = document.togglemultsettings;
8367: if (settingsform.showmultpick.length > 1) {
8368: for (var i=0; i<settingsform.showmultpick.length; i++) {
8369: if (settingsform.showmultpick[i].checked) {
8370: if (settingsform.showmultpick[i].value == 1) {
8371: inuse = 1;
8372: }
8373: }
8374: }
8375: }
8376: return inuse;
8377: }
8378:
8379: function multiActions() {
8380: var inuse = 0;
8381: var actionsform = document.togglemultactions;
8382: if (actionsform.showmultpick.length > 1) {
8383: for (var i=0; i<actionsform.showmultpick.length; i++) {
8384: if (actionsform.showmultpick[i].checked) {
8385: if (actionsform.showmultpick[i].value == 1) {
8386: inuse = 1;
8387: }
8388: }
8389: }
8390: }
8391: return inuse;
8392: }
8393:
8394: function checkSubmits() {
8395: var numchanges = 0;
8396: var form = document.saveactions;
8397: var doactions = multiActions();
8398: var cutwarnings = 0;
8399: var remwarnings = 0;
8400: var removalinfo = 0;
8401: if (doactions == 1) {
8402: var remidxlist = document.cumulativeactions.allremoveidx.value;
8403: if ((remidxlist != '') && (remidxlist != null)) {
8404: var remidxs = remidxlist.split(',');
8405: for (var i=0; i<remidxs.length; i++) {
8406: if (document.getElementById('remove_'+remidxs[i])) {
8407: if (document.getElementById('remove_'+remidxs[i]).checked) {
8408: form.multiremove.value += remidxs[i]+',';
8409: numchanges ++;
8410: if (document.getElementById('skip_remove_'+remidxs[i])) {
8411: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8412: remwarnings ++;
8413: }
8414: }
8415: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8416: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8417: removalinfo ++;
8418: }
8419: }
8420: }
8421: }
8422: }
8423: }
8424: var cutidxlist = document.cumulativeactions.allcutidx.value;
8425: if ((cutidxlist != '') && (cutidxlist != null)) {
8426: var cutidxs = cutidxlist.split(',');
8427: for (var i=0; i<cutidxs.length; i++) {
8428: if (document.getElementById('cut_'+cutidxs[i])) {
8429: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8430: form.multicut.value += cutidxs[i]+',';
8431: numchanges ++;
8432: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8433: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8434: cutwarnings ++;
8435: }
8436: }
8437: }
8438: }
8439: }
8440: }
8441: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8442: if ((copyidxlist != '') && (copyidxlist != null)) {
8443: var copyidxs = copyidxlist.split(',');
8444: for (var i=0; i<copyidxs.length; i++) {
8445: if (document.getElementById('copy_'+copyidxs[i])) {
8446: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8447: form.multicopy.value += copyidxs[i]+',';
8448: numchanges ++;
8449: }
8450: }
8451: }
8452: }
8453: if (numchanges > 0) {
8454: form.multichange.value = numchanges;
8455: }
8456: }
8457: var dosettings = multiSettings();
8458: var haschanges = 0;
8459: if (dosettings == 1) {
8460: form.allencrypturl.value = '';
8461: form.allhiddenresource.value = '';
8462: form.changeparms.value = 'all';
8463: var patt=new RegExp(",\$");
8464: var allidxlist = document.cumulativesettings.allidx.value;
8465: if ((allidxlist != '') && (allidxlist != null)) {
8466: var allidxs = allidxlist.split(',');
8467: if (allidxs.length > 1) {
8468: for (var i=0; i<allidxs.length; i++) {
8469: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8470: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8471: form.allhiddenresource.value += allidxs[i]+',';
8472: }
8473: }
8474: if (document.getElementById('encrypturl_'+allidxs[i])) {
8475: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8476: form.allencrypturl.value += allidxs[i]+',';
8477: }
8478: }
8479: }
8480: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8481: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
8482: }
8483: }
8484: form.allrandompick.value = '';
8485: form.allrandomorder.value = '';
8486: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8487: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8488: var allmapidxs = allmapidxlist.split(',');
8489: for (var i=0; i<allmapidxs.length; i++) {
8490: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8491: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8492: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8493: if ((randompick.checked) && (rpicknum.value != '')) {
8494: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8495: }
8496: if (randorder.checked) {
8497: form.allrandomorder.value += allmapidxs[i]+',';
8498: }
8499: }
8500: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8501: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8502: }
8503: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8504: haschanges = 1;
8505: }
8506: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8507: haschanges = 1;
8508: }
8509: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8510: haschanges = 1;
8511: }
8512: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8513: haschanges = 1;
8514: }
8515: }
8516: if (doactions == 1) {
8517: if (numchanges > 0) {
8518: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
8519: if (remwarnings > 0) {
8520: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
8521: return false;
8522: }
8523: }
8524: if (removalinfo > 0) {
8525: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8526: return false;
8527: }
8528: }
8529: if (cutwarnings > 0) {
8530: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
8531: return false;
8532: }
8533: }
8534: }
8535: form.submit();
8536: return true;
8537: }
8538: }
8539: if (dosettings == 1) {
8540: if (haschanges == 1) {
8541: form.submit();
8542: return true;
8543: }
8544: }
8545: if ((dosettings == 1) && (doactions == 1)) {
8546: alert("$js_lt{'noor'}");
8547: } else {
8548: if (dosettings == 1) {
8549: alert("$js_lt{'noch'}");
8550: } else {
8551: alert("$js_lt{'noac'}");
8552: }
8553: }
8554: return false;
8555: }
8556:
8557: function setClass(value) {
8558: var cutclass = 'LC_docs_cut';
8559: var copyclass = 'LC_docs_copy';
8560: var removeclass = 'LC_docs_remove';
8561: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8562: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8563: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8564: var links = document.getElementsByTagName('a');
8565: for (var i=0; i<links.length; i++) {
8566: var classes = links[i].className;
8567: if (cutreg.test(classes)) {
8568: links[i].className = cutclass;
8569: if (value == 1) {
8570: links[i].className += " LC_menubuttons_link";
8571: }
8572: } else {
8573: if (copyreg.test(classes)) {
8574: links[i].className = copyclass;
8575: if (value == 1) {
8576: links[i].className += " LC_menubuttons_link";
8577: }
8578: } else {
8579: if (removereg.test(classes)) {
8580: links[i].className = removeclass;
8581: if (value == 1) {
8582: links[i].className += " LC_menubuttons_link";
8583: }
8584: }
8585: }
8586: }
8587: }
8588: return;
8589: }
8590:
8591: function setBoxes(value) {
8592: var remidxlist = document.cumulativeactions.allremoveidx.value;
8593: if ((remidxlist != '') && (remidxlist != null)) {
8594: var remidxs = remidxlist.split(',');
8595: for (var i=0; i<remidxs.length; i++) {
8596: if (document.getElementById('remove_'+remidxs[i])) {
8597: var item = document.getElementById('remove_'+remidxs[i]);
8598: if (value == 1) {
8599: item.className = 'LC_docs_remove';
8600: } else {
8601: item.className = 'LC_hidden';
8602: }
8603: }
8604: }
8605: }
8606: var cutidxlist = document.cumulativeactions.allcutidx.value;
8607: if ((cutidxlist != '') && (cutidxlist != null)) {
8608: var cutidxs = cutidxlist.split(',');
8609: for (var i=0; i<cutidxs.length; i++) {
8610: if (document.getElementById('cut_'+cutidxs[i])) {
8611: var item = document.getElementById('cut_'+cutidxs[i]);
8612: if (value == 1) {
8613: item.className = 'LC_docs_cut';
8614: } else {
8615: item.className = 'LC_hidden';
8616: }
8617: }
8618: }
8619: }
8620: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8621: if ((copyidxlist != '') && (copyidxlist != null)) {
8622: var copyidxs = copyidxlist.split(',');
8623: for (var i=0; i<copyidxs.length; i++) {
8624: if (document.getElementById('copy_'+copyidxs[i])) {
8625: var item = document.getElementById('copy_'+copyidxs[i]);
8626: if (value == 1) {
8627: item.className = 'LC_docs_copy';
8628: } else {
8629: item.className = 'LC_hidden';
8630: }
8631: }
8632: }
8633: }
8634: return;
8635: }
8636:
8637: function validImportCrsRes() {
8638: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8639: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8640: if ((fname == '') || (fname == null)) {
8641: alert("$js_lt{'nofi'}");
8642: return false;
8643: }
8644: var url = '/res/$coursedom/$coursenum/';
8645: if (path && path != '/') {
8646: url += path+'/';
8647: }
8648: if (fname != '') {
8649: url += fname;
8650: }
8651: var title = document.crsresimportform.crsrestitle.value;
8652: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
8653: return true;
8654: }
8655:
8656: function validateNewRes(caller) {
8657: if (caller == 'single') {
8658: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8659: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8660: var resname = document.courseresform.newresourcename.value;
8661: }
8662: }
8663:
8664: ENDSCRIPT
8665: }
8666:
8667: sub history_tab_js {
8668: return <<"ENDHIST";
8669: function toggleHistoryDisp(choice) {
8670: document.docslogform.docslog.value = choice;
8671: document.docslogform.submit();
8672: return;
8673: }
8674:
8675: ENDHIST
8676: }
8677:
8678: sub inject_data_js {
8679: return <<ENDINJECT;
8680:
8681: function injectData(current, hiddenField, name, value) {
8682: currentElement = document.getElementById(hiddenField);
8683: currentElement.name = name;
8684: currentElement.value = value;
8685: current.submit();
8686: }
8687:
8688: ENDINJECT
8689: }
8690:
8691: sub dump_switchserver_js {
8692: my @hosts = @_;
8693: my %js_lt = &Apache::lonlocal::texthash(
8694: dump => 'Copying content to Authoring Space requires switching server.',
8695: swit => 'Switch server?',
8696: );
8697: my %html_js_lt = &Apache::lonlocal::texthash(
8698: swit => 'Switch server?',
8699: duco => 'Copying Content to Authoring Space',
8700: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8701: chos => 'Choose server',
8702: );
8703: &js_escape(\%js_lt);
8704: &html_escape(\%html_js_lt);
8705: &js_escape(\%html_js_lt);
8706: my $role = $env{'request.role'};
8707: my $js = <<"ENDSWJS";
8708: <script type="text/javascript">
8709: function write_switchserver() {
8710: var server;
8711: if (document.setserver.posshosts.length > 0) {
8712: for (var i=0; i<document.setserver.posshosts.length; i++) {
8713: if (document.setserver.posshosts[i].checked) {
8714: server = document.setserver.posshosts[i].value;
8715: }
8716: }
8717: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8718: }
8719: window.close();
8720: }
8721: </script>
8722:
8723: ENDSWJS
8724:
8725: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8726: {'only_body' => 1,
8727: 'js_ready' => 1,});
8728: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8729:
8730: my $hostpicker;
8731: my $count = 0;
8732: foreach my $host (sort(@hosts)) {
8733: my $checked;
8734: if ($count == 0) {
8735: $checked = ' checked="checked"';
8736: }
8737: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8738: $host.'"'.$checked.' />'.$host.'</label> ';
8739: $count++;
8740: }
8741:
8742: return <<"ENDSWITCHJS";
8743:
8744: function dump_needs_switchserver(url) {
8745: if (url!='' && url!= null) {
8746: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
8747: go(url);
8748: }
8749: }
8750: return;
8751: }
8752:
8753: function choose_switchserver_window() {
8754: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8755: newWindow.document.open();
8756: newWindow.document.writeln('$startpage');
8757: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8758: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8759: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
8760: '<form name="setserver" method="post" action="" \\/>\\n'+
8761: '$hostpicker\\n'+
8762: '<br \\/><br \\/>\\n'+
8763: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
8764: 'onclick="write_switchserver();" \\/>\\n'+
8765: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8766: newWindow.document.writeln('$endpage');
8767: newWindow.document.close();
8768: newWindow.focus();
8769: }
8770:
8771: ENDSWITCHJS
8772: }
8773:
8774: sub makedocslogform {
8775: my ($formelems,$docslog) = @_;
8776: return <<"LOGSFORM";
8777: <form action="/adm/coursedocs" method="post" name="docslogform">
8778: <input type="hidden" name="docslog" value="$docslog" />
8779: $formelems
8780: </form>
8781: LOGSFORM
8782: }
8783:
8784: sub makesimpleeditform {
8785: my ($formelems) = @_;
8786: return <<"SIMPFORM";
8787: <form name="simpleedit" method="post" action="/adm/coursedocs">
8788: <input type="hidden" name="importdetail" value="" />
8789: $formelems
8790: </form>
8791: SIMPFORM
8792: }
8793:
8794: sub makenewproblem {
8795: my ($r,$coursedom,$coursenum) = @_;
8796: # Creating a new problem
8797: my ($redirect,$error);
8798: if ($env{'form.authorrole'}) {
8799: my ($newsubdir,$filename);
8800: if ($env{'form.newsubdir'}) {
8801: if ($env{'form.newsubdirname'} ne '') {
8802: $newsubdir = $env{'form.newsubdirname'};
8803: }
8804: }
8805: if ($env{'form.newresourcename'}) {
8806: $filename = $env{'form.newresourcename'};
8807: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8808: $filename =~ s/`//g;
8809: $filename =~ s{/\.\./}{_}g;
8810: $filename =~ s/\.+/./g;
8811: $filename =~ s{/+}{_}g;
8812: if ($filename ne '') {
8813: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8814: if (($ext) && ($ext ne '.problem')) {
8815: $filename = $name.'.problem';
8816: } elsif ($ext eq '') {
8817: $filename .= '.problem';
8818: }
8819: my $docroot = $r->dir_config('lonDocRoot');
8820: my @ids=&Apache::lonnet::current_machine_ids();
8821: if ($env{'form.authorrole'} eq 'author') {
8822: if ($env{'user.author'}) {
8823: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8824: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8825: my $path = $docroot.$url;
8826: my $subdir = $env{'form.authorpath'};
8827: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8828: }
8829: }
8830: } elsif ($env{'form.authorrole'} eq 'course') {
8831: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8832: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8833: my $url = "/priv/$coursedom/$coursenum";
8834: my $path=$docroot.$url;
8835: my $subdir = $env{'form.authorpath'};
8836: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8837: if ($redirect) {
8838: my $rightsfile = 'default.rights';
8839: my $sourcerights = "$path/$rightsfile";
8840: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8841: my $now = time;
8842: if (!-e $sourcerights) {
8843: my $cid = $coursedom.'_'.$coursenum;
8844: if (open(my $fh,">$sourcerights")) {
8845: print $fh <<END;
8846: <accessrule effect="deny" realm="" type="course" role="" />
8847: <accessrule effect="allow" realm="$cid" type="course" role="" />
8848: END
8849: close($fh);
8850: }
8851: }
8852: if (!-e "$sourcerights.meta") {
8853: if (open(my $fh,">$sourcerights.meta")) {
8854: my $author=$env{'environment.firstname'}.' '.
8855: $env{'environment.middlename'}.' '.
8856: $env{'environment.lastname'}.' '.
8857: $env{'environment.generation'};
8858: $author =~ s/\s+$//;
8859: print $fh <<"END";
8860:
8861: <abstract></abstract>
8862: <author>$author</author>
8863: <authorspace>$coursenum:$coursedom</authorspace>
8864: <copyright>private</copyright>
8865: <creationdate>$now</creationdate>
8866: <customdistributionfile></customdistributionfile>
8867: <dependencies></dependencies>
8868: <domain>$coursedom</domain>
8869: <highestgradelevel>0</highestgradelevel>
8870: <keywords></keywords>
8871: <language>notset </language>
8872: <lastrevisiondate>$now</lastrevisiondate>
8873: <lowestgradelevel>0</lowestgradelevel>
8874: <mime>rights</mime>
8875: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8876: <notes></notes>
8877: <obsolete></obsolete>
8878: <obsoletereplacement></obsoletereplacement>
8879: <owner>$coursenum:$coursedom</owner>
8880: <rule>deny:::course,allow:$cid::course</rule>
8881: <sourceavail></sourceavail>
8882: <standards></standards>
8883: <subject></subject>
8884: <title></title>
8885: END
8886: close($fh);
8887: }
8888: }
8889: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8890: if (!-e "$docroot/res/$coursedom") {
8891: mkdir("$docroot/res/$coursedom",0755);
8892: }
8893: if (!-e "$docroot/res/$coursedom/$coursenum") {
8894: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8895: }
8896: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8897: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8898: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8899: }
8900: }
8901: my $source = $docroot.$redirect;
8902: if (!-e "$source.meta") {
8903: my $cid = $coursedom.'_'.$coursenum;
8904: my $now = time;
8905: if (open(my $fh,">$source.meta")) {
8906: my $author=$env{'environment.firstname'}.' '.
8907: $env{'environment.middlename'}.' '.
8908: $env{'environment.lastname'}.' '.
8909: $env{'environment.generation'};
8910: $author =~ s/\s+$//;
8911: my $title = $env{'form.newresourcetitle'};
8912: $title =~ s/^\s+|\s+$//g;
8913: print $fh <<END;
8914:
8915: <abstract></abstract>
8916: <author>$author</author>
8917: <authorspace>$coursenum:$coursedom</authorspace>
8918: <copyright>custom</copyright>
8919: <creationdate>$now</creationdate>
8920: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8921: <dependencies></dependencies>
8922: <domain>$coursedom</domain>
8923: <highestgradelevel>0</highestgradelevel>
8924: <keywords></keywords>
8925: <language>notset </language>
8926: <lastrevisiondate>$now</lastrevisiondate>
8927: <lowestgradelevel>0</lowestgradelevel>
8928: <mime>problem</mime>
8929: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8930: <notes></notes>
8931: <obsolete></obsolete>
8932: <obsoletereplacement></obsoletereplacement>
8933: <owner>$coursenum:$coursedom</owner>
8934: <sourceavail></sourceavail>
8935: <standards></standards>
8936: <subject></subject>
8937: <title>$title</title>
8938: END
8939: close($fh);
8940: }
8941: }
8942: }
8943: }
8944: } else {
8945: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8946: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8947: if (grep(/^\Q$rolehome\E$/,@ids)) {
8948: my $now = time;
8949: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8950: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8951: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8952: my $url = "/priv/$audom/$auname";
8953: my $path = $r->dir_config('lonDocRoot').$url;
8954: my $subdir = $env{'form.authorpath'};
8955: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8956: }
8957: }
8958: }
8959: }
8960: }
8961: }
8962: }
8963: return ($redirect,$error);
8964: }
8965:
8966: sub finishnewprob {
8967: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
8968: unless (-d $path) {
8969: unless (mkdir($path,02770)) {
8970: return;
8971: }
8972: }
8973: my $redirect;
8974: if ($subdir ne '/') {
8975: $subdir = &cleandir($subdir);
8976: if (($subdir ne '') && (-d "$path/$subdir")) {
8977: $path .= "/$subdir";
8978: $url .= "/$subdir";
8979: }
8980: }
8981: my $dest;
8982: if ($newsubdir ne '') {
8983: $newsubdir = &cleandir($newsubdir);
8984: }
8985: if ($newsubdir ne '') {
8986: if (-d "$path/$newsubdir") {
8987: $dest = "$path/$newsubdir/$filename";
8988: } else {
8989: my $dirok;
8990: unless (-e "$path/$newsubdir") {
8991: if (mkdir("$path/$newsubdir",02770)) {
8992: if (chmod(02770,"$path/$newsubdir")) {
8993: $dirok = 1;
8994: }
8995: }
8996: }
8997: if ($dirok) {
8998: $dest = "$path/$newsubdir/$filename";
8999: }
9000: }
9001: if (($dest ne '') && (!-e $dest)) {
9002: $redirect = "$url/$newsubdir/$filename";
9003: }
9004: } else {
9005: $dest = "$path/$filename";
9006: if (($dest ne '') && (!-e $dest)) {
9007: $redirect = "$url/$filename";
9008: }
9009: }
9010: if ((!-e $dest) && ($context ne 'upload')) {
9011: my $template = $env{'form.template'};
9012: my $copyfrom;
9013: if ($template ne '') {
9014: my %templates;
9015: my @files = &Apache::lonhomework::get_template_list('problem');
9016: foreach my $poss (@files) {
9017: if (ref($poss) eq 'ARRAY') {
9018: if ($template eq $poss->[0]) {
9019: $templates{$template} = 1;
9020: last;
9021: }
9022: }
9023: }
9024: if ($templates{$template}) {
9025: $copyfrom = $template;
9026: }
9027: }
9028: if ($filename =~ /\.problem$/) {
9029: unless ($copyfrom) {
9030: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
9031: }
9032: &File::Copy::copy($copyfrom,$dest);
9033: }
9034: }
9035: return $redirect;
9036: }
9037:
9038: sub cleandir {
9039: my ($dir) = @_;
9040: $dir =~ s/^\s+//;
9041: $dir =~ s/\s+$//;
9042: $dir =~ s/\.+//g;
9043: $dir =~ s/[\#\?&%\":]//g;
9044: return $dir;
9045: }
9046:
9047: 1;
9048: __END__
9049:
9050:
9051: =head1 NAME
9052:
9053: Apache::londocs.pm
9054:
9055: =head1 SYNOPSIS
9056:
9057: This is part of the LearningOnline Network with CAPA project
9058: described at http://www.lon-capa.org.
9059:
9060: =head1 SUBROUTINES
9061:
9062: =over
9063:
9064: =item %help=()
9065:
9066: Available help topics
9067:
9068: =item mapread()
9069:
9070: Mapread read maps into LONCAPA::map:: global arrays
9071: @order and @resources, determines status
9072: sets @order - pointer to resources in right order
9073: sets @resources - array with the resources with correct idx
9074:
9075: =item authorhosts()
9076:
9077: Return hash with valid author names
9078:
9079: =item clean()
9080:
9081: =item dumpcourse()
9082:
9083: Actually dump course
9084:
9085: =item group_import()
9086:
9087: Imports the given (name, url) resources into the course
9088: coursenum, coursedom, and folder must precede the list
9089:
9090: =item breadcrumbs()
9091:
9092: =item log_docs()
9093:
9094: =item docs_change_log()
9095:
9096: =item update_paste_buffer()
9097:
9098: =item print_paste_buffer()
9099:
9100: =item do_paste_from_buffer()
9101:
9102: =item do_buffer_empty()
9103:
9104: =item clear_from_buffer()
9105:
9106: =item get_newmap_url()
9107:
9108: =item dbcopy()
9109:
9110: =item uniqueness_check()
9111:
9112: =item contained_map_check()
9113:
9114: =item url_paste_fixups()
9115:
9116: =item apply_fixups()
9117:
9118: =item copy_dependencies()
9119:
9120: =item update_parameter()
9121:
9122: =item handle_edit_cmd()
9123:
9124: =item editor()
9125:
9126: =item process_file_upload()
9127:
9128: =item process_secondary_uploads()
9129:
9130: =item is_supplemental_title()
9131:
9132: =item entryline()
9133:
9134: =item tiehash()
9135:
9136: =item untiehash()
9137:
9138: =item checkonthis()
9139:
9140: check on this
9141:
9142: =item verifycontent()
9143:
9144: Verify Content
9145:
9146: =item devalidateversioncache()
9147:
9148: =item checkversions()
9149:
9150: Check Versions
9151:
9152: =item mark_hash_old()
9153:
9154: =item is_hash_old()
9155:
9156: =item changewarning()
9157:
9158: =item init_breadcrumbs()
9159:
9160: Breadcrumbs for special functions
9161:
9162: =item create_list_elements()
9163:
9164: =item create_form_ul()
9165:
9166: =item startContentScreen()
9167:
9168: =item endContentScreen()
9169:
9170: =item supplemental_base()
9171:
9172: =item embedded_form_elems()
9173:
9174: =item embedded_destination()
9175:
9176: =item return_to_editor()
9177:
9178: =item decompression_info()
9179:
9180: =item decompression_phase_one()
9181:
9182: =item decompression_phase_two()
9183:
9184: =item remove_archive()
9185:
9186: =item generate_admin_menu()
9187:
9188: =item generate_edit_table()
9189:
9190: =item editing_js()
9191:
9192: =item history_tab_js()
9193:
9194: =item inject_data_js()
9195:
9196: =item dump_switchserver_js()
9197:
9198: =item resize_scrollbox_js()
9199:
9200: =item makedocslogform()
9201:
9202: =item makesimpleeditform()
9203:
9204: =back
9205:
9206: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>