Annotation of loncom/interface/londocs.pm, revision 1.484.2.93.2.6
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.5 2023/01/18 22:38: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);
1.484.2.93.2. (raeburn 3010:): next unless $url;
1.484.2.29 raeburn 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.93.2. (raeburn 4148:): my ($checkencrypt,$shownurl);
4149:): if (!$env{'request.role.adv'}) {
1.484.2.67 raeburn 4150: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.484.2.93.2. (raeburn 4151:): ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.484.2.67 raeburn 4152: $checkencrypt = 1;
1.484.2.70 raeburn 4153: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 4154: unless (ref($$navmapref)) {
4155: $$navmapref = Apache::lonnavmaps::navmap->new();
4156: }
4157: if (ref($$navmapref)) {
4158: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4159: $checkencrypt = 1;
4160: }
4161: }
4162: }
1.484.2.93.2. (raeburn 4163:): }
4164:): if ($checkencrypt) {
4165:): my $currenc = $env{'request.enc'};
4166:): $env{'request.enc'} = 1;
4167:): $shownsymb = &Apache::lonenc::encrypted($symb);
4168:): $shownurl = &Apache::lonenc::encrypted($url);
4169:): if (&Apache::lonnet::symbverify($symb,$url)) {
4170:): $url = $shownurl;
1.484.2.67 raeburn 4171: } else {
1.484.2.93.2. (raeburn 4172:): $url = '';
1.484.2.67 raeburn 4173: }
1.484.2.93.2. (raeburn 4174:): $env{'request.enc'} = $currenc;
4175:): } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4176:): $shownsymb = $symb;
4177:): if ($isexternal) {
4178:): $url =~ s/\#[^#]+$//;
4179:): if ($container eq 'page') {
4180:): $url = &Apache::lonnet::clutter($url);
4181:): }
4182:): }
4183:): $shownurl = $url;
4184:): }
4185:): unless ($env{'request.role.adv'}) {
4186:): if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4187:): $url = '';
4188:): }
4189:): if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4190:): $url = '';
4191:): $hiddenres = 1;
4192:): }
4193:): }
4194:): if ($url ne '') {
4195:): $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.12 raeburn 4196: }
1.484.2.19 raeburn 4197: }
1.484.2.66 raeburn 4198: } elsif ($supplementalflag) {
4199: if ($isexternal) {
4200: if ($url =~ /^([^#]+)#([^#]+)$/) {
4201: $url = $1;
4202: $anchor = $2;
1.484.2.70 raeburn 4203: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.93 raeburn 4204: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4205: if ($hostname ne '') {
4206: $url = 'http://'.$hostname.$url;
4207: }
4208: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4209: }
1.484.2.70 raeburn 4210: $nomodal = 1;
4211: }
4212: }
4213: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4214: if (($ENV{'SERVER_PORT'} == 443) &&
4215: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 4216: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4217: if ($hostname ne '') {
4218: $url = 'http://'.$hostname.$url;
4219: }
4220: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4221: }
1.484.2.70 raeburn 4222: $nomodal = 1;
1.484.2.66 raeburn 4223: }
4224: }
1.329 droeschl 4225: }
1.484.2.67 raeburn 4226: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4227: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4228: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4229: my $foldername=&escape($foldertitle);
4230: my $folderpath=$env{'form.folderpath'};
4231: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4232: if (!$allowed && $supplementalflag) {
4233: $folderpath.=$containerarg.'&'.$foldername;
4234: $url.='folderpath='.&escape($folderpath);
4235: } else {
4236: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4237: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4238: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4239: 'parameter_randomorder'))[0]=~/^yes$/i);
4240: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4241: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4242: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4243: 'parameter_encrypturl'))[0]=~/^yes$/i);
4244: unless ($hiddenmap) {
1.484.2.70 raeburn 4245: if (ref($navmapref)) {
4246: unless (ref($$navmapref)) {
4247: $$navmapref = Apache::lonnavmaps::navmap->new();
4248: }
4249: if (ref($$navmapref)) {
4250: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4251: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4252: unless (@resources) {
4253: $hiddenmap = 1;
4254: unless ($env{'request.role.adv'}) {
4255: $url = '';
4256: $hiddenfolder = 1;
4257: }
1.484.2.67 raeburn 4258: }
4259: }
4260: }
4261: }
4262: }
4263: unless ($encryptmap) {
1.484.2.70 raeburn 4264: if ((ref($navmapref)) && (ref($$navmapref))) {
4265: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4266: $encryptmap = 1;
4267: }
1.484.2.67 raeburn 4268: }
4269: }
4270:
4271: # Append randompick number, hidden, and encrypted with ":" to foldername,
4272: # so it gets transferred between levels
4273: $folderpath.=$containerarg.'&'.$foldername.
4274: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4275: unless ($url eq '') {
4276: $url.='folderpath='.&escape($folderpath);
4277: }
1.484.2.19 raeburn 4278: my $rpckchk;
4279: if ($rpicknum) {
4280: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4281: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4282: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4283: }
1.484.2.19 raeburn 4284: }
1.484.2.29 raeburn 4285: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4286: $rand_pick_text =
1.478 raeburn 4287: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4288: $form_param."\n".
1.478 raeburn 4289: $form_common."\n".
1.484.2.67 raeburn 4290: '<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 4291: if ($rpicknum ne '') {
4292: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4293: }
1.484.2.29 raeburn 4294: $rand_pick_text .= '</span></span>'.
4295: $form_end;
1.484.2.30 raeburn 4296: my $ro_set;
1.484.2.67 raeburn 4297: if ($randorder) {
1.484.2.30 raeburn 4298: $ro_set = 'checked="checked"';
4299: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4300: push(@{$filtersref->{'randomorder'}},$orderidx);
4301: }
4302: }
1.484.2.41 raeburn 4303: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4304: $rand_order_text =
1.484.2.29 raeburn 4305: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4306: $form_param."\n".
1.484.2.29 raeburn 4307: $form_common."\n".
1.484.2.67 raeburn 4308: '<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 4309: $form_end;
1.484.2.19 raeburn 4310: }
1.484.2.18 raeburn 4311: } elsif ($supplementalflag && !$allowed) {
1.484.2.93.2. (raeburn 4312:): my $isexttool;
4313:): if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4314:): $url='/adm/wrapper'.$url;
4315:): $isexttool = 1;
4316:): }
1.484.2.19 raeburn 4317: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4318: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4319: if ($title) {
4320: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4321: }
1.484.2.93.2. (raeburn 4322:): if ((($isexternal) || ($isexttool)) && $orderidx) {
1.484.2.19 raeburn 4323: $url .= '&idx='.$orderidx;
4324: }
1.484.2.66 raeburn 4325: if ($anchor ne '') {
4326: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4327: }
1.329 droeschl 4328: }
1.484.2.19 raeburn 4329: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4330: if ($allowed) {
1.484.2.19 raeburn 4331: my $fileloc =
1.484.2.12 raeburn 4332: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4333: if ($isexternal) {
4334: ($editlink,$extresform) =
1.484.2.67 raeburn 4335: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
1.484.2.93.2. (raeburn 4336:): undef,undef,undef,undef,undef,undef,
4337:): undef,$disabled);
4338:): } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4339:): ($editlink,$extresform) =
4340:): &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4341:): undef,undef,undef,'tool',$coursedom,
4342:): $coursenum,$ltitoolsref,$disabled);
1.484.2.19 raeburn 4343: } elsif (!$isfolder && !$ispage) {
4344: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4345: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4346: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4347: my $suppanchor;
4348: if ($supplementalflag) {
4349: $suppanchor = $anchor;
4350: }
1.484.2.19 raeburn 4351: my $jscall =
1.484.2.12 raeburn 4352: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4353: $switchserver,
1.484.2.14 raeburn 4354: $forceedit,
1.484.2.93.2. (raeburn 4355:): undef,$symb,$shownsymb,
1.484.2.19 raeburn 4356: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4357: $renametitle,$hostname,
4358: '','',1,$suppanchor);
1.484.2.12 raeburn 4359: if ($jscall) {
1.484.2.19 raeburn 4360: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4361: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4362: }
4363: }
4364: }
1.484.2.19 raeburn 4365: $tdalign = ' align="right" valign="top"';
4366: $tdwidth = ' width="80%"';
1.329 droeschl 4367: }
1.408 raeburn 4368: my $reinit;
4369: if ($crstype eq 'Community') {
4370: $reinit = &mt('(re-initialize community to access)');
4371: } else {
4372: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4373: }
4374: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4375: my $link;
1.472 raeburn 4376: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4377: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4378: } elsif ($url) {
1.484.2.66 raeburn 4379: if ($anchor ne '') {
4380: if ($supplementalflag) {
4381: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4382: } else {
4383: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4384: }
4385: }
1.484.2.80 raeburn 4386:
4387: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4388: $link = 'http://'.$hostname.$url;
4389: } else {
4390: $link = $url;
4391: }
4392: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4393: if ($nomodal) {
4394: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4395: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4396: } else {
4397: $line.=&Apache::loncommon::modal_link($link,
4398: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4399: }
1.469 www 4400: } else {
4401: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4402: }
1.484.2.19 raeburn 4403: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4404: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4405: $line.='<a href="'.$url.'">'.$title.'</a>';
4406: } elsif ($url) {
1.484.2.70 raeburn 4407: if ($nomodal) {
4408: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4409: $title.'</a>';
4410: } else {
4411: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4412: }
1.484.2.67 raeburn 4413: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4414: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4415: } else {
4416: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4417: }
1.484.2.19 raeburn 4418: $line.="$extresform</td>";
1.478 raeburn 4419: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4420: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4421: if (($allowed) && ($folder!~/^supplemental/)) {
4422: my %lt=&Apache::lonlocal::texthash(
4423: 'hd' => 'Hidden',
4424: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4425: my ($enctext,$hidtext);
4426: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4427: $enctext = ' checked="checked"';
4428: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4429: push(@{$filtersref->{'encrypturl'}},$orderidx);
4430: }
4431: }
4432: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4433: $hidtext = ' checked="checked"';
4434: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4435: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4436: }
4437: }
1.484.2.29 raeburn 4438: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4439: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4440: $line.=(<<ENDPARMS);
4441: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4442: <form action="/adm/coursedocs" method="post" name="$formhidden">
4443: $form_param
1.478 raeburn 4444: $form_common
1.484.2.67 raeburn 4445: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4446: $form_end
1.458 raeburn 4447: <br />
1.484.2.29 raeburn 4448: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4449: $form_param
1.478 raeburn 4450: $form_common
1.484.2.67 raeburn 4451: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4452: $form_end
4453: </td>
1.478 raeburn 4454: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4455: $rand_order_text</td>
1.329 droeschl 4456: ENDPARMS
4457: }
1.379 bisitz 4458: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4459: return $line;
4460: }
4461:
1.484.2.30 raeburn 4462: sub action_restrictions {
4463: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4464: my %denied = (
4465: cut => 0,
4466: copy => 0,
4467: remove => 0,
4468: );
4469: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4470: # no copy for published maps
4471: $denied{'copy'} = 1;
1.484.2.82 raeburn 4472: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4473: unless ($1 eq 'simpleproblem') {
4474: $denied{'copy'} = 1;
4475: }
4476: $denied{'cut'} = 1;
1.484.2.30 raeburn 4477: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4478: if ($folderpath =~ /^default&[^\&]+$/) {
4479: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4480: $denied{'remove'} = 1;
4481: }
4482: $denied{'cut'} = 1;
4483: $denied{'copy'} = 1;
4484: }
4485: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4486: my $group = $1;
4487: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4488: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4489: $denied{'remove'} = 1;
4490: }
4491: }
4492: $denied{'cut'} = 1;
4493: $denied{'copy'} = 1;
4494: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4495: my $group = $1;
4496: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4497: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4498: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4499: if (keys(%groupsettings) > 0) {
4500: $denied{'remove'} = 1;
4501: }
4502: $denied{'cut'} = 1;
4503: $denied{'copy'} = 1;
4504: }
4505: }
4506: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4507: my $group = $1;
4508: if ($url =~ /group_boards_\Q$group\E/) {
4509: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4510: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4511: if (keys(%groupsettings) > 0) {
4512: if (ref($groupsettings{'functions'}) eq 'HASH') {
4513: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4514: $denied{'remove'} = 1;
4515: }
4516: }
4517: }
4518: $denied{'cut'} = 1;
4519: $denied{'copy'} = 1;
4520: }
4521: }
4522: }
4523: return %denied;
4524: }
4525:
1.484.2.26 raeburn 4526: sub new_timebased_suffix {
1.484.2.30 raeburn 4527: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4528: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4529: if ($type eq 'paste') {
4530: $prefix = $type;
4531: $namespace = 'courseeditor';
1.484.2.56 raeburn 4532: $idtype = 'addcode';
1.484.2.30 raeburn 4533: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4534: $prefix = 'docs';
4535: if ($area eq 'supplemental') {
4536: $prefix = 'supp';
4537: }
4538: $prefix .= $container;
4539: $namespace = 'uploadedmaps';
4540: } else {
4541: $prefix = $type;
4542: $namespace = 'templated';
1.484.2.15 raeburn 4543: }
4544: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4545: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4546: if (!$suffix) {
1.484.2.30 raeburn 4547: if ($type eq 'paste') {
4548: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4549: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4550: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4551: } elsif ($type eq 'smppg') {
4552: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.484.2.93.2. (raeburn 4553:): } elsif ($type eq 'exttool') {
4554:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.484.2.26 raeburn 4555: } else {
1.484.2.42 raeburn 4556: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4557: }
1.484.2.15 raeburn 4558: if ($error) {
4559: $errtext .= '<br />'.$error;
4560: }
4561: }
4562: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4563: $locknotfreed =
4564: '<div class="LC_error">'.
4565: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4566: if ($type eq 'paste') {
1.484.2.57 raeburn 4567: if ($freedlock eq 'nolock') {
4568: $locknotfreed =
4569: '<div class="LC_error">'.
4570: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4571:
1.484.2.60 raeburn 4572: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4573: } else {
4574: $locknotfreed .=
4575: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4576: }
1.484.2.30 raeburn 4577: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4578: $locknotfreed .=
4579: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4580: } elsif ($type eq 'smppg') {
4581: $locknotfreed .=
4582: &mt('This will prevent creation of additional simple pages in this course.');
1.484.2.93.2. (raeburn 4583:): } elsif ($type eq 'exttool') {
4584:): $locknotfreed .=
4585:): &mt('This will prevent creation of additional external tools in this course.');
1.484.2.26 raeburn 4586: } else {
4587: $locknotfreed .=
1.484.2.42 raeburn 4588: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4589: }
1.484.2.30 raeburn 4590: unless ($type eq 'paste') {
4591: $locknotfreed .=
1.484.2.38 raeburn 4592: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4593: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4594: }
4595: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4596: }
4597: return ($suffix,$errtext,$locknotfreed);
4598: }
4599:
1.329 droeschl 4600: =pod
4601:
4602: =item tiehash()
4603:
4604: tie the hash
4605:
4606: =cut
4607:
4608: sub tiehash {
4609: my ($mode)=@_;
4610: $hashtied=0;
4611: if ($env{'request.course.fn'}) {
4612: if ($mode eq 'write') {
4613: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4614: &GDBM_WRCREAT(),0640)) {
4615: $hashtied=2;
4616: }
4617: } else {
4618: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4619: &GDBM_READER(),0640)) {
4620: $hashtied=1;
4621: }
4622: }
1.364 bisitz 4623: }
1.329 droeschl 4624: }
4625:
4626: sub untiehash {
4627: if ($hashtied) { untie %hash; }
4628: $hashtied=0;
4629: return OK;
4630: }
4631:
4632:
4633:
4634:
4635: sub checkonthis {
1.484.2.78 raeburn 4636: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4637: $url=&unescape($url);
4638: $alreadyseen{$url}=1;
4639: $r->rflush();
4640: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4641: $r->print("\n<br />");
4642: if ($level==0) {
4643: $r->print("<br />");
4644: }
4645: for (my $i=0;$i<=$level*5;$i++) {
4646: $r->print(' ');
4647: }
4648: $r->print('<a href="'.$url.'" target="cat">'.
4649: ($title?$title:$url).'</a> ');
4650: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4651: my $updated;
4652: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4653: ($url !~ /\.\d+\.\w+$/)) {
4654: $updated = &Apache::lonnet::remove_stale_resfile($url);
4655: }
1.329 droeschl 4656: my $result=&Apache::lonnet::repcopy(
4657: &Apache::lonnet::filelocation('',$url));
4658: if ($result eq 'ok') {
4659: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4660: if ($updated) {
4661: $r->print('<br />');
4662: for (my $i=0;$i<=$level*5;$i++) {
4663: $r->print(' ');
4664: }
4665: $r->print('- '.&mt('Outdated copy removed'));
4666: }
1.329 droeschl 4667: $r->rflush();
4668: &Apache::lonnet::countacc($url);
4669: $url=~/\.(\w+)$/;
4670: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4671: $r->print('<br />');
4672: $r->rflush();
4673: for (my $i=0;$i<=$level*5;$i++) {
4674: $r->print(' ');
4675: }
4676: $r->print('- '.&mt('Rendering:').' ');
4677: my ($errorcount,$warningcount)=split(/:/,
4678: &Apache::lonnet::ssi_body($url,
4679: ('grade_target'=>'web',
4680: 'return_only_error_and_warning_counts' => 1)));
4681: if (($errorcount) ||
4682: ($warningcount)) {
4683: if ($errorcount) {
1.369 bisitz 4684: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4685: &mt('[quant,_1,error]',$errorcount).'</span>');
4686: }
4687: if ($warningcount) {
4688: $r->print('<span class="LC_warning">'.
4689: &mt('[quant,_1,warning]',$warningcount).'</span>');
4690: }
4691: } else {
4692: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4693: }
4694: $r->rflush();
4695: }
4696: my $dependencies=
4697: &Apache::lonnet::metadata($url,'dependencies');
4698: foreach my $dep (split(/\,/,$dependencies)) {
4699: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4700: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4701: }
4702: }
4703: } elsif ($result eq 'unavailable') {
4704: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4705: } elsif ($result eq 'not_found') {
4706: unless ($url=~/\$/) {
1.484.2.19 raeburn 4707: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4708: } else {
1.366 bisitz 4709: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4710: }
4711: } else {
4712: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4713: }
1.484.2.78 raeburn 4714: if (($updated) && ($result ne 'ok')) {
4715: $r->print('<br />'.&mt('Outdated copy removed'));
4716: }
1.329 droeschl 4717: }
4718: }
4719: }
4720:
4721:
4722:
4723: =pod
4724:
4725: =item list_symbs()
4726:
1.484.2.3 raeburn 4727: List Content Identifiers
1.329 droeschl 4728:
4729: =cut
4730:
4731: sub list_symbs {
4732: my ($r) = @_;
4733:
1.408 raeburn 4734: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4735: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4736: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4737: $r->print(&startContentScreen('tools'));
1.329 droeschl 4738: my $navmap = Apache::lonnavmaps::navmap->new();
4739: if (!defined($navmap)) {
4740: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4741: '<div class="LC_error">'.
4742: &mt('Unable to retrieve information about course contents').
4743: '</div>');
1.408 raeburn 4744: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4745: } else {
1.484 raeburn 4746: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4747: &Apache::loncommon::start_data_table().
4748: &Apache::loncommon::start_data_table_header_row().
4749: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4750: &Apache::loncommon::end_data_table_header_row()."\n");
4751: my $count;
1.329 droeschl 4752: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4753: $r->print(&Apache::loncommon::start_data_table_row().
4754: '<td>'.$res->compTitle().'</td>'.
4755: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4756: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4757: $count ++;
4758: }
4759: if (!$count) {
4760: $r->print(&Apache::loncommon::start_data_table_row().
4761: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4762: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4763: }
1.484 raeburn 4764: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4765: }
1.484.2.19 raeburn 4766: $r->print(&endContentScreen());
1.329 droeschl 4767: }
4768:
1.484.2.93.2. (raeburn 4769:): sub short_urls {
4770:): my ($r,$canedit) = @_;
4771:): my $crstype = &Apache::loncommon::course_type();
4772:): my $formname = 'shortenurl';
4773:): $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4774:): $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4775:): $r->print(&startContentScreen('tools'));
4776:): my ($navmap,$errormsg) =
4777:): &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4778:): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4779:): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4780:): my (%maps,%resources,%titles);
4781:): if (!ref($navmap)) {
4782:): $r->print($errormsg.
4783:): &endContentScreen());
4784:): return '';
4785:): } else {
4786:): $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
4787:): $r->rflush();
4788:): my $readonly;
4789:): if ($canedit) {
4790:): my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
4791:): if ($numnew) {
4792:): $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4793:): }
4794:): if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4795:): $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4796:): foreach my $error (@{$errors}) {
4797:): $r->print('<li>'.$error.'</li>');
4798:): }
4799:): $r->print('</ul><br />');
4800:): }
4801:): } else {
4802:): $readonly = 1;
4803:): }
4804:): my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4805:): $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4806:): undef,undef,undef,undef,undef,\%currtiny,$readonly));
4807:): }
4808:): $r->print(&endContentScreen());
4809:): }
4810:):
1.484.2.78 raeburn 4811: sub contentverifyform {
4812: my ($r) = @_;
4813: my $crstype = &Apache::loncommon::course_type();
4814: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4815: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4816: $r->print(&startContentScreen('tools'));
4817: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4818: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4819: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4820: ' <span class="LC_nobreak">'.
4821: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4822: &mt('No').'</label>'.(' 'x2).
4823: '<label><input type="radio" name="checkstale" value="1" />'.
4824: &mt('Yes').'</label></span></p><p>'.
1.484.2.90 raeburn 4825: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.484.2.78 raeburn 4826: '<input type="hidden" value="1" name="tools" />'.
4827: '<input type="hidden" value="1" name="verify" /></p></form>');
4828: $r->print(&endContentScreen());
4829: return;
4830: }
1.329 droeschl 4831:
4832: sub verifycontent {
1.484.2.78 raeburn 4833: my ($r,$checkstale) = @_;
1.408 raeburn 4834: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4835: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4836: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4837: $r->print(&startContentScreen('tools'));
4838: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4839: $hashtied=0;
4840: undef %alreadyseen;
4841: %alreadyseen=();
4842: &tiehash();
1.484 raeburn 4843:
1.329 droeschl 4844: foreach my $key (keys(%hash)) {
4845: if ($hash{$key}=~/\.(page|sequence)$/) {
4846: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4847: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4848: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4849: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4850: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4851: }
4852: }
4853: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4854: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4855: }
4856: }
4857: &untiehash();
1.442 www 4858: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4859: $r->print(&endContentScreen());
1.329 droeschl 4860: }
4861:
4862:
4863: sub devalidateversioncache {
4864: my $src=shift;
4865: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4866: &Apache::lonnet::clutter($src));
4867: }
4868:
4869: sub checkversions {
1.484.2.67 raeburn 4870: my ($r,$canedit) = @_;
1.408 raeburn 4871: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4872: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4873: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4874: $r->print(&startContentScreen('tools'));
1.442 www 4875:
1.329 droeschl 4876: my $header='';
4877: my $startsel='';
4878: my $monthsel='';
4879: my $weeksel='';
4880: my $daysel='';
4881: my $allsel='';
4882: my %changes=();
4883: my $starttime=0;
4884: my $haschanged=0;
4885: my %setversions=&Apache::lonnet::dump('resourceversions',
4886: $env{'course.'.$env{'request.course.id'}.'.domain'},
4887: $env{'course.'.$env{'request.course.id'}.'.num'});
4888:
4889: $hashtied=0;
4890: &tiehash();
1.484.2.67 raeburn 4891: if ($canedit) {
4892: my %newsetversions=();
4893: if ($env{'form.setmostrecent'}) {
4894: $haschanged=1;
4895: foreach my $key (keys(%hash)) {
4896: if ($key=~/^ids\_(\/res\/.+)$/) {
4897: $newsetversions{$1}='mostrecent';
4898: &devalidateversioncache($1);
4899: }
1.329 droeschl 4900: }
1.484.2.67 raeburn 4901: } elsif ($env{'form.setcurrent'}) {
4902: $haschanged=1;
4903: foreach my $key (keys(%hash)) {
4904: if ($key=~/^ids\_(\/res\/.+)$/) {
4905: my $getvers=&Apache::lonnet::getversion($1);
4906: if ($getvers>0) {
4907: $newsetversions{$1}=$getvers;
4908: &devalidateversioncache($1);
4909: }
4910: }
1.329 droeschl 4911: }
1.484.2.67 raeburn 4912: } elsif ($env{'form.setversions'}) {
4913: $haschanged=1;
4914: foreach my $key (keys(%env)) {
4915: if ($key=~/^form\.set_version_(.+)$/) {
4916: my $src=$1;
4917: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4918: $newsetversions{$src}=$env{$key};
4919: &devalidateversioncache($src);
4920: }
4921: }
1.329 droeschl 4922: }
1.484.2.67 raeburn 4923: }
4924: if ($haschanged) {
4925: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4926: $env{'course.'.$env{'request.course.id'}.'.domain'},
4927: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4928: $r->print(&Apache::loncommon::confirmwrapper(
4929: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4930: } else {
4931: $r->print(&Apache::loncommon::confirmwrapper(
4932: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4933: }
4934: &mark_hash_old();
4935: }
4936: &changewarning($r,'');
1.329 droeschl 4937: }
4938: if ($env{'form.timerange'} eq 'all') {
4939: # show all documents
1.484.2.34 raeburn 4940: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4941: $allsel=' selected="selected"';
1.329 droeschl 4942: foreach my $key (keys(%hash)) {
4943: if ($key=~/^ids\_(\/res\/.+)$/) {
4944: my $src=$1;
4945: $changes{$src}=1;
4946: }
4947: }
4948: } else {
4949: # show documents which changed
4950: %changes=&Apache::lonnet::dump
4951: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4952: $env{'course.'.$env{'request.course.id'}.'.num'});
4953: my $firstkey=(keys(%changes))[0];
4954: unless ($firstkey=~/^error\:/) {
4955: unless ($env{'form.timerange'}) {
4956: $env{'form.timerange'}=604800;
4957: }
4958: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4959: .&mt('seconds');
4960: if ($env{'form.timerange'}==-1) {
4961: $seltext='since start of course';
1.484.2.19 raeburn 4962: $startsel=' selected="selected"';
1.329 droeschl 4963: $env{'form.timerange'}=time;
4964: }
4965: $starttime=time-$env{'form.timerange'};
4966: if ($env{'form.timerange'}==2592000) {
4967: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4968: $monthsel=' selected="selected"';
1.329 droeschl 4969: } elsif ($env{'form.timerange'}==604800) {
4970: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4971: $weeksel=' selected="selected"';
1.329 droeschl 4972: } elsif ($env{'form.timerange'}==86400) {
4973: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4974: $daysel=' selected="selected"';
1.329 droeschl 4975: }
4976: $header=&mt('Content changed').' '.$seltext;
4977: } else {
4978: $header=&mt('No content modifications yet.');
4979: }
4980: }
4981: %setversions=&Apache::lonnet::dump('resourceversions',
4982: $env{'course.'.$env{'request.course.id'}.'.domain'},
4983: $env{'course.'.$env{'request.course.id'}.'.num'});
4984: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4985: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4986: 'lm' => 'Version changes since last Month',
4987: 'lw' => 'Version changes since last Week',
4988: 'sy' => 'Version changes since Yesterday',
4989: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4990: 'cd' => 'Change display',
1.329 droeschl 4991: 'sd' => 'Display',
4992: 'fi' => 'File',
4993: 'md' => 'Modification Date',
4994: 'mr' => 'Most recently published Version',
1.408 raeburn 4995: 've' => 'Version used in '.$crstype,
4996: 'vu' => 'Set Version to be used in '.$crstype,
4997: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4998: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4999: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5000: 'di' => 'Differences',
1.484 raeburn 5001: 'save' => 'Save changes',
5002: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5003: 'act' => 'Actions');
1.484.2.67 raeburn 5004: my ($disabled,$readonly);
5005: unless ($canedit) {
5006: $disabled = 'disabled="disabled"';
5007: $readonly = 1;
5008: }
1.329 droeschl 5009: $r->print(<<ENDHEADERS);
1.484 raeburn 5010: <h4 class="LC_info">$header</h4>
1.329 droeschl 5011: <form action="/adm/coursedocs" method="post">
5012: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5013: <div class="LC_left_float">
1.479 golterma 5014: <fieldset>
1.484 raeburn 5015: <legend>$lt{'cd'}</legend>
1.329 droeschl 5016: <select name="timerange">
1.484.2.19 raeburn 5017: <option value='all'$allsel>$lt{'al'}</option>
5018: <option value="-1"$startsel>$lt{'st'}</option>
5019: <option value="2592000"$monthsel>$lt{'lm'}</option>
5020: <option value="604800"$weeksel>$lt{'lw'}</option>
5021: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5022: </select>
5023: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5024: </fieldset>
5025: </div>
5026: <div class="LC_left_float">
5027: <fieldset>
5028: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 5029: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5030: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5031: </fieldset>
5032: </div>
5033: <br clear="all" />
5034: <hr />
5035: <h4>$lt{'vers'}</h4>
1.329 droeschl 5036: ENDHEADERS
1.479 golterma 5037: #number of columns for version history
1.484.2.44 raeburn 5038: my %changedbytime;
5039: foreach my $key (keys(%changes)) {
5040: #excludes not versionable problems from resource version history:
5041: next if ($key =~ /^\/res\/lib\/templates/);
5042: my $chg;
5043: if ($env{'form.timerange'} eq 'all') {
5044: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5045: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5046: } else {
5047: $chg = $changes{$key};
5048: next if ($chg < $starttime);
5049: }
5050: push(@{$changedbytime{$chg}},$key);
5051: }
5052: if (keys(%changedbytime) == 0) {
5053: &untiehash();
5054: $r->print(&mt('No content changes in imported content in specified time frame').
5055: &endContentScreen());
5056: return;
5057: }
1.479 golterma 5058: $r->print(
1.484.2.67 raeburn 5059: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5060: &Apache::loncommon::start_data_table().
5061: &Apache::loncommon::start_data_table_header_row().
5062: '<th>'.&mt('Resources').'</th>'.
5063: "<th>$lt{'mr'}</th>".
5064: "<th>$lt{'ve'}</th>".
5065: "<th>$lt{'vu'}</th>".
5066: '<th>'.&mt('History').'</th>'.
5067: &Apache::loncommon::end_data_table_header_row()
5068: );
1.484.2.44 raeburn 5069: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5070: foreach my $key (sort(@{$changedbytime{$chg}})) {
5071: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5072: my $currentversion=&Apache::lonnet::getversion($key);
5073: if ($currentversion<0) {
5074: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5075: }
5076: my $linkurl=&Apache::lonnet::clutter($key);
5077: $r->print(
5078: &Apache::loncommon::start_data_table_row().
5079: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5080: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5081: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5082: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5083: '<td align="right">'
5084: );
5085: # Used in course
5086: my $usedversion=$hash{'version_'.$linkurl};
5087: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 5088: if ($usedversion != $currentversion) {
1.479 golterma 5089: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 5090: } else {
1.479 golterma 5091: $r->print($usedversion);
5092: }
1.329 droeschl 5093: } else {
1.484.2.19 raeburn 5094: $r->print($currentversion);
1.329 droeschl 5095: }
1.484.2.44 raeburn 5096: $r->print('</td><td title="'.$lt{'vu'}.'">');
5097: # Set version
5098: $r->print(&Apache::loncommon::select_form(
5099: $setversions{$linkurl},
5100: 'set_version_'.$linkurl,
5101: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5102: '' => '',
5103: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 5104: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 5105: my $lastold=1;
5106: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5107: my $url=$root.'.'.$prevvers.'.'.$extension;
5108: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5109: $lastold=$prevvers;
5110: }
5111: }
5112: $r->print('</td>');
5113: # List all available versions
5114: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5115: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5116: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 5117: $r->print(
1.484.2.44 raeburn 5118: '<span class="LC_nobreak">'
5119: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5120: .&mt('Version [_1]',$prevvers).'</a>'
5121: .' ('.&Apache::lonlocal::locallocaltime(
5122: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5123: .')');
5124: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5125: $r->print(
5126: ' <a href="/adm/diff?filename='.
5127: &Apache::lonnet::clutter($root.'.'.$extension).
5128: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5129: '" target="diffs">'.&mt('Diffs').'</a>');
5130: }
5131: $r->print('</span><br />');
1.329 droeschl 5132: }
1.484.2.44 raeburn 5133: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 5134: }
1.329 droeschl 5135: }
1.484.2.19 raeburn 5136: $r->print(
5137: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 5138: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5139: '</form>'
5140: );
1.329 droeschl 5141:
5142: &untiehash();
1.484.2.19 raeburn 5143: $r->print(&endContentScreen());
1.484.2.44 raeburn 5144: return;
1.329 droeschl 5145: }
5146:
5147: sub mark_hash_old {
5148: my $retie_hash=0;
5149: if ($hashtied) {
5150: $retie_hash=1;
5151: &untiehash();
5152: }
5153: &tiehash('write');
5154: $hash{'old'}=1;
5155: &untiehash();
5156: if ($retie_hash) { &tiehash(); }
5157: }
5158:
5159: sub is_hash_old {
5160: my $untie_hash=0;
5161: if (!$hashtied) {
5162: $untie_hash=1;
5163: &tiehash();
5164: }
5165: my $return=$hash{'old'};
5166: if ($untie_hash) { &untiehash(); }
5167: return $return;
5168: }
5169:
5170: sub changewarning {
5171: my ($r,$postexec,$message,$url)=@_;
5172: if (!&is_hash_old()) { return; }
5173: my $pathvar='folderpath';
5174: my $path=&escape($env{'form.folderpath'});
5175: if (!defined($url)) {
5176: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5177: }
5178: my $course_type = &Apache::loncommon::course_type();
5179: if (!defined($message)) {
5180: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5181: }
5182: $r->print("\n\n".
1.372 bisitz 5183: '<script type="text/javascript">'."\n".
5184: '// <![CDATA['."\n".
5185: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5186: '// ]]>'."\n".
1.369 bisitz 5187: '</script>'."\n".
1.375 tempelho 5188: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5189: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5190: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5191: &mt($message,' <input type="hidden" name="'.
5192: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5193: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5194: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5195: }
5196:
5197:
5198: sub init_breadcrumbs {
1.484.2.44 raeburn 5199: my ($form,$text,$help)=@_;
1.329 droeschl 5200: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5201: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5202: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5203: faq=>273,
5204: bug=>'Instructor Interface',
1.484.2.44 raeburn 5205: help => $help});
1.329 droeschl 5206: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5207: text=>$text,
5208: faq=>273,
5209: bug=>'Instructor Interface'});
5210: }
5211:
1.441 www 5212: # subroutine to list form elements
5213: sub create_list_elements {
5214: my @formarr = @_;
5215: my $list = '';
1.484.2.12 raeburn 5216: foreach my $button (@formarr){
5217: foreach my $picture (keys(%{$button})) {
5218: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5219: }
5220: }
5221: return $list;
5222: }
1.329 droeschl 5223:
1.441 www 5224: # subroutine to create ul from list elements
5225: sub create_form_ul {
5226: my $list = shift;
5227: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5228: return $ul;
5229: }
1.329 droeschl 5230:
1.442 www 5231: #
5232: # Start tabs
5233: #
5234:
5235: sub startContentScreen {
1.484 raeburn 5236: my ($mode) = @_;
5237: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5238: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5239: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5240: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5241: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5242: } else {
1.484.2.34 raeburn 5243: $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 5244: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5245: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5246: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5247: }
5248: $output .= "\n".'</ul>'."\n";
5249: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5250: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5251: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5252: return $output;
1.442 www 5253: }
5254:
5255: #
5256: # End tabs
5257: #
5258:
5259: sub endContentScreen {
1.484 raeburn 5260: return '</div></div></div>';
1.442 www 5261: }
1.329 droeschl 5262:
1.446 www 5263: sub supplemental_base {
1.484.2.33 raeburn 5264: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5265: }
5266:
1.329 droeschl 5267: sub handler {
5268: my $r = shift;
5269: &Apache::loncommon::content_type($r,'text/html');
5270: $r->send_http_header;
5271: return OK if $r->header_only;
1.484 raeburn 5272:
5273: # get course data
1.408 raeburn 5274: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5275: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5276: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5277:
5278: # graphics settings
5279: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5280:
1.443 www 5281: #
1.329 droeschl 5282: # --------------------------------------------- Initialize help topics for this
5283: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.484.2.93.2. (raeburn 5284:): 'Adding_External_Resource','Adding_External_Tool',
5285:): 'Navigate_Content','Adding_Folders','Docs_Overview',
5286:): 'Load_Map','Supplemental','Score_Upload_Form',
5287:): 'Adding_Pages','Importing_LON-CAPA_Resource',
5288:): 'Importing_IMS_Course','Uploading_From_Harddrive',
5289:): 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5290: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5291: }
5292: # Composite help files
5293: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5294: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5295: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5296: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5297: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5298: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5299: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5300: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5301: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5302: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5303:
1.484.2.67 raeburn 5304: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 5305: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5306: unless ($r->uri eq '/adm/supplemental') {
5307: # does this user have privileges to modify content.
1.484.2.67 raeburn 5308: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5309: $allowed = 1;
5310: $canedit = 1;
5311: $canview = 1;
5312: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5313: $allowed = 1;
5314: $canview = 1;
5315: }
5316: }
5317: unless ($canedit) {
5318: $disabled = ' disabled="disabled"';
1.472 raeburn 5319: }
1.484.2.53 raeburn 5320: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5321: if ($env{'form.inhibitmenu'}) {
5322: unless ($env{'form.inhibitmenu'} eq 'yes') {
5323: delete($env{'form.inhibitmenu'});
5324: }
5325: }
5326:
1.484.2.53 raeburn 5327: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5328: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5329: if (!$canedit) {
5330: &verifycontent($r);
5331: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5332: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5333: text=>'Results',
5334: faq=>273,
5335: bug=>'Instructor Interface'});
5336: &verifycontent($r,$env{'form.checkstale'});
5337: } else {
5338: &contentverifyform($r);
5339: }
1.329 droeschl 5340: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5341: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5342: &list_symbs($r);
1.484.2.93.2. (raeburn 5343:): } elsif ($allowed && $env{'form.shorturls'}) {
5344:): &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5345:): &short_urls($r,$canedit);
1.329 droeschl 5346: } elsif ($allowed && $env{'form.docslog'}) {
5347: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5348: my $folder = $env{'form.folder'};
5349: if ($folder eq '') {
5350: $folder='default';
5351: }
1.484.2.67 raeburn 5352: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5353: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5354: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5355: &checkversions($r,$canedit);
5356: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5357: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5358: &dumpcourse($r);
5359: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5360: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5361: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5362: } else {
1.445 www 5363: #
5364: # Done catching special calls
1.484 raeburn 5365: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5366: # Get the parameters that may be needed
5367: #
5368: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5369: ['folderpath',
5370: 'forcesupplement','forcestandard',
5371: 'tools','symb','command','supppath']);
1.445 www 5372:
1.484.2.78 raeburn 5373: foreach my $item ('forcesupplement','forcestandard','tools') {
5374: next if ($env{'form.'.$item} eq '');
5375: unless ($env{'form.'.$item} eq '1') {
5376: delete($env{'form.'.$item});
5377: }
5378: }
5379:
5380: if ($env{'form.command'}) {
5381: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5382: delete($env{'form.command'});
5383: }
5384: }
5385:
5386: if ($env{'form.symb'}) {
5387: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5388: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5389: delete($env{'form.symb'});
5390: }
5391: }
5392:
1.445 www 5393: # standard=1: this is a "new-style" course with an uploaded map as top level
5394: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5395:
5396: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5397:
1.484 raeburn 5398: # Decide whether this should display supplemental or main content or utilities
1.445 www 5399: # supplementalflag=1: show supplemental documents
5400: # supplementalflag=0: show standard documents
1.484 raeburn 5401: # toolsflag=1: show utilities
1.445 www 5402:
1.484.2.39 raeburn 5403: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5404: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5405: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5406: $supplementalflag=0;
5407: }
5408: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5409: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5410: unless ($allowed) { $supplementalflag=1; }
5411: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5412: my $toolsflag=0;
5413: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5414:
1.484.2.78 raeburn 5415: if ($env{'form.folderpath'} ne '') {
1.484.2.92 raeburn 5416: &validate_folderpath($supplementalflag);
1.484.2.78 raeburn 5417: }
5418:
5419: if ($env{'form.supppath'} ne '') {
1.484.2.92 raeburn 5420: &validate_suppath();
1.484.2.78 raeburn 5421: }
5422:
1.329 droeschl 5423: my $script='';
5424: my $showdoc=0;
1.457 raeburn 5425: my $addentries = {};
1.475 raeburn 5426: my $container;
1.329 droeschl 5427: my $containertag;
1.484.2.17 raeburn 5428: my $pathitem;
1.484.2.93.2. (raeburn 5429:): my %ltitools;
1.484.2.67 raeburn 5430: my $hiddentop;
5431: my $navmap;
5432: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5433:
1.464 www 5434: # Do we directly jump somewhere?
1.484.2.21 raeburn 5435: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5436: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5437: $env{'form.folderpath'}=
1.484.2.67 raeburn 5438: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5439: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5440: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5441: } elsif ($env{'form.supppath'} ne '') {
5442: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5443: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5444: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5445: }
1.472 raeburn 5446: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5447: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5448: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5449: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5450: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5451: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5452: } elsif ($env{'form.command'} eq 'contents') {
5453: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5454: } elsif ($env{'form.command'} eq 'home') {
5455: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5456: }
5457:
1.484.2.23 raeburn 5458:
1.445 www 5459: # Where do we store these for when we come back?
5460: my $stored_folderpath='docs_folderpath';
5461: if ($supplementalflag) {
5462: $stored_folderpath='docs_sup_folderpath';
5463: }
1.464 www 5464:
1.484.2.19 raeburn 5465: # No folderpath, and in edit mode, see if we have something stored
5466: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5467: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5468: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5469:
5470: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5471: if ($supplementalflag) {
5472: undef($env{'form.folderpath'}) if ($1 eq 'default');
5473: } else {
5474: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5475: }
5476: } else {
1.484.2.19 raeburn 5477: undef($env{'form.folderpath'});
5478: }
1.484.2.92 raeburn 5479: if ($env{'form.folderpath'} ne '') {
5480: &validate_folderpath($supplementalflag);
5481: }
1.329 droeschl 5482: }
1.446 www 5483:
5484: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5485: if (!$allowed) {
1.446 www 5486: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5487: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5488: }
5489: }
1.446 www 5490: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5491: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5492: $env{'form.folderpath'} = &supplemental_base()
5493: .'&'.
1.329 droeschl 5494: $env{'form.folderpath'};
5495: }
1.484.2.67 raeburn 5496: # If allowed and user's role is not advanced check folderpath is not hidden
5497: if (($allowed) && (!$env{'request.role.adv'}) &&
5498: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5499: my $folderurl;
5500: my @pathitems = split(/\&/,$env{'form.folderpath'});
5501: my $folder = $pathitems[-2];
5502: if ($folder eq '') {
5503: undef($env{'form.folderpath'});
5504: } else {
5505: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.87 raeburn 5506: if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 5507: $folderurl .= '.page';
5508: } else {
5509: $folderurl .= '.sequence';
5510: }
5511: unless (ref($navmap)) {
5512: $navmap = Apache::lonnavmaps::navmap->new();
5513: }
5514: if (ref($navmap)) {
5515: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5516: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5517: unless (@resources) {
5518: undef($env{'form.folderpath'});
5519: }
5520: }
5521: }
5522: }
5523: }
5524:
5525:
1.446 www 5526: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5527: unless ($env{'form.folderpath'}) {
1.446 www 5528: if ($supplementalflag) {
5529: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5530: } elsif ($allowed) {
5531: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5532: }
1.472 raeburn 5533: }
1.446 www 5534:
1.445 www 5535: # Store this
1.484 raeburn 5536: unless ($toolsflag) {
1.484.2.67 raeburn 5537: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5538: &Apache::loncommon::store_course_settings($stored_folderpath,
5539: {'folderpath' => 'scalar'});
5540: }
5541: my $folderpath;
1.484 raeburn 5542: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5543: $folderpath = $env{'form.folderpath'};
5544: my (@folders)=split('&',$env{'form.folderpath'});
5545: $env{'form.foldername'}=&unescape(pop(@folders));
5546: if ($env{'form.foldername'} =~ /\:1$/) {
5547: $container = 'page';
5548: } else {
5549: $container = 'sequence';
5550: }
5551: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5552: } else {
1.484.2.19 raeburn 5553: if ($env{'form.folder'} eq '' ||
5554: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5555: if ($env{'form.folder'} eq 'supplemental') {
5556: $folderpath=&supplemental_base();
5557: } elsif (!$hiddentop) {
5558: $folderpath='default&'.
5559: &escape(&mt('Main Content').':::::');
5560: }
1.484 raeburn 5561: }
5562: }
1.484.2.19 raeburn 5563: $containertag = '<input type="hidden" name="folderpath" value="" />';
5564: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5565: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5566: $showdoc='/'.$1;
5567: }
5568: if ($showdoc) { # got called in sequence from course
5569: $allowed=0;
5570: } else {
1.484.2.67 raeburn 5571: if ($canedit) {
1.484 raeburn 5572: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5573: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5574: }
5575: }
1.329 droeschl 5576: }
5577:
1.344 bisitz 5578: # get personal data
1.329 droeschl 5579: my $uname=$env{'user.name'};
5580: my $udom=$env{'user.domain'};
5581: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5582:
5583: if ($allowed) {
1.484 raeburn 5584: if ($toolsflag) {
5585: $script .= &inject_data_js();
5586: my ($home,$other,%outhash)=&authorhosts();
5587: if (!$home && $other) {
5588: my @hosts;
5589: foreach my $aurole (keys(%outhash)) {
5590: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5591: push(@hosts,$outhash{$aurole});
5592: }
5593: }
5594: $script .= &dump_switchserver_js(@hosts);
5595: }
1.458 raeburn 5596: } else {
1.484.2.43 raeburn 5597: my $tid = 1;
1.484 raeburn 5598: my @tabids;
5599: if ($supplementalflag) {
5600: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5601: $tid = 2;
1.484 raeburn 5602: } else {
5603: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5604: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5605: unshift(@tabids,'001');
5606: push(@tabids,('dd1','ee1'));
5607: }
1.458 raeburn 5608: }
1.484 raeburn 5609: my $tabidstr = join("','",@tabids);
1.484.2.93.2. (raeburn 5610:): %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
5611:): my $posslti = keys(%ltitools);
1.484.2.80 raeburn 5612: my $hostname = $r->hostname();
1.484.2.93.2. (raeburn 5613:): $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 5614: $canedit,$hostname,\$navmap).
1.484 raeburn 5615: &history_tab_js().
5616: &inject_data_js().
1.484.2.43 raeburn 5617: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.93.2. (raeburn 5618:): &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5619: $addentries = {
1.484.2.3 raeburn 5620: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5621: };
1.458 raeburn 5622: }
1.484.2.30 raeburn 5623: $script .= &paste_popup_js();
1.484.2.12 raeburn 5624: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5625: &mt('Switch server?');
1.484.2.19 raeburn 5626:
5627:
1.329 droeschl 5628: }
5629: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5630: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5631: .'// <![CDATA['."\n"
5632: .$script."\n"
5633: .'// ]]>'."\n"
1.484.2.81 raeburn 5634: .'</script>'."\n"
5635: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5636:
5637: # Breadcrumbs
5638: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5639:
5640: if ($showdoc) {
5641: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5642: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5643: } elsif ($toolsflag) {
1.484.2.67 raeburn 5644: my ($breadtext,$breadtitle);
5645: $breadtext = "$crstype Editor";
5646: if ($canedit) {
5647: $breadtitle = 'Editing '.$crstype.' Contents';
5648: } else {
5649: $breadtext .= ' (View-only mode)';
5650: $breadtitle = 'Viewing '.$crstype.' Contents';
5651: }
1.484.2.44 raeburn 5652: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5653: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5654: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5655: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5656: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5657: $breadtitle)
1.484.2.44 raeburn 5658: );
1.484.2.19 raeburn 5659: } elsif ($r->uri eq '/adm/supplemental') {
5660: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5661: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5662: {'bread_crumbs' => $brcrum,}));
5663: } else {
1.484.2.67 raeburn 5664: my ($breadtext,$breadtitle,$helpitem);
5665: $breadtext = "$crstype Editor";
5666: if ($canedit) {
5667: $breadtitle = 'Editing '.$crstype.' Contents';
5668: $helpitem = 'Docs_Adding_Course_Doc';
5669: } else {
5670: $breadtext .= ' (View-only mode)';
5671: $breadtitle = 'Viewing '.$crstype.' Contents';
5672: $helpitem = 'Docs_Viewing_Course_Doc';
5673: }
1.392 raeburn 5674: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5675: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5676: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5677: {'add_entries' => $addentries}
5678: )
1.392 raeburn 5679: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5680: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5681: $breadtitle,
5682: $helpitem)
1.392 raeburn 5683: );
5684: }
1.364 bisitz 5685:
1.329 droeschl 5686: my %allfiles = ();
5687: my %codebase = ();
1.440 raeburn 5688: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5689: if ($canedit) {
1.329 droeschl 5690: if (($env{'form.uploaddoc.filename'}) &&
5691: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5692: my $context = $1;
5693: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5694: undef($hadchanges);
1.440 raeburn 5695: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5696: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5697: undef($navmap);
1.329 droeschl 5698: if ($hadchanges) {
5699: &mark_hash_old();
5700: }
1.440 raeburn 5701: $r->print($upload_output);
5702: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5703: # Process file upload - phase two - upload embedded objects
5704: $uploadphase = 'check_embedded';
5705: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5706: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5707: $env{'form.newidx'});
5708: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5709: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5710: my ($destination,$dir_root) = &embedded_destination();
5711: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5712: my $actionurl = '/adm/coursedocs';
5713: my ($result,$flag) =
5714: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5715: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5716: $actionurl);
5717: $r->print($result.&return_to_editor());
5718: } elsif ($env{'form.phase'} eq 'check_embedded') {
5719: # Process file upload - phase three - modify references in HTML file
5720: $uploadphase = 'modified_orightml';
5721: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5722: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5723: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5724: my $result =
5725: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5726: $docuname,$docudom,undef,
5727: $dir_root);
5728: $r->print($result.&return_to_editor());
1.476 raeburn 5729: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5730: $uploadphase = 'decompress_phase_one';
5731: $r->print(&decompression_phase_one().
5732: &return_to_editor());
5733: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5734: $uploadphase = 'decompress_phase_two';
5735: $r->print(&decompression_phase_two().
5736: &return_to_editor());
1.329 droeschl 5737: }
5738: }
5739:
1.484 raeburn 5740: if ($allowed && $toolsflag) {
5741: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5742: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5743: $r->print(&endContentScreen());
5744: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5745: # -----------------------------------------------------------------------------
5746: my %lt=&Apache::lonlocal::texthash(
5747: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5748: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5749: 'upld' => 'Upload Content',
1.329 droeschl 5750: 'srch' => 'Search',
5751: 'impo' => 'Import',
1.484.2.19 raeburn 5752: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5753: 'impm' => 'Import from Assembled Map',
1.484.2.93.2. (raeburn 5754:): 'extr' => 'External Resource',
5755:): 'extt' => 'External Tool',
1.329 droeschl 5756: 'selm' => 'Select Map',
5757: 'load' => 'Load Map',
5758: 'newf' => 'New Folder',
5759: 'newp' => 'New Composite Page',
5760: 'syll' => 'Syllabus',
1.425 raeburn 5761: 'navc' => 'Table of Contents',
1.343 biermanm 5762: 'sipa' => 'Simple Course Page',
1.329 droeschl 5763: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5764: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5765: 'drbx' => 'Drop Box',
1.451 www 5766: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5767: 'bull' => 'Discussion Board',
1.347 weissno 5768: 'mypi' => 'My Personal Information Page',
1.353 weissno 5769: 'grpo' => 'Group Portfolio',
1.329 droeschl 5770: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5771: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5772: 'imsf' => 'IMS Upload',
5773: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5774: 'cms' => 'Origin of IMS package',
5775: 'se' => 'Select',
1.484.2.19 raeburn 5776: 'file' => 'File',
1.329 droeschl 5777: 'title' => 'Title',
5778: 'comment' => 'Comment',
1.403 raeburn 5779: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5780: 'bb5' => 'Blackboard 5',
5781: 'bb6' => 'Blackboard 6',
5782: 'angel5' => 'ANGEL 5.5',
5783: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5784: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5785: );
1.329 droeschl 5786: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5787: # Calculate free quota space for a user or course. A javascript function checks
5788: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5789: my $quotatype = 'unofficial';
5790: if ($crstype eq 'Community') {
5791: $quotatype = 'community';
5792: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5793: $quotatype = 'official';
5794: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5795: $quotatype = 'textbook';
5796: }
5797: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5798: 'course',$quotatype); # expressed in MB
5799: my $current_disk_usage = 0;
5800: foreach my $subdir ('docs','supplemental') {
5801: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5802: "userfiles/$subdir",1); # expressed in kB
5803: }
5804: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5805: my $usage = $current_disk_usage/1024; # in MB
5806: my $quota = $disk_quota;
5807: my $percent;
5808: if ($disk_quota == 0) {
5809: $percent = 100.0;
5810: } else {
1.484.2.69 raeburn 5811: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5812: }
5813: $usage = sprintf("%.2f",$usage);
5814: $quota = sprintf("%.2f",$quota);
5815: $percent = sprintf("%.0f",$percent);
5816: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5817: $percent.'%',$quota.' MB').'</p>';
5818:
1.329 droeschl 5819: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5820: $quotainfo
1.329 droeschl 5821: $lt{'file'}:<br />
1.484.2.81 raeburn 5822: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
5823: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5824: FIUP
5825:
5826: my $checkbox=(<<CHBO);
5827: <!-- <label>$lt{'parse'}?
5828: <input type="checkbox" name="parserflag" />
5829: </label> -->
5830: <label>
1.484.2.67 raeburn 5831: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5832: </label>
5833: CHBO
1.484.2.12 raeburn 5834: my $imsfolder = $env{'form.folder'};
5835: if ($imsfolder eq '') {
1.484.2.19 raeburn 5836: $imsfolder = 'default';
1.484.2.12 raeburn 5837: }
5838: my $imspform=(<<IMSFORM);
5839: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5840: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5841: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5842: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5843: <legend>$lt{'imsf'}</legend>
5844: $fileupload
5845: <br />
5846: <p>
1.484.2.19 raeburn 5847: $lt{'cms'}:
1.484.2.67 raeburn 5848: <select name="source" $disabled>
1.484.2.12 raeburn 5849: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5850: <option value="bb5">$lt{'bb5'}</option>
5851: <option value="bb6">$lt{'bb6'}</option>
5852: <option value="angel5">$lt{'angel5'}</option>
5853: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5854: </select>
5855: <input type="hidden" name="folder" value="$imsfolder" />
5856: </p>
5857: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5858: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5859: </fieldset>
5860: </form>
5861: IMSFORM
5862:
1.484.2.19 raeburn 5863: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5864: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5865: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5866: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5867: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5868: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5869: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5870: $fileupload
5871: <br />
5872: $lt{'title'}:<br />
1.484.2.67 raeburn 5873: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5874: $pathitem
1.329 droeschl 5875: <input type="hidden" name="cmd" value="upload_default" />
5876: <br />
1.458 raeburn 5877: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5878: $checkbox
5879: </span>
1.484.2.12 raeburn 5880: <br clear="all" />
1.484.2.67 raeburn 5881: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5882: </fieldset>
5883: </form>
1.383 tempelho 5884: FUFORM
1.329 droeschl 5885:
1.484.2.67 raeburn 5886: my $mapimportjs;
5887: if ($canedit) {
5888: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5889: } else {
5890: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5891: }
1.484.2.19 raeburn 5892: my $importpubform=(<<SEDFFORM);
5893: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5894: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5895: <form action="/adm/coursedocs" method="post" name="mapimportform">
5896: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5897: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5898: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5899: $lt{'copm'}<br />
5900: <span class="LC_nobreak">
1.484.2.19 raeburn 5901: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5902: onfocus="this.blur();$mapimportjs" $disabled />
5903: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5904: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5905: </fieldset>
5906: </form>
5907:
1.383 tempelho 5908: SEDFFORM
1.484.2.67 raeburn 5909:
5910: my $fromstoredjs;
5911: if ($canedit) {
5912: $fromstoredjs = 'open_StoredLinks_Import()';
5913: } else {
5914: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5915: }
5916:
1.484.2.19 raeburn 5917: my @importpubforma = (
5918: { '<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 5919: { '<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 5920: { '<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 5921: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5922: );
5923: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5924: my $extresourcesform =
5925: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5926: $help{'Adding_External_Resource'},
1.484.2.93.2. (raeburn 5927:): undef,undef,undef,undef,undef,undef,$disabled);
5928:): my $exttoolform =
5929:): &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5930:): $help{'Adding_External_Tool'},undef,
5931:): undef,'tool',$coursedom,$coursenum,
5932:): \%ltitools,$disabled);
1.329 droeschl 5933: if ($allowed) {
1.484.2.7 raeburn 5934: my $folder = $env{'form.folder'};
5935: if ($folder eq '') {
5936: $folder='default';
5937: }
1.484.2.67 raeburn 5938: if ($canedit) {
5939: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5940: if ($output) {
5941: $r->print($output);
5942: }
1.484.2.30 raeburn 5943: }
1.337 ehlerst 5944: $r->print(<<HIDDENFORM);
5945: <form name="renameform" method="post" action="/adm/coursedocs">
5946: <input type="hidden" name="title" />
5947: <input type="hidden" name="cmd" />
5948: <input type="hidden" name="markcopy" />
5949: <input type="hidden" name="copyfolder" />
5950: $containertag
5951: </form>
1.484 raeburn 5952:
1.337 ehlerst 5953: HIDDENFORM
1.484.2.17 raeburn 5954: $r->print(&makesimpleeditform($pathitem)."\n".
5955: &makedocslogform($pathitem."\n".
1.484 raeburn 5956: '<input type="hidden" name="folder" value="'.
5957: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5958: }
1.442 www 5959:
5960: # Generate the tabs
1.484.2.19 raeburn 5961: my ($mode,$needs_end);
1.472 raeburn 5962: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5963: my @folders = split('&',$env{'form.folderpath'});
5964: unless (@folders > 2) {
5965: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5966: $needs_end = 1;
5967: }
1.472 raeburn 5968: } else {
1.484 raeburn 5969: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5970: $needs_end = 1;
1.472 raeburn 5971: }
1.443 www 5972:
1.442 www 5973: #
5974:
5975: my $savefolderpath;
1.484.2.86 raeburn 5976: my $hostname = $r->hostname();
1.442 www 5977:
1.395 raeburn 5978: if ($allowed) {
1.329 droeschl 5979: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5980: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5981: $folder='default';
1.356 tempelho 5982: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5983: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5984: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5985: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5986: }
5987: my $postexec='';
5988: if ($folder eq 'default') {
1.372 bisitz 5989: $r->print('<script type="text/javascript">'."\n"
5990: .'// <![CDATA['."\n"
5991: .'this.window.name="loncapaclient";'."\n"
5992: .'// ]]>'."\n"
5993: .'</script>'."\n"
1.369 bisitz 5994: );
1.329 droeschl 5995: } else {
5996: #$postexec='self.close();';
5997: }
1.484.2.15 raeburn 5998: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5999: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6000: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6001:
6002: my $newnavform=(<<NNFORM);
6003: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 6004: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6005: $pathitem
1.329 droeschl 6006: <input type="hidden" name="importdetail"
6007: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 6008: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6009: $help{'Navigate_Content'}
6010: </form>
6011: NNFORM
6012: my $newsmppageform=(<<NSPFORM);
6013: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 6014: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6015: $pathitem
1.329 droeschl 6016: <input type="hidden" name="importdetail" value="" />
1.423 onken 6017: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6018: $help{'Simple Page'}
1.329 droeschl 6019: </form>
6020: NSPFORM
6021:
6022: my $newsmpproblemform=(<<NSPROBFORM);
6023: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 6024: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6025: $pathitem
1.329 droeschl 6026: <input type="hidden" name="importdetail" value="" />
1.423 onken 6027: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 6028: $help{'Simple_Problem'}
1.329 droeschl 6029: </form>
6030:
6031: NSPROBFORM
6032:
6033: my $newdropboxform=(<<NDBFORM);
6034: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 6035: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6036: $pathitem
1.329 droeschl 6037: <input type="hidden" name="importdetail" value="" />
1.423 onken 6038: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 6039: $help{'Dropbox'}
1.344 bisitz 6040: </form>
1.329 droeschl 6041: NDBFORM
6042:
6043: my $newexuploadform=(<<NEXUFORM);
6044: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 6045: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6046: $pathitem
1.329 droeschl 6047: <input type="hidden" name="importdetail" value="" />
1.423 onken 6048: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6049: $help{'Score_Upload_Form'}
6050: </form>
6051: NEXUFORM
6052:
6053: my $newbulform=(<<NBFORM);
6054: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 6055: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6056: $pathitem
1.329 droeschl 6057: <input type="hidden" name="importdetail" value="" />
1.423 onken 6058: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6059: $help{'Bulletin Board'}
6060: </form>
6061: NBFORM
6062:
6063: my $newaboutmeform=(<<NAMFORM);
6064: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 6065: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6066: $pathitem
1.329 droeschl 6067: <input type="hidden" name="importdetail"
6068: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6069: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6070: $help{'My Personal Information Page'}
1.329 droeschl 6071: </form>
6072: NAMFORM
6073:
6074: my $newaboutsomeoneform=(<<NASOFORM);
6075: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 6076: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6077: $pathitem
1.329 droeschl 6078: <input type="hidden" name="importdetail" value="" />
1.423 onken 6079: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6080: </form>
6081: NASOFORM
6082:
6083: my $newrosterform=(<<NROSTFORM);
6084: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 6085: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6086: $pathitem
1.329 droeschl 6087: <input type="hidden" name="importdetail"
6088: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 6089: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 6090: $help{'Course_Roster'}
1.329 droeschl 6091: </form>
6092: NROSTFORM
6093:
1.484.2.27 raeburn 6094: my $newwebpage;
6095: if ($folder =~ /^default_?(\d*)$/) {
6096: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6097: if ($1) {
6098: $newwebpage .= $1;
6099: } else {
6100: $newwebpage .= 'default';
6101: }
6102: $newwebpage .= '/new.html';
6103: }
6104: my $newwebpageform =(<<NWEBFORM);
6105: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 6106: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 6107: $pathitem
6108: <input type="hidden" name="importdetail" value="$newwebpage" />
6109: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 6110: $help{'Web_Page'}
1.484.2.27 raeburn 6111: </form>
6112: NWEBFORM
1.484.2.30 raeburn 6113:
1.484.2.27 raeburn 6114:
1.342 ehlerst 6115: my $specialdocumentsform;
1.383 tempelho 6116: my @specialdocumentsforma;
1.451 www 6117: my $gradingform;
6118: my @gradingforma;
6119: my $communityform;
6120: my @communityforma;
1.351 ehlerst 6121: my $newfolderform;
1.390 tempelho 6122: my $newfolderb;
1.342 ehlerst 6123:
1.451 www 6124: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6125:
1.329 droeschl 6126: my $newpageform=(<<NPFORM);
6127: <form action="/adm/coursedocs" method="post" name="newpage">
6128: <input type="hidden" name="folderpath" value="$path" />
6129: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6130: <input type="hidden" name="active" value="ee" />
1.423 onken 6131: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6132: $help{'Adding_Pages'}
1.329 droeschl 6133: </form>
6134: NPFORM
1.390 tempelho 6135:
6136:
1.351 ehlerst 6137: $newfolderform=(<<NFFORM);
1.329 droeschl 6138: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 6139: $pathitem
1.329 droeschl 6140: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6141: <input type="hidden" name="active" value="" />
1.422 onken 6142: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6143: </form>
6144: NFFORM
6145:
6146: my $newsylform=(<<NSYLFORM);
6147: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 6148: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6149: $pathitem
1.329 droeschl 6150: <input type="hidden" name="importdetail"
6151: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6152: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6153: $help{'Syllabus'}
1.383 tempelho 6154:
1.329 droeschl 6155: </form>
6156: NSYLFORM
1.364 bisitz 6157:
1.329 droeschl 6158: my $newgroupfileform=(<<NGFFORM);
6159: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 6160: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6161: $pathitem
1.329 droeschl 6162: <input type="hidden" name="importdetail"
6163: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 6164: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6165: $help{'Group Portfolio'}
1.329 droeschl 6166: </form>
6167: NGFFORM
1.484.2.89 raeburn 6168: if ($container eq 'page') {
6169: @specialdocumentsforma=(
6170: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6171: );
6172: } else {
6173: @specialdocumentsforma=(
1.421 onken 6174: {'<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 6175: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6176: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6177: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 6178: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.484.2.89 raeburn 6179: );
6180: }
1.451 www 6181: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6182:
1.434 raeburn 6183:
6184: my @importdoc = (
1.484.2.19 raeburn 6185: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6186: );
1.484.2.93.2. (raeburn 6187:): if (keys(%ltitools)) {
6188:): push(@importdoc,
6189:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6190:): );
6191:): }
1.484.2.19 raeburn 6192: unless ($container eq 'page') {
6193: push(@importdoc,
6194: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6195: );
6196: }
6197: push(@importdoc,
1.484.2.38 raeburn 6198: {'<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 6199: );
1.484.2.12 raeburn 6200: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6201:
1.451 www 6202: @gradingforma=(
6203: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6204: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6205: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6206:
6207: );
6208: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6209:
6210: @communityforma=(
6211: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6212: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6213: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 6214: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6215: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6216: );
6217: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6218:
1.330 tempelho 6219: my %orderhash = (
1.484.2.36 raeburn 6220: 'aa' => ['Upload',$fileuploadform],
6221: 'bb' => ['Import',$importpubform],
6222: 'cc' => ['Grading',$gradingform],
1.484.2.89 raeburn 6223: 'ee' => ['Other',$specialdocumentsform],
1.330 tempelho 6224: );
1.484.2.19 raeburn 6225: unless ($container eq 'page') {
1.434 raeburn 6226: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6227: $orderhash{'dd'} = ['Collaboration',$communityform];
1.434 raeburn 6228: }
6229:
1.341 ehlerst 6230: $hadchanges=0;
1.484 raeburn 6231: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6232: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6233: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.93.2. (raeburn 6234:): \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 6235: undef($navmap);
1.443 www 6236: if ($error) {
6237: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6238: }
6239: if ($hadchanges) {
1.484.2.73 raeburn 6240: unless (&is_hash_old()) {
6241: &mark_hash_old();
6242: }
1.443 www 6243: }
1.341 ehlerst 6244:
1.443 www 6245: &changewarning($r,'');
6246: }
1.458 raeburn 6247: }
1.442 www 6248:
1.443 www 6249: # Supplemental documents start here
6250:
1.329 droeschl 6251: my $folder=$env{'form.folder'};
1.443 www 6252: unless ($supplementalflag) {
1.329 droeschl 6253: $folder='supplemental';
6254: }
6255: if ($folder =~ /^supplemental$/ &&
6256: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6257: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6258: } elsif ($allowed) {
1.356 tempelho 6259: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6260: }
1.484.2.17 raeburn 6261: $pathitem = '<input type="hidden" name="folderpath" value="'.
6262: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6263: if ($allowed) {
6264: my $folderseq=
1.484.2.15 raeburn 6265: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6266:
6267: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 6268: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6269: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6270: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6271: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6272: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6273: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6274: $fileupload
6275: <br />
6276: <br />
6277: <span class="LC_nobreak">
6278: $checkbox
6279: </span>
6280: <br /><br />
6281: $lt{'comment'}:<br />
1.383 tempelho 6282: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6283: <br />
1.484.2.19 raeburn 6284: $pathitem
1.329 droeschl 6285: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6286: <input type='submit' value="$lt{'upld'}" />
6287: </form>
1.484.2.19 raeburn 6288: SUPDOCFORM
1.329 droeschl 6289:
6290: my $supnewfolderform=(<<SNFFORM);
6291: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6292: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6293: $pathitem
1.329 droeschl 6294: <input type="hidden" name="importdetail" value="" />
1.423 onken 6295: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6296: $help{'Adding_Folders'}
1.329 droeschl 6297: </form>
6298: SNFFORM
1.383 tempelho 6299:
1.484.2.19 raeburn 6300: my $supextform =
6301: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6302: $help{'Adding_External_Resource'},
6303: undef,undef,$disabled);
1.484.2.93.2. (raeburn 6304:): my $supexttoolform =
6305:): &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6306:): $help{'Adding_External_Tool'},
6307:): undef,undef,'tool',$coursedom,
6308:): $coursenum,\%ltitools,$disabled);
1.329 droeschl 6309:
6310: my $supnewsylform=(<<SNSFORM);
6311: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6312: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6313: $pathitem
1.329 droeschl 6314: <input type="hidden" name="importdetail"
6315: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6316: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6317: $help{'Syllabus'}
6318: </form>
6319: SNSFORM
6320:
6321: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6322: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6323: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6324: $pathitem
1.329 droeschl 6325: <input type="hidden" name="importdetail"
6326: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6327: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6328: $help{'My Personal Information Page'}
1.329 droeschl 6329: </form>
6330: SNAMFORM
6331:
1.484.2.27 raeburn 6332: my $supwebpage;
6333: if ($folder =~ /^supplemental_?(\d*)$/) {
6334: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6335: if ($1) {
6336: $supwebpage .= $1;
6337: } else {
6338: $supwebpage .= 'default';
6339: }
6340: $supwebpage .= '/new.html';
6341: }
6342: my $supwebpageform =(<<SWEBFORM);
6343: <form action="/adm/coursedocs" method="post" name="supwebpage">
6344: <input type="hidden" name="active" value="cc" />
6345: $pathitem
6346: <input type="hidden" name="importdetail" value="$supwebpage" />
6347: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6348: $help{'Web_Page'}
1.484.2.27 raeburn 6349: </form>
6350: SWEBFORM
6351:
1.333 muellerd 6352:
1.383 tempelho 6353: my @specialdocs = (
1.484.2.67 raeburn 6354: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6355: =>$supnewsylform},
1.484.2.67 raeburn 6356: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6357: =>$supnewaboutmeform},
1.484.2.27 raeburn 6358: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6359:
1.383 tempelho 6360: );
1.417 droeschl 6361: my @supimportdoc = (
1.484.2.19 raeburn 6362: {'<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 6363:): =>$supextform});
6364:): if (keys(%ltitools)) {
6365:): push(@supimportdoc,
6366:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6367:): =>$supexttoolform});
6368:): }
6369:): push(@supimportdoc,
1.484.2.12 raeburn 6370: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6371: =>$supupdocform},
1.484.2.93.2. (raeburn 6372:): );
1.484.2.19 raeburn 6373:
1.484.2.12 raeburn 6374: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6375: my %suporderhash = (
1.390 tempelho 6376: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6377: 'ee' => ['Upload',$supupdocform],
6378: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6379: );
1.443 www 6380: if ($supplementalflag) {
1.458 raeburn 6381: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6382: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.484.2.93.2. (raeburn 6383:): \%ltitools,$canedit,$hostname);
1.443 www 6384: if ($error) {
6385: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6386: } else {
6387: if ($suppchanges) {
6388: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6389: my @ids=&Apache::lonnet::current_machine_ids();
6390: foreach my $server (keys(%servers)) {
6391: next if (grep(/^\Q$server\E$/,@ids));
6392: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6393: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6394: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6395: }
6396: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6397: undef($suppchanges);
6398: }
1.443 www 6399: }
1.393 raeburn 6400: }
1.443 www 6401: } elsif ($supplementalflag) {
1.458 raeburn 6402: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.85 raeburn 6403: $supplementalflag,'',$iconpath,$pathitem,'',$hostname);
1.393 raeburn 6404: if ($error) {
6405: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6406: }
1.393 raeburn 6407: }
1.389 tempelho 6408:
1.484.2.19 raeburn 6409: if ($needs_end) {
6410: $r->print(&endContentScreen());
6411: }
1.383 tempelho 6412:
1.329 droeschl 6413: if ($allowed) {
6414: $r->print('
6415: <form method="post" name="extimport" action="/adm/coursedocs">
6416: <input type="hidden" name="title" />
6417: <input type="hidden" name="url" />
6418: <input type="hidden" name="useform" />
6419: <input type="hidden" name="residx" />
6420: </form>');
6421: }
1.484 raeburn 6422: } elsif ($showdoc) {
1.329 droeschl 6423: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6424: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6425: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6426: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6427: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6428: }
6429: }
6430: $r->print(&Apache::loncommon::end_page());
6431: return OK;
1.364 bisitz 6432: }
1.329 droeschl 6433:
1.440 raeburn 6434: sub embedded_form_elems {
6435: my ($phase,$primaryurl,$newidx) = @_;
6436: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6437: $newidx =~s /\D+//g;
1.440 raeburn 6438: return <<STATE;
6439: <input type="hidden" name="folderpath" value="$folderpath" />
6440: <input type="hidden" name="cmd" value="upload_embedded" />
6441: <input type="hidden" name="newidx" value="$newidx" />
6442: <input type="hidden" name="phase" value="$phase" />
6443: <input type="hidden" name="primaryurl" value="$primaryurl" />
6444: STATE
6445: }
6446:
6447: sub embedded_destination {
6448: my $folder=$env{'form.folder'};
6449: my $destination = 'docs/';
6450: if ($folder =~ /^supplemental/) {
6451: $destination = 'supplemental/';
6452: }
6453: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6454: $destination .= 'default/';
6455: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6456: $destination .= $2.'/';
6457: }
1.484.2.78 raeburn 6458: my $newidx = $env{'form.newidx'};
6459: $newidx =~s /\D+//g;
6460: if ($newidx) {
6461: $destination .= $newidx;
6462: }
1.440 raeburn 6463: my $dir_root = '/userfiles';
6464: return ($destination,$dir_root);
6465: }
6466:
6467: sub return_to_editor {
6468: my $actionurl = '/adm/coursedocs';
6469: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6470: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6471: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6472: '</a></p>';
6473: }
6474:
1.476 raeburn 6475: sub decompression_info {
6476: my ($destination,$dir_root) = &embedded_destination();
6477: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6478: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6479: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6480: my $container='sequence';
1.480 raeburn 6481: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6482: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6483: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6484: $container='page';
6485: }
1.480 raeburn 6486: unshift(@hiddens,$pathitem);
6487: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6488: if ($item eq 'newidx') {
6489: next if ($env{'form.'.$item} =~ /\D/);
6490: }
1.480 raeburn 6491: if ($env{'form.'.$item}) {
6492: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6493: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6494: }
1.477 raeburn 6495: }
1.476 raeburn 6496: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6497: $hiddenelem);
6498: }
6499:
6500: sub decompression_phase_one {
6501: my ($dir,$file,$warning,$error,$output);
6502: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6503: &decompression_info();
1.484.2.7 raeburn 6504: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6505: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6506: } else {
6507: my $file = $1;
1.481 raeburn 6508: $output =
6509: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6510: $destination,$dir_root,
6511: $hiddenelem);
6512: if ($env{'form.autoextract_camtasia'}) {
6513: $output .= &remove_archive($docudom,$docuname,$container);
6514: }
1.476 raeburn 6515: }
6516: if ($error) {
6517: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6518: $error.'</p>'."\n";
6519: }
6520: if ($warning) {
6521: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6522: }
6523: return $output;
6524: }
6525:
6526: sub decompression_phase_two {
6527: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6528: &decompression_info();
1.481 raeburn 6529: my $output;
1.480 raeburn 6530: if ($env{'form.archivedelete'}) {
1.481 raeburn 6531: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6532: }
6533: $output .=
1.481 raeburn 6534: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6535: $destination,$dir_root,$hiddenelem);
6536: return $output;
6537: }
6538:
1.480 raeburn 6539: sub remove_archive {
6540: my ($docudom,$docuname,$container) = @_;
6541: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6542: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6543: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6544: if ($fatal) {
6545: if ($container eq 'page') {
6546: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6547: } else {
6548: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6549: }
1.484.2.54 raeburn 6550: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6551: } else {
6552: my $currcmd = $env{'form.cmd'};
6553: my $position = $env{'form.position'};
1.484.2.54 raeburn 6554: my $archiveidx = $position;
6555: if ($position > 0) {
6556: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6557: $archiveidx = $position-1;
6558: }
6559: $env{'form.cmd'} = 'remove_'.$archiveidx;
6560: my ($title,$url,@rrest) =
6561: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6562: if ($url eq $env{'form.archiveurl'}) {
6563: if (&handle_edit_cmd($docuname,$docudom)) {
6564: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6565: if ($fatal) {
6566: if ($container eq 'page') {
6567: $delwarning = &mt('An error occurred updating the contents of the current page.');
6568: } else {
6569: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6570: }
1.480 raeburn 6571: } else {
1.484.2.54 raeburn 6572: $delresult = &mt('Archive file removed.');
1.480 raeburn 6573: }
6574: }
1.484.2.54 raeburn 6575: } else {
6576: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6577: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6578: }
6579: }
6580: $env{'form.cmd'} = $currcmd;
6581: }
6582: if ($delwarning) {
6583: $output = '<p class="LC_warning">'.
6584: $delwarning.
6585: '</p>';
6586: }
6587: if ($delresult) {
6588: $output .= '<p class="LC_info">'.
6589: $delresult.
6590: '</p>';
6591: }
1.481 raeburn 6592: return $output;
1.480 raeburn 6593: }
6594:
1.484 raeburn 6595: sub generate_admin_menu {
1.484.2.67 raeburn 6596: my ($crstype,$canedit) = @_;
1.484 raeburn 6597: my $lc_crstype = lc($crstype);
6598: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6599: my %lt= ( # do not translate here
1.484 raeburn 6600: 'vc' => 'Verify Content',
6601: 'cv' => 'Check/Set Resource Versions',
6602: 'ls' => 'List Resource Identifiers',
1.484.2.93.2. (raeburn 6603:): 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 6604: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6605: 'dcd' => "Copy $crstype Content to Authoring Space",
6606: );
1.484 raeburn 6607: my ($candump,$dumpurl);
6608: if ($home + $other > 0) {
6609: $candump = 'F';
6610: if ($home) {
6611: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6612: } else {
6613: my @hosts;
6614: foreach my $aurole (keys(%outhash)) {
6615: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6616: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6617: }
1.484 raeburn 6618: }
6619: if (@hosts == 1) {
6620: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6621: '&role='.
6622: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6623: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6624: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6625: } else {
6626: $dumpurl = "javascript:choose_switchserver_window()";
6627: }
6628: }
6629: }
6630: my @menu=
6631: ({ categorytitle=>'Administration',
6632: items =>[
6633: { linktext => $lt{'vc'},
6634: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6635: permission => 'F',
1.484.2.44 raeburn 6636: help => 'Docs_Verify_Content',
1.484 raeburn 6637: icon => 'verify.png',
6638: linktitle => 'Verify contents can be retrieved/rendered',
6639: },
6640: { linktext => $lt{'cv'},
6641: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6642: permission => 'F',
1.484.2.44 raeburn 6643: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6644: icon => 'resversion.png',
6645: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6646: },
6647: { linktext => $lt{'ls'},
6648: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6649: permission => 'F',
6650: #help => '',
6651: icon => 'symbs.png',
6652: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6653: },
1.484.2.93.2. (raeburn 6654:): { linktext => $lt{'ct'},
6655:): url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
6656:): permission => 'F',
6657:): help => 'Docs_Short_URLs',
6658:): icon => 'shorturls.png',
6659:): linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
6660:): },
1.484 raeburn 6661: ]
1.484.2.67 raeburn 6662: });
6663: if ($canedit) {
6664: push(@menu,
1.484 raeburn 6665: { categorytitle=>'Export',
6666: items =>[
6667: { linktext => $lt{'imse'},
6668: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6669: permission => 'F',
6670: help => 'Docs_Export_Course_Docs',
6671: icon => 'imsexport.png',
6672: linktitle => $lt{'imse'},
6673: },
6674: { linktext => $lt{'dcd'},
6675: url => $dumpurl,
6676: permission => $candump,
1.484.2.44 raeburn 6677: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6678: icon => 'dump.png',
6679: linktitle => $lt{'dcd'},
6680: },
6681: ]
6682: });
1.484.2.67 raeburn 6683: }
1.484 raeburn 6684: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6685: '<input type="hidden" id="dummy" />'."\n".
6686: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6687: '</form>';
1.329 droeschl 6688: }
6689:
6690: sub generate_edit_table {
1.484.2.30 raeburn 6691: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6692: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6693: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6694: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6695: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6696: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6697: $activetab = $env{'form.active'};
6698: }
1.484.2.67 raeburn 6699: unless ($canedit) {
6700: $disabled = ' disabled="disabled"';
6701: }
1.472 raeburn 6702: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6703: my $backtext = &mt('Exit Editor');
1.458 raeburn 6704: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6705: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6706: '<li class="goback">'.
1.484.2.32 raeburn 6707: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6708: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6709: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6710: '<li>'.
6711: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6712: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6713: if ($env{'form.docslog'}) {
6714: $form .= '<li class="active">';
6715: } else {
6716: $form .= '<li>';
6717: }
6718: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6719: &mt('History').'</a></li>'."\n";
6720: if ($env{'form.docslog'}) {
6721: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6722: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6723: }
1.458 raeburn 6724: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6725: if($name ne '00'){
1.371 tempelho 6726: if($activetab eq '' || $activetab ne $name){
6727: $active = '';
6728: }elsif($activetab eq $name){
6729: $active = 'class="active"';
6730: }
1.458 raeburn 6731: $form .= '<li style="float:right" '.$active
1.484 raeburn 6732: .' 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 6733: } else {
1.484.2.43 raeburn 6734: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6735:
6736: }
1.329 droeschl 6737: }
1.484 raeburn 6738: $form .= '</ul>'."\n";
6739: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6740:
6741: if ($to_show ne '') {
1.484.2.30 raeburn 6742: my $saveform;
6743: if ($need_save) {
6744: my $button = &mt('Make changes');
6745: my $path;
6746: if ($env{'form.folderpath'}) {
6747: $path =
6748: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6749: }
6750: $saveform = <<"END";
6751: <div id="multisave" style="display:none; clear:both;" >
6752: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6753: <input type="hidden" name="folderpath" value="$path" />
6754: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6755: <input type="hidden" name="allhiddenresource" value="" />
6756: <input type="hidden" name="allencrypturl" value="" />
6757: <input type="hidden" name="allrandompick" value="" />
6758: <input type="hidden" name="allrandomorder" value="" />
6759: <input type="hidden" name="changeparms" value="" />
6760: <input type="hidden" name="multiremove" value="" />
6761: <input type="hidden" name="multicut" value="" />
6762: <input type="hidden" name="multicopy" value="" />
6763: <input type="hidden" name="multichange" value="" />
6764: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6765: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6766: </form>
6767: </div>
6768: END
6769: }
6770: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6771: }
1.363 ehlerst 6772: foreach my $field (keys(%orderhash)){
1.390 tempelho 6773: if($field ne '00'){
1.422 onken 6774: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6775: $active = 'style="display: none;float:left"';
1.422 onken 6776: }elsif($activetab eq $field){
1.458 raeburn 6777: $active = 'style="display:block;float:left"';
1.422 onken 6778: }
6779: $form .= '<div id="'.$field.$tid.'"'
6780: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6781: .'</div>'."\n";
1.363 ehlerst 6782: }
6783: }
1.484 raeburn 6784: unless ($env{'form.docslog'}) {
6785: $form .= '</div></div>'."\n";
6786: }
1.329 droeschl 6787: return $form;
6788: }
6789:
6790: sub editing_js {
1.484.2.93.2. (raeburn 6791:): my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 6792: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6793: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6794: p_mnf => 'Name of New Folder',
6795: t_mnf => 'New Folder',
6796: p_mnp => 'Name of New Page',
6797: t_mnp => 'New Page',
1.451 www 6798: p_mxu => 'Title for the External Score',
1.349 biermanm 6799: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6800: p_msb => 'Title for the Problem',
6801: p_mdb => 'Title for the Drop Box',
1.336 schafran 6802: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6803: p_mwp => 'Title for Web Page',
1.348 weissno 6804: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6805: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6806: p_mab_alrt1 => 'Not a valid user:domain',
6807: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6808: p_chn => 'New Title',
6809: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6810: p_rmr2a => 'Remove',
6811: p_rmr2b => '?',
6812: p_rmr3a => 'Remove those',
6813: p_rmr3b => 'items?',
6814: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6815: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6816: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6817: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6818: p_ctr2a => 'Cut',
6819: p_ctr2b => '?',
6820: p_ctr3a => 'Cut those',
6821: p_ctr3b => 'items?',
1.478 raeburn 6822: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6823: imsfile => 'You must choose an IMS package for import',
6824: imscms => 'You must select which Course Management System was the source of the IMS package',
6825: invurl => 'Invalid URL',
6826: titbl => 'Title is blank',
1.484.2.30 raeburn 6827: more => '(More ...)',
6828: less => '(Less ...)',
6829: noor => 'No actions selected or changes to settings specified.',
6830: noch => 'No changes to settings specified.',
6831: noac => 'No actions selected.',
1.484.2.67 raeburn 6832: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6833: );
6834:
1.484.2.61 raeburn 6835: &js_escape(\%js_lt);
1.433 raeburn 6836: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6837: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6838: my $main_container_page;
1.484.2.19 raeburn 6839: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6840: $main_container_page = 1;
1.434 raeburn 6841: }
1.484.2.67 raeburn 6842: my $backtourl;
6843: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6844: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6845:
1.484.2.21 raeburn 6846: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6847: my $caller = $1;
6848: if ($caller =~ /^supplemental/) {
6849: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6850: } else {
6851: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6852: $res = &Apache::lonnet::clutter($res);
6853: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6854: my ($url,$anchor);
6855: if ($res =~ /^([^#]+)#([^#]+)$/) {
6856: $url = $1;
6857: $anchor = $2;
6858: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6859: $caller = $1.&escape('#').$anchor;
6860: }
1.484.2.67 raeburn 6861: } else {
6862: $url = $res;
1.484.2.66 raeburn 6863: }
1.484.2.83 raeburn 6864: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
6865: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
6866: $backtourl .= '?navmap=1';
6867: } else {
6868: $backtourl .= '?symb='.
6869: &HTML::Entities::encode($caller,'<>&"');
6870: }
1.484.2.80 raeburn 6871: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6872: if (($ENV{'SERVER_PORT'} == 443) &&
6873: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 6874: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 6875: if ($hostname ne '') {
6876: $backtourl = 'http://'.$hostname.$backtourl;
6877: }
6878: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6879: }
6880: }
6881: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6882: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.484.2.93 raeburn 6883: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 6884: if ($hostname ne '') {
6885: $backtourl = 'http://'.$hostname.$backtourl;
6886: }
6887: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6888: }
6889: }
6890: }
1.484.2.66 raeburn 6891: if ($anchor ne '') {
6892: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6893: }
1.484.2.57 raeburn 6894: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6895: } else {
6896: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6897: }
6898: }
6899: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6900: $backtourl = '/adm/menu';
6901: } elsif ($supplementalflag) {
1.472 raeburn 6902: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6903: } else {
6904: $backtourl = '/adm/navmaps';
1.472 raeburn 6905: }
6906:
1.484.2.19 raeburn 6907: my $fieldsets = "'ext','doc'";
1.484.2.93.2. (raeburn 6908:): if ($posslti) {
6909:): $fieldsets .= ",'tool'";
6910:): }
1.484.2.19 raeburn 6911: unless ($main_container_page) {
6912: $fieldsets .=",'ims'";
6913: }
1.484.2.12 raeburn 6914: if ($supplementalflag) {
6915: $fieldsets = "'suppext','suppdoc'";
1.484.2.93.2. (raeburn 6916:): if ($posslti) {
6917:): $fieldsets .= ",'supptool'";
6918:): }
1.484.2.12 raeburn 6919: }
6920:
1.484.2.67 raeburn 6921: my $jsmakefunctions;
6922: if ($canedit) {
6923: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6924: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6925: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6926: if (foldername) {
1.484.2.91 raeburn 6927: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 6928: targetform.submit();
6929: }
6930: }
6931:
6932: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6933: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6934: if (pagename) {
1.484.2.91 raeburn 6935: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 6936: targetform.submit();
6937: }
6938: }
6939:
6940: function makeexamupload() {
1.484.2.61 raeburn 6941: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6942: if (title) {
1.329 droeschl 6943: this.document.forms.newexamupload.importdetail.value=
1.484.2.91 raeburn 6944: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 6945: this.document.forms.newexamupload.submit();
6946: }
6947: }
6948:
6949: function makesmppage() {
1.484.2.61 raeburn 6950: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6951: if (title) {
1.329 droeschl 6952: this.document.forms.newsmppg.importdetail.value=
1.484.2.91 raeburn 6953: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6954: this.document.forms.newsmppg.submit();
6955: }
6956: }
6957:
1.484.2.27 raeburn 6958: function makewebpage(type) {
1.484.2.61 raeburn 6959: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6960: var formname;
6961: if (type == 'supp') {
6962: formname = this.document.forms.supwebpage;
6963: } else {
6964: formname = this.document.forms.newwebpage;
6965: }
6966: if (title) {
6967: var webpage = formname.importdetail.value;
1.484.2.91 raeburn 6968: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.484.2.27 raeburn 6969: formname.submit();
6970: }
6971: }
6972:
1.329 droeschl 6973: function makesmpproblem() {
1.484.2.61 raeburn 6974: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6975: if (title) {
1.329 droeschl 6976: this.document.forms.newsmpproblem.importdetail.value=
1.484.2.91 raeburn 6977: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 6978: this.document.forms.newsmpproblem.submit();
6979: }
6980: }
6981:
6982: function makedropbox() {
1.484.2.61 raeburn 6983: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6984: if (title) {
1.329 droeschl 6985: this.document.forms.newdropbox.importdetail.value=
1.484.2.91 raeburn 6986: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 6987: this.document.forms.newdropbox.submit();
6988: }
6989: }
6990:
6991: function makebulboard() {
1.484.2.61 raeburn 6992: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6993: if (title) {
6994: this.document.forms.newbul.importdetail.value=
1.484.2.91 raeburn 6995: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6996: this.document.forms.newbul.submit();
6997: }
6998: }
6999:
7000: function makeabout() {
1.484.2.61 raeburn 7001: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7002: if (user) {
7003: var comp=new Array();
7004: comp=user.split(':');
7005: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7006: if ((comp[0]) && (comp[1])) {
7007: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 7008: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 7009: this.document.forms.newaboutsomeone.submit();
7010: } else {
7011: alert("$js_lt{'p_mab_alrt1'}");
7012: }
7013: } else {
7014: alert("$js_lt{'p_mab_alrt2'}");
7015: }
7016: }
1.335 ehlerst 7017: }
1.484.2.67 raeburn 7018:
7019: function makenew(targetform) {
7020: targetform.submit();
1.335 ehlerst 7021: }
1.484.2.67 raeburn 7022:
7023: function changename(folderpath,index,oldtitle) {
7024: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7025: if (title) {
7026: this.document.forms.renameform.markcopy.value='';
7027: this.document.forms.renameform.title.value=title;
7028: this.document.forms.renameform.cmd.value='rename_'+index;
7029: this.document.forms.renameform.folderpath.value=folderpath;
7030: this.document.forms.renameform.submit();
7031: }
1.329 droeschl 7032: }
7033:
1.484.2.67 raeburn 7034: ENDNEWSCRIPT
7035: } else {
7036: $jsmakefunctions = <<ENDNEWSCRIPT;
7037:
7038: function makenewfolder() {
7039: alert("$js_lt{'edri'}");
7040: }
7041:
7042: function makenewpage() {
7043: alert("$js_lt{'edri'}");
7044: }
7045:
7046: function makeexamupload() {
7047: alert("$js_lt{'edri'}");
7048: }
7049:
7050: function makesmppage() {
7051: alert("$js_lt{'edri'}");
7052: }
7053:
7054: function makewebpage(type) {
7055: alert("$js_lt{'edri'}");
7056: }
7057:
7058: function makesmpproblem() {
7059: alert("$js_lt{'edri'}");
7060: }
7061:
7062: function makedropbox() {
7063: alert("$js_lt{'edri'}");
7064: }
7065:
7066: function makebulboard() {
7067: alert("$js_lt{'edri'}");
7068: }
7069:
7070: function makeabout() {
7071: alert("$js_lt{'edri'}");
7072: }
7073:
7074: function changename() {
7075: alert("$js_lt{'edri'}");
7076: }
7077:
7078: function makenew() {
7079: alert("$js_lt{'edri'}");
7080: }
7081:
7082: function groupimport() {
7083: alert("$js_lt{'edri'}");
7084: }
7085:
7086: function groupsearch() {
7087: alert("$js_lt{'edri'}");
7088: }
7089:
7090: function groupopen(url,recover) {
7091: var options="scrollbars=1,resizable=1,menubar=0";
7092: idxflag=1;
7093: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7094: idx.focus();
7095: }
7096:
7097: ENDNEWSCRIPT
7098:
7099: }
7100: return <<ENDSCRIPT;
7101:
7102: $jsmakefunctions
7103:
1.484.2.13 raeburn 7104: function toggleUpload(caller) {
7105: var blocks = Array($fieldsets);
7106: for (var i=0; i<blocks.length; i++) {
7107: var disp = 'none';
7108: if (caller == blocks[i]) {
7109: var curr = document.getElementById('upload'+caller+'form').style.display;
7110: if (curr == 'none') {
7111: disp='block';
7112: }
7113: }
7114: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.484.2.93.2. (raeburn 7115:): if ((caller == 'tool') || (caller == 'supptool')) {
7116:): if (disp == 'block') {
7117:): if (document.getElementById('LC_exttoolid')) {
7118:): var toolselector = document.getElementById('LC_exttoolid');
7119:): var suppflag = 0;
7120:): if (caller == 'supptool') {
7121:): suppflag = 1;
7122:): }
7123:): currForm = document.getElementById('new'+caller);
7124:): updateExttool(toolselector,currForm,suppflag);
7125:): }
7126:): }
7127:): }
1.484.2.13 raeburn 7128: }
7129: resize_scrollbox('contentscroll','1','1');
7130: return;
7131: }
7132:
1.484.2.19 raeburn 7133: function toggleMap(caller) {
1.484.2.13 raeburn 7134: var disp = 'none';
1.484.2.19 raeburn 7135: if (document.getElementById('importmapform')) {
7136: if (caller == 'map') {
7137: var curr = document.getElementById('importmapform').style.display;
7138: if (curr == 'none') {
7139: disp='block';
7140: }
1.484.2.12 raeburn 7141: }
1.484.2.19 raeburn 7142: document.getElementById('importmapform').style.display=disp;
7143: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 7144: }
1.484.2.19 raeburn 7145: return;
1.329 droeschl 7146: }
7147:
1.484.2.12 raeburn 7148: function makeims(imsform) {
7149: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 7150: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 7151: return;
7152: }
7153: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 7154: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 7155: return;
7156: }
7157: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7158: imsform.submit();
7159: }
7160:
1.478 raeburn 7161: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 7162: var pickitem;
7163: var picknumitem;
7164: var picknumtext;
7165: if (index == 'all') {
7166: pickitem = document.getElementById('randompickall');
7167: picknumitem = document.getElementById('rpicknumall');
7168: picknumtext = document.getElementById('rpicktextall');
7169: } else {
7170: pickitem = document.getElementById('randompick_'+index);
7171: picknumitem = document.getElementById('rpicknum_'+index);
7172: picknumtext = document.getElementById('randompicknum_'+index);
7173: }
1.478 raeburn 7174: if (pickitem.checked) {
1.484.2.61 raeburn 7175: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7176: if (picknum == '' || picknum == null) {
7177: if (caller == 'check') {
7178: pickitem.checked=false;
1.484.2.29 raeburn 7179: if (index == 'all') {
7180: picknumtext.innerHTML = '';
7181: if (caller == 'link') {
7182: propagateState(targetform,'rpicknum');
7183: }
7184: } else {
1.484.2.30 raeburn 7185: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7186: }
1.478 raeburn 7187: }
7188: } else {
7189: picknum.toString();
7190: var regexdigit=/^\\d+\$/;
7191: if (regexdigit.test(picknum)) {
7192: picknumitem.value = picknum;
1.484.2.29 raeburn 7193: if (index == 'all') {
1.484.2.30 raeburn 7194: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 7195: if (caller == 'link') {
7196: propagateState(targetform,'rpicknum');
7197: }
7198: } else {
7199: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 7200: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7201: }
1.478 raeburn 7202: } else {
7203: if (caller == 'check') {
1.484.2.29 raeburn 7204: if (index == 'all') {
7205: picknumtext.innerHTML = '';
7206: if (caller == 'link') {
7207: propagateState(targetform,'rpicknum');
7208: }
7209: } else {
7210: pickitem.checked=false;
1.484.2.30 raeburn 7211: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7212: }
1.478 raeburn 7213: }
7214: return;
7215: }
7216: }
7217: } else {
1.484.2.29 raeburn 7218: picknumitem.value = '';
7219: picknumtext.innerHTML = '';
7220: if (index == 'all') {
7221: if (caller == 'link') {
7222: propagateState(targetform,'rpicknum');
7223: }
7224: } else {
1.484.2.30 raeburn 7225: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7226: }
7227: }
7228: }
7229:
7230: function propagateState(form,param) {
7231: if (document.getElementById(param+'all')) {
7232: var setcheck = 0;
7233: var rpick = 0;
7234: if (param == 'rpicknum') {
7235: if (document.getElementById('randompickall')) {
7236: if (document.getElementById('randompickall').checked) {
7237: if (document.getElementById('rpicknumall')) {
7238: rpick = document.getElementById('rpicknumall').value;
7239: }
7240: }
7241: }
7242: } else {
7243: if (document.getElementById(param+'all').checked) {
7244: setcheck = 1;
7245: }
7246: }
1.484.2.30 raeburn 7247: var allidxlist;
7248: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7249: if (document.getElementById('all'+param+'idx')) {
7250: allidxlist = document.getElementById('all'+param+'idx').value;
7251: }
7252: var actions = new Array ('remove','cut','copy');
7253: for (var i=0; i<actions.length; i++) {
7254: if (actions[i] != param) {
7255: if (document.getElementById(actions[i]+'all')) {
7256: document.getElementById(actions[i]+'all').checked = false;
7257: }
7258: }
7259: }
7260: }
1.484.2.29 raeburn 7261: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 7262: allidxlist = form.allidx.value;
7263: }
7264: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7265: allidxlist = form.allmapidx.value;
7266: }
7267: if ((allidxlist != '') && (allidxlist != null)) {
7268: var allidxs = allidxlist.split(',');
7269: if (allidxs.length > 1) {
7270: for (var i=0; i<allidxs.length; i++) {
7271: if (document.getElementById(param+'_'+allidxs[i])) {
7272: if (param == 'rpicknum') {
7273: if (document.getElementById('randompick_'+allidxs[i])) {
7274: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7275: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7276: if (rpick > 0) {
7277: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7278: } else {
7279: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7280: }
7281: }
7282: }
7283: } else {
1.484.2.29 raeburn 7284: if (setcheck == 1) {
7285: document.getElementById(param+'_'+allidxs[i]).checked = true;
7286: } else {
7287: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 7288: if (param == 'randompick') {
7289: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7290: }
1.484.2.29 raeburn 7291: }
7292: }
7293: }
7294: }
1.484.2.30 raeburn 7295: if (setcheck == 1) {
7296: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7297: var actions = new Array('copy','cut','remove');
7298: for (var i=0; i<actions.length; i++) {
7299: var otheractions;
7300: var otheridxs;
7301: if (actions[i] === param) {
7302: continue;
7303: } else {
7304: if (document.getElementById('all'+actions[i]+'idx')) {
7305: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7306: otheridxs = otheractions.split(',');
7307: if (otheridxs.length > 1) {
7308: for (var j=0; j<otheridxs.length; j++) {
7309: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7310: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7311: }
1.484.2.29 raeburn 7312: }
7313: }
7314: }
7315: }
1.484.2.30 raeburn 7316: }
1.484.2.29 raeburn 7317: }
7318: }
7319: }
7320: }
1.478 raeburn 7321: }
1.484.2.29 raeburn 7322: return;
7323: }
7324:
1.484.2.63 raeburn 7325: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7326: var canedit = '$canedit';
7327: if (canedit == '') {
7328: alert("$js_lt{'edri'}");
7329: return;
7330: }
1.484.2.30 raeburn 7331: var dosettings;
7332: var doaction;
7333: var control = document.togglemultsettings;
7334: if (context == 'actions') {
7335: control = document.togglemultactions;
7336: doaction = 1;
7337: } else {
7338: dosettings = 1;
7339: }
7340: if (control) {
7341: if (control.showmultpick.length) {
7342: for (var i=0; i<control.showmultpick.length; i++) {
7343: if (control.showmultpick[i].checked) {
7344: if (control.showmultpick[i].value == 1) {
7345: if (context == 'settings') {
7346: dosettings = 0;
7347: } else {
7348: doaction = 0;
7349: }
7350: }
7351: }
7352: }
7353: }
7354: }
7355: if (context == 'settings') {
7356: if (dosettings == 1) {
7357: targetform.changeparms.value=param;
7358: targetform.submit();
7359: }
7360: }
7361: if (context == 'actions') {
7362: if (doaction == 1) {
7363: targetform.cmd.value=param+'_'+index;
7364: targetform.folderpath.value=folderpath;
7365: targetform.markcopy.value=idx+':'+param;
7366: targetform.copyfolder.value=folder+'.'+container;
7367: if (param == 'remove') {
1.484.2.63 raeburn 7368: var doremove = 0;
7369: if (skip_confirm) {
7370: if (confirm_removal) {
7371: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7372: doremove = 1;
7373: }
7374: } else {
7375: doremove = 1;
7376: }
7377: } else {
7378: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7379: doremove = 1;
7380: }
7381: }
7382: if (doremove) {
1.484.2.30 raeburn 7383: targetform.markcopy.value='';
7384: targetform.copyfolder.value='';
1.484.2.29 raeburn 7385: targetform.submit();
7386: }
7387: }
1.484.2.30 raeburn 7388: if (param == 'cut') {
1.484.2.61 raeburn 7389: 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 7390: targetform.submit();
7391: return;
7392: }
7393: }
7394: if (param == 'copy') {
7395: targetform.submit();
7396: return;
7397: }
7398: targetform.markcopy.value='';
7399: targetform.copyfolder.value='';
7400: targetform.cmd.value='';
7401: targetform.folderpath.value='';
7402: return;
7403: } else {
7404: if (document.getElementById(param+'_'+idx)) {
7405: item = document.getElementById(param+'_'+idx);
7406: if (item.type == 'checkbox') {
7407: if (item.checked) {
7408: item.checked = false;
7409: } else {
7410: item.checked = true;
7411: singleCheck(item,idx,param);
7412: }
7413: }
7414: }
7415: }
7416: }
7417: return;
7418: }
7419:
7420: function singleCheck(caller,idx,action) {
7421: actions = new Array('cut','copy','remove');
7422: if (caller.checked) {
7423: for (var i=0; i<actions.length; i++) {
7424: if (actions[i] != action) {
7425: if (document.getElementById(actions[i]+'_'+idx)) {
7426: if (document.getElementById(actions[i]+'_'+idx).checked) {
7427: document.getElementById(actions[i]+'_'+idx).checked = false;
7428: }
7429: }
7430: }
1.484.2.29 raeburn 7431: }
7432: }
7433: return;
1.478 raeburn 7434: }
7435:
1.334 muellerd 7436: function unselectInactive(nav) {
1.335 ehlerst 7437: currentNav = document.getElementById(nav);
7438: currentLis = currentNav.getElementsByTagName('LI');
7439: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7440: if (currentLis[i].className == 'goback') {
7441: currentLis[i].className = 'goback';
7442: } else {
7443: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7444: currentLis[i].className = 'right';
1.472 raeburn 7445: } else {
1.374 tempelho 7446: currentLis[i].className = 'i';
1.472 raeburn 7447: }
7448: }
1.335 ehlerst 7449: }
1.332 tempelho 7450: }
7451:
1.334 muellerd 7452: function hideAll(current, nav, data) {
1.335 ehlerst 7453: unselectInactive(nav);
1.484.2.43 raeburn 7454: if (current) {
7455: if (current.className == 'right'){
1.374 tempelho 7456: current.className = 'right active'
1.484.2.43 raeburn 7457: } else {
1.374 tempelho 7458: current.className = 'active';
1.484.2.43 raeburn 7459: }
1.374 tempelho 7460: }
1.335 ehlerst 7461: currentData = document.getElementById(data);
7462: currentDivs = currentData.getElementsByTagName('DIV');
7463: for (i = 0; i < currentDivs.length; i++) {
7464: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7465: currentDivs[i].style.display = 'none';
1.330 tempelho 7466: }
7467: }
1.335 ehlerst 7468: }
1.330 tempelho 7469:
1.374 tempelho 7470: function openTabs(pageId) {
7471: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7472: if(tabnav.length > 2 ){
1.389 tempelho 7473: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7474: currentLis = currentNav.getElementsByTagName('LI');
7475: for(i = 0; i< currentLis.length; i++){
7476: if(currentLis[i].className == 'active') {
1.375 tempelho 7477: funcString = currentLis[i].onclick.toString();
7478: tab = funcString.split('"');
1.420 onken 7479: if(tab.length < 2) {
7480: tab = funcString.split("'");
7481: }
1.375 tempelho 7482: currentData = document.getElementById(tab[1]);
7483: currentData.style.display = 'block';
1.374 tempelho 7484: }
7485: }
7486: }
7487: }
7488:
1.334 muellerd 7489: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7490: currstate = current.className;
1.334 muellerd 7491: hideAll(current, nav, data);
1.375 tempelho 7492: openTabs(pageId);
1.334 muellerd 7493: unselectInactive(nav);
1.484.2.43 raeburn 7494: if ((currstate == 'active') || (currstate == 'right active')) {
7495: if (currstate == 'active') {
7496: current.className = '';
7497: } else {
7498: current.className = 'right';
7499: }
7500: activeTab = '';
7501: toggleUpload();
7502: toggleMap();
7503: resize_scrollbox('contentscroll','1','0');
7504: return;
7505: } else {
7506: current.className = 'active';
7507: }
1.330 tempelho 7508: currentData = document.getElementById(pageId);
7509: currentData.style.display = 'block';
1.458 raeburn 7510: activeTab = pageId;
1.484.2.12 raeburn 7511: toggleUpload();
1.484.2.14 raeburn 7512: toggleMap();
1.433 raeburn 7513: if (nav == 'mainnav') {
7514: var storedpath = "$docs_folderpath";
1.434 raeburn 7515: var storedpage = "$main_container_page";
1.433 raeburn 7516: var reg = new RegExp("^supplemental");
7517: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7518: if (storedpage == 1) {
7519: document.simpleedit.folderpath.value = '';
7520: document.uploaddocument.folderpath.value = '';
7521: } else {
7522: if (reg.test(storedpath)) {
7523: document.simpleedit.folderpath.value = '$toplevelmain';
7524: document.uploaddocument.folderpath.value = '$toplevelmain';
7525: document.newext.folderpath.value = '$toplevelmain';
7526: } else {
7527: document.simpleedit.folderpath.value = storedpath;
7528: document.uploaddocument.folderpath.value = storedpath;
7529: document.newext.folderpath.value = storedpath;
7530: }
1.433 raeburn 7531: }
7532: } else {
1.434 raeburn 7533: if (reg.test(storedpath)) {
7534: document.simpleedit.folderpath.value = storedpath;
7535: document.supuploaddocument.folderpath.value = storedpath;
7536: document.supnewext.folderpath.value = storedpath;
7537: } else {
1.433 raeburn 7538: document.simpleedit.folderpath.value = '$toplevelsupp';
7539: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7540: document.supnewext.folderpath.value = '$toplevelsupp';
7541: }
7542: }
7543: }
1.484.2.3 raeburn 7544: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7545: return false;
7546: }
1.329 droeschl 7547:
1.472 raeburn 7548: function toContents(jumpto) {
7549: var newurl = '$backtourl';
1.484.2.21 raeburn 7550: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7551: newurl = newurl+'?postdata='+jumpto;
7552: }
7553: location.href=newurl;
7554: }
7555:
1.484.2.30 raeburn 7556: function togglePick(caller,value) {
7557: var disp = 'none';
7558: if (document.getElementById('multi'+caller)) {
7559: var curr = document.getElementById('multi'+caller).style.display;
7560: if (value == 1) {
7561: disp='block';
7562: }
7563: if (curr == disp) {
7564: return;
7565: }
7566: document.getElementById('multi'+caller).style.display=disp;
7567: if (value == 1) {
1.484.2.61 raeburn 7568: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7569: } else {
7570: document.getElementById('more'+caller).innerHTML = '';
7571: }
7572: if (caller == 'actions') {
7573: setClass(value);
7574: setBoxes(value);
7575: }
7576: }
7577: var showButton = multiSettings();
7578: if (showButton != 1) {
7579: showButton = multiActions();
7580: }
7581: if (document.getElementById('multisave')) {
7582: if (showButton == 1) {
7583: document.getElementById('multisave').style.display='block';
7584: } else {
7585: document.getElementById('multisave').style.display='none';
7586: }
7587: }
7588: resize_scrollbox('contentscroll','1','1');
7589: return;
7590: }
7591:
7592: function toggleCheckUncheck(caller,more) {
7593: if (more == 1) {
1.484.2.61 raeburn 7594: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7595: document.getElementById('allfields'+caller).style.display='block';
7596: } else {
1.484.2.61 raeburn 7597: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7598: document.getElementById('allfields'+caller).style.display='none';
7599: }
7600: resize_scrollbox('contentscroll','1','1');
7601: }
7602:
7603: function multiSettings() {
7604: var inuse = 0;
7605: var settingsform = document.togglemultsettings;
7606: if (settingsform.showmultpick.length > 1) {
7607: for (var i=0; i<settingsform.showmultpick.length; i++) {
7608: if (settingsform.showmultpick[i].checked) {
7609: if (settingsform.showmultpick[i].value == 1) {
7610: inuse = 1;
7611: }
7612: }
7613: }
7614: }
7615: return inuse;
7616: }
7617:
7618: function multiActions() {
7619: var inuse = 0;
7620: var actionsform = document.togglemultactions;
7621: if (actionsform.showmultpick.length > 1) {
7622: for (var i=0; i<actionsform.showmultpick.length; i++) {
7623: if (actionsform.showmultpick[i].checked) {
7624: if (actionsform.showmultpick[i].value == 1) {
7625: inuse = 1;
7626: }
7627: }
7628: }
7629: }
7630: return inuse;
7631: }
7632:
7633: function checkSubmits() {
7634: var numchanges = 0;
7635: var form = document.saveactions;
7636: var doactions = multiActions();
7637: var cutwarnings = 0;
7638: var remwarnings = 0;
1.484.2.63 raeburn 7639: var removalinfo = 0;
1.484.2.30 raeburn 7640: if (doactions == 1) {
7641: var remidxlist = document.cumulativeactions.allremoveidx.value;
7642: if ((remidxlist != '') && (remidxlist != null)) {
7643: var remidxs = remidxlist.split(',');
7644: for (var i=0; i<remidxs.length; i++) {
7645: if (document.getElementById('remove_'+remidxs[i])) {
7646: if (document.getElementById('remove_'+remidxs[i]).checked) {
7647: form.multiremove.value += remidxs[i]+',';
7648: numchanges ++;
7649: if (document.getElementById('skip_remove_'+remidxs[i])) {
7650: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7651: remwarnings ++;
7652: }
7653: }
1.484.2.63 raeburn 7654: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7655: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7656: removalinfo ++;
7657: }
7658: }
1.484.2.30 raeburn 7659: }
7660: }
7661: }
7662: }
7663: var cutidxlist = document.cumulativeactions.allcutidx.value;
7664: if ((cutidxlist != '') && (cutidxlist != null)) {
7665: var cutidxs = cutidxlist.split(',');
7666: for (var i=0; i<cutidxs.length; i++) {
7667: if (document.getElementById('cut_'+cutidxs[i])) {
7668: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7669: form.multicut.value += cutidxs[i]+',';
7670: numchanges ++;
7671: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7672: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7673: cutwarnings ++;
7674: }
7675: }
7676: }
7677: }
7678: }
7679: }
7680: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7681: if ((copyidxlist != '') && (copyidxlist != null)) {
7682: var copyidxs = copyidxlist.split(',');
7683: for (var i=0; i<copyidxs.length; i++) {
7684: if (document.getElementById('copy_'+copyidxs[i])) {
7685: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7686: form.multicopy.value += copyidxs[i]+',';
7687: numchanges ++;
7688: }
7689: }
7690: }
7691: }
7692: if (numchanges > 0) {
7693: form.multichange.value = numchanges;
7694: }
7695: }
7696: var dosettings = multiSettings();
7697: var haschanges = 0;
7698: if (dosettings == 1) {
7699: form.allencrypturl.value = '';
7700: form.allhiddenresource.value = '';
7701: form.changeparms.value = 'all';
7702: var patt=new RegExp(",\$");
7703: var allidxlist = document.cumulativesettings.allidx.value;
7704: if ((allidxlist != '') && (allidxlist != null)) {
7705: var allidxs = allidxlist.split(',');
7706: if (allidxs.length > 1) {
7707: for (var i=0; i<allidxs.length; i++) {
7708: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7709: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7710: form.allhiddenresource.value += allidxs[i]+',';
7711: }
7712: }
7713: if (document.getElementById('encrypturl_'+allidxs[i])) {
7714: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7715: form.allencrypturl.value += allidxs[i]+',';
7716: }
1.484.2.29 raeburn 7717: }
7718: }
1.484.2.30 raeburn 7719: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7720: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7721: }
7722: }
7723: form.allrandompick.value = '';
7724: form.allrandomorder.value = '';
7725: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7726: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7727: var allmapidxs = allmapidxlist.split(',');
7728: for (var i=0; i<allmapidxs.length; i++) {
7729: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7730: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7731: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7732: if ((randompick.checked) && (rpicknum.value != '')) {
7733: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7734: }
7735: if (randorder.checked) {
7736: form.allrandomorder.value += allmapidxs[i]+',';
7737: }
7738: }
7739: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7740: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7741: }
7742: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7743: haschanges = 1;
7744: }
7745: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7746: haschanges = 1;
7747: }
7748: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7749: haschanges = 1;
7750: }
7751: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7752: haschanges = 1;
7753: }
7754: }
7755: if (doactions == 1) {
7756: if (numchanges > 0) {
1.484.2.63 raeburn 7757: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7758: if (remwarnings > 0) {
1.484.2.61 raeburn 7759: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7760: return false;
7761: }
7762: }
1.484.2.63 raeburn 7763: if (removalinfo > 0) {
7764: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7765: return false;
7766: }
7767: }
1.484.2.30 raeburn 7768: if (cutwarnings > 0) {
1.484.2.61 raeburn 7769: 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 7770: return false;
1.484.2.29 raeburn 7771: }
7772: }
7773: }
1.484.2.30 raeburn 7774: form.submit();
7775: return true;
7776: }
7777: }
7778: if (dosettings == 1) {
7779: if (haschanges == 1) {
7780: form.submit();
7781: return true;
1.484.2.29 raeburn 7782: }
7783: }
1.484.2.30 raeburn 7784: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7785: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7786: } else {
7787: if (dosettings == 1) {
1.484.2.61 raeburn 7788: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7789: } else {
1.484.2.61 raeburn 7790: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7791: }
7792: }
7793: return false;
7794: }
7795:
7796: function setClass(value) {
7797: var cutclass = 'LC_docs_cut';
7798: var copyclass = 'LC_docs_copy';
7799: var removeclass = 'LC_docs_remove';
7800: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7801: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7802: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7803: var links = document.getElementsByTagName('a');
7804: for (var i=0; i<links.length; i++) {
7805: var classes = links[i].className;
7806: if (cutreg.test(classes)) {
7807: links[i].className = cutclass;
7808: if (value == 1) {
7809: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7810: }
1.484.2.30 raeburn 7811: } else {
7812: if (copyreg.test(classes)) {
7813: links[i].className = copyclass;
7814: if (value == 1) {
7815: links[i].className += " LC_menubuttons_link";
7816: }
7817: } else {
7818: if (removereg.test(classes)) {
7819: links[i].className = removeclass;
7820: if (value == 1) {
7821: links[i].className += " LC_menubuttons_link";
7822: }
7823: }
1.484.2.29 raeburn 7824: }
7825: }
7826: }
1.484.2.30 raeburn 7827: return;
1.484.2.29 raeburn 7828: }
7829:
1.484.2.30 raeburn 7830: function setBoxes(value) {
7831: var remidxlist = document.cumulativeactions.allremoveidx.value;
7832: if ((remidxlist != '') && (remidxlist != null)) {
7833: var remidxs = remidxlist.split(',');
7834: for (var i=0; i<remidxs.length; i++) {
7835: if (document.getElementById('remove_'+remidxs[i])) {
7836: var item = document.getElementById('remove_'+remidxs[i]);
7837: if (value == 1) {
7838: item.className = 'LC_docs_remove';
7839: } else {
7840: item.className = 'LC_hidden';
7841: }
7842: }
1.484.2.29 raeburn 7843: }
7844: }
1.484.2.30 raeburn 7845: var cutidxlist = document.cumulativeactions.allcutidx.value;
7846: if ((cutidxlist != '') && (cutidxlist != null)) {
7847: var cutidxs = cutidxlist.split(',');
7848: for (var i=0; i<cutidxs.length; i++) {
7849: if (document.getElementById('cut_'+cutidxs[i])) {
7850: var item = document.getElementById('cut_'+cutidxs[i]);
7851: if (value == 1) {
7852: item.className = 'LC_docs_cut';
7853: } else {
7854: item.className = 'LC_hidden';
7855: }
7856: }
7857: }
7858: }
7859: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7860: if ((copyidxlist != '') && (copyidxlist != null)) {
7861: var copyidxs = copyidxlist.split(',');
7862: for (var i=0; i<copyidxs.length; i++) {
7863: if (document.getElementById('copy_'+copyidxs[i])) {
7864: var item = document.getElementById('copy_'+copyidxs[i]);
7865: if (value == 1) {
7866: item.className = 'LC_docs_copy';
7867: } else {
7868: item.className = 'LC_hidden';
7869: }
7870: }
1.484.2.29 raeburn 7871: }
7872: }
7873: return;
7874: }
7875:
1.484.2.67 raeburn 7876: ENDSCRIPT
1.329 droeschl 7877: }
1.457 raeburn 7878:
1.483 raeburn 7879: sub history_tab_js {
7880: return <<"ENDHIST";
7881: function toggleHistoryDisp(choice) {
7882: document.docslogform.docslog.value = choice;
7883: document.docslogform.submit();
7884: return;
7885: }
7886:
7887: ENDHIST
7888: }
7889:
1.484 raeburn 7890: sub inject_data_js {
7891: return <<ENDINJECT;
7892:
7893: function injectData(current, hiddenField, name, value) {
7894: currentElement = document.getElementById(hiddenField);
7895: currentElement.name = name;
7896: currentElement.value = value;
7897: current.submit();
7898: }
7899:
7900: ENDINJECT
7901: }
7902:
7903: sub dump_switchserver_js {
7904: my @hosts = @_;
1.484.2.61 raeburn 7905: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7906: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7907: swit => 'Switch server?',
1.484.2.61 raeburn 7908: );
7909: my %html_js_lt = &Apache::lonlocal::texthash(
7910: swit => 'Switch server?',
1.484.2.43 raeburn 7911: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7912: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7913: chos => 'Choose server',
7914: );
1.484.2.61 raeburn 7915: &js_escape(\%js_lt);
7916: &html_escape(\%html_js_lt);
7917: &js_escape(\%html_js_lt);
1.484 raeburn 7918: my $role = $env{'request.role'};
7919: my $js = <<"ENDSWJS";
7920: <script type="text/javascript">
7921: function write_switchserver() {
7922: var server;
7923: if (document.setserver.posshosts.length > 0) {
7924: for (var i=0; i<document.setserver.posshosts.length; i++) {
7925: if (document.setserver.posshosts[i].checked) {
7926: server = document.setserver.posshosts[i].value;
7927: }
7928: }
7929: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7930: }
7931: window.close();
7932: }
7933: </script>
7934:
7935: ENDSWJS
7936:
7937: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7938: {'only_body' => 1,
7939: 'js_ready' => 1,});
7940: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7941:
7942: my $hostpicker;
7943: my $count = 0;
7944: foreach my $host (sort(@hosts)) {
7945: my $checked;
7946: if ($count == 0) {
7947: $checked = ' checked="checked"';
7948: }
7949: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7950: $host.'"'.$checked.' />'.$host.'</label> ';
7951: $count++;
7952: }
7953:
7954: return <<"ENDSWITCHJS";
7955:
7956: function dump_needs_switchserver(url) {
7957: if (url!='' && url!= null) {
1.484.2.61 raeburn 7958: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7959: go(url);
7960: }
7961: }
7962: return;
7963: }
7964:
7965: function choose_switchserver_window() {
7966: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7967: newWindow.document.open();
7968: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7969: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7970: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7971: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7972: '<form name="setserver" method="post" action="" \\/>\\n'+
7973: '$hostpicker\\n'+
7974: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7975: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7976: 'onclick="write_switchserver();" \\/>\\n'+
7977: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7978: newWindow.document.writeln('$endpage');
7979: newWindow.document.close();
7980: newWindow.focus();
7981: }
7982:
7983: ENDSWITCHJS
7984: }
7985:
7986: sub makedocslogform {
7987: my ($formelems,$docslog) = @_;
7988: return <<"LOGSFORM";
7989: <form action="/adm/coursedocs" method="post" name="docslogform">
7990: <input type="hidden" name="docslog" value="$docslog" />
7991: $formelems
7992: </form>
7993: LOGSFORM
7994: }
7995:
7996: sub makesimpleeditform {
7997: my ($formelems) = @_;
7998: return <<"SIMPFORM";
7999: <form name="simpleedit" method="post" action="/adm/coursedocs">
8000: <input type="hidden" name="importdetail" value="" />
8001: $formelems
8002: </form>
8003: SIMPFORM
8004: }
8005:
1.329 droeschl 8006: 1;
8007: __END__
8008:
8009:
8010: =head1 NAME
8011:
8012: Apache::londocs.pm
8013:
8014: =head1 SYNOPSIS
8015:
8016: This is part of the LearningOnline Network with CAPA project
8017: described at http://www.lon-capa.org.
8018:
8019: =head1 SUBROUTINES
8020:
8021: =over
8022:
8023: =item %help=()
8024:
8025: Available help topics
8026:
8027: =item mapread()
8028:
1.344 bisitz 8029: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8030: @order and @resources, determines status
8031: sets @order - pointer to resources in right order
8032: sets @resources - array with the resources with correct idx
8033:
8034: =item authorhosts()
8035:
8036: Return hash with valid author names
8037:
8038: =item clean()
8039:
8040: =item dumpcourse()
8041:
8042: Actually dump course
8043:
8044: =item group_import()
8045:
8046: Imports the given (name, url) resources into the course
8047: coursenum, coursedom, and folder must precede the list
8048:
8049: =item breadcrumbs()
8050:
8051: =item log_docs()
8052:
8053: =item docs_change_log()
8054:
8055: =item update_paste_buffer()
8056:
8057: =item print_paste_buffer()
8058:
8059: =item do_paste_from_buffer()
8060:
1.484.2.30 raeburn 8061: =item do_buffer_empty()
8062:
8063: =item clear_from_buffer()
8064:
1.484.2.7 raeburn 8065: =item get_newmap_url()
8066:
8067: =item dbcopy()
8068:
8069: =item uniqueness_check()
8070:
8071: =item contained_map_check()
8072:
8073: =item url_paste_fixups()
8074:
8075: =item apply_fixups()
8076:
8077: =item copy_dependencies()
8078:
1.329 droeschl 8079: =item update_parameter()
8080:
8081: =item handle_edit_cmd()
8082:
8083: =item editor()
8084:
8085: =item process_file_upload()
8086:
8087: =item process_secondary_uploads()
8088:
8089: =item is_supplemental_title()
8090:
8091: =item entryline()
8092:
8093: =item tiehash()
8094:
8095: =item untiehash()
8096:
8097: =item checkonthis()
8098:
8099: check on this
8100:
8101: =item verifycontent()
8102:
8103: Verify Content
8104:
1.484.2.78 raeburn 8105: =item devalidateversioncache()
8106:
8107: =item checkversions()
1.329 droeschl 8108:
8109: Check Versions
8110:
8111: =item mark_hash_old()
8112:
8113: =item is_hash_old()
8114:
8115: =item changewarning()
8116:
8117: =item init_breadcrumbs()
8118:
8119: Breadcrumbs for special functions
8120:
1.484 raeburn 8121: =item create_list_elements()
8122:
8123: =item create_form_ul()
8124:
8125: =item startContentScreen()
8126:
8127: =item endContentScreen()
8128:
8129: =item supplemental_base()
8130:
8131: =item embedded_form_elems()
8132:
8133: =item embedded_destination()
8134:
8135: =item return_to_editor()
8136:
8137: =item decompression_info()
8138:
8139: =item decompression_phase_one()
8140:
8141: =item decompression_phase_two()
8142:
8143: =item remove_archive()
8144:
8145: =item generate_admin_menu()
8146:
8147: =item generate_edit_table()
8148:
8149: =item editing_js()
8150:
8151: =item history_tab_js()
8152:
8153: =item inject_data_js()
8154:
8155: =item dump_switchserver_js()
8156:
1.484.2.3 raeburn 8157: =item resize_scrollbox_js()
1.484 raeburn 8158:
8159: =item makedocslogform()
8160:
1.484.2.3 raeburn 8161: =item makesimpleeditform()
8162:
1.329 droeschl 8163: =back
8164:
8165: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>