File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.655:
download - view:
text,
annotated -
select for diffs
Tue May 29 19:33:48 2018 UTC (6 years, 2 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 6754 LON-CAPA as LTI Consumer
- Move External Resource and External Tool (if one or more LTI Tools
available in domain) to separate External "tab" in Course Editor menu.
- Update documentation for adding External Resource and External Tool.
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.655 2018/05/29 19:33:48 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: } else {
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 dumpcourse {
187: my ($r) = @_;
188: my $crstype = &Apache::loncommon::course_type();
189: my ($starthash,$js);
190: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
191: $js = <<"ENDJS";
192: <script type="text/javascript">
193: // <![CDATA[
194:
195: function hide_searching() {
196: if (document.getElementById('searching')) {
197: document.getElementById('searching').style.display = 'none';
198: }
199: return;
200: }
201:
202: // ]]>
203: </script>
204: ENDJS
205: $starthash = {
206: add_entries => {'onload' => "hide_searching();"},
207: };
208: }
209: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
210: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
211: $r->print(&startContentScreen('tools'));
212: my ($home,$other,%outhash)=&authorhosts();
213: unless ($home) {
214: $r->print(&endContentScreen());
215: return '';
216: }
217: my $origcrsid=$env{'request.course.id'};
218: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
219: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
220: # Do the dumping
221: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
222: $r->print(&endContentScreen());
223: return '';
224: }
225: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
226: $r->print('<h3>'.&mt('Copying Files').'</h3>');
227: my $title=$env{'form.authorfolder'};
228: $title=&clean($title);
229: my ($navmap,$errormsg) =
230: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
231: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
232: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
233: my (%maps,%resources,%titles);
234: if (!ref($navmap)) {
235: $r->print($errormsg.
236: &endContentScreen());
237: return '';
238: } else {
239: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
240: 'dumpdocs',$cdom,$cnum);
241: }
242: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
243: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
244: %newcontent,%has_simpleprobs);
245: foreach my $item (sort {$a <=> $b} (@todump)) {
246: my $name = $env{'form.namefor_'.$item};
247: if ($resources{$item}) {
248: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
249: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
250: $tocopy{$1} = $name;
251: $display{$item} = $1;
252: $lookup{$1} = $item;
253: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
254: $simpleproblems{$item} = {
255: symb => $resources{$item},
256: name => $name,
257: };
258: $display{$item} = 'simpleproblem_'.$name;
259: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
260: $has_simpleprobs{$1}{$id} = $item;
261: }
262: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
263: my $marker = $1;
264: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
265: $simplepages{$item} = {
266: res => $res,
267: title => $titles{$item},
268: db => $db_name,
269: marker => $marker,
270: symb => $resources{$item},
271: name => $name,
272: };
273: $display{$item} = '/'.$res;
274: }
275: } elsif ($maps{$item}) {
276: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
277: $tocopy{$1} = $name;
278: $display{$item} = $1;
279: $lookup{$1} = $item;
280: }
281: } else {
282: next;
283: }
284: }
285: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
286: $crs=~s/\_/\//g;
287: my $mm = new File::MMagic;
288: my $prefix = "/uploaded/$cdom/$cnum/";
289: %replacehash = %tocopy;
290: foreach my $item (sort(keys(%simpleproblems))) {
291: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
292: $newcontent{$display{$item}} = $content;
293: }
294: my $gateway = Apache::lonhtmlgateway->new('web');
295: foreach my $item (sort(keys(%simplepages))) {
296: if (ref($simplepages{$item}) eq 'HASH') {
297: my $pagetitle = $simplepages{$item}{'title'};
298: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
299: my %contents;
300: foreach my $field (keys(%fields)) {
301: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
302: my $name = $1;
303: my $msg = $fields{$field};
304: if ($name eq 'webreferences') {
305: if ($msg =~ m{^https?://}) {
306: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
307: }
308: } else {
309: $msg = &Encode::decode('utf8',$msg);
310: $msg = $gateway->process_outgoing_html($msg,1);
311: $contents{$name} = $msg;
312: }
313: } elsif ($field eq 'uploaded.photourl') {
314: my $marker = $simplepages{$item}{marker};
315: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
316: my $filepath = $1;
317: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
318: if ($fname ne '') {
319: $fname=~s/\.(\w+)$//;
320: my $ext=$1;
321: $fname = &clean($fname);
322: $fname.='.'.$ext;
323: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
324: $replacehash{$filepath} = $relpath.$fname;
325: $deps{$item}{$filepath} = 1;
326: }
327: }
328: }
329: }
330: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
331: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
332: my $content = '
333: <html>
334: <head>
335: <title>'.$pagetitle.'</title>
336: </head>
337: <body bgcolor="#ffffff">';
338: if ($contents{title}) {
339: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
340: }
341: if ($contents{image}) {
342: $content .= "\n".$contents{image};
343: }
344: if ($contents{content}) {
345: $content .= '
346: <div class="LC_Box">
347: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
348: $contents{content}.'
349: </div>';
350: }
351: if ($contents{webreferences}) {
352: $content .= '
353: <div class="LC_Box">
354: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
355: $contents{webreferences}.'
356: </div>';
357: }
358: $content .= '
359: </body>
360: </html>
361: ';
362: $newcontent{'/'.$simplepages{$item}{res}} = $content;
363: }
364: }
365: foreach my $item (keys(%tocopy)) {
366: unless ($item=~/\.(sequence|page)$/) {
367: my $currurlpath = $prefix.$item;
368: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
369: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
370: }
371: }
372: foreach my $num (sort {$a <=> $b} (@todump)) {
373: my $src = $display{$num};
374: next if ($src eq '');
375: my @needcopy = ();
376: if ($replacehash{$src}) {
377: push(@needcopy,$src);
378: if (ref($deps{$num}) eq 'HASH') {
379: foreach my $dep (sort(keys(%{$deps{$num}}))) {
380: if ($replacehash{$dep}) {
381: push(@needcopy,$dep);
382: }
383: }
384: }
385: } elsif ($src =~ /^simpleproblem_/) {
386: push(@needcopy,$src);
387: }
388: next if (@needcopy == 0);
389: my ($result,$depresult);
390: for (my $i=0; $i<@needcopy; $i++) {
391: my $item = $needcopy[$i];
392: my $newfilename;
393: if ($simpleproblems{$num}) {
394: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
395: } else {
396: $newfilename=$title.'/'.$replacehash{$item};
397: }
398: $newfilename=~s/\.(\w+)$//;
399: my $ext=$1;
400: $newfilename=&clean($newfilename);
401: $newfilename.='.'.$ext;
402: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
403: if ($newrelpath ne $replacehash{$item}) {
404: $replacehash{$item} = $newrelpath;
405: }
406: my @dirs=split(/\//,$newfilename);
407: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
408: my $makepath=$path;
409: my $fail;
410: my $origin;
411: for (my $i=0;$i<$#dirs;$i++) {
412: $makepath.='/'.$dirs[$i];
413: unless (-e $makepath) {
414: unless(mkdir($makepath,0755)) {
415: $fail = &mt('Directory creation failed.');
416: }
417: }
418: }
419: if ($i == 0) {
420: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
421: } else {
422: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
423: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
424: &mt('(dependency)').'</span>: ';
425: }
426: if (-e $path.'/'.$newfilename) {
427: $fail = &mt('Destination already exists -- not overwriting.');
428: } else {
429: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
430: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
431: ($item =~ /^simpleproblem_/)) {
432: print $fh $newcontent{$item};
433: } else {
434: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
435: if (-e $fileloc) {
436: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
437: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
438: (ref($has_simpleprobs{$item}) eq 'HASH')) {
439: my %changes = %{$has_simpleprobs{$item}};
440: my $content = &Apache::lonclonecourse::rewritefile(
441: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
442: (%replacehash,$crs => '')
443: );
444: my $updatedcontent = '';
445: my $parser = HTML::TokeParser->new(\$content);
446: $parser->attr_encoded(1);
447: while (my $token = $parser->get_token) {
448: if ($token->[0] eq 'S') {
449: if (($token->[1] eq 'resource') &&
450: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
451: ($changes{$token->[2]->{'id'}})) {
452: my $id = $token->[2]->{'id'};
453: $updatedcontent .= '<'.$token->[1];
454: foreach my $attrib (@{$token->[3]}) {
455: next unless ($attrib =~ /^(src|type|title|id)$/);
456: if ($attrib eq 'src') {
457: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
458: if ($file) {
459: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
460: } else {
461: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
462: }
463: } else {
464: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
465: }
466: }
467: $updatedcontent .= ' />'."\n";
468: } else {
469: $updatedcontent .= $token->[4]."\n";
470: }
471: } else {
472: $updatedcontent .= $token->[2];
473: }
474: }
475: print $fh $updatedcontent;
476: } else {
477: print $fh &Apache::lonclonecourse::rewritefile(
478: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
479: (%replacehash,$crs => '')
480: );
481: }
482: } else {
483: print $fh
484: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
485: }
486: } else {
487: $fail = &mt('Source does not exist.');
488: }
489: }
490: $fh->close();
491: } else {
492: $fail = &mt('Could not write to destination.');
493: }
494: }
495: my $text;
496: if ($fail) {
497: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
498: } else {
499: $text = '<span class="LC_success">'.&mt('ok').'</span>';
500: }
501: if ($i == 0) {
502: $result .= $text;
503: } else {
504: $depresult .= $text.'</li>';
505: }
506: }
507: $r->print($result);
508: if ($depresult) {
509: $r->print('<ul>'.$depresult.'</ul>');
510: }
511: }
512: } else {
513: my ($navmap,$errormsg) =
514: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
515: if (!ref($navmap)) {
516: $r->print($errormsg);
517: } else {
518: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
519: $r->rflush();
520: my ($preamble,$formname);
521: $formname = 'dumpdoc';
522: unless ($home==1) {
523: $preamble = '<div class="LC_left_float">'.
524: '<fieldset><legend>'.
525: &mt('Select the Authoring Space').
526: '</legend><select name="authorspace">';
527: }
528: my @orderspaces = ();
529: foreach my $key (sort(keys(%outhash))) {
530: if ($key=~/^home_(.+)$/) {
531: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
532: unshift(@orderspaces,$1);
533: } else {
534: push(@orderspaces,$1);
535: }
536: }
537: }
538: if ($home>1) {
539: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
540: }
541: foreach my $user (@orderspaces) {
542: if ($home==1) {
543: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
544: } else {
545: $preamble .= '<option value="'.$user.'">'.$user.' - '.
546: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
547: }
548: }
549: unless ($home==1) {
550: $preamble .= '</select></fieldset></div>'."\n";
551: }
552: my $title=$origcrsdata{'description'};
553: $title=~s/[\/\s]+/\_/gs;
554: $title=&clean($title);
555: $preamble .= '<div class="LC_left_float">'.
556: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
557: '<input type="text" size="50" name="authorfolder" value="'.
558: $title.'" />'.
559: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
560: my %uploadedfiles;
561: &tiehash();
562: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
563: my ($ext)=($file=~/\.(\w+)$/);
564: # FIXME Check supplemental here
565: my $title=$hash{'title_'.$hash{
566: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
567: if (!$title) {
568: $title=$file;
569: } else {
570: $title=~s|/|_|g;
571: }
572: $title=~s/\.(\w+)$//;
573: $title=&clean($title);
574: $title.='.'.$ext;
575: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
576: $uploadedfiles{$file} = $title;
577: }
578: &untiehash();
579: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
580: undef,undef,$preamble,$home,\%uploadedfiles));
581: }
582: }
583: $r->print(&endContentScreen());
584: }
585:
586: sub recurse_html {
587: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
588: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
589: my (%allfiles,%codebase);
590: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
591: if (keys(%allfiles)) {
592: foreach my $dependency (keys(%allfiles)) {
593: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
594: my ($depurl,$relfile,$newcontainer);
595: if ($dependency =~ m{^/}) {
596: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
597: $relfile = $1;
598: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
599: $newcontainer = $1;
600: next if ($replacehash->{$newcontainer});
601: }
602: $depurl = $dependency;
603: } else {
604: next;
605: }
606: } else {
607: $relfile = $dependency;
608: $depurl = $currurlpath;
609: $depurl =~ s{[^/]+$}{};
610: $depurl .= $dependency;
611: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
612: }
613: next if ($relfile eq '');
614: my $newname = $replacehash->{$container};
615: $newname =~ s{[^/]+$}{};
616: $replacehash->{$newcontainer} = $newname.$relfile;
617: $deps->{$item}{$newcontainer} = 1;
618: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
619: my $depfile = &Apache::lonnet::filelocation('',$depurl);
620: my $type = $mm->checktype_filename($depfile);
621: if ($type eq 'text/html') {
622: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
623: }
624: }
625: }
626: }
627: return;
628: }
629:
630: sub group_import {
631: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
632: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
633: %removeparam,$importuploaded,$fixuperrors);
634: $allmaps = {};
635: while (@files) {
636: my ($name, $url, $residx) = @{ shift(@files) };
637: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
638: && ($caller eq 'londocs')
639: && (!&Apache::lonnet::stat_file($url))) {
640:
641: my $errtext = '';
642: my $fatal = 0;
643: my $newmapstr = '<map>'."\n".
644: '<resource id="1" src="" type="start"></resource>'."\n".
645: '<link from="1" to="2" index="1"></link>'."\n".
646: '<resource id="2" src="" type="finish"></resource>'."\n".
647: '</map>';
648: $env{'form.output'}=$newmapstr;
649: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
650: 'output',$1.$2);
651: if ($result !~ m{^/uploaded/}) {
652: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
653: $fatal = 2;
654: }
655: if ($fatal) {
656: return ($errtext,$fatal);
657: }
658: }
659: if ($url) {
660: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
661: $url = $1;
662: my $marker = $2;
663: my $info = $3;
664: my ($toolid,%toolhash,%toolsettings);
665: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
666: my @toolinfo = split(/:/,$info);
667: if ($residx) {
668: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
669: $toolid = $toolsettings{'id'};
670: } else {
671: $toolid = shift(@toolinfo);
672: }
673: $toolid =~ s/\D//g;
674: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
675: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
676: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
677: foreach my $item (@extras) {
678: $toolhash{$item} = &unescape($toolhash{$item});
679: }
680: if ($folder =~ /^supplemental/) {
681: delete($toolhash{'gradable'});
682: } else {
683: $toolhash{'gradable'} =~ s/\D+//g;
684: }
685: if (ref($ltitoolsref) eq 'HASH') {
686: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
687: my @deleted;
688: $toolhash{'id'} = $toolid;
689: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
690: ($toolhash{'target'} eq 'window')) {
691: if ($toolhash{'target'} eq 'window') {
692: foreach my $item ('width','height') {
693: $toolhash{$item} =~ s/^\s+//;
694: $toolhash{$item} =~ s/\s+$//;
695: if ($toolhash{$item} =~ /\D/) {
696: delete($toolhash{$item});
697: if ($residx) {
698: if ($toolsettings{$item}) {
699: push(@deleted,$item);
700: }
701: }
702: }
703: }
704: }
705: } elsif ($residx) {
706: $toolhash{'target'} = $toolsettings{'target'};
707: if ($toolhash{'target'} eq 'window') {
708: foreach my $item ('width','height') {
709: $toolhash{$item} = $toolsettings{$item};
710: }
711: }
712: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
713: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
714: if ($toolhash{'target'} eq 'window') {
715: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
716: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
717: }
718: }
719: if ($toolhash{'target'} eq 'iframe') {
720: foreach my $item ('width','height','linktext','explanation') {
721: delete($toolhash{$item});
722: if ($residx) {
723: if ($toolsettings{$item}) {
724: push(@deleted,$item);
725: }
726: }
727: }
728: } elsif ($toolhash{'target'} eq 'tab') {
729: foreach my $item ('width','height') {
730: delete($toolhash{$item});
731: if ($residx) {
732: if ($toolsettings{$item}) {
733: push(@deleted,$item);
734: }
735: }
736: }
737: }
738: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
739: foreach my $item ('label','title','linktext','explanation') {
740: my $crsitem;
741: if (($item eq 'label') || ($item eq 'title')) {
742: $crsitem = 'crs'.$item;
743: } else {
744: $crsitem = $item;
745: }
746: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
747: $toolhash{$crsitem} =~ s/^\s+//;
748: $toolhash{$crsitem} =~ s/\s+$//;
749: if ($toolhash{$crsitem} eq '') {
750: delete($toolhash{$crsitem});
751: }
752: } else {
753: delete($toolhash{$crsitem});
754: }
755: if (($residx) && (exists($toolsettings{$crsitem}))) {
756: unless (exists($toolhash{$crsitem})) {
757: push(@deleted,$crsitem);
758: }
759: }
760: }
761: }
762: if ($toolhash{'passback'}) {
763: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
764: $toolhash{'gradesecret'} = $gradesecret;
765: $toolhash{'gradesecretdate'} = time;
766: }
767: if ($toolhash{'roster'}) {
768: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
769: $toolhash{'rostersecret'} = $rostersecret;
770: $toolhash{'rostersecretdate'} = time;
771: }
772: my $changegradable;
773: if (($residx) && ($folder =~ /^default/)) {
774: if ($toolsettings{'gradable'}) {
775: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
776: push(@deleted,'gradable');
777: $changegradable = 1;
778: }
779: } elsif ($toolhash{'gradable'}) {
780: $changegradable = 1;
781: }
782: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
783: $changegradable = 1;
784: if ($toolsettings{'gradable'}) {
785: $toolhash{'gradable'} = 1;
786: }
787: }
788: }
789: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
790: if ($putres eq 'ok') {
791: if (@deleted) {
792: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
793: }
794: if (($changegradable) && ($folder =~ /^default/)) {
795: my $val;
796: if ($toolhash{'gradable'}) {
797: $val = 'yes';
798: } else {
799: $val = 'no';
800: }
801: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
802: 'string_yesno');
803: &remember_parms($residx,'gradable','set',$val);
804: }
805: } else {
806: return (&mt('Failed to save update to external tool.'),1);
807: }
808: }
809: }
810: }
811: if (($caller eq 'londocs') &&
812: ($folder =~ /^default/)) {
813: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
814: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
815: my $cid = $coursedom.'_'.$coursenum;
816: $allmaps =
817: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
818: $chome,$cid);
819: $donechk = 1;
820: }
821: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
822: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
823: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
824: $importuploaded = 1;
825: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
826: next if ($allmaps->{$url});
827: }
828: }
829: if (!$residx
830: || defined($LONCAPA::map::zombies[$residx])) {
831: $residx = &LONCAPA::map::getresidx($url,$residx);
832: push(@LONCAPA::map::order, $residx);
833: }
834: my $ext = 'false';
835: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
836: $name = &LONCAPA::map::qtunescape($name);
837: if ($name eq '') {
838: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
839: }
840: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
841: my $filepath = $1;
842: my $fname = $name;
843: if ($fname =~ /^\W+$/) {
844: $fname = 'web';
845: } else {
846: $fname =~ s/\W/_/g;
847: }
848: if (length($fname) > 15) {
849: $fname = substr($fname,0,14);
850: }
851: my $initialtext = &mt('Replace with your own content.');
852: my $newhtml = <<END;
853: <html>
854: <head>
855: <title>$name</title>
856: </head>
857: <body bgcolor="#ffffff">
858: $initialtext
859: </body>
860: </html>
861: END
862: $env{'form.output'}=$newhtml;
863: my $result =
864: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
865: 'output',
866: "$filepath/$residx/$fname.html");
867: if ($result =~ m{^/uploaded/}) {
868: $url = $result;
869: if ($filepath =~ /^supplemental/) {
870: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
871: $env{'user.domain'}.'___&&&___'.$name;
872: }
873: } else {
874: return (&mt('Failed to save new web page.'),1);
875: }
876: }
877: $url = &LONCAPA::map::qtunescape($url);
878: $LONCAPA::map::resources[$residx] =
879: join(':', ($name, $url, $ext, 'normal', 'res'));
880: }
881: }
882: if ($importuploaded) {
883: my %import_errors;
884: my %updated = (
885: removefrommap => \%removefrommap,
886: removeparam => \%removeparam,
887: );
888: my ($result,$msgsarray,$lockerror) =
889: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
890: if (keys(%import_errors) > 0) {
891: $fixuperrors =
892: '<p span class="LC_warning">'."\n".
893: &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".
894: '<ul>'."\n";
895: foreach my $key (sort(keys(%import_errors))) {
896: $fixuperrors .= '<li>'.$key.'</li>'."\n";
897: }
898: $fixuperrors .= '</ul></p>'."\n";
899: }
900: if (ref($msgsarray) eq 'ARRAY') {
901: if (@{$msgsarray} > 0) {
902: $fixuperrors .= '<p class="LC_info">'.
903: join('<br />',@{$msgsarray}).
904: '</p>';
905: }
906: }
907: if ($lockerror) {
908: $fixuperrors .= '<p class="LC_error">'.
909: $lockerror.
910: '</p>';
911: }
912: }
913: my ($errtext,$fatal) =
914: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
915: unless ($fatal) {
916: if ($folder =~ /^supplemental/) {
917: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
918: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
919: $folder.'.'.$container);
920: }
921: }
922: return ($errtext,$fatal,$fixuperrors);
923: }
924:
925: sub log_docs {
926: return &Apache::lonnet::write_log('course','docslog',@_);
927: }
928:
929: {
930: my @oldresources=();
931: my @oldorder=();
932: my $parmidx;
933: my %parmaction=();
934: my %parmvalue=();
935: my $changedflag;
936:
937: sub snapshotbefore {
938: @oldresources=@LONCAPA::map::resources;
939: @oldorder=@LONCAPA::map::order;
940: $parmidx=undef;
941: %parmaction=();
942: %parmvalue=();
943: $changedflag=0;
944: }
945:
946: sub remember_parms {
947: my ($idx,$parameter,$action,$value)=@_;
948: $parmidx=$idx;
949: $parmaction{$parameter}=$action;
950: $parmvalue{$parameter}=$value;
951: $changedflag=1;
952: }
953:
954: sub log_differences {
955: my ($plain)=@_;
956: my %storehash=('folder' => $plain,
957: 'currentfolder' => $env{'form.folder'});
958: if ($parmidx) {
959: $storehash{'parameter_res'}=$oldresources[$parmidx];
960: foreach my $parm (keys(%parmaction)) {
961: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
962: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
963: }
964: }
965: my $maxidx=$#oldresources;
966: if ($#LONCAPA::map::resources>$#oldresources) {
967: $maxidx=$#LONCAPA::map::resources;
968: }
969: for (my $idx=0; $idx<=$maxidx; $idx++) {
970: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
971: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
972: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
973: $changedflag=1;
974: }
975: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
976: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
977: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
978: $changedflag=1;
979: }
980: }
981: $storehash{'maxidx'}=$maxidx;
982: if ($changedflag) { &log_docs(\%storehash); }
983: }
984: }
985:
986: sub docs_change_log {
987: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
988: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
989: my $navmap;
990: my $js = '<script type="text/javascript">'."\n".
991: '// <![CDATA['."\n".
992: &Apache::loncommon::display_filter_js('docslog')."\n".
993: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
994: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
995: &history_tab_js()."\n".
996: &Apache::lonratedt::editscript('simple')."\n".
997: '// ]]>'."\n".
998: '</script>'."\n";
999: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1000: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1001: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1002: my %orderhash;
1003: my $container='sequence';
1004: my $pathitem;
1005: if ($env{'form.folderpath'} =~ /\:1$/) {
1006: $container='page';
1007: }
1008: my $folderpath=$env{'form.folderpath'};
1009: if ($folderpath eq '') {
1010: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1011: }
1012: undef($navmap);
1013: $pathitem = '<input type="hidden" name="folderpath" value="'.
1014: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1015: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1016: my $jumpto = $readfile;
1017: $jumpto =~ s{^/}{};
1018: my $tid = 1;
1019: if ($supplementalflag) {
1020: $tid = 2;
1021: }
1022: my ($breadcrumbtrail) =
1023: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1024: $r->print($breadcrumbtrail.
1025: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1026: $readfile));
1027: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1028: $env{'course.'.$env{'request.course.id'}.'.domain'},
1029: $env{'course.'.$env{'request.course.id'}.'.num'});
1030:
1031: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1032:
1033: my %saveable_parameters = ('show' => 'scalar',);
1034: &Apache::loncommon::store_course_settings('docs_log',
1035: \%saveable_parameters);
1036: &Apache::loncommon::restore_course_settings('docs_log',
1037: \%saveable_parameters);
1038: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1039: # FIXME: internationalization seems wrong here
1040: my %lt=('hiddenresource' => 'Resources hidden',
1041: 'encrypturl' => 'URL hidden',
1042: 'randompick' => 'Randomly pick',
1043: 'randomorder' => 'Randomly ordered',
1044: 'gradable' => 'Grade can be assigned to External Tool',
1045: 'set' => 'set to',
1046: 'del' => 'deleted');
1047: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1048: $pathitem."\n".
1049: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1050: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1051: $r->print('<div class="LC_left_float">'.
1052: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1053: &makedocslogform($filter,1).
1054: '</fieldset></div><br clear="all" />');
1055: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1056: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1057: &mt('After').'</th>'.
1058: &Apache::loncommon::end_data_table_header_row());
1059: my $shown=0;
1060: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1061: if ($env{'form.displayfilter'} eq 'currentfolder') {
1062: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1063: }
1064: my @changes=keys(%{$docslog{$id}{'logentry'}});
1065: if ($env{'form.displayfilter'} eq 'containing') {
1066: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1067: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1068: foreach my $key (@changes) {
1069: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1070: }
1071: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1072: }
1073: my $count = 0;
1074: my $time =
1075: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1076: my $plainname =
1077: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1078: $docslog{$id}{'exe_udom'});
1079: my $about_me_link =
1080: &Apache::loncommon::aboutmewrapper($plainname,
1081: $docslog{$id}{'exe_uname'},
1082: $docslog{$id}{'exe_udom'});
1083: my $send_msg_link='';
1084: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1085: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1086: $send_msg_link ='<br />'.
1087: &Apache::loncommon::messagewrapper(&mt('Send message'),
1088: $docslog{$id}{'exe_uname'},
1089: $docslog{$id}{'exe_udom'});
1090: }
1091: $r->print(&Apache::loncommon::start_data_table_row());
1092: $r->print('<td>'.$time.'</td>
1093: <td>'.$about_me_link.
1094: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1095: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1096: $send_msg_link.'</td><td>'.
1097: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1098: my $is_supp = 0;
1099: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1100: $is_supp = 1;
1101: }
1102: # Before
1103: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1104: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1105: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1106: if ($oldname ne $newname) {
1107: my $shown = &LONCAPA::map::qtescape($oldname);
1108: if ($is_supp) {
1109: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1110: }
1111: $r->print($shown);
1112: }
1113: }
1114: $r->print('<ul>');
1115: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1116: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1117: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1118: if ($is_supp) {
1119: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1120: }
1121: $r->print('<li>'.$shown.'</li>');
1122: }
1123: }
1124: $r->print('</ul>');
1125: # After
1126: $r->print('</td><td>');
1127:
1128: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1129: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1130: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1131: if ($oldname ne '' && $oldname ne $newname) {
1132: my $shown = &LONCAPA::map::qtescape($newname);
1133: if ($is_supp) {
1134: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1135: }
1136: $r->print($shown);
1137: }
1138: }
1139: $r->print('<ul>');
1140: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1141: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1142: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1143: if ($is_supp) {
1144: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1145: }
1146: $r->print('<li>'.$shown.'</li>');
1147: }
1148: }
1149: $r->print('</ul>');
1150: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1151: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1152: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1153: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1154: # FIXME: internationalization seems wrong here
1155: $r->print('<li>'.
1156: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1157: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1158: .'</li>');
1159: }
1160: }
1161: $r->print('</ul>');
1162: }
1163: # End
1164: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1165: $shown++;
1166: if (!($env{'form.show'} eq &mt('all')
1167: || $shown<=$env{'form.show'})) { last; }
1168: }
1169: $r->print(&Apache::loncommon::end_data_table()."\n".
1170: &makesimpleeditform($pathitem)."\n".
1171: '</div></div>');
1172: $r->print(&endContentScreen());
1173: }
1174:
1175: sub update_paste_buffer {
1176: my ($coursenum,$coursedom,$folder) = @_;
1177: my (@possibles,%removals,%cuts,$output);
1178: if ($env{'form.multiremove'}) {
1179: $env{'form.multiremove'} =~ s/,$//;
1180: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1181: }
1182: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1183: if ($env{'form.multicut'}) {
1184: $env{'form.multicut'} =~ s/,$//;
1185: foreach my $item (split(/,/,$env{'form.multicut'})) {
1186: unless ($removals{$item}) {
1187: $cuts{$item} = 1;
1188: push(@possibles,$item.':cut');
1189: }
1190: }
1191: }
1192: if ($env{'form.multicopy'}) {
1193: $env{'form.multicopy'} =~ s/,$//;
1194: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1195: unless ($removals{$item} || $cuts{$item}) {
1196: push(@possibles,$item.':copy');
1197: }
1198: }
1199: }
1200: } elsif ($env{'form.markcopy'}) {
1201: @possibles = split(/,/,$env{'form.markcopy'});
1202: }
1203:
1204: return if (@possibles == 0);
1205: return if (!defined($env{'form.copyfolder'}));
1206:
1207: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1208: $env{'form.copyfolder'});
1209: return if ($fatal);
1210:
1211: my %curr_groups = &Apache::longroup::coursegroups();
1212:
1213: # Retrieve current paste buffer suffixes.
1214: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1215: my (%pasteurls,@newpaste);
1216:
1217: # Construct identifiers for current contents of user's paste buffer
1218: if (@currpaste) {
1219: foreach my $suffix (@currpaste) {
1220: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1221: my $url = $env{'docs.markedcopy_url_'.$suffix};
1222: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1223: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1224: ($url ne '')) {
1225: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1226: }
1227: }
1228: }
1229:
1230: # Mark items for copying (skip any items already in user's paste buffer)
1231: my %addtoenv;
1232:
1233: my @pathitems = split(/\&/,$env{'form.folderpath'});
1234: my @folderconf = split(/\:/,$pathitems[-1]);
1235: my $ispage = $folderconf[4];
1236:
1237: foreach my $item (@possibles) {
1238: my ($orderidx,$cmd) = split(/:/,$item);
1239: next if ($orderidx =~ /\D/);
1240: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1241: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1242: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1243: my %denied = &action_restrictions($coursenum,$coursedom,
1244: &LONCAPA::map::qtescape($url),
1245: $env{'form.folderpath'},\%curr_groups);
1246: next if ($denied{'copy'});
1247: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1248: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1249: my ($suffix,$errortxt,$locknotfreed) =
1250: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1251: if ($suffix ne '') {
1252: push(@newpaste,$suffix);
1253: } else {
1254: if ($locknotfreed) {
1255: return $locknotfreed;
1256: }
1257: }
1258: if (&is_supplemental_title($title)) {
1259: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1260: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1261: }
1262:
1263: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1264: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1265: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1266: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1267: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1268: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1269: my $prefix = $1;
1270: my $subdir =$2;
1271: if ($subdir eq '') {
1272: $subdir = $prefix;
1273: }
1274: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1275: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1276: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1277: if (ref($hierarchy{$url}) eq 'HASH') {
1278: my ($nested,$nestednames);
1279: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1280: $nested =~ s/\&$//;
1281: $nestednames =~ s/\Q___&&&___\E$//;
1282: if ($nested ne '') {
1283: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1284: }
1285: if ($nestednames ne '') {
1286: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1287: }
1288: }
1289: }
1290: if ($locknotfreed) {
1291: $output = $locknotfreed;
1292: last;
1293: }
1294: }
1295: if (@newpaste) {
1296: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1297: }
1298: &Apache::lonnet::appenv(\%addtoenv);
1299: delete($env{'form.markcopy'});
1300: return $output;
1301: }
1302:
1303: sub recurse_uploaded_maps {
1304: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1305: if (ref($hierarchy->{$url}) eq 'HASH') {
1306: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1307: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1308: my (@uploaded,@names,%shorter);
1309: for (my $i=0; $i<@maps; $i++) {
1310: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1311: if ($inner ne '') {
1312: push(@uploaded,$inner);
1313: push(@names,&escape($titles[$i]));
1314: $shorter{$maps[$i]} = $inner;
1315: }
1316: }
1317: $$nestref .= "$dir:".join(',',@uploaded).'&';
1318: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1319: foreach my $map (@maps) {
1320: if ($shorter{$map} ne '') {
1321: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1322: }
1323: }
1324: }
1325: return;
1326: }
1327:
1328: sub print_paste_buffer {
1329: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1330: return if (!defined($env{'docs.markedcopies'}));
1331:
1332: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1333: return if ($env{'docs.markedcopies'} eq '');
1334: }
1335:
1336: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1337: my ($pasteitems,@pasteable);
1338: my $clipboardcount = 0;
1339:
1340: # Construct identifiers for current contents of user's paste buffer
1341: foreach my $suffix (@currpaste) {
1342: next if ($suffix =~ /\D/);
1343: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1344: my $url = $env{'docs.markedcopy_url_'.$suffix};
1345: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1346: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1347: ($url ne '')) {
1348: $clipboardcount ++;
1349: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1350: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1351: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1352: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1353: $is_external = 1;
1354: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1355: $is_exttool = 1;
1356: }
1357: if ($folder =~ /^supplemental/) {
1358: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1359: unless ($canpaste) {
1360: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1361: }
1362: } else {
1363: $canpaste = 1;
1364: }
1365: if ($canpaste) {
1366: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1367: my $srcdom = $1;
1368: my $srcnum = $2;
1369: my $rem = $3;
1370: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1371: $othercourse = 1;
1372: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1373: $othercrs = '<br />'.&mt('(from another course)');
1374: } else {
1375: $canpaste = 0;
1376: $nopaste = &mt('Paste from another course unavailable.');
1377: }
1378: }
1379: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1380: my $prefix = $1;
1381: $parent = $2;
1382: if ($folder !~ /^\Q$prefix\E/) {
1383: $areachange = 1;
1384: }
1385: $is_uploaded_map = 1;
1386: }
1387: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1388: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1389: if ($cid ne $env{'request.course.id'}) {
1390: my ($srcdom,$srcnum) = split(/_/,$cid);
1391: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1392: if (($is_exttool) && ($srcdom ne $coursedom)) {
1393: $canpaste = 0;
1394: $nopaste = &mt('Paste from another domain unavailable.');
1395: } else {
1396: $othercrs = '<br />'.&mt('(from another course)');
1397: }
1398: } else {
1399: $canpaste = 0;
1400: $nopaste = &mt('Paste from another course unavailable.');
1401: }
1402: }
1403: }
1404: if ($canpaste) {
1405: push(@pasteable,$suffix);
1406: }
1407: }
1408: my $buffer;
1409: if ($is_external) {
1410: $buffer = &mt('External Resource').': '.
1411: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1412: &LONCAPA::map::qtescape($url).')';
1413: } elsif ($is_exttool) {
1414: $buffer = &mt('External Tool').': '.
1415: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1416: } else {
1417: my $icon = &Apache::loncommon::icon($extension);
1418: if ($extension eq 'sequence' &&
1419: $url =~ m{/default_\d+\.sequence$}x) {
1420: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1421: $icon .= '/navmap.folder.closed.gif';
1422: }
1423: my $title = $env{'docs.markedcopy_title_'.$suffix};
1424: if ($title eq '') {
1425: ($title) = ($url =~ m{/([^/]+)$});
1426: }
1427: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1428: ': '.
1429: &Apache::loncommon::parse_supplemental_title(
1430: &LONCAPA::map::qtescape($title));
1431: }
1432: $pasteitems .= '<div class="LC_left_float">';
1433: my ($options,$onclick);
1434: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1435: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1436: if (($is_uploaded_map) ||
1437: ($url =~ /(bulletinboard|smppg)$/) ||
1438: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1439: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1440: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1441: }
1442: }
1443: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1444: if ($nopaste) {
1445: $pasteitems .= $nopaste;
1446: } else {
1447: if ($othercrs) {
1448: $pasteitems .= $othercrs;
1449: }
1450: if ($options) {
1451: $pasteitems .= $options;
1452: }
1453: }
1454: $pasteitems .= '</div>';
1455: }
1456: }
1457: if ($pasteitems eq '') {
1458: &Apache::lonnet::delenv('docs.markedcopies');
1459: }
1460: my ($pasteform,$form_start,$buttons,$form_end);
1461: if ($pasteitems) {
1462: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1463: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1464: if (@pasteable) {
1465: my $value = &mt('Paste to current folder');
1466: if ($container eq 'page') {
1467: $value = &mt('Paste to current page');
1468: }
1469: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1470: }
1471: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1472: if ($clipboardcount > 1) {
1473: $buttons .=
1474: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1475: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1476: (' 'x2).
1477: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1478: (' 'x2);
1479: }
1480: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1481: '</form>';
1482: } else {
1483: $pasteitems = &mt('Clipboard is empty');
1484: }
1485: $r->print($form_start
1486: .'<fieldset>'
1487: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1488: .$pasteitems
1489: .'</fieldset>'
1490: .$form_end);
1491: }
1492:
1493: sub paste_options {
1494: my ($suffix,$is_uploaded_map,$parent) = @_;
1495: my ($copytext,$movetext);
1496: if ($is_uploaded_map) {
1497: $copytext = &mt('Copy to new folder');
1498: $movetext = &mt('Move old');
1499: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1500: $copytext = &mt('Copy to new board');
1501: $movetext = &mt('Move (not posts)');
1502: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1503: $copytext = &mt('Copy to new page');
1504: $movetext = &mt('Move');
1505: } else {
1506: $copytext = &mt('Copy to new file');
1507: $movetext = &mt('Move');
1508: }
1509: my $output = '<br />'.
1510: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1511: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1512: '<label>'.
1513: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1514: $copytext.'</label></span>'.(' 'x2).' '.
1515: '<span class="LC_nobreak"><label>'.
1516: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1517: $movetext.'</label></span>';
1518: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1519: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1520: '</legend><table border="0">';
1521: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1522: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1523: my $lastdir = $parent;
1524: my %depths = (
1525: $lastdir => 0,
1526: );
1527: my (%display,%deps);
1528: for (my $i=0; $i<@pastemaps; $i++) {
1529: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1530: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1531: my @subfolders = split(/,/,$subfolderstr);
1532: $deps{$lastdir} = \@subfolders;
1533: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1534: my $depth = $depths{$lastdir} + 1;
1535: my $offset = int($depth * 4);
1536: my $indent = (' ' x $offset);
1537: for (my $j=0; $j<@subfolders; $j++) {
1538: $depths{$subfolders[$j]} = $depth;
1539: $display{$subfolders[$j]} =
1540: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1541: '<td><label>'.
1542: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1543: '<label>'.
1544: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1545: &mt('Move old').'</label>'.
1546: '</td></tr>';
1547: }
1548: }
1549: &recurse_print(\$output,$parent,\%deps,\%display);
1550: $output .= '</table></fieldset>';
1551: }
1552: $output .= '</div>';
1553: return $output;
1554: }
1555:
1556: sub recurse_print {
1557: my ($outputref,$dir,$deps,$display) = @_;
1558: $$outputref .= $display->{$dir}."\n";
1559: if (ref($deps->{$dir}) eq 'ARRAY') {
1560: foreach my $subdir (@{$deps->{$dir}}) {
1561: &recurse_print($outputref,$subdir,$deps,$display);
1562: }
1563: }
1564: }
1565:
1566: sub supp_pasteable {
1567: my ($url) = @_;
1568: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1569: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1570: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1571: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1572: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1573: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1574: return 1;
1575: }
1576: return;
1577: }
1578:
1579: sub paste_popup_js {
1580: my %html_js_lt = &Apache::lonlocal::texthash(
1581: show => 'Show Options',
1582: hide => 'Hide Options',
1583: );
1584: my %js_lt = &Apache::lonlocal::texthash(
1585: none => 'No items selected from clipboard.',
1586: );
1587: &html_escape(\%html_js_lt);
1588: &js_escape(\%html_js_lt);
1589: &js_escape(\%js_lt);
1590: return <<"END";
1591:
1592: function showPasteOptions(suffix) {
1593: document.getElementById('pasteoptions_'+suffix).style.display='block';
1594: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1595: return;
1596: }
1597:
1598: function hidePasteOptions(suffix) {
1599: document.getElementById('pasteoptions_'+suffix).style.display='none';
1600: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1601: return;
1602: }
1603:
1604: function showOptions(caller,suffix) {
1605: if (document.getElementById('pasteoptionstext_'+suffix)) {
1606: if (caller.checked) {
1607: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1608: } else {
1609: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1610: }
1611: if (document.getElementById('pasteoptions_'+suffix)) {
1612: document.getElementById('pasteoptions_'+suffix).style.display='none';
1613: }
1614: }
1615: return;
1616: }
1617:
1618: function validateClipboard() {
1619: var numchk = 0;
1620: if (document.pasteform.pasting.length > 1) {
1621: for (var i=0; i<document.pasteform.pasting.length; i++) {
1622: if (document.pasteform.pasting[i].checked) {
1623: numchk ++;
1624: }
1625: }
1626: } else {
1627: if (document.pasteform.pasting.type == 'checkbox') {
1628: if (document.pasteform.pasting.checked) {
1629: numchk ++;
1630: }
1631: }
1632: }
1633: if (numchk > 0) {
1634: return true;
1635: } else {
1636: alert("$js_lt{'none'}");
1637: return false;
1638: }
1639: }
1640:
1641: function checkClipboard() {
1642: if (document.pasteform.pasting.length > 1) {
1643: for (var i=0; i<document.pasteform.pasting.length; i++) {
1644: document.pasteform.pasting[i].checked = true;
1645: }
1646: }
1647: return;
1648: }
1649:
1650: function uncheckClipboard() {
1651: if (document.pasteform.pasting.length >1) {
1652: for (var i=0; i<document.pasteform.pasting.length; i++) {
1653: document.pasteform.pasting[i].checked = false;
1654: }
1655: }
1656: return;
1657: }
1658:
1659: END
1660:
1661: }
1662:
1663: sub do_paste_from_buffer {
1664: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1665:
1666: # Array of items in paste buffer
1667: my (@currpaste,%pastebuffer,%allerrors);
1668: @currpaste = split(/,/,$env{'docs.markedcopies'});
1669:
1670: # Early out if paste buffer is empty
1671: if (@currpaste == 0) {
1672: return ();
1673: }
1674: map { $pastebuffer{$_} = 1; } @currpaste;
1675:
1676: # Array of items selected items to paste
1677: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1678:
1679: # Early out if nothing selected to paste
1680: if (@reqpaste == 0) {
1681: return();
1682: }
1683: my @topaste;
1684: foreach my $suffix (@reqpaste) {
1685: next if ($suffix =~ /\D/);
1686: next unless (exists($pastebuffer{$suffix}));
1687: push(@topaste,$suffix);
1688: }
1689:
1690: # Early out if nothing available to paste
1691: if (@topaste == 0) {
1692: return();
1693: }
1694:
1695: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1696: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1697:
1698: foreach my $suffix (@topaste) {
1699: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1700: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1701: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1702: # Supplemental content may only include certain types of content
1703: # Early out if pasted content is not supported in Supplemental area
1704: if ($folder =~ /^supplemental/) {
1705: unless (&supp_pasteable($url)) {
1706: $notinsupp{$suffix} = 1;
1707: next;
1708: }
1709: }
1710: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1711: my $srcd = $1;
1712: my $srcn = $2;
1713: # When paste buffer was populated using an active role in a different course
1714: # check for mdc privilege in the course from which the resource was pasted
1715: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1716: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1717: $notincrs{$suffix} = 1;
1718: next;
1719: }
1720: }
1721: $srcdom{$suffix} = $srcd;
1722: $srcnum{$suffix} = $srcn;
1723: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1724: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1725: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1726: my ($srcd,$srcn) = split(/_/,$cid);
1727: # When paste buffer was populated using an active role in a different course
1728: # check for mdc privilege in the course from which the resource was pasted
1729: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1730: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1731: $notincrs{$suffix} = 1;
1732: next;
1733: }
1734: }
1735: # When buffer was populated using an active role in a different course
1736: # disallow pasting of External Tool if course is in a different domain.
1737: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1738: $notindom{$suffix} = 1;
1739: next;
1740: }
1741: $srcdom{$suffix} = $srcd;
1742: $srcnum{$suffix} = $srcn;
1743: }
1744: $srcmapidx{$suffix} = $mapidx;
1745: push(@dopaste,$suffix);
1746: if ($url=~/\.(page|sequence)$/) {
1747: $is_map{$suffix} = 1;
1748: }
1749: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1750: my $oldprefix = $1;
1751: # When pasting content from Main Content to Supplemental Content and vice versa
1752: # URLs will contain different paths (which depend on whether pasted item is
1753: # a folder/page or a document).
1754: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1755: $prefixchg{$suffix} = 'docstosupp';
1756: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1757: $prefixchg{$suffix} = 'supptodocs';
1758: }
1759:
1760: # If pasting an uploaded map, get list of contained uploaded maps.
1761: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1762: my @nested;
1763: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1764: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1765: my @deps = map { /\d+:([\d,]+$)/ } @items;
1766: foreach my $dep (@deps) {
1767: if ($dep =~ /,/) {
1768: push(@nested,split(/,/,$dep));
1769: } else {
1770: push(@nested,$dep);
1771: }
1772: }
1773: foreach my $item (@nested) {
1774: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1775: push(@{$marktomove{$suffix}},$type.'_'.$item);
1776: }
1777: }
1778: }
1779: }
1780: }
1781:
1782: # Early out if nothing available to paste
1783: if (@dopaste == 0) {
1784: return ();
1785: }
1786:
1787: # Populate message hash and hashes used for main content <=> supplemental content
1788: # changes
1789:
1790: %msgs = &Apache::lonlocal::texthash (
1791: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1792: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1793: notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1794: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1795: );
1796:
1797: %before = (
1798: docstosupp => {
1799: map => 'default',
1800: doc => 'docs',
1801: },
1802: supptodocs => {
1803: map => 'supplemental',
1804: doc => 'supplemental',
1805: },
1806: );
1807:
1808: %after = (
1809: docstosupp => {
1810: map => 'supplemental',
1811: doc => 'supplemental'
1812: },
1813: supptodocs => {
1814: map => 'default',
1815: doc => 'docs',
1816: },
1817: );
1818:
1819: # Retrieve information about all course maps in main content area
1820:
1821: my $allmaps = {};
1822: if ($folder =~ /^default/) {
1823: $allmaps =
1824: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1825: $env{"course.$env{'request.course.id'}.home"},
1826: $env{'request.course.id'});
1827: }
1828:
1829: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1830:
1831: # Loop over the items to paste
1832: foreach my $suffix (@dopaste) {
1833: # Maps need to be copied first
1834: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1835: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1836: %newurls,%tomove,%resdatacopy);
1837: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1838: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1839: }
1840: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1841: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1842: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1843: my $oldurl = $url;
1844: if ($is_map{$suffix}) {
1845: # If pasting a map, check if map contains other maps
1846: my (%hierarchy,%titles);
1847: &contained_map_check($url,$folder,$coursenum,$coursedom,
1848: \%removefrommap,\%removeparam,\%addedmaps,
1849: \%hierarchy,\%titles,$allmaps);
1850: if ($url=~ m{^/uploaded/}) {
1851: my $newurl;
1852: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1853: ($newurl,my $error) =
1854: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1855: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1856: \$title,$allmaps,\%newurls);
1857: if ($error) {
1858: $allerrors{$suffix} = $error;
1859: next;
1860: }
1861: if ($newurl ne '') {
1862: if ($newurl ne $url) {
1863: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1864: $newsubdir{$url} = $1;
1865: }
1866: $mapchanges{$url} = 1;
1867: }
1868: }
1869: }
1870: if (($srcdom{$suffix} ne $coursedom) ||
1871: ($srcnum{$suffix} ne $coursenum) ||
1872: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1873: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1874: $coursedom,$coursenum,$srcdom{$suffix},
1875: $srcnum{$suffix},$allmaps,\%rewrites,
1876: \%retitles,\%copies,\%dbcopies,
1877: \%zombies,\%params,\%mapmoves,
1878: \%mapchanges,\%tomove,\%newsubdir,
1879: \%newurls,\%resdatacopy)) {
1880: $mapmoves{$url} = 1;
1881: }
1882: $url = $newurl;
1883: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1884: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1885: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1886: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1887: \%zombies,\%params,\%mapmoves,\%mapchanges,
1888: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1889: }
1890: } elsif ($url=~m {^/res/}) {
1891: # published map can only exist once, so remove from paste buffer when done
1892: push(@toclear,$suffix);
1893: # if pasting published map (main content area only) check map not already in course
1894: if ($folder =~ /^default/) {
1895: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1896: $duplicate{$suffix} = 1;
1897: next;
1898: }
1899: }
1900: }
1901: }
1902: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1903: my $prefix = $1;
1904: my $fromothercrs;
1905: #need to copy the db contents to a new one, unless this is a move.
1906: my %info = (
1907: src => $url,
1908: cdom => $coursedom,
1909: cnum => $coursenum,
1910: );
1911: if ($prefix eq 'ext.tool') {
1912: if ($prefixchg{$suffix} eq 'docstosupp') {
1913: $info{'delgradable'} = 1;
1914: }
1915: }
1916: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1917: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1918: $fromothercrs = 1;
1919: $info{'cdom'} = $srcdom{$suffix};
1920: $info{'cnum'} = $srcnum{$suffix};
1921: }
1922: }
1923: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1924: my (%lockerr,$msg);
1925: my ($newurl,$result,$errtext) =
1926: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1927: if ($result eq 'ok') {
1928: $url = $newurl;
1929: $title=&mt('Copy of').' '.$title;
1930: } else {
1931: if ($prefix eq 'smppg') {
1932: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1933: } elsif ($prefix eq 'bulletinboard') {
1934: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1935: } elsif ($prefix eq 'ext.tool') {
1936: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1937: }
1938: $results{$suffix} = $result;
1939: $msgerrs{$suffix} = $msg;
1940: $lockerrs{$suffix} = $lockerr{$prefix};
1941: next;
1942: }
1943: if ($lockerr{$prefix}) {
1944: $lockerrs{$suffix} = $lockerr{$prefix};
1945: }
1946: }
1947: }
1948: $title = &LONCAPA::map::qtunescape($title);
1949: my $ext='false';
1950: if ($url=~m{^http(|s)://}) { $ext='true'; }
1951: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1952: if ($folder !~ /^supplemental/) {
1953: (undef,undef,$title) =
1954: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1955: }
1956: } else {
1957: if ($folder=~/^supplemental/) {
1958: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1959: $env{'user.domain'}.'___&&&___'.$title;
1960: }
1961: }
1962:
1963: # For uploaded files (excluding pages/sequences) path in copied file is changed
1964: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1965: # courses.
1966:
1967: unless ($is_map{$suffix}) {
1968: my $newidx;
1969: # Now insert the URL at the bottom
1970: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1971: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1972: my $relpath = $1;
1973: if ($relpath ne '') {
1974: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1975: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1976: my $newprefix = $newloc;
1977: if ($newloc eq 'default') {
1978: $newprefix = 'docs';
1979: }
1980: if ($newdocsdir eq '') {
1981: $newdocsdir = 'default';
1982: }
1983: if (($prefixchg{$suffix}) ||
1984: ($srcdom{$suffix} ne $coursedom) ||
1985: ($srcnum{$suffix} ne $coursenum) ||
1986: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1987: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1988: $url =
1989: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1990: &Apache::lonnet::getfile($oldurl));
1991: if ($url eq '/adm/notfound.html') {
1992: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1993: next;
1994: } else {
1995: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1996: $newsubpath =~ s{/+$}{/};
1997: $docmoves{$oldurl} = $newsubpath;
1998: }
1999: }
2000: }
2001: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2002: my $template = $1;
2003: if ($newidx) {
2004: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2005: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2006: }
2007: } elsif ($url =~ /ext\.tool$/) {
2008: if (($newidx) && ($folder=~/^default/)) {
2009: my $marker = (split(m{/},$url))[4];
2010: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2011: my $val = 'no';
2012: if ($toolsettings{'gradable'}) {
2013: $val = 'yes';
2014: }
2015: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2016: 'string_yesno');
2017: &remember_parms($newidx,'gradable','set',$val);
2018: }
2019: }
2020: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2021: ':'.$ext.':normal:res';
2022: push(@LONCAPA::map::order,$newidx);
2023: # Store the result
2024: my ($errtext,$fatal) =
2025: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2026: if ($fatal) {
2027: $save_err .= $errtext;
2028: $allresult = 'fail';
2029: }
2030: }
2031:
2032: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2033: # resourcedata for simpleproblems copied from another course
2034: unless ($allresult eq 'fail') {
2035: my %updated = (
2036: rewrites => \%rewrites,
2037: zombies => \%zombies,
2038: removefrommap => \%removefrommap,
2039: removeparam => \%removeparam,
2040: dbcopies => \%dbcopies,
2041: resdatacopy => \%resdatacopy,
2042: retitles => \%retitles,
2043: );
2044: my %info = (
2045: newsubdir => \%newsubdir,
2046: params => \%params,
2047: );
2048: if ($prefixchg{$suffix}) {
2049: $info{'before'} = $before{$prefixchg{$suffix}};
2050: $info{'after'} = $after{$prefixchg{$suffix}};
2051: }
2052: my %moves = (
2053: copies => \%copies,
2054: docmoves => \%docmoves,
2055: mapmoves => \%mapmoves,
2056: );
2057: (my $result,$msgs{$suffix},my $lockerror) =
2058: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2059: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2060: $url,'paste');
2061: $lockerrors .= $lockerror;
2062: if ($result eq 'ok') {
2063: if ($is_map{$suffix}) {
2064: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2065: $folder.'.'.$container);
2066: if ($fatal) {
2067: $allresult = 'failread';
2068: } else {
2069: if ($#LONCAPA::map::order<1) {
2070: my $idx=&LONCAPA::map::getresidx();
2071: if ($idx<=0) { $idx=1; }
2072: $LONCAPA::map::order[0]=$idx;
2073: $LONCAPA::map::resources[$idx]='';
2074: }
2075: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2076: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2077: ':'.$ext.':normal:res';
2078: push(@LONCAPA::map::order,$newidx);
2079:
2080: # Store the result
2081: my ($errtext,$fatal) =
2082: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2083: if ($fatal) {
2084: $save_err .= $errtext;
2085: $allresult = 'failstore';
2086: }
2087: }
2088: }
2089: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2090: push(@toclear,$suffix);
2091: }
2092: }
2093: }
2094: }
2095: &clear_from_buffer(\@toclear,\@currpaste);
2096: my $msgsarray;
2097: foreach my $suffix (keys(%msgs)) {
2098: if (ref($msgs{$suffix}) eq 'ARRAY') {
2099: $msgsarray .= join(',',@{$msgs{$suffix}});
2100: }
2101: }
2102: return ($allresult,$save_err,$msgsarray,$lockerrors);
2103: }
2104:
2105: sub do_buffer_empty {
2106: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2107: if (@currpaste == 0) {
2108: return &mt('Clipboard is already empty');
2109: }
2110: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2111: if (@toclear == 0) {
2112: return &mt('Nothing selected to clear from clipboard');
2113: }
2114: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2115: if ($numdel) {
2116: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2117: } else {
2118: return &mt('Clipboard unchanged');
2119: }
2120: return;
2121: }
2122:
2123: sub clear_from_buffer {
2124: my ($toclear,$currpaste) = @_;
2125: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2126: my %pastebuffer;
2127: map { $pastebuffer{$_} = 1; } @{$currpaste};
2128: my $numdel = 0;
2129: foreach my $suffix (@{$toclear}) {
2130: next if ($suffix =~ /\D/);
2131: next unless (exists($pastebuffer{$suffix}));
2132: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2133: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2134: delete($pastebuffer{$suffix});
2135: $numdel ++;
2136: }
2137: }
2138: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2139: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2140: return $numdel;
2141: }
2142:
2143: sub get_newmap_url {
2144: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2145: $titleref,$allmaps,$newurls) = @_;
2146: my $newurl;
2147: if ($url=~ m{^/uploaded/}) {
2148: $$titleref=&mt('Copy of').' '.$$titleref;
2149: }
2150: my $now = time;
2151: my $suffix=$$.int(rand(100)).$now;
2152: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2153: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2154: my $path = $1;
2155: my $prefix = $2;
2156: my $ancestor = $3;
2157: if (length($ancestor) > 10) {
2158: $ancestor = substr($ancestor,-10,10);
2159: }
2160: my $newid;
2161: if ($prefixchg) {
2162: if ($folder =~ /^supplemental/) {
2163: $prefix =~ s/^default/supplemental/;
2164: } else {
2165: $prefix =~ s/^supplemental/default/;
2166: }
2167: }
2168: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2169: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2170: } else {
2171: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2172: }
2173: my $counter = 0;
2174: my $is_unique = &uniqueness_check($newurl);
2175: if ($folder =~ /^default/) {
2176: if ($allmaps->{$newurl}) {
2177: $is_unique = 0;
2178: }
2179: }
2180: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2181: $counter ++;
2182: $suffix ++;
2183: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2184: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2185: } else {
2186: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2187: }
2188: $is_unique = &uniqueness_check($newurl);
2189: }
2190: if ($is_unique) {
2191: $newurls->{$newurl} = 1;
2192: } else {
2193: if ($url=~/\.page$/) {
2194: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2195: } else {
2196: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2197: }
2198: }
2199: }
2200: return ($newurl);
2201: }
2202:
2203: sub dbcopy {
2204: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2205: my ($url,$result,$errtext);
2206: if (ref($dbref) eq 'HASH') {
2207: $url = $dbref->{'src'};
2208: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
2209: my $prefix = $1;
2210: if ($prefix eq 'ext.tool') {
2211: $prefix = 'exttool';
2212: }
2213: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2214: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2215: my $db_name;
2216: my $marker = (split(m{/},$url))[4];
2217: $marker=~s/\D//g;
2218: if ($dbref->{'src'} =~ m{/smppg$}) {
2219: $db_name =
2220: &Apache::lonsimplepage::get_db_name($url,$marker,
2221: $dbref->{'cdom'},
2222: $dbref->{'cnum'});
2223: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2224: $db_name = 'exttool_'.$marker;
2225: } else {
2226: $db_name = 'bulletinpage_'.$marker;
2227: }
2228: my ($suffix,$freedlock,$error) =
2229: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2230: $coursedom,$coursenum,
2231: 'concat');
2232: if (!$suffix) {
2233: if ($prefix eq 'smppg') {
2234: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2235: } elsif ($prefix eq 'exttool') {
2236: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
2237: } else {
2238: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
2239: }
2240: if ($error) {
2241: $errtext .= '<br />'.$error;
2242: }
2243: } else {
2244: #need to copy the db contents to a new one.
2245: my %contents=&Apache::lonnet::dump($db_name,
2246: $dbref->{'cdom'},
2247: $dbref->{'cnum'});
2248: if (exists($contents{'uploaded.photourl'})) {
2249: my $photo = $contents{'uploaded.photourl'};
2250: my ($subdir,$fname) =
2251: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2252: my $newphoto;
2253: if ($fname ne '') {
2254: my $content = &Apache::lonnet::getfile($photo);
2255: unless ($content eq '-1') {
2256: $env{'form.'.$suffix.'.photourl'} = $content;
2257: $newphoto =
2258: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2259: delete($env{'form.'.$suffix.'.photourl'});
2260: }
2261: }
2262: if ($newphoto =~ m{^/uploaded/}) {
2263: $contents{'uploaded.photourl'} = $newphoto;
2264: }
2265: }
2266: $db_name =~ s{_\d*$ }{_$suffix}x;
2267: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2268: delete($contents{'gradable'});
2269: }
2270: $result=&Apache::lonnet::put($db_name,\%contents,
2271: $coursedom,$coursenum);
2272: if ($result eq 'ok') {
2273: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
2274: }
2275: }
2276: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2277: $lockerrorsref->{$prefix} =
2278: '<div class="LC_error">'.
2279: &mt('There was a problem removing a lockfile.');
2280: if ($prefix eq 'smppg') {
2281: $lockerrorsref->{$prefix} .=
2282: ' '.&mt('This will prevent creation of additional simple pages in this course.');
2283: } elsif ($prefix eq 'exttool') {
2284: $lockerrorsref->{$prefix} .=
2285: ' '.&mt('This will prevent addition of more external tools to this course.');
2286: } else {
2287: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
2288: }
2289: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2290: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2291: '</div>';
2292: }
2293: }
2294: } elsif ($url =~ m{/syllabus$}) {
2295: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2296: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2297: if (($dbref->{'cdom'} ne $coursedom) ||
2298: ($dbref->{'cnum'} ne $coursenum)) {
2299: my %contents=&Apache::lonnet::dump('syllabus',
2300: $dbref->{'cdom'},
2301: $dbref->{'cnum'});
2302: $result=&Apache::lonnet::put('syllabus',\%contents,
2303: $coursedom,$coursenum);
2304: }
2305: }
2306: }
2307: }
2308: return ($url,$result,$errtext);
2309: }
2310:
2311: sub copy_templated_files {
2312: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2313: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2314: my $srccontainer = 'sequence';
2315: if ($srcwaspage) {
2316: $srccontainer = 'page';
2317: }
2318: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2319: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2320: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2321: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2322: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2323: $template.'.problem';
2324: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2325: if ($template eq 'simpleproblem') {
2326: $srcprefix .= '.0.';
2327: my $weightprefix = $newprefix;
2328: $newprefix .= '.0.';
2329: my @simpleprobqtypes = qw(radio option string essay numerical);
2330: my $qtype=$srcparms{$srcprefix.'questiontype'};
2331: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2332: my %newdata;
2333: foreach my $type (@simpleprobqtypes) {
2334: if ($type eq $qtype) {
2335: $newdata{"$weightprefix.$type.weight"}=1;
2336: } else {
2337: $newdata{"$weightprefix.$type.weight"}=0;
2338: }
2339: }
2340: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2341: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2342: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2343: if ($qtype eq 'numerical') {
2344: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2345: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2346: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2347: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2348: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2349: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2350: unless (defined($maxfoils)) { $maxfoils=10; }
2351: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2352: if ($maxfoils<=0) { $maxfoils=10; }
2353: my $randomize=$srcparms{$srcprefix.'randomize'};
2354: unless (defined($randomize)) { $randomize='yes'; }
2355: unless ($randomize eq 'no') { $randomize='yes'; }
2356: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2357: $newdata{$newprefix.'randomize'} = $randomize;
2358: if ($qtype eq 'option') {
2359: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2360: }
2361: for (my $i=1; $i<=10; $i++) {
2362: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2363: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2364: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2365: }
2366:
2367: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2368: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2369: unless (defined($maxfoils)) { $maxfoils=10; }
2370: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2371: if ($maxfoils<=0) { $maxfoils=10; }
2372: my $randomize=$srcparms{$srcprefix.'randomize'};
2373: unless (defined($randomize)) { $randomize='yes'; }
2374: unless ($randomize eq 'no') { $randomize='yes'; }
2375: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2376: $newdata{$newprefix.'randomize'} = $randomize;
2377: if ($qtype eq 'option') {
2378: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2379: }
2380: for (my $i=1; $i<=10; $i++) {
2381: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2382: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2383: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2384: }
2385: } elsif ($qtype eq 'string') {
2386: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2387: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2388: }
2389: if (keys(%newdata)) {
2390: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2391: $coursenum);
2392: if ($putres eq 'ok') {
2393: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2394: }
2395: }
2396: }
2397: }
2398: }
2399:
2400: sub uniqueness_check {
2401: my ($newurl) = @_;
2402: my $unique = 1;
2403: foreach my $res (@LONCAPA::map::order) {
2404: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2405: $url=&LONCAPA::map::qtescape($url);
2406: if ($newurl eq $url) {
2407: $unique = 0;
2408: last;
2409: }
2410: }
2411: return $unique;
2412: }
2413:
2414: sub contained_map_check {
2415: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2416: $hierarchy,$titles,$allmaps) = @_;
2417: my $content = &Apache::lonnet::getfile($url);
2418: unless ($content eq '-1') {
2419: my $parser = HTML::TokeParser->new(\$content);
2420: $parser->attr_encoded(1);
2421: while (my $token = $parser->get_token) {
2422: next if ($token->[0] ne 'S');
2423: if ($token->[1] eq 'resource') {
2424: next if ($token->[2]->{'type'} eq 'zombie');
2425: my $ressrc = $token->[2]->{'src'};
2426: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2427: my $srcdom = $1;
2428: unless ($srcdom eq $coursedom) {
2429: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2430: next;
2431: }
2432: } elsif ($folder =~ /^supplemental/) {
2433: unless (&supp_pasteable($ressrc)) {
2434: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2435: next;
2436: }
2437: }
2438: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2439: if ($1 eq 'uploaded') {
2440: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2441: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2442: } else {
2443: if ($allmaps->{$ressrc}) {
2444: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2445: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2446: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2447: } else {
2448: $addedmaps->{$ressrc} = [$url];
2449: }
2450: }
2451: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2452: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
2453: }
2454: } elsif ($token->[1] eq 'param') {
2455: if ($folder =~ /^supplemental/) {
2456: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2457: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2458: } else {
2459: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2460: }
2461: }
2462: }
2463: }
2464: }
2465: return;
2466: }
2467:
2468: sub url_paste_fixups {
2469: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2470: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
2471: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
2472: my $checktitle;
2473: if (($prefixchg) &&
2474: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2475: $checktitle = 1;
2476: }
2477: my $skip;
2478: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2479: my $mapid = $1.$2;
2480: if ($tomove->{$mapid}) {
2481: $skip = 1;
2482: }
2483: }
2484: my $file = &Apache::lonnet::getfile($oldurl);
2485: return if ($file eq '-1');
2486: my $parser = HTML::TokeParser->new(\$file);
2487: $parser->attr_encoded(1);
2488: my $changed = 0;
2489: while (my $token = $parser->get_token) {
2490: next if ($token->[0] ne 'S');
2491: if ($token->[1] eq 'resource') {
2492: my $ressrc = $token->[2]->{'src'};
2493: next if ($ressrc eq '');
2494: my $id = $token->[2]->{'id'};
2495: my $title = $token->[2]->{'title'};
2496: if ($checktitle) {
2497: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2498: $retitles->{$oldurl}{$id} = $ressrc;
2499: }
2500: }
2501: next if ($token->[2]->{'type'} eq 'external');
2502: if ($token->[2]->{'type'} eq 'zombie') {
2503: next if ($skip);
2504: $zombies->{$oldurl}{$id} = $ressrc;
2505: $changed = 1;
2506: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2507: my $srcdom = $1;
2508: my $srcnum = $2;
2509: my $rem = $3;
2510: my $newurl;
2511: my $mapname;
2512: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2513: my $prefix = $1;
2514: $mapname = $prefix.$2;
2515: if ($tomove->{$mapname}) {
2516: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2517: $srcdom,$srcnum,$allmaps,$rewrites,
2518: $retitles,$copies,$dbcopies,$zombies,
2519: $params,$mapmoves,$mapchanges,$tomove,
2520: $newsubdir,$newurls,$resdatacopy);
2521: next;
2522: } else {
2523: ($newurl,my $error) =
2524: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2525: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2526: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2527: $newsubdir->{$ressrc} = $1;
2528: }
2529: if ($error) {
2530: next;
2531: }
2532: }
2533: }
2534: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2535: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2536:
2537: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2538: $rewrites->{$oldurl}{$id} = $ressrc;
2539: $mapchanges->{$ressrc} = 1;
2540: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2541: $cnum,$srcdom,$srcnum,$allmaps,
2542: $rewrites,$retitles,$copies,$dbcopies,
2543: $zombies,$params,$mapmoves,$mapchanges,
2544: $tomove,$newsubdir,$newurls,$resdatacopy)) {
2545: $mapmoves->{$ressrc} = 1;
2546: }
2547: $changed = 1;
2548: } else {
2549: $rewrites->{$oldurl}{$id} = $ressrc;
2550: $copies->{$oldurl}{$ressrc} = $id;
2551: $changed = 1;
2552: }
2553: }
2554: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
2555: next if ($skip);
2556: my $srcdom = $1;
2557: my $srcnum = $2;
2558: my $rem = $3;
2559: my ($is_exttool,$exttoolchg);
2560: if ($rem =~ m{\d+/ext\.tool$}) {
2561: $is_exttool = 1;
2562: }
2563: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2564: $rewrites->{$oldurl}{$id} = $ressrc;
2565: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2566: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2567: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2568: $changed = 1;
2569: if ($is_exttool) {
2570: $exttoolchg = 1;
2571: }
2572: } elsif (($rem =~ m{\d+/ext\.tool$}) &&
2573: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2574: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2575: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2576: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2577: $changed = 1;
2578: $exttoolchg = 1;
2579: }
2580: if (($is_exttool) && ($prefixchg)) {
2581: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2582: if ($exttoolchg) {
2583: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2584: }
2585: }
2586: }
2587: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2588: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2589: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2590: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2591: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2592: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
2593: $changed = 1;
2594: }
2595: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2596: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2597: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2598: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2599: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2600: }
2601: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2602: next if ($skip);
2603: my $srcdom = $1;
2604: my $srcnum = $2;
2605: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2606: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2607: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2608: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2609: $changed = 1;
2610: }
2611: }
2612: } elsif ($token->[1] eq 'param') {
2613: next if ($skip);
2614: my $to = $token->[2]->{'to'};
2615: if ($to ne '') {
2616: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2617: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2618: } else {
2619: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2620: }
2621: }
2622: }
2623: }
2624: return $changed;
2625: }
2626:
2627: sub apply_fixups {
2628: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2629: $oldurl,$url,$caller) = @_;
2630: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
2631: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
2632: %resdatacopy,%lockerrors,$lockmsg);
2633: if (ref($updated) eq 'HASH') {
2634: if (ref($updated->{'rewrites'}) eq 'HASH') {
2635: %rewrites = %{$updated->{'rewrites'}};
2636: }
2637: if (ref($updated->{'zombies'}) eq 'HASH') {
2638: %zombies = %{$updated->{'zombies'}};
2639: }
2640: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2641: %removefrommap = %{$updated->{'removefrommap'}};
2642: }
2643: if (ref($updated->{'removeparam'}) eq 'HASH') {
2644: %removeparam = %{$updated->{'removeparam'}};
2645: }
2646: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2647: %dbcopies = %{$updated->{'dbcopies'}};
2648: }
2649: if (ref($updated->{'retitles'}) eq 'HASH') {
2650: %retitles = %{$updated->{'retitles'}};
2651: }
2652: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2653: %resdatacopy = %{$updated->{'resdatacopy'}};
2654: }
2655: }
2656: if (ref($info) eq 'HASH') {
2657: if (ref($info->{'newsubdir'}) eq 'HASH') {
2658: %newsubdir = %{$info->{'newsubdir'}};
2659: }
2660: if (ref($info->{'params'}) eq 'HASH') {
2661: %params = %{$info->{'params'}};
2662: }
2663: if (ref($info->{'before'}) eq 'HASH') {
2664: %before = %{$info->{'before'}};
2665: }
2666: if (ref($info->{'after'}) eq 'HASH') {
2667: %after = %{$info->{'after'}};
2668: }
2669: }
2670: if (ref($moves) eq 'HASH') {
2671: if (ref($moves->{'copies'}) eq 'HASH') {
2672: %copies = %{$moves->{'copies'}};
2673: }
2674: if (ref($moves->{'docmoves'}) eq 'HASH') {
2675: %docmoves = %{$moves->{'docmoves'}};
2676: }
2677: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2678: %mapmoves = %{$moves->{'mapmoves'}};
2679: }
2680: }
2681: foreach my $key (keys(%copies),keys(%docmoves)) {
2682: my @allcopies;
2683: if (exists($copies{$key})) {
2684: if (ref($copies{$key}) eq 'HASH') {
2685: my %added;
2686: foreach my $innerkey (keys(%{$copies{$key}})) {
2687: if (($innerkey ne '') && (!$added{$innerkey})) {
2688: push(@allcopies,$innerkey);
2689: $added{$innerkey} = 1;
2690: }
2691: }
2692: undef(%added);
2693: }
2694: }
2695: if ($key eq $oldurl) {
2696: if ((exists($docmoves{$key}))) {
2697: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
2698: push(@allcopies,$oldurl);
2699: }
2700: }
2701: }
2702: if (@allcopies > 0) {
2703: foreach my $item (@allcopies) {
2704: my ($relpath,$oldsubdir,$fname) =
2705: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2706: if ($fname ne '') {
2707: my $content = &Apache::lonnet::getfile($item);
2708: unless ($content eq '-1') {
2709: my $storefn;
2710: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2711: $storefn = $docmoves{$key};
2712: } else {
2713: $storefn = $relpath;
2714: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
2715: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2716: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
2717: }
2718: if ($newsubdir{$key}) {
2719: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
2720: }
2721: }
2722: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2723: my $copyurl =
2724: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2725: $storefn.$fname,$content);
2726: if ($copyurl eq '/adm/notfound.html') {
2727: if (exists($docmoves{$oldurl})) {
2728: return &mt('Paste failed: an error occurred copying the file.');
2729: } elsif (ref($errors) eq 'HASH') {
2730: $errors->{$item} = 1;
2731: }
2732: }
2733: }
2734: }
2735: }
2736: }
2737: }
2738: foreach my $key (keys(%mapmoves)) {
2739: my $storefn=$key;
2740: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2741: if ($prefixchg && $before{'map'} && $after{'map'}) {
2742: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2743: }
2744: if ($newsubdir{$key}) {
2745: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2746: }
2747: my $mapcontent = &Apache::lonnet::getfile($key);
2748: if ($mapcontent eq '-1') {
2749: if (ref($errors) eq 'HASH') {
2750: $errors->{$key} = 1;
2751: }
2752: } else {
2753: my $newmap =
2754: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2755: $mapcontent);
2756: if ($newmap eq '/adm/notfound.html') {
2757: if (ref($errors) eq 'HASH') {
2758: $errors->{$key} = 1;
2759: }
2760: }
2761: }
2762: }
2763: my %updates;
2764: if ($is_map) {
2765: if (ref($updated) eq 'HASH') {
2766: foreach my $type (keys(%{$updated})) {
2767: if (ref($updated->{$type}) eq 'HASH') {
2768: foreach my $key (keys(%{$updated->{$type}})) {
2769: $updates{$key} = 1;
2770: }
2771: }
2772: }
2773: }
2774: foreach my $key (keys(%updates)) {
2775: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
2776: if (ref($rewrites{$key}) eq 'HASH') {
2777: %torewrite = %{$rewrites{$key}};
2778: }
2779: if (ref($retitles{$key}) eq 'HASH') {
2780: %toretitle = %{$retitles{$key}};
2781: }
2782: if (ref($removefrommap{$key}) eq 'HASH') {
2783: %toremove = %{$removefrommap{$key}};
2784: }
2785: if (ref($removeparam{$key}) eq 'HASH') {
2786: %remparam = %{$removeparam{$key}};
2787: }
2788: if (ref($zombies{$key}) eq 'HASH') {
2789: %zombie = %{$zombies{$key}};
2790: }
2791: if (ref($dbcopies{$key}) eq 'HASH') {
2792: foreach my $idx (keys(%{$dbcopies{$key}})) {
2793: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2794: my ($newurl,$result,$errtext) =
2795: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2796: if ($result eq 'ok') {
2797: $newdb{$idx} = $newurl;
2798: } elsif (ref($errors) eq 'HASH') {
2799: $errors->{$key} = 1;
2800: }
2801: push(@msgs,$errtext);
2802: }
2803: }
2804: }
2805: if (ref($resdatacopy{$key}) eq 'HASH') {
2806: if ($newsubdir{$key}) {
2807:
2808: }
2809: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2810: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2811: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2812: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2813: my $template = $1;
2814: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2815: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2816: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2817: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2818: my ($newmapname) = ($key =~ m{/([^/]+)$});
2819: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2820: my $srcmapinfo = $srcfolder.':'.$idx;
2821: if ($srccontainer eq 'page') {
2822: $srcmapinfo .= ':1';
2823: }
2824: if ($newsubdir{$key}) {
2825: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2826: }
2827: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2828: $cnum,$template,$idx,$newmapname);
2829: }
2830: }
2831: }
2832: }
2833: }
2834: if (ref($params{$key}) eq 'HASH') {
2835: %currparam = %{$params{$key}};
2836: }
2837: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2838: if ($fatal) {
2839: return ($errtext);
2840: }
2841: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2842: if (defined($LONCAPA::map::zombies[$i])) {
2843: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
2844: if ($zombie{$i} eq $src) {
2845: undef($LONCAPA::map::zombies[$i]);
2846: }
2847: }
2848: }
2849: my $total = scalar(@LONCAPA::map::order) - 1;
2850: for (my $i=$total; $i>=0; $i--) {
2851: my $idx = $LONCAPA::map::order[$i];
2852: if (defined($LONCAPA::map::resources[$idx])) {
2853: my $changed;
2854: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
2855: if ((exists($toremove{$idx})) &&
2856: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
2857: splice(@LONCAPA::map::order,$i,1);
2858: if (ref($currparam{$idx}) eq 'ARRAY') {
2859: foreach my $name (@{$currparam{$idx}}) {
2860: &LONCAPA::map::delparameter($idx,$name);
2861: }
2862: }
2863: next;
2864: }
2865: my $origsrc = $src;
2866: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
2867: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2868: $changed = 1;
2869: }
2870: }
2871: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
2872: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2873: if ($origsrc =~ m{^/uploaded/}) {
2874: if ($prefixchg && $before{'map'} && $after{'map'}) {
2875: if ($src =~ /\.(page|sequence)$/) {
2876: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
2877: } else {
2878: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
2879: }
2880: }
2881: if ($origsrc =~ /\.(page|sequence)$/) {
2882: if ($newsubdir{$origsrc}) {
2883: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
2884: }
2885: } elsif ($newsubdir{$key}) {
2886: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
2887: }
2888: }
2889: $changed = 1;
2890: } elsif ($newdb{$idx} ne '') {
2891: $src = $newdb{$idx};
2892: $changed = 1;
2893: }
2894: if ($changed) {
2895: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
2896: }
2897: }
2898: }
2899: foreach my $idx (keys(%remparam)) {
2900: if (ref($remparam{$idx}) eq 'ARRAY') {
2901: foreach my $name (@{$remparam{$idx}}) {
2902: &LONCAPA::map::delparameter($idx,$name);
2903: }
2904: }
2905: }
2906: if (values(%lockerrors) > 0) {
2907: $lockmsg = join('<br />',values(%lockerrors));
2908: }
2909: my $storefn;
2910: if ($key eq $oldurl) {
2911: $storefn = $url;
2912: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2913: } else {
2914: $storefn = $key;
2915: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2916: if ($prefixchg && $before{'map'} && $after{'map'}) {
2917: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2918: }
2919: if ($newsubdir{$key}) {
2920: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2921: }
2922: }
2923: my $report;
2924: if ($folder !~ /^supplemental/) {
2925: $report = 1;
2926: }
2927: (my $outtext,$errtext) =
2928: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2929: if ($errtext) {
2930: if ($caller eq 'paste') {
2931: return (&mt('Paste failed: an error occurred saving the folder or page.'));
2932: }
2933: }
2934: }
2935: }
2936: return ('ok',\@msgs,$lockmsg);
2937: }
2938:
2939: sub copy_dependencies {
2940: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2941: my $content;
2942: if (ref($contentref)) {
2943: $content = $$contentref;
2944: } else {
2945: $content = &Apache::lonnet::getfile($item);
2946: }
2947: unless ($content eq '-1') {
2948: my $mm = new File::MMagic;
2949: my $mimetype = $mm->checktype_contents($content);
2950: if ($mimetype eq 'text/html') {
2951: my (%allfiles,%codebase,$state);
2952: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2953: if ($res eq 'ok') {
2954: my ($numexisting,$numpathchanges,$existing);
2955: (undef,$numexisting,$numpathchanges,$existing) =
2956: &Apache::loncommon::ask_for_embedded_content(
2957: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2958: {'error_on_invalid_names' => 1,
2959: 'ignore_remote_references' => 1,
2960: 'docs_url' => $item,
2961: 'context' => 'paste'});
2962: if ($numexisting > 0) {
2963: if (ref($existing) eq 'HASH') {
2964: foreach my $dep (keys(%{$existing})) {
2965: my $depfile = $dep;
2966: unless ($depfile =~ m{^\Q$relpath\E}) {
2967: $depfile = $relpath.$dep;
2968: }
2969: my $depcontent = &Apache::lonnet::getfile($depfile);
2970: unless ($depcontent eq '-1') {
2971: my $storedep = $dep;
2972: $storedep =~ s{^\Q$relpath\E}{};
2973: my $dep_url =
2974: &Apache::lonclonecourse::writefile(
2975: $env{'request.course.id'},
2976: $storefn.$storedep,$depcontent);
2977: if ($dep_url eq '/adm/notfound.html') {
2978: if (ref($errors) eq 'HASH') {
2979: $errors->{$depfile} = 1;
2980: }
2981: } else {
2982: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2983: }
2984: }
2985: }
2986: }
2987: }
2988: }
2989: }
2990: }
2991: return;
2992: }
2993:
2994: my %parameter_type = ( 'randompick' => 'int_pos',
2995: 'hiddenresource' => 'string_yesno',
2996: 'encrypturl' => 'string_yesno',
2997: 'randomorder' => 'string_yesno',);
2998: my $valid_parameters_re = join('|',keys(%parameter_type));
2999: # set parameters
3000: sub update_parameter {
3001: if ($env{'form.changeparms'} eq 'all') {
3002: my (@allidx,@allmapidx,%allchecked,%currchecked);
3003: %allchecked = (
3004: 'hiddenresource' => {},
3005: 'encrypturl' => {},
3006: 'randompick' => {},
3007: 'randomorder' => {},
3008: );
3009: foreach my $which (keys(%allchecked)) {
3010: $env{'form.all'.$which} =~ s/,$//;
3011: if ($which eq 'randompick') {
3012: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3013: my ($res,$value) = split(/:/,$item);
3014: if ($value =~ /^\d+$/) {
3015: $allchecked{$which}{$res} = $value;
3016: }
3017: }
3018: } else {
3019: if ($env{'form.all'.$which}) {
3020: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3021: }
3022: }
3023: }
3024: my $haschanges = 0;
3025: foreach my $res (@LONCAPA::map::order) {
3026: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3027: $name=&LONCAPA::map::qtescape($name);
3028: $url=&LONCAPA::map::qtescape($url);
3029: next unless ($name && $url);
3030: my $is_map;
3031: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3032: $is_map = 1;
3033: }
3034: foreach my $which (keys(%allchecked)) {
3035: if (($which eq 'randompick' || $which eq 'randomorder')) {
3036: next if (!$is_map);
3037: }
3038: my $oldvalue = 0;
3039: my $newvalue = 0;
3040: if ($allchecked{$which}{$res}) {
3041: $newvalue = $allchecked{$which}{$res};
3042: }
3043: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3044: if ($which eq 'randompick') {
3045: if ($current =~ /^(\d+)$/) {
3046: $oldvalue = $1;
3047: }
3048: } else {
3049: if ($current =~ /^yes$/i) {
3050: $oldvalue = 1;
3051: }
3052: }
3053: if ($oldvalue ne $newvalue) {
3054: $haschanges = 1;
3055: if ($newvalue) {
3056: my $storeval = 'yes';
3057: if ($which eq 'randompick') {
3058: $storeval = $newvalue;
3059: }
3060: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3061: $storeval,
3062: $parameter_type{$which});
3063: &remember_parms($res,$which,'set',$storeval);
3064: } elsif ($oldvalue) {
3065: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3066: &remember_parms($res,$which,'del');
3067: }
3068: }
3069: }
3070: }
3071: return $haschanges;
3072: } else {
3073: my $haschanges = 0;
3074: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
3075:
3076: my $which = $env{'form.changeparms'};
3077: my $idx = $env{'form.setparms'};
3078: my $oldvalue = 0;
3079: my $newvalue = 0;
3080: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3081: if ($which eq 'randompick') {
3082: if ($current =~ /^(\d+)$/) {
3083: $oldvalue = $1;
3084: }
3085: } elsif ($current =~ /^yes$/i) {
3086: $oldvalue = 1;
3087: }
3088: if ($env{'form.'.$which.'_'.$idx}) {
3089: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3090: : 1;
3091: }
3092: if ($oldvalue ne $newvalue) {
3093: $haschanges = 1;
3094: if ($newvalue) {
3095: my $storeval = 'yes';
3096: if ($which eq 'randompick') {
3097: $storeval = $newvalue;
3098: }
3099: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3100: $parameter_type{$which});
3101: &remember_parms($idx,$which,'set',$storeval);
3102: } else {
3103: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3104: &remember_parms($idx,$which,'del');
3105: }
3106: }
3107: return $haschanges;
3108: }
3109: }
3110:
3111: sub handle_edit_cmd {
3112: my ($coursenum,$coursedom) =@_;
3113: my $haschanges = 0;
3114: if ($env{'form.cmd'} eq '') {
3115: return $haschanges;
3116: }
3117: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3118:
3119: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3120: my ($title, $url, @rrest) = split(':', $ratstr);
3121:
3122: if ($cmd eq 'remove') {
3123: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3124: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3125: &Apache::lonnet::removeuploadedurl($url);
3126: } else {
3127: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3128: }
3129: splice(@LONCAPA::map::order, $idx, 1);
3130: $haschanges = 1;
3131: } elsif ($cmd eq 'cut') {
3132: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3133: splice(@LONCAPA::map::order, $idx, 1);
3134: $haschanges = 1;
3135: } elsif ($cmd eq 'up'
3136: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3137: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3138: $haschanges = 1;
3139: } elsif ($cmd eq 'down'
3140: && defined($LONCAPA::map::order[$idx+1])) {
3141: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3142: $haschanges = 1;
3143: } elsif ($cmd eq 'rename') {
3144: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3145: if ($comment=~/\S/) {
3146: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3147: $comment.':'.join(':', $url, @rrest);
3148: }
3149: # Devalidate title cache
3150: my $renamed_url=&LONCAPA::map::qtescape($url);
3151: &Apache::lonnet::devalidate_title_cache($renamed_url);
3152: $haschanges = 1;
3153: } elsif ($cmd eq 'setalias') {
3154: my $newvalue = $env{'form.alias'};
3155: if ($newvalue ne '') {
3156: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3157: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3158: 'string');
3159: &remember_parms($idx,'mapalias','set',$newvalue);
3160: $haschanges = 1;
3161: }
3162: }
3163: } elsif ($cmd eq 'delalias') {
3164: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3165: if ($current ne '') {
3166: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3167: &remember_parms($idx,'mapalias','del');
3168: $haschanges = 1;
3169: }
3170: }
3171: return $haschanges;
3172: }
3173:
3174: sub editor {
3175: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
3176: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3177: $canedit,$hostname,$navmapref,$hiddentop)=@_;
3178: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3179: if ($allowed) {
3180: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3181: $is_random_order,$container) =
3182: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3183: $r->print($breadcrumbtrail);
3184: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3185: $container = 'page';
3186: } else {
3187: $container = 'sequence';
3188: }
3189:
3190: my $jumpto;
3191:
3192: unless ($supplementalflag) {
3193: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
3194: }
3195:
3196: unless ($allowed) {
3197: $randompick = -1;
3198: }
3199:
3200: my ($errtext,$fatal);
3201: if (($folder eq '') && (!$supplementalflag)) {
3202: if (@LONCAPA::map::order) {
3203: undef(@LONCAPA::map::order);
3204: undef(@LONCAPA::map::resources);
3205: undef(@LONCAPA::map::resparms);
3206: undef(@LONCAPA::map::zombies);
3207: }
3208: $folder = 'default';
3209: $container = 'sequence';
3210: } else {
3211: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3212: $folder.'.'.$container);
3213: return $errtext if ($fatal);
3214: }
3215:
3216: if ($#LONCAPA::map::order<1) {
3217: my $idx=&LONCAPA::map::getresidx();
3218: if ($idx<=0) { $idx=1; }
3219: $LONCAPA::map::order[0]=$idx;
3220: $LONCAPA::map::resources[$idx]='';
3221: }
3222:
3223: # ------------------------------------------------------------ Process commands
3224:
3225: # ---------------- if they are for this folder and user allowed to make changes
3226: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
3227: # set parameters and change order
3228: &snapshotbefore();
3229:
3230: if (&update_parameter()) {
3231: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3232: return $errtext if ($fatal);
3233: }
3234:
3235: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3236: # change order
3237: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3238: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3239:
3240: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3241: return $errtext if ($fatal);
3242: }
3243:
3244: if ($env{'form.pastemarked'}) {
3245: my %paste_errors;
3246: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
3247: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3248: \%paste_errors);
3249: if (ref($pastemsgarray) eq 'ARRAY') {
3250: if (@{$pastemsgarray} > 0) {
3251: $r->print('<p class="LC_info">'.
3252: join('<br />',@{$pastemsgarray}).
3253: '</p>');
3254: }
3255: }
3256: if ($lockerror) {
3257: $r->print('<p class="LC_error">'.
3258: $lockerror.
3259: '</p>');
3260: }
3261: if ($save_error ne '') {
3262: return $save_error;
3263: }
3264: if ($paste_res) {
3265: my %errortext = &Apache::lonlocal::texthash (
3266: fail => 'Storage of folder contents failed',
3267: failread => 'Reading folder contents failed',
3268: failstore => 'Storage of folder contents failed',
3269: );
3270: if ($errortext{$paste_res}) {
3271: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
3272: }
3273: }
3274: if (keys(%paste_errors) > 0) {
3275: $r->print('<p class="LC_warning">'."\n".
3276: &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".
3277: '<ul>'."\n");
3278: foreach my $key (sort(keys(%paste_errors))) {
3279: $r->print('<li>'.$key.'</li>'."\n");
3280: }
3281: $r->print('</ul></p>'."\n");
3282: }
3283: } elsif ($env{'form.clearmarked'}) {
3284: my $output = &do_buffer_empty();
3285: if ($output) {
3286: $r->print('<p class="LC_info">'.$output.'</p>');
3287: }
3288: }
3289:
3290: $r->print($upload_output);
3291:
3292: # Rename, cut, copy or remove a single resource
3293: if (&handle_edit_cmd($coursenum,$coursedom)) {
3294: my $contentchg;
3295: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
3296: $contentchg = 1;
3297: }
3298: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
3299: return $errtext if ($fatal);
3300: }
3301:
3302: # Cut, copy and/or remove multiple resources
3303: if ($env{'form.multichange'}) {
3304: my %allchecked = (
3305: cut => {},
3306: remove => {},
3307: );
3308: my $needsupdate;
3309: foreach my $which (keys(%allchecked)) {
3310: $env{'form.multi'.$which} =~ s/,$//;
3311: if ($env{'form.multi'.$which}) {
3312: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3313: if (ref($allchecked{$which}) eq 'HASH') {
3314: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3315: }
3316: }
3317: }
3318: if ($needsupdate) {
3319: my $haschanges = 0;
3320: my %curr_groups = &Apache::longroup::coursegroups();
3321: my $total = scalar(@LONCAPA::map::order) - 1;
3322: for (my $i=$total; $i>=0; $i--) {
3323: my $res = $LONCAPA::map::order[$i];
3324: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3325: $name=&LONCAPA::map::qtescape($name);
3326: $url=&LONCAPA::map::qtescape($url);
3327: next unless $url;
3328: my %denied =
3329: &action_restrictions($coursenum,$coursedom,$url,
3330: $env{'form.folderpath'},\%curr_groups);
3331: foreach my $which (keys(%allchecked)) {
3332: next if ($denied{$which});
3333: next unless ($allchecked{$which}{$res});
3334: if ($which eq 'remove') {
3335: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3336: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3337: &Apache::lonnet::removeuploadedurl($url);
3338: } else {
3339: &LONCAPA::map::makezombie($res);
3340: }
3341: splice(@LONCAPA::map::order,$i,1);
3342: $haschanges ++;
3343: } elsif ($which eq 'cut') {
3344: &LONCAPA::map::makezombie($res);
3345: splice(@LONCAPA::map::order,$i,1);
3346: $haschanges ++;
3347: }
3348: }
3349: }
3350: if ($haschanges) {
3351: ($errtext,$fatal) =
3352: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3353: return $errtext if ($fatal);
3354: }
3355: }
3356: }
3357:
3358: # Group import/search
3359: if ($env{'form.importdetail'}) {
3360: my @imports;
3361: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3362: if (defined($item)) {
3363: my ($name,$url,$residx)=
3364: map { &unescape($_); } split(/\=/,$item);
3365: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3366: my ($suffix,$errortxt,$locknotfreed) =
3367: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
3368: if ($locknotfreed) {
3369: $r->print($locknotfreed);
3370: }
3371: if ($suffix) {
3372: $url =~ s/_new\./_$suffix./;
3373: } else {
3374: return $errortxt;
3375: }
3376: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3377: my $type = $1;
3378: my ($suffix,$errortxt,$locknotfreed) =
3379: &new_timebased_suffix($coursedom,$coursenum,$type);
3380: if ($locknotfreed) {
3381: $r->print($locknotfreed);
3382: }
3383: if ($suffix) {
3384: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3385: } else {
3386: return $errortxt;
3387: }
3388: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3389: my ($suffix,$errortxt,$locknotfreed) =
3390: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3391: if ($locknotfreed) {
3392: $r->print($locknotfreed);
3393: }
3394: if ($suffix) {
3395: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3396: } else {
3397: return $errortxt;
3398: }
3399: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3400: if ($supplementalflag) {
3401: next unless ($1 eq 'supplemental');
3402: if ($folder eq 'supplemental') {
3403: next unless ($2 eq 'default');
3404: } else {
3405: next unless ($folder eq 'supplemental_'.$2);
3406: }
3407: } else {
3408: next unless ($1 eq 'docs');
3409: if ($folder eq 'default') {
3410: next unless ($2 eq 'default');
3411: } else {
3412: next unless ($folder eq 'default_'.$2);
3413: }
3414: }
3415: }
3416: push(@imports, [$name, $url, $residx]);
3417: }
3418: }
3419: ($errtext,$fatal,my $fixuperrors) =
3420: &group_import($coursenum, $coursedom, $folder,$container,
3421: 'londocs',$ltitoolsref,@imports);
3422: return $errtext if ($fatal);
3423: if ($fixuperrors) {
3424: $r->print($fixuperrors);
3425: }
3426: }
3427: # Loading a complete map
3428: if ($env{'form.loadmap'}) {
3429: if ($env{'form.importmap'}=~/\w/) {
3430: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3431: my ($title,$url,$ext,$type)=split(/\:/,$res);
3432: my $idx=&LONCAPA::map::getresidx($url);
3433: $LONCAPA::map::resources[$idx]=$res;
3434: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3435: }
3436: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3437: $folder.'.'.$container,1);
3438: return $errtext if ($fatal);
3439: } else {
3440: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
3441:
3442: }
3443: }
3444: &log_differences($plain);
3445: }
3446: # ---------------------------------------------------------------- End commands
3447: # ---------------------------------------------------------------- Print screen
3448: my $idx=0;
3449: my $shown=0;
3450: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
3451: $r->print('<div class="LC_Box">'.
3452: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3453: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3454: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3455: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3456: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
3457: '</ol>');
3458: if ($randompick>=0) {
3459: $r->print('<p class="LC_warning">'
3460: .&mt('Caution: this folder is set to randomly pick a subset'
3461: .' of resources. Adding or removing resources from this'
3462: .' folder will change the set of resources that the'
3463: .' students see, resulting in spurious or missing credit'
3464: .' for completed problems, not limited to ones you'
3465: .' modify. Do not modify the contents of this folder if'
3466: .' it is in active student use.')
3467: .'</p>'
3468: );
3469: }
3470: if ($is_random_order) {
3471: $r->print('<p class="LC_warning">'
3472: .&mt('Caution: this folder is set to randomly order its'
3473: .' contents. Adding or removing resources from this folder'
3474: .' will change the order of resources shown.')
3475: .'</p>'
3476: );
3477: }
3478: $r->print('</div>');
3479: }
3480:
3481: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3482: %filters = (
3483: canremove => [],
3484: cancut => [],
3485: cancopy => [],
3486: hiddenresource => [],
3487: encrypturl => [],
3488: randomorder => [],
3489: randompick => [],
3490: );
3491: %curr_groups = &Apache::longroup::coursegroups();
3492: &Apache::loncommon::start_data_table_count(); #setup a row counter
3493: foreach my $res (@LONCAPA::map::order) {
3494: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3495: $name=&LONCAPA::map::qtescape($name);
3496: $url=&LONCAPA::map::qtescape($url);
3497: unless ($name) { $name=(split(/\//,$url))[-1]; }
3498: unless ($name) { $idx++; next; }
3499: push(@allidx,$res);
3500: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3501: push(@allmapidx,$res);
3502: }
3503:
3504: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
3505: $coursenum,$coursedom,$crstype,
3506: $pathitem,$supplementalflag,$container,
3507: \%filters,\%curr_groups,$ltitoolsref,$canedit,
3508: $isencrypted,$navmapref,$hostname);
3509: $idx++;
3510: $shown++;
3511: }
3512: &Apache::loncommon::end_data_table_count();
3513:
3514: my $need_save;
3515: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
3516: my $toolslink;
3517: if ($allowed) {
3518: $toolslink = '<table><tr><td>'
3519: .&Apache::loncommon::help_open_menu('Navigation Screen',
3520: 'Navigation_Screen',undef,'RAT')
3521: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3522: .'<td align="left"><ul id="LC_toolbar">'
3523: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
3524: .'id="LC_content_toolbar_edittoplevel" '
3525: .'class="LC_toolbarItem" '
3526: .'title="'.&mt('Supplemental Content Editor').'">'
3527: .'</a></li></ul></td></tr></table><br />';
3528: }
3529: if ($shown) {
3530: if ($allowed) {
3531: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3532: .&Apache::loncommon::start_data_table(undef,'contentlist')
3533: .&Apache::loncommon::start_data_table_header_row()
3534: .'<th colspan="2">'.&mt('Move').'</th>'
3535: .'<th colspan="3">'.&mt('Actions').'</th>'
3536: .'<th>'.&mt('Document').'</th>';
3537: if ($folder !~ /^supplemental/) {
3538: $to_show .= '<th colspan="2">'.&mt('Settings').'</th>';
3539: }
3540: $to_show .= &Apache::loncommon::end_data_table_header_row();
3541: if ($folder !~ /^supplemental/) {
3542: $lists{'canhide'} = join(',',@allidx);
3543: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3544: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3545: 'randomorder','randompick');
3546: foreach my $item (@possfilters) {
3547: if (ref($filters{$item}) eq 'ARRAY') {
3548: if (@{$filters{$item}} > 0) {
3549: $lists{$item} = join(',',@{$filters{$item}});
3550: }
3551: }
3552: }
3553: if (@allidx > 0) {
3554: my $path;
3555: if ($env{'form.folderpath'}) {
3556: $path =
3557: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3558: }
3559: if (@allidx > 1) {
3560: $to_show .=
3561: &Apache::loncommon::continue_data_table_row().
3562: '<td colspan="2"> </td>'.
3563: '<td>'.
3564: &multiple_check_form('actions',\%lists,$canedit).
3565: '</td>'.
3566: '<td colspan="3"> </td>'.
3567: '<td colspan="2">'.
3568: &multiple_check_form('settings',\%lists,$canedit).
3569: '</td>'.
3570: &Apache::loncommon::end_data_table_row();
3571: $need_save = 1;
3572: }
3573: }
3574: }
3575: $to_show .= $output.' '
3576: .&Apache::loncommon::end_data_table()
3577: .'<br style="line-height:2px;" />'
3578: .&Apache::loncommon::end_scrollbox();
3579: } else {
3580: $to_show .= $toolslink
3581: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3582: .$output.' '
3583: .&Apache::loncommon::end_data_table();
3584: }
3585: } else {
3586: if (!$allowed) {
3587: $to_show .= $toolslink;
3588: }
3589: my $noresmsg;
3590: if ($allowed && $hiddentop && !$supplementalflag) {
3591: $noresmsg = &mt('Main Content Hidden');
3592: } else {
3593: $noresmsg = &mt('Currently empty');
3594: }
3595: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3596: .'<div class="LC_info" id="contentlist">'
3597: .$noresmsg
3598: .'</div>'
3599: .&Apache::loncommon::end_scrollbox();
3600: }
3601: } else {
3602: if ($shown) {
3603: $to_show = '<div>'
3604: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3605: .$output
3606: .&Apache::loncommon::end_data_table()
3607: .'</div>';
3608: } else {
3609: $to_show = '<div class="LC_info" id="contentlist">'
3610: .&mt('Currently empty')
3611: .'</div>'
3612: }
3613: }
3614: my $tid = 1;
3615: if ($supplementalflag) {
3616: $tid = 2;
3617: }
3618: if ($allowed) {
3619: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
3620: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
3621: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3622: if ($canedit) {
3623: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3624: }
3625: } else {
3626: $r->print($to_show);
3627: }
3628: return;
3629: }
3630:
3631: sub multiple_check_form {
3632: my ($caller,$listsref,$canedit) = @_;
3633: return unless (ref($listsref) eq 'HASH');
3634: my $disabled;
3635: unless ($canedit) {
3636: $disabled = 'disabled="disabled"';
3637: }
3638: my $output =
3639: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3640: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3641: '<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>'.
3642: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3643: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3644: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3645: if ($caller eq 'settings') {
3646: $output .=
3647: '<table><tr>'.
3648: '<td class="LC_docs_entry_parameter">'.
3649: '<span class="LC_nobreak"><label>'.
3650: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
3651: '</label></span></td>'.
3652: '<td class="LC_docs_entry_parameter">'.
3653: '<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="" />'.
3654: '</span></td>'.
3655: '</tr>'."\n".
3656: '<tr>'.
3657: '<td class="LC_docs_entry_parameter">'.
3658: '<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').
3659: '</label></span>'.
3660: '</td></tr></table>'."\n";
3661: } else {
3662: $output .=
3663: '<table><tr>'.
3664: '<td class="LC_docs_entry_parameter">'.
3665: '<span class="LC_nobreak LC_docs_remove">'.
3666: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
3667: '</label></span></td>'.
3668: '<td class="LC_docs_entry_parameter">'.
3669: '<span class="LC_nobreak LC_docs_cut">'.
3670: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
3671: '</label></span></td>'."\n".
3672: '<td class="LC_docs_entry_parameter">'.
3673: '<span class="LC_nobreak LC_docs_copy">'.
3674: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
3675: '</label></span></td>'.
3676: '</tr></table>'."\n";
3677: }
3678: $output .=
3679: '</fieldset>'.
3680: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3681: if ($caller eq 'settings') {
3682: $output .=
3683: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3684: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3685: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3686: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3687: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3688: } elsif ($caller eq 'actions') {
3689: $output .=
3690: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3691: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3692: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3693: }
3694: $output .=
3695: '</form>'.
3696: '</div>';
3697: return $output;
3698: }
3699:
3700: sub process_file_upload {
3701: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
3702: # upload a file, if present
3703: my $filesize = length($env{'form.uploaddoc'});
3704: if (!$filesize) {
3705: $$upload_output = '<div class="LC_error">'.
3706: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3707: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3708: $filesize).'<br />'.
3709: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3710: '</div>';
3711: return;
3712: }
3713: my $quotatype = 'unofficial';
3714: if ($crstype eq 'Community') {
3715: $quotatype = 'community';
3716: } elsif ($crstype eq 'Placement') {
3717: $quotatype = 'placement';
3718: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
3719: $quotatype = 'official';
3720: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3721: $quotatype = 'textbook';
3722: }
3723: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3724: $filesize = int($filesize/1000); #expressed in kb
3725: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
3726: $env{'form.uploaddoc.filename'},$filesize,
3727: 'upload',$quotatype);
3728: return if ($$upload_output);
3729: }
3730: my ($parseaction,$showupload,$nextphase,$mimetype);
3731: if ($env{'form.parserflag'}) {
3732: $parseaction = 'parse';
3733: }
3734: my $folder=$env{'form.folder'};
3735: if ($folder eq '') {
3736: $folder='default';
3737: }
3738: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3739: my $errtext='';
3740: my $fatal=0;
3741: my $container='sequence';
3742: if ($env{'form.folderpath'} =~ /:1$/) {
3743: $container='page';
3744: }
3745: ($errtext,$fatal)=
3746: &mapread($coursenum,$coursedom,$folder.'.'.$container);
3747: if ($#LONCAPA::map::order<1) {
3748: $LONCAPA::map::order[0]=1;
3749: $LONCAPA::map::resources[1]='';
3750: }
3751: my $destination = 'docs/';
3752: if ($folder =~ /^supplemental/) {
3753: $destination = 'supplemental/';
3754: }
3755: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3756: $destination .= 'default/';
3757: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3758: $destination .= $2.'/';
3759: }
3760: if ($fatal) {
3761: $$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>';
3762: return;
3763: }
3764: # this is for a course, not a user, so set context to coursedoc.
3765: my $newidx=&LONCAPA::map::getresidx();
3766: $destination .= $newidx;
3767: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
3768: $parseaction,$allfiles,
3769: $codebase,undef,undef,undef,undef,
3770: undef,undef,\$mimetype);
3771: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3772: my $stored = $1;
3773: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3774: $stored.'</span>').'</p>';
3775: } else {
3776: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3777:
3778: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
3779: return;
3780: }
3781: my $ext='false';
3782: if ($url=~m{^http://}) { $ext='true'; }
3783: $url = &LONCAPA::map::qtunescape($url);
3784: my $comment=$env{'form.comment'};
3785: $comment = &LONCAPA::map::qtunescape($comment);
3786: if ($folder=~/^supplemental/) {
3787: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3788: $env{'user.domain'}.'___&&&___'.$comment;
3789: }
3790:
3791: $LONCAPA::map::resources[$newidx]=
3792: $comment.':'.$url.':'.$ext.':normal:res';
3793: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3794: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3795: $folder.'.'.$container,1);
3796: if ($fatal) {
3797: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
3798: return;
3799: } else {
3800: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3801: $$upload_output = $showupload;
3802: my $total_embedded = scalar(keys(%{$allfiles}));
3803: if ($total_embedded > 0) {
3804: my $uploadphase = 'upload_embedded';
3805: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3806: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3807: my ($embedded,$num) =
3808: &Apache::loncommon::ask_for_embedded_content(
3809: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3810: if ($embedded) {
3811: if ($num) {
3812: $$upload_output .=
3813: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3814: $nextphase = $uploadphase;
3815: } else {
3816: $$upload_output .= $embedded;
3817: }
3818: } else {
3819: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3820: }
3821: } else {
3822: $$upload_output .= &mt('No embedded items identified').'<br />';
3823: }
3824: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
3825: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3826: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
3827: $nextphase = 'decompress_uploaded';
3828: my $position = scalar(@LONCAPA::map::order)-1;
3829: my $noextract = &return_to_editor();
3830: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3831: my %archiveitems = (
3832: folderpath => $env{'form.folderpath'},
3833: cmd => $nextphase,
3834: newidx => $newidx,
3835: position => $position,
3836: phase => $nextphase,
3837: comment => $comment,
3838: );
3839: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3840: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
3841: $$upload_output = $showupload.
3842: &Apache::loncommon::decompress_form($mimetype,
3843: $archiveurl,'/adm/coursedocs',$noextract,
3844: \%archiveitems,\@current);
3845: }
3846: }
3847: }
3848: return $nextphase;
3849: }
3850:
3851: sub get_dir_list {
3852: my ($url,$coursenum,$coursedom,$newidx) = @_;
3853: my ($destination,$dir_root) = &embedded_destination();
3854: my ($dirlistref,$listerror) =
3855: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3856: my @dir_lines;
3857: my $dirptr=16384;
3858: if (ref($dirlistref) eq 'ARRAY') {
3859: foreach my $dir_line (sort
3860: {
3861: my ($afile)=split('&',$a,2);
3862: my ($bfile)=split('&',$b,2);
3863: return (lc($afile) cmp lc($bfile));
3864: } (@{$dirlistref})) {
3865: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3866: $filename =~ s/\s+$//;
3867: next if ($filename =~ /^\.\.?$/);
3868: my $isdir = 0;
3869: if ($dirptr&$testdir) {
3870: $isdir = 1;
3871: }
3872: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3873: }
3874: }
3875: return @dir_lines;
3876: }
3877:
3878: sub is_supplemental_title {
3879: my ($title) = @_;
3880: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3881: }
3882:
3883: # --------------------------------------------------------------- An entry line
3884:
3885: sub entryline {
3886: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
3887: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
3888: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
3889: my ($foldertitle,$renametitle,$oldtitle);
3890: if (&is_supplemental_title($title)) {
3891: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
3892: } else {
3893: $title=&HTML::Entities::encode($title,'"<>&\'');
3894: $renametitle=$title;
3895: $foldertitle=$title;
3896: }
3897:
3898: my ($disabled,$readonly,$js_lt);
3899: unless ($canedit) {
3900: $disabled = 'disabled="disabled"';
3901: $readonly = 1;
3902: }
3903:
3904: my $orderidx=$LONCAPA::map::order[$index];
3905:
3906: $renametitle=~s/\\/\\\\/g;
3907: $renametitle=~s/\"\;/\\\"/g;
3908: $renametitle=~s/"/%22/g;
3909: $renametitle=~s/ /%20/g;
3910: $oldtitle = $renametitle;
3911: $renametitle=~s/\'/\\\'/g;
3912: my $line=&Apache::loncommon::start_data_table_row();
3913: my ($form_start,$form_end,$form_common,$form_param);
3914: # Edit commands
3915: my ($esc_path, $path, $symb, $curralias);
3916: if ($env{'form.folderpath'}) {
3917: $esc_path=&escape($env{'form.folderpath'});
3918: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3919: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3920: }
3921: my $isexternal;
3922: if ($residx) {
3923: my $currurl = $url;
3924: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
3925: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3926: $isexternal = 1;
3927: }
3928: if (!$supplementalflag) {
3929: my $path = 'uploaded/'.
3930: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3931: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3932: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3933: $residx,
3934: &Apache::lonnet::declutter($currurl));
3935: }
3936: }
3937: my ($renamelink,%lt,$ishash);
3938: if (ref($filtersref) eq 'HASH') {
3939: $ishash = 1;
3940: }
3941:
3942: if ($allowed) {
3943: $form_start = '
3944: <form action="/adm/coursedocs" method="post">
3945: ';
3946: $form_common=(<<END);
3947: <input type="hidden" name="folderpath" value="$path" />
3948: <input type="hidden" name="symb" value="$symb" />
3949: END
3950: $form_param=(<<END);
3951: <input type="hidden" name="setparms" value="$orderidx" />
3952: <input type="hidden" name="changeparms" value="0" />
3953: END
3954: $form_end = '</form>';
3955:
3956: my $incindex=$index+1;
3957: my $selectbox='';
3958: if (($#LONCAPA::map::order>0) &&
3959: ((split(/\:/,
3960: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3961: ne '') &&
3962: ((split(/\:/,
3963: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
3964: ne '')) {
3965: $selectbox=
3966: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
3967: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
3968: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3969: if ($i==$incindex) {
3970: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
3971: } else {
3972: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3973: }
3974: }
3975: $selectbox.='</select>';
3976: }
3977: %lt=&Apache::lonlocal::texthash(
3978: 'up' => 'Move Up',
3979: 'dw' => 'Move Down',
3980: 'rm' => 'Remove',
3981: 'ct' => 'Cut',
3982: 'rn' => 'Rename',
3983: 'cp' => 'Copy',
3984: 'da' => 'Unset alias',
3985: 'sa' => 'Set alias',
3986: 'ex' => 'External Resource',
3987: 'et' => 'External Tool',
3988: 'ed' => 'Edit',
3989: 'pr' => 'Preview',
3990: 'sv' => 'Save',
3991: 'ul' => 'URL',
3992: 'ti' => 'Title',
3993: 'er' => 'Editing rights unavailable for your current role.',
3994: );
3995: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3996: $env{'form.folderpath'},
3997: $currgroups);
3998: my ($copylink,$cutlink,$removelink);
3999: my $skip_confirm = 0;
4000: my $confirm_removal = 0;
4001: if ( $folder =~ /^supplemental/
4002: || ($url =~ m{( /smppg$
4003: |/syllabus$
4004: |/aboutme$
4005: |/navmaps$
4006: |/bulletinboard$
4007: |/ext\.tool$
4008: |\.html$)}x)
4009: || $isexternal) {
4010: $skip_confirm = 1;
4011: }
4012: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4013: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4014: $confirm_removal = 1;
4015: }
4016: if ($url =~ /$LONCAPA::assess_re/) {
4017: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4018: }
4019:
4020: if ($denied{'copy'}) {
4021: $copylink=(<<ENDCOPY)
4022: <span style="visibility: hidden;">$lt{'cp'}</span>
4023: ENDCOPY
4024: } else {
4025: my $formname = 'edit_copy_'.$orderidx;
4026: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
4027: $copylink=(<<ENDCOPY);
4028: <form name="$formname" method="post" action="/adm/coursedocs">
4029: $form_common
4030: <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>
4031: $form_end
4032: ENDCOPY
4033: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4034: push(@{$filtersref->{'cancopy'}},$orderidx);
4035: }
4036: }
4037: if ($denied{'cut'}) {
4038: $cutlink=(<<ENDCUT);
4039: <span style="visibility: hidden;">$lt{'ct'}</span>
4040: ENDCUT
4041: } else {
4042: my $formname = 'edit_cut_'.$orderidx;
4043: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
4044: $cutlink=(<<ENDCUT);
4045: <form name="$formname" method="post" action="/adm/coursedocs">
4046: $form_common
4047: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
4048: <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>
4049: $form_end
4050: ENDCUT
4051: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4052: push(@{$filtersref->{'cancut'}},$orderidx);
4053: }
4054: }
4055: if ($denied{'remove'}) {
4056: $removelink=(<<ENDREM);
4057: <span style="visibility: hidden;">$lt{'rm'}</a>
4058: ENDREM
4059: } else {
4060: my $formname = 'edit_remove_'.$orderidx;
4061: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
4062: $removelink=(<<ENDREM);
4063: <form name="$formname" method="post" action="/adm/coursedocs">
4064: $form_common
4065: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
4066: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
4067: <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>
4068: $form_end
4069: ENDREM
4070: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4071: push(@{$filtersref->{'canremove'}},$orderidx);
4072: }
4073: }
4074: $renamelink=(<<ENDREN);
4075: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
4076: ENDREN
4077: my ($uplink,$downlink);
4078: if ($canedit) {
4079: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4080: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4081: } else {
4082: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4083: $downlink = $uplink;
4084: }
4085: $line.=(<<END);
4086: <td>
4087: <div class="LC_docs_entry_move">
4088: <a href="$uplink">
4089: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
4090: </a>
4091: </div>
4092: <div class="LC_docs_entry_move">
4093: <a href="$downlink">
4094: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
4095: </a>
4096: </div>
4097: </td>
4098: <td>
4099: $form_start
4100: $form_param
4101: $form_common
4102: $selectbox
4103: $form_end
4104: </td>
4105: <td class="LC_docs_entry_commands LC_nobreak">
4106: $removelink
4107: $cutlink
4108: $copylink
4109: </td>
4110: END
4111: }
4112: # Figure out what kind of a resource this is
4113: my ($extension)=($url=~/\.(\w+)$/);
4114: my $uploaded=($url=~/^\/*uploaded\//);
4115: my $icon=&Apache::loncommon::icon($url);
4116: my $isfolder;
4117: my $ispage;
4118: my $containerarg;
4119: my $folderurl;
4120: if ($uploaded) {
4121: if (($extension eq 'sequence') || ($extension eq 'page')) {
4122: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
4123: $containerarg = $1;
4124: if ($extension eq 'sequence') {
4125: $icon=$iconpath.'navmap.folder.closed.gif';
4126: $isfolder=1;
4127: } else {
4128: $icon=$iconpath.'page.gif';
4129: $ispage=1;
4130: }
4131: $folderurl = &Apache::lonnet::declutter($url);
4132: if ($allowed) {
4133: $url='/adm/coursedocs?';
4134: } else {
4135: $url='/adm/supplemental?';
4136: }
4137: } else {
4138: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4139: }
4140: }
4141:
4142: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
4143: my $orig_url = $url;
4144: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
4145: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4146: if (!$supplementalflag && $residx && $symb) {
4147: if ((!$isfolder) && (!$ispage)) {
4148: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
4149: $url=&Apache::lonnet::clutter($url);
4150: if ($url=~/^\/*uploaded\//) {
4151: $url=~/\.(\w+)$/;
4152: my $embstyle=&Apache::loncommon::fileembstyle($1);
4153: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4154: $url='/adm/wrapper'.$url;
4155: } elsif ($embstyle eq 'ssi') {
4156: #do nothing with these
4157: } elsif ($url!~/\.(sequence|page)$/) {
4158: $url='/adm/coursedocs/showdoc'.$url;
4159: }
4160: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4161: my $wrapped = $1;
4162: my $exturl = $2;
4163: if ($wrapped eq '') {
4164: $url='/adm/wrapper'.$url;
4165: }
4166: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4167: $nomodal = 1;
4168: }
4169: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4170: $url='/adm/wrapper'.$url;
4171: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4172: if (($ENV{'SERVER_PORT'} == 443) &&
4173: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4174: $url .= '?usehttp=1';
4175: $nomodal = 1;
4176: }
4177: }
4178: if (&Apache::lonnet::symbverify($symb,$url)) {
4179: my $shownsymb = $symb;
4180: if ($isexternal) {
4181: if ($url =~ /^([^#]+)#([^#]+)$/) {
4182: $url = $1;
4183: $anchor = $2;
4184: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4185: $shownsymb = $1.&escape('#').$anchor;
4186: }
4187: }
4188: }
4189: unless ($env{'request.role.adv'}) {
4190: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4191: $url = '';
4192: }
4193: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4194: $url = '';
4195: $hiddenres = 1;
4196: }
4197: }
4198: if ($url ne '') {
4199: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
4200: }
4201: } elsif (!$env{'request.role.adv'}) {
4202: my $checkencrypt;
4203: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4204: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4205: $checkencrypt = 1;
4206: } elsif (ref($navmapref)) {
4207: unless (ref($$navmapref)) {
4208: $$navmapref = Apache::lonnavmaps::navmap->new();
4209: }
4210: if (ref($$navmapref)) {
4211: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4212: $checkencrypt = 1;
4213: }
4214: }
4215: }
4216: if ($checkencrypt) {
4217: my $shownsymb = &Apache::lonenc::encrypted($symb);
4218: my $shownurl = &Apache::lonenc::encrypted($url);
4219: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
4220: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
4221: if ($env{'request.enc'} ne '') {
4222: delete($env{'request.enc'});
4223: }
4224: } else {
4225: $url='';
4226: }
4227: } else {
4228: $url='';
4229: }
4230: } else {
4231: $url='';
4232: }
4233: }
4234: } elsif ($supplementalflag) {
4235: if ($isexternal) {
4236: if ($url =~ /^([^#]+)#([^#]+)$/) {
4237: $url = $1;
4238: $anchor = $2;
4239: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4240: if ($hostname ne '') {
4241: $url = 'http://'.$hostname.$url;
4242: }
4243: $nomodal = 1;
4244: }
4245: }
4246: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4247: if (($ENV{'SERVER_PORT'} == 443) &&
4248: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4249: if ($hostname ne '') {
4250: $url = 'http://'.$hostname.$url;
4251: }
4252: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4253: $nomodal = 1;
4254: }
4255: }
4256: }
4257: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4258: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
4259: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
4260: my $foldername=&escape($foldertitle);
4261: my $folderpath=$env{'form.folderpath'};
4262: if ($folderpath) { $folderpath.='&' };
4263: if (!$allowed && $supplementalflag) {
4264: $folderpath.=$containerarg.'&'.$foldername;
4265: $url.='folderpath='.&escape($folderpath);
4266: } else {
4267: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4268: 'parameter_randompick'))[0];
4269: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4270: 'parameter_randomorder'))[0]=~/^yes$/i);
4271: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4272: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4273: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4274: 'parameter_encrypturl'))[0]=~/^yes$/i);
4275: unless ($hiddenmap) {
4276: if (ref($navmapref)) {
4277: unless (ref($$navmapref)) {
4278: $$navmapref = Apache::lonnavmaps::navmap->new();
4279: }
4280: if (ref($$navmapref)) {
4281: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4282: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4283: unless (@resources) {
4284: $hiddenmap = 1;
4285: unless ($env{'request.role.adv'}) {
4286: $url = '';
4287: $hiddenfolder = 1;
4288: }
4289: }
4290: }
4291: }
4292: }
4293: }
4294: unless ($encryptmap) {
4295: if ((ref($navmapref)) && (ref($$navmapref))) {
4296: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4297: $encryptmap = 1;
4298: }
4299: }
4300: }
4301:
4302: # Append randompick number, hidden, and encrypted with ":" to foldername,
4303: # so it gets transferred between levels
4304: $folderpath.=$containerarg.'&'.$foldername.
4305: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4306: unless ($url eq '') {
4307: $url.='folderpath='.&escape($folderpath);
4308: }
4309: my $rpckchk;
4310: if ($rpicknum) {
4311: $rpckchk = ' checked="checked"';
4312: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4313: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4314: }
4315: }
4316: my $formname = 'edit_randompick_'.$orderidx;
4317: $rand_pick_text =
4318: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4319: $form_param."\n".
4320: $form_common."\n".
4321: '<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.'">';
4322: if ($rpicknum ne '') {
4323: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4324: }
4325: $rand_pick_text .= '</span></span>'.
4326: $form_end;
4327: my $ro_set;
4328: if ($randorder) {
4329: $ro_set = 'checked="checked"';
4330: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4331: push(@{$filtersref->{'randomorder'}},$orderidx);
4332: }
4333: }
4334: $formname = 'edit_rorder_'.$orderidx;
4335: $rand_order_text =
4336: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4337: $form_param."\n".
4338: $form_common."\n".
4339: '<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>'.
4340: $form_end;
4341: }
4342: } elsif ($supplementalflag && !$allowed) {
4343: my $isexttool;
4344: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4345: $url='/adm/wrapper'.$url;
4346: $isexttool = 1;
4347: }
4348: $url .= ($url =~ /\?/) ? '&':'?';
4349: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
4350: if ($title) {
4351: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4352: }
4353: if ((($isexternal) || ($isexttool)) && $orderidx) {
4354: $url .= '&idx='.$orderidx;
4355: }
4356: if ($anchor ne '') {
4357: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4358: }
4359: }
4360: my ($tdalign,$tdwidth);
4361: if ($allowed) {
4362: my $fileloc =
4363: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
4364: if ($isexternal) {
4365: ($editlink,$extresform) =
4366: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4367: undef,undef,undef,undef,undef,undef,
4368: undef,$disabled);
4369: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4370: ($editlink,$extresform) =
4371: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4372: undef,undef,undef,'tool',$coursedom,
4373: $coursenum,$ltitoolsref,$disabled);
4374: } elsif (!$isfolder && !$ispage) {
4375: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4376: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
4377: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
4378: my $suppanchor;
4379: if ($supplementalflag) {
4380: $suppanchor = $anchor;
4381: }
4382: my $jscall =
4383: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4384: $switchserver,
4385: $forceedit,
4386: undef,$symb,
4387: &escape($env{'form.folderpath'}),
4388: $renametitle,$hostname,
4389: '','',1,$suppanchor);
4390: if ($jscall) {
4391: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4392: $jscall.'" >'.&mt('Edit').'</a> '."\n";
4393: }
4394: }
4395: }
4396: $tdalign = ' align="right" valign="top"';
4397: $tdwidth = ' width="80%"';
4398: }
4399: my $reinit;
4400: if ($crstype eq 'Community') {
4401: $reinit = &mt('(re-initialize community to access)');
4402: } else {
4403: $reinit = &mt('(re-initialize course to access)');
4404: }
4405: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
4406: if ($orig_url =~ /$LONCAPA::assess_re/) {
4407: $line.= '<br />';
4408: if ($curralias ne '') {
4409: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4410: $lt{'da'}.'</a></span>';
4411: } else {
4412: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4413: $lt{'sa'}.'</a></span>';
4414: }
4415: }
4416: $line.='</td><td>';
4417: my $link;
4418: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4419: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4420: } elsif ($url) {
4421: if ($anchor ne '') {
4422: if ($supplementalflag) {
4423: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4424: } else {
4425: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4426: }
4427: }
4428: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4429: $link = 'http://'.$hostname.$url;
4430: } else {
4431: $link = $url;
4432: }
4433: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
4434: (($anchor ne '')?$anchor:''));
4435: if ($nomodal) {
4436: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4437: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4438: } else {
4439: $line.=&Apache::loncommon::modal_link($link,
4440: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4441: }
4442: } else {
4443: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4444: }
4445: $line.='</span></td><td'.$tdwidth.'>';
4446: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4447: $line.='<a href="'.$url.'">'.$title.'</a>';
4448: } elsif ($url) {
4449: if ($nomodal) {
4450: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4451: $title.'</a>';
4452: } else {
4453: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4454: }
4455: } elsif (($hiddenfolder) || ($hiddenres)) {
4456: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
4457: } else {
4458: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4459: }
4460: if (($allowed) && ($curralias ne '')) {
4461: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4462: } else {
4463: $line .= $extresform;
4464: }
4465: $line .= '</td>';
4466: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4467: $rand_order_text = ' ' if ($rand_order_text eq '');
4468: if (($allowed) && ($folder!~/^supplemental/)) {
4469: my %lt=&Apache::lonlocal::texthash(
4470: 'hd' => 'Hidden',
4471: 'ec' => 'URL hidden');
4472: my ($enctext,$hidtext);
4473: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4474: $enctext = ' checked="checked"';
4475: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4476: push(@{$filtersref->{'encrypturl'}},$orderidx);
4477: }
4478: }
4479: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4480: $hidtext = ' checked="checked"';
4481: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4482: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4483: }
4484: }
4485: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4486: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
4487: $line.=(<<ENDPARMS);
4488: <td class="LC_docs_entry_parameter">
4489: <form action="/adm/coursedocs" method="post" name="$formhidden">
4490: $form_param
4491: $form_common
4492: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
4493: $form_end
4494: <br />
4495: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
4496: $form_param
4497: $form_common
4498: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
4499: $form_end
4500: </td>
4501: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4502: $rand_order_text</td>
4503: ENDPARMS
4504: }
4505: $line.=&Apache::loncommon::end_data_table_row();
4506: return $line;
4507: }
4508:
4509: sub action_restrictions {
4510: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4511: my %denied = (
4512: cut => 0,
4513: copy => 0,
4514: remove => 0,
4515: );
4516: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4517: # no copy for published maps
4518: $denied{'copy'} = 1;
4519: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4520: unless ($1 eq 'simpleproblem') {
4521: $denied{'copy'} = 1;
4522: }
4523: $denied{'cut'} = 1;
4524: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4525: if ($folderpath =~ /^default&[^\&]+$/) {
4526: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4527: $denied{'remove'} = 1;
4528: }
4529: $denied{'cut'} = 1;
4530: $denied{'copy'} = 1;
4531: }
4532: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4533: my $group = $1;
4534: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4535: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4536: $denied{'remove'} = 1;
4537: }
4538: }
4539: $denied{'cut'} = 1;
4540: $denied{'copy'} = 1;
4541: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4542: my $group = $1;
4543: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4544: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4545: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4546: if (keys(%groupsettings) > 0) {
4547: $denied{'remove'} = 1;
4548: }
4549: $denied{'cut'} = 1;
4550: $denied{'copy'} = 1;
4551: }
4552: }
4553: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4554: my $group = $1;
4555: if ($url =~ /group_boards_\Q$group\E/) {
4556: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4557: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4558: if (keys(%groupsettings) > 0) {
4559: if (ref($groupsettings{'functions'}) eq 'HASH') {
4560: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4561: $denied{'remove'} = 1;
4562: }
4563: }
4564: }
4565: $denied{'cut'} = 1;
4566: $denied{'copy'} = 1;
4567: }
4568: }
4569: }
4570: return %denied;
4571: }
4572:
4573: sub new_timebased_suffix {
4574: my ($dom,$num,$type,$area,$container) = @_;
4575: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
4576: if ($type eq 'paste') {
4577: $prefix = $type;
4578: $namespace = 'courseeditor';
4579: $idtype = 'addcode';
4580: } elsif ($type eq 'map') {
4581: $prefix = 'docs';
4582: if ($area eq 'supplemental') {
4583: $prefix = 'supp';
4584: }
4585: $prefix .= $container;
4586: $namespace = 'uploadedmaps';
4587: } else {
4588: $prefix = $type;
4589: $namespace = 'templated';
4590: }
4591: my ($suffix,$freedlock,$error) =
4592: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
4593: if (!$suffix) {
4594: if ($type eq 'paste') {
4595: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4596: } elsif ($type eq 'map') {
4597: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4598: } elsif ($type eq 'smppg') {
4599: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4600: } elsif ($type eq 'exttool') {
4601: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
4602: } else {
4603: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
4604: }
4605: if ($error) {
4606: $errtext .= '<br />'.$error;
4607: }
4608: }
4609: if ($freedlock ne 'ok') {
4610: $locknotfreed =
4611: '<div class="LC_error">'.
4612: &mt('There was a problem removing a lockfile.').' ';
4613: if ($type eq 'paste') {
4614: if ($freedlock eq 'nolock') {
4615: $locknotfreed =
4616: '<div class="LC_error">'.
4617: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4618:
4619: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
4620: } else {
4621: $locknotfreed .=
4622: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4623: }
4624: } elsif ($type eq 'map') {
4625: $locknotfreed .=
4626: &mt('This will prevent creation of additional folders or composite pages in this course.');
4627: } elsif ($type eq 'smppg') {
4628: $locknotfreed .=
4629: &mt('This will prevent creation of additional simple pages in this course.');
4630: } elsif ($type eq 'exttool') {
4631: $locknotfreed .=
4632: &mt('This will prevent creation of additional external tools in this course.');
4633: } else {
4634: $locknotfreed .=
4635: &mt('This will prevent creation of additional discussion boards in this course.');
4636: }
4637: unless ($type eq 'paste') {
4638: $locknotfreed .=
4639: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4640: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
4641: }
4642: $locknotfreed .= '</div>';
4643: }
4644: return ($suffix,$errtext,$locknotfreed);
4645: }
4646:
4647: =pod
4648:
4649: =item tiehash()
4650:
4651: tie the hash
4652:
4653: =cut
4654:
4655: sub tiehash {
4656: my ($mode)=@_;
4657: $hashtied=0;
4658: if ($env{'request.course.fn'}) {
4659: if ($mode eq 'write') {
4660: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4661: &GDBM_WRCREAT(),0640)) {
4662: $hashtied=2;
4663: }
4664: } else {
4665: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4666: &GDBM_READER(),0640)) {
4667: $hashtied=1;
4668: }
4669: }
4670: }
4671: }
4672:
4673: sub untiehash {
4674: if ($hashtied) { untie %hash; }
4675: $hashtied=0;
4676: return OK;
4677: }
4678:
4679:
4680:
4681:
4682: sub checkonthis {
4683: my ($r,$url,$level,$title,$checkstale)=@_;
4684: $url=&unescape($url);
4685: $alreadyseen{$url}=1;
4686: $r->rflush();
4687: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4688: $r->print("\n<br />");
4689: if ($level==0) {
4690: $r->print("<br />");
4691: }
4692: for (my $i=0;$i<=$level*5;$i++) {
4693: $r->print(' ');
4694: }
4695: $r->print('<a href="'.$url.'" target="cat">'.
4696: ($title?$title:$url).'</a> ');
4697: if ($url=~/^\/res\//) {
4698: my $updated;
4699: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4700: ($url !~ /\.\d+\.\w+$/)) {
4701: $updated = &Apache::lonnet::remove_stale_resfile($url);
4702: }
4703: my $result=&Apache::lonnet::repcopy(
4704: &Apache::lonnet::filelocation('',$url));
4705: if ($result eq 'ok') {
4706: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4707: if ($updated) {
4708: $r->print('<br />');
4709: for (my $i=0;$i<=$level*5;$i++) {
4710: $r->print(' ');
4711: }
4712: $r->print('- '.&mt('Outdated copy removed'));
4713: }
4714: $r->rflush();
4715: &Apache::lonnet::countacc($url);
4716: $url=~/\.(\w+)$/;
4717: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4718: $r->print('<br />');
4719: $r->rflush();
4720: for (my $i=0;$i<=$level*5;$i++) {
4721: $r->print(' ');
4722: }
4723: $r->print('- '.&mt('Rendering:').' ');
4724: my ($errorcount,$warningcount)=split(/:/,
4725: &Apache::lonnet::ssi_body($url,
4726: ('grade_target'=>'web',
4727: 'return_only_error_and_warning_counts' => 1)));
4728: if (($errorcount) ||
4729: ($warningcount)) {
4730: if ($errorcount) {
4731: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
4732: &mt('[quant,_1,error]',$errorcount).'</span>');
4733: }
4734: if ($warningcount) {
4735: $r->print('<span class="LC_warning">'.
4736: &mt('[quant,_1,warning]',$warningcount).'</span>');
4737: }
4738: } else {
4739: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4740: }
4741: $r->rflush();
4742: }
4743: my $dependencies=
4744: &Apache::lonnet::metadata($url,'dependencies');
4745: foreach my $dep (split(/\,/,$dependencies)) {
4746: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4747: &checkonthis($r,$dep,$level+1,'',$checkstale);
4748: }
4749: }
4750: } elsif ($result eq 'unavailable') {
4751: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4752: } elsif ($result eq 'not_found') {
4753: unless ($url=~/\$/) {
4754: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
4755: } else {
4756: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
4757: }
4758: } else {
4759: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4760: }
4761: if (($updated) && ($result ne 'ok')) {
4762: $r->print('<br />'.&mt('Outdated copy removed'));
4763: }
4764: }
4765: }
4766: }
4767:
4768:
4769:
4770: =pod
4771:
4772: =item list_symbs()
4773:
4774: List Content Identifiers
4775:
4776: =cut
4777:
4778: sub list_symbs {
4779: my ($r) = @_;
4780:
4781: my $crstype = &Apache::loncommon::course_type();
4782: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4783: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4784: $r->print(&startContentScreen('tools'));
4785: my $navmap = Apache::lonnavmaps::navmap->new();
4786: if (!defined($navmap)) {
4787: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4788: '<div class="LC_error">'.
4789: &mt('Unable to retrieve information about course contents').
4790: '</div>');
4791: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
4792: } else {
4793: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4794: &Apache::loncommon::start_data_table().
4795: &Apache::loncommon::start_data_table_header_row().
4796: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4797: &Apache::loncommon::end_data_table_header_row()."\n");
4798: my $count;
4799: foreach my $res ($navmap->retrieveResources()) {
4800: $r->print(&Apache::loncommon::start_data_table_row().
4801: '<td>'.$res->compTitle().'</td>'.
4802: '<td>'.$res->symb().'</td>'.
4803: &Apache::loncommon::end_data_table_row());
4804: $count ++;
4805: }
4806: if (!$count) {
4807: $r->print(&Apache::loncommon::start_data_table_row().
4808: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4809: &Apache::loncommon::end_data_table_row());
4810: }
4811: $r->print(&Apache::loncommon::end_data_table());
4812: }
4813: $r->print(&endContentScreen());
4814: }
4815:
4816: sub short_urls {
4817: my ($r,$canedit) = @_;
4818: my $crstype = &Apache::loncommon::course_type();
4819: my $formname = 'shortenurl';
4820: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4821: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4822: $r->print(&startContentScreen('tools'));
4823: my ($navmap,$errormsg) =
4824: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4825: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4826: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4827: my (%maps,%resources,%titles);
4828: if (!ref($navmap)) {
4829: $r->print($errormsg.
4830: &endContentScreen());
4831: return '';
4832: } else {
4833: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
4834: $r->rflush();
4835: my $readonly;
4836: if ($canedit) {
4837: my ($numnew,$errors) = &Apache::loncommon::make_short_symbs($cdom,$cnum,$navmap);
4838: if ($numnew) {
4839: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4840: }
4841: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4842: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4843: foreach my $error (@{$errors}) {
4844: $r->print('<li>'.$error.'</li>');
4845: }
4846: $r->print('</ul><br />');
4847: }
4848: } else {
4849: $readonly = 1;
4850: }
4851: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4852: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4853: undef,undef,undef,undef,undef,\%currtiny,$readonly));
4854: }
4855: $r->print(&endContentScreen());
4856: }
4857:
4858: sub contentverifyform {
4859: my ($r) = @_;
4860: my $crstype = &Apache::loncommon::course_type();
4861: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4862: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4863: $r->print(&startContentScreen('tools'));
4864: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4865: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4866: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4867: ' <span class="LC_nobreak">'.
4868: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4869: &mt('No').'</label>'.(' 'x2).
4870: '<label><input type="radio" name="checkstale" value="1" />'.
4871: &mt('Yes').'</label></span></p><p>'.
4872: '<input type="submit" value="'.&mt('Verify content').' "/>'.
4873: '<input type="hidden" value="1" name="tools" />'.
4874: '<input type="hidden" value="1" name="verify" /></p></form>');
4875: $r->print(&endContentScreen());
4876: return;
4877: }
4878:
4879: sub verifycontent {
4880: my ($r,$checkstale) = @_;
4881: my $crstype = &Apache::loncommon::course_type();
4882: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4883: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4884: $r->print(&startContentScreen('tools'));
4885: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4886: $hashtied=0;
4887: undef %alreadyseen;
4888: %alreadyseen=();
4889: &tiehash();
4890:
4891: foreach my $key (keys(%hash)) {
4892: if ($hash{$key}=~/\.(page|sequence)$/) {
4893: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4894: $r->print('<hr /><span class="LC_error">'.
4895: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
4896: &unescape($hash{$key}).'</span><br />'.
4897: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
4898: }
4899: }
4900: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4901: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
4902: }
4903: }
4904: &untiehash();
4905: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
4906: $r->print(&endContentScreen());
4907: }
4908:
4909: sub devalidateversioncache {
4910: my $src=shift;
4911: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4912: &Apache::lonnet::clutter($src));
4913: }
4914:
4915: sub checkversions {
4916: my ($r,$canedit) = @_;
4917: my $crstype = &Apache::loncommon::course_type();
4918: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4919: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
4920: $r->print(&startContentScreen('tools'));
4921:
4922: my $header='';
4923: my $startsel='';
4924: my $monthsel='';
4925: my $weeksel='';
4926: my $daysel='';
4927: my $allsel='';
4928: my %changes=();
4929: my $starttime=0;
4930: my $haschanged=0;
4931: my %setversions=&Apache::lonnet::dump('resourceversions',
4932: $env{'course.'.$env{'request.course.id'}.'.domain'},
4933: $env{'course.'.$env{'request.course.id'}.'.num'});
4934:
4935: $hashtied=0;
4936: &tiehash();
4937: if ($canedit) {
4938: my %newsetversions=();
4939: if ($env{'form.setmostrecent'}) {
4940: $haschanged=1;
4941: foreach my $key (keys(%hash)) {
4942: if ($key=~/^ids\_(\/res\/.+)$/) {
4943: $newsetversions{$1}='mostrecent';
4944: &devalidateversioncache($1);
4945: }
4946: }
4947: } elsif ($env{'form.setcurrent'}) {
4948: $haschanged=1;
4949: foreach my $key (keys(%hash)) {
4950: if ($key=~/^ids\_(\/res\/.+)$/) {
4951: my $getvers=&Apache::lonnet::getversion($1);
4952: if ($getvers>0) {
4953: $newsetversions{$1}=$getvers;
4954: &devalidateversioncache($1);
4955: }
4956: }
4957: }
4958: } elsif ($env{'form.setversions'}) {
4959: $haschanged=1;
4960: foreach my $key (keys(%env)) {
4961: if ($key=~/^form\.set_version_(.+)$/) {
4962: my $src=$1;
4963: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4964: $newsetversions{$src}=$env{$key};
4965: &devalidateversioncache($src);
4966: }
4967: }
4968: }
4969: }
4970: if ($haschanged) {
4971: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4972: $env{'course.'.$env{'request.course.id'}.'.domain'},
4973: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4974: $r->print(&Apache::loncommon::confirmwrapper(
4975: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4976: } else {
4977: $r->print(&Apache::loncommon::confirmwrapper(
4978: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4979: }
4980: &mark_hash_old();
4981: }
4982: &changewarning($r,'');
4983: }
4984: if ($env{'form.timerange'} eq 'all') {
4985: # show all documents
4986: $header=&mt('All content in '.$crstype);
4987: $allsel=' selected="selected"';
4988: foreach my $key (keys(%hash)) {
4989: if ($key=~/^ids\_(\/res\/.+)$/) {
4990: my $src=$1;
4991: $changes{$src}=1;
4992: }
4993: }
4994: } else {
4995: # show documents which changed
4996: %changes=&Apache::lonnet::dump
4997: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4998: $env{'course.'.$env{'request.course.id'}.'.num'});
4999: my $firstkey=(keys(%changes))[0];
5000: unless ($firstkey=~/^error\:/) {
5001: unless ($env{'form.timerange'}) {
5002: $env{'form.timerange'}=604800;
5003: }
5004: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5005: .&mt('seconds');
5006: if ($env{'form.timerange'}==-1) {
5007: $seltext='since start of course';
5008: $startsel=' selected="selected"';
5009: $env{'form.timerange'}=time;
5010: }
5011: $starttime=time-$env{'form.timerange'};
5012: if ($env{'form.timerange'}==2592000) {
5013: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5014: $monthsel=' selected="selected"';
5015: } elsif ($env{'form.timerange'}==604800) {
5016: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5017: $weeksel=' selected="selected"';
5018: } elsif ($env{'form.timerange'}==86400) {
5019: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5020: $daysel=' selected="selected"';
5021: }
5022: $header=&mt('Content changed').' '.$seltext;
5023: } else {
5024: $header=&mt('No content modifications yet.');
5025: }
5026: }
5027: %setversions=&Apache::lonnet::dump('resourceversions',
5028: $env{'course.'.$env{'request.course.id'}.'.domain'},
5029: $env{'course.'.$env{'request.course.id'}.'.num'});
5030: my %lt=&Apache::lonlocal::texthash
5031: ('st' => 'Version changes since start of '.$crstype,
5032: 'lm' => 'Version changes since last Month',
5033: 'lw' => 'Version changes since last Week',
5034: 'sy' => 'Version changes since Yesterday',
5035: 'al' => 'All Resources (possibly large output)',
5036: 'cd' => 'Change display',
5037: 'sd' => 'Display',
5038: 'fi' => 'File',
5039: 'md' => 'Modification Date',
5040: 'mr' => 'Most recently published Version',
5041: 've' => 'Version used in '.$crstype,
5042: 'vu' => 'Set Version to be used in '.$crstype,
5043: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
5044: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5045: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
5046: 'di' => 'Differences',
5047: 'save' => 'Save changes',
5048: 'vers' => 'Version choice(s) for specific resources',
5049: 'act' => 'Actions');
5050: my ($disabled,$readonly);
5051: unless ($canedit) {
5052: $disabled = 'disabled="disabled"';
5053: $readonly = 1;
5054: }
5055: $r->print(<<ENDHEADERS);
5056: <h4 class="LC_info">$header</h4>
5057: <form action="/adm/coursedocs" method="post">
5058: <input type="hidden" name="versions" value="1" />
5059: <div class="LC_left_float">
5060: <fieldset>
5061: <legend>$lt{'cd'}</legend>
5062: <select name="timerange">
5063: <option value='all'$allsel>$lt{'al'}</option>
5064: <option value="-1"$startsel>$lt{'st'}</option>
5065: <option value="2592000"$monthsel>$lt{'lm'}</option>
5066: <option value="604800"$weeksel>$lt{'lw'}</option>
5067: <option value="86400"$daysel>$lt{'sy'}</option>
5068: </select>
5069: <input type="submit" name="display" value="$lt{'sd'}" />
5070: </fieldset>
5071: </div>
5072: <div class="LC_left_float">
5073: <fieldset>
5074: <legend>$lt{'act'}</legend>
5075: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5076: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
5077: </fieldset>
5078: </div>
5079: <br clear="all" />
5080: <hr />
5081: <h4>$lt{'vers'}</h4>
5082: ENDHEADERS
5083: #number of columns for version history
5084: my %changedbytime;
5085: foreach my $key (keys(%changes)) {
5086: #excludes not versionable problems from resource version history:
5087: next if ($key =~ /^\/res\/lib\/templates/);
5088: my $chg;
5089: if ($env{'form.timerange'} eq 'all') {
5090: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5091: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5092: } else {
5093: $chg = $changes{$key};
5094: next if ($chg < $starttime);
5095: }
5096: push(@{$changedbytime{$chg}},$key);
5097: }
5098: if (keys(%changedbytime) == 0) {
5099: &untiehash();
5100: $r->print(&mt('No content changes in imported content in specified time frame').
5101: &endContentScreen());
5102: return;
5103: }
5104: $r->print(
5105: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
5106: &Apache::loncommon::start_data_table().
5107: &Apache::loncommon::start_data_table_header_row().
5108: '<th>'.&mt('Resources').'</th>'.
5109: "<th>$lt{'mr'}</th>".
5110: "<th>$lt{'ve'}</th>".
5111: "<th>$lt{'vu'}</th>".
5112: '<th>'.&mt('History').'</th>'.
5113: &Apache::loncommon::end_data_table_header_row()
5114: );
5115: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5116: foreach my $key (sort(@{$changedbytime{$chg}})) {
5117: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5118: my $currentversion=&Apache::lonnet::getversion($key);
5119: if ($currentversion<0) {
5120: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5121: }
5122: my $linkurl=&Apache::lonnet::clutter($key);
5123: $r->print(
5124: &Apache::loncommon::start_data_table_row().
5125: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5126: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5127: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5128: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5129: '<td align="right">'
5130: );
5131: # Used in course
5132: my $usedversion=$hash{'version_'.$linkurl};
5133: if (($usedversion) && ($usedversion ne 'mostrecent')) {
5134: if ($usedversion != $currentversion) {
5135: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
5136: } else {
5137: $r->print($usedversion);
5138: }
5139: } else {
5140: $r->print($currentversion);
5141: }
5142: $r->print('</td><td title="'.$lt{'vu'}.'">');
5143: # Set version
5144: $r->print(&Apache::loncommon::select_form(
5145: $setversions{$linkurl},
5146: 'set_version_'.$linkurl,
5147: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5148: '' => '',
5149: 'mostrecent' => &mt('most recent'),
5150: map {$_,$_} (1..$currentversion)},'',$readonly));
5151: my $lastold=1;
5152: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5153: my $url=$root.'.'.$prevvers.'.'.$extension;
5154: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5155: $lastold=$prevvers;
5156: }
5157: }
5158: $r->print('</td>');
5159: # List all available versions
5160: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5161: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5162: my $url=$root.'.'.$prevvers.'.'.$extension;
5163: $r->print(
5164: '<span class="LC_nobreak">'
5165: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5166: .&mt('Version [_1]',$prevvers).'</a>'
5167: .' ('.&Apache::lonlocal::locallocaltime(
5168: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5169: .')');
5170: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5171: $r->print(
5172: ' <a href="/adm/diff?filename='.
5173: &Apache::lonnet::clutter($root.'.'.$extension).
5174: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5175: '" target="diffs">'.&mt('Diffs').'</a>');
5176: }
5177: $r->print('</span><br />');
5178: }
5179: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
5180: }
5181: }
5182: $r->print(
5183: &Apache::loncommon::end_data_table().
5184: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
5185: '</form>'
5186: );
5187:
5188: &untiehash();
5189: $r->print(&endContentScreen());
5190: return;
5191: }
5192:
5193: sub mark_hash_old {
5194: my $retie_hash=0;
5195: if ($hashtied) {
5196: $retie_hash=1;
5197: &untiehash();
5198: }
5199: &tiehash('write');
5200: $hash{'old'}=1;
5201: &untiehash();
5202: if ($retie_hash) { &tiehash(); }
5203: }
5204:
5205: sub is_hash_old {
5206: my $untie_hash=0;
5207: if (!$hashtied) {
5208: $untie_hash=1;
5209: &tiehash();
5210: }
5211: my $return=$hash{'old'};
5212: if ($untie_hash) { &untiehash(); }
5213: return $return;
5214: }
5215:
5216: sub changewarning {
5217: my ($r,$postexec,$message,$url)=@_;
5218: if (!&is_hash_old()) { return; }
5219: my $pathvar='folderpath';
5220: my $path=&escape($env{'form.folderpath'});
5221: if (!defined($url)) {
5222: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5223: }
5224: my $course_type = &Apache::loncommon::course_type();
5225: if (!defined($message)) {
5226: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5227: }
5228: my $windowname = 'loncapaclient';
5229: if ($env{'request.lti.login'}) {
5230: $windowname .= 'lti';
5231: }
5232: $r->print("\n\n".
5233: '<script type="text/javascript">'."\n".
5234: '// <![CDATA['."\n".
5235: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5236: '// ]]>'."\n".
5237: '</script>'."\n".
5238: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
5239: '<input type="hidden" name="orgurl" value="'.$url.
5240: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
5241: &mt($message,' <input type="hidden" name="'.
5242: $env{'request.role'}.'" value="1" /><input type="button" value="'.
5243: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
5244: $help{'Caching'}.'</p></form>'."\n\n");
5245: }
5246:
5247:
5248: sub init_breadcrumbs {
5249: my ($form,$text,$help)=@_;
5250: &Apache::lonhtmlcommon::clear_breadcrumbs();
5251: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
5252: text=>&Apache::loncommon::course_type().' Editor',
5253: faq=>273,
5254: bug=>'Instructor Interface',
5255: help => $help});
5256: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5257: text=>$text,
5258: faq=>273,
5259: bug=>'Instructor Interface'});
5260: }
5261:
5262: # subroutine to list form elements
5263: sub create_list_elements {
5264: my @formarr = @_;
5265: my $list = '';
5266: foreach my $button (@formarr){
5267: foreach my $picture (keys(%{$button})) {
5268: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
5269: }
5270: }
5271: return $list;
5272: }
5273:
5274: # subroutine to create ul from list elements
5275: sub create_form_ul {
5276: my $list = shift;
5277: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5278: return $ul;
5279: }
5280:
5281: #
5282: # Start tabs
5283: #
5284:
5285: sub startContentScreen {
5286: my ($mode) = @_;
5287: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
5288: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
5289: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5290: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5291: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5292: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5293: } else {
5294: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n";
5295: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5296: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5297: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5298: }
5299: $output .= "\n".'</ul>'."\n";
5300: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5301: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5302: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5303: return $output;
5304: }
5305:
5306: #
5307: # End tabs
5308: #
5309:
5310: sub endContentScreen {
5311: return '</div></div></div>';
5312: }
5313:
5314: sub supplemental_base {
5315: return 'supplemental&'.&escape(&mt('Supplemental Content'));
5316: }
5317:
5318: sub handler {
5319: my $r = shift;
5320: &Apache::loncommon::content_type($r,'text/html');
5321: $r->send_http_header;
5322: return OK if $r->header_only;
5323:
5324: # get course data
5325: my $crstype = &Apache::loncommon::course_type();
5326: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5327: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5328:
5329: # get docroot
5330: my $londocroot = $r->dir_config('lonDocRoot');
5331:
5332: # graphics settings
5333: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
5334:
5335: #
5336: # --------------------------------------------- Initialize help topics for this
5337: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5338: 'Adding_External_Resource','Adding_External_Tool',
5339: 'Navigate_Content','Adding_Folders','Docs_Overview',
5340: 'Load_Map','Supplemental','Score_Upload_Form',
5341: 'Adding_Pages','Importing_LON-CAPA_Resource',
5342: 'Importing_IMS_Course','Uploading_From_Harddrive',
5343: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
5344: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5345: }
5346: # Composite help files
5347: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5348: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5349: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5350: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5351: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5352: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
5353: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
5354: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
5355: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
5356: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
5357:
5358: my ($allowed,$canedit,$canview,$noendpage,$disabled);
5359: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5360: unless ($r->uri eq '/adm/supplemental') {
5361: # does this user have privileges to modify content.
5362: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5363: $allowed = 1;
5364: $canedit = 1;
5365: $canview = 1;
5366: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5367: $allowed = 1;
5368: $canview = 1;
5369: }
5370: }
5371: unless ($canedit) {
5372: $disabled = ' disabled="disabled"';
5373: }
5374: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5375: if ($env{'form.inhibitmenu'}) {
5376: unless ($env{'form.inhibitmenu'} eq 'yes') {
5377: delete($env{'form.inhibitmenu'});
5378: }
5379: }
5380:
5381: if ($allowed && $env{'form.verify'}) {
5382: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
5383: if (!$canedit) {
5384: &verifycontent($r);
5385: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5386: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5387: text=>'Results',
5388: faq=>273,
5389: bug=>'Instructor Interface'});
5390: &verifycontent($r,$env{'form.checkstale'});
5391: } else {
5392: &contentverifyform($r);
5393: }
5394: } elsif ($allowed && $env{'form.listsymbs'}) {
5395: &init_breadcrumbs('listsymbs','List Content IDs');
5396: &list_symbs($r);
5397: } elsif ($allowed && $env{'form.shorturls'}) {
5398: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5399: &short_urls($r,$canedit);
5400: } elsif ($allowed && $env{'form.docslog'}) {
5401: &init_breadcrumbs('docslog','Show Log');
5402: my $folder = $env{'form.folder'};
5403: if ($folder eq '') {
5404: $folder='default';
5405: }
5406: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
5407: } elsif ($allowed && $env{'form.versions'}) {
5408: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
5409: &checkversions($r,$canedit);
5410: } elsif ($canedit && $env{'form.dumpcourse'}) {
5411: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
5412: &dumpcourse($r);
5413: } elsif ($canedit && $env{'form.exportcourse'}) {
5414: &init_breadcrumbs('exportcourse','IMS Export');
5415: &Apache::imsexport::exportcourse($r);
5416: } else {
5417: if ($canedit && $env{'form.authorrole'}) {
5418: $noendpage = 1;
5419: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5420: if ($redirect) {
5421: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5422: my $container = 'sequence';
5423: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5424: $is_random_order,$container) =
5425: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5426: my (@folders)=split('&',$env{'form.folderpath'});
5427: $env{'form.foldername'}=&unescape(pop(@folders));
5428: my $folder=pop(@folders);
5429: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5430: $folder.'.'.$container);
5431: my $warning;
5432: if ($fatal) {
5433: if ($container eq 'page') {
5434: $warning = &mt('An error occurred retrieving the contents of the current page.');
5435: } else {
5436: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5437: }
5438: } else {
5439: my $url = $redirect;
5440: my $srcfile = $londocroot.$url;
5441: $url =~ s{^/priv/}{/res/};
5442: my $targetfile = $londocroot.$url;
5443: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5444: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5445: $env{'form.folder'} = $folder;
5446: &snapshotbefore();
5447: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5448: my $ext = 'false';
5449: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5450: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5451: ':'.$ext.':normal:res';
5452: push(@LONCAPA::map::order,$newidx);
5453: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5454: 'string_yesno');
5455: &remember_parms($newidx,'hiddenresource','set','yes');
5456: ($errtext,$fatal) =
5457: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5458: &log_differences($plain);
5459: &mark_hash_old();
5460: $r->internal_redirect($redirect);
5461: return OK;
5462: }
5463: } else {
5464: $r->internal_redirect($redirect);
5465: }
5466: }
5467: }
5468: #
5469: # Done catching special calls
5470: # The whole rest is for course and supplemental documents and utilities menu
5471: # Get the parameters that may be needed
5472: #
5473: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
5474: ['folderpath',
5475: 'forcesupplement','forcestandard',
5476: 'tools','symb','command','supppath']);
5477:
5478: foreach my $item ('forcesupplement','forcestandard','tools') {
5479: next if ($env{'form.'.$item} eq '');
5480: unless ($env{'form.'.$item} eq '1') {
5481: delete($env{'form.'.$item});
5482: }
5483: }
5484:
5485: if ($env{'form.command'}) {
5486: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5487: delete($env{'form.command'});
5488: }
5489: }
5490:
5491: if ($env{'form.symb'}) {
5492: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5493: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5494: delete($env{'form.symb'});
5495: }
5496: }
5497:
5498: # standard=1: this is a "new-style" course with an uploaded map as top level
5499: # standard=2: this is a "old-style" course, and there is nothing we can do
5500:
5501: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
5502:
5503: # Decide whether this should display supplemental or main content or utilities
5504: # supplementalflag=1: show supplemental documents
5505: # supplementalflag=0: show standard documents
5506: # toolsflag=1: show utilities
5507:
5508: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5509: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5510: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
5511: $supplementalflag=0;
5512: }
5513: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5514: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5515: unless ($allowed) { $supplementalflag=1; }
5516: unless ($standard) { $supplementalflag=1; }
5517: my $toolsflag=0;
5518: if ($env{'form.tools'}) { $toolsflag=1; }
5519:
5520: if ($env{'form.folderpath'} ne '') {
5521: my @items = split(/\&/,$env{'form.folderpath'});
5522: my $badpath;
5523: for (my $i=0; $i<@items; $i++) {
5524: my $odd = $i%2;
5525: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5526: $badpath = 1;
5527: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5528: $badpath = 1;
5529: }
5530: last if ($badpath);
5531: }
5532: if ($badpath) {
5533: delete($env{'form.folderpath'});
5534: }
5535: }
5536:
5537: if ($env{'form.supppath'} ne '') {
5538: my @items = split(/\&/,$env{'form.supppath'});
5539: my $badpath;
5540: for (my $i=0; $i<@items; $i++) {
5541: my $odd = $i%2;
5542: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5543: $badpath = 1;
5544: }
5545: last if ($badpath);
5546: }
5547: if ($badpath) {
5548: delete($env{'form.supppath'});
5549: }
5550: }
5551:
5552: my $script='';
5553: my $showdoc=0;
5554: my $addentries = {};
5555: my $container;
5556: my $containertag;
5557: my $pathitem;
5558: my %ltitools;
5559: my $hiddentop;
5560: my $navmap;
5561: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
5562:
5563: # Do we directly jump somewhere?
5564: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
5565: if ($env{'form.symb'} ne '') {
5566: $env{'form.folderpath'}=
5567: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
5568: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5569: $env{'form.command'}.'_'.$env{'form.symb'}});
5570: } elsif ($env{'form.supppath'} ne '') {
5571: $env{'form.folderpath'}=$env{'form.supppath'};
5572: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5573: $env{'form.command'}.'_'.$env{'form.supppath'}});
5574: }
5575: } elsif ($env{'form.command'} eq 'editdocs') {
5576: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
5577: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
5578: } elsif ($env{'form.command'} eq 'editsupp') {
5579: $env{'form.folderpath'} = &supplemental_base();
5580: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5581: } elsif ($env{'form.command'} eq 'contents') {
5582: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5583: } elsif ($env{'form.command'} eq 'home') {
5584: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
5585: }
5586:
5587:
5588: # Where do we store these for when we come back?
5589: my $stored_folderpath='docs_folderpath';
5590: if ($supplementalflag) {
5591: $stored_folderpath='docs_sup_folderpath';
5592: }
5593:
5594: # No folderpath, and in edit mode, see if we have something stored
5595: if ((!$env{'form.folderpath'}) && $allowed) {
5596: &Apache::loncommon::restore_course_settings($stored_folderpath,
5597: {'folderpath' => 'scalar'});
5598:
5599: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5600: if ($supplementalflag) {
5601: undef($env{'form.folderpath'}) if ($1 eq 'default');
5602: } else {
5603: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5604: }
5605: } else {
5606: undef($env{'form.folderpath'});
5607: }
5608: }
5609:
5610: # If we are not allowed to make changes, all we can see are supplemental docs
5611: if (!$allowed) {
5612: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5613: $env{'form.folderpath'} = &supplemental_base();
5614: }
5615: }
5616: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
5617: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
5618: $env{'form.folderpath'} = &supplemental_base()
5619: .'&'.
5620: $env{'form.folderpath'};
5621: }
5622: # If allowed and user's role is not advanced check folderpath is not hidden
5623: if (($allowed) && (!$env{'request.role.adv'}) &&
5624: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5625: my $folderurl;
5626: my @pathitems = split(/\&/,$env{'form.folderpath'});
5627: my $folder = $pathitems[-2];
5628: if ($folder eq '') {
5629: undef($env{'form.folderpath'});
5630: } else {
5631: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
5632: if ((split(/\:/,$pathitems[-1]))[4]) {
5633: $folderurl .= '.page';
5634: } else {
5635: $folderurl .= '.sequence';
5636: }
5637: unless (ref($navmap)) {
5638: $navmap = Apache::lonnavmaps::navmap->new();
5639: }
5640: if (ref($navmap)) {
5641: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5642: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5643: unless (@resources) {
5644: undef($env{'form.folderpath'});
5645: }
5646: }
5647: }
5648: }
5649: }
5650:
5651:
5652: # If after all of this, we still don't have any paths, make them
5653: unless ($env{'form.folderpath'}) {
5654: if ($supplementalflag) {
5655: $env{'form.folderpath'}=&supplemental_base();
5656: } elsif ($allowed) {
5657: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
5658: }
5659: }
5660:
5661: # Store this
5662: unless ($toolsflag) {
5663: if (($allowed) && ($env{'form.folderpath'} ne '')) {
5664: &Apache::loncommon::store_course_settings($stored_folderpath,
5665: {'folderpath' => 'scalar'});
5666: }
5667: my $folderpath;
5668: if ($env{'form.folderpath'}) {
5669: $folderpath = $env{'form.folderpath'};
5670: my (@folders)=split('&',$env{'form.folderpath'});
5671: $env{'form.foldername'}=&unescape(pop(@folders));
5672: if ($env{'form.foldername'} =~ /\:1$/) {
5673: $container = 'page';
5674: } else {
5675: $container = 'sequence';
5676: }
5677: $env{'form.folder'}=pop(@folders);
5678: } else {
5679: if ($env{'form.folder'} eq '' ||
5680: $env{'form.folder'} eq 'supplemental') {
5681: if ($env{'form.folder'} eq 'supplemental') {
5682: $folderpath=&supplemental_base();
5683: } elsif (!$hiddentop) {
5684: $folderpath='default&'.
5685: &escape(&mt('Main Content').':::::');
5686: }
5687: }
5688: }
5689: $containertag = '<input type="hidden" name="folderpath" value="" />';
5690: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
5691: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5692: $showdoc='/'.$1;
5693: }
5694: if ($showdoc) { # got called in sequence from course
5695: $allowed=0;
5696: } else {
5697: if ($canedit) {
5698: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5699: $script=&Apache::lonratedt::editscript('simple');
5700: }
5701: }
5702: }
5703:
5704: # get personal data
5705: my $uname=$env{'user.name'};
5706: my $udom=$env{'user.domain'};
5707: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5708:
5709: if ($allowed) {
5710: if ($toolsflag) {
5711: $script .= &inject_data_js();
5712: my ($home,$other,%outhash)=&authorhosts();
5713: if (!$home && $other) {
5714: my @hosts;
5715: foreach my $aurole (keys(%outhash)) {
5716: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5717: push(@hosts,$outhash{$aurole});
5718: }
5719: }
5720: $script .= &dump_switchserver_js(@hosts);
5721: }
5722: } else {
5723: my $tid = 1;
5724: my @tabids;
5725: if ($supplementalflag) {
5726: @tabids = ('002','dd2','ee2','ff2');
5727: $tid = 2;
5728: } else {
5729: @tabids = ('aa1','bb1','cc1','ff1');
5730: unless ($env{'form.folderpath'} =~ /\:1$/) {
5731: unshift(@tabids,'001');
5732: push(@tabids,('dd1','ee1'));
5733: }
5734: }
5735: my $tabidstr = join("','",@tabids);
5736: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
5737: my $posslti = keys(%ltitools);
5738: my $hostname = $r->hostname();
5739: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
5740: $londocroot,$canedit,$hostname,\$navmap).
5741: &history_tab_js().
5742: &inject_data_js().
5743: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
5744: &Apache::lonextresedit::extedit_javascript(\%ltitools);
5745: $addentries = {
5746: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
5747: };
5748: }
5749: $script .= &paste_popup_js();
5750: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5751: &mt('Switch server?');
5752:
5753:
5754: }
5755: # -------------------------------------------------------------------- Body tag
5756: $script = '<script type="text/javascript">'."\n"
5757: .'// <![CDATA['."\n"
5758: .$script."\n"
5759: .'// ]]>'."\n"
5760: .'</script>'."\n"
5761: .'<script type="text/javascript"
5762: src="/res/adm/includes/file_upload.js"></script>'."\n";
5763:
5764: # Breadcrumbs
5765: &Apache::lonhtmlcommon::clear_breadcrumbs();
5766:
5767: if ($showdoc) {
5768: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5769: {'force_register' => $showdoc,}));
5770: } elsif ($toolsflag) {
5771: my ($breadtext,$breadtitle);
5772: $breadtext = "$crstype Editor";
5773: if ($canedit) {
5774: $breadtitle = 'Editing '.$crstype.' Contents';
5775: } else {
5776: $breadtext .= ' (View-only mode)';
5777: $breadtitle = 'Viewing '.$crstype.' Contents';
5778: }
5779: &Apache::lonhtmlcommon::add_breadcrumb({
5780: href=>"/adm/coursedocs",text=>$breadtext});
5781: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5782: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5783: .&Apache::lonhtmlcommon::breadcrumbs(
5784: $breadtitle)
5785: );
5786: } elsif ($r->uri eq '/adm/supplemental') {
5787: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5788: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5789: {'bread_crumbs' => $brcrum,}));
5790: } else {
5791: my ($breadtext,$breadtitle,$helpitem);
5792: $breadtext = "$crstype Editor";
5793: if ($canedit) {
5794: $breadtitle = 'Editing '.$crstype.' Contents';
5795: $helpitem = 'Docs_Adding_Course_Doc';
5796: } else {
5797: $breadtext .= ' (View-only mode)';
5798: $breadtitle = 'Viewing '.$crstype.' Contents';
5799: $helpitem = 'Docs_Viewing_Course_Doc';
5800: }
5801: &Apache::lonhtmlcommon::add_breadcrumb({
5802: href=>"/adm/coursedocs",text=>$breadtext});
5803: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
5804: {'add_entries' => $addentries}
5805: )
5806: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5807: .&Apache::lonhtmlcommon::breadcrumbs(
5808: $breadtitle,
5809: $helpitem)
5810: );
5811: }
5812:
5813: my %allfiles = ();
5814: my %codebase = ();
5815: my ($upload_result,$upload_output,$uploadphase);
5816: if ($canedit) {
5817: if (($env{'form.uploaddoc.filename'}) &&
5818: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
5819: my $context = $1;
5820: # Process file upload - phase one - upload and parse primary file.
5821: undef($hadchanges);
5822: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
5823: \%allfiles,\%codebase,$context,$crstype);
5824: undef($navmap);
5825: if ($hadchanges) {
5826: &mark_hash_old();
5827: }
5828: $r->print($upload_output);
5829: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5830: # Process file upload - phase two - upload embedded objects
5831: $uploadphase = 'check_embedded';
5832: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5833: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5834: $env{'form.newidx'});
5835: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5836: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5837: my ($destination,$dir_root) = &embedded_destination();
5838: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5839: my $actionurl = '/adm/coursedocs';
5840: my ($result,$flag) =
5841: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5842: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5843: $actionurl);
5844: $r->print($result.&return_to_editor());
5845: } elsif ($env{'form.phase'} eq 'check_embedded') {
5846: # Process file upload - phase three - modify references in HTML file
5847: $uploadphase = 'modified_orightml';
5848: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5849: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5850: my ($destination,$dir_root) = &embedded_destination();
5851: my $result =
5852: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5853: $docuname,$docudom,undef,
5854: $dir_root);
5855: $r->print($result.&return_to_editor());
5856: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5857: $uploadphase = 'decompress_phase_one';
5858: $r->print(&decompression_phase_one().
5859: &return_to_editor());
5860: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5861: $uploadphase = 'decompress_phase_two';
5862: $r->print(&decompression_phase_two().
5863: &return_to_editor());
5864: }
5865: }
5866:
5867: if ($allowed && $toolsflag) {
5868: $r->print(&startContentScreen('tools'));
5869: $r->print(&generate_admin_menu($crstype,$canedit));
5870: $r->print(&endContentScreen());
5871: } elsif ((!$showdoc) && (!$uploadphase)) {
5872: # -----------------------------------------------------------------------------
5873: my %lt=&Apache::lonlocal::texthash(
5874: 'copm' => 'All documents out of a published map into this folder',
5875: 'upfi' => 'Upload File',
5876: 'upld' => 'Upload Content',
5877: 'srch' => 'Search',
5878: 'impo' => 'Import',
5879: 'lnks' => 'Import from Stored Links',
5880: 'impm' => 'Import from Assembled Map',
5881: 'imcr' => 'Import from Course Resources',
5882: 'extr' => 'External Resource',
5883: 'extt' => 'External Tool',
5884: 'selm' => 'Select Map',
5885: 'load' => 'Load Map',
5886: 'newf' => 'New Folder',
5887: 'newp' => 'New Composite Page',
5888: 'syll' => 'Syllabus',
5889: 'navc' => 'Table of Contents',
5890: 'sipa' => 'Simple Course Page',
5891: 'sipr' => 'Simple Problem',
5892: 'webp' => 'Blank Web Page (editable)',
5893: 'stpr' => 'Standard Problem',
5894: 'news' => 'New sub-directory',
5895: 'crpr' => 'Create Problem',
5896: 'drbx' => 'Drop Box',
5897: 'scuf' => 'External Scores (handgrade, upload, clicker)',
5898: 'bull' => 'Discussion Board',
5899: 'mypi' => 'My Personal Information Page',
5900: 'grpo' => 'Group Portfolio',
5901: 'rost' => 'Course Roster',
5902: 'abou' => 'Personal Information Page for a User',
5903: 'imsf' => 'IMS Upload',
5904: 'imsl' => 'Upload IMS package',
5905: 'cms' => 'Origin of IMS package',
5906: 'se' => 'Select',
5907: 'file' => 'File',
5908: 'title' => 'Title',
5909: 'addp' => 'Add Placeholder to course?',
5910: 'uste' => 'Use Template?',
5911: 'fnam' => 'File Name:',
5912: 'loca' => 'Location:',
5913: 'dire' => 'Directory:',
5914: 'cate' => 'Category:',
5915: 'tmpl' => 'Template:',
5916: 'comment' => 'Comment',
5917: 'parse' => 'Upload embedded images/multimedia files if HTML file',
5918: 'bb5' => 'Blackboard 5',
5919: 'bb6' => 'Blackboard 6',
5920: 'angel5' => 'ANGEL 5.5',
5921: 'webctce4' => 'WebCT 4 Campus Edition',
5922: 'yes' => 'Yes',
5923: 'no' => 'No',
5924: 'er' => 'Editing rights unavailable for your current role.',
5925: );
5926: # -----------------------------------------------------------------------------
5927:
5928: # Calculate free quota space for a user or course. A javascript function checks
5929: # file size to determine if upload should be allowed.
5930: my $quotatype = 'unofficial';
5931: if ($crstype eq 'Community') {
5932: $quotatype = 'community';
5933: } elsif ($crstype eq 'Placement') {
5934: $quotatype = 'placement';
5935: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5936: $quotatype = 'official';
5937: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5938: $quotatype = 'textbook';
5939: }
5940: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5941: 'course',$quotatype); # expressed in MB
5942: my $current_disk_usage = 0;
5943: foreach my $subdir ('docs','supplemental') {
5944: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5945: "userfiles/$subdir",1); # expressed in kB
5946: }
5947: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5948: my $usage = $current_disk_usage/1024; # in MB
5949: my $quota = $disk_quota;
5950: my $percent;
5951: if ($disk_quota == 0) {
5952: $percent = 100.0;
5953: } else {
5954: $percent = 100*($usage/$disk_quota);
5955: }
5956: $usage = sprintf("%.2f",$usage);
5957: $quota = sprintf("%.2f",$quota);
5958: $percent = sprintf("%.0f",$percent);
5959: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5960: $percent.'%',$quota.' MB').'</p>';
5961:
5962: my $fileupload=(<<FIUP);
5963: $quotainfo
5964: $lt{'file'}:<br />
5965: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
5966: <input type="hidden" id="free_space" value="$free_space" />
5967: FIUP
5968:
5969: my $checkbox=(<<CHBO);
5970: <!-- <label>$lt{'parse'}?
5971: <input type="checkbox" name="parserflag" />
5972: </label> -->
5973: <label>
5974: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
5975: </label>
5976: CHBO
5977: my $imsfolder = $env{'form.folder'};
5978: if ($imsfolder eq '') {
5979: $imsfolder = 'default';
5980: }
5981: my $imspform=(<<IMSFORM);
5982: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5983: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5984: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
5985: <fieldset id="uploadimsform" style="display: none;">
5986: <legend>$lt{'imsf'}</legend>
5987: $fileupload
5988: <br />
5989: <p>
5990: $lt{'cms'}:
5991: <select name="source" $disabled>
5992: <option value="-1" selected="selected">$lt{'se'}</option>
5993: <option value="bb5">$lt{'bb5'}</option>
5994: <option value="bb6">$lt{'bb6'}</option>
5995: <option value="angel5">$lt{'angel5'}</option>
5996: <option value="webctce4">$lt{'webctce4'}</option>
5997: </select>
5998: <input type="hidden" name="folder" value="$imsfolder" />
5999: </p>
6000: <input type="hidden" name="phase" value="one" />
6001: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
6002: </fieldset>
6003: </form>
6004: IMSFORM
6005:
6006: my $fileuploadform=(<<FUFORM);
6007: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6008: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6009: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
6010: <fieldset id="uploaddocform" style="display: none;">
6011: <legend>$lt{'upfi'}</legend>
6012: <input type="hidden" name="active" value="aa" />
6013: $fileupload
6014: <br />
6015: $lt{'title'}:<br />
6016: <input type="text" size="60" name="comment" $disabled />
6017: $pathitem
6018: <input type="hidden" name="cmd" value="upload_default" />
6019: <br />
6020: <span class="LC_nobreak" style="float:left">
6021: $checkbox
6022: </span>
6023: <br clear="all" />
6024: <input type="submit" value="$lt{'upld'}" $disabled />
6025: </fieldset>
6026: </form>
6027: FUFORM
6028:
6029: my $mapimportjs;
6030: if ($canedit) {
6031: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6032: } else {
6033: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6034: }
6035: my $importpubform=(<<SEDFFORM);
6036: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
6037: $lt{'impm'}</a>$help{'Load_Map'}
6038: <form action="/adm/coursedocs" method="post" name="mapimportform">
6039: <fieldset id="importmapform" style="display: none;">
6040: <legend>$lt{'impm'}</legend>
6041: <input type="hidden" name="active" value="bb" />
6042: $lt{'copm'}<br />
6043: <span class="LC_nobreak">
6044: <input type="text" name="importmap" size="40" value=""
6045: onfocus="this.blur();$mapimportjs" $disabled />
6046: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6047: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
6048: </fieldset>
6049: </form>
6050:
6051: SEDFFORM
6052: my $importcrsresform;
6053: my ($numdirs,$pickfile) =
6054: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
6055: "resize_scrollbox('contentscroll','1','0');",
6056: undef,'res');
6057: if ($pickfile) {
6058: $importcrsresform=(<<CRSFORM);
6059: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
6060: $lt{'imcr'}</a>$help{'Course_Resources'}
6061: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6062: <fieldset id="importcrsresform" style="display: none;">
6063: <legend>$lt{'imcr'}</legend>
6064: <input type="hidden" name="active" value="bb" />
6065: $pickfile
6066: <p>
6067: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
6068: </p>
6069: <input type="hidden" name="importdetail" value="" />
6070: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
6071: </fieldset>
6072: </form>
6073: CRSFORM
6074: }
6075:
6076: my $fromstoredjs;
6077: if ($canedit) {
6078: $fromstoredjs = 'open_StoredLinks_Import()';
6079: } else {
6080: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6081: }
6082:
6083: my @importpubforma = (
6084: { '<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>" },
6085: { '<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'}" },
6086: { '<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>' },
6087: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6088: );
6089: if ($pickfile) {
6090: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
6091: }
6092: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
6093: my $extresourcesform =
6094: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6095: $help{'Adding_External_Resource'},
6096: undef,undef,undef,undef,undef,undef,$disabled);
6097: my $exttoolform =
6098: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6099: $help{'Adding_External_Tool'},undef,
6100: undef,'tool',$coursedom,$coursenum,
6101: \%ltitools,$disabled);
6102: if ($allowed) {
6103: my $folder = $env{'form.folder'};
6104: if ($folder eq '') {
6105: $folder='default';
6106: }
6107: if ($canedit) {
6108: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6109: if ($output) {
6110: $r->print($output);
6111: }
6112: }
6113: $r->print(<<HIDDENFORM);
6114: <form name="renameform" method="post" action="/adm/coursedocs">
6115: <input type="hidden" name="title" />
6116: <input type="hidden" name="cmd" />
6117: <input type="hidden" name="markcopy" />
6118: <input type="hidden" name="copyfolder" />
6119: $containertag
6120: </form>
6121: <form name="aliasform" method="post" action="/adm/coursedocs">
6122: <input type="hidden" name="alias" />
6123: <input type="hidden" name="cmd" />
6124: $containertag
6125: </form>
6126:
6127: HIDDENFORM
6128: $r->print(&makesimpleeditform($pathitem)."\n".
6129: &makedocslogform($pathitem."\n".
6130: '<input type="hidden" name="folder" value="'.
6131: $env{'form.folder'}.'" />'."\n"));
6132: }
6133:
6134: # Generate the tabs
6135: my ($mode,$needs_end);
6136: if (($supplementalflag) && (!$allowed)) {
6137: my @folders = split('&',$env{'form.folderpath'});
6138: unless (@folders > 2) {
6139: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6140: $needs_end = 1;
6141: }
6142: } else {
6143: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
6144: $needs_end = 1;
6145: }
6146:
6147: #
6148: my $hostname = $r->hostname();
6149: my $savefolderpath;
6150:
6151: if ($allowed) {
6152: my $folder=$env{'form.folder'};
6153: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
6154: $folder='default';
6155: $savefolderpath = $env{'form.folderpath'};
6156: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
6157: $pathitem = '<input type="hidden" name="folderpath" value="'.
6158: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6159: }
6160: my $postexec='';
6161: if ($folder eq 'default') {
6162: my $windowname = 'loncapaclient';
6163: if ($env{'request.lti.login'}) {
6164: $windowname .= 'lti';
6165: }
6166: $r->print('<script type="text/javascript">'."\n"
6167: .'// <![CDATA['."\n"
6168: .'this.window.name="'.$windowname.'";'."\n"
6169: .'// ]]>'."\n"
6170: .'</script>'."\n"
6171: );
6172: } else {
6173: #$postexec='self.close();';
6174: }
6175: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6176: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
6177: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6178:
6179: my $newnavform=(<<NNFORM);
6180: <form action="/adm/coursedocs" method="post" name="newnav">
6181: <input type="hidden" name="active" value="ff" />
6182: $pathitem
6183: <input type="hidden" name="importdetail"
6184: value="$lt{'navc'}=/adm/navmaps" />
6185: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
6186: $help{'Navigate_Content'}
6187: </form>
6188: NNFORM
6189: my $newsmppageform=(<<NSPFORM);
6190: <form action="/adm/coursedocs" method="post" name="newsmppg">
6191: <input type="hidden" name="active" value="ff" />
6192: $pathitem
6193: <input type="hidden" name="importdetail" value="" />
6194: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
6195: $help{'Simple Page'}
6196: </form>
6197: NSPFORM
6198:
6199: my $newsmpproblemform=(<<NSPROBFORM);
6200: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
6201: <input type="hidden" name="active" value="dd" />
6202: $pathitem
6203: <input type="hidden" name="importdetail" value="" />
6204: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
6205: $help{'Simple_Problem'}
6206: </form>
6207:
6208: NSPROBFORM
6209:
6210: my $newdropboxform=(<<NDBFORM);
6211: <form action="/adm/coursedocs" method="post" name="newdropbox">
6212: <input type="hidden" name="active" value="dd" />
6213: $pathitem
6214: <input type="hidden" name="importdetail" value="" />
6215: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
6216: $help{'Dropbox'}
6217: </form>
6218: NDBFORM
6219:
6220: my $newexuploadform=(<<NEXUFORM);
6221: <form action="/adm/coursedocs" method="post" name="newexamupload">
6222: <input type="hidden" name="active" value="dd" />
6223: $pathitem
6224: <input type="hidden" name="importdetail" value="" />
6225: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
6226: $help{'Score_Upload_Form'}
6227: </form>
6228: NEXUFORM
6229:
6230: my $newbulform=(<<NBFORM);
6231: <form action="/adm/coursedocs" method="post" name="newbul">
6232: <input type="hidden" name="active" value="ee" />
6233: $pathitem
6234: <input type="hidden" name="importdetail" value="" />
6235: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
6236: $help{'Bulletin Board'}
6237: </form>
6238: NBFORM
6239:
6240: my $newaboutmeform=(<<NAMFORM);
6241: <form action="/adm/coursedocs" method="post" name="newaboutme">
6242: <input type="hidden" name="active" value="ee" />
6243: $pathitem
6244: <input type="hidden" name="importdetail"
6245: value="$plainname=/adm/$udom/$uname/aboutme" />
6246: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
6247: $help{'My Personal Information Page'}
6248: </form>
6249: NAMFORM
6250:
6251: my $newaboutsomeoneform=(<<NASOFORM);
6252: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
6253: <input type="hidden" name="active" value="ee" />
6254: $pathitem
6255: <input type="hidden" name="importdetail" value="" />
6256: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
6257: </form>
6258: NASOFORM
6259:
6260: my $newrosterform=(<<NROSTFORM);
6261: <form action="/adm/coursedocs" method="post" name="newroster">
6262: <input type="hidden" name="active" value="ee" />
6263: $pathitem
6264: <input type="hidden" name="importdetail"
6265: value="$lt{'rost'}=/adm/viewclasslist" />
6266: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
6267: $help{'Course_Roster'}
6268: </form>
6269: NROSTFORM
6270:
6271: my $newwebpage;
6272: if ($folder =~ /^default_?(\d*)$/) {
6273: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6274: if ($1) {
6275: $newwebpage .= $1;
6276: } else {
6277: $newwebpage .= 'default';
6278: }
6279: $newwebpage .= '/new.html';
6280: }
6281: my $newwebpageform =(<<NWEBFORM);
6282: <form action="/adm/coursedocs" method="post" name="newwebpage">
6283: <input type="hidden" name="active" value="ff" />
6284: $pathitem
6285: <input type="hidden" name="importdetail" value="$newwebpage" />
6286: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
6287: $help{'Web_Page'}
6288: </form>
6289: NWEBFORM
6290:
6291: my @ids=&Apache::lonnet::current_machine_ids();
6292: my %select_menus;
6293: my $numauthor = 0;
6294: my $numcrsdirs = 0;
6295: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
6296: if ($env{'user.author'}) {
6297: $numauthor ++;
6298: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6299: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6300: my $is_home = 1;
6301: my %subdirs;
6302: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6303: $select_menus{'author'}->{'default'} = '/';
6304: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6305: my @ordered = ('/');
6306: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6307: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6308: push(@ordered,$relpath);
6309: }
6310: $select_menus{'author'}->{'order'} = \@ordered;
6311: } else {
6312: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6313: $select_menus{'author'}->{'default'} = 'switch';
6314: $select_menus{'author'}->{'order'} = ['switch'];
6315: }
6316: }
6317: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6318: ['active'],['ca','aa']);
6319: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6320: my %by_roletype;
6321: if (keys(%roleshash)) {
6322: foreach my $entry (keys(%roleshash)) {
6323: my ($auname,$audom,$roletype) = split(/:/,$entry);
6324: my $key = $entry;
6325: $key =~ s/:/___/g;
6326: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6327: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6328: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6329: if (grep(/^\Q$rolehome\E$/,@ids)) {
6330: my $is_home = 1;
6331: my (%subdirs,@ordered);
6332: my $toppath="/priv/$audom/$auname";
6333: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6334: $select_menus{$key}->{'default'} = '/';
6335: $select_menus{$key}->{'select2'}->{'/'} = '/';
6336: my @ordered = ('/');
6337: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6338: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6339: push(@ordered,$relpath);
6340: }
6341: $select_menus{$key}->{'order'} = \@ordered;
6342: } else {
6343: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6344: $select_menus{$key}->{'default'} = 'switch';
6345: $select_menus{$key}->{'order'} = ['switch'];
6346: }
6347: $numauthor ++;
6348: }
6349: }
6350: my ($pickdir,$showtitle);
6351: if ($numauthor) {
6352: my @order;
6353: my $defrole;
6354: if ($env{'user.author'}) {
6355: push(@order,'author');
6356: $defrole = 'author';
6357: }
6358: if (keys(%by_roletype)) {
6359: foreach my $possrole ('ca','aa') {
6360: if (ref($by_roletype{$possrole}) eq 'HASH') {
6361: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6362: unless ($defrole) {
6363: $defrole = $author;
6364: }
6365: push(@order,$author.'___'.$possrole);
6366: }
6367: }
6368: }
6369: }
6370: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6371: if (grep(/^\Q$crshome\E$/,@ids)) {
6372: my $is_home = 1;
6373: my %subdirs;
6374: my $toppath="/priv/$coursedom/$coursenum";
6375: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6376: $numcrsdirs = keys(%subdirs);
6377: $select_menus{'course'}->{'default'} = '/';
6378: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6379: my @ordered = ('/');
6380: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6381: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6382: push(@ordered,$relpath);
6383: }
6384: $select_menus{'course'}->{'order'} = \@ordered;
6385: } else {
6386: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6387: $select_menus{'course'}->{'default'} = 'switch';
6388: $select_menus{'course'}->{'order'} = ['switch'];
6389: }
6390: push(@order,'course');
6391: $pickdir = $lt{'loca'}.
6392: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6393: $defrole,'authorrole','authorpath',
6394: \%select_menus,\@order,'toggleCrsResTitle();',
6395: '','priv').'<br />';
6396: $showtitle = 'none';
6397: } else {
6398: my $is_home;
6399: $showtitle = 'inline';
6400: if (grep(/^\Q$crshome\E$/,@ids)) {
6401: $is_home = 1;
6402: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6403: my $toppath="/priv/$coursedom/$coursenum'}";
6404: my %subdirs;
6405: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6406: $numcrsdirs = keys(%subdirs);
6407: if ($numcrsdirs) {
6408: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6409: '<option value="/">/</option>'."\n";
6410: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6411: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
6412: }
6413: $pickdir .= '</select>';
6414: } else {
6415: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6416: }
6417: }
6418: }
6419:
6420: my %seltemplate_menus;
6421: my @files = &Apache::lonhomework::get_template_list('problem');
6422: my @noexamplelink = ('blank.problem','blank.library','script.library');
6423: my $currentcategory = '';
6424: my @ordered = ('');
6425: my %templatehelp;
6426: my $defcategory = '';
6427: my @catorder = ($defcategory);
6428: $seltemplate_menus{$defcategory}->{'order'} = [''];
6429: $seltemplate_menus{$defcategory}->{'text'} = '';
6430: foreach my $file (@files) {
6431: if (ref($file) eq 'ARRAY') {
6432: my ($path,$title,$category,$help) = @{$file};
6433: next if ($title !~ /\S/);
6434: if (&js_escape($category) ne $currentcategory) {
6435: $currentcategory = &js_escape($category);
6436: push(@catorder,&js_escape($currentcategory));
6437: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6438: $seltemplate_menus{$currentcategory}->{'default'} = '';
6439: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6440: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6441: }
6442: if ($path) {
6443: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6444: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6445: if ($help) {
6446: $templatehelp{$path} = $help;
6447: }
6448: }
6449: }
6450: }
6451:
6452: my $templates = $lt{'cate'}.' '.
6453: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6454: $defcategory,'tempcategory','template',
6455: \%seltemplate_menus,\@catorder,
6456: "resize_scrollbox('contentscroll','1','0');",
6457: "toggleExampleText();",'template').'<br />';
6458: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6459: '<span id="newresexample">'.&mt('Example').'<span></a>';
6460: my $crsresform=(<<RESFORM);
6461: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6462: $lt{'stpr'}</a>$help{'Course_Resource'}
6463: <form action="/adm/coursedocs" method="post" name="courseresform">
6464: <fieldset id="crsresform" style="display:none;">
6465: <legend>$lt{'stpr'}</legend>
6466: <input type="hidden" name="active" value="bb" />
6467: <p>
6468: $pickdir
6469: <span class="LC_nobreak">$lt{'news'}?
6470: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
6471:
6472: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
6473: </span><span id="newsubdir"></span>
6474: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6475: </p>
6476: $lt{'fnam'}
6477: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
6478: <p>
6479: <div id="newresource" style="display:$showtitle">
6480: $lt{'addp'}
6481: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
6482: $lt{'no'}</label>
6483: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
6484: $lt{'yes'}</label>
6485: <span id="newrestitle"></span>
6486: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
6487: </div>
6488: </p>
6489: <p>
6490: $lt{'uste'}
6491: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
6492: $lt{'no'}</label>
6493: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
6494: $lt{'yes'}</label>
6495: <div id="newrestemplate" style="display:none">
6496: $templates
6497: $templatepreview
6498: </div>
6499: </p>
6500: <span class="LC_nobreak">
6501: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
6502: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
6503: </span>
6504: </fieldset>
6505: </form>
6506:
6507: RESFORM
6508:
6509: my $specialdocumentsform;
6510: my @specialdocumentsforma;
6511: my $gradingform;
6512: my @gradingforma;
6513: my $communityform;
6514: my @communityforma;
6515: my $newfolderform;
6516: my $newfolderb;
6517:
6518: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6519:
6520: my $newpageform=(<<NPFORM);
6521: <form action="/adm/coursedocs" method="post" name="newpage">
6522: <input type="hidden" name="folderpath" value="$path" />
6523: <input type="hidden" name="importdetail" value="" />
6524: <input type="hidden" name="active" value="ee" />
6525: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
6526: $help{'Adding_Pages'}
6527: </form>
6528: NPFORM
6529:
6530:
6531: $newfolderform=(<<NFFORM);
6532: <form action="/adm/coursedocs" method="post" name="newfolder">
6533: $pathitem
6534: <input type="hidden" name="importdetail" value="" />
6535: <input type="hidden" name="active" value="" />
6536: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
6537: </form>
6538: NFFORM
6539:
6540: my $newsylform=(<<NSYLFORM);
6541: <form action="/adm/coursedocs" method="post" name="newsyl">
6542: <input type="hidden" name="active" value="ee" />
6543: $pathitem
6544: <input type="hidden" name="importdetail"
6545: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
6546: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
6547: $help{'Syllabus'}
6548:
6549: </form>
6550: NSYLFORM
6551:
6552: my $newgroupfileform=(<<NGFFORM);
6553: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
6554: <input type="hidden" name="active" value="ee" />
6555: $pathitem
6556: <input type="hidden" name="importdetail"
6557: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
6558: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
6559: $help{'Group Portfolio'}
6560: </form>
6561: NGFFORM
6562: @specialdocumentsforma=(
6563: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
6564: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6565: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
6566: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
6567: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6568: );
6569: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6570:
6571: my @external = (
6572: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
6573: );
6574: if (keys(%ltitools)) {
6575: push(@external,
6576: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6577: );
6578: }
6579: my $externalform = &create_form_ul(&create_list_elements(@external));
6580:
6581: my @importdoc = ();
6582: unless ($container eq 'page') {
6583: push(@importdoc,
6584: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6585: );
6586: }
6587: push(@importdoc,
6588: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
6589: );
6590: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
6591:
6592: @gradingforma=(
6593: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6594: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6595: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6596: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform},
6597: );
6598: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6599:
6600: @communityforma=(
6601: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6602: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6603: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
6604: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6605: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
6606: );
6607: $communityform = &create_form_ul(&create_list_elements(@communityforma));
6608:
6609: my %orderhash = (
6610: 'aa' => ['Upload',$fileuploadform],
6611: 'bb' => ['Import',$importpubform],
6612: 'cc' => ['External',$externalform],
6613: 'dd' => ['Grading',$gradingform],
6614: );
6615: unless ($container eq 'page') {
6616: $orderhash{'00'} = ['Newfolder',$newfolderform];
6617: $orderhash{'ee'} = ['Collaboration',$communityform];
6618: $orderhash{'ff'} = ['Other',$specialdocumentsform];
6619: }
6620:
6621: $hadchanges=0;
6622: unless (($supplementalflag || $toolsflag)) {
6623: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6624: $supplementalflag,\%orderhash,$iconpath,$pathitem,
6625: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
6626: undef($navmap);
6627: if ($error) {
6628: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6629: }
6630: if ($hadchanges) {
6631: unless (&is_hash_old()) {
6632: &mark_hash_old();
6633: }
6634: }
6635:
6636: &changewarning($r,'');
6637: }
6638: }
6639:
6640: # Supplemental documents start here
6641:
6642: my $folder=$env{'form.folder'};
6643: unless ($supplementalflag) {
6644: $folder='supplemental';
6645: }
6646: if ($folder =~ /^supplemental$/ &&
6647: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
6648: $env{'form.folderpath'} = &supplemental_base();
6649: } elsif ($allowed) {
6650: $env{'form.folderpath'} = $savefolderpath;
6651: }
6652: $pathitem = '<input type="hidden" name="folderpath" value="'.
6653: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6654: if ($allowed) {
6655: my $folderseq=
6656: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
6657:
6658: my $supupdocform=(<<SUPDOCFORM);
6659: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6660: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6661: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
6662: <fieldset id="uploadsuppdocform" style="display: none;">
6663: <legend>$lt{'upfi'}</legend>
6664: <input type="hidden" name="active" value="ee" />
6665: $fileupload
6666: <br />
6667: <br />
6668: <span class="LC_nobreak">
6669: $checkbox
6670: </span>
6671: <br /><br />
6672: $lt{'comment'}:<br />
6673: <textarea cols="50" rows="4" name="comment"></textarea>
6674: <br />
6675: $pathitem
6676: <input type="hidden" name="cmd" value="upload_supplemental" />
6677: <input type='submit' value="$lt{'upld'}" />
6678: </form>
6679: SUPDOCFORM
6680:
6681: my $supnewfolderform=(<<SNFFORM);
6682: <form action="/adm/coursedocs" method="post" name="supnewfolder">
6683: <input type="hidden" name="active" value="" />
6684: $pathitem
6685: <input type="hidden" name="importdetail" value="" />
6686: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
6687: $help{'Adding_Folders'}
6688: </form>
6689: SNFFORM
6690:
6691: my $supextform =
6692: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6693: $help{'Adding_External_Resource'},
6694: undef,undef,undef,undef,undef,undef,
6695: $disabled);
6696:
6697: my $supexttoolform =
6698: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6699: $help{'Adding_External_Tool'},
6700: undef,undef,'tool',$coursedom,
6701: $coursenum,\%ltitools,$disabled);
6702:
6703: my $supnewsylform=(<<SNSFORM);
6704: <form action="/adm/coursedocs" method="post" name="supnewsyl">
6705: <input type="hidden" name="active" value="ff" />
6706: $pathitem
6707: <input type="hidden" name="importdetail"
6708: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
6709: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
6710: $help{'Syllabus'}
6711: </form>
6712: SNSFORM
6713:
6714: my $supnewaboutmeform=(<<SNAMFORM);
6715: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
6716: <input type="hidden" name="active" value="ff" />
6717: $pathitem
6718: <input type="hidden" name="importdetail"
6719: value="$plainname=/adm/$udom/$uname/aboutme" />
6720: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
6721: $help{'My Personal Information Page'}
6722: </form>
6723: SNAMFORM
6724:
6725: my $supwebpage;
6726: if ($folder =~ /^supplemental_?(\d*)$/) {
6727: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6728: if ($1) {
6729: $supwebpage .= $1;
6730: } else {
6731: $supwebpage .= 'default';
6732: }
6733: $supwebpage .= '/new.html';
6734: }
6735: my $supwebpageform =(<<SWEBFORM);
6736: <form action="/adm/coursedocs" method="post" name="supwebpage">
6737: <input type="hidden" name="active" value="cc" />
6738: $pathitem
6739: <input type="hidden" name="importdetail" value="$supwebpage" />
6740: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
6741: $help{'Web_Page'}
6742: </form>
6743: SWEBFORM
6744:
6745:
6746: my @specialdocs = (
6747: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
6748: =>$supnewsylform},
6749: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
6750: =>$supnewaboutmeform},
6751: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6752:
6753: );
6754: my @supexternal = (
6755: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
6756: =>$supextform});
6757: if (keys(%ltitools)) {
6758: push(@supexternal,
6759: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
6760: =>$supexttoolform});
6761: }
6762: my @supimportdoc = (
6763: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6764: =>$supupdocform},
6765: );
6766:
6767: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
6768: my %suporderhash = (
6769: '00' => ['Supnewfolder', $supnewfolderform],
6770: 'dd' => ['Upload',$supupdocform],
6771: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
6772: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
6773: );
6774: if ($supplementalflag) {
6775: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6776: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
6777: \%ltitools,$canedit,$hostname);
6778: if ($error) {
6779: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6780: } else {
6781: if ($suppchanges) {
6782: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6783: my @ids=&Apache::lonnet::current_machine_ids();
6784: foreach my $server (keys(%servers)) {
6785: next if (grep(/^\Q$server\E$/,@ids));
6786: my $hashid=$coursenum.':'.$coursedom;
6787: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6788: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
6789: }
6790: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6791: undef($suppchanges);
6792: }
6793: }
6794: }
6795: } elsif ($supplementalflag) {
6796: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6797: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
6798: if ($error) {
6799: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6800: }
6801: }
6802:
6803: if ($needs_end) {
6804: $r->print(&endContentScreen());
6805: }
6806:
6807: if ($allowed) {
6808: $r->print('
6809: <form method="post" name="extimport" action="/adm/coursedocs">
6810: <input type="hidden" name="title" />
6811: <input type="hidden" name="url" />
6812: <input type="hidden" name="useform" />
6813: <input type="hidden" name="residx" />
6814: </form>');
6815: }
6816: } elsif ($showdoc) {
6817: # -------------------------------------------------------- This is showdoc mode
6818: $r->print("<h1>".&mt('Uploaded Document').' - '.
6819: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
6820: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
6821: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
6822: }
6823: }
6824: unless ($noendpage) {
6825: $r->print(&Apache::loncommon::end_page());
6826: }
6827: return OK;
6828: }
6829:
6830: sub embedded_form_elems {
6831: my ($phase,$primaryurl,$newidx) = @_;
6832: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6833: $newidx =~s /\D+//g;
6834: return <<STATE;
6835: <input type="hidden" name="folderpath" value="$folderpath" />
6836: <input type="hidden" name="cmd" value="upload_embedded" />
6837: <input type="hidden" name="newidx" value="$newidx" />
6838: <input type="hidden" name="phase" value="$phase" />
6839: <input type="hidden" name="primaryurl" value="$primaryurl" />
6840: STATE
6841: }
6842:
6843: sub embedded_destination {
6844: my $folder=$env{'form.folder'};
6845: my $destination = 'docs/';
6846: if ($folder =~ /^supplemental/) {
6847: $destination = 'supplemental/';
6848: }
6849: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6850: $destination .= 'default/';
6851: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6852: $destination .= $2.'/';
6853: }
6854: my $newidx = $env{'form.newidx'};
6855: $newidx =~s /\D+//g;
6856: if ($newidx) {
6857: $destination .= $newidx;
6858: }
6859: my $dir_root = '/userfiles';
6860: return ($destination,$dir_root);
6861: }
6862:
6863: sub return_to_editor {
6864: my $actionurl = '/adm/coursedocs';
6865: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6866: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6867: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6868: '</a></p>';
6869: }
6870:
6871: sub decompression_info {
6872: my ($destination,$dir_root) = &embedded_destination();
6873: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6874: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6875: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6876: my $container='sequence';
6877: my ($pathitem,$hiddenelem);
6878: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
6879: if ($env{'form.folderpath'} =~ /\:1$/) {
6880: $container='page';
6881: }
6882: unshift(@hiddens,$pathitem);
6883: foreach my $item (@hiddens) {
6884: if ($item eq 'newidx') {
6885: next if ($env{'form.'.$item} =~ /\D/);
6886: }
6887: if ($env{'form.'.$item}) {
6888: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
6889: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
6890: }
6891: }
6892: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6893: $hiddenelem);
6894: }
6895:
6896: sub decompression_phase_one {
6897: my ($dir,$file,$warning,$error,$output);
6898: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6899: &decompression_info();
6900: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
6901: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6902: } else {
6903: my $file = $1;
6904: $output =
6905: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6906: $destination,$dir_root,
6907: $hiddenelem);
6908: if ($env{'form.autoextract_camtasia'}) {
6909: $output .= &remove_archive($docudom,$docuname,$container);
6910: }
6911: }
6912: if ($error) {
6913: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6914: $error.'</p>'."\n";
6915: }
6916: if ($warning) {
6917: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6918: }
6919: return $output;
6920: }
6921:
6922: sub decompression_phase_two {
6923: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6924: &decompression_info();
6925: my $output;
6926: if ($env{'form.archivedelete'}) {
6927: $output = &remove_archive($docudom,$docuname,$container);
6928: }
6929: $output .=
6930: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
6931: $destination,$dir_root,$hiddenelem);
6932: return $output;
6933: }
6934:
6935: sub remove_archive {
6936: my ($docudom,$docuname,$container) = @_;
6937: my $map = $env{'form.folder'}.'.'.$container;
6938: my ($output,$delwarning,$delresult,$url);
6939: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6940: if ($fatal) {
6941: if ($container eq 'page') {
6942: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6943: } else {
6944: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6945: }
6946: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
6947: } else {
6948: my $currcmd = $env{'form.cmd'};
6949: my $position = $env{'form.position'};
6950: my $archiveidx = $position;
6951: if ($position > 0) {
6952: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6953: $archiveidx = $position-1;
6954: }
6955: $env{'form.cmd'} = 'remove_'.$archiveidx;
6956: my ($title,$url,@rrest) =
6957: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6958: if ($url eq $env{'form.archiveurl'}) {
6959: if (&handle_edit_cmd($docuname,$docudom)) {
6960: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6961: if ($fatal) {
6962: if ($container eq 'page') {
6963: $delwarning = &mt('An error occurred updating the contents of the current page.');
6964: } else {
6965: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6966: }
6967: } else {
6968: $delresult = &mt('Archive file removed.');
6969: }
6970: }
6971: } else {
6972: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6973: ' '.&mt('As a result the archive file has not been removed.');
6974: }
6975: }
6976: $env{'form.cmd'} = $currcmd;
6977: }
6978: if ($delwarning) {
6979: $output = '<p class="LC_warning">'.
6980: $delwarning.
6981: '</p>';
6982: }
6983: if ($delresult) {
6984: $output .= '<p class="LC_info">'.
6985: $delresult.
6986: '</p>';
6987: }
6988: return $output;
6989: }
6990:
6991: sub generate_admin_menu {
6992: my ($crstype,$canedit) = @_;
6993: my $lc_crstype = lc($crstype);
6994: my ($home,$other,%outhash)=&authorhosts();
6995: my %lt= ( # do not translate here
6996: 'vc' => 'Verify Content',
6997: 'cv' => 'Check/Set Resource Versions',
6998: 'ls' => 'List Resource Identifiers',
6999: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
7000: 'imse' => 'Export contents to IMS Archive',
7001: 'dcd' => "Copy $crstype Content to Authoring Space",
7002: );
7003: my ($candump,$dumpurl);
7004: if ($home + $other > 0) {
7005: $candump = 'F';
7006: if ($home) {
7007: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7008: } else {
7009: my @hosts;
7010: foreach my $aurole (keys(%outhash)) {
7011: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7012: push(@hosts,$outhash{$aurole});
7013: }
7014: }
7015: if (@hosts == 1) {
7016: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7017: '&role='.
7018: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7019: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7020: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7021: } else {
7022: $dumpurl = "javascript:choose_switchserver_window()";
7023: }
7024: }
7025: }
7026: my @menu=
7027: ({ categorytitle=>'Administration',
7028: items =>[
7029: { linktext => $lt{'vc'},
7030: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7031: permission => 'F',
7032: help => 'Docs_Verify_Content',
7033: icon => 'verify.png',
7034: linktitle => 'Verify contents can be retrieved/rendered',
7035: },
7036: { linktext => $lt{'cv'},
7037: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7038: permission => 'F',
7039: help => 'Docs_Check_Resource_Versions',
7040: icon => 'resversion.png',
7041: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7042: },
7043: { linktext => $lt{'ls'},
7044: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7045: permission => 'F',
7046: #help => '',
7047: icon => 'symbs.png',
7048: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7049: },
7050: { linktext => $lt{'ct'},
7051: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7052: permission => 'F',
7053: help => 'Docs_Short_URLs',
7054: icon => 'shorturls.png',
7055: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7056: },
7057: ]
7058: });
7059: if ($canedit) {
7060: push(@menu,
7061: { categorytitle=>'Export',
7062: items =>[
7063: { linktext => $lt{'imse'},
7064: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7065: permission => 'F',
7066: help => 'Docs_Export_Course_Docs',
7067: icon => 'imsexport.png',
7068: linktitle => $lt{'imse'},
7069: },
7070: { linktext => $lt{'dcd'},
7071: url => $dumpurl,
7072: permission => $candump,
7073: help => 'Docs_Dump_Course_Docs',
7074: icon => 'dump.png',
7075: linktitle => $lt{'dcd'},
7076: },
7077: ]
7078: });
7079: }
7080: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7081: '<input type="hidden" id="dummy" />'."\n".
7082: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7083: '</form>';
7084: }
7085:
7086: sub generate_edit_table {
7087: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
7088: $need_save,$copyfolder,$canedit) = @_;
7089: return unless(ref($orderhash_ref) eq 'HASH');
7090: my %orderhash = %{$orderhash_ref};
7091: my ($form, $activetab, $active, $disabled);
7092: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
7093: $activetab = $env{'form.active'};
7094: }
7095: unless ($canedit) {
7096: $disabled = ' disabled="disabled"';
7097: }
7098: my $backicon = $iconpath.'clickhere.gif';
7099: my $backtext = &mt('Exit Editor');
7100: $form = '<div class="LC_Box" style="margin:0;">'.
7101: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7102: '<li class="goback">'.
7103: '<a href="javascript:toContents('."'$jumpto'".');">'.
7104: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7105: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7106: '<li>'.
7107: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7108: &mt('Undo Delete').'</a></li>'."\n";
7109: if ($env{'form.docslog'}) {
7110: $form .= '<li class="active">';
7111: } else {
7112: $form .= '<li>';
7113: }
7114: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7115: &mt('History').'</a></li>'."\n";
7116: if ($env{'form.docslog'}) {
7117: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7118: &mt('Edit').'</a></li>'."\n";
7119: }
7120: foreach my $name (reverse(sort(keys(%orderhash)))) {
7121: if($name ne '00'){
7122: if($activetab eq '' || $activetab ne $name){
7123: $active = '';
7124: }elsif($activetab eq $name){
7125: $active = 'class="active"';
7126: }
7127: $form .= '<li style="float:right" '.$active
7128: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
7129: } else {
7130: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
7131:
7132: }
7133: }
7134: $form .= '</ul>'."\n";
7135: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
7136:
7137: if ($to_show ne '') {
7138: my $saveform;
7139: if ($need_save) {
7140: my $button = &mt('Make changes');
7141: my $path;
7142: if ($env{'form.folderpath'}) {
7143: $path =
7144: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7145: }
7146: $saveform = <<"END";
7147: <div id="multisave" style="display:none; clear:both;" >
7148: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7149: <input type="hidden" name="folderpath" value="$path" />
7150: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7151: <input type="hidden" name="allhiddenresource" value="" />
7152: <input type="hidden" name="allencrypturl" value="" />
7153: <input type="hidden" name="allrandompick" value="" />
7154: <input type="hidden" name="allrandomorder" value="" />
7155: <input type="hidden" name="changeparms" value="" />
7156: <input type="hidden" name="multiremove" value="" />
7157: <input type="hidden" name="multicut" value="" />
7158: <input type="hidden" name="multicopy" value="" />
7159: <input type="hidden" name="multichange" value="" />
7160: <input type="hidden" name="copyfolder" value="$copyfolder" />
7161: <input type="submit" name="savemultiples" value="$button" $disabled />
7162: </form>
7163: </div>
7164: END
7165: }
7166: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
7167: }
7168: foreach my $field (keys(%orderhash)){
7169: if($field ne '00'){
7170: if($activetab eq '' || $activetab ne $field){
7171: $active = 'style="display: none;float:left"';
7172: }elsif($activetab eq $field){
7173: $active = 'style="display:block;float:left"';
7174: }
7175: $form .= '<div id="'.$field.$tid.'"'
7176: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
7177: .'</div>'."\n";
7178: }
7179: }
7180: unless ($env{'form.docslog'}) {
7181: $form .= '</div></div>'."\n";
7182: }
7183: return $form;
7184: }
7185:
7186: sub editing_js {
7187: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7188: $londocroot,$canedit,$hostname,$navmapref) = @_;
7189: my %js_lt = &Apache::lonlocal::texthash(
7190: p_mnf => 'Name of New Folder',
7191: t_mnf => 'New Folder',
7192: p_mnp => 'Name of New Page',
7193: t_mnp => 'New Page',
7194: p_mxu => 'Title for the External Score',
7195: p_msp => 'Name of Simple Course Page',
7196: p_msb => 'Title for the Problem',
7197: p_mdb => 'Title for the Drop Box',
7198: p_mbb => 'Title for the Discussion Board',
7199: p_mwp => 'Title for Web Page',
7200: p_mnr => 'Title for the Resource',
7201: p_mab => "Enter user:domain for User's Personal Information Page",
7202: p_mab2 => 'Personal Information Page of ',
7203: p_mab_alrt1 => 'Not a valid user:domain',
7204: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7205: p_chn => 'New Title',
7206: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
7207: p_rmr2a => 'Remove',
7208: p_rmr2b => '?',
7209: p_rmr3a => 'Remove those',
7210: p_rmr3b => 'items?',
7211: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7212: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
7213: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7214: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
7215: p_ctr2a => 'Cut',
7216: p_ctr2b => '?',
7217: p_ctr3a => 'Cut those',
7218: p_ctr3b => 'items?',
7219: setal => 'Enter a (unique) alias',
7220: delal => 'Are you sure you want to eliminate the alias?',
7221: rpck => 'Enter number to pick (e.g., 3)',
7222: imsfile => 'You must choose an IMS package for import',
7223: imscms => 'You must select which Course Management System was the source of the IMS package',
7224: invurl => 'Invalid URL',
7225: titbl => 'Title is blank',
7226: more => '(More ...)',
7227: less => '(Less ...)',
7228: noor => 'No actions selected or changes to settings specified.',
7229: noch => 'No changes to settings specified.',
7230: noac => 'No actions selected.',
7231: nofi => 'No file selected',
7232: tinc => 'Title in course',
7233: sunm => 'Sub-directory name',
7234: edri => 'Editing rights unavailable for your current role.',
7235: );
7236: &js_escape(\%js_lt);
7237: my $crstype = &Apache::loncommon::course_type();
7238: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7239: my $main_container_page;
7240: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7241: $main_container_page = 1;
7242: }
7243: my $backtourl;
7244: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
7245: my $toplevelsupp = &supplemental_base();
7246:
7247: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7248: my $caller = $1;
7249: if ($caller =~ /^supplemental/) {
7250: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7251: } else {
7252: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7253: $res = &Apache::lonnet::clutter($res);
7254: if (&Apache::lonnet::is_on_map($res)) {
7255: my ($url,$anchor);
7256: if ($res =~ /^([^#]+)#([^#]+)$/) {
7257: $url = $1;
7258: $anchor = $2;
7259: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7260: $caller = $1.&escape('#').$anchor;
7261: }
7262: } else {
7263: $url = $res;
7264: }
7265: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7266: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7267: $backtourl .= '?navmap=1';
7268: } else {
7269: $backtourl .= '?symb='.
7270: &HTML::Entities::encode($caller,'<>&"');
7271: }
7272: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7273: if (($ENV{'SERVER_PORT'} == 443) &&
7274: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
7275: if ($hostname ne '') {
7276: $backtourl = 'http://'.$hostname.$backtourl;
7277: }
7278: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7279: }
7280: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7281: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
7282: $backtourl = 'http://'.$hostname.$backtourl;
7283: }
7284: }
7285: if ($anchor ne '') {
7286: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7287: }
7288: $backtourl = &Apache::loncommon::escape_single($backtourl);
7289: } else {
7290: $backtourl = '/adm/navmaps';
7291: }
7292: }
7293: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7294: $backtourl = '/adm/menu';
7295: } elsif ($supplementalflag) {
7296: $backtourl = '/adm/supplemental';
7297: } else {
7298: $backtourl = '/adm/navmaps';
7299: }
7300:
7301: my $fieldsets = "'doc'";
7302: unless ($main_container_page) {
7303: $fieldsets .=",'ims'";
7304: }
7305: my $extfieldsets = "'ext'";
7306: if ($posslti) {
7307: $extfieldsets .= ",'tool'";
7308: }
7309: if ($supplementalflag) {
7310: $fieldsets = "'suppdoc'";
7311: $extfieldsets = "'suppext'";
7312: if ($posslti) {
7313: $extfieldsets .= ",'supptool'";
7314: }
7315: }
7316:
7317: my $jsmakefunctions;
7318: if ($canedit) {
7319: $jsmakefunctions = <<ENDNEWSCRIPT;
7320: function makenewfolder(targetform,folderseq) {
7321: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
7322: if (foldername) {
7323: targetform.importdetail.value=escape(foldername)+"="+folderseq;
7324: targetform.submit();
7325: }
7326: }
7327:
7328: function makenewpage(targetform,folderseq) {
7329: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
7330: if (pagename) {
7331: targetform.importdetail.value=escape(pagename)+"="+folderseq;
7332: targetform.submit();
7333: }
7334: }
7335:
7336: function makeexamupload() {
7337: var title=prompt('$js_lt{"p_mxu"}');
7338: if (title) {
7339: this.document.forms.newexamupload.importdetail.value=
7340: escape(title)+'=/res/lib/templates/examupload.problem';
7341: this.document.forms.newexamupload.submit();
7342: }
7343: }
7344:
7345: function makesmppage() {
7346: var title=prompt('$js_lt{"p_msp"}');
7347: if (title) {
7348: this.document.forms.newsmppg.importdetail.value=
7349: escape(title)+'=/adm/$udom/$uname/new/smppg';
7350: this.document.forms.newsmppg.submit();
7351: }
7352: }
7353:
7354: function makewebpage(type) {
7355: var title=prompt('$js_lt{"p_mwp"}');
7356: var formname;
7357: if (type == 'supp') {
7358: formname = this.document.forms.supwebpage;
7359: } else {
7360: formname = this.document.forms.newwebpage;
7361: }
7362: if (title) {
7363: var webpage = formname.importdetail.value;
7364: formname.importdetail.value = escape(title)+'='+webpage;
7365: formname.submit();
7366: }
7367: }
7368:
7369: function makesmpproblem() {
7370: var title=prompt('$js_lt{"p_msb"}');
7371: if (title) {
7372: this.document.forms.newsmpproblem.importdetail.value=
7373: escape(title)+'=/res/lib/templates/simpleproblem.problem';
7374: this.document.forms.newsmpproblem.submit();
7375: }
7376: }
7377:
7378: function makedropbox() {
7379: var title=prompt('$js_lt{"p_mdb"}');
7380: if (title) {
7381: this.document.forms.newdropbox.importdetail.value=
7382: escape(title)+'=/res/lib/templates/DropBox.problem';
7383: this.document.forms.newdropbox.submit();
7384: }
7385: }
7386:
7387: function makebulboard() {
7388: var title=prompt('$js_lt{"p_mbb"}');
7389: if (title) {
7390: this.document.forms.newbul.importdetail.value=
7391: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
7392: this.document.forms.newbul.submit();
7393: }
7394: }
7395:
7396: function makeabout() {
7397: var user=prompt("$js_lt{'p_mab'}");
7398: if (user) {
7399: var comp=new Array();
7400: comp=user.split(':');
7401: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7402: if ((comp[0]) && (comp[1])) {
7403: this.document.forms.newaboutsomeone.importdetail.value=
7404: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
7405: this.document.forms.newaboutsomeone.submit();
7406: } else {
7407: alert("$js_lt{'p_mab_alrt1'}");
7408: }
7409: } else {
7410: alert("$js_lt{'p_mab_alrt2'}");
7411: }
7412: }
7413: }
7414:
7415: function makenew(targetform) {
7416: targetform.submit();
7417: }
7418:
7419: function changename(folderpath,index,oldtitle) {
7420: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7421: if (title) {
7422: this.document.forms.renameform.markcopy.value='';
7423: this.document.forms.renameform.title.value=title;
7424: this.document.forms.renameform.cmd.value='rename_'+index;
7425: this.document.forms.renameform.folderpath.value=folderpath;
7426: this.document.forms.renameform.submit();
7427: }
7428: }
7429:
7430: function setalias(folderpath,index) {
7431: var alias = prompt('$js_lt{"setal"}');
7432: if ((alias != null) && (alias != '')) {
7433: this.document.forms.aliasform.alias.value=alias;
7434: this.document.forms.aliasform.cmd.value='setalias_'+index;
7435: this.document.forms.aliasform.folderpath.value=folderpath;
7436: this.document.forms.aliasform.submit();
7437: }
7438: }
7439:
7440: function delalias(folderpath,index) {
7441: if (confirm('$js_lt{"delal"}')) {
7442: this.document.forms.aliasform.cmd.value='delalias_'+index;
7443: this.document.forms.aliasform.folderpath.value=folderpath;
7444: this.document.forms.aliasform.submit();
7445: }
7446: }
7447:
7448: ENDNEWSCRIPT
7449: } else {
7450: $jsmakefunctions = <<ENDNEWSCRIPT;
7451:
7452: function makenewfolder() {
7453: alert("$js_lt{'edri'}");
7454: }
7455:
7456: function makenewpage() {
7457: alert("$js_lt{'edri'}");
7458: }
7459:
7460: function makeexamupload() {
7461: alert("$js_lt{'edri'}");
7462: }
7463:
7464: function makesmppage() {
7465: alert("$js_lt{'edri'}");
7466: }
7467:
7468: function makewebpage(type) {
7469: alert("$js_lt{'edri'}");
7470: }
7471:
7472: function makesmpproblem() {
7473: alert("$js_lt{'edri'}");
7474: }
7475:
7476: function makedropbox() {
7477: alert("$js_lt{'edri'}");
7478: }
7479:
7480: function makebulboard() {
7481: alert("$js_lt{'edri'}");
7482: }
7483:
7484: function makeabout() {
7485: alert("$js_lt{'edri'}");
7486: }
7487:
7488: function changename() {
7489: alert("$js_lt{'edri'}");
7490: }
7491:
7492: function setalias() {
7493: alert("$js_lt{'edri'}");
7494: }
7495:
7496: function delalias() {
7497: alert("$js_lt{'edri'}");
7498: }
7499:
7500: function makenew() {
7501: alert("$js_lt{'edri'}");
7502: }
7503:
7504: function groupimport() {
7505: alert("$js_lt{'edri'}");
7506: }
7507:
7508: function groupsearch() {
7509: alert("$js_lt{'edri'}");
7510: }
7511:
7512: function groupopen(url,recover) {
7513: var options="scrollbars=1,resizable=1,menubar=0";
7514: idxflag=1;
7515: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7516: idx.focus();
7517: }
7518:
7519: ENDNEWSCRIPT
7520:
7521: }
7522: return <<ENDSCRIPT;
7523:
7524: $jsmakefunctions
7525:
7526: function toggleUpload(caller) {
7527: var blocks = Array($fieldsets);
7528: for (var i=0; i<blocks.length; i++) {
7529: var disp = 'none';
7530: if (caller == blocks[i]) {
7531: var curr = document.getElementById('upload'+caller+'form').style.display;
7532: if (curr == 'none') {
7533: disp='block';
7534: }
7535: }
7536: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
7537: }
7538: resize_scrollbox('contentscroll','1','1');
7539: return;
7540: }
7541:
7542: function toggleExternal(caller) {
7543: var blocks = Array($extfieldsets);
7544: for (var i=0; i<blocks.length; i++) {
7545: var disp = 'none';
7546: if (caller == blocks[i]) {
7547: var curr = document.getElementById('external'+caller+'form').style.display;
7548: if (curr == 'none') {
7549: disp='block';
7550: }
7551: }
7552: document.getElementById('external'+blocks[i]+'form').style.display=disp;
7553: if ((caller == 'tool') || (caller == 'supptool')) {
7554: if (disp == 'block') {
7555: if (document.getElementById('LC_exttoolid')) {
7556: var toolselector = document.getElementById('LC_exttoolid');
7557: var suppflag = 0;
7558: if (caller == 'supptool') {
7559: suppflag = 1;
7560: }
7561: currForm = document.getElementById('new'+caller);
7562: updateExttool(toolselector,currForm,suppflag);
7563: }
7564: }
7565: }
7566: }
7567: resize_scrollbox('contentscroll','1','1');
7568: return;
7569: }
7570:
7571: function toggleMap(caller) {
7572: var disp = 'none';
7573: if (document.getElementById('importmapform')) {
7574: if (caller == 'map') {
7575: var curr = document.getElementById('importmapform').style.display;
7576: if (curr == 'none') {
7577: disp='block';
7578: }
7579: }
7580: document.getElementById('importmapform').style.display=disp;
7581: resize_scrollbox('contentscroll','1','1');
7582: }
7583: return;
7584: }
7585:
7586: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7587: var disp = 'none';
7588: if (document.getElementById('crsresform')) {
7589: if (caller == 'res') {
7590: var curr = document.getElementById('crsresform').style.display;
7591: if (curr == 'none') {
7592: disp='block';
7593: numauthor = parseInt(numauthorrole);
7594: if (numauthor > 0) {
7595: document.courseresform.authorrole.selectedIndex = 0;
7596: select1priv_changed();
7597: document.courseresform.authorpath.selectedIndex = 0;
7598: document.courseresform.newresourceadd.selectedIndex = 0;
7599: toggleNewInCourse(document.courseresform);
7600: if (document.getElementById('newresource')) {
7601: document.getElementById('newresource').style.display = 'none';
7602: }
7603: } else {
7604: if (numcrsdirs) {
7605: document.courseresform.authorpath.selectedIndex = 0;
7606: }
7607: }
7608: if (document.courseresform.newresusetemp.length) {
7609: document.courseresform.newresusetemp[0].checked = true;
7610: toggleWithTemplate(document.courseresform);
7611: }
7612: document.courseresform.newresourcename.value = '';
7613: }
7614: }
7615: if (document.courseresform.newsubdir.length) {
7616: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7617: if (document.courseresform.newsubdir[j].value == 0) {
7618: document.courseresform.newsubdir[j].checked = true;
7619: }
7620: break;
7621: }
7622: if (document.getElementById('newsubdirname')) {
7623: document.getElementById('newsubdirname').type = "hidden";
7624: document.getElementById('newsubdirname').value = "";
7625: }
7626: if (document.getElementById('newsubdir')) {
7627: document.getElementById('newsubdir').innerHTML = "";
7628: }
7629: }
7630: document.getElementById('crsresform').style.display=disp;
7631: resize_scrollbox('contentscroll','1','0');
7632: }
7633: return;
7634: }
7635:
7636: function toggleNewsubdir(form) {
7637: if (form.newsubdir.length) {
7638: for (var j=0; j<form.newsubdir.length; j++) {
7639: if (form.newsubdir[j].checked) {
7640: if (document.getElementById('newsubdirname')) {
7641: if (form.newsubdir[j].value == '1') {
7642: document.getElementById('newsubdirname').type = "text";
7643: if (document.getElementById('newsubdir')) {
7644: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7645: }
7646: } else {
7647: document.getElementById('newsubdirname').type = "hidden";
7648: document.getElementById('newsubdirname').value = "";
7649: document.getElementById('newsubdir').innerHTML = "";
7650: }
7651: }
7652: break;
7653: }
7654: }
7655: }
7656: }
7657:
7658: function toggleCrsResTitle() {
7659: if (document.getElementById('newresource')) {
7660: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7661: document.getElementById('newresource').style.display = 'inline';
7662: document.courseresform.newresourceadd[0].checked = true;
7663: toggleNewInCourse(document.courseresform);
7664: } else {
7665: document.getElementById('newresource').style.display = 'none';
7666: }
7667: }
7668: }
7669:
7670: function toggleNewInCourse(form) {
7671: if (form.newresourceadd.length) {
7672: for (var i=0; i<form.newresourceadd.length; i++) {
7673: if (form.newresourceadd[i].checked) {
7674: if (document.getElementById('newresourcetitle')) {
7675: if (form.newresourceadd[i].value == '1') {
7676: document.getElementById('newresourcetitle').type = 'text';
7677: if (document.getElementById('newrestitle')) {
7678: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7679: }
7680: } else {
7681: document.getElementById('newresourcetitle').type = 'hidden';
7682: document.getElementById('newresourcetitle').value = '';
7683: if (document.getElementById('newrestitle')) {
7684: document.getElementById('newrestitle').innerHTML = '';
7685: }
7686: }
7687: }
7688: break;
7689: }
7690: }
7691: }
7692: }
7693:
7694: function toggleWithTemplate(form) {
7695: if (form.newresusetemp.length) {
7696: for (var i=0; i<form.newresusetemp.length; i++) {
7697: if (form.newresusetemp[i].checked) {
7698: if (document.getElementById('newrestemplate')) {
7699: if (form.newresusetemp[i].value == '1') {
7700: document.getElementById('newrestemplate').style.display = 'inline';
7701: toggleExampleText();
7702: } else {
7703: form.tempcategory.selectedIndex = 0;
7704: select1template_changed();
7705: document.getElementById('newrestemplate').style.display = 'none';
7706: }
7707: }
7708: }
7709: }
7710: }
7711: }
7712:
7713: function toggleExampleText() {
7714: if (document.getElementById('newresexample')) {
7715: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7716: if (url == '') {
7717: document.getElementById('newresexample').style.fontWeight = 'normal';
7718: } else {
7719: document.getElementById('newresexample').style.fontWeight = 'bold';
7720: }
7721: }
7722: }
7723:
7724: function getExample(width,height,scrolling,transparency) {
7725: var url;
7726: if (document.courseresform.newresusetemp.length) {
7727: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7728: if (document.courseresform.newresusetemp[i].checked) {
7729: if (document.courseresform.newresusetemp[i].value == '1') {
7730: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7731: if (url == '') {
7732: alert('Pick a category and template');
7733: } else {
7734: url = url.replace("$londocroot","");
7735: url += '?inhibitmenu=yes';
7736: }
7737: }
7738: break;
7739: }
7740: }
7741: }
7742: if (url != '') {
7743: openMyModal(url,width,height,scrolling,transparency,'');
7744: }
7745: }
7746:
7747: function toggleImportCrsres(caller,dircount) {
7748: var disp = 'none';
7749: if (document.getElementById('importcrsresform')) {
7750: if (caller == 'res') {
7751: var numdirs = parseInt(dircount);
7752: var curr = document.getElementById('importcrsresform').style.display;
7753: if (curr == 'none') {
7754: disp='block';
7755: if (numdirs > 1) {
7756: select1res_changed();
7757: }
7758: }
7759: }
7760: document.getElementById('importcrsresform').style.display=disp;
7761: resize_scrollbox('contentscroll','1','0');
7762: }
7763: return;
7764: }
7765:
7766: function makeims(imsform) {
7767: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
7768: alert("$js_lt{'imsfile'}");
7769: return;
7770: }
7771: if (imsform.source.selectedIndex == 0) {
7772: alert("$js_lt{'imscms'}");
7773: return;
7774: }
7775: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7776: imsform.submit();
7777: }
7778:
7779: function updatePick(targetform,index,caller) {
7780: var pickitem;
7781: var picknumitem;
7782: var picknumtext;
7783: if (index == 'all') {
7784: pickitem = document.getElementById('randompickall');
7785: picknumitem = document.getElementById('rpicknumall');
7786: picknumtext = document.getElementById('rpicktextall');
7787: } else {
7788: pickitem = document.getElementById('randompick_'+index);
7789: picknumitem = document.getElementById('rpicknum_'+index);
7790: picknumtext = document.getElementById('randompicknum_'+index);
7791: }
7792: if (pickitem.checked) {
7793: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
7794: if (picknum == '' || picknum == null) {
7795: if (caller == 'check') {
7796: pickitem.checked=false;
7797: if (index == 'all') {
7798: picknumtext.innerHTML = '';
7799: if (caller == 'link') {
7800: propagateState(targetform,'rpicknum');
7801: }
7802: } else {
7803: checkForSubmit(targetform,'randompick','settings');
7804: }
7805: }
7806: } else {
7807: picknum.toString();
7808: var regexdigit=/^\\d+\$/;
7809: if (regexdigit.test(picknum)) {
7810: picknumitem.value = picknum;
7811: if (index == 'all') {
7812: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
7813: if (caller == 'link') {
7814: propagateState(targetform,'rpicknum');
7815: }
7816: } else {
7817: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
7818: checkForSubmit(targetform,'randompick','settings');
7819: }
7820: } else {
7821: if (caller == 'check') {
7822: if (index == 'all') {
7823: picknumtext.innerHTML = '';
7824: if (caller == 'link') {
7825: propagateState(targetform,'rpicknum');
7826: }
7827: } else {
7828: pickitem.checked=false;
7829: checkForSubmit(targetform,'randompick','settings');
7830: }
7831: }
7832: return;
7833: }
7834: }
7835: } else {
7836: picknumitem.value = '';
7837: picknumtext.innerHTML = '';
7838: if (index == 'all') {
7839: if (caller == 'link') {
7840: propagateState(targetform,'rpicknum');
7841: }
7842: } else {
7843: checkForSubmit(targetform,'randompick','settings');
7844: }
7845: }
7846: }
7847:
7848: function propagateState(form,param) {
7849: if (document.getElementById(param+'all')) {
7850: var setcheck = 0;
7851: var rpick = 0;
7852: if (param == 'rpicknum') {
7853: if (document.getElementById('randompickall')) {
7854: if (document.getElementById('randompickall').checked) {
7855: if (document.getElementById('rpicknumall')) {
7856: rpick = document.getElementById('rpicknumall').value;
7857: }
7858: }
7859: }
7860: } else {
7861: if (document.getElementById(param+'all').checked) {
7862: setcheck = 1;
7863: }
7864: }
7865: var allidxlist;
7866: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7867: if (document.getElementById('all'+param+'idx')) {
7868: allidxlist = document.getElementById('all'+param+'idx').value;
7869: }
7870: var actions = new Array ('remove','cut','copy');
7871: for (var i=0; i<actions.length; i++) {
7872: if (actions[i] != param) {
7873: if (document.getElementById(actions[i]+'all')) {
7874: document.getElementById(actions[i]+'all').checked = false;
7875: }
7876: }
7877: }
7878: }
7879: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
7880: allidxlist = form.allidx.value;
7881: }
7882: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7883: allidxlist = form.allmapidx.value;
7884: }
7885: if ((allidxlist != '') && (allidxlist != null)) {
7886: var allidxs = allidxlist.split(',');
7887: if (allidxs.length > 1) {
7888: for (var i=0; i<allidxs.length; i++) {
7889: if (document.getElementById(param+'_'+allidxs[i])) {
7890: if (param == 'rpicknum') {
7891: if (document.getElementById('randompick_'+allidxs[i])) {
7892: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7893: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7894: if (rpick > 0) {
7895: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7896: } else {
7897: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7898: }
7899: }
7900: }
7901: } else {
7902: if (setcheck == 1) {
7903: document.getElementById(param+'_'+allidxs[i]).checked = true;
7904: } else {
7905: document.getElementById(param+'_'+allidxs[i]).checked = false;
7906: if (param == 'randompick') {
7907: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7908: }
7909: }
7910: }
7911: }
7912: }
7913: if (setcheck == 1) {
7914: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7915: var actions = new Array('copy','cut','remove');
7916: for (var i=0; i<actions.length; i++) {
7917: var otheractions;
7918: var otheridxs;
7919: if (actions[i] === param) {
7920: continue;
7921: } else {
7922: if (document.getElementById('all'+actions[i]+'idx')) {
7923: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7924: otheridxs = otheractions.split(',');
7925: if (otheridxs.length > 1) {
7926: for (var j=0; j<otheridxs.length; j++) {
7927: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7928: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7929: }
7930: }
7931: }
7932: }
7933: }
7934: }
7935: }
7936: }
7937: }
7938: }
7939: }
7940: return;
7941: }
7942:
7943: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
7944: var canedit = '$canedit';
7945: if (canedit == '') {
7946: alert("$js_lt{'edri'}");
7947: return;
7948: }
7949: var dosettings;
7950: var doaction;
7951: var control = document.togglemultsettings;
7952: if (context == 'actions') {
7953: control = document.togglemultactions;
7954: doaction = 1;
7955: } else {
7956: dosettings = 1;
7957: }
7958: if (control) {
7959: if (control.showmultpick.length) {
7960: for (var i=0; i<control.showmultpick.length; i++) {
7961: if (control.showmultpick[i].checked) {
7962: if (control.showmultpick[i].value == 1) {
7963: if (context == 'settings') {
7964: dosettings = 0;
7965: } else {
7966: doaction = 0;
7967: }
7968: }
7969: }
7970: }
7971: }
7972: }
7973: if (context == 'settings') {
7974: if (dosettings == 1) {
7975: targetform.changeparms.value=param;
7976: targetform.submit();
7977: }
7978: }
7979: if (context == 'actions') {
7980: if (doaction == 1) {
7981: targetform.cmd.value=param+'_'+index;
7982: targetform.folderpath.value=folderpath;
7983: targetform.markcopy.value=idx+':'+param;
7984: targetform.copyfolder.value=folder+'.'+container;
7985: if (param == 'remove') {
7986: var doremove = 0;
7987: if (skip_confirm) {
7988: if (confirm_removal) {
7989: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7990: doremove = 1;
7991: }
7992: } else {
7993: doremove = 1;
7994: }
7995: } else {
7996: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7997: doremove = 1;
7998: }
7999: }
8000: if (doremove) {
8001: targetform.markcopy.value='';
8002: targetform.copyfolder.value='';
8003: targetform.submit();
8004: }
8005: }
8006: if (param == 'cut') {
8007: if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) {
8008: targetform.submit();
8009: return;
8010: }
8011: }
8012: if (param == 'copy') {
8013: targetform.submit();
8014: return;
8015: }
8016: targetform.markcopy.value='';
8017: targetform.copyfolder.value='';
8018: targetform.cmd.value='';
8019: targetform.folderpath.value='';
8020: return;
8021: } else {
8022: if (document.getElementById(param+'_'+idx)) {
8023: item = document.getElementById(param+'_'+idx);
8024: if (item.type == 'checkbox') {
8025: if (item.checked) {
8026: item.checked = false;
8027: } else {
8028: item.checked = true;
8029: singleCheck(item,idx,param);
8030: }
8031: }
8032: }
8033: }
8034: }
8035: return;
8036: }
8037:
8038: function singleCheck(caller,idx,action) {
8039: actions = new Array('cut','copy','remove');
8040: if (caller.checked) {
8041: for (var i=0; i<actions.length; i++) {
8042: if (actions[i] != action) {
8043: if (document.getElementById(actions[i]+'_'+idx)) {
8044: if (document.getElementById(actions[i]+'_'+idx).checked) {
8045: document.getElementById(actions[i]+'_'+idx).checked = false;
8046: }
8047: }
8048: }
8049: }
8050: }
8051: return;
8052: }
8053:
8054: function unselectInactive(nav) {
8055: currentNav = document.getElementById(nav);
8056: currentLis = currentNav.getElementsByTagName('LI');
8057: for (i = 0; i < currentLis.length; i++) {
8058: if (currentLis[i].className == 'goback') {
8059: currentLis[i].className = 'goback';
8060: } else {
8061: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
8062: currentLis[i].className = 'right';
8063: } else {
8064: currentLis[i].className = 'i';
8065: }
8066: }
8067: }
8068: }
8069:
8070: function hideAll(current, nav, data) {
8071: unselectInactive(nav);
8072: if (current) {
8073: if (current.className == 'right'){
8074: current.className = 'right active'
8075: } else {
8076: current.className = 'active';
8077: }
8078: }
8079: currentData = document.getElementById(data);
8080: currentDivs = currentData.getElementsByTagName('DIV');
8081: for (i = 0; i < currentDivs.length; i++) {
8082: if(currentDivs[i].className == 'LC_ContentBox'){
8083: currentDivs[i].style.display = 'none';
8084: }
8085: }
8086: }
8087:
8088: function openTabs(pageId) {
8089: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
8090: if(tabnav.length > 2 ){
8091: currentNav = document.getElementById(tabnav[1].id);
8092: currentLis = currentNav.getElementsByTagName('LI');
8093: for(i = 0; i< currentLis.length; i++){
8094: if(currentLis[i].className == 'active') {
8095: funcString = currentLis[i].onclick.toString();
8096: tab = funcString.split('"');
8097: if(tab.length < 2) {
8098: tab = funcString.split("'");
8099: }
8100: currentData = document.getElementById(tab[1]);
8101: currentData.style.display = 'block';
8102: }
8103: }
8104: }
8105: }
8106:
8107: function showPage(current, pageId, nav, data) {
8108: currstate = current.className;
8109: hideAll(current, nav, data);
8110: openTabs(pageId);
8111: unselectInactive(nav);
8112: if ((currstate == 'active') || (currstate == 'right active')) {
8113: if (currstate == 'active') {
8114: current.className = '';
8115: } else {
8116: current.className = 'right';
8117: }
8118: activeTab = '';
8119: toggleUpload();
8120: toggleMap();
8121: toggleCrsRes();
8122: toggleImportCrsres();
8123: resize_scrollbox('contentscroll','1','0');
8124: return;
8125: } else {
8126: current.className = 'active';
8127: }
8128: currentData = document.getElementById(pageId);
8129: currentData.style.display = 'block';
8130: activeTab = pageId;
8131: toggleUpload();
8132: toggleMap();
8133: toggleCrsRes();
8134: toggleImportCrsres();
8135: if (nav == 'mainnav') {
8136: var storedpath = "$docs_folderpath";
8137: var storedpage = "$main_container_page";
8138: var reg = new RegExp("^supplemental");
8139: if (pageId == 'mainCourseDocuments') {
8140: if (storedpage == 1) {
8141: document.simpleedit.folderpath.value = '';
8142: document.uploaddocument.folderpath.value = '';
8143: } else {
8144: if (reg.test(storedpath)) {
8145: document.simpleedit.folderpath.value = '$toplevelmain';
8146: document.uploaddocument.folderpath.value = '$toplevelmain';
8147: document.newext.folderpath.value = '$toplevelmain';
8148: } else {
8149: document.simpleedit.folderpath.value = storedpath;
8150: document.uploaddocument.folderpath.value = storedpath;
8151: document.newext.folderpath.value = storedpath;
8152: }
8153: }
8154: } else {
8155: if (reg.test(storedpath)) {
8156: document.simpleedit.folderpath.value = storedpath;
8157: document.supuploaddocument.folderpath.value = storedpath;
8158: document.supnewext.folderpath.value = storedpath;
8159: } else {
8160: document.simpleedit.folderpath.value = '$toplevelsupp';
8161: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8162: document.supnewext.folderpath.value = '$toplevelsupp';
8163: }
8164: }
8165: }
8166: resize_scrollbox('contentscroll','1','0');
8167: return false;
8168: }
8169:
8170: function toContents(jumpto) {
8171: var newurl = '$backtourl';
8172: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
8173: newurl = newurl+'?postdata='+jumpto;
8174: }
8175: location.href=newurl;
8176: }
8177:
8178: function togglePick(caller,value) {
8179: var disp = 'none';
8180: if (document.getElementById('multi'+caller)) {
8181: var curr = document.getElementById('multi'+caller).style.display;
8182: if (value == 1) {
8183: disp='block';
8184: }
8185: if (curr == disp) {
8186: return;
8187: }
8188: document.getElementById('multi'+caller).style.display=disp;
8189: if (value == 1) {
8190: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
8191: } else {
8192: document.getElementById('more'+caller).innerHTML = '';
8193: }
8194: if (caller == 'actions') {
8195: setClass(value);
8196: setBoxes(value);
8197: }
8198: }
8199: var showButton = multiSettings();
8200: if (showButton != 1) {
8201: showButton = multiActions();
8202: }
8203: if (document.getElementById('multisave')) {
8204: if (showButton == 1) {
8205: document.getElementById('multisave').style.display='block';
8206: } else {
8207: document.getElementById('multisave').style.display='none';
8208: }
8209: }
8210: resize_scrollbox('contentscroll','1','1');
8211: return;
8212: }
8213:
8214: function toggleCheckUncheck(caller,more) {
8215: if (more == 1) {
8216: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
8217: document.getElementById('allfields'+caller).style.display='block';
8218: } else {
8219: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
8220: document.getElementById('allfields'+caller).style.display='none';
8221: }
8222: resize_scrollbox('contentscroll','1','1');
8223: }
8224:
8225: function multiSettings() {
8226: var inuse = 0;
8227: var settingsform = document.togglemultsettings;
8228: if (settingsform.showmultpick.length > 1) {
8229: for (var i=0; i<settingsform.showmultpick.length; i++) {
8230: if (settingsform.showmultpick[i].checked) {
8231: if (settingsform.showmultpick[i].value == 1) {
8232: inuse = 1;
8233: }
8234: }
8235: }
8236: }
8237: return inuse;
8238: }
8239:
8240: function multiActions() {
8241: var inuse = 0;
8242: var actionsform = document.togglemultactions;
8243: if (actionsform.showmultpick.length > 1) {
8244: for (var i=0; i<actionsform.showmultpick.length; i++) {
8245: if (actionsform.showmultpick[i].checked) {
8246: if (actionsform.showmultpick[i].value == 1) {
8247: inuse = 1;
8248: }
8249: }
8250: }
8251: }
8252: return inuse;
8253: }
8254:
8255: function checkSubmits() {
8256: var numchanges = 0;
8257: var form = document.saveactions;
8258: var doactions = multiActions();
8259: var cutwarnings = 0;
8260: var remwarnings = 0;
8261: var removalinfo = 0;
8262: if (doactions == 1) {
8263: var remidxlist = document.cumulativeactions.allremoveidx.value;
8264: if ((remidxlist != '') && (remidxlist != null)) {
8265: var remidxs = remidxlist.split(',');
8266: for (var i=0; i<remidxs.length; i++) {
8267: if (document.getElementById('remove_'+remidxs[i])) {
8268: if (document.getElementById('remove_'+remidxs[i]).checked) {
8269: form.multiremove.value += remidxs[i]+',';
8270: numchanges ++;
8271: if (document.getElementById('skip_remove_'+remidxs[i])) {
8272: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8273: remwarnings ++;
8274: }
8275: }
8276: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8277: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8278: removalinfo ++;
8279: }
8280: }
8281: }
8282: }
8283: }
8284: }
8285: var cutidxlist = document.cumulativeactions.allcutidx.value;
8286: if ((cutidxlist != '') && (cutidxlist != null)) {
8287: var cutidxs = cutidxlist.split(',');
8288: for (var i=0; i<cutidxs.length; i++) {
8289: if (document.getElementById('cut_'+cutidxs[i])) {
8290: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8291: form.multicut.value += cutidxs[i]+',';
8292: numchanges ++;
8293: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8294: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8295: cutwarnings ++;
8296: }
8297: }
8298: }
8299: }
8300: }
8301: }
8302: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8303: if ((copyidxlist != '') && (copyidxlist != null)) {
8304: var copyidxs = copyidxlist.split(',');
8305: for (var i=0; i<copyidxs.length; i++) {
8306: if (document.getElementById('copy_'+copyidxs[i])) {
8307: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8308: form.multicopy.value += copyidxs[i]+',';
8309: numchanges ++;
8310: }
8311: }
8312: }
8313: }
8314: if (numchanges > 0) {
8315: form.multichange.value = numchanges;
8316: }
8317: }
8318: var dosettings = multiSettings();
8319: var haschanges = 0;
8320: if (dosettings == 1) {
8321: form.allencrypturl.value = '';
8322: form.allhiddenresource.value = '';
8323: form.changeparms.value = 'all';
8324: var patt=new RegExp(",\$");
8325: var allidxlist = document.cumulativesettings.allidx.value;
8326: if ((allidxlist != '') && (allidxlist != null)) {
8327: var allidxs = allidxlist.split(',');
8328: if (allidxs.length > 1) {
8329: for (var i=0; i<allidxs.length; i++) {
8330: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8331: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8332: form.allhiddenresource.value += allidxs[i]+',';
8333: }
8334: }
8335: if (document.getElementById('encrypturl_'+allidxs[i])) {
8336: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8337: form.allencrypturl.value += allidxs[i]+',';
8338: }
8339: }
8340: }
8341: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8342: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
8343: }
8344: }
8345: form.allrandompick.value = '';
8346: form.allrandomorder.value = '';
8347: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8348: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8349: var allmapidxs = allmapidxlist.split(',');
8350: for (var i=0; i<allmapidxs.length; i++) {
8351: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8352: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8353: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8354: if ((randompick.checked) && (rpicknum.value != '')) {
8355: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8356: }
8357: if (randorder.checked) {
8358: form.allrandomorder.value += allmapidxs[i]+',';
8359: }
8360: }
8361: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8362: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8363: }
8364: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8365: haschanges = 1;
8366: }
8367: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8368: haschanges = 1;
8369: }
8370: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8371: haschanges = 1;
8372: }
8373: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8374: haschanges = 1;
8375: }
8376: }
8377: if (doactions == 1) {
8378: if (numchanges > 0) {
8379: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
8380: if (remwarnings > 0) {
8381: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
8382: return false;
8383: }
8384: }
8385: if (removalinfo > 0) {
8386: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8387: return false;
8388: }
8389: }
8390: if (cutwarnings > 0) {
8391: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
8392: return false;
8393: }
8394: }
8395: }
8396: form.submit();
8397: return true;
8398: }
8399: }
8400: if (dosettings == 1) {
8401: if (haschanges == 1) {
8402: form.submit();
8403: return true;
8404: }
8405: }
8406: if ((dosettings == 1) && (doactions == 1)) {
8407: alert("$js_lt{'noor'}");
8408: } else {
8409: if (dosettings == 1) {
8410: alert("$js_lt{'noch'}");
8411: } else {
8412: alert("$js_lt{'noac'}");
8413: }
8414: }
8415: return false;
8416: }
8417:
8418: function setClass(value) {
8419: var cutclass = 'LC_docs_cut';
8420: var copyclass = 'LC_docs_copy';
8421: var removeclass = 'LC_docs_remove';
8422: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8423: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8424: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8425: var links = document.getElementsByTagName('a');
8426: for (var i=0; i<links.length; i++) {
8427: var classes = links[i].className;
8428: if (cutreg.test(classes)) {
8429: links[i].className = cutclass;
8430: if (value == 1) {
8431: links[i].className += " LC_menubuttons_link";
8432: }
8433: } else {
8434: if (copyreg.test(classes)) {
8435: links[i].className = copyclass;
8436: if (value == 1) {
8437: links[i].className += " LC_menubuttons_link";
8438: }
8439: } else {
8440: if (removereg.test(classes)) {
8441: links[i].className = removeclass;
8442: if (value == 1) {
8443: links[i].className += " LC_menubuttons_link";
8444: }
8445: }
8446: }
8447: }
8448: }
8449: return;
8450: }
8451:
8452: function setBoxes(value) {
8453: var remidxlist = document.cumulativeactions.allremoveidx.value;
8454: if ((remidxlist != '') && (remidxlist != null)) {
8455: var remidxs = remidxlist.split(',');
8456: for (var i=0; i<remidxs.length; i++) {
8457: if (document.getElementById('remove_'+remidxs[i])) {
8458: var item = document.getElementById('remove_'+remidxs[i]);
8459: if (value == 1) {
8460: item.className = 'LC_docs_remove';
8461: } else {
8462: item.className = 'LC_hidden';
8463: }
8464: }
8465: }
8466: }
8467: var cutidxlist = document.cumulativeactions.allcutidx.value;
8468: if ((cutidxlist != '') && (cutidxlist != null)) {
8469: var cutidxs = cutidxlist.split(',');
8470: for (var i=0; i<cutidxs.length; i++) {
8471: if (document.getElementById('cut_'+cutidxs[i])) {
8472: var item = document.getElementById('cut_'+cutidxs[i]);
8473: if (value == 1) {
8474: item.className = 'LC_docs_cut';
8475: } else {
8476: item.className = 'LC_hidden';
8477: }
8478: }
8479: }
8480: }
8481: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8482: if ((copyidxlist != '') && (copyidxlist != null)) {
8483: var copyidxs = copyidxlist.split(',');
8484: for (var i=0; i<copyidxs.length; i++) {
8485: if (document.getElementById('copy_'+copyidxs[i])) {
8486: var item = document.getElementById('copy_'+copyidxs[i]);
8487: if (value == 1) {
8488: item.className = 'LC_docs_copy';
8489: } else {
8490: item.className = 'LC_hidden';
8491: }
8492: }
8493: }
8494: }
8495: return;
8496: }
8497:
8498: function validImportCrsRes() {
8499: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8500: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8501: if ((fname == '') || (fname == null)) {
8502: alert("$js_lt{'nofi'}");
8503: return false;
8504: }
8505: var url = '/res/$coursedom/$coursenum/';
8506: if (path && path != '/') {
8507: url += path+'/';
8508: }
8509: if (fname != '') {
8510: url += fname;
8511: }
8512: var title = document.crsresimportform.crsrestitle.value;
8513: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8514: return true;
8515: }
8516:
8517: function validateNewRes(caller) {
8518: if (caller == 'single') {
8519: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8520: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8521: var resname = document.courseresform.newresourcename.value;
8522: }
8523: }
8524:
8525: ENDSCRIPT
8526: }
8527:
8528: sub history_tab_js {
8529: return <<"ENDHIST";
8530: function toggleHistoryDisp(choice) {
8531: document.docslogform.docslog.value = choice;
8532: document.docslogform.submit();
8533: return;
8534: }
8535:
8536: ENDHIST
8537: }
8538:
8539: sub inject_data_js {
8540: return <<ENDINJECT;
8541:
8542: function injectData(current, hiddenField, name, value) {
8543: currentElement = document.getElementById(hiddenField);
8544: currentElement.name = name;
8545: currentElement.value = value;
8546: current.submit();
8547: }
8548:
8549: ENDINJECT
8550: }
8551:
8552: sub dump_switchserver_js {
8553: my @hosts = @_;
8554: my %js_lt = &Apache::lonlocal::texthash(
8555: dump => 'Copying content to Authoring Space requires switching server.',
8556: swit => 'Switch server?',
8557: );
8558: my %html_js_lt = &Apache::lonlocal::texthash(
8559: swit => 'Switch server?',
8560: duco => 'Copying Content to Authoring Space',
8561: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8562: chos => 'Choose server',
8563: );
8564: &js_escape(\%js_lt);
8565: &html_escape(\%html_js_lt);
8566: &js_escape(\%html_js_lt);
8567: my $role = $env{'request.role'};
8568: my $js = <<"ENDSWJS";
8569: <script type="text/javascript">
8570: function write_switchserver() {
8571: var server;
8572: if (document.setserver.posshosts.length > 0) {
8573: for (var i=0; i<document.setserver.posshosts.length; i++) {
8574: if (document.setserver.posshosts[i].checked) {
8575: server = document.setserver.posshosts[i].value;
8576: }
8577: }
8578: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8579: }
8580: window.close();
8581: }
8582: </script>
8583:
8584: ENDSWJS
8585:
8586: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8587: {'only_body' => 1,
8588: 'js_ready' => 1,});
8589: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8590:
8591: my $hostpicker;
8592: my $count = 0;
8593: foreach my $host (sort(@hosts)) {
8594: my $checked;
8595: if ($count == 0) {
8596: $checked = ' checked="checked"';
8597: }
8598: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8599: $host.'"'.$checked.' />'.$host.'</label> ';
8600: $count++;
8601: }
8602:
8603: return <<"ENDSWITCHJS";
8604:
8605: function dump_needs_switchserver(url) {
8606: if (url!='' && url!= null) {
8607: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
8608: go(url);
8609: }
8610: }
8611: return;
8612: }
8613:
8614: function choose_switchserver_window() {
8615: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8616: newWindow.document.open();
8617: newWindow.document.writeln('$startpage');
8618: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8619: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8620: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
8621: '<form name="setserver" method="post" action="" \\/>\\n'+
8622: '$hostpicker\\n'+
8623: '<br \\/><br \\/>\\n'+
8624: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
8625: 'onclick="write_switchserver();" \\/>\\n'+
8626: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8627: newWindow.document.writeln('$endpage');
8628: newWindow.document.close();
8629: newWindow.focus();
8630: }
8631:
8632: ENDSWITCHJS
8633: }
8634:
8635: sub makedocslogform {
8636: my ($formelems,$docslog) = @_;
8637: return <<"LOGSFORM";
8638: <form action="/adm/coursedocs" method="post" name="docslogform">
8639: <input type="hidden" name="docslog" value="$docslog" />
8640: $formelems
8641: </form>
8642: LOGSFORM
8643: }
8644:
8645: sub makesimpleeditform {
8646: my ($formelems) = @_;
8647: return <<"SIMPFORM";
8648: <form name="simpleedit" method="post" action="/adm/coursedocs">
8649: <input type="hidden" name="importdetail" value="" />
8650: $formelems
8651: </form>
8652: SIMPFORM
8653: }
8654:
8655: sub makenewproblem {
8656: my ($r,$coursedom,$coursenum) = @_;
8657: # Creating a new problem
8658: my ($redirect,$error);
8659: if ($env{'form.authorrole'}) {
8660: my ($newsubdir,$filename);
8661: if ($env{'form.newsubdir'}) {
8662: if ($env{'form.newsubdirname'} ne '') {
8663: $newsubdir = $env{'form.newsubdirname'};
8664: }
8665: }
8666: if ($env{'form.newresourcename'}) {
8667: $filename = $env{'form.newresourcename'};
8668: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8669: $filename =~ s/`//g;
8670: $filename =~ s{/\.\./}{_}g;
8671: $filename =~ s/\.+/./g;
8672: $filename =~ s{/+}{_}g;
8673: if ($filename ne '') {
8674: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8675: if (($ext) && ($ext ne '.problem')) {
8676: $filename = $name.'.problem';
8677: } elsif ($ext eq '') {
8678: $filename .= '.problem';
8679: }
8680: my $docroot = $r->dir_config('lonDocRoot');
8681: my @ids=&Apache::lonnet::current_machine_ids();
8682: if ($env{'form.authorrole'} eq 'author') {
8683: if ($env{'user.author'}) {
8684: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8685: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8686: my $path = $docroot.$url;
8687: my $subdir = $env{'form.authorpath'};
8688: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8689: }
8690: }
8691: } elsif ($env{'form.authorrole'} eq 'course') {
8692: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8693: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8694: my $url = "/priv/$coursedom/$coursenum";
8695: my $path=$docroot.$url;
8696: my $subdir = $env{'form.authorpath'};
8697: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8698: if ($redirect) {
8699: my $rightsfile = 'default.rights';
8700: my $sourcerights = "$path/$rightsfile";
8701: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8702: my $now = time;
8703: if (!-e $sourcerights) {
8704: my $cid = $coursedom.'_'.$coursenum;
8705: if (open(my $fh,">$sourcerights")) {
8706: print $fh <<END;
8707: <accessrule effect="deny" realm="" type="course" role="" />
8708: <accessrule effect="allow" realm="$cid" type="course" role="" />
8709: END
8710: close($fh);
8711: }
8712: }
8713: if (!-e "$sourcerights.meta") {
8714: if (open(my $fh,">$sourcerights.meta")) {
8715: my $author=$env{'environment.firstname'}.' '.
8716: $env{'environment.middlename'}.' '.
8717: $env{'environment.lastname'}.' '.
8718: $env{'environment.generation'};
8719: $author =~ s/\s+$//;
8720: print $fh <<"END";
8721:
8722: <abstract></abstract>
8723: <author>$author</author>
8724: <authorspace>$coursenum:$coursedom</authorspace>
8725: <copyright>private</copyright>
8726: <creationdate>$now</creationdate>
8727: <customdistributionfile></customdistributionfile>
8728: <dependencies></dependencies>
8729: <domain>$coursedom</domain>
8730: <highestgradelevel>0</highestgradelevel>
8731: <keywords></keywords>
8732: <language>notset </language>
8733: <lastrevisiondate>$now</lastrevisiondate>
8734: <lowestgradelevel>0</lowestgradelevel>
8735: <mime>rights</mime>
8736: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8737: <notes></notes>
8738: <obsolete></obsolete>
8739: <obsoletereplacement></obsoletereplacement>
8740: <owner>$coursenum:$coursedom</owner>
8741: <rule>deny:::course,allow:$cid::course</rule>
8742: <sourceavail></sourceavail>
8743: <standards></standards>
8744: <subject></subject>
8745: <title></title>
8746: END
8747: close($fh);
8748: }
8749: }
8750: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8751: if (!-e "$docroot/res/$coursedom") {
8752: mkdir("$docroot/res/$coursedom",0755);
8753: }
8754: if (!-e "$docroot/res/$coursedom/$coursenum") {
8755: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8756: }
8757: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8758: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8759: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8760: }
8761: }
8762: my $source = $docroot.$redirect;
8763: if (!-e "$source.meta") {
8764: my $cid = $coursedom.'_'.$coursenum;
8765: my $now = time;
8766: if (open(my $fh,">$source.meta")) {
8767: my $author=$env{'environment.firstname'}.' '.
8768: $env{'environment.middlename'}.' '.
8769: $env{'environment.lastname'}.' '.
8770: $env{'environment.generation'};
8771: $author =~ s/\s+$//;
8772: my $title = $env{'form.newresourcetitle'};
8773: $title =~ s/^\s+|\s+$//g;
8774: print $fh <<END;
8775:
8776: <abstract></abstract>
8777: <author>$author</author>
8778: <authorspace>$coursenum:$coursedom</authorspace>
8779: <copyright>custom</copyright>
8780: <creationdate>$now</creationdate>
8781: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8782: <dependencies></dependencies>
8783: <domain>$coursedom</domain>
8784: <highestgradelevel>0</highestgradelevel>
8785: <keywords></keywords>
8786: <language>notset </language>
8787: <lastrevisiondate>$now</lastrevisiondate>
8788: <lowestgradelevel>0</lowestgradelevel>
8789: <mime>problem</mime>
8790: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8791: <notes></notes>
8792: <obsolete></obsolete>
8793: <obsoletereplacement></obsoletereplacement>
8794: <owner>$coursenum:$coursedom</owner>
8795: <sourceavail></sourceavail>
8796: <standards></standards>
8797: <subject></subject>
8798: <title>$title</title>
8799: END
8800: close($fh);
8801: }
8802: }
8803: }
8804: }
8805: } else {
8806: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8807: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8808: if (grep(/^\Q$rolehome\E$/,@ids)) {
8809: my $now = time;
8810: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8811: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8812: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8813: my $url = "/priv/$audom/$auname";
8814: my $path = $r->dir_config('lonDocRoot').$url;
8815: my $subdir = $env{'form.authorpath'};
8816: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8817: }
8818: }
8819: }
8820: }
8821: }
8822: }
8823: }
8824: return ($redirect,$error);
8825: }
8826:
8827: sub finishnewprob {
8828: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
8829: unless (-d $path) {
8830: unless (mkdir($path,02770)) {
8831: return;
8832: }
8833: }
8834: my $redirect;
8835: if ($subdir ne '/') {
8836: $subdir = &cleandir($subdir);
8837: if (($subdir ne '') && (-d "$path/$subdir")) {
8838: $path .= "/$subdir";
8839: $url .= "/$subdir";
8840: }
8841: }
8842: my $dest;
8843: if ($newsubdir ne '') {
8844: $newsubdir = &cleandir($newsubdir);
8845: }
8846: if ($newsubdir ne '') {
8847: if (-d "$path/$newsubdir") {
8848: $dest = "$path/$newsubdir/$filename";
8849: } else {
8850: my $dirok;
8851: unless (-e "$path/$newsubdir") {
8852: if (mkdir("$path/$newsubdir",02770)) {
8853: if (chmod(02770,"$path/$newsubdir")) {
8854: $dirok = 1;
8855: }
8856: }
8857: }
8858: if ($dirok) {
8859: $dest = "$path/$newsubdir/$filename";
8860: }
8861: }
8862: if (($dest ne '') && (!-e $dest)) {
8863: $redirect = "$url/$newsubdir/$filename";
8864: }
8865: } else {
8866: $dest = "$path/$filename";
8867: if (($dest ne '') && (!-e $dest)) {
8868: $redirect = "$url/$filename";
8869: }
8870: }
8871: if ((!-e $dest) && ($context ne 'upload')) {
8872: my $template = $env{'form.template'};
8873: my $copyfrom;
8874: if ($template ne '') {
8875: my %templates;
8876: my @files = &Apache::lonhomework::get_template_list('problem');
8877: foreach my $poss (@files) {
8878: if (ref($poss) eq 'ARRAY') {
8879: if ($template eq $poss->[0]) {
8880: $templates{$template} = 1;
8881: last;
8882: }
8883: }
8884: }
8885: if ($templates{$template}) {
8886: $copyfrom = $template;
8887: }
8888: }
8889: if ($filename =~ /\.problem$/) {
8890: unless ($copyfrom) {
8891: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
8892: }
8893: &File::Copy::copy($copyfrom,$dest);
8894: }
8895: }
8896: return $redirect;
8897: }
8898:
8899: sub cleandir {
8900: my ($dir) = @_;
8901: $dir =~ s/^\s+//;
8902: $dir =~ s/\s+$//;
8903: $dir =~ s/\.+//g;
8904: $dir =~ s/[\#\?&%\":]//g;
8905: return $dir;
8906: }
8907:
8908: 1;
8909: __END__
8910:
8911:
8912: =head1 NAME
8913:
8914: Apache::londocs.pm
8915:
8916: =head1 SYNOPSIS
8917:
8918: This is part of the LearningOnline Network with CAPA project
8919: described at http://www.lon-capa.org.
8920:
8921: =head1 SUBROUTINES
8922:
8923: =over
8924:
8925: =item %help=()
8926:
8927: Available help topics
8928:
8929: =item mapread()
8930:
8931: Mapread read maps into LONCAPA::map:: global arrays
8932: @order and @resources, determines status
8933: sets @order - pointer to resources in right order
8934: sets @resources - array with the resources with correct idx
8935:
8936: =item authorhosts()
8937:
8938: Return hash with valid author names
8939:
8940: =item clean()
8941:
8942: =item dumpcourse()
8943:
8944: Actually dump course
8945:
8946: =item group_import()
8947:
8948: Imports the given (name, url) resources into the course
8949: coursenum, coursedom, and folder must precede the list
8950:
8951: =item breadcrumbs()
8952:
8953: =item log_docs()
8954:
8955: =item docs_change_log()
8956:
8957: =item update_paste_buffer()
8958:
8959: =item print_paste_buffer()
8960:
8961: =item do_paste_from_buffer()
8962:
8963: =item do_buffer_empty()
8964:
8965: =item clear_from_buffer()
8966:
8967: =item get_newmap_url()
8968:
8969: =item dbcopy()
8970:
8971: =item uniqueness_check()
8972:
8973: =item contained_map_check()
8974:
8975: =item url_paste_fixups()
8976:
8977: =item apply_fixups()
8978:
8979: =item copy_dependencies()
8980:
8981: =item update_parameter()
8982:
8983: =item handle_edit_cmd()
8984:
8985: =item editor()
8986:
8987: =item process_file_upload()
8988:
8989: =item process_secondary_uploads()
8990:
8991: =item is_supplemental_title()
8992:
8993: =item entryline()
8994:
8995: =item tiehash()
8996:
8997: =item untiehash()
8998:
8999: =item checkonthis()
9000:
9001: check on this
9002:
9003: =item verifycontent()
9004:
9005: Verify Content
9006:
9007: =item devalidateversioncache()
9008:
9009: =item checkversions()
9010:
9011: Check Versions
9012:
9013: =item mark_hash_old()
9014:
9015: =item is_hash_old()
9016:
9017: =item changewarning()
9018:
9019: =item init_breadcrumbs()
9020:
9021: Breadcrumbs for special functions
9022:
9023: =item create_list_elements()
9024:
9025: =item create_form_ul()
9026:
9027: =item startContentScreen()
9028:
9029: =item endContentScreen()
9030:
9031: =item supplemental_base()
9032:
9033: =item embedded_form_elems()
9034:
9035: =item embedded_destination()
9036:
9037: =item return_to_editor()
9038:
9039: =item decompression_info()
9040:
9041: =item decompression_phase_one()
9042:
9043: =item decompression_phase_two()
9044:
9045: =item remove_archive()
9046:
9047: =item generate_admin_menu()
9048:
9049: =item generate_edit_table()
9050:
9051: =item editing_js()
9052:
9053: =item history_tab_js()
9054:
9055: =item inject_data_js()
9056:
9057: =item dump_switchserver_js()
9058:
9059: =item resize_scrollbox_js()
9060:
9061: =item makedocslogform()
9062:
9063: =item makesimpleeditform()
9064:
9065: =back
9066:
9067: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>