Annotation of loncom/interface/londocs.pm, revision 1.484.2.93.2.4
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.93.2. (raeburn 4:): # $Id: londocs.pm,v 1.484.2.93.2.3 2022/09/19 19:37:46 raeburn Exp $
1.329 droeschl 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;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.484.2.19 raeburn 43: use Apache::lonextresedit();
1.484.2.43 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.484.2.93.2. (raeburn 46:): use Apache::loncourserespicker();
1.329 droeschl 47: use HTML::Entities;
1.484.2.7 raeburn 48: use HTML::TokeParser;
1.329 droeschl 49: use GDBM_File;
1.484.2.51 raeburn 50: use File::MMagic;
1.329 droeschl 51: use Apache::lonlocal;
52: use Cwd;
53: use LONCAPA qw(:DEFAULT :match);
54:
55: my $iconpath;
56:
57: my %hash;
58:
59: my $hashtied;
60: my %alreadyseen=();
61:
62: my $hadchanges;
1.484.2.37 raeburn 63: my $suppchanges;
1.329 droeschl 64:
65:
66: my %help=();
67:
68:
69: sub mapread {
70: my ($coursenum,$coursedom,$map)=@_;
71: return
72: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
73: $map);
74: }
75:
76: sub storemap {
1.484.2.7 raeburn 77: my ($coursenum,$coursedom,$map,$contentchg)=@_;
78: my $report;
79: if (($contentchg) && ($map =~ /^default/)) {
80: $report = 1;
81: }
1.329 droeschl 82: my ($outtext,$errtext)=
83: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.484.2.7 raeburn 84: $map,1,$report);
1.329 droeschl 85: if ($errtext) { return ($errtext,2); }
1.364 bisitz 86:
1.484.2.37 raeburn 87: if ($map =~ /^default/) {
88: $hadchanges=1;
89: } else {
90: $suppchanges=1;
91: }
1.329 droeschl 92: return ($errtext,0);
93: }
94:
95:
96:
97: sub authorhosts {
98: my %outhash=();
99: my $home=0;
100: my $other=0;
101: foreach my $key (keys(%env)) {
102: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
103: my $role=$1;
104: my $realm=$2;
105: my ($start,$end)=split(/\./,$env{$key});
106: if (($start) && ($start>time)) { next; }
107: if (($end) && (time>$end)) { next; }
108: my ($ca,$cd);
109: if ($1 eq 'au') {
110: $ca=$env{'user.name'};
111: $cd=$env{'user.domain'};
112: } else {
113: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
114: }
115: my $allowed=0;
116: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
117: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 118: foreach my $id (@ids) {
119: if ($id eq $myhome) {
120: $allowed=1;
121: last;
122: }
123: }
1.329 droeschl 124: if ($allowed) {
125: $home++;
1.484 raeburn 126: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 127: } else {
1.484 raeburn 128: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 129: $other++;
130: }
131: }
132: }
133: return ($home,$other,%outhash);
134: }
135:
136:
137: sub clean {
138: my ($title)=@_;
139: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 140: return $title;
1.329 droeschl 141: }
142:
1.484.2.67 raeburn 143: sub default_folderpath {
144: my ($coursenum,$coursedom,$navmapref) = @_;
145: return unless ($coursenum && $coursedom && ref($navmapref));
146: # Check if entire course is hidden and/or encrypted
147: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
148: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
149: unless (ref($$navmapref)) {
150: $$navmapref = Apache::lonnavmaps::navmap->new();
151: }
152: if (ref($$navmapref)) {
153: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
154: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
155: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
156: unless (@resources) {
157: $hiddenmap = 1;
158: unless ($env{'request.role.adv'}) {
159: $hiddentop = 1;
160: if ($env{'form.folder'}) {
161: undef($env{'form.folder'});
162: }
163: }
164: }
165: }
166: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
167: $encryptmap = 1;
168: }
169: }
170: unless ($hiddentop) {
171: $folderpath='default&'.&escape(&mt('Main Content')).
172: '::'.$hiddenmap.':'.$encryptmap.'::';
173: }
174: if (wantarray) {
175: return ($folderpath,$hiddentop);
176: } else {
177: return $folderpath;
178: }
179: }
1.329 droeschl 180:
1.484.2.92 raeburn 181: sub validate_folderpath {
182: my ($supplementalflag) = @_;
183: if ($env{'form.folderpath'} ne '') {
184: my @items = split(/\&/,$env{'form.folderpath'});
185: my $badpath;
186: for (my $i=0; $i<@items; $i++) {
187: my $odd = $i%2;
188: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
189: $badpath = 1;
190: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
191: $badpath = 1;
192: }
193: last if ($badpath);
194: }
195: if ($badpath) {
196: delete($env{'form.folderpath'});
197: }
198: }
199: return;
200: }
201:
202: sub validate_suppath {
203: if ($env{'form.supppath'} ne '') {
204: my @items = split(/\&/,$env{'form.supppath'});
205: my $badpath;
206: for (my $i=0; $i<@items; $i++) {
207: my $odd = $i%2;
208: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
209: $badpath = 1;
210: }
211: last if ($badpath);
212: }
213: if ($badpath) {
214: delete($env{'form.supppath'});
215: }
216: }
217: return;
218: }
219:
1.329 droeschl 220: sub dumpcourse {
221: my ($r) = @_;
1.408 raeburn 222: my $crstype = &Apache::loncommon::course_type();
1.484.2.43 raeburn 223: my ($starthash,$js);
224: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
225: $js = <<"ENDJS";
226: <script type="text/javascript">
227: // <![CDATA[
228:
229: function hide_searching() {
230: if (document.getElementById('searching')) {
231: document.getElementById('searching').style.display = 'none';
232: }
233: return;
234: }
235:
236: // ]]>
237: </script>
238: ENDJS
239: $starthash = {
240: add_entries => {'onload' => "hide_searching();"},
241: };
242: }
243: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
244: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 245: $r->print(&startContentScreen('tools'));
1.329 droeschl 246: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 247: unless ($home) {
248: $r->print(&endContentScreen());
249: return '';
250: }
1.329 droeschl 251: my $origcrsid=$env{'request.course.id'};
252: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
253: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
254: # Do the dumping
1.484 raeburn 255: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
256: $r->print(&endContentScreen());
257: return '';
258: }
1.484.2.24 raeburn 259: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 260: $r->print('<h3>'.&mt('Copying Files').'</h3>');
261: my $title=$env{'form.authorfolder'};
262: $title=&clean($title);
1.484.2.43 raeburn 263: my ($navmap,$errormsg) =
264: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
265: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
266: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
267: my (%maps,%resources,%titles);
268: if (!ref($navmap)) {
269: $r->print($errormsg.
270: &endContentScreen());
271: return '';
272: } else {
273: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
274: 'dumpdocs',$cdom,$cnum);
275: }
276: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
277: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
278: %newcontent,%has_simpleprobs);
279: foreach my $item (sort {$a <=> $b} (@todump)) {
280: my $name = $env{'form.namefor_'.$item};
281: if ($resources{$item}) {
282: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
283: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
284: $tocopy{$1} = $name;
285: $display{$item} = $1;
286: $lookup{$1} = $item;
287: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
288: $simpleproblems{$item} = {
289: symb => $resources{$item},
290: name => $name,
291: };
292: $display{$item} = 'simpleproblem_'.$name;
293: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
294: $has_simpleprobs{$1}{$id} = $item;
295: }
296: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
297: my $marker = $1;
298: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
299: $simplepages{$item} = {
300: res => $res,
301: title => $titles{$item},
302: db => $db_name,
303: marker => $marker,
304: symb => $resources{$item},
305: name => $name,
306: };
307: $display{$item} = '/'.$res;
308: }
309: } elsif ($maps{$item}) {
310: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
311: $tocopy{$1} = $name;
312: $display{$item} = $1;
313: $lookup{$1} = $item;
314: }
315: } else {
316: next;
317: }
318: }
1.329 droeschl 319: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
320: $crs=~s/\_/\//g;
1.484.2.43 raeburn 321: my $mm = new File::MMagic;
322: my $prefix = "/uploaded/$cdom/$cnum/";
323: %replacehash = %tocopy;
324: foreach my $item (sort(keys(%simpleproblems))) {
325: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
326: $newcontent{$display{$item}} = $content;
327: }
328: my $gateway = Apache::lonhtmlgateway->new('web');
329: foreach my $item (sort(keys(%simplepages))) {
330: if (ref($simplepages{$item}) eq 'HASH') {
331: my $pagetitle = $simplepages{$item}{'title'};
332: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
333: my %contents;
334: foreach my $field (keys(%fields)) {
335: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
336: my $name = $1;
337: my $msg = $fields{$field};
338: if ($name eq 'webreferences') {
339: if ($msg =~ m{^https?://}) {
340: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
341: }
342: } else {
343: $msg = &Encode::decode('utf8',$msg);
344: $msg = $gateway->process_outgoing_html($msg,1);
345: $contents{$name} = $msg;
346: }
347: } elsif ($field eq 'uploaded.photourl') {
348: my $marker = $simplepages{$item}{marker};
349: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
350: my $filepath = $1;
351: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
352: if ($fname ne '') {
353: $fname=~s/\.(\w+)$//;
354: my $ext=$1;
355: $fname = &clean($fname);
356: $fname.='.'.$ext;
357: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
358: $replacehash{$filepath} = $relpath.$fname;
359: $deps{$item}{$filepath} = 1;
360: }
361: }
362: }
363: }
364: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
365: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
366: my $content = '
367: <html>
368: <head>
369: <title>'.$pagetitle.'</title>
370: </head>
371: <body bgcolor="#ffffff">';
372: if ($contents{title}) {
373: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
374: }
375: if ($contents{image}) {
376: $content .= "\n".$contents{image};
377: }
378: if ($contents{content}) {
379: $content .= '
380: <div class="LC_Box">
1.484.2.50 raeburn 381: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.484.2.43 raeburn 382: $contents{content}.'
383: </div>';
384: }
385: if ($contents{webreferences}) {
386: $content .= '
387: <div class="LC_Box">
1.484.2.50 raeburn 388: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.484.2.43 raeburn 389: $contents{webreferences}.'
390: </div>';
391: }
392: $content .= '
393: </body>
394: </html>
395: ';
396: $newcontent{'/'.$simplepages{$item}{res}} = $content;
397: }
398: }
399: foreach my $item (keys(%tocopy)) {
400: unless ($item=~/\.(sequence|page)$/) {
401: my $currurlpath = $prefix.$item;
402: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
403: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
404: }
405: }
406: foreach my $num (sort {$a <=> $b} (@todump)) {
407: my $src = $display{$num};
408: next if ($src eq '');
409: my @needcopy = ();
410: if ($replacehash{$src}) {
411: push(@needcopy,$src);
412: if (ref($deps{$num}) eq 'HASH') {
413: foreach my $dep (sort(keys(%{$deps{$num}}))) {
414: if ($replacehash{$dep}) {
415: push(@needcopy,$dep);
416: }
417: }
418: }
419: } elsif ($src =~ /^simpleproblem_/) {
420: push(@needcopy,$src);
421: }
422: next if (@needcopy == 0);
423: my ($result,$depresult);
424: for (my $i=0; $i<@needcopy; $i++) {
425: my $item = $needcopy[$i];
426: my $newfilename;
427: if ($simpleproblems{$num}) {
428: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
429: } else {
430: $newfilename=$title.'/'.$replacehash{$item};
431: }
432: $newfilename=~s/\.(\w+)$//;
433: my $ext=$1;
434: $newfilename=&clean($newfilename);
435: $newfilename.='.'.$ext;
436: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
437: if ($newrelpath ne $replacehash{$item}) {
438: $replacehash{$item} = $newrelpath;
439: }
440: my @dirs=split(/\//,$newfilename);
441: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
442: my $makepath=$path;
443: my $fail;
444: my $origin;
445: for (my $i=0;$i<$#dirs;$i++) {
446: $makepath.='/'.$dirs[$i];
447: unless (-e $makepath) {
448: unless(mkdir($makepath,0755)) {
449: $fail = &mt('Directory creation failed.');
450: }
451: }
452: }
453: if ($i == 0) {
454: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
455: } else {
456: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
457: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
458: &mt('(dependency)').'</span>: ';
459: }
460: if (-e $path.'/'.$newfilename) {
461: $fail = &mt('Destination already exists -- not overwriting.');
462: } else {
463: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
464: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
465: ($item =~ /^simpleproblem_/)) {
466: print $fh $newcontent{$item};
467: } else {
468: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
469: if (-e $fileloc) {
470: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
471: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
472: (ref($has_simpleprobs{$item}) eq 'HASH')) {
473: my %changes = %{$has_simpleprobs{$item}};
474: my $content = &Apache::lonclonecourse::rewritefile(
475: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
476: (%replacehash,$crs => '')
477: );
478: my $updatedcontent = '';
479: my $parser = HTML::TokeParser->new(\$content);
480: $parser->attr_encoded(1);
481: while (my $token = $parser->get_token) {
482: if ($token->[0] eq 'S') {
483: if (($token->[1] eq 'resource') &&
484: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
485: ($changes{$token->[2]->{'id'}})) {
486: my $id = $token->[2]->{'id'};
487: $updatedcontent .= '<'.$token->[1];
488: foreach my $attrib (@{$token->[3]}) {
489: next unless ($attrib =~ /^(src|type|title|id)$/);
490: if ($attrib eq 'src') {
491: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
492: if ($file) {
493: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
494: } else {
495: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
496: }
497: } else {
498: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
499: }
500: }
501: $updatedcontent .= ' />'."\n";
502: } else {
503: $updatedcontent .= $token->[4]."\n";
504: }
505: } else {
506: $updatedcontent .= $token->[2];
507: }
508: }
509: print $fh $updatedcontent;
510: } else {
511: print $fh &Apache::lonclonecourse::rewritefile(
512: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
513: (%replacehash,$crs => '')
514: );
515: }
516: } else {
517: print $fh
518: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
519: }
520: } else {
521: $fail = &mt('Source does not exist.');
522: }
523: }
524: $fh->close();
525: } else {
526: $fail = &mt('Could not write to destination.');
527: }
528: }
529: my $text;
530: if ($fail) {
531: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
532: } else {
533: $text = '<span class="LC_success">'.&mt('ok').'</span>';
534: }
535: if ($i == 0) {
536: $result .= $text;
537: } else {
538: $depresult .= $text.'</li>';
539: }
540: }
541: $r->print($result);
542: if ($depresult) {
543: $r->print('<ul>'.$depresult.'</ul>');
544: }
545: }
1.329 droeschl 546: } else {
1.484.2.43 raeburn 547: my ($navmap,$errormsg) =
548: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
549: if (!ref($navmap)) {
550: $r->print($errormsg);
551: } else {
552: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
553: $r->rflush();
554: my ($preamble,$formname);
555: $formname = 'dumpdoc';
556: unless ($home==1) {
557: $preamble = '<div class="LC_left_float">'.
558: '<fieldset><legend>'.
559: &mt('Select the Authoring Space').
560: '</legend><select name="authorspace">';
561: }
562: my @orderspaces = ();
563: foreach my $key (sort(keys(%outhash))) {
564: if ($key=~/^home_(.+)$/) {
565: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
566: unshift(@orderspaces,$1);
567: } else {
568: push(@orderspaces,$1);
569: }
570: }
571: }
572: if ($home>1) {
573: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
574: }
575: foreach my $user (@orderspaces) {
576: if ($home==1) {
577: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
578: } else {
579: $preamble .= '<option value="'.$user.'">'.$user.' - '.
580: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
581: }
582: }
583: unless ($home==1) {
584: $preamble .= '</select></fieldset></div>'."\n";
585: }
586: my $title=$origcrsdata{'description'};
587: $title=~s/[\/\s]+/\_/gs;
588: $title=&clean($title);
589: $preamble .= '<div class="LC_left_float">'.
590: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
591: '<input type="text" size="50" name="authorfolder" value="'.
592: $title.'" />'.
593: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
594: my %uploadedfiles;
595: &tiehash();
596: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
597: my ($ext)=($file=~/\.(\w+)$/);
598: # FIXME Check supplemental here
599: my $title=$hash{'title_'.$hash{
600: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
601: if (!$title) {
602: $title=$file;
603: } else {
604: $title=~s|/|_|g;
605: }
606: $title=~s/\.(\w+)$//;
607: $title=&clean($title);
608: $title.='.'.$ext;
609: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
610: $uploadedfiles{$file} = $title;
611: }
612: &untiehash();
613: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
614: undef,undef,$preamble,$home,\%uploadedfiles));
615: }
1.329 droeschl 616: }
1.484 raeburn 617: $r->print(&endContentScreen());
1.329 droeschl 618: }
619:
1.484.2.43 raeburn 620: sub recurse_html {
621: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
622: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
623: my (%allfiles,%codebase);
624: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
625: if (keys(%allfiles)) {
626: foreach my $dependency (keys(%allfiles)) {
627: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
628: my ($depurl,$relfile,$newcontainer);
629: if ($dependency =~ m{^/}) {
630: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
631: $relfile = $1;
632: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
633: $newcontainer = $1;
634: next if ($replacehash->{$newcontainer});
635: }
636: $depurl = $dependency;
637: } else {
638: next;
639: }
640: } else {
641: $relfile = $dependency;
642: $depurl = $currurlpath;
643: $depurl =~ s{[^/]+$}{};
644: $depurl .= $dependency;
645: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
646: }
647: next if ($relfile eq '');
648: my $newname = $replacehash->{$container};
649: $newname =~ s{[^/]+$}{};
650: $replacehash->{$newcontainer} = $newname.$relfile;
651: $deps->{$item}{$newcontainer} = 1;
652: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
653: my $depfile = &Apache::lonnet::filelocation('',$depurl);
654: my $type = $mm->checktype_filename($depfile);
655: if ($type eq 'text/html') {
656: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
657: }
658: }
659: }
660: }
661: return;
662: }
663:
1.329 droeschl 664: sub group_import {
1.484.2.93.2. (raeburn 665:): my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.484.2.23 raeburn 666: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
667: %removeparam,$importuploaded,$fixuperrors);
668: $allmaps = {};
1.329 droeschl 669: while (@files) {
670: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 671: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 672: && ($caller eq 'londocs')
673: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 674:
1.329 droeschl 675: my $errtext = '';
676: my $fatal = 0;
677: my $newmapstr = '<map>'."\n".
678: '<resource id="1" src="" type="start"></resource>'."\n".
679: '<link from="1" to="2" index="1"></link>'."\n".
680: '<resource id="2" src="" type="finish"></resource>'."\n".
681: '</map>';
682: $env{'form.output'}=$newmapstr;
683: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
684: 'output',$1.$2);
1.484.2.27 raeburn 685: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 686: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
687: $fatal = 2;
688: }
689: if ($fatal) {
690: return ($errtext,$fatal);
691: }
692: }
693: if ($url) {
1.484.2.93.2. (raeburn 694:): if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
695:): $url = $1;
696:): my $marker = $2;
697:): my $info = $3;
698:): my ($toolid,%toolhash,%toolsettings);
699:): my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
700:): my @toolinfo = split(/:/,$info);
701:): if ($residx) {
702:): %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
703:): $toolid = $toolsettings{'id'};
704:): } else {
705:): $toolid = shift(@toolinfo);
706:): }
707:): $toolid =~ s/\D//g;
708:): ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
709:): $toolhash{'linktext'},$toolhash{'explanation'},
710:): $toolhash{'crslabel'},$toolhash{'crstitle'},$toolhash{'crsappend'}) = @toolinfo;
711:): foreach my $item (@extras) {
712:): $toolhash{$item} = &unescape($toolhash{$item});
713:): }
714:): if (ref($ltitoolsref) eq 'HASH') {
715:): my @deleted;
716:): if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
717:): $toolhash{'id'} = $toolid;
718:): if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
719:): ($toolhash{'target'} eq 'window')) {
720:): if ($toolhash{'target'} eq 'window') {
721:): foreach my $item ('width','height') {
722:): $toolhash{$item} =~ s/^\s+//;
723:): $toolhash{$item} =~ s/\s+$//;
724:): if ($toolhash{$item} =~ /\D/) {
725:): delete($toolhash{$item});
726:): if ($residx) {
727:): if ($toolsettings{$item}) {
728:): push(@deleted,$item);
729:): }
730:): }
731:): }
732:): }
733:): }
734:): } elsif ($residx) {
735:): $toolhash{'target'} = $toolsettings{'target'};
736:): if ($toolhash{'target'} eq 'window') {
737:): foreach my $item ('width','height') {
738:): $toolhash{$item} = $toolsettings{$item};
739:): }
740:): }
741:): } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
742:): $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
743:): if ($toolhash{'target'} eq 'window') {
744:): $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
745:): $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
746:): }
747:): }
748:): if ($toolhash{'target'} eq 'iframe') {
749:): foreach my $item ('width','height','linktext','explanation') {
750:): delete($toolhash{$item});
751:): if ($residx) {
752:): if ($toolsettings{$item}) {
753:): push(@deleted,$item);
754:): }
755:): }
756:): }
757:): } elsif ($toolhash{'target'} eq 'tab') {
758:): foreach my $item ('width','height') {
759:): delete($toolhash{$item});
760:): if ($residx) {
761:): if ($toolsettings{$item}) {
762:): push(@deleted,$item);
763:): }
764:): }
765:): }
766:): }
767:): if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
768:): foreach my $item ('label','title','linktext','explanation') {
769:): my $crsitem;
770:): if (($item eq 'label') || ($item eq 'title')) {
771:): $crsitem = 'crs'.$item;
772:): } else {
773:): $crsitem = $item;
774:): }
775:): if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
776:): $toolhash{$crsitem} =~ s/^\s+//;
777:): $toolhash{$crsitem} =~ s/\s+$//;
778:): if ($toolhash{$crsitem} eq '') {
779:): delete($toolhash{$crsitem});
780:): }
781:): } else {
782:): delete($toolhash{$crsitem});
783:): }
784:): if (($residx) && (exists($toolsettings{$crsitem}))) {
785:): unless (exists($toolhash{$crsitem})) {
786:): push(@deleted,$crsitem);
787:): }
788:): }
789:): }
790:): }
791:): my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
792:): if ($putres eq 'ok') {
793:): if (@deleted) {
794:): &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
795:): }
796:): } else {
797:): return (&mt('Failed to save update to external tool.'),1);
798:): }
799:): }
800:): }
801:): }
1.484.2.23 raeburn 802: if (($caller eq 'londocs') &&
803: ($folder =~ /^default/)) {
1.484.2.27 raeburn 804: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 805: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
806: my $cid = $coursedom.'_'.$coursenum;
807: $allmaps =
808: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
809: $chome,$cid);
810: $donechk = 1;
811: }
812: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.484.2.93.2. (raeburn 813:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
814:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.484.2.23 raeburn 815: $importuploaded = 1;
816: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
817: next if ($allmaps->{$url});
818: }
819: }
1.344 bisitz 820: if (!$residx
1.329 droeschl 821: || defined($LONCAPA::map::zombies[$residx])) {
822: $residx = &LONCAPA::map::getresidx($url,$residx);
823: push(@LONCAPA::map::order, $residx);
824: }
825: my $ext = 'false';
826: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.484.2.27 raeburn 827: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
828: my $filepath = $1;
1.484.2.91 raeburn 829: my $fname;
830: if ($name eq '') {
831: $name = &mt('Web Page');
1.484.2.27 raeburn 832: $fname = 'web';
833: } else {
1.484.2.91 raeburn 834: $fname = $name;
835: $fname=&Apache::lonnet::clean_filename($fname);
836: if ($fname eq '') {
837: $fname = 'web';
838: } elsif (length($fname) > 15) {
839: $fname = substr($fname,0,14);
840: }
1.484.2.27 raeburn 841: }
1.484.2.91 raeburn 842: my $title = &Apache::loncommon::cleanup_html($name);
1.484.2.27 raeburn 843: my $initialtext = &mt('Replace with your own content.');
844: my $newhtml = <<END;
1.484.2.31 raeburn 845: <html>
1.484.2.27 raeburn 846: <head>
1.484.2.91 raeburn 847: <title>$title</title>
1.484.2.27 raeburn 848: </head>
849: <body bgcolor="#ffffff">
850: $initialtext
851: </body>
852: </html>
853: END
854: $env{'form.output'}=$newhtml;
855: my $result =
856: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
857: 'output',
858: "$filepath/$residx/$fname.html");
859: if ($result =~ m{^/uploaded/}) {
860: $url = $result;
861: if ($filepath =~ /^supplemental/) {
862: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
863: $env{'user.domain'}.'___&&&___'.$name;
864: }
865: } else {
866: return (&mt('Failed to save new web page.'),1);
867: }
868: }
1.484.2.91 raeburn 869: $name = &LONCAPA::map::qtunescape($name);
1.484.2.30 raeburn 870: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 871: $LONCAPA::map::resources[$residx] =
1.329 droeschl 872: join(':', ($name, $url, $ext, 'normal', 'res'));
873: }
874: }
1.484.2.23 raeburn 875: if ($importuploaded) {
876: my %import_errors;
877: my %updated = (
878: removefrommap => \%removefrommap,
879: removeparam => \%removeparam,
880: );
1.484.2.26 raeburn 881: my ($result,$msgsarray,$lockerror) =
882: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 883: if (keys(%import_errors) > 0) {
884: $fixuperrors =
885: '<p span class="LC_warning">'."\n".
886: &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".
887: '<ul>'."\n";
888: foreach my $key (sort(keys(%import_errors))) {
889: $fixuperrors .= '<li>'.$key.'</li>'."\n";
890: }
891: $fixuperrors .= '</ul></p>'."\n";
892: }
1.484.2.26 raeburn 893: if (ref($msgsarray) eq 'ARRAY') {
894: if (@{$msgsarray} > 0) {
895: $fixuperrors .= '<p class="LC_info">'.
896: join('<br />',@{$msgsarray}).
897: '</p>';
898: }
899: }
900: if ($lockerror) {
901: $fixuperrors .= '<p class="LC_error">'.
902: $lockerror.
903: '</p>';
904: }
1.484.2.23 raeburn 905: }
906: my ($errtext,$fatal) =
907: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 908: unless ($fatal) {
909: if ($folder =~ /^supplemental/) {
910: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 911: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
912: $folder.'.'.$container);
1.484.2.37 raeburn 913: }
914: }
1.484.2.23 raeburn 915: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 916: }
917:
918: sub log_docs {
1.484.2.8 raeburn 919: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 920: }
921:
922: {
923: my @oldresources=();
924: my @oldorder=();
925: my $parmidx;
926: my %parmaction=();
927: my %parmvalue=();
928: my $changedflag;
929:
930: sub snapshotbefore {
931: @oldresources=@LONCAPA::map::resources;
932: @oldorder=@LONCAPA::map::order;
933: $parmidx=undef;
934: %parmaction=();
935: %parmvalue=();
936: $changedflag=0;
937: }
938:
939: sub remember_parms {
940: my ($idx,$parameter,$action,$value)=@_;
941: $parmidx=$idx;
942: $parmaction{$parameter}=$action;
943: $parmvalue{$parameter}=$value;
944: $changedflag=1;
945: }
946:
947: sub log_differences {
948: my ($plain)=@_;
949: my %storehash=('folder' => $plain,
950: 'currentfolder' => $env{'form.folder'});
951: if ($parmidx) {
952: $storehash{'parameter_res'}=$oldresources[$parmidx];
953: foreach my $parm (keys(%parmaction)) {
954: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
955: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
956: }
957: }
958: my $maxidx=$#oldresources;
959: if ($#LONCAPA::map::resources>$#oldresources) {
960: $maxidx=$#LONCAPA::map::resources;
961: }
962: for (my $idx=0; $idx<=$maxidx; $idx++) {
963: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
964: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
965: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
966: $changedflag=1;
967: }
968: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
969: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
970: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
971: $changedflag=1;
972: }
973: }
974: $storehash{'maxidx'}=$maxidx;
975: if ($changedflag) { &log_docs(\%storehash); }
976: }
977: }
978:
979: sub docs_change_log {
1.484.2.67 raeburn 980: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 981: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 982: my $navmap;
1.483 raeburn 983: my $js = '<script type="text/javascript">'."\n".
984: '// <![CDATA['."\n".
985: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 986: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.93.2. (raeburn 987:): $coursedom,$coursenum,'',$canedit,'',\$navmap)."\n".
1.483 raeburn 988: &history_tab_js()."\n".
1.484 raeburn 989: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 990: '// ]]>'."\n".
991: '</script>'."\n";
1.484 raeburn 992: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
993: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 994: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 995: my %orderhash;
996: my $container='sequence';
997: my $pathitem;
1.484.2.19 raeburn 998: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 999: $container='page';
1000: }
1.484.2.19 raeburn 1001: my $folderpath=$env{'form.folderpath'};
1002: if ($folderpath eq '') {
1.484.2.67 raeburn 1003: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 1004: }
1.484.2.67 raeburn 1005: undef($navmap);
1.484.2.19 raeburn 1006: $pathitem = '<input type="hidden" name="folderpath" value="'.
1007: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1008: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1009: my $jumpto = $readfile;
1010: $jumpto =~ s{^/}{};
1011: my $tid = 1;
1.484.2.7 raeburn 1012: if ($supplementalflag) {
1013: $tid = 2;
1014: }
1.484.2.19 raeburn 1015: my ($breadcrumbtrail) =
1.484.2.18 raeburn 1016: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1017: $r->print($breadcrumbtrail.
1018: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1019: $readfile));
1.329 droeschl 1020: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1021: $env{'course.'.$env{'request.course.id'}.'.domain'},
1022: $env{'course.'.$env{'request.course.id'}.'.num'});
1023:
1024: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1025:
1026: my %saveable_parameters = ('show' => 'scalar',);
1027: &Apache::loncommon::store_course_settings('docs_log',
1028: \%saveable_parameters);
1029: &Apache::loncommon::restore_course_settings('docs_log',
1030: \%saveable_parameters);
1031: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1032: # FIXME: internationalization seems wrong here
1.329 droeschl 1033: my %lt=('hiddenresource' => 'Resources hidden',
1034: 'encrypturl' => 'URL hidden',
1035: 'randompick' => 'Randomly pick',
1036: 'randomorder' => 'Randomly ordered',
1037: 'set' => 'set to',
1038: 'del' => 'deleted');
1.484 raeburn 1039: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1040: $pathitem."\n".
1041: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1042: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1043: $r->print('<div class="LC_left_float">'.
1044: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1045: &makedocslogform($filter,1).
1046: '</fieldset></div><br clear="all" />');
1.329 droeschl 1047: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1048: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1049: &mt('After').'</th>'.
1050: &Apache::loncommon::end_data_table_header_row());
1051: my $shown=0;
1052: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1053: if ($env{'form.displayfilter'} eq 'currentfolder') {
1054: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1055: }
1056: my @changes=keys(%{$docslog{$id}{'logentry'}});
1057: if ($env{'form.displayfilter'} eq 'containing') {
1058: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1059: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1060: foreach my $key (@changes) {
1061: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1062: }
1.344 bisitz 1063: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1064: }
1065: my $count = 0;
1066: my $time =
1067: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1068: my $plainname =
1069: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1070: $docslog{$id}{'exe_udom'});
1071: my $about_me_link =
1072: &Apache::loncommon::aboutmewrapper($plainname,
1073: $docslog{$id}{'exe_uname'},
1074: $docslog{$id}{'exe_udom'});
1075: my $send_msg_link='';
1076: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1077: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1078: $send_msg_link ='<br />'.
1079: &Apache::loncommon::messagewrapper(&mt('Send message'),
1080: $docslog{$id}{'exe_uname'},
1081: $docslog{$id}{'exe_udom'});
1082: }
1083: $r->print(&Apache::loncommon::start_data_table_row());
1084: $r->print('<td>'.$time.'</td>
1085: <td>'.$about_me_link.
1086: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1087: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1088: $send_msg_link.'</td><td>'.
1089: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 1090: my $is_supp = 0;
1.484.2.7 raeburn 1091: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1092: $is_supp = 1;
1093: }
1.329 droeschl 1094: # Before
1095: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1096: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1097: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1098: if ($oldname ne $newname) {
1.484.2.7 raeburn 1099: my $shown = &LONCAPA::map::qtescape($oldname);
1100: if ($is_supp) {
1101: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1102: }
1103: $r->print($shown);
1.329 droeschl 1104: }
1105: }
1106: $r->print('<ul>');
1107: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1108: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 1109: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1110: if ($is_supp) {
1111: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1112: }
1.484.2.19 raeburn 1113: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1114: }
1115: }
1116: $r->print('</ul>');
1117: # After
1118: $r->print('</td><td>');
1119:
1120: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1121: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1122: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1123: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 1124: my $shown = &LONCAPA::map::qtescape($newname);
1125: if ($is_supp) {
1126: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1127: }
1128: $r->print($shown);
1.329 droeschl 1129: }
1.364 bisitz 1130: }
1.329 droeschl 1131: $r->print('<ul>');
1132: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1133: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 1134: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1135: if ($is_supp) {
1136: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1137: }
1138: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1139: }
1140: }
1141: $r->print('</ul>');
1142: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1143: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1144: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1145: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1146: # FIXME: internationalization seems wrong here
1.329 droeschl 1147: $r->print('<li>'.
1148: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1149: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1150: .'</li>');
1151: }
1152: }
1153: $r->print('</ul>');
1154: }
1155: # End
1156: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1157: $shown++;
1158: if (!($env{'form.show'} eq &mt('all')
1159: || $shown<=$env{'form.show'})) { last; }
1160: }
1.484 raeburn 1161: $r->print(&Apache::loncommon::end_data_table()."\n".
1162: &makesimpleeditform($pathitem)."\n".
1163: '</div></div>');
1164: $r->print(&endContentScreen());
1.329 droeschl 1165: }
1166:
1167: sub update_paste_buffer {
1.484.2.7 raeburn 1168: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1169: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1170: if ($env{'form.multiremove'}) {
1171: $env{'form.multiremove'} =~ s/,$//;
1172: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1173: }
1174: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1175: if ($env{'form.multicut'}) {
1176: $env{'form.multicut'} =~ s/,$//;
1177: foreach my $item (split(/,/,$env{'form.multicut'})) {
1178: unless ($removals{$item}) {
1179: $cuts{$item} = 1;
1180: push(@possibles,$item.':cut');
1181: }
1182: }
1183: }
1184: if ($env{'form.multicopy'}) {
1185: $env{'form.multicopy'} =~ s/,$//;
1186: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1187: unless ($removals{$item} || $cuts{$item}) {
1188: push(@possibles,$item.':copy');
1189: }
1190: }
1191: }
1192: } elsif ($env{'form.markcopy'}) {
1193: @possibles = split(/,/,$env{'form.markcopy'});
1194: }
1.329 droeschl 1195:
1.484.2.30 raeburn 1196: return if (@possibles == 0);
1.329 droeschl 1197: return if (!defined($env{'form.copyfolder'}));
1198:
1199: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1200: $env{'form.copyfolder'});
1201: return if ($fatal);
1202:
1.484.2.30 raeburn 1203: my %curr_groups = &Apache::longroup::coursegroups();
1204:
1205: # Retrieve current paste buffer suffixes.
1206: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1207: my (%pasteurls,@newpaste);
1208:
1209: # Construct identifiers for current contents of user's paste buffer
1210: if (@currpaste) {
1211: foreach my $suffix (@currpaste) {
1.484.2.87 raeburn 1212: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1213: my $url = $env{'docs.markedcopy_url_'.$suffix};
1214: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1215: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1216: ($url ne '')) {
1217: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1218: $pasteurls{$cid.'_'.$mapidx} = 1;
1219: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1220: $pasteurls{$url} = 1;
1221: } else {
1222: $pasteurls{$cid.'_'.$url} = 1;
1223: }
1224: }
1.484.2.30 raeburn 1225: }
1226: }
1227:
1228: # Mark items for copying (skip any items already in user's paste buffer)
1229: my %addtoenv;
1.484.2.82 raeburn 1230:
1231: my @pathitems = split(/\&/,$env{'form.folderpath'});
1232: my @folderconf = split(/\:/,$pathitems[-1]);
1.484.2.87 raeburn 1233: my $ispage = $folderconf[5];
1.484.2.82 raeburn 1234:
1.484.2.30 raeburn 1235: foreach my $item (@possibles) {
1236: my ($orderidx,$cmd) = split(/:/,$item);
1237: next if ($orderidx =~ /\D/);
1238: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1239: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1240: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1241: my %denied = &action_restrictions($coursenum,$coursedom,
1242: &LONCAPA::map::qtescape($url),
1243: $env{'form.folderpath'},\%curr_groups);
1244: next if ($denied{'copy'});
1245: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 1246: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1247: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1248: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1249: next if (exists($pasteurls{$url}));
1250: } else {
1251: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1252: }
1.484.2.30 raeburn 1253: my ($suffix,$errortxt,$locknotfreed) =
1254: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1255: if ($suffix ne '') {
1256: push(@newpaste,$suffix);
1257: } else {
1258: if ($locknotfreed) {
1259: return $locknotfreed;
1260: }
1.484.2.30 raeburn 1261: }
1262: if (&is_supplemental_title($title)) {
1263: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1264: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1265: }
1266:
1267: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1268: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1269: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1270: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1271: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1272: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1273: my $prefix = $1;
1274: my $subdir =$2;
1275: if ($subdir eq '') {
1276: $subdir = $prefix;
1.484.2.7 raeburn 1277: }
1.484.2.30 raeburn 1278: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.484.2.93.2. (raeburn 1279:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1280:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.484.2.30 raeburn 1281: if (ref($hierarchy{$url}) eq 'HASH') {
1282: my ($nested,$nestednames);
1283: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1284: $nested =~ s/\&$//;
1285: $nestednames =~ s/\Q___&&&___\E$//;
1286: if ($nested ne '') {
1287: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1288: }
1289: if ($nestednames ne '') {
1290: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1291: }
1.484.2.7 raeburn 1292: }
1293: }
1.484.2.57 raeburn 1294: if ($locknotfreed) {
1295: $output = $locknotfreed;
1296: last;
1297: }
1.484.2.7 raeburn 1298: }
1.484.2.30 raeburn 1299: if (@newpaste) {
1300: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1301: }
1.484.2.7 raeburn 1302: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1303: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1304: return $output;
1.329 droeschl 1305: }
1306:
1.484.2.7 raeburn 1307: sub recurse_uploaded_maps {
1308: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1309: if (ref($hierarchy->{$url}) eq 'HASH') {
1310: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1311: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1312: my (@uploaded,@names,%shorter);
1313: for (my $i=0; $i<@maps; $i++) {
1314: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1315: if ($inner ne '') {
1316: push(@uploaded,$inner);
1317: push(@names,&escape($titles[$i]));
1318: $shorter{$maps[$i]} = $inner;
1319: }
1320: }
1321: $$nestref .= "$dir:".join(',',@uploaded).'&';
1322: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1323: foreach my $map (@maps) {
1324: if ($shorter{$map} ne '') {
1325: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1326: }
1327: }
1328: }
1329: return;
1330: }
1331:
1.329 droeschl 1332: sub print_paste_buffer {
1.484.2.7 raeburn 1333: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1334: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1335:
1.484.2.30 raeburn 1336: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1337: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1338: }
1339:
1.484.2.30 raeburn 1340: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1341: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1342: my $clipboardcount = 0;
1.484.2.7 raeburn 1343:
1.484.2.30 raeburn 1344: # Construct identifiers for current contents of user's paste buffer
1345: foreach my $suffix (@currpaste) {
1346: next if ($suffix =~ /\D/);
1347: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1348: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1349: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1350: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1351: ($url ne '')) {
1.484.2.47 raeburn 1352: $clipboardcount ++;
1.484.2.30 raeburn 1353: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.484.2.93.2. (raeburn 1354:): $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.484.2.30 raeburn 1355: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1356: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1357: $is_external = 1;
1.484.2.93.2. (raeburn 1358:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1359:): $is_exttool = 1;
1.484.2.7 raeburn 1360: }
1.484.2.30 raeburn 1361: if ($folder =~ /^supplemental/) {
1362: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1363: unless ($canpaste) {
1364: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1365: }
1.484.2.30 raeburn 1366: } else {
1367: $canpaste = 1;
1.484.2.7 raeburn 1368: }
1.484.2.30 raeburn 1369: if ($canpaste) {
1370: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1371: my $srcdom = $1;
1372: my $srcnum = $2;
1373: my $rem = $3;
1374: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1375: $othercourse = 1;
1376: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1377: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1378: } else {
1379: $canpaste = 0;
1380: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1381: }
1382: }
1.484.2.30 raeburn 1383: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1384: my $prefix = $1;
1385: $parent = $2;
1386: if ($folder !~ /^\Q$prefix\E/) {
1387: $areachange = 1;
1388: }
1389: $is_uploaded_map = 1;
1390: }
1.484.2.82 raeburn 1391: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.484.2.93.2. (raeburn 1392:): ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.484.2.76 raeburn 1393: if ($cid ne $env{'request.course.id'}) {
1394: my ($srcdom,$srcnum) = split(/_/,$cid);
1395: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.93.2. (raeburn 1396:): if (($is_exttool) && ($srcdom ne $coursedom)) {
1397:): $canpaste = 0;
1398:): $nopaste = &mt('Paste from another domain unavailable.');
1399:): } else {
1400:): $othercrs = '<br />'.&mt('(from another course)');
1401:): }
1.484.2.76 raeburn 1402: } else {
1403: $canpaste = 0;
1404: $nopaste = &mt('Paste from another course unavailable.');
1405: }
1406: }
1407: }
1408: if ($canpaste) {
1409: push(@pasteable,$suffix);
1.484.2.30 raeburn 1410: }
1411: }
1412: my $buffer;
1413: if ($is_external) {
1414: $buffer = &mt('External Resource').': '.
1415: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1416: &LONCAPA::map::qtescape($url).')';
1.484.2.93.2. (raeburn 1417:): } elsif ($is_exttool) {
1418:): $buffer = &mt('External Tool').': '.
1419:): &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.30 raeburn 1420: } else {
1421: my $icon = &Apache::loncommon::icon($extension);
1422: if ($extension eq 'sequence' &&
1423: $url =~ m{/default_\d+\.sequence$}x) {
1424: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1425: $icon .= '/navmap.folder.closed.gif';
1426: }
1.484.2.57 raeburn 1427: my $title = $env{'docs.markedcopy_title_'.$suffix};
1428: if ($title eq '') {
1429: ($title) = ($url =~ m{/([^/]+)$});
1430: }
1.484.2.30 raeburn 1431: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1432: ': '.
1433: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1434: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1435: }
1436: $pasteitems .= '<div class="LC_left_float">';
1437: my ($options,$onclick);
1438: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1439: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1440: if (($is_uploaded_map) ||
1441: ($url =~ /(bulletinboard|smppg)$/) ||
1442: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1443: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1444: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1445: }
1446: }
1447: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1448: if ($nopaste) {
1.484.2.93.2. (raeburn 1449:): $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.484.2.30 raeburn 1450: } else {
1451: if ($othercrs) {
1452: $pasteitems .= $othercrs;
1453: }
1454: if ($options) {
1455: $pasteitems .= $options;
1.484.2.7 raeburn 1456: }
1457: }
1.484.2.30 raeburn 1458: $pasteitems .= '</div>';
1459: }
1460: }
1461: if ($pasteitems eq '') {
1462: &Apache::lonnet::delenv('docs.markedcopies');
1463: }
1464: my ($pasteform,$form_start,$buttons,$form_end);
1465: if ($pasteitems) {
1466: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1467: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1468: if (@pasteable) {
1.484.2.47 raeburn 1469: my $value = &mt('Paste to current folder');
1470: if ($container eq 'page') {
1471: $value = &mt('Paste to current page');
1472: }
1473: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1474: }
1.484.2.93.2. (raeburn 1475:): $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1.484.2.47 raeburn 1476: if ($clipboardcount > 1) {
1477: $buttons .=
1478: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1479: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1480: (' 'x2).
1481: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1482: (' 'x2);
1.484.2.7 raeburn 1483: }
1.484.2.48 raeburn 1484: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1485: '</form>';
1.484.2.30 raeburn 1486: } else {
1487: $pasteitems = &mt('Clipboard is empty');
1488: }
1489: $r->print($form_start
1490: .'<fieldset>'
1491: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1492: .$pasteitems
1493: .'</fieldset>'
1494: .$form_end);
1495: }
1496:
1497: sub paste_options {
1498: my ($suffix,$is_uploaded_map,$parent) = @_;
1499: my ($copytext,$movetext);
1500: if ($is_uploaded_map) {
1501: $copytext = &mt('Copy to new folder');
1502: $movetext = &mt('Move old');
1503: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1504: $copytext = &mt('Copy to new board');
1505: $movetext = &mt('Move (not posts)');
1506: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1507: $copytext = &mt('Copy to new page');
1508: $movetext = &mt('Move');
1.484.2.7 raeburn 1509: } else {
1.484.2.30 raeburn 1510: $copytext = &mt('Copy to new file');
1511: $movetext = &mt('Move');
1512: }
1513: my $output = '<br />'.
1514: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1515: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1516: '<label>'.
1517: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1518: $copytext.'</label></span>'.(' 'x2).' '.
1519: '<span class="LC_nobreak"><label>'.
1520: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1521: $movetext.'</label></span>';
1522: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1523: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1524: '</legend><table border="0">';
1525: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1526: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1527: my $lastdir = $parent;
1528: my %depths = (
1529: $lastdir => 0,
1530: );
1531: my (%display,%deps);
1532: for (my $i=0; $i<@pastemaps; $i++) {
1533: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1534: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1535: my @subfolders = split(/,/,$subfolderstr);
1536: $deps{$lastdir} = \@subfolders;
1537: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1538: my $depth = $depths{$lastdir} + 1;
1539: my $offset = int($depth * 4);
1540: my $indent = (' ' x $offset);
1541: for (my $j=0; $j<@subfolders; $j++) {
1542: $depths{$subfolders[$j]} = $depth;
1543: $display{$subfolders[$j]} =
1544: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1545: '<td><label>'.
1546: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1547: '<label>'.
1548: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1549: &mt('Move old').'</label>'.
1550: '</td></tr>';
1551: }
1552: }
1553: &recurse_print(\$output,$parent,\%deps,\%display);
1554: $output .= '</table></fieldset>';
1.329 droeschl 1555: }
1.484.2.30 raeburn 1556: $output .= '</div>';
1557: return $output;
1.329 droeschl 1558: }
1559:
1.484.2.7 raeburn 1560: sub recurse_print {
1.484.2.30 raeburn 1561: my ($outputref,$dir,$deps,$display) = @_;
1562: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1563: if (ref($deps->{$dir}) eq 'ARRAY') {
1564: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1565: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1566: }
1567: }
1568: }
1569:
1570: sub supp_pasteable {
1571: my ($url) = @_;
1572: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1573: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1574: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1575: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.484.2.93.2. (raeburn 1576:): ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1577:): ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.484.2.7 raeburn 1578: return 1;
1579: }
1580: return;
1581: }
1582:
1583: sub paste_popup_js {
1.484.2.61 raeburn 1584: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1585: show => 'Show Options',
1586: hide => 'Hide Options',
1.484.2.61 raeburn 1587: );
1588: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1589: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1590: );
1.484.2.61 raeburn 1591: &html_escape(\%html_js_lt);
1592: &js_escape(\%html_js_lt);
1593: &js_escape(\%js_lt);
1.484.2.7 raeburn 1594: return <<"END";
1595:
1.484.2.30 raeburn 1596: function showPasteOptions(suffix) {
1597: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1598: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1599: return;
1600: }
1601:
1.484.2.30 raeburn 1602: function hidePasteOptions(suffix) {
1603: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1604: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1605: return;
1606: }
1607:
1.484.2.30 raeburn 1608: function showOptions(caller,suffix) {
1609: if (document.getElementById('pasteoptionstext_'+suffix)) {
1610: if (caller.checked) {
1.484.2.61 raeburn 1611: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1612: } else {
1613: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1614: }
1615: if (document.getElementById('pasteoptions_'+suffix)) {
1616: document.getElementById('pasteoptions_'+suffix).style.display='none';
1617: }
1618: }
1619: return;
1620: }
1.484.2.7 raeburn 1621:
1.484.2.30 raeburn 1622: function validateClipboard() {
1623: var numchk = 0;
1624: if (document.pasteform.pasting.length > 1) {
1625: for (var i=0; i<document.pasteform.pasting.length; i++) {
1626: if (document.pasteform.pasting[i].checked) {
1627: numchk ++;
1628: }
1629: }
1630: } else {
1631: if (document.pasteform.pasting.type == 'checkbox') {
1632: if (document.pasteform.pasting.checked) {
1633: numchk ++;
1634: }
1635: }
1636: }
1637: if (numchk > 0) {
1638: return true;
1639: } else {
1.484.2.61 raeburn 1640: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1641: return false;
1642: }
1.484.2.7 raeburn 1643: }
1644:
1.484.2.47 raeburn 1645: function checkClipboard() {
1646: if (document.pasteform.pasting.length > 1) {
1647: for (var i=0; i<document.pasteform.pasting.length; i++) {
1648: document.pasteform.pasting[i].checked = true;
1649: }
1650: }
1651: return;
1652: }
1653:
1654: function uncheckClipboard() {
1655: if (document.pasteform.pasting.length >1) {
1656: for (var i=0; i<document.pasteform.pasting.length; i++) {
1657: document.pasteform.pasting[i].checked = false;
1658: }
1659: }
1660: return;
1661: }
1662:
1.484.2.30 raeburn 1663: END
1664:
1665: }
1.484.2.7 raeburn 1666:
1.329 droeschl 1667: sub do_paste_from_buffer {
1.484.2.7 raeburn 1668: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1669:
1.484.2.30 raeburn 1670: # Array of items in paste buffer
1671: my (@currpaste,%pastebuffer,%allerrors);
1672: @currpaste = split(/,/,$env{'docs.markedcopies'});
1673:
1.484.2.7 raeburn 1674: # Early out if paste buffer is empty
1.484.2.30 raeburn 1675: if (@currpaste == 0) {
1.484.2.7 raeburn 1676: return ();
1.484.2.30 raeburn 1677: }
1678: map { $pastebuffer{$_} = 1; } @currpaste;
1679:
1680: # Array of items selected items to paste
1681: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1682:
1683: # Early out if nothing selected to paste
1684: if (@reqpaste == 0) {
1685: return();
1686: }
1687: my @topaste;
1688: foreach my $suffix (@reqpaste) {
1689: next if ($suffix =~ /\D/);
1690: next unless (exists($pastebuffer{$suffix}));
1691: push(@topaste,$suffix);
1.484.2.7 raeburn 1692: }
1693:
1.484.2.30 raeburn 1694: # Early out if nothing available to paste
1695: if (@topaste == 0) {
1696: return();
1.329 droeschl 1697: }
1698:
1.484.2.93.2. (raeburn 1699:): my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.484.2.82 raeburn 1700: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1701:
1.484.2.30 raeburn 1702: foreach my $suffix (@topaste) {
1703: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1704: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1705: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1706: # Supplemental content may only include certain types of content
1707: # Early out if pasted content is not supported in Supplemental area
1708: if ($folder =~ /^supplemental/) {
1709: unless (&supp_pasteable($url)) {
1710: $notinsupp{$suffix} = 1;
1711: next;
1712: }
1713: }
1714: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1715: my $srcd = $1;
1716: my $srcn = $2;
1.484.2.7 raeburn 1717: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1718: # check for mdc privilege in the course from which the resource was pasted
1719: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1720: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1721: $notincrs{$suffix} = 1;
1722: next;
1723: }
1.329 droeschl 1724: }
1.484.2.30 raeburn 1725: $srcdom{$suffix} = $srcd;
1726: $srcnum{$suffix} = $srcn;
1.484.2.93.2. (raeburn 1727:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1728:): my ($srcd,$srcn) = split(/_/,$cid);
1729:): # When paste buffer was populated using an active role in a different course
1730:): # check for mdc privilege in the course from which the resource was pasted
1731:): if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1732:): unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1733:): $notincrs{$suffix} = 1;
1734:): next;
1735:): }
1736:): }
1737:): # When buffer was populated using an active role in a different course
1738:): # disallow pasting of External Tool if course is in a different domain.
1739:): if ($srcd ne $coursedom) {
1740:): $notindom{$suffix} = 1;
1741:): next;
1742:): }
1743:): $srcdom{$suffix} = $srcd;
1744:): $srcnum{$suffix} = $srcn;
1.484.2.82 raeburn 1745: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1746: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1747: my ($srcd,$srcn) = split(/_/,$cid);
1748: # When paste buffer was populated using an active role in a different course
1749: # check for mdc privilege in the course from which the resource was pasted
1750: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1751: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1752: $notincrs{$suffix} = 1;
1753: next;
1754: }
1755: }
1756: $srcdom{$suffix} = $srcd;
1757: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1758: }
1.484.2.82 raeburn 1759: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1760: push(@dopaste,$suffix);
1761: if ($url=~/\.(page|sequence)$/) {
1762: $is_map{$suffix} = 1;
1.329 droeschl 1763: }
1.484.2.30 raeburn 1764:
1765: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1766: my $oldprefix = $1;
1.484.2.19 raeburn 1767: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1768: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1769: # a folder/page or a document).
1.484.2.30 raeburn 1770: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1771: $prefixchg{$suffix} = 'docstosupp';
1772: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1773: $prefixchg{$suffix} = 'supptodocs';
1774: }
1.484.2.7 raeburn 1775:
1776: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1777: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1778: my @nested;
1779: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1780: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1781: my @deps = map { /\d+:([\d,]+$)/ } @items;
1782: foreach my $dep (@deps) {
1783: if ($dep =~ /,/) {
1784: push(@nested,split(/,/,$dep));
1785: } else {
1786: push(@nested,$dep);
1787: }
1.484.2.7 raeburn 1788: }
1.484.2.30 raeburn 1789: foreach my $item (@nested) {
1790: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1791: push(@{$marktomove{$suffix}},$type.'_'.$item);
1792: }
1.484.2.7 raeburn 1793: }
1794: }
1.329 droeschl 1795: }
1.484.2.7 raeburn 1796: }
1797:
1.484.2.30 raeburn 1798: # Early out if nothing available to paste
1799: if (@dopaste == 0) {
1800: return ();
1801: }
1802:
1803: # Populate message hash and hashes used for main content <=> supplemental content
1804: # changes
1805:
1806: %msgs = &Apache::lonlocal::texthash (
1807: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1808: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.484.2.93.2. (raeburn 1809:): notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.484.2.30 raeburn 1810: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1811: );
1812:
1813: %before = (
1814: docstosupp => {
1815: map => 'default',
1816: doc => 'docs',
1817: },
1818: supptodocs => {
1819: map => 'supplemental',
1820: doc => 'supplemental',
1821: },
1822: );
1823:
1824: %after = (
1825: docstosupp => {
1826: map => 'supplemental',
1827: doc => 'supplemental'
1828: },
1829: supptodocs => {
1830: map => 'default',
1831: doc => 'docs',
1832: },
1833: );
1834:
1835: # Retrieve information about all course maps in main content area
1836:
1837: my $allmaps = {};
1.484.2.79 raeburn 1838: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1839:
1840: # Loop over the items to paste
1841: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1842: # Maps need to be copied first
1.484.2.30 raeburn 1843: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1844: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1845: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1846: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1847: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1848: }
1849: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1850: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1851: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1852: my $oldurl = $url;
1853: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1854: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1855: my (%hierarchy,%titles);
1.484.2.79 raeburn 1856: if (($folder =~ /^default/) && (!$donechk)) {
1857: $allmaps =
1858: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1859: $env{"course.$env{'request.course.id'}.home"},
1860: $env{'request.course.id'});
1861: $donechk = 1;
1862: }
1.484.2.93.2. (raeburn 1863:): &contained_map_check($url,$folder,$coursenum,$coursedom,
1864:): \%removefrommap,\%removeparam,\%addedmaps,
1865:): \%hierarchy,\%titles,$allmaps);
1.484.2.30 raeburn 1866: if ($url=~ m{^/uploaded/}) {
1867: my $newurl;
1868: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1869: ($newurl,my $error) =
1870: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1871: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1872: \$title,$allmaps,\%newurls);
1873: if ($error) {
1874: $allerrors{$suffix} = $error;
1875: next;
1876: }
1877: if ($newurl ne '') {
1878: if ($newurl ne $url) {
1879: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1880: $newsubdir{$url} = $1;
1881: }
1882: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1883: }
1884: }
1885: }
1.484.2.30 raeburn 1886: if (($srcdom{$suffix} ne $coursedom) ||
1887: ($srcnum{$suffix} ne $coursenum) ||
1888: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1889: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1890: $coursedom,$coursenum,$srcdom{$suffix},
1891: $srcnum{$suffix},$allmaps,\%rewrites,
1892: \%retitles,\%copies,\%dbcopies,
1893: \%zombies,\%params,\%mapmoves,
1894: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 1895: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 1896: $mapmoves{$url} = 1;
1897: }
1898: $url = $newurl;
1899: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1900: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1901: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1902: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1903: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 1904: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 1905: }
1906: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 1907: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1908: push(@toclear,$suffix);
1909: # if pasting published map (main content area only) check map not already in course
1910: if ($folder =~ /^default/) {
1911: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1912: $duplicate{$suffix} = 1;
1913: next;
1914: }
1.484.2.7 raeburn 1915: }
1916: }
1917: }
1.484.2.93.2. (raeburn 1918:): if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.484.2.30 raeburn 1919: my $prefix = $1;
1.484.2.76 raeburn 1920: my $fromothercrs;
1.484.2.30 raeburn 1921: #need to copy the db contents to a new one, unless this is a move.
1922: my %info = (
1923: src => $url,
1924: cdom => $coursedom,
1925: cnum => $coursenum,
1.484.2.76 raeburn 1926: );
1927: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1928: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1929: $fromothercrs = 1;
1930: $info{'cdom'} = $srcdom{$suffix};
1931: $info{'cnum'} = $srcnum{$suffix};
1932: }
1933: }
1934: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1935: my (%lockerr,$msg);
1936: my ($newurl,$result,$errtext) =
1937: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1938: if ($result eq 'ok') {
1939: $url = $newurl;
1940: $title=&mt('Copy of').' '.$title;
1941: } else {
1942: if ($prefix eq 'smppg') {
1943: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1944: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1945: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.93.2. (raeburn 1946:): } elsif ($prefix eq 'ext.tool') {
1947:): $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.484.2.30 raeburn 1948: }
1949: $results{$suffix} = $result;
1950: $msgerrs{$suffix} = $msg;
1951: $lockerrs{$suffix} = $lockerr{$prefix};
1952: next;
1953: }
1954: if ($lockerr{$prefix}) {
1955: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1956: }
1.484.2.7 raeburn 1957: }
1.484.2.30 raeburn 1958: }
1959: $title = &LONCAPA::map::qtunescape($title);
1960: my $ext='false';
1961: if ($url=~m{^http(|s)://}) { $ext='true'; }
1962: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1963: if ($folder !~ /^supplemental/) {
1964: (undef,undef,$title) =
1965: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1966: }
1967: } else {
1968: if ($folder=~/^supplemental/) {
1969: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1970: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1971: }
1972: }
1.484.2.7 raeburn 1973:
1974: # For uploaded files (excluding pages/sequences) path in copied file is changed
1975: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1976: # courses.
1977:
1.484.2.30 raeburn 1978: unless ($is_map{$suffix}) {
1979: my $newidx;
1.329 droeschl 1980: # Now insert the URL at the bottom
1.484.2.30 raeburn 1981: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1982: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1983: my $relpath = $1;
1984: if ($relpath ne '') {
1985: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1986: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1987: my $newprefix = $newloc;
1988: if ($newloc eq 'default') {
1989: $newprefix = 'docs';
1990: }
1991: if ($newdocsdir eq '') {
1992: $newdocsdir = 'default';
1993: }
1994: if (($prefixchg{$suffix}) ||
1995: ($srcdom{$suffix} ne $coursedom) ||
1996: ($srcnum{$suffix} ne $coursenum) ||
1997: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1998: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1999: $url =
2000: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2001: &Apache::lonnet::getfile($oldurl));
2002: if ($url eq '/adm/notfound.html') {
2003: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2004: next;
2005: } else {
2006: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2007: $newsubpath =~ s{/+$}{/};
2008: $docmoves{$oldurl} = $newsubpath;
2009: }
1.484.2.7 raeburn 2010: }
2011: }
1.484.2.82 raeburn 2012: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2013: my $template = $1;
2014: if ($newidx) {
2015: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2016: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2017: }
1.484.2.7 raeburn 2018: }
1.484.2.30 raeburn 2019: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2020: ':'.$ext.':normal:res';
2021: push(@LONCAPA::map::order,$newidx);
2022: # Store the result
2023: my ($errtext,$fatal) =
2024: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2025: if ($fatal) {
2026: $save_err .= $errtext;
2027: $allresult = 'fail';
1.484.2.7 raeburn 2028: }
1.329 droeschl 2029: }
1.484.2.30 raeburn 2030:
1.484.2.82 raeburn 2031: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2032: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 2033: unless ($allresult eq 'fail') {
2034: my %updated = (
2035: rewrites => \%rewrites,
2036: zombies => \%zombies,
2037: removefrommap => \%removefrommap,
2038: removeparam => \%removeparam,
2039: dbcopies => \%dbcopies,
1.484.2.82 raeburn 2040: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 2041: retitles => \%retitles,
2042: );
2043: my %info = (
2044: newsubdir => \%newsubdir,
2045: params => \%params,
2046: );
2047: if ($prefixchg{$suffix}) {
2048: $info{'before'} = $before{$prefixchg{$suffix}};
2049: $info{'after'} = $after{$prefixchg{$suffix}};
2050: }
2051: my %moves = (
2052: copies => \%copies,
2053: docmoves => \%docmoves,
2054: mapmoves => \%mapmoves,
2055: );
2056: (my $result,$msgs{$suffix},my $lockerror) =
2057: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2058: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2059: $url,'paste');
2060: $lockerrors .= $lockerror;
2061: if ($result eq 'ok') {
2062: if ($is_map{$suffix}) {
2063: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2064: $folder.'.'.$container);
2065: if ($fatal) {
2066: $allresult = 'failread';
2067: } else {
2068: if ($#LONCAPA::map::order<1) {
2069: my $idx=&LONCAPA::map::getresidx();
2070: if ($idx<=0) { $idx=1; }
2071: $LONCAPA::map::order[0]=$idx;
2072: $LONCAPA::map::resources[$idx]='';
2073: }
2074: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2075: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2076: ':'.$ext.':normal:res';
2077: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 2078:
2079: # Store the result
1.484.2.30 raeburn 2080: my ($errtext,$fatal) =
2081: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2082: if ($fatal) {
2083: $save_err .= $errtext;
2084: $allresult = 'failstore';
2085: }
2086: }
2087: }
2088: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2089: push(@toclear,$suffix);
2090: }
2091: }
1.329 droeschl 2092: }
2093: }
1.484.2.30 raeburn 2094: &clear_from_buffer(\@toclear,\@currpaste);
2095: my $msgsarray;
2096: foreach my $suffix (keys(%msgs)) {
2097: if (ref($msgs{$suffix}) eq 'ARRAY') {
2098: $msgsarray .= join(',',@{$msgs{$suffix}});
2099: }
2100: }
2101: return ($allresult,$save_err,$msgsarray,$lockerrors);
2102: }
2103:
2104: sub do_buffer_empty {
2105: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2106: if (@currpaste == 0) {
2107: return &mt('Clipboard is already empty');
2108: }
2109: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2110: if (@toclear == 0) {
2111: return &mt('Nothing selected to clear from clipboard');
2112: }
2113: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2114: if ($numdel) {
2115: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2116: } else {
2117: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 2118: }
1.484.2.30 raeburn 2119: return;
2120: }
2121:
2122: sub clear_from_buffer {
2123: my ($toclear,$currpaste) = @_;
2124: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2125: my %pastebuffer;
2126: map { $pastebuffer{$_} = 1; } @{$currpaste};
2127: my $numdel = 0;
2128: foreach my $suffix (@{$toclear}) {
2129: next if ($suffix =~ /\D/);
2130: next unless (exists($pastebuffer{$suffix}));
2131: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2132: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2133: delete($pastebuffer{$suffix});
2134: $numdel ++;
2135: }
2136: }
2137: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2138: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2139: return $numdel;
1.484.2.7 raeburn 2140: }
2141:
2142: sub get_newmap_url {
2143: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2144: $titleref,$allmaps,$newurls) = @_;
2145: my $newurl;
2146: if ($url=~ m{^/uploaded/}) {
2147: $$titleref=&mt('Copy of').' '.$$titleref;
2148: }
2149: my $now = time;
2150: my $suffix=$$.int(rand(100)).$now;
2151: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2152: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2153: my $path = $1;
2154: my $prefix = $2;
2155: my $ancestor = $3;
2156: if (length($ancestor) > 10) {
2157: $ancestor = substr($ancestor,-10,10);
2158: }
2159: my $newid;
2160: if ($prefixchg) {
2161: if ($folder =~ /^supplemental/) {
2162: $prefix =~ s/^default/supplemental/;
2163: } else {
2164: $prefix =~ s/^supplemental/default/;
2165: }
2166: }
2167: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2168: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2169: } else {
2170: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2171: }
2172: my $counter = 0;
2173: my $is_unique = &uniqueness_check($newurl);
2174: if ($folder =~ /^default/) {
2175: if ($allmaps->{$newurl}) {
2176: $is_unique = 0;
2177: }
2178: }
2179: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2180: $counter ++;
2181: $suffix ++;
2182: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2183: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2184: } else {
2185: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2186: }
2187: $is_unique = &uniqueness_check($newurl);
2188: }
2189: if ($is_unique) {
2190: $newurls->{$newurl} = 1;
2191: } else {
2192: if ($url=~/\.page$/) {
2193: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2194: } else {
2195: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2196: }
2197: }
2198: }
2199: return ($newurl);
2200: }
2201:
2202: sub dbcopy {
1.484.2.26 raeburn 2203: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2204: my ($url,$result,$errtext);
2205: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2206: $url = $dbref->{'src'};
1.484.2.93.2. (raeburn 2207:): if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.484.2.26 raeburn 2208: my $prefix = $1;
1.484.2.93.2. (raeburn 2209:): if ($prefix eq 'ext.tool') {
2210:): $prefix = 'exttool';
2211:): }
1.484.2.26 raeburn 2212: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2213: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2214: my $db_name;
2215: my $marker = (split(m{/},$url))[4];
2216: $marker=~s/\D//g;
2217: if ($dbref->{'src'} =~ m{/smppg$}) {
2218: $db_name =
2219: &Apache::lonsimplepage::get_db_name($url,$marker,
2220: $dbref->{'cdom'},
2221: $dbref->{'cnum'});
1.484.2.93.2. (raeburn 2222:): } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2223:): $db_name = 'exttool_'.$marker;
1.484.2.26 raeburn 2224: } else {
2225: $db_name = 'bulletinpage_'.$marker;
2226: }
2227: my ($suffix,$freedlock,$error) =
2228: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2229: $coursedom,$coursenum,
2230: 'concat');
2231: if (!$suffix) {
2232: if ($prefix eq 'smppg') {
2233: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.484.2.93.2. (raeburn 2234:): } elsif ($prefix eq 'exttool') {
2235:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.484.2.26 raeburn 2236: } else {
1.484.2.42 raeburn 2237: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2238: }
2239: if ($error) {
2240: $errtext .= '<br />'.$error;
2241: }
2242: } else {
2243: #need to copy the db contents to a new one.
2244: my %contents=&Apache::lonnet::dump($db_name,
2245: $dbref->{'cdom'},
2246: $dbref->{'cnum'});
2247: if (exists($contents{'uploaded.photourl'})) {
2248: my $photo = $contents{'uploaded.photourl'};
2249: my ($subdir,$fname) =
2250: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2251: my $newphoto;
2252: if ($fname ne '') {
2253: my $content = &Apache::lonnet::getfile($photo);
2254: unless ($content eq '-1') {
2255: $env{'form.'.$suffix.'.photourl'} = $content;
2256: $newphoto =
2257: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2258: delete($env{'form.'.$suffix.'.photourl'});
2259: }
2260: }
2261: if ($newphoto =~ m{^/uploaded/}) {
2262: $contents{'uploaded.photourl'} = $newphoto;
2263: }
2264: }
2265: $db_name =~ s{_\d*$ }{_$suffix}x;
2266: $result=&Apache::lonnet::put($db_name,\%contents,
2267: $coursedom,$coursenum);
2268: if ($result eq 'ok') {
1.484.2.93.2. (raeburn 2269:): $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.484.2.26 raeburn 2270: }
2271: }
2272: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2273: $lockerrorsref->{$prefix} =
2274: '<div class="LC_error">'.
2275: &mt('There was a problem removing a lockfile.');
2276: if ($prefix eq 'smppg') {
2277: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2278: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.93.2. (raeburn 2279:): } elsif ($prefix eq 'exttool') {
2280:): $lockerrorsref->{$prefix} .=
2281:): ' '.&mt('This will prevent addition of more external tools to this course.');
1.484.2.26 raeburn 2282: } else {
1.484.2.42 raeburn 2283: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2284: }
1.484.2.38 raeburn 2285: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2286: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2287: '</div>';
1.484.2.26 raeburn 2288: }
2289: }
2290: } elsif ($url =~ m{/syllabus$}) {
2291: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2292: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2293: if (($dbref->{'cdom'} ne $coursedom) ||
2294: ($dbref->{'cnum'} ne $coursenum)) {
2295: my %contents=&Apache::lonnet::dump('syllabus',
2296: $dbref->{'cdom'},
2297: $dbref->{'cnum'});
2298: $result=&Apache::lonnet::put('syllabus',\%contents,
2299: $coursedom,$coursenum);
2300: }
2301: }
1.484.2.7 raeburn 2302: }
2303: }
1.484.2.26 raeburn 2304: return ($url,$result,$errtext);
1.329 droeschl 2305: }
2306:
1.484.2.82 raeburn 2307: sub copy_templated_files {
2308: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2309: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2310: my $srccontainer = 'sequence';
2311: if ($srcwaspage) {
2312: $srccontainer = 'page';
2313: }
2314: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2315: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2316: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2317: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2318: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2319: $template.'.problem';
2320: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2321: if ($template eq 'simpleproblem') {
2322: $srcprefix .= '.0.';
2323: my $weightprefix = $newprefix;
2324: $newprefix .= '.0.';
2325: my @simpleprobqtypes = qw(radio option string essay numerical);
2326: my $qtype=$srcparms{$srcprefix.'questiontype'};
2327: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2328: my %newdata = (
2329: $newprefix.'questiontype' => $qtype,
1.484.2.84 raeburn 2330: );
1.484.2.82 raeburn 2331: foreach my $type (@simpleprobqtypes) {
2332: if ($type eq $qtype) {
2333: $newdata{"$weightprefix.$type.weight"}=1;
2334: } else {
2335: $newdata{"$weightprefix.$type.weight"}=0;
2336: }
2337: }
2338: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2339: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2340: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2341: if ($qtype eq 'numerical') {
2342: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2343: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2344: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2345: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2346: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2347: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2348: unless (defined($maxfoils)) { $maxfoils=10; }
2349: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2350: if ($maxfoils<=0) { $maxfoils=10; }
2351: my $randomize=$srcparms{$srcprefix.'randomize'};
2352: unless (defined($randomize)) { $randomize='yes'; }
2353: unless ($randomize eq 'no') { $randomize='yes'; }
2354: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2355: $newdata{$newprefix.'randomize'} = $randomize;
2356: if ($qtype eq 'option') {
2357: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2358: }
2359: for (my $i=1; $i<=10; $i++) {
2360: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2361: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2362: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2363: }
2364:
2365: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2366: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2367: unless (defined($maxfoils)) { $maxfoils=10; }
2368: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2369: if ($maxfoils<=0) { $maxfoils=10; }
2370: my $randomize=$srcparms{$srcprefix.'randomize'};
2371: unless (defined($randomize)) { $randomize='yes'; }
2372: unless ($randomize eq 'no') { $randomize='yes'; }
2373: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2374: $newdata{$newprefix.'randomize'} = $randomize;
2375: if ($qtype eq 'option') {
2376: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2377: }
2378: for (my $i=1; $i<=10; $i++) {
2379: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2380: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2381: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2382: }
2383: } elsif ($qtype eq 'string') {
2384: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2385: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2386: }
2387: if (keys(%newdata)) {
2388: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2389: $coursenum);
2390: if ($putres eq 'ok') {
2391: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2392: }
2393: }
2394: }
2395: }
2396: }
2397:
1.329 droeschl 2398: sub uniqueness_check {
2399: my ($newurl) = @_;
2400: my $unique = 1;
2401: foreach my $res (@LONCAPA::map::order) {
2402: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2403: $url=&LONCAPA::map::qtescape($url);
2404: if ($newurl eq $url) {
2405: $unique = 0;
1.344 bisitz 2406: last;
1.329 droeschl 2407: }
2408: }
2409: return $unique;
2410: }
2411:
1.484.2.7 raeburn 2412: sub contained_map_check {
1.484.2.93.2. (raeburn 2413:): my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2414:): $hierarchy,$titles,$allmaps) = @_;
1.484.2.7 raeburn 2415: my $content = &Apache::lonnet::getfile($url);
2416: unless ($content eq '-1') {
2417: my $parser = HTML::TokeParser->new(\$content);
2418: $parser->attr_encoded(1);
2419: while (my $token = $parser->get_token) {
2420: next if ($token->[0] ne 'S');
2421: if ($token->[1] eq 'resource') {
2422: next if ($token->[2]->{'type'} eq 'zombie');
2423: my $ressrc = $token->[2]->{'src'};
2424: if ($folder =~ /^supplemental/) {
2425: unless (&supp_pasteable($ressrc)) {
2426: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2427: next;
2428: }
2429: }
2430: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2431: if ($1 eq 'uploaded') {
2432: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2433: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2434: } else {
2435: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2436: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2437: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2438: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2439: } else {
2440: $addedmaps->{$ressrc} = [$url];
2441: }
2442: }
1.484.2.93.2. (raeburn 2443:): &contained_map_check($ressrc,$folder,$coursenum,$coursedom,
2444:): $removefrommap,$removeparam,
1.484.2.7 raeburn 2445: $addedmaps,$hierarchy,$titles,$allmaps);
2446: }
2447: } elsif ($token->[1] eq 'param') {
2448: if ($folder =~ /^supplemental/) {
2449: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2450: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2451: } else {
1.484.2.19 raeburn 2452: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2453: }
2454: }
2455: }
2456: }
2457: }
2458: return;
2459: }
2460:
2461: sub url_paste_fixups {
1.484.2.26 raeburn 2462: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2463: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2464: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2465: my $checktitle;
2466: if (($prefixchg) &&
2467: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2468: $checktitle = 1;
2469: }
2470: my $skip;
2471: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2472: my $mapid = $1.$2;
2473: if ($tomove->{$mapid}) {
2474: $skip = 1;
2475: }
2476: }
2477: my $file = &Apache::lonnet::getfile($oldurl);
2478: return if ($file eq '-1');
2479: my $parser = HTML::TokeParser->new(\$file);
2480: $parser->attr_encoded(1);
2481: my $changed = 0;
2482: while (my $token = $parser->get_token) {
2483: next if ($token->[0] ne 'S');
2484: if ($token->[1] eq 'resource') {
2485: my $ressrc = $token->[2]->{'src'};
2486: next if ($ressrc eq '');
2487: my $id = $token->[2]->{'id'};
2488: my $title = $token->[2]->{'title'};
2489: if ($checktitle) {
2490: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2491: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2492: }
2493: }
2494: next if ($token->[2]->{'type'} eq 'external');
2495: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2496: next if ($skip);
1.484.2.25 raeburn 2497: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2498: $changed = 1;
2499: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2500: my $srcdom = $1;
2501: my $srcnum = $2;
2502: my $rem = $3;
2503: my $newurl;
2504: my $mapname;
2505: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2506: my $prefix = $1;
2507: $mapname = $prefix.$2;
2508: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2509: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2510: $srcdom,$srcnum,$allmaps,$rewrites,
2511: $retitles,$copies,$dbcopies,$zombies,
2512: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2513: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2514: next;
2515: } else {
2516: ($newurl,my $error) =
2517: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2518: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2519: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2520: $newsubdir->{$ressrc} = $1;
2521: }
2522: if ($error) {
2523: next;
2524: }
2525: }
2526: }
2527: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2528: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2529:
1.484.2.7 raeburn 2530: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2531: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2532: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2533: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2534: $cnum,$srcdom,$srcnum,$allmaps,
2535: $rewrites,$retitles,$copies,$dbcopies,
2536: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2537: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2538: $mapmoves->{$ressrc} = 1;
2539: }
2540: $changed = 1;
2541: } else {
1.484.2.25 raeburn 2542: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2543: $copies->{$oldurl}{$ressrc} = $id;
2544: $changed = 1;
2545: }
2546: }
1.484.2.26 raeburn 2547: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2548: next if ($skip);
1.484.2.7 raeburn 2549: my $srcdom = $1;
2550: my $srcnum = $2;
2551: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2552: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2553: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2554: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2555: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2556: $changed = 1;
2557: }
2558: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2559: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2560: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2561: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2562: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2563: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2564: $changed = 1;
2565: }
1.484.2.82 raeburn 2566: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2567: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2568: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2569: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2570: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2571: }
1.484.2.7 raeburn 2572: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2573: next if ($skip);
2574: my $srcdom = $1;
2575: my $srcnum = $2;
2576: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2577: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2578: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2579: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2580: $changed = 1;
2581: }
2582: }
2583: } elsif ($token->[1] eq 'param') {
2584: next if ($skip);
1.484.2.19 raeburn 2585: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2586: if ($to ne '') {
2587: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2588: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2589: } else {
2590: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2591: }
2592: }
2593: }
2594: }
2595: return $changed;
2596: }
2597:
2598: sub apply_fixups {
1.484.2.23 raeburn 2599: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2600: $oldurl,$url,$caller) = @_;
2601: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2602: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.82 raeburn 2603: %resdatacopy,%lockerrors,$lockmsg);
1.484.2.23 raeburn 2604: if (ref($updated) eq 'HASH') {
2605: if (ref($updated->{'rewrites'}) eq 'HASH') {
2606: %rewrites = %{$updated->{'rewrites'}};
2607: }
2608: if (ref($updated->{'zombies'}) eq 'HASH') {
2609: %zombies = %{$updated->{'zombies'}};
2610: }
2611: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2612: %removefrommap = %{$updated->{'removefrommap'}};
2613: }
2614: if (ref($updated->{'removeparam'}) eq 'HASH') {
2615: %removeparam = %{$updated->{'removeparam'}};
2616: }
2617: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2618: %dbcopies = %{$updated->{'dbcopies'}};
2619: }
2620: if (ref($updated->{'retitles'}) eq 'HASH') {
2621: %retitles = %{$updated->{'retitles'}};
2622: }
1.484.2.82 raeburn 2623: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2624: %resdatacopy = %{$updated->{'resdatacopy'}};
2625: }
1.484.2.23 raeburn 2626: }
2627: if (ref($info) eq 'HASH') {
2628: if (ref($info->{'newsubdir'}) eq 'HASH') {
2629: %newsubdir = %{$info->{'newsubdir'}};
2630: }
2631: if (ref($info->{'params'}) eq 'HASH') {
2632: %params = %{$info->{'params'}};
2633: }
2634: if (ref($info->{'before'}) eq 'HASH') {
2635: %before = %{$info->{'before'}};
2636: }
2637: if (ref($info->{'after'}) eq 'HASH') {
2638: %after = %{$info->{'after'}};
2639: }
2640: }
2641: if (ref($moves) eq 'HASH') {
2642: if (ref($moves->{'copies'}) eq 'HASH') {
2643: %copies = %{$moves->{'copies'}};
2644: }
2645: if (ref($moves->{'docmoves'}) eq 'HASH') {
2646: %docmoves = %{$moves->{'docmoves'}};
2647: }
2648: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2649: %mapmoves = %{$moves->{'mapmoves'}};
2650: }
2651: }
2652: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2653: my @allcopies;
1.484.2.23 raeburn 2654: if (exists($copies{$key})) {
2655: if (ref($copies{$key}) eq 'HASH') {
2656: my %added;
2657: foreach my $innerkey (keys(%{$copies{$key}})) {
2658: if (($innerkey ne '') && (!$added{$innerkey})) {
2659: push(@allcopies,$innerkey);
2660: $added{$innerkey} = 1;
2661: }
1.484.2.7 raeburn 2662: }
1.484.2.23 raeburn 2663: undef(%added);
1.484.2.7 raeburn 2664: }
2665: }
2666: if ($key eq $oldurl) {
1.484.2.23 raeburn 2667: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2668: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2669: push(@allcopies,$oldurl);
2670: }
2671: }
2672: }
2673: if (@allcopies > 0) {
2674: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2675: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2676: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2677: if ($fname ne '') {
2678: my $content = &Apache::lonnet::getfile($item);
2679: unless ($content eq '-1') {
2680: my $storefn;
1.484.2.23 raeburn 2681: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2682: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2683: } else {
2684: $storefn = $relpath;
2685: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2686: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2687: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2688: }
1.484.2.23 raeburn 2689: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2690: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2691: }
2692: }
2693: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2694: my $copyurl =
1.484.2.7 raeburn 2695: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2696: $storefn.$fname,$content);
2697: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2698: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2699: return &mt('Paste failed: an error occurred copying the file.');
2700: } elsif (ref($errors) eq 'HASH') {
2701: $errors->{$item} = 1;
2702: }
2703: }
2704: }
2705: }
2706: }
2707: }
2708: }
1.484.2.23 raeburn 2709: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2710: my $storefn=$key;
2711: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2712: if ($prefixchg && $before{'map'} && $after{'map'}) {
2713: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2714: }
1.484.2.23 raeburn 2715: if ($newsubdir{$key}) {
2716: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2717: }
2718: my $mapcontent = &Apache::lonnet::getfile($key);
1.484.2.93.2. (raeburn 2719:): if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
2720:): ($after{'map'} eq 'default') &&
2721:): ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
2722:): $mapcontent = '<map>'."\n".
2723:): '<resource id="1" src="" type="start" />'."\n".
2724:): '<link from="1" to="2" index="1" />'."\n".
2725:): '<resource id="2" src="" type="finish" />'."\n".
2726:): '</map>';
2727:): }
1.484.2.7 raeburn 2728: if ($mapcontent eq '-1') {
2729: if (ref($errors) eq 'HASH') {
2730: $errors->{$key} = 1;
2731: }
2732: } else {
2733: my $newmap =
2734: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2735: $mapcontent);
2736: if ($newmap eq '/adm/notfound.html') {
2737: if (ref($errors) eq 'HASH') {
2738: $errors->{$key} = 1;
2739: }
2740: }
2741: }
2742: }
2743: my %updates;
2744: if ($is_map) {
1.484.2.23 raeburn 2745: if (ref($updated) eq 'HASH') {
2746: foreach my $type (keys(%{$updated})) {
2747: if (ref($updated->{$type}) eq 'HASH') {
2748: foreach my $key (keys(%{$updated->{$type}})) {
2749: $updates{$key} = 1;
2750: }
2751: }
2752: }
1.484.2.7 raeburn 2753: }
2754: foreach my $key (keys(%updates)) {
2755: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2756: if (ref($rewrites{$key}) eq 'HASH') {
2757: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2758: }
1.484.2.23 raeburn 2759: if (ref($retitles{$key}) eq 'HASH') {
2760: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2761: }
1.484.2.23 raeburn 2762: if (ref($removefrommap{$key}) eq 'HASH') {
2763: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2764: }
1.484.2.23 raeburn 2765: if (ref($removeparam{$key}) eq 'HASH') {
2766: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2767: }
1.484.2.23 raeburn 2768: if (ref($zombies{$key}) eq 'HASH') {
2769: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2770: }
1.484.2.23 raeburn 2771: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2772: foreach my $idx (keys(%{$dbcopies{$key}})) {
2773: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2774: my ($newurl,$result,$errtext) =
2775: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2776: if ($result eq 'ok') {
2777: $newdb{$idx} = $newurl;
2778: } elsif (ref($errors) eq 'HASH') {
2779: $errors->{$key} = 1;
2780: }
2781: push(@msgs,$errtext);
2782: }
1.484.2.7 raeburn 2783: }
2784: }
1.484.2.82 raeburn 2785: if (ref($resdatacopy{$key}) eq 'HASH') {
2786: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2787: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2788: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2789: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2790: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2791: my $template = $1;
2792: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2793: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2794: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2795: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2796: unless ($gotnewmapname) {
2797: ($newmapname) = ($key =~ m{/([^/]+)$});
2798: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2799: if ($newsubdir{$key}) {
2800: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2801: }
2802: $gotnewmapname = 1;
2803: }
2804: my $srcmapinfo = $srcfolder.':'.$idx;
2805: if ($srccontainer eq 'page') {
2806: $srcmapinfo .= ':1';
2807: }
2808: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2809: $cnum,$template,$idx,$newmapname);
2810: }
2811: }
2812: }
2813: }
2814: }
1.484.2.23 raeburn 2815: if (ref($params{$key}) eq 'HASH') {
2816: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2817: }
2818: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2819: if ($fatal) {
1.484.2.26 raeburn 2820: return ($errtext);
1.484.2.7 raeburn 2821: }
2822: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2823: if (defined($LONCAPA::map::zombies[$i])) {
2824: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2825: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2826: undef($LONCAPA::map::zombies[$i]);
2827: }
2828: }
2829: }
1.484.2.77 raeburn 2830: my $total = scalar(@LONCAPA::map::order) - 1;
2831: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2832: my $idx = $LONCAPA::map::order[$i];
2833: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2834: my $changed;
1.484.2.23 raeburn 2835: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2836: if ((exists($toremove{$idx})) &&
2837: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2838: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2839: if (ref($currparam{$idx}) eq 'ARRAY') {
2840: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2841: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2842: }
2843: }
2844: next;
2845: }
2846: my $origsrc = $src;
1.484.2.25 raeburn 2847: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2848: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2849: $changed = 1;
2850: }
2851: }
1.484.2.25 raeburn 2852: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2853: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2854: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2855: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2856: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2857: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2858: } else {
1.484.2.23 raeburn 2859: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2860: }
2861: }
1.484.2.25 raeburn 2862: if ($origsrc =~ /\.(page|sequence)$/) {
2863: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2864: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2865: }
1.484.2.25 raeburn 2866: } elsif ($newsubdir{$key}) {
2867: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2868: }
2869: }
2870: $changed = 1;
1.484.2.26 raeburn 2871: } elsif ($newdb{$idx} ne '') {
2872: $src = $newdb{$idx};
1.484.2.7 raeburn 2873: $changed = 1;
2874: }
2875: if ($changed) {
1.484.2.30 raeburn 2876: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2877: }
2878: }
2879: }
2880: foreach my $idx (keys(%remparam)) {
2881: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2882: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2883: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2884: }
2885: }
2886: }
1.484.2.26 raeburn 2887: if (values(%lockerrors) > 0) {
2888: $lockmsg = join('<br />',values(%lockerrors));
2889: }
1.484.2.7 raeburn 2890: my $storefn;
2891: if ($key eq $oldurl) {
2892: $storefn = $url;
2893: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2894: } else {
2895: $storefn = $key;
2896: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2897: if ($prefixchg && $before{'map'} && $after{'map'}) {
2898: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2899: }
1.484.2.23 raeburn 2900: if ($newsubdir{$key}) {
2901: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2902: }
2903: }
2904: my $report;
2905: if ($folder !~ /^supplemental/) {
2906: $report = 1;
2907: }
1.484.2.20 raeburn 2908: (my $outtext,$errtext) =
1.484.2.7 raeburn 2909: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2910: if ($errtext) {
1.484.2.23 raeburn 2911: if ($caller eq 'paste') {
1.484.2.26 raeburn 2912: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2913: }
1.484.2.7 raeburn 2914: }
2915: }
2916: }
1.484.2.26 raeburn 2917: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2918: }
2919:
2920: sub copy_dependencies {
2921: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2922: my $content;
2923: if (ref($contentref)) {
2924: $content = $$contentref;
2925: } else {
2926: $content = &Apache::lonnet::getfile($item);
2927: }
2928: unless ($content eq '-1') {
2929: my $mm = new File::MMagic;
2930: my $mimetype = $mm->checktype_contents($content);
2931: if ($mimetype eq 'text/html') {
2932: my (%allfiles,%codebase,$state);
2933: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2934: if ($res eq 'ok') {
2935: my ($numexisting,$numpathchanges,$existing);
2936: (undef,$numexisting,$numpathchanges,$existing) =
2937: &Apache::loncommon::ask_for_embedded_content(
2938: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2939: {'error_on_invalid_names' => 1,
2940: 'ignore_remote_references' => 1,
2941: 'docs_url' => $item,
2942: 'context' => 'paste'});
2943: if ($numexisting > 0) {
2944: if (ref($existing) eq 'HASH') {
2945: foreach my $dep (keys(%{$existing})) {
2946: my $depfile = $dep;
2947: unless ($depfile =~ m{^\Q$relpath\E}) {
2948: $depfile = $relpath.$dep;
2949: }
2950: my $depcontent = &Apache::lonnet::getfile($depfile);
2951: unless ($depcontent eq '-1') {
2952: my $storedep = $dep;
2953: $storedep =~ s{^\Q$relpath\E}{};
2954: my $dep_url =
2955: &Apache::lonclonecourse::writefile(
2956: $env{'request.course.id'},
2957: $storefn.$storedep,$depcontent);
2958: if ($dep_url eq '/adm/notfound.html') {
2959: if (ref($errors) eq 'HASH') {
2960: $errors->{$depfile} = 1;
2961: }
2962: } else {
2963: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2964: }
2965: }
2966: }
2967: }
2968: }
2969: }
2970: }
2971: }
2972: return;
2973: }
2974:
1.329 droeschl 2975: my %parameter_type = ( 'randompick' => 'int_pos',
2976: 'hiddenresource' => 'string_yesno',
2977: 'encrypturl' => 'string_yesno',
2978: 'randomorder' => 'string_yesno',);
2979: my $valid_parameters_re = join('|',keys(%parameter_type));
2980: # set parameters
2981: sub update_parameter {
1.484.2.29 raeburn 2982: if ($env{'form.changeparms'} eq 'all') {
2983: my (@allidx,@allmapidx,%allchecked,%currchecked);
2984: %allchecked = (
2985: 'hiddenresource' => {},
2986: 'encrypturl' => {},
2987: 'randompick' => {},
2988: 'randomorder' => {},
2989: );
2990: foreach my $which (keys(%allchecked)) {
2991: $env{'form.all'.$which} =~ s/,$//;
2992: if ($which eq 'randompick') {
2993: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2994: my ($res,$value) = split(/:/,$item);
2995: if ($value =~ /^\d+$/) {
2996: $allchecked{$which}{$res} = $value;
2997: }
2998: }
2999: } else {
1.484.2.30 raeburn 3000: if ($env{'form.all'.$which}) {
3001: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3002: }
1.484.2.29 raeburn 3003: }
3004: }
3005: my $haschanges = 0;
3006: foreach my $res (@LONCAPA::map::order) {
3007: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3008: $name=&LONCAPA::map::qtescape($name);
3009: $url=&LONCAPA::map::qtescape($url);
3010: next unless ($name && $url);
3011: my $is_map;
3012: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3013: $is_map = 1;
3014: }
3015: foreach my $which (keys(%allchecked)) {
3016: if (($which eq 'randompick' || $which eq 'randomorder')) {
3017: next if (!$is_map);
3018: }
3019: my $oldvalue = 0;
3020: my $newvalue = 0;
3021: if ($allchecked{$which}{$res}) {
3022: $newvalue = $allchecked{$which}{$res};
3023: }
3024: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3025: if ($which eq 'randompick') {
3026: if ($current =~ /^(\d+)$/) {
3027: $oldvalue = $1;
3028: }
3029: } else {
3030: if ($current =~ /^yes$/i) {
3031: $oldvalue = 1;
3032: }
3033: }
3034: if ($oldvalue ne $newvalue) {
3035: $haschanges = 1;
3036: if ($newvalue) {
3037: my $storeval = 'yes';
3038: if ($which eq 'randompick') {
3039: $storeval = $newvalue;
3040: }
3041: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3042: $storeval,
3043: $parameter_type{$which});
3044: &remember_parms($res,$which,'set',$storeval);
3045: } elsif ($oldvalue) {
3046: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3047: &remember_parms($res,$which,'del');
3048: }
3049: }
3050: }
3051: }
3052: return $haschanges;
1.329 droeschl 3053: } else {
1.484.2.59 raeburn 3054: my $haschanges = 0;
3055: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 3056:
1.484.2.29 raeburn 3057: my $which = $env{'form.changeparms'};
3058: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 3059: my $oldvalue = 0;
3060: my $newvalue = 0;
3061: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3062: if ($which eq 'randompick') {
3063: if ($current =~ /^(\d+)$/) {
3064: $oldvalue = $1;
3065: }
3066: } elsif ($current =~ /^yes$/i) {
3067: $oldvalue = 1;
3068: }
1.484.2.29 raeburn 3069: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 3070: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3071: : 1;
1.484.2.29 raeburn 3072: }
1.484.2.59 raeburn 3073: if ($oldvalue ne $newvalue) {
3074: $haschanges = 1;
3075: if ($newvalue) {
3076: my $storeval = 'yes';
3077: if ($which eq 'randompick') {
3078: $storeval = $newvalue;
3079: }
3080: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3081: $parameter_type{$which});
3082: &remember_parms($idx,$which,'set',$storeval);
3083: } else {
3084: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3085: &remember_parms($idx,$which,'del');
3086: }
3087: }
3088: return $haschanges;
1.329 droeschl 3089: }
1.484.2.59 raeburn 3090: return;
1.329 droeschl 3091: }
3092:
3093: sub handle_edit_cmd {
3094: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 3095: if ($env{'form.cmd'} eq '') {
3096: return 0;
3097: }
1.329 droeschl 3098: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3099:
3100: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3101: my ($title, $url, @rrest) = split(':', $ratstr);
3102:
1.484.2.30 raeburn 3103: if ($cmd eq 'remove') {
1.329 droeschl 3104: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3105: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3106: &Apache::lonnet::removeuploadedurl($url);
3107: } else {
3108: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3109: }
3110: splice(@LONCAPA::map::order, $idx, 1);
3111:
3112: } elsif ($cmd eq 'cut') {
3113: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3114: splice(@LONCAPA::map::order, $idx, 1);
3115:
1.344 bisitz 3116: } elsif ($cmd eq 'up'
1.329 droeschl 3117: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3118: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3119:
3120: } elsif ($cmd eq 'down'
3121: && defined($LONCAPA::map::order[$idx+1])) {
3122: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3123:
3124: } elsif ($cmd eq 'rename') {
3125: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3126: if ($comment=~/\S/) {
3127: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3128: $comment.':'.join(':', $url, @rrest);
3129: }
3130: # Devalidate title cache
3131: my $renamed_url=&LONCAPA::map::qtescape($url);
3132: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 3133:
1.329 droeschl 3134: } else {
3135: return 0;
3136: }
3137: return 1;
3138: }
3139:
3140: sub editor {
1.458 raeburn 3141: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.93.2. (raeburn 3142:): $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3143:): $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 3144: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3145: if ($allowed) {
3146: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3147: $is_random_order,$container) =
3148: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3149: $r->print($breadcrumbtrail);
3150: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3151: $container = 'page';
3152: } else {
3153: $container = 'sequence';
3154: }
1.484 raeburn 3155:
1.484.2.21 raeburn 3156: my $jumpto;
3157:
3158: unless ($supplementalflag) {
1.484.2.32 raeburn 3159: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 3160: }
1.484 raeburn 3161:
3162: unless ($allowed) {
3163: $randompick = -1;
3164: }
3165:
1.484.2.67 raeburn 3166: my ($errtext,$fatal);
3167: if (($folder eq '') && (!$supplementalflag)) {
3168: if (@LONCAPA::map::order) {
3169: undef(@LONCAPA::map::order);
3170: undef(@LONCAPA::map::resources);
3171: undef(@LONCAPA::map::resparms);
3172: undef(@LONCAPA::map::zombies);
3173: }
3174: $folder = 'default';
3175: $container = 'sequence';
3176: } else {
3177: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3178: $folder.'.'.$container);
3179: return $errtext if ($fatal);
3180: }
1.329 droeschl 3181:
3182: if ($#LONCAPA::map::order<1) {
3183: my $idx=&LONCAPA::map::getresidx();
3184: if ($idx<=0) { $idx=1; }
3185: $LONCAPA::map::order[0]=$idx;
3186: $LONCAPA::map::resources[$idx]='';
3187: }
1.364 bisitz 3188:
1.329 droeschl 3189: # ------------------------------------------------------------ Process commands
3190:
3191: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 3192: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3193: # set parameters and change order
3194: &snapshotbefore();
3195:
3196: if (&update_parameter()) {
1.484.2.59 raeburn 3197: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3198: return $errtext if ($fatal);
3199: }
3200:
3201: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3202: # change order
3203: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3204: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3205:
3206: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3207: return $errtext if ($fatal);
3208: }
1.364 bisitz 3209:
1.329 droeschl 3210: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 3211: my %paste_errors;
1.484.2.26 raeburn 3212: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 3213: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3214: \%paste_errors);
1.484.2.30 raeburn 3215: if (ref($pastemsgarray) eq 'ARRAY') {
3216: if (@{$pastemsgarray} > 0) {
3217: $r->print('<p class="LC_info">'.
3218: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3219: '</p>');
3220: }
1.484.2.30 raeburn 3221: }
3222: if ($lockerror) {
3223: $r->print('<p class="LC_error">'.
3224: $lockerror.
3225: '</p>');
3226: }
3227: if ($save_error ne '') {
3228: return $save_error;
3229: }
3230: if ($paste_res) {
3231: my %errortext = &Apache::lonlocal::texthash (
3232: fail => 'Storage of folder contents failed',
3233: failread => 'Reading folder contents failed',
3234: failstore => 'Storage of folder contents failed',
3235: );
3236: if ($errortext{$paste_res}) {
3237: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3238: }
1.329 droeschl 3239: }
1.484.2.7 raeburn 3240: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3241: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3242: &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".
3243: '<ul>'."\n");
3244: foreach my $key (sort(keys(%paste_errors))) {
3245: $r->print('<li>'.$key.'</li>'."\n");
3246: }
3247: $r->print('</ul></p>'."\n");
3248: }
1.484.2.30 raeburn 3249: } elsif ($env{'form.clearmarked'}) {
3250: my $output = &do_buffer_empty();
3251: if ($output) {
3252: $r->print('<p class="LC_info">'.$output.'</p>');
3253: }
3254: }
1.329 droeschl 3255:
3256: $r->print($upload_output);
3257:
1.484.2.30 raeburn 3258: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3259: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3260: my $contentchg;
1.484.2.58 raeburn 3261: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3262: $contentchg = 1;
3263: }
3264: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3265: return $errtext if ($fatal);
3266: }
1.484.2.30 raeburn 3267:
3268: # Cut, copy and/or remove multiple resources
3269: if ($env{'form.multichange'}) {
3270: my %allchecked = (
3271: cut => {},
3272: remove => {},
3273: );
3274: my $needsupdate;
3275: foreach my $which (keys(%allchecked)) {
3276: $env{'form.multi'.$which} =~ s/,$//;
3277: if ($env{'form.multi'.$which}) {
3278: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3279: if (ref($allchecked{$which}) eq 'HASH') {
3280: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3281: }
3282: }
3283: }
3284: if ($needsupdate) {
3285: my $haschanges = 0;
3286: my %curr_groups = &Apache::longroup::coursegroups();
3287: my $total = scalar(@LONCAPA::map::order) - 1;
3288: for (my $i=$total; $i>=0; $i--) {
3289: my $res = $LONCAPA::map::order[$i];
3290: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3291: $name=&LONCAPA::map::qtescape($name);
3292: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3293: next unless $url;
1.484.2.30 raeburn 3294: my %denied =
3295: &action_restrictions($coursenum,$coursedom,$url,
3296: $env{'form.folderpath'},\%curr_groups);
3297: foreach my $which (keys(%allchecked)) {
3298: next if ($denied{$which});
3299: next unless ($allchecked{$which}{$res});
3300: if ($which eq 'remove') {
3301: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3302: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3303: &Apache::lonnet::removeuploadedurl($url);
3304: } else {
3305: &LONCAPA::map::makezombie($res);
3306: }
3307: splice(@LONCAPA::map::order,$i,1);
3308: $haschanges ++;
3309: } elsif ($which eq 'cut') {
3310: &LONCAPA::map::makezombie($res);
3311: splice(@LONCAPA::map::order,$i,1);
3312: $haschanges ++;
3313: }
3314: }
3315: }
3316: if ($haschanges) {
3317: ($errtext,$fatal) =
3318: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3319: return $errtext if ($fatal);
3320: }
3321: }
3322: }
3323:
1.329 droeschl 3324: # Group import/search
3325: if ($env{'form.importdetail'}) {
3326: my @imports;
3327: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3328: if (defined($item)) {
3329: my ($name,$url,$residx)=
1.484.2.26 raeburn 3330: map { &unescape($_); } split(/\=/,$item);
3331: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3332: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3333: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3334: if ($locknotfreed) {
3335: $r->print($locknotfreed);
3336: }
3337: if ($suffix) {
1.484.2.19 raeburn 3338: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3339: } else {
3340: return $errortxt;
3341: }
1.484.2.26 raeburn 3342: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3343: my $type = $1;
3344: my ($suffix,$errortxt,$locknotfreed) =
3345: &new_timebased_suffix($coursedom,$coursenum,$type);
3346: if ($locknotfreed) {
3347: $r->print($locknotfreed);
3348: }
3349: if ($suffix) {
3350: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3351: } else {
3352: return $errortxt;
3353: }
1.484.2.93.2. (raeburn 3354:): } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3355:): my ($suffix,$errortxt,$locknotfreed) =
3356:): &new_timebased_suffix($coursedom,$coursenum,'exttool');
3357:): if ($locknotfreed) {
3358:): $r->print($locknotfreed);
3359:): }
3360:): if ($suffix) {
3361:): $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3362:): } else {
3363:): return $errortxt;
3364:): }
1.484.2.27 raeburn 3365: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3366: if ($supplementalflag) {
3367: next unless ($1 eq 'supplemental');
3368: if ($folder eq 'supplemental') {
3369: next unless ($2 eq 'default');
3370: } else {
3371: next unless ($folder eq 'supplemental_'.$2);
3372: }
3373: } else {
3374: next unless ($1 eq 'docs');
3375: if ($folder eq 'default') {
3376: next unless ($2 eq 'default');
3377: } else {
3378: next unless ($folder eq 'default_'.$2);
3379: }
3380: }
1.484.2.15 raeburn 3381: }
1.329 droeschl 3382: push(@imports, [$name, $url, $residx]);
3383: }
3384: }
1.484.2.23 raeburn 3385: ($errtext,$fatal,my $fixuperrors) =
3386: &group_import($coursenum, $coursedom, $folder,$container,
1.484.2.93.2. (raeburn 3387:): 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3388: return $errtext if ($fatal);
1.484.2.23 raeburn 3389: if ($fixuperrors) {
3390: $r->print($fixuperrors);
3391: }
1.329 droeschl 3392: }
3393: # Loading a complete map
3394: if ($env{'form.loadmap'}) {
3395: if ($env{'form.importmap'}=~/\w/) {
3396: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3397: my ($title,$url,$ext,$type)=split(/\:/,$res);
3398: my $idx=&LONCAPA::map::getresidx($url);
3399: $LONCAPA::map::resources[$idx]=$res;
3400: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3401: }
3402: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3403: $folder.'.'.$container,1);
1.329 droeschl 3404: return $errtext if ($fatal);
3405: } else {
3406: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3407:
1.329 droeschl 3408: }
3409: }
3410: &log_differences($plain);
3411: }
3412: # ---------------------------------------------------------------- End commands
3413: # ---------------------------------------------------------------- Print screen
3414: my $idx=0;
3415: my $shown=0;
3416: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3417: $r->print('<div class="LC_Box">'.
1.432 raeburn 3418: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3419: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3420: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3421: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3422: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3423: '</ol>');
1.381 bisitz 3424: if ($randompick>=0) {
3425: $r->print('<p class="LC_warning">'
3426: .&mt('Caution: this folder is set to randomly pick a subset'
3427: .' of resources. Adding or removing resources from this'
3428: .' folder will change the set of resources that the'
3429: .' students see, resulting in spurious or missing credit'
3430: .' for completed problems, not limited to ones you'
3431: .' modify. Do not modify the contents of this folder if'
3432: .' it is in active student use.')
3433: .'</p>'
3434: );
3435: }
3436: if ($is_random_order) {
3437: $r->print('<p class="LC_warning">'
3438: .&mt('Caution: this folder is set to randomly order its'
3439: .' contents. Adding or removing resources from this folder'
3440: .' will change the order of resources shown.')
3441: .'</p>'
3442: );
3443: }
3444: $r->print('</div>');
1.364 bisitz 3445: }
1.381 bisitz 3446:
1.484.2.30 raeburn 3447: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3448: %filters = (
3449: canremove => [],
3450: cancut => [],
3451: cancopy => [],
3452: hiddenresource => [],
3453: encrypturl => [],
3454: randomorder => [],
3455: randompick => [],
3456: );
3457: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3458: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3459: foreach my $res (@LONCAPA::map::order) {
3460: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3461: $name=&LONCAPA::map::qtescape($name);
3462: $url=&LONCAPA::map::qtescape($url);
3463: unless ($name) { $name=(split(/\//,$url))[-1]; }
3464: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3465: push(@allidx,$res);
3466: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3467: push(@allmapidx,$res);
3468: }
1.484.2.67 raeburn 3469:
1.381 bisitz 3470: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3471: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3472: $pathitem,$supplementalflag,$container,
1.484.2.93.2. (raeburn 3473:): \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.484.2.80 raeburn 3474: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3475: $idx++;
3476: $shown++;
1.329 droeschl 3477: }
1.424 onken 3478: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3479:
1.484.2.30 raeburn 3480: my $need_save;
1.484.2.67 raeburn 3481: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3482: my $toolslink;
1.484.2.67 raeburn 3483: if ($allowed) {
1.484.2.31 raeburn 3484: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3485: .&Apache::loncommon::help_open_menu('Navigation Screen',
3486: 'Navigation_Screen',undef,'RAT')
3487: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3488: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3489: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3490: .'id="LC_content_toolbar_edittoplevel" '
3491: .'class="LC_toolbarItem" '
3492: .'title="'.&mt('Supplemental Content Editor').'">'
3493: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3494: }
1.484.2.19 raeburn 3495: if ($shown) {
3496: if ($allowed) {
3497: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3498: .&Apache::loncommon::start_data_table(undef,'contentlist')
3499: .&Apache::loncommon::start_data_table_header_row()
3500: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3501: .'<th colspan="2">'.&mt('Actions').'</th>'
3502: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3503: if ($folder !~ /^supplemental/) {
3504: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3505: }
1.484.2.29 raeburn 3506: $to_show .= &Apache::loncommon::end_data_table_header_row();
3507: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3508: $lists{'canhide'} = join(',',@allidx);
3509: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3510: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3511: 'randomorder','randompick');
3512: foreach my $item (@possfilters) {
3513: if (ref($filters{$item}) eq 'ARRAY') {
3514: if (@{$filters{$item}} > 0) {
3515: $lists{$item} = join(',',@{$filters{$item}});
3516: }
3517: }
3518: }
1.484.2.29 raeburn 3519: if (@allidx > 0) {
3520: my $path;
3521: if ($env{'form.folderpath'}) {
3522: $path =
3523: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3524: }
1.484.2.30 raeburn 3525: if (@allidx > 1) {
3526: $to_show .=
3527: &Apache::loncommon::continue_data_table_row().
3528: '<td colspan="2"> </td>'.
3529: '<td>'.
1.484.2.67 raeburn 3530: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3531: '</td>'.
3532: '<td> </td>'.
3533: '<td> </td>'.
3534: '<td colspan="4">'.
1.484.2.67 raeburn 3535: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3536: '</td>'.
3537: &Apache::loncommon::end_data_table_row();
3538: $need_save = 1;
3539: }
1.484.2.29 raeburn 3540: }
3541: }
3542: $to_show .= $output.' '
1.484.2.19 raeburn 3543: .&Apache::loncommon::end_data_table()
3544: .'<br style="line-height:2px;" />'
3545: .&Apache::loncommon::end_scrollbox();
3546: } else {
3547: $to_show .= $toolslink
3548: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3549: .$output.' '
3550: .&Apache::loncommon::end_data_table();
3551: }
3552: } else {
3553: if (!$allowed) {
3554: $to_show .= $toolslink;
1.393 raeburn 3555: }
1.484.2.67 raeburn 3556: my $noresmsg;
3557: if ($allowed && $hiddentop && !$supplementalflag) {
3558: $noresmsg = &mt('Main Content Hidden');
3559: } else {
3560: $noresmsg = &mt('Currently empty');
3561: }
1.484.2.19 raeburn 3562: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3563: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3564: .$noresmsg
1.484.2.19 raeburn 3565: .'</div>'
3566: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3567: }
3568: } else {
1.484.2.19 raeburn 3569: if ($shown) {
3570: $to_show = '<div>'
3571: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3572: .$output
3573: .&Apache::loncommon::end_data_table()
3574: .'</div>';
3575: } else {
3576: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3577: .&mt('Currently empty')
1.484.2.19 raeburn 3578: .'</div>'
3579: }
1.458 raeburn 3580: }
3581: my $tid = 1;
3582: if ($supplementalflag) {
3583: $tid = 2;
1.329 droeschl 3584: }
3585: if ($allowed) {
1.484 raeburn 3586: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3587: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3588: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3589: if ($canedit) {
1.484.2.67 raeburn 3590: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3591: }
1.460 raeburn 3592: } else {
3593: $r->print($to_show);
1.329 droeschl 3594: }
3595: return;
3596: }
3597:
1.484.2.30 raeburn 3598: sub multiple_check_form {
1.484.2.67 raeburn 3599: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3600: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3601: my $disabled;
3602: unless ($canedit) {
3603: $disabled = 'disabled="disabled"';
3604: }
1.484.2.30 raeburn 3605: my $output =
3606: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3607: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3608: '<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>'.
3609: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3610: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3611: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3612: if ($caller eq 'settings') {
3613: $output .=
3614: '<table><tr>'.
3615: '<td class="LC_docs_entry_parameter">'.
3616: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3617: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3618: '</label></span></td>'.
3619: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3620: '<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'".');"'.$disabled.' />'.&mt('Randomly Pick').'</label><span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" />'.
1.484.2.30 raeburn 3621: '</span></td>'.
3622: '</tr>'."\n".
3623: '<tr>'.
3624: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3625: '<span class="LC_nobreak"><label><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')"'.$disabled.' />'.&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'".')"'.$disabled.' />'.&mt('Random Order').
1.484.2.30 raeburn 3626: '</label></span>'.
3627: '</td></tr></table>'."\n";
3628: } else {
3629: $output .=
3630: '<table><tr>'.
3631: '<td class="LC_docs_entry_parameter">'.
3632: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3633: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3634: '</label></span></td>'.
3635: '<td class="LC_docs_entry_parameter">'.
3636: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3637: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3638: '</label></span></td>'."\n".
3639: '<td class="LC_docs_entry_parameter">'.
3640: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3641: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3642: '</label></span></td>'.
3643: '</tr></table>'."\n";
3644: }
3645: $output .=
3646: '</fieldset>'.
3647: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3648: if ($caller eq 'settings') {
3649: $output .=
3650: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3651: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3652: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3653: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3654: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3655: } elsif ($caller eq 'actions') {
3656: $output .=
3657: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3658: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3659: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3660: }
3661: $output .=
3662: '</form>'.
3663: '</div>';
3664: return $output;
3665: }
3666:
1.329 droeschl 3667: sub process_file_upload {
1.484.2.36 raeburn 3668: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3669: # upload a file, if present
1.484.2.36 raeburn 3670: my $filesize = length($env{'form.uploaddoc'});
3671: if (!$filesize) {
3672: $$upload_output = '<div class="LC_error">'.
3673: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3674: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3675: $filesize).'<br />'.
3676: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3677: '</div>';
3678: return;
3679: }
3680: my $quotatype = 'unofficial';
3681: if ($crstype eq 'Community') {
3682: $quotatype = 'community';
1.484.2.51 raeburn 3683: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3684: $quotatype = 'official';
1.484.2.45 raeburn 3685: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3686: $quotatype = 'textbook';
1.484.2.36 raeburn 3687: }
3688: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3689: $filesize = int($filesize/1000); #expressed in kb
3690: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3691: $env{'form.uploaddoc.filename'},$filesize,
3692: 'upload',$quotatype);
1.484.2.36 raeburn 3693: return if ($$upload_output);
3694: }
1.440 raeburn 3695: my ($parseaction,$showupload,$nextphase,$mimetype);
3696: if ($env{'form.parserflag'}) {
1.329 droeschl 3697: $parseaction = 'parse';
3698: }
3699: my $folder=$env{'form.folder'};
3700: if ($folder eq '') {
3701: $folder='default';
3702: }
3703: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3704: my $errtext='';
3705: my $fatal=0;
3706: my $container='sequence';
1.484.2.19 raeburn 3707: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3708: $container='page';
3709: }
3710: ($errtext,$fatal)=
1.484.2.27 raeburn 3711: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3712: if ($#LONCAPA::map::order<1) {
3713: $LONCAPA::map::order[0]=1;
3714: $LONCAPA::map::resources[1]='';
3715: }
3716: my $destination = 'docs/';
3717: if ($folder =~ /^supplemental/) {
3718: $destination = 'supplemental/';
3719: }
3720: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3721: $destination .= 'default/';
3722: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3723: $destination .= $2.'/';
3724: }
1.484.2.27 raeburn 3725: if ($fatal) {
3726: $$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>';
3727: return;
3728: }
1.440 raeburn 3729: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3730: my $newidx=&LONCAPA::map::getresidx();
3731: $destination .= $newidx;
1.439 raeburn 3732: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3733: $parseaction,$allfiles,
1.440 raeburn 3734: $codebase,undef,undef,undef,undef,
3735: undef,undef,\$mimetype);
3736: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3737: my $stored = $1;
3738: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3739: $stored.'</span>').'</p>';
3740: } else {
3741: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3742:
1.457 raeburn 3743: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3744: return;
3745: }
1.329 droeschl 3746: my $ext='false';
3747: if ($url=~m{^http://}) { $ext='true'; }
3748: $url = &LONCAPA::map::qtunescape($url);
3749: my $comment=$env{'form.comment'};
3750: $comment = &LONCAPA::map::qtunescape($comment);
3751: if ($folder=~/^supplemental/) {
3752: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3753: $env{'user.domain'}.'___&&&___'.$comment;
3754: }
3755:
3756: $LONCAPA::map::resources[$newidx]=
3757: $comment.':'.$url.':'.$ext.':normal:res';
3758: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3759: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3760: $folder.'.'.$container,1);
1.329 droeschl 3761: if ($fatal) {
1.457 raeburn 3762: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3763: return;
1.329 droeschl 3764: } else {
1.440 raeburn 3765: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3766: $$upload_output = $showupload;
1.384 raeburn 3767: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3768: if ($total_embedded > 0) {
1.440 raeburn 3769: my $uploadphase = 'upload_embedded';
3770: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3771: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3772: my ($embedded,$num) =
3773: &Apache::loncommon::ask_for_embedded_content(
3774: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3775: if ($embedded) {
3776: if ($num) {
3777: $$upload_output .=
3778: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3779: $nextphase = $uploadphase;
3780: } else {
3781: $$upload_output .= $embedded;
3782: }
3783: } else {
3784: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3785: }
1.329 droeschl 3786: } else {
1.440 raeburn 3787: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3788: }
1.457 raeburn 3789: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3790: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3791: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3792: $nextphase = 'decompress_uploaded';
3793: my $position = scalar(@LONCAPA::map::order)-1;
3794: my $noextract = &return_to_editor();
3795: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3796: my %archiveitems = (
3797: folderpath => $env{'form.folderpath'},
3798: cmd => $nextphase,
3799: newidx => $newidx,
3800: position => $position,
3801: phase => $nextphase,
1.477 raeburn 3802: comment => $comment,
1.480 raeburn 3803: );
3804: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3805: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3806: $$upload_output = $showupload.
3807: &Apache::loncommon::decompress_form($mimetype,
3808: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3809: \%archiveitems,\@current);
1.329 droeschl 3810: }
3811: }
3812: }
1.440 raeburn 3813: return $nextphase;
1.329 droeschl 3814: }
3815:
1.480 raeburn 3816: sub get_dir_list {
3817: my ($url,$coursenum,$coursedom,$newidx) = @_;
3818: my ($destination,$dir_root) = &embedded_destination();
3819: my ($dirlistref,$listerror) =
3820: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3821: my @dir_lines;
3822: my $dirptr=16384;
3823: if (ref($dirlistref) eq 'ARRAY') {
3824: foreach my $dir_line (sort
3825: {
3826: my ($afile)=split('&',$a,2);
3827: my ($bfile)=split('&',$b,2);
3828: return (lc($afile) cmp lc($bfile));
3829: } (@{$dirlistref})) {
3830: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3831: $filename =~ s/\s+$//;
3832: next if ($filename =~ /^\.\.?$/);
3833: my $isdir = 0;
3834: if ($dirptr&$testdir) {
3835: $isdir = 1;
3836: }
3837: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3838: }
3839: }
3840: return @dir_lines;
3841: }
3842:
1.329 droeschl 3843: sub is_supplemental_title {
3844: my ($title) = @_;
3845: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3846: }
3847:
3848: # --------------------------------------------------------------- An entry line
3849:
3850: sub entryline {
1.484.2.12 raeburn 3851: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3852: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.93.2. (raeburn 3853:): $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.484.2.52 raeburn 3854: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3855: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3856: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3857: } else {
3858: $title=&HTML::Entities::encode($title,'"<>&\'');
3859: $renametitle=$title;
3860: $foldertitle=$title;
3861: }
3862:
1.484.2.67 raeburn 3863: my ($disabled,$readonly,$js_lt);
3864: unless ($canedit) {
3865: $disabled = 'disabled="disabled"';
3866: $readonly = 1;
3867: }
3868:
1.329 droeschl 3869: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3870:
1.329 droeschl 3871: $renametitle=~s/\\/\\\\/g;
3872: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3873: $renametitle=~s/"/%22/g;
1.329 droeschl 3874: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3875: $oldtitle = $renametitle;
3876: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3877: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3878: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3879: # Edit commands
1.484.2.93.2. (raeburn 3880:): my ($esc_path, $path, $symb, $shownsymb);
1.329 droeschl 3881: if ($env{'form.folderpath'}) {
3882: $esc_path=&escape($env{'form.folderpath'});
3883: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3884: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3885: }
1.484.2.16 raeburn 3886: my $isexternal;
1.484.2.19 raeburn 3887: if ($residx) {
1.484.2.12 raeburn 3888: my $currurl = $url;
3889: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3890: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3891: $isexternal = 1;
3892: }
1.484.2.19 raeburn 3893: if (!$supplementalflag) {
3894: my $path = 'uploaded/'.
3895: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3896: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3897: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3898: $residx,
3899: &Apache::lonnet::declutter($currurl));
3900: }
1.484.2.12 raeburn 3901: }
1.484.2.30 raeburn 3902: my ($renamelink,%lt,$ishash);
3903: if (ref($filtersref) eq 'HASH') {
3904: $ishash = 1;
3905: }
3906:
1.329 droeschl 3907: if ($allowed) {
1.484.2.30 raeburn 3908: $form_start = '
3909: <form action="/adm/coursedocs" method="post">
3910: ';
3911: $form_common=(<<END);
3912: <input type="hidden" name="folderpath" value="$path" />
3913: <input type="hidden" name="symb" value="$symb" />
3914: END
3915: $form_param=(<<END);
3916: <input type="hidden" name="setparms" value="$orderidx" />
3917: <input type="hidden" name="changeparms" value="0" />
3918: END
3919: $form_end = '</form>';
3920:
1.329 droeschl 3921: my $incindex=$index+1;
3922: my $selectbox='';
1.471 raeburn 3923: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3924: ((split(/\:/,
1.344 bisitz 3925: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3926: ne '') &&
1.329 droeschl 3927: ((split(/\:/,
1.344 bisitz 3928: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3929: ne '')) {
3930: $selectbox=
3931: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3932: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3933: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3934: if ($i==$incindex) {
1.358 bisitz 3935: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3936: } else {
3937: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3938: }
3939: }
3940: $selectbox.='</select>';
3941: }
1.484.2.12 raeburn 3942: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3943: 'up' => 'Move Up',
3944: 'dw' => 'Move Down',
3945: 'rm' => 'Remove',
3946: 'ct' => 'Cut',
3947: 'rn' => 'Rename',
1.484.2.12 raeburn 3948: 'cp' => 'Copy',
3949: 'ex' => 'External Resource',
1.484.2.93.2. (raeburn 3950:): 'et' => 'External Tool',
1.484.2.12 raeburn 3951: 'ed' => 'Edit',
3952: 'pr' => 'Preview',
3953: 'sv' => 'Save',
3954: 'ul' => 'URL',
1.484.2.67 raeburn 3955: 'ti' => 'Title',
3956: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3957: );
1.484.2.30 raeburn 3958: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3959: $env{'form.folderpath'},
3960: $currgroups);
1.484.2.19 raeburn 3961: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3962: my $skip_confirm = 0;
1.484.2.63 raeburn 3963: my $confirm_removal = 0;
1.329 droeschl 3964: if ( $folder =~ /^supplemental/
3965: || ($url =~ m{( /smppg$
3966: |/syllabus$
3967: |/aboutme$
3968: |/navmaps$
3969: |/bulletinboard$
1.484.2.93.2. (raeburn 3970:): |/ext\.tool$
1.484.2.16 raeburn 3971: |\.html$)}x)
1.484.2.19 raeburn 3972: || $isexternal) {
1.329 droeschl 3973: $skip_confirm = 1;
3974: }
1.484.2.63 raeburn 3975: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3976: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3977: $confirm_removal = 1;
3978: }
1.484.2.19 raeburn 3979:
1.484.2.30 raeburn 3980: if ($denied{'copy'}) {
3981: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3982: <span style="visibility: hidden;">$lt{'cp'}</span>
3983: ENDCOPY
3984: } else {
1.484.2.30 raeburn 3985: my $formname = 'edit_copy_'.$orderidx;
3986: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3987: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3988: <form name="$formname" method="post" action="/adm/coursedocs">
3989: $form_common
1.484.2.67 raeburn 3990: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
1.484.2.30 raeburn 3991: $form_end
1.329 droeschl 3992: ENDCOPY
1.484.2.30 raeburn 3993: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3994: push(@{$filtersref->{'cancopy'}},$orderidx);
3995: }
1.329 droeschl 3996: }
1.484.2.30 raeburn 3997: if ($denied{'cut'}) {
1.484.2.16 raeburn 3998: $cutlink=(<<ENDCUT);
3999: <span style="visibility: hidden;">$lt{'ct'}</span>
4000: ENDCUT
4001: } else {
1.484.2.30 raeburn 4002: my $formname = 'edit_cut_'.$orderidx;
4003: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 4004: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 4005: <form name="$formname" method="post" action="/adm/coursedocs">
4006: $form_common
4007: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 4008: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
1.484.2.30 raeburn 4009: $form_end
1.329 droeschl 4010: ENDCUT
1.484.2.30 raeburn 4011: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4012: push(@{$filtersref->{'cancut'}},$orderidx);
4013: }
1.329 droeschl 4014: }
1.484.2.30 raeburn 4015: if ($denied{'remove'}) {
1.484.2.16 raeburn 4016: $removelink=(<<ENDREM);
4017: <span style="visibility: hidden;">$lt{'rm'}</a>
4018: ENDREM
4019: } else {
1.484.2.30 raeburn 4020: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 4021: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.484.2.9 raeburn 4022: $removelink=(<<ENDREM);
1.484.2.30 raeburn 4023: <form name="$formname" method="post" action="/adm/coursedocs">
4024: $form_common
4025: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 4026: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 4027: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
1.484.2.30 raeburn 4028: $form_end
1.484.2.9 raeburn 4029: ENDREM
1.484.2.30 raeburn 4030: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4031: push(@{$filtersref->{'canremove'}},$orderidx);
4032: }
1.484.2.9 raeburn 4033: }
1.484.2.35 raeburn 4034: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 4035: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 4036: ENDREN
1.484.2.67 raeburn 4037: my ($uplink,$downlink);
4038: if ($canedit) {
4039: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4040: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4041: } else {
4042: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4043: $downlink = $uplink;
4044: }
1.329 droeschl 4045: $line.=(<<END);
4046: <td>
1.379 bisitz 4047: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4048: <a href="$uplink">
1.484.2.12 raeburn 4049: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4050: </a>
4051: </div>
4052: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4053: <a href="$downlink">
1.484.2.12 raeburn 4054: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4055: </a>
4056: </div>
1.329 droeschl 4057: </td>
4058: <td>
4059: $form_start
1.484.2.30 raeburn 4060: $form_param
1.478 raeburn 4061: $form_common
1.329 droeschl 4062: $selectbox
4063: $form_end
4064: </td>
1.484.2.30 raeburn 4065: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 4066: $removelink
1.329 droeschl 4067: $cutlink
4068: $copylink
4069: </td>
4070: END
4071: }
4072: # Figure out what kind of a resource this is
4073: my ($extension)=($url=~/\.(\w+)$/);
4074: my $uploaded=($url=~/^\/*uploaded\//);
4075: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 4076: my $isfolder;
4077: my $ispage;
4078: my $containerarg;
1.484.2.67 raeburn 4079: my $folderurl;
1.329 droeschl 4080: if ($uploaded) {
1.472 raeburn 4081: if (($extension eq 'sequence') || ($extension eq 'page')) {
4082: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 4083: $containerarg = $1;
1.472 raeburn 4084: if ($extension eq 'sequence') {
4085: $icon=$iconpath.'navmap.folder.closed.gif';
4086: $isfolder=1;
4087: } else {
4088: $icon=$iconpath.'page.gif';
4089: $ispage=1;
4090: }
1.484.2.67 raeburn 4091: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4092: if ($allowed) {
4093: $url='/adm/coursedocs?';
4094: } else {
4095: $url='/adm/supplemental?';
4096: }
1.329 droeschl 4097: } else {
4098: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4099: }
4100: }
1.364 bisitz 4101:
1.484.2.70 raeburn 4102: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4103: my $orig_url = $url;
1.340 raeburn 4104: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 4105: if ($container eq 'page') {
4106: $url=~s{^http(|s)(:|:)//}{/ext/};
4107: } else {
4108: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4109: }
1.484.2.12 raeburn 4110: if (!$supplementalflag && $residx && $symb) {
4111: if ((!$isfolder) && (!$ispage)) {
4112: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.484.2.87 raeburn 4113: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4114: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4115: } else {
4116: $url=&Apache::lonnet::clutter($url);
4117: }
1.484.2.12 raeburn 4118: if ($url=~/^\/*uploaded\//) {
4119: $url=~/\.(\w+)$/;
4120: my $embstyle=&Apache::loncommon::fileembstyle($1);
4121: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4122: $url='/adm/wrapper'.$url;
4123: } elsif ($embstyle eq 'ssi') {
4124: #do nothing with these
4125: } elsif ($url!~/\.(sequence|page)$/) {
4126: $url='/adm/coursedocs/showdoc'.$url;
4127: }
1.484.2.70 raeburn 4128: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4129: my $wrapped = $1;
4130: my $exturl = $2;
1.484.2.87 raeburn 4131: if (($wrapped eq '') && ($container ne 'page')) {
1.484.2.70 raeburn 4132: $url='/adm/wrapper'.$url;
4133: }
4134: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4135: $nomodal = 1;
4136: }
1.484.2.93.2. (raeburn 4137:): } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4138:): $url='/adm/wrapper'.$url;
1.484.2.70 raeburn 4139: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4140: if (($ENV{'SERVER_PORT'} == 443) &&
4141: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 4142: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4143: $url .= '?usehttp=1';
4144: }
1.484.2.70 raeburn 4145: $nomodal = 1;
4146: }
1.484.2.19 raeburn 4147: }
1.484.2.12 raeburn 4148: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.93.2. (raeburn 4149:): $shownsymb = $symb;
1.484.2.66 raeburn 4150: if ($isexternal) {
1.484.2.88 raeburn 4151: $url =~ s/\#[^#]+$//;
1.484.2.87 raeburn 4152: if ($container eq 'page') {
4153: $url = &Apache::lonnet::clutter($url);
4154: }
1.484.2.66 raeburn 4155: }
1.484.2.67 raeburn 4156: unless ($env{'request.role.adv'}) {
4157: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4158: $url = '';
4159: }
4160: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4161: $url = '';
4162: $hiddenres = 1;
4163: }
4164: }
4165: if ($url ne '') {
1.484.2.75 raeburn 4166: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 4167: }
4168: } elsif (!$env{'request.role.adv'}) {
4169: my $checkencrypt;
4170: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4171: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4172: $checkencrypt = 1;
1.484.2.70 raeburn 4173: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 4174: unless (ref($$navmapref)) {
4175: $$navmapref = Apache::lonnavmaps::navmap->new();
4176: }
4177: if (ref($$navmapref)) {
4178: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4179: $checkencrypt = 1;
4180: }
4181: }
4182: }
4183: if ($checkencrypt) {
1.484.2.93.2. (raeburn 4184:): $shownsymb = &Apache::lonenc::encrypted($symb);
1.484.2.67 raeburn 4185: my $shownurl = &Apache::lonenc::encrypted($url);
4186: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.484.2.80 raeburn 4187: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 4188: if ($env{'request.enc'} ne '') {
4189: delete($env{'request.enc'});
4190: }
4191: } else {
4192: $url='';
4193: }
4194: } else {
4195: $url='';
4196: }
1.484.2.12 raeburn 4197: } else {
4198: $url='';
4199: }
1.484.2.19 raeburn 4200: }
1.484.2.66 raeburn 4201: } elsif ($supplementalflag) {
4202: if ($isexternal) {
4203: if ($url =~ /^([^#]+)#([^#]+)$/) {
4204: $url = $1;
4205: $anchor = $2;
1.484.2.70 raeburn 4206: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.93 raeburn 4207: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4208: if ($hostname ne '') {
4209: $url = 'http://'.$hostname.$url;
4210: }
4211: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4212: }
1.484.2.70 raeburn 4213: $nomodal = 1;
4214: }
4215: }
4216: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4217: if (($ENV{'SERVER_PORT'} == 443) &&
4218: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 4219: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4220: if ($hostname ne '') {
4221: $url = 'http://'.$hostname.$url;
4222: }
4223: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4224: }
1.484.2.70 raeburn 4225: $nomodal = 1;
1.484.2.66 raeburn 4226: }
4227: }
1.329 droeschl 4228: }
1.484.2.67 raeburn 4229: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4230: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4231: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4232: my $foldername=&escape($foldertitle);
4233: my $folderpath=$env{'form.folderpath'};
4234: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4235: if (!$allowed && $supplementalflag) {
4236: $folderpath.=$containerarg.'&'.$foldername;
4237: $url.='folderpath='.&escape($folderpath);
4238: } else {
4239: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4240: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4241: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4242: 'parameter_randomorder'))[0]=~/^yes$/i);
4243: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4244: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4245: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4246: 'parameter_encrypturl'))[0]=~/^yes$/i);
4247: unless ($hiddenmap) {
1.484.2.70 raeburn 4248: if (ref($navmapref)) {
4249: unless (ref($$navmapref)) {
4250: $$navmapref = Apache::lonnavmaps::navmap->new();
4251: }
4252: if (ref($$navmapref)) {
4253: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4254: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4255: unless (@resources) {
4256: $hiddenmap = 1;
4257: unless ($env{'request.role.adv'}) {
4258: $url = '';
4259: $hiddenfolder = 1;
4260: }
1.484.2.67 raeburn 4261: }
4262: }
4263: }
4264: }
4265: }
4266: unless ($encryptmap) {
1.484.2.70 raeburn 4267: if ((ref($navmapref)) && (ref($$navmapref))) {
4268: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4269: $encryptmap = 1;
4270: }
1.484.2.67 raeburn 4271: }
4272: }
4273:
4274: # Append randompick number, hidden, and encrypted with ":" to foldername,
4275: # so it gets transferred between levels
4276: $folderpath.=$containerarg.'&'.$foldername.
4277: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4278: unless ($url eq '') {
4279: $url.='folderpath='.&escape($folderpath);
4280: }
1.484.2.19 raeburn 4281: my $rpckchk;
4282: if ($rpicknum) {
4283: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4284: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4285: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4286: }
1.484.2.19 raeburn 4287: }
1.484.2.29 raeburn 4288: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4289: $rand_pick_text =
1.478 raeburn 4290: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4291: $form_param."\n".
1.478 raeburn 4292: $form_common."\n".
1.484.2.67 raeburn 4293: '<span class="LC_nobreak"><label><input type="checkbox" name="randompick_'.$orderidx.'" id="randompick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.$disabled.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="rpicknum_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" /><span id="randompicknum_'.$orderidx.'">';
1.484.2.19 raeburn 4294: if ($rpicknum ne '') {
4295: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4296: }
1.484.2.29 raeburn 4297: $rand_pick_text .= '</span></span>'.
4298: $form_end;
1.484.2.30 raeburn 4299: my $ro_set;
1.484.2.67 raeburn 4300: if ($randorder) {
1.484.2.30 raeburn 4301: $ro_set = 'checked="checked"';
4302: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4303: push(@{$filtersref->{'randomorder'}},$orderidx);
4304: }
4305: }
1.484.2.41 raeburn 4306: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4307: $rand_order_text =
1.484.2.29 raeburn 4308: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4309: $form_param."\n".
1.484.2.29 raeburn 4310: $form_common."\n".
1.484.2.67 raeburn 4311: '<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder','settings'".');" '.$ro_set.$disabled.' /> '.&mt('Random Order').' </label></span>'.
1.484.2.29 raeburn 4312: $form_end;
1.484.2.19 raeburn 4313: }
1.484.2.18 raeburn 4314: } elsif ($supplementalflag && !$allowed) {
1.484.2.93.2. (raeburn 4315:): my $isexttool;
4316:): if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4317:): $url='/adm/wrapper'.$url;
4318:): $isexttool = 1;
4319:): }
1.484.2.19 raeburn 4320: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4321: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4322: if ($title) {
4323: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4324: }
1.484.2.93.2. (raeburn 4325:): if ((($isexternal) || ($isexttool)) && $orderidx) {
1.484.2.19 raeburn 4326: $url .= '&idx='.$orderidx;
4327: }
1.484.2.66 raeburn 4328: if ($anchor ne '') {
4329: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4330: }
1.329 droeschl 4331: }
1.484.2.19 raeburn 4332: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4333: if ($allowed) {
1.484.2.19 raeburn 4334: my $fileloc =
1.484.2.12 raeburn 4335: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4336: if ($isexternal) {
4337: ($editlink,$extresform) =
1.484.2.67 raeburn 4338: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
1.484.2.93.2. (raeburn 4339:): undef,undef,undef,undef,undef,undef,
4340:): undef,$disabled);
4341:): } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4342:): ($editlink,$extresform) =
4343:): &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4344:): undef,undef,undef,'tool',$coursedom,
4345:): $coursenum,$ltitoolsref,$disabled);
1.484.2.19 raeburn 4346: } elsif (!$isfolder && !$ispage) {
4347: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4348: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4349: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4350: my $suppanchor;
4351: if ($supplementalflag) {
4352: $suppanchor = $anchor;
4353: }
1.484.2.19 raeburn 4354: my $jscall =
1.484.2.12 raeburn 4355: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4356: $switchserver,
1.484.2.14 raeburn 4357: $forceedit,
1.484.2.93.2. (raeburn 4358:): undef,$symb,$shownsymb,
1.484.2.19 raeburn 4359: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4360: $renametitle,$hostname,
4361: '','',1,$suppanchor);
1.484.2.12 raeburn 4362: if ($jscall) {
1.484.2.19 raeburn 4363: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4364: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4365: }
4366: }
4367: }
1.484.2.19 raeburn 4368: $tdalign = ' align="right" valign="top"';
4369: $tdwidth = ' width="80%"';
1.329 droeschl 4370: }
1.408 raeburn 4371: my $reinit;
4372: if ($crstype eq 'Community') {
4373: $reinit = &mt('(re-initialize community to access)');
4374: } else {
4375: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4376: }
4377: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4378: my $link;
1.472 raeburn 4379: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4380: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4381: } elsif ($url) {
1.484.2.66 raeburn 4382: if ($anchor ne '') {
4383: if ($supplementalflag) {
4384: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4385: } else {
4386: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4387: }
4388: }
1.484.2.80 raeburn 4389:
4390: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4391: $link = 'http://'.$hostname.$url;
4392: } else {
4393: $link = $url;
4394: }
4395: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4396: if ($nomodal) {
4397: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4398: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4399: } else {
4400: $line.=&Apache::loncommon::modal_link($link,
4401: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4402: }
1.469 www 4403: } else {
4404: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4405: }
1.484.2.19 raeburn 4406: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4407: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4408: $line.='<a href="'.$url.'">'.$title.'</a>';
4409: } elsif ($url) {
1.484.2.70 raeburn 4410: if ($nomodal) {
4411: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4412: $title.'</a>';
4413: } else {
4414: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4415: }
1.484.2.67 raeburn 4416: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4417: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4418: } else {
4419: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4420: }
1.484.2.19 raeburn 4421: $line.="$extresform</td>";
1.478 raeburn 4422: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4423: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4424: if (($allowed) && ($folder!~/^supplemental/)) {
4425: my %lt=&Apache::lonlocal::texthash(
4426: 'hd' => 'Hidden',
4427: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4428: my ($enctext,$hidtext);
4429: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4430: $enctext = ' checked="checked"';
4431: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4432: push(@{$filtersref->{'encrypturl'}},$orderidx);
4433: }
4434: }
4435: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4436: $hidtext = ' checked="checked"';
4437: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4438: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4439: }
4440: }
1.484.2.29 raeburn 4441: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4442: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4443: $line.=(<<ENDPARMS);
4444: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4445: <form action="/adm/coursedocs" method="post" name="$formhidden">
4446: $form_param
1.478 raeburn 4447: $form_common
1.484.2.67 raeburn 4448: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4449: $form_end
1.458 raeburn 4450: <br />
1.484.2.29 raeburn 4451: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4452: $form_param
1.478 raeburn 4453: $form_common
1.484.2.67 raeburn 4454: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4455: $form_end
4456: </td>
1.478 raeburn 4457: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4458: $rand_order_text</td>
1.329 droeschl 4459: ENDPARMS
4460: }
1.379 bisitz 4461: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4462: return $line;
4463: }
4464:
1.484.2.30 raeburn 4465: sub action_restrictions {
4466: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4467: my %denied = (
4468: cut => 0,
4469: copy => 0,
4470: remove => 0,
4471: );
4472: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4473: # no copy for published maps
4474: $denied{'copy'} = 1;
1.484.2.82 raeburn 4475: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4476: unless ($1 eq 'simpleproblem') {
4477: $denied{'copy'} = 1;
4478: }
4479: $denied{'cut'} = 1;
1.484.2.30 raeburn 4480: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4481: if ($folderpath =~ /^default&[^\&]+$/) {
4482: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4483: $denied{'remove'} = 1;
4484: }
4485: $denied{'cut'} = 1;
4486: $denied{'copy'} = 1;
4487: }
4488: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4489: my $group = $1;
4490: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4491: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4492: $denied{'remove'} = 1;
4493: }
4494: }
4495: $denied{'cut'} = 1;
4496: $denied{'copy'} = 1;
4497: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4498: my $group = $1;
4499: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4500: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4501: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4502: if (keys(%groupsettings) > 0) {
4503: $denied{'remove'} = 1;
4504: }
4505: $denied{'cut'} = 1;
4506: $denied{'copy'} = 1;
4507: }
4508: }
4509: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4510: my $group = $1;
4511: if ($url =~ /group_boards_\Q$group\E/) {
4512: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4513: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4514: if (keys(%groupsettings) > 0) {
4515: if (ref($groupsettings{'functions'}) eq 'HASH') {
4516: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4517: $denied{'remove'} = 1;
4518: }
4519: }
4520: }
4521: $denied{'cut'} = 1;
4522: $denied{'copy'} = 1;
4523: }
4524: }
4525: }
4526: return %denied;
4527: }
4528:
1.484.2.26 raeburn 4529: sub new_timebased_suffix {
1.484.2.30 raeburn 4530: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4531: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4532: if ($type eq 'paste') {
4533: $prefix = $type;
4534: $namespace = 'courseeditor';
1.484.2.56 raeburn 4535: $idtype = 'addcode';
1.484.2.30 raeburn 4536: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4537: $prefix = 'docs';
4538: if ($area eq 'supplemental') {
4539: $prefix = 'supp';
4540: }
4541: $prefix .= $container;
4542: $namespace = 'uploadedmaps';
4543: } else {
4544: $prefix = $type;
4545: $namespace = 'templated';
1.484.2.15 raeburn 4546: }
4547: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4548: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4549: if (!$suffix) {
1.484.2.30 raeburn 4550: if ($type eq 'paste') {
4551: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4552: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4553: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4554: } elsif ($type eq 'smppg') {
4555: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.484.2.93.2. (raeburn 4556:): } elsif ($type eq 'exttool') {
4557:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.484.2.26 raeburn 4558: } else {
1.484.2.42 raeburn 4559: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4560: }
1.484.2.15 raeburn 4561: if ($error) {
4562: $errtext .= '<br />'.$error;
4563: }
4564: }
4565: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4566: $locknotfreed =
4567: '<div class="LC_error">'.
4568: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4569: if ($type eq 'paste') {
1.484.2.57 raeburn 4570: if ($freedlock eq 'nolock') {
4571: $locknotfreed =
4572: '<div class="LC_error">'.
4573: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4574:
1.484.2.60 raeburn 4575: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4576: } else {
4577: $locknotfreed .=
4578: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4579: }
1.484.2.30 raeburn 4580: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4581: $locknotfreed .=
4582: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4583: } elsif ($type eq 'smppg') {
4584: $locknotfreed .=
4585: &mt('This will prevent creation of additional simple pages in this course.');
1.484.2.93.2. (raeburn 4586:): } elsif ($type eq 'exttool') {
4587:): $locknotfreed .=
4588:): &mt('This will prevent creation of additional external tools in this course.');
1.484.2.26 raeburn 4589: } else {
4590: $locknotfreed .=
1.484.2.42 raeburn 4591: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4592: }
1.484.2.30 raeburn 4593: unless ($type eq 'paste') {
4594: $locknotfreed .=
1.484.2.38 raeburn 4595: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4596: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4597: }
4598: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4599: }
4600: return ($suffix,$errtext,$locknotfreed);
4601: }
4602:
1.329 droeschl 4603: =pod
4604:
4605: =item tiehash()
4606:
4607: tie the hash
4608:
4609: =cut
4610:
4611: sub tiehash {
4612: my ($mode)=@_;
4613: $hashtied=0;
4614: if ($env{'request.course.fn'}) {
4615: if ($mode eq 'write') {
4616: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4617: &GDBM_WRCREAT(),0640)) {
4618: $hashtied=2;
4619: }
4620: } else {
4621: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4622: &GDBM_READER(),0640)) {
4623: $hashtied=1;
4624: }
4625: }
1.364 bisitz 4626: }
1.329 droeschl 4627: }
4628:
4629: sub untiehash {
4630: if ($hashtied) { untie %hash; }
4631: $hashtied=0;
4632: return OK;
4633: }
4634:
4635:
4636:
4637:
4638: sub checkonthis {
1.484.2.78 raeburn 4639: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4640: $url=&unescape($url);
4641: $alreadyseen{$url}=1;
4642: $r->rflush();
4643: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4644: $r->print("\n<br />");
4645: if ($level==0) {
4646: $r->print("<br />");
4647: }
4648: for (my $i=0;$i<=$level*5;$i++) {
4649: $r->print(' ');
4650: }
4651: $r->print('<a href="'.$url.'" target="cat">'.
4652: ($title?$title:$url).'</a> ');
4653: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4654: my $updated;
4655: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4656: ($url !~ /\.\d+\.\w+$/)) {
4657: $updated = &Apache::lonnet::remove_stale_resfile($url);
4658: }
1.329 droeschl 4659: my $result=&Apache::lonnet::repcopy(
4660: &Apache::lonnet::filelocation('',$url));
4661: if ($result eq 'ok') {
4662: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4663: if ($updated) {
4664: $r->print('<br />');
4665: for (my $i=0;$i<=$level*5;$i++) {
4666: $r->print(' ');
4667: }
4668: $r->print('- '.&mt('Outdated copy removed'));
4669: }
1.329 droeschl 4670: $r->rflush();
4671: &Apache::lonnet::countacc($url);
4672: $url=~/\.(\w+)$/;
4673: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4674: $r->print('<br />');
4675: $r->rflush();
4676: for (my $i=0;$i<=$level*5;$i++) {
4677: $r->print(' ');
4678: }
4679: $r->print('- '.&mt('Rendering:').' ');
4680: my ($errorcount,$warningcount)=split(/:/,
4681: &Apache::lonnet::ssi_body($url,
4682: ('grade_target'=>'web',
4683: 'return_only_error_and_warning_counts' => 1)));
4684: if (($errorcount) ||
4685: ($warningcount)) {
4686: if ($errorcount) {
1.369 bisitz 4687: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4688: &mt('[quant,_1,error]',$errorcount).'</span>');
4689: }
4690: if ($warningcount) {
4691: $r->print('<span class="LC_warning">'.
4692: &mt('[quant,_1,warning]',$warningcount).'</span>');
4693: }
4694: } else {
4695: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4696: }
4697: $r->rflush();
4698: }
4699: my $dependencies=
4700: &Apache::lonnet::metadata($url,'dependencies');
4701: foreach my $dep (split(/\,/,$dependencies)) {
4702: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4703: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4704: }
4705: }
4706: } elsif ($result eq 'unavailable') {
4707: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4708: } elsif ($result eq 'not_found') {
4709: unless ($url=~/\$/) {
1.484.2.19 raeburn 4710: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4711: } else {
1.366 bisitz 4712: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4713: }
4714: } else {
4715: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4716: }
1.484.2.78 raeburn 4717: if (($updated) && ($result ne 'ok')) {
4718: $r->print('<br />'.&mt('Outdated copy removed'));
4719: }
1.329 droeschl 4720: }
4721: }
4722: }
4723:
4724:
4725:
4726: =pod
4727:
4728: =item list_symbs()
4729:
1.484.2.3 raeburn 4730: List Content Identifiers
1.329 droeschl 4731:
4732: =cut
4733:
4734: sub list_symbs {
4735: my ($r) = @_;
4736:
1.408 raeburn 4737: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4738: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4739: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4740: $r->print(&startContentScreen('tools'));
1.329 droeschl 4741: my $navmap = Apache::lonnavmaps::navmap->new();
4742: if (!defined($navmap)) {
4743: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4744: '<div class="LC_error">'.
4745: &mt('Unable to retrieve information about course contents').
4746: '</div>');
1.408 raeburn 4747: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4748: } else {
1.484 raeburn 4749: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4750: &Apache::loncommon::start_data_table().
4751: &Apache::loncommon::start_data_table_header_row().
4752: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4753: &Apache::loncommon::end_data_table_header_row()."\n");
4754: my $count;
1.329 droeschl 4755: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4756: $r->print(&Apache::loncommon::start_data_table_row().
4757: '<td>'.$res->compTitle().'</td>'.
4758: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4759: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4760: $count ++;
4761: }
4762: if (!$count) {
4763: $r->print(&Apache::loncommon::start_data_table_row().
4764: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4765: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4766: }
1.484 raeburn 4767: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4768: }
1.484.2.19 raeburn 4769: $r->print(&endContentScreen());
1.329 droeschl 4770: }
4771:
1.484.2.93.2. (raeburn 4772:): sub short_urls {
4773:): my ($r,$canedit) = @_;
4774:): my $crstype = &Apache::loncommon::course_type();
4775:): my $formname = 'shortenurl';
4776:): $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4777:): $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4778:): $r->print(&startContentScreen('tools'));
4779:): my ($navmap,$errormsg) =
4780:): &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4781:): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4782:): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4783:): my (%maps,%resources,%titles);
4784:): if (!ref($navmap)) {
4785:): $r->print($errormsg.
4786:): &endContentScreen());
4787:): return '';
4788:): } else {
4789:): $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
4790:): $r->rflush();
4791:): my $readonly;
4792:): if ($canedit) {
4793:): my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
4794:): if ($numnew) {
4795:): $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4796:): }
4797:): if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4798:): $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4799:): foreach my $error (@{$errors}) {
4800:): $r->print('<li>'.$error.'</li>');
4801:): }
4802:): $r->print('</ul><br />');
4803:): }
4804:): } else {
4805:): $readonly = 1;
4806:): }
4807:): my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4808:): $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4809:): undef,undef,undef,undef,undef,\%currtiny,$readonly));
4810:): }
4811:): $r->print(&endContentScreen());
4812:): }
4813:):
1.484.2.78 raeburn 4814: sub contentverifyform {
4815: my ($r) = @_;
4816: my $crstype = &Apache::loncommon::course_type();
4817: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4818: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4819: $r->print(&startContentScreen('tools'));
4820: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4821: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4822: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4823: ' <span class="LC_nobreak">'.
4824: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4825: &mt('No').'</label>'.(' 'x2).
4826: '<label><input type="radio" name="checkstale" value="1" />'.
4827: &mt('Yes').'</label></span></p><p>'.
1.484.2.90 raeburn 4828: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.484.2.78 raeburn 4829: '<input type="hidden" value="1" name="tools" />'.
4830: '<input type="hidden" value="1" name="verify" /></p></form>');
4831: $r->print(&endContentScreen());
4832: return;
4833: }
1.329 droeschl 4834:
4835: sub verifycontent {
1.484.2.78 raeburn 4836: my ($r,$checkstale) = @_;
1.408 raeburn 4837: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4838: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4839: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4840: $r->print(&startContentScreen('tools'));
4841: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4842: $hashtied=0;
4843: undef %alreadyseen;
4844: %alreadyseen=();
4845: &tiehash();
1.484 raeburn 4846:
1.329 droeschl 4847: foreach my $key (keys(%hash)) {
4848: if ($hash{$key}=~/\.(page|sequence)$/) {
4849: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4850: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4851: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4852: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4853: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4854: }
4855: }
4856: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4857: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4858: }
4859: }
4860: &untiehash();
1.442 www 4861: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4862: $r->print(&endContentScreen());
1.329 droeschl 4863: }
4864:
4865:
4866: sub devalidateversioncache {
4867: my $src=shift;
4868: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4869: &Apache::lonnet::clutter($src));
4870: }
4871:
4872: sub checkversions {
1.484.2.67 raeburn 4873: my ($r,$canedit) = @_;
1.408 raeburn 4874: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4875: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4876: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4877: $r->print(&startContentScreen('tools'));
1.442 www 4878:
1.329 droeschl 4879: my $header='';
4880: my $startsel='';
4881: my $monthsel='';
4882: my $weeksel='';
4883: my $daysel='';
4884: my $allsel='';
4885: my %changes=();
4886: my $starttime=0;
4887: my $haschanged=0;
4888: my %setversions=&Apache::lonnet::dump('resourceversions',
4889: $env{'course.'.$env{'request.course.id'}.'.domain'},
4890: $env{'course.'.$env{'request.course.id'}.'.num'});
4891:
4892: $hashtied=0;
4893: &tiehash();
1.484.2.67 raeburn 4894: if ($canedit) {
4895: my %newsetversions=();
4896: if ($env{'form.setmostrecent'}) {
4897: $haschanged=1;
4898: foreach my $key (keys(%hash)) {
4899: if ($key=~/^ids\_(\/res\/.+)$/) {
4900: $newsetversions{$1}='mostrecent';
4901: &devalidateversioncache($1);
4902: }
1.329 droeschl 4903: }
1.484.2.67 raeburn 4904: } elsif ($env{'form.setcurrent'}) {
4905: $haschanged=1;
4906: foreach my $key (keys(%hash)) {
4907: if ($key=~/^ids\_(\/res\/.+)$/) {
4908: my $getvers=&Apache::lonnet::getversion($1);
4909: if ($getvers>0) {
4910: $newsetversions{$1}=$getvers;
4911: &devalidateversioncache($1);
4912: }
4913: }
1.329 droeschl 4914: }
1.484.2.67 raeburn 4915: } elsif ($env{'form.setversions'}) {
4916: $haschanged=1;
4917: foreach my $key (keys(%env)) {
4918: if ($key=~/^form\.set_version_(.+)$/) {
4919: my $src=$1;
4920: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4921: $newsetversions{$src}=$env{$key};
4922: &devalidateversioncache($src);
4923: }
4924: }
1.329 droeschl 4925: }
1.484.2.67 raeburn 4926: }
4927: if ($haschanged) {
4928: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4929: $env{'course.'.$env{'request.course.id'}.'.domain'},
4930: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4931: $r->print(&Apache::loncommon::confirmwrapper(
4932: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4933: } else {
4934: $r->print(&Apache::loncommon::confirmwrapper(
4935: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4936: }
4937: &mark_hash_old();
4938: }
4939: &changewarning($r,'');
1.329 droeschl 4940: }
4941: if ($env{'form.timerange'} eq 'all') {
4942: # show all documents
1.484.2.34 raeburn 4943: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4944: $allsel=' selected="selected"';
1.329 droeschl 4945: foreach my $key (keys(%hash)) {
4946: if ($key=~/^ids\_(\/res\/.+)$/) {
4947: my $src=$1;
4948: $changes{$src}=1;
4949: }
4950: }
4951: } else {
4952: # show documents which changed
4953: %changes=&Apache::lonnet::dump
4954: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4955: $env{'course.'.$env{'request.course.id'}.'.num'});
4956: my $firstkey=(keys(%changes))[0];
4957: unless ($firstkey=~/^error\:/) {
4958: unless ($env{'form.timerange'}) {
4959: $env{'form.timerange'}=604800;
4960: }
4961: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4962: .&mt('seconds');
4963: if ($env{'form.timerange'}==-1) {
4964: $seltext='since start of course';
1.484.2.19 raeburn 4965: $startsel=' selected="selected"';
1.329 droeschl 4966: $env{'form.timerange'}=time;
4967: }
4968: $starttime=time-$env{'form.timerange'};
4969: if ($env{'form.timerange'}==2592000) {
4970: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4971: $monthsel=' selected="selected"';
1.329 droeschl 4972: } elsif ($env{'form.timerange'}==604800) {
4973: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4974: $weeksel=' selected="selected"';
1.329 droeschl 4975: } elsif ($env{'form.timerange'}==86400) {
4976: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4977: $daysel=' selected="selected"';
1.329 droeschl 4978: }
4979: $header=&mt('Content changed').' '.$seltext;
4980: } else {
4981: $header=&mt('No content modifications yet.');
4982: }
4983: }
4984: %setversions=&Apache::lonnet::dump('resourceversions',
4985: $env{'course.'.$env{'request.course.id'}.'.domain'},
4986: $env{'course.'.$env{'request.course.id'}.'.num'});
4987: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4988: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4989: 'lm' => 'Version changes since last Month',
4990: 'lw' => 'Version changes since last Week',
4991: 'sy' => 'Version changes since Yesterday',
4992: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4993: 'cd' => 'Change display',
1.329 droeschl 4994: 'sd' => 'Display',
4995: 'fi' => 'File',
4996: 'md' => 'Modification Date',
4997: 'mr' => 'Most recently published Version',
1.408 raeburn 4998: 've' => 'Version used in '.$crstype,
4999: 'vu' => 'Set Version to be used in '.$crstype,
5000: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5001: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5002: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5003: 'di' => 'Differences',
1.484 raeburn 5004: 'save' => 'Save changes',
5005: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5006: 'act' => 'Actions');
1.484.2.67 raeburn 5007: my ($disabled,$readonly);
5008: unless ($canedit) {
5009: $disabled = 'disabled="disabled"';
5010: $readonly = 1;
5011: }
1.329 droeschl 5012: $r->print(<<ENDHEADERS);
1.484 raeburn 5013: <h4 class="LC_info">$header</h4>
1.329 droeschl 5014: <form action="/adm/coursedocs" method="post">
5015: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5016: <div class="LC_left_float">
1.479 golterma 5017: <fieldset>
1.484 raeburn 5018: <legend>$lt{'cd'}</legend>
1.329 droeschl 5019: <select name="timerange">
1.484.2.19 raeburn 5020: <option value='all'$allsel>$lt{'al'}</option>
5021: <option value="-1"$startsel>$lt{'st'}</option>
5022: <option value="2592000"$monthsel>$lt{'lm'}</option>
5023: <option value="604800"$weeksel>$lt{'lw'}</option>
5024: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5025: </select>
5026: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5027: </fieldset>
5028: </div>
5029: <div class="LC_left_float">
5030: <fieldset>
5031: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 5032: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5033: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5034: </fieldset>
5035: </div>
5036: <br clear="all" />
5037: <hr />
5038: <h4>$lt{'vers'}</h4>
1.329 droeschl 5039: ENDHEADERS
1.479 golterma 5040: #number of columns for version history
1.484.2.44 raeburn 5041: my %changedbytime;
5042: foreach my $key (keys(%changes)) {
5043: #excludes not versionable problems from resource version history:
5044: next if ($key =~ /^\/res\/lib\/templates/);
5045: my $chg;
5046: if ($env{'form.timerange'} eq 'all') {
5047: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5048: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5049: } else {
5050: $chg = $changes{$key};
5051: next if ($chg < $starttime);
5052: }
5053: push(@{$changedbytime{$chg}},$key);
5054: }
5055: if (keys(%changedbytime) == 0) {
5056: &untiehash();
5057: $r->print(&mt('No content changes in imported content in specified time frame').
5058: &endContentScreen());
5059: return;
5060: }
1.479 golterma 5061: $r->print(
1.484.2.67 raeburn 5062: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5063: &Apache::loncommon::start_data_table().
5064: &Apache::loncommon::start_data_table_header_row().
5065: '<th>'.&mt('Resources').'</th>'.
5066: "<th>$lt{'mr'}</th>".
5067: "<th>$lt{'ve'}</th>".
5068: "<th>$lt{'vu'}</th>".
5069: '<th>'.&mt('History').'</th>'.
5070: &Apache::loncommon::end_data_table_header_row()
5071: );
1.484.2.44 raeburn 5072: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5073: foreach my $key (sort(@{$changedbytime{$chg}})) {
5074: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5075: my $currentversion=&Apache::lonnet::getversion($key);
5076: if ($currentversion<0) {
5077: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5078: }
5079: my $linkurl=&Apache::lonnet::clutter($key);
5080: $r->print(
5081: &Apache::loncommon::start_data_table_row().
5082: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5083: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5084: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5085: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5086: '<td align="right">'
5087: );
5088: # Used in course
5089: my $usedversion=$hash{'version_'.$linkurl};
5090: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 5091: if ($usedversion != $currentversion) {
1.479 golterma 5092: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 5093: } else {
1.479 golterma 5094: $r->print($usedversion);
5095: }
1.329 droeschl 5096: } else {
1.484.2.19 raeburn 5097: $r->print($currentversion);
1.329 droeschl 5098: }
1.484.2.44 raeburn 5099: $r->print('</td><td title="'.$lt{'vu'}.'">');
5100: # Set version
5101: $r->print(&Apache::loncommon::select_form(
5102: $setversions{$linkurl},
5103: 'set_version_'.$linkurl,
5104: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5105: '' => '',
5106: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 5107: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 5108: my $lastold=1;
5109: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5110: my $url=$root.'.'.$prevvers.'.'.$extension;
5111: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5112: $lastold=$prevvers;
5113: }
5114: }
5115: $r->print('</td>');
5116: # List all available versions
5117: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5118: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5119: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 5120: $r->print(
1.484.2.44 raeburn 5121: '<span class="LC_nobreak">'
5122: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5123: .&mt('Version [_1]',$prevvers).'</a>'
5124: .' ('.&Apache::lonlocal::locallocaltime(
5125: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5126: .')');
5127: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5128: $r->print(
5129: ' <a href="/adm/diff?filename='.
5130: &Apache::lonnet::clutter($root.'.'.$extension).
5131: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5132: '" target="diffs">'.&mt('Diffs').'</a>');
5133: }
5134: $r->print('</span><br />');
1.329 droeschl 5135: }
1.484.2.44 raeburn 5136: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 5137: }
1.329 droeschl 5138: }
1.484.2.19 raeburn 5139: $r->print(
5140: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 5141: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5142: '</form>'
5143: );
1.329 droeschl 5144:
5145: &untiehash();
1.484.2.19 raeburn 5146: $r->print(&endContentScreen());
1.484.2.44 raeburn 5147: return;
1.329 droeschl 5148: }
5149:
5150: sub mark_hash_old {
5151: my $retie_hash=0;
5152: if ($hashtied) {
5153: $retie_hash=1;
5154: &untiehash();
5155: }
5156: &tiehash('write');
5157: $hash{'old'}=1;
5158: &untiehash();
5159: if ($retie_hash) { &tiehash(); }
5160: }
5161:
5162: sub is_hash_old {
5163: my $untie_hash=0;
5164: if (!$hashtied) {
5165: $untie_hash=1;
5166: &tiehash();
5167: }
5168: my $return=$hash{'old'};
5169: if ($untie_hash) { &untiehash(); }
5170: return $return;
5171: }
5172:
5173: sub changewarning {
5174: my ($r,$postexec,$message,$url)=@_;
5175: if (!&is_hash_old()) { return; }
5176: my $pathvar='folderpath';
5177: my $path=&escape($env{'form.folderpath'});
5178: if (!defined($url)) {
5179: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5180: }
5181: my $course_type = &Apache::loncommon::course_type();
5182: if (!defined($message)) {
5183: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5184: }
5185: $r->print("\n\n".
1.372 bisitz 5186: '<script type="text/javascript">'."\n".
5187: '// <![CDATA['."\n".
5188: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5189: '// ]]>'."\n".
1.369 bisitz 5190: '</script>'."\n".
1.375 tempelho 5191: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5192: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5193: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5194: &mt($message,' <input type="hidden" name="'.
5195: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5196: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5197: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5198: }
5199:
5200:
5201: sub init_breadcrumbs {
1.484.2.44 raeburn 5202: my ($form,$text,$help)=@_;
1.329 droeschl 5203: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5204: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5205: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5206: faq=>273,
5207: bug=>'Instructor Interface',
1.484.2.44 raeburn 5208: help => $help});
1.329 droeschl 5209: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5210: text=>$text,
5211: faq=>273,
5212: bug=>'Instructor Interface'});
5213: }
5214:
1.441 www 5215: # subroutine to list form elements
5216: sub create_list_elements {
5217: my @formarr = @_;
5218: my $list = '';
1.484.2.12 raeburn 5219: foreach my $button (@formarr){
5220: foreach my $picture (keys(%{$button})) {
5221: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5222: }
5223: }
5224: return $list;
5225: }
1.329 droeschl 5226:
1.441 www 5227: # subroutine to create ul from list elements
5228: sub create_form_ul {
5229: my $list = shift;
5230: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5231: return $ul;
5232: }
1.329 droeschl 5233:
1.442 www 5234: #
5235: # Start tabs
5236: #
5237:
5238: sub startContentScreen {
1.484 raeburn 5239: my ($mode) = @_;
5240: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5241: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5242: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5243: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5244: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5245: } else {
1.484.2.34 raeburn 5246: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n";
1.484 raeburn 5247: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5248: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5249: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5250: }
5251: $output .= "\n".'</ul>'."\n";
5252: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5253: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5254: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5255: return $output;
1.442 www 5256: }
5257:
5258: #
5259: # End tabs
5260: #
5261:
5262: sub endContentScreen {
1.484 raeburn 5263: return '</div></div></div>';
1.442 www 5264: }
1.329 droeschl 5265:
1.446 www 5266: sub supplemental_base {
1.484.2.33 raeburn 5267: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5268: }
5269:
1.329 droeschl 5270: sub handler {
5271: my $r = shift;
5272: &Apache::loncommon::content_type($r,'text/html');
5273: $r->send_http_header;
5274: return OK if $r->header_only;
1.484 raeburn 5275:
5276: # get course data
1.408 raeburn 5277: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5278: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5279: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5280:
5281: # graphics settings
5282: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5283:
1.443 www 5284: #
1.329 droeschl 5285: # --------------------------------------------- Initialize help topics for this
5286: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.484.2.93.2. (raeburn 5287:): 'Adding_External_Resource','Adding_External_Tool',
5288:): 'Navigate_Content','Adding_Folders','Docs_Overview',
5289:): 'Load_Map','Supplemental','Score_Upload_Form',
5290:): 'Adding_Pages','Importing_LON-CAPA_Resource',
5291:): 'Importing_IMS_Course','Uploading_From_Harddrive',
5292:): 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5293: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5294: }
5295: # Composite help files
5296: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5297: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5298: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5299: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5300: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5301: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5302: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5303: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5304: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5305: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5306:
1.484.2.67 raeburn 5307: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 5308: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5309: unless ($r->uri eq '/adm/supplemental') {
5310: # does this user have privileges to modify content.
1.484.2.67 raeburn 5311: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5312: $allowed = 1;
5313: $canedit = 1;
5314: $canview = 1;
5315: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5316: $allowed = 1;
5317: $canview = 1;
5318: }
5319: }
5320: unless ($canedit) {
5321: $disabled = ' disabled="disabled"';
1.472 raeburn 5322: }
1.484.2.53 raeburn 5323: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5324: if ($env{'form.inhibitmenu'}) {
5325: unless ($env{'form.inhibitmenu'} eq 'yes') {
5326: delete($env{'form.inhibitmenu'});
5327: }
5328: }
5329:
1.484.2.53 raeburn 5330: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5331: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5332: if (!$canedit) {
5333: &verifycontent($r);
5334: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5335: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5336: text=>'Results',
5337: faq=>273,
5338: bug=>'Instructor Interface'});
5339: &verifycontent($r,$env{'form.checkstale'});
5340: } else {
5341: &contentverifyform($r);
5342: }
1.329 droeschl 5343: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5344: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5345: &list_symbs($r);
1.484.2.93.2. (raeburn 5346:): } elsif ($allowed && $env{'form.shorturls'}) {
5347:): &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5348:): &short_urls($r,$canedit);
1.329 droeschl 5349: } elsif ($allowed && $env{'form.docslog'}) {
5350: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5351: my $folder = $env{'form.folder'};
5352: if ($folder eq '') {
5353: $folder='default';
5354: }
1.484.2.67 raeburn 5355: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5356: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5357: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5358: &checkversions($r,$canedit);
5359: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5360: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5361: &dumpcourse($r);
5362: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5363: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5364: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5365: } else {
1.445 www 5366: #
5367: # Done catching special calls
1.484 raeburn 5368: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5369: # Get the parameters that may be needed
5370: #
5371: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5372: ['folderpath',
5373: 'forcesupplement','forcestandard',
5374: 'tools','symb','command','supppath']);
1.445 www 5375:
1.484.2.78 raeburn 5376: foreach my $item ('forcesupplement','forcestandard','tools') {
5377: next if ($env{'form.'.$item} eq '');
5378: unless ($env{'form.'.$item} eq '1') {
5379: delete($env{'form.'.$item});
5380: }
5381: }
5382:
5383: if ($env{'form.command'}) {
5384: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5385: delete($env{'form.command'});
5386: }
5387: }
5388:
5389: if ($env{'form.symb'}) {
5390: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5391: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5392: delete($env{'form.symb'});
5393: }
5394: }
5395:
1.445 www 5396: # standard=1: this is a "new-style" course with an uploaded map as top level
5397: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5398:
5399: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5400:
1.484 raeburn 5401: # Decide whether this should display supplemental or main content or utilities
1.445 www 5402: # supplementalflag=1: show supplemental documents
5403: # supplementalflag=0: show standard documents
1.484 raeburn 5404: # toolsflag=1: show utilities
1.445 www 5405:
1.484.2.39 raeburn 5406: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5407: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5408: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5409: $supplementalflag=0;
5410: }
5411: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5412: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5413: unless ($allowed) { $supplementalflag=1; }
5414: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5415: my $toolsflag=0;
5416: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5417:
1.484.2.78 raeburn 5418: if ($env{'form.folderpath'} ne '') {
1.484.2.92 raeburn 5419: &validate_folderpath($supplementalflag);
1.484.2.78 raeburn 5420: }
5421:
5422: if ($env{'form.supppath'} ne '') {
1.484.2.92 raeburn 5423: &validate_suppath();
1.484.2.78 raeburn 5424: }
5425:
1.329 droeschl 5426: my $script='';
5427: my $showdoc=0;
1.457 raeburn 5428: my $addentries = {};
1.475 raeburn 5429: my $container;
1.329 droeschl 5430: my $containertag;
1.484.2.17 raeburn 5431: my $pathitem;
1.484.2.93.2. (raeburn 5432:): my %ltitools;
1.484.2.67 raeburn 5433: my $hiddentop;
5434: my $navmap;
5435: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5436:
1.464 www 5437: # Do we directly jump somewhere?
1.484.2.21 raeburn 5438: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5439: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5440: $env{'form.folderpath'}=
1.484.2.67 raeburn 5441: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5442: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5443: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5444: } elsif ($env{'form.supppath'} ne '') {
5445: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5446: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5447: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5448: }
1.472 raeburn 5449: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5450: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5451: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5452: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5453: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5454: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5455: } elsif ($env{'form.command'} eq 'contents') {
5456: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5457: } elsif ($env{'form.command'} eq 'home') {
5458: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5459: }
5460:
1.484.2.23 raeburn 5461:
1.445 www 5462: # Where do we store these for when we come back?
5463: my $stored_folderpath='docs_folderpath';
5464: if ($supplementalflag) {
5465: $stored_folderpath='docs_sup_folderpath';
5466: }
1.464 www 5467:
1.484.2.19 raeburn 5468: # No folderpath, and in edit mode, see if we have something stored
5469: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5470: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5471: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5472:
5473: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5474: if ($supplementalflag) {
5475: undef($env{'form.folderpath'}) if ($1 eq 'default');
5476: } else {
5477: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5478: }
5479: } else {
1.484.2.19 raeburn 5480: undef($env{'form.folderpath'});
5481: }
1.484.2.92 raeburn 5482: if ($env{'form.folderpath'} ne '') {
5483: &validate_folderpath($supplementalflag);
5484: }
1.329 droeschl 5485: }
1.446 www 5486:
5487: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5488: if (!$allowed) {
1.446 www 5489: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5490: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5491: }
5492: }
1.446 www 5493: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5494: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5495: $env{'form.folderpath'} = &supplemental_base()
5496: .'&'.
1.329 droeschl 5497: $env{'form.folderpath'};
5498: }
1.484.2.67 raeburn 5499: # If allowed and user's role is not advanced check folderpath is not hidden
5500: if (($allowed) && (!$env{'request.role.adv'}) &&
5501: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5502: my $folderurl;
5503: my @pathitems = split(/\&/,$env{'form.folderpath'});
5504: my $folder = $pathitems[-2];
5505: if ($folder eq '') {
5506: undef($env{'form.folderpath'});
5507: } else {
5508: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.87 raeburn 5509: if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 5510: $folderurl .= '.page';
5511: } else {
5512: $folderurl .= '.sequence';
5513: }
5514: unless (ref($navmap)) {
5515: $navmap = Apache::lonnavmaps::navmap->new();
5516: }
5517: if (ref($navmap)) {
5518: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5519: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5520: unless (@resources) {
5521: undef($env{'form.folderpath'});
5522: }
5523: }
5524: }
5525: }
5526: }
5527:
5528:
1.446 www 5529: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5530: unless ($env{'form.folderpath'}) {
1.446 www 5531: if ($supplementalflag) {
5532: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5533: } elsif ($allowed) {
5534: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5535: }
1.472 raeburn 5536: }
1.446 www 5537:
1.445 www 5538: # Store this
1.484 raeburn 5539: unless ($toolsflag) {
1.484.2.67 raeburn 5540: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5541: &Apache::loncommon::store_course_settings($stored_folderpath,
5542: {'folderpath' => 'scalar'});
5543: }
5544: my $folderpath;
1.484 raeburn 5545: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5546: $folderpath = $env{'form.folderpath'};
5547: my (@folders)=split('&',$env{'form.folderpath'});
5548: $env{'form.foldername'}=&unescape(pop(@folders));
5549: if ($env{'form.foldername'} =~ /\:1$/) {
5550: $container = 'page';
5551: } else {
5552: $container = 'sequence';
5553: }
5554: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5555: } else {
1.484.2.19 raeburn 5556: if ($env{'form.folder'} eq '' ||
5557: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5558: if ($env{'form.folder'} eq 'supplemental') {
5559: $folderpath=&supplemental_base();
5560: } elsif (!$hiddentop) {
5561: $folderpath='default&'.
5562: &escape(&mt('Main Content').':::::');
5563: }
1.484 raeburn 5564: }
5565: }
1.484.2.19 raeburn 5566: $containertag = '<input type="hidden" name="folderpath" value="" />';
5567: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5568: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5569: $showdoc='/'.$1;
5570: }
5571: if ($showdoc) { # got called in sequence from course
5572: $allowed=0;
5573: } else {
1.484.2.67 raeburn 5574: if ($canedit) {
1.484 raeburn 5575: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5576: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5577: }
5578: }
1.329 droeschl 5579: }
5580:
1.344 bisitz 5581: # get personal data
1.329 droeschl 5582: my $uname=$env{'user.name'};
5583: my $udom=$env{'user.domain'};
5584: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5585:
5586: if ($allowed) {
1.484 raeburn 5587: if ($toolsflag) {
5588: $script .= &inject_data_js();
5589: my ($home,$other,%outhash)=&authorhosts();
5590: if (!$home && $other) {
5591: my @hosts;
5592: foreach my $aurole (keys(%outhash)) {
5593: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5594: push(@hosts,$outhash{$aurole});
5595: }
5596: }
5597: $script .= &dump_switchserver_js(@hosts);
5598: }
1.458 raeburn 5599: } else {
1.484.2.43 raeburn 5600: my $tid = 1;
1.484 raeburn 5601: my @tabids;
5602: if ($supplementalflag) {
5603: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5604: $tid = 2;
1.484 raeburn 5605: } else {
5606: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5607: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5608: unshift(@tabids,'001');
5609: push(@tabids,('dd1','ee1'));
5610: }
1.458 raeburn 5611: }
1.484 raeburn 5612: my $tabidstr = join("','",@tabids);
1.484.2.93.2. (raeburn 5613:): %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
5614:): my $posslti = keys(%ltitools);
1.484.2.80 raeburn 5615: my $hostname = $r->hostname();
1.484.2.93.2. (raeburn 5616:): $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 5617: $canedit,$hostname,\$navmap).
1.484 raeburn 5618: &history_tab_js().
5619: &inject_data_js().
1.484.2.43 raeburn 5620: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.93.2. (raeburn 5621:): &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5622: $addentries = {
1.484.2.3 raeburn 5623: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5624: };
1.458 raeburn 5625: }
1.484.2.30 raeburn 5626: $script .= &paste_popup_js();
1.484.2.12 raeburn 5627: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5628: &mt('Switch server?');
1.484.2.19 raeburn 5629:
5630:
1.329 droeschl 5631: }
5632: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5633: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5634: .'// <![CDATA['."\n"
5635: .$script."\n"
5636: .'// ]]>'."\n"
1.484.2.81 raeburn 5637: .'</script>'."\n"
5638: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5639:
5640: # Breadcrumbs
5641: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5642:
5643: if ($showdoc) {
5644: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5645: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5646: } elsif ($toolsflag) {
1.484.2.67 raeburn 5647: my ($breadtext,$breadtitle);
5648: $breadtext = "$crstype Editor";
5649: if ($canedit) {
5650: $breadtitle = 'Editing '.$crstype.' Contents';
5651: } else {
5652: $breadtext .= ' (View-only mode)';
5653: $breadtitle = 'Viewing '.$crstype.' Contents';
5654: }
1.484.2.44 raeburn 5655: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5656: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5657: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5658: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5659: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5660: $breadtitle)
1.484.2.44 raeburn 5661: );
1.484.2.19 raeburn 5662: } elsif ($r->uri eq '/adm/supplemental') {
5663: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5664: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5665: {'bread_crumbs' => $brcrum,}));
5666: } else {
1.484.2.67 raeburn 5667: my ($breadtext,$breadtitle,$helpitem);
5668: $breadtext = "$crstype Editor";
5669: if ($canedit) {
5670: $breadtitle = 'Editing '.$crstype.' Contents';
5671: $helpitem = 'Docs_Adding_Course_Doc';
5672: } else {
5673: $breadtext .= ' (View-only mode)';
5674: $breadtitle = 'Viewing '.$crstype.' Contents';
5675: $helpitem = 'Docs_Viewing_Course_Doc';
5676: }
1.392 raeburn 5677: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5678: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5679: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5680: {'add_entries' => $addentries}
5681: )
1.392 raeburn 5682: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5683: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5684: $breadtitle,
5685: $helpitem)
1.392 raeburn 5686: );
5687: }
1.364 bisitz 5688:
1.329 droeschl 5689: my %allfiles = ();
5690: my %codebase = ();
1.440 raeburn 5691: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5692: if ($canedit) {
1.329 droeschl 5693: if (($env{'form.uploaddoc.filename'}) &&
5694: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5695: my $context = $1;
5696: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5697: undef($hadchanges);
1.440 raeburn 5698: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5699: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5700: undef($navmap);
1.329 droeschl 5701: if ($hadchanges) {
5702: &mark_hash_old();
5703: }
1.440 raeburn 5704: $r->print($upload_output);
5705: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5706: # Process file upload - phase two - upload embedded objects
5707: $uploadphase = 'check_embedded';
5708: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5709: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5710: $env{'form.newidx'});
5711: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5712: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5713: my ($destination,$dir_root) = &embedded_destination();
5714: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5715: my $actionurl = '/adm/coursedocs';
5716: my ($result,$flag) =
5717: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5718: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5719: $actionurl);
5720: $r->print($result.&return_to_editor());
5721: } elsif ($env{'form.phase'} eq 'check_embedded') {
5722: # Process file upload - phase three - modify references in HTML file
5723: $uploadphase = 'modified_orightml';
5724: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5725: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5726: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5727: my $result =
5728: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5729: $docuname,$docudom,undef,
5730: $dir_root);
5731: $r->print($result.&return_to_editor());
1.476 raeburn 5732: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5733: $uploadphase = 'decompress_phase_one';
5734: $r->print(&decompression_phase_one().
5735: &return_to_editor());
5736: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5737: $uploadphase = 'decompress_phase_two';
5738: $r->print(&decompression_phase_two().
5739: &return_to_editor());
1.329 droeschl 5740: }
5741: }
5742:
1.484 raeburn 5743: if ($allowed && $toolsflag) {
5744: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5745: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5746: $r->print(&endContentScreen());
5747: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5748: # -----------------------------------------------------------------------------
5749: my %lt=&Apache::lonlocal::texthash(
5750: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5751: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5752: 'upld' => 'Upload Content',
1.329 droeschl 5753: 'srch' => 'Search',
5754: 'impo' => 'Import',
1.484.2.19 raeburn 5755: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5756: 'impm' => 'Import from Assembled Map',
1.484.2.93.2. (raeburn 5757:): 'extr' => 'External Resource',
5758:): 'extt' => 'External Tool',
1.329 droeschl 5759: 'selm' => 'Select Map',
5760: 'load' => 'Load Map',
5761: 'newf' => 'New Folder',
5762: 'newp' => 'New Composite Page',
5763: 'syll' => 'Syllabus',
1.425 raeburn 5764: 'navc' => 'Table of Contents',
1.343 biermanm 5765: 'sipa' => 'Simple Course Page',
1.329 droeschl 5766: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5767: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5768: 'drbx' => 'Drop Box',
1.451 www 5769: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5770: 'bull' => 'Discussion Board',
1.347 weissno 5771: 'mypi' => 'My Personal Information Page',
1.353 weissno 5772: 'grpo' => 'Group Portfolio',
1.329 droeschl 5773: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5774: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5775: 'imsf' => 'IMS Upload',
5776: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5777: 'cms' => 'Origin of IMS package',
5778: 'se' => 'Select',
1.484.2.19 raeburn 5779: 'file' => 'File',
1.329 droeschl 5780: 'title' => 'Title',
5781: 'comment' => 'Comment',
1.403 raeburn 5782: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5783: 'bb5' => 'Blackboard 5',
5784: 'bb6' => 'Blackboard 6',
5785: 'angel5' => 'ANGEL 5.5',
5786: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5787: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5788: );
1.329 droeschl 5789: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5790: # Calculate free quota space for a user or course. A javascript function checks
5791: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5792: my $quotatype = 'unofficial';
5793: if ($crstype eq 'Community') {
5794: $quotatype = 'community';
5795: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5796: $quotatype = 'official';
5797: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5798: $quotatype = 'textbook';
5799: }
5800: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5801: 'course',$quotatype); # expressed in MB
5802: my $current_disk_usage = 0;
5803: foreach my $subdir ('docs','supplemental') {
5804: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5805: "userfiles/$subdir",1); # expressed in kB
5806: }
5807: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5808: my $usage = $current_disk_usage/1024; # in MB
5809: my $quota = $disk_quota;
5810: my $percent;
5811: if ($disk_quota == 0) {
5812: $percent = 100.0;
5813: } else {
1.484.2.69 raeburn 5814: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5815: }
5816: $usage = sprintf("%.2f",$usage);
5817: $quota = sprintf("%.2f",$quota);
5818: $percent = sprintf("%.0f",$percent);
5819: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5820: $percent.'%',$quota.' MB').'</p>';
5821:
1.329 droeschl 5822: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5823: $quotainfo
1.329 droeschl 5824: $lt{'file'}:<br />
1.484.2.81 raeburn 5825: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
5826: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5827: FIUP
5828:
5829: my $checkbox=(<<CHBO);
5830: <!-- <label>$lt{'parse'}?
5831: <input type="checkbox" name="parserflag" />
5832: </label> -->
5833: <label>
1.484.2.67 raeburn 5834: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5835: </label>
5836: CHBO
1.484.2.12 raeburn 5837: my $imsfolder = $env{'form.folder'};
5838: if ($imsfolder eq '') {
1.484.2.19 raeburn 5839: $imsfolder = 'default';
1.484.2.12 raeburn 5840: }
5841: my $imspform=(<<IMSFORM);
5842: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5843: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5844: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5845: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5846: <legend>$lt{'imsf'}</legend>
5847: $fileupload
5848: <br />
5849: <p>
1.484.2.19 raeburn 5850: $lt{'cms'}:
1.484.2.67 raeburn 5851: <select name="source" $disabled>
1.484.2.12 raeburn 5852: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5853: <option value="bb5">$lt{'bb5'}</option>
5854: <option value="bb6">$lt{'bb6'}</option>
5855: <option value="angel5">$lt{'angel5'}</option>
5856: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5857: </select>
5858: <input type="hidden" name="folder" value="$imsfolder" />
5859: </p>
5860: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5861: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5862: </fieldset>
5863: </form>
5864: IMSFORM
5865:
1.484.2.19 raeburn 5866: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5867: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5868: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5869: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5870: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5871: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5872: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5873: $fileupload
5874: <br />
5875: $lt{'title'}:<br />
1.484.2.67 raeburn 5876: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5877: $pathitem
1.329 droeschl 5878: <input type="hidden" name="cmd" value="upload_default" />
5879: <br />
1.458 raeburn 5880: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5881: $checkbox
5882: </span>
1.484.2.12 raeburn 5883: <br clear="all" />
1.484.2.67 raeburn 5884: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5885: </fieldset>
5886: </form>
1.383 tempelho 5887: FUFORM
1.329 droeschl 5888:
1.484.2.67 raeburn 5889: my $mapimportjs;
5890: if ($canedit) {
5891: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5892: } else {
5893: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5894: }
1.484.2.19 raeburn 5895: my $importpubform=(<<SEDFFORM);
5896: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5897: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5898: <form action="/adm/coursedocs" method="post" name="mapimportform">
5899: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5900: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5901: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5902: $lt{'copm'}<br />
5903: <span class="LC_nobreak">
1.484.2.19 raeburn 5904: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5905: onfocus="this.blur();$mapimportjs" $disabled />
5906: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5907: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5908: </fieldset>
5909: </form>
5910:
1.383 tempelho 5911: SEDFFORM
1.484.2.67 raeburn 5912:
5913: my $fromstoredjs;
5914: if ($canedit) {
5915: $fromstoredjs = 'open_StoredLinks_Import()';
5916: } else {
5917: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5918: }
5919:
1.484.2.19 raeburn 5920: my @importpubforma = (
5921: { '<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>" },
1.423 onken 5922: { '<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'}" },
1.484.2.67 raeburn 5923: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:'.$fromstoredjs.';" />' => '<a class="LC_menubuttons_link" href="javascript:'.$fromstoredjs.';">'.$lt{'lnks'}.'</a>' },
1.484.2.19 raeburn 5924: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5925: );
5926: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5927: my $extresourcesform =
5928: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5929: $help{'Adding_External_Resource'},
1.484.2.93.2. (raeburn 5930:): undef,undef,undef,undef,undef,undef,$disabled);
5931:): my $exttoolform =
5932:): &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5933:): $help{'Adding_External_Tool'},undef,
5934:): undef,'tool',$coursedom,$coursenum,
5935:): \%ltitools,$disabled);
1.329 droeschl 5936: if ($allowed) {
1.484.2.7 raeburn 5937: my $folder = $env{'form.folder'};
5938: if ($folder eq '') {
5939: $folder='default';
5940: }
1.484.2.67 raeburn 5941: if ($canedit) {
5942: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5943: if ($output) {
5944: $r->print($output);
5945: }
1.484.2.30 raeburn 5946: }
1.337 ehlerst 5947: $r->print(<<HIDDENFORM);
5948: <form name="renameform" method="post" action="/adm/coursedocs">
5949: <input type="hidden" name="title" />
5950: <input type="hidden" name="cmd" />
5951: <input type="hidden" name="markcopy" />
5952: <input type="hidden" name="copyfolder" />
5953: $containertag
5954: </form>
1.484 raeburn 5955:
1.337 ehlerst 5956: HIDDENFORM
1.484.2.17 raeburn 5957: $r->print(&makesimpleeditform($pathitem)."\n".
5958: &makedocslogform($pathitem."\n".
1.484 raeburn 5959: '<input type="hidden" name="folder" value="'.
5960: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5961: }
1.442 www 5962:
5963: # Generate the tabs
1.484.2.19 raeburn 5964: my ($mode,$needs_end);
1.472 raeburn 5965: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5966: my @folders = split('&',$env{'form.folderpath'});
5967: unless (@folders > 2) {
5968: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5969: $needs_end = 1;
5970: }
1.472 raeburn 5971: } else {
1.484 raeburn 5972: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5973: $needs_end = 1;
1.472 raeburn 5974: }
1.443 www 5975:
1.442 www 5976: #
5977:
5978: my $savefolderpath;
1.484.2.86 raeburn 5979: my $hostname = $r->hostname();
1.442 www 5980:
1.395 raeburn 5981: if ($allowed) {
1.329 droeschl 5982: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5983: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5984: $folder='default';
1.356 tempelho 5985: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5986: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5987: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5988: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5989: }
5990: my $postexec='';
5991: if ($folder eq 'default') {
1.372 bisitz 5992: $r->print('<script type="text/javascript">'."\n"
5993: .'// <![CDATA['."\n"
5994: .'this.window.name="loncapaclient";'."\n"
5995: .'// ]]>'."\n"
5996: .'</script>'."\n"
1.369 bisitz 5997: );
1.329 droeschl 5998: } else {
5999: #$postexec='self.close();';
6000: }
1.484.2.15 raeburn 6001: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6002: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6003: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6004:
6005: my $newnavform=(<<NNFORM);
6006: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 6007: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6008: $pathitem
1.329 droeschl 6009: <input type="hidden" name="importdetail"
6010: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 6011: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6012: $help{'Navigate_Content'}
6013: </form>
6014: NNFORM
6015: my $newsmppageform=(<<NSPFORM);
6016: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 6017: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6018: $pathitem
1.329 droeschl 6019: <input type="hidden" name="importdetail" value="" />
1.423 onken 6020: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6021: $help{'Simple Page'}
1.329 droeschl 6022: </form>
6023: NSPFORM
6024:
6025: my $newsmpproblemform=(<<NSPROBFORM);
6026: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 6027: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6028: $pathitem
1.329 droeschl 6029: <input type="hidden" name="importdetail" value="" />
1.423 onken 6030: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 6031: $help{'Simple_Problem'}
1.329 droeschl 6032: </form>
6033:
6034: NSPROBFORM
6035:
6036: my $newdropboxform=(<<NDBFORM);
6037: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 6038: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6039: $pathitem
1.329 droeschl 6040: <input type="hidden" name="importdetail" value="" />
1.423 onken 6041: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 6042: $help{'Dropbox'}
1.344 bisitz 6043: </form>
1.329 droeschl 6044: NDBFORM
6045:
6046: my $newexuploadform=(<<NEXUFORM);
6047: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 6048: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6049: $pathitem
1.329 droeschl 6050: <input type="hidden" name="importdetail" value="" />
1.423 onken 6051: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6052: $help{'Score_Upload_Form'}
6053: </form>
6054: NEXUFORM
6055:
6056: my $newbulform=(<<NBFORM);
6057: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 6058: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6059: $pathitem
1.329 droeschl 6060: <input type="hidden" name="importdetail" value="" />
1.423 onken 6061: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6062: $help{'Bulletin Board'}
6063: </form>
6064: NBFORM
6065:
6066: my $newaboutmeform=(<<NAMFORM);
6067: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 6068: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6069: $pathitem
1.329 droeschl 6070: <input type="hidden" name="importdetail"
6071: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6072: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6073: $help{'My Personal Information Page'}
1.329 droeschl 6074: </form>
6075: NAMFORM
6076:
6077: my $newaboutsomeoneform=(<<NASOFORM);
6078: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 6079: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6080: $pathitem
1.329 droeschl 6081: <input type="hidden" name="importdetail" value="" />
1.423 onken 6082: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6083: </form>
6084: NASOFORM
6085:
6086: my $newrosterform=(<<NROSTFORM);
6087: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 6088: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6089: $pathitem
1.329 droeschl 6090: <input type="hidden" name="importdetail"
6091: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 6092: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 6093: $help{'Course_Roster'}
1.329 droeschl 6094: </form>
6095: NROSTFORM
6096:
1.484.2.27 raeburn 6097: my $newwebpage;
6098: if ($folder =~ /^default_?(\d*)$/) {
6099: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6100: if ($1) {
6101: $newwebpage .= $1;
6102: } else {
6103: $newwebpage .= 'default';
6104: }
6105: $newwebpage .= '/new.html';
6106: }
6107: my $newwebpageform =(<<NWEBFORM);
6108: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 6109: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 6110: $pathitem
6111: <input type="hidden" name="importdetail" value="$newwebpage" />
6112: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 6113: $help{'Web_Page'}
1.484.2.27 raeburn 6114: </form>
6115: NWEBFORM
1.484.2.30 raeburn 6116:
1.484.2.27 raeburn 6117:
1.342 ehlerst 6118: my $specialdocumentsform;
1.383 tempelho 6119: my @specialdocumentsforma;
1.451 www 6120: my $gradingform;
6121: my @gradingforma;
6122: my $communityform;
6123: my @communityforma;
1.351 ehlerst 6124: my $newfolderform;
1.390 tempelho 6125: my $newfolderb;
1.342 ehlerst 6126:
1.451 www 6127: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6128:
1.329 droeschl 6129: my $newpageform=(<<NPFORM);
6130: <form action="/adm/coursedocs" method="post" name="newpage">
6131: <input type="hidden" name="folderpath" value="$path" />
6132: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6133: <input type="hidden" name="active" value="ee" />
1.423 onken 6134: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6135: $help{'Adding_Pages'}
1.329 droeschl 6136: </form>
6137: NPFORM
1.390 tempelho 6138:
6139:
1.351 ehlerst 6140: $newfolderform=(<<NFFORM);
1.329 droeschl 6141: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 6142: $pathitem
1.329 droeschl 6143: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6144: <input type="hidden" name="active" value="" />
1.422 onken 6145: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6146: </form>
6147: NFFORM
6148:
6149: my $newsylform=(<<NSYLFORM);
6150: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 6151: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6152: $pathitem
1.329 droeschl 6153: <input type="hidden" name="importdetail"
6154: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6155: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6156: $help{'Syllabus'}
1.383 tempelho 6157:
1.329 droeschl 6158: </form>
6159: NSYLFORM
1.364 bisitz 6160:
1.329 droeschl 6161: my $newgroupfileform=(<<NGFFORM);
6162: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 6163: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6164: $pathitem
1.329 droeschl 6165: <input type="hidden" name="importdetail"
6166: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 6167: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6168: $help{'Group Portfolio'}
1.329 droeschl 6169: </form>
6170: NGFFORM
1.484.2.89 raeburn 6171: if ($container eq 'page') {
6172: @specialdocumentsforma=(
6173: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6174: );
6175: } else {
6176: @specialdocumentsforma=(
1.421 onken 6177: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.484.2.67 raeburn 6178: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6179: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6180: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 6181: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.484.2.89 raeburn 6182: );
6183: }
1.451 www 6184: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6185:
1.434 raeburn 6186:
6187: my @importdoc = (
1.484.2.19 raeburn 6188: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6189: );
1.484.2.93.2. (raeburn 6190:): if (keys(%ltitools)) {
6191:): push(@importdoc,
6192:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6193:): );
6194:): }
1.484.2.19 raeburn 6195: unless ($container eq 'page') {
6196: push(@importdoc,
6197: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6198: );
6199: }
6200: push(@importdoc,
1.484.2.38 raeburn 6201: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.484.2.19 raeburn 6202: );
1.484.2.12 raeburn 6203: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6204:
1.451 www 6205: @gradingforma=(
6206: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6207: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6208: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6209:
6210: );
6211: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6212:
6213: @communityforma=(
6214: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6215: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6216: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 6217: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6218: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6219: );
6220: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6221:
1.330 tempelho 6222: my %orderhash = (
1.484.2.36 raeburn 6223: 'aa' => ['Upload',$fileuploadform],
6224: 'bb' => ['Import',$importpubform],
6225: 'cc' => ['Grading',$gradingform],
1.484.2.89 raeburn 6226: 'ee' => ['Other',$specialdocumentsform],
1.330 tempelho 6227: );
1.484.2.19 raeburn 6228: unless ($container eq 'page') {
1.434 raeburn 6229: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6230: $orderhash{'dd'} = ['Collaboration',$communityform];
1.434 raeburn 6231: }
6232:
1.341 ehlerst 6233: $hadchanges=0;
1.484 raeburn 6234: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6235: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6236: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.93.2. (raeburn 6237:): \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 6238: undef($navmap);
1.443 www 6239: if ($error) {
6240: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6241: }
6242: if ($hadchanges) {
1.484.2.73 raeburn 6243: unless (&is_hash_old()) {
6244: &mark_hash_old();
6245: }
1.443 www 6246: }
1.341 ehlerst 6247:
1.443 www 6248: &changewarning($r,'');
6249: }
1.458 raeburn 6250: }
1.442 www 6251:
1.443 www 6252: # Supplemental documents start here
6253:
1.329 droeschl 6254: my $folder=$env{'form.folder'};
1.443 www 6255: unless ($supplementalflag) {
1.329 droeschl 6256: $folder='supplemental';
6257: }
6258: if ($folder =~ /^supplemental$/ &&
6259: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6260: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6261: } elsif ($allowed) {
1.356 tempelho 6262: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6263: }
1.484.2.17 raeburn 6264: $pathitem = '<input type="hidden" name="folderpath" value="'.
6265: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6266: if ($allowed) {
6267: my $folderseq=
1.484.2.15 raeburn 6268: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6269:
6270: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 6271: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6272: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6273: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6274: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6275: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6276: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6277: $fileupload
6278: <br />
6279: <br />
6280: <span class="LC_nobreak">
6281: $checkbox
6282: </span>
6283: <br /><br />
6284: $lt{'comment'}:<br />
1.383 tempelho 6285: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6286: <br />
1.484.2.19 raeburn 6287: $pathitem
1.329 droeschl 6288: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6289: <input type='submit' value="$lt{'upld'}" />
6290: </form>
1.484.2.19 raeburn 6291: SUPDOCFORM
1.329 droeschl 6292:
6293: my $supnewfolderform=(<<SNFFORM);
6294: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6295: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6296: $pathitem
1.329 droeschl 6297: <input type="hidden" name="importdetail" value="" />
1.423 onken 6298: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6299: $help{'Adding_Folders'}
1.329 droeschl 6300: </form>
6301: SNFFORM
1.383 tempelho 6302:
1.484.2.19 raeburn 6303: my $supextform =
6304: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6305: $help{'Adding_External_Resource'},
6306: undef,undef,$disabled);
1.484.2.93.2. (raeburn 6307:): my $supexttoolform =
6308:): &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6309:): $help{'Adding_External_Tool'},
6310:): undef,undef,'tool',$coursedom,
6311:): $coursenum,\%ltitools,$disabled);
1.329 droeschl 6312:
6313: my $supnewsylform=(<<SNSFORM);
6314: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6315: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6316: $pathitem
1.329 droeschl 6317: <input type="hidden" name="importdetail"
6318: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6319: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6320: $help{'Syllabus'}
6321: </form>
6322: SNSFORM
6323:
6324: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6325: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6326: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6327: $pathitem
1.329 droeschl 6328: <input type="hidden" name="importdetail"
6329: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6330: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6331: $help{'My Personal Information Page'}
1.329 droeschl 6332: </form>
6333: SNAMFORM
6334:
1.484.2.27 raeburn 6335: my $supwebpage;
6336: if ($folder =~ /^supplemental_?(\d*)$/) {
6337: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6338: if ($1) {
6339: $supwebpage .= $1;
6340: } else {
6341: $supwebpage .= 'default';
6342: }
6343: $supwebpage .= '/new.html';
6344: }
6345: my $supwebpageform =(<<SWEBFORM);
6346: <form action="/adm/coursedocs" method="post" name="supwebpage">
6347: <input type="hidden" name="active" value="cc" />
6348: $pathitem
6349: <input type="hidden" name="importdetail" value="$supwebpage" />
6350: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6351: $help{'Web_Page'}
1.484.2.27 raeburn 6352: </form>
6353: SWEBFORM
6354:
1.333 muellerd 6355:
1.383 tempelho 6356: my @specialdocs = (
1.484.2.67 raeburn 6357: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6358: =>$supnewsylform},
1.484.2.67 raeburn 6359: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6360: =>$supnewaboutmeform},
1.484.2.27 raeburn 6361: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6362:
1.383 tempelho 6363: );
1.417 droeschl 6364: my @supimportdoc = (
1.484.2.19 raeburn 6365: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.93.2. (raeburn 6366:): =>$supextform});
6367:): if (keys(%ltitools)) {
6368:): push(@supimportdoc,
6369:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6370:): =>$supexttoolform});
6371:): }
6372:): push(@supimportdoc,
1.484.2.12 raeburn 6373: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6374: =>$supupdocform},
1.484.2.93.2. (raeburn 6375:): );
1.484.2.19 raeburn 6376:
1.484.2.12 raeburn 6377: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6378: my %suporderhash = (
1.390 tempelho 6379: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6380: 'ee' => ['Upload',$supupdocform],
6381: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6382: );
1.443 www 6383: if ($supplementalflag) {
1.458 raeburn 6384: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6385: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.484.2.93.2. (raeburn 6386:): \%ltitools,$canedit,$hostname);
1.443 www 6387: if ($error) {
6388: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6389: } else {
6390: if ($suppchanges) {
6391: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6392: my @ids=&Apache::lonnet::current_machine_ids();
6393: foreach my $server (keys(%servers)) {
6394: next if (grep(/^\Q$server\E$/,@ids));
6395: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6396: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6397: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6398: }
6399: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6400: undef($suppchanges);
6401: }
1.443 www 6402: }
1.393 raeburn 6403: }
1.443 www 6404: } elsif ($supplementalflag) {
1.458 raeburn 6405: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.85 raeburn 6406: $supplementalflag,'',$iconpath,$pathitem,'',$hostname);
1.393 raeburn 6407: if ($error) {
6408: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6409: }
1.393 raeburn 6410: }
1.389 tempelho 6411:
1.484.2.19 raeburn 6412: if ($needs_end) {
6413: $r->print(&endContentScreen());
6414: }
1.383 tempelho 6415:
1.329 droeschl 6416: if ($allowed) {
6417: $r->print('
6418: <form method="post" name="extimport" action="/adm/coursedocs">
6419: <input type="hidden" name="title" />
6420: <input type="hidden" name="url" />
6421: <input type="hidden" name="useform" />
6422: <input type="hidden" name="residx" />
6423: </form>');
6424: }
1.484 raeburn 6425: } elsif ($showdoc) {
1.329 droeschl 6426: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6427: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6428: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6429: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6430: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6431: }
6432: }
6433: $r->print(&Apache::loncommon::end_page());
6434: return OK;
1.364 bisitz 6435: }
1.329 droeschl 6436:
1.440 raeburn 6437: sub embedded_form_elems {
6438: my ($phase,$primaryurl,$newidx) = @_;
6439: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6440: $newidx =~s /\D+//g;
1.440 raeburn 6441: return <<STATE;
6442: <input type="hidden" name="folderpath" value="$folderpath" />
6443: <input type="hidden" name="cmd" value="upload_embedded" />
6444: <input type="hidden" name="newidx" value="$newidx" />
6445: <input type="hidden" name="phase" value="$phase" />
6446: <input type="hidden" name="primaryurl" value="$primaryurl" />
6447: STATE
6448: }
6449:
6450: sub embedded_destination {
6451: my $folder=$env{'form.folder'};
6452: my $destination = 'docs/';
6453: if ($folder =~ /^supplemental/) {
6454: $destination = 'supplemental/';
6455: }
6456: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6457: $destination .= 'default/';
6458: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6459: $destination .= $2.'/';
6460: }
1.484.2.78 raeburn 6461: my $newidx = $env{'form.newidx'};
6462: $newidx =~s /\D+//g;
6463: if ($newidx) {
6464: $destination .= $newidx;
6465: }
1.440 raeburn 6466: my $dir_root = '/userfiles';
6467: return ($destination,$dir_root);
6468: }
6469:
6470: sub return_to_editor {
6471: my $actionurl = '/adm/coursedocs';
6472: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6473: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6474: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6475: '</a></p>';
6476: }
6477:
1.476 raeburn 6478: sub decompression_info {
6479: my ($destination,$dir_root) = &embedded_destination();
6480: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6481: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6482: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6483: my $container='sequence';
1.480 raeburn 6484: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6485: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6486: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6487: $container='page';
6488: }
1.480 raeburn 6489: unshift(@hiddens,$pathitem);
6490: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6491: if ($item eq 'newidx') {
6492: next if ($env{'form.'.$item} =~ /\D/);
6493: }
1.480 raeburn 6494: if ($env{'form.'.$item}) {
6495: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6496: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6497: }
1.477 raeburn 6498: }
1.476 raeburn 6499: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6500: $hiddenelem);
6501: }
6502:
6503: sub decompression_phase_one {
6504: my ($dir,$file,$warning,$error,$output);
6505: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6506: &decompression_info();
1.484.2.7 raeburn 6507: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6508: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6509: } else {
6510: my $file = $1;
1.481 raeburn 6511: $output =
6512: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6513: $destination,$dir_root,
6514: $hiddenelem);
6515: if ($env{'form.autoextract_camtasia'}) {
6516: $output .= &remove_archive($docudom,$docuname,$container);
6517: }
1.476 raeburn 6518: }
6519: if ($error) {
6520: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6521: $error.'</p>'."\n";
6522: }
6523: if ($warning) {
6524: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6525: }
6526: return $output;
6527: }
6528:
6529: sub decompression_phase_two {
6530: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6531: &decompression_info();
1.481 raeburn 6532: my $output;
1.480 raeburn 6533: if ($env{'form.archivedelete'}) {
1.481 raeburn 6534: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6535: }
6536: $output .=
1.481 raeburn 6537: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6538: $destination,$dir_root,$hiddenelem);
6539: return $output;
6540: }
6541:
1.480 raeburn 6542: sub remove_archive {
6543: my ($docudom,$docuname,$container) = @_;
6544: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6545: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6546: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6547: if ($fatal) {
6548: if ($container eq 'page') {
6549: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6550: } else {
6551: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6552: }
1.484.2.54 raeburn 6553: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6554: } else {
6555: my $currcmd = $env{'form.cmd'};
6556: my $position = $env{'form.position'};
1.484.2.54 raeburn 6557: my $archiveidx = $position;
6558: if ($position > 0) {
6559: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6560: $archiveidx = $position-1;
6561: }
6562: $env{'form.cmd'} = 'remove_'.$archiveidx;
6563: my ($title,$url,@rrest) =
6564: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6565: if ($url eq $env{'form.archiveurl'}) {
6566: if (&handle_edit_cmd($docuname,$docudom)) {
6567: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6568: if ($fatal) {
6569: if ($container eq 'page') {
6570: $delwarning = &mt('An error occurred updating the contents of the current page.');
6571: } else {
6572: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6573: }
1.480 raeburn 6574: } else {
1.484.2.54 raeburn 6575: $delresult = &mt('Archive file removed.');
1.480 raeburn 6576: }
6577: }
1.484.2.54 raeburn 6578: } else {
6579: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6580: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6581: }
6582: }
6583: $env{'form.cmd'} = $currcmd;
6584: }
6585: if ($delwarning) {
6586: $output = '<p class="LC_warning">'.
6587: $delwarning.
6588: '</p>';
6589: }
6590: if ($delresult) {
6591: $output .= '<p class="LC_info">'.
6592: $delresult.
6593: '</p>';
6594: }
1.481 raeburn 6595: return $output;
1.480 raeburn 6596: }
6597:
1.484 raeburn 6598: sub generate_admin_menu {
1.484.2.67 raeburn 6599: my ($crstype,$canedit) = @_;
1.484 raeburn 6600: my $lc_crstype = lc($crstype);
6601: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6602: my %lt= ( # do not translate here
1.484 raeburn 6603: 'vc' => 'Verify Content',
6604: 'cv' => 'Check/Set Resource Versions',
6605: 'ls' => 'List Resource Identifiers',
1.484.2.93.2. (raeburn 6606:): 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 6607: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6608: 'dcd' => "Copy $crstype Content to Authoring Space",
6609: );
1.484 raeburn 6610: my ($candump,$dumpurl);
6611: if ($home + $other > 0) {
6612: $candump = 'F';
6613: if ($home) {
6614: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6615: } else {
6616: my @hosts;
6617: foreach my $aurole (keys(%outhash)) {
6618: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6619: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6620: }
1.484 raeburn 6621: }
6622: if (@hosts == 1) {
6623: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6624: '&role='.
6625: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6626: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6627: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6628: } else {
6629: $dumpurl = "javascript:choose_switchserver_window()";
6630: }
6631: }
6632: }
6633: my @menu=
6634: ({ categorytitle=>'Administration',
6635: items =>[
6636: { linktext => $lt{'vc'},
6637: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6638: permission => 'F',
1.484.2.44 raeburn 6639: help => 'Docs_Verify_Content',
1.484 raeburn 6640: icon => 'verify.png',
6641: linktitle => 'Verify contents can be retrieved/rendered',
6642: },
6643: { linktext => $lt{'cv'},
6644: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6645: permission => 'F',
1.484.2.44 raeburn 6646: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6647: icon => 'resversion.png',
6648: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6649: },
6650: { linktext => $lt{'ls'},
6651: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6652: permission => 'F',
6653: #help => '',
6654: icon => 'symbs.png',
6655: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6656: },
1.484.2.93.2. (raeburn 6657:): { linktext => $lt{'ct'},
6658:): url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
6659:): permission => 'F',
6660:): help => 'Docs_Short_URLs',
6661:): icon => 'shorturls.png',
6662:): linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
6663:): },
1.484 raeburn 6664: ]
1.484.2.67 raeburn 6665: });
6666: if ($canedit) {
6667: push(@menu,
1.484 raeburn 6668: { categorytitle=>'Export',
6669: items =>[
6670: { linktext => $lt{'imse'},
6671: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6672: permission => 'F',
6673: help => 'Docs_Export_Course_Docs',
6674: icon => 'imsexport.png',
6675: linktitle => $lt{'imse'},
6676: },
6677: { linktext => $lt{'dcd'},
6678: url => $dumpurl,
6679: permission => $candump,
1.484.2.44 raeburn 6680: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6681: icon => 'dump.png',
6682: linktitle => $lt{'dcd'},
6683: },
6684: ]
6685: });
1.484.2.67 raeburn 6686: }
1.484 raeburn 6687: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6688: '<input type="hidden" id="dummy" />'."\n".
6689: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6690: '</form>';
1.329 droeschl 6691: }
6692:
6693: sub generate_edit_table {
1.484.2.30 raeburn 6694: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6695: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6696: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6697: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6698: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6699: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6700: $activetab = $env{'form.active'};
6701: }
1.484.2.67 raeburn 6702: unless ($canedit) {
6703: $disabled = ' disabled="disabled"';
6704: }
1.472 raeburn 6705: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6706: my $backtext = &mt('Exit Editor');
1.458 raeburn 6707: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6708: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6709: '<li class="goback">'.
1.484.2.32 raeburn 6710: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6711: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6712: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6713: '<li>'.
6714: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6715: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6716: if ($env{'form.docslog'}) {
6717: $form .= '<li class="active">';
6718: } else {
6719: $form .= '<li>';
6720: }
6721: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6722: &mt('History').'</a></li>'."\n";
6723: if ($env{'form.docslog'}) {
6724: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6725: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6726: }
1.458 raeburn 6727: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6728: if($name ne '00'){
1.371 tempelho 6729: if($activetab eq '' || $activetab ne $name){
6730: $active = '';
6731: }elsif($activetab eq $name){
6732: $active = 'class="active"';
6733: }
1.458 raeburn 6734: $form .= '<li style="float:right" '.$active
1.484 raeburn 6735: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
1.390 tempelho 6736: } else {
1.484.2.43 raeburn 6737: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6738:
6739: }
1.329 droeschl 6740: }
1.484 raeburn 6741: $form .= '</ul>'."\n";
6742: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6743:
6744: if ($to_show ne '') {
1.484.2.30 raeburn 6745: my $saveform;
6746: if ($need_save) {
6747: my $button = &mt('Make changes');
6748: my $path;
6749: if ($env{'form.folderpath'}) {
6750: $path =
6751: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6752: }
6753: $saveform = <<"END";
6754: <div id="multisave" style="display:none; clear:both;" >
6755: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6756: <input type="hidden" name="folderpath" value="$path" />
6757: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6758: <input type="hidden" name="allhiddenresource" value="" />
6759: <input type="hidden" name="allencrypturl" value="" />
6760: <input type="hidden" name="allrandompick" value="" />
6761: <input type="hidden" name="allrandomorder" value="" />
6762: <input type="hidden" name="changeparms" value="" />
6763: <input type="hidden" name="multiremove" value="" />
6764: <input type="hidden" name="multicut" value="" />
6765: <input type="hidden" name="multicopy" value="" />
6766: <input type="hidden" name="multichange" value="" />
6767: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6768: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6769: </form>
6770: </div>
6771: END
6772: }
6773: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6774: }
1.363 ehlerst 6775: foreach my $field (keys(%orderhash)){
1.390 tempelho 6776: if($field ne '00'){
1.422 onken 6777: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6778: $active = 'style="display: none;float:left"';
1.422 onken 6779: }elsif($activetab eq $field){
1.458 raeburn 6780: $active = 'style="display:block;float:left"';
1.422 onken 6781: }
6782: $form .= '<div id="'.$field.$tid.'"'
6783: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6784: .'</div>'."\n";
1.363 ehlerst 6785: }
6786: }
1.484 raeburn 6787: unless ($env{'form.docslog'}) {
6788: $form .= '</div></div>'."\n";
6789: }
1.329 droeschl 6790: return $form;
6791: }
6792:
6793: sub editing_js {
1.484.2.93.2. (raeburn 6794:): my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 6795: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6796: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6797: p_mnf => 'Name of New Folder',
6798: t_mnf => 'New Folder',
6799: p_mnp => 'Name of New Page',
6800: t_mnp => 'New Page',
1.451 www 6801: p_mxu => 'Title for the External Score',
1.349 biermanm 6802: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6803: p_msb => 'Title for the Problem',
6804: p_mdb => 'Title for the Drop Box',
1.336 schafran 6805: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6806: p_mwp => 'Title for Web Page',
1.348 weissno 6807: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6808: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6809: p_mab_alrt1 => 'Not a valid user:domain',
6810: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6811: p_chn => 'New Title',
6812: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6813: p_rmr2a => 'Remove',
6814: p_rmr2b => '?',
6815: p_rmr3a => 'Remove those',
6816: p_rmr3b => 'items?',
6817: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6818: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6819: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6820: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6821: p_ctr2a => 'Cut',
6822: p_ctr2b => '?',
6823: p_ctr3a => 'Cut those',
6824: p_ctr3b => 'items?',
1.478 raeburn 6825: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6826: imsfile => 'You must choose an IMS package for import',
6827: imscms => 'You must select which Course Management System was the source of the IMS package',
6828: invurl => 'Invalid URL',
6829: titbl => 'Title is blank',
1.484.2.30 raeburn 6830: more => '(More ...)',
6831: less => '(Less ...)',
6832: noor => 'No actions selected or changes to settings specified.',
6833: noch => 'No changes to settings specified.',
6834: noac => 'No actions selected.',
1.484.2.67 raeburn 6835: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6836: );
6837:
1.484.2.61 raeburn 6838: &js_escape(\%js_lt);
1.433 raeburn 6839: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6840: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6841: my $main_container_page;
1.484.2.19 raeburn 6842: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6843: $main_container_page = 1;
1.434 raeburn 6844: }
1.484.2.67 raeburn 6845: my $backtourl;
6846: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6847: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6848:
1.484.2.21 raeburn 6849: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6850: my $caller = $1;
6851: if ($caller =~ /^supplemental/) {
6852: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6853: } else {
6854: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6855: $res = &Apache::lonnet::clutter($res);
6856: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6857: my ($url,$anchor);
6858: if ($res =~ /^([^#]+)#([^#]+)$/) {
6859: $url = $1;
6860: $anchor = $2;
6861: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6862: $caller = $1.&escape('#').$anchor;
6863: }
1.484.2.67 raeburn 6864: } else {
6865: $url = $res;
1.484.2.66 raeburn 6866: }
1.484.2.83 raeburn 6867: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
6868: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
6869: $backtourl .= '?navmap=1';
6870: } else {
6871: $backtourl .= '?symb='.
6872: &HTML::Entities::encode($caller,'<>&"');
6873: }
1.484.2.80 raeburn 6874: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6875: if (($ENV{'SERVER_PORT'} == 443) &&
6876: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 6877: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 6878: if ($hostname ne '') {
6879: $backtourl = 'http://'.$hostname.$backtourl;
6880: }
6881: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6882: }
6883: }
6884: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6885: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.484.2.93 raeburn 6886: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 6887: if ($hostname ne '') {
6888: $backtourl = 'http://'.$hostname.$backtourl;
6889: }
6890: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6891: }
6892: }
6893: }
1.484.2.66 raeburn 6894: if ($anchor ne '') {
6895: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6896: }
1.484.2.57 raeburn 6897: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6898: } else {
6899: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6900: }
6901: }
6902: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6903: $backtourl = '/adm/menu';
6904: } elsif ($supplementalflag) {
1.472 raeburn 6905: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6906: } else {
6907: $backtourl = '/adm/navmaps';
1.472 raeburn 6908: }
6909:
1.484.2.19 raeburn 6910: my $fieldsets = "'ext','doc'";
1.484.2.93.2. (raeburn 6911:): if ($posslti) {
6912:): $fieldsets .= ",'tool'";
6913:): }
1.484.2.19 raeburn 6914: unless ($main_container_page) {
6915: $fieldsets .=",'ims'";
6916: }
1.484.2.12 raeburn 6917: if ($supplementalflag) {
6918: $fieldsets = "'suppext','suppdoc'";
1.484.2.93.2. (raeburn 6919:): if ($posslti) {
6920:): $fieldsets .= ",'supptool'";
6921:): }
1.484.2.12 raeburn 6922: }
6923:
1.484.2.67 raeburn 6924: my $jsmakefunctions;
6925: if ($canedit) {
6926: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6927: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6928: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6929: if (foldername) {
1.484.2.91 raeburn 6930: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 6931: targetform.submit();
6932: }
6933: }
6934:
6935: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6936: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6937: if (pagename) {
1.484.2.91 raeburn 6938: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 6939: targetform.submit();
6940: }
6941: }
6942:
6943: function makeexamupload() {
1.484.2.61 raeburn 6944: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6945: if (title) {
1.329 droeschl 6946: this.document.forms.newexamupload.importdetail.value=
1.484.2.91 raeburn 6947: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 6948: this.document.forms.newexamupload.submit();
6949: }
6950: }
6951:
6952: function makesmppage() {
1.484.2.61 raeburn 6953: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6954: if (title) {
1.329 droeschl 6955: this.document.forms.newsmppg.importdetail.value=
1.484.2.91 raeburn 6956: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6957: this.document.forms.newsmppg.submit();
6958: }
6959: }
6960:
1.484.2.27 raeburn 6961: function makewebpage(type) {
1.484.2.61 raeburn 6962: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6963: var formname;
6964: if (type == 'supp') {
6965: formname = this.document.forms.supwebpage;
6966: } else {
6967: formname = this.document.forms.newwebpage;
6968: }
6969: if (title) {
6970: var webpage = formname.importdetail.value;
1.484.2.91 raeburn 6971: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.484.2.27 raeburn 6972: formname.submit();
6973: }
6974: }
6975:
1.329 droeschl 6976: function makesmpproblem() {
1.484.2.61 raeburn 6977: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6978: if (title) {
1.329 droeschl 6979: this.document.forms.newsmpproblem.importdetail.value=
1.484.2.91 raeburn 6980: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 6981: this.document.forms.newsmpproblem.submit();
6982: }
6983: }
6984:
6985: function makedropbox() {
1.484.2.61 raeburn 6986: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6987: if (title) {
1.329 droeschl 6988: this.document.forms.newdropbox.importdetail.value=
1.484.2.91 raeburn 6989: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 6990: this.document.forms.newdropbox.submit();
6991: }
6992: }
6993:
6994: function makebulboard() {
1.484.2.61 raeburn 6995: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6996: if (title) {
6997: this.document.forms.newbul.importdetail.value=
1.484.2.91 raeburn 6998: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6999: this.document.forms.newbul.submit();
7000: }
7001: }
7002:
7003: function makeabout() {
1.484.2.61 raeburn 7004: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7005: if (user) {
7006: var comp=new Array();
7007: comp=user.split(':');
7008: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7009: if ((comp[0]) && (comp[1])) {
7010: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 7011: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 7012: this.document.forms.newaboutsomeone.submit();
7013: } else {
7014: alert("$js_lt{'p_mab_alrt1'}");
7015: }
7016: } else {
7017: alert("$js_lt{'p_mab_alrt2'}");
7018: }
7019: }
1.335 ehlerst 7020: }
1.484.2.67 raeburn 7021:
7022: function makenew(targetform) {
7023: targetform.submit();
1.335 ehlerst 7024: }
1.484.2.67 raeburn 7025:
7026: function changename(folderpath,index,oldtitle) {
7027: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7028: if (title) {
7029: this.document.forms.renameform.markcopy.value='';
7030: this.document.forms.renameform.title.value=title;
7031: this.document.forms.renameform.cmd.value='rename_'+index;
7032: this.document.forms.renameform.folderpath.value=folderpath;
7033: this.document.forms.renameform.submit();
7034: }
1.329 droeschl 7035: }
7036:
1.484.2.67 raeburn 7037: ENDNEWSCRIPT
7038: } else {
7039: $jsmakefunctions = <<ENDNEWSCRIPT;
7040:
7041: function makenewfolder() {
7042: alert("$js_lt{'edri'}");
7043: }
7044:
7045: function makenewpage() {
7046: alert("$js_lt{'edri'}");
7047: }
7048:
7049: function makeexamupload() {
7050: alert("$js_lt{'edri'}");
7051: }
7052:
7053: function makesmppage() {
7054: alert("$js_lt{'edri'}");
7055: }
7056:
7057: function makewebpage(type) {
7058: alert("$js_lt{'edri'}");
7059: }
7060:
7061: function makesmpproblem() {
7062: alert("$js_lt{'edri'}");
7063: }
7064:
7065: function makedropbox() {
7066: alert("$js_lt{'edri'}");
7067: }
7068:
7069: function makebulboard() {
7070: alert("$js_lt{'edri'}");
7071: }
7072:
7073: function makeabout() {
7074: alert("$js_lt{'edri'}");
7075: }
7076:
7077: function changename() {
7078: alert("$js_lt{'edri'}");
7079: }
7080:
7081: function makenew() {
7082: alert("$js_lt{'edri'}");
7083: }
7084:
7085: function groupimport() {
7086: alert("$js_lt{'edri'}");
7087: }
7088:
7089: function groupsearch() {
7090: alert("$js_lt{'edri'}");
7091: }
7092:
7093: function groupopen(url,recover) {
7094: var options="scrollbars=1,resizable=1,menubar=0";
7095: idxflag=1;
7096: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7097: idx.focus();
7098: }
7099:
7100: ENDNEWSCRIPT
7101:
7102: }
7103: return <<ENDSCRIPT;
7104:
7105: $jsmakefunctions
7106:
1.484.2.13 raeburn 7107: function toggleUpload(caller) {
7108: var blocks = Array($fieldsets);
7109: for (var i=0; i<blocks.length; i++) {
7110: var disp = 'none';
7111: if (caller == blocks[i]) {
7112: var curr = document.getElementById('upload'+caller+'form').style.display;
7113: if (curr == 'none') {
7114: disp='block';
7115: }
7116: }
7117: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.484.2.93.2. (raeburn 7118:): if ((caller == 'tool') || (caller == 'supptool')) {
7119:): if (disp == 'block') {
7120:): if (document.getElementById('LC_exttoolid')) {
7121:): var toolselector = document.getElementById('LC_exttoolid');
7122:): var suppflag = 0;
7123:): if (caller == 'supptool') {
7124:): suppflag = 1;
7125:): }
7126:): currForm = document.getElementById('new'+caller);
7127:): updateExttool(toolselector,currForm,suppflag);
7128:): }
7129:): }
7130:): }
1.484.2.13 raeburn 7131: }
7132: resize_scrollbox('contentscroll','1','1');
7133: return;
7134: }
7135:
1.484.2.19 raeburn 7136: function toggleMap(caller) {
1.484.2.13 raeburn 7137: var disp = 'none';
1.484.2.19 raeburn 7138: if (document.getElementById('importmapform')) {
7139: if (caller == 'map') {
7140: var curr = document.getElementById('importmapform').style.display;
7141: if (curr == 'none') {
7142: disp='block';
7143: }
1.484.2.12 raeburn 7144: }
1.484.2.19 raeburn 7145: document.getElementById('importmapform').style.display=disp;
7146: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 7147: }
1.484.2.19 raeburn 7148: return;
1.329 droeschl 7149: }
7150:
1.484.2.12 raeburn 7151: function makeims(imsform) {
7152: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 7153: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 7154: return;
7155: }
7156: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 7157: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 7158: return;
7159: }
7160: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7161: imsform.submit();
7162: }
7163:
1.478 raeburn 7164: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 7165: var pickitem;
7166: var picknumitem;
7167: var picknumtext;
7168: if (index == 'all') {
7169: pickitem = document.getElementById('randompickall');
7170: picknumitem = document.getElementById('rpicknumall');
7171: picknumtext = document.getElementById('rpicktextall');
7172: } else {
7173: pickitem = document.getElementById('randompick_'+index);
7174: picknumitem = document.getElementById('rpicknum_'+index);
7175: picknumtext = document.getElementById('randompicknum_'+index);
7176: }
1.478 raeburn 7177: if (pickitem.checked) {
1.484.2.61 raeburn 7178: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7179: if (picknum == '' || picknum == null) {
7180: if (caller == 'check') {
7181: pickitem.checked=false;
1.484.2.29 raeburn 7182: if (index == 'all') {
7183: picknumtext.innerHTML = '';
7184: if (caller == 'link') {
7185: propagateState(targetform,'rpicknum');
7186: }
7187: } else {
1.484.2.30 raeburn 7188: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7189: }
1.478 raeburn 7190: }
7191: } else {
7192: picknum.toString();
7193: var regexdigit=/^\\d+\$/;
7194: if (regexdigit.test(picknum)) {
7195: picknumitem.value = picknum;
1.484.2.29 raeburn 7196: if (index == 'all') {
1.484.2.30 raeburn 7197: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 7198: if (caller == 'link') {
7199: propagateState(targetform,'rpicknum');
7200: }
7201: } else {
7202: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 7203: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7204: }
1.478 raeburn 7205: } else {
7206: if (caller == 'check') {
1.484.2.29 raeburn 7207: if (index == 'all') {
7208: picknumtext.innerHTML = '';
7209: if (caller == 'link') {
7210: propagateState(targetform,'rpicknum');
7211: }
7212: } else {
7213: pickitem.checked=false;
1.484.2.30 raeburn 7214: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7215: }
1.478 raeburn 7216: }
7217: return;
7218: }
7219: }
7220: } else {
1.484.2.29 raeburn 7221: picknumitem.value = '';
7222: picknumtext.innerHTML = '';
7223: if (index == 'all') {
7224: if (caller == 'link') {
7225: propagateState(targetform,'rpicknum');
7226: }
7227: } else {
1.484.2.30 raeburn 7228: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7229: }
7230: }
7231: }
7232:
7233: function propagateState(form,param) {
7234: if (document.getElementById(param+'all')) {
7235: var setcheck = 0;
7236: var rpick = 0;
7237: if (param == 'rpicknum') {
7238: if (document.getElementById('randompickall')) {
7239: if (document.getElementById('randompickall').checked) {
7240: if (document.getElementById('rpicknumall')) {
7241: rpick = document.getElementById('rpicknumall').value;
7242: }
7243: }
7244: }
7245: } else {
7246: if (document.getElementById(param+'all').checked) {
7247: setcheck = 1;
7248: }
7249: }
1.484.2.30 raeburn 7250: var allidxlist;
7251: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7252: if (document.getElementById('all'+param+'idx')) {
7253: allidxlist = document.getElementById('all'+param+'idx').value;
7254: }
7255: var actions = new Array ('remove','cut','copy');
7256: for (var i=0; i<actions.length; i++) {
7257: if (actions[i] != param) {
7258: if (document.getElementById(actions[i]+'all')) {
7259: document.getElementById(actions[i]+'all').checked = false;
7260: }
7261: }
7262: }
7263: }
1.484.2.29 raeburn 7264: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 7265: allidxlist = form.allidx.value;
7266: }
7267: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7268: allidxlist = form.allmapidx.value;
7269: }
7270: if ((allidxlist != '') && (allidxlist != null)) {
7271: var allidxs = allidxlist.split(',');
7272: if (allidxs.length > 1) {
7273: for (var i=0; i<allidxs.length; i++) {
7274: if (document.getElementById(param+'_'+allidxs[i])) {
7275: if (param == 'rpicknum') {
7276: if (document.getElementById('randompick_'+allidxs[i])) {
7277: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7278: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7279: if (rpick > 0) {
7280: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7281: } else {
7282: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7283: }
7284: }
7285: }
7286: } else {
1.484.2.29 raeburn 7287: if (setcheck == 1) {
7288: document.getElementById(param+'_'+allidxs[i]).checked = true;
7289: } else {
7290: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 7291: if (param == 'randompick') {
7292: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7293: }
1.484.2.29 raeburn 7294: }
7295: }
7296: }
7297: }
1.484.2.30 raeburn 7298: if (setcheck == 1) {
7299: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7300: var actions = new Array('copy','cut','remove');
7301: for (var i=0; i<actions.length; i++) {
7302: var otheractions;
7303: var otheridxs;
7304: if (actions[i] === param) {
7305: continue;
7306: } else {
7307: if (document.getElementById('all'+actions[i]+'idx')) {
7308: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7309: otheridxs = otheractions.split(',');
7310: if (otheridxs.length > 1) {
7311: for (var j=0; j<otheridxs.length; j++) {
7312: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7313: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7314: }
1.484.2.29 raeburn 7315: }
7316: }
7317: }
7318: }
1.484.2.30 raeburn 7319: }
1.484.2.29 raeburn 7320: }
7321: }
7322: }
7323: }
1.478 raeburn 7324: }
1.484.2.29 raeburn 7325: return;
7326: }
7327:
1.484.2.63 raeburn 7328: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7329: var canedit = '$canedit';
7330: if (canedit == '') {
7331: alert("$js_lt{'edri'}");
7332: return;
7333: }
1.484.2.30 raeburn 7334: var dosettings;
7335: var doaction;
7336: var control = document.togglemultsettings;
7337: if (context == 'actions') {
7338: control = document.togglemultactions;
7339: doaction = 1;
7340: } else {
7341: dosettings = 1;
7342: }
7343: if (control) {
7344: if (control.showmultpick.length) {
7345: for (var i=0; i<control.showmultpick.length; i++) {
7346: if (control.showmultpick[i].checked) {
7347: if (control.showmultpick[i].value == 1) {
7348: if (context == 'settings') {
7349: dosettings = 0;
7350: } else {
7351: doaction = 0;
7352: }
7353: }
7354: }
7355: }
7356: }
7357: }
7358: if (context == 'settings') {
7359: if (dosettings == 1) {
7360: targetform.changeparms.value=param;
7361: targetform.submit();
7362: }
7363: }
7364: if (context == 'actions') {
7365: if (doaction == 1) {
7366: targetform.cmd.value=param+'_'+index;
7367: targetform.folderpath.value=folderpath;
7368: targetform.markcopy.value=idx+':'+param;
7369: targetform.copyfolder.value=folder+'.'+container;
7370: if (param == 'remove') {
1.484.2.63 raeburn 7371: var doremove = 0;
7372: if (skip_confirm) {
7373: if (confirm_removal) {
7374: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7375: doremove = 1;
7376: }
7377: } else {
7378: doremove = 1;
7379: }
7380: } else {
7381: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7382: doremove = 1;
7383: }
7384: }
7385: if (doremove) {
1.484.2.30 raeburn 7386: targetform.markcopy.value='';
7387: targetform.copyfolder.value='';
1.484.2.29 raeburn 7388: targetform.submit();
7389: }
7390: }
1.484.2.30 raeburn 7391: if (param == 'cut') {
1.484.2.61 raeburn 7392: if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) {
1.484.2.30 raeburn 7393: targetform.submit();
7394: return;
7395: }
7396: }
7397: if (param == 'copy') {
7398: targetform.submit();
7399: return;
7400: }
7401: targetform.markcopy.value='';
7402: targetform.copyfolder.value='';
7403: targetform.cmd.value='';
7404: targetform.folderpath.value='';
7405: return;
7406: } else {
7407: if (document.getElementById(param+'_'+idx)) {
7408: item = document.getElementById(param+'_'+idx);
7409: if (item.type == 'checkbox') {
7410: if (item.checked) {
7411: item.checked = false;
7412: } else {
7413: item.checked = true;
7414: singleCheck(item,idx,param);
7415: }
7416: }
7417: }
7418: }
7419: }
7420: return;
7421: }
7422:
7423: function singleCheck(caller,idx,action) {
7424: actions = new Array('cut','copy','remove');
7425: if (caller.checked) {
7426: for (var i=0; i<actions.length; i++) {
7427: if (actions[i] != action) {
7428: if (document.getElementById(actions[i]+'_'+idx)) {
7429: if (document.getElementById(actions[i]+'_'+idx).checked) {
7430: document.getElementById(actions[i]+'_'+idx).checked = false;
7431: }
7432: }
7433: }
1.484.2.29 raeburn 7434: }
7435: }
7436: return;
1.478 raeburn 7437: }
7438:
1.334 muellerd 7439: function unselectInactive(nav) {
1.335 ehlerst 7440: currentNav = document.getElementById(nav);
7441: currentLis = currentNav.getElementsByTagName('LI');
7442: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7443: if (currentLis[i].className == 'goback') {
7444: currentLis[i].className = 'goback';
7445: } else {
7446: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7447: currentLis[i].className = 'right';
1.472 raeburn 7448: } else {
1.374 tempelho 7449: currentLis[i].className = 'i';
1.472 raeburn 7450: }
7451: }
1.335 ehlerst 7452: }
1.332 tempelho 7453: }
7454:
1.334 muellerd 7455: function hideAll(current, nav, data) {
1.335 ehlerst 7456: unselectInactive(nav);
1.484.2.43 raeburn 7457: if (current) {
7458: if (current.className == 'right'){
1.374 tempelho 7459: current.className = 'right active'
1.484.2.43 raeburn 7460: } else {
1.374 tempelho 7461: current.className = 'active';
1.484.2.43 raeburn 7462: }
1.374 tempelho 7463: }
1.335 ehlerst 7464: currentData = document.getElementById(data);
7465: currentDivs = currentData.getElementsByTagName('DIV');
7466: for (i = 0; i < currentDivs.length; i++) {
7467: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7468: currentDivs[i].style.display = 'none';
1.330 tempelho 7469: }
7470: }
1.335 ehlerst 7471: }
1.330 tempelho 7472:
1.374 tempelho 7473: function openTabs(pageId) {
7474: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7475: if(tabnav.length > 2 ){
1.389 tempelho 7476: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7477: currentLis = currentNav.getElementsByTagName('LI');
7478: for(i = 0; i< currentLis.length; i++){
7479: if(currentLis[i].className == 'active') {
1.375 tempelho 7480: funcString = currentLis[i].onclick.toString();
7481: tab = funcString.split('"');
1.420 onken 7482: if(tab.length < 2) {
7483: tab = funcString.split("'");
7484: }
1.375 tempelho 7485: currentData = document.getElementById(tab[1]);
7486: currentData.style.display = 'block';
1.374 tempelho 7487: }
7488: }
7489: }
7490: }
7491:
1.334 muellerd 7492: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7493: currstate = current.className;
1.334 muellerd 7494: hideAll(current, nav, data);
1.375 tempelho 7495: openTabs(pageId);
1.334 muellerd 7496: unselectInactive(nav);
1.484.2.43 raeburn 7497: if ((currstate == 'active') || (currstate == 'right active')) {
7498: if (currstate == 'active') {
7499: current.className = '';
7500: } else {
7501: current.className = 'right';
7502: }
7503: activeTab = '';
7504: toggleUpload();
7505: toggleMap();
7506: resize_scrollbox('contentscroll','1','0');
7507: return;
7508: } else {
7509: current.className = 'active';
7510: }
1.330 tempelho 7511: currentData = document.getElementById(pageId);
7512: currentData.style.display = 'block';
1.458 raeburn 7513: activeTab = pageId;
1.484.2.12 raeburn 7514: toggleUpload();
1.484.2.14 raeburn 7515: toggleMap();
1.433 raeburn 7516: if (nav == 'mainnav') {
7517: var storedpath = "$docs_folderpath";
1.434 raeburn 7518: var storedpage = "$main_container_page";
1.433 raeburn 7519: var reg = new RegExp("^supplemental");
7520: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7521: if (storedpage == 1) {
7522: document.simpleedit.folderpath.value = '';
7523: document.uploaddocument.folderpath.value = '';
7524: } else {
7525: if (reg.test(storedpath)) {
7526: document.simpleedit.folderpath.value = '$toplevelmain';
7527: document.uploaddocument.folderpath.value = '$toplevelmain';
7528: document.newext.folderpath.value = '$toplevelmain';
7529: } else {
7530: document.simpleedit.folderpath.value = storedpath;
7531: document.uploaddocument.folderpath.value = storedpath;
7532: document.newext.folderpath.value = storedpath;
7533: }
1.433 raeburn 7534: }
7535: } else {
1.434 raeburn 7536: if (reg.test(storedpath)) {
7537: document.simpleedit.folderpath.value = storedpath;
7538: document.supuploaddocument.folderpath.value = storedpath;
7539: document.supnewext.folderpath.value = storedpath;
7540: } else {
1.433 raeburn 7541: document.simpleedit.folderpath.value = '$toplevelsupp';
7542: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7543: document.supnewext.folderpath.value = '$toplevelsupp';
7544: }
7545: }
7546: }
1.484.2.3 raeburn 7547: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7548: return false;
7549: }
1.329 droeschl 7550:
1.472 raeburn 7551: function toContents(jumpto) {
7552: var newurl = '$backtourl';
1.484.2.21 raeburn 7553: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7554: newurl = newurl+'?postdata='+jumpto;
7555: }
7556: location.href=newurl;
7557: }
7558:
1.484.2.30 raeburn 7559: function togglePick(caller,value) {
7560: var disp = 'none';
7561: if (document.getElementById('multi'+caller)) {
7562: var curr = document.getElementById('multi'+caller).style.display;
7563: if (value == 1) {
7564: disp='block';
7565: }
7566: if (curr == disp) {
7567: return;
7568: }
7569: document.getElementById('multi'+caller).style.display=disp;
7570: if (value == 1) {
1.484.2.61 raeburn 7571: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7572: } else {
7573: document.getElementById('more'+caller).innerHTML = '';
7574: }
7575: if (caller == 'actions') {
7576: setClass(value);
7577: setBoxes(value);
7578: }
7579: }
7580: var showButton = multiSettings();
7581: if (showButton != 1) {
7582: showButton = multiActions();
7583: }
7584: if (document.getElementById('multisave')) {
7585: if (showButton == 1) {
7586: document.getElementById('multisave').style.display='block';
7587: } else {
7588: document.getElementById('multisave').style.display='none';
7589: }
7590: }
7591: resize_scrollbox('contentscroll','1','1');
7592: return;
7593: }
7594:
7595: function toggleCheckUncheck(caller,more) {
7596: if (more == 1) {
1.484.2.61 raeburn 7597: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7598: document.getElementById('allfields'+caller).style.display='block';
7599: } else {
1.484.2.61 raeburn 7600: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7601: document.getElementById('allfields'+caller).style.display='none';
7602: }
7603: resize_scrollbox('contentscroll','1','1');
7604: }
7605:
7606: function multiSettings() {
7607: var inuse = 0;
7608: var settingsform = document.togglemultsettings;
7609: if (settingsform.showmultpick.length > 1) {
7610: for (var i=0; i<settingsform.showmultpick.length; i++) {
7611: if (settingsform.showmultpick[i].checked) {
7612: if (settingsform.showmultpick[i].value == 1) {
7613: inuse = 1;
7614: }
7615: }
7616: }
7617: }
7618: return inuse;
7619: }
7620:
7621: function multiActions() {
7622: var inuse = 0;
7623: var actionsform = document.togglemultactions;
7624: if (actionsform.showmultpick.length > 1) {
7625: for (var i=0; i<actionsform.showmultpick.length; i++) {
7626: if (actionsform.showmultpick[i].checked) {
7627: if (actionsform.showmultpick[i].value == 1) {
7628: inuse = 1;
7629: }
7630: }
7631: }
7632: }
7633: return inuse;
7634: }
7635:
7636: function checkSubmits() {
7637: var numchanges = 0;
7638: var form = document.saveactions;
7639: var doactions = multiActions();
7640: var cutwarnings = 0;
7641: var remwarnings = 0;
1.484.2.63 raeburn 7642: var removalinfo = 0;
1.484.2.30 raeburn 7643: if (doactions == 1) {
7644: var remidxlist = document.cumulativeactions.allremoveidx.value;
7645: if ((remidxlist != '') && (remidxlist != null)) {
7646: var remidxs = remidxlist.split(',');
7647: for (var i=0; i<remidxs.length; i++) {
7648: if (document.getElementById('remove_'+remidxs[i])) {
7649: if (document.getElementById('remove_'+remidxs[i]).checked) {
7650: form.multiremove.value += remidxs[i]+',';
7651: numchanges ++;
7652: if (document.getElementById('skip_remove_'+remidxs[i])) {
7653: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7654: remwarnings ++;
7655: }
7656: }
1.484.2.63 raeburn 7657: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7658: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7659: removalinfo ++;
7660: }
7661: }
1.484.2.30 raeburn 7662: }
7663: }
7664: }
7665: }
7666: var cutidxlist = document.cumulativeactions.allcutidx.value;
7667: if ((cutidxlist != '') && (cutidxlist != null)) {
7668: var cutidxs = cutidxlist.split(',');
7669: for (var i=0; i<cutidxs.length; i++) {
7670: if (document.getElementById('cut_'+cutidxs[i])) {
7671: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7672: form.multicut.value += cutidxs[i]+',';
7673: numchanges ++;
7674: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7675: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7676: cutwarnings ++;
7677: }
7678: }
7679: }
7680: }
7681: }
7682: }
7683: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7684: if ((copyidxlist != '') && (copyidxlist != null)) {
7685: var copyidxs = copyidxlist.split(',');
7686: for (var i=0; i<copyidxs.length; i++) {
7687: if (document.getElementById('copy_'+copyidxs[i])) {
7688: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7689: form.multicopy.value += copyidxs[i]+',';
7690: numchanges ++;
7691: }
7692: }
7693: }
7694: }
7695: if (numchanges > 0) {
7696: form.multichange.value = numchanges;
7697: }
7698: }
7699: var dosettings = multiSettings();
7700: var haschanges = 0;
7701: if (dosettings == 1) {
7702: form.allencrypturl.value = '';
7703: form.allhiddenresource.value = '';
7704: form.changeparms.value = 'all';
7705: var patt=new RegExp(",\$");
7706: var allidxlist = document.cumulativesettings.allidx.value;
7707: if ((allidxlist != '') && (allidxlist != null)) {
7708: var allidxs = allidxlist.split(',');
7709: if (allidxs.length > 1) {
7710: for (var i=0; i<allidxs.length; i++) {
7711: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7712: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7713: form.allhiddenresource.value += allidxs[i]+',';
7714: }
7715: }
7716: if (document.getElementById('encrypturl_'+allidxs[i])) {
7717: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7718: form.allencrypturl.value += allidxs[i]+',';
7719: }
1.484.2.29 raeburn 7720: }
7721: }
1.484.2.30 raeburn 7722: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7723: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7724: }
7725: }
7726: form.allrandompick.value = '';
7727: form.allrandomorder.value = '';
7728: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7729: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7730: var allmapidxs = allmapidxlist.split(',');
7731: for (var i=0; i<allmapidxs.length; i++) {
7732: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7733: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7734: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7735: if ((randompick.checked) && (rpicknum.value != '')) {
7736: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7737: }
7738: if (randorder.checked) {
7739: form.allrandomorder.value += allmapidxs[i]+',';
7740: }
7741: }
7742: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7743: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7744: }
7745: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7746: haschanges = 1;
7747: }
7748: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7749: haschanges = 1;
7750: }
7751: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7752: haschanges = 1;
7753: }
7754: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7755: haschanges = 1;
7756: }
7757: }
7758: if (doactions == 1) {
7759: if (numchanges > 0) {
1.484.2.63 raeburn 7760: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7761: if (remwarnings > 0) {
1.484.2.61 raeburn 7762: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7763: return false;
7764: }
7765: }
1.484.2.63 raeburn 7766: if (removalinfo > 0) {
7767: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7768: return false;
7769: }
7770: }
1.484.2.30 raeburn 7771: if (cutwarnings > 0) {
1.484.2.61 raeburn 7772: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
1.484.2.30 raeburn 7773: return false;
1.484.2.29 raeburn 7774: }
7775: }
7776: }
1.484.2.30 raeburn 7777: form.submit();
7778: return true;
7779: }
7780: }
7781: if (dosettings == 1) {
7782: if (haschanges == 1) {
7783: form.submit();
7784: return true;
1.484.2.29 raeburn 7785: }
7786: }
1.484.2.30 raeburn 7787: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7788: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7789: } else {
7790: if (dosettings == 1) {
1.484.2.61 raeburn 7791: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7792: } else {
1.484.2.61 raeburn 7793: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7794: }
7795: }
7796: return false;
7797: }
7798:
7799: function setClass(value) {
7800: var cutclass = 'LC_docs_cut';
7801: var copyclass = 'LC_docs_copy';
7802: var removeclass = 'LC_docs_remove';
7803: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7804: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7805: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7806: var links = document.getElementsByTagName('a');
7807: for (var i=0; i<links.length; i++) {
7808: var classes = links[i].className;
7809: if (cutreg.test(classes)) {
7810: links[i].className = cutclass;
7811: if (value == 1) {
7812: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7813: }
1.484.2.30 raeburn 7814: } else {
7815: if (copyreg.test(classes)) {
7816: links[i].className = copyclass;
7817: if (value == 1) {
7818: links[i].className += " LC_menubuttons_link";
7819: }
7820: } else {
7821: if (removereg.test(classes)) {
7822: links[i].className = removeclass;
7823: if (value == 1) {
7824: links[i].className += " LC_menubuttons_link";
7825: }
7826: }
1.484.2.29 raeburn 7827: }
7828: }
7829: }
1.484.2.30 raeburn 7830: return;
1.484.2.29 raeburn 7831: }
7832:
1.484.2.30 raeburn 7833: function setBoxes(value) {
7834: var remidxlist = document.cumulativeactions.allremoveidx.value;
7835: if ((remidxlist != '') && (remidxlist != null)) {
7836: var remidxs = remidxlist.split(',');
7837: for (var i=0; i<remidxs.length; i++) {
7838: if (document.getElementById('remove_'+remidxs[i])) {
7839: var item = document.getElementById('remove_'+remidxs[i]);
7840: if (value == 1) {
7841: item.className = 'LC_docs_remove';
7842: } else {
7843: item.className = 'LC_hidden';
7844: }
7845: }
1.484.2.29 raeburn 7846: }
7847: }
1.484.2.30 raeburn 7848: var cutidxlist = document.cumulativeactions.allcutidx.value;
7849: if ((cutidxlist != '') && (cutidxlist != null)) {
7850: var cutidxs = cutidxlist.split(',');
7851: for (var i=0; i<cutidxs.length; i++) {
7852: if (document.getElementById('cut_'+cutidxs[i])) {
7853: var item = document.getElementById('cut_'+cutidxs[i]);
7854: if (value == 1) {
7855: item.className = 'LC_docs_cut';
7856: } else {
7857: item.className = 'LC_hidden';
7858: }
7859: }
7860: }
7861: }
7862: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7863: if ((copyidxlist != '') && (copyidxlist != null)) {
7864: var copyidxs = copyidxlist.split(',');
7865: for (var i=0; i<copyidxs.length; i++) {
7866: if (document.getElementById('copy_'+copyidxs[i])) {
7867: var item = document.getElementById('copy_'+copyidxs[i]);
7868: if (value == 1) {
7869: item.className = 'LC_docs_copy';
7870: } else {
7871: item.className = 'LC_hidden';
7872: }
7873: }
1.484.2.29 raeburn 7874: }
7875: }
7876: return;
7877: }
7878:
1.484.2.67 raeburn 7879: ENDSCRIPT
1.329 droeschl 7880: }
1.457 raeburn 7881:
1.483 raeburn 7882: sub history_tab_js {
7883: return <<"ENDHIST";
7884: function toggleHistoryDisp(choice) {
7885: document.docslogform.docslog.value = choice;
7886: document.docslogform.submit();
7887: return;
7888: }
7889:
7890: ENDHIST
7891: }
7892:
1.484 raeburn 7893: sub inject_data_js {
7894: return <<ENDINJECT;
7895:
7896: function injectData(current, hiddenField, name, value) {
7897: currentElement = document.getElementById(hiddenField);
7898: currentElement.name = name;
7899: currentElement.value = value;
7900: current.submit();
7901: }
7902:
7903: ENDINJECT
7904: }
7905:
7906: sub dump_switchserver_js {
7907: my @hosts = @_;
1.484.2.61 raeburn 7908: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7909: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7910: swit => 'Switch server?',
1.484.2.61 raeburn 7911: );
7912: my %html_js_lt = &Apache::lonlocal::texthash(
7913: swit => 'Switch server?',
1.484.2.43 raeburn 7914: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7915: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7916: chos => 'Choose server',
7917: );
1.484.2.61 raeburn 7918: &js_escape(\%js_lt);
7919: &html_escape(\%html_js_lt);
7920: &js_escape(\%html_js_lt);
1.484 raeburn 7921: my $role = $env{'request.role'};
7922: my $js = <<"ENDSWJS";
7923: <script type="text/javascript">
7924: function write_switchserver() {
7925: var server;
7926: if (document.setserver.posshosts.length > 0) {
7927: for (var i=0; i<document.setserver.posshosts.length; i++) {
7928: if (document.setserver.posshosts[i].checked) {
7929: server = document.setserver.posshosts[i].value;
7930: }
7931: }
7932: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7933: }
7934: window.close();
7935: }
7936: </script>
7937:
7938: ENDSWJS
7939:
7940: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7941: {'only_body' => 1,
7942: 'js_ready' => 1,});
7943: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7944:
7945: my $hostpicker;
7946: my $count = 0;
7947: foreach my $host (sort(@hosts)) {
7948: my $checked;
7949: if ($count == 0) {
7950: $checked = ' checked="checked"';
7951: }
7952: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7953: $host.'"'.$checked.' />'.$host.'</label> ';
7954: $count++;
7955: }
7956:
7957: return <<"ENDSWITCHJS";
7958:
7959: function dump_needs_switchserver(url) {
7960: if (url!='' && url!= null) {
1.484.2.61 raeburn 7961: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7962: go(url);
7963: }
7964: }
7965: return;
7966: }
7967:
7968: function choose_switchserver_window() {
7969: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7970: newWindow.document.open();
7971: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7972: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7973: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7974: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7975: '<form name="setserver" method="post" action="" \\/>\\n'+
7976: '$hostpicker\\n'+
7977: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7978: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7979: 'onclick="write_switchserver();" \\/>\\n'+
7980: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7981: newWindow.document.writeln('$endpage');
7982: newWindow.document.close();
7983: newWindow.focus();
7984: }
7985:
7986: ENDSWITCHJS
7987: }
7988:
7989: sub makedocslogform {
7990: my ($formelems,$docslog) = @_;
7991: return <<"LOGSFORM";
7992: <form action="/adm/coursedocs" method="post" name="docslogform">
7993: <input type="hidden" name="docslog" value="$docslog" />
7994: $formelems
7995: </form>
7996: LOGSFORM
7997: }
7998:
7999: sub makesimpleeditform {
8000: my ($formelems) = @_;
8001: return <<"SIMPFORM";
8002: <form name="simpleedit" method="post" action="/adm/coursedocs">
8003: <input type="hidden" name="importdetail" value="" />
8004: $formelems
8005: </form>
8006: SIMPFORM
8007: }
8008:
1.329 droeschl 8009: 1;
8010: __END__
8011:
8012:
8013: =head1 NAME
8014:
8015: Apache::londocs.pm
8016:
8017: =head1 SYNOPSIS
8018:
8019: This is part of the LearningOnline Network with CAPA project
8020: described at http://www.lon-capa.org.
8021:
8022: =head1 SUBROUTINES
8023:
8024: =over
8025:
8026: =item %help=()
8027:
8028: Available help topics
8029:
8030: =item mapread()
8031:
1.344 bisitz 8032: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8033: @order and @resources, determines status
8034: sets @order - pointer to resources in right order
8035: sets @resources - array with the resources with correct idx
8036:
8037: =item authorhosts()
8038:
8039: Return hash with valid author names
8040:
8041: =item clean()
8042:
8043: =item dumpcourse()
8044:
8045: Actually dump course
8046:
8047: =item group_import()
8048:
8049: Imports the given (name, url) resources into the course
8050: coursenum, coursedom, and folder must precede the list
8051:
8052: =item breadcrumbs()
8053:
8054: =item log_docs()
8055:
8056: =item docs_change_log()
8057:
8058: =item update_paste_buffer()
8059:
8060: =item print_paste_buffer()
8061:
8062: =item do_paste_from_buffer()
8063:
1.484.2.30 raeburn 8064: =item do_buffer_empty()
8065:
8066: =item clear_from_buffer()
8067:
1.484.2.7 raeburn 8068: =item get_newmap_url()
8069:
8070: =item dbcopy()
8071:
8072: =item uniqueness_check()
8073:
8074: =item contained_map_check()
8075:
8076: =item url_paste_fixups()
8077:
8078: =item apply_fixups()
8079:
8080: =item copy_dependencies()
8081:
1.329 droeschl 8082: =item update_parameter()
8083:
8084: =item handle_edit_cmd()
8085:
8086: =item editor()
8087:
8088: =item process_file_upload()
8089:
8090: =item process_secondary_uploads()
8091:
8092: =item is_supplemental_title()
8093:
8094: =item entryline()
8095:
8096: =item tiehash()
8097:
8098: =item untiehash()
8099:
8100: =item checkonthis()
8101:
8102: check on this
8103:
8104: =item verifycontent()
8105:
8106: Verify Content
8107:
1.484.2.78 raeburn 8108: =item devalidateversioncache()
8109:
8110: =item checkversions()
1.329 droeschl 8111:
8112: Check Versions
8113:
8114: =item mark_hash_old()
8115:
8116: =item is_hash_old()
8117:
8118: =item changewarning()
8119:
8120: =item init_breadcrumbs()
8121:
8122: Breadcrumbs for special functions
8123:
1.484 raeburn 8124: =item create_list_elements()
8125:
8126: =item create_form_ul()
8127:
8128: =item startContentScreen()
8129:
8130: =item endContentScreen()
8131:
8132: =item supplemental_base()
8133:
8134: =item embedded_form_elems()
8135:
8136: =item embedded_destination()
8137:
8138: =item return_to_editor()
8139:
8140: =item decompression_info()
8141:
8142: =item decompression_phase_one()
8143:
8144: =item decompression_phase_two()
8145:
8146: =item remove_archive()
8147:
8148: =item generate_admin_menu()
8149:
8150: =item generate_edit_table()
8151:
8152: =item editing_js()
8153:
8154: =item history_tab_js()
8155:
8156: =item inject_data_js()
8157:
8158: =item dump_switchserver_js()
8159:
1.484.2.3 raeburn 8160: =item resize_scrollbox_js()
1.484 raeburn 8161:
8162: =item makedocslogform()
8163:
1.484.2.3 raeburn 8164: =item makesimpleeditform()
8165:
1.329 droeschl 8166: =back
8167:
8168: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>