File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.704:
download - view:
text,
annotated -
select for diffs
Thu Jul 20 22:12:39 2023 UTC (13 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- External Tool instances can be copied between courses in the same domain
via the Course Editor Clipboard. For tools defined within a course, the
tool definition (including tool and secret) will be copied to the new course,
as long as the session-hosting server belongs to the course's homeserver
institution.
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.704 2023/07/20 22:12:39 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::loncourserespicker();
49: use HTML::Entities;
50: use HTML::TokeParser;
51: use GDBM_File;
52: use File::MMagic;
53: use File::Copy;
54: use Apache::lonlocal;
55: use Cwd;
56: use UUID::Tiny ':std';
57: use LONCAPA qw(:DEFAULT :match);
58:
59: my $iconpath;
60:
61: my %hash;
62:
63: my $hashtied;
64: my %alreadyseen=();
65:
66: my $hadchanges;
67: my $suppchanges;
68:
69:
70: my %help=();
71:
72:
73: sub mapread {
74: my ($coursenum,$coursedom,$map)=@_;
75: return
76: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
77: $map);
78: }
79:
80: sub storemap {
81: my ($coursenum,$coursedom,$map,$contentchg)=@_;
82: my $report;
83: if (($contentchg) && ($map =~ /^default/)) {
84: $report = 1;
85: }
86: my ($outtext,$errtext)=
87: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
88: $map,1,$report);
89: if ($errtext) { return ($errtext,2); }
90:
91: if ($map =~ /^default/) {
92: $hadchanges=1;
93: } elsif ($contentchg) {
94: $suppchanges=1;
95: }
96: return ($errtext,0);
97: }
98:
99:
100:
101: sub authorhosts {
102: my %outhash=();
103: my $home=0;
104: my $other=0;
105: foreach my $key (keys(%env)) {
106: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
107: my $role=$1;
108: my $realm=$2;
109: my ($start,$end)=split(/\./,$env{$key});
110: if (($start) && ($start>time)) { next; }
111: if (($end) && (time>$end)) { next; }
112: my ($ca,$cd);
113: if ($1 eq 'au') {
114: $ca=$env{'user.name'};
115: $cd=$env{'user.domain'};
116: } else {
117: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
118: }
119: my $allowed=0;
120: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
121: my @ids=&Apache::lonnet::current_machine_ids();
122: foreach my $id (@ids) {
123: if ($id eq $myhome) {
124: $allowed=1;
125: last;
126: }
127: }
128: if ($allowed) {
129: $home++;
130: $outhash{'home_'.$ca.':'.$cd}=1;
131: } else {
132: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
133: $other++;
134: }
135: }
136: }
137: return ($home,$other,%outhash);
138: }
139:
140:
141: sub clean {
142: my ($title)=@_;
143: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
144: return $title;
145: }
146:
147: sub default_folderpath {
148: my ($coursenum,$coursedom,$navmapref) = @_;
149: return unless ($coursenum && $coursedom && ref($navmapref));
150: # Check if entire course is hidden and/or encrypted
151: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
152: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
153: unless (ref($$navmapref)) {
154: $$navmapref = Apache::lonnavmaps::navmap->new();
155: }
156: if (ref($$navmapref)) {
157: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
158: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
159: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
160: unless (@resources) {
161: $hiddenmap = 1;
162: unless ($env{'request.role.adv'}) {
163: $hiddentop = 1;
164: if ($env{'form.folder'}) {
165: undef($env{'form.folder'});
166: }
167: }
168: }
169: }
170: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
171: $encryptmap = 1;
172: }
173: }
174: unless ($hiddentop) {
175: $folderpath='default&'.&escape(&mt('Main Content')).
176: '::'.$hiddenmap.':'.$encryptmap.'::';
177: }
178: if (wantarray) {
179: return ($folderpath,$hiddentop);
180: } else {
181: return $folderpath;
182: }
183: }
184:
185: sub validate_supppath {
186: my ($coursenum,$coursedom) = @_;
187: my $backto;
188: if ($env{'form.supppath'} ne '') {
189: my @items = split(/\&/,$env{'form.supppath'});
190: my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
191: for (my $i=0; $i<@items; $i++) {
192: my $odd = $i%2;
193: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
194: $badpath = 1;
195: last;
196: } elsif ($odd) {
197: my $suffix;
198: my $idx = $i-1;
199: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
200: $backto .= '&'.$1;
201: } elsif ($items[$idx] eq 'supplemental') {
202: $backto .= '&'.$items[$i];
203: } else {
204: $backto .= '&'.$items[$i];
205: my $is_hidden;
206: unless ($got_supp) {
207: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
208: if (ref($supplemental) eq 'HASH') {
209: if (ref($supplemental->{'hidden'}) eq 'HASH') {
210: %supphidden = %{$supplemental->{'hidden'}};
211: }
212: if (ref($supplemental->{'ids'}) eq 'HASH') {
213: %suppids = %{$supplemental->{'ids'}};
214: }
215: }
216: $got_supp = 1;
217: }
218: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
219: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
220: if ($supphidden{$mapid}) {
221: $is_hidden = 1;
222: }
223: }
224: $suffix = '::'.$is_hidden.':::';
225: }
226: $supppath .= '&'.$items[$i].$suffix;
227: } else {
228: $supppath .= '&'.$items[$i];
229: $backto .= '&'.$items[$i];
230: }
231: }
232: if ($badpath) {
233: delete($env{'form.supppath'});
234: } else {
235: $supppath =~ s/^\&//;
236: $backto =~ s/^\&//;
237: $env{'form.supppath'} = $supppath;
238: }
239: }
240: return $backto;
241: }
242:
243: sub dumpcourse {
244: my ($r) = @_;
245: my $crstype = &Apache::loncommon::course_type();
246: my ($starthash,$js);
247: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
248: $js = <<"ENDJS";
249: <script type="text/javascript">
250: // <![CDATA[
251:
252: function hide_searching() {
253: if (document.getElementById('searching')) {
254: document.getElementById('searching').style.display = 'none';
255: }
256: return;
257: }
258:
259: // ]]>
260: </script>
261: ENDJS
262: $starthash = {
263: add_entries => {'onload' => "hide_searching();"},
264: };
265: }
266: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
267: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
268: $r->print(&startContentScreen('tools'));
269: my ($home,$other,%outhash)=&authorhosts();
270: unless ($home) {
271: $r->print(&endContentScreen());
272: return '';
273: }
274: my $origcrsid=$env{'request.course.id'};
275: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
276: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
277: # Do the dumping
278: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
279: $r->print(&endContentScreen());
280: return '';
281: }
282: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
283: $r->print('<h3>'.&mt('Copying Files').'</h3>');
284: my $title=$env{'form.authorfolder'};
285: $title=&clean($title);
286: my ($navmap,$errormsg) =
287: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
288: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
289: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
290: my (%maps,%resources,%titles);
291: if (!ref($navmap)) {
292: $r->print($errormsg.
293: &endContentScreen());
294: return '';
295: } else {
296: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
297: 'dumpdocs',$cdom,$cnum);
298: }
299: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
300: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
301: %newcontent,%has_simpleprobs);
302: foreach my $item (sort {$a <=> $b} (@todump)) {
303: my $name = $env{'form.namefor_'.$item};
304: if ($resources{$item}) {
305: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
306: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
307: $tocopy{$1} = $name;
308: $display{$item} = $1;
309: $lookup{$1} = $item;
310: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
311: $simpleproblems{$item} = {
312: symb => $resources{$item},
313: name => $name,
314: };
315: $display{$item} = 'simpleproblem_'.$name;
316: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
317: $has_simpleprobs{$1}{$id} = $item;
318: }
319: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
320: my $marker = $1;
321: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
322: $simplepages{$item} = {
323: res => $res,
324: title => $titles{$item},
325: db => $db_name,
326: marker => $marker,
327: symb => $resources{$item},
328: name => $name,
329: };
330: $display{$item} = '/'.$res;
331: }
332: } elsif ($maps{$item}) {
333: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
334: $tocopy{$1} = $name;
335: $display{$item} = $1;
336: $lookup{$1} = $item;
337: }
338: } else {
339: next;
340: }
341: }
342: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
343: $crs=~s/\_/\//g;
344: my $mm = new File::MMagic;
345: my $prefix = "/uploaded/$cdom/$cnum/";
346: %replacehash = %tocopy;
347: foreach my $item (sort(keys(%simpleproblems))) {
348: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
349: $newcontent{$display{$item}} = $content;
350: }
351: my $gateway = Apache::lonhtmlgateway->new('web');
352: foreach my $item (sort(keys(%simplepages))) {
353: if (ref($simplepages{$item}) eq 'HASH') {
354: my $pagetitle = $simplepages{$item}{'title'};
355: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
356: my %contents;
357: foreach my $field (keys(%fields)) {
358: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
359: my $name = $1;
360: my $msg = $fields{$field};
361: if ($name eq 'webreferences') {
362: if ($msg =~ m{^https?://}) {
363: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
364: }
365: } else {
366: $msg = &Encode::decode('utf8',$msg);
367: $msg = $gateway->process_outgoing_html($msg,1);
368: $contents{$name} = $msg;
369: }
370: } elsif ($field eq 'uploaded.photourl') {
371: my $marker = $simplepages{$item}{marker};
372: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
373: my $filepath = $1;
374: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
375: if ($fname ne '') {
376: $fname=~s/\.(\w+)$//;
377: my $ext=$1;
378: $fname = &clean($fname);
379: $fname.='.'.$ext;
380: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
381: $replacehash{$filepath} = $relpath.$fname;
382: $deps{$item}{$filepath} = 1;
383: }
384: }
385: }
386: }
387: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
388: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
389: my $content = '
390: <html>
391: <head>
392: <title>'.$pagetitle.'</title>
393: </head>
394: <body bgcolor="#ffffff">';
395: if ($contents{title}) {
396: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
397: }
398: if ($contents{image}) {
399: $content .= "\n".$contents{image};
400: }
401: if ($contents{content}) {
402: $content .= '
403: <div class="LC_Box">
404: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
405: $contents{content}.'
406: </div>';
407: }
408: if ($contents{webreferences}) {
409: $content .= '
410: <div class="LC_Box">
411: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
412: $contents{webreferences}.'
413: </div>';
414: }
415: $content .= '
416: </body>
417: </html>
418: ';
419: $newcontent{'/'.$simplepages{$item}{res}} = $content;
420: }
421: }
422: foreach my $item (keys(%tocopy)) {
423: unless ($item=~/\.(sequence|page)$/) {
424: my $currurlpath = $prefix.$item;
425: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
426: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
427: }
428: }
429: foreach my $num (sort {$a <=> $b} (@todump)) {
430: my $src = $display{$num};
431: next if ($src eq '');
432: my @needcopy = ();
433: if ($replacehash{$src}) {
434: push(@needcopy,$src);
435: if (ref($deps{$num}) eq 'HASH') {
436: foreach my $dep (sort(keys(%{$deps{$num}}))) {
437: if ($replacehash{$dep}) {
438: push(@needcopy,$dep);
439: }
440: }
441: }
442: } elsif ($src =~ /^simpleproblem_/) {
443: push(@needcopy,$src);
444: }
445: next if (@needcopy == 0);
446: my ($result,$depresult);
447: for (my $i=0; $i<@needcopy; $i++) {
448: my $item = $needcopy[$i];
449: my $newfilename;
450: if ($simpleproblems{$num}) {
451: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
452: } else {
453: $newfilename=$title.'/'.$replacehash{$item};
454: }
455: $newfilename=~s/\.(\w+)$//;
456: my $ext=$1;
457: $newfilename=&clean($newfilename);
458: $newfilename.='.'.$ext;
459: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
460: if ($newrelpath ne $replacehash{$item}) {
461: $replacehash{$item} = $newrelpath;
462: }
463: my @dirs=split(/\//,$newfilename);
464: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
465: my $makepath=$path;
466: my $fail;
467: my $origin;
468: for (my $i=0;$i<$#dirs;$i++) {
469: $makepath.='/'.$dirs[$i];
470: unless (-e $makepath) {
471: unless(mkdir($makepath,0755)) {
472: $fail = &mt('Directory creation failed.');
473: }
474: }
475: }
476: if ($i == 0) {
477: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
478: } else {
479: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
480: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
481: &mt('(dependency)').'</span>: ';
482: }
483: if (-e $path.'/'.$newfilename) {
484: $fail = &mt('Destination already exists -- not overwriting.');
485: } else {
486: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
487: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
488: ($item =~ /^simpleproblem_/)) {
489: print $fh $newcontent{$item};
490: } else {
491: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
492: if (-e $fileloc) {
493: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
494: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
495: (ref($has_simpleprobs{$item}) eq 'HASH')) {
496: my %changes = %{$has_simpleprobs{$item}};
497: my $content = &Apache::lonclonecourse::rewritefile(
498: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
499: (%replacehash,$crs => '')
500: );
501: my $updatedcontent = '';
502: my $parser = HTML::TokeParser->new(\$content);
503: $parser->attr_encoded(1);
504: while (my $token = $parser->get_token) {
505: if ($token->[0] eq 'S') {
506: if (($token->[1] eq 'resource') &&
507: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
508: ($changes{$token->[2]->{'id'}})) {
509: my $id = $token->[2]->{'id'};
510: $updatedcontent .= '<'.$token->[1];
511: foreach my $attrib (@{$token->[3]}) {
512: next unless ($attrib =~ /^(src|type|title|id)$/);
513: if ($attrib eq 'src') {
514: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
515: if ($file) {
516: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
517: } else {
518: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
519: }
520: } else {
521: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
522: }
523: }
524: $updatedcontent .= ' />'."\n";
525: } else {
526: $updatedcontent .= $token->[4]."\n";
527: }
528: } else {
529: $updatedcontent .= $token->[2];
530: }
531: }
532: print $fh $updatedcontent;
533: } else {
534: print $fh &Apache::lonclonecourse::rewritefile(
535: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
536: (%replacehash,$crs => '')
537: );
538: }
539: } else {
540: print $fh
541: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
542: }
543: } else {
544: $fail = &mt('Source does not exist.');
545: }
546: }
547: $fh->close();
548: } else {
549: $fail = &mt('Could not write to destination.');
550: }
551: }
552: my $text;
553: if ($fail) {
554: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
555: } else {
556: $text = '<span class="LC_success">'.&mt('ok').'</span>';
557: }
558: if ($i == 0) {
559: $result .= $text;
560: } else {
561: $depresult .= $text.'</li>';
562: }
563: }
564: $r->print($result);
565: if ($depresult) {
566: $r->print('<ul>'.$depresult.'</ul>');
567: }
568: }
569: } else {
570: my ($navmap,$errormsg) =
571: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
572: if (!ref($navmap)) {
573: $r->print($errormsg);
574: } else {
575: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
576: $r->rflush();
577: my ($preamble,$formname);
578: $formname = 'dumpdoc';
579: unless ($home==1) {
580: $preamble = '<div class="LC_left_float">'.
581: '<fieldset><legend>'.
582: &mt('Select the Authoring Space').
583: '</legend><select name="authorspace">';
584: }
585: my @orderspaces = ();
586: foreach my $key (sort(keys(%outhash))) {
587: if ($key=~/^home_(.+)$/) {
588: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
589: unshift(@orderspaces,$1);
590: } else {
591: push(@orderspaces,$1);
592: }
593: }
594: }
595: if ($home>1) {
596: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
597: }
598: foreach my $user (@orderspaces) {
599: if ($home==1) {
600: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
601: } else {
602: $preamble .= '<option value="'.$user.'">'.$user.' - '.
603: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
604: }
605: }
606: unless ($home==1) {
607: $preamble .= '</select></fieldset></div>'."\n";
608: }
609: my $title=$origcrsdata{'description'};
610: $title=~s/[\/\s]+/\_/gs;
611: $title=&clean($title);
612: $preamble .= '<div class="LC_left_float">'.
613: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
614: '<input type="text" size="50" name="authorfolder" value="'.
615: $title.'" />'.
616: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
617: my %uploadedfiles;
618: &tiehash();
619: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
620: my ($ext)=($file=~/\.(\w+)$/);
621: # FIXME Check supplemental here
622: my $title=$hash{'title_'.$hash{
623: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
624: if (!$title) {
625: $title=$file;
626: } else {
627: $title=~s|/|_|g;
628: }
629: $title=~s/\.(\w+)$//;
630: $title=&clean($title);
631: $title.='.'.$ext;
632: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
633: $uploadedfiles{$file} = $title;
634: }
635: &untiehash();
636: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
637: undef,undef,$preamble,$home,\%uploadedfiles));
638: }
639: }
640: $r->print(&endContentScreen());
641: }
642:
643: sub recurse_html {
644: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
645: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
646: my (%allfiles,%codebase);
647: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
648: if (keys(%allfiles)) {
649: foreach my $dependency (keys(%allfiles)) {
650: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
651: my ($depurl,$relfile,$newcontainer);
652: if ($dependency =~ m{^/}) {
653: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
654: $relfile = $1;
655: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
656: $newcontainer = $1;
657: next if ($replacehash->{$newcontainer});
658: }
659: $depurl = $dependency;
660: } else {
661: next;
662: }
663: } else {
664: $relfile = $dependency;
665: $depurl = $currurlpath;
666: $depurl =~ s{[^/]+$}{};
667: $depurl .= $dependency;
668: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
669: }
670: next if ($relfile eq '');
671: my $newname = $replacehash->{$container};
672: $newname =~ s{[^/]+$}{};
673: $replacehash->{$newcontainer} = $newname.$relfile;
674: $deps->{$item}{$newcontainer} = 1;
675: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
676: my $depfile = &Apache::lonnet::filelocation('',$depurl);
677: my $type = $mm->checktype_filename($depfile);
678: if ($type eq 'text/html') {
679: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
680: }
681: }
682: }
683: }
684: return;
685: }
686:
687: sub group_import {
688: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
689: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
690: %removeparam,$importuploaded,$fixuperrors);
691: $allmaps = {};
692: while (@files) {
693: my ($name, $url, $residx) = @{ shift(@files) };
694: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
695: && ($caller eq 'londocs')
696: && (!&Apache::lonnet::stat_file($url))) {
697:
698: my $errtext = '';
699: my $fatal = 0;
700: my $newmapstr = '<map>'."\n".
701: '<resource id="1" src="" type="start"></resource>'."\n".
702: '<link from="1" to="2" index="1"></link>'."\n".
703: '<resource id="2" src="" type="finish"></resource>'."\n".
704: '</map>';
705: $env{'form.output'}=$newmapstr;
706: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
707: 'output',$1.$2);
708: if ($result !~ m{^/uploaded/}) {
709: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
710: $fatal = 2;
711: }
712: if ($fatal) {
713: return ($errtext,$fatal);
714: }
715: }
716: if ($url) {
717: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
718: $url = $1;
719: my $marker = $2;
720: my $info = $3;
721: my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
722: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
723: my @toolinfo = split(/:/,$info);
724: if ($residx) {
725: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
726: $toolid = $toolsettings{'id'};
727: } else {
728: $toolid = shift(@toolinfo);
729: }
730: if ($toolid =~ /^c/) {
731: $tooltype = 'crs';
732: $toolprefix = 'c';
733: } else {
734: $tooltype = 'dom';
735: }
736: $toolid =~ s/\D//g;
737: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
738: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
739: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
740: foreach my $item (@extras) {
741: $toolhash{$item} = &unescape($toolhash{$item});
742: }
743: if ($folder =~ /^supplemental/) {
744: delete($toolhash{'gradable'});
745: } else {
746: $toolhash{'gradable'} =~ s/\D+//g;
747: }
748: if (ref($ltitoolsref) eq 'HASH') {
749: if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
750: if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
751: my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
752: my @deleted;
753: $toolhash{'id'} = $toolprefix.$toolid;
754: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
755: ($toolhash{'target'} eq 'window')) {
756: if ($toolhash{'target'} eq 'window') {
757: foreach my $item ('width','height') {
758: $toolhash{$item} =~ s/^\s+//;
759: $toolhash{$item} =~ s/\s+$//;
760: if ($toolhash{$item} =~ /\D/) {
761: delete($toolhash{$item});
762: if ($residx) {
763: if ($toolsettings{$item}) {
764: push(@deleted,$item);
765: }
766: }
767: }
768: }
769: }
770: } elsif ($residx) {
771: $toolhash{'target'} = $toolsettings{'target'};
772: if ($toolhash{'target'} eq 'window') {
773: foreach my $item ('width','height') {
774: $toolhash{$item} = $toolsettings{$item};
775: }
776: }
777: } elsif (ref($tools{'display'}) eq 'HASH') {
778: $toolhash{'target'} = $tools{'display'}{'target'};
779: if ($toolhash{'target'} eq 'window') {
780: $toolhash{'width'} = $tools{'display'}{'width'};
781: $toolhash{'height'} = $tools{'display'}{'height'};
782: }
783: }
784: if ($toolhash{'target'} eq 'iframe') {
785: foreach my $item ('width','height','linktext','explanation') {
786: delete($toolhash{$item});
787: if ($residx) {
788: if ($toolsettings{$item}) {
789: push(@deleted,$item);
790: }
791: }
792: }
793: } elsif ($toolhash{'target'} eq 'tab') {
794: foreach my $item ('width','height') {
795: delete($toolhash{$item});
796: if ($residx) {
797: if ($toolsettings{$item}) {
798: push(@deleted,$item);
799: }
800: }
801: }
802: }
803: if (ref($tools{'crsconf'}) eq 'HASH') {
804: foreach my $item ('label','title','linktext','explanation') {
805: my $crsitem;
806: if (($item eq 'label') || ($item eq 'title')) {
807: $crsitem = 'crs'.$item;
808: } else {
809: $crsitem = $item;
810: }
811: if ($tools{'crsconf'}{$item}) {
812: $toolhash{$crsitem} =~ s/^\s+//;
813: $toolhash{$crsitem} =~ s/\s+$//;
814: if ($toolhash{$crsitem} eq '') {
815: delete($toolhash{$crsitem});
816: }
817: } else {
818: delete($toolhash{$crsitem});
819: }
820: if (($residx) && (exists($toolsettings{$crsitem}))) {
821: unless (exists($toolhash{$crsitem})) {
822: push(@deleted,$crsitem);
823: }
824: }
825: }
826: }
827: if ($toolhash{'passback'}) {
828: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
829: $toolhash{'gradesecret'} = $gradesecret;
830: $toolhash{'gradesecretdate'} = time;
831: }
832: if ($toolhash{'roster'}) {
833: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
834: $toolhash{'rostersecret'} = $rostersecret;
835: $toolhash{'rostersecretdate'} = time;
836: }
837: my $changegradable;
838: if (($residx) && ($folder =~ /^default/)) {
839: if ($toolsettings{'gradable'}) {
840: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
841: push(@deleted,'gradable');
842: $changegradable = 1;
843: }
844: } elsif ($toolhash{'gradable'}) {
845: $changegradable = 1;
846: }
847: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
848: $changegradable = 1;
849: if ($toolsettings{'gradable'}) {
850: $toolhash{'gradable'} = 1;
851: }
852: }
853: }
854: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
855: if ($putres eq 'ok') {
856: if (@deleted) {
857: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
858: }
859: if (($changegradable) && ($folder =~ /^default/)) {
860: my $val;
861: if ($toolhash{'gradable'}) {
862: $val = 'yes';
863: } else {
864: $val = 'no';
865: }
866: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
867: 'string_yesno');
868: &remember_parms($residx,'gradable','set',$val);
869: }
870: } else {
871: return (&mt('Failed to save update to external tool.'),1);
872: }
873: }
874: }
875: }
876: }
877: if (($caller eq 'londocs') &&
878: ($folder =~ /^default/)) {
879: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
880: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
881: my $cid = $coursedom.'_'.$coursenum;
882: $allmaps =
883: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
884: $chome,$cid);
885: $donechk = 1;
886: }
887: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
888: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
889: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
890: $importuploaded = 1;
891: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
892: next if ($allmaps->{$url});
893: }
894: }
895: if (!$residx
896: || defined($LONCAPA::map::zombies[$residx])) {
897: $residx = &LONCAPA::map::getresidx($url,$residx);
898: push(@LONCAPA::map::order, $residx);
899: }
900: my $ext = 'false';
901: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
902: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
903: my $filepath = $1;
904: my $fname;
905: if ($name eq '') {
906: $name = &mt('Web Page');
907: $fname = 'web';
908: } else {
909: $fname = $name;
910: $fname=&Apache::lonnet::clean_filename($fname);
911: if ($fname eq '') {
912: $fname = 'web';
913: } elsif (length($fname) > 15) {
914: $fname = substr($fname,0,14);
915: }
916: }
917: my $title = &Apache::loncommon::cleanup_html($name);
918: my $initialtext = &mt('Replace with your own content.');
919: my $newhtml = <<END;
920: <html>
921: <head>
922: <title>$title</title>
923: </head>
924: <body bgcolor="#ffffff">
925: $initialtext
926: </body>
927: </html>
928: END
929: $env{'form.output'}=$newhtml;
930: my $result =
931: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
932: 'output',
933: "$filepath/$residx/$fname.html");
934: if ($result =~ m{^/uploaded/}) {
935: $url = $result;
936: if ($filepath =~ /^supplemental/) {
937: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
938: $env{'user.domain'}.'___&&&___'.$name;
939: }
940: } else {
941: return (&mt('Failed to save new web page.'),1);
942: }
943: }
944: $name = &LONCAPA::map::qtunescape($name);
945: $url = &LONCAPA::map::qtunescape($url);
946: $LONCAPA::map::resources[$residx] =
947: join(':', ($name, $url, $ext, 'normal', 'res'));
948: }
949: }
950: if ($importuploaded) {
951: my %import_errors;
952: my %updated = (
953: removefrommap => \%removefrommap,
954: removeparam => \%removeparam,
955: );
956: my ($result,$msgsarray,$lockerror) =
957: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
958: if (keys(%import_errors) > 0) {
959: $fixuperrors =
960: '<p span class="LC_warning">'."\n".
961: &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".
962: '<ul>'."\n";
963: foreach my $key (sort(keys(%import_errors))) {
964: $fixuperrors .= '<li>'.$key.'</li>'."\n";
965: }
966: $fixuperrors .= '</ul></p>'."\n";
967: }
968: if (ref($msgsarray) eq 'ARRAY') {
969: if (@{$msgsarray} > 0) {
970: $fixuperrors .= '<p class="LC_info">'.
971: join('<br />',@{$msgsarray}).
972: '</p>';
973: }
974: }
975: if ($lockerror) {
976: $fixuperrors .= '<p class="LC_error">'.
977: $lockerror.
978: '</p>';
979: }
980: }
981: my ($errtext,$fatal) =
982: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
983: unless ($fatal) {
984: if ($folder =~ /^supplemental/) {
985: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
986: $folder.'.'.$container);
987: }
988: }
989: return ($errtext,$fatal,$fixuperrors);
990: }
991:
992: sub log_docs {
993: return &Apache::lonnet::write_log('course','docslog',@_);
994: }
995:
996: {
997: my @oldresources=();
998: my @oldorder=();
999: my $parmidx;
1000: my %parmaction=();
1001: my %parmvalue=();
1002: my $changedflag;
1003:
1004: sub snapshotbefore {
1005: @oldresources=@LONCAPA::map::resources;
1006: @oldorder=@LONCAPA::map::order;
1007: $parmidx=undef;
1008: %parmaction=();
1009: %parmvalue=();
1010: $changedflag=0;
1011: }
1012:
1013: sub remember_parms {
1014: my ($idx,$parameter,$action,$value)=@_;
1015: $parmidx=$idx;
1016: $parmaction{$parameter}=$action;
1017: $parmvalue{$parameter}=$value;
1018: $changedflag=1;
1019: }
1020:
1021: sub log_differences {
1022: my ($plain)=@_;
1023: my %storehash=('folder' => $plain,
1024: 'currentfolder' => $env{'form.folder'});
1025: if ($parmidx) {
1026: $storehash{'parameter_res'}=$oldresources[$parmidx];
1027: foreach my $parm (keys(%parmaction)) {
1028: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1029: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1030: }
1031: }
1032: my $maxidx=$#oldresources;
1033: if ($#LONCAPA::map::resources>$#oldresources) {
1034: $maxidx=$#LONCAPA::map::resources;
1035: }
1036: for (my $idx=0; $idx<=$maxidx; $idx++) {
1037: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1038: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1039: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1040: $changedflag=1;
1041: }
1042: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1043: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1044: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1045: $changedflag=1;
1046: }
1047: }
1048: $storehash{'maxidx'}=$maxidx;
1049: if ($changedflag) { &log_docs(\%storehash); }
1050: }
1051: }
1052:
1053: sub docs_change_log {
1054: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1055: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1056: my $navmap;
1057: my $js = '<script type="text/javascript">'."\n".
1058: '// <![CDATA['."\n".
1059: &Apache::loncommon::display_filter_js('docslog')."\n".
1060: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1061: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1062: &history_tab_js()."\n".
1063: &Apache::lonratedt::editscript('simple')."\n".
1064: '// ]]>'."\n".
1065: '</script>'."\n";
1066: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1067: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1068: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1069: my %orderhash;
1070: my $container='sequence';
1071: my $pathitem;
1072: if ($env{'form.folderpath'} =~ /\:1$/) {
1073: $container='page';
1074: }
1075: my $folderpath=$env{'form.folderpath'};
1076: if ($folderpath eq '') {
1077: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1078: }
1079: undef($navmap);
1080: $pathitem = '<input type="hidden" name="folderpath" value="'.
1081: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1082: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1083: my $jumpto = $readfile;
1084: $jumpto =~ s{^/}{};
1085: my $tid = 1;
1086: if ($supplementalflag) {
1087: $tid = 2;
1088: }
1089: my ($breadcrumbtrail) =
1090: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1091: $r->print($breadcrumbtrail.
1092: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1093: $readfile));
1094: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1095: $env{'course.'.$env{'request.course.id'}.'.domain'},
1096: $env{'course.'.$env{'request.course.id'}.'.num'});
1097:
1098: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1099:
1100: my %saveable_parameters = ('show' => 'scalar',);
1101: &Apache::loncommon::store_course_settings('docs_log',
1102: \%saveable_parameters);
1103: &Apache::loncommon::restore_course_settings('docs_log',
1104: \%saveable_parameters);
1105: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1106: # FIXME: internationalization seems wrong here
1107: my %lt=('hiddenresource' => 'Resources hidden',
1108: 'encrypturl' => 'URL hidden',
1109: 'randompick' => 'Randomly pick',
1110: 'randomorder' => 'Randomly ordered',
1111: 'gradable' => 'Grade can be assigned to External Tool',
1112: 'set' => 'set to',
1113: 'del' => 'deleted');
1114: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1115: $pathitem."\n".
1116: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1117: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1118: $r->print('<div class="LC_left_float">'.
1119: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1120: &makedocslogform($filter,1).
1121: '</fieldset></div><br clear="all" />');
1122: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1123: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1124: &mt('After').'</th>'.
1125: &Apache::loncommon::end_data_table_header_row());
1126: my $shown=0;
1127: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1128: if ($env{'form.displayfilter'} eq 'currentfolder') {
1129: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1130: }
1131: my @changes=keys(%{$docslog{$id}{'logentry'}});
1132: if ($env{'form.displayfilter'} eq 'containing') {
1133: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1134: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1135: foreach my $key (@changes) {
1136: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1137: }
1138: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1139: }
1140: my $count = 0;
1141: my $time =
1142: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1143: my $plainname =
1144: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1145: $docslog{$id}{'exe_udom'});
1146: my $about_me_link =
1147: &Apache::loncommon::aboutmewrapper($plainname,
1148: $docslog{$id}{'exe_uname'},
1149: $docslog{$id}{'exe_udom'});
1150: my $send_msg_link='';
1151: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1152: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1153: $send_msg_link ='<br />'.
1154: &Apache::loncommon::messagewrapper(&mt('Send message'),
1155: $docslog{$id}{'exe_uname'},
1156: $docslog{$id}{'exe_udom'});
1157: }
1158: $r->print(&Apache::loncommon::start_data_table_row());
1159: $r->print('<td>'.$time.'</td>
1160: <td>'.$about_me_link.
1161: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1162: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1163: $send_msg_link.'</td><td>'.
1164: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1165: my $is_supp = 0;
1166: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1167: $is_supp = 1;
1168: }
1169: # Before
1170: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1171: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1172: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1173: if ($oldname ne $newname) {
1174: my $shown = &LONCAPA::map::qtescape($oldname);
1175: if ($is_supp) {
1176: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1177: }
1178: $r->print($shown);
1179: }
1180: }
1181: $r->print('<ul>');
1182: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1183: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1184: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1185: if ($is_supp) {
1186: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1187: }
1188: $r->print('<li>'.$shown.'</li>');
1189: }
1190: }
1191: $r->print('</ul>');
1192: # After
1193: $r->print('</td><td>');
1194:
1195: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1196: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1197: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1198: if ($oldname ne '' && $oldname ne $newname) {
1199: my $shown = &LONCAPA::map::qtescape($newname);
1200: if ($is_supp) {
1201: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1202: }
1203: $r->print($shown);
1204: }
1205: }
1206: $r->print('<ul>');
1207: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1208: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1209: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1210: if ($is_supp) {
1211: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1212: }
1213: $r->print('<li>'.$shown.'</li>');
1214: }
1215: }
1216: $r->print('</ul>');
1217: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1218: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1219: if ($title eq '') {
1220: ($title) = ($url =~ m{/([^/]+)$});
1221: } elsif ($is_supp) {
1222: $title = &Apache::loncommon::parse_supplemental_title($title);
1223: }
1224: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1225: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1226: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1227: # FIXME: internationalization seems wrong here
1228: $r->print('<li>'.
1229: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1230: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1231: .'</li>');
1232: }
1233: }
1234: $r->print('</ul>');
1235: }
1236: # End
1237: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1238: $shown++;
1239: if (!($env{'form.show'} eq &mt('all')
1240: || $shown<=$env{'form.show'})) { last; }
1241: }
1242: $r->print(&Apache::loncommon::end_data_table()."\n".
1243: &makesimpleeditform($pathitem)."\n".
1244: '</div></div>');
1245: $r->print(&endContentScreen());
1246: }
1247:
1248: sub update_paste_buffer {
1249: my ($coursenum,$coursedom,$folder) = @_;
1250: my (@possibles,%removals,%cuts,$output);
1251: if ($env{'form.multiremove'}) {
1252: $env{'form.multiremove'} =~ s/,$//;
1253: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1254: }
1255: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1256: if ($env{'form.multicut'}) {
1257: $env{'form.multicut'} =~ s/,$//;
1258: foreach my $item (split(/,/,$env{'form.multicut'})) {
1259: unless ($removals{$item}) {
1260: $cuts{$item} = 1;
1261: push(@possibles,$item.':cut');
1262: }
1263: }
1264: }
1265: if ($env{'form.multicopy'}) {
1266: $env{'form.multicopy'} =~ s/,$//;
1267: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1268: unless ($removals{$item} || $cuts{$item}) {
1269: push(@possibles,$item.':copy');
1270: }
1271: }
1272: }
1273: } elsif ($env{'form.markcopy'}) {
1274: @possibles = split(/,/,$env{'form.markcopy'});
1275: }
1276:
1277: return if (@possibles == 0);
1278: return if (!defined($env{'form.copyfolder'}));
1279:
1280: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1281: $env{'form.copyfolder'});
1282: return if ($fatal);
1283:
1284: my %curr_groups = &Apache::longroup::coursegroups();
1285:
1286: # Retrieve current paste buffer suffixes.
1287: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1288: my (%pasteurls,@newpaste);
1289:
1290: # Construct identifiers for current contents of user's paste buffer
1291: if (@currpaste) {
1292: foreach my $suffix (@currpaste) {
1293: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1294: my $url = $env{'docs.markedcopy_url_'.$suffix};
1295: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1296: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1297: ($url ne '')) {
1298: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1299: $pasteurls{$cid.'_'.$mapidx} = 1;
1300: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1301: $pasteurls{$url} = 1;
1302: } else {
1303: $pasteurls{$cid.'_'.$url} = 1;
1304: }
1305: }
1306: }
1307: }
1308:
1309: # Mark items for copying (skip any items already in user's paste buffer)
1310: my %addtoenv;
1311:
1312: my @pathitems = split(/\&/,$env{'form.folderpath'});
1313: my @folderconf = split(/\:/,$pathitems[-1]);
1314: my $ispage = $folderconf[5];
1315:
1316: foreach my $item (@possibles) {
1317: my ($orderidx,$cmd) = split(/:/,$item);
1318: next if ($orderidx =~ /\D/);
1319: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1320: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1321: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1322: my %denied = &action_restrictions($coursenum,$coursedom,
1323: &LONCAPA::map::qtescape($url),
1324: $env{'form.folderpath'},\%curr_groups);
1325: next if ($denied{'copy'});
1326: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1327: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1328: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1329: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1330: next if (exists($pasteurls{$url}));
1331: } else {
1332: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1333: }
1334: my ($suffix,$errortxt,$locknotfreed) =
1335: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1336: if ($suffix ne '') {
1337: push(@newpaste,$suffix);
1338: } else {
1339: if ($locknotfreed) {
1340: return $locknotfreed;
1341: }
1342: }
1343: if (&is_supplemental_title($title)) {
1344: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1345: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1346: }
1347:
1348: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1349: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1350: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1351: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1352: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1353: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1354: my $prefix = $1;
1355: my $subdir =$2;
1356: if ($subdir eq '') {
1357: $subdir = $prefix;
1358: }
1359: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1360: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1361: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1362: if (ref($hierarchy{$url}) eq 'HASH') {
1363: my ($nested,$nestednames);
1364: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1365: $nested =~ s/\&$//;
1366: $nestednames =~ s/\Q___&&&___\E$//;
1367: if ($nested ne '') {
1368: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1369: }
1370: if ($nestednames ne '') {
1371: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1372: }
1373: }
1374: }
1375: if ($locknotfreed) {
1376: $output = $locknotfreed;
1377: last;
1378: }
1379: }
1380: if (@newpaste) {
1381: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1382: }
1383: &Apache::lonnet::appenv(\%addtoenv);
1384: delete($env{'form.markcopy'});
1385: return $output;
1386: }
1387:
1388: sub recurse_uploaded_maps {
1389: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1390: if (ref($hierarchy->{$url}) eq 'HASH') {
1391: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1392: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1393: my (@uploaded,@names,%shorter);
1394: for (my $i=0; $i<@maps; $i++) {
1395: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1396: if ($inner ne '') {
1397: push(@uploaded,$inner);
1398: push(@names,&escape($titles[$i]));
1399: $shorter{$maps[$i]} = $inner;
1400: }
1401: }
1402: $$nestref .= "$dir:".join(',',@uploaded).'&';
1403: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1404: foreach my $map (@maps) {
1405: if ($shorter{$map} ne '') {
1406: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1407: }
1408: }
1409: }
1410: return;
1411: }
1412:
1413: sub print_paste_buffer {
1414: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1415: return if (!defined($env{'docs.markedcopies'}));
1416:
1417: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1418: return if ($env{'docs.markedcopies'} eq '');
1419: }
1420:
1421: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1422: my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
1423: my $clipboardcount = 0;
1424:
1425: # Construct identifiers for current contents of user's paste buffer
1426: foreach my $suffix (@currpaste) {
1427: next if ($suffix =~ /\D/);
1428: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1429: my $url = $env{'docs.markedcopy_url_'.$suffix};
1430: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1431: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1432: ($url ne '')) {
1433: $clipboardcount ++;
1434: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1435: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
1436: $toolcnum,$marker);
1437: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1438: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1439: $is_external = 1;
1440: } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
1441: ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1442: $is_exttool = 1;
1443: }
1444: if ($folder =~ /^supplemental/) {
1445: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1446: unless ($canpaste) {
1447: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1448: }
1449: } else {
1450: $canpaste = 1;
1451: }
1452: if ($canpaste) {
1453: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1454: my $srcdom = $1;
1455: my $srcnum = $2;
1456: my $rem = $3;
1457: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1458: $othercourse = 1;
1459: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1460: $othercrs = '<br />'.&mt('(from another course)');
1461: } else {
1462: $canpaste = 0;
1463: $nopaste = &mt('Paste from another course unavailable.');
1464: }
1465: }
1466: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1467: my $prefix = $1;
1468: $parent = $2;
1469: if ($folder !~ /^\Q$prefix\E/) {
1470: $areachange = 1;
1471: }
1472: $is_uploaded_map = 1;
1473: }
1474: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1475: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1476: if ($cid ne $env{'request.course.id'}) {
1477: my ($srcdom,$srcnum) = split(/_/,$cid);
1478: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1479: if ($is_exttool) {
1480: if ($toolcdom ne $coursedom) {
1481: $canpaste = 0;
1482: $nopaste = &mt('Paste from another domain unavailable.');
1483: } elsif ($toolcnum ne $coursenum) {
1484: my %toolsettings =
1485: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
1486: my %tooltypes = &Apache::loncommon::usable_exttools();
1487: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
1488: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
1489: $canpaste = 0;
1490: $nopaste = &mt('Paste from another course unavailable.');
1491: } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
1492: unless ($checkedsameinst) {
1493: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
1494: my $intdom = &Apache::lonnet::internet_dom($primary_id);
1495: if ($intdom ne '') {
1496: my $internet_names =
1497: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
1498: if (ref($internet_names) eq 'ARRAY') {
1499: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
1500: $same_institution = 1;
1501: }
1502: }
1503: }
1504: $checkedsameinst = 1;
1505: }
1506: if ($same_institution) {
1507: $othercrs = '<br />'.&mt('(from another course)');
1508: } else {
1509: $nopaste = &mt('Paste from another course unavailable.');
1510: }
1511: } else {
1512: $othercrs = '<br />'.&mt('(from another course)');
1513: }
1514: }
1515: }
1516: } else {
1517: $canpaste = 0;
1518: $nopaste = &mt('Paste from another course unavailable.');
1519: }
1520: }
1521: } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
1522: my ($audom,$auname) = ($1,$2);
1523: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
1524: if (&Apache::lonnet::is_course($audom,$auname)) {
1525: $canpaste = 0;
1526: $nopaste = &mt('Paste from another course unavailable.');
1527: }
1528: }
1529: }
1530: if ($canpaste) {
1531: push(@pasteable,$suffix);
1532: }
1533: }
1534: my $buffer;
1535: if ($is_external) {
1536: $buffer = &mt('External Resource').': '.
1537: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1538: &LONCAPA::map::qtescape($url).')';
1539: } elsif ($is_exttool) {
1540: $buffer = &mt('External Tool').': '.
1541: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1542: } else {
1543: my $icon = &Apache::loncommon::icon($extension);
1544: if ($extension eq 'sequence' &&
1545: $url =~ m{/default_\d+\.sequence$}x) {
1546: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1547: $icon .= '/navmap.folder.closed.gif';
1548: }
1549: my $title = $env{'docs.markedcopy_title_'.$suffix};
1550: if ($title eq '') {
1551: ($title) = ($url =~ m{/([^/]+)$});
1552: }
1553: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1554: ': '.
1555: &Apache::loncommon::parse_supplemental_title(
1556: &LONCAPA::map::qtescape($title));
1557: }
1558: $pasteitems .= '<div class="LC_left_float">';
1559: my ($options,$onclick);
1560: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1561: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1562: if (($is_uploaded_map) ||
1563: ($url =~ /(bulletinboard|smppg)$/) ||
1564: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1565: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1566: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1567: }
1568: }
1569: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1570: if ($nopaste) {
1571: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1572: } else {
1573: if ($othercrs) {
1574: $pasteitems .= $othercrs;
1575: }
1576: if ($options) {
1577: $pasteitems .= $options;
1578: }
1579: }
1580: $pasteitems .= '</div>';
1581: }
1582: }
1583: if ($pasteitems eq '') {
1584: &Apache::lonnet::delenv('docs.markedcopies');
1585: }
1586: my ($pasteform,$form_start,$buttons,$form_end);
1587: if ($pasteitems) {
1588: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1589: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1590: if (@pasteable) {
1591: my $value = &mt('Paste to current folder');
1592: if ($container eq 'page') {
1593: $value = &mt('Paste to current page');
1594: }
1595: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1596: }
1597: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1598: if ($clipboardcount > 1) {
1599: $buttons .=
1600: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1601: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1602: (' 'x2).
1603: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1604: (' 'x2);
1605: }
1606: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1607: '</form>';
1608: } else {
1609: $pasteitems = &mt('Clipboard is empty');
1610: }
1611: $r->print($form_start
1612: .'<fieldset>'
1613: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1614: .$pasteitems
1615: .'</fieldset>'
1616: .$form_end);
1617: }
1618:
1619: sub paste_options {
1620: my ($suffix,$is_uploaded_map,$parent) = @_;
1621: my ($copytext,$movetext);
1622: if ($is_uploaded_map) {
1623: $copytext = &mt('Copy to new folder');
1624: $movetext = &mt('Move old');
1625: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1626: $copytext = &mt('Copy to new board');
1627: $movetext = &mt('Move (not posts)');
1628: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1629: $copytext = &mt('Copy to new page');
1630: $movetext = &mt('Move');
1631: } else {
1632: $copytext = &mt('Copy to new file');
1633: $movetext = &mt('Move');
1634: }
1635: my $output = '<br />'.
1636: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1637: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1638: '<label>'.
1639: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1640: $copytext.'</label></span>'.(' 'x2).' '.
1641: '<span class="LC_nobreak"><label>'.
1642: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1643: $movetext.'</label></span>';
1644: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1645: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1646: '</legend><table border="0">';
1647: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1648: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1649: my $lastdir = $parent;
1650: my %depths = (
1651: $lastdir => 0,
1652: );
1653: my (%display,%deps);
1654: for (my $i=0; $i<@pastemaps; $i++) {
1655: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1656: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1657: my @subfolders = split(/,/,$subfolderstr);
1658: $deps{$lastdir} = \@subfolders;
1659: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1660: my $depth = $depths{$lastdir} + 1;
1661: my $offset = int($depth * 4);
1662: my $indent = (' ' x $offset);
1663: for (my $j=0; $j<@subfolders; $j++) {
1664: $depths{$subfolders[$j]} = $depth;
1665: $display{$subfolders[$j]} =
1666: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1667: '<td><label>'.
1668: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1669: '<label>'.
1670: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1671: &mt('Move old').'</label>'.
1672: '</td></tr>';
1673: }
1674: }
1675: &recurse_print(\$output,$parent,\%deps,\%display);
1676: $output .= '</table></fieldset>';
1677: }
1678: $output .= '</div>';
1679: return $output;
1680: }
1681:
1682: sub recurse_print {
1683: my ($outputref,$dir,$deps,$display) = @_;
1684: $$outputref .= $display->{$dir}."\n";
1685: if (ref($deps->{$dir}) eq 'ARRAY') {
1686: foreach my $subdir (@{$deps->{$dir}}) {
1687: &recurse_print($outputref,$subdir,$deps,$display);
1688: }
1689: }
1690: }
1691:
1692: sub supp_pasteable {
1693: my ($url) = @_;
1694: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1695: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1696: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1697: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1698: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1699: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1700: return 1;
1701: }
1702: return;
1703: }
1704:
1705: sub paste_popup_js {
1706: my %html_js_lt = &Apache::lonlocal::texthash(
1707: show => 'Show Options',
1708: hide => 'Hide Options',
1709: );
1710: my %js_lt = &Apache::lonlocal::texthash(
1711: none => 'No items selected from clipboard.',
1712: );
1713: &html_escape(\%html_js_lt);
1714: &js_escape(\%html_js_lt);
1715: &js_escape(\%js_lt);
1716: return <<"END";
1717:
1718: function showPasteOptions(suffix) {
1719: document.getElementById('pasteoptions_'+suffix).style.display='block';
1720: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1721: return;
1722: }
1723:
1724: function hidePasteOptions(suffix) {
1725: document.getElementById('pasteoptions_'+suffix).style.display='none';
1726: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1727: return;
1728: }
1729:
1730: function showOptions(caller,suffix) {
1731: if (document.getElementById('pasteoptionstext_'+suffix)) {
1732: if (caller.checked) {
1733: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1734: } else {
1735: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1736: }
1737: if (document.getElementById('pasteoptions_'+suffix)) {
1738: document.getElementById('pasteoptions_'+suffix).style.display='none';
1739: }
1740: }
1741: return;
1742: }
1743:
1744: function validateClipboard() {
1745: var numchk = 0;
1746: if (document.pasteform.pasting.length > 1) {
1747: for (var i=0; i<document.pasteform.pasting.length; i++) {
1748: if (document.pasteform.pasting[i].checked) {
1749: numchk ++;
1750: }
1751: }
1752: } else {
1753: if (document.pasteform.pasting.type == 'checkbox') {
1754: if (document.pasteform.pasting.checked) {
1755: numchk ++;
1756: }
1757: }
1758: }
1759: if (numchk > 0) {
1760: return true;
1761: } else {
1762: alert("$js_lt{'none'}");
1763: return false;
1764: }
1765: }
1766:
1767: function checkClipboard() {
1768: if (document.pasteform.pasting.length > 1) {
1769: for (var i=0; i<document.pasteform.pasting.length; i++) {
1770: document.pasteform.pasting[i].checked = true;
1771: }
1772: }
1773: return;
1774: }
1775:
1776: function uncheckClipboard() {
1777: if (document.pasteform.pasting.length >1) {
1778: for (var i=0; i<document.pasteform.pasting.length; i++) {
1779: document.pasteform.pasting[i].checked = false;
1780: }
1781: }
1782: return;
1783: }
1784:
1785: END
1786:
1787: }
1788:
1789: sub do_paste_from_buffer {
1790: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1791:
1792: # Array of items in paste buffer
1793: my (@currpaste,%pastebuffer,%allerrors);
1794: @currpaste = split(/,/,$env{'docs.markedcopies'});
1795:
1796: # Early out if paste buffer is empty
1797: if (@currpaste == 0) {
1798: return ();
1799: }
1800: map { $pastebuffer{$_} = 1; } @currpaste;
1801:
1802: # Array of items selected items to paste
1803: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1804:
1805: # Early out if nothing selected to paste
1806: if (@reqpaste == 0) {
1807: return();
1808: }
1809: my @topaste;
1810: foreach my $suffix (@reqpaste) {
1811: next if ($suffix =~ /\D/);
1812: next unless (exists($pastebuffer{$suffix}));
1813: push(@topaste,$suffix);
1814: }
1815:
1816: # Early out if nothing available to paste
1817: if (@topaste == 0) {
1818: return();
1819: }
1820:
1821: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
1822: %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
1823: %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
1824: %currltititles,$currltimax,$gotcrsltitools);
1825: $currltimax = 0;
1826: $gotcrsltitools = 0;
1827: foreach my $suffix (@topaste) {
1828: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1829: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1830: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1831: # Supplemental content may only include certain types of content
1832: # Early out if pasted content is not supported in Supplemental area
1833: if ($folder =~ /^supplemental/) {
1834: unless (&supp_pasteable($url)) {
1835: $notinsupp{$suffix} = 1;
1836: next;
1837: }
1838: }
1839: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1840: my $srcd = $1;
1841: my $srcn = $2;
1842: # When paste buffer was populated using an active role in a different course
1843: # check for mdc privilege in the course from which the resource was pasted
1844: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1845: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1846: $notincrs{$suffix} = 1;
1847: next;
1848: }
1849: }
1850: $srcdom{$suffix} = $srcd;
1851: $srcnum{$suffix} = $srcn;
1852: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1853: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1854: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1855: my ($srcd,$srcn) = split(/_/,$cid);
1856: # When paste buffer was populated using an active role in a different course
1857: # check for mdc privilege in the course from which the resource was pasted
1858: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1859: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1860: $notincrs{$suffix} = 1;
1861: next;
1862: }
1863: }
1864: # When buffer was populated using an active role in a different course
1865: # disallow pasting of External Tool if course is in a different domain,
1866: # or if External Tool use is not permitted in this course.
1867: if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
1868: my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1869: if ($toolcdom ne $coursedom) {
1870: $notindom{$suffix} = 1;
1871: next;
1872: } elsif ($toolcnum ne $coursenum) {
1873: my %toolsettings =
1874: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
1875: my %tooltypes = &Apache::loncommon::usable_exttools();
1876: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
1877: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
1878: $othcrstool{$suffix} = 1;
1879: next;
1880: }
1881: if ($toolsettings{'id'} =~ /^c\d+$/) {
1882: unless ($gotcrsltitools) {
1883: %currcrsltitools =
1884: &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
1885: foreach my $item (sort(keys(%currcrsltitools))) {
1886: if (ref($currcrsltitools{$item}) eq 'HASH') {
1887: $currltimax ++;
1888: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
1889: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
1890: } else {
1891: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
1892: }
1893: }
1894: }
1895: $gotcrsltitools = 1;
1896: }
1897: }
1898: }
1899: }
1900: $srcdom{$suffix} = $srcd;
1901: $srcnum{$suffix} = $srcn;
1902: } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
1903: my ($audom,$auname) = ($1,$2);
1904: # When buffer was populated using an active role in a different course
1905: # disallow pasting of published resources from Course Authoring Space
1906: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
1907: if (&Apache::lonnet::is_course($audom,$auname)) {
1908: $othcrsres{$suffix} = 1;
1909: next;
1910: }
1911: }
1912: }
1913: $srcmapidx{$suffix} = $mapidx;
1914: push(@dopaste,$suffix);
1915: if ($url=~/\.(page|sequence)$/) {
1916: $is_map{$suffix} = 1;
1917: }
1918: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1919: my $oldprefix = $1;
1920: # When pasting content from Main Content to Supplemental Content and vice versa
1921: # URLs will contain different paths (which depend on whether pasted item is
1922: # a folder/page or a document).
1923: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1924: $prefixchg{$suffix} = 'docstosupp';
1925: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1926: $prefixchg{$suffix} = 'supptodocs';
1927: }
1928:
1929: # If pasting an uploaded map, get list of contained uploaded maps.
1930: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1931: my @nested;
1932: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1933: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1934: my @deps = map { /\d+:([\d,]+$)/ } @items;
1935: foreach my $dep (@deps) {
1936: if ($dep =~ /,/) {
1937: push(@nested,split(/,/,$dep));
1938: } else {
1939: push(@nested,$dep);
1940: }
1941: }
1942: foreach my $item (@nested) {
1943: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1944: push(@{$marktomove{$suffix}},$type.'_'.$item);
1945: }
1946: }
1947: }
1948: }
1949: }
1950:
1951: # Early out if nothing available to paste
1952: if (@dopaste == 0) {
1953: return ();
1954: }
1955:
1956: # Populate message hash and hashes used for main content <=> supplemental content
1957: # changes
1958:
1959: %msgs = &Apache::lonlocal::texthash (
1960: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1961: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1962: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1963: othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1964: othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1965: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1966: );
1967:
1968: %before = (
1969: docstosupp => {
1970: map => 'default',
1971: doc => 'docs',
1972: },
1973: supptodocs => {
1974: map => 'supplemental',
1975: doc => 'supplemental',
1976: },
1977: );
1978:
1979: %after = (
1980: docstosupp => {
1981: map => 'supplemental',
1982: doc => 'supplemental'
1983: },
1984: supptodocs => {
1985: map => 'default',
1986: doc => 'docs',
1987: },
1988: );
1989:
1990: # Retrieve information about all course maps in main content area
1991:
1992: my $allmaps = {};
1993: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
1994: @updatetoolsenc,$updatetoolscache,$checkedsameinst,
1995: $same_institution);
1996:
1997: # Loop over the items to paste
1998: foreach my $suffix (@dopaste) {
1999: # Maps need to be copied first
2000: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
2001: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
2002: %newurls,%tomove,%resdatacopy);
2003: if (ref($marktomove{$suffix}) eq 'ARRAY') {
2004: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
2005: }
2006: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
2007: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
2008: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
2009: my $oldurl = $url;
2010: if ($is_map{$suffix}) {
2011: # If pasting a map, check if map contains other maps
2012: my (%hierarchy,%titles);
2013: if (($folder =~ /^default/) && (!$donechk)) {
2014: $allmaps =
2015: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
2016: $env{"course.$env{'request.course.id'}.home"},
2017: $env{'request.course.id'});
2018: $donechk = 1;
2019: }
2020: &contained_map_check($url,$folder,$coursenum,$coursedom,
2021: \%removefrommap,\%removeparam,\%addedmaps,
2022: \%hierarchy,\%titles,$allmaps);
2023: if ($url=~ m{^/uploaded/}) {
2024: my $newurl;
2025: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2026: ($newurl,my $error) =
2027: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
2028: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2029: \$title,$allmaps,\%newurls);
2030: if ($error) {
2031: $allerrors{$suffix} = $error;
2032: next;
2033: }
2034: if ($newurl ne '') {
2035: if ($newurl ne $url) {
2036: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
2037: $newsubdir{$url} = $1;
2038: }
2039: $mapchanges{$url} = 1;
2040: }
2041: }
2042: }
2043: if (($srcdom{$suffix} ne $coursedom) ||
2044: ($srcnum{$suffix} ne $coursenum) ||
2045: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
2046: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
2047: $coursedom,$coursenum,$srcdom{$suffix},
2048: $srcnum{$suffix},$allmaps,\%rewrites,
2049: \%retitles,\%copies,\%dbcopies,
2050: \%zombies,\%params,\%mapmoves,
2051: \%mapchanges,\%tomove,\%newsubdir,
2052: \%newurls,\%resdatacopy)) {
2053: $mapmoves{$url} = 1;
2054: }
2055: $url = $newurl;
2056: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
2057: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
2058: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2059: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
2060: \%zombies,\%params,\%mapmoves,\%mapchanges,
2061: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
2062: }
2063: } elsif ($url=~m {^/res/}) {
2064: # published map can only exist once, so remove from paste buffer when done
2065: push(@toclear,$suffix);
2066: # if pasting published map (main content area only) check map not already in course
2067: if ($folder =~ /^default/) {
2068: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
2069: $duplicate{$suffix} = 1;
2070: next;
2071: }
2072: }
2073: }
2074: }
2075: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
2076: my $prefix = $1;
2077: my $fromothercrs;
2078: #need to copy the db contents to a new one, unless this is a move.
2079: my %info = (
2080: src => $url,
2081: cdom => $coursedom,
2082: cnum => $coursenum,
2083: );
2084: if ($prefix eq 'ext.tool') {
2085: if ($prefixchg{$suffix} eq 'docstosupp') {
2086: $info{'delgradable'} = 1;
2087: }
2088: }
2089: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
2090: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
2091: $fromothercrs = 1;
2092: $info{'cdom'} = $srcdom{$suffix};
2093: $info{'cnum'} = $srcnum{$suffix};
2094: unless ($checkedsameinst) {
2095: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2096: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2097: if ($intdom ne '') {
2098: my $internet_names =
2099: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2100: if (ref($internet_names) eq 'ARRAY') {
2101: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2102: $same_institution = 1;
2103: }
2104: }
2105: }
2106: $checkedsameinst = 1;
2107: }
2108: }
2109: }
2110: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
2111: my (%lockerr,$msg);
2112: my ($newurl,$result,$errtext) =
2113: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
2114: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
2115: if ($result eq 'ok') {
2116: $url = $newurl;
2117: $title=&mt('Copy of').' '.$title;
2118: } else {
2119: if ($prefix eq 'smppg') {
2120: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2121: } elsif ($prefix eq 'bulletinboard') {
2122: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
2123: } elsif ($prefix eq 'ext.tool') {
2124: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
2125: }
2126: $results{$suffix} = $result;
2127: $msgerrs{$suffix} = $msg;
2128: $lockerrs{$suffix} = $lockerr{$prefix};
2129: next;
2130: }
2131: if ($lockerr{$prefix}) {
2132: $lockerrs{$suffix} = $lockerr{$prefix};
2133: }
2134: }
2135: }
2136: $title = &LONCAPA::map::qtunescape($title);
2137: my $ext='false';
2138: if ($url=~m{^http(|s)://}) { $ext='true'; }
2139: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2140: if ($folder !~ /^supplemental/) {
2141: (undef,undef,$title) =
2142: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2143: }
2144: } else {
2145: if ($folder=~/^supplemental/) {
2146: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2147: $env{'user.domain'}.'___&&&___'.$title;
2148: }
2149: }
2150:
2151: # For uploaded files (excluding pages/sequences) path in copied file is changed
2152: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2153: # courses.
2154:
2155: unless ($is_map{$suffix}) {
2156: my $newidx;
2157: # Now insert the URL at the bottom
2158: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2159: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2160: my $relpath = $1;
2161: if ($relpath ne '') {
2162: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2163: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2164: my $newprefix = $newloc;
2165: if ($newloc eq 'default') {
2166: $newprefix = 'docs';
2167: }
2168: if ($newdocsdir eq '') {
2169: $newdocsdir = 'default';
2170: }
2171: if (($prefixchg{$suffix}) ||
2172: ($srcdom{$suffix} ne $coursedom) ||
2173: ($srcnum{$suffix} ne $coursenum) ||
2174: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2175: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2176: $url =
2177: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2178: &Apache::lonnet::getfile($oldurl));
2179: if ($url eq '/adm/notfound.html') {
2180: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2181: next;
2182: } else {
2183: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2184: $newsubpath =~ s{/+$}{/};
2185: $docmoves{$oldurl} = $newsubpath;
2186: }
2187: }
2188: }
2189: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2190: my $template = $1;
2191: if ($newidx) {
2192: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2193: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2194: }
2195: } elsif ($url =~ /ext\.tool$/) {
2196: if (($newidx) && ($folder=~/^default/)) {
2197: my $marker = (split(m{/},$url))[4];
2198: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2199: my $val = 'no';
2200: if ($toolsettings{'gradable'}) {
2201: $val = 'yes';
2202: }
2203: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2204: 'string_yesno');
2205: &remember_parms($newidx,'gradable','set',$val);
2206: }
2207: }
2208: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2209: ':'.$ext.':normal:res';
2210: push(@LONCAPA::map::order,$newidx);
2211: # Store the result
2212: my ($errtext,$fatal) =
2213: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2214: if ($fatal) {
2215: $save_err .= $errtext;
2216: $allresult = 'fail';
2217: }
2218: }
2219:
2220: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2221: # resourcedata for simpleproblems copied from another course
2222: unless ($allresult eq 'fail') {
2223: my %updated = (
2224: rewrites => \%rewrites,
2225: zombies => \%zombies,
2226: removefrommap => \%removefrommap,
2227: removeparam => \%removeparam,
2228: dbcopies => \%dbcopies,
2229: resdatacopy => \%resdatacopy,
2230: retitles => \%retitles,
2231: );
2232: my %info = (
2233: newsubdir => \%newsubdir,
2234: params => \%params,
2235: );
2236: if ($prefixchg{$suffix}) {
2237: $info{'before'} = $before{$prefixchg{$suffix}};
2238: $info{'after'} = $after{$prefixchg{$suffix}};
2239: }
2240: my %moves = (
2241: copies => \%copies,
2242: docmoves => \%docmoves,
2243: mapmoves => \%mapmoves,
2244: );
2245: (my $result,$msgs{$suffix},my $lockerror) =
2246: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2247: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2248: $url,'paste');
2249: $lockerrors .= $lockerror;
2250: if ($result eq 'ok') {
2251: if ($is_map{$suffix}) {
2252: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2253: $folder.'.'.$container);
2254: if ($fatal) {
2255: $allresult = 'failread';
2256: } else {
2257: if ($#LONCAPA::map::order<1) {
2258: my $idx=&LONCAPA::map::getresidx();
2259: if ($idx<=0) { $idx=1; }
2260: $LONCAPA::map::order[0]=$idx;
2261: $LONCAPA::map::resources[$idx]='';
2262: }
2263: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2264: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2265: ':'.$ext.':normal:res';
2266: push(@LONCAPA::map::order,$newidx);
2267:
2268: # Store the result
2269: my ($errtext,$fatal) =
2270: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2271: if ($fatal) {
2272: $save_err .= $errtext;
2273: $allresult = 'failstore';
2274: }
2275: }
2276: }
2277: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2278: push(@toclear,$suffix);
2279: }
2280: }
2281: }
2282: }
2283: if (($updatetoolscache) || (@updatetoolsenc)) {
2284: &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
2285: \@updatetoolsenc);
2286: }
2287: &clear_from_buffer(\@toclear,\@currpaste);
2288: my $msgsarray;
2289: foreach my $suffix (keys(%msgs)) {
2290: if (ref($msgs{$suffix}) eq 'ARRAY') {
2291: $msgsarray .= join(',',@{$msgs{$suffix}});
2292: }
2293: }
2294: return ($allresult,$save_err,$msgsarray,$lockerrors);
2295: }
2296:
2297: sub do_buffer_empty {
2298: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2299: if (@currpaste == 0) {
2300: return &mt('Clipboard is already empty');
2301: }
2302: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2303: if (@toclear == 0) {
2304: return &mt('Nothing selected to clear from clipboard');
2305: }
2306: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2307: if ($numdel) {
2308: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2309: } else {
2310: return &mt('Clipboard unchanged');
2311: }
2312: return;
2313: }
2314:
2315: sub clear_from_buffer {
2316: my ($toclear,$currpaste) = @_;
2317: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2318: my %pastebuffer;
2319: map { $pastebuffer{$_} = 1; } @{$currpaste};
2320: my $numdel = 0;
2321: foreach my $suffix (@{$toclear}) {
2322: next if ($suffix =~ /\D/);
2323: next unless (exists($pastebuffer{$suffix}));
2324: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2325: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2326: delete($pastebuffer{$suffix});
2327: $numdel ++;
2328: }
2329: }
2330: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2331: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2332: return $numdel;
2333: }
2334:
2335: sub update_ltitools_caches {
2336: my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
2337: my $hashid=$coursedom.'_'.$coursenum;
2338: if ($updatetoolscache) {
2339: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
2340: }
2341: if ((ref($updatetoolsenc) eq 'ARRAY') &&
2342: (@{$updatetoolsenc})) {
2343: my @ids=&Apache::lonnet::current_machine_ids();
2344: my $updatedone;
2345: foreach my $lonhost (@{$updatetoolsenc}) {
2346: if (grep(/^\Q$lonhost\E$/,@ids)) {
2347: unless ($updatedone) {
2348: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
2349: }
2350: $updatedone = 1;
2351: } else {
2352: &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
2353: }
2354: }
2355: }
2356: return;
2357: }
2358:
2359: sub get_newmap_url {
2360: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2361: $titleref,$allmaps,$newurls) = @_;
2362: my $newurl;
2363: if ($url=~ m{^/uploaded/}) {
2364: $$titleref=&mt('Copy of').' '.$$titleref;
2365: }
2366: my $now = time;
2367: my $suffix=$$.int(rand(100)).$now;
2368: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2369: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2370: my $path = $1;
2371: my $prefix = $2;
2372: my $ancestor = $3;
2373: if (length($ancestor) > 10) {
2374: $ancestor = substr($ancestor,-10,10);
2375: }
2376: my $newid;
2377: if ($prefixchg) {
2378: if ($folder =~ /^supplemental/) {
2379: $prefix =~ s/^default/supplemental/;
2380: } else {
2381: $prefix =~ s/^supplemental/default/;
2382: }
2383: }
2384: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2385: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2386: } else {
2387: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2388: }
2389: my $counter = 0;
2390: my $is_unique = &uniqueness_check($newurl);
2391: if ($folder =~ /^default/) {
2392: if ($allmaps->{$newurl}) {
2393: $is_unique = 0;
2394: }
2395: }
2396: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2397: $counter ++;
2398: $suffix ++;
2399: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2400: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2401: } else {
2402: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2403: }
2404: $is_unique = &uniqueness_check($newurl);
2405: }
2406: if ($is_unique) {
2407: $newurls->{$newurl} = 1;
2408: } else {
2409: if ($url=~/\.page$/) {
2410: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2411: } else {
2412: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2413: }
2414: }
2415: }
2416: return ($newurl);
2417: }
2418:
2419: sub dbcopy {
2420: my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
2421: $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
2422: my ($url,$result,$errtext);
2423: if (ref($dbref) eq 'HASH') {
2424: $url = $dbref->{'src'};
2425: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
2426: my $prefix = $1;
2427: if ($prefix eq 'ext.tool') {
2428: $prefix = 'exttool';
2429: }
2430: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2431: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2432: my $db_name;
2433: my $marker = (split(m{/},$url))[4];
2434: $marker=~s/\D//g;
2435: if ($dbref->{'src'} =~ m{/smppg$}) {
2436: $db_name =
2437: &Apache::lonsimplepage::get_db_name($url,$marker,
2438: $dbref->{'cdom'},
2439: $dbref->{'cnum'});
2440: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2441: $db_name = 'exttool_'.$marker;
2442: } else {
2443: $db_name = 'bulletinpage_'.$marker;
2444: }
2445: my ($suffix,$freedlock,$error) =
2446: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2447: $coursedom,$coursenum,
2448: 'concat');
2449: if (!$suffix) {
2450: if ($prefix eq 'smppg') {
2451: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2452: } elsif ($prefix eq 'exttool') {
2453: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
2454: } else {
2455: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
2456: }
2457: if ($error) {
2458: $errtext .= '<br />'.$error;
2459: }
2460: } else {
2461: #need to copy the db contents to a new one.
2462: my %contents=&Apache::lonnet::dump($db_name,
2463: $dbref->{'cdom'},
2464: $dbref->{'cnum'});
2465: my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
2466: if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
2467: if ($contents{'id'} =~ /^(|c)(\d+)$/) {
2468: $oldtoolid = $2;
2469: if ($1 eq 'c') {
2470: $defincrs = 1;
2471: %toolinfo =
2472: &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
2473: } else {
2474: %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
2475: }
2476: if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
2477: if ($toolinfo{$oldtoolid}{'passback'}) {
2478: $toolpassback = 1;
2479: }
2480: if ($toolinfo{$oldtoolid}{'roster'}) {
2481: $toolroster = 1;
2482: }
2483: } else {
2484: $toolcopyerror = 1;
2485: $errtext = &mt('Could not retrieve original settings for pasted external tool.');
2486: }
2487: }
2488: unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
2489: $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
2490: if ($contents{'crstitle'} ne '') {
2491: $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
2492: }
2493: if (($defincrs) && (!$toolcopyerror)) {
2494: my %newtool;
2495: my $oldcdom = $dbref->{'cdom'};
2496: my $oldcnum = $dbref->{'cnum'};
2497: my $title = $toolinfo{$oldtoolid}{'title'};
2498: if (ref($currltititles) eq 'HASH') {
2499: if (exists($currltititles->{$title})) {
2500: $title .= ' (copied from another course)';
2501: }
2502: }
2503: my ($newid,$iderror) =
2504: &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
2505: if ($newid =~ /^\d+$/) {
2506: %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
2507: $newtool{$newid}{'title'} = $title;
2508: if (ref($currltimax)) {
2509: $newtool{$newid}{'order'} = $$currltimax;
2510: }
2511: if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
2512: my $fname = $1;
2513: my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
2514: if ($content eq '-1') {
2515: delete($newtool{$newid}{'image'});
2516: } else {
2517: $env{'form.'.$suffix.'.image'} = $content;
2518: my $newlogo =
2519: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
2520: delete($env{'form.'.$suffix.'.image'});
2521: if ($newlogo =~ m{^/uploaded/}) {
2522: $newtool{$newid}{'image'} = $newlogo;
2523: } else {
2524: delete($newtool{$newid}{'image'});
2525: }
2526: }
2527: }
2528: my $newusable;
2529: if ($same_institution) {
2530: my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
2531: if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
2532: my %newtoolsenc;
2533: %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
2534: my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
2535: if ($putres eq 'ok') {
2536: if (ref($updatetoolsenc) eq 'ARRAY') {
2537: my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
2538: unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
2539: push(@{$updatetoolsenc},$newhome);
2540: }
2541: }
2542: $newusable = 1;
2543: }
2544: }
2545: }
2546: if ($newtool{$newid}{'usable'}) {
2547: unless ($newusable) {
2548: delete($newtool{$newid}{'usable'});
2549: }
2550: }
2551: my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
2552: if ($putres eq 'ok') {
2553: $contents{'id'} = "c$newid";
2554: if (ref($updatetoolscache)) {
2555: $$updatetoolscache ++;
2556: }
2557: if (ref($currltititles->{$title}) eq 'ARRAY') {
2558: push(@{$currltititles->{$title}},$newid);
2559: } else {
2560: $currltititles->{$title} = [$newid];
2561: }
2562: if (ref($currltimax)) {
2563: $$currltimax ++;
2564: }
2565: } else {
2566: $toolcopyerror = 1;
2567: $errtext = &mt('Unable to save external tool definition in Course Settings.');
2568: }
2569: } else {
2570: $toolcopyerror = 1;
2571: $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
2572: }
2573: }
2574: }
2575: }
2576: if (exists($contents{'uploaded.photourl'})) {
2577: my $photo = $contents{'uploaded.photourl'};
2578: my ($subdir,$fname) =
2579: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2580: my $newphoto;
2581: if ($fname ne '') {
2582: my $content = &Apache::lonnet::getfile($photo);
2583: unless ($content eq '-1') {
2584: $env{'form.'.$suffix.'.photourl'} = $content;
2585: $newphoto =
2586: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2587: delete($env{'form.'.$suffix.'.photourl'});
2588: }
2589: }
2590: if ($newphoto =~ m{^/uploaded/}) {
2591: $contents{'uploaded.photourl'} = $newphoto;
2592: }
2593: }
2594: $db_name =~ s{_\d*$ }{_$suffix}x;
2595: if ($prefix eq 'exttool') {
2596: unless ($toolcopyerror) {
2597: foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
2598: if (exists($contents{$key})) {
2599: delete($contents{$key});
2600: }
2601: }
2602: if ($dbref->{'delgradable'}) {
2603: if (exists($contents{'gradable'})) {
2604: delete($contents{'gradable'});
2605: }
2606: }
2607: if ($toolpassback) {
2608: if ($contents{'gradable'}) {
2609: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
2610: $contents{'gradesecret'} = $gradesecret;
2611: $contents{'gradesecretdate'} = time;
2612: }
2613: }
2614: if ($toolroster) {
2615: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
2616: $contents{'rostersecret'} = $rostersecret;
2617: $contents{'rostersecretdate'} = time;
2618: }
2619: }
2620: }
2621: if (($prefix eq 'exttool') && ($toolcopyerror)) {
2622: $result = 'error';
2623: } else {
2624: $result=&Apache::lonnet::put($db_name,\%contents,
2625: $coursedom,$coursenum);
2626: if ($result eq 'ok') {
2627: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
2628: }
2629: }
2630: }
2631: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2632: $lockerrorsref->{$prefix} =
2633: '<div class="LC_error">'.
2634: &mt('There was a problem removing a lockfile.');
2635: if ($prefix eq 'smppg') {
2636: $lockerrorsref->{$prefix} .=
2637: ' '.&mt('This will prevent creation of additional simple pages in this course.');
2638: } elsif ($prefix eq 'exttool') {
2639: $lockerrorsref->{$prefix} .=
2640: ' '.&mt('This will prevent addition of more external tools to this course.');
2641: } else {
2642: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
2643: }
2644: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2645: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2646: '</div>';
2647: }
2648: }
2649: } elsif ($url =~ m{/syllabus$}) {
2650: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2651: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2652: if (($dbref->{'cdom'} ne $coursedom) ||
2653: ($dbref->{'cnum'} ne $coursenum)) {
2654: my %contents=&Apache::lonnet::dump('syllabus',
2655: $dbref->{'cdom'},
2656: $dbref->{'cnum'});
2657: $result=&Apache::lonnet::put('syllabus',\%contents,
2658: $coursedom,$coursenum);
2659: }
2660: }
2661: }
2662: }
2663: return ($url,$result,$errtext);
2664: }
2665:
2666: sub copy_templated_files {
2667: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2668: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2669: my $srccontainer = 'sequence';
2670: if ($srcwaspage) {
2671: $srccontainer = 'page';
2672: }
2673: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2674: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2675: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2676: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2677: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2678: $template.'.problem';
2679: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2680: if ($template eq 'simpleproblem') {
2681: $srcprefix .= '.0.';
2682: my $weightprefix = $newprefix;
2683: $newprefix .= '.0.';
2684: my @simpleprobqtypes = qw(radio option string essay numerical);
2685: my $qtype=$srcparms{$srcprefix.'questiontype'};
2686: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2687: my %newdata = (
2688: $newprefix.'questiontype' => $qtype,
2689: );
2690: foreach my $type (@simpleprobqtypes) {
2691: if ($type eq $qtype) {
2692: $newdata{"$weightprefix.$type.weight"}=1;
2693: } else {
2694: $newdata{"$weightprefix.$type.weight"}=0;
2695: }
2696: }
2697: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2698: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2699: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2700: if ($qtype eq 'numerical') {
2701: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2702: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2703: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2704: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2705: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2706: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2707: unless (defined($maxfoils)) { $maxfoils=10; }
2708: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2709: if ($maxfoils<=0) { $maxfoils=10; }
2710: my $randomize=$srcparms{$srcprefix.'randomize'};
2711: unless (defined($randomize)) { $randomize='yes'; }
2712: unless ($randomize eq 'no') { $randomize='yes'; }
2713: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2714: $newdata{$newprefix.'randomize'} = $randomize;
2715: if ($qtype eq 'option') {
2716: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2717: }
2718: for (my $i=1; $i<=10; $i++) {
2719: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2720: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2721: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2722: }
2723:
2724: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2725: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2726: unless (defined($maxfoils)) { $maxfoils=10; }
2727: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2728: if ($maxfoils<=0) { $maxfoils=10; }
2729: my $randomize=$srcparms{$srcprefix.'randomize'};
2730: unless (defined($randomize)) { $randomize='yes'; }
2731: unless ($randomize eq 'no') { $randomize='yes'; }
2732: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2733: $newdata{$newprefix.'randomize'} = $randomize;
2734: if ($qtype eq 'option') {
2735: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2736: }
2737: for (my $i=1; $i<=10; $i++) {
2738: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2739: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2740: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2741: }
2742: } elsif ($qtype eq 'string') {
2743: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2744: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2745: }
2746: if (keys(%newdata)) {
2747: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2748: $coursenum);
2749: if ($putres eq 'ok') {
2750: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2751: }
2752: }
2753: }
2754: }
2755: }
2756:
2757: sub uniqueness_check {
2758: my ($newurl) = @_;
2759: my $unique = 1;
2760: foreach my $res (@LONCAPA::map::order) {
2761: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2762: $url=&LONCAPA::map::qtescape($url);
2763: if ($newurl eq $url) {
2764: $unique = 0;
2765: last;
2766: }
2767: }
2768: return $unique;
2769: }
2770:
2771: sub contained_map_check {
2772: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2773: $hierarchy,$titles,$allmaps) = @_;
2774: my $content = &Apache::lonnet::getfile($url);
2775: unless ($content eq '-1') {
2776: my $parser = HTML::TokeParser->new(\$content);
2777: $parser->attr_encoded(1);
2778: while (my $token = $parser->get_token) {
2779: next if ($token->[0] ne 'S');
2780: if ($token->[1] eq 'resource') {
2781: next if ($token->[2]->{'type'} eq 'zombie');
2782: my $ressrc = $token->[2]->{'src'};
2783: if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2784: my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
2785: unless ($srcdom eq $coursedom) {
2786: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2787: next;
2788: }
2789: unless ($srcnum eq $coursenum) {
2790: my %toolsettings =
2791: &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
2792: my %tooltypes = &Apache::loncommon::usable_exttools();
2793: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2794: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2795: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2796: next;
2797: }
2798: }
2799: } elsif ($folder =~ /^supplemental/) {
2800: unless (&supp_pasteable($ressrc)) {
2801: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2802: next;
2803: }
2804: }
2805: if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
2806: my ($srcdom,$srcnum) = ($1,$2);
2807: unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
2808: if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
2809: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2810: next;
2811: }
2812: }
2813: }
2814: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2815: if ($1 eq 'uploaded') {
2816: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2817: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2818: } else {
2819: if ($allmaps->{$ressrc}) {
2820: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2821: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2822: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2823: } else {
2824: $addedmaps->{$ressrc} = [$url];
2825: }
2826: }
2827: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2828: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
2829: }
2830: } elsif ($token->[1] eq 'param') {
2831: if ($folder =~ /^supplemental/) {
2832: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2833: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2834: } else {
2835: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2836: }
2837: }
2838: }
2839: }
2840: }
2841: return;
2842: }
2843:
2844: sub url_paste_fixups {
2845: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2846: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
2847: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
2848: my $checktitle;
2849: if (($prefixchg) &&
2850: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2851: $checktitle = 1;
2852: }
2853: my $skip;
2854: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2855: my $mapid = $1.$2;
2856: if ($tomove->{$mapid}) {
2857: $skip = 1;
2858: }
2859: }
2860: my $file = &Apache::lonnet::getfile($oldurl);
2861: return if ($file eq '-1');
2862: my $parser = HTML::TokeParser->new(\$file);
2863: $parser->attr_encoded(1);
2864: my $changed = 0;
2865: while (my $token = $parser->get_token) {
2866: next if ($token->[0] ne 'S');
2867: if ($token->[1] eq 'resource') {
2868: my $ressrc = $token->[2]->{'src'};
2869: next if ($ressrc eq '');
2870: my $id = $token->[2]->{'id'};
2871: my $title = $token->[2]->{'title'};
2872: if ($checktitle) {
2873: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2874: $retitles->{$oldurl}{$id} = $ressrc;
2875: }
2876: }
2877: next if ($token->[2]->{'type'} eq 'external');
2878: if ($token->[2]->{'type'} eq 'zombie') {
2879: next if ($skip);
2880: $zombies->{$oldurl}{$id} = $ressrc;
2881: $changed = 1;
2882: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2883: my $srcdom = $1;
2884: my $srcnum = $2;
2885: my $rem = $3;
2886: my $newurl;
2887: my $mapname;
2888: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2889: my $prefix = $1;
2890: $mapname = $prefix.$2;
2891: if ($tomove->{$mapname}) {
2892: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2893: $srcdom,$srcnum,$allmaps,$rewrites,
2894: $retitles,$copies,$dbcopies,$zombies,
2895: $params,$mapmoves,$mapchanges,$tomove,
2896: $newsubdir,$newurls,$resdatacopy);
2897: next;
2898: } else {
2899: ($newurl,my $error) =
2900: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2901: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2902: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2903: $newsubdir->{$ressrc} = $1;
2904: }
2905: if ($error) {
2906: next;
2907: }
2908: }
2909: }
2910: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2911: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2912:
2913: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2914: $rewrites->{$oldurl}{$id} = $ressrc;
2915: $mapchanges->{$ressrc} = 1;
2916: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2917: $cnum,$srcdom,$srcnum,$allmaps,
2918: $rewrites,$retitles,$copies,$dbcopies,
2919: $zombies,$params,$mapmoves,$mapchanges,
2920: $tomove,$newsubdir,$newurls,$resdatacopy)) {
2921: $mapmoves->{$ressrc} = 1;
2922: }
2923: $changed = 1;
2924: } else {
2925: $rewrites->{$oldurl}{$id} = $ressrc;
2926: $copies->{$oldurl}{$ressrc} = $id;
2927: $changed = 1;
2928: }
2929: }
2930: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
2931: next if ($skip);
2932: my $srcdom = $1;
2933: my $srcnum = $2;
2934: my $rem = $3;
2935: my ($is_exttool,$exttoolchg);
2936: if ($rem =~ m{\d+/ext\.tool$}) {
2937: $is_exttool = 1;
2938: }
2939: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2940: $rewrites->{$oldurl}{$id} = $ressrc;
2941: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2942: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2943: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2944: $changed = 1;
2945: if ($is_exttool) {
2946: $exttoolchg = 1;
2947: }
2948: } elsif (($is_exttool) &&
2949: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2950: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2951: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2952: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2953: $changed = 1;
2954: $exttoolchg = 1;
2955: }
2956: if (($is_exttool) && ($prefixchg)) {
2957: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2958: if ($exttoolchg) {
2959: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2960: }
2961: }
2962: }
2963: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2964: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2965: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2966: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2967: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2968: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
2969: $changed = 1;
2970: }
2971: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2972: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2973: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2974: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2975: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2976: }
2977: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2978: next if ($skip);
2979: my $srcdom = $1;
2980: my $srcnum = $2;
2981: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2982: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2983: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2984: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2985: $changed = 1;
2986: }
2987: }
2988: } elsif ($token->[1] eq 'param') {
2989: next if ($skip);
2990: my $to = $token->[2]->{'to'};
2991: if ($to ne '') {
2992: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2993: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2994: } else {
2995: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2996: }
2997: }
2998: }
2999: }
3000: return $changed;
3001: }
3002:
3003: sub apply_fixups {
3004: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
3005: $oldurl,$url,$caller) = @_;
3006: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
3007: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
3008: %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
3009: %currltititles,$currltimax);
3010: $currltimax = 0;
3011: if (ref($updated) eq 'HASH') {
3012: if (ref($updated->{'rewrites'}) eq 'HASH') {
3013: %rewrites = %{$updated->{'rewrites'}};
3014: }
3015: if (ref($updated->{'zombies'}) eq 'HASH') {
3016: %zombies = %{$updated->{'zombies'}};
3017: }
3018: if (ref($updated->{'removefrommap'}) eq 'HASH') {
3019: %removefrommap = %{$updated->{'removefrommap'}};
3020: }
3021: if (ref($updated->{'removeparam'}) eq 'HASH') {
3022: %removeparam = %{$updated->{'removeparam'}};
3023: }
3024: if (ref($updated->{'dbcopies'}) eq 'HASH') {
3025: %dbcopies = %{$updated->{'dbcopies'}};
3026: }
3027: if (ref($updated->{'retitles'}) eq 'HASH') {
3028: %retitles = %{$updated->{'retitles'}};
3029: }
3030: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
3031: %resdatacopy = %{$updated->{'resdatacopy'}};
3032: }
3033: }
3034: if (ref($info) eq 'HASH') {
3035: if (ref($info->{'newsubdir'}) eq 'HASH') {
3036: %newsubdir = %{$info->{'newsubdir'}};
3037: }
3038: if (ref($info->{'params'}) eq 'HASH') {
3039: %params = %{$info->{'params'}};
3040: }
3041: if (ref($info->{'before'}) eq 'HASH') {
3042: %before = %{$info->{'before'}};
3043: }
3044: if (ref($info->{'after'}) eq 'HASH') {
3045: %after = %{$info->{'after'}};
3046: }
3047: }
3048: if (ref($moves) eq 'HASH') {
3049: if (ref($moves->{'copies'}) eq 'HASH') {
3050: %copies = %{$moves->{'copies'}};
3051: }
3052: if (ref($moves->{'docmoves'}) eq 'HASH') {
3053: %docmoves = %{$moves->{'docmoves'}};
3054: }
3055: if (ref($moves->{'mapmoves'}) eq 'HASH') {
3056: %mapmoves = %{$moves->{'mapmoves'}};
3057: }
3058: }
3059: foreach my $key (keys(%copies),keys(%docmoves)) {
3060: my @allcopies;
3061: if (exists($copies{$key})) {
3062: if (ref($copies{$key}) eq 'HASH') {
3063: my %added;
3064: foreach my $innerkey (keys(%{$copies{$key}})) {
3065: if (($innerkey ne '') && (!$added{$innerkey})) {
3066: push(@allcopies,$innerkey);
3067: $added{$innerkey} = 1;
3068: }
3069: }
3070: undef(%added);
3071: }
3072: }
3073: if ($key eq $oldurl) {
3074: if ((exists($docmoves{$key}))) {
3075: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
3076: push(@allcopies,$oldurl);
3077: }
3078: }
3079: }
3080: if (@allcopies > 0) {
3081: foreach my $item (@allcopies) {
3082: my ($relpath,$oldsubdir,$fname) =
3083: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
3084: if ($fname ne '') {
3085: my $content = &Apache::lonnet::getfile($item);
3086: unless ($content eq '-1') {
3087: my $storefn;
3088: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
3089: $storefn = $docmoves{$key};
3090: } else {
3091: $storefn = $relpath;
3092: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
3093: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
3094: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
3095: }
3096: if ($newsubdir{$key}) {
3097: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
3098: }
3099: }
3100: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
3101: my $copyurl =
3102: &Apache::lonclonecourse::writefile($env{'request.course.id'},
3103: $storefn.$fname,$content);
3104: if ($copyurl eq '/adm/notfound.html') {
3105: if (exists($docmoves{$oldurl})) {
3106: return &mt('Paste failed: an error occurred copying the file.');
3107: } elsif (ref($errors) eq 'HASH') {
3108: $errors->{$item} = 1;
3109: }
3110: }
3111: }
3112: }
3113: }
3114: }
3115: }
3116: foreach my $key (keys(%mapmoves)) {
3117: my $storefn=$key;
3118: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3119: if ($prefixchg && $before{'map'} && $after{'map'}) {
3120: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
3121: }
3122: if ($newsubdir{$key}) {
3123: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
3124: }
3125: my $mapcontent = &Apache::lonnet::getfile($key);
3126: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
3127: ($after{'map'} eq 'default') &&
3128: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
3129: $mapcontent = '<map>'."\n".
3130: '<resource id="1" src="" type="start" />'."\n".
3131: '<link from="1" to="2" index="1" />'."\n".
3132: '<resource id="2" src="" type="finish" />'."\n".
3133: '</map>';
3134: }
3135: if ($mapcontent eq '-1') {
3136: if (ref($errors) eq 'HASH') {
3137: $errors->{$key} = 1;
3138: }
3139: } else {
3140: my $newmap =
3141: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
3142: $mapcontent);
3143: if ($newmap eq '/adm/notfound.html') {
3144: if (ref($errors) eq 'HASH') {
3145: $errors->{$key} = 1;
3146: }
3147: }
3148: }
3149: }
3150: my %updates;
3151: if ($is_map) {
3152: if (ref($updated) eq 'HASH') {
3153: foreach my $type (keys(%{$updated})) {
3154: if (ref($updated->{$type}) eq 'HASH') {
3155: foreach my $key (keys(%{$updated->{$type}})) {
3156: $updates{$key} = 1;
3157: }
3158: }
3159: }
3160: }
3161: my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
3162: foreach my $key (keys(%updates)) {
3163: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
3164: if (ref($rewrites{$key}) eq 'HASH') {
3165: %torewrite = %{$rewrites{$key}};
3166: }
3167: if (ref($retitles{$key}) eq 'HASH') {
3168: %toretitle = %{$retitles{$key}};
3169: }
3170: if (ref($removefrommap{$key}) eq 'HASH') {
3171: %toremove = %{$removefrommap{$key}};
3172: }
3173: if (ref($removeparam{$key}) eq 'HASH') {
3174: %remparam = %{$removeparam{$key}};
3175: }
3176: if (ref($zombies{$key}) eq 'HASH') {
3177: %zombie = %{$zombies{$key}};
3178: }
3179: if (ref($dbcopies{$key}) eq 'HASH') {
3180: foreach my $idx (keys(%{$dbcopies{$key}})) {
3181: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
3182: my $oldurl = $dbcopies{$key}{$idx}{'src'};
3183: my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
3184: my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
3185: my $oldmarker;
3186: if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
3187: $oldmarker = $1;
3188: unless (($gotcrsltitools) ||
3189: (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
3190: my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
3191: if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
3192: unless ($gotcrsltitools) {
3193: %currcrsltitools =
3194: &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
3195: foreach my $item (sort(keys(%currcrsltitools))) {
3196: if (ref($currcrsltitools{$item}) eq 'HASH') {
3197: $currltimax ++;
3198: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
3199: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
3200: } else {
3201: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
3202: }
3203: }
3204: }
3205: $gotcrsltitools = 1;
3206: }
3207: unless ($checkedsameinst) {
3208: my $primary_id = &Apache::lonnet::domain($cdom,'primary');
3209: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3210: if ($intdom ne '') {
3211: my $internet_names =
3212: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
3213: if (ref($internet_names) eq 'ARRAY') {
3214: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
3215: $same_institution = 1;
3216: }
3217: }
3218: }
3219: $checkedsameinst = 1;
3220: }
3221: }
3222: }
3223: }
3224: my ($newurl,$result,$errtext) =
3225: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
3226: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
3227: if ($result eq 'ok') {
3228: $newdb{$idx} = $newurl;
3229: if ($newurl =~ /ext\.tool$/) {
3230: if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
3231: if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
3232: my $newmarker = $1;
3233: unless ($oldmarker eq $newmarker) {
3234: $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
3235: }
3236: }
3237: }
3238: }
3239: } elsif (ref($errors) eq 'HASH') {
3240: $errors->{$key} = 1;
3241: }
3242: push(@msgs,$errtext);
3243: }
3244: }
3245: }
3246: if (ref($resdatacopy{$key}) eq 'HASH') {
3247: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
3248: foreach my $idx (keys(%{$resdatacopy{$key}})) {
3249: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
3250: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
3251: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
3252: my $template = $1;
3253: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
3254: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
3255: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
3256: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
3257: unless ($gotnewmapname) {
3258: ($newmapname) = ($key =~ m{/([^/]+)$});
3259: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
3260: if ($newsubdir{$key}) {
3261: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
3262: }
3263: $gotnewmapname = 1;
3264: }
3265: my $srcmapinfo = $srcfolder.':'.$idx;
3266: if ($srccontainer eq 'page') {
3267: $srcmapinfo .= ':1';
3268: }
3269: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
3270: $cnum,$template,$idx,$newmapname);
3271: }
3272: }
3273: }
3274: }
3275: }
3276: if (ref($params{$key}) eq 'HASH') {
3277: %currparam = %{$params{$key}};
3278: }
3279: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
3280: if ($fatal) {
3281: return ($errtext);
3282: }
3283: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
3284: if (defined($LONCAPA::map::zombies[$i])) {
3285: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
3286: if ($zombie{$i} eq $src) {
3287: undef($LONCAPA::map::zombies[$i]);
3288: }
3289: }
3290: }
3291: my $total = scalar(@LONCAPA::map::order) - 1;
3292: for (my $i=$total; $i>=0; $i--) {
3293: my $idx = $LONCAPA::map::order[$i];
3294: if (defined($LONCAPA::map::resources[$idx])) {
3295: my $changed;
3296: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
3297: if ((exists($toremove{$idx})) &&
3298: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
3299: splice(@LONCAPA::map::order,$i,1);
3300: if (ref($currparam{$idx}) eq 'ARRAY') {
3301: foreach my $name (@{$currparam{$idx}}) {
3302: &LONCAPA::map::delparameter($idx,$name);
3303: }
3304: }
3305: next;
3306: }
3307: my $origsrc = $src;
3308: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
3309: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
3310: $changed = 1;
3311: }
3312: }
3313: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
3314: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
3315: if ($origsrc =~ m{^/uploaded/}) {
3316: if ($prefixchg && $before{'map'} && $after{'map'}) {
3317: if ($src =~ /\.(page|sequence)$/) {
3318: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
3319: } else {
3320: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
3321: }
3322: }
3323: if ($origsrc =~ /\.(page|sequence)$/) {
3324: if ($newsubdir{$origsrc}) {
3325: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
3326: }
3327: } elsif ($newsubdir{$key}) {
3328: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
3329: }
3330: }
3331: $changed = 1;
3332: } elsif ($newdb{$idx} ne '') {
3333: $src = $newdb{$idx};
3334: $changed = 1;
3335: }
3336: if ($changed) {
3337: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
3338: }
3339: }
3340: }
3341: foreach my $idx (keys(%remparam)) {
3342: if (ref($remparam{$idx}) eq 'ARRAY') {
3343: foreach my $name (@{$remparam{$idx}}) {
3344: &LONCAPA::map::delparameter($idx,$name);
3345: }
3346: }
3347: }
3348: if (values(%lockerrors) > 0) {
3349: $lockmsg = join('<br />',values(%lockerrors));
3350: }
3351: my $storefn;
3352: if ($key eq $oldurl) {
3353: $storefn = $url;
3354: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3355: } else {
3356: $storefn = $key;
3357: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3358: if ($prefixchg && $before{'map'} && $after{'map'}) {
3359: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
3360: }
3361: if ($newsubdir{$key}) {
3362: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
3363: }
3364: }
3365: my $report;
3366: if ($folder !~ /^supplemental/) {
3367: $report = 1;
3368: }
3369: (my $outtext,$errtext) =
3370: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3371: if ($errtext) {
3372: if ($caller eq 'paste') {
3373: return (&mt('Paste failed: an error occurred saving the folder or page.'));
3374: }
3375: }
3376: }
3377: if (($updatetoolscache) || (@updatetoolsenc)) {
3378: &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
3379: \@updatetoolsenc);
3380: }
3381: }
3382: return ('ok',\@msgs,$lockmsg);
3383: }
3384:
3385: sub copy_dependencies {
3386: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3387: my $content;
3388: if (ref($contentref)) {
3389: $content = $$contentref;
3390: } else {
3391: $content = &Apache::lonnet::getfile($item);
3392: }
3393: unless ($content eq '-1') {
3394: my $mm = new File::MMagic;
3395: my $mimetype = $mm->checktype_contents($content);
3396: if ($mimetype eq 'text/html') {
3397: my (%allfiles,%codebase,$state);
3398: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3399: if ($res eq 'ok') {
3400: my ($numexisting,$numpathchanges,$existing);
3401: (undef,$numexisting,$numpathchanges,$existing) =
3402: &Apache::loncommon::ask_for_embedded_content(
3403: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3404: {'error_on_invalid_names' => 1,
3405: 'ignore_remote_references' => 1,
3406: 'docs_url' => $item,
3407: 'context' => 'paste'});
3408: if ($numexisting > 0) {
3409: if (ref($existing) eq 'HASH') {
3410: foreach my $dep (keys(%{$existing})) {
3411: my $depfile = $dep;
3412: unless ($depfile =~ m{^\Q$relpath\E}) {
3413: $depfile = $relpath.$dep;
3414: }
3415: my $depcontent = &Apache::lonnet::getfile($depfile);
3416: unless ($depcontent eq '-1') {
3417: my $storedep = $dep;
3418: $storedep =~ s{^\Q$relpath\E}{};
3419: my $dep_url =
3420: &Apache::lonclonecourse::writefile(
3421: $env{'request.course.id'},
3422: $storefn.$storedep,$depcontent);
3423: if ($dep_url eq '/adm/notfound.html') {
3424: if (ref($errors) eq 'HASH') {
3425: $errors->{$depfile} = 1;
3426: }
3427: } else {
3428: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3429: }
3430: }
3431: }
3432: }
3433: }
3434: }
3435: }
3436: }
3437: return;
3438: }
3439:
3440: my %parameter_type = ( 'randompick' => 'int_pos',
3441: 'hiddenresource' => 'string_yesno',
3442: 'encrypturl' => 'string_yesno',
3443: 'randomorder' => 'string_yesno',);
3444: my $valid_parameters_re = join('|',keys(%parameter_type));
3445: # set parameters
3446: sub update_parameter {
3447: if ($env{'form.changeparms'} eq 'all') {
3448: my (@allidx,@allmapidx,%allchecked,%currchecked);
3449: %allchecked = (
3450: 'hiddenresource' => {},
3451: 'encrypturl' => {},
3452: 'randompick' => {},
3453: 'randomorder' => {},
3454: );
3455: foreach my $which (keys(%allchecked)) {
3456: $env{'form.all'.$which} =~ s/,$//;
3457: if ($which eq 'randompick') {
3458: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3459: my ($res,$value) = split(/:/,$item);
3460: if ($value =~ /^\d+$/) {
3461: $allchecked{$which}{$res} = $value;
3462: }
3463: }
3464: } else {
3465: if ($env{'form.all'.$which}) {
3466: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3467: }
3468: }
3469: }
3470: my $haschanges = 0;
3471: foreach my $res (@LONCAPA::map::order) {
3472: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3473: $name=&LONCAPA::map::qtescape($name);
3474: $url=&LONCAPA::map::qtescape($url);
3475: next unless $url;
3476: my $is_map;
3477: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3478: $is_map = 1;
3479: }
3480: foreach my $which (keys(%allchecked)) {
3481: if (($which eq 'randompick' || $which eq 'randomorder')) {
3482: next if (!$is_map);
3483: }
3484: my $oldvalue = 0;
3485: my $newvalue = 0;
3486: if ($allchecked{$which}{$res}) {
3487: $newvalue = $allchecked{$which}{$res};
3488: }
3489: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3490: if ($which eq 'randompick') {
3491: if ($current =~ /^(\d+)$/) {
3492: $oldvalue = $1;
3493: }
3494: } else {
3495: if ($current =~ /^yes$/i) {
3496: $oldvalue = 1;
3497: }
3498: }
3499: if ($oldvalue ne $newvalue) {
3500: $haschanges = 1;
3501: if ($newvalue) {
3502: my $storeval = 'yes';
3503: if ($which eq 'randompick') {
3504: $storeval = $newvalue;
3505: }
3506: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3507: $storeval,
3508: $parameter_type{$which});
3509: &remember_parms($res,$which,'set',$storeval);
3510: } elsif ($oldvalue) {
3511: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3512: &remember_parms($res,$which,'del');
3513: }
3514: }
3515: }
3516: }
3517: return $haschanges;
3518: } else {
3519: my $haschanges = 0;
3520: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
3521:
3522: my $which = $env{'form.changeparms'};
3523: my $idx = $env{'form.setparms'};
3524: my $oldvalue = 0;
3525: my $newvalue = 0;
3526: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3527: if ($which eq 'randompick') {
3528: if ($current =~ /^(\d+)$/) {
3529: $oldvalue = $1;
3530: }
3531: } elsif ($current =~ /^yes$/i) {
3532: $oldvalue = 1;
3533: }
3534: if ($env{'form.'.$which.'_'.$idx}) {
3535: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3536: : 1;
3537: }
3538: if ($oldvalue ne $newvalue) {
3539: $haschanges = 1;
3540: if ($newvalue) {
3541: my $storeval = 'yes';
3542: if ($which eq 'randompick') {
3543: $storeval = $newvalue;
3544: }
3545: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3546: $parameter_type{$which});
3547: &remember_parms($idx,$which,'set',$storeval);
3548: } else {
3549: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3550: &remember_parms($idx,$which,'del');
3551: }
3552: }
3553: return $haschanges;
3554: }
3555: }
3556:
3557: sub handle_edit_cmd {
3558: my ($coursenum,$coursedom) =@_;
3559: my $haschanges = 0;
3560: if ($env{'form.cmd'} eq '') {
3561: return $haschanges;
3562: }
3563: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3564:
3565: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3566: my ($title, $url, @rrest) = split(':', $ratstr);
3567:
3568: if ($cmd eq 'remove') {
3569: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3570: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3571: &Apache::lonnet::removeuploadedurl($url);
3572: } else {
3573: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3574: }
3575: splice(@LONCAPA::map::order, $idx, 1);
3576: $haschanges = 1;
3577: } elsif ($cmd eq 'cut') {
3578: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3579: splice(@LONCAPA::map::order, $idx, 1);
3580: $haschanges = 1;
3581: } elsif ($cmd eq 'up'
3582: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3583: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3584: $haschanges = 1;
3585: } elsif ($cmd eq 'down'
3586: && defined($LONCAPA::map::order[$idx+1])) {
3587: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3588: $haschanges = 1;
3589: } elsif ($cmd eq 'rename') {
3590: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3591: if ($comment=~/\S/) {
3592: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3593: $comment.':'.join(':', $url, @rrest);
3594: }
3595: # Devalidate title cache
3596: my $renamed_url=&LONCAPA::map::qtescape($url);
3597: &Apache::lonnet::devalidate_title_cache($renamed_url);
3598: $haschanges = 1;
3599: } elsif ($cmd eq 'setalias') {
3600: my $newvalue = $env{'form.alias'};
3601: if ($newvalue ne '') {
3602: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3603: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3604: 'string');
3605: &remember_parms($idx,'mapalias','set',$newvalue);
3606: $haschanges = 1;
3607: }
3608: }
3609: } elsif ($cmd eq 'delalias') {
3610: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3611: if ($current ne '') {
3612: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3613: &remember_parms($idx,'mapalias','del');
3614: $haschanges = 1;
3615: }
3616: }
3617: return $haschanges;
3618: }
3619:
3620: sub editor {
3621: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
3622: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3623: $canedit,$hostname,$navmapref,$hiddentop)=@_;
3624: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3625: if ($allowed) {
3626: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3627: $is_random_order,$container) =
3628: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3629: $r->print($breadcrumbtrail);
3630: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3631: $container = 'page';
3632: } else {
3633: $container = 'sequence';
3634: }
3635:
3636: my $jumpto;
3637:
3638: unless ($supplementalflag) {
3639: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
3640: }
3641:
3642: unless ($allowed) {
3643: $randompick = -1;
3644: }
3645:
3646: my ($errtext,$fatal);
3647: if (($folder eq '') && (!$supplementalflag)) {
3648: if (@LONCAPA::map::order) {
3649: undef(@LONCAPA::map::order);
3650: undef(@LONCAPA::map::resources);
3651: undef(@LONCAPA::map::resparms);
3652: undef(@LONCAPA::map::zombies);
3653: }
3654: $folder = 'default';
3655: $container = 'sequence';
3656: } else {
3657: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3658: $folder.'.'.$container);
3659: return $errtext if ($fatal);
3660: }
3661:
3662: if ($#LONCAPA::map::order<1) {
3663: my $idx=&LONCAPA::map::getresidx();
3664: if ($idx<=0) { $idx=1; }
3665: $LONCAPA::map::order[0]=$idx;
3666: $LONCAPA::map::resources[$idx]='';
3667: }
3668:
3669: # ------------------------------------------------------------ Process commands
3670:
3671: # ---------------- if they are for this folder and user allowed to make changes
3672: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
3673: # set parameters and change order
3674: &snapshotbefore();
3675:
3676: if (&update_parameter()) {
3677: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3678: return $errtext if ($fatal);
3679: }
3680:
3681: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3682: # change order
3683: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3684: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3685:
3686: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3687: return $errtext if ($fatal);
3688: }
3689:
3690: if ($env{'form.pastemarked'}) {
3691: my %paste_errors;
3692: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
3693: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3694: \%paste_errors);
3695: if (ref($pastemsgarray) eq 'ARRAY') {
3696: if (@{$pastemsgarray} > 0) {
3697: $r->print('<p class="LC_info">'.
3698: join('<br />',@{$pastemsgarray}).
3699: '</p>');
3700: }
3701: }
3702: if ($lockerror) {
3703: $r->print('<p class="LC_error">'.
3704: $lockerror.
3705: '</p>');
3706: }
3707: if ($save_error ne '') {
3708: return $save_error;
3709: }
3710: if ($paste_res) {
3711: my %errortext = &Apache::lonlocal::texthash (
3712: fail => 'Storage of folder contents failed',
3713: failread => 'Reading folder contents failed',
3714: failstore => 'Storage of folder contents failed',
3715: );
3716: if ($errortext{$paste_res}) {
3717: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
3718: }
3719: }
3720: if (keys(%paste_errors) > 0) {
3721: $r->print('<p class="LC_warning">'."\n".
3722: &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".
3723: '<ul>'."\n");
3724: foreach my $key (sort(keys(%paste_errors))) {
3725: $r->print('<li>'.$key.'</li>'."\n");
3726: }
3727: $r->print('</ul></p>'."\n");
3728: }
3729: } elsif ($env{'form.clearmarked'}) {
3730: my $output = &do_buffer_empty();
3731: if ($output) {
3732: $r->print('<p class="LC_info">'.$output.'</p>');
3733: }
3734: }
3735:
3736: $r->print($upload_output);
3737:
3738: # Rename, cut, copy or remove a single resource
3739: if (&handle_edit_cmd($coursenum,$coursedom)) {
3740: my $contentchg;
3741: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
3742: $contentchg = 1;
3743: }
3744: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
3745: return $errtext if ($fatal);
3746: }
3747:
3748: # Cut, copy and/or remove multiple resources
3749: if ($env{'form.multichange'}) {
3750: my %allchecked = (
3751: cut => {},
3752: remove => {},
3753: );
3754: my $needsupdate;
3755: foreach my $which (keys(%allchecked)) {
3756: $env{'form.multi'.$which} =~ s/,$//;
3757: if ($env{'form.multi'.$which}) {
3758: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3759: if (ref($allchecked{$which}) eq 'HASH') {
3760: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3761: }
3762: }
3763: }
3764: if ($needsupdate) {
3765: my $haschanges = 0;
3766: my %curr_groups = &Apache::longroup::coursegroups();
3767: my $total = scalar(@LONCAPA::map::order) - 1;
3768: for (my $i=$total; $i>=0; $i--) {
3769: my $res = $LONCAPA::map::order[$i];
3770: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3771: $name=&LONCAPA::map::qtescape($name);
3772: $url=&LONCAPA::map::qtescape($url);
3773: next unless $url;
3774: my %denied =
3775: &action_restrictions($coursenum,$coursedom,$url,
3776: $env{'form.folderpath'},\%curr_groups);
3777: foreach my $which (keys(%allchecked)) {
3778: next if ($denied{$which});
3779: next unless ($allchecked{$which}{$res});
3780: if ($which eq 'remove') {
3781: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3782: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3783: &Apache::lonnet::removeuploadedurl($url);
3784: } else {
3785: &LONCAPA::map::makezombie($res);
3786: }
3787: splice(@LONCAPA::map::order,$i,1);
3788: $haschanges ++;
3789: } elsif ($which eq 'cut') {
3790: &LONCAPA::map::makezombie($res);
3791: splice(@LONCAPA::map::order,$i,1);
3792: $haschanges ++;
3793: }
3794: }
3795: }
3796: if ($haschanges) {
3797: ($errtext,$fatal) =
3798: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3799: return $errtext if ($fatal);
3800: }
3801: }
3802: }
3803:
3804: # Group import/search
3805: if ($env{'form.importdetail'}) {
3806: my @imports;
3807: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3808: if (defined($item)) {
3809: my ($name,$url,$residx)=
3810: map { &unescape($_); } split(/\=/,$item);
3811: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3812: my ($suffix,$errortxt,$locknotfreed) =
3813: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
3814: if ($locknotfreed) {
3815: $r->print($locknotfreed);
3816: }
3817: if ($suffix) {
3818: $url =~ s/_new\./_$suffix./;
3819: } else {
3820: return $errortxt;
3821: }
3822: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3823: my $type = $1;
3824: my ($suffix,$errortxt,$locknotfreed) =
3825: &new_timebased_suffix($coursedom,$coursenum,$type);
3826: if ($locknotfreed) {
3827: $r->print($locknotfreed);
3828: }
3829: if ($suffix) {
3830: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3831: } else {
3832: return $errortxt;
3833: }
3834: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3835: my ($suffix,$errortxt,$locknotfreed) =
3836: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3837: if ($locknotfreed) {
3838: $r->print($locknotfreed);
3839: }
3840: if ($suffix) {
3841: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3842: } else {
3843: return $errortxt;
3844: }
3845: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3846: if ($supplementalflag) {
3847: next unless ($1 eq 'supplemental');
3848: if ($folder eq 'supplemental') {
3849: next unless ($2 eq 'default');
3850: } else {
3851: next unless ($folder eq 'supplemental_'.$2);
3852: }
3853: } else {
3854: next unless ($1 eq 'docs');
3855: if ($folder eq 'default') {
3856: next unless ($2 eq 'default');
3857: } else {
3858: next unless ($folder eq 'default_'.$2);
3859: }
3860: }
3861: }
3862: push(@imports, [$name, $url, $residx]);
3863: }
3864: }
3865: ($errtext,$fatal,my $fixuperrors) =
3866: &group_import($coursenum, $coursedom, $folder,$container,
3867: 'londocs',$ltitoolsref,@imports);
3868: return $errtext if ($fatal);
3869: if ($fixuperrors) {
3870: $r->print($fixuperrors);
3871: }
3872: }
3873: # Loading a complete map
3874: if ($env{'form.loadmap'}) {
3875: if ($env{'form.importmap'}=~/\w/) {
3876: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3877: my ($title,$url,$ext,$type)=split(/\:/,$res);
3878: my $idx=&LONCAPA::map::getresidx($url);
3879: $LONCAPA::map::resources[$idx]=$res;
3880: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3881: }
3882: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3883: $folder.'.'.$container,1);
3884: return $errtext if ($fatal);
3885: } else {
3886: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
3887:
3888: }
3889: }
3890: &log_differences($plain);
3891: }
3892: # ---------------------------------------------------------------- End commands
3893: # ---------------------------------------------------------------- Print screen
3894: my $idx=0;
3895: my $shown=0;
3896: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
3897: $r->print('<div class="LC_Box">'.
3898: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3899: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3900: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3901: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3902: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
3903: '</ol>');
3904: if ($randompick>=0) {
3905: $r->print('<p class="LC_warning">'
3906: .&mt('Caution: this folder is set to randomly pick a subset'
3907: .' of resources. Adding or removing resources from this'
3908: .' folder will change the set of resources that the'
3909: .' students see, resulting in spurious or missing credit'
3910: .' for completed problems, not limited to ones you'
3911: .' modify. Do not modify the contents of this folder if'
3912: .' it is in active student use.')
3913: .'</p>'
3914: );
3915: }
3916: if ($is_random_order) {
3917: $r->print('<p class="LC_warning">'
3918: .&mt('Caution: this folder is set to randomly order its'
3919: .' contents. Adding or removing resources from this folder'
3920: .' will change the order of resources shown.')
3921: .'</p>'
3922: );
3923: }
3924: $r->print('</div>');
3925: }
3926:
3927: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
3928: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
3929: if (ref($supplemental) eq 'HASH') {
3930: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
3931: (ref($supplemental->{'ids'}) eq 'HASH')) {
3932: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
3933: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
3934: if ($supplemental->{'hidden'}->{$mapnum}) {
3935: $ishidden = 1;
3936: }
3937: }
3938: }
3939: }
3940: }
3941:
3942: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3943: %filters = (
3944: canremove => [],
3945: cancut => [],
3946: cancopy => [],
3947: hiddenresource => [],
3948: encrypturl => [],
3949: randomorder => [],
3950: randompick => [],
3951: );
3952: %curr_groups = &Apache::longroup::coursegroups();
3953: &Apache::loncommon::start_data_table_count(); #setup a row counter
3954: foreach my $res (@LONCAPA::map::order) {
3955: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3956: $name=&LONCAPA::map::qtescape($name);
3957: $url=&LONCAPA::map::qtescape($url);
3958: unless ($name) { $name=(split(/\//,$url))[-1]; }
3959: unless ($name) { $idx++; next; }
3960: push(@allidx,$res);
3961: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3962: push(@allmapidx,$res);
3963: }
3964:
3965: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
3966: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
3967: $idx++;
3968: next;
3969: }
3970: }
3971: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
3972: $coursenum,$coursedom,$crstype,
3973: $pathitem,$supplementalflag,$container,
3974: \%filters,\%curr_groups,$ltitoolsref,$canedit,
3975: $isencrypted,$ishidden,$navmapref,$hostname);
3976: $idx++;
3977: $shown++;
3978: }
3979: &Apache::loncommon::end_data_table_count();
3980:
3981: my $need_save;
3982: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
3983: my $toolslink;
3984: if ($allowed || $canedit) {
3985: my $helpitem = 'Navigation_Screen';
3986: if (!$allowed) {
3987: $helpitem = 'Supplemental_Navigation';
3988: }
3989: $toolslink = '<table><tr><td>'
3990: .&Apache::loncommon::help_open_menu('Navigation Screen',
3991: $helpitem,undef,'RAT')
3992: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3993: .'<td align="left"><ul id="LC_toolbar">'
3994: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
3995: .'id="LC_content_toolbar_edittoplevel" '
3996: .'class="LC_toolbarItem" '
3997: .'title="'.&mt('Supplemental Content Editor').'">'
3998: .'</a></li></ul></td></tr></table><br />';
3999: }
4000: if ($shown) {
4001: if ($allowed) {
4002: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
4003: .&Apache::loncommon::start_data_table(undef,'contentlist')
4004: .&Apache::loncommon::start_data_table_header_row()
4005: .'<th colspan="2">'.&mt('Move').'</th>'
4006: .'<th colspan="3">'.&mt('Actions').'</th>'
4007: .'<th>'.&mt('Document').'</th>'
4008: .'<th colspan="2">'.&mt('Settings').'</th>'
4009: .&Apache::loncommon::end_data_table_header_row();
4010: if ($folder !~ /^supplemental/) {
4011: $lists{'canhide'} = join(',',@allidx);
4012: $lists{'canrandomlyorder'} = join(',',@allmapidx);
4013: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
4014: 'randomorder','randompick');
4015: foreach my $item (@possfilters) {
4016: if (ref($filters{$item}) eq 'ARRAY') {
4017: if (@{$filters{$item}} > 0) {
4018: $lists{$item} = join(',',@{$filters{$item}});
4019: }
4020: }
4021: }
4022: if (@allidx > 0) {
4023: my $path;
4024: if ($env{'form.folderpath'}) {
4025: $path =
4026: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4027: }
4028: if (@allidx > 1) {
4029: $to_show .=
4030: &Apache::loncommon::continue_data_table_row().
4031: '<td colspan="2"> </td>'.
4032: '<td>'.
4033: &multiple_check_form('actions',\%lists,$canedit).
4034: '</td>'.
4035: '<td colspan="3"> </td>'.
4036: '<td colspan="2">'.
4037: &multiple_check_form('settings',\%lists,$canedit).
4038: '</td>'.
4039: &Apache::loncommon::end_data_table_row();
4040: $need_save = 1;
4041: }
4042: }
4043: }
4044: $to_show .= $output.' '
4045: .&Apache::loncommon::end_data_table()
4046: .'<br style="line-height:2px;" />'
4047: .&Apache::loncommon::end_scrollbox();
4048: } else {
4049: $to_show .= $toolslink
4050: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4051: .$output.' '
4052: .&Apache::loncommon::end_data_table();
4053: }
4054: } else {
4055: if (!$allowed) {
4056: $to_show .= $toolslink;
4057: }
4058: my $noresmsg;
4059: if ($allowed && $hiddentop && !$supplementalflag) {
4060: $noresmsg = &mt('Main Content Hidden');
4061: } else {
4062: $noresmsg = &mt('Currently empty');
4063: }
4064: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
4065: .'<div class="LC_info" id="contentlist">'
4066: .$noresmsg
4067: .'</div>'
4068: .&Apache::loncommon::end_scrollbox();
4069: }
4070: } else {
4071: if ($shown) {
4072: $to_show = '<div>'
4073: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4074: .$output
4075: .&Apache::loncommon::end_data_table()
4076: .'</div>';
4077: } else {
4078: $to_show = '<div class="LC_info" id="contentlist">'
4079: .&mt('Currently empty')
4080: .'</div>'
4081: }
4082: }
4083: my $tid = 1;
4084: if ($supplementalflag) {
4085: $tid = 2;
4086: }
4087: if ($allowed) {
4088: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
4089: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
4090: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
4091: if ($canedit) {
4092: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
4093: }
4094: } else {
4095: $r->print($to_show);
4096: }
4097: return;
4098: }
4099:
4100: sub multiple_check_form {
4101: my ($caller,$listsref,$canedit) = @_;
4102: return unless (ref($listsref) eq 'HASH');
4103: my $disabled;
4104: unless ($canedit) {
4105: $disabled = ' disabled="disabled"';
4106: }
4107: my $output =
4108: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
4109: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
4110: '<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>'.
4111: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
4112: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
4113: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
4114: if ($caller eq 'settings') {
4115: $output .=
4116: '<table><tr>'.
4117: '<td class="LC_docs_entry_parameter">'.
4118: '<span class="LC_nobreak"><label>'.
4119: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
4120: '</label></span></td>'.
4121: '<td class="LC_docs_entry_parameter">'.
4122: '<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="" />'.
4123: '</span></td>'.
4124: '</tr>'."\n".
4125: '<tr>'.
4126: '<td class="LC_docs_entry_parameter">'.
4127: '<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').
4128: '</label></span>'.
4129: '</td></tr></table>'."\n";
4130: } else {
4131: $output .=
4132: '<table><tr>'.
4133: '<td class="LC_docs_entry_parameter">'.
4134: '<span class="LC_nobreak LC_docs_remove">'.
4135: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
4136: '</label></span></td>'.
4137: '<td class="LC_docs_entry_parameter">'.
4138: '<span class="LC_nobreak LC_docs_cut">'.
4139: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
4140: '</label></span></td>'."\n".
4141: '<td class="LC_docs_entry_parameter">'.
4142: '<span class="LC_nobreak LC_docs_copy">'.
4143: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
4144: '</label></span></td>'.
4145: '</tr></table>'."\n";
4146: }
4147: $output .=
4148: '</fieldset>'.
4149: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
4150: if ($caller eq 'settings') {
4151: $output .=
4152: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
4153: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
4154: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
4155: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
4156: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
4157: } elsif ($caller eq 'actions') {
4158: $output .=
4159: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
4160: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
4161: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
4162: }
4163: $output .=
4164: '</form>'.
4165: '</div>';
4166: return $output;
4167: }
4168:
4169: sub process_file_upload {
4170: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
4171: # upload a file, if present
4172: my $filesize = length($env{'form.uploaddoc'});
4173: if (!$filesize) {
4174: $$upload_output = '<div class="LC_error">'.
4175: &mt('Unable to upload [_1]. (size = [_2] bytes)',
4176: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
4177: $filesize).'<br />'.
4178: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
4179: '</div>';
4180: return;
4181: }
4182: my $quotatype = 'unofficial';
4183: if ($crstype eq 'Community') {
4184: $quotatype = 'community';
4185: } elsif ($crstype eq 'Placement') {
4186: $quotatype = 'placement';
4187: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
4188: $quotatype = 'official';
4189: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
4190: $quotatype = 'textbook';
4191: }
4192: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
4193: $filesize = int($filesize/1000); #expressed in kb
4194: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
4195: $env{'form.uploaddoc.filename'},$filesize,
4196: 'upload',$quotatype);
4197: return if ($$upload_output);
4198: }
4199: my ($parseaction,$showupload,$nextphase,$mimetype);
4200: if ($env{'form.parserflag'}) {
4201: $parseaction = 'parse';
4202: }
4203: my $folder=$env{'form.folder'};
4204: if ($folder eq '') {
4205: $folder='default';
4206: }
4207: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
4208: my $errtext='';
4209: my $fatal=0;
4210: my $container='sequence';
4211: if ($env{'form.folderpath'} =~ /:1$/) {
4212: $container='page';
4213: }
4214: ($errtext,$fatal)=
4215: &mapread($coursenum,$coursedom,$folder.'.'.$container);
4216: if ($#LONCAPA::map::order<1) {
4217: $LONCAPA::map::order[0]=1;
4218: $LONCAPA::map::resources[1]='';
4219: }
4220: my $destination = 'docs/';
4221: if ($folder =~ /^supplemental/) {
4222: $destination = 'supplemental/';
4223: }
4224: if (($folder eq 'default') || ($folder eq 'supplemental')) {
4225: $destination .= 'default/';
4226: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
4227: $destination .= $2.'/';
4228: }
4229: if ($fatal) {
4230: $$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>';
4231: return;
4232: }
4233: # this is for a course, not a user, so set context to coursedoc.
4234: my $newidx=&LONCAPA::map::getresidx();
4235: $destination .= $newidx;
4236: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
4237: $parseaction,$allfiles,
4238: $codebase,undef,undef,undef,undef,
4239: undef,undef,\$mimetype);
4240: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
4241: my $stored = $1;
4242: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
4243: $stored.'</span>').'</p>';
4244: } else {
4245: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
4246:
4247: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
4248: return;
4249: }
4250: my $ext='false';
4251: if ($url=~m{^http://}) { $ext='true'; }
4252: $url = &LONCAPA::map::qtunescape($url);
4253: my $comment=$env{'form.comment'};
4254: $comment = &LONCAPA::map::qtunescape($comment);
4255: if ($folder=~/^supplemental/) {
4256: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
4257: $env{'user.domain'}.'___&&&___'.$comment;
4258: }
4259:
4260: $LONCAPA::map::resources[$newidx]=
4261: $comment.':'.$url.':'.$ext.':normal:res';
4262: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
4263: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
4264: $folder.'.'.$container,1);
4265: if ($fatal) {
4266: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
4267: return;
4268: } else {
4269: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
4270: $$upload_output = $showupload;
4271: my $total_embedded = scalar(keys(%{$allfiles}));
4272: if ($total_embedded > 0) {
4273: my $uploadphase = 'upload_embedded';
4274: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
4275: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
4276: my ($embedded,$num) =
4277: &Apache::loncommon::ask_for_embedded_content(
4278: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
4279: if ($embedded) {
4280: if ($num) {
4281: $$upload_output .=
4282: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
4283: $nextphase = $uploadphase;
4284: } else {
4285: $$upload_output .= $embedded;
4286: }
4287: } else {
4288: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
4289: }
4290: } else {
4291: $$upload_output .= &mt('No embedded items identified').'<br />';
4292: }
4293: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
4294: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
4295: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
4296: $nextphase = 'decompress_uploaded';
4297: my $position = scalar(@LONCAPA::map::order)-1;
4298: my $noextract = &return_to_editor();
4299: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
4300: my %archiveitems = (
4301: folderpath => $env{'form.folderpath'},
4302: cmd => $nextphase,
4303: newidx => $newidx,
4304: position => $position,
4305: phase => $nextphase,
4306: comment => $comment,
4307: );
4308: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
4309: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
4310: $$upload_output = $showupload.
4311: &Apache::loncommon::decompress_form($mimetype,
4312: $archiveurl,'/adm/coursedocs',$noextract,
4313: \%archiveitems,\@current);
4314: }
4315: }
4316: }
4317: return $nextphase;
4318: }
4319:
4320: sub get_dir_list {
4321: my ($url,$coursenum,$coursedom,$newidx) = @_;
4322: my ($destination,$dir_root) = &embedded_destination();
4323: my ($dirlistref,$listerror) =
4324: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
4325: my @dir_lines;
4326: my $dirptr=16384;
4327: if (ref($dirlistref) eq 'ARRAY') {
4328: foreach my $dir_line (sort
4329: {
4330: my ($afile)=split('&',$a,2);
4331: my ($bfile)=split('&',$b,2);
4332: return (lc($afile) cmp lc($bfile));
4333: } (@{$dirlistref})) {
4334: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
4335: $filename =~ s/\s+$//;
4336: next if ($filename =~ /^\.\.?$/);
4337: my $isdir = 0;
4338: if ($dirptr&$testdir) {
4339: $isdir = 1;
4340: }
4341: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
4342: }
4343: }
4344: return @dir_lines;
4345: }
4346:
4347: sub is_supplemental_title {
4348: my ($title) = @_;
4349: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
4350: }
4351:
4352: # --------------------------------------------------------------- An entry line
4353:
4354: sub entryline {
4355: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
4356: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
4357: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
4358: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
4359: if (&is_supplemental_title($title)) {
4360: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
4361: $encodedtitle=$title;
4362: } else {
4363: $title=&HTML::Entities::encode($title,'"<>&\'');
4364: $encodedtitle=$title;
4365: $renametitle=$title;
4366: $foldertitle=$title;
4367: }
4368:
4369: my ($disabled,$readonly,$js_lt);
4370: unless ($canedit) {
4371: $disabled = 'disabled="disabled"';
4372: $readonly = 1;
4373: }
4374:
4375: my $orderidx=$LONCAPA::map::order[$index];
4376:
4377: $renametitle=~s/\\/\\\\/g;
4378: $renametitle=~s/\"\;/\\\"/g;
4379: $renametitle=~s/"/%22/g;
4380: $renametitle=~s/ /%20/g;
4381: $oldtitle = $renametitle;
4382: $renametitle=~s/\'/\\\'/g;
4383: my $line=&Apache::loncommon::start_data_table_row();
4384: my ($form_start,$form_end,$form_common,$form_param);
4385: # Edit commands
4386: my ($esc_path, $path, $symb, $shownsymb, $curralias);
4387: if ($env{'form.folderpath'}) {
4388: $esc_path=&escape($env{'form.folderpath'});
4389: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4390: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4391: }
4392: my $isexternal;
4393: if ($residx) {
4394: my $currurl = $url;
4395: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4396: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4397: $isexternal = 1;
4398: }
4399: if (!$supplementalflag) {
4400: my $path = 'uploaded/'.
4401: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4402: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4403: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4404: $residx,
4405: &Apache::lonnet::declutter($currurl));
4406: }
4407: }
4408: my ($renamelink,%lt,$ishash);
4409: if (ref($filtersref) eq 'HASH') {
4410: $ishash = 1;
4411: }
4412:
4413: if ($allowed) {
4414: $form_start = '
4415: <form action="/adm/coursedocs" method="post">
4416: ';
4417: $form_common=(<<END);
4418: <input type="hidden" name="folderpath" value="$path" />
4419: <input type="hidden" name="symb" value="$symb" />
4420: END
4421: $form_param=(<<END);
4422: <input type="hidden" name="setparms" value="$orderidx" />
4423: <input type="hidden" name="changeparms" value="0" />
4424: END
4425: $form_end = '</form>';
4426:
4427: my $incindex=$index+1;
4428: my $selectbox='';
4429: if (($#LONCAPA::map::order>0) &&
4430: ((split(/\:/,
4431: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4432: ne '') &&
4433: ((split(/\:/,
4434: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
4435: ne '')) {
4436: $selectbox=
4437: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
4438: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
4439: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4440: if ($i==$incindex) {
4441: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
4442: } else {
4443: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4444: }
4445: }
4446: $selectbox.='</select>';
4447: }
4448: %lt=&Apache::lonlocal::texthash(
4449: 'up' => 'Move Up',
4450: 'dw' => 'Move Down',
4451: 'rm' => 'Remove',
4452: 'ct' => 'Cut',
4453: 'rn' => 'Rename',
4454: 'cp' => 'Copy',
4455: 'da' => 'Unset alias',
4456: 'sa' => 'Set alias',
4457: 'ex' => 'External Resource',
4458: 'et' => 'External Tool',
4459: 'ed' => 'Edit',
4460: 'pr' => 'Preview',
4461: 'sv' => 'Save',
4462: 'ul' => 'URL',
4463: 'ti' => 'Title',
4464: 'er' => 'Editing rights unavailable for your current role.',
4465: );
4466: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4467: $env{'form.folderpath'},
4468: $currgroups);
4469: my ($copylink,$cutlink,$removelink);
4470: my $skip_confirm = 0;
4471: my $confirm_removal = 0;
4472: if ( $folder =~ /^supplemental/
4473: || ($url =~ m{( /smppg$
4474: |/syllabus$
4475: |/aboutme$
4476: |/navmaps$
4477: |/bulletinboard$
4478: |/ext\.tool$
4479: |\.html$)}x)
4480: || $isexternal) {
4481: $skip_confirm = 1;
4482: }
4483: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4484: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4485: $confirm_removal = 1;
4486: }
4487: if ($url =~ /$LONCAPA::assess_re/) {
4488: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4489: }
4490:
4491: if ($denied{'copy'}) {
4492: $copylink=(<<ENDCOPY)
4493: <span style="visibility: hidden;">$lt{'cp'}</span>
4494: ENDCOPY
4495: } else {
4496: my $formname = 'edit_copy_'.$orderidx;
4497: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
4498: $copylink=(<<ENDCOPY);
4499: <form name="$formname" method="post" action="/adm/coursedocs">
4500: $form_common
4501: <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>
4502: $form_end
4503: ENDCOPY
4504: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4505: push(@{$filtersref->{'cancopy'}},$orderidx);
4506: }
4507: }
4508: if ($denied{'cut'}) {
4509: $cutlink=(<<ENDCUT);
4510: <span style="visibility: hidden;">$lt{'ct'}</span>
4511: ENDCUT
4512: } else {
4513: my $formname = 'edit_cut_'.$orderidx;
4514: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
4515: $cutlink=(<<ENDCUT);
4516: <form name="$formname" method="post" action="/adm/coursedocs">
4517: $form_common
4518: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
4519: <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>
4520: $form_end
4521: ENDCUT
4522: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4523: push(@{$filtersref->{'cancut'}},$orderidx);
4524: }
4525: }
4526: if ($denied{'remove'}) {
4527: $removelink=(<<ENDREM);
4528: <span style="visibility: hidden;">$lt{'rm'}</a>
4529: ENDREM
4530: } else {
4531: my $formname = 'edit_remove_'.$orderidx;
4532: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
4533: $removelink=(<<ENDREM);
4534: <form name="$formname" method="post" action="/adm/coursedocs">
4535: $form_common
4536: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
4537: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
4538: <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>
4539: $form_end
4540: ENDREM
4541: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4542: push(@{$filtersref->{'canremove'}},$orderidx);
4543: }
4544: }
4545: $renamelink=(<<ENDREN);
4546: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
4547: ENDREN
4548: my ($uplink,$downlink);
4549: if ($canedit) {
4550: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4551: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4552: } else {
4553: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4554: $downlink = $uplink;
4555: }
4556: $line.=(<<END);
4557: <td>
4558: <div class="LC_docs_entry_move">
4559: <a href="$uplink">
4560: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
4561: </a>
4562: </div>
4563: <div class="LC_docs_entry_move">
4564: <a href="$downlink">
4565: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
4566: </a>
4567: </div>
4568: </td>
4569: <td>
4570: $form_start
4571: $form_param
4572: $form_common
4573: $selectbox
4574: $form_end
4575: </td>
4576: <td class="LC_docs_entry_commands LC_nobreak">
4577: $removelink
4578: $cutlink
4579: $copylink
4580: </td>
4581: END
4582: }
4583: # Figure out what kind of a resource this is
4584: my ($extension)=($url=~/\.(\w+)$/);
4585: my $uploaded=($url=~/^\/*uploaded\//);
4586: my $icon=&Apache::loncommon::icon($url);
4587: my $isfolder;
4588: my $ispage;
4589: my $containerarg;
4590: my $folderurl;
4591: my $plainurl;
4592: if ($uploaded) {
4593: if (($extension eq 'sequence') || ($extension eq 'page')) {
4594: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
4595: $containerarg = $1;
4596: if ($extension eq 'sequence') {
4597: $icon=$iconpath.'navmap.folder.closed.gif';
4598: $isfolder=1;
4599: } else {
4600: $icon=$iconpath.'page.gif';
4601: $ispage=1;
4602: }
4603: $folderurl = &Apache::lonnet::declutter($url);
4604: if ($allowed) {
4605: $url='/adm/coursedocs?';
4606: } else {
4607: $url='/adm/supplemental?';
4608: }
4609: } else {
4610: $plainurl = $url;
4611: }
4612: }
4613:
4614: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
4615: my $orig_url = $url;
4616: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
4617: if ($container eq 'page') {
4618: $url=~s{^http(|s)(:|:)//}{/ext/};
4619: } else {
4620: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4621: }
4622: if (!$supplementalflag && $residx && $symb) {
4623: if ((!$isfolder) && (!$ispage)) {
4624: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
4625: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4626: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4627: } else {
4628: $url=&Apache::lonnet::clutter($url);
4629: }
4630: if ($url=~/^\/*uploaded\//) {
4631: $url=~/\.(\w+)$/;
4632: my $embstyle=&Apache::loncommon::fileembstyle($1);
4633: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4634: $url='/adm/wrapper'.$url;
4635: } elsif ($embstyle eq 'ssi') {
4636: #do nothing with these
4637: } elsif ($url!~/\.(sequence|page)$/) {
4638: $url='/adm/coursedocs/showdoc'.$url;
4639: }
4640: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4641: my $wrapped = $1;
4642: my $exturl = $2;
4643: if (($wrapped eq '') && ($container ne 'page')) {
4644: $url='/adm/wrapper'.$url;
4645: }
4646: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4647: $nomodal = 1;
4648: }
4649: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4650: $url='/adm/wrapper'.$url;
4651: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4652: if (($ENV{'SERVER_PORT'} == 443) &&
4653: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4654: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
4655: $url .= '?usehttp=1';
4656: }
4657: $nomodal = 1;
4658: }
4659: }
4660: my $checkencrypt;
4661: if (!$env{'request.role.adv'}) {
4662: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4663: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4664: $checkencrypt = 1;
4665: } elsif (ref($navmapref)) {
4666: unless (ref($$navmapref)) {
4667: $$navmapref = Apache::lonnavmaps::navmap->new();
4668: }
4669: if (ref($$navmapref)) {
4670: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4671: $checkencrypt = 1;
4672: }
4673: }
4674: }
4675: }
4676: if ($checkencrypt) {
4677: my $currenc = $env{'request.enc'};
4678: $env{'request.enc'} = 1;
4679: $shownsymb = &Apache::lonenc::encrypted($symb);
4680: my $shownurl = &Apache::lonenc::encrypted($url);
4681: if (&Apache::lonnet::symbverify($symb,$url)) {
4682: $url = $shownurl;
4683: } else {
4684: $url = '';
4685: }
4686: $env{'request.enc'} = $currenc;
4687: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4688: $shownsymb = $symb;
4689: if ($isexternal) {
4690: $url =~ s/\#[^#]+$//;
4691: if ($container eq 'page') {
4692: $url = &Apache::lonnet::clutter($url);
4693: }
4694: }
4695: } else {
4696: $url = '';
4697: }
4698: unless ($env{'request.role.adv'}) {
4699: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4700: $url = '';
4701: }
4702: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4703: $url = '';
4704: $hiddenres = 1;
4705: }
4706: }
4707: if (($url ne '') && ($shownsymb ne '')) {
4708: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
4709: }
4710: }
4711: } elsif ($supplementalflag) {
4712: if ($isexternal) {
4713: if ($url =~ /^([^#]+)#([^#]+)$/) {
4714: $url = $1;
4715: $anchor = $2;
4716: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4717: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
4718: if ($hostname ne '') {
4719: $url = 'http://'.$hostname.$url;
4720: }
4721: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4722: }
4723: $nomodal = 1;
4724: }
4725: }
4726: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4727: if (($ENV{'SERVER_PORT'} == 443) &&
4728: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4729: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
4730: if ($hostname ne '') {
4731: $url = 'http://'.$hostname.$url;
4732: }
4733: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4734: }
4735: $nomodal = 1;
4736: }
4737: } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
4738: my $embstyle=&Apache::loncommon::fileembstyle($extension);
4739: unless ($embstyle eq 'ssi') {
4740: if (($embstyle eq 'img')
4741: || ($embstyle eq 'emb')
4742: || ($embstyle eq 'wrp')) {
4743: $url='/adm/wrapper'.$url;
4744: } elsif ($url !~ /\.(sequence|page)$/) {
4745: $url='/adm/coursedocs/showdoc'.$url;
4746: }
4747: }
4748: }
4749: unless ($allowed && $env{'request.role.adv'}) {
4750: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4751: $hiddenres = 1;
4752: }
4753: }
4754: }
4755: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4756: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
4757: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
4758: my $foldername=&escape($foldertitle);
4759: my $folderpath=$env{'form.folderpath'};
4760: if ($folderpath) { $folderpath.='&' };
4761: if (!$allowed && $supplementalflag) {
4762: $folderpath.=$containerarg.'&'.$foldername;
4763: $url.='folderpath='.&escape($folderpath);
4764: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4765: $hiddenfolder = 1;
4766: }
4767: } else {
4768: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4769: 'parameter_randompick'))[0];
4770: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4771: 'parameter_randomorder'))[0]=~/^yes$/i);
4772: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4773: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4774: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4775: 'parameter_encrypturl'))[0]=~/^yes$/i);
4776: unless ($hiddenmap) {
4777: if (ref($navmapref)) {
4778: unless (ref($$navmapref)) {
4779: $$navmapref = Apache::lonnavmaps::navmap->new();
4780: }
4781: if (ref($$navmapref)) {
4782: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4783: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4784: unless (@resources) {
4785: $hiddenmap = 1;
4786: unless ($env{'request.role.adv'}) {
4787: $url = '';
4788: $hiddenfolder = 1;
4789: }
4790: }
4791: }
4792: }
4793: }
4794: }
4795: unless ($encryptmap) {
4796: if ((ref($navmapref)) && (ref($$navmapref))) {
4797: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4798: $encryptmap = 1;
4799: }
4800: }
4801: }
4802:
4803: # Append randompick number, hidden, and encrypted with ":" to foldername,
4804: # so it gets transferred between levels
4805: $folderpath.=$containerarg.'&'.$foldername.
4806: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4807: unless ($url eq '') {
4808: $url.='folderpath='.&escape($folderpath);
4809: }
4810: my $rpckchk;
4811: if ($rpicknum) {
4812: $rpckchk = ' checked="checked"';
4813: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4814: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4815: }
4816: }
4817: my $formname = 'edit_randompick_'.$orderidx;
4818: $rand_pick_text =
4819: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4820: $form_param."\n".
4821: $form_common."\n".
4822: '<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.'">';
4823: if ($rpicknum ne '') {
4824: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4825: }
4826: $rand_pick_text .= '</span></span>'.
4827: $form_end;
4828: my $ro_set;
4829: if ($randorder) {
4830: $ro_set = 'checked="checked"';
4831: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4832: push(@{$filtersref->{'randomorder'}},$orderidx);
4833: }
4834: }
4835: $formname = 'edit_rorder_'.$orderidx;
4836: $rand_order_text =
4837: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4838: $form_param."\n".
4839: $form_common."\n".
4840: '<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>'.
4841: $form_end;
4842: }
4843: } elsif ($supplementalflag && !$allowed) {
4844: my $isexttool;
4845: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4846: $url='/adm/wrapper'.$url;
4847: $isexttool = 1;
4848: }
4849: $url .= ($url =~ /\?/) ? '&':'?';
4850: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
4851: if ($title) {
4852: $url .= '&title='.$encodedtitle;
4853: }
4854: if ((($isexternal) || ($isexttool)) && $orderidx) {
4855: $url .= '&idx='.$orderidx;
4856: }
4857: if ($anchor ne '') {
4858: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4859: }
4860: }
4861: my ($tdalign,$tdwidth);
4862: if ($allowed) {
4863: my $fileloc =
4864: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
4865: if ($isexternal) {
4866: ($editlink,$extresform) =
4867: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4868: undef,undef,undef,undef,undef,undef,
4869: undef,$disabled);
4870: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4871: ($editlink,$extresform) =
4872: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4873: undef,undef,undef,'tool',$coursedom,
4874: $coursenum,$ltitoolsref,$disabled);
4875: } elsif (!$isfolder && !$ispage) {
4876: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4877: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
4878: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
4879: my $suppanchor;
4880: if ($supplementalflag) {
4881: $suppanchor = $anchor;
4882: }
4883: my $jscall =
4884: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4885: $switchserver,
4886: $forceedit,
4887: undef,$symb,$shownsymb,
4888: &escape($env{'form.folderpath'}),
4889: $renametitle,$hostname,
4890: '','',1,$suppanchor);
4891: if ($jscall) {
4892: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4893: $jscall.'" >'.&mt('Edit').'</a> '."\n";
4894: }
4895: }
4896: }
4897: $tdalign = ' align="right" valign="top"';
4898: $tdwidth = ' width="80%"';
4899: }
4900: my $reinit;
4901: if ($crstype eq 'Community') {
4902: $reinit = &mt('(re-initialize community to access)');
4903: } else {
4904: $reinit = &mt('(re-initialize course to access)');
4905: }
4906: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
4907: if ($orig_url =~ /$LONCAPA::assess_re/) {
4908: $line.= '<br />';
4909: if ($curralias ne '') {
4910: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4911: $lt{'da'}.'</a></span>';
4912: } else {
4913: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4914: $lt{'sa'}.'</a></span>';
4915: }
4916: }
4917: $line.='</td><td><span class="LC_nobreak">';
4918: my ($link,$nolink);
4919: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4920: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
4921: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4922: $nolink = 1;
4923: }
4924: }
4925: if ($nolink) {
4926: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4927: } else {
4928: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4929: }
4930: } elsif ($url) {
4931: if ($anchor ne '') {
4932: if ($supplementalflag) {
4933: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4934: } else {
4935: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4936: }
4937: }
4938: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4939: $link = 'http://'.$hostname.$url;
4940: } else {
4941: $link = $url;
4942: }
4943: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
4944: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
4945: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4946: $nolink = 1;
4947: }
4948: }
4949: if ($nolink) {
4950: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4951: } elsif ($nomodal) {
4952: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4953: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4954: } else {
4955: $line.=&Apache::loncommon::modal_link($link,
4956: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4957: }
4958: } else {
4959: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4960: }
4961: $line.='</span></td><td'.$tdwidth.'>';
4962: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4963: if ($nolink) {
4964: $line.=$title;
4965: } else {
4966: $line.='<a href="'.$url.'">'.$title.'</a>';
4967: }
4968: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4969: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4970: my $editurl = $url;
4971: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4972: $line .= ' '.'<a href="'.$editurl.'">'.
4973: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4974: '</a>';
4975: }
4976: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4977: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4978: }
4979: } elsif ($url) {
4980: if ($nolink) {
4981: $line.=$title;
4982: } elsif ($nomodal) {
4983: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4984: $title.'</a>';
4985: } else {
4986: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4987: }
4988: } elsif (($hiddenfolder) || ($hiddenres)) {
4989: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
4990: } else {
4991: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4992: }
4993: if (($allowed) && ($curralias ne '')) {
4994: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4995: } else {
4996: $line .= $extresform;
4997: }
4998: $line .= '</td>';
4999: $rand_pick_text = ' ' if ($rand_pick_text eq '');
5000: $rand_order_text = ' ' if ($rand_order_text eq '');
5001: if ($uploaded && $url && !$isfolder && !$ispage) {
5002: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
5003: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
5004: }
5005: }
5006: if ($allowed) {
5007: my %lt=&Apache::lonlocal::texthash(
5008: 'hd' => 'Hidden',
5009: 'ec' => 'URL hidden');
5010: my ($enctext,$hidtext,$formhidden,$formurlhidden);
5011: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5012: $hidtext = ' checked="checked"';
5013: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
5014: push(@{$filtersref->{'hiddenresource'}},$orderidx);
5015: }
5016: }
5017: $formhidden = 'edit_hiddenresource_'.$orderidx;
5018: $line.=(<<ENDPARMS);
5019: <td class="LC_docs_entry_parameter">
5020: <form action="/adm/coursedocs" method="post" name="$formhidden">
5021: $form_param
5022: $form_common
5023: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
5024: $form_end
5025: ENDPARMS
5026: if ($folder =~/^supplemental/) {
5027: $line.= "\n <td>";
5028: } else {
5029: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
5030: $enctext = ' checked="checked"';
5031: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
5032: push(@{$filtersref->{'encrypturl'}},$orderidx);
5033: }
5034: }
5035: $formurlhidden = 'edit_encrypturl_'.$orderidx;
5036: $line.=(<<ENDPARMS);
5037: <br />
5038: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
5039: $form_param
5040: $form_common
5041: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
5042: $form_end
5043: </td>
5044: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
5045: $rand_order_text</td>
5046: ENDPARMS
5047: }
5048: }
5049: $line.=&Apache::loncommon::end_data_table_row();
5050: return $line;
5051: }
5052:
5053: sub action_restrictions {
5054: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
5055: my %denied = (
5056: cut => 0,
5057: copy => 0,
5058: remove => 0,
5059: );
5060: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
5061: # no copy for published maps
5062: $denied{'copy'} = 1;
5063: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
5064: unless ($1 eq 'simpleproblem') {
5065: $denied{'copy'} = 1;
5066: }
5067: $denied{'cut'} = 1;
5068: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
5069: if ($folderpath =~ /^default&[^\&]+$/) {
5070: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
5071: $denied{'remove'} = 1;
5072: }
5073: $denied{'cut'} = 1;
5074: $denied{'copy'} = 1;
5075: }
5076: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
5077: my $group = $1;
5078: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
5079: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5080: $denied{'remove'} = 1;
5081: }
5082: }
5083: $denied{'cut'} = 1;
5084: $denied{'copy'} = 1;
5085: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
5086: my $group = $1;
5087: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
5088: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5089: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5090: if (keys(%groupsettings) > 0) {
5091: $denied{'remove'} = 1;
5092: }
5093: $denied{'cut'} = 1;
5094: $denied{'copy'} = 1;
5095: }
5096: }
5097: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
5098: my $group = $1;
5099: if ($url =~ /group_boards_\Q$group\E/) {
5100: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5101: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5102: if (keys(%groupsettings) > 0) {
5103: if (ref($groupsettings{'functions'}) eq 'HASH') {
5104: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
5105: $denied{'remove'} = 1;
5106: }
5107: }
5108: }
5109: $denied{'cut'} = 1;
5110: $denied{'copy'} = 1;
5111: }
5112: }
5113: }
5114: return %denied;
5115: }
5116:
5117: sub new_timebased_suffix {
5118: my ($dom,$num,$type,$area,$container) = @_;
5119: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
5120: if ($type eq 'paste') {
5121: $prefix = $type;
5122: $namespace = 'courseeditor';
5123: $idtype = 'addcode';
5124: } elsif ($type eq 'map') {
5125: $prefix = 'docs';
5126: if ($area eq 'supplemental') {
5127: $prefix = 'supp';
5128: }
5129: $prefix .= $container;
5130: $namespace = 'uploadedmaps';
5131: } else {
5132: $prefix = $type;
5133: $namespace = 'templated';
5134: }
5135: my ($suffix,$freedlock,$error) =
5136: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
5137: if (!$suffix) {
5138: if ($type eq 'paste') {
5139: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
5140: } elsif ($type eq 'map') {
5141: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
5142: } elsif ($type eq 'smppg') {
5143: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
5144: } elsif ($type eq 'exttool') {
5145: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
5146: } else {
5147: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
5148: }
5149: if ($error) {
5150: $errtext .= '<br />'.$error;
5151: }
5152: }
5153: if ($freedlock ne 'ok') {
5154: $locknotfreed =
5155: '<div class="LC_error">'.
5156: &mt('There was a problem removing a lockfile.').' ';
5157: if ($type eq 'paste') {
5158: if ($freedlock eq 'nolock') {
5159: $locknotfreed =
5160: '<div class="LC_error">'.
5161: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
5162:
5163: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
5164: } else {
5165: $locknotfreed .=
5166: &mt('This will prevent addition of items to the clipboard until your next log-in.');
5167: }
5168: } elsif ($type eq 'map') {
5169: $locknotfreed .=
5170: &mt('This will prevent creation of additional folders or composite pages in this course.');
5171: } elsif ($type eq 'smppg') {
5172: $locknotfreed .=
5173: &mt('This will prevent creation of additional simple pages in this course.');
5174: } elsif ($type eq 'exttool') {
5175: $locknotfreed .=
5176: &mt('This will prevent creation of additional external tools in this course.');
5177: } else {
5178: $locknotfreed .=
5179: &mt('This will prevent creation of additional discussion boards in this course.');
5180: }
5181: unless ($type eq 'paste') {
5182: $locknotfreed .=
5183: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
5184: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
5185: }
5186: $locknotfreed .= '</div>';
5187: }
5188: return ($suffix,$errtext,$locknotfreed);
5189: }
5190:
5191: =pod
5192:
5193: =item tiehash()
5194:
5195: tie the hash
5196:
5197: =cut
5198:
5199: sub tiehash {
5200: my ($mode)=@_;
5201: $hashtied=0;
5202: if ($env{'request.course.fn'}) {
5203: if ($mode eq 'write') {
5204: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5205: &GDBM_WRCREAT(),0640)) {
5206: $hashtied=2;
5207: }
5208: } else {
5209: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5210: &GDBM_READER(),0640)) {
5211: $hashtied=1;
5212: }
5213: }
5214: }
5215: }
5216:
5217: sub untiehash {
5218: if ($hashtied) { untie %hash; }
5219: $hashtied=0;
5220: return OK;
5221: }
5222:
5223:
5224:
5225:
5226: sub checkonthis {
5227: my ($r,$url,$level,$title,$checkstale)=@_;
5228: $url=&unescape($url);
5229: $alreadyseen{$url}=1;
5230: $r->rflush();
5231: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
5232: $r->print("\n<br />");
5233: if ($level==0) {
5234: $r->print("<br />");
5235: }
5236: for (my $i=0;$i<=$level*5;$i++) {
5237: $r->print(' ');
5238: }
5239: $r->print('<a href="'.$url.'" target="cat">'.
5240: ($title?$title:$url).'</a> ');
5241: if ($url=~/^\/res\//) {
5242: my $updated;
5243: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
5244: ($url !~ /\.\d+\.\w+$/)) {
5245: $updated = &Apache::lonnet::remove_stale_resfile($url);
5246: }
5247: my $result=&Apache::lonnet::repcopy(
5248: &Apache::lonnet::filelocation('',$url));
5249: if ($result eq 'ok') {
5250: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
5251: if ($updated) {
5252: $r->print('<br />');
5253: for (my $i=0;$i<=$level*5;$i++) {
5254: $r->print(' ');
5255: }
5256: $r->print('- '.&mt('Outdated copy removed'));
5257: }
5258: $r->rflush();
5259: &Apache::lonnet::countacc($url);
5260: $url=~/\.(\w+)$/;
5261: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
5262: $r->print('<br />');
5263: $r->rflush();
5264: for (my $i=0;$i<=$level*5;$i++) {
5265: $r->print(' ');
5266: }
5267: $r->print('- '.&mt('Rendering:').' ');
5268: my ($errorcount,$warningcount)=split(/:/,
5269: &Apache::lonnet::ssi_body($url,
5270: ('grade_target'=>'web',
5271: 'return_only_error_and_warning_counts' => 1)));
5272: if (($errorcount) ||
5273: ($warningcount)) {
5274: if ($errorcount) {
5275: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
5276: &mt('[quant,_1,error]',$errorcount).'</span>');
5277: }
5278: if ($warningcount) {
5279: $r->print('<span class="LC_warning">'.
5280: &mt('[quant,_1,warning]',$warningcount).'</span>');
5281: }
5282: } else {
5283: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
5284: }
5285: $r->rflush();
5286: }
5287: my $dependencies=
5288: &Apache::lonnet::metadata($url,'dependencies');
5289: foreach my $dep (split(/\,/,$dependencies)) {
5290: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
5291: &checkonthis($r,$dep,$level+1,'',$checkstale);
5292: }
5293: }
5294: } elsif ($result eq 'unavailable') {
5295: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
5296: } elsif ($result eq 'not_found') {
5297: unless ($url=~/\$/) {
5298: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
5299: } else {
5300: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
5301: }
5302: } else {
5303: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
5304: }
5305: if (($updated) && ($result ne 'ok')) {
5306: $r->print('<br />'.&mt('Outdated copy removed'));
5307: }
5308: }
5309: }
5310: }
5311:
5312:
5313:
5314: =pod
5315:
5316: =item list_symbs()
5317:
5318: List Content Identifiers
5319:
5320: =cut
5321:
5322: sub list_symbs {
5323: my ($r) = @_;
5324:
5325: my $crstype = &Apache::loncommon::course_type();
5326: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
5327: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
5328: $r->print(&startContentScreen('tools'));
5329: my $navmap = Apache::lonnavmaps::navmap->new();
5330: if (!defined($navmap)) {
5331: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
5332: '<div class="LC_error">'.
5333: &mt('Unable to retrieve information about course contents').
5334: '</div>');
5335: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
5336: } else {
5337: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
5338: &Apache::loncommon::start_data_table().
5339: &Apache::loncommon::start_data_table_header_row().
5340: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
5341: &Apache::loncommon::end_data_table_header_row()."\n");
5342: my $count;
5343: foreach my $res ($navmap->retrieveResources()) {
5344: $r->print(&Apache::loncommon::start_data_table_row().
5345: '<td>'.$res->compTitle().'</td>'.
5346: '<td>'.$res->symb().'</td>'.
5347: &Apache::loncommon::end_data_table_row());
5348: $count ++;
5349: }
5350: if (!$count) {
5351: $r->print(&Apache::loncommon::start_data_table_row().
5352: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
5353: &Apache::loncommon::end_data_table_row());
5354: }
5355: $r->print(&Apache::loncommon::end_data_table());
5356: }
5357: $r->print(&endContentScreen());
5358: }
5359:
5360: sub short_urls {
5361: my ($r,$canedit) = @_;
5362: my $crstype = &Apache::loncommon::course_type();
5363: my $formname = 'shortenurl';
5364: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5365: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5366: $r->print(&startContentScreen('tools'));
5367: my ($navmap,$errormsg) =
5368: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5369: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5370: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5371: my (%maps,%resources,%titles);
5372: if (!ref($navmap)) {
5373: $r->print($errormsg.
5374: &endContentScreen());
5375: return '';
5376: } else {
5377: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
5378: $r->rflush();
5379: my $readonly;
5380: if ($canedit) {
5381: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
5382: if ($numnew) {
5383: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
5384: }
5385: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
5386: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
5387: foreach my $error (@{$errors}) {
5388: $r->print('<li>'.$error.'</li>');
5389: }
5390: $r->print('</ul><br />');
5391: }
5392: } else {
5393: $readonly = 1;
5394: }
5395: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
5396: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
5397: undef,undef,undef,undef,undef,\%currtiny,$readonly));
5398: }
5399: $r->print(&endContentScreen());
5400: }
5401:
5402: sub contentverifyform {
5403: my ($r) = @_;
5404: my $crstype = &Apache::loncommon::course_type();
5405: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5406: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5407: $r->print(&startContentScreen('tools'));
5408: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5409: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
5410: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
5411: ' <span class="LC_nobreak">'.
5412: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
5413: &mt('No').'</label>'.(' 'x2).
5414: '<label><input type="radio" name="checkstale" value="1" />'.
5415: &mt('Yes').'</label></span></p><p>'.
5416: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
5417: '<input type="hidden" value="1" name="tools" />'.
5418: '<input type="hidden" value="1" name="verify" /></p></form>');
5419: $r->print(&endContentScreen());
5420: return;
5421: }
5422:
5423: sub verifycontent {
5424: my ($r,$checkstale) = @_;
5425: my $crstype = &Apache::loncommon::course_type();
5426: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5427: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5428: $r->print(&startContentScreen('tools'));
5429: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5430: $hashtied=0;
5431: undef %alreadyseen;
5432: %alreadyseen=();
5433: &tiehash();
5434:
5435: foreach my $key (keys(%hash)) {
5436: if ($hash{$key}=~/\.(page|sequence)$/) {
5437: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5438: $r->print('<hr /><span class="LC_error">'.
5439: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
5440: &unescape($hash{$key}).'</span><br />'.
5441: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
5442: }
5443: }
5444: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
5445: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
5446: }
5447: }
5448: &untiehash();
5449: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
5450: $r->print(&endContentScreen());
5451: }
5452:
5453: sub devalidateversioncache {
5454: my $src=shift;
5455: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5456: &Apache::lonnet::clutter($src));
5457: }
5458:
5459: sub checkversions {
5460: my ($r,$canedit) = @_;
5461: my $crstype = &Apache::loncommon::course_type();
5462: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5463: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
5464: $r->print(&startContentScreen('tools'));
5465:
5466: my $header='';
5467: my $startsel='';
5468: my $monthsel='';
5469: my $weeksel='';
5470: my $daysel='';
5471: my $allsel='';
5472: my %changes=();
5473: my $starttime=0;
5474: my $haschanged=0;
5475: my %setversions=&Apache::lonnet::dump('resourceversions',
5476: $env{'course.'.$env{'request.course.id'}.'.domain'},
5477: $env{'course.'.$env{'request.course.id'}.'.num'});
5478:
5479: $hashtied=0;
5480: &tiehash();
5481: if ($canedit) {
5482: my %newsetversions=();
5483: if ($env{'form.setmostrecent'}) {
5484: $haschanged=1;
5485: foreach my $key (keys(%hash)) {
5486: if ($key=~/^ids\_(\/res\/.+)$/) {
5487: $newsetversions{$1}='mostrecent';
5488: &devalidateversioncache($1);
5489: }
5490: }
5491: } elsif ($env{'form.setcurrent'}) {
5492: $haschanged=1;
5493: foreach my $key (keys(%hash)) {
5494: if ($key=~/^ids\_(\/res\/.+)$/) {
5495: my $getvers=&Apache::lonnet::getversion($1);
5496: if ($getvers>0) {
5497: $newsetversions{$1}=$getvers;
5498: &devalidateversioncache($1);
5499: }
5500: }
5501: }
5502: } elsif ($env{'form.setversions'}) {
5503: $haschanged=1;
5504: foreach my $key (keys(%env)) {
5505: if ($key=~/^form\.set_version_(.+)$/) {
5506: my $src=$1;
5507: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5508: $newsetversions{$src}=$env{$key};
5509: &devalidateversioncache($src);
5510: }
5511: }
5512: }
5513: }
5514: if ($haschanged) {
5515: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5516: $env{'course.'.$env{'request.course.id'}.'.domain'},
5517: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5518: $r->print(&Apache::loncommon::confirmwrapper(
5519: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5520: } else {
5521: $r->print(&Apache::loncommon::confirmwrapper(
5522: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
5523: }
5524: &mark_hash_old();
5525: }
5526: &changewarning($r,'');
5527: }
5528: if ($env{'form.timerange'} eq 'all') {
5529: # show all documents
5530: $header=&mt('All content in '.$crstype);
5531: $allsel=' selected="selected"';
5532: foreach my $key (keys(%hash)) {
5533: if ($key=~/^ids\_(\/res\/.+)$/) {
5534: my $src=$1;
5535: $changes{$src}=1;
5536: }
5537: }
5538: } else {
5539: # show documents which changed
5540: %changes=&Apache::lonnet::dump
5541: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5542: $env{'course.'.$env{'request.course.id'}.'.num'});
5543: my $firstkey=(keys(%changes))[0];
5544: unless ($firstkey=~/^error\:/) {
5545: unless ($env{'form.timerange'}) {
5546: $env{'form.timerange'}=604800;
5547: }
5548: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5549: .&mt('seconds');
5550: if ($env{'form.timerange'}==-1) {
5551: $seltext='since start of course';
5552: $startsel=' selected="selected"';
5553: $env{'form.timerange'}=time;
5554: }
5555: $starttime=time-$env{'form.timerange'};
5556: if ($env{'form.timerange'}==2592000) {
5557: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5558: $monthsel=' selected="selected"';
5559: } elsif ($env{'form.timerange'}==604800) {
5560: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5561: $weeksel=' selected="selected"';
5562: } elsif ($env{'form.timerange'}==86400) {
5563: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5564: $daysel=' selected="selected"';
5565: }
5566: $header=&mt('Content changed').' '.$seltext;
5567: } else {
5568: $header=&mt('No content modifications yet.');
5569: }
5570: }
5571: %setversions=&Apache::lonnet::dump('resourceversions',
5572: $env{'course.'.$env{'request.course.id'}.'.domain'},
5573: $env{'course.'.$env{'request.course.id'}.'.num'});
5574: my %lt=&Apache::lonlocal::texthash
5575: ('st' => 'Version changes since start of '.$crstype,
5576: 'lm' => 'Version changes since last Month',
5577: 'lw' => 'Version changes since last Week',
5578: 'sy' => 'Version changes since Yesterday',
5579: 'al' => 'All Resources (possibly large output)',
5580: 'cd' => 'Change display',
5581: 'sd' => 'Display',
5582: 'fi' => 'File',
5583: 'md' => 'Modification Date',
5584: 'mr' => 'Most recently published Version',
5585: 've' => 'Version used in '.$crstype,
5586: 'vu' => 'Set Version to be used in '.$crstype,
5587: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
5588: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5589: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
5590: 'di' => 'Differences',
5591: 'save' => 'Save changes',
5592: 'vers' => 'Version choice(s) for specific resources',
5593: 'act' => 'Actions');
5594: my ($disabled,$readonly);
5595: unless ($canedit) {
5596: $disabled = 'disabled="disabled"';
5597: $readonly = 1;
5598: }
5599: $r->print(<<ENDHEADERS);
5600: <h4 class="LC_info">$header</h4>
5601: <form action="/adm/coursedocs" method="post">
5602: <input type="hidden" name="versions" value="1" />
5603: <div class="LC_left_float">
5604: <fieldset>
5605: <legend>$lt{'cd'}</legend>
5606: <select name="timerange">
5607: <option value='all'$allsel>$lt{'al'}</option>
5608: <option value="-1"$startsel>$lt{'st'}</option>
5609: <option value="2592000"$monthsel>$lt{'lm'}</option>
5610: <option value="604800"$weeksel>$lt{'lw'}</option>
5611: <option value="86400"$daysel>$lt{'sy'}</option>
5612: </select>
5613: <input type="submit" name="display" value="$lt{'sd'}" />
5614: </fieldset>
5615: </div>
5616: <div class="LC_left_float">
5617: <fieldset>
5618: <legend>$lt{'act'}</legend>
5619: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5620: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
5621: </fieldset>
5622: </div>
5623: <br clear="all" />
5624: <hr />
5625: <h4>$lt{'vers'}</h4>
5626: ENDHEADERS
5627: #number of columns for version history
5628: my %changedbytime;
5629: foreach my $key (keys(%changes)) {
5630: #excludes not versionable problems from resource version history:
5631: next if ($key =~ /^\/res\/lib\/templates/);
5632: my $chg;
5633: if ($env{'form.timerange'} eq 'all') {
5634: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5635: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5636: } else {
5637: $chg = $changes{$key};
5638: next if ($chg < $starttime);
5639: }
5640: push(@{$changedbytime{$chg}},$key);
5641: }
5642: if (keys(%changedbytime) == 0) {
5643: &untiehash();
5644: $r->print(&mt('No content changes in imported content in specified time frame').
5645: &endContentScreen());
5646: return;
5647: }
5648: $r->print(
5649: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
5650: &Apache::loncommon::start_data_table().
5651: &Apache::loncommon::start_data_table_header_row().
5652: '<th>'.&mt('Resources').'</th>'.
5653: "<th>$lt{'mr'}</th>".
5654: "<th>$lt{'ve'}</th>".
5655: "<th>$lt{'vu'}</th>".
5656: '<th>'.&mt('History').'</th>'.
5657: &Apache::loncommon::end_data_table_header_row()
5658: );
5659: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5660: foreach my $key (sort(@{$changedbytime{$chg}})) {
5661: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5662: my $currentversion=&Apache::lonnet::getversion($key);
5663: if ($currentversion<0) {
5664: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5665: }
5666: my $linkurl=&Apache::lonnet::clutter($key);
5667: $r->print(
5668: &Apache::loncommon::start_data_table_row().
5669: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5670: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5671: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5672: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5673: '<td align="right">'
5674: );
5675: # Used in course
5676: my $usedversion=$hash{'version_'.$linkurl};
5677: if (($usedversion) && ($usedversion ne 'mostrecent')) {
5678: if ($usedversion != $currentversion) {
5679: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
5680: } else {
5681: $r->print($usedversion);
5682: }
5683: } else {
5684: $r->print($currentversion);
5685: }
5686: $r->print('</td><td title="'.$lt{'vu'}.'">');
5687: # Set version
5688: $r->print(&Apache::loncommon::select_form(
5689: $setversions{$linkurl},
5690: 'set_version_'.$linkurl,
5691: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5692: '' => '',
5693: 'mostrecent' => &mt('most recent'),
5694: map {$_,$_} (1..$currentversion)},'',$readonly));
5695: my $lastold=1;
5696: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5697: my $url=$root.'.'.$prevvers.'.'.$extension;
5698: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5699: $lastold=$prevvers;
5700: }
5701: }
5702: $r->print('</td>');
5703: # List all available versions
5704: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5705: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5706: my $url=$root.'.'.$prevvers.'.'.$extension;
5707: $r->print(
5708: '<span class="LC_nobreak">'
5709: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5710: .&mt('Version [_1]',$prevvers).'</a>'
5711: .' ('.&Apache::lonlocal::locallocaltime(
5712: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5713: .')');
5714: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5715: $r->print(
5716: ' <a href="/adm/diff?filename='.
5717: &Apache::lonnet::clutter($root.'.'.$extension).
5718: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5719: '" target="diffs">'.&mt('Diffs').'</a>');
5720: }
5721: $r->print('</span><br />');
5722: }
5723: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
5724: }
5725: }
5726: $r->print(
5727: &Apache::loncommon::end_data_table().
5728: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
5729: '</form>'
5730: );
5731:
5732: &untiehash();
5733: $r->print(&endContentScreen());
5734: return;
5735: }
5736:
5737: sub mark_hash_old {
5738: my $retie_hash=0;
5739: if ($hashtied) {
5740: $retie_hash=1;
5741: &untiehash();
5742: }
5743: &tiehash('write');
5744: $hash{'old'}=1;
5745: &untiehash();
5746: if ($retie_hash) { &tiehash(); }
5747: }
5748:
5749: sub is_hash_old {
5750: my $untie_hash=0;
5751: if (!$hashtied) {
5752: $untie_hash=1;
5753: &tiehash();
5754: }
5755: my $return=$hash{'old'};
5756: if ($untie_hash) { &untiehash(); }
5757: return $return;
5758: }
5759:
5760: sub changewarning {
5761: my ($r,$postexec,$message,$url)=@_;
5762: if (!&is_hash_old()) { return; }
5763: my $pathvar='folderpath';
5764: my $path=&escape($env{'form.folderpath'});
5765: if (!defined($url)) {
5766: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5767: }
5768: my $course_type = &Apache::loncommon::course_type();
5769: if (!defined($message)) {
5770: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5771: }
5772: my $windowname = 'loncapaclient';
5773: if ($env{'request.lti.login'}) {
5774: $windowname .= 'lti';
5775: }
5776: $r->print("\n\n".
5777: '<script type="text/javascript">'."\n".
5778: '// <![CDATA['."\n".
5779: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5780: '// ]]>'."\n".
5781: '</script>'."\n".
5782: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
5783: '<input type="hidden" name="orgurl" value="'.$url.
5784: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
5785: &mt($message,' <input type="hidden" name="'.
5786: $env{'request.role'}.'" value="1" /><input type="button" value="'.
5787: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
5788: $help{'Caching'}.'</p></form>'."\n\n");
5789: }
5790:
5791:
5792: sub init_breadcrumbs {
5793: my ($form,$text,$help)=@_;
5794: &Apache::lonhtmlcommon::clear_breadcrumbs();
5795: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
5796: text=>&Apache::loncommon::course_type().' Editor',
5797: faq=>273,
5798: bug=>'Instructor Interface',
5799: help => $help});
5800: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5801: text=>$text,
5802: faq=>273,
5803: bug=>'Instructor Interface'});
5804: }
5805:
5806: # subroutine to list form elements
5807: sub create_list_elements {
5808: my @formarr = @_;
5809: my $list = '';
5810: foreach my $button (@formarr){
5811: foreach my $picture (keys(%{$button})) {
5812: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
5813: }
5814: }
5815: return $list;
5816: }
5817:
5818: # subroutine to create ul from list elements
5819: sub create_form_ul {
5820: my $list = shift;
5821: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5822: return $ul;
5823: }
5824:
5825: #
5826: # Start tabs
5827: #
5828:
5829: sub startContentScreen {
5830: my ($mode) = @_;
5831: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
5832: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
5833: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5834: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5835: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5836: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5837: } else {
5838: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n";
5839: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5840: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5841: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5842: }
5843: $output .= "\n".'</ul>'."\n";
5844: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5845: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5846: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5847: return $output;
5848: }
5849:
5850: #
5851: # End tabs
5852: #
5853:
5854: sub endContentScreen {
5855: return '</div></div></div>';
5856: }
5857:
5858: sub supplemental_base {
5859: return 'supplemental&'.&escape(&mt('Supplemental Content'));
5860: }
5861:
5862: sub handler {
5863: my $r = shift;
5864: &Apache::loncommon::content_type($r,'text/html');
5865: $r->send_http_header;
5866: return OK if $r->header_only;
5867:
5868: # get course data
5869: my $crstype = &Apache::loncommon::course_type();
5870: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5871: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5872:
5873: # get docroot
5874: my $londocroot = $r->dir_config('lonDocRoot');
5875:
5876: # graphics settings
5877: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
5878:
5879: #
5880: # --------------------------------------------- Initialize help topics for this
5881: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5882: 'Adding_External_Resource','Adding_External_Tool',
5883: 'Navigate_Content','Adding_Folders','Docs_Overview',
5884: 'Load_Map','Supplemental','Score_Upload_Form',
5885: 'Adding_Pages','Importing_LON-CAPA_Resource',
5886: 'Importing_IMS_Course','Uploading_From_Harddrive',
5887: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
5888: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5889: }
5890: # Composite help files
5891: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5892: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5893: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5894: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5895: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5896: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
5897: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
5898: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
5899: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
5900: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
5901:
5902: my ($allowed,$canedit,$canview,$noendpage,$disabled);
5903: # does this user have privileges to modify content.
5904: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5905: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5906: unless ($r->uri eq '/adm/supplemental') {
5907: $allowed = 1;
5908: }
5909: $canedit = 1;
5910: $canview = 1;
5911: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5912: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5913: unless ($r->uri eq '/adm/supplemental') {
5914: $allowed = 1;
5915: }
5916: $canview = 1;
5917: }
5918: unless ($canedit) {
5919: $disabled = ' disabled="disabled"';
5920: }
5921: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5922: if ($env{'form.inhibitmenu'}) {
5923: unless ($env{'form.inhibitmenu'} eq 'yes') {
5924: delete($env{'form.inhibitmenu'});
5925: }
5926: }
5927:
5928: if ($allowed && $env{'form.verify'}) {
5929: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
5930: if (!$canedit) {
5931: &verifycontent($r);
5932: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5933: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5934: text=>'Results',
5935: faq=>273,
5936: bug=>'Instructor Interface'});
5937: &verifycontent($r,$env{'form.checkstale'});
5938: } else {
5939: &contentverifyform($r);
5940: }
5941: } elsif ($allowed && $env{'form.listsymbs'}) {
5942: &init_breadcrumbs('listsymbs','List Content IDs');
5943: &list_symbs($r);
5944: } elsif ($allowed && $env{'form.shorturls'}) {
5945: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5946: &short_urls($r,$canedit);
5947: } elsif ($allowed && $env{'form.docslog'}) {
5948: &init_breadcrumbs('docslog','Show Log');
5949: my $folder = $env{'form.folder'};
5950: if ($folder eq '') {
5951: $folder='default';
5952: }
5953: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
5954: } elsif ($allowed && $env{'form.versions'}) {
5955: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
5956: &checkversions($r,$canedit);
5957: } elsif ($canedit && $env{'form.dumpcourse'}) {
5958: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
5959: &dumpcourse($r);
5960: } elsif ($canedit && $env{'form.exportcourse'}) {
5961: &init_breadcrumbs('exportcourse','IMS Export');
5962: &Apache::imsexport::exportcourse($r);
5963: } else {
5964: if ($canedit && $env{'form.authorrole'}) {
5965: $noendpage = 1;
5966: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5967: if ($redirect) {
5968: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5969: my $container = 'sequence';
5970: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5971: $is_random_order,$container) =
5972: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5973: my (@folders)=split('&',$env{'form.folderpath'});
5974: $env{'form.foldername'}=&unescape(pop(@folders));
5975: my $folder=pop(@folders);
5976: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5977: $folder.'.'.$container);
5978: my $warning;
5979: if ($fatal) {
5980: if ($container eq 'page') {
5981: $warning = &mt('An error occurred retrieving the contents of the current page.');
5982: } else {
5983: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5984: }
5985: } else {
5986: my $url = $redirect;
5987: my $srcfile = $londocroot.$url;
5988: $url =~ s{^/priv/}{/res/};
5989: my $targetfile = $londocroot.$url;
5990: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5991: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5992: $env{'form.folder'} = $folder;
5993: &snapshotbefore();
5994: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5995: my $ext = 'false';
5996: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5997: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5998: ':'.$ext.':normal:res';
5999: push(@LONCAPA::map::order,$newidx);
6000: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
6001: 'string_yesno');
6002: &remember_parms($newidx,'hiddenresource','set','yes');
6003: ($errtext,$fatal) =
6004: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
6005: &log_differences($plain);
6006: &mark_hash_old();
6007: $r->internal_redirect($redirect);
6008: return OK;
6009: }
6010: } else {
6011: $r->internal_redirect($redirect);
6012: }
6013: }
6014: }
6015: #
6016: # Done catching special calls
6017: # The whole rest is for course and supplemental documents and utilities menu
6018: # Get the parameters that may be needed
6019: #
6020: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
6021: ['folderpath','title',
6022: 'forcesupplement','forcestandard',
6023: 'tools','symb','command','supppath']);
6024:
6025: foreach my $item ('forcesupplement','forcestandard','tools') {
6026: next if ($env{'form.'.$item} eq '');
6027: unless ($env{'form.'.$item} eq '1') {
6028: delete($env{'form.'.$item});
6029: }
6030: }
6031:
6032: if ($env{'form.command'}) {
6033: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
6034: delete($env{'form.command'});
6035: }
6036: }
6037:
6038: if ($env{'form.symb'}) {
6039: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
6040: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
6041: delete($env{'form.symb'});
6042: }
6043: }
6044:
6045: # standard=1: this is a "new-style" course with an uploaded map as top level
6046: # standard=2: this is a "old-style" course, and there is nothing we can do
6047:
6048: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
6049:
6050: # Decide whether this should display supplemental or main content or utilities
6051: # supplementalflag=1: show supplemental documents
6052: # supplementalflag=0: show standard documents
6053: # toolsflag=1: show utilities
6054:
6055: my $unesc_folderpath = &unescape($env{'form.folderpath'});
6056: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
6057: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
6058: $supplementalflag=0;
6059: }
6060: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
6061: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
6062: unless ($allowed) { $supplementalflag=1; }
6063: unless ($standard) { $supplementalflag=1; }
6064: my $toolsflag=0;
6065: if ($env{'form.tools'}) { $toolsflag=1; }
6066:
6067: if ($env{'form.folderpath'} ne '') {
6068: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
6069: }
6070:
6071: my $backto_supppath;
6072: if ($env{'form.supppath'} ne '') {
6073: if ($supplementalflag && $allowed) {
6074: $backto_supppath = &validate_supppath($coursenum,$coursedom);
6075: }
6076: }
6077:
6078: my $script='';
6079: my $showdoc=0;
6080: my $addentries = {};
6081: my $container;
6082: my $containertag;
6083: my $pathitem;
6084: my %ltitools;
6085: my $posslti;
6086: my $hiddentop;
6087: my $navmap;
6088: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
6089:
6090: # Do we directly jump somewhere?
6091: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
6092: if ($env{'form.symb'} ne '') {
6093: $env{'form.folderpath'}=
6094: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
6095: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
6096: $env{'form.command'}.'_'.$env{'form.symb'}});
6097: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
6098: $env{'form.folderpath'}=$env{'form.supppath'};
6099: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
6100: $env{'form.command'}.'_'.$backto_supppath});
6101: }
6102: } elsif ($env{'form.command'} eq 'editdocs') {
6103: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
6104: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
6105: } elsif ($env{'form.command'} eq 'editsupp') {
6106: $env{'form.folderpath'} = &supplemental_base();
6107: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
6108: } elsif ($env{'form.command'} eq 'contents') {
6109: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
6110: } elsif ($env{'form.command'} eq 'home') {
6111: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
6112: }
6113:
6114:
6115: # Where do we store these for when we come back?
6116: my $stored_folderpath='docs_folderpath';
6117: if ($supplementalflag) {
6118: $stored_folderpath='docs_sup_folderpath';
6119: }
6120:
6121: # No folderpath, and in edit mode, see if we have something stored
6122: if ((!$env{'form.folderpath'}) && $allowed) {
6123: &Apache::loncommon::restore_course_settings($stored_folderpath,
6124: {'folderpath' => 'scalar'});
6125:
6126: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
6127: if ($supplementalflag) {
6128: undef($env{'form.folderpath'}) if ($1 eq 'default');
6129: } else {
6130: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
6131: }
6132: } else {
6133: undef($env{'form.folderpath'});
6134: }
6135: if ($env{'form.folderpath'} ne '') {
6136: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
6137: }
6138: }
6139:
6140: # If we are not allowed to make changes, all we can see are supplemental docs
6141: if (!$allowed) {
6142: unless ($env{'form.folderpath'} =~ /^supplemental/) {
6143: $env{'form.folderpath'} = &supplemental_base();
6144: }
6145: }
6146: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
6147: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
6148: $env{'form.folderpath'} = &supplemental_base()
6149: .'&'.
6150: $env{'form.folderpath'};
6151: }
6152: # If allowed and user's role is not advanced check folderpath is not hidden
6153: my $hidden_and_empty;
6154: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
6155: my ($folderurl,$foldername,$hiddenfolder);
6156: my @pathitems = split(/\&/,$env{'form.folderpath'});
6157: my $folder = $pathitems[-2];
6158: if ($folder eq '') {
6159: undef($env{'form.folderpath'});
6160: } else {
6161: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
6162: if ((split(/\:/,$pathitems[-1]))[5]) {
6163: $folderurl .= '.page';
6164: } else {
6165: $folderurl .= '.sequence';
6166: }
6167: if ($supplementalflag) {
6168: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
6169: $foldername = &HTML::Entities::decode(&unescape($foldername));
6170: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
6171: if (ref($supplemental) eq 'HASH') {
6172: my ($suppmap,$suppmapnum);
6173: if ($folder eq 'supplemental') {
6174: $suppmap = 'default';
6175: $suppmapnum = 0;
6176: } elsif ($folder =~ /^supplemental_(\d+)$/) {
6177: $suppmap = $1;
6178: $suppmapnum = $suppmap;
6179: }
6180: if ($hiddenfolder) {
6181: my $hascontent;
6182: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
6183: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
6184: $hascontent = 1;
6185: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
6186: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
6187: if ($id =~ /^$suppmapnum\:/) {
6188: $hascontent = 1;
6189: last;
6190: }
6191: }
6192: }
6193: last if ($hascontent);
6194: }
6195: unless ($hascontent) {
6196: if ($foldername ne '') {
6197: $hidden_and_empty = $foldername;
6198: } else {
6199: $hidden_and_empty = $folder;
6200: }
6201: }
6202: }
6203: }
6204: } else {
6205: unless (ref($navmap)) {
6206: $navmap = Apache::lonnavmaps::navmap->new();
6207: }
6208: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
6209: $foldername = &HTML::Entities::decode(&unescape($foldername));
6210: if (ref($navmap)) {
6211: if ($hiddenfolder ||
6212: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
6213: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
6214: unless (@resources) {
6215: if ($foldername ne '') {
6216: $hidden_and_empty = $foldername;
6217: } else {
6218: $hidden_and_empty = $folder;
6219: }
6220: }
6221: }
6222: }
6223: }
6224: if ($hidden_and_empty ne '') {
6225: splice(@pathitems,-2);
6226: if (@pathitems) {
6227: $env{'form.folderpath'} = join('&',@pathitems);
6228: } else {
6229: undef($env{'form.folderpath'});
6230: }
6231: }
6232: }
6233: }
6234:
6235: # If after all of this, we still don't have any paths, make them
6236: unless ($env{'form.folderpath'}) {
6237: if ($supplementalflag) {
6238: $env{'form.folderpath'}=&supplemental_base();
6239: } elsif ($allowed) {
6240: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
6241: }
6242: }
6243:
6244: # Store this
6245: unless ($toolsflag) {
6246: if (($allowed) && ($env{'form.folderpath'} ne '')) {
6247: &Apache::loncommon::store_course_settings($stored_folderpath,
6248: {'folderpath' => 'scalar'});
6249: }
6250: my $folderpath;
6251: if ($env{'form.folderpath'}) {
6252: $folderpath = $env{'form.folderpath'};
6253: my (@folders)=split('&',$env{'form.folderpath'});
6254: $env{'form.foldername'}=&unescape(pop(@folders));
6255: if ($env{'form.foldername'} =~ /\:1$/) {
6256: $container = 'page';
6257: } else {
6258: $container = 'sequence';
6259: }
6260: $env{'form.folder'}=pop(@folders);
6261: } else {
6262: if ($env{'form.folder'} eq '' ||
6263: $env{'form.folder'} eq 'supplemental') {
6264: if ($env{'form.folder'} eq 'supplemental') {
6265: $folderpath=&supplemental_base();
6266: } elsif (!$hiddentop) {
6267: $folderpath='default&'.
6268: &escape(&mt('Main Content').':::::');
6269: }
6270: }
6271: }
6272: $containertag = '<input type="hidden" name="folderpath" value="" />';
6273: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
6274: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
6275: $showdoc='/'.$1;
6276: }
6277: if ($showdoc) { # got called in sequence from course
6278: $allowed=0;
6279: } else {
6280: if ($canedit) {
6281: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
6282: $script=&Apache::lonratedt::editscript('simple');
6283: }
6284: }
6285: }
6286:
6287: # get personal data
6288: my $uname=$env{'user.name'};
6289: my $udom=$env{'user.domain'};
6290: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
6291:
6292: if ($allowed) {
6293: if ($toolsflag) {
6294: $script .= &inject_data_js();
6295: my ($home,$other,%outhash)=&authorhosts();
6296: if (!$home && $other) {
6297: my @hosts;
6298: foreach my $aurole (keys(%outhash)) {
6299: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6300: push(@hosts,$outhash{$aurole});
6301: }
6302: }
6303: $script .= &dump_switchserver_js(@hosts);
6304: }
6305: } else {
6306: my $tid = 1;
6307: my @tabids;
6308: if ($supplementalflag) {
6309: @tabids = ('002','dd2','ee2','ff2');
6310: $tid = 2;
6311: } else {
6312: @tabids = ('aa1','bb1','cc1','ff1');
6313: unless ($env{'form.folderpath'} =~ /\:1$/) {
6314: unshift(@tabids,'001');
6315: push(@tabids,('dd1','ee1'));
6316: }
6317: }
6318: my $tabidstr = join("','",@tabids);
6319: my (%domtools,%crstools);
6320: my %tooltypes = &Apache::loncommon::usable_exttools();
6321: if ($tooltypes{'dom'}) {
6322: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
6323: }
6324: if ($tooltypes{'crs'}) {
6325: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
6326: }
6327: %ltitools = (
6328: dom => \%domtools,
6329: crs => \%crstools,
6330: );
6331: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
6332: my $hostname = $r->hostname();
6333: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
6334: $londocroot,$canedit,$hostname,\$navmap).
6335: &history_tab_js().
6336: &inject_data_js().
6337: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
6338: &Apache::lonextresedit::extedit_javascript(\%ltitools);
6339: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
6340: if ($hidden_and_empty ne '') {
6341: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
6342: $hidden_and_empty);
6343: $onload .= "javascript:alert('".&js_escape($alert)."');";
6344: }
6345: $addentries = {
6346: onload => $onload,
6347: };
6348: }
6349: $script .= &paste_popup_js();
6350: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
6351: &mt('Switch server?');
6352:
6353:
6354: }
6355: # -------------------------------------------------------------------- Body tag
6356: $script = '<script type="text/javascript">'."\n"
6357: .'// <![CDATA['."\n"
6358: .$script."\n"
6359: .'// ]]>'."\n"
6360: .'</script>'."\n"
6361: .'<script type="text/javascript"
6362: src="/res/adm/includes/file_upload.js"></script>'."\n";
6363:
6364: # Breadcrumbs
6365: &Apache::lonhtmlcommon::clear_breadcrumbs();
6366:
6367: if ($showdoc) {
6368: my $args;
6369: if ($supplementalflag) {
6370: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
6371: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
6372: $args = {'bread_crumbs' => $brcrum};
6373: } else {
6374: $args = {'force_register' => $showdoc};
6375: }
6376: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
6377: } elsif ($toolsflag) {
6378: my ($breadtext,$breadtitle);
6379: $breadtext = "$crstype Editor";
6380: if ($canedit) {
6381: $breadtitle = 'Editing '.$crstype.' Contents';
6382: } else {
6383: $breadtext .= ' (View-only mode)';
6384: $breadtitle = 'Viewing '.$crstype.' Contents';
6385: }
6386: &Apache::lonhtmlcommon::add_breadcrumb({
6387: href=>"/adm/coursedocs",text=>$breadtext});
6388: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
6389: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6390: .&Apache::lonhtmlcommon::breadcrumbs(
6391: $breadtitle)
6392: );
6393: } elsif ($r->uri eq '/adm/supplemental') {
6394: unless ($env{'request.role.adv'}) {
6395: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
6396: $r->internal_redirect('/adm/navmaps');
6397: return OK;
6398: }
6399: }
6400: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
6401: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
6402: {'bread_crumbs' => $brcrum,}));
6403: } else {
6404: my ($breadtext,$breadtitle,$helpitem);
6405: $breadtext = "$crstype Editor";
6406: if ($canedit) {
6407: $breadtitle = 'Editing '.$crstype.' Contents';
6408: $helpitem = 'Docs_Adding_Course_Doc';
6409: } else {
6410: $breadtext .= ' (View-only mode)';
6411: $breadtitle = 'Viewing '.$crstype.' Contents';
6412: $helpitem = 'Docs_Viewing_Course_Doc';
6413: }
6414: &Apache::lonhtmlcommon::add_breadcrumb({
6415: href=>"/adm/coursedocs",text=>$breadtext});
6416: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
6417: {'add_entries' => $addentries}
6418: )
6419: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6420: .&Apache::lonhtmlcommon::breadcrumbs(
6421: $breadtitle,
6422: $helpitem)
6423: );
6424: }
6425:
6426: my %allfiles = ();
6427: my %codebase = ();
6428: my ($upload_result,$upload_output,$uploadphase);
6429: if ($canedit) {
6430: undef($suppchanges);
6431: if (($env{'form.uploaddoc.filename'}) &&
6432: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
6433: my $context = $1;
6434: # Process file upload - phase one - upload and parse primary file.
6435: undef($hadchanges);
6436: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
6437: \%allfiles,\%codebase,$context,$crstype);
6438: undef($navmap);
6439: if ($hadchanges) {
6440: &mark_hash_old();
6441: }
6442: if ($suppchanges) {
6443: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6444: undef($suppchanges);
6445: }
6446: $r->print($upload_output);
6447: } elsif ($env{'form.phase'} eq 'upload_embedded') {
6448: # Process file upload - phase two - upload embedded objects
6449: $uploadphase = 'check_embedded';
6450: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
6451: my $state = &embedded_form_elems($uploadphase,$primaryurl,
6452: $env{'form.newidx'});
6453: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6454: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6455: my ($destination,$dir_root) = &embedded_destination();
6456: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
6457: my $actionurl = '/adm/coursedocs';
6458: my ($result,$flag) =
6459: &Apache::loncommon::upload_embedded('coursedoc',$destination,
6460: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
6461: $actionurl);
6462: $r->print($result.&return_to_editor());
6463: } elsif ($env{'form.phase'} eq 'check_embedded') {
6464: # Process file upload - phase three - modify references in HTML file
6465: $uploadphase = 'modified_orightml';
6466: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6467: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6468: my ($destination,$dir_root) = &embedded_destination();
6469: my $result =
6470: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
6471: $docuname,$docudom,undef,
6472: $dir_root);
6473: $r->print($result.&return_to_editor());
6474: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
6475: $uploadphase = 'decompress_phase_one';
6476: $r->print(&decompression_phase_one().
6477: &return_to_editor());
6478: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
6479: $uploadphase = 'decompress_phase_two';
6480: $r->print(&decompression_phase_two().
6481: &return_to_editor());
6482: }
6483: }
6484:
6485: if ($allowed && $toolsflag) {
6486: $r->print(&startContentScreen('tools'));
6487: $r->print(&generate_admin_menu($crstype,$canedit));
6488: $r->print(&endContentScreen());
6489: } elsif ((!$showdoc) && (!$uploadphase)) {
6490: # -----------------------------------------------------------------------------
6491: my %lt=&Apache::lonlocal::texthash(
6492: 'copm' => 'All documents out of a published map into this folder',
6493: 'upfi' => 'Upload File',
6494: 'upld' => 'Upload Content',
6495: 'srch' => 'Search',
6496: 'impo' => 'Import',
6497: 'lnks' => 'Import from Stored Links',
6498: 'impm' => 'Import from Assembled Map',
6499: 'imcr' => 'Import from Course Resources',
6500: 'extr' => 'External Resource',
6501: 'extt' => 'External Tool',
6502: 'selm' => 'Select Map',
6503: 'load' => 'Load Map',
6504: 'newf' => 'New Folder',
6505: 'newp' => 'New Composite Page',
6506: 'syll' => 'Syllabus',
6507: 'navc' => 'Table of Contents',
6508: 'sipa' => 'Simple Course Page',
6509: 'sipr' => 'Simple Problem',
6510: 'webp' => 'Blank Web Page (editable)',
6511: 'stpr' => 'Standard Problem',
6512: 'news' => 'New sub-directory',
6513: 'crpr' => 'Create Problem',
6514: 'swit' => 'Switch Server',
6515: 'drbx' => 'Drop Box',
6516: 'scuf' => 'External Scores (handgrade, upload, clicker)',
6517: 'bull' => 'Discussion Board',
6518: 'mypi' => 'My Personal Information Page',
6519: 'grpo' => 'Group Portfolio',
6520: 'rost' => 'Course Roster',
6521: 'abou' => 'Personal Information Page for a User',
6522: 'imsf' => 'IMS Upload',
6523: 'imsl' => 'Upload IMS package',
6524: 'cms' => 'Origin of IMS package',
6525: 'se' => 'Select',
6526: 'file' => 'File',
6527: 'title' => 'Title',
6528: 'addp' => 'Add Placeholder to course?',
6529: 'uste' => 'Use Template?',
6530: 'fnam' => 'File Name:',
6531: 'loca' => 'Location:',
6532: 'dire' => 'Directory:',
6533: 'cate' => 'Category:',
6534: 'tmpl' => 'Template:',
6535: 'empd' => 'No resources found',
6536: 'comment' => 'Comment',
6537: 'parse' => 'Upload embedded images/multimedia files if HTML file',
6538: 'bb5' => 'Blackboard 5',
6539: 'bb6' => 'Blackboard 6',
6540: 'angel5' => 'ANGEL 5.5',
6541: 'webctce4' => 'WebCT 4 Campus Edition',
6542: 'yes' => 'Yes',
6543: 'no' => 'No',
6544: 'er' => 'Editing rights unavailable for your current role.',
6545: );
6546: # -----------------------------------------------------------------------------
6547:
6548: # Calculate free quota space for a user or course. A javascript function checks
6549: # file size to determine if upload should be allowed.
6550: my $quotatype = 'unofficial';
6551: if ($crstype eq 'Community') {
6552: $quotatype = 'community';
6553: } elsif ($crstype eq 'Placement') {
6554: $quotatype = 'placement';
6555: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6556: $quotatype = 'official';
6557: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6558: $quotatype = 'textbook';
6559: }
6560: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6561: 'course',$quotatype); # expressed in MB
6562: my $current_disk_usage = 0;
6563: foreach my $subdir ('docs','supplemental') {
6564: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6565: "userfiles/$subdir",1); # expressed in kB
6566: }
6567: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
6568: my $usage = $current_disk_usage/1024; # in MB
6569: my $quota = $disk_quota;
6570: my $percent;
6571: if ($disk_quota == 0) {
6572: $percent = 100.0;
6573: } else {
6574: $percent = 100*($usage/$disk_quota);
6575: }
6576: $usage = sprintf("%.2f",$usage);
6577: $quota = sprintf("%.2f",$quota);
6578: $percent = sprintf("%.0f",$percent);
6579: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6580: $percent.'%',$quota.' MB').'</p>';
6581:
6582: my $fileupload=(<<FIUP);
6583: $quotainfo
6584: $lt{'file'}:<br />
6585: FIUP
6586: my $checkbox=(<<CHBO);
6587: <!-- <label>$lt{'parse'}?
6588: <input type="checkbox" name="parserflag" />
6589: </label> -->
6590: <label>
6591: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
6592: </label>
6593: CHBO
6594: my $imsfolder = $env{'form.folder'};
6595: if ($imsfolder eq '') {
6596: $imsfolder = 'default';
6597: }
6598: my $imspform=(<<IMSFORM);
6599: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6600: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6601: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
6602: <fieldset id="uploadimsform" style="display: none;">
6603: <legend>$lt{'imsf'}</legend>
6604: $fileupload
6605: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
6606: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
6607: <br />
6608: <p>
6609: $lt{'cms'}:
6610: <select name="source" $disabled>
6611: <option value="-1" selected="selected">$lt{'se'}</option>
6612: <option value="bb5">$lt{'bb5'}</option>
6613: <option value="bb6">$lt{'bb6'}</option>
6614: <option value="angel5">$lt{'angel5'}</option>
6615: <option value="webctce4">$lt{'webctce4'}</option>
6616: </select>
6617: <input type="hidden" name="folder" value="$imsfolder" />
6618: </p>
6619: <input type="hidden" name="phase" value="one" />
6620: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
6621: </fieldset>
6622: </form>
6623: IMSFORM
6624:
6625: my $fileuploadform=(<<FUFORM);
6626: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6627: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6628: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
6629: <fieldset id="uploaddocform" style="display: none;">
6630: <legend>$lt{'upfi'}</legend>
6631: <input type="hidden" name="active" value="aa" />
6632: $fileupload
6633: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
6634: <input type="hidden" id="LC_free_space" value="$free_space" />
6635: <br />
6636: $lt{'title'}:<br />
6637: <input type="text" size="60" name="comment" $disabled />
6638: $pathitem
6639: <input type="hidden" name="cmd" value="upload_default" />
6640: <br />
6641: <span class="LC_nobreak" style="float:left">
6642: $checkbox
6643: </span>
6644: <br clear="all" />
6645: <input type="submit" value="$lt{'upld'}" $disabled />
6646: </fieldset>
6647: </form>
6648: FUFORM
6649:
6650: my $mapimportjs;
6651: if ($canedit) {
6652: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6653: } else {
6654: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6655: }
6656: my $importpubform=(<<SEDFFORM);
6657: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
6658: $lt{'impm'}</a>$help{'Load_Map'}
6659: <form action="/adm/coursedocs" method="post" name="mapimportform">
6660: <fieldset id="importmapform" style="display: none;">
6661: <legend>$lt{'impm'}</legend>
6662: <input type="hidden" name="active" value="bb" />
6663: $lt{'copm'}<br />
6664: <span class="LC_nobreak">
6665: <input type="text" name="importmap" size="40" value=""
6666: onfocus="this.blur();$mapimportjs" $disabled />
6667: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6668: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
6669: </fieldset>
6670: </form>
6671:
6672: SEDFFORM
6673: my $importcrsresform;
6674: my ($numdirs,$pickfile) =
6675: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
6676: "resize_scrollbox('contentscroll','1','0');",
6677: undef,'res');
6678: if ($pickfile) {
6679: $importcrsresform=(<<CRSFORM);
6680: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
6681: $lt{'imcr'}</a>$help{'Course_Resources'}
6682: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6683: <fieldset id="importcrsresform" style="display: none;">
6684: <legend>$lt{'imcr'}</legend>
6685: <div id="importcrsrescontent" style="display: none;">
6686: <input type="hidden" name="active" value="bb" />
6687: $pickfile
6688: <p>
6689: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
6690: </p>
6691: <input type="hidden" name="importdetail" value="" />
6692: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
6693: </div>
6694: <div id="importcrsresempty" style="display: none;">
6695: <p>
6696: $lt{'empd'}
6697: </p>
6698: </div>
6699: </fieldset>
6700: </form>
6701: CRSFORM
6702: }
6703:
6704: my $fromstoredjs;
6705: if ($canedit) {
6706: $fromstoredjs = 'open_StoredLinks_Import()';
6707: } else {
6708: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6709: }
6710:
6711: my @importpubforma = (
6712: { '<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>" },
6713: { '<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'}" },
6714: { '<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>' },
6715: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6716: );
6717: if ($pickfile) {
6718: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\');" />' => $importcrsresform});
6719: }
6720: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
6721: my $extresourcesform =
6722: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6723: $help{'Adding_External_Resource'},
6724: undef,undef,undef,undef,undef,undef,$disabled);
6725: my $exttoolform =
6726: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6727: $help{'Adding_External_Tool'},undef,
6728: undef,'tool',$coursedom,$coursenum,
6729: \%ltitools,$disabled);
6730: if ($allowed) {
6731: my $folder = $env{'form.folder'};
6732: if ($folder eq '') {
6733: $folder='default';
6734: }
6735: if ($canedit) {
6736: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6737: if ($output) {
6738: $r->print($output);
6739: }
6740: }
6741: $r->print(<<HIDDENFORM);
6742: <form name="renameform" method="post" action="/adm/coursedocs">
6743: <input type="hidden" name="title" />
6744: <input type="hidden" name="cmd" />
6745: <input type="hidden" name="markcopy" />
6746: <input type="hidden" name="copyfolder" />
6747: $containertag
6748: </form>
6749: <form name="aliasform" method="post" action="/adm/coursedocs">
6750: <input type="hidden" name="alias" />
6751: <input type="hidden" name="cmd" />
6752: $containertag
6753: </form>
6754:
6755: HIDDENFORM
6756: $r->print(&makesimpleeditform($pathitem)."\n".
6757: &makedocslogform($pathitem."\n".
6758: '<input type="hidden" name="folder" value="'.
6759: $env{'form.folder'}.'" />'."\n"));
6760: }
6761:
6762: # Generate the tabs
6763: my ($mode,$needs_end);
6764: if (($supplementalflag) && (!$allowed)) {
6765: my @folders = split('&',$env{'form.folderpath'});
6766: unless (@folders > 2) {
6767: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6768: $needs_end = 1;
6769: }
6770: } else {
6771: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
6772: $needs_end = 1;
6773: }
6774:
6775: #
6776: my $hostname = $r->hostname();
6777: my $savefolderpath;
6778:
6779: if ($allowed) {
6780: my $folder=$env{'form.folder'};
6781: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
6782: $folder='default';
6783: $savefolderpath = $env{'form.folderpath'};
6784: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
6785: $pathitem = '<input type="hidden" name="folderpath" value="'.
6786: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6787: }
6788: my $postexec='';
6789: if ($folder eq 'default') {
6790: my $windowname = 'loncapaclient';
6791: if ($env{'request.lti.login'}) {
6792: $windowname .= 'lti';
6793: }
6794: $r->print('<script type="text/javascript">'."\n"
6795: .'// <![CDATA['."\n"
6796: .'this.window.name="'.$windowname.'";'."\n"
6797: .'// ]]>'."\n"
6798: .'</script>'."\n"
6799: );
6800: } else {
6801: #$postexec='self.close();';
6802: }
6803: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6804: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
6805: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6806:
6807: my $newnavform=(<<NNFORM);
6808: <form action="/adm/coursedocs" method="post" name="newnav">
6809: <input type="hidden" name="active" value="ff" />
6810: $pathitem
6811: <input type="hidden" name="importdetail"
6812: value="$lt{'navc'}=/adm/navmaps" />
6813: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
6814: $help{'Navigate_Content'}
6815: </form>
6816: NNFORM
6817: my $newsmppageform=(<<NSPFORM);
6818: <form action="/adm/coursedocs" method="post" name="newsmppg">
6819: <input type="hidden" name="active" value="ff" />
6820: $pathitem
6821: <input type="hidden" name="importdetail" value="" />
6822: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
6823: $help{'Simple Page'}
6824: </form>
6825: NSPFORM
6826:
6827: my $newsmpproblemform=(<<NSPROBFORM);
6828: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
6829: <input type="hidden" name="active" value="dd" />
6830: $pathitem
6831: <input type="hidden" name="importdetail" value="" />
6832: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
6833: $help{'Simple_Problem'}
6834: </form>
6835:
6836: NSPROBFORM
6837:
6838: my $newdropboxform=(<<NDBFORM);
6839: <form action="/adm/coursedocs" method="post" name="newdropbox">
6840: <input type="hidden" name="active" value="dd" />
6841: $pathitem
6842: <input type="hidden" name="importdetail" value="" />
6843: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
6844: $help{'Dropbox'}
6845: </form>
6846: NDBFORM
6847:
6848: my $newexuploadform=(<<NEXUFORM);
6849: <form action="/adm/coursedocs" method="post" name="newexamupload">
6850: <input type="hidden" name="active" value="dd" />
6851: $pathitem
6852: <input type="hidden" name="importdetail" value="" />
6853: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
6854: $help{'Score_Upload_Form'}
6855: </form>
6856: NEXUFORM
6857:
6858: my $newbulform=(<<NBFORM);
6859: <form action="/adm/coursedocs" method="post" name="newbul">
6860: <input type="hidden" name="active" value="ee" />
6861: $pathitem
6862: <input type="hidden" name="importdetail" value="" />
6863: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
6864: $help{'Bulletin Board'}
6865: </form>
6866: NBFORM
6867:
6868: my $newaboutmeform=(<<NAMFORM);
6869: <form action="/adm/coursedocs" method="post" name="newaboutme">
6870: <input type="hidden" name="active" value="ee" />
6871: $pathitem
6872: <input type="hidden" name="importdetail"
6873: value="$plainname=/adm/$udom/$uname/aboutme" />
6874: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
6875: $help{'My Personal Information Page'}
6876: </form>
6877: NAMFORM
6878:
6879: my $newaboutsomeoneform=(<<NASOFORM);
6880: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
6881: <input type="hidden" name="active" value="ee" />
6882: $pathitem
6883: <input type="hidden" name="importdetail" value="" />
6884: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
6885: </form>
6886: NASOFORM
6887:
6888: my $newrosterform=(<<NROSTFORM);
6889: <form action="/adm/coursedocs" method="post" name="newroster">
6890: <input type="hidden" name="active" value="ee" />
6891: $pathitem
6892: <input type="hidden" name="importdetail"
6893: value="$lt{'rost'}=/adm/viewclasslist" />
6894: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
6895: $help{'Course_Roster'}
6896: </form>
6897: NROSTFORM
6898:
6899: my $newwebpage;
6900: if ($folder =~ /^default_?(\d*)$/) {
6901: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6902: if ($1) {
6903: $newwebpage .= $1;
6904: } else {
6905: $newwebpage .= 'default';
6906: }
6907: $newwebpage .= '/new.html';
6908: }
6909: my $newwebpageform =(<<NWEBFORM);
6910: <form action="/adm/coursedocs" method="post" name="newwebpage">
6911: <input type="hidden" name="active" value="ff" />
6912: $pathitem
6913: <input type="hidden" name="importdetail" value="$newwebpage" />
6914: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
6915: $help{'Web_Page'}
6916: </form>
6917: NWEBFORM
6918: my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6919: my @ids=&Apache::lonnet::current_machine_ids();
6920: my $machines_str = "'".join("','",@ids)."'";
6921: my (%is_home,%toppath,$rolehomes);
6922: if ($env{'user.author'}) {
6923: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6924: $is_home{'author'} = 1;
6925: }
6926: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
6927: }
6928: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6929: ['active'],['ca','aa']);
6930: my %by_roletype;
6931: if (keys(%roleshash)) {
6932: foreach my $entry (keys(%roleshash)) {
6933: my ($auname,$audom,$roletype) = split(/:/,$entry);
6934: my $key = $entry;
6935: $key =~ s/:/___/g;
6936: my $author = $auname.'___'.$audom;
6937: $by_roletype{$roletype}{$author} = 1;
6938: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6939: $toppath{$author} = "/priv/$audom/$auname";
6940: if (grep(/^\Q$rolehome\E$/,@ids)) {
6941: $is_home{$author} = 1;
6942: }
6943: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
6944: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
6945: }
6946: }
6947: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6948: if (grep(/^\Q$crshome\E$/,@ids)) {
6949: $is_home{'course'} = 1;
6950: }
6951: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
6952: my $pickdir = $lt{'loca'}.
6953: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
6954: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
6955: if ($env{'user.author'}) {
6956: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
6957: }
6958: if (keys(%by_roletype)) {
6959: foreach my $possrole ('ca','aa') {
6960: if (ref($by_roletype{$possrole}) eq 'HASH') {
6961: my $roletitle = &Apache::lonnet::plaintext($possrole);
6962: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6963: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
6964: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
6965: $roletitle." ($audom/$auname)</option>\n";
6966: }
6967: }
6968: }
6969: }
6970: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n".
6971: '</select><br />'."\n".
6972: $lt{'dire'}.
6973: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
6974: '<option value=""></option>'.
6975: '</select><br />'."\n";
6976:
6977: my %seltemplate_menus;
6978: my @files = &Apache::lonhomework::get_template_list('problem');
6979: my @noexamplelink = ('blank.problem','blank.library','script.library');
6980: my $currentcategory = '';
6981: my @ordered = ('');
6982: my %templatehelp;
6983: my $defcategory = '';
6984: my @catorder = ($defcategory);
6985: $seltemplate_menus{$defcategory}->{'order'} = [''];
6986: $seltemplate_menus{$defcategory}->{'text'} = '';
6987: foreach my $file (@files) {
6988: if (ref($file) eq 'ARRAY') {
6989: my ($path,$title,$category,$help) = @{$file};
6990: next if ($title !~ /\S/);
6991: if (&js_escape($category) ne $currentcategory) {
6992: $currentcategory = &js_escape($category);
6993: push(@catorder,&js_escape($currentcategory));
6994: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6995: $seltemplate_menus{$currentcategory}->{'default'} = '';
6996: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6997: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6998: }
6999: if ($path) {
7000: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
7001: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
7002: if ($help) {
7003: $templatehelp{$path} = $help;
7004: }
7005: }
7006: }
7007: }
7008:
7009: my $templates = $lt{'cate'}.' '.
7010: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
7011: $defcategory,'tempcategory','template',
7012: \%seltemplate_menus,\@catorder,
7013: "resize_scrollbox('contentscroll','1','0');",
7014: "toggleExampleText();",'template').'<br />';
7015: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
7016: '<span id="newresexample">'.&mt('Example').'</span></a>';
7017: my $crsresform=(<<RESFORM);
7018: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
7019: $lt{'stpr'}</a>$help{'Course_Resource'}
7020: <form action="/adm/coursedocs" method="post" name="courseresform">
7021: <fieldset id="crsresform" style="display:none;">
7022: <legend>$lt{'stpr'}</legend>
7023: <input type="hidden" name="active" value="bb" />
7024: <p>
7025: $pickdir
7026: </p>
7027: <div id="newstdproblem" style="display:none;">
7028: <p>
7029: <span class="LC_nobreak">$lt{'news'}?
7030: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
7031:
7032: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
7033: </span><span id="newsubdir"></span>
7034: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
7035: </p>
7036: </div>
7037: $lt{'fnam'}
7038: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
7039: <div id="newresource" style="display:none">
7040: <p>
7041: $lt{'addp'}
7042: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
7043: $lt{'no'}</label>
7044: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
7045: $lt{'yes'}</label>
7046: <span id="newrestitle"></span>
7047: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
7048: </p>
7049: </div>
7050: <p>
7051: $lt{'uste'}
7052: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
7053: $lt{'no'}</label>
7054: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
7055: $lt{'yes'}</label>
7056: </p>
7057: <div id="newrestemplate" style="display:none">
7058: $templates
7059: $templatepreview
7060: </div>
7061: <span class="LC_nobreak">
7062: <input type="hidden" name="folderpath" value="$showpath" />
7063: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
7064: </span>
7065: <div id="stdprobswitch" style="display:none;">
7066: $rolehomes
7067: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
7068: </div>
7069: </fieldset>
7070: </form>
7071:
7072: RESFORM
7073:
7074: my $specialdocumentsform;
7075: my @specialdocumentsforma;
7076: my $gradingform;
7077: my @gradingforma;
7078: my $communityform;
7079: my @communityforma;
7080: my $newfolderform;
7081: my $newfolderb;
7082:
7083: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7084:
7085: my $newpageform=(<<NPFORM);
7086: <form action="/adm/coursedocs" method="post" name="newpage">
7087: <input type="hidden" name="folderpath" value="$path" />
7088: <input type="hidden" name="importdetail" value="" />
7089: <input type="hidden" name="active" value="ee" />
7090: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
7091: $help{'Adding_Pages'}
7092: </form>
7093: NPFORM
7094:
7095:
7096: $newfolderform=(<<NFFORM);
7097: <form action="/adm/coursedocs" method="post" name="newfolder">
7098: $pathitem
7099: <input type="hidden" name="importdetail" value="" />
7100: <input type="hidden" name="active" value="" />
7101: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
7102: </form>
7103: NFFORM
7104:
7105: my $newsylform=(<<NSYLFORM);
7106: <form action="/adm/coursedocs" method="post" name="newsyl">
7107: <input type="hidden" name="active" value="ee" />
7108: $pathitem
7109: <input type="hidden" name="importdetail"
7110: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
7111: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
7112: $help{'Syllabus'}
7113:
7114: </form>
7115: NSYLFORM
7116:
7117: my $newgroupfileform=(<<NGFFORM);
7118: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
7119: <input type="hidden" name="active" value="ee" />
7120: $pathitem
7121: <input type="hidden" name="importdetail"
7122: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
7123: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
7124: $help{'Group Portfolio'}
7125: </form>
7126: NGFFORM
7127: if ($container eq 'page') {
7128: @specialdocumentsforma=(
7129: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
7130: );
7131: } else {
7132: @specialdocumentsforma=(
7133: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
7134: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
7135: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
7136: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
7137: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
7138: );
7139: }
7140: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
7141:
7142: my @external = (
7143: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
7144: );
7145: if ($posslti) {
7146: push(@external,
7147: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
7148: );
7149: }
7150: my $externalform = &create_form_ul(&create_list_elements(@external));
7151:
7152: my @importdoc = ();
7153: unless ($container eq 'page') {
7154: push(@importdoc,
7155: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
7156: );
7157: }
7158: push(@importdoc,
7159: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
7160: );
7161: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
7162:
7163: @gradingforma=(
7164: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
7165: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
7166: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
7167: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform},
7168: );
7169: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
7170:
7171: @communityforma=(
7172: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
7173: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
7174: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
7175: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
7176: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
7177: );
7178: $communityform = &create_form_ul(&create_list_elements(@communityforma));
7179:
7180: my %orderhash = (
7181: 'aa' => ['Upload',$fileuploadform],
7182: 'bb' => ['Import',$importpubform],
7183: 'cc' => ['External',$externalform],
7184: 'dd' => ['Assessment',$gradingform],
7185: 'ff' => ['Other',$specialdocumentsform],
7186: );
7187: unless ($container eq 'page') {
7188: $orderhash{'00'} = ['Newfolder',$newfolderform];
7189: $orderhash{'ee'} = ['Collaboration',$communityform];
7190: }
7191:
7192: $hadchanges=0;
7193: unless (($supplementalflag || $toolsflag)) {
7194: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
7195: $supplementalflag,\%orderhash,$iconpath,$pathitem,
7196: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
7197: undef($navmap);
7198: if ($error) {
7199: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7200: }
7201: if ($hadchanges) {
7202: unless (&is_hash_old()) {
7203: &mark_hash_old();
7204: }
7205: }
7206:
7207: &changewarning($r,'');
7208: }
7209: }
7210:
7211: # Supplemental documents start here
7212:
7213: my $folder=$env{'form.folder'};
7214: unless ($supplementalflag) {
7215: $folder='supplemental';
7216: }
7217: if (($folder eq 'supplemental') &&
7218: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
7219: $env{'form.folderpath'} = &supplemental_base();
7220: } elsif ($allowed) {
7221: $env{'form.folderpath'} = $savefolderpath;
7222: }
7223: $pathitem = '<input type="hidden" name="folderpath" value="'.
7224: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
7225: if ($allowed) {
7226: my $folderseq=
7227: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
7228:
7229: my $supupdocform=(<<SUPDOCFORM);
7230: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
7231: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
7232: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
7233: <fieldset id="uploadsuppdocform" style="display: none;">
7234: <legend>$lt{'upfi'}</legend>
7235: <input type="hidden" name="active" value="ee" />
7236: $fileupload
7237: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
7238: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
7239: <br />
7240: <br />
7241: <span class="LC_nobreak">
7242: $checkbox
7243: </span>
7244: <br /><br />
7245: $lt{'comment'}:<br />
7246: <textarea cols="50" rows="4" name="comment"></textarea>
7247: <br />
7248: $pathitem
7249: <input type="hidden" name="cmd" value="upload_supplemental" />
7250: <input type='submit' value="$lt{'upld'}" />
7251: </fieldset>
7252: </form>
7253: SUPDOCFORM
7254:
7255: my $supnewfolderform=(<<SNFFORM);
7256: <form action="/adm/coursedocs" method="post" name="supnewfolder">
7257: <input type="hidden" name="active" value="" />
7258: $pathitem
7259: <input type="hidden" name="importdetail" value="" />
7260: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
7261: $help{'Adding_Folders'}
7262: </form>
7263: SNFFORM
7264:
7265: my $supextform =
7266: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
7267: $help{'Adding_External_Resource'},
7268: undef,undef,undef,undef,undef,undef,
7269: $disabled);
7270:
7271: my $supexttoolform =
7272: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
7273: $help{'Adding_External_Tool'},
7274: undef,undef,'tool',$coursedom,
7275: $coursenum,\%ltitools,$disabled);
7276:
7277: my $supnewsylform=(<<SNSFORM);
7278: <form action="/adm/coursedocs" method="post" name="supnewsyl">
7279: <input type="hidden" name="active" value="ff" />
7280: $pathitem
7281: <input type="hidden" name="importdetail"
7282: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
7283: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
7284: $help{'Syllabus'}
7285: </form>
7286: SNSFORM
7287:
7288: my $supnewaboutmeform=(<<SNAMFORM);
7289: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
7290: <input type="hidden" name="active" value="ff" />
7291: $pathitem
7292: <input type="hidden" name="importdetail"
7293: value="$plainname=/adm/$udom/$uname/aboutme" />
7294: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
7295: $help{'My Personal Information Page'}
7296: </form>
7297: SNAMFORM
7298:
7299: my $supwebpage;
7300: if ($folder =~ /^supplemental_?(\d*)$/) {
7301: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
7302: if ($1) {
7303: $supwebpage .= $1;
7304: } else {
7305: $supwebpage .= 'default';
7306: }
7307: $supwebpage .= '/new.html';
7308: }
7309: my $supwebpageform =(<<SWEBFORM);
7310: <form action="/adm/coursedocs" method="post" name="supwebpage">
7311: <input type="hidden" name="active" value="cc" />
7312: $pathitem
7313: <input type="hidden" name="importdetail" value="$supwebpage" />
7314: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
7315: $help{'Web_Page'}
7316: </form>
7317: SWEBFORM
7318:
7319:
7320: my @specialdocs = (
7321: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
7322: =>$supnewsylform},
7323: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
7324: =>$supnewaboutmeform},
7325: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
7326:
7327: );
7328: my @supexternal = (
7329: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
7330: =>$supextform});
7331: if ($posslti) {
7332: push(@supexternal,
7333: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
7334: =>$supexttoolform});
7335: }
7336: my @supimportdoc = (
7337: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
7338: =>$supupdocform},
7339: );
7340:
7341: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
7342: my %suporderhash = (
7343: '00' => ['Supnewfolder', $supnewfolderform],
7344: 'dd' => ['Upload',$supupdocform],
7345: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
7346: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
7347: );
7348: if ($supplementalflag) {
7349: $suppchanges = 0;
7350: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
7351: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
7352: \%ltitools,$canedit,$hostname);
7353: if ($error) {
7354: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7355: }
7356: if ($suppchanges) {
7357: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
7358: undef($suppchanges);
7359: }
7360: }
7361: } elsif ($supplementalflag) {
7362: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
7363: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
7364: $hostname);
7365: if ($error) {
7366: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7367: }
7368: }
7369:
7370: if ($needs_end) {
7371: $r->print(&endContentScreen());
7372: }
7373:
7374: if ($allowed) {
7375: $r->print('
7376: <form method="post" name="extimport" action="/adm/coursedocs">
7377: <input type="hidden" name="title" />
7378: <input type="hidden" name="url" />
7379: <input type="hidden" name="useform" />
7380: <input type="hidden" name="residx" />
7381: </form>');
7382: }
7383: } elsif ($showdoc) {
7384: # -------------------------------------------------------- This is showdoc mode
7385: $r->print("<h1>".&mt('Uploaded Document').' - '.
7386: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
7387: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
7388: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
7389: }
7390: }
7391: unless ($noendpage) {
7392: $r->print(&Apache::loncommon::end_page());
7393: }
7394: return OK;
7395: }
7396:
7397: sub embedded_form_elems {
7398: my ($phase,$primaryurl,$newidx) = @_;
7399: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7400: $newidx =~s /\D+//g;
7401: return <<STATE;
7402: <input type="hidden" name="folderpath" value="$folderpath" />
7403: <input type="hidden" name="cmd" value="upload_embedded" />
7404: <input type="hidden" name="newidx" value="$newidx" />
7405: <input type="hidden" name="phase" value="$phase" />
7406: <input type="hidden" name="primaryurl" value="$primaryurl" />
7407: STATE
7408: }
7409:
7410: sub embedded_destination {
7411: my $folder=$env{'form.folder'};
7412: my $destination = 'docs/';
7413: if ($folder =~ /^supplemental/) {
7414: $destination = 'supplemental/';
7415: }
7416: if (($folder eq 'default') || ($folder eq 'supplemental')) {
7417: $destination .= 'default/';
7418: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
7419: $destination .= $2.'/';
7420: }
7421: my $newidx = $env{'form.newidx'};
7422: $newidx =~s /\D+//g;
7423: if ($newidx) {
7424: $destination .= $newidx;
7425: }
7426: my $dir_root = '/userfiles';
7427: return ($destination,$dir_root);
7428: }
7429:
7430: sub return_to_editor {
7431: my $actionurl = '/adm/coursedocs';
7432: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7433: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7434: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7435: '</a></p>';
7436: }
7437:
7438: sub decompression_info {
7439: my ($destination,$dir_root) = &embedded_destination();
7440: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7441: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7442: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7443: my $container='sequence';
7444: my ($pathitem,$hiddenelem);
7445: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
7446: if ($env{'form.folderpath'} =~ /\:1$/) {
7447: $container='page';
7448: }
7449: unshift(@hiddens,$pathitem);
7450: foreach my $item (@hiddens) {
7451: if ($item eq 'newidx') {
7452: next if ($env{'form.'.$item} =~ /\D/);
7453: }
7454: if ($env{'form.'.$item}) {
7455: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
7456: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
7457: }
7458: }
7459: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7460: $hiddenelem);
7461: }
7462:
7463: sub decompression_phase_one {
7464: my ($dir,$file,$warning,$error,$output);
7465: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7466: &decompression_info();
7467: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
7468: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7469: } else {
7470: my $file = $1;
7471: $output =
7472: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7473: $destination,$dir_root,
7474: $hiddenelem);
7475: if ($env{'form.autoextract_camtasia'}) {
7476: $output .= &remove_archive($docudom,$docuname,$container);
7477: }
7478: }
7479: if ($error) {
7480: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7481: $error.'</p>'."\n";
7482: }
7483: if ($warning) {
7484: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7485: }
7486: return $output;
7487: }
7488:
7489: sub decompression_phase_two {
7490: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7491: &decompression_info();
7492: my $output;
7493: if ($env{'form.archivedelete'}) {
7494: $output = &remove_archive($docudom,$docuname,$container);
7495: }
7496: $output .=
7497: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
7498: $destination,$dir_root,$hiddenelem);
7499: return $output;
7500: }
7501:
7502: sub remove_archive {
7503: my ($docudom,$docuname,$container) = @_;
7504: my $map = $env{'form.folder'}.'.'.$container;
7505: my ($output,$delwarning,$delresult,$url);
7506: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7507: if ($fatal) {
7508: if ($container eq 'page') {
7509: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7510: } else {
7511: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7512: }
7513: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
7514: } else {
7515: my $currcmd = $env{'form.cmd'};
7516: my $position = $env{'form.position'};
7517: my $archiveidx = $position;
7518: if ($position > 0) {
7519: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7520: $archiveidx = $position-1;
7521: }
7522: $env{'form.cmd'} = 'remove_'.$archiveidx;
7523: my ($title,$url,@rrest) =
7524: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7525: if ($url eq $env{'form.archiveurl'}) {
7526: if (&handle_edit_cmd($docuname,$docudom)) {
7527: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
7528: if ($suppchanges) {
7529: &Apache::lonnet::update_supp_caches($docudom,$docuname);
7530: undef($suppchanges);
7531: }
7532: if ($fatal) {
7533: if ($container eq 'page') {
7534: $delwarning = &mt('An error occurred updating the contents of the current page.');
7535: } else {
7536: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7537: }
7538: } else {
7539: $delresult = &mt('Archive file removed.');
7540: }
7541: }
7542: } else {
7543: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7544: ' '.&mt('As a result the archive file has not been removed.');
7545: }
7546: }
7547: $env{'form.cmd'} = $currcmd;
7548: }
7549: if ($delwarning) {
7550: $output = '<p class="LC_warning">'.
7551: $delwarning.
7552: '</p>';
7553: }
7554: if ($delresult) {
7555: $output .= '<p class="LC_info">'.
7556: $delresult.
7557: '</p>';
7558: }
7559: return $output;
7560: }
7561:
7562: sub generate_admin_menu {
7563: my ($crstype,$canedit) = @_;
7564: my $lc_crstype = lc($crstype);
7565: my ($home,$other,%outhash)=&authorhosts();
7566: my %lt= ( # do not translate here
7567: 'vc' => 'Verify Content',
7568: 'cv' => 'Check/Set Resource Versions',
7569: 'ls' => 'List Resource Identifiers',
7570: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
7571: 'imse' => 'Export contents to IMS Archive',
7572: 'dcd' => "Copy $crstype Content to Authoring Space",
7573: );
7574: my ($candump,$dumpurl);
7575: if ($home + $other > 0) {
7576: $candump = 'F';
7577: if ($home) {
7578: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7579: } else {
7580: my @hosts;
7581: foreach my $aurole (keys(%outhash)) {
7582: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7583: push(@hosts,$outhash{$aurole});
7584: }
7585: }
7586: if (@hosts == 1) {
7587: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7588: '&role='.
7589: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7590: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7591: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7592: } else {
7593: $dumpurl = "javascript:choose_switchserver_window()";
7594: }
7595: }
7596: }
7597: my @menu=
7598: ({ categorytitle=>'Administration',
7599: items =>[
7600: { linktext => $lt{'vc'},
7601: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7602: permission => 'F',
7603: help => 'Docs_Verify_Content',
7604: icon => 'verify.png',
7605: linktitle => 'Verify contents can be retrieved/rendered',
7606: },
7607: { linktext => $lt{'cv'},
7608: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7609: permission => 'F',
7610: help => 'Docs_Check_Resource_Versions',
7611: icon => 'resversion.png',
7612: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7613: },
7614: { linktext => $lt{'ls'},
7615: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7616: permission => 'F',
7617: #help => '',
7618: icon => 'symbs.png',
7619: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7620: },
7621: { linktext => $lt{'ct'},
7622: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7623: permission => 'F',
7624: help => 'Docs_Short_URLs',
7625: icon => 'shorturls.png',
7626: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7627: },
7628: ]
7629: });
7630: if ($canedit) {
7631: push(@menu,
7632: { categorytitle=>'Export',
7633: items =>[
7634: { linktext => $lt{'imse'},
7635: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7636: permission => 'F',
7637: help => 'Docs_Export_Course_Docs',
7638: icon => 'imsexport.png',
7639: linktitle => $lt{'imse'},
7640: },
7641: { linktext => $lt{'dcd'},
7642: url => $dumpurl,
7643: permission => $candump,
7644: help => 'Docs_Dump_Course_Docs',
7645: icon => 'dump.png',
7646: linktitle => $lt{'dcd'},
7647: },
7648: ]
7649: });
7650: }
7651: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7652: '<input type="hidden" id="dummy" />'."\n".
7653: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7654: '</form>';
7655: }
7656:
7657: sub generate_edit_table {
7658: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
7659: $need_save,$copyfolder,$canedit) = @_;
7660: return unless(ref($orderhash_ref) eq 'HASH');
7661: my %orderhash = %{$orderhash_ref};
7662: my ($form, $activetab, $active, $disabled);
7663: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
7664: $activetab = $env{'form.active'};
7665: }
7666: unless ($canedit) {
7667: $disabled = ' disabled="disabled"';
7668: }
7669: my $backicon = $iconpath.'clickhere.gif';
7670: my $backtext = &mt('Exit Editor');
7671: $form = '<div class="LC_Box" style="margin:0;">'.
7672: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7673: '<li class="goback">'.
7674: '<a href="javascript:toContents('."'$jumpto'".');">'.
7675: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7676: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7677: '<li>'.
7678: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7679: &mt('Undo Delete').'</a></li>'."\n";
7680: if ($env{'form.docslog'}) {
7681: $form .= '<li class="active">';
7682: } else {
7683: $form .= '<li>';
7684: }
7685: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7686: &mt('History').'</a></li>'."\n";
7687: if ($env{'form.docslog'}) {
7688: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7689: &mt('Edit').'</a></li>'."\n";
7690: }
7691: foreach my $name (reverse(sort(keys(%orderhash)))) {
7692: if($name ne '00'){
7693: if($activetab eq '' || $activetab ne $name){
7694: $active = '';
7695: }elsif($activetab eq $name){
7696: $active = 'class="active"';
7697: }
7698: $form .= '<li style="float:right" '.$active
7699: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
7700: } else {
7701: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
7702:
7703: }
7704: }
7705: $form .= '</ul>'."\n";
7706: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
7707:
7708: if ($to_show ne '') {
7709: my $saveform;
7710: if ($need_save) {
7711: my $button = &mt('Make changes');
7712: my $path;
7713: if ($env{'form.folderpath'}) {
7714: $path =
7715: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7716: }
7717: $saveform = <<"END";
7718: <div id="multisave" style="display:none; clear:both;" >
7719: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7720: <input type="hidden" name="folderpath" value="$path" />
7721: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7722: <input type="hidden" name="allhiddenresource" value="" />
7723: <input type="hidden" name="allencrypturl" value="" />
7724: <input type="hidden" name="allrandompick" value="" />
7725: <input type="hidden" name="allrandomorder" value="" />
7726: <input type="hidden" name="changeparms" value="" />
7727: <input type="hidden" name="multiremove" value="" />
7728: <input type="hidden" name="multicut" value="" />
7729: <input type="hidden" name="multicopy" value="" />
7730: <input type="hidden" name="multichange" value="" />
7731: <input type="hidden" name="copyfolder" value="$copyfolder" />
7732: <input type="submit" name="savemultiples" value="$button" $disabled />
7733: </form>
7734: </div>
7735: END
7736: }
7737: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
7738: }
7739: foreach my $field (keys(%orderhash)){
7740: if($field ne '00'){
7741: if($activetab eq '' || $activetab ne $field){
7742: $active = 'style="display: none;float:left"';
7743: }elsif($activetab eq $field){
7744: $active = 'style="display:block;float:left"';
7745: }
7746: $form .= '<div id="'.$field.$tid.'"'
7747: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
7748: .'</div>'."\n";
7749: }
7750: }
7751: unless ($env{'form.docslog'}) {
7752: $form .= '</div></div>'."\n";
7753: }
7754: return $form;
7755: }
7756:
7757: sub editing_js {
7758: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7759: $londocroot,$canedit,$hostname,$navmapref) = @_;
7760: my %js_lt = &Apache::lonlocal::texthash(
7761: p_mnf => 'Name of New Folder',
7762: t_mnf => 'New Folder',
7763: p_mnp => 'Name of New Page',
7764: t_mnp => 'New Page',
7765: p_mxu => 'Title for the External Score',
7766: p_msp => 'Name of Simple Course Page',
7767: p_msb => 'Title for the Problem',
7768: p_mdb => 'Title for the Drop Box',
7769: p_mbb => 'Title for the Discussion Board',
7770: p_mwp => 'Title for Web Page',
7771: p_mnr => 'Title for the Resource',
7772: p_mab => "Enter user:domain for User's Personal Information Page",
7773: p_mab2 => 'Personal Information Page of ',
7774: p_mab_alrt1 => 'Not a valid user:domain',
7775: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7776: p_chn => 'New Title',
7777: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
7778: p_rmr2a => 'Remove',
7779: p_rmr2b => '?',
7780: p_rmr3a => 'Remove those',
7781: p_rmr3b => 'items?',
7782: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7783: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
7784: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7785: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
7786: p_ctr2a => 'Cut',
7787: p_ctr2b => '?',
7788: p_ctr3a => 'Cut those',
7789: p_ctr3b => 'items?',
7790: setal => 'Enter a (unique) alias',
7791: delal => 'Are you sure you want to eliminate the alias?',
7792: rpck => 'Enter number to pick (e.g., 3)',
7793: imsfile => 'You must choose an IMS package for import',
7794: imscms => 'You must select which Course Management System was the source of the IMS package',
7795: invurl => 'Invalid URL',
7796: titbl => 'Title is blank',
7797: more => '(More ...)',
7798: less => '(Less ...)',
7799: noor => 'No actions selected or changes to settings specified.',
7800: noch => 'No changes to settings specified.',
7801: noac => 'No actions selected.',
7802: nofi => 'No file selected',
7803: tinc => 'Title in course',
7804: sunm => 'Sub-directory name',
7805: edri => 'Editing rights unavailable for your current role.',
7806: sele => 'Select',
7807: swit => 'Switch server required',
7808: );
7809: &js_escape(\%js_lt);
7810: my $crstype = &Apache::loncommon::course_type();
7811: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7812: my $main_container_page;
7813: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7814: $main_container_page = 1;
7815: }
7816: my $backtourl;
7817: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
7818: my $toplevelsupp = &supplemental_base();
7819: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
7820: my @ids=&Apache::lonnet::current_machine_ids();
7821: my $machines_str = "'".join("','",@ids)."'";
7822: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7823: my $caller = $1;
7824: if ($caller =~ /^supplemental/) {
7825: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7826: } else {
7827: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7828: $res = &Apache::lonnet::clutter($res);
7829: if (&Apache::lonnet::is_on_map($res)) {
7830: my ($url,$anchor);
7831: if ($res =~ /^([^#]+)#([^#]+)$/) {
7832: $url = $1;
7833: $anchor = $2;
7834: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7835: $caller = $1.&escape('#').$anchor;
7836: }
7837: } else {
7838: $url = $res;
7839: }
7840: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7841: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7842: $backtourl .= '?navmap=1';
7843: } else {
7844: $backtourl .= '?symb='.
7845: &HTML::Entities::encode($caller,'<>&"');
7846: }
7847: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7848: if (($ENV{'SERVER_PORT'} == 443) &&
7849: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
7850: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
7851: if ($hostname ne '') {
7852: $backtourl = 'http://'.$hostname.$backtourl;
7853: }
7854: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7855: }
7856: }
7857: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7858: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
7859: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
7860: if ($hostname ne '') {
7861: $backtourl = 'http://'.$hostname.$backtourl;
7862: }
7863: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7864: }
7865: }
7866: }
7867: if ($anchor ne '') {
7868: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7869: }
7870: $backtourl = &Apache::loncommon::escape_single($backtourl);
7871: } else {
7872: $backtourl = '/adm/navmaps';
7873: }
7874: }
7875: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7876: $backtourl = '/adm/menu';
7877: } elsif ($supplementalflag) {
7878: if (($env{'request.role.adv'}) ||
7879: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7880: $backtourl = '/adm/supplemental';
7881: } else {
7882: $backtourl = '/adm/navmaps';
7883: }
7884: } else {
7885: $backtourl = '/adm/navmaps';
7886: }
7887:
7888: my $fieldsets = "'doc'";
7889: unless ($main_container_page) {
7890: $fieldsets .=",'ims'";
7891: }
7892: my $extfieldsets = "'ext'";
7893: if ($posslti) {
7894: $extfieldsets .= ",'tool'";
7895: }
7896: if ($supplementalflag) {
7897: $fieldsets = "'suppdoc'";
7898: $extfieldsets = "'suppext'";
7899: if ($posslti) {
7900: $extfieldsets .= ",'supptool'";
7901: }
7902: }
7903:
7904: my $jsmakefunctions;
7905: if ($canedit) {
7906: $jsmakefunctions = <<ENDNEWSCRIPT;
7907: function makenewfolder(targetform,folderseq) {
7908: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
7909: if (foldername) {
7910: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
7911: targetform.submit();
7912: }
7913: }
7914:
7915: function makenewpage(targetform,folderseq) {
7916: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
7917: if (pagename) {
7918: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
7919: targetform.submit();
7920: }
7921: }
7922:
7923: function makeexamupload() {
7924: var title=prompt('$js_lt{"p_mxu"}');
7925: if (title) {
7926: this.document.forms.newexamupload.importdetail.value=
7927: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
7928: this.document.forms.newexamupload.submit();
7929: }
7930: }
7931:
7932: function makesmppage() {
7933: var title=prompt('$js_lt{"p_msp"}');
7934: if (title) {
7935: this.document.forms.newsmppg.importdetail.value=
7936: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
7937: this.document.forms.newsmppg.submit();
7938: }
7939: }
7940:
7941: function makewebpage(type) {
7942: var title=prompt('$js_lt{"p_mwp"}');
7943: var formname;
7944: if (type == 'supp') {
7945: formname = this.document.forms.supwebpage;
7946: } else {
7947: formname = this.document.forms.newwebpage;
7948: }
7949: if (title) {
7950: var webpage = formname.importdetail.value;
7951: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
7952: formname.submit();
7953: }
7954: }
7955:
7956: function makesmpproblem() {
7957: var title=prompt('$js_lt{"p_msb"}');
7958: if (title) {
7959: this.document.forms.newsmpproblem.importdetail.value=
7960: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
7961: this.document.forms.newsmpproblem.submit();
7962: }
7963: }
7964:
7965: function makedropbox() {
7966: var title=prompt('$js_lt{"p_mdb"}');
7967: if (title) {
7968: this.document.forms.newdropbox.importdetail.value=
7969: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
7970: this.document.forms.newdropbox.submit();
7971: }
7972: }
7973:
7974: function makebulboard() {
7975: var title=prompt('$js_lt{"p_mbb"}');
7976: if (title) {
7977: this.document.forms.newbul.importdetail.value=
7978: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
7979: this.document.forms.newbul.submit();
7980: }
7981: }
7982:
7983: function makeabout() {
7984: var user=prompt("$js_lt{'p_mab'}");
7985: if (user) {
7986: var comp=new Array();
7987: comp=user.split(':');
7988: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7989: if ((comp[0]) && (comp[1])) {
7990: this.document.forms.newaboutsomeone.importdetail.value=
7991: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
7992: this.document.forms.newaboutsomeone.submit();
7993: } else {
7994: alert("$js_lt{'p_mab_alrt1'}");
7995: }
7996: } else {
7997: alert("$js_lt{'p_mab_alrt2'}");
7998: }
7999: }
8000: }
8001:
8002: function makenew(targetform) {
8003: targetform.submit();
8004: }
8005:
8006: function changename(folderpath,index,oldtitle) {
8007: var title=prompt('$js_lt{"p_chn"}',oldtitle);
8008: if (title) {
8009: this.document.forms.renameform.markcopy.value='';
8010: this.document.forms.renameform.title.value=title;
8011: this.document.forms.renameform.cmd.value='rename_'+index;
8012: this.document.forms.renameform.folderpath.value=folderpath;
8013: this.document.forms.renameform.submit();
8014: }
8015: }
8016:
8017: function setalias(folderpath,index) {
8018: var alias = prompt('$js_lt{"setal"}');
8019: if ((alias != null) && (alias != '')) {
8020: this.document.forms.aliasform.alias.value=alias;
8021: this.document.forms.aliasform.cmd.value='setalias_'+index;
8022: this.document.forms.aliasform.folderpath.value=folderpath;
8023: this.document.forms.aliasform.submit();
8024: }
8025: }
8026:
8027: function delalias(folderpath,index) {
8028: if (confirm('$js_lt{"delal"}')) {
8029: this.document.forms.aliasform.cmd.value='delalias_'+index;
8030: this.document.forms.aliasform.folderpath.value=folderpath;
8031: this.document.forms.aliasform.submit();
8032: }
8033: }
8034:
8035: ENDNEWSCRIPT
8036: } else {
8037: $jsmakefunctions = <<ENDNEWSCRIPT;
8038:
8039: function makenewfolder() {
8040: alert("$js_lt{'edri'}");
8041: }
8042:
8043: function makenewpage() {
8044: alert("$js_lt{'edri'}");
8045: }
8046:
8047: function makeexamupload() {
8048: alert("$js_lt{'edri'}");
8049: }
8050:
8051: function makesmppage() {
8052: alert("$js_lt{'edri'}");
8053: }
8054:
8055: function makewebpage(type) {
8056: alert("$js_lt{'edri'}");
8057: }
8058:
8059: function makesmpproblem() {
8060: alert("$js_lt{'edri'}");
8061: }
8062:
8063: function makedropbox() {
8064: alert("$js_lt{'edri'}");
8065: }
8066:
8067: function makebulboard() {
8068: alert("$js_lt{'edri'}");
8069: }
8070:
8071: function makeabout() {
8072: alert("$js_lt{'edri'}");
8073: }
8074:
8075: function changename() {
8076: alert("$js_lt{'edri'}");
8077: }
8078:
8079: function setalias() {
8080: alert("$js_lt{'edri'}");
8081: }
8082:
8083: function delalias() {
8084: alert("$js_lt{'edri'}");
8085: }
8086:
8087: function makenew() {
8088: alert("$js_lt{'edri'}");
8089: }
8090:
8091: function groupimport() {
8092: alert("$js_lt{'edri'}");
8093: }
8094:
8095: function groupsearch() {
8096: alert("$js_lt{'edri'}");
8097: }
8098:
8099: function groupopen(url,recover) {
8100: var options="scrollbars=1,resizable=1,menubar=0";
8101: idxflag=1;
8102: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
8103: idx.focus();
8104: }
8105:
8106: ENDNEWSCRIPT
8107:
8108: }
8109: return <<ENDSCRIPT;
8110:
8111: $jsmakefunctions
8112:
8113: function toggleUpload(caller) {
8114: var blocks = Array($fieldsets);
8115: for (var i=0; i<blocks.length; i++) {
8116: var disp = 'none';
8117: if (caller == blocks[i]) {
8118: var curr = document.getElementById('upload'+caller+'form').style.display;
8119: if (curr == 'none') {
8120: disp='block';
8121: }
8122: }
8123: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
8124: }
8125: resize_scrollbox('contentscroll','1','1');
8126: return;
8127: }
8128:
8129: function toggleExternal(caller) {
8130: var blocks = Array($extfieldsets);
8131: for (var i=0; i<blocks.length; i++) {
8132: var disp = 'none';
8133: if (caller == blocks[i]) {
8134: var curr = document.getElementById('external'+caller+'form').style.display;
8135: if (curr == 'none') {
8136: disp='block';
8137: }
8138: }
8139: document.getElementById('external'+blocks[i]+'form').style.display=disp;
8140: if ((caller == 'tool') || (caller == 'supptool')) {
8141: if (disp == 'block') {
8142: if (document.getElementById('LC_exttoolid')) {
8143: var toolselector = document.getElementById('LC_exttoolid');
8144: var suppflag = 0;
8145: if (caller == 'supptool') {
8146: suppflag = 1;
8147: }
8148: currForm = document.getElementById('new'+caller);
8149: updateExttool(toolselector,currForm,suppflag);
8150: }
8151: }
8152: }
8153: }
8154: resize_scrollbox('contentscroll','1','1');
8155: return;
8156: }
8157:
8158: function toggleMap(caller) {
8159: var disp = 'none';
8160: if (document.getElementById('importmapform')) {
8161: if (caller == 'map') {
8162: var curr = document.getElementById('importmapform').style.display;
8163: if (curr == 'none') {
8164: disp='block';
8165: }
8166: }
8167: document.getElementById('importmapform').style.display=disp;
8168: resize_scrollbox('contentscroll','1','1');
8169: }
8170: return;
8171: }
8172:
8173: function toggleCrsRes(caller) {
8174: var disp = 'none';
8175: if (document.getElementById('crsresform')) {
8176: if (caller == 'res') {
8177: var form = document.getElementById('crsresform');
8178: var curr = form.style.display;
8179: if (curr == 'none') {
8180: disp='block';
8181: document.courseresform.authorrole.selectedIndex = 0;
8182: document.courseresform.authorpath.selectedIndex = 0;
8183: document.courseresform.newresourceadd.selectedIndex = 0;
8184: populateDirSelects(form,'authorrole','authorpath',1,0,0);
8185: toggleNewInCourse(document.courseresform);
8186: if (document.getElementById('newresource')) {
8187: document.getElementById('newresource').style.display = 'none';
8188: }
8189: if (document.courseresform.newresusetemp.length) {
8190: document.courseresform.newresusetemp[0].checked = true;
8191: toggleWithTemplate(document.courseresform);
8192: }
8193: document.courseresform.newresourcename.value = '';
8194: }
8195: }
8196: if (document.courseresform.newsubdir.length) {
8197: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
8198: if (document.courseresform.newsubdir[j].value == 0) {
8199: document.courseresform.newsubdir[j].checked = true;
8200: }
8201: break;
8202: }
8203: if (document.getElementById('newsubdirname')) {
8204: document.getElementById('newsubdirname').type = "hidden";
8205: document.getElementById('newsubdirname').value = "";
8206: }
8207: if (document.getElementById('newsubdir')) {
8208: document.getElementById('newsubdir').innerHTML = "";
8209: }
8210: }
8211: document.getElementById('crsresform').style.display=disp;
8212: resize_scrollbox('contentscroll','1','0');
8213: }
8214: return;
8215: }
8216:
8217: function toggleNewsubdir(form) {
8218: if (form.newsubdir.length) {
8219: for (var j=0; j<form.newsubdir.length; j++) {
8220: if (form.newsubdir[j].checked) {
8221: if (document.getElementById('newsubdirname')) {
8222: if (form.newsubdir[j].value == '1') {
8223: document.getElementById('newsubdirname').type = "text";
8224: if (document.getElementById('newsubdir')) {
8225: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
8226: }
8227: } else {
8228: document.getElementById('newsubdirname').type = "hidden";
8229: document.getElementById('newsubdirname').value = "";
8230: document.getElementById('newsubdir').innerHTML = "";
8231: }
8232: }
8233: break;
8234: }
8235: }
8236: }
8237: }
8238:
8239: function toggleCrsResTitle() {
8240: if (document.getElementById('newresource')) {
8241: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8242: if (selloc == 'course') {
8243: document.getElementById('newresource').style.display = 'inline';
8244: document.courseresform.newresourceadd[0].checked = true;
8245: toggleNewInCourse(document.courseresform);
8246: } else {
8247: document.getElementById('newresource').style.display = 'none';
8248: }
8249: }
8250: if (document.getElementById('newstdproblem')) {
8251: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8252: document.getElementById('newstdproblem').style.display = 'none';
8253: if (document.getElementById('stdprobswitch')) {
8254: document.getElementById('stdprobswitch').style.display = 'block';
8255: }
8256: } else {
8257: document.getElementById('newstdproblem').style.display = 'block';
8258: if (document.getElementById('stdprobswitch')) {
8259: document.getElementById('stdprobswitch').style.display = 'none';
8260: }
8261: }
8262: }
8263: }
8264:
8265: function toggleNewInCourse(form) {
8266: if (form.newresourceadd.length) {
8267: for (var i=0; i<form.newresourceadd.length; i++) {
8268: if (form.newresourceadd[i].checked) {
8269: if (document.getElementById('newresourcetitle')) {
8270: if (form.newresourceadd[i].value == '1') {
8271: document.getElementById('newresourcetitle').type = 'text';
8272: if (document.getElementById('newrestitle')) {
8273: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
8274: }
8275: } else {
8276: document.getElementById('newresourcetitle').type = 'hidden';
8277: document.getElementById('newresourcetitle').value = '';
8278: if (document.getElementById('newrestitle')) {
8279: document.getElementById('newrestitle').innerHTML = '';
8280: }
8281: }
8282: }
8283: break;
8284: }
8285: }
8286: }
8287: }
8288:
8289: function toggleWithTemplate(form) {
8290: if (form.newresusetemp.length) {
8291: for (var i=0; i<form.newresusetemp.length; i++) {
8292: if (form.newresusetemp[i].checked) {
8293: if (document.getElementById('newrestemplate')) {
8294: if (form.newresusetemp[i].value == '1') {
8295: document.getElementById('newrestemplate').style.display = 'inline';
8296: toggleExampleText();
8297: } else {
8298: form.tempcategory.selectedIndex = 0;
8299: select1template_changed();
8300: document.getElementById('newrestemplate').style.display = 'none';
8301: }
8302: }
8303: }
8304: }
8305: }
8306: }
8307:
8308: function toggleExampleText() {
8309: if (document.getElementById('newresexample')) {
8310: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
8311: if (url == '') {
8312: document.getElementById('newresexample').style.fontWeight = 'normal';
8313: } else {
8314: document.getElementById('newresexample').style.fontWeight = 'bold';
8315: }
8316: }
8317: }
8318:
8319: function getExample(width,height,scrolling,transparency) {
8320: var url;
8321: if (document.courseresform.newresusetemp.length) {
8322: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
8323: if (document.courseresform.newresusetemp[i].checked) {
8324: if (document.courseresform.newresusetemp[i].value == '1') {
8325: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
8326: if (url == '') {
8327: alert('Pick a category and template');
8328: } else {
8329: url = url.replace("$londocroot","");
8330: url += '?inhibitmenu=yes';
8331: }
8332: }
8333: break;
8334: }
8335: }
8336: }
8337: if (url != '') {
8338: openMyModal(url,width,height,scrolling,transparency,'');
8339: }
8340: }
8341:
8342: function toggleImportCrsres(caller) {
8343: var disp = 'none';
8344: if (document.getElementById('importcrsresform')) {
8345: if (caller == 'res') {
8346: var curr = document.getElementById('importcrsresform').style.display;
8347: if (curr == 'none') {
8348: disp='block';
8349: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
8350: if ((document.getElementById('importcrsrescontent')) &&
8351: (document.getElementById('importcrsresempty'))) {
8352: var selelem = document.crsresimportform.elements['coursepath'];
8353: var numdirs = 0;
8354: if (selelem.options.length) {
8355: numdirs = selelem.options.length - 1;
8356: }
8357: if (numdirs) {
8358: document.getElementById('importcrsrescontent').style.display='block';
8359: document.getElementById('importcrsresempty').style.display='none';
8360: } else {
8361: document.getElementById('importcrsrescontent').style.display='none';
8362: document.getElementById('importcrsresempty').style.display='block';
8363: }
8364: }
8365: }
8366: }
8367: document.getElementById('importcrsresform').style.display=disp;
8368: resize_scrollbox('contentscroll','1','0');
8369: }
8370: return;
8371: }
8372:
8373: $showfile_js
8374:
8375: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
8376: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
8377: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
8378: var selelem = form.elements[dirsel];
8379: var i, numfiles = selelem.options.length -1;
8380: if (numfiles >=0) {
8381: for (i = numfiles; i >= 0; i--) {
8382: selelem.remove(i);
8383: }
8384: }
8385: if ((location == '') || (location == null) || (location == 'undefined')) {
8386: if (selelem.options.length == 0) {
8387: selelem.options[selelem.options.length] = new Option('','');
8388: selelem.selectedIndex = 0;
8389: }
8390: if (document.getElementById('newstdproblem')) {
8391: document.getElementById('newstdproblem').style.display = 'none';
8392: }
8393: return;
8394: }
8395: var machineIds = new Array($machines_str);
8396: var athome = 0;
8397: var role = location;
8398: if ((location == 'author') || (location == 'course')) {
8399: if (document.getElementById('rolehome_'+location)) {
8400: var currhome = document.getElementById('rolehome_'+location).value;
8401: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8402: if (machineIds.includes(currhome)) {
8403: athome = 1;
8404: }
8405: }
8406: }
8407: } else {
8408: const roleinfo = location.split('___');
8409: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
8410: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
8411: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
8412: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8413: if (machineIds.includes(currhome)) {
8414: athome = 1;
8415: }
8416: }
8417: }
8418: }
8419: if (athome) {
8420: if (document.getElementById('stdprobswitch')) {
8421: document.getElementById('stdprobswitch').style.display = 'none';
8422: }
8423: if (document.getElementById('newstdproblem')) {
8424: document.getElementById('newstdproblem').style.display = 'none';
8425: }
8426: var http = new XMLHttpRequest();
8427: var url = "/adm/courseauthor";
8428: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
8429: http.open("POST", url, true);
8430: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
8431: http.onreadystatechange = function() {
8432: if (http.readyState == 4 && http.status == 200) {
8433: var data = JSON.parse(http.responseText);
8434: if (Array.isArray(data.dirs)) {
8435: var len = data.dirs.length;
8436: if (len) {
8437: if (len > 1) {
8438: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
8439: }
8440: }
8441: if (len) {
8442: var j;
8443: for (j = 0; j < len; j++) {
8444: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
8445: }
8446: selelem.selectedIndex = 0;
8447: if (len == 1) {
8448: toggleCrsResTitle();
8449: }
8450: }
8451: }
8452: }
8453: }
8454: http.send(params);
8455: } else {
8456: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
8457: selelem.selectedIndex = 0;
8458: if (document.getElementById('stdprobswitch')) {
8459: document.getElementById('stdprobswitch').style.display = 'block';
8460: }
8461: if (document.getElementById('newstdproblem')) {
8462: document.getElementById('newstdproblem').style.display = 'none';
8463: }
8464: }
8465: }
8466: return;
8467: }
8468:
8469: function switchForProb() {
8470: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8471: var url = '/adm/switchserver?otherserver=';
8472: var newhostid = '';
8473: var role = '';
8474: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8475: if (selloc == 'author') {
8476: newhostid = document.courseresform.rolehome_author.value;
8477: role = "au./&js_escape($env{'user.domain'})/";
8478: } else if (selloc == 'course') {
8479: newhostid = document.courseresform.rolehome_course.value;
8480: role = "&js_escape($env{'request.role'})";
8481: } else {
8482: var items = new Array();
8483: items = selloc.split('___');
8484: var len = document.courseresform.rolehome_coauthor.length;
8485: if (null == len) {
8486: var currval = document.courseresform.rolehome_coauthor.value;
8487: if (null != currval) {
8488: var info = new Array();
8489: info = currval.split('=');
8490: newhostid = info[2];
8491: role = info[0]+'./'+info[1];
8492: }
8493: } else {
8494: for (var i=0; i<len; i++) {
8495: var currval = document.courseresform.rolehome_coauthor[i].value;
8496: if (null != currval) {
8497: var info = new Array();
8498: info = currval.split('=');
8499: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
8500: newhostid = info[2];
8501: role = info[0]+'./'+info[1];
8502: break;
8503: }
8504: }
8505: }
8506: }
8507: }
8508: if (newhostid != '') {
8509: url += newhostid;
8510: if (role != '') {
8511: url += '&role='+role;
8512: }
8513: document.location.href = url;
8514: }
8515: }
8516: return;
8517: }
8518:
8519: function makeims(imsform) {
8520: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
8521: alert("$js_lt{'imsfile'}");
8522: return;
8523: }
8524: if (imsform.source.selectedIndex == 0) {
8525: alert("$js_lt{'imscms'}");
8526: return;
8527: }
8528: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
8529: imsform.submit();
8530: }
8531:
8532: function updatePick(targetform,index,caller) {
8533: var pickitem;
8534: var picknumitem;
8535: var picknumtext;
8536: if (index == 'all') {
8537: pickitem = document.getElementById('randompickall');
8538: picknumitem = document.getElementById('rpicknumall');
8539: picknumtext = document.getElementById('rpicktextall');
8540: } else {
8541: pickitem = document.getElementById('randompick_'+index);
8542: picknumitem = document.getElementById('rpicknum_'+index);
8543: picknumtext = document.getElementById('randompicknum_'+index);
8544: }
8545: if (pickitem.checked) {
8546: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
8547: if (picknum == '' || picknum == null) {
8548: if (caller == 'check') {
8549: pickitem.checked=false;
8550: if (index == 'all') {
8551: picknumtext.innerHTML = '';
8552: if (caller == 'link') {
8553: propagateState(targetform,'rpicknum');
8554: }
8555: } else {
8556: checkForSubmit(targetform,'randompick','settings');
8557: }
8558: }
8559: } else {
8560: picknum.toString();
8561: var regexdigit=/^\\d+\$/;
8562: if (regexdigit.test(picknum)) {
8563: picknumitem.value = picknum;
8564: if (index == 'all') {
8565: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
8566: if (caller == 'link') {
8567: propagateState(targetform,'rpicknum');
8568: }
8569: } else {
8570: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
8571: checkForSubmit(targetform,'randompick','settings');
8572: }
8573: } else {
8574: if (caller == 'check') {
8575: if (index == 'all') {
8576: picknumtext.innerHTML = '';
8577: if (caller == 'link') {
8578: propagateState(targetform,'rpicknum');
8579: }
8580: } else {
8581: pickitem.checked=false;
8582: checkForSubmit(targetform,'randompick','settings');
8583: }
8584: }
8585: return;
8586: }
8587: }
8588: } else {
8589: picknumitem.value = '';
8590: picknumtext.innerHTML = '';
8591: if (index == 'all') {
8592: if (caller == 'link') {
8593: propagateState(targetform,'rpicknum');
8594: }
8595: } else {
8596: checkForSubmit(targetform,'randompick','settings');
8597: }
8598: }
8599: }
8600:
8601: function propagateState(form,param) {
8602: if (document.getElementById(param+'all')) {
8603: var setcheck = 0;
8604: var rpick = 0;
8605: if (param == 'rpicknum') {
8606: if (document.getElementById('randompickall')) {
8607: if (document.getElementById('randompickall').checked) {
8608: if (document.getElementById('rpicknumall')) {
8609: rpick = document.getElementById('rpicknumall').value;
8610: }
8611: }
8612: }
8613: } else {
8614: if (document.getElementById(param+'all').checked) {
8615: setcheck = 1;
8616: }
8617: }
8618: var allidxlist;
8619: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8620: if (document.getElementById('all'+param+'idx')) {
8621: allidxlist = document.getElementById('all'+param+'idx').value;
8622: }
8623: var actions = new Array ('remove','cut','copy');
8624: for (var i=0; i<actions.length; i++) {
8625: if (actions[i] != param) {
8626: if (document.getElementById(actions[i]+'all')) {
8627: document.getElementById(actions[i]+'all').checked = false;
8628: }
8629: }
8630: }
8631: }
8632: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
8633: allidxlist = form.allidx.value;
8634: }
8635: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
8636: allidxlist = form.allmapidx.value;
8637: }
8638: if ((allidxlist != '') && (allidxlist != null)) {
8639: var allidxs = allidxlist.split(',');
8640: if (allidxs.length > 1) {
8641: for (var i=0; i<allidxs.length; i++) {
8642: if (document.getElementById(param+'_'+allidxs[i])) {
8643: if (param == 'rpicknum') {
8644: if (document.getElementById('randompick_'+allidxs[i])) {
8645: if (document.getElementById('randompick_'+allidxs[i]).checked) {
8646: document.getElementById(param+'_'+allidxs[i]).value = rpick;
8647: if (rpick > 0) {
8648: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
8649: } else {
8650: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8651: }
8652: }
8653: }
8654: } else {
8655: if (setcheck == 1) {
8656: document.getElementById(param+'_'+allidxs[i]).checked = true;
8657: } else {
8658: document.getElementById(param+'_'+allidxs[i]).checked = false;
8659: if (param == 'randompick') {
8660: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8661: }
8662: }
8663: }
8664: }
8665: }
8666: if (setcheck == 1) {
8667: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8668: var actions = new Array('copy','cut','remove');
8669: for (var i=0; i<actions.length; i++) {
8670: var otheractions;
8671: var otheridxs;
8672: if (actions[i] === param) {
8673: continue;
8674: } else {
8675: if (document.getElementById('all'+actions[i]+'idx')) {
8676: otheractions = document.getElementById('all'+actions[i]+'idx').value;
8677: otheridxs = otheractions.split(',');
8678: if (otheridxs.length > 1) {
8679: for (var j=0; j<otheridxs.length; j++) {
8680: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
8681: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
8682: }
8683: }
8684: }
8685: }
8686: }
8687: }
8688: }
8689: }
8690: }
8691: }
8692: }
8693: return;
8694: }
8695:
8696: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
8697: var canedit = '$canedit';
8698: if (canedit == '') {
8699: alert("$js_lt{'edri'}");
8700: return;
8701: }
8702: var dosettings;
8703: var doaction;
8704: var control = document.togglemultsettings;
8705: if (context == 'actions') {
8706: control = document.togglemultactions;
8707: doaction = 1;
8708: } else {
8709: dosettings = 1;
8710: }
8711: if (control) {
8712: if (control.showmultpick.length) {
8713: for (var i=0; i<control.showmultpick.length; i++) {
8714: if (control.showmultpick[i].checked) {
8715: if (control.showmultpick[i].value == 1) {
8716: if (context == 'settings') {
8717: dosettings = 0;
8718: } else {
8719: doaction = 0;
8720: }
8721: }
8722: }
8723: }
8724: }
8725: }
8726: if (context == 'settings') {
8727: if (dosettings == 1) {
8728: targetform.changeparms.value=param;
8729: targetform.submit();
8730: }
8731: }
8732: if (context == 'actions') {
8733: if (doaction == 1) {
8734: targetform.cmd.value=param+'_'+index;
8735: targetform.folderpath.value=folderpath;
8736: targetform.markcopy.value=idx+':'+param;
8737: targetform.copyfolder.value=folder+'.'+container;
8738: if (param == 'remove') {
8739: var doremove = 0;
8740: if (skip_confirm) {
8741: if (confirm_removal) {
8742: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8743: doremove = 1;
8744: }
8745: } else {
8746: doremove = 1;
8747: }
8748: } else {
8749: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8750: doremove = 1;
8751: }
8752: }
8753: if (doremove) {
8754: targetform.markcopy.value='';
8755: targetform.copyfolder.value='';
8756: targetform.submit();
8757: }
8758: }
8759: if (param == 'cut') {
8760: if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) {
8761: targetform.submit();
8762: return;
8763: }
8764: }
8765: if (param == 'copy') {
8766: targetform.submit();
8767: return;
8768: }
8769: targetform.markcopy.value='';
8770: targetform.copyfolder.value='';
8771: targetform.cmd.value='';
8772: targetform.folderpath.value='';
8773: return;
8774: } else {
8775: if (document.getElementById(param+'_'+idx)) {
8776: item = document.getElementById(param+'_'+idx);
8777: if (item.type == 'checkbox') {
8778: if (item.checked) {
8779: item.checked = false;
8780: } else {
8781: item.checked = true;
8782: singleCheck(item,idx,param);
8783: }
8784: }
8785: }
8786: }
8787: }
8788: return;
8789: }
8790:
8791: function singleCheck(caller,idx,action) {
8792: actions = new Array('cut','copy','remove');
8793: if (caller.checked) {
8794: for (var i=0; i<actions.length; i++) {
8795: if (actions[i] != action) {
8796: if (document.getElementById(actions[i]+'_'+idx)) {
8797: if (document.getElementById(actions[i]+'_'+idx).checked) {
8798: document.getElementById(actions[i]+'_'+idx).checked = false;
8799: }
8800: }
8801: }
8802: }
8803: }
8804: return;
8805: }
8806:
8807: function unselectInactive(nav) {
8808: currentNav = document.getElementById(nav);
8809: currentLis = currentNav.getElementsByTagName('LI');
8810: for (i = 0; i < currentLis.length; i++) {
8811: if (currentLis[i].className == 'goback') {
8812: currentLis[i].className = 'goback';
8813: } else {
8814: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
8815: currentLis[i].className = 'right';
8816: } else {
8817: currentLis[i].className = 'i';
8818: }
8819: }
8820: }
8821: }
8822:
8823: function hideAll(current, nav, data) {
8824: unselectInactive(nav);
8825: if (current) {
8826: if (current.className == 'right'){
8827: current.className = 'right active'
8828: } else {
8829: current.className = 'active';
8830: }
8831: }
8832: currentData = document.getElementById(data);
8833: currentDivs = currentData.getElementsByTagName('DIV');
8834: for (i = 0; i < currentDivs.length; i++) {
8835: if(currentDivs[i].className == 'LC_ContentBox'){
8836: currentDivs[i].style.display = 'none';
8837: }
8838: }
8839: }
8840:
8841: function openTabs(pageId) {
8842: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
8843: if(tabnav.length > 2 ){
8844: currentNav = document.getElementById(tabnav[1].id);
8845: currentLis = currentNav.getElementsByTagName('LI');
8846: for(i = 0; i< currentLis.length; i++){
8847: if(currentLis[i].className == 'active') {
8848: funcString = currentLis[i].onclick.toString();
8849: tab = funcString.split('"');
8850: if(tab.length < 2) {
8851: tab = funcString.split("'");
8852: }
8853: currentData = document.getElementById(tab[1]);
8854: currentData.style.display = 'block';
8855: }
8856: }
8857: }
8858: }
8859:
8860: function showPage(current, pageId, nav, data) {
8861: currstate = current.className;
8862: hideAll(current, nav, data);
8863: openTabs(pageId);
8864: unselectInactive(nav);
8865: if ((currstate == 'active') || (currstate == 'right active')) {
8866: if (currstate == 'active') {
8867: current.className = '';
8868: } else {
8869: current.className = 'right';
8870: }
8871: activeTab = '';
8872: toggleExternal();
8873: toggleUpload();
8874: toggleMap();
8875: toggleCrsRes();
8876: toggleImportCrsres();
8877: resize_scrollbox('contentscroll','1','0');
8878: return;
8879: } else {
8880: current.className = 'active';
8881: }
8882: currentData = document.getElementById(pageId);
8883: currentData.style.display = 'block';
8884: activeTab = pageId;
8885: toggleExternal();
8886: toggleUpload();
8887: toggleMap();
8888: toggleCrsRes();
8889: toggleImportCrsres();
8890: if (nav == 'mainnav') {
8891: var storedpath = "$docs_folderpath";
8892: var storedpage = "$main_container_page";
8893: var reg = new RegExp("^supplemental");
8894: if (pageId == 'mainCourseDocuments') {
8895: if (storedpage == 1) {
8896: document.simpleedit.folderpath.value = '';
8897: document.uploaddocument.folderpath.value = '';
8898: } else {
8899: if (reg.test(storedpath)) {
8900: document.simpleedit.folderpath.value = '$toplevelmain';
8901: document.uploaddocument.folderpath.value = '$toplevelmain';
8902: document.newext.folderpath.value = '$toplevelmain';
8903: } else {
8904: document.simpleedit.folderpath.value = storedpath;
8905: document.uploaddocument.folderpath.value = storedpath;
8906: document.newext.folderpath.value = storedpath;
8907: }
8908: }
8909: } else {
8910: if (reg.test(storedpath)) {
8911: document.simpleedit.folderpath.value = storedpath;
8912: document.supuploaddocument.folderpath.value = storedpath;
8913: document.supnewext.folderpath.value = storedpath;
8914: } else {
8915: document.simpleedit.folderpath.value = '$toplevelsupp';
8916: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8917: document.supnewext.folderpath.value = '$toplevelsupp';
8918: }
8919: }
8920: }
8921: resize_scrollbox('contentscroll','1','0');
8922: return false;
8923: }
8924:
8925: function toContents(jumpto) {
8926: var newurl = '$backtourl';
8927: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
8928: newurl = newurl+'?postdata='+jumpto;
8929: }
8930: location.href=newurl;
8931: }
8932:
8933: function togglePick(caller,value) {
8934: var disp = 'none';
8935: if (document.getElementById('multi'+caller)) {
8936: var curr = document.getElementById('multi'+caller).style.display;
8937: if (value == 1) {
8938: disp='block';
8939: }
8940: if (curr == disp) {
8941: return;
8942: }
8943: document.getElementById('multi'+caller).style.display=disp;
8944: if (value == 1) {
8945: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
8946: } else {
8947: document.getElementById('more'+caller).innerHTML = '';
8948: }
8949: if (caller == 'actions') {
8950: setClass(value);
8951: setBoxes(value);
8952: }
8953: }
8954: var showButton = multiSettings();
8955: if (showButton != 1) {
8956: showButton = multiActions();
8957: }
8958: if (document.getElementById('multisave')) {
8959: if (showButton == 1) {
8960: document.getElementById('multisave').style.display='block';
8961: } else {
8962: document.getElementById('multisave').style.display='none';
8963: }
8964: }
8965: resize_scrollbox('contentscroll','1','1');
8966: return;
8967: }
8968:
8969: function toggleCheckUncheck(caller,more) {
8970: if (more == 1) {
8971: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
8972: document.getElementById('allfields'+caller).style.display='block';
8973: } else {
8974: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
8975: document.getElementById('allfields'+caller).style.display='none';
8976: }
8977: resize_scrollbox('contentscroll','1','1');
8978: }
8979:
8980: function multiSettings() {
8981: var inuse = 0;
8982: var settingsform = document.togglemultsettings;
8983: if (settingsform.showmultpick.length > 1) {
8984: for (var i=0; i<settingsform.showmultpick.length; i++) {
8985: if (settingsform.showmultpick[i].checked) {
8986: if (settingsform.showmultpick[i].value == 1) {
8987: inuse = 1;
8988: }
8989: }
8990: }
8991: }
8992: return inuse;
8993: }
8994:
8995: function multiActions() {
8996: var inuse = 0;
8997: var actionsform = document.togglemultactions;
8998: if (actionsform.showmultpick.length > 1) {
8999: for (var i=0; i<actionsform.showmultpick.length; i++) {
9000: if (actionsform.showmultpick[i].checked) {
9001: if (actionsform.showmultpick[i].value == 1) {
9002: inuse = 1;
9003: }
9004: }
9005: }
9006: }
9007: return inuse;
9008: }
9009:
9010: function checkSubmits() {
9011: var numchanges = 0;
9012: var form = document.saveactions;
9013: var doactions = multiActions();
9014: var cutwarnings = 0;
9015: var remwarnings = 0;
9016: var removalinfo = 0;
9017: if (doactions == 1) {
9018: var remidxlist = document.cumulativeactions.allremoveidx.value;
9019: if ((remidxlist != '') && (remidxlist != null)) {
9020: var remidxs = remidxlist.split(',');
9021: for (var i=0; i<remidxs.length; i++) {
9022: if (document.getElementById('remove_'+remidxs[i])) {
9023: if (document.getElementById('remove_'+remidxs[i]).checked) {
9024: form.multiremove.value += remidxs[i]+',';
9025: numchanges ++;
9026: if (document.getElementById('skip_remove_'+remidxs[i])) {
9027: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
9028: remwarnings ++;
9029: }
9030: }
9031: if (document.getElementById('confirm_removal_'+remidxs[i])) {
9032: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
9033: removalinfo ++;
9034: }
9035: }
9036: }
9037: }
9038: }
9039: }
9040: var cutidxlist = document.cumulativeactions.allcutidx.value;
9041: if ((cutidxlist != '') && (cutidxlist != null)) {
9042: var cutidxs = cutidxlist.split(',');
9043: for (var i=0; i<cutidxs.length; i++) {
9044: if (document.getElementById('cut_'+cutidxs[i])) {
9045: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
9046: form.multicut.value += cutidxs[i]+',';
9047: numchanges ++;
9048: if (document.getElementById('skip_cut_'+cutidxs[i])) {
9049: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
9050: cutwarnings ++;
9051: }
9052: }
9053: }
9054: }
9055: }
9056: }
9057: var copyidxlist = document.cumulativeactions.allcopyidx.value;
9058: if ((copyidxlist != '') && (copyidxlist != null)) {
9059: var copyidxs = copyidxlist.split(',');
9060: for (var i=0; i<copyidxs.length; i++) {
9061: if (document.getElementById('copy_'+copyidxs[i])) {
9062: if (document.getElementById('copy_'+copyidxs[i]).checked) {
9063: form.multicopy.value += copyidxs[i]+',';
9064: numchanges ++;
9065: }
9066: }
9067: }
9068: }
9069: if (numchanges > 0) {
9070: form.multichange.value = numchanges;
9071: }
9072: }
9073: var dosettings = multiSettings();
9074: var haschanges = 0;
9075: if (dosettings == 1) {
9076: form.allencrypturl.value = '';
9077: form.allhiddenresource.value = '';
9078: form.changeparms.value = 'all';
9079: var patt=new RegExp(",\$");
9080: var allidxlist = document.cumulativesettings.allidx.value;
9081: if ((allidxlist != '') && (allidxlist != null)) {
9082: var allidxs = allidxlist.split(',');
9083: if (allidxs.length > 1) {
9084: for (var i=0; i<allidxs.length; i++) {
9085: if (document.getElementById('hiddenresource_'+allidxs[i])) {
9086: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
9087: form.allhiddenresource.value += allidxs[i]+',';
9088: }
9089: }
9090: if (document.getElementById('encrypturl_'+allidxs[i])) {
9091: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
9092: form.allencrypturl.value += allidxs[i]+',';
9093: }
9094: }
9095: }
9096: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
9097: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
9098: }
9099: }
9100: form.allrandompick.value = '';
9101: form.allrandomorder.value = '';
9102: var allmapidxlist = document.cumulativesettings.allmapidx.value;
9103: if ((allmapidxlist != '') && (allmapidxlist != null)) {
9104: var allmapidxs = allmapidxlist.split(',');
9105: for (var i=0; i<allmapidxs.length; i++) {
9106: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
9107: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
9108: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
9109: if ((randompick.checked) && (rpicknum.value != '')) {
9110: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
9111: }
9112: if (randorder.checked) {
9113: form.allrandomorder.value += allmapidxs[i]+',';
9114: }
9115: }
9116: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
9117: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
9118: }
9119: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
9120: haschanges = 1;
9121: }
9122: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
9123: haschanges = 1;
9124: }
9125: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
9126: haschanges = 1;
9127: }
9128: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
9129: haschanges = 1;
9130: }
9131: }
9132: if (doactions == 1) {
9133: if (numchanges > 0) {
9134: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
9135: if (remwarnings > 0) {
9136: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
9137: return false;
9138: }
9139: }
9140: if (removalinfo > 0) {
9141: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
9142: return false;
9143: }
9144: }
9145: if (cutwarnings > 0) {
9146: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
9147: return false;
9148: }
9149: }
9150: }
9151: form.submit();
9152: return true;
9153: }
9154: }
9155: if (dosettings == 1) {
9156: if (haschanges == 1) {
9157: form.submit();
9158: return true;
9159: }
9160: }
9161: if ((dosettings == 1) && (doactions == 1)) {
9162: alert("$js_lt{'noor'}");
9163: } else {
9164: if (dosettings == 1) {
9165: alert("$js_lt{'noch'}");
9166: } else {
9167: alert("$js_lt{'noac'}");
9168: }
9169: }
9170: return false;
9171: }
9172:
9173: function setClass(value) {
9174: var cutclass = 'LC_docs_cut';
9175: var copyclass = 'LC_docs_copy';
9176: var removeclass = 'LC_docs_remove';
9177: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
9178: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
9179: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
9180: var links = document.getElementsByTagName('a');
9181: for (var i=0; i<links.length; i++) {
9182: var classes = links[i].className;
9183: if (cutreg.test(classes)) {
9184: links[i].className = cutclass;
9185: if (value == 1) {
9186: links[i].className += " LC_menubuttons_link";
9187: }
9188: } else {
9189: if (copyreg.test(classes)) {
9190: links[i].className = copyclass;
9191: if (value == 1) {
9192: links[i].className += " LC_menubuttons_link";
9193: }
9194: } else {
9195: if (removereg.test(classes)) {
9196: links[i].className = removeclass;
9197: if (value == 1) {
9198: links[i].className += " LC_menubuttons_link";
9199: }
9200: }
9201: }
9202: }
9203: }
9204: return;
9205: }
9206:
9207: function setBoxes(value) {
9208: var remidxlist = document.cumulativeactions.allremoveidx.value;
9209: if ((remidxlist != '') && (remidxlist != null)) {
9210: var remidxs = remidxlist.split(',');
9211: for (var i=0; i<remidxs.length; i++) {
9212: if (document.getElementById('remove_'+remidxs[i])) {
9213: var item = document.getElementById('remove_'+remidxs[i]);
9214: if (value == 1) {
9215: item.className = 'LC_docs_remove';
9216: } else {
9217: item.className = 'LC_hidden';
9218: }
9219: }
9220: }
9221: }
9222: var cutidxlist = document.cumulativeactions.allcutidx.value;
9223: if ((cutidxlist != '') && (cutidxlist != null)) {
9224: var cutidxs = cutidxlist.split(',');
9225: for (var i=0; i<cutidxs.length; i++) {
9226: if (document.getElementById('cut_'+cutidxs[i])) {
9227: var item = document.getElementById('cut_'+cutidxs[i]);
9228: if (value == 1) {
9229: item.className = 'LC_docs_cut';
9230: } else {
9231: item.className = 'LC_hidden';
9232: }
9233: }
9234: }
9235: }
9236: var copyidxlist = document.cumulativeactions.allcopyidx.value;
9237: if ((copyidxlist != '') && (copyidxlist != null)) {
9238: var copyidxs = copyidxlist.split(',');
9239: for (var i=0; i<copyidxs.length; i++) {
9240: if (document.getElementById('copy_'+copyidxs[i])) {
9241: var item = document.getElementById('copy_'+copyidxs[i]);
9242: if (value == 1) {
9243: item.className = 'LC_docs_copy';
9244: } else {
9245: item.className = 'LC_hidden';
9246: }
9247: }
9248: }
9249: }
9250: return;
9251: }
9252:
9253: function validImportCrsRes() {
9254: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
9255: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
9256: if ((fname == '') || (fname == null)) {
9257: alert("$js_lt{'nofi'}");
9258: return false;
9259: }
9260: var url = '/res/$coursedom/$coursenum/';
9261: if (path && path != '/') {
9262: url += path+'/';
9263: }
9264: if (fname != '') {
9265: url += fname;
9266: }
9267: var title = document.crsresimportform.crsrestitle.value;
9268: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
9269: return true;
9270: }
9271:
9272: function validateNewRes(caller) {
9273: if (caller == 'single') {
9274: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9275: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
9276: var resname = document.courseresform.newresourcename.value;
9277: }
9278: }
9279:
9280: ENDSCRIPT
9281: }
9282:
9283: sub history_tab_js {
9284: return <<"ENDHIST";
9285: function toggleHistoryDisp(choice) {
9286: document.docslogform.docslog.value = choice;
9287: document.docslogform.submit();
9288: return;
9289: }
9290:
9291: ENDHIST
9292: }
9293:
9294: sub inject_data_js {
9295: return <<ENDINJECT;
9296:
9297: function injectData(current, hiddenField, name, value) {
9298: currentElement = document.getElementById(hiddenField);
9299: currentElement.name = name;
9300: currentElement.value = value;
9301: current.submit();
9302: }
9303:
9304: ENDINJECT
9305: }
9306:
9307: sub dump_switchserver_js {
9308: my @hosts = @_;
9309: my %js_lt = &Apache::lonlocal::texthash(
9310: dump => 'Copying content to Authoring Space requires switching server.',
9311: swit => 'Switch server?',
9312: );
9313: my %html_js_lt = &Apache::lonlocal::texthash(
9314: swit => 'Switch server?',
9315: duco => 'Copying Content to Authoring Space',
9316: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
9317: chos => 'Choose server',
9318: );
9319: &js_escape(\%js_lt);
9320: &html_escape(\%html_js_lt);
9321: &js_escape(\%html_js_lt);
9322: my $role = $env{'request.role'};
9323: my $js = <<"ENDSWJS";
9324: <script type="text/javascript">
9325: function write_switchserver() {
9326: var server;
9327: if (document.setserver.posshosts.length > 0) {
9328: for (var i=0; i<document.setserver.posshosts.length; i++) {
9329: if (document.setserver.posshosts[i].checked) {
9330: server = document.setserver.posshosts[i].value;
9331: }
9332: }
9333: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
9334: }
9335: window.close();
9336: }
9337: </script>
9338:
9339: ENDSWJS
9340:
9341: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
9342: {'only_body' => 1,
9343: 'js_ready' => 1,});
9344: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
9345:
9346: my $hostpicker;
9347: my $count = 0;
9348: foreach my $host (sort(@hosts)) {
9349: my $checked;
9350: if ($count == 0) {
9351: $checked = ' checked="checked"';
9352: }
9353: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
9354: $host.'"'.$checked.' />'.$host.'</label> ';
9355: $count++;
9356: }
9357:
9358: return <<"ENDSWITCHJS";
9359:
9360: function dump_needs_switchserver(url) {
9361: if (url!='' && url!= null) {
9362: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
9363: go(url);
9364: }
9365: }
9366: return;
9367: }
9368:
9369: function choose_switchserver_window() {
9370: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
9371: newWindow.document.open();
9372: newWindow.document.writeln('$startpage');
9373: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
9374: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
9375: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
9376: '<form name="setserver" method="post" action="" \\/>\\n'+
9377: '$hostpicker\\n'+
9378: '<br \\/><br \\/>\\n'+
9379: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
9380: 'onclick="write_switchserver();" \\/>\\n'+
9381: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
9382: newWindow.document.writeln('$endpage');
9383: newWindow.document.close();
9384: newWindow.focus();
9385: }
9386:
9387: ENDSWITCHJS
9388: }
9389:
9390: sub makedocslogform {
9391: my ($formelems,$docslog) = @_;
9392: return <<"LOGSFORM";
9393: <form action="/adm/coursedocs" method="post" name="docslogform">
9394: <input type="hidden" name="docslog" value="$docslog" />
9395: $formelems
9396: </form>
9397: LOGSFORM
9398: }
9399:
9400: sub makesimpleeditform {
9401: my ($formelems) = @_;
9402: return <<"SIMPFORM";
9403: <form name="simpleedit" method="post" action="/adm/coursedocs">
9404: <input type="hidden" name="importdetail" value="" />
9405: $formelems
9406: </form>
9407: SIMPFORM
9408: }
9409:
9410: sub makenewproblem {
9411: my ($r,$coursedom,$coursenum) = @_;
9412: # Creating a new problem
9413: my ($redirect,$error);
9414: if ($env{'form.authorrole'}) {
9415: my ($newsubdir,$filename);
9416: if ($env{'form.newsubdir'}) {
9417: if ($env{'form.newsubdirname'} ne '') {
9418: $newsubdir = $env{'form.newsubdirname'};
9419: }
9420: }
9421: if ($env{'form.newresourcename'}) {
9422: $filename = $env{'form.newresourcename'};
9423: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
9424: $filename =~ s/`//g;
9425: $filename =~ s{/\.\./}{_}g;
9426: $filename =~ s/\.+/./g;
9427: $filename =~ s{/+}{_}g;
9428: if ($filename ne '') {
9429: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
9430: if (($ext) && ($ext ne '.problem')) {
9431: $filename = $name.'.problem';
9432: } elsif ($ext eq '') {
9433: $filename .= '.problem';
9434: }
9435: my $docroot = $r->dir_config('lonDocRoot');
9436: my @ids=&Apache::lonnet::current_machine_ids();
9437: if ($env{'form.authorrole'} eq 'author') {
9438: if ($env{'user.author'}) {
9439: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
9440: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
9441: my $path = $docroot.$url;
9442: my $subdir = $env{'form.authorpath'};
9443: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9444: }
9445: }
9446: } elsif ($env{'form.authorrole'} eq 'course') {
9447: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
9448: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
9449: my $url = "/priv/$coursedom/$coursenum";
9450: my $path=$docroot.$url;
9451: my $subdir = $env{'form.authorpath'};
9452: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9453: if ($redirect) {
9454: my $rightsfile = 'default.rights';
9455: my $sourcerights = "$path/$rightsfile";
9456: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
9457: my $now = time;
9458: if (!-e $sourcerights) {
9459: my $cid = $coursedom.'_'.$coursenum;
9460: if (open(my $fh,">$sourcerights")) {
9461: print $fh <<END;
9462: <accessrule effect="deny" realm="" type="course" role="" />
9463: <accessrule effect="allow" realm="$cid" type="course" role="" />
9464: END
9465: close($fh);
9466: }
9467: }
9468: if (!-e "$sourcerights.meta") {
9469: if (open(my $fh,">$sourcerights.meta")) {
9470: my $author=$env{'environment.firstname'}.' '.
9471: $env{'environment.middlename'}.' '.
9472: $env{'environment.lastname'}.' '.
9473: $env{'environment.generation'};
9474: $author =~ s/\s+$//;
9475: print $fh <<"END";
9476:
9477: <abstract></abstract>
9478: <author>$author</author>
9479: <authorspace>$coursenum:$coursedom</authorspace>
9480: <copyright>private</copyright>
9481: <creationdate>$now</creationdate>
9482: <customdistributionfile></customdistributionfile>
9483: <dependencies></dependencies>
9484: <domain>$coursedom</domain>
9485: <highestgradelevel>0</highestgradelevel>
9486: <keywords></keywords>
9487: <language>notset </language>
9488: <lastrevisiondate>$now</lastrevisiondate>
9489: <lowestgradelevel>0</lowestgradelevel>
9490: <mime>rights</mime>
9491: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
9492: <notes></notes>
9493: <obsolete></obsolete>
9494: <obsoletereplacement></obsoletereplacement>
9495: <owner>$coursenum:$coursedom</owner>
9496: <rule>deny:::course,allow:$cid::course</rule>
9497: <sourceavail></sourceavail>
9498: <standards></standards>
9499: <subject></subject>
9500: <title>Course Authoring Rights</title>
9501: END
9502: close($fh);
9503: }
9504: }
9505: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
9506: if (!-e "$docroot/res/$coursedom") {
9507: mkdir("$docroot/res/$coursedom",0755);
9508: }
9509: if (!-e "$docroot/res/$coursedom/$coursenum") {
9510: mkdir("$docroot/res/$coursedom/$coursenum",0755);
9511: }
9512: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
9513: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
9514: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
9515: }
9516: }
9517: my $source = $docroot.$redirect;
9518: if (!-e "$source.meta") {
9519: my $cid = $coursedom.'_'.$coursenum;
9520: my $now = time;
9521: if (open(my $fh,">$source.meta")) {
9522: my $author=$env{'environment.firstname'}.' '.
9523: $env{'environment.middlename'}.' '.
9524: $env{'environment.lastname'}.' '.
9525: $env{'environment.generation'};
9526: $author =~ s/\s+$//;
9527: my $title = $env{'form.newresourcetitle'};
9528: $title =~ s/^\s+|\s+$//g;
9529: print $fh <<END;
9530:
9531: <abstract></abstract>
9532: <author>$author</author>
9533: <authorspace>$coursenum:$coursedom</authorspace>
9534: <copyright>custom</copyright>
9535: <creationdate>$now</creationdate>
9536: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
9537: <dependencies></dependencies>
9538: <domain>$coursedom</domain>
9539: <highestgradelevel>0</highestgradelevel>
9540: <keywords></keywords>
9541: <language>notset </language>
9542: <lastrevisiondate>$now</lastrevisiondate>
9543: <lowestgradelevel>0</lowestgradelevel>
9544: <mime>problem</mime>
9545: <modifyinguser>$coursenum:$coursedom</modifyinguser>
9546: <notes></notes>
9547: <obsolete></obsolete>
9548: <obsoletereplacement></obsoletereplacement>
9549: <owner>$coursenum:$coursedom</owner>
9550: <sourceavail></sourceavail>
9551: <standards></standards>
9552: <subject></subject>
9553: <title>$title</title>
9554: END
9555: close($fh);
9556: }
9557: }
9558: }
9559: }
9560: } else {
9561: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
9562: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
9563: if (grep(/^\Q$rolehome\E$/,@ids)) {
9564: my $now = time;
9565: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
9566: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
9567: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
9568: my $url = "/priv/$audom/$auname";
9569: my $path = $r->dir_config('lonDocRoot').$url;
9570: my $subdir = $env{'form.authorpath'};
9571: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9572: }
9573: }
9574: }
9575: }
9576: }
9577: }
9578: }
9579: return ($redirect,$error);
9580: }
9581:
9582: sub finishnewprob {
9583: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
9584: unless (-d $path) {
9585: unless (mkdir($path,02770)) {
9586: return;
9587: }
9588: }
9589: my $redirect;
9590: if ($subdir ne '/') {
9591: $subdir = &cleandir($subdir);
9592: if (($subdir ne '') && (-d "$path/$subdir")) {
9593: $path .= "/$subdir";
9594: $url .= "/$subdir";
9595: }
9596: }
9597: my $dest;
9598: if ($newsubdir ne '') {
9599: $newsubdir = &cleandir($newsubdir);
9600: }
9601: if ($newsubdir ne '') {
9602: if (-d "$path/$newsubdir") {
9603: $dest = "$path/$newsubdir/$filename";
9604: } else {
9605: my $dirok;
9606: unless (-e "$path/$newsubdir") {
9607: if (mkdir("$path/$newsubdir",02770)) {
9608: if (chmod(02770,"$path/$newsubdir")) {
9609: $dirok = 1;
9610: }
9611: }
9612: }
9613: if ($dirok) {
9614: $dest = "$path/$newsubdir/$filename";
9615: }
9616: }
9617: if (($dest ne '') && (!-e $dest)) {
9618: $redirect = "$url/$newsubdir/$filename";
9619: }
9620: } else {
9621: $dest = "$path/$filename";
9622: if (($dest ne '') && (!-e $dest)) {
9623: $redirect = "$url/$filename";
9624: }
9625: }
9626: if ((!-e $dest) && ($context ne 'upload')) {
9627: my $template = $env{'form.template'};
9628: my $copyfrom;
9629: if ($template ne '') {
9630: my %templates;
9631: my @files = &Apache::lonhomework::get_template_list('problem');
9632: foreach my $poss (@files) {
9633: if (ref($poss) eq 'ARRAY') {
9634: if ($template eq $poss->[0]) {
9635: $templates{$template} = 1;
9636: last;
9637: }
9638: }
9639: }
9640: if ($templates{$template}) {
9641: $copyfrom = $template;
9642: }
9643: }
9644: if ($filename =~ /\.problem$/) {
9645: unless ($copyfrom) {
9646: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
9647: }
9648: &File::Copy::copy($copyfrom,$dest);
9649: }
9650: }
9651: return $redirect;
9652: }
9653:
9654: sub cleandir {
9655: my ($dir) = @_;
9656: $dir =~ s/^\s+//;
9657: $dir =~ s/\s+$//;
9658: $dir =~ s/\.+//g;
9659: $dir =~ s/[\#\?&%\":]//g;
9660: return $dir;
9661: }
9662:
9663: 1;
9664: __END__
9665:
9666:
9667: =head1 NAME
9668:
9669: Apache::londocs.pm
9670:
9671: =head1 SYNOPSIS
9672:
9673: This is part of the LearningOnline Network with CAPA project
9674: described at http://www.lon-capa.org.
9675:
9676: =head1 SUBROUTINES
9677:
9678: =over
9679:
9680: =item %help=()
9681:
9682: Available help topics
9683:
9684: =item mapread()
9685:
9686: Mapread read maps into LONCAPA::map:: global arrays
9687: @order and @resources, determines status
9688: sets @order - pointer to resources in right order
9689: sets @resources - array with the resources with correct idx
9690:
9691: =item authorhosts()
9692:
9693: Return hash with valid author names
9694:
9695: =item clean()
9696:
9697: =item dumpcourse()
9698:
9699: Actually dump course
9700:
9701: =item group_import()
9702:
9703: Imports the given (name, url) resources into the course
9704: coursenum, coursedom, and folder must precede the list
9705:
9706: =item breadcrumbs()
9707:
9708: =item log_docs()
9709:
9710: =item docs_change_log()
9711:
9712: =item update_paste_buffer()
9713:
9714: =item print_paste_buffer()
9715:
9716: =item do_paste_from_buffer()
9717:
9718: =item do_buffer_empty()
9719:
9720: =item clear_from_buffer()
9721:
9722: =item get_newmap_url()
9723:
9724: =item dbcopy()
9725:
9726: =item uniqueness_check()
9727:
9728: =item contained_map_check()
9729:
9730: =item url_paste_fixups()
9731:
9732: =item apply_fixups()
9733:
9734: =item copy_dependencies()
9735:
9736: =item update_parameter()
9737:
9738: =item handle_edit_cmd()
9739:
9740: =item editor()
9741:
9742: =item process_file_upload()
9743:
9744: =item process_secondary_uploads()
9745:
9746: =item is_supplemental_title()
9747:
9748: =item entryline()
9749:
9750: =item tiehash()
9751:
9752: =item untiehash()
9753:
9754: =item checkonthis()
9755:
9756: check on this
9757:
9758: =item verifycontent()
9759:
9760: Verify Content
9761:
9762: =item devalidateversioncache()
9763:
9764: =item checkversions()
9765:
9766: Check Versions
9767:
9768: =item mark_hash_old()
9769:
9770: =item is_hash_old()
9771:
9772: =item changewarning()
9773:
9774: =item init_breadcrumbs()
9775:
9776: Breadcrumbs for special functions
9777:
9778: =item create_list_elements()
9779:
9780: =item create_form_ul()
9781:
9782: =item startContentScreen()
9783:
9784: =item endContentScreen()
9785:
9786: =item supplemental_base()
9787:
9788: =item embedded_form_elems()
9789:
9790: =item embedded_destination()
9791:
9792: =item return_to_editor()
9793:
9794: =item decompression_info()
9795:
9796: =item decompression_phase_one()
9797:
9798: =item decompression_phase_two()
9799:
9800: =item remove_archive()
9801:
9802: =item generate_admin_menu()
9803:
9804: =item generate_edit_table()
9805:
9806: =item editing_js()
9807:
9808: =item history_tab_js()
9809:
9810: =item inject_data_js()
9811:
9812: =item dump_switchserver_js()
9813:
9814: =item resize_scrollbox_js()
9815:
9816: =item makedocslogform()
9817:
9818: =item makesimpleeditform()
9819:
9820: =back
9821:
9822: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>