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