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