File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.571:
download - view:
text,
annotated -
select for diffs
Wed Dec 18 18:56:41 2013 UTC (10 years, 8 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Fix documentation links on Course Utilities menu in Course Editor
- Supply appropriate help link on right side of breadcrumbs container
when using Course Utilities
- Only display table (and headers) for Check Resource Versions screen if
there are imported published resources with version changes in specified
time frame.
- Sort resources in Check Resource Versions screen in date order (items
most recently changed listed first).
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.571 2013/12/18 18:56:41 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 Resource Versions"));
4037: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource 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: ENDHEADERS
4194: #number of columns for version history
4195: my %changedbytime;
4196: foreach my $key (keys(%changes)) {
4197: #excludes not versionable problems from resource version history:
4198: next if ($key =~ /^\/res\/lib\/templates/);
4199: my $chg;
4200: if ($env{'form.timerange'} eq 'all') {
4201: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4202: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4203: } else {
4204: $chg = $changes{$key};
4205: next if ($chg < $starttime);
4206: }
4207: push(@{$changedbytime{$chg}},$key);
4208: }
4209: if (keys(%changedbytime) == 0) {
4210: &untiehash();
4211: $r->print(&mt('No content changes in imported content in specified time frame').
4212: &endContentScreen());
4213: return;
4214: }
4215: $r->print(
4216: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />'.
4217: &Apache::loncommon::start_data_table().
4218: &Apache::loncommon::start_data_table_header_row().
4219: '<th>'.&mt('Resources').'</th>'.
4220: "<th>$lt{'mr'}</th>".
4221: "<th>$lt{'ve'}</th>".
4222: "<th>$lt{'vu'}</th>".
4223: '<th>'.&mt('History').'</th>'.
4224: &Apache::loncommon::end_data_table_header_row()
4225: );
4226: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4227: foreach my $key (sort(@{$changedbytime{$chg}})) {
4228: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4229: my $currentversion=&Apache::lonnet::getversion($key);
4230: if ($currentversion<0) {
4231: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4232: }
4233: my $linkurl=&Apache::lonnet::clutter($key);
4234: $r->print(
4235: &Apache::loncommon::start_data_table_row().
4236: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4237: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4238: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4239: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4240: '<td align="right">'
4241: );
4242: # Used in course
4243: my $usedversion=$hash{'version_'.$linkurl};
4244: if (($usedversion) && ($usedversion ne 'mostrecent')) {
4245: if ($usedversion != $currentversion) {
4246: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
4247: } else {
4248: $r->print($usedversion);
4249: }
4250: } else {
4251: $r->print($currentversion);
4252: }
4253: $r->print('</td><td title="'.$lt{'vu'}.'">');
4254: # Set version
4255: $r->print(&Apache::loncommon::select_form(
4256: $setversions{$linkurl},
4257: 'set_version_'.$linkurl,
4258: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4259: '' => '',
4260: 'mostrecent' => &mt('most recent'),
4261: map {$_,$_} (1..$currentversion)}));
4262: my $lastold=1;
4263: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4264: my $url=$root.'.'.$prevvers.'.'.$extension;
4265: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4266: $lastold=$prevvers;
4267: }
4268: }
4269: $r->print('</td>');
4270: # List all available versions
4271: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4272: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4273: my $url=$root.'.'.$prevvers.'.'.$extension;
4274: $r->print(
4275: '<span class="LC_nobreak">'
4276: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4277: .&mt('Version [_1]',$prevvers).'</a>'
4278: .' ('.&Apache::lonlocal::locallocaltime(
4279: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4280: .')');
4281: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4282: $r->print(
4283: ' <a href="/adm/diff?filename='.
4284: &Apache::lonnet::clutter($root.'.'.$extension).
4285: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4286: '" target="diffs">'.&mt('Diffs').'</a>');
4287: }
4288: $r->print('</span><br />');
4289: }
4290: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
4291: }
4292: }
4293: $r->print(
4294: &Apache::loncommon::end_data_table().
4295: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />'.
4296: '</form>'
4297: );
4298:
4299: &untiehash();
4300: $r->print(&endContentScreen());
4301: return;
4302: }
4303:
4304: sub mark_hash_old {
4305: my $retie_hash=0;
4306: if ($hashtied) {
4307: $retie_hash=1;
4308: &untiehash();
4309: }
4310: &tiehash('write');
4311: $hash{'old'}=1;
4312: &untiehash();
4313: if ($retie_hash) { &tiehash(); }
4314: }
4315:
4316: sub is_hash_old {
4317: my $untie_hash=0;
4318: if (!$hashtied) {
4319: $untie_hash=1;
4320: &tiehash();
4321: }
4322: my $return=$hash{'old'};
4323: if ($untie_hash) { &untiehash(); }
4324: return $return;
4325: }
4326:
4327: sub changewarning {
4328: my ($r,$postexec,$message,$url)=@_;
4329: if (!&is_hash_old()) { return; }
4330: my $pathvar='folderpath';
4331: my $path=&escape($env{'form.folderpath'});
4332: if (!defined($url)) {
4333: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4334: }
4335: my $course_type = &Apache::loncommon::course_type();
4336: if (!defined($message)) {
4337: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4338: }
4339: $r->print("\n\n".
4340: '<script type="text/javascript">'."\n".
4341: '// <![CDATA['."\n".
4342: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4343: '// ]]>'."\n".
4344: '</script>'."\n".
4345: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
4346: '<input type="hidden" name="orgurl" value="'.$url.
4347: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
4348: &mt($message,' <input type="hidden" name="'.
4349: $env{'request.role'}.'" value="1" /><input type="button" value="'.
4350: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
4351: $help{'Caching'}.'</p></form>'."\n\n");
4352: }
4353:
4354:
4355: sub init_breadcrumbs {
4356: my ($form,$text,$help)=@_;
4357: &Apache::lonhtmlcommon::clear_breadcrumbs();
4358: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
4359: text=>&Apache::loncommon::course_type().' Editor',
4360: faq=>273,
4361: bug=>'Instructor Interface',
4362: help => $help});
4363: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4364: text=>$text,
4365: faq=>273,
4366: bug=>'Instructor Interface'});
4367: }
4368:
4369: # subroutine to list form elements
4370: sub create_list_elements {
4371: my @formarr = @_;
4372: my $list = '';
4373: foreach my $button (@formarr){
4374: foreach my $picture (keys(%{$button})) {
4375: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
4376: }
4377: }
4378: return $list;
4379: }
4380:
4381: # subroutine to create ul from list elements
4382: sub create_form_ul {
4383: my $list = shift;
4384: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4385: return $ul;
4386: }
4387:
4388: #
4389: # Start tabs
4390: #
4391:
4392: sub startContentScreen {
4393: my ($mode) = @_;
4394: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
4395: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
4396: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4397: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4398: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
4399: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4400: } else {
4401: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n";
4402: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4403: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4404: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4405: }
4406: $output .= "\n".'</ul>'."\n";
4407: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4408: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4409: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4410: return $output;
4411: }
4412:
4413: #
4414: # End tabs
4415: #
4416:
4417: sub endContentScreen {
4418: return '</div></div></div>';
4419: }
4420:
4421: sub supplemental_base {
4422: return 'supplemental&'.&escape(&mt('Supplemental Content'));
4423: }
4424:
4425: sub handler {
4426: my $r = shift;
4427: &Apache::loncommon::content_type($r,'text/html');
4428: $r->send_http_header;
4429: return OK if $r->header_only;
4430:
4431: # get course data
4432: my $crstype = &Apache::loncommon::course_type();
4433: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4434: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4435:
4436: # graphics settings
4437: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
4438:
4439: #
4440: # --------------------------------------------- Initialize help topics for this
4441: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4442: 'Adding_External_Resource','Navigate_Content',
4443: 'Adding_Folders','Docs_Overview', 'Load_Map',
4444: 'Supplemental','Score_Upload_Form','Adding_Pages',
4445: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
4446: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
4447: 'Dropbox') {
4448: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4449: }
4450: # Composite help files
4451: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4452: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4453: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4454: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4455: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
4456: 'Option_Response_Simple');
4457: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4458: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
4459: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
4460: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
4461: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
4462: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
4463:
4464: my $allowed;
4465: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4466: unless ($r->uri eq '/adm/supplemental') {
4467: # does this user have privileges to modify content.
4468: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
4469: }
4470:
4471: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
4472: 'inhibitmenu']);
4473: if ($allowed && $env{'form.chooseserver'}) {
4474: &choose_dump_server($r);
4475: return OK;
4476: } elsif ($allowed && $env{'form.verify'}) {
4477: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
4478: &verifycontent($r);
4479: } elsif ($allowed && $env{'form.listsymbs'}) {
4480: &init_breadcrumbs('listsymbs','List Content IDs');
4481: &list_symbs($r);
4482: } elsif ($allowed && $env{'form.docslog'}) {
4483: &init_breadcrumbs('docslog','Show Log');
4484: my $folder = $env{'form.folder'};
4485: if ($folder eq '') {
4486: $folder='default';
4487: }
4488: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
4489: } elsif ($allowed && $env{'form.versions'}) {
4490: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
4491: &checkversions($r);
4492: } elsif ($allowed && $env{'form.dumpcourse'}) {
4493: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
4494: &dumpcourse($r);
4495: } elsif ($allowed && $env{'form.exportcourse'}) {
4496: &init_breadcrumbs('exportcourse','IMS Export');
4497: &Apache::imsexport::exportcourse($r);
4498: } else {
4499: #
4500: # Done catching special calls
4501: # The whole rest is for course and supplemental documents and utilities menu
4502: # Get the parameters that may be needed
4503: #
4504: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4505: ['folderpath',
4506: 'forcesupplement','forcestandard',
4507: 'tools','symb','command','supppath']);
4508:
4509: # standard=1: this is a "new-style" course with an uploaded map as top level
4510: # standard=2: this is a "old-style" course, and there is nothing we can do
4511:
4512: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
4513:
4514: # Decide whether this should display supplemental or main content or utilities
4515: # supplementalflag=1: show supplemental documents
4516: # supplementalflag=0: show standard documents
4517: # toolsflag=1: show utilities
4518:
4519: my $unesc_folderpath = &unescape($env{'form.folderpath'});
4520: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
4521: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
4522: $supplementalflag=0;
4523: }
4524: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
4525: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
4526: unless ($allowed) { $supplementalflag=1; }
4527: unless ($standard) { $supplementalflag=1; }
4528: my $toolsflag=0;
4529: if ($env{'form.tools'}) { $toolsflag=1; }
4530:
4531: my $script='';
4532: my $showdoc=0;
4533: my $addentries = {};
4534: my $container;
4535: my $containertag;
4536: my $pathitem;
4537:
4538: # Do we directly jump somewhere?
4539:
4540: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
4541: if ($env{'form.symb'} ne '') {
4542: $env{'form.folderpath'}=
4543: &Apache::loncommon::symb_to_docspath($env{'form.symb'});
4544: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
4545: $env{'form.command'}.'_'.$env{'form.symb'}});
4546: } elsif ($env{'form.supppath'} ne '') {
4547: $env{'form.folderpath'}=$env{'form.supppath'};
4548: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
4549: $env{'form.command'}.'_'.$env{'form.supppath'}});
4550: }
4551: } elsif ($env{'form.command'} eq 'editdocs') {
4552: $env{'form.folderpath'} = 'default&'.
4553: &escape(&mt('Main Content').':::::');
4554: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
4555: } elsif ($env{'form.command'} eq 'editsupp') {
4556: $env{'form.folderpath'} = 'supplemental&'.
4557: &escape('Supplemental Content');
4558: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
4559: } elsif ($env{'form.command'} eq 'contents') {
4560: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
4561: } elsif ($env{'form.command'} eq 'home') {
4562: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
4563: }
4564:
4565:
4566: # Where do we store these for when we come back?
4567: my $stored_folderpath='docs_folderpath';
4568: if ($supplementalflag) {
4569: $stored_folderpath='docs_sup_folderpath';
4570: }
4571:
4572: # No folderpath, and in edit mode, see if we have something stored
4573: if ((!$env{'form.folderpath'}) && $allowed) {
4574: &Apache::loncommon::restore_course_settings($stored_folderpath,
4575: {'folderpath' => 'scalar'});
4576: unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
4577: undef($env{'form.folderpath'});
4578: }
4579: }
4580:
4581: # If we are not allowed to make changes, all we can see are supplemental docs
4582: if (!$allowed) {
4583: unless ($env{'form.folderpath'} =~ /^supplemental/) {
4584: $env{'form.folderpath'} = &supplemental_base();
4585: }
4586: }
4587: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
4588: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
4589: $env{'form.folderpath'} = &supplemental_base()
4590: .'&'.
4591: $env{'form.folderpath'};
4592: }
4593: # If after all of this, we still don't have any paths, make them
4594: unless ($env{'form.folderpath'}) {
4595: if ($supplementalflag) {
4596: $env{'form.folderpath'}=&supplemental_base();
4597: } else {
4598: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content').
4599: ':::::');
4600: }
4601: }
4602:
4603: # Store this
4604: unless ($toolsflag) {
4605: if ($allowed) {
4606: &Apache::loncommon::store_course_settings($stored_folderpath,
4607: {'folderpath' => 'scalar'});
4608: }
4609: my $folderpath;
4610: if ($env{'form.folderpath'}) {
4611: $folderpath = $env{'form.folderpath'};
4612: my (@folders)=split('&',$env{'form.folderpath'});
4613: $env{'form.foldername'}=&unescape(pop(@folders));
4614: if ($env{'form.foldername'} =~ /\:1$/) {
4615: $container = 'page';
4616: } else {
4617: $container = 'sequence';
4618: }
4619: $env{'form.folder'}=pop(@folders);
4620: } else {
4621: if ($env{'form.folder'} eq '' ||
4622: $env{'form.folder'} eq 'supplemental') {
4623: $folderpath='default&'.
4624: &escape(&mt('Main Content').':::::');
4625: }
4626: }
4627: $containertag = '<input type="hidden" name="folderpath" value="" />';
4628: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
4629: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
4630: $showdoc='/'.$1;
4631: }
4632: if ($showdoc) { # got called in sequence from course
4633: $allowed=0;
4634: } else {
4635: if ($allowed) {
4636: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
4637: $script=&Apache::lonratedt::editscript('simple');
4638: }
4639: }
4640: }
4641:
4642: # get personal data
4643: my $uname=$env{'user.name'};
4644: my $udom=$env{'user.domain'};
4645: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
4646:
4647: if ($allowed) {
4648: if ($toolsflag) {
4649: $script .= &inject_data_js();
4650: my ($home,$other,%outhash)=&authorhosts();
4651: if (!$home && $other) {
4652: my @hosts;
4653: foreach my $aurole (keys(%outhash)) {
4654: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
4655: push(@hosts,$outhash{$aurole});
4656: }
4657: }
4658: $script .= &dump_switchserver_js(@hosts);
4659: }
4660: } else {
4661: my $tid = 1;
4662: my @tabids;
4663: if ($supplementalflag) {
4664: @tabids = ('002','ee2','ff2');
4665: $tid = 2;
4666: } else {
4667: @tabids = ('aa1','bb1','cc1','ff1');
4668: unless ($env{'form.folderpath'} =~ /\:1$/) {
4669: unshift(@tabids,'001');
4670: push(@tabids,('dd1','ee1'));
4671: }
4672: }
4673: my $tabidstr = join("','",@tabids);
4674: $script .= &editing_js($udom,$uname,$supplementalflag).
4675: &history_tab_js().
4676: &inject_data_js().
4677: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
4678: &Apache::lonextresedit::extedit_javascript();
4679: $addentries = {
4680: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
4681: };
4682: }
4683: $script .= &paste_popup_js();
4684: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
4685: &mt('Switch server?');
4686:
4687:
4688: }
4689: # -------------------------------------------------------------------- Body tag
4690: $script = '<script type="text/javascript">'."\n"
4691: .'// <![CDATA['."\n"
4692: .$script."\n"
4693: .'// ]]>'."\n"
4694: .'</script>'."\n";
4695:
4696: # Breadcrumbs
4697: &Apache::lonhtmlcommon::clear_breadcrumbs();
4698:
4699: if ($showdoc) {
4700: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
4701: {'force_register' => $showdoc,}));
4702: } elsif ($toolsflag) {
4703: &Apache::lonhtmlcommon::add_breadcrumb({
4704: href=>"/adm/coursedocs",text=>"$crstype Contents"});
4705: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
4706: .&Apache::loncommon::help_open_menu('','',273,'RAT')
4707: .&Apache::lonhtmlcommon::breadcrumbs(
4708: 'Editing Course Contents')
4709: );
4710: } elsif ($r->uri eq '/adm/supplemental') {
4711: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
4712: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
4713: {'bread_crumbs' => $brcrum,}));
4714: } else {
4715: &Apache::lonhtmlcommon::add_breadcrumb({
4716: href=>"/adm/coursedocs",text=>"$crstype Contents"});
4717: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
4718: {'add_entries' => $addentries}
4719: )
4720: .&Apache::loncommon::help_open_menu('','',273,'RAT')
4721: .&Apache::lonhtmlcommon::breadcrumbs(
4722: 'Editing '.$crstype.' Contents',
4723: 'Docs_Adding_Course_Doc')
4724: );
4725: }
4726:
4727: my %allfiles = ();
4728: my %codebase = ();
4729: my ($upload_result,$upload_output,$uploadphase);
4730: if ($allowed) {
4731: if (($env{'form.uploaddoc.filename'}) &&
4732: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
4733: my $context = $1;
4734: # Process file upload - phase one - upload and parse primary file.
4735: undef($hadchanges);
4736: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
4737: \%allfiles,\%codebase,$context,$crstype);
4738: if ($hadchanges) {
4739: &mark_hash_old();
4740: }
4741: $r->print($upload_output);
4742: } elsif ($env{'form.phase'} eq 'upload_embedded') {
4743: # Process file upload - phase two - upload embedded objects
4744: $uploadphase = 'check_embedded';
4745: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
4746: my $state = &embedded_form_elems($uploadphase,$primaryurl,
4747: $env{'form.newidx'});
4748: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4749: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4750: my ($destination,$dir_root) = &embedded_destination();
4751: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
4752: my $actionurl = '/adm/coursedocs';
4753: my ($result,$flag) =
4754: &Apache::loncommon::upload_embedded('coursedoc',$destination,
4755: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
4756: $actionurl);
4757: $r->print($result.&return_to_editor());
4758: } elsif ($env{'form.phase'} eq 'check_embedded') {
4759: # Process file upload - phase three - modify references in HTML file
4760: $uploadphase = 'modified_orightml';
4761: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4762: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4763: my ($destination,$dir_root) = &embedded_destination();
4764: my $result =
4765: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
4766: $docuname,$docudom,undef,
4767: $dir_root);
4768: $r->print($result.&return_to_editor());
4769: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
4770: $uploadphase = 'decompress_phase_one';
4771: $r->print(&decompression_phase_one().
4772: &return_to_editor());
4773: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
4774: $uploadphase = 'decompress_phase_two';
4775: $r->print(&decompression_phase_two().
4776: &return_to_editor());
4777: }
4778: }
4779:
4780: if ($allowed && $toolsflag) {
4781: $r->print(&startContentScreen('tools'));
4782: $r->print(&generate_admin_menu($crstype));
4783: $r->print(&endContentScreen());
4784: } elsif ((!$showdoc) && (!$uploadphase)) {
4785: # -----------------------------------------------------------------------------
4786: my %lt=&Apache::lonlocal::texthash(
4787: 'copm' => 'All documents out of a published map into this folder',
4788: 'upfi' => 'Upload File',
4789: 'upld' => 'Upload Content',
4790: 'srch' => 'Search',
4791: 'impo' => 'Import',
4792: 'lnks' => 'Import from Stored Links',
4793: 'impm' => 'Import from Assembled Map',
4794: 'selm' => 'Select Map',
4795: 'load' => 'Load Map',
4796: 'newf' => 'New Folder',
4797: 'newp' => 'New Composite Page',
4798: 'syll' => 'Syllabus',
4799: 'navc' => 'Table of Contents',
4800: 'sipa' => 'Simple Course Page',
4801: 'sipr' => 'Simple Problem',
4802: 'webp' => 'Blank Web Page (editable)',
4803: 'drbx' => 'Drop Box',
4804: 'scuf' => 'External Scores (handgrade, upload, clicker)',
4805: 'bull' => 'Discussion Board',
4806: 'mypi' => 'My Personal Information Page',
4807: 'grpo' => 'Group Portfolio',
4808: 'rost' => 'Course Roster',
4809: 'abou' => 'Personal Information Page for a User',
4810: 'imsf' => 'IMS Upload',
4811: 'imsl' => 'Upload IMS package',
4812: 'cms' => 'Origin of IMS package',
4813: 'se' => 'Select',
4814: 'file' => 'File',
4815: 'title' => 'Title',
4816: 'comment' => 'Comment',
4817: 'parse' => 'Upload embedded images/multimedia files if HTML file',
4818: );
4819: # -----------------------------------------------------------------------------
4820: my $fileupload=(<<FIUP);
4821: $lt{'file'}:<br />
4822: <input type="file" name="uploaddoc" size="40" />
4823: FIUP
4824:
4825: my $checkbox=(<<CHBO);
4826: <!-- <label>$lt{'parse'}?
4827: <input type="checkbox" name="parserflag" />
4828: </label> -->
4829: <label>
4830: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
4831: </label>
4832: CHBO
4833: my $imsfolder = $env{'form.folder'};
4834: if ($imsfolder eq '') {
4835: $imsfolder = 'default';
4836: }
4837: my $imspform=(<<IMSFORM);
4838: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
4839: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
4840: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
4841: <fieldset id="uploadimsform" style="display: none;">
4842: <legend>$lt{'imsf'}</legend>
4843: $fileupload
4844: <br />
4845: <p>
4846: $lt{'cms'}:
4847: <select name="source">
4848: <option value="-1" selected="selected">$lt{'se'}</option>
4849: <option value="bb5">Blackboard 5</option>
4850: <option value="bb6">Blackboard 6</option>
4851: <option value="angel5">ANGEL 5.5</option>
4852: <option value="webctce4">WebCT 4 Campus Edition</option>
4853: </select>
4854: <input type="hidden" name="folder" value="$imsfolder" />
4855: </p>
4856: <input type="hidden" name="phase" value="one" />
4857: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" />
4858: </fieldset>
4859: </form>
4860: IMSFORM
4861:
4862: my $fileuploadform=(<<FUFORM);
4863: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
4864: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
4865: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
4866: <fieldset id="uploaddocform" style="display: none;">
4867: <legend>$lt{'upfi'}</legend>
4868: <input type="hidden" name="active" value="aa" />
4869: $fileupload
4870: <br />
4871: $lt{'title'}:<br />
4872: <input type="text" size="60" name="comment" />
4873: $pathitem
4874: <input type="hidden" name="cmd" value="upload_default" />
4875: <br />
4876: <span class="LC_nobreak" style="float:left">
4877: $checkbox
4878: </span>
4879: <br clear="all" />
4880: <input type="submit" value="$lt{'upld'}" />
4881: </fieldset>
4882: </form>
4883: FUFORM
4884:
4885: my $importpubform=(<<SEDFFORM);
4886: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
4887: $lt{'impm'}</a>$help{'Load_Map'}
4888: <form action="/adm/coursedocs" method="post" name="mapimportform">
4889: <fieldset id="importmapform" style="display: none;">
4890: <legend>$lt{'impm'}</legend>
4891: <input type="hidden" name="active" value="bb" />
4892: $lt{'copm'}<br />
4893: <span class="LC_nobreak">
4894: <input type="text" name="importmap" size="40" value=""
4895: onfocus="this.blur();openbrowser('mapimportform','importmap','sequence,page','');" />
4896: <a href="javascript:openbrowser('mapimportform','importmap','sequence,page','');">$lt{'selm'}</a></span><br />
4897: <input type="submit" name="loadmap" value="$lt{'load'}" />
4898: </fieldset>
4899: </form>
4900:
4901: SEDFFORM
4902: my @importpubforma = (
4903: { '<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>" },
4904: { '<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'}" },
4905: { '<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>" },
4906: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
4907: );
4908: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
4909: my $extresourcesform =
4910: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
4911: $help{'Adding_External_Resource'});
4912: if ($allowed) {
4913: my $folder = $env{'form.folder'};
4914: if ($folder eq '') {
4915: $folder='default';
4916: }
4917: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
4918: if ($output) {
4919: $r->print($output);
4920: }
4921: $r->print(<<HIDDENFORM);
4922: <form name="renameform" method="post" action="/adm/coursedocs">
4923: <input type="hidden" name="title" />
4924: <input type="hidden" name="cmd" />
4925: <input type="hidden" name="markcopy" />
4926: <input type="hidden" name="copyfolder" />
4927: $containertag
4928: </form>
4929:
4930: HIDDENFORM
4931: $r->print(&makesimpleeditform($pathitem)."\n".
4932: &makedocslogform($pathitem."\n".
4933: '<input type="hidden" name="folder" value="'.
4934: $env{'form.folder'}.'" />'."\n"));
4935: }
4936:
4937: # Generate the tabs
4938: my ($mode,$needs_end);
4939: if (($supplementalflag) && (!$allowed)) {
4940: my @folders = split('&',$env{'form.folderpath'});
4941: unless (@folders > 2) {
4942: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
4943: $needs_end = 1;
4944: }
4945: } else {
4946: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
4947: $needs_end = 1;
4948: }
4949:
4950: #
4951:
4952: my $savefolderpath;
4953:
4954: if ($allowed) {
4955: my $folder=$env{'form.folder'};
4956: if ($folder eq '' || $supplementalflag) {
4957: $folder='default';
4958: $savefolderpath = $env{'form.folderpath'};
4959: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
4960: $pathitem = '<input type="hidden" name="folderpath" value="'.
4961: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
4962: }
4963: my $postexec='';
4964: if ($folder eq 'default') {
4965: $r->print('<script type="text/javascript">'."\n"
4966: .'// <![CDATA['."\n"
4967: .'this.window.name="loncapaclient";'."\n"
4968: .'// ]]>'."\n"
4969: .'</script>'."\n"
4970: );
4971: } else {
4972: #$postexec='self.close();';
4973: }
4974: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
4975: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
4976: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
4977:
4978: my $newnavform=(<<NNFORM);
4979: <form action="/adm/coursedocs" method="post" name="newnav">
4980: <input type="hidden" name="active" value="ee" />
4981: $pathitem
4982: <input type="hidden" name="importdetail"
4983: value="$lt{'navc'}=/adm/navmaps" />
4984: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
4985: $help{'Navigate_Content'}
4986: </form>
4987: NNFORM
4988: my $newsmppageform=(<<NSPFORM);
4989: <form action="/adm/coursedocs" method="post" name="newsmppg">
4990: <input type="hidden" name="active" value="ee" />
4991: $pathitem
4992: <input type="hidden" name="importdetail" value="" />
4993: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
4994: $help{'Simple Page'}
4995: </form>
4996: NSPFORM
4997:
4998: my $newsmpproblemform=(<<NSPROBFORM);
4999: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
5000: <input type="hidden" name="active" value="cc" />
5001: $pathitem
5002: <input type="hidden" name="importdetail" value="" />
5003: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
5004: $help{'Simple Problem'}
5005: </form>
5006:
5007: NSPROBFORM
5008:
5009: my $newdropboxform=(<<NDBFORM);
5010: <form action="/adm/coursedocs" method="post" name="newdropbox">
5011: <input type="hidden" name="active" value="cc" />
5012: $pathitem
5013: <input type="hidden" name="importdetail" value="" />
5014: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
5015: $help{'Dropbox'}
5016: </form>
5017: NDBFORM
5018:
5019: my $newexuploadform=(<<NEXUFORM);
5020: <form action="/adm/coursedocs" method="post" name="newexamupload">
5021: <input type="hidden" name="active" value="cc" />
5022: $pathitem
5023: <input type="hidden" name="importdetail" value="" />
5024: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
5025: $help{'Score_Upload_Form'}
5026: </form>
5027: NEXUFORM
5028:
5029: my $newbulform=(<<NBFORM);
5030: <form action="/adm/coursedocs" method="post" name="newbul">
5031: <input type="hidden" name="active" value="dd" />
5032: $pathitem
5033: <input type="hidden" name="importdetail" value="" />
5034: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
5035: $help{'Bulletin Board'}
5036: </form>
5037: NBFORM
5038:
5039: my $newaboutmeform=(<<NAMFORM);
5040: <form action="/adm/coursedocs" method="post" name="newaboutme">
5041: <input type="hidden" name="active" value="dd" />
5042: $pathitem
5043: <input type="hidden" name="importdetail"
5044: value="$plainname=/adm/$udom/$uname/aboutme" />
5045: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
5046: $help{'My Personal Information Page'}
5047: </form>
5048: NAMFORM
5049:
5050: my $newaboutsomeoneform=(<<NASOFORM);
5051: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
5052: <input type="hidden" name="active" value="dd" />
5053: $pathitem
5054: <input type="hidden" name="importdetail" value="" />
5055: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
5056: </form>
5057: NASOFORM
5058:
5059: my $newrosterform=(<<NROSTFORM);
5060: <form action="/adm/coursedocs" method="post" name="newroster">
5061: <input type="hidden" name="active" value="dd" />
5062: $pathitem
5063: <input type="hidden" name="importdetail"
5064: value="$lt{'rost'}=/adm/viewclasslist" />
5065: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
5066: $help{'Course_Roster'}
5067: </form>
5068: NROSTFORM
5069:
5070: my $newwebpage;
5071: if ($folder =~ /^default_?(\d*)$/) {
5072: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5073: if ($1) {
5074: $newwebpage .= $1;
5075: } else {
5076: $newwebpage .= 'default';
5077: }
5078: $newwebpage .= '/new.html';
5079: }
5080: my $newwebpageform =(<<NWEBFORM);
5081: <form action="/adm/coursedocs" method="post" name="newwebpage">
5082: <input type="hidden" name="active" value="ee" />
5083: $pathitem
5084: <input type="hidden" name="importdetail" value="$newwebpage" />
5085: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
5086: $help{'Web_Page'}
5087: </form>
5088: NWEBFORM
5089:
5090:
5091: my $specialdocumentsform;
5092: my @specialdocumentsforma;
5093: my $gradingform;
5094: my @gradingforma;
5095: my $communityform;
5096: my @communityforma;
5097: my $newfolderform;
5098: my $newfolderb;
5099:
5100: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5101:
5102: my $newpageform=(<<NPFORM);
5103: <form action="/adm/coursedocs" method="post" name="newpage">
5104: <input type="hidden" name="folderpath" value="$path" />
5105: <input type="hidden" name="importdetail" value="" />
5106: <input type="hidden" name="active" value="ee" />
5107: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
5108: $help{'Adding_Pages'}
5109: </form>
5110: NPFORM
5111:
5112:
5113: $newfolderform=(<<NFFORM);
5114: <form action="/adm/coursedocs" method="post" name="newfolder">
5115: $pathitem
5116: <input type="hidden" name="importdetail" value="" />
5117: <input type="hidden" name="active" value="" />
5118: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
5119: </form>
5120: NFFORM
5121:
5122: my $newsylform=(<<NSYLFORM);
5123: <form action="/adm/coursedocs" method="post" name="newsyl">
5124: <input type="hidden" name="active" value="ee" />
5125: $pathitem
5126: <input type="hidden" name="importdetail"
5127: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
5128: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
5129: $help{'Syllabus'}
5130:
5131: </form>
5132: NSYLFORM
5133:
5134: my $newgroupfileform=(<<NGFFORM);
5135: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
5136: <input type="hidden" name="active" value="dd" />
5137: $pathitem
5138: <input type="hidden" name="importdetail"
5139: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
5140: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
5141: $help{'Group Portfolio'}
5142: </form>
5143: NGFFORM
5144: @specialdocumentsforma=(
5145: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
5146: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
5147: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
5148: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
5149: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
5150: );
5151: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5152:
5153:
5154: my @importdoc = (
5155: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5156: );
5157: unless ($container eq 'page') {
5158: push(@importdoc,
5159: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5160: );
5161: }
5162: push(@importdoc,
5163: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
5164: );
5165: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
5166:
5167: @gradingforma=(
5168: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5169: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5170: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5171:
5172: );
5173: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5174:
5175: @communityforma=(
5176: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5177: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5178: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
5179: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
5180: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
5181: );
5182: $communityform = &create_form_ul(&create_list_elements(@communityforma));
5183:
5184: my %orderhash = (
5185: 'aa' => ['Upload',$fileuploadform],
5186: 'bb' => ['Import',$importpubform],
5187: 'cc' => ['Grading',$gradingform],
5188: );
5189: unless ($container eq 'page') {
5190: $orderhash{'00'} = ['Newfolder',$newfolderform];
5191: $orderhash{'dd'} = ['Collaboration',$communityform];
5192: $orderhash{'ee'} = ['Other',$specialdocumentsform];
5193: }
5194:
5195: $hadchanges=0;
5196: unless (($supplementalflag || $toolsflag)) {
5197: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
5198: $supplementalflag,\%orderhash,$iconpath,$pathitem);
5199: if ($error) {
5200: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5201: }
5202: if ($hadchanges) {
5203: &mark_hash_old();
5204: }
5205:
5206: &changewarning($r,'');
5207: }
5208: }
5209:
5210: # Supplemental documents start here
5211:
5212: my $folder=$env{'form.folder'};
5213: unless ($supplementalflag) {
5214: $folder='supplemental';
5215: }
5216: if ($folder =~ /^supplemental$/ &&
5217: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
5218: $env{'form.folderpath'} = &supplemental_base();
5219: } elsif ($allowed) {
5220: $env{'form.folderpath'} = $savefolderpath;
5221: }
5222: $pathitem = '<input type="hidden" name="folderpath" value="'.
5223: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5224: if ($allowed) {
5225: my $folderseq=
5226: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
5227:
5228: my $supupdocform=(<<SUPDOCFORM);
5229: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5230: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5231: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
5232: <fieldset id="uploadsuppdocform" style="display: none;">
5233: <legend>$lt{'upfi'}</legend>
5234: <input type="hidden" name="active" value="ee" />
5235: $fileupload
5236: <br />
5237: <br />
5238: <span class="LC_nobreak">
5239: $checkbox
5240: </span>
5241: <br /><br />
5242: $lt{'comment'}:<br />
5243: <textarea cols="50" rows="4" name="comment"></textarea>
5244: <br />
5245: $pathitem
5246: <input type="hidden" name="cmd" value="upload_supplemental" />
5247: <input type='submit' value="$lt{'upld'}" />
5248: </form>
5249: SUPDOCFORM
5250:
5251: my $supnewfolderform=(<<SNFFORM);
5252: <form action="/adm/coursedocs" method="post" name="supnewfolder">
5253: <input type="hidden" name="active" value="" />
5254: $pathitem
5255: <input type="hidden" name="importdetail" value="" />
5256: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
5257: $help{'Adding_Folders'}
5258: </form>
5259: SNFFORM
5260:
5261: my $supextform =
5262: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
5263: $help{'Adding_External_Resource'});
5264:
5265: my $supnewsylform=(<<SNSFORM);
5266: <form action="/adm/coursedocs" method="post" name="supnewsyl">
5267: <input type="hidden" name="active" value="ff" />
5268: $pathitem
5269: <input type="hidden" name="importdetail"
5270: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
5271: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
5272: $help{'Syllabus'}
5273: </form>
5274: SNSFORM
5275:
5276: my $supnewaboutmeform=(<<SNAMFORM);
5277: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
5278: <input type="hidden" name="active" value="ff" />
5279: $pathitem
5280: <input type="hidden" name="importdetail"
5281: value="$plainname=/adm/$udom/$uname/aboutme" />
5282: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
5283: $help{'My Personal Information Page'}
5284: </form>
5285: SNAMFORM
5286:
5287: my $supwebpage;
5288: if ($folder =~ /^supplemental_?(\d*)$/) {
5289: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
5290: if ($1) {
5291: $supwebpage .= $1;
5292: } else {
5293: $supwebpage .= 'default';
5294: }
5295: $supwebpage .= '/new.html';
5296: }
5297: my $supwebpageform =(<<SWEBFORM);
5298: <form action="/adm/coursedocs" method="post" name="supwebpage">
5299: <input type="hidden" name="active" value="cc" />
5300: $pathitem
5301: <input type="hidden" name="importdetail" value="$supwebpage" />
5302: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
5303: $help{'Web_Page'}
5304: </form>
5305: SWEBFORM
5306:
5307:
5308: my @specialdocs = (
5309: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
5310: =>$supnewsylform},
5311: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
5312: =>$supnewaboutmeform},
5313: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
5314:
5315: );
5316: my @supimportdoc = (
5317: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
5318: =>$supextform},
5319: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
5320: =>$supupdocform},
5321: );
5322:
5323: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
5324: my %suporderhash = (
5325: '00' => ['Supnewfolder', $supnewfolderform],
5326: 'ee' => ['Upload',$supupdocform],
5327: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
5328: );
5329: if ($supplementalflag) {
5330: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
5331: $supplementalflag,\%suporderhash,$iconpath,$pathitem);
5332: if ($error) {
5333: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5334: } else {
5335: if ($suppchanges) {
5336: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
5337: my @ids=&Apache::lonnet::current_machine_ids();
5338: foreach my $server (keys(%servers)) {
5339: next if (grep(/^\Q$server\E$/,@ids));
5340: my $hashid=$coursenum.':'.$coursedom;
5341: my $cachekey = &escape('suppcount').':'.&escape($hashid);
5342: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
5343: }
5344: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
5345: undef($suppchanges);
5346: }
5347: }
5348: }
5349: } elsif ($supplementalflag) {
5350: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
5351: $supplementalflag,'',$iconpath,$pathitem);
5352: if ($error) {
5353: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5354: }
5355: }
5356:
5357: if ($needs_end) {
5358: $r->print(&endContentScreen());
5359: }
5360:
5361: if ($allowed) {
5362: $r->print('
5363: <form method="post" name="extimport" action="/adm/coursedocs">
5364: <input type="hidden" name="title" />
5365: <input type="hidden" name="url" />
5366: <input type="hidden" name="useform" />
5367: <input type="hidden" name="residx" />
5368: </form>');
5369: }
5370: } elsif ($showdoc) {
5371: # -------------------------------------------------------- This is showdoc mode
5372: $r->print("<h1>".&mt('Uploaded Document').' - '.
5373: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
5374: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
5375: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
5376: }
5377: }
5378: $r->print(&Apache::loncommon::end_page());
5379: return OK;
5380: }
5381:
5382: sub embedded_form_elems {
5383: my ($phase,$primaryurl,$newidx) = @_;
5384: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5385: return <<STATE;
5386: <input type="hidden" name="folderpath" value="$folderpath" />
5387: <input type="hidden" name="cmd" value="upload_embedded" />
5388: <input type="hidden" name="newidx" value="$newidx" />
5389: <input type="hidden" name="phase" value="$phase" />
5390: <input type="hidden" name="primaryurl" value="$primaryurl" />
5391: STATE
5392: }
5393:
5394: sub embedded_destination {
5395: my $folder=$env{'form.folder'};
5396: my $destination = 'docs/';
5397: if ($folder =~ /^supplemental/) {
5398: $destination = 'supplemental/';
5399: }
5400: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5401: $destination .= 'default/';
5402: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5403: $destination .= $2.'/';
5404: }
5405: $destination .= $env{'form.newidx'};
5406: my $dir_root = '/userfiles';
5407: return ($destination,$dir_root);
5408: }
5409:
5410: sub return_to_editor {
5411: my $actionurl = '/adm/coursedocs';
5412: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
5413: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
5414: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
5415: '</a></p>';
5416: }
5417:
5418: sub decompression_info {
5419: my ($destination,$dir_root) = &embedded_destination();
5420: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
5421: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5422: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5423: my $container='sequence';
5424: my ($pathitem,$hiddenelem);
5425: my @hiddens = ('newidx','comment','position','folderpath');
5426: if ($env{'form.folderpath'} =~ /\:1$/) {
5427: $container='page';
5428: }
5429: unshift(@hiddens,$pathitem);
5430: foreach my $item (@hiddens) {
5431: if ($env{'form.'.$item}) {
5432: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
5433: $env{'form.'.$item}.'" />'."\n";
5434: }
5435: }
5436: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
5437: $hiddenelem);
5438: }
5439:
5440: sub decompression_phase_one {
5441: my ($dir,$file,$warning,$error,$output);
5442: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5443: &decompression_info();
5444: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
5445: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
5446: } else {
5447: my $file = $1;
5448: $output =
5449: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
5450: $destination,$dir_root,
5451: $hiddenelem);
5452: if ($env{'form.autoextract_camtasia'}) {
5453: $output .= &remove_archive($docudom,$docuname,$container);
5454: }
5455: }
5456: if ($error) {
5457: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
5458: $error.'</p>'."\n";
5459: }
5460: if ($warning) {
5461: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
5462: }
5463: return $output;
5464: }
5465:
5466: sub decompression_phase_two {
5467: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5468: &decompression_info();
5469: my $output;
5470: if ($env{'form.archivedelete'}) {
5471: $output = &remove_archive($docudom,$docuname,$container);
5472: }
5473: $output .=
5474: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
5475: $destination,$dir_root,$hiddenelem);
5476: return $output;
5477: }
5478:
5479: sub remove_archive {
5480: my ($docudom,$docuname,$container) = @_;
5481: my $map = $env{'form.folder'}.'.'.$container;
5482: my ($output,$delwarning,$delresult,$url);
5483: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
5484: if ($fatal) {
5485: if ($container eq 'page') {
5486: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
5487: } else {
5488: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
5489: }
5490: $delwarning .= &mt('As a result the archive file has not been removed.');
5491: } else {
5492: my $currcmd = $env{'form.cmd'};
5493: my $position = $env{'form.position'};
5494: if ($position > 0) {
5495: $env{'form.cmd'} = 'remove_'.$position;
5496: my ($title,$url,@rrest) =
5497: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
5498: if (&handle_edit_cmd($docuname,$docudom)) {
5499: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
5500: if ($fatal) {
5501: if ($container eq 'page') {
5502: $delwarning = &mt('An error occurred updating the contents of the current page.');
5503: } else {
5504: $delwarning = &mt('An error occurred updating the contents of the current folder.');
5505: }
5506: } else {
5507: $delresult = &mt('Archive file removed.');
5508: }
5509: }
5510: }
5511: $env{'form.cmd'} = $currcmd;
5512: }
5513: if ($delwarning) {
5514: $output = '<p class="LC_warning">'.
5515: $delwarning.
5516: '</p>';
5517: }
5518: if ($delresult) {
5519: $output .= '<p class="LC_info">'.
5520: $delresult.
5521: '</p>';
5522: }
5523: return $output;
5524: }
5525:
5526: sub generate_admin_menu {
5527: my ($crstype) = @_;
5528: my $lc_crstype = lc($crstype);
5529: my ($home,$other,%outhash)=&authorhosts();
5530: my %lt= ( # do not translate here
5531: 'vc' => 'Verify Content',
5532: 'cv' => 'Check/Set Resource Versions',
5533: 'ls' => 'List Resource Identifiers',
5534: 'imse' => 'Export contents to IMS Archive',
5535: 'dcd' => "Copy $crstype Content to Authoring Space",
5536: );
5537: my ($candump,$dumpurl);
5538: if ($home + $other > 0) {
5539: $candump = 'F';
5540: if ($home) {
5541: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
5542: } else {
5543: my @hosts;
5544: foreach my $aurole (keys(%outhash)) {
5545: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5546: push(@hosts,$outhash{$aurole});
5547: }
5548: }
5549: if (@hosts == 1) {
5550: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
5551: '&role='.
5552: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
5553: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
5554: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
5555: } else {
5556: $dumpurl = "javascript:choose_switchserver_window()";
5557: }
5558: }
5559: }
5560: my @menu=
5561: ({ categorytitle=>'Administration',
5562: items =>[
5563: { linktext => $lt{'vc'},
5564: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
5565: permission => 'F',
5566: help => 'Docs_Verify_Content',
5567: icon => 'verify.png',
5568: linktitle => 'Verify contents can be retrieved/rendered',
5569: },
5570: { linktext => $lt{'cv'},
5571: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
5572: permission => 'F',
5573: help => 'Docs_Check_Resource_Versions',
5574: icon => 'resversion.png',
5575: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
5576: },
5577: { linktext => $lt{'ls'},
5578: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
5579: permission => 'F',
5580: #help => '',
5581: icon => 'symbs.png',
5582: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
5583: },
5584: ]
5585: },
5586: { categorytitle=>'Export',
5587: items =>[
5588: { linktext => $lt{'imse'},
5589: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
5590: permission => 'F',
5591: help => 'Docs_Export_Course_Docs',
5592: icon => 'imsexport.png',
5593: linktitle => $lt{'imse'},
5594: },
5595: { linktext => $lt{'dcd'},
5596: url => $dumpurl,
5597: permission => $candump,
5598: help => 'Docs_Dump_Course_Docs',
5599: icon => 'dump.png',
5600: linktitle => $lt{'dcd'},
5601: },
5602: ]
5603: });
5604: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
5605: '<input type="hidden" id="dummy" />'."\n".
5606: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
5607: '</form>';
5608: }
5609:
5610: sub generate_edit_table {
5611: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
5612: $need_save,$copyfolder) = @_;
5613: return unless(ref($orderhash_ref) eq 'HASH');
5614: my %orderhash = %{$orderhash_ref};
5615: my $form;
5616: my $activetab;
5617: my $active;
5618: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
5619: $activetab = $env{'form.active'};
5620: }
5621: my $backicon = $iconpath.'clickhere.gif';
5622: my $backtext = &mt('Exit Editor');
5623: $form = '<div class="LC_Box" style="margin:0;">'.
5624: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
5625: '<li class="goback">'.
5626: '<a href="javascript:toContents('."'$jumpto'".');">'.
5627: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
5628: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
5629: '<li>'.
5630: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
5631: &mt('Undo Delete').'</a></li>'."\n";
5632: if ($env{'form.docslog'}) {
5633: $form .= '<li class="active">';
5634: } else {
5635: $form .= '<li>';
5636: }
5637: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
5638: &mt('History').'</a></li>'."\n";
5639: if ($env{'form.docslog'}) {
5640: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
5641: &mt('Edit').'</a></li>'."\n";
5642: }
5643: foreach my $name (reverse(sort(keys(%orderhash)))) {
5644: if($name ne '00'){
5645: if($activetab eq '' || $activetab ne $name){
5646: $active = '';
5647: }elsif($activetab eq $name){
5648: $active = 'class="active"';
5649: }
5650: $form .= '<li style="float:right" '.$active
5651: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
5652: } else {
5653: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
5654:
5655: }
5656: }
5657: $form .= '</ul>'."\n";
5658: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
5659:
5660: if ($to_show ne '') {
5661: my $saveform;
5662: if ($need_save) {
5663: my $button = &mt('Make changes');
5664: my $path;
5665: if ($env{'form.folderpath'}) {
5666: $path =
5667: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5668: }
5669: $saveform = <<"END";
5670: <div id="multisave" style="display:none; clear:both;" >
5671: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
5672: <input type="hidden" name="folderpath" value="$path" />
5673: <input type="hidden" name="symb" value="$env{'form.symb'}" />
5674: <input type="hidden" name="allhiddenresource" value="" />
5675: <input type="hidden" name="allencrypturl" value="" />
5676: <input type="hidden" name="allrandompick" value="" />
5677: <input type="hidden" name="allrandomorder" value="" />
5678: <input type="hidden" name="changeparms" value="" />
5679: <input type="hidden" name="multiremove" value="" />
5680: <input type="hidden" name="multicut" value="" />
5681: <input type="hidden" name="multicopy" value="" />
5682: <input type="hidden" name="multichange" value="" />
5683: <input type="hidden" name="copyfolder" value="$copyfolder" />
5684: <input type="submit" name="savemultiples" value="$button" />
5685: </form>
5686: </div>
5687: END
5688: }
5689: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
5690: }
5691: foreach my $field (keys(%orderhash)){
5692: if($field ne '00'){
5693: if($activetab eq '' || $activetab ne $field){
5694: $active = 'style="display: none;float:left"';
5695: }elsif($activetab eq $field){
5696: $active = 'style="display:block;float:left"';
5697: }
5698: $form .= '<div id="'.$field.$tid.'"'
5699: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
5700: .'</div>'."\n";
5701: }
5702: }
5703: unless ($env{'form.docslog'}) {
5704: $form .= '</div></div>'."\n";
5705: }
5706: return $form;
5707: }
5708:
5709: sub editing_js {
5710: my ($udom,$uname,$supplementalflag) = @_;
5711: my %lt = &Apache::lonlocal::texthash(
5712: p_mnf => 'Name of New Folder',
5713: t_mnf => 'New Folder',
5714: p_mnp => 'Name of New Page',
5715: t_mnp => 'New Page',
5716: p_mxu => 'Title for the External Score',
5717: p_msp => 'Name of Simple Course Page',
5718: p_msb => 'Title for the Problem',
5719: p_mdb => 'Title for the Drop Box',
5720: p_mbb => 'Title for the Discussion Board',
5721: p_mwp => 'Title for Web Page',
5722: p_mab => "Enter user:domain for User's Personal Information Page",
5723: p_mab2 => 'Personal Information Page of ',
5724: p_mab_alrt1 => 'Not a valid user:domain',
5725: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
5726: p_chn => 'New Title',
5727: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
5728: p_rmr2a => 'Remove[_99]',
5729: p_rmr2b => '?[_99]',
5730: p_rmr3a => 'Remove those [_2]',
5731: p_rmr3b => 'items?[_2]',
5732: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
5733: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
5734: p_ctr2a => 'Cut[_98]',
5735: p_ctr2b => '?[_98]',
5736: p_ctr3a => 'Cut those[_2]',
5737: p_ctr3b => 'items?[_2]',
5738: rpck => 'Enter number to pick (e.g., 3)',
5739: imsfile => 'You must choose an IMS package for import',
5740: imscms => 'You must select which Course Management System was the source of the IMS package',
5741: invurl => 'Invalid URL',
5742: titbl => 'Title is blank',
5743: more => '(More ...)',
5744: less => '(Less ...)',
5745: noor => 'No actions selected or changes to settings specified.',
5746: noch => 'No changes to settings specified.',
5747: noac => 'No actions selected.',
5748: );
5749:
5750: my $crstype = &Apache::loncommon::course_type();
5751: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
5752: my $main_container_page;
5753: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
5754: $main_container_page = 1;
5755: }
5756: my $toplevelmain =
5757: &escape(&mt('Main Content').':::::');
5758: my $toplevelsupp = &supplemental_base();
5759:
5760: my $backtourl;
5761: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
5762: my $caller = $1;
5763: if ($caller =~ /^supplemental/) {
5764: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
5765: } else {
5766: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
5767: $res = &Apache::lonnet::clutter($res);
5768: if (&Apache::lonnet::is_on_map($res)) {
5769: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($res),'<>&"').'?symb='.
5770: &HTML::Entities::encode($caller,'<>&"');
5771: } else {
5772: $backtourl = '/adm/navmaps';
5773: }
5774: }
5775: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
5776: $backtourl = '/adm/menu';
5777: } elsif ($supplementalflag) {
5778: $backtourl = '/adm/supplemental';
5779: } else {
5780: $backtourl = '/adm/navmaps';
5781: }
5782:
5783: my $fieldsets = "'ext','doc'";
5784: unless ($main_container_page) {
5785: $fieldsets .=",'ims'";
5786: }
5787: if ($supplementalflag) {
5788: $fieldsets = "'suppext','suppdoc'";
5789: }
5790:
5791: return <<ENDNEWSCRIPT;
5792: function makenewfolder(targetform,folderseq) {
5793: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
5794: if (foldername) {
5795: targetform.importdetail.value=escape(foldername)+"="+folderseq;
5796: targetform.submit();
5797: }
5798: }
5799:
5800: function makenewpage(targetform,folderseq) {
5801: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
5802: if (pagename) {
5803: targetform.importdetail.value=escape(pagename)+"="+folderseq;
5804: targetform.submit();
5805: }
5806: }
5807:
5808: function makeexamupload() {
5809: var title=prompt('$lt{"p_mxu"}');
5810: if (title) {
5811: this.document.forms.newexamupload.importdetail.value=
5812: escape(title)+'=/res/lib/templates/examupload.problem';
5813: this.document.forms.newexamupload.submit();
5814: }
5815: }
5816:
5817: function makesmppage() {
5818: var title=prompt('$lt{"p_msp"}');
5819: if (title) {
5820: this.document.forms.newsmppg.importdetail.value=
5821: escape(title)+'=/adm/$udom/$uname/new/smppg';
5822: this.document.forms.newsmppg.submit();
5823: }
5824: }
5825:
5826: function makewebpage(type) {
5827: var title=prompt('$lt{"p_mwp"}');
5828: var formname;
5829: if (type == 'supp') {
5830: formname = this.document.forms.supwebpage;
5831: } else {
5832: formname = this.document.forms.newwebpage;
5833: }
5834: if (title) {
5835: var webpage = formname.importdetail.value;
5836: formname.importdetail.value = escape(title)+'='+webpage;
5837: formname.submit();
5838: }
5839: }
5840:
5841: function makesmpproblem() {
5842: var title=prompt('$lt{"p_msb"}');
5843: if (title) {
5844: this.document.forms.newsmpproblem.importdetail.value=
5845: escape(title)+'=/res/lib/templates/simpleproblem.problem';
5846: this.document.forms.newsmpproblem.submit();
5847: }
5848: }
5849:
5850: function makedropbox() {
5851: var title=prompt('$lt{"p_mdb"}');
5852: if (title) {
5853: this.document.forms.newdropbox.importdetail.value=
5854: escape(title)+'=/res/lib/templates/DropBox.problem';
5855: this.document.forms.newdropbox.submit();
5856: }
5857: }
5858:
5859: function makebulboard() {
5860: var title=prompt('$lt{"p_mbb"}');
5861: if (title) {
5862: this.document.forms.newbul.importdetail.value=
5863: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
5864: this.document.forms.newbul.submit();
5865: }
5866: }
5867:
5868: function makeabout() {
5869: var user=prompt("$lt{'p_mab'}");
5870: if (user) {
5871: var comp=new Array();
5872: comp=user.split(':');
5873: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
5874: if ((comp[0]) && (comp[1])) {
5875: this.document.forms.newaboutsomeone.importdetail.value=
5876: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
5877: this.document.forms.newaboutsomeone.submit();
5878: } else {
5879: alert("$lt{'p_mab_alrt1'}");
5880: }
5881: } else {
5882: alert("$lt{'p_mab_alrt2'}");
5883: }
5884: }
5885: }
5886:
5887: function toggleUpload(caller) {
5888: var blocks = Array($fieldsets);
5889: for (var i=0; i<blocks.length; i++) {
5890: var disp = 'none';
5891: if (caller == blocks[i]) {
5892: var curr = document.getElementById('upload'+caller+'form').style.display;
5893: if (curr == 'none') {
5894: disp='block';
5895: }
5896: }
5897: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
5898: }
5899: resize_scrollbox('contentscroll','1','1');
5900: return;
5901: }
5902:
5903: function toggleMap(caller) {
5904: var disp = 'none';
5905: if (document.getElementById('importmapform')) {
5906: if (caller == 'map') {
5907: var curr = document.getElementById('importmapform').style.display;
5908: if (curr == 'none') {
5909: disp='block';
5910: }
5911: }
5912: document.getElementById('importmapform').style.display=disp;
5913: resize_scrollbox('contentscroll','1','1');
5914: }
5915: return;
5916: }
5917:
5918: function makeims(imsform) {
5919: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
5920: alert("$lt{'imsfile'}");
5921: return;
5922: }
5923: if (imsform.source.selectedIndex == 0) {
5924: alert("$lt{'imscms'}");
5925: return;
5926: }
5927: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
5928: imsform.submit();
5929: }
5930:
5931: function changename(folderpath,index,oldtitle) {
5932: var title=prompt('$lt{"p_chn"}',oldtitle);
5933: if (title) {
5934: this.document.forms.renameform.markcopy.value='';
5935: this.document.forms.renameform.title.value=title;
5936: this.document.forms.renameform.cmd.value='rename_'+index;
5937: this.document.forms.renameform.folderpath.value=folderpath;
5938: this.document.forms.renameform.submit();
5939: }
5940: }
5941:
5942: function updatePick(targetform,index,caller) {
5943: var pickitem;
5944: var picknumitem;
5945: var picknumtext;
5946: if (index == 'all') {
5947: pickitem = document.getElementById('randompickall');
5948: picknumitem = document.getElementById('rpicknumall');
5949: picknumtext = document.getElementById('rpicktextall');
5950: } else {
5951: pickitem = document.getElementById('randompick_'+index);
5952: picknumitem = document.getElementById('rpicknum_'+index);
5953: picknumtext = document.getElementById('randompicknum_'+index);
5954: }
5955: if (pickitem.checked) {
5956: var picknum=prompt('$lt{"rpck"}',picknumitem.value);
5957: if (picknum == '' || picknum == null) {
5958: if (caller == 'check') {
5959: pickitem.checked=false;
5960: if (index == 'all') {
5961: picknumtext.innerHTML = '';
5962: if (caller == 'link') {
5963: propagateState(targetform,'rpicknum');
5964: }
5965: } else {
5966: checkForSubmit(targetform,'randompick','settings');
5967: }
5968: }
5969: } else {
5970: picknum.toString();
5971: var regexdigit=/^\\d+\$/;
5972: if (regexdigit.test(picknum)) {
5973: picknumitem.value = picknum;
5974: if (index == 'all') {
5975: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
5976: if (caller == 'link') {
5977: propagateState(targetform,'rpicknum');
5978: }
5979: } else {
5980: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
5981: checkForSubmit(targetform,'randompick','settings');
5982: }
5983: } else {
5984: if (caller == 'check') {
5985: if (index == 'all') {
5986: picknumtext.innerHTML = '';
5987: if (caller == 'link') {
5988: propagateState(targetform,'rpicknum');
5989: }
5990: } else {
5991: pickitem.checked=false;
5992: checkForSubmit(targetform,'randompick','settings');
5993: }
5994: }
5995: return;
5996: }
5997: }
5998: } else {
5999: picknumitem.value = '';
6000: picknumtext.innerHTML = '';
6001: if (index == 'all') {
6002: if (caller == 'link') {
6003: propagateState(targetform,'rpicknum');
6004: }
6005: } else {
6006: checkForSubmit(targetform,'randompick','settings');
6007: }
6008: }
6009: }
6010:
6011: function propagateState(form,param) {
6012: if (document.getElementById(param+'all')) {
6013: var setcheck = 0;
6014: var rpick = 0;
6015: if (param == 'rpicknum') {
6016: if (document.getElementById('randompickall')) {
6017: if (document.getElementById('randompickall').checked) {
6018: if (document.getElementById('rpicknumall')) {
6019: rpick = document.getElementById('rpicknumall').value;
6020: }
6021: }
6022: }
6023: } else {
6024: if (document.getElementById(param+'all').checked) {
6025: setcheck = 1;
6026: }
6027: }
6028: var allidxlist;
6029: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6030: if (document.getElementById('all'+param+'idx')) {
6031: allidxlist = document.getElementById('all'+param+'idx').value;
6032: }
6033: var actions = new Array ('remove','cut','copy');
6034: for (var i=0; i<actions.length; i++) {
6035: if (actions[i] != param) {
6036: if (document.getElementById(actions[i]+'all')) {
6037: document.getElementById(actions[i]+'all').checked = false;
6038: }
6039: }
6040: }
6041: }
6042: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
6043: allidxlist = form.allidx.value;
6044: }
6045: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6046: allidxlist = form.allmapidx.value;
6047: }
6048: if ((allidxlist != '') && (allidxlist != null)) {
6049: var allidxs = allidxlist.split(',');
6050: if (allidxs.length > 1) {
6051: for (var i=0; i<allidxs.length; i++) {
6052: if (document.getElementById(param+'_'+allidxs[i])) {
6053: if (param == 'rpicknum') {
6054: if (document.getElementById('randompick_'+allidxs[i])) {
6055: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6056: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6057: if (rpick > 0) {
6058: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6059: } else {
6060: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6061: }
6062: }
6063: }
6064: } else {
6065: if (setcheck == 1) {
6066: document.getElementById(param+'_'+allidxs[i]).checked = true;
6067: } else {
6068: document.getElementById(param+'_'+allidxs[i]).checked = false;
6069: if (param == 'randompick') {
6070: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6071: }
6072: }
6073: }
6074: }
6075: }
6076: if (setcheck == 1) {
6077: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6078: var actions = new Array('copy','cut','remove');
6079: for (var i=0; i<actions.length; i++) {
6080: var otheractions;
6081: var otheridxs;
6082: if (actions[i] === param) {
6083: continue;
6084: } else {
6085: if (document.getElementById('all'+actions[i]+'idx')) {
6086: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6087: otheridxs = otheractions.split(',');
6088: if (otheridxs.length > 1) {
6089: for (var j=0; j<otheridxs.length; j++) {
6090: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
6091: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
6092: }
6093: }
6094: }
6095: }
6096: }
6097: }
6098: }
6099: }
6100: }
6101: }
6102: }
6103: return;
6104: }
6105:
6106: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder) {
6107: var dosettings;
6108: var doaction;
6109: var control = document.togglemultsettings;
6110: if (context == 'actions') {
6111: control = document.togglemultactions;
6112: doaction = 1;
6113: } else {
6114: dosettings = 1;
6115: }
6116: if (control) {
6117: if (control.showmultpick.length) {
6118: for (var i=0; i<control.showmultpick.length; i++) {
6119: if (control.showmultpick[i].checked) {
6120: if (control.showmultpick[i].value == 1) {
6121: if (context == 'settings') {
6122: dosettings = 0;
6123: } else {
6124: doaction = 0;
6125: }
6126: }
6127: }
6128: }
6129: }
6130: }
6131: if (context == 'settings') {
6132: if (dosettings == 1) {
6133: targetform.changeparms.value=param;
6134: targetform.submit();
6135: }
6136: }
6137: if (context == 'actions') {
6138: if (doaction == 1) {
6139: targetform.cmd.value=param+'_'+index;
6140: targetform.folderpath.value=folderpath;
6141: targetform.markcopy.value=idx+':'+param;
6142: targetform.copyfolder.value=folder+'.'+container;
6143: if (param == 'remove') {
6144: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
6145: targetform.markcopy.value='';
6146: targetform.copyfolder.value='';
6147: targetform.submit();
6148: }
6149: }
6150: if (param == 'cut') {
6151: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
6152: targetform.submit();
6153: return;
6154: }
6155: }
6156: if (param == 'copy') {
6157: targetform.submit();
6158: return;
6159: }
6160: targetform.markcopy.value='';
6161: targetform.copyfolder.value='';
6162: targetform.cmd.value='';
6163: targetform.folderpath.value='';
6164: return;
6165: } else {
6166: if (document.getElementById(param+'_'+idx)) {
6167: item = document.getElementById(param+'_'+idx);
6168: if (item.type == 'checkbox') {
6169: if (item.checked) {
6170: item.checked = false;
6171: } else {
6172: item.checked = true;
6173: singleCheck(item,idx,param);
6174: }
6175: }
6176: }
6177: }
6178: }
6179: return;
6180: }
6181:
6182: function singleCheck(caller,idx,action) {
6183: actions = new Array('cut','copy','remove');
6184: if (caller.checked) {
6185: for (var i=0; i<actions.length; i++) {
6186: if (actions[i] != action) {
6187: if (document.getElementById(actions[i]+'_'+idx)) {
6188: if (document.getElementById(actions[i]+'_'+idx).checked) {
6189: document.getElementById(actions[i]+'_'+idx).checked = false;
6190: }
6191: }
6192: }
6193: }
6194: }
6195: return;
6196: }
6197:
6198: function unselectInactive(nav) {
6199: currentNav = document.getElementById(nav);
6200: currentLis = currentNav.getElementsByTagName('LI');
6201: for (i = 0; i < currentLis.length; i++) {
6202: if (currentLis[i].className == 'goback') {
6203: currentLis[i].className = 'goback';
6204: } else {
6205: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
6206: currentLis[i].className = 'right';
6207: } else {
6208: currentLis[i].className = 'i';
6209: }
6210: }
6211: }
6212: }
6213:
6214: function hideAll(current, nav, data) {
6215: unselectInactive(nav);
6216: if (current) {
6217: if (current.className == 'right'){
6218: current.className = 'right active'
6219: } else {
6220: current.className = 'active';
6221: }
6222: }
6223: currentData = document.getElementById(data);
6224: currentDivs = currentData.getElementsByTagName('DIV');
6225: for (i = 0; i < currentDivs.length; i++) {
6226: if(currentDivs[i].className == 'LC_ContentBox'){
6227: currentDivs[i].style.display = 'none';
6228: }
6229: }
6230: }
6231:
6232: function openTabs(pageId) {
6233: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
6234: if(tabnav.length > 2 ){
6235: currentNav = document.getElementById(tabnav[1].id);
6236: currentLis = currentNav.getElementsByTagName('LI');
6237: for(i = 0; i< currentLis.length; i++){
6238: if(currentLis[i].className == 'active') {
6239: funcString = currentLis[i].onclick.toString();
6240: tab = funcString.split('"');
6241: if(tab.length < 2) {
6242: tab = funcString.split("'");
6243: }
6244: currentData = document.getElementById(tab[1]);
6245: currentData.style.display = 'block';
6246: }
6247: }
6248: }
6249: }
6250:
6251: function showPage(current, pageId, nav, data) {
6252: currstate = current.className;
6253: hideAll(current, nav, data);
6254: openTabs(pageId);
6255: unselectInactive(nav);
6256: if ((currstate == 'active') || (currstate == 'right active')) {
6257: if (currstate == 'active') {
6258: current.className = '';
6259: } else {
6260: current.className = 'right';
6261: }
6262: activeTab = '';
6263: toggleUpload();
6264: toggleMap();
6265: resize_scrollbox('contentscroll','1','0');
6266: return;
6267: } else {
6268: current.className = 'active';
6269: }
6270: currentData = document.getElementById(pageId);
6271: currentData.style.display = 'block';
6272: activeTab = pageId;
6273: toggleUpload();
6274: toggleMap();
6275: if (nav == 'mainnav') {
6276: var storedpath = "$docs_folderpath";
6277: var storedpage = "$main_container_page";
6278: var reg = new RegExp("^supplemental");
6279: if (pageId == 'mainCourseDocuments') {
6280: if (storedpage == 1) {
6281: document.simpleedit.folderpath.value = '';
6282: document.uploaddocument.folderpath.value = '';
6283: } else {
6284: if (reg.test(storedpath)) {
6285: document.simpleedit.folderpath.value = '$toplevelmain';
6286: document.uploaddocument.folderpath.value = '$toplevelmain';
6287: document.newext.folderpath.value = '$toplevelmain';
6288: } else {
6289: document.simpleedit.folderpath.value = storedpath;
6290: document.uploaddocument.folderpath.value = storedpath;
6291: document.newext.folderpath.value = storedpath;
6292: }
6293: }
6294: } else {
6295: if (reg.test(storedpath)) {
6296: document.simpleedit.folderpath.value = storedpath;
6297: document.supuploaddocument.folderpath.value = storedpath;
6298: document.supnewext.folderpath.value = storedpath;
6299: } else {
6300: document.simpleedit.folderpath.value = '$toplevelsupp';
6301: document.supuploaddocument.folderpath.value = '$toplevelsupp';
6302: document.supnewext.folderpath.value = '$toplevelsupp';
6303: }
6304: }
6305: }
6306: resize_scrollbox('contentscroll','1','0');
6307: return false;
6308: }
6309:
6310: function toContents(jumpto) {
6311: var newurl = '$backtourl';
6312: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
6313: newurl = newurl+'?postdata='+jumpto;
6314: }
6315: location.href=newurl;
6316: }
6317:
6318: function togglePick(caller,value) {
6319: var disp = 'none';
6320: if (document.getElementById('multi'+caller)) {
6321: var curr = document.getElementById('multi'+caller).style.display;
6322: if (value == 1) {
6323: disp='block';
6324: }
6325: if (curr == disp) {
6326: return;
6327: }
6328: document.getElementById('multi'+caller).style.display=disp;
6329: if (value == 1) {
6330: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$lt{'more'}</a>';
6331: } else {
6332: document.getElementById('more'+caller).innerHTML = '';
6333: }
6334: if (caller == 'actions') {
6335: setClass(value);
6336: setBoxes(value);
6337: }
6338: }
6339: var showButton = multiSettings();
6340: if (showButton != 1) {
6341: showButton = multiActions();
6342: }
6343: if (document.getElementById('multisave')) {
6344: if (showButton == 1) {
6345: document.getElementById('multisave').style.display='block';
6346: } else {
6347: document.getElementById('multisave').style.display='none';
6348: }
6349: }
6350: resize_scrollbox('contentscroll','1','1');
6351: return;
6352: }
6353:
6354: function toggleCheckUncheck(caller,more) {
6355: if (more == 1) {
6356: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$lt{'less'}</a>';
6357: document.getElementById('allfields'+caller).style.display='block';
6358: } else {
6359: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$lt{'more'}</a>';
6360: document.getElementById('allfields'+caller).style.display='none';
6361: }
6362: resize_scrollbox('contentscroll','1','1');
6363: }
6364:
6365: function multiSettings() {
6366: var inuse = 0;
6367: var settingsform = document.togglemultsettings;
6368: if (settingsform.showmultpick.length > 1) {
6369: for (var i=0; i<settingsform.showmultpick.length; i++) {
6370: if (settingsform.showmultpick[i].checked) {
6371: if (settingsform.showmultpick[i].value == 1) {
6372: inuse = 1;
6373: }
6374: }
6375: }
6376: }
6377: return inuse;
6378: }
6379:
6380: function multiActions() {
6381: var inuse = 0;
6382: var actionsform = document.togglemultactions;
6383: if (actionsform.showmultpick.length > 1) {
6384: for (var i=0; i<actionsform.showmultpick.length; i++) {
6385: if (actionsform.showmultpick[i].checked) {
6386: if (actionsform.showmultpick[i].value == 1) {
6387: inuse = 1;
6388: }
6389: }
6390: }
6391: }
6392: return inuse;
6393: }
6394:
6395: function checkSubmits() {
6396: var numchanges = 0;
6397: var form = document.saveactions;
6398: var doactions = multiActions();
6399: var cutwarnings = 0;
6400: var remwarnings = 0;
6401: if (doactions == 1) {
6402: var remidxlist = document.cumulativeactions.allremoveidx.value;
6403: if ((remidxlist != '') && (remidxlist != null)) {
6404: var remidxs = remidxlist.split(',');
6405: for (var i=0; i<remidxs.length; i++) {
6406: if (document.getElementById('remove_'+remidxs[i])) {
6407: if (document.getElementById('remove_'+remidxs[i]).checked) {
6408: form.multiremove.value += remidxs[i]+',';
6409: numchanges ++;
6410: if (document.getElementById('skip_remove_'+remidxs[i])) {
6411: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
6412: remwarnings ++;
6413: }
6414: }
6415: }
6416: }
6417: }
6418: }
6419: var cutidxlist = document.cumulativeactions.allcutidx.value;
6420: if ((cutidxlist != '') && (cutidxlist != null)) {
6421: var cutidxs = cutidxlist.split(',');
6422: for (var i=0; i<cutidxs.length; i++) {
6423: if (document.getElementById('cut_'+cutidxs[i])) {
6424: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
6425: form.multicut.value += cutidxs[i]+',';
6426: numchanges ++;
6427: if (document.getElementById('skip_cut_'+cutidxs[i])) {
6428: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
6429: cutwarnings ++;
6430: }
6431: }
6432: }
6433: }
6434: }
6435: }
6436: var copyidxlist = document.cumulativeactions.allcopyidx.value;
6437: if ((copyidxlist != '') && (copyidxlist != null)) {
6438: var copyidxs = copyidxlist.split(',');
6439: for (var i=0; i<copyidxs.length; i++) {
6440: if (document.getElementById('copy_'+copyidxs[i])) {
6441: if (document.getElementById('copy_'+copyidxs[i]).checked) {
6442: form.multicopy.value += copyidxs[i]+',';
6443: numchanges ++;
6444: }
6445: }
6446: }
6447: }
6448: if (numchanges > 0) {
6449: form.multichange.value = numchanges;
6450: }
6451: }
6452: var dosettings = multiSettings();
6453: var haschanges = 0;
6454: if (dosettings == 1) {
6455: form.allencrypturl.value = '';
6456: form.allhiddenresource.value = '';
6457: form.changeparms.value = 'all';
6458: var patt=new RegExp(",\$");
6459: var allidxlist = document.cumulativesettings.allidx.value;
6460: if ((allidxlist != '') && (allidxlist != null)) {
6461: var allidxs = allidxlist.split(',');
6462: if (allidxs.length > 1) {
6463: for (var i=0; i<allidxs.length; i++) {
6464: if (document.getElementById('hiddenresource_'+allidxs[i])) {
6465: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
6466: form.allhiddenresource.value += allidxs[i]+',';
6467: }
6468: }
6469: if (document.getElementById('encrypturl_'+allidxs[i])) {
6470: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
6471: form.allencrypturl.value += allidxs[i]+',';
6472: }
6473: }
6474: }
6475: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
6476: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
6477: }
6478: }
6479: form.allrandompick.value = '';
6480: form.allrandomorder.value = '';
6481: var allmapidxlist = document.cumulativesettings.allmapidx.value;
6482: if ((allmapidxlist != '') && (allmapidxlist != null)) {
6483: var allmapidxs = allmapidxlist.split(',');
6484: for (var i=0; i<allmapidxs.length; i++) {
6485: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
6486: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
6487: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
6488: if ((randompick.checked) && (rpicknum.value != '')) {
6489: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
6490: }
6491: if (randorder.checked) {
6492: form.allrandomorder.value += allmapidxs[i]+',';
6493: }
6494: }
6495: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
6496: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
6497: }
6498: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
6499: haschanges = 1;
6500: }
6501: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
6502: haschanges = 1;
6503: }
6504: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
6505: haschanges = 1;
6506: }
6507: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
6508: haschanges = 1;
6509: }
6510: }
6511: if (doactions == 1) {
6512: if (numchanges > 0) {
6513: if ((cutwarnings > 0) || (remwarnings > 0)) {
6514: if (remwarnings > 0) {
6515: if (!confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr3a"} '+remwarnings+' $lt{"p_rmr3b"}')) {
6516: return false;
6517: }
6518: }
6519: if (cutwarnings > 0) {
6520: if (!confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr3a"} '+cutwarnings+' $lt{"p_ctr3b"}')) {
6521: return false;
6522: }
6523: }
6524: }
6525: form.submit();
6526: return true;
6527: }
6528: }
6529: if (dosettings == 1) {
6530: if (haschanges == 1) {
6531: form.submit();
6532: return true;
6533: }
6534: }
6535: if ((dosettings == 1) && (doactions == 1)) {
6536: alert("$lt{'noor'}");
6537: } else {
6538: if (dosettings == 1) {
6539: alert("$lt{'noch'}");
6540: } else {
6541: alert("$lt{'noac'}");
6542: }
6543: }
6544: return false;
6545: }
6546:
6547: function setClass(value) {
6548: var cutclass = 'LC_docs_cut';
6549: var copyclass = 'LC_docs_copy';
6550: var removeclass = 'LC_docs_remove';
6551: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
6552: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
6553: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
6554: var links = document.getElementsByTagName('a');
6555: for (var i=0; i<links.length; i++) {
6556: var classes = links[i].className;
6557: if (cutreg.test(classes)) {
6558: links[i].className = cutclass;
6559: if (value == 1) {
6560: links[i].className += " LC_menubuttons_link";
6561: }
6562: } else {
6563: if (copyreg.test(classes)) {
6564: links[i].className = copyclass;
6565: if (value == 1) {
6566: links[i].className += " LC_menubuttons_link";
6567: }
6568: } else {
6569: if (removereg.test(classes)) {
6570: links[i].className = removeclass;
6571: if (value == 1) {
6572: links[i].className += " LC_menubuttons_link";
6573: }
6574: }
6575: }
6576: }
6577: }
6578: return;
6579: }
6580:
6581: function setBoxes(value) {
6582: var remidxlist = document.cumulativeactions.allremoveidx.value;
6583: if ((remidxlist != '') && (remidxlist != null)) {
6584: var remidxs = remidxlist.split(',');
6585: for (var i=0; i<remidxs.length; i++) {
6586: if (document.getElementById('remove_'+remidxs[i])) {
6587: var item = document.getElementById('remove_'+remidxs[i]);
6588: if (value == 1) {
6589: item.className = 'LC_docs_remove';
6590: } else {
6591: item.className = 'LC_hidden';
6592: }
6593: }
6594: }
6595: }
6596: var cutidxlist = document.cumulativeactions.allcutidx.value;
6597: if ((cutidxlist != '') && (cutidxlist != null)) {
6598: var cutidxs = cutidxlist.split(',');
6599: for (var i=0; i<cutidxs.length; i++) {
6600: if (document.getElementById('cut_'+cutidxs[i])) {
6601: var item = document.getElementById('cut_'+cutidxs[i]);
6602: if (value == 1) {
6603: item.className = 'LC_docs_cut';
6604: } else {
6605: item.className = 'LC_hidden';
6606: }
6607: }
6608: }
6609: }
6610: var copyidxlist = document.cumulativeactions.allcopyidx.value;
6611: if ((copyidxlist != '') && (copyidxlist != null)) {
6612: var copyidxs = copyidxlist.split(',');
6613: for (var i=0; i<copyidxs.length; i++) {
6614: if (document.getElementById('copy_'+copyidxs[i])) {
6615: var item = document.getElementById('copy_'+copyidxs[i]);
6616: if (value == 1) {
6617: item.className = 'LC_docs_copy';
6618: } else {
6619: item.className = 'LC_hidden';
6620: }
6621: }
6622: }
6623: }
6624: return;
6625: }
6626:
6627: ENDNEWSCRIPT
6628: }
6629:
6630: sub history_tab_js {
6631: return <<"ENDHIST";
6632: function toggleHistoryDisp(choice) {
6633: document.docslogform.docslog.value = choice;
6634: document.docslogform.submit();
6635: return;
6636: }
6637:
6638: ENDHIST
6639: }
6640:
6641: sub inject_data_js {
6642: return <<ENDINJECT;
6643:
6644: function injectData(current, hiddenField, name, value) {
6645: currentElement = document.getElementById(hiddenField);
6646: currentElement.name = name;
6647: currentElement.value = value;
6648: current.submit();
6649: }
6650:
6651: ENDINJECT
6652: }
6653:
6654: sub dump_switchserver_js {
6655: my @hosts = @_;
6656: my %lt = &Apache::lonlocal::texthash(
6657: dump => 'Copying Content to Authoring Space requires switching server.',
6658: swit => 'Switch server?',
6659: duco => 'Copying Content to Authoring Space',
6660: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
6661: chos => 'Choose server',
6662: );
6663: my $role = $env{'request.role'};
6664: my $js = <<"ENDSWJS";
6665: <script type="text/javascript">
6666: function write_switchserver() {
6667: var server;
6668: if (document.setserver.posshosts.length > 0) {
6669: for (var i=0; i<document.setserver.posshosts.length; i++) {
6670: if (document.setserver.posshosts[i].checked) {
6671: server = document.setserver.posshosts[i].value;
6672: }
6673: }
6674: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
6675: }
6676: window.close();
6677: }
6678: </script>
6679:
6680: ENDSWJS
6681:
6682: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
6683: {'only_body' => 1,
6684: 'js_ready' => 1,});
6685: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
6686:
6687: my $hostpicker;
6688: my $count = 0;
6689: foreach my $host (sort(@hosts)) {
6690: my $checked;
6691: if ($count == 0) {
6692: $checked = ' checked="checked"';
6693: }
6694: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
6695: $host.'"'.$checked.' />'.$host.'</label> ';
6696: $count++;
6697: }
6698:
6699: return <<"ENDSWITCHJS";
6700:
6701: function dump_needs_switchserver(url) {
6702: if (url!='' && url!= null) {
6703: if (confirm("$lt{'dump'}\\n$lt{'swit'}")) {
6704: go(url);
6705: }
6706: }
6707: return;
6708: }
6709:
6710: function choose_switchserver_window() {
6711: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
6712: newWindow.document.open();
6713: newWindow.document.writeln('$startpage');
6714: newWindow.document.write('<h3>$lt{'duco'}<\\/h3>\\n'+
6715: '<p>$lt{'yone'}<\\/p>\\n'+
6716: '<div class="LC_left_float"><fieldset><legend>$lt{'chos'}<\\/legend>\\n'+
6717: '<form name="setserver" method="post" action="" \\/>\\n'+
6718: '$hostpicker\\n'+
6719: '<br \\/><br \\/>\\n'+
6720: '<input type="button" name="makeswitch" value="$lt{'swit'}" '+
6721: 'onclick="write_switchserver();" \\/>\\n'+
6722: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
6723: newWindow.document.writeln('$endpage');
6724: newWindow.document.close();
6725: newWindow.focus();
6726: }
6727:
6728: ENDSWITCHJS
6729: }
6730:
6731: sub makedocslogform {
6732: my ($formelems,$docslog) = @_;
6733: return <<"LOGSFORM";
6734: <form action="/adm/coursedocs" method="post" name="docslogform">
6735: <input type="hidden" name="docslog" value="$docslog" />
6736: $formelems
6737: </form>
6738: LOGSFORM
6739: }
6740:
6741: sub makesimpleeditform {
6742: my ($formelems) = @_;
6743: return <<"SIMPFORM";
6744: <form name="simpleedit" method="post" action="/adm/coursedocs">
6745: <input type="hidden" name="importdetail" value="" />
6746: $formelems
6747: </form>
6748: SIMPFORM
6749: }
6750:
6751: 1;
6752: __END__
6753:
6754:
6755: =head1 NAME
6756:
6757: Apache::londocs.pm
6758:
6759: =head1 SYNOPSIS
6760:
6761: This is part of the LearningOnline Network with CAPA project
6762: described at http://www.lon-capa.org.
6763:
6764: =head1 SUBROUTINES
6765:
6766: =over
6767:
6768: =item %help=()
6769:
6770: Available help topics
6771:
6772: =item mapread()
6773:
6774: Mapread read maps into LONCAPA::map:: global arrays
6775: @order and @resources, determines status
6776: sets @order - pointer to resources in right order
6777: sets @resources - array with the resources with correct idx
6778:
6779: =item authorhosts()
6780:
6781: Return hash with valid author names
6782:
6783: =item clean()
6784:
6785: =item dumpcourse()
6786:
6787: Actually dump course
6788:
6789: =item group_import()
6790:
6791: Imports the given (name, url) resources into the course
6792: coursenum, coursedom, and folder must precede the list
6793:
6794: =item breadcrumbs()
6795:
6796: =item log_docs()
6797:
6798: =item docs_change_log()
6799:
6800: =item update_paste_buffer()
6801:
6802: =item print_paste_buffer()
6803:
6804: =item do_paste_from_buffer()
6805:
6806: =item do_buffer_empty()
6807:
6808: =item clear_from_buffer()
6809:
6810: =item get_newmap_url()
6811:
6812: =item dbcopy()
6813:
6814: =item uniqueness_check()
6815:
6816: =item contained_map_check()
6817:
6818: =item url_paste_fixups()
6819:
6820: =item apply_fixups()
6821:
6822: =item copy_dependencies()
6823:
6824: =item update_parameter()
6825:
6826: =item handle_edit_cmd()
6827:
6828: =item editor()
6829:
6830: =item process_file_upload()
6831:
6832: =item process_secondary_uploads()
6833:
6834: =item is_supplemental_title()
6835:
6836: =item entryline()
6837:
6838: =item tiehash()
6839:
6840: =item untiehash()
6841:
6842: =item checkonthis()
6843:
6844: check on this
6845:
6846: =item verifycontent()
6847:
6848: Verify Content
6849:
6850: =item devalidateversioncache() & checkversions()
6851:
6852: Check Versions
6853:
6854: =item mark_hash_old()
6855:
6856: =item is_hash_old()
6857:
6858: =item changewarning()
6859:
6860: =item init_breadcrumbs()
6861:
6862: Breadcrumbs for special functions
6863:
6864: =item create_list_elements()
6865:
6866: =item create_form_ul()
6867:
6868: =item startContentScreen()
6869:
6870: =item endContentScreen()
6871:
6872: =item supplemental_base()
6873:
6874: =item embedded_form_elems()
6875:
6876: =item embedded_destination()
6877:
6878: =item return_to_editor()
6879:
6880: =item decompression_info()
6881:
6882: =item decompression_phase_one()
6883:
6884: =item decompression_phase_two()
6885:
6886: =item remove_archive()
6887:
6888: =item generate_admin_menu()
6889:
6890: =item generate_edit_table()
6891:
6892: =item editing_js()
6893:
6894: =item history_tab_js()
6895:
6896: =item inject_data_js()
6897:
6898: =item dump_switchserver_js()
6899:
6900: =item resize_scrollbox_js()
6901:
6902: =item makedocslogform()
6903:
6904: =item makesimpleeditform()
6905:
6906: =back
6907:
6908: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>