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