Annotation of loncom/interface/londocs.pm, revision 1.484.2.93.2.7
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.6 2023/01/19 03:27:48 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'}) {
1.484.2.93.2. (raeburn 1143:): my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1144:): if ($title eq '') {
1145:): ($title) = ($url =~ m{/([^/]+)$});
1146:): }
1147:): $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.329 droeschl 1148: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1149: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1150: # FIXME: internationalization seems wrong here
1.329 droeschl 1151: $r->print('<li>'.
1152: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1153: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1154: .'</li>');
1155: }
1156: }
1157: $r->print('</ul>');
1158: }
1159: # End
1160: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1161: $shown++;
1162: if (!($env{'form.show'} eq &mt('all')
1163: || $shown<=$env{'form.show'})) { last; }
1164: }
1.484 raeburn 1165: $r->print(&Apache::loncommon::end_data_table()."\n".
1166: &makesimpleeditform($pathitem)."\n".
1167: '</div></div>');
1168: $r->print(&endContentScreen());
1.329 droeschl 1169: }
1170:
1171: sub update_paste_buffer {
1.484.2.7 raeburn 1172: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1173: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1174: if ($env{'form.multiremove'}) {
1175: $env{'form.multiremove'} =~ s/,$//;
1176: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1177: }
1178: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1179: if ($env{'form.multicut'}) {
1180: $env{'form.multicut'} =~ s/,$//;
1181: foreach my $item (split(/,/,$env{'form.multicut'})) {
1182: unless ($removals{$item}) {
1183: $cuts{$item} = 1;
1184: push(@possibles,$item.':cut');
1185: }
1186: }
1187: }
1188: if ($env{'form.multicopy'}) {
1189: $env{'form.multicopy'} =~ s/,$//;
1190: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1191: unless ($removals{$item} || $cuts{$item}) {
1192: push(@possibles,$item.':copy');
1193: }
1194: }
1195: }
1196: } elsif ($env{'form.markcopy'}) {
1197: @possibles = split(/,/,$env{'form.markcopy'});
1198: }
1.329 droeschl 1199:
1.484.2.30 raeburn 1200: return if (@possibles == 0);
1.329 droeschl 1201: return if (!defined($env{'form.copyfolder'}));
1202:
1203: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1204: $env{'form.copyfolder'});
1205: return if ($fatal);
1206:
1.484.2.30 raeburn 1207: my %curr_groups = &Apache::longroup::coursegroups();
1208:
1209: # Retrieve current paste buffer suffixes.
1210: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1211: my (%pasteurls,@newpaste);
1212:
1213: # Construct identifiers for current contents of user's paste buffer
1214: if (@currpaste) {
1215: foreach my $suffix (@currpaste) {
1.484.2.87 raeburn 1216: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1217: my $url = $env{'docs.markedcopy_url_'.$suffix};
1218: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1219: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1220: ($url ne '')) {
1221: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1222: $pasteurls{$cid.'_'.$mapidx} = 1;
1223: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1224: $pasteurls{$url} = 1;
1225: } else {
1226: $pasteurls{$cid.'_'.$url} = 1;
1227: }
1228: }
1.484.2.30 raeburn 1229: }
1230: }
1231:
1232: # Mark items for copying (skip any items already in user's paste buffer)
1233: my %addtoenv;
1.484.2.82 raeburn 1234:
1235: my @pathitems = split(/\&/,$env{'form.folderpath'});
1236: my @folderconf = split(/\:/,$pathitems[-1]);
1.484.2.87 raeburn 1237: my $ispage = $folderconf[5];
1.484.2.82 raeburn 1238:
1.484.2.30 raeburn 1239: foreach my $item (@possibles) {
1240: my ($orderidx,$cmd) = split(/:/,$item);
1241: next if ($orderidx =~ /\D/);
1242: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1243: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1244: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1245: my %denied = &action_restrictions($coursenum,$coursedom,
1246: &LONCAPA::map::qtescape($url),
1247: $env{'form.folderpath'},\%curr_groups);
1248: next if ($denied{'copy'});
1249: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 1250: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1251: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1252: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1253: next if (exists($pasteurls{$url}));
1254: } else {
1255: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1256: }
1.484.2.30 raeburn 1257: my ($suffix,$errortxt,$locknotfreed) =
1258: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1259: if ($suffix ne '') {
1260: push(@newpaste,$suffix);
1261: } else {
1262: if ($locknotfreed) {
1263: return $locknotfreed;
1264: }
1.484.2.30 raeburn 1265: }
1266: if (&is_supplemental_title($title)) {
1267: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1268: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1269: }
1270:
1271: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1272: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1273: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1274: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1275: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1276: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1277: my $prefix = $1;
1278: my $subdir =$2;
1279: if ($subdir eq '') {
1280: $subdir = $prefix;
1.484.2.7 raeburn 1281: }
1.484.2.30 raeburn 1282: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.484.2.93.2. (raeburn 1283:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1284:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.484.2.30 raeburn 1285: if (ref($hierarchy{$url}) eq 'HASH') {
1286: my ($nested,$nestednames);
1287: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1288: $nested =~ s/\&$//;
1289: $nestednames =~ s/\Q___&&&___\E$//;
1290: if ($nested ne '') {
1291: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1292: }
1293: if ($nestednames ne '') {
1294: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1295: }
1.484.2.7 raeburn 1296: }
1297: }
1.484.2.57 raeburn 1298: if ($locknotfreed) {
1299: $output = $locknotfreed;
1300: last;
1301: }
1.484.2.7 raeburn 1302: }
1.484.2.30 raeburn 1303: if (@newpaste) {
1304: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1305: }
1.484.2.7 raeburn 1306: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1307: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1308: return $output;
1.329 droeschl 1309: }
1310:
1.484.2.7 raeburn 1311: sub recurse_uploaded_maps {
1312: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1313: if (ref($hierarchy->{$url}) eq 'HASH') {
1314: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1315: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1316: my (@uploaded,@names,%shorter);
1317: for (my $i=0; $i<@maps; $i++) {
1318: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1319: if ($inner ne '') {
1320: push(@uploaded,$inner);
1321: push(@names,&escape($titles[$i]));
1322: $shorter{$maps[$i]} = $inner;
1323: }
1324: }
1325: $$nestref .= "$dir:".join(',',@uploaded).'&';
1326: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1327: foreach my $map (@maps) {
1328: if ($shorter{$map} ne '') {
1329: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1330: }
1331: }
1332: }
1333: return;
1334: }
1335:
1.329 droeschl 1336: sub print_paste_buffer {
1.484.2.7 raeburn 1337: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1338: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1339:
1.484.2.30 raeburn 1340: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1341: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1342: }
1343:
1.484.2.30 raeburn 1344: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1345: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1346: my $clipboardcount = 0;
1.484.2.7 raeburn 1347:
1.484.2.30 raeburn 1348: # Construct identifiers for current contents of user's paste buffer
1349: foreach my $suffix (@currpaste) {
1350: next if ($suffix =~ /\D/);
1351: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1352: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1353: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1354: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1355: ($url ne '')) {
1.484.2.47 raeburn 1356: $clipboardcount ++;
1.484.2.30 raeburn 1357: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.484.2.93.2. (raeburn 1358:): $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.484.2.30 raeburn 1359: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1360: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1361: $is_external = 1;
1.484.2.93.2. (raeburn 1362:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1363:): $is_exttool = 1;
1.484.2.7 raeburn 1364: }
1.484.2.30 raeburn 1365: if ($folder =~ /^supplemental/) {
1366: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1367: unless ($canpaste) {
1368: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1369: }
1.484.2.30 raeburn 1370: } else {
1371: $canpaste = 1;
1.484.2.7 raeburn 1372: }
1.484.2.30 raeburn 1373: if ($canpaste) {
1374: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1375: my $srcdom = $1;
1376: my $srcnum = $2;
1377: my $rem = $3;
1378: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1379: $othercourse = 1;
1380: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1381: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1382: } else {
1383: $canpaste = 0;
1384: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1385: }
1386: }
1.484.2.30 raeburn 1387: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1388: my $prefix = $1;
1389: $parent = $2;
1390: if ($folder !~ /^\Q$prefix\E/) {
1391: $areachange = 1;
1392: }
1393: $is_uploaded_map = 1;
1394: }
1.484.2.82 raeburn 1395: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.484.2.93.2. (raeburn 1396:): ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.484.2.76 raeburn 1397: if ($cid ne $env{'request.course.id'}) {
1398: my ($srcdom,$srcnum) = split(/_/,$cid);
1399: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.93.2. (raeburn 1400:): if (($is_exttool) && ($srcdom ne $coursedom)) {
1401:): $canpaste = 0;
1402:): $nopaste = &mt('Paste from another domain unavailable.');
1403:): } else {
1404:): $othercrs = '<br />'.&mt('(from another course)');
1405:): }
1.484.2.76 raeburn 1406: } else {
1407: $canpaste = 0;
1408: $nopaste = &mt('Paste from another course unavailable.');
1409: }
1410: }
1411: }
1412: if ($canpaste) {
1413: push(@pasteable,$suffix);
1.484.2.30 raeburn 1414: }
1415: }
1416: my $buffer;
1417: if ($is_external) {
1418: $buffer = &mt('External Resource').': '.
1419: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1420: &LONCAPA::map::qtescape($url).')';
1.484.2.93.2. (raeburn 1421:): } elsif ($is_exttool) {
1422:): $buffer = &mt('External Tool').': '.
1423:): &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.30 raeburn 1424: } else {
1425: my $icon = &Apache::loncommon::icon($extension);
1426: if ($extension eq 'sequence' &&
1427: $url =~ m{/default_\d+\.sequence$}x) {
1428: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1429: $icon .= '/navmap.folder.closed.gif';
1430: }
1.484.2.57 raeburn 1431: my $title = $env{'docs.markedcopy_title_'.$suffix};
1432: if ($title eq '') {
1433: ($title) = ($url =~ m{/([^/]+)$});
1434: }
1.484.2.30 raeburn 1435: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1436: ': '.
1437: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1438: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1439: }
1440: $pasteitems .= '<div class="LC_left_float">';
1441: my ($options,$onclick);
1442: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1443: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1444: if (($is_uploaded_map) ||
1445: ($url =~ /(bulletinboard|smppg)$/) ||
1446: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1447: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1448: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1449: }
1450: }
1451: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1452: if ($nopaste) {
1.484.2.93.2. (raeburn 1453:): $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.484.2.30 raeburn 1454: } else {
1455: if ($othercrs) {
1456: $pasteitems .= $othercrs;
1457: }
1458: if ($options) {
1459: $pasteitems .= $options;
1.484.2.7 raeburn 1460: }
1461: }
1.484.2.30 raeburn 1462: $pasteitems .= '</div>';
1463: }
1464: }
1465: if ($pasteitems eq '') {
1466: &Apache::lonnet::delenv('docs.markedcopies');
1467: }
1468: my ($pasteform,$form_start,$buttons,$form_end);
1469: if ($pasteitems) {
1470: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1471: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1472: if (@pasteable) {
1.484.2.47 raeburn 1473: my $value = &mt('Paste to current folder');
1474: if ($container eq 'page') {
1475: $value = &mt('Paste to current page');
1476: }
1477: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1478: }
1.484.2.93.2. (raeburn 1479:): $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1.484.2.47 raeburn 1480: if ($clipboardcount > 1) {
1481: $buttons .=
1482: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1483: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1484: (' 'x2).
1485: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1486: (' 'x2);
1.484.2.7 raeburn 1487: }
1.484.2.48 raeburn 1488: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1489: '</form>';
1.484.2.30 raeburn 1490: } else {
1491: $pasteitems = &mt('Clipboard is empty');
1492: }
1493: $r->print($form_start
1494: .'<fieldset>'
1495: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1496: .$pasteitems
1497: .'</fieldset>'
1498: .$form_end);
1499: }
1500:
1501: sub paste_options {
1502: my ($suffix,$is_uploaded_map,$parent) = @_;
1503: my ($copytext,$movetext);
1504: if ($is_uploaded_map) {
1505: $copytext = &mt('Copy to new folder');
1506: $movetext = &mt('Move old');
1507: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1508: $copytext = &mt('Copy to new board');
1509: $movetext = &mt('Move (not posts)');
1510: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1511: $copytext = &mt('Copy to new page');
1512: $movetext = &mt('Move');
1.484.2.7 raeburn 1513: } else {
1.484.2.30 raeburn 1514: $copytext = &mt('Copy to new file');
1515: $movetext = &mt('Move');
1516: }
1517: my $output = '<br />'.
1518: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1519: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1520: '<label>'.
1521: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1522: $copytext.'</label></span>'.(' 'x2).' '.
1523: '<span class="LC_nobreak"><label>'.
1524: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1525: $movetext.'</label></span>';
1526: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1527: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1528: '</legend><table border="0">';
1529: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1530: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1531: my $lastdir = $parent;
1532: my %depths = (
1533: $lastdir => 0,
1534: );
1535: my (%display,%deps);
1536: for (my $i=0; $i<@pastemaps; $i++) {
1537: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1538: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1539: my @subfolders = split(/,/,$subfolderstr);
1540: $deps{$lastdir} = \@subfolders;
1541: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1542: my $depth = $depths{$lastdir} + 1;
1543: my $offset = int($depth * 4);
1544: my $indent = (' ' x $offset);
1545: for (my $j=0; $j<@subfolders; $j++) {
1546: $depths{$subfolders[$j]} = $depth;
1547: $display{$subfolders[$j]} =
1548: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1549: '<td><label>'.
1550: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1551: '<label>'.
1552: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1553: &mt('Move old').'</label>'.
1554: '</td></tr>';
1555: }
1556: }
1557: &recurse_print(\$output,$parent,\%deps,\%display);
1558: $output .= '</table></fieldset>';
1.329 droeschl 1559: }
1.484.2.30 raeburn 1560: $output .= '</div>';
1561: return $output;
1.329 droeschl 1562: }
1563:
1.484.2.7 raeburn 1564: sub recurse_print {
1.484.2.30 raeburn 1565: my ($outputref,$dir,$deps,$display) = @_;
1566: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1567: if (ref($deps->{$dir}) eq 'ARRAY') {
1568: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1569: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1570: }
1571: }
1572: }
1573:
1574: sub supp_pasteable {
1575: my ($url) = @_;
1576: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1577: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1578: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1579: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.484.2.93.2. (raeburn 1580:): ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1581:): ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.484.2.7 raeburn 1582: return 1;
1583: }
1584: return;
1585: }
1586:
1587: sub paste_popup_js {
1.484.2.61 raeburn 1588: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1589: show => 'Show Options',
1590: hide => 'Hide Options',
1.484.2.61 raeburn 1591: );
1592: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1593: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1594: );
1.484.2.61 raeburn 1595: &html_escape(\%html_js_lt);
1596: &js_escape(\%html_js_lt);
1597: &js_escape(\%js_lt);
1.484.2.7 raeburn 1598: return <<"END";
1599:
1.484.2.30 raeburn 1600: function showPasteOptions(suffix) {
1601: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1602: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1603: return;
1604: }
1605:
1.484.2.30 raeburn 1606: function hidePasteOptions(suffix) {
1607: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1608: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1609: return;
1610: }
1611:
1.484.2.30 raeburn 1612: function showOptions(caller,suffix) {
1613: if (document.getElementById('pasteoptionstext_'+suffix)) {
1614: if (caller.checked) {
1.484.2.61 raeburn 1615: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1616: } else {
1617: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1618: }
1619: if (document.getElementById('pasteoptions_'+suffix)) {
1620: document.getElementById('pasteoptions_'+suffix).style.display='none';
1621: }
1622: }
1623: return;
1624: }
1.484.2.7 raeburn 1625:
1.484.2.30 raeburn 1626: function validateClipboard() {
1627: var numchk = 0;
1628: if (document.pasteform.pasting.length > 1) {
1629: for (var i=0; i<document.pasteform.pasting.length; i++) {
1630: if (document.pasteform.pasting[i].checked) {
1631: numchk ++;
1632: }
1633: }
1634: } else {
1635: if (document.pasteform.pasting.type == 'checkbox') {
1636: if (document.pasteform.pasting.checked) {
1637: numchk ++;
1638: }
1639: }
1640: }
1641: if (numchk > 0) {
1642: return true;
1643: } else {
1.484.2.61 raeburn 1644: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1645: return false;
1646: }
1.484.2.7 raeburn 1647: }
1648:
1.484.2.47 raeburn 1649: function checkClipboard() {
1650: if (document.pasteform.pasting.length > 1) {
1651: for (var i=0; i<document.pasteform.pasting.length; i++) {
1652: document.pasteform.pasting[i].checked = true;
1653: }
1654: }
1655: return;
1656: }
1657:
1658: function uncheckClipboard() {
1659: if (document.pasteform.pasting.length >1) {
1660: for (var i=0; i<document.pasteform.pasting.length; i++) {
1661: document.pasteform.pasting[i].checked = false;
1662: }
1663: }
1664: return;
1665: }
1666:
1.484.2.30 raeburn 1667: END
1668:
1669: }
1.484.2.7 raeburn 1670:
1.329 droeschl 1671: sub do_paste_from_buffer {
1.484.2.7 raeburn 1672: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1673:
1.484.2.30 raeburn 1674: # Array of items in paste buffer
1675: my (@currpaste,%pastebuffer,%allerrors);
1676: @currpaste = split(/,/,$env{'docs.markedcopies'});
1677:
1.484.2.7 raeburn 1678: # Early out if paste buffer is empty
1.484.2.30 raeburn 1679: if (@currpaste == 0) {
1.484.2.7 raeburn 1680: return ();
1.484.2.30 raeburn 1681: }
1682: map { $pastebuffer{$_} = 1; } @currpaste;
1683:
1684: # Array of items selected items to paste
1685: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1686:
1687: # Early out if nothing selected to paste
1688: if (@reqpaste == 0) {
1689: return();
1690: }
1691: my @topaste;
1692: foreach my $suffix (@reqpaste) {
1693: next if ($suffix =~ /\D/);
1694: next unless (exists($pastebuffer{$suffix}));
1695: push(@topaste,$suffix);
1.484.2.7 raeburn 1696: }
1697:
1.484.2.30 raeburn 1698: # Early out if nothing available to paste
1699: if (@topaste == 0) {
1700: return();
1.329 droeschl 1701: }
1702:
1.484.2.93.2. (raeburn 1703:): my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.484.2.82 raeburn 1704: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1705:
1.484.2.30 raeburn 1706: foreach my $suffix (@topaste) {
1707: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1708: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1709: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1710: # Supplemental content may only include certain types of content
1711: # Early out if pasted content is not supported in Supplemental area
1712: if ($folder =~ /^supplemental/) {
1713: unless (&supp_pasteable($url)) {
1714: $notinsupp{$suffix} = 1;
1715: next;
1716: }
1717: }
1718: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1719: my $srcd = $1;
1720: my $srcn = $2;
1.484.2.7 raeburn 1721: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1722: # check for mdc privilege in the course from which the resource was pasted
1723: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1724: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1725: $notincrs{$suffix} = 1;
1726: next;
1727: }
1.329 droeschl 1728: }
1.484.2.30 raeburn 1729: $srcdom{$suffix} = $srcd;
1730: $srcnum{$suffix} = $srcn;
1.484.2.93.2. (raeburn 1731:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1732:): my ($srcd,$srcn) = split(/_/,$cid);
1733:): # When paste buffer was populated using an active role in a different course
1734:): # check for mdc privilege in the course from which the resource was pasted
1735:): if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1736:): unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1737:): $notincrs{$suffix} = 1;
1738:): next;
1739:): }
1740:): }
1741:): # When buffer was populated using an active role in a different course
1742:): # disallow pasting of External Tool if course is in a different domain.
1743:): if ($srcd ne $coursedom) {
1744:): $notindom{$suffix} = 1;
1745:): next;
1746:): }
1747:): $srcdom{$suffix} = $srcd;
1748:): $srcnum{$suffix} = $srcn;
1.484.2.82 raeburn 1749: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1750: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1751: my ($srcd,$srcn) = split(/_/,$cid);
1752: # When paste buffer was populated using an active role in a different course
1753: # check for mdc privilege in the course from which the resource was pasted
1754: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1755: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1756: $notincrs{$suffix} = 1;
1757: next;
1758: }
1759: }
1760: $srcdom{$suffix} = $srcd;
1761: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1762: }
1.484.2.82 raeburn 1763: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1764: push(@dopaste,$suffix);
1765: if ($url=~/\.(page|sequence)$/) {
1766: $is_map{$suffix} = 1;
1.329 droeschl 1767: }
1.484.2.30 raeburn 1768:
1769: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1770: my $oldprefix = $1;
1.484.2.19 raeburn 1771: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1772: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1773: # a folder/page or a document).
1.484.2.30 raeburn 1774: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1775: $prefixchg{$suffix} = 'docstosupp';
1776: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1777: $prefixchg{$suffix} = 'supptodocs';
1778: }
1.484.2.7 raeburn 1779:
1780: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1781: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1782: my @nested;
1783: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1784: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1785: my @deps = map { /\d+:([\d,]+$)/ } @items;
1786: foreach my $dep (@deps) {
1787: if ($dep =~ /,/) {
1788: push(@nested,split(/,/,$dep));
1789: } else {
1790: push(@nested,$dep);
1791: }
1.484.2.7 raeburn 1792: }
1.484.2.30 raeburn 1793: foreach my $item (@nested) {
1794: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1795: push(@{$marktomove{$suffix}},$type.'_'.$item);
1796: }
1.484.2.7 raeburn 1797: }
1798: }
1.329 droeschl 1799: }
1.484.2.7 raeburn 1800: }
1801:
1.484.2.30 raeburn 1802: # Early out if nothing available to paste
1803: if (@dopaste == 0) {
1804: return ();
1805: }
1806:
1807: # Populate message hash and hashes used for main content <=> supplemental content
1808: # changes
1809:
1810: %msgs = &Apache::lonlocal::texthash (
1811: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1812: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.484.2.93.2. (raeburn 1813:): notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.484.2.30 raeburn 1814: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1815: );
1816:
1817: %before = (
1818: docstosupp => {
1819: map => 'default',
1820: doc => 'docs',
1821: },
1822: supptodocs => {
1823: map => 'supplemental',
1824: doc => 'supplemental',
1825: },
1826: );
1827:
1828: %after = (
1829: docstosupp => {
1830: map => 'supplemental',
1831: doc => 'supplemental'
1832: },
1833: supptodocs => {
1834: map => 'default',
1835: doc => 'docs',
1836: },
1837: );
1838:
1839: # Retrieve information about all course maps in main content area
1840:
1841: my $allmaps = {};
1.484.2.79 raeburn 1842: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1843:
1844: # Loop over the items to paste
1845: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1846: # Maps need to be copied first
1.484.2.30 raeburn 1847: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1848: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1849: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1850: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1851: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1852: }
1853: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1854: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1855: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1856: my $oldurl = $url;
1857: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1858: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1859: my (%hierarchy,%titles);
1.484.2.79 raeburn 1860: if (($folder =~ /^default/) && (!$donechk)) {
1861: $allmaps =
1862: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1863: $env{"course.$env{'request.course.id'}.home"},
1864: $env{'request.course.id'});
1865: $donechk = 1;
1866: }
1.484.2.93.2. (raeburn 1867:): &contained_map_check($url,$folder,$coursenum,$coursedom,
1868:): \%removefrommap,\%removeparam,\%addedmaps,
1869:): \%hierarchy,\%titles,$allmaps);
1.484.2.30 raeburn 1870: if ($url=~ m{^/uploaded/}) {
1871: my $newurl;
1872: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1873: ($newurl,my $error) =
1874: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1875: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1876: \$title,$allmaps,\%newurls);
1877: if ($error) {
1878: $allerrors{$suffix} = $error;
1879: next;
1880: }
1881: if ($newurl ne '') {
1882: if ($newurl ne $url) {
1883: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1884: $newsubdir{$url} = $1;
1885: }
1886: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1887: }
1888: }
1889: }
1.484.2.30 raeburn 1890: if (($srcdom{$suffix} ne $coursedom) ||
1891: ($srcnum{$suffix} ne $coursenum) ||
1892: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1893: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1894: $coursedom,$coursenum,$srcdom{$suffix},
1895: $srcnum{$suffix},$allmaps,\%rewrites,
1896: \%retitles,\%copies,\%dbcopies,
1897: \%zombies,\%params,\%mapmoves,
1898: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 1899: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 1900: $mapmoves{$url} = 1;
1901: }
1902: $url = $newurl;
1903: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1904: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1905: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1906: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1907: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 1908: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 1909: }
1910: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 1911: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1912: push(@toclear,$suffix);
1913: # if pasting published map (main content area only) check map not already in course
1914: if ($folder =~ /^default/) {
1915: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1916: $duplicate{$suffix} = 1;
1917: next;
1918: }
1.484.2.7 raeburn 1919: }
1920: }
1921: }
1.484.2.93.2. (raeburn 1922:): if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.484.2.30 raeburn 1923: my $prefix = $1;
1.484.2.76 raeburn 1924: my $fromothercrs;
1.484.2.30 raeburn 1925: #need to copy the db contents to a new one, unless this is a move.
1926: my %info = (
1927: src => $url,
1928: cdom => $coursedom,
1929: cnum => $coursenum,
1.484.2.76 raeburn 1930: );
1931: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1932: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1933: $fromothercrs = 1;
1934: $info{'cdom'} = $srcdom{$suffix};
1935: $info{'cnum'} = $srcnum{$suffix};
1936: }
1937: }
1938: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1939: my (%lockerr,$msg);
1940: my ($newurl,$result,$errtext) =
1941: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1942: if ($result eq 'ok') {
1943: $url = $newurl;
1944: $title=&mt('Copy of').' '.$title;
1945: } else {
1946: if ($prefix eq 'smppg') {
1947: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1948: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1949: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.93.2. (raeburn 1950:): } elsif ($prefix eq 'ext.tool') {
1951:): $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.484.2.30 raeburn 1952: }
1953: $results{$suffix} = $result;
1954: $msgerrs{$suffix} = $msg;
1955: $lockerrs{$suffix} = $lockerr{$prefix};
1956: next;
1957: }
1958: if ($lockerr{$prefix}) {
1959: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1960: }
1.484.2.7 raeburn 1961: }
1.484.2.30 raeburn 1962: }
1963: $title = &LONCAPA::map::qtunescape($title);
1964: my $ext='false';
1965: if ($url=~m{^http(|s)://}) { $ext='true'; }
1966: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1967: if ($folder !~ /^supplemental/) {
1968: (undef,undef,$title) =
1969: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1970: }
1971: } else {
1972: if ($folder=~/^supplemental/) {
1973: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1974: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1975: }
1976: }
1.484.2.7 raeburn 1977:
1978: # For uploaded files (excluding pages/sequences) path in copied file is changed
1979: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1980: # courses.
1981:
1.484.2.30 raeburn 1982: unless ($is_map{$suffix}) {
1983: my $newidx;
1.329 droeschl 1984: # Now insert the URL at the bottom
1.484.2.30 raeburn 1985: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1986: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1987: my $relpath = $1;
1988: if ($relpath ne '') {
1989: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1990: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1991: my $newprefix = $newloc;
1992: if ($newloc eq 'default') {
1993: $newprefix = 'docs';
1994: }
1995: if ($newdocsdir eq '') {
1996: $newdocsdir = 'default';
1997: }
1998: if (($prefixchg{$suffix}) ||
1999: ($srcdom{$suffix} ne $coursedom) ||
2000: ($srcnum{$suffix} ne $coursenum) ||
2001: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2002: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2003: $url =
2004: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2005: &Apache::lonnet::getfile($oldurl));
2006: if ($url eq '/adm/notfound.html') {
2007: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2008: next;
2009: } else {
2010: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2011: $newsubpath =~ s{/+$}{/};
2012: $docmoves{$oldurl} = $newsubpath;
2013: }
1.484.2.7 raeburn 2014: }
2015: }
1.484.2.82 raeburn 2016: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2017: my $template = $1;
2018: if ($newidx) {
2019: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2020: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2021: }
1.484.2.7 raeburn 2022: }
1.484.2.30 raeburn 2023: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2024: ':'.$ext.':normal:res';
2025: push(@LONCAPA::map::order,$newidx);
2026: # Store the result
2027: my ($errtext,$fatal) =
2028: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2029: if ($fatal) {
2030: $save_err .= $errtext;
2031: $allresult = 'fail';
1.484.2.7 raeburn 2032: }
1.329 droeschl 2033: }
1.484.2.30 raeburn 2034:
1.484.2.82 raeburn 2035: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2036: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 2037: unless ($allresult eq 'fail') {
2038: my %updated = (
2039: rewrites => \%rewrites,
2040: zombies => \%zombies,
2041: removefrommap => \%removefrommap,
2042: removeparam => \%removeparam,
2043: dbcopies => \%dbcopies,
1.484.2.82 raeburn 2044: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 2045: retitles => \%retitles,
2046: );
2047: my %info = (
2048: newsubdir => \%newsubdir,
2049: params => \%params,
2050: );
2051: if ($prefixchg{$suffix}) {
2052: $info{'before'} = $before{$prefixchg{$suffix}};
2053: $info{'after'} = $after{$prefixchg{$suffix}};
2054: }
2055: my %moves = (
2056: copies => \%copies,
2057: docmoves => \%docmoves,
2058: mapmoves => \%mapmoves,
2059: );
2060: (my $result,$msgs{$suffix},my $lockerror) =
2061: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2062: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2063: $url,'paste');
2064: $lockerrors .= $lockerror;
2065: if ($result eq 'ok') {
2066: if ($is_map{$suffix}) {
2067: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2068: $folder.'.'.$container);
2069: if ($fatal) {
2070: $allresult = 'failread';
2071: } else {
2072: if ($#LONCAPA::map::order<1) {
2073: my $idx=&LONCAPA::map::getresidx();
2074: if ($idx<=0) { $idx=1; }
2075: $LONCAPA::map::order[0]=$idx;
2076: $LONCAPA::map::resources[$idx]='';
2077: }
2078: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2079: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2080: ':'.$ext.':normal:res';
2081: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 2082:
2083: # Store the result
1.484.2.30 raeburn 2084: my ($errtext,$fatal) =
2085: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2086: if ($fatal) {
2087: $save_err .= $errtext;
2088: $allresult = 'failstore';
2089: }
2090: }
2091: }
2092: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2093: push(@toclear,$suffix);
2094: }
2095: }
1.329 droeschl 2096: }
2097: }
1.484.2.30 raeburn 2098: &clear_from_buffer(\@toclear,\@currpaste);
2099: my $msgsarray;
2100: foreach my $suffix (keys(%msgs)) {
2101: if (ref($msgs{$suffix}) eq 'ARRAY') {
2102: $msgsarray .= join(',',@{$msgs{$suffix}});
2103: }
2104: }
2105: return ($allresult,$save_err,$msgsarray,$lockerrors);
2106: }
2107:
2108: sub do_buffer_empty {
2109: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2110: if (@currpaste == 0) {
2111: return &mt('Clipboard is already empty');
2112: }
2113: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2114: if (@toclear == 0) {
2115: return &mt('Nothing selected to clear from clipboard');
2116: }
2117: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2118: if ($numdel) {
2119: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2120: } else {
2121: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 2122: }
1.484.2.30 raeburn 2123: return;
2124: }
2125:
2126: sub clear_from_buffer {
2127: my ($toclear,$currpaste) = @_;
2128: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2129: my %pastebuffer;
2130: map { $pastebuffer{$_} = 1; } @{$currpaste};
2131: my $numdel = 0;
2132: foreach my $suffix (@{$toclear}) {
2133: next if ($suffix =~ /\D/);
2134: next unless (exists($pastebuffer{$suffix}));
2135: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2136: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2137: delete($pastebuffer{$suffix});
2138: $numdel ++;
2139: }
2140: }
2141: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2142: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2143: return $numdel;
1.484.2.7 raeburn 2144: }
2145:
2146: sub get_newmap_url {
2147: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2148: $titleref,$allmaps,$newurls) = @_;
2149: my $newurl;
2150: if ($url=~ m{^/uploaded/}) {
2151: $$titleref=&mt('Copy of').' '.$$titleref;
2152: }
2153: my $now = time;
2154: my $suffix=$$.int(rand(100)).$now;
2155: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2156: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2157: my $path = $1;
2158: my $prefix = $2;
2159: my $ancestor = $3;
2160: if (length($ancestor) > 10) {
2161: $ancestor = substr($ancestor,-10,10);
2162: }
2163: my $newid;
2164: if ($prefixchg) {
2165: if ($folder =~ /^supplemental/) {
2166: $prefix =~ s/^default/supplemental/;
2167: } else {
2168: $prefix =~ s/^supplemental/default/;
2169: }
2170: }
2171: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2172: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2173: } else {
2174: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2175: }
2176: my $counter = 0;
2177: my $is_unique = &uniqueness_check($newurl);
2178: if ($folder =~ /^default/) {
2179: if ($allmaps->{$newurl}) {
2180: $is_unique = 0;
2181: }
2182: }
2183: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2184: $counter ++;
2185: $suffix ++;
2186: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2187: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2188: } else {
2189: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2190: }
2191: $is_unique = &uniqueness_check($newurl);
2192: }
2193: if ($is_unique) {
2194: $newurls->{$newurl} = 1;
2195: } else {
2196: if ($url=~/\.page$/) {
2197: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2198: } else {
2199: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2200: }
2201: }
2202: }
2203: return ($newurl);
2204: }
2205:
2206: sub dbcopy {
1.484.2.26 raeburn 2207: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2208: my ($url,$result,$errtext);
2209: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2210: $url = $dbref->{'src'};
1.484.2.93.2. (raeburn 2211:): if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.484.2.26 raeburn 2212: my $prefix = $1;
1.484.2.93.2. (raeburn 2213:): if ($prefix eq 'ext.tool') {
2214:): $prefix = 'exttool';
2215:): }
1.484.2.26 raeburn 2216: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2217: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2218: my $db_name;
2219: my $marker = (split(m{/},$url))[4];
2220: $marker=~s/\D//g;
2221: if ($dbref->{'src'} =~ m{/smppg$}) {
2222: $db_name =
2223: &Apache::lonsimplepage::get_db_name($url,$marker,
2224: $dbref->{'cdom'},
2225: $dbref->{'cnum'});
1.484.2.93.2. (raeburn 2226:): } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2227:): $db_name = 'exttool_'.$marker;
1.484.2.26 raeburn 2228: } else {
2229: $db_name = 'bulletinpage_'.$marker;
2230: }
2231: my ($suffix,$freedlock,$error) =
2232: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2233: $coursedom,$coursenum,
2234: 'concat');
2235: if (!$suffix) {
2236: if ($prefix eq 'smppg') {
2237: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.484.2.93.2. (raeburn 2238:): } elsif ($prefix eq 'exttool') {
2239:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.484.2.26 raeburn 2240: } else {
1.484.2.42 raeburn 2241: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2242: }
2243: if ($error) {
2244: $errtext .= '<br />'.$error;
2245: }
2246: } else {
2247: #need to copy the db contents to a new one.
2248: my %contents=&Apache::lonnet::dump($db_name,
2249: $dbref->{'cdom'},
2250: $dbref->{'cnum'});
2251: if (exists($contents{'uploaded.photourl'})) {
2252: my $photo = $contents{'uploaded.photourl'};
2253: my ($subdir,$fname) =
2254: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2255: my $newphoto;
2256: if ($fname ne '') {
2257: my $content = &Apache::lonnet::getfile($photo);
2258: unless ($content eq '-1') {
2259: $env{'form.'.$suffix.'.photourl'} = $content;
2260: $newphoto =
2261: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2262: delete($env{'form.'.$suffix.'.photourl'});
2263: }
2264: }
2265: if ($newphoto =~ m{^/uploaded/}) {
2266: $contents{'uploaded.photourl'} = $newphoto;
2267: }
2268: }
2269: $db_name =~ s{_\d*$ }{_$suffix}x;
2270: $result=&Apache::lonnet::put($db_name,\%contents,
2271: $coursedom,$coursenum);
2272: if ($result eq 'ok') {
1.484.2.93.2. (raeburn 2273:): $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.484.2.26 raeburn 2274: }
2275: }
2276: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2277: $lockerrorsref->{$prefix} =
2278: '<div class="LC_error">'.
2279: &mt('There was a problem removing a lockfile.');
2280: if ($prefix eq 'smppg') {
2281: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2282: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.93.2. (raeburn 2283:): } elsif ($prefix eq 'exttool') {
2284:): $lockerrorsref->{$prefix} .=
2285:): ' '.&mt('This will prevent addition of more external tools to this course.');
1.484.2.26 raeburn 2286: } else {
1.484.2.42 raeburn 2287: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2288: }
1.484.2.38 raeburn 2289: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2290: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2291: '</div>';
1.484.2.26 raeburn 2292: }
2293: }
2294: } elsif ($url =~ m{/syllabus$}) {
2295: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2296: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2297: if (($dbref->{'cdom'} ne $coursedom) ||
2298: ($dbref->{'cnum'} ne $coursenum)) {
2299: my %contents=&Apache::lonnet::dump('syllabus',
2300: $dbref->{'cdom'},
2301: $dbref->{'cnum'});
2302: $result=&Apache::lonnet::put('syllabus',\%contents,
2303: $coursedom,$coursenum);
2304: }
2305: }
1.484.2.7 raeburn 2306: }
2307: }
1.484.2.26 raeburn 2308: return ($url,$result,$errtext);
1.329 droeschl 2309: }
2310:
1.484.2.82 raeburn 2311: sub copy_templated_files {
2312: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2313: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2314: my $srccontainer = 'sequence';
2315: if ($srcwaspage) {
2316: $srccontainer = 'page';
2317: }
2318: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2319: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2320: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2321: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2322: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2323: $template.'.problem';
2324: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2325: if ($template eq 'simpleproblem') {
2326: $srcprefix .= '.0.';
2327: my $weightprefix = $newprefix;
2328: $newprefix .= '.0.';
2329: my @simpleprobqtypes = qw(radio option string essay numerical);
2330: my $qtype=$srcparms{$srcprefix.'questiontype'};
2331: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2332: my %newdata = (
2333: $newprefix.'questiontype' => $qtype,
1.484.2.84 raeburn 2334: );
1.484.2.82 raeburn 2335: foreach my $type (@simpleprobqtypes) {
2336: if ($type eq $qtype) {
2337: $newdata{"$weightprefix.$type.weight"}=1;
2338: } else {
2339: $newdata{"$weightprefix.$type.weight"}=0;
2340: }
2341: }
2342: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2343: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2344: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2345: if ($qtype eq 'numerical') {
2346: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2347: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2348: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2349: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2350: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2351: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2352: unless (defined($maxfoils)) { $maxfoils=10; }
2353: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2354: if ($maxfoils<=0) { $maxfoils=10; }
2355: my $randomize=$srcparms{$srcprefix.'randomize'};
2356: unless (defined($randomize)) { $randomize='yes'; }
2357: unless ($randomize eq 'no') { $randomize='yes'; }
2358: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2359: $newdata{$newprefix.'randomize'} = $randomize;
2360: if ($qtype eq 'option') {
2361: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2362: }
2363: for (my $i=1; $i<=10; $i++) {
2364: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2365: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2366: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2367: }
2368:
2369: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2370: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2371: unless (defined($maxfoils)) { $maxfoils=10; }
2372: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2373: if ($maxfoils<=0) { $maxfoils=10; }
2374: my $randomize=$srcparms{$srcprefix.'randomize'};
2375: unless (defined($randomize)) { $randomize='yes'; }
2376: unless ($randomize eq 'no') { $randomize='yes'; }
2377: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2378: $newdata{$newprefix.'randomize'} = $randomize;
2379: if ($qtype eq 'option') {
2380: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2381: }
2382: for (my $i=1; $i<=10; $i++) {
2383: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2384: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2385: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2386: }
2387: } elsif ($qtype eq 'string') {
2388: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2389: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2390: }
2391: if (keys(%newdata)) {
2392: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2393: $coursenum);
2394: if ($putres eq 'ok') {
2395: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2396: }
2397: }
2398: }
2399: }
2400: }
2401:
1.329 droeschl 2402: sub uniqueness_check {
2403: my ($newurl) = @_;
2404: my $unique = 1;
2405: foreach my $res (@LONCAPA::map::order) {
2406: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2407: $url=&LONCAPA::map::qtescape($url);
2408: if ($newurl eq $url) {
2409: $unique = 0;
1.344 bisitz 2410: last;
1.329 droeschl 2411: }
2412: }
2413: return $unique;
2414: }
2415:
1.484.2.7 raeburn 2416: sub contained_map_check {
1.484.2.93.2. (raeburn 2417:): my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2418:): $hierarchy,$titles,$allmaps) = @_;
1.484.2.7 raeburn 2419: my $content = &Apache::lonnet::getfile($url);
2420: unless ($content eq '-1') {
2421: my $parser = HTML::TokeParser->new(\$content);
2422: $parser->attr_encoded(1);
2423: while (my $token = $parser->get_token) {
2424: next if ($token->[0] ne 'S');
2425: if ($token->[1] eq 'resource') {
2426: next if ($token->[2]->{'type'} eq 'zombie');
2427: my $ressrc = $token->[2]->{'src'};
2428: if ($folder =~ /^supplemental/) {
2429: unless (&supp_pasteable($ressrc)) {
2430: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2431: next;
2432: }
2433: }
2434: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2435: if ($1 eq 'uploaded') {
2436: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2437: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2438: } else {
2439: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2440: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2441: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2442: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2443: } else {
2444: $addedmaps->{$ressrc} = [$url];
2445: }
2446: }
1.484.2.93.2. (raeburn 2447:): &contained_map_check($ressrc,$folder,$coursenum,$coursedom,
2448:): $removefrommap,$removeparam,
1.484.2.7 raeburn 2449: $addedmaps,$hierarchy,$titles,$allmaps);
2450: }
2451: } elsif ($token->[1] eq 'param') {
2452: if ($folder =~ /^supplemental/) {
2453: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2454: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2455: } else {
1.484.2.19 raeburn 2456: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2457: }
2458: }
2459: }
2460: }
2461: }
2462: return;
2463: }
2464:
2465: sub url_paste_fixups {
1.484.2.26 raeburn 2466: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2467: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2468: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2469: my $checktitle;
2470: if (($prefixchg) &&
2471: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2472: $checktitle = 1;
2473: }
2474: my $skip;
2475: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2476: my $mapid = $1.$2;
2477: if ($tomove->{$mapid}) {
2478: $skip = 1;
2479: }
2480: }
2481: my $file = &Apache::lonnet::getfile($oldurl);
2482: return if ($file eq '-1');
2483: my $parser = HTML::TokeParser->new(\$file);
2484: $parser->attr_encoded(1);
2485: my $changed = 0;
2486: while (my $token = $parser->get_token) {
2487: next if ($token->[0] ne 'S');
2488: if ($token->[1] eq 'resource') {
2489: my $ressrc = $token->[2]->{'src'};
2490: next if ($ressrc eq '');
2491: my $id = $token->[2]->{'id'};
2492: my $title = $token->[2]->{'title'};
2493: if ($checktitle) {
2494: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2495: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2496: }
2497: }
2498: next if ($token->[2]->{'type'} eq 'external');
2499: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2500: next if ($skip);
1.484.2.25 raeburn 2501: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2502: $changed = 1;
2503: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2504: my $srcdom = $1;
2505: my $srcnum = $2;
2506: my $rem = $3;
2507: my $newurl;
2508: my $mapname;
2509: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2510: my $prefix = $1;
2511: $mapname = $prefix.$2;
2512: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2513: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2514: $srcdom,$srcnum,$allmaps,$rewrites,
2515: $retitles,$copies,$dbcopies,$zombies,
2516: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2517: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2518: next;
2519: } else {
2520: ($newurl,my $error) =
2521: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2522: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2523: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2524: $newsubdir->{$ressrc} = $1;
2525: }
2526: if ($error) {
2527: next;
2528: }
2529: }
2530: }
2531: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2532: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2533:
1.484.2.7 raeburn 2534: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2535: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2536: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2537: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2538: $cnum,$srcdom,$srcnum,$allmaps,
2539: $rewrites,$retitles,$copies,$dbcopies,
2540: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2541: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2542: $mapmoves->{$ressrc} = 1;
2543: }
2544: $changed = 1;
2545: } else {
1.484.2.25 raeburn 2546: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2547: $copies->{$oldurl}{$ressrc} = $id;
2548: $changed = 1;
2549: }
2550: }
1.484.2.26 raeburn 2551: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2552: next if ($skip);
1.484.2.7 raeburn 2553: my $srcdom = $1;
2554: my $srcnum = $2;
2555: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2556: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2557: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2558: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2559: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2560: $changed = 1;
2561: }
2562: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2563: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2564: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2565: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2566: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2567: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2568: $changed = 1;
2569: }
1.484.2.82 raeburn 2570: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2571: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2572: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2573: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2574: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2575: }
1.484.2.7 raeburn 2576: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2577: next if ($skip);
2578: my $srcdom = $1;
2579: my $srcnum = $2;
2580: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2581: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2582: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2583: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2584: $changed = 1;
2585: }
2586: }
2587: } elsif ($token->[1] eq 'param') {
2588: next if ($skip);
1.484.2.19 raeburn 2589: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2590: if ($to ne '') {
2591: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2592: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2593: } else {
2594: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2595: }
2596: }
2597: }
2598: }
2599: return $changed;
2600: }
2601:
2602: sub apply_fixups {
1.484.2.23 raeburn 2603: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2604: $oldurl,$url,$caller) = @_;
2605: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2606: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.82 raeburn 2607: %resdatacopy,%lockerrors,$lockmsg);
1.484.2.23 raeburn 2608: if (ref($updated) eq 'HASH') {
2609: if (ref($updated->{'rewrites'}) eq 'HASH') {
2610: %rewrites = %{$updated->{'rewrites'}};
2611: }
2612: if (ref($updated->{'zombies'}) eq 'HASH') {
2613: %zombies = %{$updated->{'zombies'}};
2614: }
2615: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2616: %removefrommap = %{$updated->{'removefrommap'}};
2617: }
2618: if (ref($updated->{'removeparam'}) eq 'HASH') {
2619: %removeparam = %{$updated->{'removeparam'}};
2620: }
2621: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2622: %dbcopies = %{$updated->{'dbcopies'}};
2623: }
2624: if (ref($updated->{'retitles'}) eq 'HASH') {
2625: %retitles = %{$updated->{'retitles'}};
2626: }
1.484.2.82 raeburn 2627: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2628: %resdatacopy = %{$updated->{'resdatacopy'}};
2629: }
1.484.2.23 raeburn 2630: }
2631: if (ref($info) eq 'HASH') {
2632: if (ref($info->{'newsubdir'}) eq 'HASH') {
2633: %newsubdir = %{$info->{'newsubdir'}};
2634: }
2635: if (ref($info->{'params'}) eq 'HASH') {
2636: %params = %{$info->{'params'}};
2637: }
2638: if (ref($info->{'before'}) eq 'HASH') {
2639: %before = %{$info->{'before'}};
2640: }
2641: if (ref($info->{'after'}) eq 'HASH') {
2642: %after = %{$info->{'after'}};
2643: }
2644: }
2645: if (ref($moves) eq 'HASH') {
2646: if (ref($moves->{'copies'}) eq 'HASH') {
2647: %copies = %{$moves->{'copies'}};
2648: }
2649: if (ref($moves->{'docmoves'}) eq 'HASH') {
2650: %docmoves = %{$moves->{'docmoves'}};
2651: }
2652: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2653: %mapmoves = %{$moves->{'mapmoves'}};
2654: }
2655: }
2656: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2657: my @allcopies;
1.484.2.23 raeburn 2658: if (exists($copies{$key})) {
2659: if (ref($copies{$key}) eq 'HASH') {
2660: my %added;
2661: foreach my $innerkey (keys(%{$copies{$key}})) {
2662: if (($innerkey ne '') && (!$added{$innerkey})) {
2663: push(@allcopies,$innerkey);
2664: $added{$innerkey} = 1;
2665: }
1.484.2.7 raeburn 2666: }
1.484.2.23 raeburn 2667: undef(%added);
1.484.2.7 raeburn 2668: }
2669: }
2670: if ($key eq $oldurl) {
1.484.2.23 raeburn 2671: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2672: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2673: push(@allcopies,$oldurl);
2674: }
2675: }
2676: }
2677: if (@allcopies > 0) {
2678: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2679: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2680: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2681: if ($fname ne '') {
2682: my $content = &Apache::lonnet::getfile($item);
2683: unless ($content eq '-1') {
2684: my $storefn;
1.484.2.23 raeburn 2685: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2686: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2687: } else {
2688: $storefn = $relpath;
2689: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2690: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2691: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2692: }
1.484.2.23 raeburn 2693: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2694: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2695: }
2696: }
2697: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2698: my $copyurl =
1.484.2.7 raeburn 2699: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2700: $storefn.$fname,$content);
2701: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2702: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2703: return &mt('Paste failed: an error occurred copying the file.');
2704: } elsif (ref($errors) eq 'HASH') {
2705: $errors->{$item} = 1;
2706: }
2707: }
2708: }
2709: }
2710: }
2711: }
2712: }
1.484.2.23 raeburn 2713: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2714: my $storefn=$key;
2715: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2716: if ($prefixchg && $before{'map'} && $after{'map'}) {
2717: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2718: }
1.484.2.23 raeburn 2719: if ($newsubdir{$key}) {
2720: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2721: }
2722: my $mapcontent = &Apache::lonnet::getfile($key);
1.484.2.93.2. (raeburn 2723:): if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
2724:): ($after{'map'} eq 'default') &&
2725:): ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
2726:): $mapcontent = '<map>'."\n".
2727:): '<resource id="1" src="" type="start" />'."\n".
2728:): '<link from="1" to="2" index="1" />'."\n".
2729:): '<resource id="2" src="" type="finish" />'."\n".
2730:): '</map>';
2731:): }
1.484.2.7 raeburn 2732: if ($mapcontent eq '-1') {
2733: if (ref($errors) eq 'HASH') {
2734: $errors->{$key} = 1;
2735: }
2736: } else {
2737: my $newmap =
2738: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2739: $mapcontent);
2740: if ($newmap eq '/adm/notfound.html') {
2741: if (ref($errors) eq 'HASH') {
2742: $errors->{$key} = 1;
2743: }
2744: }
2745: }
2746: }
2747: my %updates;
2748: if ($is_map) {
1.484.2.23 raeburn 2749: if (ref($updated) eq 'HASH') {
2750: foreach my $type (keys(%{$updated})) {
2751: if (ref($updated->{$type}) eq 'HASH') {
2752: foreach my $key (keys(%{$updated->{$type}})) {
2753: $updates{$key} = 1;
2754: }
2755: }
2756: }
1.484.2.7 raeburn 2757: }
2758: foreach my $key (keys(%updates)) {
2759: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2760: if (ref($rewrites{$key}) eq 'HASH') {
2761: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2762: }
1.484.2.23 raeburn 2763: if (ref($retitles{$key}) eq 'HASH') {
2764: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2765: }
1.484.2.23 raeburn 2766: if (ref($removefrommap{$key}) eq 'HASH') {
2767: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2768: }
1.484.2.23 raeburn 2769: if (ref($removeparam{$key}) eq 'HASH') {
2770: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2771: }
1.484.2.23 raeburn 2772: if (ref($zombies{$key}) eq 'HASH') {
2773: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2774: }
1.484.2.23 raeburn 2775: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2776: foreach my $idx (keys(%{$dbcopies{$key}})) {
2777: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2778: my ($newurl,$result,$errtext) =
2779: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2780: if ($result eq 'ok') {
2781: $newdb{$idx} = $newurl;
2782: } elsif (ref($errors) eq 'HASH') {
2783: $errors->{$key} = 1;
2784: }
2785: push(@msgs,$errtext);
2786: }
1.484.2.7 raeburn 2787: }
2788: }
1.484.2.82 raeburn 2789: if (ref($resdatacopy{$key}) eq 'HASH') {
2790: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2791: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2792: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2793: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2794: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2795: my $template = $1;
2796: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2797: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2798: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2799: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2800: unless ($gotnewmapname) {
2801: ($newmapname) = ($key =~ m{/([^/]+)$});
2802: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2803: if ($newsubdir{$key}) {
2804: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2805: }
2806: $gotnewmapname = 1;
2807: }
2808: my $srcmapinfo = $srcfolder.':'.$idx;
2809: if ($srccontainer eq 'page') {
2810: $srcmapinfo .= ':1';
2811: }
2812: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2813: $cnum,$template,$idx,$newmapname);
2814: }
2815: }
2816: }
2817: }
2818: }
1.484.2.23 raeburn 2819: if (ref($params{$key}) eq 'HASH') {
2820: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2821: }
2822: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2823: if ($fatal) {
1.484.2.26 raeburn 2824: return ($errtext);
1.484.2.7 raeburn 2825: }
2826: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2827: if (defined($LONCAPA::map::zombies[$i])) {
2828: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2829: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2830: undef($LONCAPA::map::zombies[$i]);
2831: }
2832: }
2833: }
1.484.2.77 raeburn 2834: my $total = scalar(@LONCAPA::map::order) - 1;
2835: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2836: my $idx = $LONCAPA::map::order[$i];
2837: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2838: my $changed;
1.484.2.23 raeburn 2839: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2840: if ((exists($toremove{$idx})) &&
2841: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2842: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2843: if (ref($currparam{$idx}) eq 'ARRAY') {
2844: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2845: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2846: }
2847: }
2848: next;
2849: }
2850: my $origsrc = $src;
1.484.2.25 raeburn 2851: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2852: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2853: $changed = 1;
2854: }
2855: }
1.484.2.25 raeburn 2856: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2857: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2858: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2859: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2860: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2861: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2862: } else {
1.484.2.23 raeburn 2863: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2864: }
2865: }
1.484.2.25 raeburn 2866: if ($origsrc =~ /\.(page|sequence)$/) {
2867: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2868: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2869: }
1.484.2.25 raeburn 2870: } elsif ($newsubdir{$key}) {
2871: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2872: }
2873: }
2874: $changed = 1;
1.484.2.26 raeburn 2875: } elsif ($newdb{$idx} ne '') {
2876: $src = $newdb{$idx};
1.484.2.7 raeburn 2877: $changed = 1;
2878: }
2879: if ($changed) {
1.484.2.30 raeburn 2880: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2881: }
2882: }
2883: }
2884: foreach my $idx (keys(%remparam)) {
2885: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2886: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2887: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2888: }
2889: }
2890: }
1.484.2.26 raeburn 2891: if (values(%lockerrors) > 0) {
2892: $lockmsg = join('<br />',values(%lockerrors));
2893: }
1.484.2.7 raeburn 2894: my $storefn;
2895: if ($key eq $oldurl) {
2896: $storefn = $url;
2897: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2898: } else {
2899: $storefn = $key;
2900: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2901: if ($prefixchg && $before{'map'} && $after{'map'}) {
2902: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2903: }
1.484.2.23 raeburn 2904: if ($newsubdir{$key}) {
2905: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2906: }
2907: }
2908: my $report;
2909: if ($folder !~ /^supplemental/) {
2910: $report = 1;
2911: }
1.484.2.20 raeburn 2912: (my $outtext,$errtext) =
1.484.2.7 raeburn 2913: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2914: if ($errtext) {
1.484.2.23 raeburn 2915: if ($caller eq 'paste') {
1.484.2.26 raeburn 2916: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2917: }
1.484.2.7 raeburn 2918: }
2919: }
2920: }
1.484.2.26 raeburn 2921: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2922: }
2923:
2924: sub copy_dependencies {
2925: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2926: my $content;
2927: if (ref($contentref)) {
2928: $content = $$contentref;
2929: } else {
2930: $content = &Apache::lonnet::getfile($item);
2931: }
2932: unless ($content eq '-1') {
2933: my $mm = new File::MMagic;
2934: my $mimetype = $mm->checktype_contents($content);
2935: if ($mimetype eq 'text/html') {
2936: my (%allfiles,%codebase,$state);
2937: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2938: if ($res eq 'ok') {
2939: my ($numexisting,$numpathchanges,$existing);
2940: (undef,$numexisting,$numpathchanges,$existing) =
2941: &Apache::loncommon::ask_for_embedded_content(
2942: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2943: {'error_on_invalid_names' => 1,
2944: 'ignore_remote_references' => 1,
2945: 'docs_url' => $item,
2946: 'context' => 'paste'});
2947: if ($numexisting > 0) {
2948: if (ref($existing) eq 'HASH') {
2949: foreach my $dep (keys(%{$existing})) {
2950: my $depfile = $dep;
2951: unless ($depfile =~ m{^\Q$relpath\E}) {
2952: $depfile = $relpath.$dep;
2953: }
2954: my $depcontent = &Apache::lonnet::getfile($depfile);
2955: unless ($depcontent eq '-1') {
2956: my $storedep = $dep;
2957: $storedep =~ s{^\Q$relpath\E}{};
2958: my $dep_url =
2959: &Apache::lonclonecourse::writefile(
2960: $env{'request.course.id'},
2961: $storefn.$storedep,$depcontent);
2962: if ($dep_url eq '/adm/notfound.html') {
2963: if (ref($errors) eq 'HASH') {
2964: $errors->{$depfile} = 1;
2965: }
2966: } else {
2967: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2968: }
2969: }
2970: }
2971: }
2972: }
2973: }
2974: }
2975: }
2976: return;
2977: }
2978:
1.329 droeschl 2979: my %parameter_type = ( 'randompick' => 'int_pos',
2980: 'hiddenresource' => 'string_yesno',
2981: 'encrypturl' => 'string_yesno',
2982: 'randomorder' => 'string_yesno',);
2983: my $valid_parameters_re = join('|',keys(%parameter_type));
2984: # set parameters
2985: sub update_parameter {
1.484.2.29 raeburn 2986: if ($env{'form.changeparms'} eq 'all') {
2987: my (@allidx,@allmapidx,%allchecked,%currchecked);
2988: %allchecked = (
2989: 'hiddenresource' => {},
2990: 'encrypturl' => {},
2991: 'randompick' => {},
2992: 'randomorder' => {},
2993: );
2994: foreach my $which (keys(%allchecked)) {
2995: $env{'form.all'.$which} =~ s/,$//;
2996: if ($which eq 'randompick') {
2997: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2998: my ($res,$value) = split(/:/,$item);
2999: if ($value =~ /^\d+$/) {
3000: $allchecked{$which}{$res} = $value;
3001: }
3002: }
3003: } else {
1.484.2.30 raeburn 3004: if ($env{'form.all'.$which}) {
3005: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3006: }
1.484.2.29 raeburn 3007: }
3008: }
3009: my $haschanges = 0;
3010: foreach my $res (@LONCAPA::map::order) {
3011: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3012: $name=&LONCAPA::map::qtescape($name);
3013: $url=&LONCAPA::map::qtescape($url);
1.484.2.93.2. (raeburn 3014:): next unless $url;
1.484.2.29 raeburn 3015: my $is_map;
3016: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3017: $is_map = 1;
3018: }
3019: foreach my $which (keys(%allchecked)) {
3020: if (($which eq 'randompick' || $which eq 'randomorder')) {
3021: next if (!$is_map);
3022: }
3023: my $oldvalue = 0;
3024: my $newvalue = 0;
3025: if ($allchecked{$which}{$res}) {
3026: $newvalue = $allchecked{$which}{$res};
3027: }
3028: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3029: if ($which eq 'randompick') {
3030: if ($current =~ /^(\d+)$/) {
3031: $oldvalue = $1;
3032: }
3033: } else {
3034: if ($current =~ /^yes$/i) {
3035: $oldvalue = 1;
3036: }
3037: }
3038: if ($oldvalue ne $newvalue) {
3039: $haschanges = 1;
3040: if ($newvalue) {
3041: my $storeval = 'yes';
3042: if ($which eq 'randompick') {
3043: $storeval = $newvalue;
3044: }
3045: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3046: $storeval,
3047: $parameter_type{$which});
3048: &remember_parms($res,$which,'set',$storeval);
3049: } elsif ($oldvalue) {
3050: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3051: &remember_parms($res,$which,'del');
3052: }
3053: }
3054: }
3055: }
3056: return $haschanges;
1.329 droeschl 3057: } else {
1.484.2.59 raeburn 3058: my $haschanges = 0;
3059: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 3060:
1.484.2.29 raeburn 3061: my $which = $env{'form.changeparms'};
3062: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 3063: my $oldvalue = 0;
3064: my $newvalue = 0;
3065: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3066: if ($which eq 'randompick') {
3067: if ($current =~ /^(\d+)$/) {
3068: $oldvalue = $1;
3069: }
3070: } elsif ($current =~ /^yes$/i) {
3071: $oldvalue = 1;
3072: }
1.484.2.29 raeburn 3073: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 3074: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3075: : 1;
1.484.2.29 raeburn 3076: }
1.484.2.59 raeburn 3077: if ($oldvalue ne $newvalue) {
3078: $haschanges = 1;
3079: if ($newvalue) {
3080: my $storeval = 'yes';
3081: if ($which eq 'randompick') {
3082: $storeval = $newvalue;
3083: }
3084: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3085: $parameter_type{$which});
3086: &remember_parms($idx,$which,'set',$storeval);
3087: } else {
3088: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3089: &remember_parms($idx,$which,'del');
3090: }
3091: }
3092: return $haschanges;
1.329 droeschl 3093: }
1.484.2.59 raeburn 3094: return;
1.329 droeschl 3095: }
3096:
3097: sub handle_edit_cmd {
3098: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 3099: if ($env{'form.cmd'} eq '') {
3100: return 0;
3101: }
1.329 droeschl 3102: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3103:
3104: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3105: my ($title, $url, @rrest) = split(':', $ratstr);
3106:
1.484.2.30 raeburn 3107: if ($cmd eq 'remove') {
1.329 droeschl 3108: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3109: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3110: &Apache::lonnet::removeuploadedurl($url);
3111: } else {
3112: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3113: }
3114: splice(@LONCAPA::map::order, $idx, 1);
3115:
3116: } elsif ($cmd eq 'cut') {
3117: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3118: splice(@LONCAPA::map::order, $idx, 1);
3119:
1.344 bisitz 3120: } elsif ($cmd eq 'up'
1.329 droeschl 3121: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3122: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3123:
3124: } elsif ($cmd eq 'down'
3125: && defined($LONCAPA::map::order[$idx+1])) {
3126: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3127:
3128: } elsif ($cmd eq 'rename') {
3129: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3130: if ($comment=~/\S/) {
3131: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3132: $comment.':'.join(':', $url, @rrest);
3133: }
3134: # Devalidate title cache
3135: my $renamed_url=&LONCAPA::map::qtescape($url);
3136: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 3137:
1.329 droeschl 3138: } else {
3139: return 0;
3140: }
3141: return 1;
3142: }
3143:
3144: sub editor {
1.458 raeburn 3145: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.93.2. (raeburn 3146:): $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3147:): $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 3148: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3149: if ($allowed) {
3150: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3151: $is_random_order,$container) =
3152: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3153: $r->print($breadcrumbtrail);
3154: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3155: $container = 'page';
3156: } else {
3157: $container = 'sequence';
3158: }
1.484 raeburn 3159:
1.484.2.21 raeburn 3160: my $jumpto;
3161:
3162: unless ($supplementalflag) {
1.484.2.32 raeburn 3163: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 3164: }
1.484 raeburn 3165:
3166: unless ($allowed) {
3167: $randompick = -1;
3168: }
3169:
1.484.2.67 raeburn 3170: my ($errtext,$fatal);
3171: if (($folder eq '') && (!$supplementalflag)) {
3172: if (@LONCAPA::map::order) {
3173: undef(@LONCAPA::map::order);
3174: undef(@LONCAPA::map::resources);
3175: undef(@LONCAPA::map::resparms);
3176: undef(@LONCAPA::map::zombies);
3177: }
3178: $folder = 'default';
3179: $container = 'sequence';
3180: } else {
3181: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3182: $folder.'.'.$container);
3183: return $errtext if ($fatal);
3184: }
1.329 droeschl 3185:
3186: if ($#LONCAPA::map::order<1) {
3187: my $idx=&LONCAPA::map::getresidx();
3188: if ($idx<=0) { $idx=1; }
3189: $LONCAPA::map::order[0]=$idx;
3190: $LONCAPA::map::resources[$idx]='';
3191: }
1.364 bisitz 3192:
1.329 droeschl 3193: # ------------------------------------------------------------ Process commands
3194:
3195: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 3196: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3197: # set parameters and change order
3198: &snapshotbefore();
3199:
3200: if (&update_parameter()) {
1.484.2.59 raeburn 3201: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3202: return $errtext if ($fatal);
3203: }
3204:
3205: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3206: # change order
3207: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3208: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3209:
3210: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3211: return $errtext if ($fatal);
3212: }
1.364 bisitz 3213:
1.329 droeschl 3214: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 3215: my %paste_errors;
1.484.2.26 raeburn 3216: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 3217: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3218: \%paste_errors);
1.484.2.30 raeburn 3219: if (ref($pastemsgarray) eq 'ARRAY') {
3220: if (@{$pastemsgarray} > 0) {
3221: $r->print('<p class="LC_info">'.
3222: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3223: '</p>');
3224: }
1.484.2.30 raeburn 3225: }
3226: if ($lockerror) {
3227: $r->print('<p class="LC_error">'.
3228: $lockerror.
3229: '</p>');
3230: }
3231: if ($save_error ne '') {
3232: return $save_error;
3233: }
3234: if ($paste_res) {
3235: my %errortext = &Apache::lonlocal::texthash (
3236: fail => 'Storage of folder contents failed',
3237: failread => 'Reading folder contents failed',
3238: failstore => 'Storage of folder contents failed',
3239: );
3240: if ($errortext{$paste_res}) {
3241: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3242: }
1.329 droeschl 3243: }
1.484.2.7 raeburn 3244: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3245: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3246: &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".
3247: '<ul>'."\n");
3248: foreach my $key (sort(keys(%paste_errors))) {
3249: $r->print('<li>'.$key.'</li>'."\n");
3250: }
3251: $r->print('</ul></p>'."\n");
3252: }
1.484.2.30 raeburn 3253: } elsif ($env{'form.clearmarked'}) {
3254: my $output = &do_buffer_empty();
3255: if ($output) {
3256: $r->print('<p class="LC_info">'.$output.'</p>');
3257: }
3258: }
1.329 droeschl 3259:
3260: $r->print($upload_output);
3261:
1.484.2.30 raeburn 3262: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3263: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3264: my $contentchg;
1.484.2.58 raeburn 3265: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3266: $contentchg = 1;
3267: }
3268: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3269: return $errtext if ($fatal);
3270: }
1.484.2.30 raeburn 3271:
3272: # Cut, copy and/or remove multiple resources
3273: if ($env{'form.multichange'}) {
3274: my %allchecked = (
3275: cut => {},
3276: remove => {},
3277: );
3278: my $needsupdate;
3279: foreach my $which (keys(%allchecked)) {
3280: $env{'form.multi'.$which} =~ s/,$//;
3281: if ($env{'form.multi'.$which}) {
3282: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3283: if (ref($allchecked{$which}) eq 'HASH') {
3284: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3285: }
3286: }
3287: }
3288: if ($needsupdate) {
3289: my $haschanges = 0;
3290: my %curr_groups = &Apache::longroup::coursegroups();
3291: my $total = scalar(@LONCAPA::map::order) - 1;
3292: for (my $i=$total; $i>=0; $i--) {
3293: my $res = $LONCAPA::map::order[$i];
3294: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3295: $name=&LONCAPA::map::qtescape($name);
3296: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3297: next unless $url;
1.484.2.30 raeburn 3298: my %denied =
3299: &action_restrictions($coursenum,$coursedom,$url,
3300: $env{'form.folderpath'},\%curr_groups);
3301: foreach my $which (keys(%allchecked)) {
3302: next if ($denied{$which});
3303: next unless ($allchecked{$which}{$res});
3304: if ($which eq 'remove') {
3305: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3306: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3307: &Apache::lonnet::removeuploadedurl($url);
3308: } else {
3309: &LONCAPA::map::makezombie($res);
3310: }
3311: splice(@LONCAPA::map::order,$i,1);
3312: $haschanges ++;
3313: } elsif ($which eq 'cut') {
3314: &LONCAPA::map::makezombie($res);
3315: splice(@LONCAPA::map::order,$i,1);
3316: $haschanges ++;
3317: }
3318: }
3319: }
3320: if ($haschanges) {
3321: ($errtext,$fatal) =
3322: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3323: return $errtext if ($fatal);
3324: }
3325: }
3326: }
3327:
1.329 droeschl 3328: # Group import/search
3329: if ($env{'form.importdetail'}) {
3330: my @imports;
3331: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3332: if (defined($item)) {
3333: my ($name,$url,$residx)=
1.484.2.26 raeburn 3334: map { &unescape($_); } split(/\=/,$item);
3335: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3336: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3337: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3338: if ($locknotfreed) {
3339: $r->print($locknotfreed);
3340: }
3341: if ($suffix) {
1.484.2.19 raeburn 3342: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3343: } else {
3344: return $errortxt;
3345: }
1.484.2.26 raeburn 3346: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3347: my $type = $1;
3348: my ($suffix,$errortxt,$locknotfreed) =
3349: &new_timebased_suffix($coursedom,$coursenum,$type);
3350: if ($locknotfreed) {
3351: $r->print($locknotfreed);
3352: }
3353: if ($suffix) {
3354: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3355: } else {
3356: return $errortxt;
3357: }
1.484.2.93.2. (raeburn 3358:): } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3359:): my ($suffix,$errortxt,$locknotfreed) =
3360:): &new_timebased_suffix($coursedom,$coursenum,'exttool');
3361:): if ($locknotfreed) {
3362:): $r->print($locknotfreed);
3363:): }
3364:): if ($suffix) {
3365:): $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3366:): } else {
3367:): return $errortxt;
3368:): }
1.484.2.27 raeburn 3369: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3370: if ($supplementalflag) {
3371: next unless ($1 eq 'supplemental');
3372: if ($folder eq 'supplemental') {
3373: next unless ($2 eq 'default');
3374: } else {
3375: next unless ($folder eq 'supplemental_'.$2);
3376: }
3377: } else {
3378: next unless ($1 eq 'docs');
3379: if ($folder eq 'default') {
3380: next unless ($2 eq 'default');
3381: } else {
3382: next unless ($folder eq 'default_'.$2);
3383: }
3384: }
1.484.2.15 raeburn 3385: }
1.329 droeschl 3386: push(@imports, [$name, $url, $residx]);
3387: }
3388: }
1.484.2.23 raeburn 3389: ($errtext,$fatal,my $fixuperrors) =
3390: &group_import($coursenum, $coursedom, $folder,$container,
1.484.2.93.2. (raeburn 3391:): 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3392: return $errtext if ($fatal);
1.484.2.23 raeburn 3393: if ($fixuperrors) {
3394: $r->print($fixuperrors);
3395: }
1.329 droeschl 3396: }
3397: # Loading a complete map
3398: if ($env{'form.loadmap'}) {
3399: if ($env{'form.importmap'}=~/\w/) {
3400: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3401: my ($title,$url,$ext,$type)=split(/\:/,$res);
3402: my $idx=&LONCAPA::map::getresidx($url);
3403: $LONCAPA::map::resources[$idx]=$res;
3404: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3405: }
3406: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3407: $folder.'.'.$container,1);
1.329 droeschl 3408: return $errtext if ($fatal);
3409: } else {
3410: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3411:
1.329 droeschl 3412: }
3413: }
3414: &log_differences($plain);
3415: }
3416: # ---------------------------------------------------------------- End commands
3417: # ---------------------------------------------------------------- Print screen
3418: my $idx=0;
3419: my $shown=0;
3420: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3421: $r->print('<div class="LC_Box">'.
1.432 raeburn 3422: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3423: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3424: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3425: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3426: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3427: '</ol>');
1.381 bisitz 3428: if ($randompick>=0) {
3429: $r->print('<p class="LC_warning">'
3430: .&mt('Caution: this folder is set to randomly pick a subset'
3431: .' of resources. Adding or removing resources from this'
3432: .' folder will change the set of resources that the'
3433: .' students see, resulting in spurious or missing credit'
3434: .' for completed problems, not limited to ones you'
3435: .' modify. Do not modify the contents of this folder if'
3436: .' it is in active student use.')
3437: .'</p>'
3438: );
3439: }
3440: if ($is_random_order) {
3441: $r->print('<p class="LC_warning">'
3442: .&mt('Caution: this folder is set to randomly order its'
3443: .' contents. Adding or removing resources from this folder'
3444: .' will change the order of resources shown.')
3445: .'</p>'
3446: );
3447: }
3448: $r->print('</div>');
1.364 bisitz 3449: }
1.381 bisitz 3450:
1.484.2.30 raeburn 3451: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3452: %filters = (
3453: canremove => [],
3454: cancut => [],
3455: cancopy => [],
3456: hiddenresource => [],
3457: encrypturl => [],
3458: randomorder => [],
3459: randompick => [],
3460: );
3461: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3462: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3463: foreach my $res (@LONCAPA::map::order) {
3464: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3465: $name=&LONCAPA::map::qtescape($name);
3466: $url=&LONCAPA::map::qtescape($url);
3467: unless ($name) { $name=(split(/\//,$url))[-1]; }
3468: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3469: push(@allidx,$res);
3470: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3471: push(@allmapidx,$res);
3472: }
1.484.2.67 raeburn 3473:
1.381 bisitz 3474: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3475: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3476: $pathitem,$supplementalflag,$container,
1.484.2.93.2. (raeburn 3477:): \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.484.2.80 raeburn 3478: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3479: $idx++;
3480: $shown++;
1.329 droeschl 3481: }
1.424 onken 3482: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3483:
1.484.2.30 raeburn 3484: my $need_save;
1.484.2.67 raeburn 3485: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3486: my $toolslink;
1.484.2.67 raeburn 3487: if ($allowed) {
1.484.2.31 raeburn 3488: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3489: .&Apache::loncommon::help_open_menu('Navigation Screen',
3490: 'Navigation_Screen',undef,'RAT')
3491: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3492: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3493: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3494: .'id="LC_content_toolbar_edittoplevel" '
3495: .'class="LC_toolbarItem" '
3496: .'title="'.&mt('Supplemental Content Editor').'">'
3497: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3498: }
1.484.2.19 raeburn 3499: if ($shown) {
3500: if ($allowed) {
3501: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3502: .&Apache::loncommon::start_data_table(undef,'contentlist')
3503: .&Apache::loncommon::start_data_table_header_row()
3504: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3505: .'<th colspan="2">'.&mt('Actions').'</th>'
3506: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3507: if ($folder !~ /^supplemental/) {
3508: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3509: }
1.484.2.29 raeburn 3510: $to_show .= &Apache::loncommon::end_data_table_header_row();
3511: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3512: $lists{'canhide'} = join(',',@allidx);
3513: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3514: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3515: 'randomorder','randompick');
3516: foreach my $item (@possfilters) {
3517: if (ref($filters{$item}) eq 'ARRAY') {
3518: if (@{$filters{$item}} > 0) {
3519: $lists{$item} = join(',',@{$filters{$item}});
3520: }
3521: }
3522: }
1.484.2.29 raeburn 3523: if (@allidx > 0) {
3524: my $path;
3525: if ($env{'form.folderpath'}) {
3526: $path =
3527: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3528: }
1.484.2.30 raeburn 3529: if (@allidx > 1) {
3530: $to_show .=
3531: &Apache::loncommon::continue_data_table_row().
3532: '<td colspan="2"> </td>'.
3533: '<td>'.
1.484.2.67 raeburn 3534: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3535: '</td>'.
3536: '<td> </td>'.
3537: '<td> </td>'.
3538: '<td colspan="4">'.
1.484.2.67 raeburn 3539: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3540: '</td>'.
3541: &Apache::loncommon::end_data_table_row();
3542: $need_save = 1;
3543: }
1.484.2.29 raeburn 3544: }
3545: }
3546: $to_show .= $output.' '
1.484.2.19 raeburn 3547: .&Apache::loncommon::end_data_table()
3548: .'<br style="line-height:2px;" />'
3549: .&Apache::loncommon::end_scrollbox();
3550: } else {
3551: $to_show .= $toolslink
3552: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3553: .$output.' '
3554: .&Apache::loncommon::end_data_table();
3555: }
3556: } else {
3557: if (!$allowed) {
3558: $to_show .= $toolslink;
1.393 raeburn 3559: }
1.484.2.67 raeburn 3560: my $noresmsg;
3561: if ($allowed && $hiddentop && !$supplementalflag) {
3562: $noresmsg = &mt('Main Content Hidden');
3563: } else {
3564: $noresmsg = &mt('Currently empty');
3565: }
1.484.2.19 raeburn 3566: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3567: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3568: .$noresmsg
1.484.2.19 raeburn 3569: .'</div>'
3570: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3571: }
3572: } else {
1.484.2.19 raeburn 3573: if ($shown) {
3574: $to_show = '<div>'
3575: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3576: .$output
3577: .&Apache::loncommon::end_data_table()
3578: .'</div>';
3579: } else {
3580: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3581: .&mt('Currently empty')
1.484.2.19 raeburn 3582: .'</div>'
3583: }
1.458 raeburn 3584: }
3585: my $tid = 1;
3586: if ($supplementalflag) {
3587: $tid = 2;
1.329 droeschl 3588: }
3589: if ($allowed) {
1.484 raeburn 3590: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3591: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3592: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3593: if ($canedit) {
1.484.2.67 raeburn 3594: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3595: }
1.460 raeburn 3596: } else {
3597: $r->print($to_show);
1.329 droeschl 3598: }
3599: return;
3600: }
3601:
1.484.2.30 raeburn 3602: sub multiple_check_form {
1.484.2.67 raeburn 3603: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3604: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3605: my $disabled;
3606: unless ($canedit) {
3607: $disabled = 'disabled="disabled"';
3608: }
1.484.2.30 raeburn 3609: my $output =
3610: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3611: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3612: '<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>'.
3613: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3614: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3615: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3616: if ($caller eq 'settings') {
3617: $output .=
3618: '<table><tr>'.
3619: '<td class="LC_docs_entry_parameter">'.
3620: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3621: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3622: '</label></span></td>'.
3623: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3624: '<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 3625: '</span></td>'.
3626: '</tr>'."\n".
3627: '<tr>'.
3628: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3629: '<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 3630: '</label></span>'.
3631: '</td></tr></table>'."\n";
3632: } else {
3633: $output .=
3634: '<table><tr>'.
3635: '<td class="LC_docs_entry_parameter">'.
3636: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3637: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3638: '</label></span></td>'.
3639: '<td class="LC_docs_entry_parameter">'.
3640: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3641: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3642: '</label></span></td>'."\n".
3643: '<td class="LC_docs_entry_parameter">'.
3644: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3645: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3646: '</label></span></td>'.
3647: '</tr></table>'."\n";
3648: }
3649: $output .=
3650: '</fieldset>'.
3651: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3652: if ($caller eq 'settings') {
3653: $output .=
3654: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3655: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3656: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3657: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3658: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3659: } elsif ($caller eq 'actions') {
3660: $output .=
3661: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3662: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3663: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3664: }
3665: $output .=
3666: '</form>'.
3667: '</div>';
3668: return $output;
3669: }
3670:
1.329 droeschl 3671: sub process_file_upload {
1.484.2.36 raeburn 3672: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3673: # upload a file, if present
1.484.2.36 raeburn 3674: my $filesize = length($env{'form.uploaddoc'});
3675: if (!$filesize) {
3676: $$upload_output = '<div class="LC_error">'.
3677: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3678: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3679: $filesize).'<br />'.
3680: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3681: '</div>';
3682: return;
3683: }
3684: my $quotatype = 'unofficial';
3685: if ($crstype eq 'Community') {
3686: $quotatype = 'community';
1.484.2.51 raeburn 3687: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3688: $quotatype = 'official';
1.484.2.45 raeburn 3689: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3690: $quotatype = 'textbook';
1.484.2.36 raeburn 3691: }
3692: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3693: $filesize = int($filesize/1000); #expressed in kb
3694: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3695: $env{'form.uploaddoc.filename'},$filesize,
3696: 'upload',$quotatype);
1.484.2.36 raeburn 3697: return if ($$upload_output);
3698: }
1.440 raeburn 3699: my ($parseaction,$showupload,$nextphase,$mimetype);
3700: if ($env{'form.parserflag'}) {
1.329 droeschl 3701: $parseaction = 'parse';
3702: }
3703: my $folder=$env{'form.folder'};
3704: if ($folder eq '') {
3705: $folder='default';
3706: }
3707: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3708: my $errtext='';
3709: my $fatal=0;
3710: my $container='sequence';
1.484.2.19 raeburn 3711: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3712: $container='page';
3713: }
3714: ($errtext,$fatal)=
1.484.2.27 raeburn 3715: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3716: if ($#LONCAPA::map::order<1) {
3717: $LONCAPA::map::order[0]=1;
3718: $LONCAPA::map::resources[1]='';
3719: }
3720: my $destination = 'docs/';
3721: if ($folder =~ /^supplemental/) {
3722: $destination = 'supplemental/';
3723: }
3724: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3725: $destination .= 'default/';
3726: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3727: $destination .= $2.'/';
3728: }
1.484.2.27 raeburn 3729: if ($fatal) {
3730: $$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>';
3731: return;
3732: }
1.440 raeburn 3733: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3734: my $newidx=&LONCAPA::map::getresidx();
3735: $destination .= $newidx;
1.439 raeburn 3736: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3737: $parseaction,$allfiles,
1.440 raeburn 3738: $codebase,undef,undef,undef,undef,
3739: undef,undef,\$mimetype);
3740: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3741: my $stored = $1;
3742: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3743: $stored.'</span>').'</p>';
3744: } else {
3745: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3746:
1.457 raeburn 3747: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3748: return;
3749: }
1.329 droeschl 3750: my $ext='false';
3751: if ($url=~m{^http://}) { $ext='true'; }
3752: $url = &LONCAPA::map::qtunescape($url);
3753: my $comment=$env{'form.comment'};
3754: $comment = &LONCAPA::map::qtunescape($comment);
3755: if ($folder=~/^supplemental/) {
3756: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3757: $env{'user.domain'}.'___&&&___'.$comment;
3758: }
3759:
3760: $LONCAPA::map::resources[$newidx]=
3761: $comment.':'.$url.':'.$ext.':normal:res';
3762: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3763: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3764: $folder.'.'.$container,1);
1.329 droeschl 3765: if ($fatal) {
1.457 raeburn 3766: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3767: return;
1.329 droeschl 3768: } else {
1.440 raeburn 3769: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3770: $$upload_output = $showupload;
1.384 raeburn 3771: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3772: if ($total_embedded > 0) {
1.440 raeburn 3773: my $uploadphase = 'upload_embedded';
3774: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3775: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3776: my ($embedded,$num) =
3777: &Apache::loncommon::ask_for_embedded_content(
3778: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3779: if ($embedded) {
3780: if ($num) {
3781: $$upload_output .=
3782: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3783: $nextphase = $uploadphase;
3784: } else {
3785: $$upload_output .= $embedded;
3786: }
3787: } else {
3788: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3789: }
1.329 droeschl 3790: } else {
1.440 raeburn 3791: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3792: }
1.457 raeburn 3793: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3794: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3795: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3796: $nextphase = 'decompress_uploaded';
3797: my $position = scalar(@LONCAPA::map::order)-1;
3798: my $noextract = &return_to_editor();
3799: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3800: my %archiveitems = (
3801: folderpath => $env{'form.folderpath'},
3802: cmd => $nextphase,
3803: newidx => $newidx,
3804: position => $position,
3805: phase => $nextphase,
1.477 raeburn 3806: comment => $comment,
1.480 raeburn 3807: );
3808: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3809: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3810: $$upload_output = $showupload.
3811: &Apache::loncommon::decompress_form($mimetype,
3812: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3813: \%archiveitems,\@current);
1.329 droeschl 3814: }
3815: }
3816: }
1.440 raeburn 3817: return $nextphase;
1.329 droeschl 3818: }
3819:
1.480 raeburn 3820: sub get_dir_list {
3821: my ($url,$coursenum,$coursedom,$newidx) = @_;
3822: my ($destination,$dir_root) = &embedded_destination();
3823: my ($dirlistref,$listerror) =
3824: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3825: my @dir_lines;
3826: my $dirptr=16384;
3827: if (ref($dirlistref) eq 'ARRAY') {
3828: foreach my $dir_line (sort
3829: {
3830: my ($afile)=split('&',$a,2);
3831: my ($bfile)=split('&',$b,2);
3832: return (lc($afile) cmp lc($bfile));
3833: } (@{$dirlistref})) {
3834: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3835: $filename =~ s/\s+$//;
3836: next if ($filename =~ /^\.\.?$/);
3837: my $isdir = 0;
3838: if ($dirptr&$testdir) {
3839: $isdir = 1;
3840: }
3841: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3842: }
3843: }
3844: return @dir_lines;
3845: }
3846:
1.329 droeschl 3847: sub is_supplemental_title {
3848: my ($title) = @_;
3849: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3850: }
3851:
3852: # --------------------------------------------------------------- An entry line
3853:
3854: sub entryline {
1.484.2.12 raeburn 3855: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3856: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.93.2. (raeburn 3857:): $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.484.2.52 raeburn 3858: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3859: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3860: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3861: } else {
3862: $title=&HTML::Entities::encode($title,'"<>&\'');
3863: $renametitle=$title;
3864: $foldertitle=$title;
3865: }
3866:
1.484.2.67 raeburn 3867: my ($disabled,$readonly,$js_lt);
3868: unless ($canedit) {
3869: $disabled = 'disabled="disabled"';
3870: $readonly = 1;
3871: }
3872:
1.329 droeschl 3873: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3874:
1.329 droeschl 3875: $renametitle=~s/\\/\\\\/g;
3876: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3877: $renametitle=~s/"/%22/g;
1.329 droeschl 3878: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3879: $oldtitle = $renametitle;
3880: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3881: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3882: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3883: # Edit commands
1.484.2.93.2. (raeburn 3884:): my ($esc_path, $path, $symb, $shownsymb);
1.329 droeschl 3885: if ($env{'form.folderpath'}) {
3886: $esc_path=&escape($env{'form.folderpath'});
3887: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3888: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3889: }
1.484.2.16 raeburn 3890: my $isexternal;
1.484.2.19 raeburn 3891: if ($residx) {
1.484.2.12 raeburn 3892: my $currurl = $url;
3893: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3894: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3895: $isexternal = 1;
3896: }
1.484.2.19 raeburn 3897: if (!$supplementalflag) {
3898: my $path = 'uploaded/'.
3899: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3900: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3901: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3902: $residx,
3903: &Apache::lonnet::declutter($currurl));
3904: }
1.484.2.12 raeburn 3905: }
1.484.2.30 raeburn 3906: my ($renamelink,%lt,$ishash);
3907: if (ref($filtersref) eq 'HASH') {
3908: $ishash = 1;
3909: }
3910:
1.329 droeschl 3911: if ($allowed) {
1.484.2.30 raeburn 3912: $form_start = '
3913: <form action="/adm/coursedocs" method="post">
3914: ';
3915: $form_common=(<<END);
3916: <input type="hidden" name="folderpath" value="$path" />
3917: <input type="hidden" name="symb" value="$symb" />
3918: END
3919: $form_param=(<<END);
3920: <input type="hidden" name="setparms" value="$orderidx" />
3921: <input type="hidden" name="changeparms" value="0" />
3922: END
3923: $form_end = '</form>';
3924:
1.329 droeschl 3925: my $incindex=$index+1;
3926: my $selectbox='';
1.471 raeburn 3927: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3928: ((split(/\:/,
1.344 bisitz 3929: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3930: ne '') &&
1.329 droeschl 3931: ((split(/\:/,
1.344 bisitz 3932: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3933: ne '')) {
3934: $selectbox=
3935: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3936: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3937: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3938: if ($i==$incindex) {
1.358 bisitz 3939: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3940: } else {
3941: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3942: }
3943: }
3944: $selectbox.='</select>';
3945: }
1.484.2.12 raeburn 3946: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3947: 'up' => 'Move Up',
3948: 'dw' => 'Move Down',
3949: 'rm' => 'Remove',
3950: 'ct' => 'Cut',
3951: 'rn' => 'Rename',
1.484.2.12 raeburn 3952: 'cp' => 'Copy',
3953: 'ex' => 'External Resource',
1.484.2.93.2. (raeburn 3954:): 'et' => 'External Tool',
1.484.2.12 raeburn 3955: 'ed' => 'Edit',
3956: 'pr' => 'Preview',
3957: 'sv' => 'Save',
3958: 'ul' => 'URL',
1.484.2.67 raeburn 3959: 'ti' => 'Title',
3960: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3961: );
1.484.2.30 raeburn 3962: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3963: $env{'form.folderpath'},
3964: $currgroups);
1.484.2.19 raeburn 3965: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3966: my $skip_confirm = 0;
1.484.2.63 raeburn 3967: my $confirm_removal = 0;
1.329 droeschl 3968: if ( $folder =~ /^supplemental/
3969: || ($url =~ m{( /smppg$
3970: |/syllabus$
3971: |/aboutme$
3972: |/navmaps$
3973: |/bulletinboard$
1.484.2.93.2. (raeburn 3974:): |/ext\.tool$
1.484.2.16 raeburn 3975: |\.html$)}x)
1.484.2.19 raeburn 3976: || $isexternal) {
1.329 droeschl 3977: $skip_confirm = 1;
3978: }
1.484.2.63 raeburn 3979: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3980: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3981: $confirm_removal = 1;
3982: }
1.484.2.19 raeburn 3983:
1.484.2.30 raeburn 3984: if ($denied{'copy'}) {
3985: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3986: <span style="visibility: hidden;">$lt{'cp'}</span>
3987: ENDCOPY
3988: } else {
1.484.2.30 raeburn 3989: my $formname = 'edit_copy_'.$orderidx;
3990: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3991: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3992: <form name="$formname" method="post" action="/adm/coursedocs">
3993: $form_common
1.484.2.67 raeburn 3994: <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 3995: $form_end
1.329 droeschl 3996: ENDCOPY
1.484.2.30 raeburn 3997: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3998: push(@{$filtersref->{'cancopy'}},$orderidx);
3999: }
1.329 droeschl 4000: }
1.484.2.30 raeburn 4001: if ($denied{'cut'}) {
1.484.2.16 raeburn 4002: $cutlink=(<<ENDCUT);
4003: <span style="visibility: hidden;">$lt{'ct'}</span>
4004: ENDCUT
4005: } else {
1.484.2.30 raeburn 4006: my $formname = 'edit_cut_'.$orderidx;
4007: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 4008: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 4009: <form name="$formname" method="post" action="/adm/coursedocs">
4010: $form_common
4011: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 4012: <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 4013: $form_end
1.329 droeschl 4014: ENDCUT
1.484.2.30 raeburn 4015: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4016: push(@{$filtersref->{'cancut'}},$orderidx);
4017: }
1.329 droeschl 4018: }
1.484.2.30 raeburn 4019: if ($denied{'remove'}) {
1.484.2.16 raeburn 4020: $removelink=(<<ENDREM);
4021: <span style="visibility: hidden;">$lt{'rm'}</a>
4022: ENDREM
4023: } else {
1.484.2.30 raeburn 4024: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 4025: 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 4026: $removelink=(<<ENDREM);
1.484.2.30 raeburn 4027: <form name="$formname" method="post" action="/adm/coursedocs">
4028: $form_common
4029: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 4030: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 4031: <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 4032: $form_end
1.484.2.9 raeburn 4033: ENDREM
1.484.2.30 raeburn 4034: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4035: push(@{$filtersref->{'canremove'}},$orderidx);
4036: }
1.484.2.9 raeburn 4037: }
1.484.2.35 raeburn 4038: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 4039: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 4040: ENDREN
1.484.2.67 raeburn 4041: my ($uplink,$downlink);
4042: if ($canedit) {
4043: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4044: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4045: } else {
4046: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4047: $downlink = $uplink;
4048: }
1.329 droeschl 4049: $line.=(<<END);
4050: <td>
1.379 bisitz 4051: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4052: <a href="$uplink">
1.484.2.12 raeburn 4053: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4054: </a>
4055: </div>
4056: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4057: <a href="$downlink">
1.484.2.12 raeburn 4058: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4059: </a>
4060: </div>
1.329 droeschl 4061: </td>
4062: <td>
4063: $form_start
1.484.2.30 raeburn 4064: $form_param
1.478 raeburn 4065: $form_common
1.329 droeschl 4066: $selectbox
4067: $form_end
4068: </td>
1.484.2.30 raeburn 4069: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 4070: $removelink
1.329 droeschl 4071: $cutlink
4072: $copylink
4073: </td>
4074: END
4075: }
4076: # Figure out what kind of a resource this is
4077: my ($extension)=($url=~/\.(\w+)$/);
4078: my $uploaded=($url=~/^\/*uploaded\//);
4079: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 4080: my $isfolder;
4081: my $ispage;
4082: my $containerarg;
1.484.2.67 raeburn 4083: my $folderurl;
1.329 droeschl 4084: if ($uploaded) {
1.472 raeburn 4085: if (($extension eq 'sequence') || ($extension eq 'page')) {
4086: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 4087: $containerarg = $1;
1.472 raeburn 4088: if ($extension eq 'sequence') {
4089: $icon=$iconpath.'navmap.folder.closed.gif';
4090: $isfolder=1;
4091: } else {
4092: $icon=$iconpath.'page.gif';
4093: $ispage=1;
4094: }
1.484.2.67 raeburn 4095: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4096: if ($allowed) {
4097: $url='/adm/coursedocs?';
4098: } else {
4099: $url='/adm/supplemental?';
4100: }
1.329 droeschl 4101: } else {
4102: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4103: }
4104: }
1.364 bisitz 4105:
1.484.2.70 raeburn 4106: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4107: my $orig_url = $url;
1.340 raeburn 4108: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 4109: if ($container eq 'page') {
4110: $url=~s{^http(|s)(:|:)//}{/ext/};
4111: } else {
4112: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4113: }
1.484.2.12 raeburn 4114: if (!$supplementalflag && $residx && $symb) {
4115: if ((!$isfolder) && (!$ispage)) {
4116: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.484.2.87 raeburn 4117: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4118: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4119: } else {
4120: $url=&Apache::lonnet::clutter($url);
4121: }
1.484.2.12 raeburn 4122: if ($url=~/^\/*uploaded\//) {
4123: $url=~/\.(\w+)$/;
4124: my $embstyle=&Apache::loncommon::fileembstyle($1);
4125: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4126: $url='/adm/wrapper'.$url;
4127: } elsif ($embstyle eq 'ssi') {
4128: #do nothing with these
4129: } elsif ($url!~/\.(sequence|page)$/) {
4130: $url='/adm/coursedocs/showdoc'.$url;
4131: }
1.484.2.70 raeburn 4132: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4133: my $wrapped = $1;
4134: my $exturl = $2;
1.484.2.87 raeburn 4135: if (($wrapped eq '') && ($container ne 'page')) {
1.484.2.70 raeburn 4136: $url='/adm/wrapper'.$url;
4137: }
4138: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4139: $nomodal = 1;
4140: }
1.484.2.93.2. (raeburn 4141:): } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4142:): $url='/adm/wrapper'.$url;
1.484.2.70 raeburn 4143: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4144: if (($ENV{'SERVER_PORT'} == 443) &&
4145: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 4146: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4147: $url .= '?usehttp=1';
4148: }
1.484.2.70 raeburn 4149: $nomodal = 1;
4150: }
1.484.2.19 raeburn 4151: }
1.484.2.93.2. (raeburn 4152:): my ($checkencrypt,$shownurl);
4153:): if (!$env{'request.role.adv'}) {
1.484.2.67 raeburn 4154: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.484.2.93.2. (raeburn 4155:): ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.484.2.67 raeburn 4156: $checkencrypt = 1;
1.484.2.70 raeburn 4157: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 4158: unless (ref($$navmapref)) {
4159: $$navmapref = Apache::lonnavmaps::navmap->new();
4160: }
4161: if (ref($$navmapref)) {
4162: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4163: $checkencrypt = 1;
4164: }
4165: }
4166: }
1.484.2.93.2. (raeburn 4167:): }
4168:): if ($checkencrypt) {
4169:): my $currenc = $env{'request.enc'};
4170:): $env{'request.enc'} = 1;
4171:): $shownsymb = &Apache::lonenc::encrypted($symb);
4172:): $shownurl = &Apache::lonenc::encrypted($url);
4173:): if (&Apache::lonnet::symbverify($symb,$url)) {
4174:): $url = $shownurl;
1.484.2.67 raeburn 4175: } else {
1.484.2.93.2. (raeburn 4176:): $url = '';
1.484.2.67 raeburn 4177: }
1.484.2.93.2. (raeburn 4178:): $env{'request.enc'} = $currenc;
4179:): } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4180:): $shownsymb = $symb;
4181:): if ($isexternal) {
4182:): $url =~ s/\#[^#]+$//;
4183:): if ($container eq 'page') {
4184:): $url = &Apache::lonnet::clutter($url);
4185:): }
4186:): }
4187:): $shownurl = $url;
4188:): }
4189:): unless ($env{'request.role.adv'}) {
4190:): if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4191:): $url = '';
4192:): }
4193:): if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4194:): $url = '';
4195:): $hiddenres = 1;
4196:): }
4197:): }
4198:): if ($url ne '') {
4199:): $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.12 raeburn 4200: }
1.484.2.19 raeburn 4201: }
1.484.2.66 raeburn 4202: } elsif ($supplementalflag) {
4203: if ($isexternal) {
4204: if ($url =~ /^([^#]+)#([^#]+)$/) {
4205: $url = $1;
4206: $anchor = $2;
1.484.2.70 raeburn 4207: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.93 raeburn 4208: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4209: if ($hostname ne '') {
4210: $url = 'http://'.$hostname.$url;
4211: }
4212: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4213: }
1.484.2.70 raeburn 4214: $nomodal = 1;
4215: }
4216: }
4217: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4218: if (($ENV{'SERVER_PORT'} == 443) &&
4219: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 4220: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4221: if ($hostname ne '') {
4222: $url = 'http://'.$hostname.$url;
4223: }
4224: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4225: }
1.484.2.70 raeburn 4226: $nomodal = 1;
1.484.2.66 raeburn 4227: }
4228: }
1.329 droeschl 4229: }
1.484.2.67 raeburn 4230: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4231: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4232: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4233: my $foldername=&escape($foldertitle);
4234: my $folderpath=$env{'form.folderpath'};
4235: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4236: if (!$allowed && $supplementalflag) {
4237: $folderpath.=$containerarg.'&'.$foldername;
4238: $url.='folderpath='.&escape($folderpath);
4239: } else {
4240: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4241: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4242: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4243: 'parameter_randomorder'))[0]=~/^yes$/i);
4244: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4245: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4246: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4247: 'parameter_encrypturl'))[0]=~/^yes$/i);
4248: unless ($hiddenmap) {
1.484.2.70 raeburn 4249: if (ref($navmapref)) {
4250: unless (ref($$navmapref)) {
4251: $$navmapref = Apache::lonnavmaps::navmap->new();
4252: }
4253: if (ref($$navmapref)) {
4254: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4255: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4256: unless (@resources) {
4257: $hiddenmap = 1;
4258: unless ($env{'request.role.adv'}) {
4259: $url = '';
4260: $hiddenfolder = 1;
4261: }
1.484.2.67 raeburn 4262: }
4263: }
4264: }
4265: }
4266: }
4267: unless ($encryptmap) {
1.484.2.70 raeburn 4268: if ((ref($navmapref)) && (ref($$navmapref))) {
4269: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4270: $encryptmap = 1;
4271: }
1.484.2.67 raeburn 4272: }
4273: }
4274:
4275: # Append randompick number, hidden, and encrypted with ":" to foldername,
4276: # so it gets transferred between levels
4277: $folderpath.=$containerarg.'&'.$foldername.
4278: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4279: unless ($url eq '') {
4280: $url.='folderpath='.&escape($folderpath);
4281: }
1.484.2.19 raeburn 4282: my $rpckchk;
4283: if ($rpicknum) {
4284: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4285: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4286: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4287: }
1.484.2.19 raeburn 4288: }
1.484.2.29 raeburn 4289: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4290: $rand_pick_text =
1.478 raeburn 4291: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4292: $form_param."\n".
1.478 raeburn 4293: $form_common."\n".
1.484.2.67 raeburn 4294: '<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 4295: if ($rpicknum ne '') {
4296: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4297: }
1.484.2.29 raeburn 4298: $rand_pick_text .= '</span></span>'.
4299: $form_end;
1.484.2.30 raeburn 4300: my $ro_set;
1.484.2.67 raeburn 4301: if ($randorder) {
1.484.2.30 raeburn 4302: $ro_set = 'checked="checked"';
4303: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4304: push(@{$filtersref->{'randomorder'}},$orderidx);
4305: }
4306: }
1.484.2.41 raeburn 4307: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4308: $rand_order_text =
1.484.2.29 raeburn 4309: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4310: $form_param."\n".
1.484.2.29 raeburn 4311: $form_common."\n".
1.484.2.67 raeburn 4312: '<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 4313: $form_end;
1.484.2.19 raeburn 4314: }
1.484.2.18 raeburn 4315: } elsif ($supplementalflag && !$allowed) {
1.484.2.93.2. (raeburn 4316:): my $isexttool;
4317:): if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4318:): $url='/adm/wrapper'.$url;
4319:): $isexttool = 1;
4320:): }
1.484.2.19 raeburn 4321: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4322: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4323: if ($title) {
4324: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4325: }
1.484.2.93.2. (raeburn 4326:): if ((($isexternal) || ($isexttool)) && $orderidx) {
1.484.2.19 raeburn 4327: $url .= '&idx='.$orderidx;
4328: }
1.484.2.66 raeburn 4329: if ($anchor ne '') {
4330: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4331: }
1.329 droeschl 4332: }
1.484.2.19 raeburn 4333: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4334: if ($allowed) {
1.484.2.19 raeburn 4335: my $fileloc =
1.484.2.12 raeburn 4336: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4337: if ($isexternal) {
4338: ($editlink,$extresform) =
1.484.2.67 raeburn 4339: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
1.484.2.93.2. (raeburn 4340:): undef,undef,undef,undef,undef,undef,
4341:): undef,$disabled);
4342:): } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4343:): ($editlink,$extresform) =
4344:): &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4345:): undef,undef,undef,'tool',$coursedom,
4346:): $coursenum,$ltitoolsref,$disabled);
1.484.2.19 raeburn 4347: } elsif (!$isfolder && !$ispage) {
4348: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4349: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4350: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4351: my $suppanchor;
4352: if ($supplementalflag) {
4353: $suppanchor = $anchor;
4354: }
1.484.2.19 raeburn 4355: my $jscall =
1.484.2.12 raeburn 4356: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4357: $switchserver,
1.484.2.14 raeburn 4358: $forceedit,
1.484.2.93.2. (raeburn 4359:): undef,$symb,$shownsymb,
1.484.2.19 raeburn 4360: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4361: $renametitle,$hostname,
4362: '','',1,$suppanchor);
1.484.2.12 raeburn 4363: if ($jscall) {
1.484.2.19 raeburn 4364: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4365: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4366: }
4367: }
4368: }
1.484.2.19 raeburn 4369: $tdalign = ' align="right" valign="top"';
4370: $tdwidth = ' width="80%"';
1.329 droeschl 4371: }
1.408 raeburn 4372: my $reinit;
4373: if ($crstype eq 'Community') {
4374: $reinit = &mt('(re-initialize community to access)');
4375: } else {
4376: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4377: }
4378: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4379: my $link;
1.472 raeburn 4380: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4381: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4382: } elsif ($url) {
1.484.2.66 raeburn 4383: if ($anchor ne '') {
4384: if ($supplementalflag) {
4385: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4386: } else {
4387: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4388: }
4389: }
1.484.2.80 raeburn 4390:
4391: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4392: $link = 'http://'.$hostname.$url;
4393: } else {
4394: $link = $url;
4395: }
4396: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4397: if ($nomodal) {
4398: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4399: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4400: } else {
4401: $line.=&Apache::loncommon::modal_link($link,
4402: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4403: }
1.469 www 4404: } else {
4405: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4406: }
1.484.2.19 raeburn 4407: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4408: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4409: $line.='<a href="'.$url.'">'.$title.'</a>';
4410: } elsif ($url) {
1.484.2.70 raeburn 4411: if ($nomodal) {
4412: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4413: $title.'</a>';
4414: } else {
4415: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4416: }
1.484.2.67 raeburn 4417: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4418: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4419: } else {
4420: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4421: }
1.484.2.19 raeburn 4422: $line.="$extresform</td>";
1.478 raeburn 4423: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4424: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4425: if (($allowed) && ($folder!~/^supplemental/)) {
4426: my %lt=&Apache::lonlocal::texthash(
4427: 'hd' => 'Hidden',
4428: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4429: my ($enctext,$hidtext);
4430: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4431: $enctext = ' checked="checked"';
4432: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4433: push(@{$filtersref->{'encrypturl'}},$orderidx);
4434: }
4435: }
4436: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4437: $hidtext = ' checked="checked"';
4438: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4439: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4440: }
4441: }
1.484.2.29 raeburn 4442: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4443: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4444: $line.=(<<ENDPARMS);
4445: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4446: <form action="/adm/coursedocs" method="post" name="$formhidden">
4447: $form_param
1.478 raeburn 4448: $form_common
1.484.2.67 raeburn 4449: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4450: $form_end
1.458 raeburn 4451: <br />
1.484.2.29 raeburn 4452: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4453: $form_param
1.478 raeburn 4454: $form_common
1.484.2.67 raeburn 4455: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4456: $form_end
4457: </td>
1.478 raeburn 4458: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4459: $rand_order_text</td>
1.329 droeschl 4460: ENDPARMS
4461: }
1.379 bisitz 4462: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4463: return $line;
4464: }
4465:
1.484.2.30 raeburn 4466: sub action_restrictions {
4467: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4468: my %denied = (
4469: cut => 0,
4470: copy => 0,
4471: remove => 0,
4472: );
4473: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4474: # no copy for published maps
4475: $denied{'copy'} = 1;
1.484.2.82 raeburn 4476: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4477: unless ($1 eq 'simpleproblem') {
4478: $denied{'copy'} = 1;
4479: }
4480: $denied{'cut'} = 1;
1.484.2.30 raeburn 4481: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4482: if ($folderpath =~ /^default&[^\&]+$/) {
4483: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4484: $denied{'remove'} = 1;
4485: }
4486: $denied{'cut'} = 1;
4487: $denied{'copy'} = 1;
4488: }
4489: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4490: my $group = $1;
4491: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4492: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4493: $denied{'remove'} = 1;
4494: }
4495: }
4496: $denied{'cut'} = 1;
4497: $denied{'copy'} = 1;
4498: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4499: my $group = $1;
4500: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4501: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4502: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4503: if (keys(%groupsettings) > 0) {
4504: $denied{'remove'} = 1;
4505: }
4506: $denied{'cut'} = 1;
4507: $denied{'copy'} = 1;
4508: }
4509: }
4510: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4511: my $group = $1;
4512: if ($url =~ /group_boards_\Q$group\E/) {
4513: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4514: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4515: if (keys(%groupsettings) > 0) {
4516: if (ref($groupsettings{'functions'}) eq 'HASH') {
4517: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4518: $denied{'remove'} = 1;
4519: }
4520: }
4521: }
4522: $denied{'cut'} = 1;
4523: $denied{'copy'} = 1;
4524: }
4525: }
4526: }
4527: return %denied;
4528: }
4529:
1.484.2.26 raeburn 4530: sub new_timebased_suffix {
1.484.2.30 raeburn 4531: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4532: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4533: if ($type eq 'paste') {
4534: $prefix = $type;
4535: $namespace = 'courseeditor';
1.484.2.56 raeburn 4536: $idtype = 'addcode';
1.484.2.30 raeburn 4537: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4538: $prefix = 'docs';
4539: if ($area eq 'supplemental') {
4540: $prefix = 'supp';
4541: }
4542: $prefix .= $container;
4543: $namespace = 'uploadedmaps';
4544: } else {
4545: $prefix = $type;
4546: $namespace = 'templated';
1.484.2.15 raeburn 4547: }
4548: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4549: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4550: if (!$suffix) {
1.484.2.30 raeburn 4551: if ($type eq 'paste') {
4552: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4553: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4554: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4555: } elsif ($type eq 'smppg') {
4556: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.484.2.93.2. (raeburn 4557:): } elsif ($type eq 'exttool') {
4558:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.484.2.26 raeburn 4559: } else {
1.484.2.42 raeburn 4560: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4561: }
1.484.2.15 raeburn 4562: if ($error) {
4563: $errtext .= '<br />'.$error;
4564: }
4565: }
4566: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4567: $locknotfreed =
4568: '<div class="LC_error">'.
4569: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4570: if ($type eq 'paste') {
1.484.2.57 raeburn 4571: if ($freedlock eq 'nolock') {
4572: $locknotfreed =
4573: '<div class="LC_error">'.
4574: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4575:
1.484.2.60 raeburn 4576: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4577: } else {
4578: $locknotfreed .=
4579: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4580: }
1.484.2.30 raeburn 4581: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4582: $locknotfreed .=
4583: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4584: } elsif ($type eq 'smppg') {
4585: $locknotfreed .=
4586: &mt('This will prevent creation of additional simple pages in this course.');
1.484.2.93.2. (raeburn 4587:): } elsif ($type eq 'exttool') {
4588:): $locknotfreed .=
4589:): &mt('This will prevent creation of additional external tools in this course.');
1.484.2.26 raeburn 4590: } else {
4591: $locknotfreed .=
1.484.2.42 raeburn 4592: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4593: }
1.484.2.30 raeburn 4594: unless ($type eq 'paste') {
4595: $locknotfreed .=
1.484.2.38 raeburn 4596: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4597: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4598: }
4599: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4600: }
4601: return ($suffix,$errtext,$locknotfreed);
4602: }
4603:
1.329 droeschl 4604: =pod
4605:
4606: =item tiehash()
4607:
4608: tie the hash
4609:
4610: =cut
4611:
4612: sub tiehash {
4613: my ($mode)=@_;
4614: $hashtied=0;
4615: if ($env{'request.course.fn'}) {
4616: if ($mode eq 'write') {
4617: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4618: &GDBM_WRCREAT(),0640)) {
4619: $hashtied=2;
4620: }
4621: } else {
4622: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4623: &GDBM_READER(),0640)) {
4624: $hashtied=1;
4625: }
4626: }
1.364 bisitz 4627: }
1.329 droeschl 4628: }
4629:
4630: sub untiehash {
4631: if ($hashtied) { untie %hash; }
4632: $hashtied=0;
4633: return OK;
4634: }
4635:
4636:
4637:
4638:
4639: sub checkonthis {
1.484.2.78 raeburn 4640: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4641: $url=&unescape($url);
4642: $alreadyseen{$url}=1;
4643: $r->rflush();
4644: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4645: $r->print("\n<br />");
4646: if ($level==0) {
4647: $r->print("<br />");
4648: }
4649: for (my $i=0;$i<=$level*5;$i++) {
4650: $r->print(' ');
4651: }
4652: $r->print('<a href="'.$url.'" target="cat">'.
4653: ($title?$title:$url).'</a> ');
4654: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4655: my $updated;
4656: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4657: ($url !~ /\.\d+\.\w+$/)) {
4658: $updated = &Apache::lonnet::remove_stale_resfile($url);
4659: }
1.329 droeschl 4660: my $result=&Apache::lonnet::repcopy(
4661: &Apache::lonnet::filelocation('',$url));
4662: if ($result eq 'ok') {
4663: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4664: if ($updated) {
4665: $r->print('<br />');
4666: for (my $i=0;$i<=$level*5;$i++) {
4667: $r->print(' ');
4668: }
4669: $r->print('- '.&mt('Outdated copy removed'));
4670: }
1.329 droeschl 4671: $r->rflush();
4672: &Apache::lonnet::countacc($url);
4673: $url=~/\.(\w+)$/;
4674: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4675: $r->print('<br />');
4676: $r->rflush();
4677: for (my $i=0;$i<=$level*5;$i++) {
4678: $r->print(' ');
4679: }
4680: $r->print('- '.&mt('Rendering:').' ');
4681: my ($errorcount,$warningcount)=split(/:/,
4682: &Apache::lonnet::ssi_body($url,
4683: ('grade_target'=>'web',
4684: 'return_only_error_and_warning_counts' => 1)));
4685: if (($errorcount) ||
4686: ($warningcount)) {
4687: if ($errorcount) {
1.369 bisitz 4688: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4689: &mt('[quant,_1,error]',$errorcount).'</span>');
4690: }
4691: if ($warningcount) {
4692: $r->print('<span class="LC_warning">'.
4693: &mt('[quant,_1,warning]',$warningcount).'</span>');
4694: }
4695: } else {
4696: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4697: }
4698: $r->rflush();
4699: }
4700: my $dependencies=
4701: &Apache::lonnet::metadata($url,'dependencies');
4702: foreach my $dep (split(/\,/,$dependencies)) {
4703: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4704: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4705: }
4706: }
4707: } elsif ($result eq 'unavailable') {
4708: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4709: } elsif ($result eq 'not_found') {
4710: unless ($url=~/\$/) {
1.484.2.19 raeburn 4711: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4712: } else {
1.366 bisitz 4713: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4714: }
4715: } else {
4716: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4717: }
1.484.2.78 raeburn 4718: if (($updated) && ($result ne 'ok')) {
4719: $r->print('<br />'.&mt('Outdated copy removed'));
4720: }
1.329 droeschl 4721: }
4722: }
4723: }
4724:
4725:
4726:
4727: =pod
4728:
4729: =item list_symbs()
4730:
1.484.2.3 raeburn 4731: List Content Identifiers
1.329 droeschl 4732:
4733: =cut
4734:
4735: sub list_symbs {
4736: my ($r) = @_;
4737:
1.408 raeburn 4738: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4739: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4740: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4741: $r->print(&startContentScreen('tools'));
1.329 droeschl 4742: my $navmap = Apache::lonnavmaps::navmap->new();
4743: if (!defined($navmap)) {
4744: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4745: '<div class="LC_error">'.
4746: &mt('Unable to retrieve information about course contents').
4747: '</div>');
1.408 raeburn 4748: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4749: } else {
1.484 raeburn 4750: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4751: &Apache::loncommon::start_data_table().
4752: &Apache::loncommon::start_data_table_header_row().
4753: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4754: &Apache::loncommon::end_data_table_header_row()."\n");
4755: my $count;
1.329 droeschl 4756: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4757: $r->print(&Apache::loncommon::start_data_table_row().
4758: '<td>'.$res->compTitle().'</td>'.
4759: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4760: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4761: $count ++;
4762: }
4763: if (!$count) {
4764: $r->print(&Apache::loncommon::start_data_table_row().
4765: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4766: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4767: }
1.484 raeburn 4768: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4769: }
1.484.2.19 raeburn 4770: $r->print(&endContentScreen());
1.329 droeschl 4771: }
4772:
1.484.2.93.2. (raeburn 4773:): sub short_urls {
4774:): my ($r,$canedit) = @_;
4775:): my $crstype = &Apache::loncommon::course_type();
4776:): my $formname = 'shortenurl';
4777:): $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4778:): $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4779:): $r->print(&startContentScreen('tools'));
4780:): my ($navmap,$errormsg) =
4781:): &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4782:): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4783:): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4784:): my (%maps,%resources,%titles);
4785:): if (!ref($navmap)) {
4786:): $r->print($errormsg.
4787:): &endContentScreen());
4788:): return '';
4789:): } else {
4790:): $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
4791:): $r->rflush();
4792:): my $readonly;
4793:): if ($canedit) {
4794:): my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
4795:): if ($numnew) {
4796:): $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4797:): }
4798:): if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4799:): $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4800:): foreach my $error (@{$errors}) {
4801:): $r->print('<li>'.$error.'</li>');
4802:): }
4803:): $r->print('</ul><br />');
4804:): }
4805:): } else {
4806:): $readonly = 1;
4807:): }
4808:): my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4809:): $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4810:): undef,undef,undef,undef,undef,\%currtiny,$readonly));
4811:): }
4812:): $r->print(&endContentScreen());
4813:): }
4814:):
1.484.2.78 raeburn 4815: sub contentverifyform {
4816: my ($r) = @_;
4817: my $crstype = &Apache::loncommon::course_type();
4818: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4819: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4820: $r->print(&startContentScreen('tools'));
4821: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4822: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4823: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4824: ' <span class="LC_nobreak">'.
4825: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4826: &mt('No').'</label>'.(' 'x2).
4827: '<label><input type="radio" name="checkstale" value="1" />'.
4828: &mt('Yes').'</label></span></p><p>'.
1.484.2.90 raeburn 4829: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.484.2.78 raeburn 4830: '<input type="hidden" value="1" name="tools" />'.
4831: '<input type="hidden" value="1" name="verify" /></p></form>');
4832: $r->print(&endContentScreen());
4833: return;
4834: }
1.329 droeschl 4835:
4836: sub verifycontent {
1.484.2.78 raeburn 4837: my ($r,$checkstale) = @_;
1.408 raeburn 4838: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4839: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4840: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4841: $r->print(&startContentScreen('tools'));
4842: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4843: $hashtied=0;
4844: undef %alreadyseen;
4845: %alreadyseen=();
4846: &tiehash();
1.484 raeburn 4847:
1.329 droeschl 4848: foreach my $key (keys(%hash)) {
4849: if ($hash{$key}=~/\.(page|sequence)$/) {
4850: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4851: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4852: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4853: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4854: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4855: }
4856: }
4857: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4858: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4859: }
4860: }
4861: &untiehash();
1.442 www 4862: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4863: $r->print(&endContentScreen());
1.329 droeschl 4864: }
4865:
4866:
4867: sub devalidateversioncache {
4868: my $src=shift;
4869: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4870: &Apache::lonnet::clutter($src));
4871: }
4872:
4873: sub checkversions {
1.484.2.67 raeburn 4874: my ($r,$canedit) = @_;
1.408 raeburn 4875: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4876: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4877: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4878: $r->print(&startContentScreen('tools'));
1.442 www 4879:
1.329 droeschl 4880: my $header='';
4881: my $startsel='';
4882: my $monthsel='';
4883: my $weeksel='';
4884: my $daysel='';
4885: my $allsel='';
4886: my %changes=();
4887: my $starttime=0;
4888: my $haschanged=0;
4889: my %setversions=&Apache::lonnet::dump('resourceversions',
4890: $env{'course.'.$env{'request.course.id'}.'.domain'},
4891: $env{'course.'.$env{'request.course.id'}.'.num'});
4892:
4893: $hashtied=0;
4894: &tiehash();
1.484.2.67 raeburn 4895: if ($canedit) {
4896: my %newsetversions=();
4897: if ($env{'form.setmostrecent'}) {
4898: $haschanged=1;
4899: foreach my $key (keys(%hash)) {
4900: if ($key=~/^ids\_(\/res\/.+)$/) {
4901: $newsetversions{$1}='mostrecent';
4902: &devalidateversioncache($1);
4903: }
1.329 droeschl 4904: }
1.484.2.67 raeburn 4905: } elsif ($env{'form.setcurrent'}) {
4906: $haschanged=1;
4907: foreach my $key (keys(%hash)) {
4908: if ($key=~/^ids\_(\/res\/.+)$/) {
4909: my $getvers=&Apache::lonnet::getversion($1);
4910: if ($getvers>0) {
4911: $newsetversions{$1}=$getvers;
4912: &devalidateversioncache($1);
4913: }
4914: }
1.329 droeschl 4915: }
1.484.2.67 raeburn 4916: } elsif ($env{'form.setversions'}) {
4917: $haschanged=1;
4918: foreach my $key (keys(%env)) {
4919: if ($key=~/^form\.set_version_(.+)$/) {
4920: my $src=$1;
4921: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4922: $newsetversions{$src}=$env{$key};
4923: &devalidateversioncache($src);
4924: }
4925: }
1.329 droeschl 4926: }
1.484.2.67 raeburn 4927: }
4928: if ($haschanged) {
4929: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4930: $env{'course.'.$env{'request.course.id'}.'.domain'},
4931: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4932: $r->print(&Apache::loncommon::confirmwrapper(
4933: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4934: } else {
4935: $r->print(&Apache::loncommon::confirmwrapper(
4936: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4937: }
4938: &mark_hash_old();
4939: }
4940: &changewarning($r,'');
1.329 droeschl 4941: }
4942: if ($env{'form.timerange'} eq 'all') {
4943: # show all documents
1.484.2.34 raeburn 4944: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4945: $allsel=' selected="selected"';
1.329 droeschl 4946: foreach my $key (keys(%hash)) {
4947: if ($key=~/^ids\_(\/res\/.+)$/) {
4948: my $src=$1;
4949: $changes{$src}=1;
4950: }
4951: }
4952: } else {
4953: # show documents which changed
4954: %changes=&Apache::lonnet::dump
4955: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4956: $env{'course.'.$env{'request.course.id'}.'.num'});
4957: my $firstkey=(keys(%changes))[0];
4958: unless ($firstkey=~/^error\:/) {
4959: unless ($env{'form.timerange'}) {
4960: $env{'form.timerange'}=604800;
4961: }
4962: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4963: .&mt('seconds');
4964: if ($env{'form.timerange'}==-1) {
4965: $seltext='since start of course';
1.484.2.19 raeburn 4966: $startsel=' selected="selected"';
1.329 droeschl 4967: $env{'form.timerange'}=time;
4968: }
4969: $starttime=time-$env{'form.timerange'};
4970: if ($env{'form.timerange'}==2592000) {
4971: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4972: $monthsel=' selected="selected"';
1.329 droeschl 4973: } elsif ($env{'form.timerange'}==604800) {
4974: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4975: $weeksel=' selected="selected"';
1.329 droeschl 4976: } elsif ($env{'form.timerange'}==86400) {
4977: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4978: $daysel=' selected="selected"';
1.329 droeschl 4979: }
4980: $header=&mt('Content changed').' '.$seltext;
4981: } else {
4982: $header=&mt('No content modifications yet.');
4983: }
4984: }
4985: %setversions=&Apache::lonnet::dump('resourceversions',
4986: $env{'course.'.$env{'request.course.id'}.'.domain'},
4987: $env{'course.'.$env{'request.course.id'}.'.num'});
4988: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4989: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4990: 'lm' => 'Version changes since last Month',
4991: 'lw' => 'Version changes since last Week',
4992: 'sy' => 'Version changes since Yesterday',
4993: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4994: 'cd' => 'Change display',
1.329 droeschl 4995: 'sd' => 'Display',
4996: 'fi' => 'File',
4997: 'md' => 'Modification Date',
4998: 'mr' => 'Most recently published Version',
1.408 raeburn 4999: 've' => 'Version used in '.$crstype,
5000: 'vu' => 'Set Version to be used in '.$crstype,
5001: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5002: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5003: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5004: 'di' => 'Differences',
1.484 raeburn 5005: 'save' => 'Save changes',
5006: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5007: 'act' => 'Actions');
1.484.2.67 raeburn 5008: my ($disabled,$readonly);
5009: unless ($canedit) {
5010: $disabled = 'disabled="disabled"';
5011: $readonly = 1;
5012: }
1.329 droeschl 5013: $r->print(<<ENDHEADERS);
1.484 raeburn 5014: <h4 class="LC_info">$header</h4>
1.329 droeschl 5015: <form action="/adm/coursedocs" method="post">
5016: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5017: <div class="LC_left_float">
1.479 golterma 5018: <fieldset>
1.484 raeburn 5019: <legend>$lt{'cd'}</legend>
1.329 droeschl 5020: <select name="timerange">
1.484.2.19 raeburn 5021: <option value='all'$allsel>$lt{'al'}</option>
5022: <option value="-1"$startsel>$lt{'st'}</option>
5023: <option value="2592000"$monthsel>$lt{'lm'}</option>
5024: <option value="604800"$weeksel>$lt{'lw'}</option>
5025: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5026: </select>
5027: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5028: </fieldset>
5029: </div>
5030: <div class="LC_left_float">
5031: <fieldset>
5032: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 5033: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5034: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5035: </fieldset>
5036: </div>
5037: <br clear="all" />
5038: <hr />
5039: <h4>$lt{'vers'}</h4>
1.329 droeschl 5040: ENDHEADERS
1.479 golterma 5041: #number of columns for version history
1.484.2.44 raeburn 5042: my %changedbytime;
5043: foreach my $key (keys(%changes)) {
5044: #excludes not versionable problems from resource version history:
5045: next if ($key =~ /^\/res\/lib\/templates/);
5046: my $chg;
5047: if ($env{'form.timerange'} eq 'all') {
5048: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5049: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5050: } else {
5051: $chg = $changes{$key};
5052: next if ($chg < $starttime);
5053: }
5054: push(@{$changedbytime{$chg}},$key);
5055: }
5056: if (keys(%changedbytime) == 0) {
5057: &untiehash();
5058: $r->print(&mt('No content changes in imported content in specified time frame').
5059: &endContentScreen());
5060: return;
5061: }
1.479 golterma 5062: $r->print(
1.484.2.67 raeburn 5063: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5064: &Apache::loncommon::start_data_table().
5065: &Apache::loncommon::start_data_table_header_row().
5066: '<th>'.&mt('Resources').'</th>'.
5067: "<th>$lt{'mr'}</th>".
5068: "<th>$lt{'ve'}</th>".
5069: "<th>$lt{'vu'}</th>".
5070: '<th>'.&mt('History').'</th>'.
5071: &Apache::loncommon::end_data_table_header_row()
5072: );
1.484.2.44 raeburn 5073: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5074: foreach my $key (sort(@{$changedbytime{$chg}})) {
5075: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5076: my $currentversion=&Apache::lonnet::getversion($key);
5077: if ($currentversion<0) {
5078: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5079: }
5080: my $linkurl=&Apache::lonnet::clutter($key);
5081: $r->print(
5082: &Apache::loncommon::start_data_table_row().
5083: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5084: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5085: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5086: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5087: '<td align="right">'
5088: );
5089: # Used in course
5090: my $usedversion=$hash{'version_'.$linkurl};
5091: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 5092: if ($usedversion != $currentversion) {
1.479 golterma 5093: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 5094: } else {
1.479 golterma 5095: $r->print($usedversion);
5096: }
1.329 droeschl 5097: } else {
1.484.2.19 raeburn 5098: $r->print($currentversion);
1.329 droeschl 5099: }
1.484.2.44 raeburn 5100: $r->print('</td><td title="'.$lt{'vu'}.'">');
5101: # Set version
5102: $r->print(&Apache::loncommon::select_form(
5103: $setversions{$linkurl},
5104: 'set_version_'.$linkurl,
5105: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5106: '' => '',
5107: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 5108: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 5109: my $lastold=1;
5110: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5111: my $url=$root.'.'.$prevvers.'.'.$extension;
5112: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5113: $lastold=$prevvers;
5114: }
5115: }
5116: $r->print('</td>');
5117: # List all available versions
5118: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5119: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5120: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 5121: $r->print(
1.484.2.44 raeburn 5122: '<span class="LC_nobreak">'
5123: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5124: .&mt('Version [_1]',$prevvers).'</a>'
5125: .' ('.&Apache::lonlocal::locallocaltime(
5126: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5127: .')');
5128: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5129: $r->print(
5130: ' <a href="/adm/diff?filename='.
5131: &Apache::lonnet::clutter($root.'.'.$extension).
5132: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5133: '" target="diffs">'.&mt('Diffs').'</a>');
5134: }
5135: $r->print('</span><br />');
1.329 droeschl 5136: }
1.484.2.44 raeburn 5137: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 5138: }
1.329 droeschl 5139: }
1.484.2.19 raeburn 5140: $r->print(
5141: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 5142: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5143: '</form>'
5144: );
1.329 droeschl 5145:
5146: &untiehash();
1.484.2.19 raeburn 5147: $r->print(&endContentScreen());
1.484.2.44 raeburn 5148: return;
1.329 droeschl 5149: }
5150:
5151: sub mark_hash_old {
5152: my $retie_hash=0;
5153: if ($hashtied) {
5154: $retie_hash=1;
5155: &untiehash();
5156: }
5157: &tiehash('write');
5158: $hash{'old'}=1;
5159: &untiehash();
5160: if ($retie_hash) { &tiehash(); }
5161: }
5162:
5163: sub is_hash_old {
5164: my $untie_hash=0;
5165: if (!$hashtied) {
5166: $untie_hash=1;
5167: &tiehash();
5168: }
5169: my $return=$hash{'old'};
5170: if ($untie_hash) { &untiehash(); }
5171: return $return;
5172: }
5173:
5174: sub changewarning {
5175: my ($r,$postexec,$message,$url)=@_;
5176: if (!&is_hash_old()) { return; }
5177: my $pathvar='folderpath';
5178: my $path=&escape($env{'form.folderpath'});
5179: if (!defined($url)) {
5180: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5181: }
5182: my $course_type = &Apache::loncommon::course_type();
5183: if (!defined($message)) {
5184: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5185: }
5186: $r->print("\n\n".
1.372 bisitz 5187: '<script type="text/javascript">'."\n".
5188: '// <![CDATA['."\n".
5189: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5190: '// ]]>'."\n".
1.369 bisitz 5191: '</script>'."\n".
1.375 tempelho 5192: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5193: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5194: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5195: &mt($message,' <input type="hidden" name="'.
5196: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5197: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5198: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5199: }
5200:
5201:
5202: sub init_breadcrumbs {
1.484.2.44 raeburn 5203: my ($form,$text,$help)=@_;
1.329 droeschl 5204: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5205: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5206: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5207: faq=>273,
5208: bug=>'Instructor Interface',
1.484.2.44 raeburn 5209: help => $help});
1.329 droeschl 5210: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5211: text=>$text,
5212: faq=>273,
5213: bug=>'Instructor Interface'});
5214: }
5215:
1.441 www 5216: # subroutine to list form elements
5217: sub create_list_elements {
5218: my @formarr = @_;
5219: my $list = '';
1.484.2.12 raeburn 5220: foreach my $button (@formarr){
5221: foreach my $picture (keys(%{$button})) {
5222: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5223: }
5224: }
5225: return $list;
5226: }
1.329 droeschl 5227:
1.441 www 5228: # subroutine to create ul from list elements
5229: sub create_form_ul {
5230: my $list = shift;
5231: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5232: return $ul;
5233: }
1.329 droeschl 5234:
1.442 www 5235: #
5236: # Start tabs
5237: #
5238:
5239: sub startContentScreen {
1.484 raeburn 5240: my ($mode) = @_;
5241: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5242: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5243: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5244: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5245: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5246: } else {
1.484.2.34 raeburn 5247: $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 5248: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5249: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5250: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5251: }
5252: $output .= "\n".'</ul>'."\n";
5253: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5254: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5255: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5256: return $output;
1.442 www 5257: }
5258:
5259: #
5260: # End tabs
5261: #
5262:
5263: sub endContentScreen {
1.484 raeburn 5264: return '</div></div></div>';
1.442 www 5265: }
1.329 droeschl 5266:
1.446 www 5267: sub supplemental_base {
1.484.2.33 raeburn 5268: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5269: }
5270:
1.329 droeschl 5271: sub handler {
5272: my $r = shift;
5273: &Apache::loncommon::content_type($r,'text/html');
5274: $r->send_http_header;
5275: return OK if $r->header_only;
1.484 raeburn 5276:
5277: # get course data
1.408 raeburn 5278: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5279: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5280: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5281:
5282: # graphics settings
5283: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5284:
1.443 www 5285: #
1.329 droeschl 5286: # --------------------------------------------- Initialize help topics for this
5287: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.484.2.93.2. (raeburn 5288:): 'Adding_External_Resource','Adding_External_Tool',
5289:): 'Navigate_Content','Adding_Folders','Docs_Overview',
5290:): 'Load_Map','Supplemental','Score_Upload_Form',
5291:): 'Adding_Pages','Importing_LON-CAPA_Resource',
5292:): 'Importing_IMS_Course','Uploading_From_Harddrive',
5293:): 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5294: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5295: }
5296: # Composite help files
5297: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5298: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5299: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5300: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5301: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5302: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5303: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5304: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5305: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5306: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5307:
1.484.2.67 raeburn 5308: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 5309: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5310: unless ($r->uri eq '/adm/supplemental') {
5311: # does this user have privileges to modify content.
1.484.2.67 raeburn 5312: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5313: $allowed = 1;
5314: $canedit = 1;
5315: $canview = 1;
5316: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5317: $allowed = 1;
5318: $canview = 1;
5319: }
5320: }
5321: unless ($canedit) {
5322: $disabled = ' disabled="disabled"';
1.472 raeburn 5323: }
1.484.2.53 raeburn 5324: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5325: if ($env{'form.inhibitmenu'}) {
5326: unless ($env{'form.inhibitmenu'} eq 'yes') {
5327: delete($env{'form.inhibitmenu'});
5328: }
5329: }
5330:
1.484.2.53 raeburn 5331: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5332: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5333: if (!$canedit) {
5334: &verifycontent($r);
5335: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5336: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5337: text=>'Results',
5338: faq=>273,
5339: bug=>'Instructor Interface'});
5340: &verifycontent($r,$env{'form.checkstale'});
5341: } else {
5342: &contentverifyform($r);
5343: }
1.329 droeschl 5344: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5345: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5346: &list_symbs($r);
1.484.2.93.2. (raeburn 5347:): } elsif ($allowed && $env{'form.shorturls'}) {
5348:): &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5349:): &short_urls($r,$canedit);
1.329 droeschl 5350: } elsif ($allowed && $env{'form.docslog'}) {
5351: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5352: my $folder = $env{'form.folder'};
5353: if ($folder eq '') {
5354: $folder='default';
5355: }
1.484.2.67 raeburn 5356: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5357: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5358: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5359: &checkversions($r,$canedit);
5360: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5361: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5362: &dumpcourse($r);
5363: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5364: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5365: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5366: } else {
1.445 www 5367: #
5368: # Done catching special calls
1.484 raeburn 5369: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5370: # Get the parameters that may be needed
5371: #
5372: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5373: ['folderpath',
5374: 'forcesupplement','forcestandard',
5375: 'tools','symb','command','supppath']);
1.445 www 5376:
1.484.2.78 raeburn 5377: foreach my $item ('forcesupplement','forcestandard','tools') {
5378: next if ($env{'form.'.$item} eq '');
5379: unless ($env{'form.'.$item} eq '1') {
5380: delete($env{'form.'.$item});
5381: }
5382: }
5383:
5384: if ($env{'form.command'}) {
5385: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5386: delete($env{'form.command'});
5387: }
5388: }
5389:
5390: if ($env{'form.symb'}) {
5391: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5392: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5393: delete($env{'form.symb'});
5394: }
5395: }
5396:
1.445 www 5397: # standard=1: this is a "new-style" course with an uploaded map as top level
5398: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5399:
5400: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5401:
1.484 raeburn 5402: # Decide whether this should display supplemental or main content or utilities
1.445 www 5403: # supplementalflag=1: show supplemental documents
5404: # supplementalflag=0: show standard documents
1.484 raeburn 5405: # toolsflag=1: show utilities
1.445 www 5406:
1.484.2.39 raeburn 5407: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5408: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5409: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5410: $supplementalflag=0;
5411: }
5412: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5413: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5414: unless ($allowed) { $supplementalflag=1; }
5415: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5416: my $toolsflag=0;
5417: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5418:
1.484.2.78 raeburn 5419: if ($env{'form.folderpath'} ne '') {
1.484.2.92 raeburn 5420: &validate_folderpath($supplementalflag);
1.484.2.78 raeburn 5421: }
5422:
5423: if ($env{'form.supppath'} ne '') {
1.484.2.92 raeburn 5424: &validate_suppath();
1.484.2.78 raeburn 5425: }
5426:
1.329 droeschl 5427: my $script='';
5428: my $showdoc=0;
1.457 raeburn 5429: my $addentries = {};
1.475 raeburn 5430: my $container;
1.329 droeschl 5431: my $containertag;
1.484.2.17 raeburn 5432: my $pathitem;
1.484.2.93.2. (raeburn 5433:): my %ltitools;
1.484.2.67 raeburn 5434: my $hiddentop;
5435: my $navmap;
5436: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5437:
1.464 www 5438: # Do we directly jump somewhere?
1.484.2.21 raeburn 5439: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5440: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5441: $env{'form.folderpath'}=
1.484.2.67 raeburn 5442: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5443: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5444: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5445: } elsif ($env{'form.supppath'} ne '') {
5446: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5447: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5448: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5449: }
1.472 raeburn 5450: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5451: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5452: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5453: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5454: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5455: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5456: } elsif ($env{'form.command'} eq 'contents') {
5457: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5458: } elsif ($env{'form.command'} eq 'home') {
5459: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5460: }
5461:
1.484.2.23 raeburn 5462:
1.445 www 5463: # Where do we store these for when we come back?
5464: my $stored_folderpath='docs_folderpath';
5465: if ($supplementalflag) {
5466: $stored_folderpath='docs_sup_folderpath';
5467: }
1.464 www 5468:
1.484.2.19 raeburn 5469: # No folderpath, and in edit mode, see if we have something stored
5470: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5471: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5472: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5473:
5474: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5475: if ($supplementalflag) {
5476: undef($env{'form.folderpath'}) if ($1 eq 'default');
5477: } else {
5478: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5479: }
5480: } else {
1.484.2.19 raeburn 5481: undef($env{'form.folderpath'});
5482: }
1.484.2.92 raeburn 5483: if ($env{'form.folderpath'} ne '') {
5484: &validate_folderpath($supplementalflag);
5485: }
1.329 droeschl 5486: }
1.446 www 5487:
5488: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5489: if (!$allowed) {
1.446 www 5490: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5491: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5492: }
5493: }
1.446 www 5494: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5495: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5496: $env{'form.folderpath'} = &supplemental_base()
5497: .'&'.
1.329 droeschl 5498: $env{'form.folderpath'};
5499: }
1.484.2.67 raeburn 5500: # If allowed and user's role is not advanced check folderpath is not hidden
5501: if (($allowed) && (!$env{'request.role.adv'}) &&
5502: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5503: my $folderurl;
5504: my @pathitems = split(/\&/,$env{'form.folderpath'});
5505: my $folder = $pathitems[-2];
5506: if ($folder eq '') {
5507: undef($env{'form.folderpath'});
5508: } else {
5509: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.87 raeburn 5510: if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 5511: $folderurl .= '.page';
5512: } else {
5513: $folderurl .= '.sequence';
5514: }
5515: unless (ref($navmap)) {
5516: $navmap = Apache::lonnavmaps::navmap->new();
5517: }
5518: if (ref($navmap)) {
5519: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5520: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5521: unless (@resources) {
5522: undef($env{'form.folderpath'});
5523: }
5524: }
5525: }
5526: }
5527: }
5528:
5529:
1.446 www 5530: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5531: unless ($env{'form.folderpath'}) {
1.446 www 5532: if ($supplementalflag) {
5533: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5534: } elsif ($allowed) {
5535: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5536: }
1.472 raeburn 5537: }
1.446 www 5538:
1.445 www 5539: # Store this
1.484 raeburn 5540: unless ($toolsflag) {
1.484.2.67 raeburn 5541: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5542: &Apache::loncommon::store_course_settings($stored_folderpath,
5543: {'folderpath' => 'scalar'});
5544: }
5545: my $folderpath;
1.484 raeburn 5546: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5547: $folderpath = $env{'form.folderpath'};
5548: my (@folders)=split('&',$env{'form.folderpath'});
5549: $env{'form.foldername'}=&unescape(pop(@folders));
5550: if ($env{'form.foldername'} =~ /\:1$/) {
5551: $container = 'page';
5552: } else {
5553: $container = 'sequence';
5554: }
5555: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5556: } else {
1.484.2.19 raeburn 5557: if ($env{'form.folder'} eq '' ||
5558: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5559: if ($env{'form.folder'} eq 'supplemental') {
5560: $folderpath=&supplemental_base();
5561: } elsif (!$hiddentop) {
5562: $folderpath='default&'.
5563: &escape(&mt('Main Content').':::::');
5564: }
1.484 raeburn 5565: }
5566: }
1.484.2.19 raeburn 5567: $containertag = '<input type="hidden" name="folderpath" value="" />';
5568: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5569: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5570: $showdoc='/'.$1;
5571: }
5572: if ($showdoc) { # got called in sequence from course
5573: $allowed=0;
5574: } else {
1.484.2.67 raeburn 5575: if ($canedit) {
1.484 raeburn 5576: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5577: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5578: }
5579: }
1.329 droeschl 5580: }
5581:
1.344 bisitz 5582: # get personal data
1.329 droeschl 5583: my $uname=$env{'user.name'};
5584: my $udom=$env{'user.domain'};
5585: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5586:
5587: if ($allowed) {
1.484 raeburn 5588: if ($toolsflag) {
5589: $script .= &inject_data_js();
5590: my ($home,$other,%outhash)=&authorhosts();
5591: if (!$home && $other) {
5592: my @hosts;
5593: foreach my $aurole (keys(%outhash)) {
5594: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5595: push(@hosts,$outhash{$aurole});
5596: }
5597: }
5598: $script .= &dump_switchserver_js(@hosts);
5599: }
1.458 raeburn 5600: } else {
1.484.2.43 raeburn 5601: my $tid = 1;
1.484 raeburn 5602: my @tabids;
5603: if ($supplementalflag) {
5604: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5605: $tid = 2;
1.484 raeburn 5606: } else {
5607: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5608: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5609: unshift(@tabids,'001');
5610: push(@tabids,('dd1','ee1'));
5611: }
1.458 raeburn 5612: }
1.484 raeburn 5613: my $tabidstr = join("','",@tabids);
1.484.2.93.2. (raeburn 5614:): %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
5615:): my $posslti = keys(%ltitools);
1.484.2.80 raeburn 5616: my $hostname = $r->hostname();
1.484.2.93.2. (raeburn 5617:): $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 5618: $canedit,$hostname,\$navmap).
1.484 raeburn 5619: &history_tab_js().
5620: &inject_data_js().
1.484.2.43 raeburn 5621: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.93.2. (raeburn 5622:): &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5623: $addentries = {
1.484.2.3 raeburn 5624: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5625: };
1.458 raeburn 5626: }
1.484.2.30 raeburn 5627: $script .= &paste_popup_js();
1.484.2.12 raeburn 5628: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5629: &mt('Switch server?');
1.484.2.19 raeburn 5630:
5631:
1.329 droeschl 5632: }
5633: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5634: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5635: .'// <![CDATA['."\n"
5636: .$script."\n"
5637: .'// ]]>'."\n"
1.484.2.81 raeburn 5638: .'</script>'."\n"
5639: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5640:
5641: # Breadcrumbs
5642: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5643:
5644: if ($showdoc) {
5645: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5646: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5647: } elsif ($toolsflag) {
1.484.2.67 raeburn 5648: my ($breadtext,$breadtitle);
5649: $breadtext = "$crstype Editor";
5650: if ($canedit) {
5651: $breadtitle = 'Editing '.$crstype.' Contents';
5652: } else {
5653: $breadtext .= ' (View-only mode)';
5654: $breadtitle = 'Viewing '.$crstype.' Contents';
5655: }
1.484.2.44 raeburn 5656: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5657: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5658: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5659: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5660: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5661: $breadtitle)
1.484.2.44 raeburn 5662: );
1.484.2.19 raeburn 5663: } elsif ($r->uri eq '/adm/supplemental') {
5664: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5665: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5666: {'bread_crumbs' => $brcrum,}));
5667: } else {
1.484.2.67 raeburn 5668: my ($breadtext,$breadtitle,$helpitem);
5669: $breadtext = "$crstype Editor";
5670: if ($canedit) {
5671: $breadtitle = 'Editing '.$crstype.' Contents';
5672: $helpitem = 'Docs_Adding_Course_Doc';
5673: } else {
5674: $breadtext .= ' (View-only mode)';
5675: $breadtitle = 'Viewing '.$crstype.' Contents';
5676: $helpitem = 'Docs_Viewing_Course_Doc';
5677: }
1.392 raeburn 5678: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5679: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5680: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5681: {'add_entries' => $addentries}
5682: )
1.392 raeburn 5683: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5684: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5685: $breadtitle,
5686: $helpitem)
1.392 raeburn 5687: );
5688: }
1.364 bisitz 5689:
1.329 droeschl 5690: my %allfiles = ();
5691: my %codebase = ();
1.440 raeburn 5692: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5693: if ($canedit) {
1.329 droeschl 5694: if (($env{'form.uploaddoc.filename'}) &&
5695: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5696: my $context = $1;
5697: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5698: undef($hadchanges);
1.440 raeburn 5699: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5700: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5701: undef($navmap);
1.329 droeschl 5702: if ($hadchanges) {
5703: &mark_hash_old();
5704: }
1.440 raeburn 5705: $r->print($upload_output);
5706: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5707: # Process file upload - phase two - upload embedded objects
5708: $uploadphase = 'check_embedded';
5709: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5710: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5711: $env{'form.newidx'});
5712: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5713: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5714: my ($destination,$dir_root) = &embedded_destination();
5715: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5716: my $actionurl = '/adm/coursedocs';
5717: my ($result,$flag) =
5718: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5719: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5720: $actionurl);
5721: $r->print($result.&return_to_editor());
5722: } elsif ($env{'form.phase'} eq 'check_embedded') {
5723: # Process file upload - phase three - modify references in HTML file
5724: $uploadphase = 'modified_orightml';
5725: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5726: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5727: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5728: my $result =
5729: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5730: $docuname,$docudom,undef,
5731: $dir_root);
5732: $r->print($result.&return_to_editor());
1.476 raeburn 5733: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5734: $uploadphase = 'decompress_phase_one';
5735: $r->print(&decompression_phase_one().
5736: &return_to_editor());
5737: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5738: $uploadphase = 'decompress_phase_two';
5739: $r->print(&decompression_phase_two().
5740: &return_to_editor());
1.329 droeschl 5741: }
5742: }
5743:
1.484 raeburn 5744: if ($allowed && $toolsflag) {
5745: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5746: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5747: $r->print(&endContentScreen());
5748: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5749: # -----------------------------------------------------------------------------
5750: my %lt=&Apache::lonlocal::texthash(
5751: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5752: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5753: 'upld' => 'Upload Content',
1.329 droeschl 5754: 'srch' => 'Search',
5755: 'impo' => 'Import',
1.484.2.19 raeburn 5756: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5757: 'impm' => 'Import from Assembled Map',
1.484.2.93.2. (raeburn 5758:): 'extr' => 'External Resource',
5759:): 'extt' => 'External Tool',
1.329 droeschl 5760: 'selm' => 'Select Map',
5761: 'load' => 'Load Map',
5762: 'newf' => 'New Folder',
5763: 'newp' => 'New Composite Page',
5764: 'syll' => 'Syllabus',
1.425 raeburn 5765: 'navc' => 'Table of Contents',
1.343 biermanm 5766: 'sipa' => 'Simple Course Page',
1.329 droeschl 5767: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5768: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5769: 'drbx' => 'Drop Box',
1.451 www 5770: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5771: 'bull' => 'Discussion Board',
1.347 weissno 5772: 'mypi' => 'My Personal Information Page',
1.353 weissno 5773: 'grpo' => 'Group Portfolio',
1.329 droeschl 5774: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5775: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5776: 'imsf' => 'IMS Upload',
5777: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5778: 'cms' => 'Origin of IMS package',
5779: 'se' => 'Select',
1.484.2.19 raeburn 5780: 'file' => 'File',
1.329 droeschl 5781: 'title' => 'Title',
5782: 'comment' => 'Comment',
1.403 raeburn 5783: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5784: 'bb5' => 'Blackboard 5',
5785: 'bb6' => 'Blackboard 6',
5786: 'angel5' => 'ANGEL 5.5',
5787: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5788: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5789: );
1.329 droeschl 5790: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5791: # Calculate free quota space for a user or course. A javascript function checks
5792: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5793: my $quotatype = 'unofficial';
5794: if ($crstype eq 'Community') {
5795: $quotatype = 'community';
5796: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5797: $quotatype = 'official';
5798: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5799: $quotatype = 'textbook';
5800: }
5801: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5802: 'course',$quotatype); # expressed in MB
5803: my $current_disk_usage = 0;
5804: foreach my $subdir ('docs','supplemental') {
5805: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5806: "userfiles/$subdir",1); # expressed in kB
5807: }
5808: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5809: my $usage = $current_disk_usage/1024; # in MB
5810: my $quota = $disk_quota;
5811: my $percent;
5812: if ($disk_quota == 0) {
5813: $percent = 100.0;
5814: } else {
1.484.2.69 raeburn 5815: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5816: }
5817: $usage = sprintf("%.2f",$usage);
5818: $quota = sprintf("%.2f",$quota);
5819: $percent = sprintf("%.0f",$percent);
5820: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5821: $percent.'%',$quota.' MB').'</p>';
5822:
1.329 droeschl 5823: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5824: $quotainfo
1.329 droeschl 5825: $lt{'file'}:<br />
1.484.2.81 raeburn 5826: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
5827: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5828: FIUP
5829:
5830: my $checkbox=(<<CHBO);
5831: <!-- <label>$lt{'parse'}?
5832: <input type="checkbox" name="parserflag" />
5833: </label> -->
5834: <label>
1.484.2.67 raeburn 5835: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5836: </label>
5837: CHBO
1.484.2.12 raeburn 5838: my $imsfolder = $env{'form.folder'};
5839: if ($imsfolder eq '') {
1.484.2.19 raeburn 5840: $imsfolder = 'default';
1.484.2.12 raeburn 5841: }
5842: my $imspform=(<<IMSFORM);
5843: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5844: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5845: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5846: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5847: <legend>$lt{'imsf'}</legend>
5848: $fileupload
5849: <br />
5850: <p>
1.484.2.19 raeburn 5851: $lt{'cms'}:
1.484.2.67 raeburn 5852: <select name="source" $disabled>
1.484.2.12 raeburn 5853: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5854: <option value="bb5">$lt{'bb5'}</option>
5855: <option value="bb6">$lt{'bb6'}</option>
5856: <option value="angel5">$lt{'angel5'}</option>
5857: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5858: </select>
5859: <input type="hidden" name="folder" value="$imsfolder" />
5860: </p>
5861: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5862: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5863: </fieldset>
5864: </form>
5865: IMSFORM
5866:
1.484.2.19 raeburn 5867: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5868: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5869: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5870: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5871: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5872: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5873: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5874: $fileupload
5875: <br />
5876: $lt{'title'}:<br />
1.484.2.67 raeburn 5877: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5878: $pathitem
1.329 droeschl 5879: <input type="hidden" name="cmd" value="upload_default" />
5880: <br />
1.458 raeburn 5881: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5882: $checkbox
5883: </span>
1.484.2.12 raeburn 5884: <br clear="all" />
1.484.2.67 raeburn 5885: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5886: </fieldset>
5887: </form>
1.383 tempelho 5888: FUFORM
1.329 droeschl 5889:
1.484.2.67 raeburn 5890: my $mapimportjs;
5891: if ($canedit) {
5892: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5893: } else {
5894: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5895: }
1.484.2.19 raeburn 5896: my $importpubform=(<<SEDFFORM);
5897: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5898: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5899: <form action="/adm/coursedocs" method="post" name="mapimportform">
5900: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5901: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5902: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5903: $lt{'copm'}<br />
5904: <span class="LC_nobreak">
1.484.2.19 raeburn 5905: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5906: onfocus="this.blur();$mapimportjs" $disabled />
5907: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5908: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5909: </fieldset>
5910: </form>
5911:
1.383 tempelho 5912: SEDFFORM
1.484.2.67 raeburn 5913:
5914: my $fromstoredjs;
5915: if ($canedit) {
5916: $fromstoredjs = 'open_StoredLinks_Import()';
5917: } else {
5918: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5919: }
5920:
1.484.2.19 raeburn 5921: my @importpubforma = (
5922: { '<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 5923: { '<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 5924: { '<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 5925: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5926: );
5927: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5928: my $extresourcesform =
5929: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5930: $help{'Adding_External_Resource'},
1.484.2.93.2. (raeburn 5931:): undef,undef,undef,undef,undef,undef,$disabled);
5932:): my $exttoolform =
5933:): &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5934:): $help{'Adding_External_Tool'},undef,
5935:): undef,'tool',$coursedom,$coursenum,
5936:): \%ltitools,$disabled);
1.329 droeschl 5937: if ($allowed) {
1.484.2.7 raeburn 5938: my $folder = $env{'form.folder'};
5939: if ($folder eq '') {
5940: $folder='default';
5941: }
1.484.2.67 raeburn 5942: if ($canedit) {
5943: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5944: if ($output) {
5945: $r->print($output);
5946: }
1.484.2.30 raeburn 5947: }
1.337 ehlerst 5948: $r->print(<<HIDDENFORM);
5949: <form name="renameform" method="post" action="/adm/coursedocs">
5950: <input type="hidden" name="title" />
5951: <input type="hidden" name="cmd" />
5952: <input type="hidden" name="markcopy" />
5953: <input type="hidden" name="copyfolder" />
5954: $containertag
5955: </form>
1.484 raeburn 5956:
1.337 ehlerst 5957: HIDDENFORM
1.484.2.17 raeburn 5958: $r->print(&makesimpleeditform($pathitem)."\n".
5959: &makedocslogform($pathitem."\n".
1.484 raeburn 5960: '<input type="hidden" name="folder" value="'.
5961: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5962: }
1.442 www 5963:
5964: # Generate the tabs
1.484.2.19 raeburn 5965: my ($mode,$needs_end);
1.472 raeburn 5966: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5967: my @folders = split('&',$env{'form.folderpath'});
5968: unless (@folders > 2) {
5969: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5970: $needs_end = 1;
5971: }
1.472 raeburn 5972: } else {
1.484 raeburn 5973: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5974: $needs_end = 1;
1.472 raeburn 5975: }
1.443 www 5976:
1.442 www 5977: #
5978:
5979: my $savefolderpath;
1.484.2.86 raeburn 5980: my $hostname = $r->hostname();
1.442 www 5981:
1.395 raeburn 5982: if ($allowed) {
1.329 droeschl 5983: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5984: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5985: $folder='default';
1.356 tempelho 5986: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5987: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5988: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5989: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5990: }
5991: my $postexec='';
5992: if ($folder eq 'default') {
1.372 bisitz 5993: $r->print('<script type="text/javascript">'."\n"
5994: .'// <![CDATA['."\n"
5995: .'this.window.name="loncapaclient";'."\n"
5996: .'// ]]>'."\n"
5997: .'</script>'."\n"
1.369 bisitz 5998: );
1.329 droeschl 5999: } else {
6000: #$postexec='self.close();';
6001: }
1.484.2.15 raeburn 6002: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6003: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6004: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6005:
6006: my $newnavform=(<<NNFORM);
6007: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 6008: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6009: $pathitem
1.329 droeschl 6010: <input type="hidden" name="importdetail"
6011: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 6012: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6013: $help{'Navigate_Content'}
6014: </form>
6015: NNFORM
6016: my $newsmppageform=(<<NSPFORM);
6017: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 6018: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6019: $pathitem
1.329 droeschl 6020: <input type="hidden" name="importdetail" value="" />
1.423 onken 6021: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6022: $help{'Simple Page'}
1.329 droeschl 6023: </form>
6024: NSPFORM
6025:
6026: my $newsmpproblemform=(<<NSPROBFORM);
6027: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 6028: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6029: $pathitem
1.329 droeschl 6030: <input type="hidden" name="importdetail" value="" />
1.423 onken 6031: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 6032: $help{'Simple_Problem'}
1.329 droeschl 6033: </form>
6034:
6035: NSPROBFORM
6036:
6037: my $newdropboxform=(<<NDBFORM);
6038: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 6039: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6040: $pathitem
1.329 droeschl 6041: <input type="hidden" name="importdetail" value="" />
1.423 onken 6042: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 6043: $help{'Dropbox'}
1.344 bisitz 6044: </form>
1.329 droeschl 6045: NDBFORM
6046:
6047: my $newexuploadform=(<<NEXUFORM);
6048: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 6049: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6050: $pathitem
1.329 droeschl 6051: <input type="hidden" name="importdetail" value="" />
1.423 onken 6052: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6053: $help{'Score_Upload_Form'}
6054: </form>
6055: NEXUFORM
6056:
6057: my $newbulform=(<<NBFORM);
6058: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 6059: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6060: $pathitem
1.329 droeschl 6061: <input type="hidden" name="importdetail" value="" />
1.423 onken 6062: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6063: $help{'Bulletin Board'}
6064: </form>
6065: NBFORM
6066:
6067: my $newaboutmeform=(<<NAMFORM);
6068: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 6069: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6070: $pathitem
1.329 droeschl 6071: <input type="hidden" name="importdetail"
6072: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6073: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6074: $help{'My Personal Information Page'}
1.329 droeschl 6075: </form>
6076: NAMFORM
6077:
6078: my $newaboutsomeoneform=(<<NASOFORM);
6079: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 6080: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6081: $pathitem
1.329 droeschl 6082: <input type="hidden" name="importdetail" value="" />
1.423 onken 6083: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6084: </form>
6085: NASOFORM
6086:
6087: my $newrosterform=(<<NROSTFORM);
6088: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 6089: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6090: $pathitem
1.329 droeschl 6091: <input type="hidden" name="importdetail"
6092: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 6093: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 6094: $help{'Course_Roster'}
1.329 droeschl 6095: </form>
6096: NROSTFORM
6097:
1.484.2.27 raeburn 6098: my $newwebpage;
6099: if ($folder =~ /^default_?(\d*)$/) {
6100: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6101: if ($1) {
6102: $newwebpage .= $1;
6103: } else {
6104: $newwebpage .= 'default';
6105: }
6106: $newwebpage .= '/new.html';
6107: }
6108: my $newwebpageform =(<<NWEBFORM);
6109: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 6110: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 6111: $pathitem
6112: <input type="hidden" name="importdetail" value="$newwebpage" />
6113: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 6114: $help{'Web_Page'}
1.484.2.27 raeburn 6115: </form>
6116: NWEBFORM
1.484.2.30 raeburn 6117:
1.484.2.27 raeburn 6118:
1.342 ehlerst 6119: my $specialdocumentsform;
1.383 tempelho 6120: my @specialdocumentsforma;
1.451 www 6121: my $gradingform;
6122: my @gradingforma;
6123: my $communityform;
6124: my @communityforma;
1.351 ehlerst 6125: my $newfolderform;
1.390 tempelho 6126: my $newfolderb;
1.342 ehlerst 6127:
1.451 www 6128: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6129:
1.329 droeschl 6130: my $newpageform=(<<NPFORM);
6131: <form action="/adm/coursedocs" method="post" name="newpage">
6132: <input type="hidden" name="folderpath" value="$path" />
6133: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6134: <input type="hidden" name="active" value="ee" />
1.423 onken 6135: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6136: $help{'Adding_Pages'}
1.329 droeschl 6137: </form>
6138: NPFORM
1.390 tempelho 6139:
6140:
1.351 ehlerst 6141: $newfolderform=(<<NFFORM);
1.329 droeschl 6142: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 6143: $pathitem
1.329 droeschl 6144: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6145: <input type="hidden" name="active" value="" />
1.422 onken 6146: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6147: </form>
6148: NFFORM
6149:
6150: my $newsylform=(<<NSYLFORM);
6151: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 6152: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6153: $pathitem
1.329 droeschl 6154: <input type="hidden" name="importdetail"
6155: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6156: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6157: $help{'Syllabus'}
1.383 tempelho 6158:
1.329 droeschl 6159: </form>
6160: NSYLFORM
1.364 bisitz 6161:
1.329 droeschl 6162: my $newgroupfileform=(<<NGFFORM);
6163: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 6164: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6165: $pathitem
1.329 droeschl 6166: <input type="hidden" name="importdetail"
6167: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 6168: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6169: $help{'Group Portfolio'}
1.329 droeschl 6170: </form>
6171: NGFFORM
1.484.2.89 raeburn 6172: if ($container eq 'page') {
6173: @specialdocumentsforma=(
6174: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6175: );
6176: } else {
6177: @specialdocumentsforma=(
1.421 onken 6178: {'<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 6179: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6180: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6181: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 6182: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.484.2.89 raeburn 6183: );
6184: }
1.451 www 6185: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6186:
1.434 raeburn 6187:
6188: my @importdoc = (
1.484.2.19 raeburn 6189: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6190: );
1.484.2.93.2. (raeburn 6191:): if (keys(%ltitools)) {
6192:): push(@importdoc,
6193:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6194:): );
6195:): }
1.484.2.19 raeburn 6196: unless ($container eq 'page') {
6197: push(@importdoc,
6198: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6199: );
6200: }
6201: push(@importdoc,
1.484.2.38 raeburn 6202: {'<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 6203: );
1.484.2.12 raeburn 6204: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6205:
1.451 www 6206: @gradingforma=(
6207: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6208: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6209: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6210:
6211: );
6212: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6213:
6214: @communityforma=(
6215: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6216: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6217: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 6218: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6219: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6220: );
6221: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6222:
1.330 tempelho 6223: my %orderhash = (
1.484.2.36 raeburn 6224: 'aa' => ['Upload',$fileuploadform],
6225: 'bb' => ['Import',$importpubform],
6226: 'cc' => ['Grading',$gradingform],
1.484.2.89 raeburn 6227: 'ee' => ['Other',$specialdocumentsform],
1.330 tempelho 6228: );
1.484.2.19 raeburn 6229: unless ($container eq 'page') {
1.434 raeburn 6230: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6231: $orderhash{'dd'} = ['Collaboration',$communityform];
1.434 raeburn 6232: }
6233:
1.341 ehlerst 6234: $hadchanges=0;
1.484 raeburn 6235: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6236: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6237: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.93.2. (raeburn 6238:): \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 6239: undef($navmap);
1.443 www 6240: if ($error) {
6241: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6242: }
6243: if ($hadchanges) {
1.484.2.73 raeburn 6244: unless (&is_hash_old()) {
6245: &mark_hash_old();
6246: }
1.443 www 6247: }
1.341 ehlerst 6248:
1.443 www 6249: &changewarning($r,'');
6250: }
1.458 raeburn 6251: }
1.442 www 6252:
1.443 www 6253: # Supplemental documents start here
6254:
1.329 droeschl 6255: my $folder=$env{'form.folder'};
1.443 www 6256: unless ($supplementalflag) {
1.329 droeschl 6257: $folder='supplemental';
6258: }
6259: if ($folder =~ /^supplemental$/ &&
6260: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6261: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6262: } elsif ($allowed) {
1.356 tempelho 6263: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6264: }
1.484.2.17 raeburn 6265: $pathitem = '<input type="hidden" name="folderpath" value="'.
6266: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6267: if ($allowed) {
6268: my $folderseq=
1.484.2.15 raeburn 6269: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6270:
6271: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 6272: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6273: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6274: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6275: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6276: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6277: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6278: $fileupload
6279: <br />
6280: <br />
6281: <span class="LC_nobreak">
6282: $checkbox
6283: </span>
6284: <br /><br />
6285: $lt{'comment'}:<br />
1.383 tempelho 6286: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6287: <br />
1.484.2.19 raeburn 6288: $pathitem
1.329 droeschl 6289: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6290: <input type='submit' value="$lt{'upld'}" />
6291: </form>
1.484.2.19 raeburn 6292: SUPDOCFORM
1.329 droeschl 6293:
6294: my $supnewfolderform=(<<SNFFORM);
6295: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6296: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6297: $pathitem
1.329 droeschl 6298: <input type="hidden" name="importdetail" value="" />
1.423 onken 6299: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6300: $help{'Adding_Folders'}
1.329 droeschl 6301: </form>
6302: SNFFORM
1.383 tempelho 6303:
1.484.2.19 raeburn 6304: my $supextform =
6305: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6306: $help{'Adding_External_Resource'},
6307: undef,undef,$disabled);
1.484.2.93.2. (raeburn 6308:): my $supexttoolform =
6309:): &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6310:): $help{'Adding_External_Tool'},
6311:): undef,undef,'tool',$coursedom,
6312:): $coursenum,\%ltitools,$disabled);
1.329 droeschl 6313:
6314: my $supnewsylform=(<<SNSFORM);
6315: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6316: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6317: $pathitem
1.329 droeschl 6318: <input type="hidden" name="importdetail"
6319: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6320: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6321: $help{'Syllabus'}
6322: </form>
6323: SNSFORM
6324:
6325: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6326: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6327: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6328: $pathitem
1.329 droeschl 6329: <input type="hidden" name="importdetail"
6330: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6331: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6332: $help{'My Personal Information Page'}
1.329 droeschl 6333: </form>
6334: SNAMFORM
6335:
1.484.2.27 raeburn 6336: my $supwebpage;
6337: if ($folder =~ /^supplemental_?(\d*)$/) {
6338: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6339: if ($1) {
6340: $supwebpage .= $1;
6341: } else {
6342: $supwebpage .= 'default';
6343: }
6344: $supwebpage .= '/new.html';
6345: }
6346: my $supwebpageform =(<<SWEBFORM);
6347: <form action="/adm/coursedocs" method="post" name="supwebpage">
6348: <input type="hidden" name="active" value="cc" />
6349: $pathitem
6350: <input type="hidden" name="importdetail" value="$supwebpage" />
6351: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6352: $help{'Web_Page'}
1.484.2.27 raeburn 6353: </form>
6354: SWEBFORM
6355:
1.333 muellerd 6356:
1.383 tempelho 6357: my @specialdocs = (
1.484.2.67 raeburn 6358: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6359: =>$supnewsylform},
1.484.2.67 raeburn 6360: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6361: =>$supnewaboutmeform},
1.484.2.27 raeburn 6362: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6363:
1.383 tempelho 6364: );
1.417 droeschl 6365: my @supimportdoc = (
1.484.2.19 raeburn 6366: {'<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 6367:): =>$supextform});
6368:): if (keys(%ltitools)) {
6369:): push(@supimportdoc,
6370:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6371:): =>$supexttoolform});
6372:): }
6373:): push(@supimportdoc,
1.484.2.12 raeburn 6374: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6375: =>$supupdocform},
1.484.2.93.2. (raeburn 6376:): );
1.484.2.19 raeburn 6377:
1.484.2.12 raeburn 6378: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6379: my %suporderhash = (
1.390 tempelho 6380: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6381: 'ee' => ['Upload',$supupdocform],
6382: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6383: );
1.443 www 6384: if ($supplementalflag) {
1.458 raeburn 6385: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6386: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.484.2.93.2. (raeburn 6387:): \%ltitools,$canedit,$hostname);
1.443 www 6388: if ($error) {
6389: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6390: } else {
6391: if ($suppchanges) {
6392: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6393: my @ids=&Apache::lonnet::current_machine_ids();
6394: foreach my $server (keys(%servers)) {
6395: next if (grep(/^\Q$server\E$/,@ids));
6396: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6397: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6398: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6399: }
6400: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6401: undef($suppchanges);
6402: }
1.443 www 6403: }
1.393 raeburn 6404: }
1.443 www 6405: } elsif ($supplementalflag) {
1.458 raeburn 6406: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.85 raeburn 6407: $supplementalflag,'',$iconpath,$pathitem,'',$hostname);
1.393 raeburn 6408: if ($error) {
6409: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6410: }
1.393 raeburn 6411: }
1.389 tempelho 6412:
1.484.2.19 raeburn 6413: if ($needs_end) {
6414: $r->print(&endContentScreen());
6415: }
1.383 tempelho 6416:
1.329 droeschl 6417: if ($allowed) {
6418: $r->print('
6419: <form method="post" name="extimport" action="/adm/coursedocs">
6420: <input type="hidden" name="title" />
6421: <input type="hidden" name="url" />
6422: <input type="hidden" name="useform" />
6423: <input type="hidden" name="residx" />
6424: </form>');
6425: }
1.484 raeburn 6426: } elsif ($showdoc) {
1.329 droeschl 6427: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6428: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6429: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6430: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6431: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6432: }
6433: }
6434: $r->print(&Apache::loncommon::end_page());
6435: return OK;
1.364 bisitz 6436: }
1.329 droeschl 6437:
1.440 raeburn 6438: sub embedded_form_elems {
6439: my ($phase,$primaryurl,$newidx) = @_;
6440: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6441: $newidx =~s /\D+//g;
1.440 raeburn 6442: return <<STATE;
6443: <input type="hidden" name="folderpath" value="$folderpath" />
6444: <input type="hidden" name="cmd" value="upload_embedded" />
6445: <input type="hidden" name="newidx" value="$newidx" />
6446: <input type="hidden" name="phase" value="$phase" />
6447: <input type="hidden" name="primaryurl" value="$primaryurl" />
6448: STATE
6449: }
6450:
6451: sub embedded_destination {
6452: my $folder=$env{'form.folder'};
6453: my $destination = 'docs/';
6454: if ($folder =~ /^supplemental/) {
6455: $destination = 'supplemental/';
6456: }
6457: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6458: $destination .= 'default/';
6459: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6460: $destination .= $2.'/';
6461: }
1.484.2.78 raeburn 6462: my $newidx = $env{'form.newidx'};
6463: $newidx =~s /\D+//g;
6464: if ($newidx) {
6465: $destination .= $newidx;
6466: }
1.440 raeburn 6467: my $dir_root = '/userfiles';
6468: return ($destination,$dir_root);
6469: }
6470:
6471: sub return_to_editor {
6472: my $actionurl = '/adm/coursedocs';
6473: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6474: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6475: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6476: '</a></p>';
6477: }
6478:
1.476 raeburn 6479: sub decompression_info {
6480: my ($destination,$dir_root) = &embedded_destination();
6481: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6482: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6483: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6484: my $container='sequence';
1.480 raeburn 6485: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6486: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6487: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6488: $container='page';
6489: }
1.480 raeburn 6490: unshift(@hiddens,$pathitem);
6491: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6492: if ($item eq 'newidx') {
6493: next if ($env{'form.'.$item} =~ /\D/);
6494: }
1.480 raeburn 6495: if ($env{'form.'.$item}) {
6496: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6497: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6498: }
1.477 raeburn 6499: }
1.476 raeburn 6500: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6501: $hiddenelem);
6502: }
6503:
6504: sub decompression_phase_one {
6505: my ($dir,$file,$warning,$error,$output);
6506: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6507: &decompression_info();
1.484.2.7 raeburn 6508: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6509: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6510: } else {
6511: my $file = $1;
1.481 raeburn 6512: $output =
6513: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6514: $destination,$dir_root,
6515: $hiddenelem);
6516: if ($env{'form.autoextract_camtasia'}) {
6517: $output .= &remove_archive($docudom,$docuname,$container);
6518: }
1.476 raeburn 6519: }
6520: if ($error) {
6521: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6522: $error.'</p>'."\n";
6523: }
6524: if ($warning) {
6525: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6526: }
6527: return $output;
6528: }
6529:
6530: sub decompression_phase_two {
6531: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6532: &decompression_info();
1.481 raeburn 6533: my $output;
1.480 raeburn 6534: if ($env{'form.archivedelete'}) {
1.481 raeburn 6535: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6536: }
6537: $output .=
1.481 raeburn 6538: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6539: $destination,$dir_root,$hiddenelem);
6540: return $output;
6541: }
6542:
1.480 raeburn 6543: sub remove_archive {
6544: my ($docudom,$docuname,$container) = @_;
6545: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6546: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6547: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6548: if ($fatal) {
6549: if ($container eq 'page') {
6550: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6551: } else {
6552: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6553: }
1.484.2.54 raeburn 6554: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6555: } else {
6556: my $currcmd = $env{'form.cmd'};
6557: my $position = $env{'form.position'};
1.484.2.54 raeburn 6558: my $archiveidx = $position;
6559: if ($position > 0) {
6560: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6561: $archiveidx = $position-1;
6562: }
6563: $env{'form.cmd'} = 'remove_'.$archiveidx;
6564: my ($title,$url,@rrest) =
6565: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6566: if ($url eq $env{'form.archiveurl'}) {
6567: if (&handle_edit_cmd($docuname,$docudom)) {
6568: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6569: if ($fatal) {
6570: if ($container eq 'page') {
6571: $delwarning = &mt('An error occurred updating the contents of the current page.');
6572: } else {
6573: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6574: }
1.480 raeburn 6575: } else {
1.484.2.54 raeburn 6576: $delresult = &mt('Archive file removed.');
1.480 raeburn 6577: }
6578: }
1.484.2.54 raeburn 6579: } else {
6580: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6581: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6582: }
6583: }
6584: $env{'form.cmd'} = $currcmd;
6585: }
6586: if ($delwarning) {
6587: $output = '<p class="LC_warning">'.
6588: $delwarning.
6589: '</p>';
6590: }
6591: if ($delresult) {
6592: $output .= '<p class="LC_info">'.
6593: $delresult.
6594: '</p>';
6595: }
1.481 raeburn 6596: return $output;
1.480 raeburn 6597: }
6598:
1.484 raeburn 6599: sub generate_admin_menu {
1.484.2.67 raeburn 6600: my ($crstype,$canedit) = @_;
1.484 raeburn 6601: my $lc_crstype = lc($crstype);
6602: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6603: my %lt= ( # do not translate here
1.484 raeburn 6604: 'vc' => 'Verify Content',
6605: 'cv' => 'Check/Set Resource Versions',
6606: 'ls' => 'List Resource Identifiers',
1.484.2.93.2. (raeburn 6607:): 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 6608: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6609: 'dcd' => "Copy $crstype Content to Authoring Space",
6610: );
1.484 raeburn 6611: my ($candump,$dumpurl);
6612: if ($home + $other > 0) {
6613: $candump = 'F';
6614: if ($home) {
6615: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6616: } else {
6617: my @hosts;
6618: foreach my $aurole (keys(%outhash)) {
6619: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6620: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6621: }
1.484 raeburn 6622: }
6623: if (@hosts == 1) {
6624: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6625: '&role='.
6626: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6627: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6628: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6629: } else {
6630: $dumpurl = "javascript:choose_switchserver_window()";
6631: }
6632: }
6633: }
6634: my @menu=
6635: ({ categorytitle=>'Administration',
6636: items =>[
6637: { linktext => $lt{'vc'},
6638: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6639: permission => 'F',
1.484.2.44 raeburn 6640: help => 'Docs_Verify_Content',
1.484 raeburn 6641: icon => 'verify.png',
6642: linktitle => 'Verify contents can be retrieved/rendered',
6643: },
6644: { linktext => $lt{'cv'},
6645: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6646: permission => 'F',
1.484.2.44 raeburn 6647: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6648: icon => 'resversion.png',
6649: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6650: },
6651: { linktext => $lt{'ls'},
6652: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6653: permission => 'F',
6654: #help => '',
6655: icon => 'symbs.png',
6656: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6657: },
1.484.2.93.2. (raeburn 6658:): { linktext => $lt{'ct'},
6659:): url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
6660:): permission => 'F',
6661:): help => 'Docs_Short_URLs',
6662:): icon => 'shorturls.png',
6663:): linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
6664:): },
1.484 raeburn 6665: ]
1.484.2.67 raeburn 6666: });
6667: if ($canedit) {
6668: push(@menu,
1.484 raeburn 6669: { categorytitle=>'Export',
6670: items =>[
6671: { linktext => $lt{'imse'},
6672: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6673: permission => 'F',
6674: help => 'Docs_Export_Course_Docs',
6675: icon => 'imsexport.png',
6676: linktitle => $lt{'imse'},
6677: },
6678: { linktext => $lt{'dcd'},
6679: url => $dumpurl,
6680: permission => $candump,
1.484.2.44 raeburn 6681: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6682: icon => 'dump.png',
6683: linktitle => $lt{'dcd'},
6684: },
6685: ]
6686: });
1.484.2.67 raeburn 6687: }
1.484 raeburn 6688: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6689: '<input type="hidden" id="dummy" />'."\n".
6690: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6691: '</form>';
1.329 droeschl 6692: }
6693:
6694: sub generate_edit_table {
1.484.2.30 raeburn 6695: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6696: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6697: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6698: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6699: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6700: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6701: $activetab = $env{'form.active'};
6702: }
1.484.2.67 raeburn 6703: unless ($canedit) {
6704: $disabled = ' disabled="disabled"';
6705: }
1.472 raeburn 6706: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6707: my $backtext = &mt('Exit Editor');
1.458 raeburn 6708: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6709: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6710: '<li class="goback">'.
1.484.2.32 raeburn 6711: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6712: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6713: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6714: '<li>'.
6715: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6716: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6717: if ($env{'form.docslog'}) {
6718: $form .= '<li class="active">';
6719: } else {
6720: $form .= '<li>';
6721: }
6722: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6723: &mt('History').'</a></li>'."\n";
6724: if ($env{'form.docslog'}) {
6725: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6726: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6727: }
1.458 raeburn 6728: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6729: if($name ne '00'){
1.371 tempelho 6730: if($activetab eq '' || $activetab ne $name){
6731: $active = '';
6732: }elsif($activetab eq $name){
6733: $active = 'class="active"';
6734: }
1.458 raeburn 6735: $form .= '<li style="float:right" '.$active
1.484 raeburn 6736: .' 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 6737: } else {
1.484.2.43 raeburn 6738: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6739:
6740: }
1.329 droeschl 6741: }
1.484 raeburn 6742: $form .= '</ul>'."\n";
6743: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6744:
6745: if ($to_show ne '') {
1.484.2.30 raeburn 6746: my $saveform;
6747: if ($need_save) {
6748: my $button = &mt('Make changes');
6749: my $path;
6750: if ($env{'form.folderpath'}) {
6751: $path =
6752: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6753: }
6754: $saveform = <<"END";
6755: <div id="multisave" style="display:none; clear:both;" >
6756: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6757: <input type="hidden" name="folderpath" value="$path" />
6758: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6759: <input type="hidden" name="allhiddenresource" value="" />
6760: <input type="hidden" name="allencrypturl" value="" />
6761: <input type="hidden" name="allrandompick" value="" />
6762: <input type="hidden" name="allrandomorder" value="" />
6763: <input type="hidden" name="changeparms" value="" />
6764: <input type="hidden" name="multiremove" value="" />
6765: <input type="hidden" name="multicut" value="" />
6766: <input type="hidden" name="multicopy" value="" />
6767: <input type="hidden" name="multichange" value="" />
6768: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6769: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6770: </form>
6771: </div>
6772: END
6773: }
6774: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6775: }
1.363 ehlerst 6776: foreach my $field (keys(%orderhash)){
1.390 tempelho 6777: if($field ne '00'){
1.422 onken 6778: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6779: $active = 'style="display: none;float:left"';
1.422 onken 6780: }elsif($activetab eq $field){
1.458 raeburn 6781: $active = 'style="display:block;float:left"';
1.422 onken 6782: }
6783: $form .= '<div id="'.$field.$tid.'"'
6784: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6785: .'</div>'."\n";
1.363 ehlerst 6786: }
6787: }
1.484 raeburn 6788: unless ($env{'form.docslog'}) {
6789: $form .= '</div></div>'."\n";
6790: }
1.329 droeschl 6791: return $form;
6792: }
6793:
6794: sub editing_js {
1.484.2.93.2. (raeburn 6795:): my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 6796: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6797: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6798: p_mnf => 'Name of New Folder',
6799: t_mnf => 'New Folder',
6800: p_mnp => 'Name of New Page',
6801: t_mnp => 'New Page',
1.451 www 6802: p_mxu => 'Title for the External Score',
1.349 biermanm 6803: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6804: p_msb => 'Title for the Problem',
6805: p_mdb => 'Title for the Drop Box',
1.336 schafran 6806: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6807: p_mwp => 'Title for Web Page',
1.348 weissno 6808: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6809: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6810: p_mab_alrt1 => 'Not a valid user:domain',
6811: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6812: p_chn => 'New Title',
6813: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6814: p_rmr2a => 'Remove',
6815: p_rmr2b => '?',
6816: p_rmr3a => 'Remove those',
6817: p_rmr3b => 'items?',
6818: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6819: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6820: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6821: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6822: p_ctr2a => 'Cut',
6823: p_ctr2b => '?',
6824: p_ctr3a => 'Cut those',
6825: p_ctr3b => 'items?',
1.478 raeburn 6826: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6827: imsfile => 'You must choose an IMS package for import',
6828: imscms => 'You must select which Course Management System was the source of the IMS package',
6829: invurl => 'Invalid URL',
6830: titbl => 'Title is blank',
1.484.2.30 raeburn 6831: more => '(More ...)',
6832: less => '(Less ...)',
6833: noor => 'No actions selected or changes to settings specified.',
6834: noch => 'No changes to settings specified.',
6835: noac => 'No actions selected.',
1.484.2.67 raeburn 6836: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6837: );
6838:
1.484.2.61 raeburn 6839: &js_escape(\%js_lt);
1.433 raeburn 6840: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6841: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6842: my $main_container_page;
1.484.2.19 raeburn 6843: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6844: $main_container_page = 1;
1.434 raeburn 6845: }
1.484.2.67 raeburn 6846: my $backtourl;
6847: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6848: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6849:
1.484.2.21 raeburn 6850: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6851: my $caller = $1;
6852: if ($caller =~ /^supplemental/) {
6853: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6854: } else {
6855: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6856: $res = &Apache::lonnet::clutter($res);
6857: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6858: my ($url,$anchor);
6859: if ($res =~ /^([^#]+)#([^#]+)$/) {
6860: $url = $1;
6861: $anchor = $2;
6862: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6863: $caller = $1.&escape('#').$anchor;
6864: }
1.484.2.67 raeburn 6865: } else {
6866: $url = $res;
1.484.2.66 raeburn 6867: }
1.484.2.83 raeburn 6868: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
6869: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
6870: $backtourl .= '?navmap=1';
6871: } else {
6872: $backtourl .= '?symb='.
6873: &HTML::Entities::encode($caller,'<>&"');
6874: }
1.484.2.80 raeburn 6875: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6876: if (($ENV{'SERVER_PORT'} == 443) &&
6877: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 6878: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 6879: if ($hostname ne '') {
6880: $backtourl = 'http://'.$hostname.$backtourl;
6881: }
6882: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6883: }
6884: }
6885: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6886: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.484.2.93 raeburn 6887: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 6888: if ($hostname ne '') {
6889: $backtourl = 'http://'.$hostname.$backtourl;
6890: }
6891: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6892: }
6893: }
6894: }
1.484.2.66 raeburn 6895: if ($anchor ne '') {
6896: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6897: }
1.484.2.57 raeburn 6898: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6899: } else {
6900: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6901: }
6902: }
6903: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6904: $backtourl = '/adm/menu';
6905: } elsif ($supplementalflag) {
1.472 raeburn 6906: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6907: } else {
6908: $backtourl = '/adm/navmaps';
1.472 raeburn 6909: }
6910:
1.484.2.19 raeburn 6911: my $fieldsets = "'ext','doc'";
1.484.2.93.2. (raeburn 6912:): if ($posslti) {
6913:): $fieldsets .= ",'tool'";
6914:): }
1.484.2.19 raeburn 6915: unless ($main_container_page) {
6916: $fieldsets .=",'ims'";
6917: }
1.484.2.12 raeburn 6918: if ($supplementalflag) {
6919: $fieldsets = "'suppext','suppdoc'";
1.484.2.93.2. (raeburn 6920:): if ($posslti) {
6921:): $fieldsets .= ",'supptool'";
6922:): }
1.484.2.12 raeburn 6923: }
6924:
1.484.2.67 raeburn 6925: my $jsmakefunctions;
6926: if ($canedit) {
6927: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6928: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6929: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6930: if (foldername) {
1.484.2.91 raeburn 6931: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 6932: targetform.submit();
6933: }
6934: }
6935:
6936: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6937: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6938: if (pagename) {
1.484.2.91 raeburn 6939: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 6940: targetform.submit();
6941: }
6942: }
6943:
6944: function makeexamupload() {
1.484.2.61 raeburn 6945: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6946: if (title) {
1.329 droeschl 6947: this.document.forms.newexamupload.importdetail.value=
1.484.2.91 raeburn 6948: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 6949: this.document.forms.newexamupload.submit();
6950: }
6951: }
6952:
6953: function makesmppage() {
1.484.2.61 raeburn 6954: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6955: if (title) {
1.329 droeschl 6956: this.document.forms.newsmppg.importdetail.value=
1.484.2.91 raeburn 6957: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6958: this.document.forms.newsmppg.submit();
6959: }
6960: }
6961:
1.484.2.27 raeburn 6962: function makewebpage(type) {
1.484.2.61 raeburn 6963: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6964: var formname;
6965: if (type == 'supp') {
6966: formname = this.document.forms.supwebpage;
6967: } else {
6968: formname = this.document.forms.newwebpage;
6969: }
6970: if (title) {
6971: var webpage = formname.importdetail.value;
1.484.2.91 raeburn 6972: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.484.2.27 raeburn 6973: formname.submit();
6974: }
6975: }
6976:
1.329 droeschl 6977: function makesmpproblem() {
1.484.2.61 raeburn 6978: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6979: if (title) {
1.329 droeschl 6980: this.document.forms.newsmpproblem.importdetail.value=
1.484.2.91 raeburn 6981: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 6982: this.document.forms.newsmpproblem.submit();
6983: }
6984: }
6985:
6986: function makedropbox() {
1.484.2.61 raeburn 6987: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6988: if (title) {
1.329 droeschl 6989: this.document.forms.newdropbox.importdetail.value=
1.484.2.91 raeburn 6990: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 6991: this.document.forms.newdropbox.submit();
6992: }
6993: }
6994:
6995: function makebulboard() {
1.484.2.61 raeburn 6996: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6997: if (title) {
6998: this.document.forms.newbul.importdetail.value=
1.484.2.91 raeburn 6999: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7000: this.document.forms.newbul.submit();
7001: }
7002: }
7003:
7004: function makeabout() {
1.484.2.61 raeburn 7005: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7006: if (user) {
7007: var comp=new Array();
7008: comp=user.split(':');
7009: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7010: if ((comp[0]) && (comp[1])) {
7011: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 7012: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 7013: this.document.forms.newaboutsomeone.submit();
7014: } else {
7015: alert("$js_lt{'p_mab_alrt1'}");
7016: }
7017: } else {
7018: alert("$js_lt{'p_mab_alrt2'}");
7019: }
7020: }
1.335 ehlerst 7021: }
1.484.2.67 raeburn 7022:
7023: function makenew(targetform) {
7024: targetform.submit();
1.335 ehlerst 7025: }
1.484.2.67 raeburn 7026:
7027: function changename(folderpath,index,oldtitle) {
7028: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7029: if (title) {
7030: this.document.forms.renameform.markcopy.value='';
7031: this.document.forms.renameform.title.value=title;
7032: this.document.forms.renameform.cmd.value='rename_'+index;
7033: this.document.forms.renameform.folderpath.value=folderpath;
7034: this.document.forms.renameform.submit();
7035: }
1.329 droeschl 7036: }
7037:
1.484.2.67 raeburn 7038: ENDNEWSCRIPT
7039: } else {
7040: $jsmakefunctions = <<ENDNEWSCRIPT;
7041:
7042: function makenewfolder() {
7043: alert("$js_lt{'edri'}");
7044: }
7045:
7046: function makenewpage() {
7047: alert("$js_lt{'edri'}");
7048: }
7049:
7050: function makeexamupload() {
7051: alert("$js_lt{'edri'}");
7052: }
7053:
7054: function makesmppage() {
7055: alert("$js_lt{'edri'}");
7056: }
7057:
7058: function makewebpage(type) {
7059: alert("$js_lt{'edri'}");
7060: }
7061:
7062: function makesmpproblem() {
7063: alert("$js_lt{'edri'}");
7064: }
7065:
7066: function makedropbox() {
7067: alert("$js_lt{'edri'}");
7068: }
7069:
7070: function makebulboard() {
7071: alert("$js_lt{'edri'}");
7072: }
7073:
7074: function makeabout() {
7075: alert("$js_lt{'edri'}");
7076: }
7077:
7078: function changename() {
7079: alert("$js_lt{'edri'}");
7080: }
7081:
7082: function makenew() {
7083: alert("$js_lt{'edri'}");
7084: }
7085:
7086: function groupimport() {
7087: alert("$js_lt{'edri'}");
7088: }
7089:
7090: function groupsearch() {
7091: alert("$js_lt{'edri'}");
7092: }
7093:
7094: function groupopen(url,recover) {
7095: var options="scrollbars=1,resizable=1,menubar=0";
7096: idxflag=1;
7097: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7098: idx.focus();
7099: }
7100:
7101: ENDNEWSCRIPT
7102:
7103: }
7104: return <<ENDSCRIPT;
7105:
7106: $jsmakefunctions
7107:
1.484.2.13 raeburn 7108: function toggleUpload(caller) {
7109: var blocks = Array($fieldsets);
7110: for (var i=0; i<blocks.length; i++) {
7111: var disp = 'none';
7112: if (caller == blocks[i]) {
7113: var curr = document.getElementById('upload'+caller+'form').style.display;
7114: if (curr == 'none') {
7115: disp='block';
7116: }
7117: }
7118: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.484.2.93.2. (raeburn 7119:): if ((caller == 'tool') || (caller == 'supptool')) {
7120:): if (disp == 'block') {
7121:): if (document.getElementById('LC_exttoolid')) {
7122:): var toolselector = document.getElementById('LC_exttoolid');
7123:): var suppflag = 0;
7124:): if (caller == 'supptool') {
7125:): suppflag = 1;
7126:): }
7127:): currForm = document.getElementById('new'+caller);
7128:): updateExttool(toolselector,currForm,suppflag);
7129:): }
7130:): }
7131:): }
1.484.2.13 raeburn 7132: }
7133: resize_scrollbox('contentscroll','1','1');
7134: return;
7135: }
7136:
1.484.2.19 raeburn 7137: function toggleMap(caller) {
1.484.2.13 raeburn 7138: var disp = 'none';
1.484.2.19 raeburn 7139: if (document.getElementById('importmapform')) {
7140: if (caller == 'map') {
7141: var curr = document.getElementById('importmapform').style.display;
7142: if (curr == 'none') {
7143: disp='block';
7144: }
1.484.2.12 raeburn 7145: }
1.484.2.19 raeburn 7146: document.getElementById('importmapform').style.display=disp;
7147: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 7148: }
1.484.2.19 raeburn 7149: return;
1.329 droeschl 7150: }
7151:
1.484.2.12 raeburn 7152: function makeims(imsform) {
7153: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 7154: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 7155: return;
7156: }
7157: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 7158: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 7159: return;
7160: }
7161: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7162: imsform.submit();
7163: }
7164:
1.478 raeburn 7165: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 7166: var pickitem;
7167: var picknumitem;
7168: var picknumtext;
7169: if (index == 'all') {
7170: pickitem = document.getElementById('randompickall');
7171: picknumitem = document.getElementById('rpicknumall');
7172: picknumtext = document.getElementById('rpicktextall');
7173: } else {
7174: pickitem = document.getElementById('randompick_'+index);
7175: picknumitem = document.getElementById('rpicknum_'+index);
7176: picknumtext = document.getElementById('randompicknum_'+index);
7177: }
1.478 raeburn 7178: if (pickitem.checked) {
1.484.2.61 raeburn 7179: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7180: if (picknum == '' || picknum == null) {
7181: if (caller == 'check') {
7182: pickitem.checked=false;
1.484.2.29 raeburn 7183: if (index == 'all') {
7184: picknumtext.innerHTML = '';
7185: if (caller == 'link') {
7186: propagateState(targetform,'rpicknum');
7187: }
7188: } else {
1.484.2.30 raeburn 7189: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7190: }
1.478 raeburn 7191: }
7192: } else {
7193: picknum.toString();
7194: var regexdigit=/^\\d+\$/;
7195: if (regexdigit.test(picknum)) {
7196: picknumitem.value = picknum;
1.484.2.29 raeburn 7197: if (index == 'all') {
1.484.2.30 raeburn 7198: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 7199: if (caller == 'link') {
7200: propagateState(targetform,'rpicknum');
7201: }
7202: } else {
7203: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 7204: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7205: }
1.478 raeburn 7206: } else {
7207: if (caller == 'check') {
1.484.2.29 raeburn 7208: if (index == 'all') {
7209: picknumtext.innerHTML = '';
7210: if (caller == 'link') {
7211: propagateState(targetform,'rpicknum');
7212: }
7213: } else {
7214: pickitem.checked=false;
1.484.2.30 raeburn 7215: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7216: }
1.478 raeburn 7217: }
7218: return;
7219: }
7220: }
7221: } else {
1.484.2.29 raeburn 7222: picknumitem.value = '';
7223: picknumtext.innerHTML = '';
7224: if (index == 'all') {
7225: if (caller == 'link') {
7226: propagateState(targetform,'rpicknum');
7227: }
7228: } else {
1.484.2.30 raeburn 7229: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7230: }
7231: }
7232: }
7233:
7234: function propagateState(form,param) {
7235: if (document.getElementById(param+'all')) {
7236: var setcheck = 0;
7237: var rpick = 0;
7238: if (param == 'rpicknum') {
7239: if (document.getElementById('randompickall')) {
7240: if (document.getElementById('randompickall').checked) {
7241: if (document.getElementById('rpicknumall')) {
7242: rpick = document.getElementById('rpicknumall').value;
7243: }
7244: }
7245: }
7246: } else {
7247: if (document.getElementById(param+'all').checked) {
7248: setcheck = 1;
7249: }
7250: }
1.484.2.30 raeburn 7251: var allidxlist;
7252: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7253: if (document.getElementById('all'+param+'idx')) {
7254: allidxlist = document.getElementById('all'+param+'idx').value;
7255: }
7256: var actions = new Array ('remove','cut','copy');
7257: for (var i=0; i<actions.length; i++) {
7258: if (actions[i] != param) {
7259: if (document.getElementById(actions[i]+'all')) {
7260: document.getElementById(actions[i]+'all').checked = false;
7261: }
7262: }
7263: }
7264: }
1.484.2.29 raeburn 7265: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 7266: allidxlist = form.allidx.value;
7267: }
7268: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7269: allidxlist = form.allmapidx.value;
7270: }
7271: if ((allidxlist != '') && (allidxlist != null)) {
7272: var allidxs = allidxlist.split(',');
7273: if (allidxs.length > 1) {
7274: for (var i=0; i<allidxs.length; i++) {
7275: if (document.getElementById(param+'_'+allidxs[i])) {
7276: if (param == 'rpicknum') {
7277: if (document.getElementById('randompick_'+allidxs[i])) {
7278: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7279: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7280: if (rpick > 0) {
7281: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7282: } else {
7283: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7284: }
7285: }
7286: }
7287: } else {
1.484.2.29 raeburn 7288: if (setcheck == 1) {
7289: document.getElementById(param+'_'+allidxs[i]).checked = true;
7290: } else {
7291: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 7292: if (param == 'randompick') {
7293: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7294: }
1.484.2.29 raeburn 7295: }
7296: }
7297: }
7298: }
1.484.2.30 raeburn 7299: if (setcheck == 1) {
7300: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7301: var actions = new Array('copy','cut','remove');
7302: for (var i=0; i<actions.length; i++) {
7303: var otheractions;
7304: var otheridxs;
7305: if (actions[i] === param) {
7306: continue;
7307: } else {
7308: if (document.getElementById('all'+actions[i]+'idx')) {
7309: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7310: otheridxs = otheractions.split(',');
7311: if (otheridxs.length > 1) {
7312: for (var j=0; j<otheridxs.length; j++) {
7313: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7314: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7315: }
1.484.2.29 raeburn 7316: }
7317: }
7318: }
7319: }
1.484.2.30 raeburn 7320: }
1.484.2.29 raeburn 7321: }
7322: }
7323: }
7324: }
1.478 raeburn 7325: }
1.484.2.29 raeburn 7326: return;
7327: }
7328:
1.484.2.63 raeburn 7329: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7330: var canedit = '$canedit';
7331: if (canedit == '') {
7332: alert("$js_lt{'edri'}");
7333: return;
7334: }
1.484.2.30 raeburn 7335: var dosettings;
7336: var doaction;
7337: var control = document.togglemultsettings;
7338: if (context == 'actions') {
7339: control = document.togglemultactions;
7340: doaction = 1;
7341: } else {
7342: dosettings = 1;
7343: }
7344: if (control) {
7345: if (control.showmultpick.length) {
7346: for (var i=0; i<control.showmultpick.length; i++) {
7347: if (control.showmultpick[i].checked) {
7348: if (control.showmultpick[i].value == 1) {
7349: if (context == 'settings') {
7350: dosettings = 0;
7351: } else {
7352: doaction = 0;
7353: }
7354: }
7355: }
7356: }
7357: }
7358: }
7359: if (context == 'settings') {
7360: if (dosettings == 1) {
7361: targetform.changeparms.value=param;
7362: targetform.submit();
7363: }
7364: }
7365: if (context == 'actions') {
7366: if (doaction == 1) {
7367: targetform.cmd.value=param+'_'+index;
7368: targetform.folderpath.value=folderpath;
7369: targetform.markcopy.value=idx+':'+param;
7370: targetform.copyfolder.value=folder+'.'+container;
7371: if (param == 'remove') {
1.484.2.63 raeburn 7372: var doremove = 0;
7373: if (skip_confirm) {
7374: if (confirm_removal) {
7375: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7376: doremove = 1;
7377: }
7378: } else {
7379: doremove = 1;
7380: }
7381: } else {
7382: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7383: doremove = 1;
7384: }
7385: }
7386: if (doremove) {
1.484.2.30 raeburn 7387: targetform.markcopy.value='';
7388: targetform.copyfolder.value='';
1.484.2.29 raeburn 7389: targetform.submit();
7390: }
7391: }
1.484.2.30 raeburn 7392: if (param == 'cut') {
1.484.2.61 raeburn 7393: 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 7394: targetform.submit();
7395: return;
7396: }
7397: }
7398: if (param == 'copy') {
7399: targetform.submit();
7400: return;
7401: }
7402: targetform.markcopy.value='';
7403: targetform.copyfolder.value='';
7404: targetform.cmd.value='';
7405: targetform.folderpath.value='';
7406: return;
7407: } else {
7408: if (document.getElementById(param+'_'+idx)) {
7409: item = document.getElementById(param+'_'+idx);
7410: if (item.type == 'checkbox') {
7411: if (item.checked) {
7412: item.checked = false;
7413: } else {
7414: item.checked = true;
7415: singleCheck(item,idx,param);
7416: }
7417: }
7418: }
7419: }
7420: }
7421: return;
7422: }
7423:
7424: function singleCheck(caller,idx,action) {
7425: actions = new Array('cut','copy','remove');
7426: if (caller.checked) {
7427: for (var i=0; i<actions.length; i++) {
7428: if (actions[i] != action) {
7429: if (document.getElementById(actions[i]+'_'+idx)) {
7430: if (document.getElementById(actions[i]+'_'+idx).checked) {
7431: document.getElementById(actions[i]+'_'+idx).checked = false;
7432: }
7433: }
7434: }
1.484.2.29 raeburn 7435: }
7436: }
7437: return;
1.478 raeburn 7438: }
7439:
1.334 muellerd 7440: function unselectInactive(nav) {
1.335 ehlerst 7441: currentNav = document.getElementById(nav);
7442: currentLis = currentNav.getElementsByTagName('LI');
7443: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7444: if (currentLis[i].className == 'goback') {
7445: currentLis[i].className = 'goback';
7446: } else {
7447: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7448: currentLis[i].className = 'right';
1.472 raeburn 7449: } else {
1.374 tempelho 7450: currentLis[i].className = 'i';
1.472 raeburn 7451: }
7452: }
1.335 ehlerst 7453: }
1.332 tempelho 7454: }
7455:
1.334 muellerd 7456: function hideAll(current, nav, data) {
1.335 ehlerst 7457: unselectInactive(nav);
1.484.2.43 raeburn 7458: if (current) {
7459: if (current.className == 'right'){
1.374 tempelho 7460: current.className = 'right active'
1.484.2.43 raeburn 7461: } else {
1.374 tempelho 7462: current.className = 'active';
1.484.2.43 raeburn 7463: }
1.374 tempelho 7464: }
1.335 ehlerst 7465: currentData = document.getElementById(data);
7466: currentDivs = currentData.getElementsByTagName('DIV');
7467: for (i = 0; i < currentDivs.length; i++) {
7468: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7469: currentDivs[i].style.display = 'none';
1.330 tempelho 7470: }
7471: }
1.335 ehlerst 7472: }
1.330 tempelho 7473:
1.374 tempelho 7474: function openTabs(pageId) {
7475: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7476: if(tabnav.length > 2 ){
1.389 tempelho 7477: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7478: currentLis = currentNav.getElementsByTagName('LI');
7479: for(i = 0; i< currentLis.length; i++){
7480: if(currentLis[i].className == 'active') {
1.375 tempelho 7481: funcString = currentLis[i].onclick.toString();
7482: tab = funcString.split('"');
1.420 onken 7483: if(tab.length < 2) {
7484: tab = funcString.split("'");
7485: }
1.375 tempelho 7486: currentData = document.getElementById(tab[1]);
7487: currentData.style.display = 'block';
1.374 tempelho 7488: }
7489: }
7490: }
7491: }
7492:
1.334 muellerd 7493: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7494: currstate = current.className;
1.334 muellerd 7495: hideAll(current, nav, data);
1.375 tempelho 7496: openTabs(pageId);
1.334 muellerd 7497: unselectInactive(nav);
1.484.2.43 raeburn 7498: if ((currstate == 'active') || (currstate == 'right active')) {
7499: if (currstate == 'active') {
7500: current.className = '';
7501: } else {
7502: current.className = 'right';
7503: }
7504: activeTab = '';
7505: toggleUpload();
7506: toggleMap();
7507: resize_scrollbox('contentscroll','1','0');
7508: return;
7509: } else {
7510: current.className = 'active';
7511: }
1.330 tempelho 7512: currentData = document.getElementById(pageId);
7513: currentData.style.display = 'block';
1.458 raeburn 7514: activeTab = pageId;
1.484.2.12 raeburn 7515: toggleUpload();
1.484.2.14 raeburn 7516: toggleMap();
1.433 raeburn 7517: if (nav == 'mainnav') {
7518: var storedpath = "$docs_folderpath";
1.434 raeburn 7519: var storedpage = "$main_container_page";
1.433 raeburn 7520: var reg = new RegExp("^supplemental");
7521: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7522: if (storedpage == 1) {
7523: document.simpleedit.folderpath.value = '';
7524: document.uploaddocument.folderpath.value = '';
7525: } else {
7526: if (reg.test(storedpath)) {
7527: document.simpleedit.folderpath.value = '$toplevelmain';
7528: document.uploaddocument.folderpath.value = '$toplevelmain';
7529: document.newext.folderpath.value = '$toplevelmain';
7530: } else {
7531: document.simpleedit.folderpath.value = storedpath;
7532: document.uploaddocument.folderpath.value = storedpath;
7533: document.newext.folderpath.value = storedpath;
7534: }
1.433 raeburn 7535: }
7536: } else {
1.434 raeburn 7537: if (reg.test(storedpath)) {
7538: document.simpleedit.folderpath.value = storedpath;
7539: document.supuploaddocument.folderpath.value = storedpath;
7540: document.supnewext.folderpath.value = storedpath;
7541: } else {
1.433 raeburn 7542: document.simpleedit.folderpath.value = '$toplevelsupp';
7543: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7544: document.supnewext.folderpath.value = '$toplevelsupp';
7545: }
7546: }
7547: }
1.484.2.3 raeburn 7548: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7549: return false;
7550: }
1.329 droeschl 7551:
1.472 raeburn 7552: function toContents(jumpto) {
7553: var newurl = '$backtourl';
1.484.2.21 raeburn 7554: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7555: newurl = newurl+'?postdata='+jumpto;
7556: }
7557: location.href=newurl;
7558: }
7559:
1.484.2.30 raeburn 7560: function togglePick(caller,value) {
7561: var disp = 'none';
7562: if (document.getElementById('multi'+caller)) {
7563: var curr = document.getElementById('multi'+caller).style.display;
7564: if (value == 1) {
7565: disp='block';
7566: }
7567: if (curr == disp) {
7568: return;
7569: }
7570: document.getElementById('multi'+caller).style.display=disp;
7571: if (value == 1) {
1.484.2.61 raeburn 7572: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7573: } else {
7574: document.getElementById('more'+caller).innerHTML = '';
7575: }
7576: if (caller == 'actions') {
7577: setClass(value);
7578: setBoxes(value);
7579: }
7580: }
7581: var showButton = multiSettings();
7582: if (showButton != 1) {
7583: showButton = multiActions();
7584: }
7585: if (document.getElementById('multisave')) {
7586: if (showButton == 1) {
7587: document.getElementById('multisave').style.display='block';
7588: } else {
7589: document.getElementById('multisave').style.display='none';
7590: }
7591: }
7592: resize_scrollbox('contentscroll','1','1');
7593: return;
7594: }
7595:
7596: function toggleCheckUncheck(caller,more) {
7597: if (more == 1) {
1.484.2.61 raeburn 7598: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7599: document.getElementById('allfields'+caller).style.display='block';
7600: } else {
1.484.2.61 raeburn 7601: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7602: document.getElementById('allfields'+caller).style.display='none';
7603: }
7604: resize_scrollbox('contentscroll','1','1');
7605: }
7606:
7607: function multiSettings() {
7608: var inuse = 0;
7609: var settingsform = document.togglemultsettings;
7610: if (settingsform.showmultpick.length > 1) {
7611: for (var i=0; i<settingsform.showmultpick.length; i++) {
7612: if (settingsform.showmultpick[i].checked) {
7613: if (settingsform.showmultpick[i].value == 1) {
7614: inuse = 1;
7615: }
7616: }
7617: }
7618: }
7619: return inuse;
7620: }
7621:
7622: function multiActions() {
7623: var inuse = 0;
7624: var actionsform = document.togglemultactions;
7625: if (actionsform.showmultpick.length > 1) {
7626: for (var i=0; i<actionsform.showmultpick.length; i++) {
7627: if (actionsform.showmultpick[i].checked) {
7628: if (actionsform.showmultpick[i].value == 1) {
7629: inuse = 1;
7630: }
7631: }
7632: }
7633: }
7634: return inuse;
7635: }
7636:
7637: function checkSubmits() {
7638: var numchanges = 0;
7639: var form = document.saveactions;
7640: var doactions = multiActions();
7641: var cutwarnings = 0;
7642: var remwarnings = 0;
1.484.2.63 raeburn 7643: var removalinfo = 0;
1.484.2.30 raeburn 7644: if (doactions == 1) {
7645: var remidxlist = document.cumulativeactions.allremoveidx.value;
7646: if ((remidxlist != '') && (remidxlist != null)) {
7647: var remidxs = remidxlist.split(',');
7648: for (var i=0; i<remidxs.length; i++) {
7649: if (document.getElementById('remove_'+remidxs[i])) {
7650: if (document.getElementById('remove_'+remidxs[i]).checked) {
7651: form.multiremove.value += remidxs[i]+',';
7652: numchanges ++;
7653: if (document.getElementById('skip_remove_'+remidxs[i])) {
7654: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7655: remwarnings ++;
7656: }
7657: }
1.484.2.63 raeburn 7658: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7659: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7660: removalinfo ++;
7661: }
7662: }
1.484.2.30 raeburn 7663: }
7664: }
7665: }
7666: }
7667: var cutidxlist = document.cumulativeactions.allcutidx.value;
7668: if ((cutidxlist != '') && (cutidxlist != null)) {
7669: var cutidxs = cutidxlist.split(',');
7670: for (var i=0; i<cutidxs.length; i++) {
7671: if (document.getElementById('cut_'+cutidxs[i])) {
7672: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7673: form.multicut.value += cutidxs[i]+',';
7674: numchanges ++;
7675: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7676: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7677: cutwarnings ++;
7678: }
7679: }
7680: }
7681: }
7682: }
7683: }
7684: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7685: if ((copyidxlist != '') && (copyidxlist != null)) {
7686: var copyidxs = copyidxlist.split(',');
7687: for (var i=0; i<copyidxs.length; i++) {
7688: if (document.getElementById('copy_'+copyidxs[i])) {
7689: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7690: form.multicopy.value += copyidxs[i]+',';
7691: numchanges ++;
7692: }
7693: }
7694: }
7695: }
7696: if (numchanges > 0) {
7697: form.multichange.value = numchanges;
7698: }
7699: }
7700: var dosettings = multiSettings();
7701: var haschanges = 0;
7702: if (dosettings == 1) {
7703: form.allencrypturl.value = '';
7704: form.allhiddenresource.value = '';
7705: form.changeparms.value = 'all';
7706: var patt=new RegExp(",\$");
7707: var allidxlist = document.cumulativesettings.allidx.value;
7708: if ((allidxlist != '') && (allidxlist != null)) {
7709: var allidxs = allidxlist.split(',');
7710: if (allidxs.length > 1) {
7711: for (var i=0; i<allidxs.length; i++) {
7712: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7713: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7714: form.allhiddenresource.value += allidxs[i]+',';
7715: }
7716: }
7717: if (document.getElementById('encrypturl_'+allidxs[i])) {
7718: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7719: form.allencrypturl.value += allidxs[i]+',';
7720: }
1.484.2.29 raeburn 7721: }
7722: }
1.484.2.30 raeburn 7723: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7724: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7725: }
7726: }
7727: form.allrandompick.value = '';
7728: form.allrandomorder.value = '';
7729: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7730: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7731: var allmapidxs = allmapidxlist.split(',');
7732: for (var i=0; i<allmapidxs.length; i++) {
7733: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7734: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7735: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7736: if ((randompick.checked) && (rpicknum.value != '')) {
7737: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7738: }
7739: if (randorder.checked) {
7740: form.allrandomorder.value += allmapidxs[i]+',';
7741: }
7742: }
7743: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7744: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7745: }
7746: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7747: haschanges = 1;
7748: }
7749: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7750: haschanges = 1;
7751: }
7752: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7753: haschanges = 1;
7754: }
7755: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7756: haschanges = 1;
7757: }
7758: }
7759: if (doactions == 1) {
7760: if (numchanges > 0) {
1.484.2.63 raeburn 7761: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7762: if (remwarnings > 0) {
1.484.2.61 raeburn 7763: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7764: return false;
7765: }
7766: }
1.484.2.63 raeburn 7767: if (removalinfo > 0) {
7768: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7769: return false;
7770: }
7771: }
1.484.2.30 raeburn 7772: if (cutwarnings > 0) {
1.484.2.61 raeburn 7773: 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 7774: return false;
1.484.2.29 raeburn 7775: }
7776: }
7777: }
1.484.2.30 raeburn 7778: form.submit();
7779: return true;
7780: }
7781: }
7782: if (dosettings == 1) {
7783: if (haschanges == 1) {
7784: form.submit();
7785: return true;
1.484.2.29 raeburn 7786: }
7787: }
1.484.2.30 raeburn 7788: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7789: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7790: } else {
7791: if (dosettings == 1) {
1.484.2.61 raeburn 7792: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7793: } else {
1.484.2.61 raeburn 7794: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7795: }
7796: }
7797: return false;
7798: }
7799:
7800: function setClass(value) {
7801: var cutclass = 'LC_docs_cut';
7802: var copyclass = 'LC_docs_copy';
7803: var removeclass = 'LC_docs_remove';
7804: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7805: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7806: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7807: var links = document.getElementsByTagName('a');
7808: for (var i=0; i<links.length; i++) {
7809: var classes = links[i].className;
7810: if (cutreg.test(classes)) {
7811: links[i].className = cutclass;
7812: if (value == 1) {
7813: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7814: }
1.484.2.30 raeburn 7815: } else {
7816: if (copyreg.test(classes)) {
7817: links[i].className = copyclass;
7818: if (value == 1) {
7819: links[i].className += " LC_menubuttons_link";
7820: }
7821: } else {
7822: if (removereg.test(classes)) {
7823: links[i].className = removeclass;
7824: if (value == 1) {
7825: links[i].className += " LC_menubuttons_link";
7826: }
7827: }
1.484.2.29 raeburn 7828: }
7829: }
7830: }
1.484.2.30 raeburn 7831: return;
1.484.2.29 raeburn 7832: }
7833:
1.484.2.30 raeburn 7834: function setBoxes(value) {
7835: var remidxlist = document.cumulativeactions.allremoveidx.value;
7836: if ((remidxlist != '') && (remidxlist != null)) {
7837: var remidxs = remidxlist.split(',');
7838: for (var i=0; i<remidxs.length; i++) {
7839: if (document.getElementById('remove_'+remidxs[i])) {
7840: var item = document.getElementById('remove_'+remidxs[i]);
7841: if (value == 1) {
7842: item.className = 'LC_docs_remove';
7843: } else {
7844: item.className = 'LC_hidden';
7845: }
7846: }
1.484.2.29 raeburn 7847: }
7848: }
1.484.2.30 raeburn 7849: var cutidxlist = document.cumulativeactions.allcutidx.value;
7850: if ((cutidxlist != '') && (cutidxlist != null)) {
7851: var cutidxs = cutidxlist.split(',');
7852: for (var i=0; i<cutidxs.length; i++) {
7853: if (document.getElementById('cut_'+cutidxs[i])) {
7854: var item = document.getElementById('cut_'+cutidxs[i]);
7855: if (value == 1) {
7856: item.className = 'LC_docs_cut';
7857: } else {
7858: item.className = 'LC_hidden';
7859: }
7860: }
7861: }
7862: }
7863: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7864: if ((copyidxlist != '') && (copyidxlist != null)) {
7865: var copyidxs = copyidxlist.split(',');
7866: for (var i=0; i<copyidxs.length; i++) {
7867: if (document.getElementById('copy_'+copyidxs[i])) {
7868: var item = document.getElementById('copy_'+copyidxs[i]);
7869: if (value == 1) {
7870: item.className = 'LC_docs_copy';
7871: } else {
7872: item.className = 'LC_hidden';
7873: }
7874: }
1.484.2.29 raeburn 7875: }
7876: }
7877: return;
7878: }
7879:
1.484.2.67 raeburn 7880: ENDSCRIPT
1.329 droeschl 7881: }
1.457 raeburn 7882:
1.483 raeburn 7883: sub history_tab_js {
7884: return <<"ENDHIST";
7885: function toggleHistoryDisp(choice) {
7886: document.docslogform.docslog.value = choice;
7887: document.docslogform.submit();
7888: return;
7889: }
7890:
7891: ENDHIST
7892: }
7893:
1.484 raeburn 7894: sub inject_data_js {
7895: return <<ENDINJECT;
7896:
7897: function injectData(current, hiddenField, name, value) {
7898: currentElement = document.getElementById(hiddenField);
7899: currentElement.name = name;
7900: currentElement.value = value;
7901: current.submit();
7902: }
7903:
7904: ENDINJECT
7905: }
7906:
7907: sub dump_switchserver_js {
7908: my @hosts = @_;
1.484.2.61 raeburn 7909: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7910: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7911: swit => 'Switch server?',
1.484.2.61 raeburn 7912: );
7913: my %html_js_lt = &Apache::lonlocal::texthash(
7914: swit => 'Switch server?',
1.484.2.43 raeburn 7915: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7916: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7917: chos => 'Choose server',
7918: );
1.484.2.61 raeburn 7919: &js_escape(\%js_lt);
7920: &html_escape(\%html_js_lt);
7921: &js_escape(\%html_js_lt);
1.484 raeburn 7922: my $role = $env{'request.role'};
7923: my $js = <<"ENDSWJS";
7924: <script type="text/javascript">
7925: function write_switchserver() {
7926: var server;
7927: if (document.setserver.posshosts.length > 0) {
7928: for (var i=0; i<document.setserver.posshosts.length; i++) {
7929: if (document.setserver.posshosts[i].checked) {
7930: server = document.setserver.posshosts[i].value;
7931: }
7932: }
7933: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7934: }
7935: window.close();
7936: }
7937: </script>
7938:
7939: ENDSWJS
7940:
7941: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7942: {'only_body' => 1,
7943: 'js_ready' => 1,});
7944: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7945:
7946: my $hostpicker;
7947: my $count = 0;
7948: foreach my $host (sort(@hosts)) {
7949: my $checked;
7950: if ($count == 0) {
7951: $checked = ' checked="checked"';
7952: }
7953: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7954: $host.'"'.$checked.' />'.$host.'</label> ';
7955: $count++;
7956: }
7957:
7958: return <<"ENDSWITCHJS";
7959:
7960: function dump_needs_switchserver(url) {
7961: if (url!='' && url!= null) {
1.484.2.61 raeburn 7962: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7963: go(url);
7964: }
7965: }
7966: return;
7967: }
7968:
7969: function choose_switchserver_window() {
7970: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7971: newWindow.document.open();
7972: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7973: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7974: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7975: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7976: '<form name="setserver" method="post" action="" \\/>\\n'+
7977: '$hostpicker\\n'+
7978: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7979: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7980: 'onclick="write_switchserver();" \\/>\\n'+
7981: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7982: newWindow.document.writeln('$endpage');
7983: newWindow.document.close();
7984: newWindow.focus();
7985: }
7986:
7987: ENDSWITCHJS
7988: }
7989:
7990: sub makedocslogform {
7991: my ($formelems,$docslog) = @_;
7992: return <<"LOGSFORM";
7993: <form action="/adm/coursedocs" method="post" name="docslogform">
7994: <input type="hidden" name="docslog" value="$docslog" />
7995: $formelems
7996: </form>
7997: LOGSFORM
7998: }
7999:
8000: sub makesimpleeditform {
8001: my ($formelems) = @_;
8002: return <<"SIMPFORM";
8003: <form name="simpleedit" method="post" action="/adm/coursedocs">
8004: <input type="hidden" name="importdetail" value="" />
8005: $formelems
8006: </form>
8007: SIMPFORM
8008: }
8009:
1.329 droeschl 8010: 1;
8011: __END__
8012:
8013:
8014: =head1 NAME
8015:
8016: Apache::londocs.pm
8017:
8018: =head1 SYNOPSIS
8019:
8020: This is part of the LearningOnline Network with CAPA project
8021: described at http://www.lon-capa.org.
8022:
8023: =head1 SUBROUTINES
8024:
8025: =over
8026:
8027: =item %help=()
8028:
8029: Available help topics
8030:
8031: =item mapread()
8032:
1.344 bisitz 8033: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8034: @order and @resources, determines status
8035: sets @order - pointer to resources in right order
8036: sets @resources - array with the resources with correct idx
8037:
8038: =item authorhosts()
8039:
8040: Return hash with valid author names
8041:
8042: =item clean()
8043:
8044: =item dumpcourse()
8045:
8046: Actually dump course
8047:
8048: =item group_import()
8049:
8050: Imports the given (name, url) resources into the course
8051: coursenum, coursedom, and folder must precede the list
8052:
8053: =item breadcrumbs()
8054:
8055: =item log_docs()
8056:
8057: =item docs_change_log()
8058:
8059: =item update_paste_buffer()
8060:
8061: =item print_paste_buffer()
8062:
8063: =item do_paste_from_buffer()
8064:
1.484.2.30 raeburn 8065: =item do_buffer_empty()
8066:
8067: =item clear_from_buffer()
8068:
1.484.2.7 raeburn 8069: =item get_newmap_url()
8070:
8071: =item dbcopy()
8072:
8073: =item uniqueness_check()
8074:
8075: =item contained_map_check()
8076:
8077: =item url_paste_fixups()
8078:
8079: =item apply_fixups()
8080:
8081: =item copy_dependencies()
8082:
1.329 droeschl 8083: =item update_parameter()
8084:
8085: =item handle_edit_cmd()
8086:
8087: =item editor()
8088:
8089: =item process_file_upload()
8090:
8091: =item process_secondary_uploads()
8092:
8093: =item is_supplemental_title()
8094:
8095: =item entryline()
8096:
8097: =item tiehash()
8098:
8099: =item untiehash()
8100:
8101: =item checkonthis()
8102:
8103: check on this
8104:
8105: =item verifycontent()
8106:
8107: Verify Content
8108:
1.484.2.78 raeburn 8109: =item devalidateversioncache()
8110:
8111: =item checkversions()
1.329 droeschl 8112:
8113: Check Versions
8114:
8115: =item mark_hash_old()
8116:
8117: =item is_hash_old()
8118:
8119: =item changewarning()
8120:
8121: =item init_breadcrumbs()
8122:
8123: Breadcrumbs for special functions
8124:
1.484 raeburn 8125: =item create_list_elements()
8126:
8127: =item create_form_ul()
8128:
8129: =item startContentScreen()
8130:
8131: =item endContentScreen()
8132:
8133: =item supplemental_base()
8134:
8135: =item embedded_form_elems()
8136:
8137: =item embedded_destination()
8138:
8139: =item return_to_editor()
8140:
8141: =item decompression_info()
8142:
8143: =item decompression_phase_one()
8144:
8145: =item decompression_phase_two()
8146:
8147: =item remove_archive()
8148:
8149: =item generate_admin_menu()
8150:
8151: =item generate_edit_table()
8152:
8153: =item editing_js()
8154:
8155: =item history_tab_js()
8156:
8157: =item inject_data_js()
8158:
8159: =item dump_switchserver_js()
8160:
1.484.2.3 raeburn 8161: =item resize_scrollbox_js()
1.484 raeburn 8162:
8163: =item makedocslogform()
8164:
1.484.2.3 raeburn 8165: =item makesimpleeditform()
8166:
1.329 droeschl 8167: =back
8168:
8169: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>