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