File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.696:
download - view:
text,
annotated -
select for diffs
Thu Mar 23 16:45:50 2023 UTC (17 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Re-instate pre-rev 1.680 functionality in Course Editor whereby the message:
"re-initialize course to access" is displayed (instead of a link) for any
resource with an unverifiable symb, after regression in rev. 1.680.
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.696 2023/03/23 16:45:50 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
36: use Apache::lonhtmlcommon;
37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
42: use Apache::lonnavdisplay();
43: use Apache::lonextresedit();
44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
46: use Apache::lonhomework();
47: use Apache::lonpublisher();
48: use Apache::lonparmset();
49: use Apache::loncourserespicker();
50: use HTML::Entities;
51: use HTML::TokeParser;
52: use GDBM_File;
53: use File::MMagic;
54: use File::Copy;
55: use Apache::lonlocal;
56: use Cwd;
57: use UUID::Tiny ':std';
58: use LONCAPA qw(:DEFAULT :match);
59:
60: my $iconpath;
61:
62: my %hash;
63:
64: my $hashtied;
65: my %alreadyseen=();
66:
67: my $hadchanges;
68: my $suppchanges;
69:
70:
71: my %help=();
72:
73:
74: sub mapread {
75: my ($coursenum,$coursedom,$map)=@_;
76: return
77: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
78: $map);
79: }
80:
81: sub storemap {
82: my ($coursenum,$coursedom,$map,$contentchg)=@_;
83: my $report;
84: if (($contentchg) && ($map =~ /^default/)) {
85: $report = 1;
86: }
87: my ($outtext,$errtext)=
88: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
89: $map,1,$report);
90: if ($errtext) { return ($errtext,2); }
91:
92: if ($map =~ /^default/) {
93: $hadchanges=1;
94: } elsif ($contentchg) {
95: $suppchanges=1;
96: }
97: return ($errtext,0);
98: }
99:
100:
101:
102: sub authorhosts {
103: my %outhash=();
104: my $home=0;
105: my $other=0;
106: foreach my $key (keys(%env)) {
107: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
108: my $role=$1;
109: my $realm=$2;
110: my ($start,$end)=split(/\./,$env{$key});
111: if (($start) && ($start>time)) { next; }
112: if (($end) && (time>$end)) { next; }
113: my ($ca,$cd);
114: if ($1 eq 'au') {
115: $ca=$env{'user.name'};
116: $cd=$env{'user.domain'};
117: } else {
118: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
119: }
120: my $allowed=0;
121: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
122: my @ids=&Apache::lonnet::current_machine_ids();
123: foreach my $id (@ids) {
124: if ($id eq $myhome) {
125: $allowed=1;
126: last;
127: }
128: }
129: if ($allowed) {
130: $home++;
131: $outhash{'home_'.$ca.':'.$cd}=1;
132: } else {
133: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
134: $other++;
135: }
136: }
137: }
138: return ($home,$other,%outhash);
139: }
140:
141:
142: sub clean {
143: my ($title)=@_;
144: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
145: return $title;
146: }
147:
148: sub default_folderpath {
149: my ($coursenum,$coursedom,$navmapref) = @_;
150: return unless ($coursenum && $coursedom && ref($navmapref));
151: # Check if entire course is hidden and/or encrypted
152: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
153: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
154: unless (ref($$navmapref)) {
155: $$navmapref = Apache::lonnavmaps::navmap->new();
156: }
157: if (ref($$navmapref)) {
158: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
159: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
160: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
161: unless (@resources) {
162: $hiddenmap = 1;
163: unless ($env{'request.role.adv'}) {
164: $hiddentop = 1;
165: if ($env{'form.folder'}) {
166: undef($env{'form.folder'});
167: }
168: }
169: }
170: }
171: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
172: $encryptmap = 1;
173: }
174: }
175: unless ($hiddentop) {
176: $folderpath='default&'.&escape(&mt('Main Content')).
177: '::'.$hiddenmap.':'.$encryptmap.'::';
178: }
179: if (wantarray) {
180: return ($folderpath,$hiddentop);
181: } else {
182: return $folderpath;
183: }
184: }
185:
186: sub validate_supppath {
187: my ($coursenum,$coursedom) = @_;
188: my $backto;
189: if ($env{'form.supppath'} ne '') {
190: my @items = split(/\&/,$env{'form.supppath'});
191: my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
192: for (my $i=0; $i<@items; $i++) {
193: my $odd = $i%2;
194: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
195: $badpath = 1;
196: last;
197: } elsif ($odd) {
198: my $suffix;
199: my $idx = $i-1;
200: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
201: $backto .= '&'.$1;
202: } elsif ($items[$idx] eq 'supplemental') {
203: $backto .= '&'.$items[$i];
204: } else {
205: $backto .= '&'.$items[$i];
206: my $is_hidden;
207: unless ($got_supp) {
208: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
209: if (ref($supplemental) eq 'HASH') {
210: if (ref($supplemental->{'hidden'}) eq 'HASH') {
211: %supphidden = %{$supplemental->{'hidden'}};
212: }
213: if (ref($supplemental->{'ids'}) eq 'HASH') {
214: %suppids = %{$supplemental->{'ids'}};
215: }
216: }
217: $got_supp = 1;
218: }
219: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
220: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
221: if ($supphidden{$mapid}) {
222: $is_hidden = 1;
223: }
224: }
225: $suffix = '::'.$is_hidden.':::';
226: }
227: $supppath .= '&'.$items[$i].$suffix;
228: } else {
229: $supppath .= '&'.$items[$i];
230: $backto .= '&'.$items[$i];
231: }
232: }
233: if ($badpath) {
234: delete($env{'form.supppath'});
235: } else {
236: $supppath =~ s/^\&//;
237: $backto =~ s/^\&//;
238: $env{'form.supppath'} = $supppath;
239: }
240: }
241: return $backto;
242: }
243:
244: sub dumpcourse {
245: my ($r) = @_;
246: my $crstype = &Apache::loncommon::course_type();
247: my ($starthash,$js);
248: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
249: $js = <<"ENDJS";
250: <script type="text/javascript">
251: // <![CDATA[
252:
253: function hide_searching() {
254: if (document.getElementById('searching')) {
255: document.getElementById('searching').style.display = 'none';
256: }
257: return;
258: }
259:
260: // ]]>
261: </script>
262: ENDJS
263: $starthash = {
264: add_entries => {'onload' => "hide_searching();"},
265: };
266: }
267: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
268: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
269: $r->print(&startContentScreen('tools'));
270: my ($home,$other,%outhash)=&authorhosts();
271: unless ($home) {
272: $r->print(&endContentScreen());
273: return '';
274: }
275: my $origcrsid=$env{'request.course.id'};
276: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
277: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
278: # Do the dumping
279: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
280: $r->print(&endContentScreen());
281: return '';
282: }
283: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
284: $r->print('<h3>'.&mt('Copying Files').'</h3>');
285: my $title=$env{'form.authorfolder'};
286: $title=&clean($title);
287: my ($navmap,$errormsg) =
288: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
289: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
290: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
291: my (%maps,%resources,%titles);
292: if (!ref($navmap)) {
293: $r->print($errormsg.
294: &endContentScreen());
295: return '';
296: } else {
297: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
298: 'dumpdocs',$cdom,$cnum);
299: }
300: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
301: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
302: %newcontent,%has_simpleprobs);
303: foreach my $item (sort {$a <=> $b} (@todump)) {
304: my $name = $env{'form.namefor_'.$item};
305: if ($resources{$item}) {
306: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
307: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
308: $tocopy{$1} = $name;
309: $display{$item} = $1;
310: $lookup{$1} = $item;
311: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
312: $simpleproblems{$item} = {
313: symb => $resources{$item},
314: name => $name,
315: };
316: $display{$item} = 'simpleproblem_'.$name;
317: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
318: $has_simpleprobs{$1}{$id} = $item;
319: }
320: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
321: my $marker = $1;
322: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
323: $simplepages{$item} = {
324: res => $res,
325: title => $titles{$item},
326: db => $db_name,
327: marker => $marker,
328: symb => $resources{$item},
329: name => $name,
330: };
331: $display{$item} = '/'.$res;
332: }
333: } elsif ($maps{$item}) {
334: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
335: $tocopy{$1} = $name;
336: $display{$item} = $1;
337: $lookup{$1} = $item;
338: }
339: } else {
340: next;
341: }
342: }
343: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
344: $crs=~s/\_/\//g;
345: my $mm = new File::MMagic;
346: my $prefix = "/uploaded/$cdom/$cnum/";
347: %replacehash = %tocopy;
348: foreach my $item (sort(keys(%simpleproblems))) {
349: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
350: $newcontent{$display{$item}} = $content;
351: }
352: my $gateway = Apache::lonhtmlgateway->new('web');
353: foreach my $item (sort(keys(%simplepages))) {
354: if (ref($simplepages{$item}) eq 'HASH') {
355: my $pagetitle = $simplepages{$item}{'title'};
356: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
357: my %contents;
358: foreach my $field (keys(%fields)) {
359: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
360: my $name = $1;
361: my $msg = $fields{$field};
362: if ($name eq 'webreferences') {
363: if ($msg =~ m{^https?://}) {
364: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
365: }
366: } else {
367: $msg = &Encode::decode('utf8',$msg);
368: $msg = $gateway->process_outgoing_html($msg,1);
369: $contents{$name} = $msg;
370: }
371: } elsif ($field eq 'uploaded.photourl') {
372: my $marker = $simplepages{$item}{marker};
373: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
374: my $filepath = $1;
375: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
376: if ($fname ne '') {
377: $fname=~s/\.(\w+)$//;
378: my $ext=$1;
379: $fname = &clean($fname);
380: $fname.='.'.$ext;
381: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
382: $replacehash{$filepath} = $relpath.$fname;
383: $deps{$item}{$filepath} = 1;
384: }
385: }
386: }
387: }
388: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
389: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
390: my $content = '
391: <html>
392: <head>
393: <title>'.$pagetitle.'</title>
394: </head>
395: <body bgcolor="#ffffff">';
396: if ($contents{title}) {
397: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
398: }
399: if ($contents{image}) {
400: $content .= "\n".$contents{image};
401: }
402: if ($contents{content}) {
403: $content .= '
404: <div class="LC_Box">
405: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
406: $contents{content}.'
407: </div>';
408: }
409: if ($contents{webreferences}) {
410: $content .= '
411: <div class="LC_Box">
412: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
413: $contents{webreferences}.'
414: </div>';
415: }
416: $content .= '
417: </body>
418: </html>
419: ';
420: $newcontent{'/'.$simplepages{$item}{res}} = $content;
421: }
422: }
423: foreach my $item (keys(%tocopy)) {
424: unless ($item=~/\.(sequence|page)$/) {
425: my $currurlpath = $prefix.$item;
426: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
427: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
428: }
429: }
430: foreach my $num (sort {$a <=> $b} (@todump)) {
431: my $src = $display{$num};
432: next if ($src eq '');
433: my @needcopy = ();
434: if ($replacehash{$src}) {
435: push(@needcopy,$src);
436: if (ref($deps{$num}) eq 'HASH') {
437: foreach my $dep (sort(keys(%{$deps{$num}}))) {
438: if ($replacehash{$dep}) {
439: push(@needcopy,$dep);
440: }
441: }
442: }
443: } elsif ($src =~ /^simpleproblem_/) {
444: push(@needcopy,$src);
445: }
446: next if (@needcopy == 0);
447: my ($result,$depresult);
448: for (my $i=0; $i<@needcopy; $i++) {
449: my $item = $needcopy[$i];
450: my $newfilename;
451: if ($simpleproblems{$num}) {
452: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
453: } else {
454: $newfilename=$title.'/'.$replacehash{$item};
455: }
456: $newfilename=~s/\.(\w+)$//;
457: my $ext=$1;
458: $newfilename=&clean($newfilename);
459: $newfilename.='.'.$ext;
460: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
461: if ($newrelpath ne $replacehash{$item}) {
462: $replacehash{$item} = $newrelpath;
463: }
464: my @dirs=split(/\//,$newfilename);
465: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
466: my $makepath=$path;
467: my $fail;
468: my $origin;
469: for (my $i=0;$i<$#dirs;$i++) {
470: $makepath.='/'.$dirs[$i];
471: unless (-e $makepath) {
472: unless(mkdir($makepath,0755)) {
473: $fail = &mt('Directory creation failed.');
474: }
475: }
476: }
477: if ($i == 0) {
478: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
479: } else {
480: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
481: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
482: &mt('(dependency)').'</span>: ';
483: }
484: if (-e $path.'/'.$newfilename) {
485: $fail = &mt('Destination already exists -- not overwriting.');
486: } else {
487: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
488: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
489: ($item =~ /^simpleproblem_/)) {
490: print $fh $newcontent{$item};
491: } else {
492: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
493: if (-e $fileloc) {
494: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
495: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
496: (ref($has_simpleprobs{$item}) eq 'HASH')) {
497: my %changes = %{$has_simpleprobs{$item}};
498: my $content = &Apache::lonclonecourse::rewritefile(
499: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
500: (%replacehash,$crs => '')
501: );
502: my $updatedcontent = '';
503: my $parser = HTML::TokeParser->new(\$content);
504: $parser->attr_encoded(1);
505: while (my $token = $parser->get_token) {
506: if ($token->[0] eq 'S') {
507: if (($token->[1] eq 'resource') &&
508: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
509: ($changes{$token->[2]->{'id'}})) {
510: my $id = $token->[2]->{'id'};
511: $updatedcontent .= '<'.$token->[1];
512: foreach my $attrib (@{$token->[3]}) {
513: next unless ($attrib =~ /^(src|type|title|id)$/);
514: if ($attrib eq 'src') {
515: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
516: if ($file) {
517: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
518: } else {
519: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
520: }
521: } else {
522: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
523: }
524: }
525: $updatedcontent .= ' />'."\n";
526: } else {
527: $updatedcontent .= $token->[4]."\n";
528: }
529: } else {
530: $updatedcontent .= $token->[2];
531: }
532: }
533: print $fh $updatedcontent;
534: } else {
535: print $fh &Apache::lonclonecourse::rewritefile(
536: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
537: (%replacehash,$crs => '')
538: );
539: }
540: } else {
541: print $fh
542: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
543: }
544: } else {
545: $fail = &mt('Source does not exist.');
546: }
547: }
548: $fh->close();
549: } else {
550: $fail = &mt('Could not write to destination.');
551: }
552: }
553: my $text;
554: if ($fail) {
555: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
556: } else {
557: $text = '<span class="LC_success">'.&mt('ok').'</span>';
558: }
559: if ($i == 0) {
560: $result .= $text;
561: } else {
562: $depresult .= $text.'</li>';
563: }
564: }
565: $r->print($result);
566: if ($depresult) {
567: $r->print('<ul>'.$depresult.'</ul>');
568: }
569: }
570: } else {
571: my ($navmap,$errormsg) =
572: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
573: if (!ref($navmap)) {
574: $r->print($errormsg);
575: } else {
576: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
577: $r->rflush();
578: my ($preamble,$formname);
579: $formname = 'dumpdoc';
580: unless ($home==1) {
581: $preamble = '<div class="LC_left_float">'.
582: '<fieldset><legend>'.
583: &mt('Select the Authoring Space').
584: '</legend><select name="authorspace">';
585: }
586: my @orderspaces = ();
587: foreach my $key (sort(keys(%outhash))) {
588: if ($key=~/^home_(.+)$/) {
589: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
590: unshift(@orderspaces,$1);
591: } else {
592: push(@orderspaces,$1);
593: }
594: }
595: }
596: if ($home>1) {
597: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
598: }
599: foreach my $user (@orderspaces) {
600: if ($home==1) {
601: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
602: } else {
603: $preamble .= '<option value="'.$user.'">'.$user.' - '.
604: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
605: }
606: }
607: unless ($home==1) {
608: $preamble .= '</select></fieldset></div>'."\n";
609: }
610: my $title=$origcrsdata{'description'};
611: $title=~s/[\/\s]+/\_/gs;
612: $title=&clean($title);
613: $preamble .= '<div class="LC_left_float">'.
614: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
615: '<input type="text" size="50" name="authorfolder" value="'.
616: $title.'" />'.
617: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
618: my %uploadedfiles;
619: &tiehash();
620: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
621: my ($ext)=($file=~/\.(\w+)$/);
622: # FIXME Check supplemental here
623: my $title=$hash{'title_'.$hash{
624: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
625: if (!$title) {
626: $title=$file;
627: } else {
628: $title=~s|/|_|g;
629: }
630: $title=~s/\.(\w+)$//;
631: $title=&clean($title);
632: $title.='.'.$ext;
633: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
634: $uploadedfiles{$file} = $title;
635: }
636: &untiehash();
637: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
638: undef,undef,$preamble,$home,\%uploadedfiles));
639: }
640: }
641: $r->print(&endContentScreen());
642: }
643:
644: sub recurse_html {
645: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
646: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
647: my (%allfiles,%codebase);
648: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
649: if (keys(%allfiles)) {
650: foreach my $dependency (keys(%allfiles)) {
651: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
652: my ($depurl,$relfile,$newcontainer);
653: if ($dependency =~ m{^/}) {
654: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
655: $relfile = $1;
656: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
657: $newcontainer = $1;
658: next if ($replacehash->{$newcontainer});
659: }
660: $depurl = $dependency;
661: } else {
662: next;
663: }
664: } else {
665: $relfile = $dependency;
666: $depurl = $currurlpath;
667: $depurl =~ s{[^/]+$}{};
668: $depurl .= $dependency;
669: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
670: }
671: next if ($relfile eq '');
672: my $newname = $replacehash->{$container};
673: $newname =~ s{[^/]+$}{};
674: $replacehash->{$newcontainer} = $newname.$relfile;
675: $deps->{$item}{$newcontainer} = 1;
676: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
677: my $depfile = &Apache::lonnet::filelocation('',$depurl);
678: my $type = $mm->checktype_filename($depfile);
679: if ($type eq 'text/html') {
680: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
681: }
682: }
683: }
684: }
685: return;
686: }
687:
688: sub group_import {
689: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
690: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
691: %removeparam,$importuploaded,$fixuperrors);
692: $allmaps = {};
693: while (@files) {
694: my ($name, $url, $residx) = @{ shift(@files) };
695: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
696: && ($caller eq 'londocs')
697: && (!&Apache::lonnet::stat_file($url))) {
698:
699: my $errtext = '';
700: my $fatal = 0;
701: my $newmapstr = '<map>'."\n".
702: '<resource id="1" src="" type="start"></resource>'."\n".
703: '<link from="1" to="2" index="1"></link>'."\n".
704: '<resource id="2" src="" type="finish"></resource>'."\n".
705: '</map>';
706: $env{'form.output'}=$newmapstr;
707: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
708: 'output',$1.$2);
709: if ($result !~ m{^/uploaded/}) {
710: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
711: $fatal = 2;
712: }
713: if ($fatal) {
714: return ($errtext,$fatal);
715: }
716: }
717: if ($url) {
718: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
719: $url = $1;
720: my $marker = $2;
721: my $info = $3;
722: my ($toolid,%toolhash,%toolsettings);
723: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
724: my @toolinfo = split(/:/,$info);
725: if ($residx) {
726: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
727: $toolid = $toolsettings{'id'};
728: } else {
729: $toolid = shift(@toolinfo);
730: }
731: $toolid =~ s/\D//g;
732: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
733: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
734: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
735: foreach my $item (@extras) {
736: $toolhash{$item} = &unescape($toolhash{$item});
737: }
738: if ($folder =~ /^supplemental/) {
739: delete($toolhash{'gradable'});
740: } else {
741: $toolhash{'gradable'} =~ s/\D+//g;
742: }
743: if (ref($ltitoolsref) eq 'HASH') {
744: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
745: my @deleted;
746: $toolhash{'id'} = $toolid;
747: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
748: ($toolhash{'target'} eq 'window')) {
749: if ($toolhash{'target'} eq 'window') {
750: foreach my $item ('width','height') {
751: $toolhash{$item} =~ s/^\s+//;
752: $toolhash{$item} =~ s/\s+$//;
753: if ($toolhash{$item} =~ /\D/) {
754: delete($toolhash{$item});
755: if ($residx) {
756: if ($toolsettings{$item}) {
757: push(@deleted,$item);
758: }
759: }
760: }
761: }
762: }
763: } elsif ($residx) {
764: $toolhash{'target'} = $toolsettings{'target'};
765: if ($toolhash{'target'} eq 'window') {
766: foreach my $item ('width','height') {
767: $toolhash{$item} = $toolsettings{$item};
768: }
769: }
770: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
771: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
772: if ($toolhash{'target'} eq 'window') {
773: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
774: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
775: }
776: }
777: if ($toolhash{'target'} eq 'iframe') {
778: foreach my $item ('width','height','linktext','explanation') {
779: delete($toolhash{$item});
780: if ($residx) {
781: if ($toolsettings{$item}) {
782: push(@deleted,$item);
783: }
784: }
785: }
786: } elsif ($toolhash{'target'} eq 'tab') {
787: foreach my $item ('width','height') {
788: delete($toolhash{$item});
789: if ($residx) {
790: if ($toolsettings{$item}) {
791: push(@deleted,$item);
792: }
793: }
794: }
795: }
796: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
797: foreach my $item ('label','title','linktext','explanation') {
798: my $crsitem;
799: if (($item eq 'label') || ($item eq 'title')) {
800: $crsitem = 'crs'.$item;
801: } else {
802: $crsitem = $item;
803: }
804: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
805: $toolhash{$crsitem} =~ s/^\s+//;
806: $toolhash{$crsitem} =~ s/\s+$//;
807: if ($toolhash{$crsitem} eq '') {
808: delete($toolhash{$crsitem});
809: }
810: } else {
811: delete($toolhash{$crsitem});
812: }
813: if (($residx) && (exists($toolsettings{$crsitem}))) {
814: unless (exists($toolhash{$crsitem})) {
815: push(@deleted,$crsitem);
816: }
817: }
818: }
819: }
820: if ($toolhash{'passback'}) {
821: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
822: $toolhash{'gradesecret'} = $gradesecret;
823: $toolhash{'gradesecretdate'} = time;
824: }
825: if ($toolhash{'roster'}) {
826: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
827: $toolhash{'rostersecret'} = $rostersecret;
828: $toolhash{'rostersecretdate'} = time;
829: }
830: my $changegradable;
831: if (($residx) && ($folder =~ /^default/)) {
832: if ($toolsettings{'gradable'}) {
833: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
834: push(@deleted,'gradable');
835: $changegradable = 1;
836: }
837: } elsif ($toolhash{'gradable'}) {
838: $changegradable = 1;
839: }
840: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
841: $changegradable = 1;
842: if ($toolsettings{'gradable'}) {
843: $toolhash{'gradable'} = 1;
844: }
845: }
846: }
847: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
848: if ($putres eq 'ok') {
849: if (@deleted) {
850: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
851: }
852: if (($changegradable) && ($folder =~ /^default/)) {
853: my $val;
854: if ($toolhash{'gradable'}) {
855: $val = 'yes';
856: } else {
857: $val = 'no';
858: }
859: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
860: 'string_yesno');
861: &remember_parms($residx,'gradable','set',$val);
862: }
863: } else {
864: return (&mt('Failed to save update to external tool.'),1);
865: }
866: }
867: }
868: }
869: if (($caller eq 'londocs') &&
870: ($folder =~ /^default/)) {
871: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
872: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
873: my $cid = $coursedom.'_'.$coursenum;
874: $allmaps =
875: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
876: $chome,$cid);
877: $donechk = 1;
878: }
879: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
880: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
881: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
882: $importuploaded = 1;
883: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
884: next if ($allmaps->{$url});
885: }
886: }
887: if (!$residx
888: || defined($LONCAPA::map::zombies[$residx])) {
889: $residx = &LONCAPA::map::getresidx($url,$residx);
890: push(@LONCAPA::map::order, $residx);
891: }
892: my $ext = 'false';
893: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
894: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
895: my $filepath = $1;
896: my $fname;
897: if ($name eq '') {
898: $name = &mt('Web Page');
899: $fname = 'web';
900: } else {
901: $fname = $name;
902: $fname=&Apache::lonnet::clean_filename($fname);
903: if ($fname eq '') {
904: $fname = 'web';
905: } elsif (length($fname) > 15) {
906: $fname = substr($fname,0,14);
907: }
908: }
909: my $title = &Apache::loncommon::cleanup_html($name);
910: my $initialtext = &mt('Replace with your own content.');
911: my $newhtml = <<END;
912: <html>
913: <head>
914: <title>$title</title>
915: </head>
916: <body bgcolor="#ffffff">
917: $initialtext
918: </body>
919: </html>
920: END
921: $env{'form.output'}=$newhtml;
922: my $result =
923: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
924: 'output',
925: "$filepath/$residx/$fname.html");
926: if ($result =~ m{^/uploaded/}) {
927: $url = $result;
928: if ($filepath =~ /^supplemental/) {
929: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
930: $env{'user.domain'}.'___&&&___'.$name;
931: }
932: } else {
933: return (&mt('Failed to save new web page.'),1);
934: }
935: }
936: $name = &LONCAPA::map::qtunescape($name);
937: $url = &LONCAPA::map::qtunescape($url);
938: $LONCAPA::map::resources[$residx] =
939: join(':', ($name, $url, $ext, 'normal', 'res'));
940: }
941: }
942: if ($importuploaded) {
943: my %import_errors;
944: my %updated = (
945: removefrommap => \%removefrommap,
946: removeparam => \%removeparam,
947: );
948: my ($result,$msgsarray,$lockerror) =
949: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
950: if (keys(%import_errors) > 0) {
951: $fixuperrors =
952: '<p span class="LC_warning">'."\n".
953: &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".
954: '<ul>'."\n";
955: foreach my $key (sort(keys(%import_errors))) {
956: $fixuperrors .= '<li>'.$key.'</li>'."\n";
957: }
958: $fixuperrors .= '</ul></p>'."\n";
959: }
960: if (ref($msgsarray) eq 'ARRAY') {
961: if (@{$msgsarray} > 0) {
962: $fixuperrors .= '<p class="LC_info">'.
963: join('<br />',@{$msgsarray}).
964: '</p>';
965: }
966: }
967: if ($lockerror) {
968: $fixuperrors .= '<p class="LC_error">'.
969: $lockerror.
970: '</p>';
971: }
972: }
973: my ($errtext,$fatal) =
974: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
975: unless ($fatal) {
976: if ($folder =~ /^supplemental/) {
977: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
978: $folder.'.'.$container);
979: }
980: }
981: return ($errtext,$fatal,$fixuperrors);
982: }
983:
984: sub log_docs {
985: return &Apache::lonnet::write_log('course','docslog',@_);
986: }
987:
988: {
989: my @oldresources=();
990: my @oldorder=();
991: my $parmidx;
992: my %parmaction=();
993: my %parmvalue=();
994: my $changedflag;
995:
996: sub snapshotbefore {
997: @oldresources=@LONCAPA::map::resources;
998: @oldorder=@LONCAPA::map::order;
999: $parmidx=undef;
1000: %parmaction=();
1001: %parmvalue=();
1002: $changedflag=0;
1003: }
1004:
1005: sub remember_parms {
1006: my ($idx,$parameter,$action,$value)=@_;
1007: $parmidx=$idx;
1008: $parmaction{$parameter}=$action;
1009: $parmvalue{$parameter}=$value;
1010: $changedflag=1;
1011: }
1012:
1013: sub log_differences {
1014: my ($plain)=@_;
1015: my %storehash=('folder' => $plain,
1016: 'currentfolder' => $env{'form.folder'});
1017: if ($parmidx) {
1018: $storehash{'parameter_res'}=$oldresources[$parmidx];
1019: foreach my $parm (keys(%parmaction)) {
1020: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1021: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1022: }
1023: }
1024: my $maxidx=$#oldresources;
1025: if ($#LONCAPA::map::resources>$#oldresources) {
1026: $maxidx=$#LONCAPA::map::resources;
1027: }
1028: for (my $idx=0; $idx<=$maxidx; $idx++) {
1029: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1030: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1031: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1032: $changedflag=1;
1033: }
1034: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1035: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1036: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1037: $changedflag=1;
1038: }
1039: }
1040: $storehash{'maxidx'}=$maxidx;
1041: if ($changedflag) { &log_docs(\%storehash); }
1042: }
1043: }
1044:
1045: sub docs_change_log {
1046: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1047: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1048: my $navmap;
1049: my $js = '<script type="text/javascript">'."\n".
1050: '// <![CDATA['."\n".
1051: &Apache::loncommon::display_filter_js('docslog')."\n".
1052: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1053: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1054: &history_tab_js()."\n".
1055: &Apache::lonratedt::editscript('simple')."\n".
1056: '// ]]>'."\n".
1057: '</script>'."\n";
1058: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1059: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1060: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1061: my %orderhash;
1062: my $container='sequence';
1063: my $pathitem;
1064: if ($env{'form.folderpath'} =~ /\:1$/) {
1065: $container='page';
1066: }
1067: my $folderpath=$env{'form.folderpath'};
1068: if ($folderpath eq '') {
1069: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1070: }
1071: undef($navmap);
1072: $pathitem = '<input type="hidden" name="folderpath" value="'.
1073: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1074: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1075: my $jumpto = $readfile;
1076: $jumpto =~ s{^/}{};
1077: my $tid = 1;
1078: if ($supplementalflag) {
1079: $tid = 2;
1080: }
1081: my ($breadcrumbtrail) =
1082: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1083: $r->print($breadcrumbtrail.
1084: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1085: $readfile));
1086: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1087: $env{'course.'.$env{'request.course.id'}.'.domain'},
1088: $env{'course.'.$env{'request.course.id'}.'.num'});
1089:
1090: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1091:
1092: my %saveable_parameters = ('show' => 'scalar',);
1093: &Apache::loncommon::store_course_settings('docs_log',
1094: \%saveable_parameters);
1095: &Apache::loncommon::restore_course_settings('docs_log',
1096: \%saveable_parameters);
1097: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1098: # FIXME: internationalization seems wrong here
1099: my %lt=('hiddenresource' => 'Resources hidden',
1100: 'encrypturl' => 'URL hidden',
1101: 'randompick' => 'Randomly pick',
1102: 'randomorder' => 'Randomly ordered',
1103: 'gradable' => 'Grade can be assigned to External Tool',
1104: 'set' => 'set to',
1105: 'del' => 'deleted');
1106: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1107: $pathitem."\n".
1108: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1109: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1110: $r->print('<div class="LC_left_float">'.
1111: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1112: &makedocslogform($filter,1).
1113: '</fieldset></div><br clear="all" />');
1114: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1115: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1116: &mt('After').'</th>'.
1117: &Apache::loncommon::end_data_table_header_row());
1118: my $shown=0;
1119: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1120: if ($env{'form.displayfilter'} eq 'currentfolder') {
1121: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1122: }
1123: my @changes=keys(%{$docslog{$id}{'logentry'}});
1124: if ($env{'form.displayfilter'} eq 'containing') {
1125: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1126: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1127: foreach my $key (@changes) {
1128: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1129: }
1130: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1131: }
1132: my $count = 0;
1133: my $time =
1134: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1135: my $plainname =
1136: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1137: $docslog{$id}{'exe_udom'});
1138: my $about_me_link =
1139: &Apache::loncommon::aboutmewrapper($plainname,
1140: $docslog{$id}{'exe_uname'},
1141: $docslog{$id}{'exe_udom'});
1142: my $send_msg_link='';
1143: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1144: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1145: $send_msg_link ='<br />'.
1146: &Apache::loncommon::messagewrapper(&mt('Send message'),
1147: $docslog{$id}{'exe_uname'},
1148: $docslog{$id}{'exe_udom'});
1149: }
1150: $r->print(&Apache::loncommon::start_data_table_row());
1151: $r->print('<td>'.$time.'</td>
1152: <td>'.$about_me_link.
1153: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1154: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1155: $send_msg_link.'</td><td>'.
1156: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1157: my $is_supp = 0;
1158: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1159: $is_supp = 1;
1160: }
1161: # Before
1162: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1163: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1164: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1165: if ($oldname ne $newname) {
1166: my $shown = &LONCAPA::map::qtescape($oldname);
1167: if ($is_supp) {
1168: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1169: }
1170: $r->print($shown);
1171: }
1172: }
1173: $r->print('<ul>');
1174: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1175: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1176: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1177: if ($is_supp) {
1178: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1179: }
1180: $r->print('<li>'.$shown.'</li>');
1181: }
1182: }
1183: $r->print('</ul>');
1184: # After
1185: $r->print('</td><td>');
1186:
1187: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1188: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1189: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1190: if ($oldname ne '' && $oldname ne $newname) {
1191: my $shown = &LONCAPA::map::qtescape($newname);
1192: if ($is_supp) {
1193: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1194: }
1195: $r->print($shown);
1196: }
1197: }
1198: $r->print('<ul>');
1199: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1200: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1201: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1202: if ($is_supp) {
1203: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1204: }
1205: $r->print('<li>'.$shown.'</li>');
1206: }
1207: }
1208: $r->print('</ul>');
1209: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1210: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1211: if ($title eq '') {
1212: ($title) = ($url =~ m{/([^/]+)$});
1213: } elsif ($is_supp) {
1214: $title = &Apache::loncommon::parse_supplemental_title($title);
1215: }
1216: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1217: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1218: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1219: # FIXME: internationalization seems wrong here
1220: $r->print('<li>'.
1221: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1222: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1223: .'</li>');
1224: }
1225: }
1226: $r->print('</ul>');
1227: }
1228: # End
1229: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1230: $shown++;
1231: if (!($env{'form.show'} eq &mt('all')
1232: || $shown<=$env{'form.show'})) { last; }
1233: }
1234: $r->print(&Apache::loncommon::end_data_table()."\n".
1235: &makesimpleeditform($pathitem)."\n".
1236: '</div></div>');
1237: $r->print(&endContentScreen());
1238: }
1239:
1240: sub update_paste_buffer {
1241: my ($coursenum,$coursedom,$folder) = @_;
1242: my (@possibles,%removals,%cuts,$output);
1243: if ($env{'form.multiremove'}) {
1244: $env{'form.multiremove'} =~ s/,$//;
1245: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1246: }
1247: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1248: if ($env{'form.multicut'}) {
1249: $env{'form.multicut'} =~ s/,$//;
1250: foreach my $item (split(/,/,$env{'form.multicut'})) {
1251: unless ($removals{$item}) {
1252: $cuts{$item} = 1;
1253: push(@possibles,$item.':cut');
1254: }
1255: }
1256: }
1257: if ($env{'form.multicopy'}) {
1258: $env{'form.multicopy'} =~ s/,$//;
1259: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1260: unless ($removals{$item} || $cuts{$item}) {
1261: push(@possibles,$item.':copy');
1262: }
1263: }
1264: }
1265: } elsif ($env{'form.markcopy'}) {
1266: @possibles = split(/,/,$env{'form.markcopy'});
1267: }
1268:
1269: return if (@possibles == 0);
1270: return if (!defined($env{'form.copyfolder'}));
1271:
1272: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1273: $env{'form.copyfolder'});
1274: return if ($fatal);
1275:
1276: my %curr_groups = &Apache::longroup::coursegroups();
1277:
1278: # Retrieve current paste buffer suffixes.
1279: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1280: my (%pasteurls,@newpaste);
1281:
1282: # Construct identifiers for current contents of user's paste buffer
1283: if (@currpaste) {
1284: foreach my $suffix (@currpaste) {
1285: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1286: my $url = $env{'docs.markedcopy_url_'.$suffix};
1287: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1288: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1289: ($url ne '')) {
1290: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1291: $pasteurls{$cid.'_'.$mapidx} = 1;
1292: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1293: $pasteurls{$url} = 1;
1294: } else {
1295: $pasteurls{$cid.'_'.$url} = 1;
1296: }
1297: }
1298: }
1299: }
1300:
1301: # Mark items for copying (skip any items already in user's paste buffer)
1302: my %addtoenv;
1303:
1304: my @pathitems = split(/\&/,$env{'form.folderpath'});
1305: my @folderconf = split(/\:/,$pathitems[-1]);
1306: my $ispage = $folderconf[5];
1307:
1308: foreach my $item (@possibles) {
1309: my ($orderidx,$cmd) = split(/:/,$item);
1310: next if ($orderidx =~ /\D/);
1311: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1312: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1313: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1314: my %denied = &action_restrictions($coursenum,$coursedom,
1315: &LONCAPA::map::qtescape($url),
1316: $env{'form.folderpath'},\%curr_groups);
1317: next if ($denied{'copy'});
1318: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1319: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1320: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1321: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1322: next if (exists($pasteurls{$url}));
1323: } else {
1324: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1325: }
1326: my ($suffix,$errortxt,$locknotfreed) =
1327: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1328: if ($suffix ne '') {
1329: push(@newpaste,$suffix);
1330: } else {
1331: if ($locknotfreed) {
1332: return $locknotfreed;
1333: }
1334: }
1335: if (&is_supplemental_title($title)) {
1336: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1337: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1338: }
1339:
1340: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1341: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1342: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1343: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1344: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1345: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1346: my $prefix = $1;
1347: my $subdir =$2;
1348: if ($subdir eq '') {
1349: $subdir = $prefix;
1350: }
1351: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1352: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1353: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1354: if (ref($hierarchy{$url}) eq 'HASH') {
1355: my ($nested,$nestednames);
1356: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1357: $nested =~ s/\&$//;
1358: $nestednames =~ s/\Q___&&&___\E$//;
1359: if ($nested ne '') {
1360: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1361: }
1362: if ($nestednames ne '') {
1363: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1364: }
1365: }
1366: }
1367: if ($locknotfreed) {
1368: $output = $locknotfreed;
1369: last;
1370: }
1371: }
1372: if (@newpaste) {
1373: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1374: }
1375: &Apache::lonnet::appenv(\%addtoenv);
1376: delete($env{'form.markcopy'});
1377: return $output;
1378: }
1379:
1380: sub recurse_uploaded_maps {
1381: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1382: if (ref($hierarchy->{$url}) eq 'HASH') {
1383: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1384: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1385: my (@uploaded,@names,%shorter);
1386: for (my $i=0; $i<@maps; $i++) {
1387: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1388: if ($inner ne '') {
1389: push(@uploaded,$inner);
1390: push(@names,&escape($titles[$i]));
1391: $shorter{$maps[$i]} = $inner;
1392: }
1393: }
1394: $$nestref .= "$dir:".join(',',@uploaded).'&';
1395: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1396: foreach my $map (@maps) {
1397: if ($shorter{$map} ne '') {
1398: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1399: }
1400: }
1401: }
1402: return;
1403: }
1404:
1405: sub print_paste_buffer {
1406: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1407: return if (!defined($env{'docs.markedcopies'}));
1408:
1409: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1410: return if ($env{'docs.markedcopies'} eq '');
1411: }
1412:
1413: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1414: my ($pasteitems,@pasteable);
1415: my $clipboardcount = 0;
1416:
1417: # Construct identifiers for current contents of user's paste buffer
1418: foreach my $suffix (@currpaste) {
1419: next if ($suffix =~ /\D/);
1420: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1421: my $url = $env{'docs.markedcopy_url_'.$suffix};
1422: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1423: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1424: ($url ne '')) {
1425: $clipboardcount ++;
1426: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1427: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1428: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1429: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1430: $is_external = 1;
1431: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1432: $is_exttool = 1;
1433: }
1434: if ($folder =~ /^supplemental/) {
1435: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1436: unless ($canpaste) {
1437: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1438: }
1439: } else {
1440: $canpaste = 1;
1441: }
1442: if ($canpaste) {
1443: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1444: my $srcdom = $1;
1445: my $srcnum = $2;
1446: my $rem = $3;
1447: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1448: $othercourse = 1;
1449: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1450: $othercrs = '<br />'.&mt('(from another course)');
1451: } else {
1452: $canpaste = 0;
1453: $nopaste = &mt('Paste from another course unavailable.');
1454: }
1455: }
1456: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1457: my $prefix = $1;
1458: $parent = $2;
1459: if ($folder !~ /^\Q$prefix\E/) {
1460: $areachange = 1;
1461: }
1462: $is_uploaded_map = 1;
1463: }
1464: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1465: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1466: if ($cid ne $env{'request.course.id'}) {
1467: my ($srcdom,$srcnum) = split(/_/,$cid);
1468: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1469: if (($is_exttool) && ($srcdom ne $coursedom)) {
1470: $canpaste = 0;
1471: $nopaste = &mt('Paste from another domain unavailable.');
1472: } else {
1473: $othercrs = '<br />'.&mt('(from another course)');
1474: }
1475: } else {
1476: $canpaste = 0;
1477: $nopaste = &mt('Paste from another course unavailable.');
1478: }
1479: }
1480: }
1481: if ($canpaste) {
1482: push(@pasteable,$suffix);
1483: }
1484: }
1485: my $buffer;
1486: if ($is_external) {
1487: $buffer = &mt('External Resource').': '.
1488: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1489: &LONCAPA::map::qtescape($url).')';
1490: } elsif ($is_exttool) {
1491: $buffer = &mt('External Tool').': '.
1492: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1493: } else {
1494: my $icon = &Apache::loncommon::icon($extension);
1495: if ($extension eq 'sequence' &&
1496: $url =~ m{/default_\d+\.sequence$}x) {
1497: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1498: $icon .= '/navmap.folder.closed.gif';
1499: }
1500: my $title = $env{'docs.markedcopy_title_'.$suffix};
1501: if ($title eq '') {
1502: ($title) = ($url =~ m{/([^/]+)$});
1503: }
1504: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1505: ': '.
1506: &Apache::loncommon::parse_supplemental_title(
1507: &LONCAPA::map::qtescape($title));
1508: }
1509: $pasteitems .= '<div class="LC_left_float">';
1510: my ($options,$onclick);
1511: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1512: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1513: if (($is_uploaded_map) ||
1514: ($url =~ /(bulletinboard|smppg)$/) ||
1515: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1516: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1517: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1518: }
1519: }
1520: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1521: if ($nopaste) {
1522: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1523: } else {
1524: if ($othercrs) {
1525: $pasteitems .= $othercrs;
1526: }
1527: if ($options) {
1528: $pasteitems .= $options;
1529: }
1530: }
1531: $pasteitems .= '</div>';
1532: }
1533: }
1534: if ($pasteitems eq '') {
1535: &Apache::lonnet::delenv('docs.markedcopies');
1536: }
1537: my ($pasteform,$form_start,$buttons,$form_end);
1538: if ($pasteitems) {
1539: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1540: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1541: if (@pasteable) {
1542: my $value = &mt('Paste to current folder');
1543: if ($container eq 'page') {
1544: $value = &mt('Paste to current page');
1545: }
1546: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1547: }
1548: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1549: if ($clipboardcount > 1) {
1550: $buttons .=
1551: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1552: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1553: (' 'x2).
1554: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1555: (' 'x2);
1556: }
1557: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1558: '</form>';
1559: } else {
1560: $pasteitems = &mt('Clipboard is empty');
1561: }
1562: $r->print($form_start
1563: .'<fieldset>'
1564: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1565: .$pasteitems
1566: .'</fieldset>'
1567: .$form_end);
1568: }
1569:
1570: sub paste_options {
1571: my ($suffix,$is_uploaded_map,$parent) = @_;
1572: my ($copytext,$movetext);
1573: if ($is_uploaded_map) {
1574: $copytext = &mt('Copy to new folder');
1575: $movetext = &mt('Move old');
1576: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1577: $copytext = &mt('Copy to new board');
1578: $movetext = &mt('Move (not posts)');
1579: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1580: $copytext = &mt('Copy to new page');
1581: $movetext = &mt('Move');
1582: } else {
1583: $copytext = &mt('Copy to new file');
1584: $movetext = &mt('Move');
1585: }
1586: my $output = '<br />'.
1587: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1588: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1589: '<label>'.
1590: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1591: $copytext.'</label></span>'.(' 'x2).' '.
1592: '<span class="LC_nobreak"><label>'.
1593: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1594: $movetext.'</label></span>';
1595: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1596: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1597: '</legend><table border="0">';
1598: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1599: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1600: my $lastdir = $parent;
1601: my %depths = (
1602: $lastdir => 0,
1603: );
1604: my (%display,%deps);
1605: for (my $i=0; $i<@pastemaps; $i++) {
1606: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1607: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1608: my @subfolders = split(/,/,$subfolderstr);
1609: $deps{$lastdir} = \@subfolders;
1610: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1611: my $depth = $depths{$lastdir} + 1;
1612: my $offset = int($depth * 4);
1613: my $indent = (' ' x $offset);
1614: for (my $j=0; $j<@subfolders; $j++) {
1615: $depths{$subfolders[$j]} = $depth;
1616: $display{$subfolders[$j]} =
1617: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1618: '<td><label>'.
1619: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1620: '<label>'.
1621: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1622: &mt('Move old').'</label>'.
1623: '</td></tr>';
1624: }
1625: }
1626: &recurse_print(\$output,$parent,\%deps,\%display);
1627: $output .= '</table></fieldset>';
1628: }
1629: $output .= '</div>';
1630: return $output;
1631: }
1632:
1633: sub recurse_print {
1634: my ($outputref,$dir,$deps,$display) = @_;
1635: $$outputref .= $display->{$dir}."\n";
1636: if (ref($deps->{$dir}) eq 'ARRAY') {
1637: foreach my $subdir (@{$deps->{$dir}}) {
1638: &recurse_print($outputref,$subdir,$deps,$display);
1639: }
1640: }
1641: }
1642:
1643: sub supp_pasteable {
1644: my ($url) = @_;
1645: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1646: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1647: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1648: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1649: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1650: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1651: return 1;
1652: }
1653: return;
1654: }
1655:
1656: sub paste_popup_js {
1657: my %html_js_lt = &Apache::lonlocal::texthash(
1658: show => 'Show Options',
1659: hide => 'Hide Options',
1660: );
1661: my %js_lt = &Apache::lonlocal::texthash(
1662: none => 'No items selected from clipboard.',
1663: );
1664: &html_escape(\%html_js_lt);
1665: &js_escape(\%html_js_lt);
1666: &js_escape(\%js_lt);
1667: return <<"END";
1668:
1669: function showPasteOptions(suffix) {
1670: document.getElementById('pasteoptions_'+suffix).style.display='block';
1671: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1672: return;
1673: }
1674:
1675: function hidePasteOptions(suffix) {
1676: document.getElementById('pasteoptions_'+suffix).style.display='none';
1677: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1678: return;
1679: }
1680:
1681: function showOptions(caller,suffix) {
1682: if (document.getElementById('pasteoptionstext_'+suffix)) {
1683: if (caller.checked) {
1684: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1685: } else {
1686: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1687: }
1688: if (document.getElementById('pasteoptions_'+suffix)) {
1689: document.getElementById('pasteoptions_'+suffix).style.display='none';
1690: }
1691: }
1692: return;
1693: }
1694:
1695: function validateClipboard() {
1696: var numchk = 0;
1697: if (document.pasteform.pasting.length > 1) {
1698: for (var i=0; i<document.pasteform.pasting.length; i++) {
1699: if (document.pasteform.pasting[i].checked) {
1700: numchk ++;
1701: }
1702: }
1703: } else {
1704: if (document.pasteform.pasting.type == 'checkbox') {
1705: if (document.pasteform.pasting.checked) {
1706: numchk ++;
1707: }
1708: }
1709: }
1710: if (numchk > 0) {
1711: return true;
1712: } else {
1713: alert("$js_lt{'none'}");
1714: return false;
1715: }
1716: }
1717:
1718: function checkClipboard() {
1719: if (document.pasteform.pasting.length > 1) {
1720: for (var i=0; i<document.pasteform.pasting.length; i++) {
1721: document.pasteform.pasting[i].checked = true;
1722: }
1723: }
1724: return;
1725: }
1726:
1727: function uncheckClipboard() {
1728: if (document.pasteform.pasting.length >1) {
1729: for (var i=0; i<document.pasteform.pasting.length; i++) {
1730: document.pasteform.pasting[i].checked = false;
1731: }
1732: }
1733: return;
1734: }
1735:
1736: END
1737:
1738: }
1739:
1740: sub do_paste_from_buffer {
1741: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1742:
1743: # Array of items in paste buffer
1744: my (@currpaste,%pastebuffer,%allerrors);
1745: @currpaste = split(/,/,$env{'docs.markedcopies'});
1746:
1747: # Early out if paste buffer is empty
1748: if (@currpaste == 0) {
1749: return ();
1750: }
1751: map { $pastebuffer{$_} = 1; } @currpaste;
1752:
1753: # Array of items selected items to paste
1754: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1755:
1756: # Early out if nothing selected to paste
1757: if (@reqpaste == 0) {
1758: return();
1759: }
1760: my @topaste;
1761: foreach my $suffix (@reqpaste) {
1762: next if ($suffix =~ /\D/);
1763: next unless (exists($pastebuffer{$suffix}));
1764: push(@topaste,$suffix);
1765: }
1766:
1767: # Early out if nothing available to paste
1768: if (@topaste == 0) {
1769: return();
1770: }
1771:
1772: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1773: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1774:
1775: foreach my $suffix (@topaste) {
1776: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1777: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1778: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1779: # Supplemental content may only include certain types of content
1780: # Early out if pasted content is not supported in Supplemental area
1781: if ($folder =~ /^supplemental/) {
1782: unless (&supp_pasteable($url)) {
1783: $notinsupp{$suffix} = 1;
1784: next;
1785: }
1786: }
1787: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1788: my $srcd = $1;
1789: my $srcn = $2;
1790: # When paste buffer was populated using an active role in a different course
1791: # check for mdc privilege in the course from which the resource was pasted
1792: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1793: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1794: $notincrs{$suffix} = 1;
1795: next;
1796: }
1797: }
1798: $srcdom{$suffix} = $srcd;
1799: $srcnum{$suffix} = $srcn;
1800: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1801: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1802: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1803: my ($srcd,$srcn) = split(/_/,$cid);
1804: # When paste buffer was populated using an active role in a different course
1805: # check for mdc privilege in the course from which the resource was pasted
1806: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1807: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1808: $notincrs{$suffix} = 1;
1809: next;
1810: }
1811: }
1812: # When buffer was populated using an active role in a different course
1813: # disallow pasting of External Tool if course is in a different domain.
1814: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1815: $notindom{$suffix} = 1;
1816: next;
1817: }
1818: $srcdom{$suffix} = $srcd;
1819: $srcnum{$suffix} = $srcn;
1820: }
1821: $srcmapidx{$suffix} = $mapidx;
1822: push(@dopaste,$suffix);
1823: if ($url=~/\.(page|sequence)$/) {
1824: $is_map{$suffix} = 1;
1825: }
1826: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1827: my $oldprefix = $1;
1828: # When pasting content from Main Content to Supplemental Content and vice versa
1829: # URLs will contain different paths (which depend on whether pasted item is
1830: # a folder/page or a document).
1831: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1832: $prefixchg{$suffix} = 'docstosupp';
1833: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1834: $prefixchg{$suffix} = 'supptodocs';
1835: }
1836:
1837: # If pasting an uploaded map, get list of contained uploaded maps.
1838: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1839: my @nested;
1840: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1841: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1842: my @deps = map { /\d+:([\d,]+$)/ } @items;
1843: foreach my $dep (@deps) {
1844: if ($dep =~ /,/) {
1845: push(@nested,split(/,/,$dep));
1846: } else {
1847: push(@nested,$dep);
1848: }
1849: }
1850: foreach my $item (@nested) {
1851: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1852: push(@{$marktomove{$suffix}},$type.'_'.$item);
1853: }
1854: }
1855: }
1856: }
1857: }
1858:
1859: # Early out if nothing available to paste
1860: if (@dopaste == 0) {
1861: return ();
1862: }
1863:
1864: # Populate message hash and hashes used for main content <=> supplemental content
1865: # changes
1866:
1867: %msgs = &Apache::lonlocal::texthash (
1868: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1869: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1870: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1871: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1872: );
1873:
1874: %before = (
1875: docstosupp => {
1876: map => 'default',
1877: doc => 'docs',
1878: },
1879: supptodocs => {
1880: map => 'supplemental',
1881: doc => 'supplemental',
1882: },
1883: );
1884:
1885: %after = (
1886: docstosupp => {
1887: map => 'supplemental',
1888: doc => 'supplemental'
1889: },
1890: supptodocs => {
1891: map => 'default',
1892: doc => 'docs',
1893: },
1894: );
1895:
1896: # Retrieve information about all course maps in main content area
1897:
1898: my $allmaps = {};
1899: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1900:
1901: # Loop over the items to paste
1902: foreach my $suffix (@dopaste) {
1903: # Maps need to be copied first
1904: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1905: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1906: %newurls,%tomove,%resdatacopy);
1907: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1908: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1909: }
1910: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1911: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1912: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1913: my $oldurl = $url;
1914: if ($is_map{$suffix}) {
1915: # If pasting a map, check if map contains other maps
1916: my (%hierarchy,%titles);
1917: if (($folder =~ /^default/) && (!$donechk)) {
1918: $allmaps =
1919: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1920: $env{"course.$env{'request.course.id'}.home"},
1921: $env{'request.course.id'});
1922: $donechk = 1;
1923: }
1924: &contained_map_check($url,$folder,$coursenum,$coursedom,
1925: \%removefrommap,\%removeparam,\%addedmaps,
1926: \%hierarchy,\%titles,$allmaps);
1927: if ($url=~ m{^/uploaded/}) {
1928: my $newurl;
1929: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1930: ($newurl,my $error) =
1931: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1932: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1933: \$title,$allmaps,\%newurls);
1934: if ($error) {
1935: $allerrors{$suffix} = $error;
1936: next;
1937: }
1938: if ($newurl ne '') {
1939: if ($newurl ne $url) {
1940: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1941: $newsubdir{$url} = $1;
1942: }
1943: $mapchanges{$url} = 1;
1944: }
1945: }
1946: }
1947: if (($srcdom{$suffix} ne $coursedom) ||
1948: ($srcnum{$suffix} ne $coursenum) ||
1949: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1950: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1951: $coursedom,$coursenum,$srcdom{$suffix},
1952: $srcnum{$suffix},$allmaps,\%rewrites,
1953: \%retitles,\%copies,\%dbcopies,
1954: \%zombies,\%params,\%mapmoves,
1955: \%mapchanges,\%tomove,\%newsubdir,
1956: \%newurls,\%resdatacopy)) {
1957: $mapmoves{$url} = 1;
1958: }
1959: $url = $newurl;
1960: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1961: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1962: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1963: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1964: \%zombies,\%params,\%mapmoves,\%mapchanges,
1965: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1966: }
1967: } elsif ($url=~m {^/res/}) {
1968: # published map can only exist once, so remove from paste buffer when done
1969: push(@toclear,$suffix);
1970: # if pasting published map (main content area only) check map not already in course
1971: if ($folder =~ /^default/) {
1972: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1973: $duplicate{$suffix} = 1;
1974: next;
1975: }
1976: }
1977: }
1978: }
1979: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1980: my $prefix = $1;
1981: my $fromothercrs;
1982: #need to copy the db contents to a new one, unless this is a move.
1983: my %info = (
1984: src => $url,
1985: cdom => $coursedom,
1986: cnum => $coursenum,
1987: );
1988: if ($prefix eq 'ext.tool') {
1989: if ($prefixchg{$suffix} eq 'docstosupp') {
1990: $info{'delgradable'} = 1;
1991: }
1992: }
1993: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1994: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1995: $fromothercrs = 1;
1996: $info{'cdom'} = $srcdom{$suffix};
1997: $info{'cnum'} = $srcnum{$suffix};
1998: }
1999: }
2000: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
2001: my (%lockerr,$msg);
2002: my ($newurl,$result,$errtext) =
2003: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
2004: if ($result eq 'ok') {
2005: $url = $newurl;
2006: $title=&mt('Copy of').' '.$title;
2007: } else {
2008: if ($prefix eq 'smppg') {
2009: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2010: } elsif ($prefix eq 'bulletinboard') {
2011: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
2012: } elsif ($prefix eq 'ext.tool') {
2013: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
2014: }
2015: $results{$suffix} = $result;
2016: $msgerrs{$suffix} = $msg;
2017: $lockerrs{$suffix} = $lockerr{$prefix};
2018: next;
2019: }
2020: if ($lockerr{$prefix}) {
2021: $lockerrs{$suffix} = $lockerr{$prefix};
2022: }
2023: }
2024: }
2025: $title = &LONCAPA::map::qtunescape($title);
2026: my $ext='false';
2027: if ($url=~m{^http(|s)://}) { $ext='true'; }
2028: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2029: if ($folder !~ /^supplemental/) {
2030: (undef,undef,$title) =
2031: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2032: }
2033: } else {
2034: if ($folder=~/^supplemental/) {
2035: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2036: $env{'user.domain'}.'___&&&___'.$title;
2037: }
2038: }
2039:
2040: # For uploaded files (excluding pages/sequences) path in copied file is changed
2041: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2042: # courses.
2043:
2044: unless ($is_map{$suffix}) {
2045: my $newidx;
2046: # Now insert the URL at the bottom
2047: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2048: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2049: my $relpath = $1;
2050: if ($relpath ne '') {
2051: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2052: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2053: my $newprefix = $newloc;
2054: if ($newloc eq 'default') {
2055: $newprefix = 'docs';
2056: }
2057: if ($newdocsdir eq '') {
2058: $newdocsdir = 'default';
2059: }
2060: if (($prefixchg{$suffix}) ||
2061: ($srcdom{$suffix} ne $coursedom) ||
2062: ($srcnum{$suffix} ne $coursenum) ||
2063: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2064: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2065: $url =
2066: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2067: &Apache::lonnet::getfile($oldurl));
2068: if ($url eq '/adm/notfound.html') {
2069: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2070: next;
2071: } else {
2072: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2073: $newsubpath =~ s{/+$}{/};
2074: $docmoves{$oldurl} = $newsubpath;
2075: }
2076: }
2077: }
2078: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2079: my $template = $1;
2080: if ($newidx) {
2081: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2082: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2083: }
2084: } elsif ($url =~ /ext\.tool$/) {
2085: if (($newidx) && ($folder=~/^default/)) {
2086: my $marker = (split(m{/},$url))[4];
2087: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2088: my $val = 'no';
2089: if ($toolsettings{'gradable'}) {
2090: $val = 'yes';
2091: }
2092: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2093: 'string_yesno');
2094: &remember_parms($newidx,'gradable','set',$val);
2095: }
2096: }
2097: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2098: ':'.$ext.':normal:res';
2099: push(@LONCAPA::map::order,$newidx);
2100: # Store the result
2101: my ($errtext,$fatal) =
2102: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2103: if ($fatal) {
2104: $save_err .= $errtext;
2105: $allresult = 'fail';
2106: }
2107: }
2108:
2109: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2110: # resourcedata for simpleproblems copied from another course
2111: unless ($allresult eq 'fail') {
2112: my %updated = (
2113: rewrites => \%rewrites,
2114: zombies => \%zombies,
2115: removefrommap => \%removefrommap,
2116: removeparam => \%removeparam,
2117: dbcopies => \%dbcopies,
2118: resdatacopy => \%resdatacopy,
2119: retitles => \%retitles,
2120: );
2121: my %info = (
2122: newsubdir => \%newsubdir,
2123: params => \%params,
2124: );
2125: if ($prefixchg{$suffix}) {
2126: $info{'before'} = $before{$prefixchg{$suffix}};
2127: $info{'after'} = $after{$prefixchg{$suffix}};
2128: }
2129: my %moves = (
2130: copies => \%copies,
2131: docmoves => \%docmoves,
2132: mapmoves => \%mapmoves,
2133: );
2134: (my $result,$msgs{$suffix},my $lockerror) =
2135: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2136: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2137: $url,'paste');
2138: $lockerrors .= $lockerror;
2139: if ($result eq 'ok') {
2140: if ($is_map{$suffix}) {
2141: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2142: $folder.'.'.$container);
2143: if ($fatal) {
2144: $allresult = 'failread';
2145: } else {
2146: if ($#LONCAPA::map::order<1) {
2147: my $idx=&LONCAPA::map::getresidx();
2148: if ($idx<=0) { $idx=1; }
2149: $LONCAPA::map::order[0]=$idx;
2150: $LONCAPA::map::resources[$idx]='';
2151: }
2152: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2153: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2154: ':'.$ext.':normal:res';
2155: push(@LONCAPA::map::order,$newidx);
2156:
2157: # Store the result
2158: my ($errtext,$fatal) =
2159: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2160: if ($fatal) {
2161: $save_err .= $errtext;
2162: $allresult = 'failstore';
2163: }
2164: }
2165: }
2166: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2167: push(@toclear,$suffix);
2168: }
2169: }
2170: }
2171: }
2172: &clear_from_buffer(\@toclear,\@currpaste);
2173: my $msgsarray;
2174: foreach my $suffix (keys(%msgs)) {
2175: if (ref($msgs{$suffix}) eq 'ARRAY') {
2176: $msgsarray .= join(',',@{$msgs{$suffix}});
2177: }
2178: }
2179: return ($allresult,$save_err,$msgsarray,$lockerrors);
2180: }
2181:
2182: sub do_buffer_empty {
2183: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2184: if (@currpaste == 0) {
2185: return &mt('Clipboard is already empty');
2186: }
2187: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2188: if (@toclear == 0) {
2189: return &mt('Nothing selected to clear from clipboard');
2190: }
2191: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2192: if ($numdel) {
2193: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2194: } else {
2195: return &mt('Clipboard unchanged');
2196: }
2197: return;
2198: }
2199:
2200: sub clear_from_buffer {
2201: my ($toclear,$currpaste) = @_;
2202: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2203: my %pastebuffer;
2204: map { $pastebuffer{$_} = 1; } @{$currpaste};
2205: my $numdel = 0;
2206: foreach my $suffix (@{$toclear}) {
2207: next if ($suffix =~ /\D/);
2208: next unless (exists($pastebuffer{$suffix}));
2209: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2210: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2211: delete($pastebuffer{$suffix});
2212: $numdel ++;
2213: }
2214: }
2215: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2216: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2217: return $numdel;
2218: }
2219:
2220: sub get_newmap_url {
2221: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2222: $titleref,$allmaps,$newurls) = @_;
2223: my $newurl;
2224: if ($url=~ m{^/uploaded/}) {
2225: $$titleref=&mt('Copy of').' '.$$titleref;
2226: }
2227: my $now = time;
2228: my $suffix=$$.int(rand(100)).$now;
2229: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2230: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2231: my $path = $1;
2232: my $prefix = $2;
2233: my $ancestor = $3;
2234: if (length($ancestor) > 10) {
2235: $ancestor = substr($ancestor,-10,10);
2236: }
2237: my $newid;
2238: if ($prefixchg) {
2239: if ($folder =~ /^supplemental/) {
2240: $prefix =~ s/^default/supplemental/;
2241: } else {
2242: $prefix =~ s/^supplemental/default/;
2243: }
2244: }
2245: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2246: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2247: } else {
2248: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2249: }
2250: my $counter = 0;
2251: my $is_unique = &uniqueness_check($newurl);
2252: if ($folder =~ /^default/) {
2253: if ($allmaps->{$newurl}) {
2254: $is_unique = 0;
2255: }
2256: }
2257: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2258: $counter ++;
2259: $suffix ++;
2260: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2261: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2262: } else {
2263: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2264: }
2265: $is_unique = &uniqueness_check($newurl);
2266: }
2267: if ($is_unique) {
2268: $newurls->{$newurl} = 1;
2269: } else {
2270: if ($url=~/\.page$/) {
2271: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2272: } else {
2273: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2274: }
2275: }
2276: }
2277: return ($newurl);
2278: }
2279:
2280: sub dbcopy {
2281: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2282: my ($url,$result,$errtext);
2283: if (ref($dbref) eq 'HASH') {
2284: $url = $dbref->{'src'};
2285: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
2286: my $prefix = $1;
2287: if ($prefix eq 'ext.tool') {
2288: $prefix = 'exttool';
2289: }
2290: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2291: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2292: my $db_name;
2293: my $marker = (split(m{/},$url))[4];
2294: $marker=~s/\D//g;
2295: if ($dbref->{'src'} =~ m{/smppg$}) {
2296: $db_name =
2297: &Apache::lonsimplepage::get_db_name($url,$marker,
2298: $dbref->{'cdom'},
2299: $dbref->{'cnum'});
2300: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2301: $db_name = 'exttool_'.$marker;
2302: } else {
2303: $db_name = 'bulletinpage_'.$marker;
2304: }
2305: my ($suffix,$freedlock,$error) =
2306: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2307: $coursedom,$coursenum,
2308: 'concat');
2309: if (!$suffix) {
2310: if ($prefix eq 'smppg') {
2311: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2312: } elsif ($prefix eq 'exttool') {
2313: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
2314: } else {
2315: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
2316: }
2317: if ($error) {
2318: $errtext .= '<br />'.$error;
2319: }
2320: } else {
2321: #need to copy the db contents to a new one.
2322: my %contents=&Apache::lonnet::dump($db_name,
2323: $dbref->{'cdom'},
2324: $dbref->{'cnum'});
2325: if (exists($contents{'uploaded.photourl'})) {
2326: my $photo = $contents{'uploaded.photourl'};
2327: my ($subdir,$fname) =
2328: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2329: my $newphoto;
2330: if ($fname ne '') {
2331: my $content = &Apache::lonnet::getfile($photo);
2332: unless ($content eq '-1') {
2333: $env{'form.'.$suffix.'.photourl'} = $content;
2334: $newphoto =
2335: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2336: delete($env{'form.'.$suffix.'.photourl'});
2337: }
2338: }
2339: if ($newphoto =~ m{^/uploaded/}) {
2340: $contents{'uploaded.photourl'} = $newphoto;
2341: }
2342: }
2343: $db_name =~ s{_\d*$ }{_$suffix}x;
2344: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2345: delete($contents{'gradable'});
2346: }
2347: $result=&Apache::lonnet::put($db_name,\%contents,
2348: $coursedom,$coursenum);
2349: if ($result eq 'ok') {
2350: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
2351: }
2352: }
2353: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2354: $lockerrorsref->{$prefix} =
2355: '<div class="LC_error">'.
2356: &mt('There was a problem removing a lockfile.');
2357: if ($prefix eq 'smppg') {
2358: $lockerrorsref->{$prefix} .=
2359: ' '.&mt('This will prevent creation of additional simple pages in this course.');
2360: } elsif ($prefix eq 'exttool') {
2361: $lockerrorsref->{$prefix} .=
2362: ' '.&mt('This will prevent addition of more external tools to this course.');
2363: } else {
2364: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
2365: }
2366: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2367: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2368: '</div>';
2369: }
2370: }
2371: } elsif ($url =~ m{/syllabus$}) {
2372: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2373: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2374: if (($dbref->{'cdom'} ne $coursedom) ||
2375: ($dbref->{'cnum'} ne $coursenum)) {
2376: my %contents=&Apache::lonnet::dump('syllabus',
2377: $dbref->{'cdom'},
2378: $dbref->{'cnum'});
2379: $result=&Apache::lonnet::put('syllabus',\%contents,
2380: $coursedom,$coursenum);
2381: }
2382: }
2383: }
2384: }
2385: return ($url,$result,$errtext);
2386: }
2387:
2388: sub copy_templated_files {
2389: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2390: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2391: my $srccontainer = 'sequence';
2392: if ($srcwaspage) {
2393: $srccontainer = 'page';
2394: }
2395: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2396: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2397: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2398: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2399: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2400: $template.'.problem';
2401: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2402: if ($template eq 'simpleproblem') {
2403: $srcprefix .= '.0.';
2404: my $weightprefix = $newprefix;
2405: $newprefix .= '.0.';
2406: my @simpleprobqtypes = qw(radio option string essay numerical);
2407: my $qtype=$srcparms{$srcprefix.'questiontype'};
2408: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2409: my %newdata = (
2410: $newprefix.'questiontype' => $qtype,
2411: );
2412: foreach my $type (@simpleprobqtypes) {
2413: if ($type eq $qtype) {
2414: $newdata{"$weightprefix.$type.weight"}=1;
2415: } else {
2416: $newdata{"$weightprefix.$type.weight"}=0;
2417: }
2418: }
2419: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2420: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2421: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2422: if ($qtype eq 'numerical') {
2423: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2424: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2425: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2426: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2427: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2428: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2429: unless (defined($maxfoils)) { $maxfoils=10; }
2430: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2431: if ($maxfoils<=0) { $maxfoils=10; }
2432: my $randomize=$srcparms{$srcprefix.'randomize'};
2433: unless (defined($randomize)) { $randomize='yes'; }
2434: unless ($randomize eq 'no') { $randomize='yes'; }
2435: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2436: $newdata{$newprefix.'randomize'} = $randomize;
2437: if ($qtype eq 'option') {
2438: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2439: }
2440: for (my $i=1; $i<=10; $i++) {
2441: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2442: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2443: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2444: }
2445:
2446: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2447: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2448: unless (defined($maxfoils)) { $maxfoils=10; }
2449: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2450: if ($maxfoils<=0) { $maxfoils=10; }
2451: my $randomize=$srcparms{$srcprefix.'randomize'};
2452: unless (defined($randomize)) { $randomize='yes'; }
2453: unless ($randomize eq 'no') { $randomize='yes'; }
2454: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2455: $newdata{$newprefix.'randomize'} = $randomize;
2456: if ($qtype eq 'option') {
2457: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2458: }
2459: for (my $i=1; $i<=10; $i++) {
2460: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2461: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2462: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2463: }
2464: } elsif ($qtype eq 'string') {
2465: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2466: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2467: }
2468: if (keys(%newdata)) {
2469: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2470: $coursenum);
2471: if ($putres eq 'ok') {
2472: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2473: }
2474: }
2475: }
2476: }
2477: }
2478:
2479: sub uniqueness_check {
2480: my ($newurl) = @_;
2481: my $unique = 1;
2482: foreach my $res (@LONCAPA::map::order) {
2483: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2484: $url=&LONCAPA::map::qtescape($url);
2485: if ($newurl eq $url) {
2486: $unique = 0;
2487: last;
2488: }
2489: }
2490: return $unique;
2491: }
2492:
2493: sub contained_map_check {
2494: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2495: $hierarchy,$titles,$allmaps) = @_;
2496: my $content = &Apache::lonnet::getfile($url);
2497: unless ($content eq '-1') {
2498: my $parser = HTML::TokeParser->new(\$content);
2499: $parser->attr_encoded(1);
2500: while (my $token = $parser->get_token) {
2501: next if ($token->[0] ne 'S');
2502: if ($token->[1] eq 'resource') {
2503: next if ($token->[2]->{'type'} eq 'zombie');
2504: my $ressrc = $token->[2]->{'src'};
2505: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2506: my $srcdom = $1;
2507: unless ($srcdom eq $coursedom) {
2508: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2509: next;
2510: }
2511: } elsif ($folder =~ /^supplemental/) {
2512: unless (&supp_pasteable($ressrc)) {
2513: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2514: next;
2515: }
2516: }
2517: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2518: if ($1 eq 'uploaded') {
2519: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2520: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2521: } else {
2522: if ($allmaps->{$ressrc}) {
2523: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2524: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2525: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2526: } else {
2527: $addedmaps->{$ressrc} = [$url];
2528: }
2529: }
2530: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2531: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
2532: }
2533: } elsif ($token->[1] eq 'param') {
2534: if ($folder =~ /^supplemental/) {
2535: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2536: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2537: } else {
2538: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2539: }
2540: }
2541: }
2542: }
2543: }
2544: return;
2545: }
2546:
2547: sub url_paste_fixups {
2548: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2549: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
2550: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
2551: my $checktitle;
2552: if (($prefixchg) &&
2553: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2554: $checktitle = 1;
2555: }
2556: my $skip;
2557: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2558: my $mapid = $1.$2;
2559: if ($tomove->{$mapid}) {
2560: $skip = 1;
2561: }
2562: }
2563: my $file = &Apache::lonnet::getfile($oldurl);
2564: return if ($file eq '-1');
2565: my $parser = HTML::TokeParser->new(\$file);
2566: $parser->attr_encoded(1);
2567: my $changed = 0;
2568: while (my $token = $parser->get_token) {
2569: next if ($token->[0] ne 'S');
2570: if ($token->[1] eq 'resource') {
2571: my $ressrc = $token->[2]->{'src'};
2572: next if ($ressrc eq '');
2573: my $id = $token->[2]->{'id'};
2574: my $title = $token->[2]->{'title'};
2575: if ($checktitle) {
2576: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2577: $retitles->{$oldurl}{$id} = $ressrc;
2578: }
2579: }
2580: next if ($token->[2]->{'type'} eq 'external');
2581: if ($token->[2]->{'type'} eq 'zombie') {
2582: next if ($skip);
2583: $zombies->{$oldurl}{$id} = $ressrc;
2584: $changed = 1;
2585: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2586: my $srcdom = $1;
2587: my $srcnum = $2;
2588: my $rem = $3;
2589: my $newurl;
2590: my $mapname;
2591: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2592: my $prefix = $1;
2593: $mapname = $prefix.$2;
2594: if ($tomove->{$mapname}) {
2595: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2596: $srcdom,$srcnum,$allmaps,$rewrites,
2597: $retitles,$copies,$dbcopies,$zombies,
2598: $params,$mapmoves,$mapchanges,$tomove,
2599: $newsubdir,$newurls,$resdatacopy);
2600: next;
2601: } else {
2602: ($newurl,my $error) =
2603: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2604: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2605: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2606: $newsubdir->{$ressrc} = $1;
2607: }
2608: if ($error) {
2609: next;
2610: }
2611: }
2612: }
2613: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2614: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2615:
2616: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2617: $rewrites->{$oldurl}{$id} = $ressrc;
2618: $mapchanges->{$ressrc} = 1;
2619: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2620: $cnum,$srcdom,$srcnum,$allmaps,
2621: $rewrites,$retitles,$copies,$dbcopies,
2622: $zombies,$params,$mapmoves,$mapchanges,
2623: $tomove,$newsubdir,$newurls,$resdatacopy)) {
2624: $mapmoves->{$ressrc} = 1;
2625: }
2626: $changed = 1;
2627: } else {
2628: $rewrites->{$oldurl}{$id} = $ressrc;
2629: $copies->{$oldurl}{$ressrc} = $id;
2630: $changed = 1;
2631: }
2632: }
2633: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
2634: next if ($skip);
2635: my $srcdom = $1;
2636: my $srcnum = $2;
2637: my $rem = $3;
2638: my ($is_exttool,$exttoolchg);
2639: if ($rem =~ m{\d+/ext\.tool$}) {
2640: $is_exttool = 1;
2641: }
2642: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2643: $rewrites->{$oldurl}{$id} = $ressrc;
2644: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2645: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2646: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2647: $changed = 1;
2648: if ($is_exttool) {
2649: $exttoolchg = 1;
2650: }
2651: } elsif (($rem =~ m{\d+/ext\.tool$}) &&
2652: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2653: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2654: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2655: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2656: $changed = 1;
2657: $exttoolchg = 1;
2658: }
2659: if (($is_exttool) && ($prefixchg)) {
2660: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2661: if ($exttoolchg) {
2662: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2663: }
2664: }
2665: }
2666: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2667: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2668: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2669: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2670: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2671: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
2672: $changed = 1;
2673: }
2674: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2675: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2676: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2677: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2678: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2679: }
2680: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2681: next if ($skip);
2682: my $srcdom = $1;
2683: my $srcnum = $2;
2684: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2685: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2686: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2687: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2688: $changed = 1;
2689: }
2690: }
2691: } elsif ($token->[1] eq 'param') {
2692: next if ($skip);
2693: my $to = $token->[2]->{'to'};
2694: if ($to ne '') {
2695: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2696: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2697: } else {
2698: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2699: }
2700: }
2701: }
2702: }
2703: return $changed;
2704: }
2705:
2706: sub apply_fixups {
2707: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2708: $oldurl,$url,$caller) = @_;
2709: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
2710: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
2711: %resdatacopy,%lockerrors,$lockmsg);
2712: if (ref($updated) eq 'HASH') {
2713: if (ref($updated->{'rewrites'}) eq 'HASH') {
2714: %rewrites = %{$updated->{'rewrites'}};
2715: }
2716: if (ref($updated->{'zombies'}) eq 'HASH') {
2717: %zombies = %{$updated->{'zombies'}};
2718: }
2719: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2720: %removefrommap = %{$updated->{'removefrommap'}};
2721: }
2722: if (ref($updated->{'removeparam'}) eq 'HASH') {
2723: %removeparam = %{$updated->{'removeparam'}};
2724: }
2725: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2726: %dbcopies = %{$updated->{'dbcopies'}};
2727: }
2728: if (ref($updated->{'retitles'}) eq 'HASH') {
2729: %retitles = %{$updated->{'retitles'}};
2730: }
2731: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2732: %resdatacopy = %{$updated->{'resdatacopy'}};
2733: }
2734: }
2735: if (ref($info) eq 'HASH') {
2736: if (ref($info->{'newsubdir'}) eq 'HASH') {
2737: %newsubdir = %{$info->{'newsubdir'}};
2738: }
2739: if (ref($info->{'params'}) eq 'HASH') {
2740: %params = %{$info->{'params'}};
2741: }
2742: if (ref($info->{'before'}) eq 'HASH') {
2743: %before = %{$info->{'before'}};
2744: }
2745: if (ref($info->{'after'}) eq 'HASH') {
2746: %after = %{$info->{'after'}};
2747: }
2748: }
2749: if (ref($moves) eq 'HASH') {
2750: if (ref($moves->{'copies'}) eq 'HASH') {
2751: %copies = %{$moves->{'copies'}};
2752: }
2753: if (ref($moves->{'docmoves'}) eq 'HASH') {
2754: %docmoves = %{$moves->{'docmoves'}};
2755: }
2756: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2757: %mapmoves = %{$moves->{'mapmoves'}};
2758: }
2759: }
2760: foreach my $key (keys(%copies),keys(%docmoves)) {
2761: my @allcopies;
2762: if (exists($copies{$key})) {
2763: if (ref($copies{$key}) eq 'HASH') {
2764: my %added;
2765: foreach my $innerkey (keys(%{$copies{$key}})) {
2766: if (($innerkey ne '') && (!$added{$innerkey})) {
2767: push(@allcopies,$innerkey);
2768: $added{$innerkey} = 1;
2769: }
2770: }
2771: undef(%added);
2772: }
2773: }
2774: if ($key eq $oldurl) {
2775: if ((exists($docmoves{$key}))) {
2776: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
2777: push(@allcopies,$oldurl);
2778: }
2779: }
2780: }
2781: if (@allcopies > 0) {
2782: foreach my $item (@allcopies) {
2783: my ($relpath,$oldsubdir,$fname) =
2784: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2785: if ($fname ne '') {
2786: my $content = &Apache::lonnet::getfile($item);
2787: unless ($content eq '-1') {
2788: my $storefn;
2789: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2790: $storefn = $docmoves{$key};
2791: } else {
2792: $storefn = $relpath;
2793: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
2794: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2795: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
2796: }
2797: if ($newsubdir{$key}) {
2798: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
2799: }
2800: }
2801: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2802: my $copyurl =
2803: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2804: $storefn.$fname,$content);
2805: if ($copyurl eq '/adm/notfound.html') {
2806: if (exists($docmoves{$oldurl})) {
2807: return &mt('Paste failed: an error occurred copying the file.');
2808: } elsif (ref($errors) eq 'HASH') {
2809: $errors->{$item} = 1;
2810: }
2811: }
2812: }
2813: }
2814: }
2815: }
2816: }
2817: foreach my $key (keys(%mapmoves)) {
2818: my $storefn=$key;
2819: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2820: if ($prefixchg && $before{'map'} && $after{'map'}) {
2821: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2822: }
2823: if ($newsubdir{$key}) {
2824: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2825: }
2826: my $mapcontent = &Apache::lonnet::getfile($key);
2827: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
2828: ($after{'map'} eq 'default') &&
2829: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
2830: $mapcontent = '<map>'."\n".
2831: '<resource id="1" src="" type="start" />'."\n".
2832: '<link from="1" to="2" index="1" />'."\n".
2833: '<resource id="2" src="" type="finish" />'."\n".
2834: '</map>';
2835: }
2836: if ($mapcontent eq '-1') {
2837: if (ref($errors) eq 'HASH') {
2838: $errors->{$key} = 1;
2839: }
2840: } else {
2841: my $newmap =
2842: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2843: $mapcontent);
2844: if ($newmap eq '/adm/notfound.html') {
2845: if (ref($errors) eq 'HASH') {
2846: $errors->{$key} = 1;
2847: }
2848: }
2849: }
2850: }
2851: my %updates;
2852: if ($is_map) {
2853: if (ref($updated) eq 'HASH') {
2854: foreach my $type (keys(%{$updated})) {
2855: if (ref($updated->{$type}) eq 'HASH') {
2856: foreach my $key (keys(%{$updated->{$type}})) {
2857: $updates{$key} = 1;
2858: }
2859: }
2860: }
2861: }
2862: foreach my $key (keys(%updates)) {
2863: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
2864: if (ref($rewrites{$key}) eq 'HASH') {
2865: %torewrite = %{$rewrites{$key}};
2866: }
2867: if (ref($retitles{$key}) eq 'HASH') {
2868: %toretitle = %{$retitles{$key}};
2869: }
2870: if (ref($removefrommap{$key}) eq 'HASH') {
2871: %toremove = %{$removefrommap{$key}};
2872: }
2873: if (ref($removeparam{$key}) eq 'HASH') {
2874: %remparam = %{$removeparam{$key}};
2875: }
2876: if (ref($zombies{$key}) eq 'HASH') {
2877: %zombie = %{$zombies{$key}};
2878: }
2879: if (ref($dbcopies{$key}) eq 'HASH') {
2880: foreach my $idx (keys(%{$dbcopies{$key}})) {
2881: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2882: my ($newurl,$result,$errtext) =
2883: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2884: if ($result eq 'ok') {
2885: $newdb{$idx} = $newurl;
2886: } elsif (ref($errors) eq 'HASH') {
2887: $errors->{$key} = 1;
2888: }
2889: push(@msgs,$errtext);
2890: }
2891: }
2892: }
2893: if (ref($resdatacopy{$key}) eq 'HASH') {
2894: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2895: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2896: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2897: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2898: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2899: my $template = $1;
2900: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2901: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2902: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2903: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2904: unless ($gotnewmapname) {
2905: ($newmapname) = ($key =~ m{/([^/]+)$});
2906: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2907: if ($newsubdir{$key}) {
2908: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2909: }
2910: $gotnewmapname = 1;
2911: }
2912: my $srcmapinfo = $srcfolder.':'.$idx;
2913: if ($srccontainer eq 'page') {
2914: $srcmapinfo .= ':1';
2915: }
2916: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2917: $cnum,$template,$idx,$newmapname);
2918: }
2919: }
2920: }
2921: }
2922: }
2923: if (ref($params{$key}) eq 'HASH') {
2924: %currparam = %{$params{$key}};
2925: }
2926: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2927: if ($fatal) {
2928: return ($errtext);
2929: }
2930: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2931: if (defined($LONCAPA::map::zombies[$i])) {
2932: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
2933: if ($zombie{$i} eq $src) {
2934: undef($LONCAPA::map::zombies[$i]);
2935: }
2936: }
2937: }
2938: my $total = scalar(@LONCAPA::map::order) - 1;
2939: for (my $i=$total; $i>=0; $i--) {
2940: my $idx = $LONCAPA::map::order[$i];
2941: if (defined($LONCAPA::map::resources[$idx])) {
2942: my $changed;
2943: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
2944: if ((exists($toremove{$idx})) &&
2945: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
2946: splice(@LONCAPA::map::order,$i,1);
2947: if (ref($currparam{$idx}) eq 'ARRAY') {
2948: foreach my $name (@{$currparam{$idx}}) {
2949: &LONCAPA::map::delparameter($idx,$name);
2950: }
2951: }
2952: next;
2953: }
2954: my $origsrc = $src;
2955: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
2956: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2957: $changed = 1;
2958: }
2959: }
2960: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
2961: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2962: if ($origsrc =~ m{^/uploaded/}) {
2963: if ($prefixchg && $before{'map'} && $after{'map'}) {
2964: if ($src =~ /\.(page|sequence)$/) {
2965: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
2966: } else {
2967: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
2968: }
2969: }
2970: if ($origsrc =~ /\.(page|sequence)$/) {
2971: if ($newsubdir{$origsrc}) {
2972: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
2973: }
2974: } elsif ($newsubdir{$key}) {
2975: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
2976: }
2977: }
2978: $changed = 1;
2979: } elsif ($newdb{$idx} ne '') {
2980: $src = $newdb{$idx};
2981: $changed = 1;
2982: }
2983: if ($changed) {
2984: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
2985: }
2986: }
2987: }
2988: foreach my $idx (keys(%remparam)) {
2989: if (ref($remparam{$idx}) eq 'ARRAY') {
2990: foreach my $name (@{$remparam{$idx}}) {
2991: &LONCAPA::map::delparameter($idx,$name);
2992: }
2993: }
2994: }
2995: if (values(%lockerrors) > 0) {
2996: $lockmsg = join('<br />',values(%lockerrors));
2997: }
2998: my $storefn;
2999: if ($key eq $oldurl) {
3000: $storefn = $url;
3001: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3002: } else {
3003: $storefn = $key;
3004: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3005: if ($prefixchg && $before{'map'} && $after{'map'}) {
3006: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
3007: }
3008: if ($newsubdir{$key}) {
3009: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
3010: }
3011: }
3012: my $report;
3013: if ($folder !~ /^supplemental/) {
3014: $report = 1;
3015: }
3016: (my $outtext,$errtext) =
3017: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3018: if ($errtext) {
3019: if ($caller eq 'paste') {
3020: return (&mt('Paste failed: an error occurred saving the folder or page.'));
3021: }
3022: }
3023: }
3024: }
3025: return ('ok',\@msgs,$lockmsg);
3026: }
3027:
3028: sub copy_dependencies {
3029: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3030: my $content;
3031: if (ref($contentref)) {
3032: $content = $$contentref;
3033: } else {
3034: $content = &Apache::lonnet::getfile($item);
3035: }
3036: unless ($content eq '-1') {
3037: my $mm = new File::MMagic;
3038: my $mimetype = $mm->checktype_contents($content);
3039: if ($mimetype eq 'text/html') {
3040: my (%allfiles,%codebase,$state);
3041: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3042: if ($res eq 'ok') {
3043: my ($numexisting,$numpathchanges,$existing);
3044: (undef,$numexisting,$numpathchanges,$existing) =
3045: &Apache::loncommon::ask_for_embedded_content(
3046: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3047: {'error_on_invalid_names' => 1,
3048: 'ignore_remote_references' => 1,
3049: 'docs_url' => $item,
3050: 'context' => 'paste'});
3051: if ($numexisting > 0) {
3052: if (ref($existing) eq 'HASH') {
3053: foreach my $dep (keys(%{$existing})) {
3054: my $depfile = $dep;
3055: unless ($depfile =~ m{^\Q$relpath\E}) {
3056: $depfile = $relpath.$dep;
3057: }
3058: my $depcontent = &Apache::lonnet::getfile($depfile);
3059: unless ($depcontent eq '-1') {
3060: my $storedep = $dep;
3061: $storedep =~ s{^\Q$relpath\E}{};
3062: my $dep_url =
3063: &Apache::lonclonecourse::writefile(
3064: $env{'request.course.id'},
3065: $storefn.$storedep,$depcontent);
3066: if ($dep_url eq '/adm/notfound.html') {
3067: if (ref($errors) eq 'HASH') {
3068: $errors->{$depfile} = 1;
3069: }
3070: } else {
3071: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3072: }
3073: }
3074: }
3075: }
3076: }
3077: }
3078: }
3079: }
3080: return;
3081: }
3082:
3083: my %parameter_type = ( 'randompick' => 'int_pos',
3084: 'hiddenresource' => 'string_yesno',
3085: 'encrypturl' => 'string_yesno',
3086: 'randomorder' => 'string_yesno',);
3087: my $valid_parameters_re = join('|',keys(%parameter_type));
3088: # set parameters
3089: sub update_parameter {
3090: if ($env{'form.changeparms'} eq 'all') {
3091: my (@allidx,@allmapidx,%allchecked,%currchecked);
3092: %allchecked = (
3093: 'hiddenresource' => {},
3094: 'encrypturl' => {},
3095: 'randompick' => {},
3096: 'randomorder' => {},
3097: );
3098: foreach my $which (keys(%allchecked)) {
3099: $env{'form.all'.$which} =~ s/,$//;
3100: if ($which eq 'randompick') {
3101: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3102: my ($res,$value) = split(/:/,$item);
3103: if ($value =~ /^\d+$/) {
3104: $allchecked{$which}{$res} = $value;
3105: }
3106: }
3107: } else {
3108: if ($env{'form.all'.$which}) {
3109: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3110: }
3111: }
3112: }
3113: my $haschanges = 0;
3114: foreach my $res (@LONCAPA::map::order) {
3115: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3116: $name=&LONCAPA::map::qtescape($name);
3117: $url=&LONCAPA::map::qtescape($url);
3118: next unless $url;
3119: my $is_map;
3120: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3121: $is_map = 1;
3122: }
3123: foreach my $which (keys(%allchecked)) {
3124: if (($which eq 'randompick' || $which eq 'randomorder')) {
3125: next if (!$is_map);
3126: }
3127: my $oldvalue = 0;
3128: my $newvalue = 0;
3129: if ($allchecked{$which}{$res}) {
3130: $newvalue = $allchecked{$which}{$res};
3131: }
3132: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3133: if ($which eq 'randompick') {
3134: if ($current =~ /^(\d+)$/) {
3135: $oldvalue = $1;
3136: }
3137: } else {
3138: if ($current =~ /^yes$/i) {
3139: $oldvalue = 1;
3140: }
3141: }
3142: if ($oldvalue ne $newvalue) {
3143: $haschanges = 1;
3144: if ($newvalue) {
3145: my $storeval = 'yes';
3146: if ($which eq 'randompick') {
3147: $storeval = $newvalue;
3148: }
3149: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3150: $storeval,
3151: $parameter_type{$which});
3152: &remember_parms($res,$which,'set',$storeval);
3153: } elsif ($oldvalue) {
3154: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3155: &remember_parms($res,$which,'del');
3156: }
3157: }
3158: }
3159: }
3160: return $haschanges;
3161: } else {
3162: my $haschanges = 0;
3163: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
3164:
3165: my $which = $env{'form.changeparms'};
3166: my $idx = $env{'form.setparms'};
3167: my $oldvalue = 0;
3168: my $newvalue = 0;
3169: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3170: if ($which eq 'randompick') {
3171: if ($current =~ /^(\d+)$/) {
3172: $oldvalue = $1;
3173: }
3174: } elsif ($current =~ /^yes$/i) {
3175: $oldvalue = 1;
3176: }
3177: if ($env{'form.'.$which.'_'.$idx}) {
3178: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3179: : 1;
3180: }
3181: if ($oldvalue ne $newvalue) {
3182: $haschanges = 1;
3183: if ($newvalue) {
3184: my $storeval = 'yes';
3185: if ($which eq 'randompick') {
3186: $storeval = $newvalue;
3187: }
3188: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3189: $parameter_type{$which});
3190: &remember_parms($idx,$which,'set',$storeval);
3191: } else {
3192: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3193: &remember_parms($idx,$which,'del');
3194: }
3195: }
3196: return $haschanges;
3197: }
3198: }
3199:
3200: sub handle_edit_cmd {
3201: my ($coursenum,$coursedom) =@_;
3202: my $haschanges = 0;
3203: if ($env{'form.cmd'} eq '') {
3204: return $haschanges;
3205: }
3206: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3207:
3208: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3209: my ($title, $url, @rrest) = split(':', $ratstr);
3210:
3211: if ($cmd eq 'remove') {
3212: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3213: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3214: &Apache::lonnet::removeuploadedurl($url);
3215: } else {
3216: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3217: }
3218: splice(@LONCAPA::map::order, $idx, 1);
3219: $haschanges = 1;
3220: } elsif ($cmd eq 'cut') {
3221: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3222: splice(@LONCAPA::map::order, $idx, 1);
3223: $haschanges = 1;
3224: } elsif ($cmd eq 'up'
3225: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3226: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3227: $haschanges = 1;
3228: } elsif ($cmd eq 'down'
3229: && defined($LONCAPA::map::order[$idx+1])) {
3230: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3231: $haschanges = 1;
3232: } elsif ($cmd eq 'rename') {
3233: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3234: if ($comment=~/\S/) {
3235: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3236: $comment.':'.join(':', $url, @rrest);
3237: }
3238: # Devalidate title cache
3239: my $renamed_url=&LONCAPA::map::qtescape($url);
3240: &Apache::lonnet::devalidate_title_cache($renamed_url);
3241: $haschanges = 1;
3242: } elsif ($cmd eq 'setalias') {
3243: my $newvalue = $env{'form.alias'};
3244: if ($newvalue ne '') {
3245: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3246: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3247: 'string');
3248: &remember_parms($idx,'mapalias','set',$newvalue);
3249: $haschanges = 1;
3250: }
3251: }
3252: } elsif ($cmd eq 'delalias') {
3253: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3254: if ($current ne '') {
3255: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3256: &remember_parms($idx,'mapalias','del');
3257: $haschanges = 1;
3258: }
3259: }
3260: return $haschanges;
3261: }
3262:
3263: sub editor {
3264: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
3265: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3266: $canedit,$hostname,$navmapref,$hiddentop)=@_;
3267: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3268: if ($allowed) {
3269: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3270: $is_random_order,$container) =
3271: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3272: $r->print($breadcrumbtrail);
3273: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3274: $container = 'page';
3275: } else {
3276: $container = 'sequence';
3277: }
3278:
3279: my $jumpto;
3280:
3281: unless ($supplementalflag) {
3282: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
3283: }
3284:
3285: unless ($allowed) {
3286: $randompick = -1;
3287: }
3288:
3289: my ($errtext,$fatal);
3290: if (($folder eq '') && (!$supplementalflag)) {
3291: if (@LONCAPA::map::order) {
3292: undef(@LONCAPA::map::order);
3293: undef(@LONCAPA::map::resources);
3294: undef(@LONCAPA::map::resparms);
3295: undef(@LONCAPA::map::zombies);
3296: }
3297: $folder = 'default';
3298: $container = 'sequence';
3299: } else {
3300: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3301: $folder.'.'.$container);
3302: return $errtext if ($fatal);
3303: }
3304:
3305: if ($#LONCAPA::map::order<1) {
3306: my $idx=&LONCAPA::map::getresidx();
3307: if ($idx<=0) { $idx=1; }
3308: $LONCAPA::map::order[0]=$idx;
3309: $LONCAPA::map::resources[$idx]='';
3310: }
3311:
3312: # ------------------------------------------------------------ Process commands
3313:
3314: # ---------------- if they are for this folder and user allowed to make changes
3315: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
3316: # set parameters and change order
3317: &snapshotbefore();
3318:
3319: if (&update_parameter()) {
3320: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3321: return $errtext if ($fatal);
3322: }
3323:
3324: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3325: # change order
3326: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3327: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3328:
3329: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3330: return $errtext if ($fatal);
3331: }
3332:
3333: if ($env{'form.pastemarked'}) {
3334: my %paste_errors;
3335: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
3336: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3337: \%paste_errors);
3338: if (ref($pastemsgarray) eq 'ARRAY') {
3339: if (@{$pastemsgarray} > 0) {
3340: $r->print('<p class="LC_info">'.
3341: join('<br />',@{$pastemsgarray}).
3342: '</p>');
3343: }
3344: }
3345: if ($lockerror) {
3346: $r->print('<p class="LC_error">'.
3347: $lockerror.
3348: '</p>');
3349: }
3350: if ($save_error ne '') {
3351: return $save_error;
3352: }
3353: if ($paste_res) {
3354: my %errortext = &Apache::lonlocal::texthash (
3355: fail => 'Storage of folder contents failed',
3356: failread => 'Reading folder contents failed',
3357: failstore => 'Storage of folder contents failed',
3358: );
3359: if ($errortext{$paste_res}) {
3360: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
3361: }
3362: }
3363: if (keys(%paste_errors) > 0) {
3364: $r->print('<p class="LC_warning">'."\n".
3365: &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".
3366: '<ul>'."\n");
3367: foreach my $key (sort(keys(%paste_errors))) {
3368: $r->print('<li>'.$key.'</li>'."\n");
3369: }
3370: $r->print('</ul></p>'."\n");
3371: }
3372: } elsif ($env{'form.clearmarked'}) {
3373: my $output = &do_buffer_empty();
3374: if ($output) {
3375: $r->print('<p class="LC_info">'.$output.'</p>');
3376: }
3377: }
3378:
3379: $r->print($upload_output);
3380:
3381: # Rename, cut, copy or remove a single resource
3382: if (&handle_edit_cmd($coursenum,$coursedom)) {
3383: my $contentchg;
3384: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
3385: $contentchg = 1;
3386: }
3387: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
3388: return $errtext if ($fatal);
3389: }
3390:
3391: # Cut, copy and/or remove multiple resources
3392: if ($env{'form.multichange'}) {
3393: my %allchecked = (
3394: cut => {},
3395: remove => {},
3396: );
3397: my $needsupdate;
3398: foreach my $which (keys(%allchecked)) {
3399: $env{'form.multi'.$which} =~ s/,$//;
3400: if ($env{'form.multi'.$which}) {
3401: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3402: if (ref($allchecked{$which}) eq 'HASH') {
3403: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3404: }
3405: }
3406: }
3407: if ($needsupdate) {
3408: my $haschanges = 0;
3409: my %curr_groups = &Apache::longroup::coursegroups();
3410: my $total = scalar(@LONCAPA::map::order) - 1;
3411: for (my $i=$total; $i>=0; $i--) {
3412: my $res = $LONCAPA::map::order[$i];
3413: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3414: $name=&LONCAPA::map::qtescape($name);
3415: $url=&LONCAPA::map::qtescape($url);
3416: next unless $url;
3417: my %denied =
3418: &action_restrictions($coursenum,$coursedom,$url,
3419: $env{'form.folderpath'},\%curr_groups);
3420: foreach my $which (keys(%allchecked)) {
3421: next if ($denied{$which});
3422: next unless ($allchecked{$which}{$res});
3423: if ($which eq 'remove') {
3424: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3425: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3426: &Apache::lonnet::removeuploadedurl($url);
3427: } else {
3428: &LONCAPA::map::makezombie($res);
3429: }
3430: splice(@LONCAPA::map::order,$i,1);
3431: $haschanges ++;
3432: } elsif ($which eq 'cut') {
3433: &LONCAPA::map::makezombie($res);
3434: splice(@LONCAPA::map::order,$i,1);
3435: $haschanges ++;
3436: }
3437: }
3438: }
3439: if ($haschanges) {
3440: ($errtext,$fatal) =
3441: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3442: return $errtext if ($fatal);
3443: }
3444: }
3445: }
3446:
3447: # Group import/search
3448: if ($env{'form.importdetail'}) {
3449: my @imports;
3450: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3451: if (defined($item)) {
3452: my ($name,$url,$residx)=
3453: map { &unescape($_); } split(/\=/,$item);
3454: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3455: my ($suffix,$errortxt,$locknotfreed) =
3456: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
3457: if ($locknotfreed) {
3458: $r->print($locknotfreed);
3459: }
3460: if ($suffix) {
3461: $url =~ s/_new\./_$suffix./;
3462: } else {
3463: return $errortxt;
3464: }
3465: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3466: my $type = $1;
3467: my ($suffix,$errortxt,$locknotfreed) =
3468: &new_timebased_suffix($coursedom,$coursenum,$type);
3469: if ($locknotfreed) {
3470: $r->print($locknotfreed);
3471: }
3472: if ($suffix) {
3473: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3474: } else {
3475: return $errortxt;
3476: }
3477: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3478: my ($suffix,$errortxt,$locknotfreed) =
3479: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3480: if ($locknotfreed) {
3481: $r->print($locknotfreed);
3482: }
3483: if ($suffix) {
3484: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3485: } else {
3486: return $errortxt;
3487: }
3488: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3489: if ($supplementalflag) {
3490: next unless ($1 eq 'supplemental');
3491: if ($folder eq 'supplemental') {
3492: next unless ($2 eq 'default');
3493: } else {
3494: next unless ($folder eq 'supplemental_'.$2);
3495: }
3496: } else {
3497: next unless ($1 eq 'docs');
3498: if ($folder eq 'default') {
3499: next unless ($2 eq 'default');
3500: } else {
3501: next unless ($folder eq 'default_'.$2);
3502: }
3503: }
3504: }
3505: push(@imports, [$name, $url, $residx]);
3506: }
3507: }
3508: ($errtext,$fatal,my $fixuperrors) =
3509: &group_import($coursenum, $coursedom, $folder,$container,
3510: 'londocs',$ltitoolsref,@imports);
3511: return $errtext if ($fatal);
3512: if ($fixuperrors) {
3513: $r->print($fixuperrors);
3514: }
3515: }
3516: # Loading a complete map
3517: if ($env{'form.loadmap'}) {
3518: if ($env{'form.importmap'}=~/\w/) {
3519: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3520: my ($title,$url,$ext,$type)=split(/\:/,$res);
3521: my $idx=&LONCAPA::map::getresidx($url);
3522: $LONCAPA::map::resources[$idx]=$res;
3523: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3524: }
3525: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3526: $folder.'.'.$container,1);
3527: return $errtext if ($fatal);
3528: } else {
3529: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
3530:
3531: }
3532: }
3533: &log_differences($plain);
3534: }
3535: # ---------------------------------------------------------------- End commands
3536: # ---------------------------------------------------------------- Print screen
3537: my $idx=0;
3538: my $shown=0;
3539: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
3540: $r->print('<div class="LC_Box">'.
3541: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3542: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3543: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3544: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3545: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
3546: '</ol>');
3547: if ($randompick>=0) {
3548: $r->print('<p class="LC_warning">'
3549: .&mt('Caution: this folder is set to randomly pick a subset'
3550: .' of resources. Adding or removing resources from this'
3551: .' folder will change the set of resources that the'
3552: .' students see, resulting in spurious or missing credit'
3553: .' for completed problems, not limited to ones you'
3554: .' modify. Do not modify the contents of this folder if'
3555: .' it is in active student use.')
3556: .'</p>'
3557: );
3558: }
3559: if ($is_random_order) {
3560: $r->print('<p class="LC_warning">'
3561: .&mt('Caution: this folder is set to randomly order its'
3562: .' contents. Adding or removing resources from this folder'
3563: .' will change the order of resources shown.')
3564: .'</p>'
3565: );
3566: }
3567: $r->print('</div>');
3568: }
3569:
3570: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
3571: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
3572: if (ref($supplemental) eq 'HASH') {
3573: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
3574: (ref($supplemental->{'ids'}) eq 'HASH')) {
3575: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
3576: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
3577: if ($supplemental->{'hidden'}->{$mapnum}) {
3578: $ishidden = 1;
3579: }
3580: }
3581: }
3582: }
3583: }
3584:
3585: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3586: %filters = (
3587: canremove => [],
3588: cancut => [],
3589: cancopy => [],
3590: hiddenresource => [],
3591: encrypturl => [],
3592: randomorder => [],
3593: randompick => [],
3594: );
3595: %curr_groups = &Apache::longroup::coursegroups();
3596: &Apache::loncommon::start_data_table_count(); #setup a row counter
3597: foreach my $res (@LONCAPA::map::order) {
3598: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3599: $name=&LONCAPA::map::qtescape($name);
3600: $url=&LONCAPA::map::qtescape($url);
3601: unless ($name) { $name=(split(/\//,$url))[-1]; }
3602: unless ($name) { $idx++; next; }
3603: push(@allidx,$res);
3604: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3605: push(@allmapidx,$res);
3606: }
3607:
3608: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
3609: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
3610: $idx++;
3611: next;
3612: }
3613: }
3614: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
3615: $coursenum,$coursedom,$crstype,
3616: $pathitem,$supplementalflag,$container,
3617: \%filters,\%curr_groups,$ltitoolsref,$canedit,
3618: $isencrypted,$ishidden,$navmapref,$hostname);
3619: $idx++;
3620: $shown++;
3621: }
3622: &Apache::loncommon::end_data_table_count();
3623:
3624: my $need_save;
3625: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
3626: my $toolslink;
3627: if ($allowed || $canedit) {
3628: my $helpitem = 'Navigation_Screen';
3629: if (!$allowed) {
3630: $helpitem = 'Supplemental_Navigation';
3631: }
3632: $toolslink = '<table><tr><td>'
3633: .&Apache::loncommon::help_open_menu('Navigation Screen',
3634: $helpitem,undef,'RAT')
3635: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3636: .'<td align="left"><ul id="LC_toolbar">'
3637: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
3638: .'id="LC_content_toolbar_edittoplevel" '
3639: .'class="LC_toolbarItem" '
3640: .'title="'.&mt('Supplemental Content Editor').'">'
3641: .'</a></li></ul></td></tr></table><br />';
3642: }
3643: if ($shown) {
3644: if ($allowed) {
3645: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3646: .&Apache::loncommon::start_data_table(undef,'contentlist')
3647: .&Apache::loncommon::start_data_table_header_row()
3648: .'<th colspan="2">'.&mt('Move').'</th>'
3649: .'<th colspan="3">'.&mt('Actions').'</th>'
3650: .'<th>'.&mt('Document').'</th>'
3651: .'<th colspan="2">'.&mt('Settings').'</th>'
3652: .&Apache::loncommon::end_data_table_header_row();
3653: if ($folder !~ /^supplemental/) {
3654: $lists{'canhide'} = join(',',@allidx);
3655: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3656: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3657: 'randomorder','randompick');
3658: foreach my $item (@possfilters) {
3659: if (ref($filters{$item}) eq 'ARRAY') {
3660: if (@{$filters{$item}} > 0) {
3661: $lists{$item} = join(',',@{$filters{$item}});
3662: }
3663: }
3664: }
3665: if (@allidx > 0) {
3666: my $path;
3667: if ($env{'form.folderpath'}) {
3668: $path =
3669: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3670: }
3671: if (@allidx > 1) {
3672: $to_show .=
3673: &Apache::loncommon::continue_data_table_row().
3674: '<td colspan="2"> </td>'.
3675: '<td>'.
3676: &multiple_check_form('actions',\%lists,$canedit).
3677: '</td>'.
3678: '<td colspan="3"> </td>'.
3679: '<td colspan="2">'.
3680: &multiple_check_form('settings',\%lists,$canedit).
3681: '</td>'.
3682: &Apache::loncommon::end_data_table_row();
3683: $need_save = 1;
3684: }
3685: }
3686: }
3687: $to_show .= $output.' '
3688: .&Apache::loncommon::end_data_table()
3689: .'<br style="line-height:2px;" />'
3690: .&Apache::loncommon::end_scrollbox();
3691: } else {
3692: $to_show .= $toolslink
3693: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3694: .$output.' '
3695: .&Apache::loncommon::end_data_table();
3696: }
3697: } else {
3698: if (!$allowed) {
3699: $to_show .= $toolslink;
3700: }
3701: my $noresmsg;
3702: if ($allowed && $hiddentop && !$supplementalflag) {
3703: $noresmsg = &mt('Main Content Hidden');
3704: } else {
3705: $noresmsg = &mt('Currently empty');
3706: }
3707: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3708: .'<div class="LC_info" id="contentlist">'
3709: .$noresmsg
3710: .'</div>'
3711: .&Apache::loncommon::end_scrollbox();
3712: }
3713: } else {
3714: if ($shown) {
3715: $to_show = '<div>'
3716: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3717: .$output
3718: .&Apache::loncommon::end_data_table()
3719: .'</div>';
3720: } else {
3721: $to_show = '<div class="LC_info" id="contentlist">'
3722: .&mt('Currently empty')
3723: .'</div>'
3724: }
3725: }
3726: my $tid = 1;
3727: if ($supplementalflag) {
3728: $tid = 2;
3729: }
3730: if ($allowed) {
3731: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
3732: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
3733: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3734: if ($canedit) {
3735: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3736: }
3737: } else {
3738: $r->print($to_show);
3739: }
3740: return;
3741: }
3742:
3743: sub multiple_check_form {
3744: my ($caller,$listsref,$canedit) = @_;
3745: return unless (ref($listsref) eq 'HASH');
3746: my $disabled;
3747: unless ($canedit) {
3748: $disabled = 'disabled="disabled"';
3749: }
3750: my $output =
3751: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3752: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3753: '<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>'.
3754: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3755: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3756: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3757: if ($caller eq 'settings') {
3758: $output .=
3759: '<table><tr>'.
3760: '<td class="LC_docs_entry_parameter">'.
3761: '<span class="LC_nobreak"><label>'.
3762: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
3763: '</label></span></td>'.
3764: '<td class="LC_docs_entry_parameter">'.
3765: '<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="" />'.
3766: '</span></td>'.
3767: '</tr>'."\n".
3768: '<tr>'.
3769: '<td class="LC_docs_entry_parameter">'.
3770: '<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').
3771: '</label></span>'.
3772: '</td></tr></table>'."\n";
3773: } else {
3774: $output .=
3775: '<table><tr>'.
3776: '<td class="LC_docs_entry_parameter">'.
3777: '<span class="LC_nobreak LC_docs_remove">'.
3778: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
3779: '</label></span></td>'.
3780: '<td class="LC_docs_entry_parameter">'.
3781: '<span class="LC_nobreak LC_docs_cut">'.
3782: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
3783: '</label></span></td>'."\n".
3784: '<td class="LC_docs_entry_parameter">'.
3785: '<span class="LC_nobreak LC_docs_copy">'.
3786: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
3787: '</label></span></td>'.
3788: '</tr></table>'."\n";
3789: }
3790: $output .=
3791: '</fieldset>'.
3792: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3793: if ($caller eq 'settings') {
3794: $output .=
3795: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3796: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3797: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3798: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3799: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3800: } elsif ($caller eq 'actions') {
3801: $output .=
3802: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3803: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3804: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3805: }
3806: $output .=
3807: '</form>'.
3808: '</div>';
3809: return $output;
3810: }
3811:
3812: sub process_file_upload {
3813: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
3814: # upload a file, if present
3815: my $filesize = length($env{'form.uploaddoc'});
3816: if (!$filesize) {
3817: $$upload_output = '<div class="LC_error">'.
3818: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3819: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3820: $filesize).'<br />'.
3821: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3822: '</div>';
3823: return;
3824: }
3825: my $quotatype = 'unofficial';
3826: if ($crstype eq 'Community') {
3827: $quotatype = 'community';
3828: } elsif ($crstype eq 'Placement') {
3829: $quotatype = 'placement';
3830: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
3831: $quotatype = 'official';
3832: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3833: $quotatype = 'textbook';
3834: }
3835: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3836: $filesize = int($filesize/1000); #expressed in kb
3837: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
3838: $env{'form.uploaddoc.filename'},$filesize,
3839: 'upload',$quotatype);
3840: return if ($$upload_output);
3841: }
3842: my ($parseaction,$showupload,$nextphase,$mimetype);
3843: if ($env{'form.parserflag'}) {
3844: $parseaction = 'parse';
3845: }
3846: my $folder=$env{'form.folder'};
3847: if ($folder eq '') {
3848: $folder='default';
3849: }
3850: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3851: my $errtext='';
3852: my $fatal=0;
3853: my $container='sequence';
3854: if ($env{'form.folderpath'} =~ /:1$/) {
3855: $container='page';
3856: }
3857: ($errtext,$fatal)=
3858: &mapread($coursenum,$coursedom,$folder.'.'.$container);
3859: if ($#LONCAPA::map::order<1) {
3860: $LONCAPA::map::order[0]=1;
3861: $LONCAPA::map::resources[1]='';
3862: }
3863: my $destination = 'docs/';
3864: if ($folder =~ /^supplemental/) {
3865: $destination = 'supplemental/';
3866: }
3867: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3868: $destination .= 'default/';
3869: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3870: $destination .= $2.'/';
3871: }
3872: if ($fatal) {
3873: $$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>';
3874: return;
3875: }
3876: # this is for a course, not a user, so set context to coursedoc.
3877: my $newidx=&LONCAPA::map::getresidx();
3878: $destination .= $newidx;
3879: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
3880: $parseaction,$allfiles,
3881: $codebase,undef,undef,undef,undef,
3882: undef,undef,\$mimetype);
3883: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3884: my $stored = $1;
3885: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3886: $stored.'</span>').'</p>';
3887: } else {
3888: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3889:
3890: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
3891: return;
3892: }
3893: my $ext='false';
3894: if ($url=~m{^http://}) { $ext='true'; }
3895: $url = &LONCAPA::map::qtunescape($url);
3896: my $comment=$env{'form.comment'};
3897: $comment = &LONCAPA::map::qtunescape($comment);
3898: if ($folder=~/^supplemental/) {
3899: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3900: $env{'user.domain'}.'___&&&___'.$comment;
3901: }
3902:
3903: $LONCAPA::map::resources[$newidx]=
3904: $comment.':'.$url.':'.$ext.':normal:res';
3905: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3906: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3907: $folder.'.'.$container,1);
3908: if ($fatal) {
3909: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
3910: return;
3911: } else {
3912: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3913: $$upload_output = $showupload;
3914: my $total_embedded = scalar(keys(%{$allfiles}));
3915: if ($total_embedded > 0) {
3916: my $uploadphase = 'upload_embedded';
3917: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3918: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3919: my ($embedded,$num) =
3920: &Apache::loncommon::ask_for_embedded_content(
3921: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3922: if ($embedded) {
3923: if ($num) {
3924: $$upload_output .=
3925: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3926: $nextphase = $uploadphase;
3927: } else {
3928: $$upload_output .= $embedded;
3929: }
3930: } else {
3931: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3932: }
3933: } else {
3934: $$upload_output .= &mt('No embedded items identified').'<br />';
3935: }
3936: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
3937: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3938: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
3939: $nextphase = 'decompress_uploaded';
3940: my $position = scalar(@LONCAPA::map::order)-1;
3941: my $noextract = &return_to_editor();
3942: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3943: my %archiveitems = (
3944: folderpath => $env{'form.folderpath'},
3945: cmd => $nextphase,
3946: newidx => $newidx,
3947: position => $position,
3948: phase => $nextphase,
3949: comment => $comment,
3950: );
3951: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3952: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
3953: $$upload_output = $showupload.
3954: &Apache::loncommon::decompress_form($mimetype,
3955: $archiveurl,'/adm/coursedocs',$noextract,
3956: \%archiveitems,\@current);
3957: }
3958: }
3959: }
3960: return $nextphase;
3961: }
3962:
3963: sub get_dir_list {
3964: my ($url,$coursenum,$coursedom,$newidx) = @_;
3965: my ($destination,$dir_root) = &embedded_destination();
3966: my ($dirlistref,$listerror) =
3967: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3968: my @dir_lines;
3969: my $dirptr=16384;
3970: if (ref($dirlistref) eq 'ARRAY') {
3971: foreach my $dir_line (sort
3972: {
3973: my ($afile)=split('&',$a,2);
3974: my ($bfile)=split('&',$b,2);
3975: return (lc($afile) cmp lc($bfile));
3976: } (@{$dirlistref})) {
3977: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3978: $filename =~ s/\s+$//;
3979: next if ($filename =~ /^\.\.?$/);
3980: my $isdir = 0;
3981: if ($dirptr&$testdir) {
3982: $isdir = 1;
3983: }
3984: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3985: }
3986: }
3987: return @dir_lines;
3988: }
3989:
3990: sub is_supplemental_title {
3991: my ($title) = @_;
3992: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3993: }
3994:
3995: # --------------------------------------------------------------- An entry line
3996:
3997: sub entryline {
3998: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
3999: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
4000: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
4001: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
4002: if (&is_supplemental_title($title)) {
4003: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
4004: $encodedtitle=$title;
4005: } else {
4006: $title=&HTML::Entities::encode($title,'"<>&\'');
4007: $encodedtitle=$title;
4008: $renametitle=$title;
4009: $foldertitle=$title;
4010: }
4011:
4012: my ($disabled,$readonly,$js_lt);
4013: unless ($canedit) {
4014: $disabled = 'disabled="disabled"';
4015: $readonly = 1;
4016: }
4017:
4018: my $orderidx=$LONCAPA::map::order[$index];
4019:
4020: $renametitle=~s/\\/\\\\/g;
4021: $renametitle=~s/\"\;/\\\"/g;
4022: $renametitle=~s/"/%22/g;
4023: $renametitle=~s/ /%20/g;
4024: $oldtitle = $renametitle;
4025: $renametitle=~s/\'/\\\'/g;
4026: my $line=&Apache::loncommon::start_data_table_row();
4027: my ($form_start,$form_end,$form_common,$form_param);
4028: # Edit commands
4029: my ($esc_path, $path, $symb, $shownsymb, $curralias);
4030: if ($env{'form.folderpath'}) {
4031: $esc_path=&escape($env{'form.folderpath'});
4032: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4033: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4034: }
4035: my $isexternal;
4036: if ($residx) {
4037: my $currurl = $url;
4038: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4039: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4040: $isexternal = 1;
4041: }
4042: if (!$supplementalflag) {
4043: my $path = 'uploaded/'.
4044: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4045: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4046: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4047: $residx,
4048: &Apache::lonnet::declutter($currurl));
4049: }
4050: }
4051: my ($renamelink,%lt,$ishash);
4052: if (ref($filtersref) eq 'HASH') {
4053: $ishash = 1;
4054: }
4055:
4056: if ($allowed) {
4057: $form_start = '
4058: <form action="/adm/coursedocs" method="post">
4059: ';
4060: $form_common=(<<END);
4061: <input type="hidden" name="folderpath" value="$path" />
4062: <input type="hidden" name="symb" value="$symb" />
4063: END
4064: $form_param=(<<END);
4065: <input type="hidden" name="setparms" value="$orderidx" />
4066: <input type="hidden" name="changeparms" value="0" />
4067: END
4068: $form_end = '</form>';
4069:
4070: my $incindex=$index+1;
4071: my $selectbox='';
4072: if (($#LONCAPA::map::order>0) &&
4073: ((split(/\:/,
4074: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4075: ne '') &&
4076: ((split(/\:/,
4077: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
4078: ne '')) {
4079: $selectbox=
4080: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
4081: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
4082: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4083: if ($i==$incindex) {
4084: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
4085: } else {
4086: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4087: }
4088: }
4089: $selectbox.='</select>';
4090: }
4091: %lt=&Apache::lonlocal::texthash(
4092: 'up' => 'Move Up',
4093: 'dw' => 'Move Down',
4094: 'rm' => 'Remove',
4095: 'ct' => 'Cut',
4096: 'rn' => 'Rename',
4097: 'cp' => 'Copy',
4098: 'da' => 'Unset alias',
4099: 'sa' => 'Set alias',
4100: 'ex' => 'External Resource',
4101: 'et' => 'External Tool',
4102: 'ed' => 'Edit',
4103: 'pr' => 'Preview',
4104: 'sv' => 'Save',
4105: 'ul' => 'URL',
4106: 'ti' => 'Title',
4107: 'er' => 'Editing rights unavailable for your current role.',
4108: );
4109: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4110: $env{'form.folderpath'},
4111: $currgroups);
4112: my ($copylink,$cutlink,$removelink);
4113: my $skip_confirm = 0;
4114: my $confirm_removal = 0;
4115: if ( $folder =~ /^supplemental/
4116: || ($url =~ m{( /smppg$
4117: |/syllabus$
4118: |/aboutme$
4119: |/navmaps$
4120: |/bulletinboard$
4121: |/ext\.tool$
4122: |\.html$)}x)
4123: || $isexternal) {
4124: $skip_confirm = 1;
4125: }
4126: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4127: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4128: $confirm_removal = 1;
4129: }
4130: if ($url =~ /$LONCAPA::assess_re/) {
4131: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4132: }
4133:
4134: if ($denied{'copy'}) {
4135: $copylink=(<<ENDCOPY)
4136: <span style="visibility: hidden;">$lt{'cp'}</span>
4137: ENDCOPY
4138: } else {
4139: my $formname = 'edit_copy_'.$orderidx;
4140: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
4141: $copylink=(<<ENDCOPY);
4142: <form name="$formname" method="post" action="/adm/coursedocs">
4143: $form_common
4144: <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>
4145: $form_end
4146: ENDCOPY
4147: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4148: push(@{$filtersref->{'cancopy'}},$orderidx);
4149: }
4150: }
4151: if ($denied{'cut'}) {
4152: $cutlink=(<<ENDCUT);
4153: <span style="visibility: hidden;">$lt{'ct'}</span>
4154: ENDCUT
4155: } else {
4156: my $formname = 'edit_cut_'.$orderidx;
4157: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
4158: $cutlink=(<<ENDCUT);
4159: <form name="$formname" method="post" action="/adm/coursedocs">
4160: $form_common
4161: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
4162: <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>
4163: $form_end
4164: ENDCUT
4165: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4166: push(@{$filtersref->{'cancut'}},$orderidx);
4167: }
4168: }
4169: if ($denied{'remove'}) {
4170: $removelink=(<<ENDREM);
4171: <span style="visibility: hidden;">$lt{'rm'}</a>
4172: ENDREM
4173: } else {
4174: my $formname = 'edit_remove_'.$orderidx;
4175: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
4176: $removelink=(<<ENDREM);
4177: <form name="$formname" method="post" action="/adm/coursedocs">
4178: $form_common
4179: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
4180: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
4181: <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>
4182: $form_end
4183: ENDREM
4184: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4185: push(@{$filtersref->{'canremove'}},$orderidx);
4186: }
4187: }
4188: $renamelink=(<<ENDREN);
4189: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
4190: ENDREN
4191: my ($uplink,$downlink);
4192: if ($canedit) {
4193: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4194: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4195: } else {
4196: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4197: $downlink = $uplink;
4198: }
4199: $line.=(<<END);
4200: <td>
4201: <div class="LC_docs_entry_move">
4202: <a href="$uplink">
4203: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
4204: </a>
4205: </div>
4206: <div class="LC_docs_entry_move">
4207: <a href="$downlink">
4208: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
4209: </a>
4210: </div>
4211: </td>
4212: <td>
4213: $form_start
4214: $form_param
4215: $form_common
4216: $selectbox
4217: $form_end
4218: </td>
4219: <td class="LC_docs_entry_commands LC_nobreak">
4220: $removelink
4221: $cutlink
4222: $copylink
4223: </td>
4224: END
4225: }
4226: # Figure out what kind of a resource this is
4227: my ($extension)=($url=~/\.(\w+)$/);
4228: my $uploaded=($url=~/^\/*uploaded\//);
4229: my $icon=&Apache::loncommon::icon($url);
4230: my $isfolder;
4231: my $ispage;
4232: my $containerarg;
4233: my $folderurl;
4234: my $plainurl;
4235: if ($uploaded) {
4236: if (($extension eq 'sequence') || ($extension eq 'page')) {
4237: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
4238: $containerarg = $1;
4239: if ($extension eq 'sequence') {
4240: $icon=$iconpath.'navmap.folder.closed.gif';
4241: $isfolder=1;
4242: } else {
4243: $icon=$iconpath.'page.gif';
4244: $ispage=1;
4245: }
4246: $folderurl = &Apache::lonnet::declutter($url);
4247: if ($allowed) {
4248: $url='/adm/coursedocs?';
4249: } else {
4250: $url='/adm/supplemental?';
4251: }
4252: } else {
4253: $plainurl = $url;
4254: }
4255: }
4256:
4257: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
4258: my $orig_url = $url;
4259: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
4260: if ($container eq 'page') {
4261: $url=~s{^http(|s)(:|:)//}{/ext/};
4262: } else {
4263: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4264: }
4265: if (!$supplementalflag && $residx && $symb) {
4266: if ((!$isfolder) && (!$ispage)) {
4267: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
4268: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4269: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4270: } else {
4271: $url=&Apache::lonnet::clutter($url);
4272: }
4273: if ($url=~/^\/*uploaded\//) {
4274: $url=~/\.(\w+)$/;
4275: my $embstyle=&Apache::loncommon::fileembstyle($1);
4276: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4277: $url='/adm/wrapper'.$url;
4278: } elsif ($embstyle eq 'ssi') {
4279: #do nothing with these
4280: } elsif ($url!~/\.(sequence|page)$/) {
4281: $url='/adm/coursedocs/showdoc'.$url;
4282: }
4283: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4284: my $wrapped = $1;
4285: my $exturl = $2;
4286: if (($wrapped eq '') && ($container ne 'page')) {
4287: $url='/adm/wrapper'.$url;
4288: }
4289: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4290: $nomodal = 1;
4291: }
4292: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4293: $url='/adm/wrapper'.$url;
4294: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4295: if (($ENV{'SERVER_PORT'} == 443) &&
4296: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4297: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
4298: $url .= '?usehttp=1';
4299: }
4300: $nomodal = 1;
4301: }
4302: }
4303: my $checkencrypt;
4304: if (!$env{'request.role.adv'}) {
4305: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4306: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4307: $checkencrypt = 1;
4308: } elsif (ref($navmapref)) {
4309: unless (ref($$navmapref)) {
4310: $$navmapref = Apache::lonnavmaps::navmap->new();
4311: }
4312: if (ref($$navmapref)) {
4313: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4314: $checkencrypt = 1;
4315: }
4316: }
4317: }
4318: }
4319: if ($checkencrypt) {
4320: my $currenc = $env{'request.enc'};
4321: $env{'request.enc'} = 1;
4322: $shownsymb = &Apache::lonenc::encrypted($symb);
4323: my $shownurl = &Apache::lonenc::encrypted($url);
4324: if (&Apache::lonnet::symbverify($symb,$url)) {
4325: $url = $shownurl;
4326: } else {
4327: $url = '';
4328: }
4329: $env{'request.enc'} = $currenc;
4330: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4331: $shownsymb = $symb;
4332: if ($isexternal) {
4333: $url =~ s/\#[^#]+$//;
4334: if ($container eq 'page') {
4335: $url = &Apache::lonnet::clutter($url);
4336: }
4337: }
4338: } else {
4339: $url = '';
4340: }
4341: unless ($env{'request.role.adv'}) {
4342: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4343: $url = '';
4344: }
4345: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4346: $url = '';
4347: $hiddenres = 1;
4348: }
4349: }
4350: if (($url ne '') && ($shownsymb ne '')) {
4351: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
4352: }
4353: }
4354: } elsif ($supplementalflag) {
4355: if ($isexternal) {
4356: if ($url =~ /^([^#]+)#([^#]+)$/) {
4357: $url = $1;
4358: $anchor = $2;
4359: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4360: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
4361: if ($hostname ne '') {
4362: $url = 'http://'.$hostname.$url;
4363: }
4364: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4365: }
4366: $nomodal = 1;
4367: }
4368: }
4369: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4370: if (($ENV{'SERVER_PORT'} == 443) &&
4371: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4372: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
4373: if ($hostname ne '') {
4374: $url = 'http://'.$hostname.$url;
4375: }
4376: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4377: }
4378: $nomodal = 1;
4379: }
4380: } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
4381: my $embstyle=&Apache::loncommon::fileembstyle($extension);
4382: unless ($embstyle eq 'ssi') {
4383: if (($embstyle eq 'img')
4384: || ($embstyle eq 'emb')
4385: || ($embstyle eq 'wrp')) {
4386: $url='/adm/wrapper'.$url;
4387: } elsif ($url !~ /\.(sequence|page)$/) {
4388: $url='/adm/coursedocs/showdoc'.$url;
4389: }
4390: }
4391: }
4392: unless ($allowed && $env{'request.role.adv'}) {
4393: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4394: $hiddenres = 1;
4395: }
4396: }
4397: }
4398: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4399: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
4400: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
4401: my $foldername=&escape($foldertitle);
4402: my $folderpath=$env{'form.folderpath'};
4403: if ($folderpath) { $folderpath.='&' };
4404: if (!$allowed && $supplementalflag) {
4405: $folderpath.=$containerarg.'&'.$foldername;
4406: $url.='folderpath='.&escape($folderpath);
4407: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4408: $hiddenfolder = 1;
4409: }
4410: } else {
4411: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4412: 'parameter_randompick'))[0];
4413: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4414: 'parameter_randomorder'))[0]=~/^yes$/i);
4415: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4416: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4417: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4418: 'parameter_encrypturl'))[0]=~/^yes$/i);
4419: unless ($hiddenmap) {
4420: if (ref($navmapref)) {
4421: unless (ref($$navmapref)) {
4422: $$navmapref = Apache::lonnavmaps::navmap->new();
4423: }
4424: if (ref($$navmapref)) {
4425: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4426: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4427: unless (@resources) {
4428: $hiddenmap = 1;
4429: unless ($env{'request.role.adv'}) {
4430: $url = '';
4431: $hiddenfolder = 1;
4432: }
4433: }
4434: }
4435: }
4436: }
4437: }
4438: unless ($encryptmap) {
4439: if ((ref($navmapref)) && (ref($$navmapref))) {
4440: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4441: $encryptmap = 1;
4442: }
4443: }
4444: }
4445:
4446: # Append randompick number, hidden, and encrypted with ":" to foldername,
4447: # so it gets transferred between levels
4448: $folderpath.=$containerarg.'&'.$foldername.
4449: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4450: unless ($url eq '') {
4451: $url.='folderpath='.&escape($folderpath);
4452: }
4453: my $rpckchk;
4454: if ($rpicknum) {
4455: $rpckchk = ' checked="checked"';
4456: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4457: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4458: }
4459: }
4460: my $formname = 'edit_randompick_'.$orderidx;
4461: $rand_pick_text =
4462: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4463: $form_param."\n".
4464: $form_common."\n".
4465: '<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.'">';
4466: if ($rpicknum ne '') {
4467: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4468: }
4469: $rand_pick_text .= '</span></span>'.
4470: $form_end;
4471: my $ro_set;
4472: if ($randorder) {
4473: $ro_set = 'checked="checked"';
4474: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4475: push(@{$filtersref->{'randomorder'}},$orderidx);
4476: }
4477: }
4478: $formname = 'edit_rorder_'.$orderidx;
4479: $rand_order_text =
4480: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4481: $form_param."\n".
4482: $form_common."\n".
4483: '<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>'.
4484: $form_end;
4485: }
4486: } elsif ($supplementalflag && !$allowed) {
4487: my $isexttool;
4488: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4489: $url='/adm/wrapper'.$url;
4490: $isexttool = 1;
4491: }
4492: $url .= ($url =~ /\?/) ? '&':'?';
4493: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
4494: if ($title) {
4495: $url .= '&title='.$encodedtitle;
4496: }
4497: if ((($isexternal) || ($isexttool)) && $orderidx) {
4498: $url .= '&idx='.$orderidx;
4499: }
4500: if ($anchor ne '') {
4501: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4502: }
4503: }
4504: my ($tdalign,$tdwidth);
4505: if ($allowed) {
4506: my $fileloc =
4507: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
4508: if ($isexternal) {
4509: ($editlink,$extresform) =
4510: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4511: undef,undef,undef,undef,undef,undef,
4512: undef,$disabled);
4513: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4514: ($editlink,$extresform) =
4515: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4516: undef,undef,undef,'tool',$coursedom,
4517: $coursenum,$ltitoolsref,$disabled);
4518: } elsif (!$isfolder && !$ispage) {
4519: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4520: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
4521: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
4522: my $suppanchor;
4523: if ($supplementalflag) {
4524: $suppanchor = $anchor;
4525: }
4526: my $jscall =
4527: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4528: $switchserver,
4529: $forceedit,
4530: undef,$symb,$shownsymb,
4531: &escape($env{'form.folderpath'}),
4532: $renametitle,$hostname,
4533: '','',1,$suppanchor);
4534: if ($jscall) {
4535: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4536: $jscall.'" >'.&mt('Edit').'</a> '."\n";
4537: }
4538: }
4539: }
4540: $tdalign = ' align="right" valign="top"';
4541: $tdwidth = ' width="80%"';
4542: }
4543: my $reinit;
4544: if ($crstype eq 'Community') {
4545: $reinit = &mt('(re-initialize community to access)');
4546: } else {
4547: $reinit = &mt('(re-initialize course to access)');
4548: }
4549: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
4550: if ($orig_url =~ /$LONCAPA::assess_re/) {
4551: $line.= '<br />';
4552: if ($curralias ne '') {
4553: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4554: $lt{'da'}.'</a></span>';
4555: } else {
4556: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4557: $lt{'sa'}.'</a></span>';
4558: }
4559: }
4560: $line.='</td><td>';
4561: my ($link,$nolink);
4562: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4563: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
4564: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4565: $nolink = 1;
4566: }
4567: }
4568: if ($nolink) {
4569: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4570: } else {
4571: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4572: }
4573: } elsif ($url) {
4574: if ($anchor ne '') {
4575: if ($supplementalflag) {
4576: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4577: } else {
4578: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4579: }
4580: }
4581: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4582: $link = 'http://'.$hostname.$url;
4583: } else {
4584: $link = $url;
4585: }
4586: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
4587: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
4588: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4589: $nolink = 1;
4590: }
4591: }
4592: if ($nolink) {
4593: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4594: } elsif ($nomodal) {
4595: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4596: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4597: } else {
4598: $line.=&Apache::loncommon::modal_link($link,
4599: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4600: }
4601: } else {
4602: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4603: }
4604: $line.='</span></td><td'.$tdwidth.'>';
4605: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4606: if ($nolink) {
4607: $line.=$title;
4608: } else {
4609: $line.='<a href="'.$url.'">'.$title.'</a>';
4610: }
4611: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4612: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4613: my $editurl = $url;
4614: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4615: $line .= ' '.'<a href="'.$editurl.'">'.
4616: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4617: '</a>';
4618: }
4619: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4620: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4621: }
4622: } elsif ($url) {
4623: if ($nolink) {
4624: $line.=$title;
4625: } elsif ($nomodal) {
4626: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4627: $title.'</a>';
4628: } else {
4629: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4630: }
4631: } elsif (($hiddenfolder) || ($hiddenres)) {
4632: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
4633: } else {
4634: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4635: }
4636: if (($allowed) && ($curralias ne '')) {
4637: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4638: } else {
4639: $line .= $extresform;
4640: }
4641: $line .= '</td>';
4642: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4643: $rand_order_text = ' ' if ($rand_order_text eq '');
4644: if ($uploaded && $url && !$isfolder && !$ispage) {
4645: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
4646: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
4647: }
4648: }
4649: if ($allowed) {
4650: my %lt=&Apache::lonlocal::texthash(
4651: 'hd' => 'Hidden',
4652: 'ec' => 'URL hidden');
4653: my ($enctext,$hidtext,$formhidden,$formurlhidden);
4654: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4655: $hidtext = ' checked="checked"';
4656: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
4657: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4658: }
4659: }
4660: $formhidden = 'edit_hiddenresource_'.$orderidx;
4661: $line.=(<<ENDPARMS);
4662: <td class="LC_docs_entry_parameter">
4663: <form action="/adm/coursedocs" method="post" name="$formhidden">
4664: $form_param
4665: $form_common
4666: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
4667: $form_end
4668: ENDPARMS
4669: if ($folder =~/^supplemental/) {
4670: $line.= "\n <td>";
4671: } else {
4672: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4673: $enctext = ' checked="checked"';
4674: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4675: push(@{$filtersref->{'encrypturl'}},$orderidx);
4676: }
4677: }
4678: $formurlhidden = 'edit_encrypturl_'.$orderidx;
4679: $line.=(<<ENDPARMS);
4680: <br />
4681: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
4682: $form_param
4683: $form_common
4684: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
4685: $form_end
4686: </td>
4687: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4688: $rand_order_text</td>
4689: ENDPARMS
4690: }
4691: }
4692: $line.=&Apache::loncommon::end_data_table_row();
4693: return $line;
4694: }
4695:
4696: sub action_restrictions {
4697: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4698: my %denied = (
4699: cut => 0,
4700: copy => 0,
4701: remove => 0,
4702: );
4703: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4704: # no copy for published maps
4705: $denied{'copy'} = 1;
4706: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4707: unless ($1 eq 'simpleproblem') {
4708: $denied{'copy'} = 1;
4709: }
4710: $denied{'cut'} = 1;
4711: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4712: if ($folderpath =~ /^default&[^\&]+$/) {
4713: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4714: $denied{'remove'} = 1;
4715: }
4716: $denied{'cut'} = 1;
4717: $denied{'copy'} = 1;
4718: }
4719: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4720: my $group = $1;
4721: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4722: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4723: $denied{'remove'} = 1;
4724: }
4725: }
4726: $denied{'cut'} = 1;
4727: $denied{'copy'} = 1;
4728: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4729: my $group = $1;
4730: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4731: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4732: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4733: if (keys(%groupsettings) > 0) {
4734: $denied{'remove'} = 1;
4735: }
4736: $denied{'cut'} = 1;
4737: $denied{'copy'} = 1;
4738: }
4739: }
4740: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4741: my $group = $1;
4742: if ($url =~ /group_boards_\Q$group\E/) {
4743: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4744: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4745: if (keys(%groupsettings) > 0) {
4746: if (ref($groupsettings{'functions'}) eq 'HASH') {
4747: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4748: $denied{'remove'} = 1;
4749: }
4750: }
4751: }
4752: $denied{'cut'} = 1;
4753: $denied{'copy'} = 1;
4754: }
4755: }
4756: }
4757: return %denied;
4758: }
4759:
4760: sub new_timebased_suffix {
4761: my ($dom,$num,$type,$area,$container) = @_;
4762: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
4763: if ($type eq 'paste') {
4764: $prefix = $type;
4765: $namespace = 'courseeditor';
4766: $idtype = 'addcode';
4767: } elsif ($type eq 'map') {
4768: $prefix = 'docs';
4769: if ($area eq 'supplemental') {
4770: $prefix = 'supp';
4771: }
4772: $prefix .= $container;
4773: $namespace = 'uploadedmaps';
4774: } else {
4775: $prefix = $type;
4776: $namespace = 'templated';
4777: }
4778: my ($suffix,$freedlock,$error) =
4779: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
4780: if (!$suffix) {
4781: if ($type eq 'paste') {
4782: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4783: } elsif ($type eq 'map') {
4784: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4785: } elsif ($type eq 'smppg') {
4786: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4787: } elsif ($type eq 'exttool') {
4788: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
4789: } else {
4790: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
4791: }
4792: if ($error) {
4793: $errtext .= '<br />'.$error;
4794: }
4795: }
4796: if ($freedlock ne 'ok') {
4797: $locknotfreed =
4798: '<div class="LC_error">'.
4799: &mt('There was a problem removing a lockfile.').' ';
4800: if ($type eq 'paste') {
4801: if ($freedlock eq 'nolock') {
4802: $locknotfreed =
4803: '<div class="LC_error">'.
4804: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4805:
4806: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
4807: } else {
4808: $locknotfreed .=
4809: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4810: }
4811: } elsif ($type eq 'map') {
4812: $locknotfreed .=
4813: &mt('This will prevent creation of additional folders or composite pages in this course.');
4814: } elsif ($type eq 'smppg') {
4815: $locknotfreed .=
4816: &mt('This will prevent creation of additional simple pages in this course.');
4817: } elsif ($type eq 'exttool') {
4818: $locknotfreed .=
4819: &mt('This will prevent creation of additional external tools in this course.');
4820: } else {
4821: $locknotfreed .=
4822: &mt('This will prevent creation of additional discussion boards in this course.');
4823: }
4824: unless ($type eq 'paste') {
4825: $locknotfreed .=
4826: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4827: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
4828: }
4829: $locknotfreed .= '</div>';
4830: }
4831: return ($suffix,$errtext,$locknotfreed);
4832: }
4833:
4834: =pod
4835:
4836: =item tiehash()
4837:
4838: tie the hash
4839:
4840: =cut
4841:
4842: sub tiehash {
4843: my ($mode)=@_;
4844: $hashtied=0;
4845: if ($env{'request.course.fn'}) {
4846: if ($mode eq 'write') {
4847: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4848: &GDBM_WRCREAT(),0640)) {
4849: $hashtied=2;
4850: }
4851: } else {
4852: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4853: &GDBM_READER(),0640)) {
4854: $hashtied=1;
4855: }
4856: }
4857: }
4858: }
4859:
4860: sub untiehash {
4861: if ($hashtied) { untie %hash; }
4862: $hashtied=0;
4863: return OK;
4864: }
4865:
4866:
4867:
4868:
4869: sub checkonthis {
4870: my ($r,$url,$level,$title,$checkstale)=@_;
4871: $url=&unescape($url);
4872: $alreadyseen{$url}=1;
4873: $r->rflush();
4874: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4875: $r->print("\n<br />");
4876: if ($level==0) {
4877: $r->print("<br />");
4878: }
4879: for (my $i=0;$i<=$level*5;$i++) {
4880: $r->print(' ');
4881: }
4882: $r->print('<a href="'.$url.'" target="cat">'.
4883: ($title?$title:$url).'</a> ');
4884: if ($url=~/^\/res\//) {
4885: my $updated;
4886: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4887: ($url !~ /\.\d+\.\w+$/)) {
4888: $updated = &Apache::lonnet::remove_stale_resfile($url);
4889: }
4890: my $result=&Apache::lonnet::repcopy(
4891: &Apache::lonnet::filelocation('',$url));
4892: if ($result eq 'ok') {
4893: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4894: if ($updated) {
4895: $r->print('<br />');
4896: for (my $i=0;$i<=$level*5;$i++) {
4897: $r->print(' ');
4898: }
4899: $r->print('- '.&mt('Outdated copy removed'));
4900: }
4901: $r->rflush();
4902: &Apache::lonnet::countacc($url);
4903: $url=~/\.(\w+)$/;
4904: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4905: $r->print('<br />');
4906: $r->rflush();
4907: for (my $i=0;$i<=$level*5;$i++) {
4908: $r->print(' ');
4909: }
4910: $r->print('- '.&mt('Rendering:').' ');
4911: my ($errorcount,$warningcount)=split(/:/,
4912: &Apache::lonnet::ssi_body($url,
4913: ('grade_target'=>'web',
4914: 'return_only_error_and_warning_counts' => 1)));
4915: if (($errorcount) ||
4916: ($warningcount)) {
4917: if ($errorcount) {
4918: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
4919: &mt('[quant,_1,error]',$errorcount).'</span>');
4920: }
4921: if ($warningcount) {
4922: $r->print('<span class="LC_warning">'.
4923: &mt('[quant,_1,warning]',$warningcount).'</span>');
4924: }
4925: } else {
4926: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4927: }
4928: $r->rflush();
4929: }
4930: my $dependencies=
4931: &Apache::lonnet::metadata($url,'dependencies');
4932: foreach my $dep (split(/\,/,$dependencies)) {
4933: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4934: &checkonthis($r,$dep,$level+1,'',$checkstale);
4935: }
4936: }
4937: } elsif ($result eq 'unavailable') {
4938: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4939: } elsif ($result eq 'not_found') {
4940: unless ($url=~/\$/) {
4941: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
4942: } else {
4943: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
4944: }
4945: } else {
4946: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4947: }
4948: if (($updated) && ($result ne 'ok')) {
4949: $r->print('<br />'.&mt('Outdated copy removed'));
4950: }
4951: }
4952: }
4953: }
4954:
4955:
4956:
4957: =pod
4958:
4959: =item list_symbs()
4960:
4961: List Content Identifiers
4962:
4963: =cut
4964:
4965: sub list_symbs {
4966: my ($r) = @_;
4967:
4968: my $crstype = &Apache::loncommon::course_type();
4969: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4970: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4971: $r->print(&startContentScreen('tools'));
4972: my $navmap = Apache::lonnavmaps::navmap->new();
4973: if (!defined($navmap)) {
4974: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4975: '<div class="LC_error">'.
4976: &mt('Unable to retrieve information about course contents').
4977: '</div>');
4978: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
4979: } else {
4980: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4981: &Apache::loncommon::start_data_table().
4982: &Apache::loncommon::start_data_table_header_row().
4983: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4984: &Apache::loncommon::end_data_table_header_row()."\n");
4985: my $count;
4986: foreach my $res ($navmap->retrieveResources()) {
4987: $r->print(&Apache::loncommon::start_data_table_row().
4988: '<td>'.$res->compTitle().'</td>'.
4989: '<td>'.$res->symb().'</td>'.
4990: &Apache::loncommon::end_data_table_row());
4991: $count ++;
4992: }
4993: if (!$count) {
4994: $r->print(&Apache::loncommon::start_data_table_row().
4995: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4996: &Apache::loncommon::end_data_table_row());
4997: }
4998: $r->print(&Apache::loncommon::end_data_table());
4999: }
5000: $r->print(&endContentScreen());
5001: }
5002:
5003: sub short_urls {
5004: my ($r,$canedit) = @_;
5005: my $crstype = &Apache::loncommon::course_type();
5006: my $formname = 'shortenurl';
5007: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5008: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5009: $r->print(&startContentScreen('tools'));
5010: my ($navmap,$errormsg) =
5011: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5012: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5013: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5014: my (%maps,%resources,%titles);
5015: if (!ref($navmap)) {
5016: $r->print($errormsg.
5017: &endContentScreen());
5018: return '';
5019: } else {
5020: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
5021: $r->rflush();
5022: my $readonly;
5023: if ($canedit) {
5024: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
5025: if ($numnew) {
5026: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
5027: }
5028: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
5029: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
5030: foreach my $error (@{$errors}) {
5031: $r->print('<li>'.$error.'</li>');
5032: }
5033: $r->print('</ul><br />');
5034: }
5035: } else {
5036: $readonly = 1;
5037: }
5038: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
5039: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
5040: undef,undef,undef,undef,undef,\%currtiny,$readonly));
5041: }
5042: $r->print(&endContentScreen());
5043: }
5044:
5045: sub contentverifyform {
5046: my ($r) = @_;
5047: my $crstype = &Apache::loncommon::course_type();
5048: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5049: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5050: $r->print(&startContentScreen('tools'));
5051: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5052: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
5053: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
5054: ' <span class="LC_nobreak">'.
5055: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
5056: &mt('No').'</label>'.(' 'x2).
5057: '<label><input type="radio" name="checkstale" value="1" />'.
5058: &mt('Yes').'</label></span></p><p>'.
5059: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
5060: '<input type="hidden" value="1" name="tools" />'.
5061: '<input type="hidden" value="1" name="verify" /></p></form>');
5062: $r->print(&endContentScreen());
5063: return;
5064: }
5065:
5066: sub verifycontent {
5067: my ($r,$checkstale) = @_;
5068: my $crstype = &Apache::loncommon::course_type();
5069: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5070: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5071: $r->print(&startContentScreen('tools'));
5072: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5073: $hashtied=0;
5074: undef %alreadyseen;
5075: %alreadyseen=();
5076: &tiehash();
5077:
5078: foreach my $key (keys(%hash)) {
5079: if ($hash{$key}=~/\.(page|sequence)$/) {
5080: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5081: $r->print('<hr /><span class="LC_error">'.
5082: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
5083: &unescape($hash{$key}).'</span><br />'.
5084: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
5085: }
5086: }
5087: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
5088: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
5089: }
5090: }
5091: &untiehash();
5092: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
5093: $r->print(&endContentScreen());
5094: }
5095:
5096: sub devalidateversioncache {
5097: my $src=shift;
5098: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5099: &Apache::lonnet::clutter($src));
5100: }
5101:
5102: sub checkversions {
5103: my ($r,$canedit) = @_;
5104: my $crstype = &Apache::loncommon::course_type();
5105: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5106: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
5107: $r->print(&startContentScreen('tools'));
5108:
5109: my $header='';
5110: my $startsel='';
5111: my $monthsel='';
5112: my $weeksel='';
5113: my $daysel='';
5114: my $allsel='';
5115: my %changes=();
5116: my $starttime=0;
5117: my $haschanged=0;
5118: my %setversions=&Apache::lonnet::dump('resourceversions',
5119: $env{'course.'.$env{'request.course.id'}.'.domain'},
5120: $env{'course.'.$env{'request.course.id'}.'.num'});
5121:
5122: $hashtied=0;
5123: &tiehash();
5124: if ($canedit) {
5125: my %newsetversions=();
5126: if ($env{'form.setmostrecent'}) {
5127: $haschanged=1;
5128: foreach my $key (keys(%hash)) {
5129: if ($key=~/^ids\_(\/res\/.+)$/) {
5130: $newsetversions{$1}='mostrecent';
5131: &devalidateversioncache($1);
5132: }
5133: }
5134: } elsif ($env{'form.setcurrent'}) {
5135: $haschanged=1;
5136: foreach my $key (keys(%hash)) {
5137: if ($key=~/^ids\_(\/res\/.+)$/) {
5138: my $getvers=&Apache::lonnet::getversion($1);
5139: if ($getvers>0) {
5140: $newsetversions{$1}=$getvers;
5141: &devalidateversioncache($1);
5142: }
5143: }
5144: }
5145: } elsif ($env{'form.setversions'}) {
5146: $haschanged=1;
5147: foreach my $key (keys(%env)) {
5148: if ($key=~/^form\.set_version_(.+)$/) {
5149: my $src=$1;
5150: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5151: $newsetversions{$src}=$env{$key};
5152: &devalidateversioncache($src);
5153: }
5154: }
5155: }
5156: }
5157: if ($haschanged) {
5158: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5159: $env{'course.'.$env{'request.course.id'}.'.domain'},
5160: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5161: $r->print(&Apache::loncommon::confirmwrapper(
5162: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5163: } else {
5164: $r->print(&Apache::loncommon::confirmwrapper(
5165: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
5166: }
5167: &mark_hash_old();
5168: }
5169: &changewarning($r,'');
5170: }
5171: if ($env{'form.timerange'} eq 'all') {
5172: # show all documents
5173: $header=&mt('All content in '.$crstype);
5174: $allsel=' selected="selected"';
5175: foreach my $key (keys(%hash)) {
5176: if ($key=~/^ids\_(\/res\/.+)$/) {
5177: my $src=$1;
5178: $changes{$src}=1;
5179: }
5180: }
5181: } else {
5182: # show documents which changed
5183: %changes=&Apache::lonnet::dump
5184: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5185: $env{'course.'.$env{'request.course.id'}.'.num'});
5186: my $firstkey=(keys(%changes))[0];
5187: unless ($firstkey=~/^error\:/) {
5188: unless ($env{'form.timerange'}) {
5189: $env{'form.timerange'}=604800;
5190: }
5191: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5192: .&mt('seconds');
5193: if ($env{'form.timerange'}==-1) {
5194: $seltext='since start of course';
5195: $startsel=' selected="selected"';
5196: $env{'form.timerange'}=time;
5197: }
5198: $starttime=time-$env{'form.timerange'};
5199: if ($env{'form.timerange'}==2592000) {
5200: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5201: $monthsel=' selected="selected"';
5202: } elsif ($env{'form.timerange'}==604800) {
5203: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5204: $weeksel=' selected="selected"';
5205: } elsif ($env{'form.timerange'}==86400) {
5206: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5207: $daysel=' selected="selected"';
5208: }
5209: $header=&mt('Content changed').' '.$seltext;
5210: } else {
5211: $header=&mt('No content modifications yet.');
5212: }
5213: }
5214: %setversions=&Apache::lonnet::dump('resourceversions',
5215: $env{'course.'.$env{'request.course.id'}.'.domain'},
5216: $env{'course.'.$env{'request.course.id'}.'.num'});
5217: my %lt=&Apache::lonlocal::texthash
5218: ('st' => 'Version changes since start of '.$crstype,
5219: 'lm' => 'Version changes since last Month',
5220: 'lw' => 'Version changes since last Week',
5221: 'sy' => 'Version changes since Yesterday',
5222: 'al' => 'All Resources (possibly large output)',
5223: 'cd' => 'Change display',
5224: 'sd' => 'Display',
5225: 'fi' => 'File',
5226: 'md' => 'Modification Date',
5227: 'mr' => 'Most recently published Version',
5228: 've' => 'Version used in '.$crstype,
5229: 'vu' => 'Set Version to be used in '.$crstype,
5230: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
5231: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5232: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
5233: 'di' => 'Differences',
5234: 'save' => 'Save changes',
5235: 'vers' => 'Version choice(s) for specific resources',
5236: 'act' => 'Actions');
5237: my ($disabled,$readonly);
5238: unless ($canedit) {
5239: $disabled = 'disabled="disabled"';
5240: $readonly = 1;
5241: }
5242: $r->print(<<ENDHEADERS);
5243: <h4 class="LC_info">$header</h4>
5244: <form action="/adm/coursedocs" method="post">
5245: <input type="hidden" name="versions" value="1" />
5246: <div class="LC_left_float">
5247: <fieldset>
5248: <legend>$lt{'cd'}</legend>
5249: <select name="timerange">
5250: <option value='all'$allsel>$lt{'al'}</option>
5251: <option value="-1"$startsel>$lt{'st'}</option>
5252: <option value="2592000"$monthsel>$lt{'lm'}</option>
5253: <option value="604800"$weeksel>$lt{'lw'}</option>
5254: <option value="86400"$daysel>$lt{'sy'}</option>
5255: </select>
5256: <input type="submit" name="display" value="$lt{'sd'}" />
5257: </fieldset>
5258: </div>
5259: <div class="LC_left_float">
5260: <fieldset>
5261: <legend>$lt{'act'}</legend>
5262: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5263: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
5264: </fieldset>
5265: </div>
5266: <br clear="all" />
5267: <hr />
5268: <h4>$lt{'vers'}</h4>
5269: ENDHEADERS
5270: #number of columns for version history
5271: my %changedbytime;
5272: foreach my $key (keys(%changes)) {
5273: #excludes not versionable problems from resource version history:
5274: next if ($key =~ /^\/res\/lib\/templates/);
5275: my $chg;
5276: if ($env{'form.timerange'} eq 'all') {
5277: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5278: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5279: } else {
5280: $chg = $changes{$key};
5281: next if ($chg < $starttime);
5282: }
5283: push(@{$changedbytime{$chg}},$key);
5284: }
5285: if (keys(%changedbytime) == 0) {
5286: &untiehash();
5287: $r->print(&mt('No content changes in imported content in specified time frame').
5288: &endContentScreen());
5289: return;
5290: }
5291: $r->print(
5292: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
5293: &Apache::loncommon::start_data_table().
5294: &Apache::loncommon::start_data_table_header_row().
5295: '<th>'.&mt('Resources').'</th>'.
5296: "<th>$lt{'mr'}</th>".
5297: "<th>$lt{'ve'}</th>".
5298: "<th>$lt{'vu'}</th>".
5299: '<th>'.&mt('History').'</th>'.
5300: &Apache::loncommon::end_data_table_header_row()
5301: );
5302: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5303: foreach my $key (sort(@{$changedbytime{$chg}})) {
5304: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5305: my $currentversion=&Apache::lonnet::getversion($key);
5306: if ($currentversion<0) {
5307: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5308: }
5309: my $linkurl=&Apache::lonnet::clutter($key);
5310: $r->print(
5311: &Apache::loncommon::start_data_table_row().
5312: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5313: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5314: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5315: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5316: '<td align="right">'
5317: );
5318: # Used in course
5319: my $usedversion=$hash{'version_'.$linkurl};
5320: if (($usedversion) && ($usedversion ne 'mostrecent')) {
5321: if ($usedversion != $currentversion) {
5322: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
5323: } else {
5324: $r->print($usedversion);
5325: }
5326: } else {
5327: $r->print($currentversion);
5328: }
5329: $r->print('</td><td title="'.$lt{'vu'}.'">');
5330: # Set version
5331: $r->print(&Apache::loncommon::select_form(
5332: $setversions{$linkurl},
5333: 'set_version_'.$linkurl,
5334: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5335: '' => '',
5336: 'mostrecent' => &mt('most recent'),
5337: map {$_,$_} (1..$currentversion)},'',$readonly));
5338: my $lastold=1;
5339: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5340: my $url=$root.'.'.$prevvers.'.'.$extension;
5341: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5342: $lastold=$prevvers;
5343: }
5344: }
5345: $r->print('</td>');
5346: # List all available versions
5347: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5348: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5349: my $url=$root.'.'.$prevvers.'.'.$extension;
5350: $r->print(
5351: '<span class="LC_nobreak">'
5352: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5353: .&mt('Version [_1]',$prevvers).'</a>'
5354: .' ('.&Apache::lonlocal::locallocaltime(
5355: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5356: .')');
5357: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5358: $r->print(
5359: ' <a href="/adm/diff?filename='.
5360: &Apache::lonnet::clutter($root.'.'.$extension).
5361: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5362: '" target="diffs">'.&mt('Diffs').'</a>');
5363: }
5364: $r->print('</span><br />');
5365: }
5366: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
5367: }
5368: }
5369: $r->print(
5370: &Apache::loncommon::end_data_table().
5371: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
5372: '</form>'
5373: );
5374:
5375: &untiehash();
5376: $r->print(&endContentScreen());
5377: return;
5378: }
5379:
5380: sub mark_hash_old {
5381: my $retie_hash=0;
5382: if ($hashtied) {
5383: $retie_hash=1;
5384: &untiehash();
5385: }
5386: &tiehash('write');
5387: $hash{'old'}=1;
5388: &untiehash();
5389: if ($retie_hash) { &tiehash(); }
5390: }
5391:
5392: sub is_hash_old {
5393: my $untie_hash=0;
5394: if (!$hashtied) {
5395: $untie_hash=1;
5396: &tiehash();
5397: }
5398: my $return=$hash{'old'};
5399: if ($untie_hash) { &untiehash(); }
5400: return $return;
5401: }
5402:
5403: sub changewarning {
5404: my ($r,$postexec,$message,$url)=@_;
5405: if (!&is_hash_old()) { return; }
5406: my $pathvar='folderpath';
5407: my $path=&escape($env{'form.folderpath'});
5408: if (!defined($url)) {
5409: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5410: }
5411: my $course_type = &Apache::loncommon::course_type();
5412: if (!defined($message)) {
5413: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5414: }
5415: my $windowname = 'loncapaclient';
5416: if ($env{'request.lti.login'}) {
5417: $windowname .= 'lti';
5418: }
5419: $r->print("\n\n".
5420: '<script type="text/javascript">'."\n".
5421: '// <![CDATA['."\n".
5422: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5423: '// ]]>'."\n".
5424: '</script>'."\n".
5425: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
5426: '<input type="hidden" name="orgurl" value="'.$url.
5427: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
5428: &mt($message,' <input type="hidden" name="'.
5429: $env{'request.role'}.'" value="1" /><input type="button" value="'.
5430: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
5431: $help{'Caching'}.'</p></form>'."\n\n");
5432: }
5433:
5434:
5435: sub init_breadcrumbs {
5436: my ($form,$text,$help)=@_;
5437: &Apache::lonhtmlcommon::clear_breadcrumbs();
5438: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
5439: text=>&Apache::loncommon::course_type().' Editor',
5440: faq=>273,
5441: bug=>'Instructor Interface',
5442: help => $help});
5443: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5444: text=>$text,
5445: faq=>273,
5446: bug=>'Instructor Interface'});
5447: }
5448:
5449: # subroutine to list form elements
5450: sub create_list_elements {
5451: my @formarr = @_;
5452: my $list = '';
5453: foreach my $button (@formarr){
5454: foreach my $picture (keys(%{$button})) {
5455: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
5456: }
5457: }
5458: return $list;
5459: }
5460:
5461: # subroutine to create ul from list elements
5462: sub create_form_ul {
5463: my $list = shift;
5464: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5465: return $ul;
5466: }
5467:
5468: #
5469: # Start tabs
5470: #
5471:
5472: sub startContentScreen {
5473: my ($mode) = @_;
5474: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
5475: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
5476: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5477: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5478: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5479: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5480: } else {
5481: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n";
5482: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5483: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5484: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5485: }
5486: $output .= "\n".'</ul>'."\n";
5487: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5488: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5489: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5490: return $output;
5491: }
5492:
5493: #
5494: # End tabs
5495: #
5496:
5497: sub endContentScreen {
5498: return '</div></div></div>';
5499: }
5500:
5501: sub supplemental_base {
5502: return 'supplemental&'.&escape(&mt('Supplemental Content'));
5503: }
5504:
5505: sub handler {
5506: my $r = shift;
5507: &Apache::loncommon::content_type($r,'text/html');
5508: $r->send_http_header;
5509: return OK if $r->header_only;
5510:
5511: # get course data
5512: my $crstype = &Apache::loncommon::course_type();
5513: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5514: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5515:
5516: # get docroot
5517: my $londocroot = $r->dir_config('lonDocRoot');
5518:
5519: # graphics settings
5520: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
5521:
5522: #
5523: # --------------------------------------------- Initialize help topics for this
5524: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5525: 'Adding_External_Resource','Adding_External_Tool',
5526: 'Navigate_Content','Adding_Folders','Docs_Overview',
5527: 'Load_Map','Supplemental','Score_Upload_Form',
5528: 'Adding_Pages','Importing_LON-CAPA_Resource',
5529: 'Importing_IMS_Course','Uploading_From_Harddrive',
5530: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
5531: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5532: }
5533: # Composite help files
5534: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5535: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5536: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5537: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5538: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5539: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
5540: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
5541: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
5542: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
5543: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
5544:
5545: my ($allowed,$canedit,$canview,$noendpage,$disabled);
5546: # does this user have privileges to modify content.
5547: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5548: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5549: unless ($r->uri eq '/adm/supplemental') {
5550: $allowed = 1;
5551: }
5552: $canedit = 1;
5553: $canview = 1;
5554: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5555: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5556: unless ($r->uri eq '/adm/supplemental') {
5557: $allowed = 1;
5558: }
5559: $canview = 1;
5560: }
5561: unless ($canedit) {
5562: $disabled = ' disabled="disabled"';
5563: }
5564: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5565: if ($env{'form.inhibitmenu'}) {
5566: unless ($env{'form.inhibitmenu'} eq 'yes') {
5567: delete($env{'form.inhibitmenu'});
5568: }
5569: }
5570:
5571: if ($allowed && $env{'form.verify'}) {
5572: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
5573: if (!$canedit) {
5574: &verifycontent($r);
5575: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5576: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5577: text=>'Results',
5578: faq=>273,
5579: bug=>'Instructor Interface'});
5580: &verifycontent($r,$env{'form.checkstale'});
5581: } else {
5582: &contentverifyform($r);
5583: }
5584: } elsif ($allowed && $env{'form.listsymbs'}) {
5585: &init_breadcrumbs('listsymbs','List Content IDs');
5586: &list_symbs($r);
5587: } elsif ($allowed && $env{'form.shorturls'}) {
5588: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5589: &short_urls($r,$canedit);
5590: } elsif ($allowed && $env{'form.docslog'}) {
5591: &init_breadcrumbs('docslog','Show Log');
5592: my $folder = $env{'form.folder'};
5593: if ($folder eq '') {
5594: $folder='default';
5595: }
5596: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
5597: } elsif ($allowed && $env{'form.versions'}) {
5598: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
5599: &checkversions($r,$canedit);
5600: } elsif ($canedit && $env{'form.dumpcourse'}) {
5601: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
5602: &dumpcourse($r);
5603: } elsif ($canedit && $env{'form.exportcourse'}) {
5604: &init_breadcrumbs('exportcourse','IMS Export');
5605: &Apache::imsexport::exportcourse($r);
5606: } else {
5607: if ($canedit && $env{'form.authorrole'}) {
5608: $noendpage = 1;
5609: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5610: if ($redirect) {
5611: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5612: my $container = 'sequence';
5613: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5614: $is_random_order,$container) =
5615: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5616: my (@folders)=split('&',$env{'form.folderpath'});
5617: $env{'form.foldername'}=&unescape(pop(@folders));
5618: my $folder=pop(@folders);
5619: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5620: $folder.'.'.$container);
5621: my $warning;
5622: if ($fatal) {
5623: if ($container eq 'page') {
5624: $warning = &mt('An error occurred retrieving the contents of the current page.');
5625: } else {
5626: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5627: }
5628: } else {
5629: my $url = $redirect;
5630: my $srcfile = $londocroot.$url;
5631: $url =~ s{^/priv/}{/res/};
5632: my $targetfile = $londocroot.$url;
5633: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5634: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5635: $env{'form.folder'} = $folder;
5636: &snapshotbefore();
5637: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5638: my $ext = 'false';
5639: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5640: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5641: ':'.$ext.':normal:res';
5642: push(@LONCAPA::map::order,$newidx);
5643: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5644: 'string_yesno');
5645: &remember_parms($newidx,'hiddenresource','set','yes');
5646: ($errtext,$fatal) =
5647: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5648: &log_differences($plain);
5649: &mark_hash_old();
5650: $r->internal_redirect($redirect);
5651: return OK;
5652: }
5653: } else {
5654: $r->internal_redirect($redirect);
5655: }
5656: }
5657: }
5658: #
5659: # Done catching special calls
5660: # The whole rest is for course and supplemental documents and utilities menu
5661: # Get the parameters that may be needed
5662: #
5663: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
5664: ['folderpath','title',
5665: 'forcesupplement','forcestandard',
5666: 'tools','symb','command','supppath']);
5667:
5668: foreach my $item ('forcesupplement','forcestandard','tools') {
5669: next if ($env{'form.'.$item} eq '');
5670: unless ($env{'form.'.$item} eq '1') {
5671: delete($env{'form.'.$item});
5672: }
5673: }
5674:
5675: if ($env{'form.command'}) {
5676: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5677: delete($env{'form.command'});
5678: }
5679: }
5680:
5681: if ($env{'form.symb'}) {
5682: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5683: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5684: delete($env{'form.symb'});
5685: }
5686: }
5687:
5688: # standard=1: this is a "new-style" course with an uploaded map as top level
5689: # standard=2: this is a "old-style" course, and there is nothing we can do
5690:
5691: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
5692:
5693: # Decide whether this should display supplemental or main content or utilities
5694: # supplementalflag=1: show supplemental documents
5695: # supplementalflag=0: show standard documents
5696: # toolsflag=1: show utilities
5697:
5698: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5699: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5700: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
5701: $supplementalflag=0;
5702: }
5703: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5704: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5705: unless ($allowed) { $supplementalflag=1; }
5706: unless ($standard) { $supplementalflag=1; }
5707: my $toolsflag=0;
5708: if ($env{'form.tools'}) { $toolsflag=1; }
5709:
5710: if ($env{'form.folderpath'} ne '') {
5711: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
5712: }
5713:
5714: my $backto_supppath;
5715: if ($env{'form.supppath'} ne '') {
5716: if ($supplementalflag && $allowed) {
5717: $backto_supppath = &validate_supppath($coursenum,$coursedom);
5718: }
5719: }
5720:
5721: my $script='';
5722: my $showdoc=0;
5723: my $addentries = {};
5724: my $container;
5725: my $containertag;
5726: my $pathitem;
5727: my %ltitools;
5728: my $hiddentop;
5729: my $navmap;
5730: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
5731:
5732: # Do we directly jump somewhere?
5733: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
5734: if ($env{'form.symb'} ne '') {
5735: $env{'form.folderpath'}=
5736: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
5737: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5738: $env{'form.command'}.'_'.$env{'form.symb'}});
5739: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
5740: $env{'form.folderpath'}=$env{'form.supppath'};
5741: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5742: $env{'form.command'}.'_'.$backto_supppath});
5743: }
5744: } elsif ($env{'form.command'} eq 'editdocs') {
5745: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
5746: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
5747: } elsif ($env{'form.command'} eq 'editsupp') {
5748: $env{'form.folderpath'} = &supplemental_base();
5749: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5750: } elsif ($env{'form.command'} eq 'contents') {
5751: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5752: } elsif ($env{'form.command'} eq 'home') {
5753: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
5754: }
5755:
5756:
5757: # Where do we store these for when we come back?
5758: my $stored_folderpath='docs_folderpath';
5759: if ($supplementalflag) {
5760: $stored_folderpath='docs_sup_folderpath';
5761: }
5762:
5763: # No folderpath, and in edit mode, see if we have something stored
5764: if ((!$env{'form.folderpath'}) && $allowed) {
5765: &Apache::loncommon::restore_course_settings($stored_folderpath,
5766: {'folderpath' => 'scalar'});
5767:
5768: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5769: if ($supplementalflag) {
5770: undef($env{'form.folderpath'}) if ($1 eq 'default');
5771: } else {
5772: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5773: }
5774: } else {
5775: undef($env{'form.folderpath'});
5776: }
5777: if ($env{'form.folderpath'} ne '') {
5778: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
5779: }
5780: }
5781:
5782: # If we are not allowed to make changes, all we can see are supplemental docs
5783: if (!$allowed) {
5784: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5785: $env{'form.folderpath'} = &supplemental_base();
5786: }
5787: }
5788: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
5789: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
5790: $env{'form.folderpath'} = &supplemental_base()
5791: .'&'.
5792: $env{'form.folderpath'};
5793: }
5794: # If allowed and user's role is not advanced check folderpath is not hidden
5795: my $hidden_and_empty;
5796: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
5797: my ($folderurl,$foldername,$hiddenfolder);
5798: my @pathitems = split(/\&/,$env{'form.folderpath'});
5799: my $folder = $pathitems[-2];
5800: if ($folder eq '') {
5801: undef($env{'form.folderpath'});
5802: } else {
5803: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
5804: if ((split(/\:/,$pathitems[-1]))[5]) {
5805: $folderurl .= '.page';
5806: } else {
5807: $folderurl .= '.sequence';
5808: }
5809: if ($supplementalflag) {
5810: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
5811: $foldername = &HTML::Entities::decode(&unescape($foldername));
5812: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
5813: if (ref($supplemental) eq 'HASH') {
5814: my ($suppmap,$suppmapnum);
5815: if ($folder eq 'supplemental') {
5816: $suppmap = 'default';
5817: $suppmapnum = 0;
5818: } elsif ($folder =~ /^supplemental_(\d+)$/) {
5819: $suppmap = $1;
5820: $suppmapnum = $suppmap;
5821: }
5822: if ($hiddenfolder) {
5823: my $hascontent;
5824: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
5825: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
5826: $hascontent = 1;
5827: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
5828: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
5829: if ($id =~ /^$suppmapnum\:/) {
5830: $hascontent = 1;
5831: last;
5832: }
5833: }
5834: }
5835: last if ($hascontent);
5836: }
5837: unless ($hascontent) {
5838: if ($foldername ne '') {
5839: $hidden_and_empty = $foldername;
5840: } else {
5841: $hidden_and_empty = $folder;
5842: }
5843: }
5844: }
5845: }
5846: } else {
5847: unless (ref($navmap)) {
5848: $navmap = Apache::lonnavmaps::navmap->new();
5849: }
5850: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
5851: $foldername = &HTML::Entities::decode(&unescape($foldername));
5852: if (ref($navmap)) {
5853: if ($hiddenfolder ||
5854: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
5855: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5856: unless (@resources) {
5857: if ($foldername ne '') {
5858: $hidden_and_empty = $foldername;
5859: } else {
5860: $hidden_and_empty = $folder;
5861: }
5862: }
5863: }
5864: }
5865: }
5866: if ($hidden_and_empty ne '') {
5867: splice(@pathitems,-2);
5868: if (@pathitems) {
5869: $env{'form.folderpath'} = join('&',@pathitems);
5870: } else {
5871: undef($env{'form.folderpath'});
5872: }
5873: }
5874: }
5875: }
5876:
5877: # If after all of this, we still don't have any paths, make them
5878: unless ($env{'form.folderpath'}) {
5879: if ($supplementalflag) {
5880: $env{'form.folderpath'}=&supplemental_base();
5881: } elsif ($allowed) {
5882: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
5883: }
5884: }
5885:
5886: # Store this
5887: unless ($toolsflag) {
5888: if (($allowed) && ($env{'form.folderpath'} ne '')) {
5889: &Apache::loncommon::store_course_settings($stored_folderpath,
5890: {'folderpath' => 'scalar'});
5891: }
5892: my $folderpath;
5893: if ($env{'form.folderpath'}) {
5894: $folderpath = $env{'form.folderpath'};
5895: my (@folders)=split('&',$env{'form.folderpath'});
5896: $env{'form.foldername'}=&unescape(pop(@folders));
5897: if ($env{'form.foldername'} =~ /\:1$/) {
5898: $container = 'page';
5899: } else {
5900: $container = 'sequence';
5901: }
5902: $env{'form.folder'}=pop(@folders);
5903: } else {
5904: if ($env{'form.folder'} eq '' ||
5905: $env{'form.folder'} eq 'supplemental') {
5906: if ($env{'form.folder'} eq 'supplemental') {
5907: $folderpath=&supplemental_base();
5908: } elsif (!$hiddentop) {
5909: $folderpath='default&'.
5910: &escape(&mt('Main Content').':::::');
5911: }
5912: }
5913: }
5914: $containertag = '<input type="hidden" name="folderpath" value="" />';
5915: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
5916: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5917: $showdoc='/'.$1;
5918: }
5919: if ($showdoc) { # got called in sequence from course
5920: $allowed=0;
5921: } else {
5922: if ($canedit) {
5923: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5924: $script=&Apache::lonratedt::editscript('simple');
5925: }
5926: }
5927: }
5928:
5929: # get personal data
5930: my $uname=$env{'user.name'};
5931: my $udom=$env{'user.domain'};
5932: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5933:
5934: if ($allowed) {
5935: if ($toolsflag) {
5936: $script .= &inject_data_js();
5937: my ($home,$other,%outhash)=&authorhosts();
5938: if (!$home && $other) {
5939: my @hosts;
5940: foreach my $aurole (keys(%outhash)) {
5941: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5942: push(@hosts,$outhash{$aurole});
5943: }
5944: }
5945: $script .= &dump_switchserver_js(@hosts);
5946: }
5947: } else {
5948: my $tid = 1;
5949: my @tabids;
5950: if ($supplementalflag) {
5951: @tabids = ('002','dd2','ee2','ff2');
5952: $tid = 2;
5953: } else {
5954: @tabids = ('aa1','bb1','cc1','ff1');
5955: unless ($env{'form.folderpath'} =~ /\:1$/) {
5956: unshift(@tabids,'001');
5957: push(@tabids,('dd1','ee1'));
5958: }
5959: }
5960: my $tabidstr = join("','",@tabids);
5961: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
5962: my $posslti = keys(%ltitools);
5963: my $hostname = $r->hostname();
5964: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
5965: $londocroot,$canedit,$hostname,\$navmap).
5966: &history_tab_js().
5967: &inject_data_js().
5968: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
5969: &Apache::lonextresedit::extedit_javascript(\%ltitools);
5970: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
5971: if ($hidden_and_empty ne '') {
5972: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
5973: $hidden_and_empty);
5974: $onload .= "javascript:alert('".&js_escape($alert)."');";
5975: }
5976: $addentries = {
5977: onload => $onload,
5978: };
5979: }
5980: $script .= &paste_popup_js();
5981: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5982: &mt('Switch server?');
5983:
5984:
5985: }
5986: # -------------------------------------------------------------------- Body tag
5987: $script = '<script type="text/javascript">'."\n"
5988: .'// <![CDATA['."\n"
5989: .$script."\n"
5990: .'// ]]>'."\n"
5991: .'</script>'."\n"
5992: .'<script type="text/javascript"
5993: src="/res/adm/includes/file_upload.js"></script>'."\n";
5994:
5995: # Breadcrumbs
5996: &Apache::lonhtmlcommon::clear_breadcrumbs();
5997:
5998: if ($showdoc) {
5999: my $args;
6000: if ($supplementalflag) {
6001: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
6002: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
6003: $args = {'bread_crumbs' => $brcrum};
6004: } else {
6005: $args = {'force_register' => $showdoc};
6006: }
6007: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
6008: } elsif ($toolsflag) {
6009: my ($breadtext,$breadtitle);
6010: $breadtext = "$crstype Editor";
6011: if ($canedit) {
6012: $breadtitle = 'Editing '.$crstype.' Contents';
6013: } else {
6014: $breadtext .= ' (View-only mode)';
6015: $breadtitle = 'Viewing '.$crstype.' Contents';
6016: }
6017: &Apache::lonhtmlcommon::add_breadcrumb({
6018: href=>"/adm/coursedocs",text=>$breadtext});
6019: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
6020: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6021: .&Apache::lonhtmlcommon::breadcrumbs(
6022: $breadtitle)
6023: );
6024: } elsif ($r->uri eq '/adm/supplemental') {
6025: unless ($env{'request.role.adv'}) {
6026: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
6027: $r->internal_redirect('/adm/navmaps');
6028: return OK;
6029: }
6030: }
6031: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
6032: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
6033: {'bread_crumbs' => $brcrum,}));
6034: } else {
6035: my ($breadtext,$breadtitle,$helpitem);
6036: $breadtext = "$crstype Editor";
6037: if ($canedit) {
6038: $breadtitle = 'Editing '.$crstype.' Contents';
6039: $helpitem = 'Docs_Adding_Course_Doc';
6040: } else {
6041: $breadtext .= ' (View-only mode)';
6042: $breadtitle = 'Viewing '.$crstype.' Contents';
6043: $helpitem = 'Docs_Viewing_Course_Doc';
6044: }
6045: &Apache::lonhtmlcommon::add_breadcrumb({
6046: href=>"/adm/coursedocs",text=>$breadtext});
6047: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
6048: {'add_entries' => $addentries}
6049: )
6050: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6051: .&Apache::lonhtmlcommon::breadcrumbs(
6052: $breadtitle,
6053: $helpitem)
6054: );
6055: }
6056:
6057: my %allfiles = ();
6058: my %codebase = ();
6059: my ($upload_result,$upload_output,$uploadphase);
6060: if ($canedit) {
6061: undef($suppchanges);
6062: if (($env{'form.uploaddoc.filename'}) &&
6063: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
6064: my $context = $1;
6065: # Process file upload - phase one - upload and parse primary file.
6066: undef($hadchanges);
6067: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
6068: \%allfiles,\%codebase,$context,$crstype);
6069: undef($navmap);
6070: if ($hadchanges) {
6071: &mark_hash_old();
6072: }
6073: if ($suppchanges) {
6074: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6075: undef($suppchanges);
6076: }
6077: $r->print($upload_output);
6078: } elsif ($env{'form.phase'} eq 'upload_embedded') {
6079: # Process file upload - phase two - upload embedded objects
6080: $uploadphase = 'check_embedded';
6081: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
6082: my $state = &embedded_form_elems($uploadphase,$primaryurl,
6083: $env{'form.newidx'});
6084: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6085: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6086: my ($destination,$dir_root) = &embedded_destination();
6087: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
6088: my $actionurl = '/adm/coursedocs';
6089: my ($result,$flag) =
6090: &Apache::loncommon::upload_embedded('coursedoc',$destination,
6091: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
6092: $actionurl);
6093: $r->print($result.&return_to_editor());
6094: } elsif ($env{'form.phase'} eq 'check_embedded') {
6095: # Process file upload - phase three - modify references in HTML file
6096: $uploadphase = 'modified_orightml';
6097: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6098: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6099: my ($destination,$dir_root) = &embedded_destination();
6100: my $result =
6101: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
6102: $docuname,$docudom,undef,
6103: $dir_root);
6104: $r->print($result.&return_to_editor());
6105: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
6106: $uploadphase = 'decompress_phase_one';
6107: $r->print(&decompression_phase_one().
6108: &return_to_editor());
6109: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
6110: $uploadphase = 'decompress_phase_two';
6111: $r->print(&decompression_phase_two().
6112: &return_to_editor());
6113: }
6114: }
6115:
6116: if ($allowed && $toolsflag) {
6117: $r->print(&startContentScreen('tools'));
6118: $r->print(&generate_admin_menu($crstype,$canedit));
6119: $r->print(&endContentScreen());
6120: } elsif ((!$showdoc) && (!$uploadphase)) {
6121: # -----------------------------------------------------------------------------
6122: my %lt=&Apache::lonlocal::texthash(
6123: 'copm' => 'All documents out of a published map into this folder',
6124: 'upfi' => 'Upload File',
6125: 'upld' => 'Upload Content',
6126: 'srch' => 'Search',
6127: 'impo' => 'Import',
6128: 'lnks' => 'Import from Stored Links',
6129: 'impm' => 'Import from Assembled Map',
6130: 'imcr' => 'Import from Course Resources',
6131: 'extr' => 'External Resource',
6132: 'extt' => 'External Tool',
6133: 'selm' => 'Select Map',
6134: 'load' => 'Load Map',
6135: 'newf' => 'New Folder',
6136: 'newp' => 'New Composite Page',
6137: 'syll' => 'Syllabus',
6138: 'navc' => 'Table of Contents',
6139: 'sipa' => 'Simple Course Page',
6140: 'sipr' => 'Simple Problem',
6141: 'webp' => 'Blank Web Page (editable)',
6142: 'stpr' => 'Standard Problem',
6143: 'news' => 'New sub-directory',
6144: 'crpr' => 'Create Problem',
6145: 'swit' => 'Switch Server',
6146: 'drbx' => 'Drop Box',
6147: 'scuf' => 'External Scores (handgrade, upload, clicker)',
6148: 'bull' => 'Discussion Board',
6149: 'mypi' => 'My Personal Information Page',
6150: 'grpo' => 'Group Portfolio',
6151: 'rost' => 'Course Roster',
6152: 'abou' => 'Personal Information Page for a User',
6153: 'imsf' => 'IMS Upload',
6154: 'imsl' => 'Upload IMS package',
6155: 'cms' => 'Origin of IMS package',
6156: 'se' => 'Select',
6157: 'file' => 'File',
6158: 'title' => 'Title',
6159: 'addp' => 'Add Placeholder to course?',
6160: 'uste' => 'Use Template?',
6161: 'fnam' => 'File Name:',
6162: 'loca' => 'Location:',
6163: 'dire' => 'Directory:',
6164: 'cate' => 'Category:',
6165: 'tmpl' => 'Template:',
6166: 'comment' => 'Comment',
6167: 'parse' => 'Upload embedded images/multimedia files if HTML file',
6168: 'bb5' => 'Blackboard 5',
6169: 'bb6' => 'Blackboard 6',
6170: 'angel5' => 'ANGEL 5.5',
6171: 'webctce4' => 'WebCT 4 Campus Edition',
6172: 'yes' => 'Yes',
6173: 'no' => 'No',
6174: 'er' => 'Editing rights unavailable for your current role.',
6175: );
6176: # -----------------------------------------------------------------------------
6177:
6178: # Calculate free quota space for a user or course. A javascript function checks
6179: # file size to determine if upload should be allowed.
6180: my $quotatype = 'unofficial';
6181: if ($crstype eq 'Community') {
6182: $quotatype = 'community';
6183: } elsif ($crstype eq 'Placement') {
6184: $quotatype = 'placement';
6185: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6186: $quotatype = 'official';
6187: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6188: $quotatype = 'textbook';
6189: }
6190: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6191: 'course',$quotatype); # expressed in MB
6192: my $current_disk_usage = 0;
6193: foreach my $subdir ('docs','supplemental') {
6194: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6195: "userfiles/$subdir",1); # expressed in kB
6196: }
6197: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
6198: my $usage = $current_disk_usage/1024; # in MB
6199: my $quota = $disk_quota;
6200: my $percent;
6201: if ($disk_quota == 0) {
6202: $percent = 100.0;
6203: } else {
6204: $percent = 100*($usage/$disk_quota);
6205: }
6206: $usage = sprintf("%.2f",$usage);
6207: $quota = sprintf("%.2f",$quota);
6208: $percent = sprintf("%.0f",$percent);
6209: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6210: $percent.'%',$quota.' MB').'</p>';
6211:
6212: my $fileupload=(<<FIUP);
6213: $quotainfo
6214: $lt{'file'}:<br />
6215: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
6216: <input type="hidden" id="LC_free_space" value="$free_space" />
6217: FIUP
6218:
6219: my $checkbox=(<<CHBO);
6220: <!-- <label>$lt{'parse'}?
6221: <input type="checkbox" name="parserflag" />
6222: </label> -->
6223: <label>
6224: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
6225: </label>
6226: CHBO
6227: my $imsfolder = $env{'form.folder'};
6228: if ($imsfolder eq '') {
6229: $imsfolder = 'default';
6230: }
6231: my $imspform=(<<IMSFORM);
6232: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6233: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6234: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
6235: <fieldset id="uploadimsform" style="display: none;">
6236: <legend>$lt{'imsf'}</legend>
6237: $fileupload
6238: <br />
6239: <p>
6240: $lt{'cms'}:
6241: <select name="source" $disabled>
6242: <option value="-1" selected="selected">$lt{'se'}</option>
6243: <option value="bb5">$lt{'bb5'}</option>
6244: <option value="bb6">$lt{'bb6'}</option>
6245: <option value="angel5">$lt{'angel5'}</option>
6246: <option value="webctce4">$lt{'webctce4'}</option>
6247: </select>
6248: <input type="hidden" name="folder" value="$imsfolder" />
6249: </p>
6250: <input type="hidden" name="phase" value="one" />
6251: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
6252: </fieldset>
6253: </form>
6254: IMSFORM
6255:
6256: my $fileuploadform=(<<FUFORM);
6257: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6258: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6259: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
6260: <fieldset id="uploaddocform" style="display: none;">
6261: <legend>$lt{'upfi'}</legend>
6262: <input type="hidden" name="active" value="aa" />
6263: $fileupload
6264: <br />
6265: $lt{'title'}:<br />
6266: <input type="text" size="60" name="comment" $disabled />
6267: $pathitem
6268: <input type="hidden" name="cmd" value="upload_default" />
6269: <br />
6270: <span class="LC_nobreak" style="float:left">
6271: $checkbox
6272: </span>
6273: <br clear="all" />
6274: <input type="submit" value="$lt{'upld'}" $disabled />
6275: </fieldset>
6276: </form>
6277: FUFORM
6278:
6279: my $mapimportjs;
6280: if ($canedit) {
6281: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6282: } else {
6283: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6284: }
6285: my $importpubform=(<<SEDFFORM);
6286: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
6287: $lt{'impm'}</a>$help{'Load_Map'}
6288: <form action="/adm/coursedocs" method="post" name="mapimportform">
6289: <fieldset id="importmapform" style="display: none;">
6290: <legend>$lt{'impm'}</legend>
6291: <input type="hidden" name="active" value="bb" />
6292: $lt{'copm'}<br />
6293: <span class="LC_nobreak">
6294: <input type="text" name="importmap" size="40" value=""
6295: onfocus="this.blur();$mapimportjs" $disabled />
6296: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6297: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
6298: </fieldset>
6299: </form>
6300:
6301: SEDFFORM
6302: my $importcrsresform;
6303: my ($numdirs,$pickfile) =
6304: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
6305: "resize_scrollbox('contentscroll','1','0');",
6306: undef,'res');
6307: if ($pickfile) {
6308: $importcrsresform=(<<CRSFORM);
6309: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
6310: $lt{'imcr'}</a>$help{'Course_Resources'}
6311: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6312: <fieldset id="importcrsresform" style="display: none;">
6313: <legend>$lt{'imcr'}</legend>
6314: <input type="hidden" name="active" value="bb" />
6315: $pickfile
6316: <p>
6317: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
6318: </p>
6319: <input type="hidden" name="importdetail" value="" />
6320: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
6321: </fieldset>
6322: </form>
6323: CRSFORM
6324: }
6325:
6326: my $fromstoredjs;
6327: if ($canedit) {
6328: $fromstoredjs = 'open_StoredLinks_Import()';
6329: } else {
6330: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6331: }
6332:
6333: my @importpubforma = (
6334: { '<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>" },
6335: { '<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'}" },
6336: { '<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>' },
6337: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6338: );
6339: if ($pickfile) {
6340: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\');" />' => $importcrsresform});
6341: }
6342: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
6343: my $extresourcesform =
6344: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6345: $help{'Adding_External_Resource'},
6346: undef,undef,undef,undef,undef,undef,$disabled);
6347: my $exttoolform =
6348: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6349: $help{'Adding_External_Tool'},undef,
6350: undef,'tool',$coursedom,$coursenum,
6351: \%ltitools,$disabled);
6352: if ($allowed) {
6353: my $folder = $env{'form.folder'};
6354: if ($folder eq '') {
6355: $folder='default';
6356: }
6357: if ($canedit) {
6358: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6359: if ($output) {
6360: $r->print($output);
6361: }
6362: }
6363: $r->print(<<HIDDENFORM);
6364: <form name="renameform" method="post" action="/adm/coursedocs">
6365: <input type="hidden" name="title" />
6366: <input type="hidden" name="cmd" />
6367: <input type="hidden" name="markcopy" />
6368: <input type="hidden" name="copyfolder" />
6369: $containertag
6370: </form>
6371: <form name="aliasform" method="post" action="/adm/coursedocs">
6372: <input type="hidden" name="alias" />
6373: <input type="hidden" name="cmd" />
6374: $containertag
6375: </form>
6376:
6377: HIDDENFORM
6378: $r->print(&makesimpleeditform($pathitem)."\n".
6379: &makedocslogform($pathitem."\n".
6380: '<input type="hidden" name="folder" value="'.
6381: $env{'form.folder'}.'" />'."\n"));
6382: }
6383:
6384: # Generate the tabs
6385: my ($mode,$needs_end);
6386: if (($supplementalflag) && (!$allowed)) {
6387: my @folders = split('&',$env{'form.folderpath'});
6388: unless (@folders > 2) {
6389: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6390: $needs_end = 1;
6391: }
6392: } else {
6393: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
6394: $needs_end = 1;
6395: }
6396:
6397: #
6398: my $hostname = $r->hostname();
6399: my $savefolderpath;
6400:
6401: if ($allowed) {
6402: my $folder=$env{'form.folder'};
6403: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
6404: $folder='default';
6405: $savefolderpath = $env{'form.folderpath'};
6406: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
6407: $pathitem = '<input type="hidden" name="folderpath" value="'.
6408: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6409: }
6410: my $postexec='';
6411: if ($folder eq 'default') {
6412: my $windowname = 'loncapaclient';
6413: if ($env{'request.lti.login'}) {
6414: $windowname .= 'lti';
6415: }
6416: $r->print('<script type="text/javascript">'."\n"
6417: .'// <![CDATA['."\n"
6418: .'this.window.name="'.$windowname.'";'."\n"
6419: .'// ]]>'."\n"
6420: .'</script>'."\n"
6421: );
6422: } else {
6423: #$postexec='self.close();';
6424: }
6425: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6426: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
6427: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6428:
6429: my $newnavform=(<<NNFORM);
6430: <form action="/adm/coursedocs" method="post" name="newnav">
6431: <input type="hidden" name="active" value="ff" />
6432: $pathitem
6433: <input type="hidden" name="importdetail"
6434: value="$lt{'navc'}=/adm/navmaps" />
6435: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
6436: $help{'Navigate_Content'}
6437: </form>
6438: NNFORM
6439: my $newsmppageform=(<<NSPFORM);
6440: <form action="/adm/coursedocs" method="post" name="newsmppg">
6441: <input type="hidden" name="active" value="ff" />
6442: $pathitem
6443: <input type="hidden" name="importdetail" value="" />
6444: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
6445: $help{'Simple Page'}
6446: </form>
6447: NSPFORM
6448:
6449: my $newsmpproblemform=(<<NSPROBFORM);
6450: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
6451: <input type="hidden" name="active" value="dd" />
6452: $pathitem
6453: <input type="hidden" name="importdetail" value="" />
6454: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
6455: $help{'Simple_Problem'}
6456: </form>
6457:
6458: NSPROBFORM
6459:
6460: my $newdropboxform=(<<NDBFORM);
6461: <form action="/adm/coursedocs" method="post" name="newdropbox">
6462: <input type="hidden" name="active" value="dd" />
6463: $pathitem
6464: <input type="hidden" name="importdetail" value="" />
6465: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
6466: $help{'Dropbox'}
6467: </form>
6468: NDBFORM
6469:
6470: my $newexuploadform=(<<NEXUFORM);
6471: <form action="/adm/coursedocs" method="post" name="newexamupload">
6472: <input type="hidden" name="active" value="dd" />
6473: $pathitem
6474: <input type="hidden" name="importdetail" value="" />
6475: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
6476: $help{'Score_Upload_Form'}
6477: </form>
6478: NEXUFORM
6479:
6480: my $newbulform=(<<NBFORM);
6481: <form action="/adm/coursedocs" method="post" name="newbul">
6482: <input type="hidden" name="active" value="ee" />
6483: $pathitem
6484: <input type="hidden" name="importdetail" value="" />
6485: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
6486: $help{'Bulletin Board'}
6487: </form>
6488: NBFORM
6489:
6490: my $newaboutmeform=(<<NAMFORM);
6491: <form action="/adm/coursedocs" method="post" name="newaboutme">
6492: <input type="hidden" name="active" value="ee" />
6493: $pathitem
6494: <input type="hidden" name="importdetail"
6495: value="$plainname=/adm/$udom/$uname/aboutme" />
6496: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
6497: $help{'My Personal Information Page'}
6498: </form>
6499: NAMFORM
6500:
6501: my $newaboutsomeoneform=(<<NASOFORM);
6502: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
6503: <input type="hidden" name="active" value="ee" />
6504: $pathitem
6505: <input type="hidden" name="importdetail" value="" />
6506: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
6507: </form>
6508: NASOFORM
6509:
6510: my $newrosterform=(<<NROSTFORM);
6511: <form action="/adm/coursedocs" method="post" name="newroster">
6512: <input type="hidden" name="active" value="ee" />
6513: $pathitem
6514: <input type="hidden" name="importdetail"
6515: value="$lt{'rost'}=/adm/viewclasslist" />
6516: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
6517: $help{'Course_Roster'}
6518: </form>
6519: NROSTFORM
6520:
6521: my $newwebpage;
6522: if ($folder =~ /^default_?(\d*)$/) {
6523: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6524: if ($1) {
6525: $newwebpage .= $1;
6526: } else {
6527: $newwebpage .= 'default';
6528: }
6529: $newwebpage .= '/new.html';
6530: }
6531: my $newwebpageform =(<<NWEBFORM);
6532: <form action="/adm/coursedocs" method="post" name="newwebpage">
6533: <input type="hidden" name="active" value="ff" />
6534: $pathitem
6535: <input type="hidden" name="importdetail" value="$newwebpage" />
6536: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
6537: $help{'Web_Page'}
6538: </form>
6539: NWEBFORM
6540:
6541: my @ids=&Apache::lonnet::current_machine_ids();
6542: my $machines_str = "'".join("','",@ids)."'";
6543: my (%is_home,%toppath,$rolehomes);
6544: if ($env{'user.author'}) {
6545: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6546: $is_home{'author'} = 1;
6547: }
6548: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
6549: }
6550: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6551: ['active'],['ca','aa']);
6552: my %by_roletype;
6553: if (keys(%roleshash)) {
6554: foreach my $entry (keys(%roleshash)) {
6555: my ($auname,$audom,$roletype) = split(/:/,$entry);
6556: my $key = $entry;
6557: $key =~ s/:/___/g;
6558: my $author = $auname.'___'.$audom;
6559: $by_roletype{$roletype}{$author} = 1;
6560: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6561: $toppath{$author} = "/priv/$audom/$auname";
6562: if (grep(/^\Q$rolehome\E$/,@ids)) {
6563: $is_home{$author} = 1;
6564: }
6565: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
6566: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
6567: }
6568: }
6569: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6570: if (grep(/^\Q$crshome\E$/,@ids)) {
6571: $is_home{'course'} = 1;
6572: }
6573: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
6574: my $pickdir = $lt{'loca'}.
6575: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
6576: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
6577: if ($env{'user.author'}) {
6578: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
6579: }
6580: if (keys(%by_roletype)) {
6581: foreach my $possrole ('ca','aa') {
6582: if (ref($by_roletype{$possrole}) eq 'HASH') {
6583: my $roletitle = &Apache::lonnet::plaintext($possrole);
6584: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6585: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
6586: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
6587: $roletitle." ($audom/$auname)</option>\n";
6588: }
6589: }
6590: }
6591: }
6592: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n".
6593: '</select><br />'."\n".
6594: $lt{'dire'}.
6595: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
6596: '<option value=""></option>'.
6597: '</select><br />'."\n";
6598:
6599: my %seltemplate_menus;
6600: my @files = &Apache::lonhomework::get_template_list('problem');
6601: my @noexamplelink = ('blank.problem','blank.library','script.library');
6602: my $currentcategory = '';
6603: my @ordered = ('');
6604: my %templatehelp;
6605: my $defcategory = '';
6606: my @catorder = ($defcategory);
6607: $seltemplate_menus{$defcategory}->{'order'} = [''];
6608: $seltemplate_menus{$defcategory}->{'text'} = '';
6609: foreach my $file (@files) {
6610: if (ref($file) eq 'ARRAY') {
6611: my ($path,$title,$category,$help) = @{$file};
6612: next if ($title !~ /\S/);
6613: if (&js_escape($category) ne $currentcategory) {
6614: $currentcategory = &js_escape($category);
6615: push(@catorder,&js_escape($currentcategory));
6616: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6617: $seltemplate_menus{$currentcategory}->{'default'} = '';
6618: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6619: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6620: }
6621: if ($path) {
6622: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6623: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6624: if ($help) {
6625: $templatehelp{$path} = $help;
6626: }
6627: }
6628: }
6629: }
6630:
6631: my $templates = $lt{'cate'}.' '.
6632: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6633: $defcategory,'tempcategory','template',
6634: \%seltemplate_menus,\@catorder,
6635: "resize_scrollbox('contentscroll','1','0');",
6636: "toggleExampleText();",'template').'<br />';
6637: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6638: '<span id="newresexample">'.&mt('Example').'<span></a>';
6639: my $crsresform=(<<RESFORM);
6640: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
6641: $lt{'stpr'}</a>$help{'Course_Resource'}
6642: <form action="/adm/coursedocs" method="post" name="courseresform">
6643: <fieldset id="crsresform" style="display:none;">
6644: <legend>$lt{'stpr'}</legend>
6645: <input type="hidden" name="active" value="bb" />
6646: <p>
6647: $pickdir
6648: <div id="newstdproblem" style="display:none;">
6649: <span class="LC_nobreak">$lt{'news'}?
6650: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
6651:
6652: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
6653: </span><span id="newsubdir"></span>
6654: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6655: </p>
6656: $lt{'fnam'}
6657: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
6658: <p>
6659: <div id="newresource" style="display:none">
6660: $lt{'addp'}
6661: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
6662: $lt{'no'}</label>
6663: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
6664: $lt{'yes'}</label>
6665: <span id="newrestitle"></span>
6666: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
6667: </div>
6668: </p>
6669: <p>
6670: $lt{'uste'}
6671: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
6672: $lt{'no'}</label>
6673: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
6674: $lt{'yes'}</label>
6675: <div id="newrestemplate" style="display:none">
6676: $templates
6677: $templatepreview
6678: </div>
6679: </p>
6680: <span class="LC_nobreak">
6681: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
6682: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
6683: </span>
6684: </div>
6685: <div id="stdprobswitch" style="display:none;">
6686: $rolehomes
6687: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
6688: </div>
6689: </fieldset>
6690: </form>
6691:
6692: RESFORM
6693:
6694: my $specialdocumentsform;
6695: my @specialdocumentsforma;
6696: my $gradingform;
6697: my @gradingforma;
6698: my $communityform;
6699: my @communityforma;
6700: my $newfolderform;
6701: my $newfolderb;
6702:
6703: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6704:
6705: my $newpageform=(<<NPFORM);
6706: <form action="/adm/coursedocs" method="post" name="newpage">
6707: <input type="hidden" name="folderpath" value="$path" />
6708: <input type="hidden" name="importdetail" value="" />
6709: <input type="hidden" name="active" value="ee" />
6710: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
6711: $help{'Adding_Pages'}
6712: </form>
6713: NPFORM
6714:
6715:
6716: $newfolderform=(<<NFFORM);
6717: <form action="/adm/coursedocs" method="post" name="newfolder">
6718: $pathitem
6719: <input type="hidden" name="importdetail" value="" />
6720: <input type="hidden" name="active" value="" />
6721: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
6722: </form>
6723: NFFORM
6724:
6725: my $newsylform=(<<NSYLFORM);
6726: <form action="/adm/coursedocs" method="post" name="newsyl">
6727: <input type="hidden" name="active" value="ee" />
6728: $pathitem
6729: <input type="hidden" name="importdetail"
6730: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
6731: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
6732: $help{'Syllabus'}
6733:
6734: </form>
6735: NSYLFORM
6736:
6737: my $newgroupfileform=(<<NGFFORM);
6738: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
6739: <input type="hidden" name="active" value="ee" />
6740: $pathitem
6741: <input type="hidden" name="importdetail"
6742: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
6743: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
6744: $help{'Group Portfolio'}
6745: </form>
6746: NGFFORM
6747: if ($container eq 'page') {
6748: @specialdocumentsforma=(
6749: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6750: );
6751: } else {
6752: @specialdocumentsforma=(
6753: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
6754: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6755: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
6756: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
6757: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6758: );
6759: }
6760: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6761:
6762: my @external = (
6763: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
6764: );
6765: if (keys(%ltitools)) {
6766: push(@external,
6767: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6768: );
6769: }
6770: my $externalform = &create_form_ul(&create_list_elements(@external));
6771:
6772: my @importdoc = ();
6773: unless ($container eq 'page') {
6774: push(@importdoc,
6775: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6776: );
6777: }
6778: push(@importdoc,
6779: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
6780: );
6781: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
6782:
6783: @gradingforma=(
6784: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6785: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6786: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6787: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform},
6788: );
6789: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6790:
6791: @communityforma=(
6792: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6793: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6794: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
6795: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6796: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
6797: );
6798: $communityform = &create_form_ul(&create_list_elements(@communityforma));
6799:
6800: my %orderhash = (
6801: 'aa' => ['Upload',$fileuploadform],
6802: 'bb' => ['Import',$importpubform],
6803: 'cc' => ['External',$externalform],
6804: 'dd' => ['Grading',$gradingform],
6805: 'ff' => ['Other',$specialdocumentsform],
6806: );
6807: unless ($container eq 'page') {
6808: $orderhash{'00'} = ['Newfolder',$newfolderform];
6809: $orderhash{'ee'} = ['Collaboration',$communityform];
6810: }
6811:
6812: $hadchanges=0;
6813: unless (($supplementalflag || $toolsflag)) {
6814: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6815: $supplementalflag,\%orderhash,$iconpath,$pathitem,
6816: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
6817: undef($navmap);
6818: if ($error) {
6819: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6820: }
6821: if ($hadchanges) {
6822: unless (&is_hash_old()) {
6823: &mark_hash_old();
6824: }
6825: }
6826:
6827: &changewarning($r,'');
6828: }
6829: }
6830:
6831: # Supplemental documents start here
6832:
6833: my $folder=$env{'form.folder'};
6834: unless ($supplementalflag) {
6835: $folder='supplemental';
6836: }
6837: if (($folder eq 'supplemental') &&
6838: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
6839: $env{'form.folderpath'} = &supplemental_base();
6840: } elsif ($allowed) {
6841: $env{'form.folderpath'} = $savefolderpath;
6842: }
6843: $pathitem = '<input type="hidden" name="folderpath" value="'.
6844: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6845: if ($allowed) {
6846: my $folderseq=
6847: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
6848:
6849: my $supupdocform=(<<SUPDOCFORM);
6850: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6851: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6852: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
6853: <fieldset id="uploadsuppdocform" style="display: none;">
6854: <legend>$lt{'upfi'}</legend>
6855: <input type="hidden" name="active" value="ee" />
6856: $fileupload
6857: <br />
6858: <br />
6859: <span class="LC_nobreak">
6860: $checkbox
6861: </span>
6862: <br /><br />
6863: $lt{'comment'}:<br />
6864: <textarea cols="50" rows="4" name="comment"></textarea>
6865: <br />
6866: $pathitem
6867: <input type="hidden" name="cmd" value="upload_supplemental" />
6868: <input type='submit' value="$lt{'upld'}" />
6869: </form>
6870: SUPDOCFORM
6871:
6872: my $supnewfolderform=(<<SNFFORM);
6873: <form action="/adm/coursedocs" method="post" name="supnewfolder">
6874: <input type="hidden" name="active" value="" />
6875: $pathitem
6876: <input type="hidden" name="importdetail" value="" />
6877: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
6878: $help{'Adding_Folders'}
6879: </form>
6880: SNFFORM
6881:
6882: my $supextform =
6883: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6884: $help{'Adding_External_Resource'},
6885: undef,undef,undef,undef,undef,undef,
6886: $disabled);
6887:
6888: my $supexttoolform =
6889: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6890: $help{'Adding_External_Tool'},
6891: undef,undef,'tool',$coursedom,
6892: $coursenum,\%ltitools,$disabled);
6893:
6894: my $supnewsylform=(<<SNSFORM);
6895: <form action="/adm/coursedocs" method="post" name="supnewsyl">
6896: <input type="hidden" name="active" value="ff" />
6897: $pathitem
6898: <input type="hidden" name="importdetail"
6899: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
6900: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
6901: $help{'Syllabus'}
6902: </form>
6903: SNSFORM
6904:
6905: my $supnewaboutmeform=(<<SNAMFORM);
6906: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
6907: <input type="hidden" name="active" value="ff" />
6908: $pathitem
6909: <input type="hidden" name="importdetail"
6910: value="$plainname=/adm/$udom/$uname/aboutme" />
6911: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
6912: $help{'My Personal Information Page'}
6913: </form>
6914: SNAMFORM
6915:
6916: my $supwebpage;
6917: if ($folder =~ /^supplemental_?(\d*)$/) {
6918: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6919: if ($1) {
6920: $supwebpage .= $1;
6921: } else {
6922: $supwebpage .= 'default';
6923: }
6924: $supwebpage .= '/new.html';
6925: }
6926: my $supwebpageform =(<<SWEBFORM);
6927: <form action="/adm/coursedocs" method="post" name="supwebpage">
6928: <input type="hidden" name="active" value="cc" />
6929: $pathitem
6930: <input type="hidden" name="importdetail" value="$supwebpage" />
6931: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
6932: $help{'Web_Page'}
6933: </form>
6934: SWEBFORM
6935:
6936:
6937: my @specialdocs = (
6938: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
6939: =>$supnewsylform},
6940: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
6941: =>$supnewaboutmeform},
6942: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6943:
6944: );
6945: my @supexternal = (
6946: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
6947: =>$supextform});
6948: if (keys(%ltitools)) {
6949: push(@supexternal,
6950: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
6951: =>$supexttoolform});
6952: }
6953: my @supimportdoc = (
6954: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6955: =>$supupdocform},
6956: );
6957:
6958: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
6959: my %suporderhash = (
6960: '00' => ['Supnewfolder', $supnewfolderform],
6961: 'dd' => ['Upload',$supupdocform],
6962: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
6963: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
6964: );
6965: if ($supplementalflag) {
6966: $suppchanges = 0;
6967: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6968: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
6969: \%ltitools,$canedit,$hostname);
6970: if ($error) {
6971: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6972: }
6973: if ($suppchanges) {
6974: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6975: undef($suppchanges);
6976: }
6977: }
6978: } elsif ($supplementalflag) {
6979: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6980: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
6981: $hostname);
6982: if ($error) {
6983: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6984: }
6985: }
6986:
6987: if ($needs_end) {
6988: $r->print(&endContentScreen());
6989: }
6990:
6991: if ($allowed) {
6992: $r->print('
6993: <form method="post" name="extimport" action="/adm/coursedocs">
6994: <input type="hidden" name="title" />
6995: <input type="hidden" name="url" />
6996: <input type="hidden" name="useform" />
6997: <input type="hidden" name="residx" />
6998: </form>');
6999: }
7000: } elsif ($showdoc) {
7001: # -------------------------------------------------------- This is showdoc mode
7002: $r->print("<h1>".&mt('Uploaded Document').' - '.
7003: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
7004: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
7005: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
7006: }
7007: }
7008: unless ($noendpage) {
7009: $r->print(&Apache::loncommon::end_page());
7010: }
7011: return OK;
7012: }
7013:
7014: sub embedded_form_elems {
7015: my ($phase,$primaryurl,$newidx) = @_;
7016: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7017: $newidx =~s /\D+//g;
7018: return <<STATE;
7019: <input type="hidden" name="folderpath" value="$folderpath" />
7020: <input type="hidden" name="cmd" value="upload_embedded" />
7021: <input type="hidden" name="newidx" value="$newidx" />
7022: <input type="hidden" name="phase" value="$phase" />
7023: <input type="hidden" name="primaryurl" value="$primaryurl" />
7024: STATE
7025: }
7026:
7027: sub embedded_destination {
7028: my $folder=$env{'form.folder'};
7029: my $destination = 'docs/';
7030: if ($folder =~ /^supplemental/) {
7031: $destination = 'supplemental/';
7032: }
7033: if (($folder eq 'default') || ($folder eq 'supplemental')) {
7034: $destination .= 'default/';
7035: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
7036: $destination .= $2.'/';
7037: }
7038: my $newidx = $env{'form.newidx'};
7039: $newidx =~s /\D+//g;
7040: if ($newidx) {
7041: $destination .= $newidx;
7042: }
7043: my $dir_root = '/userfiles';
7044: return ($destination,$dir_root);
7045: }
7046:
7047: sub return_to_editor {
7048: my $actionurl = '/adm/coursedocs';
7049: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7050: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7051: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7052: '</a></p>';
7053: }
7054:
7055: sub decompression_info {
7056: my ($destination,$dir_root) = &embedded_destination();
7057: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7058: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7059: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7060: my $container='sequence';
7061: my ($pathitem,$hiddenelem);
7062: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
7063: if ($env{'form.folderpath'} =~ /\:1$/) {
7064: $container='page';
7065: }
7066: unshift(@hiddens,$pathitem);
7067: foreach my $item (@hiddens) {
7068: if ($item eq 'newidx') {
7069: next if ($env{'form.'.$item} =~ /\D/);
7070: }
7071: if ($env{'form.'.$item}) {
7072: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
7073: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
7074: }
7075: }
7076: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7077: $hiddenelem);
7078: }
7079:
7080: sub decompression_phase_one {
7081: my ($dir,$file,$warning,$error,$output);
7082: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7083: &decompression_info();
7084: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
7085: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7086: } else {
7087: my $file = $1;
7088: $output =
7089: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7090: $destination,$dir_root,
7091: $hiddenelem);
7092: if ($env{'form.autoextract_camtasia'}) {
7093: $output .= &remove_archive($docudom,$docuname,$container);
7094: }
7095: }
7096: if ($error) {
7097: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7098: $error.'</p>'."\n";
7099: }
7100: if ($warning) {
7101: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7102: }
7103: return $output;
7104: }
7105:
7106: sub decompression_phase_two {
7107: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7108: &decompression_info();
7109: my $output;
7110: if ($env{'form.archivedelete'}) {
7111: $output = &remove_archive($docudom,$docuname,$container);
7112: }
7113: $output .=
7114: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
7115: $destination,$dir_root,$hiddenelem);
7116: return $output;
7117: }
7118:
7119: sub remove_archive {
7120: my ($docudom,$docuname,$container) = @_;
7121: my $map = $env{'form.folder'}.'.'.$container;
7122: my ($output,$delwarning,$delresult,$url);
7123: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7124: if ($fatal) {
7125: if ($container eq 'page') {
7126: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7127: } else {
7128: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7129: }
7130: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
7131: } else {
7132: my $currcmd = $env{'form.cmd'};
7133: my $position = $env{'form.position'};
7134: my $archiveidx = $position;
7135: if ($position > 0) {
7136: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7137: $archiveidx = $position-1;
7138: }
7139: $env{'form.cmd'} = 'remove_'.$archiveidx;
7140: my ($title,$url,@rrest) =
7141: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7142: if ($url eq $env{'form.archiveurl'}) {
7143: if (&handle_edit_cmd($docuname,$docudom)) {
7144: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
7145: if ($suppchanges) {
7146: &Apache::lonnet::update_supp_caches($docudom,$docuname);
7147: undef($suppchanges);
7148: }
7149: if ($fatal) {
7150: if ($container eq 'page') {
7151: $delwarning = &mt('An error occurred updating the contents of the current page.');
7152: } else {
7153: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7154: }
7155: } else {
7156: $delresult = &mt('Archive file removed.');
7157: }
7158: }
7159: } else {
7160: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7161: ' '.&mt('As a result the archive file has not been removed.');
7162: }
7163: }
7164: $env{'form.cmd'} = $currcmd;
7165: }
7166: if ($delwarning) {
7167: $output = '<p class="LC_warning">'.
7168: $delwarning.
7169: '</p>';
7170: }
7171: if ($delresult) {
7172: $output .= '<p class="LC_info">'.
7173: $delresult.
7174: '</p>';
7175: }
7176: return $output;
7177: }
7178:
7179: sub generate_admin_menu {
7180: my ($crstype,$canedit) = @_;
7181: my $lc_crstype = lc($crstype);
7182: my ($home,$other,%outhash)=&authorhosts();
7183: my %lt= ( # do not translate here
7184: 'vc' => 'Verify Content',
7185: 'cv' => 'Check/Set Resource Versions',
7186: 'ls' => 'List Resource Identifiers',
7187: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
7188: 'imse' => 'Export contents to IMS Archive',
7189: 'dcd' => "Copy $crstype Content to Authoring Space",
7190: );
7191: my ($candump,$dumpurl);
7192: if ($home + $other > 0) {
7193: $candump = 'F';
7194: if ($home) {
7195: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7196: } else {
7197: my @hosts;
7198: foreach my $aurole (keys(%outhash)) {
7199: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7200: push(@hosts,$outhash{$aurole});
7201: }
7202: }
7203: if (@hosts == 1) {
7204: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7205: '&role='.
7206: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7207: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7208: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7209: } else {
7210: $dumpurl = "javascript:choose_switchserver_window()";
7211: }
7212: }
7213: }
7214: my @menu=
7215: ({ categorytitle=>'Administration',
7216: items =>[
7217: { linktext => $lt{'vc'},
7218: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7219: permission => 'F',
7220: help => 'Docs_Verify_Content',
7221: icon => 'verify.png',
7222: linktitle => 'Verify contents can be retrieved/rendered',
7223: },
7224: { linktext => $lt{'cv'},
7225: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7226: permission => 'F',
7227: help => 'Docs_Check_Resource_Versions',
7228: icon => 'resversion.png',
7229: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7230: },
7231: { linktext => $lt{'ls'},
7232: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7233: permission => 'F',
7234: #help => '',
7235: icon => 'symbs.png',
7236: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7237: },
7238: { linktext => $lt{'ct'},
7239: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7240: permission => 'F',
7241: help => 'Docs_Short_URLs',
7242: icon => 'shorturls.png',
7243: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7244: },
7245: ]
7246: });
7247: if ($canedit) {
7248: push(@menu,
7249: { categorytitle=>'Export',
7250: items =>[
7251: { linktext => $lt{'imse'},
7252: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7253: permission => 'F',
7254: help => 'Docs_Export_Course_Docs',
7255: icon => 'imsexport.png',
7256: linktitle => $lt{'imse'},
7257: },
7258: { linktext => $lt{'dcd'},
7259: url => $dumpurl,
7260: permission => $candump,
7261: help => 'Docs_Dump_Course_Docs',
7262: icon => 'dump.png',
7263: linktitle => $lt{'dcd'},
7264: },
7265: ]
7266: });
7267: }
7268: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7269: '<input type="hidden" id="dummy" />'."\n".
7270: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7271: '</form>';
7272: }
7273:
7274: sub generate_edit_table {
7275: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
7276: $need_save,$copyfolder,$canedit) = @_;
7277: return unless(ref($orderhash_ref) eq 'HASH');
7278: my %orderhash = %{$orderhash_ref};
7279: my ($form, $activetab, $active, $disabled);
7280: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
7281: $activetab = $env{'form.active'};
7282: }
7283: unless ($canedit) {
7284: $disabled = ' disabled="disabled"';
7285: }
7286: my $backicon = $iconpath.'clickhere.gif';
7287: my $backtext = &mt('Exit Editor');
7288: $form = '<div class="LC_Box" style="margin:0;">'.
7289: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7290: '<li class="goback">'.
7291: '<a href="javascript:toContents('."'$jumpto'".');">'.
7292: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7293: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7294: '<li>'.
7295: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7296: &mt('Undo Delete').'</a></li>'."\n";
7297: if ($env{'form.docslog'}) {
7298: $form .= '<li class="active">';
7299: } else {
7300: $form .= '<li>';
7301: }
7302: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7303: &mt('History').'</a></li>'."\n";
7304: if ($env{'form.docslog'}) {
7305: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7306: &mt('Edit').'</a></li>'."\n";
7307: }
7308: foreach my $name (reverse(sort(keys(%orderhash)))) {
7309: if($name ne '00'){
7310: if($activetab eq '' || $activetab ne $name){
7311: $active = '';
7312: }elsif($activetab eq $name){
7313: $active = 'class="active"';
7314: }
7315: $form .= '<li style="float:right" '.$active
7316: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
7317: } else {
7318: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
7319:
7320: }
7321: }
7322: $form .= '</ul>'."\n";
7323: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
7324:
7325: if ($to_show ne '') {
7326: my $saveform;
7327: if ($need_save) {
7328: my $button = &mt('Make changes');
7329: my $path;
7330: if ($env{'form.folderpath'}) {
7331: $path =
7332: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7333: }
7334: $saveform = <<"END";
7335: <div id="multisave" style="display:none; clear:both;" >
7336: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7337: <input type="hidden" name="folderpath" value="$path" />
7338: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7339: <input type="hidden" name="allhiddenresource" value="" />
7340: <input type="hidden" name="allencrypturl" value="" />
7341: <input type="hidden" name="allrandompick" value="" />
7342: <input type="hidden" name="allrandomorder" value="" />
7343: <input type="hidden" name="changeparms" value="" />
7344: <input type="hidden" name="multiremove" value="" />
7345: <input type="hidden" name="multicut" value="" />
7346: <input type="hidden" name="multicopy" value="" />
7347: <input type="hidden" name="multichange" value="" />
7348: <input type="hidden" name="copyfolder" value="$copyfolder" />
7349: <input type="submit" name="savemultiples" value="$button" $disabled />
7350: </form>
7351: </div>
7352: END
7353: }
7354: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
7355: }
7356: foreach my $field (keys(%orderhash)){
7357: if($field ne '00'){
7358: if($activetab eq '' || $activetab ne $field){
7359: $active = 'style="display: none;float:left"';
7360: }elsif($activetab eq $field){
7361: $active = 'style="display:block;float:left"';
7362: }
7363: $form .= '<div id="'.$field.$tid.'"'
7364: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
7365: .'</div>'."\n";
7366: }
7367: }
7368: unless ($env{'form.docslog'}) {
7369: $form .= '</div></div>'."\n";
7370: }
7371: return $form;
7372: }
7373:
7374: sub editing_js {
7375: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7376: $londocroot,$canedit,$hostname,$navmapref) = @_;
7377: my %js_lt = &Apache::lonlocal::texthash(
7378: p_mnf => 'Name of New Folder',
7379: t_mnf => 'New Folder',
7380: p_mnp => 'Name of New Page',
7381: t_mnp => 'New Page',
7382: p_mxu => 'Title for the External Score',
7383: p_msp => 'Name of Simple Course Page',
7384: p_msb => 'Title for the Problem',
7385: p_mdb => 'Title for the Drop Box',
7386: p_mbb => 'Title for the Discussion Board',
7387: p_mwp => 'Title for Web Page',
7388: p_mnr => 'Title for the Resource',
7389: p_mab => "Enter user:domain for User's Personal Information Page",
7390: p_mab2 => 'Personal Information Page of ',
7391: p_mab_alrt1 => 'Not a valid user:domain',
7392: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7393: p_chn => 'New Title',
7394: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
7395: p_rmr2a => 'Remove',
7396: p_rmr2b => '?',
7397: p_rmr3a => 'Remove those',
7398: p_rmr3b => 'items?',
7399: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7400: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
7401: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7402: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
7403: p_ctr2a => 'Cut',
7404: p_ctr2b => '?',
7405: p_ctr3a => 'Cut those',
7406: p_ctr3b => 'items?',
7407: setal => 'Enter a (unique) alias',
7408: delal => 'Are you sure you want to eliminate the alias?',
7409: rpck => 'Enter number to pick (e.g., 3)',
7410: imsfile => 'You must choose an IMS package for import',
7411: imscms => 'You must select which Course Management System was the source of the IMS package',
7412: invurl => 'Invalid URL',
7413: titbl => 'Title is blank',
7414: more => '(More ...)',
7415: less => '(Less ...)',
7416: noor => 'No actions selected or changes to settings specified.',
7417: noch => 'No changes to settings specified.',
7418: noac => 'No actions selected.',
7419: nofi => 'No file selected',
7420: tinc => 'Title in course',
7421: sunm => 'Sub-directory name',
7422: edri => 'Editing rights unavailable for your current role.',
7423: sele => 'Select',
7424: swit => 'Switch server required',
7425: );
7426: &js_escape(\%js_lt);
7427: my $crstype = &Apache::loncommon::course_type();
7428: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7429: my $main_container_page;
7430: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7431: $main_container_page = 1;
7432: }
7433: my $backtourl;
7434: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
7435: my $toplevelsupp = &supplemental_base();
7436: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
7437: my @ids=&Apache::lonnet::current_machine_ids();
7438: my $machines_str = "'".join("','",@ids)."'";
7439: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7440: my $caller = $1;
7441: if ($caller =~ /^supplemental/) {
7442: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7443: } else {
7444: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7445: $res = &Apache::lonnet::clutter($res);
7446: if (&Apache::lonnet::is_on_map($res)) {
7447: my ($url,$anchor);
7448: if ($res =~ /^([^#]+)#([^#]+)$/) {
7449: $url = $1;
7450: $anchor = $2;
7451: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7452: $caller = $1.&escape('#').$anchor;
7453: }
7454: } else {
7455: $url = $res;
7456: }
7457: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7458: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7459: $backtourl .= '?navmap=1';
7460: } else {
7461: $backtourl .= '?symb='.
7462: &HTML::Entities::encode($caller,'<>&"');
7463: }
7464: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7465: if (($ENV{'SERVER_PORT'} == 443) &&
7466: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
7467: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
7468: if ($hostname ne '') {
7469: $backtourl = 'http://'.$hostname.$backtourl;
7470: }
7471: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7472: }
7473: }
7474: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7475: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
7476: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
7477: if ($hostname ne '') {
7478: $backtourl = 'http://'.$hostname.$backtourl;
7479: }
7480: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7481: }
7482: }
7483: }
7484: if ($anchor ne '') {
7485: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7486: }
7487: $backtourl = &Apache::loncommon::escape_single($backtourl);
7488: } else {
7489: $backtourl = '/adm/navmaps';
7490: }
7491: }
7492: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7493: $backtourl = '/adm/menu';
7494: } elsif ($supplementalflag) {
7495: if (($env{'request.role.adv'}) ||
7496: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7497: $backtourl = '/adm/supplemental';
7498: } else {
7499: $backtourl = '/adm/navmaps';
7500: }
7501: } else {
7502: $backtourl = '/adm/navmaps';
7503: }
7504:
7505: my $fieldsets = "'doc'";
7506: unless ($main_container_page) {
7507: $fieldsets .=",'ims'";
7508: }
7509: my $extfieldsets = "'ext'";
7510: if ($posslti) {
7511: $extfieldsets .= ",'tool'";
7512: }
7513: if ($supplementalflag) {
7514: $fieldsets = "'suppdoc'";
7515: $extfieldsets = "'suppext'";
7516: if ($posslti) {
7517: $extfieldsets .= ",'supptool'";
7518: }
7519: }
7520:
7521: my $jsmakefunctions;
7522: if ($canedit) {
7523: $jsmakefunctions = <<ENDNEWSCRIPT;
7524: function makenewfolder(targetform,folderseq) {
7525: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
7526: if (foldername) {
7527: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
7528: targetform.submit();
7529: }
7530: }
7531:
7532: function makenewpage(targetform,folderseq) {
7533: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
7534: if (pagename) {
7535: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
7536: targetform.submit();
7537: }
7538: }
7539:
7540: function makeexamupload() {
7541: var title=prompt('$js_lt{"p_mxu"}');
7542: if (title) {
7543: this.document.forms.newexamupload.importdetail.value=
7544: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
7545: this.document.forms.newexamupload.submit();
7546: }
7547: }
7548:
7549: function makesmppage() {
7550: var title=prompt('$js_lt{"p_msp"}');
7551: if (title) {
7552: this.document.forms.newsmppg.importdetail.value=
7553: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
7554: this.document.forms.newsmppg.submit();
7555: }
7556: }
7557:
7558: function makewebpage(type) {
7559: var title=prompt('$js_lt{"p_mwp"}');
7560: var formname;
7561: if (type == 'supp') {
7562: formname = this.document.forms.supwebpage;
7563: } else {
7564: formname = this.document.forms.newwebpage;
7565: }
7566: if (title) {
7567: var webpage = formname.importdetail.value;
7568: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
7569: formname.submit();
7570: }
7571: }
7572:
7573: function makesmpproblem() {
7574: var title=prompt('$js_lt{"p_msb"}');
7575: if (title) {
7576: this.document.forms.newsmpproblem.importdetail.value=
7577: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
7578: this.document.forms.newsmpproblem.submit();
7579: }
7580: }
7581:
7582: function makedropbox() {
7583: var title=prompt('$js_lt{"p_mdb"}');
7584: if (title) {
7585: this.document.forms.newdropbox.importdetail.value=
7586: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
7587: this.document.forms.newdropbox.submit();
7588: }
7589: }
7590:
7591: function makebulboard() {
7592: var title=prompt('$js_lt{"p_mbb"}');
7593: if (title) {
7594: this.document.forms.newbul.importdetail.value=
7595: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
7596: this.document.forms.newbul.submit();
7597: }
7598: }
7599:
7600: function makeabout() {
7601: var user=prompt("$js_lt{'p_mab'}");
7602: if (user) {
7603: var comp=new Array();
7604: comp=user.split(':');
7605: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7606: if ((comp[0]) && (comp[1])) {
7607: this.document.forms.newaboutsomeone.importdetail.value=
7608: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
7609: this.document.forms.newaboutsomeone.submit();
7610: } else {
7611: alert("$js_lt{'p_mab_alrt1'}");
7612: }
7613: } else {
7614: alert("$js_lt{'p_mab_alrt2'}");
7615: }
7616: }
7617: }
7618:
7619: function makenew(targetform) {
7620: targetform.submit();
7621: }
7622:
7623: function changename(folderpath,index,oldtitle) {
7624: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7625: if (title) {
7626: this.document.forms.renameform.markcopy.value='';
7627: this.document.forms.renameform.title.value=title;
7628: this.document.forms.renameform.cmd.value='rename_'+index;
7629: this.document.forms.renameform.folderpath.value=folderpath;
7630: this.document.forms.renameform.submit();
7631: }
7632: }
7633:
7634: function setalias(folderpath,index) {
7635: var alias = prompt('$js_lt{"setal"}');
7636: if ((alias != null) && (alias != '')) {
7637: this.document.forms.aliasform.alias.value=alias;
7638: this.document.forms.aliasform.cmd.value='setalias_'+index;
7639: this.document.forms.aliasform.folderpath.value=folderpath;
7640: this.document.forms.aliasform.submit();
7641: }
7642: }
7643:
7644: function delalias(folderpath,index) {
7645: if (confirm('$js_lt{"delal"}')) {
7646: this.document.forms.aliasform.cmd.value='delalias_'+index;
7647: this.document.forms.aliasform.folderpath.value=folderpath;
7648: this.document.forms.aliasform.submit();
7649: }
7650: }
7651:
7652: ENDNEWSCRIPT
7653: } else {
7654: $jsmakefunctions = <<ENDNEWSCRIPT;
7655:
7656: function makenewfolder() {
7657: alert("$js_lt{'edri'}");
7658: }
7659:
7660: function makenewpage() {
7661: alert("$js_lt{'edri'}");
7662: }
7663:
7664: function makeexamupload() {
7665: alert("$js_lt{'edri'}");
7666: }
7667:
7668: function makesmppage() {
7669: alert("$js_lt{'edri'}");
7670: }
7671:
7672: function makewebpage(type) {
7673: alert("$js_lt{'edri'}");
7674: }
7675:
7676: function makesmpproblem() {
7677: alert("$js_lt{'edri'}");
7678: }
7679:
7680: function makedropbox() {
7681: alert("$js_lt{'edri'}");
7682: }
7683:
7684: function makebulboard() {
7685: alert("$js_lt{'edri'}");
7686: }
7687:
7688: function makeabout() {
7689: alert("$js_lt{'edri'}");
7690: }
7691:
7692: function changename() {
7693: alert("$js_lt{'edri'}");
7694: }
7695:
7696: function setalias() {
7697: alert("$js_lt{'edri'}");
7698: }
7699:
7700: function delalias() {
7701: alert("$js_lt{'edri'}");
7702: }
7703:
7704: function makenew() {
7705: alert("$js_lt{'edri'}");
7706: }
7707:
7708: function groupimport() {
7709: alert("$js_lt{'edri'}");
7710: }
7711:
7712: function groupsearch() {
7713: alert("$js_lt{'edri'}");
7714: }
7715:
7716: function groupopen(url,recover) {
7717: var options="scrollbars=1,resizable=1,menubar=0";
7718: idxflag=1;
7719: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7720: idx.focus();
7721: }
7722:
7723: ENDNEWSCRIPT
7724:
7725: }
7726: return <<ENDSCRIPT;
7727:
7728: $jsmakefunctions
7729:
7730: function toggleUpload(caller) {
7731: var blocks = Array($fieldsets);
7732: for (var i=0; i<blocks.length; i++) {
7733: var disp = 'none';
7734: if (caller == blocks[i]) {
7735: var curr = document.getElementById('upload'+caller+'form').style.display;
7736: if (curr == 'none') {
7737: disp='block';
7738: }
7739: }
7740: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
7741: }
7742: resize_scrollbox('contentscroll','1','1');
7743: return;
7744: }
7745:
7746: function toggleExternal(caller) {
7747: var blocks = Array($extfieldsets);
7748: for (var i=0; i<blocks.length; i++) {
7749: var disp = 'none';
7750: if (caller == blocks[i]) {
7751: var curr = document.getElementById('external'+caller+'form').style.display;
7752: if (curr == 'none') {
7753: disp='block';
7754: }
7755: }
7756: document.getElementById('external'+blocks[i]+'form').style.display=disp;
7757: if ((caller == 'tool') || (caller == 'supptool')) {
7758: if (disp == 'block') {
7759: if (document.getElementById('LC_exttoolid')) {
7760: var toolselector = document.getElementById('LC_exttoolid');
7761: var suppflag = 0;
7762: if (caller == 'supptool') {
7763: suppflag = 1;
7764: }
7765: currForm = document.getElementById('new'+caller);
7766: updateExttool(toolselector,currForm,suppflag);
7767: }
7768: }
7769: }
7770: }
7771: resize_scrollbox('contentscroll','1','1');
7772: return;
7773: }
7774:
7775: function toggleMap(caller) {
7776: var disp = 'none';
7777: if (document.getElementById('importmapform')) {
7778: if (caller == 'map') {
7779: var curr = document.getElementById('importmapform').style.display;
7780: if (curr == 'none') {
7781: disp='block';
7782: }
7783: }
7784: document.getElementById('importmapform').style.display=disp;
7785: resize_scrollbox('contentscroll','1','1');
7786: }
7787: return;
7788: }
7789:
7790: function toggleCrsRes(caller) {
7791: var disp = 'none';
7792: if (document.getElementById('crsresform')) {
7793: if (caller == 'res') {
7794: var form = document.getElementById('crsresform');
7795: var curr = form.style.display;
7796: if (curr == 'none') {
7797: disp='block';
7798: document.courseresform.authorrole.selectedIndex = 0;
7799: document.courseresform.authorpath.selectedIndex = 0;
7800: document.courseresform.newresourceadd.selectedIndex = 0;
7801: populateDirSelects(form,'authorrole','authorpath',1,0,0);
7802: toggleNewInCourse(document.courseresform);
7803: if (document.getElementById('newresource')) {
7804: document.getElementById('newresource').style.display = 'none';
7805: }
7806: if (document.courseresform.newresusetemp.length) {
7807: document.courseresform.newresusetemp[0].checked = true;
7808: toggleWithTemplate(document.courseresform);
7809: }
7810: document.courseresform.newresourcename.value = '';
7811: }
7812: }
7813: if (document.courseresform.newsubdir.length) {
7814: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7815: if (document.courseresform.newsubdir[j].value == 0) {
7816: document.courseresform.newsubdir[j].checked = true;
7817: }
7818: break;
7819: }
7820: if (document.getElementById('newsubdirname')) {
7821: document.getElementById('newsubdirname').type = "hidden";
7822: document.getElementById('newsubdirname').value = "";
7823: }
7824: if (document.getElementById('newsubdir')) {
7825: document.getElementById('newsubdir').innerHTML = "";
7826: }
7827: }
7828: document.getElementById('crsresform').style.display=disp;
7829: resize_scrollbox('contentscroll','1','0');
7830: }
7831: return;
7832: }
7833:
7834: function toggleNewsubdir(form) {
7835: if (form.newsubdir.length) {
7836: for (var j=0; j<form.newsubdir.length; j++) {
7837: if (form.newsubdir[j].checked) {
7838: if (document.getElementById('newsubdirname')) {
7839: if (form.newsubdir[j].value == '1') {
7840: document.getElementById('newsubdirname').type = "text";
7841: if (document.getElementById('newsubdir')) {
7842: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7843: }
7844: } else {
7845: document.getElementById('newsubdirname').type = "hidden";
7846: document.getElementById('newsubdirname').value = "";
7847: document.getElementById('newsubdir').innerHTML = "";
7848: }
7849: }
7850: break;
7851: }
7852: }
7853: }
7854: }
7855:
7856: function toggleCrsResTitle() {
7857: if (document.getElementById('newresource')) {
7858: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
7859: if (selloc == 'course') {
7860: document.getElementById('newresource').style.display = 'inline';
7861: document.courseresform.newresourceadd[0].checked = true;
7862: toggleNewInCourse(document.courseresform);
7863: } else {
7864: document.getElementById('newresource').style.display = 'none';
7865: }
7866: }
7867: if (document.getElementById('newstdproblem')) {
7868: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
7869: document.getElementById('newstdproblem').style.display = 'none';
7870: if (document.getElementById('stdprobswitch')) {
7871: document.getElementById('stdprobswitch').style.display = 'block';
7872: }
7873: } else {
7874: document.getElementById('newstdproblem').style.display = 'block';
7875: if (document.getElementById('stdprobswitch')) {
7876: document.getElementById('stdprobswitch').style.display = 'none';
7877: }
7878: }
7879: }
7880: }
7881:
7882: function toggleNewInCourse(form) {
7883: if (form.newresourceadd.length) {
7884: for (var i=0; i<form.newresourceadd.length; i++) {
7885: if (form.newresourceadd[i].checked) {
7886: if (document.getElementById('newresourcetitle')) {
7887: if (form.newresourceadd[i].value == '1') {
7888: document.getElementById('newresourcetitle').type = 'text';
7889: if (document.getElementById('newrestitle')) {
7890: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7891: }
7892: } else {
7893: document.getElementById('newresourcetitle').type = 'hidden';
7894: document.getElementById('newresourcetitle').value = '';
7895: if (document.getElementById('newrestitle')) {
7896: document.getElementById('newrestitle').innerHTML = '';
7897: }
7898: }
7899: }
7900: break;
7901: }
7902: }
7903: }
7904: }
7905:
7906: function toggleWithTemplate(form) {
7907: if (form.newresusetemp.length) {
7908: for (var i=0; i<form.newresusetemp.length; i++) {
7909: if (form.newresusetemp[i].checked) {
7910: if (document.getElementById('newrestemplate')) {
7911: if (form.newresusetemp[i].value == '1') {
7912: document.getElementById('newrestemplate').style.display = 'inline';
7913: toggleExampleText();
7914: } else {
7915: form.tempcategory.selectedIndex = 0;
7916: select1template_changed();
7917: document.getElementById('newrestemplate').style.display = 'none';
7918: }
7919: }
7920: }
7921: }
7922: }
7923: }
7924:
7925: function toggleExampleText() {
7926: if (document.getElementById('newresexample')) {
7927: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7928: if (url == '') {
7929: document.getElementById('newresexample').style.fontWeight = 'normal';
7930: } else {
7931: document.getElementById('newresexample').style.fontWeight = 'bold';
7932: }
7933: }
7934: }
7935:
7936: function getExample(width,height,scrolling,transparency) {
7937: var url;
7938: if (document.courseresform.newresusetemp.length) {
7939: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7940: if (document.courseresform.newresusetemp[i].checked) {
7941: if (document.courseresform.newresusetemp[i].value == '1') {
7942: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7943: if (url == '') {
7944: alert('Pick a category and template');
7945: } else {
7946: url = url.replace("$londocroot","");
7947: url += '?inhibitmenu=yes';
7948: }
7949: }
7950: break;
7951: }
7952: }
7953: }
7954: if (url != '') {
7955: openMyModal(url,width,height,scrolling,transparency,'');
7956: }
7957: }
7958:
7959: function toggleImportCrsres(caller) {
7960: var disp = 'none';
7961: if (document.getElementById('importcrsresform')) {
7962: if (caller == 'res') {
7963: var curr = document.getElementById('importcrsresform').style.display;
7964: if (curr == 'none') {
7965: disp='block';
7966: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1);
7967: }
7968: }
7969: document.getElementById('importcrsresform').style.display=disp;
7970: resize_scrollbox('contentscroll','1','0');
7971: }
7972: return;
7973: }
7974:
7975: $showfile_js
7976:
7977: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
7978: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
7979: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
7980: var selelem = form.elements[dirsel];
7981: var i, numfiles = selelem.options.length -1;
7982: if (numfiles >=0) {
7983: for (i = numfiles; i >= 0; i--) {
7984: selelem.remove(i);
7985: }
7986: }
7987: if ((location == '') || (location == null) || (location == 'undefined')) {
7988: if (selelem.options.length == 0) {
7989: selelem.options[selelem.options.length] = new Option('','');
7990: selelem.selectedIndex = 0;
7991: }
7992: if (document.getElementById('newstdproblem')) {
7993: document.getElementById('newstdproblem').style.display = 'none';
7994: }
7995: return;
7996: }
7997: var machineIds = new Array($machines_str);
7998: var athome = 0;
7999: var role = location;
8000: if ((location == 'author') || (location == 'course')) {
8001: if (document.getElementById('rolehome_'+location)) {
8002: var currhome = document.getElementById('rolehome_'+location).value;
8003: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8004: if (machineIds.includes(currhome)) {
8005: athome = 1;
8006: }
8007: }
8008: }
8009: } else {
8010: const roleinfo = location.split('___');
8011: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
8012: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
8013: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
8014: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8015: if (machineIds.includes(currhome)) {
8016: athome = 1;
8017: }
8018: }
8019: }
8020: }
8021: if (athome) {
8022: if (document.getElementById('stdprobswitch')) {
8023: document.getElementById('stdprobswitch').style.display = 'none';
8024: }
8025: if (document.getElementById('newstdproblem')) {
8026: document.getElementById('newstdproblem').style.display = 'none';
8027: }
8028: var http = new XMLHttpRequest();
8029: var url = "/adm/courseauthor";
8030: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir;
8031: http.open("POST", url, true);
8032: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
8033: http.onreadystatechange = function() {
8034: if (http.readyState == 4 && http.status == 200) {
8035: var data = JSON.parse(http.responseText);
8036: if (Array.isArray(data.dirs)) {
8037: var len = data.dirs.length;
8038: if (len) {
8039: if (len > 1) {
8040: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
8041: }
8042: }
8043: if (len) {
8044: var j;
8045: for (j = 0; j < len; j++) {
8046: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
8047: }
8048: selelem.selectedIndex = 0;
8049: }
8050: }
8051: }
8052: }
8053: http.send(params);
8054: } else {
8055: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
8056: selelem.selectedIndex = 0;
8057: if (document.getElementById('stdprobswitch')) {
8058: document.getElementById('stdprobswitch').style.display = 'block';
8059: }
8060: if (document.getElementById('newstdproblem')) {
8061: document.getElementById('newstdproblem').style.display = 'none';
8062: }
8063: }
8064: }
8065: return;
8066: }
8067:
8068: function switchForProb() {
8069: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8070: var url = '/adm/switchserver?otherserver=';
8071: var newhostid = '';
8072: var role = '';
8073: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8074: if (selloc == 'author') {
8075: newhostid = document.courseresform.rolehome_author.value;
8076: role = "au./&js_escape($env{'user.domain'})/";
8077: } else if (selloc == 'course') {
8078: newhostid = document.courseresform.rolehome_course.value;
8079: role = "&js_escape($env{'request.role'})";
8080: } else {
8081: var items = new Array();
8082: items = selloc.split('___');
8083: var len = document.courseresform.rolehome_coauthor.length;
8084: if (null == len) {
8085: var currval = document.courseresform.rolehome_coauthor.value;
8086: if (null != currval) {
8087: var info = new Array();
8088: info = currval.split('=');
8089: newhostid = info[2];
8090: role = info[0]+'./'+info[1];
8091: }
8092: } else {
8093: for (var i=0; i<len; i++) {
8094: var currval = document.courseresform.rolehome_coauthor[i].value;
8095: if (null != currval) {
8096: var info = new Array();
8097: info = currval.split('=');
8098: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
8099: newhostid = info[2];
8100: role = info[0]+'./'+info[1];
8101: break;
8102: }
8103: }
8104: }
8105: }
8106: }
8107: if (newhostid != '') {
8108: url += newhostid;
8109: if (role != '') {
8110: url += '&role='+role;
8111: }
8112: document.location.href = url;
8113: }
8114: }
8115: return;
8116: }
8117:
8118: function makeims(imsform) {
8119: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
8120: alert("$js_lt{'imsfile'}");
8121: return;
8122: }
8123: if (imsform.source.selectedIndex == 0) {
8124: alert("$js_lt{'imscms'}");
8125: return;
8126: }
8127: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
8128: imsform.submit();
8129: }
8130:
8131: function updatePick(targetform,index,caller) {
8132: var pickitem;
8133: var picknumitem;
8134: var picknumtext;
8135: if (index == 'all') {
8136: pickitem = document.getElementById('randompickall');
8137: picknumitem = document.getElementById('rpicknumall');
8138: picknumtext = document.getElementById('rpicktextall');
8139: } else {
8140: pickitem = document.getElementById('randompick_'+index);
8141: picknumitem = document.getElementById('rpicknum_'+index);
8142: picknumtext = document.getElementById('randompicknum_'+index);
8143: }
8144: if (pickitem.checked) {
8145: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
8146: if (picknum == '' || picknum == null) {
8147: if (caller == 'check') {
8148: pickitem.checked=false;
8149: if (index == 'all') {
8150: picknumtext.innerHTML = '';
8151: if (caller == 'link') {
8152: propagateState(targetform,'rpicknum');
8153: }
8154: } else {
8155: checkForSubmit(targetform,'randompick','settings');
8156: }
8157: }
8158: } else {
8159: picknum.toString();
8160: var regexdigit=/^\\d+\$/;
8161: if (regexdigit.test(picknum)) {
8162: picknumitem.value = picknum;
8163: if (index == 'all') {
8164: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
8165: if (caller == 'link') {
8166: propagateState(targetform,'rpicknum');
8167: }
8168: } else {
8169: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
8170: checkForSubmit(targetform,'randompick','settings');
8171: }
8172: } else {
8173: if (caller == 'check') {
8174: if (index == 'all') {
8175: picknumtext.innerHTML = '';
8176: if (caller == 'link') {
8177: propagateState(targetform,'rpicknum');
8178: }
8179: } else {
8180: pickitem.checked=false;
8181: checkForSubmit(targetform,'randompick','settings');
8182: }
8183: }
8184: return;
8185: }
8186: }
8187: } else {
8188: picknumitem.value = '';
8189: picknumtext.innerHTML = '';
8190: if (index == 'all') {
8191: if (caller == 'link') {
8192: propagateState(targetform,'rpicknum');
8193: }
8194: } else {
8195: checkForSubmit(targetform,'randompick','settings');
8196: }
8197: }
8198: }
8199:
8200: function propagateState(form,param) {
8201: if (document.getElementById(param+'all')) {
8202: var setcheck = 0;
8203: var rpick = 0;
8204: if (param == 'rpicknum') {
8205: if (document.getElementById('randompickall')) {
8206: if (document.getElementById('randompickall').checked) {
8207: if (document.getElementById('rpicknumall')) {
8208: rpick = document.getElementById('rpicknumall').value;
8209: }
8210: }
8211: }
8212: } else {
8213: if (document.getElementById(param+'all').checked) {
8214: setcheck = 1;
8215: }
8216: }
8217: var allidxlist;
8218: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8219: if (document.getElementById('all'+param+'idx')) {
8220: allidxlist = document.getElementById('all'+param+'idx').value;
8221: }
8222: var actions = new Array ('remove','cut','copy');
8223: for (var i=0; i<actions.length; i++) {
8224: if (actions[i] != param) {
8225: if (document.getElementById(actions[i]+'all')) {
8226: document.getElementById(actions[i]+'all').checked = false;
8227: }
8228: }
8229: }
8230: }
8231: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
8232: allidxlist = form.allidx.value;
8233: }
8234: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
8235: allidxlist = form.allmapidx.value;
8236: }
8237: if ((allidxlist != '') && (allidxlist != null)) {
8238: var allidxs = allidxlist.split(',');
8239: if (allidxs.length > 1) {
8240: for (var i=0; i<allidxs.length; i++) {
8241: if (document.getElementById(param+'_'+allidxs[i])) {
8242: if (param == 'rpicknum') {
8243: if (document.getElementById('randompick_'+allidxs[i])) {
8244: if (document.getElementById('randompick_'+allidxs[i]).checked) {
8245: document.getElementById(param+'_'+allidxs[i]).value = rpick;
8246: if (rpick > 0) {
8247: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
8248: } else {
8249: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8250: }
8251: }
8252: }
8253: } else {
8254: if (setcheck == 1) {
8255: document.getElementById(param+'_'+allidxs[i]).checked = true;
8256: } else {
8257: document.getElementById(param+'_'+allidxs[i]).checked = false;
8258: if (param == 'randompick') {
8259: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8260: }
8261: }
8262: }
8263: }
8264: }
8265: if (setcheck == 1) {
8266: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8267: var actions = new Array('copy','cut','remove');
8268: for (var i=0; i<actions.length; i++) {
8269: var otheractions;
8270: var otheridxs;
8271: if (actions[i] === param) {
8272: continue;
8273: } else {
8274: if (document.getElementById('all'+actions[i]+'idx')) {
8275: otheractions = document.getElementById('all'+actions[i]+'idx').value;
8276: otheridxs = otheractions.split(',');
8277: if (otheridxs.length > 1) {
8278: for (var j=0; j<otheridxs.length; j++) {
8279: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
8280: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
8281: }
8282: }
8283: }
8284: }
8285: }
8286: }
8287: }
8288: }
8289: }
8290: }
8291: }
8292: return;
8293: }
8294:
8295: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
8296: var canedit = '$canedit';
8297: if (canedit == '') {
8298: alert("$js_lt{'edri'}");
8299: return;
8300: }
8301: var dosettings;
8302: var doaction;
8303: var control = document.togglemultsettings;
8304: if (context == 'actions') {
8305: control = document.togglemultactions;
8306: doaction = 1;
8307: } else {
8308: dosettings = 1;
8309: }
8310: if (control) {
8311: if (control.showmultpick.length) {
8312: for (var i=0; i<control.showmultpick.length; i++) {
8313: if (control.showmultpick[i].checked) {
8314: if (control.showmultpick[i].value == 1) {
8315: if (context == 'settings') {
8316: dosettings = 0;
8317: } else {
8318: doaction = 0;
8319: }
8320: }
8321: }
8322: }
8323: }
8324: }
8325: if (context == 'settings') {
8326: if (dosettings == 1) {
8327: targetform.changeparms.value=param;
8328: targetform.submit();
8329: }
8330: }
8331: if (context == 'actions') {
8332: if (doaction == 1) {
8333: targetform.cmd.value=param+'_'+index;
8334: targetform.folderpath.value=folderpath;
8335: targetform.markcopy.value=idx+':'+param;
8336: targetform.copyfolder.value=folder+'.'+container;
8337: if (param == 'remove') {
8338: var doremove = 0;
8339: if (skip_confirm) {
8340: if (confirm_removal) {
8341: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8342: doremove = 1;
8343: }
8344: } else {
8345: doremove = 1;
8346: }
8347: } else {
8348: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8349: doremove = 1;
8350: }
8351: }
8352: if (doremove) {
8353: targetform.markcopy.value='';
8354: targetform.copyfolder.value='';
8355: targetform.submit();
8356: }
8357: }
8358: if (param == 'cut') {
8359: if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) {
8360: targetform.submit();
8361: return;
8362: }
8363: }
8364: if (param == 'copy') {
8365: targetform.submit();
8366: return;
8367: }
8368: targetform.markcopy.value='';
8369: targetform.copyfolder.value='';
8370: targetform.cmd.value='';
8371: targetform.folderpath.value='';
8372: return;
8373: } else {
8374: if (document.getElementById(param+'_'+idx)) {
8375: item = document.getElementById(param+'_'+idx);
8376: if (item.type == 'checkbox') {
8377: if (item.checked) {
8378: item.checked = false;
8379: } else {
8380: item.checked = true;
8381: singleCheck(item,idx,param);
8382: }
8383: }
8384: }
8385: }
8386: }
8387: return;
8388: }
8389:
8390: function singleCheck(caller,idx,action) {
8391: actions = new Array('cut','copy','remove');
8392: if (caller.checked) {
8393: for (var i=0; i<actions.length; i++) {
8394: if (actions[i] != action) {
8395: if (document.getElementById(actions[i]+'_'+idx)) {
8396: if (document.getElementById(actions[i]+'_'+idx).checked) {
8397: document.getElementById(actions[i]+'_'+idx).checked = false;
8398: }
8399: }
8400: }
8401: }
8402: }
8403: return;
8404: }
8405:
8406: function unselectInactive(nav) {
8407: currentNav = document.getElementById(nav);
8408: currentLis = currentNav.getElementsByTagName('LI');
8409: for (i = 0; i < currentLis.length; i++) {
8410: if (currentLis[i].className == 'goback') {
8411: currentLis[i].className = 'goback';
8412: } else {
8413: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
8414: currentLis[i].className = 'right';
8415: } else {
8416: currentLis[i].className = 'i';
8417: }
8418: }
8419: }
8420: }
8421:
8422: function hideAll(current, nav, data) {
8423: unselectInactive(nav);
8424: if (current) {
8425: if (current.className == 'right'){
8426: current.className = 'right active'
8427: } else {
8428: current.className = 'active';
8429: }
8430: }
8431: currentData = document.getElementById(data);
8432: currentDivs = currentData.getElementsByTagName('DIV');
8433: for (i = 0; i < currentDivs.length; i++) {
8434: if(currentDivs[i].className == 'LC_ContentBox'){
8435: currentDivs[i].style.display = 'none';
8436: }
8437: }
8438: }
8439:
8440: function openTabs(pageId) {
8441: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
8442: if(tabnav.length > 2 ){
8443: currentNav = document.getElementById(tabnav[1].id);
8444: currentLis = currentNav.getElementsByTagName('LI');
8445: for(i = 0; i< currentLis.length; i++){
8446: if(currentLis[i].className == 'active') {
8447: funcString = currentLis[i].onclick.toString();
8448: tab = funcString.split('"');
8449: if(tab.length < 2) {
8450: tab = funcString.split("'");
8451: }
8452: currentData = document.getElementById(tab[1]);
8453: currentData.style.display = 'block';
8454: }
8455: }
8456: }
8457: }
8458:
8459: function showPage(current, pageId, nav, data) {
8460: currstate = current.className;
8461: hideAll(current, nav, data);
8462: openTabs(pageId);
8463: unselectInactive(nav);
8464: if ((currstate == 'active') || (currstate == 'right active')) {
8465: if (currstate == 'active') {
8466: current.className = '';
8467: } else {
8468: current.className = 'right';
8469: }
8470: activeTab = '';
8471: toggleExternal();
8472: toggleUpload();
8473: toggleMap();
8474: toggleCrsRes();
8475: toggleImportCrsres();
8476: resize_scrollbox('contentscroll','1','0');
8477: return;
8478: } else {
8479: current.className = 'active';
8480: }
8481: currentData = document.getElementById(pageId);
8482: currentData.style.display = 'block';
8483: activeTab = pageId;
8484: toggleExternal();
8485: toggleUpload();
8486: toggleMap();
8487: toggleCrsRes();
8488: toggleImportCrsres();
8489: if (nav == 'mainnav') {
8490: var storedpath = "$docs_folderpath";
8491: var storedpage = "$main_container_page";
8492: var reg = new RegExp("^supplemental");
8493: if (pageId == 'mainCourseDocuments') {
8494: if (storedpage == 1) {
8495: document.simpleedit.folderpath.value = '';
8496: document.uploaddocument.folderpath.value = '';
8497: } else {
8498: if (reg.test(storedpath)) {
8499: document.simpleedit.folderpath.value = '$toplevelmain';
8500: document.uploaddocument.folderpath.value = '$toplevelmain';
8501: document.newext.folderpath.value = '$toplevelmain';
8502: } else {
8503: document.simpleedit.folderpath.value = storedpath;
8504: document.uploaddocument.folderpath.value = storedpath;
8505: document.newext.folderpath.value = storedpath;
8506: }
8507: }
8508: } else {
8509: if (reg.test(storedpath)) {
8510: document.simpleedit.folderpath.value = storedpath;
8511: document.supuploaddocument.folderpath.value = storedpath;
8512: document.supnewext.folderpath.value = storedpath;
8513: } else {
8514: document.simpleedit.folderpath.value = '$toplevelsupp';
8515: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8516: document.supnewext.folderpath.value = '$toplevelsupp';
8517: }
8518: }
8519: }
8520: resize_scrollbox('contentscroll','1','0');
8521: return false;
8522: }
8523:
8524: function toContents(jumpto) {
8525: var newurl = '$backtourl';
8526: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
8527: newurl = newurl+'?postdata='+jumpto;
8528: }
8529: location.href=newurl;
8530: }
8531:
8532: function togglePick(caller,value) {
8533: var disp = 'none';
8534: if (document.getElementById('multi'+caller)) {
8535: var curr = document.getElementById('multi'+caller).style.display;
8536: if (value == 1) {
8537: disp='block';
8538: }
8539: if (curr == disp) {
8540: return;
8541: }
8542: document.getElementById('multi'+caller).style.display=disp;
8543: if (value == 1) {
8544: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
8545: } else {
8546: document.getElementById('more'+caller).innerHTML = '';
8547: }
8548: if (caller == 'actions') {
8549: setClass(value);
8550: setBoxes(value);
8551: }
8552: }
8553: var showButton = multiSettings();
8554: if (showButton != 1) {
8555: showButton = multiActions();
8556: }
8557: if (document.getElementById('multisave')) {
8558: if (showButton == 1) {
8559: document.getElementById('multisave').style.display='block';
8560: } else {
8561: document.getElementById('multisave').style.display='none';
8562: }
8563: }
8564: resize_scrollbox('contentscroll','1','1');
8565: return;
8566: }
8567:
8568: function toggleCheckUncheck(caller,more) {
8569: if (more == 1) {
8570: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
8571: document.getElementById('allfields'+caller).style.display='block';
8572: } else {
8573: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
8574: document.getElementById('allfields'+caller).style.display='none';
8575: }
8576: resize_scrollbox('contentscroll','1','1');
8577: }
8578:
8579: function multiSettings() {
8580: var inuse = 0;
8581: var settingsform = document.togglemultsettings;
8582: if (settingsform.showmultpick.length > 1) {
8583: for (var i=0; i<settingsform.showmultpick.length; i++) {
8584: if (settingsform.showmultpick[i].checked) {
8585: if (settingsform.showmultpick[i].value == 1) {
8586: inuse = 1;
8587: }
8588: }
8589: }
8590: }
8591: return inuse;
8592: }
8593:
8594: function multiActions() {
8595: var inuse = 0;
8596: var actionsform = document.togglemultactions;
8597: if (actionsform.showmultpick.length > 1) {
8598: for (var i=0; i<actionsform.showmultpick.length; i++) {
8599: if (actionsform.showmultpick[i].checked) {
8600: if (actionsform.showmultpick[i].value == 1) {
8601: inuse = 1;
8602: }
8603: }
8604: }
8605: }
8606: return inuse;
8607: }
8608:
8609: function checkSubmits() {
8610: var numchanges = 0;
8611: var form = document.saveactions;
8612: var doactions = multiActions();
8613: var cutwarnings = 0;
8614: var remwarnings = 0;
8615: var removalinfo = 0;
8616: if (doactions == 1) {
8617: var remidxlist = document.cumulativeactions.allremoveidx.value;
8618: if ((remidxlist != '') && (remidxlist != null)) {
8619: var remidxs = remidxlist.split(',');
8620: for (var i=0; i<remidxs.length; i++) {
8621: if (document.getElementById('remove_'+remidxs[i])) {
8622: if (document.getElementById('remove_'+remidxs[i]).checked) {
8623: form.multiremove.value += remidxs[i]+',';
8624: numchanges ++;
8625: if (document.getElementById('skip_remove_'+remidxs[i])) {
8626: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8627: remwarnings ++;
8628: }
8629: }
8630: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8631: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8632: removalinfo ++;
8633: }
8634: }
8635: }
8636: }
8637: }
8638: }
8639: var cutidxlist = document.cumulativeactions.allcutidx.value;
8640: if ((cutidxlist != '') && (cutidxlist != null)) {
8641: var cutidxs = cutidxlist.split(',');
8642: for (var i=0; i<cutidxs.length; i++) {
8643: if (document.getElementById('cut_'+cutidxs[i])) {
8644: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8645: form.multicut.value += cutidxs[i]+',';
8646: numchanges ++;
8647: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8648: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8649: cutwarnings ++;
8650: }
8651: }
8652: }
8653: }
8654: }
8655: }
8656: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8657: if ((copyidxlist != '') && (copyidxlist != null)) {
8658: var copyidxs = copyidxlist.split(',');
8659: for (var i=0; i<copyidxs.length; i++) {
8660: if (document.getElementById('copy_'+copyidxs[i])) {
8661: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8662: form.multicopy.value += copyidxs[i]+',';
8663: numchanges ++;
8664: }
8665: }
8666: }
8667: }
8668: if (numchanges > 0) {
8669: form.multichange.value = numchanges;
8670: }
8671: }
8672: var dosettings = multiSettings();
8673: var haschanges = 0;
8674: if (dosettings == 1) {
8675: form.allencrypturl.value = '';
8676: form.allhiddenresource.value = '';
8677: form.changeparms.value = 'all';
8678: var patt=new RegExp(",\$");
8679: var allidxlist = document.cumulativesettings.allidx.value;
8680: if ((allidxlist != '') && (allidxlist != null)) {
8681: var allidxs = allidxlist.split(',');
8682: if (allidxs.length > 1) {
8683: for (var i=0; i<allidxs.length; i++) {
8684: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8685: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8686: form.allhiddenresource.value += allidxs[i]+',';
8687: }
8688: }
8689: if (document.getElementById('encrypturl_'+allidxs[i])) {
8690: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8691: form.allencrypturl.value += allidxs[i]+',';
8692: }
8693: }
8694: }
8695: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8696: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
8697: }
8698: }
8699: form.allrandompick.value = '';
8700: form.allrandomorder.value = '';
8701: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8702: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8703: var allmapidxs = allmapidxlist.split(',');
8704: for (var i=0; i<allmapidxs.length; i++) {
8705: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8706: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8707: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8708: if ((randompick.checked) && (rpicknum.value != '')) {
8709: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8710: }
8711: if (randorder.checked) {
8712: form.allrandomorder.value += allmapidxs[i]+',';
8713: }
8714: }
8715: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8716: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8717: }
8718: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8719: haschanges = 1;
8720: }
8721: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8722: haschanges = 1;
8723: }
8724: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8725: haschanges = 1;
8726: }
8727: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8728: haschanges = 1;
8729: }
8730: }
8731: if (doactions == 1) {
8732: if (numchanges > 0) {
8733: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
8734: if (remwarnings > 0) {
8735: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
8736: return false;
8737: }
8738: }
8739: if (removalinfo > 0) {
8740: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8741: return false;
8742: }
8743: }
8744: if (cutwarnings > 0) {
8745: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
8746: return false;
8747: }
8748: }
8749: }
8750: form.submit();
8751: return true;
8752: }
8753: }
8754: if (dosettings == 1) {
8755: if (haschanges == 1) {
8756: form.submit();
8757: return true;
8758: }
8759: }
8760: if ((dosettings == 1) && (doactions == 1)) {
8761: alert("$js_lt{'noor'}");
8762: } else {
8763: if (dosettings == 1) {
8764: alert("$js_lt{'noch'}");
8765: } else {
8766: alert("$js_lt{'noac'}");
8767: }
8768: }
8769: return false;
8770: }
8771:
8772: function setClass(value) {
8773: var cutclass = 'LC_docs_cut';
8774: var copyclass = 'LC_docs_copy';
8775: var removeclass = 'LC_docs_remove';
8776: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8777: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8778: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8779: var links = document.getElementsByTagName('a');
8780: for (var i=0; i<links.length; i++) {
8781: var classes = links[i].className;
8782: if (cutreg.test(classes)) {
8783: links[i].className = cutclass;
8784: if (value == 1) {
8785: links[i].className += " LC_menubuttons_link";
8786: }
8787: } else {
8788: if (copyreg.test(classes)) {
8789: links[i].className = copyclass;
8790: if (value == 1) {
8791: links[i].className += " LC_menubuttons_link";
8792: }
8793: } else {
8794: if (removereg.test(classes)) {
8795: links[i].className = removeclass;
8796: if (value == 1) {
8797: links[i].className += " LC_menubuttons_link";
8798: }
8799: }
8800: }
8801: }
8802: }
8803: return;
8804: }
8805:
8806: function setBoxes(value) {
8807: var remidxlist = document.cumulativeactions.allremoveidx.value;
8808: if ((remidxlist != '') && (remidxlist != null)) {
8809: var remidxs = remidxlist.split(',');
8810: for (var i=0; i<remidxs.length; i++) {
8811: if (document.getElementById('remove_'+remidxs[i])) {
8812: var item = document.getElementById('remove_'+remidxs[i]);
8813: if (value == 1) {
8814: item.className = 'LC_docs_remove';
8815: } else {
8816: item.className = 'LC_hidden';
8817: }
8818: }
8819: }
8820: }
8821: var cutidxlist = document.cumulativeactions.allcutidx.value;
8822: if ((cutidxlist != '') && (cutidxlist != null)) {
8823: var cutidxs = cutidxlist.split(',');
8824: for (var i=0; i<cutidxs.length; i++) {
8825: if (document.getElementById('cut_'+cutidxs[i])) {
8826: var item = document.getElementById('cut_'+cutidxs[i]);
8827: if (value == 1) {
8828: item.className = 'LC_docs_cut';
8829: } else {
8830: item.className = 'LC_hidden';
8831: }
8832: }
8833: }
8834: }
8835: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8836: if ((copyidxlist != '') && (copyidxlist != null)) {
8837: var copyidxs = copyidxlist.split(',');
8838: for (var i=0; i<copyidxs.length; i++) {
8839: if (document.getElementById('copy_'+copyidxs[i])) {
8840: var item = document.getElementById('copy_'+copyidxs[i]);
8841: if (value == 1) {
8842: item.className = 'LC_docs_copy';
8843: } else {
8844: item.className = 'LC_hidden';
8845: }
8846: }
8847: }
8848: }
8849: return;
8850: }
8851:
8852: function validImportCrsRes() {
8853: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8854: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8855: if ((fname == '') || (fname == null)) {
8856: alert("$js_lt{'nofi'}");
8857: return false;
8858: }
8859: var url = '/res/$coursedom/$coursenum/';
8860: if (path && path != '/') {
8861: url += path+'/';
8862: }
8863: if (fname != '') {
8864: url += fname;
8865: }
8866: var title = document.crsresimportform.crsrestitle.value;
8867: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
8868: return true;
8869: }
8870:
8871: function validateNewRes(caller) {
8872: if (caller == 'single') {
8873: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8874: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8875: var resname = document.courseresform.newresourcename.value;
8876: }
8877: }
8878:
8879: ENDSCRIPT
8880: }
8881:
8882: sub history_tab_js {
8883: return <<"ENDHIST";
8884: function toggleHistoryDisp(choice) {
8885: document.docslogform.docslog.value = choice;
8886: document.docslogform.submit();
8887: return;
8888: }
8889:
8890: ENDHIST
8891: }
8892:
8893: sub inject_data_js {
8894: return <<ENDINJECT;
8895:
8896: function injectData(current, hiddenField, name, value) {
8897: currentElement = document.getElementById(hiddenField);
8898: currentElement.name = name;
8899: currentElement.value = value;
8900: current.submit();
8901: }
8902:
8903: ENDINJECT
8904: }
8905:
8906: sub dump_switchserver_js {
8907: my @hosts = @_;
8908: my %js_lt = &Apache::lonlocal::texthash(
8909: dump => 'Copying content to Authoring Space requires switching server.',
8910: swit => 'Switch server?',
8911: );
8912: my %html_js_lt = &Apache::lonlocal::texthash(
8913: swit => 'Switch server?',
8914: duco => 'Copying Content to Authoring Space',
8915: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8916: chos => 'Choose server',
8917: );
8918: &js_escape(\%js_lt);
8919: &html_escape(\%html_js_lt);
8920: &js_escape(\%html_js_lt);
8921: my $role = $env{'request.role'};
8922: my $js = <<"ENDSWJS";
8923: <script type="text/javascript">
8924: function write_switchserver() {
8925: var server;
8926: if (document.setserver.posshosts.length > 0) {
8927: for (var i=0; i<document.setserver.posshosts.length; i++) {
8928: if (document.setserver.posshosts[i].checked) {
8929: server = document.setserver.posshosts[i].value;
8930: }
8931: }
8932: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8933: }
8934: window.close();
8935: }
8936: </script>
8937:
8938: ENDSWJS
8939:
8940: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8941: {'only_body' => 1,
8942: 'js_ready' => 1,});
8943: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8944:
8945: my $hostpicker;
8946: my $count = 0;
8947: foreach my $host (sort(@hosts)) {
8948: my $checked;
8949: if ($count == 0) {
8950: $checked = ' checked="checked"';
8951: }
8952: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8953: $host.'"'.$checked.' />'.$host.'</label> ';
8954: $count++;
8955: }
8956:
8957: return <<"ENDSWITCHJS";
8958:
8959: function dump_needs_switchserver(url) {
8960: if (url!='' && url!= null) {
8961: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
8962: go(url);
8963: }
8964: }
8965: return;
8966: }
8967:
8968: function choose_switchserver_window() {
8969: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8970: newWindow.document.open();
8971: newWindow.document.writeln('$startpage');
8972: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8973: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8974: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
8975: '<form name="setserver" method="post" action="" \\/>\\n'+
8976: '$hostpicker\\n'+
8977: '<br \\/><br \\/>\\n'+
8978: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
8979: 'onclick="write_switchserver();" \\/>\\n'+
8980: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8981: newWindow.document.writeln('$endpage');
8982: newWindow.document.close();
8983: newWindow.focus();
8984: }
8985:
8986: ENDSWITCHJS
8987: }
8988:
8989: sub makedocslogform {
8990: my ($formelems,$docslog) = @_;
8991: return <<"LOGSFORM";
8992: <form action="/adm/coursedocs" method="post" name="docslogform">
8993: <input type="hidden" name="docslog" value="$docslog" />
8994: $formelems
8995: </form>
8996: LOGSFORM
8997: }
8998:
8999: sub makesimpleeditform {
9000: my ($formelems) = @_;
9001: return <<"SIMPFORM";
9002: <form name="simpleedit" method="post" action="/adm/coursedocs">
9003: <input type="hidden" name="importdetail" value="" />
9004: $formelems
9005: </form>
9006: SIMPFORM
9007: }
9008:
9009: sub makenewproblem {
9010: my ($r,$coursedom,$coursenum) = @_;
9011: # Creating a new problem
9012: my ($redirect,$error);
9013: if ($env{'form.authorrole'}) {
9014: my ($newsubdir,$filename);
9015: if ($env{'form.newsubdir'}) {
9016: if ($env{'form.newsubdirname'} ne '') {
9017: $newsubdir = $env{'form.newsubdirname'};
9018: }
9019: }
9020: if ($env{'form.newresourcename'}) {
9021: $filename = $env{'form.newresourcename'};
9022: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
9023: $filename =~ s/`//g;
9024: $filename =~ s{/\.\./}{_}g;
9025: $filename =~ s/\.+/./g;
9026: $filename =~ s{/+}{_}g;
9027: if ($filename ne '') {
9028: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
9029: if (($ext) && ($ext ne '.problem')) {
9030: $filename = $name.'.problem';
9031: } elsif ($ext eq '') {
9032: $filename .= '.problem';
9033: }
9034: my $docroot = $r->dir_config('lonDocRoot');
9035: my @ids=&Apache::lonnet::current_machine_ids();
9036: if ($env{'form.authorrole'} eq 'author') {
9037: if ($env{'user.author'}) {
9038: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
9039: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
9040: my $path = $docroot.$url;
9041: my $subdir = $env{'form.authorpath'};
9042: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9043: }
9044: }
9045: } elsif ($env{'form.authorrole'} eq 'course') {
9046: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
9047: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
9048: my $url = "/priv/$coursedom/$coursenum";
9049: my $path=$docroot.$url;
9050: my $subdir = $env{'form.authorpath'};
9051: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9052: if ($redirect) {
9053: my $rightsfile = 'default.rights';
9054: my $sourcerights = "$path/$rightsfile";
9055: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
9056: my $now = time;
9057: if (!-e $sourcerights) {
9058: my $cid = $coursedom.'_'.$coursenum;
9059: if (open(my $fh,">$sourcerights")) {
9060: print $fh <<END;
9061: <accessrule effect="deny" realm="" type="course" role="" />
9062: <accessrule effect="allow" realm="$cid" type="course" role="" />
9063: END
9064: close($fh);
9065: }
9066: }
9067: if (!-e "$sourcerights.meta") {
9068: if (open(my $fh,">$sourcerights.meta")) {
9069: my $author=$env{'environment.firstname'}.' '.
9070: $env{'environment.middlename'}.' '.
9071: $env{'environment.lastname'}.' '.
9072: $env{'environment.generation'};
9073: $author =~ s/\s+$//;
9074: print $fh <<"END";
9075:
9076: <abstract></abstract>
9077: <author>$author</author>
9078: <authorspace>$coursenum:$coursedom</authorspace>
9079: <copyright>private</copyright>
9080: <creationdate>$now</creationdate>
9081: <customdistributionfile></customdistributionfile>
9082: <dependencies></dependencies>
9083: <domain>$coursedom</domain>
9084: <highestgradelevel>0</highestgradelevel>
9085: <keywords></keywords>
9086: <language>notset </language>
9087: <lastrevisiondate>$now</lastrevisiondate>
9088: <lowestgradelevel>0</lowestgradelevel>
9089: <mime>rights</mime>
9090: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
9091: <notes></notes>
9092: <obsolete></obsolete>
9093: <obsoletereplacement></obsoletereplacement>
9094: <owner>$coursenum:$coursedom</owner>
9095: <rule>deny:::course,allow:$cid::course</rule>
9096: <sourceavail></sourceavail>
9097: <standards></standards>
9098: <subject></subject>
9099: <title></title>
9100: END
9101: close($fh);
9102: }
9103: }
9104: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
9105: if (!-e "$docroot/res/$coursedom") {
9106: mkdir("$docroot/res/$coursedom",0755);
9107: }
9108: if (!-e "$docroot/res/$coursedom/$coursenum") {
9109: mkdir("$docroot/res/$coursedom/$coursenum",0755);
9110: }
9111: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
9112: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
9113: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
9114: }
9115: }
9116: my $source = $docroot.$redirect;
9117: if (!-e "$source.meta") {
9118: my $cid = $coursedom.'_'.$coursenum;
9119: my $now = time;
9120: if (open(my $fh,">$source.meta")) {
9121: my $author=$env{'environment.firstname'}.' '.
9122: $env{'environment.middlename'}.' '.
9123: $env{'environment.lastname'}.' '.
9124: $env{'environment.generation'};
9125: $author =~ s/\s+$//;
9126: my $title = $env{'form.newresourcetitle'};
9127: $title =~ s/^\s+|\s+$//g;
9128: print $fh <<END;
9129:
9130: <abstract></abstract>
9131: <author>$author</author>
9132: <authorspace>$coursenum:$coursedom</authorspace>
9133: <copyright>custom</copyright>
9134: <creationdate>$now</creationdate>
9135: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
9136: <dependencies></dependencies>
9137: <domain>$coursedom</domain>
9138: <highestgradelevel>0</highestgradelevel>
9139: <keywords></keywords>
9140: <language>notset </language>
9141: <lastrevisiondate>$now</lastrevisiondate>
9142: <lowestgradelevel>0</lowestgradelevel>
9143: <mime>problem</mime>
9144: <modifyinguser>$coursenum:$coursedom</modifyinguser>
9145: <notes></notes>
9146: <obsolete></obsolete>
9147: <obsoletereplacement></obsoletereplacement>
9148: <owner>$coursenum:$coursedom</owner>
9149: <sourceavail></sourceavail>
9150: <standards></standards>
9151: <subject></subject>
9152: <title>$title</title>
9153: END
9154: close($fh);
9155: }
9156: }
9157: }
9158: }
9159: } else {
9160: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
9161: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
9162: if (grep(/^\Q$rolehome\E$/,@ids)) {
9163: my $now = time;
9164: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
9165: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
9166: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
9167: my $url = "/priv/$audom/$auname";
9168: my $path = $r->dir_config('lonDocRoot').$url;
9169: my $subdir = $env{'form.authorpath'};
9170: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9171: }
9172: }
9173: }
9174: }
9175: }
9176: }
9177: }
9178: return ($redirect,$error);
9179: }
9180:
9181: sub finishnewprob {
9182: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
9183: unless (-d $path) {
9184: unless (mkdir($path,02770)) {
9185: return;
9186: }
9187: }
9188: my $redirect;
9189: if ($subdir ne '/') {
9190: $subdir = &cleandir($subdir);
9191: if (($subdir ne '') && (-d "$path/$subdir")) {
9192: $path .= "/$subdir";
9193: $url .= "/$subdir";
9194: }
9195: }
9196: my $dest;
9197: if ($newsubdir ne '') {
9198: $newsubdir = &cleandir($newsubdir);
9199: }
9200: if ($newsubdir ne '') {
9201: if (-d "$path/$newsubdir") {
9202: $dest = "$path/$newsubdir/$filename";
9203: } else {
9204: my $dirok;
9205: unless (-e "$path/$newsubdir") {
9206: if (mkdir("$path/$newsubdir",02770)) {
9207: if (chmod(02770,"$path/$newsubdir")) {
9208: $dirok = 1;
9209: }
9210: }
9211: }
9212: if ($dirok) {
9213: $dest = "$path/$newsubdir/$filename";
9214: }
9215: }
9216: if (($dest ne '') && (!-e $dest)) {
9217: $redirect = "$url/$newsubdir/$filename";
9218: }
9219: } else {
9220: $dest = "$path/$filename";
9221: if (($dest ne '') && (!-e $dest)) {
9222: $redirect = "$url/$filename";
9223: }
9224: }
9225: if ((!-e $dest) && ($context ne 'upload')) {
9226: my $template = $env{'form.template'};
9227: my $copyfrom;
9228: if ($template ne '') {
9229: my %templates;
9230: my @files = &Apache::lonhomework::get_template_list('problem');
9231: foreach my $poss (@files) {
9232: if (ref($poss) eq 'ARRAY') {
9233: if ($template eq $poss->[0]) {
9234: $templates{$template} = 1;
9235: last;
9236: }
9237: }
9238: }
9239: if ($templates{$template}) {
9240: $copyfrom = $template;
9241: }
9242: }
9243: if ($filename =~ /\.problem$/) {
9244: unless ($copyfrom) {
9245: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
9246: }
9247: &File::Copy::copy($copyfrom,$dest);
9248: }
9249: }
9250: return $redirect;
9251: }
9252:
9253: sub cleandir {
9254: my ($dir) = @_;
9255: $dir =~ s/^\s+//;
9256: $dir =~ s/\s+$//;
9257: $dir =~ s/\.+//g;
9258: $dir =~ s/[\#\?&%\":]//g;
9259: return $dir;
9260: }
9261:
9262: 1;
9263: __END__
9264:
9265:
9266: =head1 NAME
9267:
9268: Apache::londocs.pm
9269:
9270: =head1 SYNOPSIS
9271:
9272: This is part of the LearningOnline Network with CAPA project
9273: described at http://www.lon-capa.org.
9274:
9275: =head1 SUBROUTINES
9276:
9277: =over
9278:
9279: =item %help=()
9280:
9281: Available help topics
9282:
9283: =item mapread()
9284:
9285: Mapread read maps into LONCAPA::map:: global arrays
9286: @order and @resources, determines status
9287: sets @order - pointer to resources in right order
9288: sets @resources - array with the resources with correct idx
9289:
9290: =item authorhosts()
9291:
9292: Return hash with valid author names
9293:
9294: =item clean()
9295:
9296: =item dumpcourse()
9297:
9298: Actually dump course
9299:
9300: =item group_import()
9301:
9302: Imports the given (name, url) resources into the course
9303: coursenum, coursedom, and folder must precede the list
9304:
9305: =item breadcrumbs()
9306:
9307: =item log_docs()
9308:
9309: =item docs_change_log()
9310:
9311: =item update_paste_buffer()
9312:
9313: =item print_paste_buffer()
9314:
9315: =item do_paste_from_buffer()
9316:
9317: =item do_buffer_empty()
9318:
9319: =item clear_from_buffer()
9320:
9321: =item get_newmap_url()
9322:
9323: =item dbcopy()
9324:
9325: =item uniqueness_check()
9326:
9327: =item contained_map_check()
9328:
9329: =item url_paste_fixups()
9330:
9331: =item apply_fixups()
9332:
9333: =item copy_dependencies()
9334:
9335: =item update_parameter()
9336:
9337: =item handle_edit_cmd()
9338:
9339: =item editor()
9340:
9341: =item process_file_upload()
9342:
9343: =item process_secondary_uploads()
9344:
9345: =item is_supplemental_title()
9346:
9347: =item entryline()
9348:
9349: =item tiehash()
9350:
9351: =item untiehash()
9352:
9353: =item checkonthis()
9354:
9355: check on this
9356:
9357: =item verifycontent()
9358:
9359: Verify Content
9360:
9361: =item devalidateversioncache()
9362:
9363: =item checkversions()
9364:
9365: Check Versions
9366:
9367: =item mark_hash_old()
9368:
9369: =item is_hash_old()
9370:
9371: =item changewarning()
9372:
9373: =item init_breadcrumbs()
9374:
9375: Breadcrumbs for special functions
9376:
9377: =item create_list_elements()
9378:
9379: =item create_form_ul()
9380:
9381: =item startContentScreen()
9382:
9383: =item endContentScreen()
9384:
9385: =item supplemental_base()
9386:
9387: =item embedded_form_elems()
9388:
9389: =item embedded_destination()
9390:
9391: =item return_to_editor()
9392:
9393: =item decompression_info()
9394:
9395: =item decompression_phase_one()
9396:
9397: =item decompression_phase_two()
9398:
9399: =item remove_archive()
9400:
9401: =item generate_admin_menu()
9402:
9403: =item generate_edit_table()
9404:
9405: =item editing_js()
9406:
9407: =item history_tab_js()
9408:
9409: =item inject_data_js()
9410:
9411: =item dump_switchserver_js()
9412:
9413: =item resize_scrollbox_js()
9414:
9415: =item makedocslogform()
9416:
9417: =item makesimpleeditform()
9418:
9419: =back
9420:
9421: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>