Annotation of loncom/interface/londocs.pm, revision 1.484.2.93.2.1
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 2021/12/22 01:22:06 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.484.2.19 raeburn 43: use Apache::lonextresedit();
1.484.2.43 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.484.2.93.2. (raeburn 46:): use Apache::loncourserespicker();
1.329 droeschl 47: use HTML::Entities;
1.484.2.7 raeburn 48: use HTML::TokeParser;
1.329 droeschl 49: use GDBM_File;
1.484.2.51 raeburn 50: use File::MMagic;
1.329 droeschl 51: use Apache::lonlocal;
52: use Cwd;
53: use LONCAPA qw(:DEFAULT :match);
54:
55: my $iconpath;
56:
57: my %hash;
58:
59: my $hashtied;
60: my %alreadyseen=();
61:
62: my $hadchanges;
1.484.2.37 raeburn 63: my $suppchanges;
1.329 droeschl 64:
65:
66: my %help=();
67:
68:
69: sub mapread {
70: my ($coursenum,$coursedom,$map)=@_;
71: return
72: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
73: $map);
74: }
75:
76: sub storemap {
1.484.2.7 raeburn 77: my ($coursenum,$coursedom,$map,$contentchg)=@_;
78: my $report;
79: if (($contentchg) && ($map =~ /^default/)) {
80: $report = 1;
81: }
1.329 droeschl 82: my ($outtext,$errtext)=
83: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.484.2.7 raeburn 84: $map,1,$report);
1.329 droeschl 85: if ($errtext) { return ($errtext,2); }
1.364 bisitz 86:
1.484.2.37 raeburn 87: if ($map =~ /^default/) {
88: $hadchanges=1;
89: } else {
90: $suppchanges=1;
91: }
1.329 droeschl 92: return ($errtext,0);
93: }
94:
95:
96:
97: sub authorhosts {
98: my %outhash=();
99: my $home=0;
100: my $other=0;
101: foreach my $key (keys(%env)) {
102: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
103: my $role=$1;
104: my $realm=$2;
105: my ($start,$end)=split(/\./,$env{$key});
106: if (($start) && ($start>time)) { next; }
107: if (($end) && (time>$end)) { next; }
108: my ($ca,$cd);
109: if ($1 eq 'au') {
110: $ca=$env{'user.name'};
111: $cd=$env{'user.domain'};
112: } else {
113: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
114: }
115: my $allowed=0;
116: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
117: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 118: foreach my $id (@ids) {
119: if ($id eq $myhome) {
120: $allowed=1;
121: last;
122: }
123: }
1.329 droeschl 124: if ($allowed) {
125: $home++;
1.484 raeburn 126: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 127: } else {
1.484 raeburn 128: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 129: $other++;
130: }
131: }
132: }
133: return ($home,$other,%outhash);
134: }
135:
136:
137: sub clean {
138: my ($title)=@_;
139: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 140: return $title;
1.329 droeschl 141: }
142:
1.484.2.67 raeburn 143: sub default_folderpath {
144: my ($coursenum,$coursedom,$navmapref) = @_;
145: return unless ($coursenum && $coursedom && ref($navmapref));
146: # Check if entire course is hidden and/or encrypted
147: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
148: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
149: unless (ref($$navmapref)) {
150: $$navmapref = Apache::lonnavmaps::navmap->new();
151: }
152: if (ref($$navmapref)) {
153: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
154: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
155: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
156: unless (@resources) {
157: $hiddenmap = 1;
158: unless ($env{'request.role.adv'}) {
159: $hiddentop = 1;
160: if ($env{'form.folder'}) {
161: undef($env{'form.folder'});
162: }
163: }
164: }
165: }
166: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
167: $encryptmap = 1;
168: }
169: }
170: unless ($hiddentop) {
171: $folderpath='default&'.&escape(&mt('Main Content')).
172: '::'.$hiddenmap.':'.$encryptmap.'::';
173: }
174: if (wantarray) {
175: return ($folderpath,$hiddentop);
176: } else {
177: return $folderpath;
178: }
179: }
1.329 droeschl 180:
1.484.2.92 raeburn 181: sub validate_folderpath {
182: my ($supplementalflag) = @_;
183: if ($env{'form.folderpath'} ne '') {
184: my @items = split(/\&/,$env{'form.folderpath'});
185: my $badpath;
186: for (my $i=0; $i<@items; $i++) {
187: my $odd = $i%2;
188: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
189: $badpath = 1;
190: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
191: $badpath = 1;
192: }
193: last if ($badpath);
194: }
195: if ($badpath) {
196: delete($env{'form.folderpath'});
197: }
198: }
199: return;
200: }
201:
202: sub validate_suppath {
203: if ($env{'form.supppath'} ne '') {
204: my @items = split(/\&/,$env{'form.supppath'});
205: my $badpath;
206: for (my $i=0; $i<@items; $i++) {
207: my $odd = $i%2;
208: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
209: $badpath = 1;
210: }
211: last if ($badpath);
212: }
213: if ($badpath) {
214: delete($env{'form.supppath'});
215: }
216: }
217: return;
218: }
219:
1.329 droeschl 220: sub dumpcourse {
221: my ($r) = @_;
1.408 raeburn 222: my $crstype = &Apache::loncommon::course_type();
1.484.2.43 raeburn 223: my ($starthash,$js);
224: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
225: $js = <<"ENDJS";
226: <script type="text/javascript">
227: // <![CDATA[
228:
229: function hide_searching() {
230: if (document.getElementById('searching')) {
231: document.getElementById('searching').style.display = 'none';
232: }
233: return;
234: }
235:
236: // ]]>
237: </script>
238: ENDJS
239: $starthash = {
240: add_entries => {'onload' => "hide_searching();"},
241: };
242: }
243: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
244: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 245: $r->print(&startContentScreen('tools'));
1.329 droeschl 246: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 247: unless ($home) {
248: $r->print(&endContentScreen());
249: return '';
250: }
1.329 droeschl 251: my $origcrsid=$env{'request.course.id'};
252: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
253: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
254: # Do the dumping
1.484 raeburn 255: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
256: $r->print(&endContentScreen());
257: return '';
258: }
1.484.2.24 raeburn 259: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 260: $r->print('<h3>'.&mt('Copying Files').'</h3>');
261: my $title=$env{'form.authorfolder'};
262: $title=&clean($title);
1.484.2.43 raeburn 263: my ($navmap,$errormsg) =
264: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
265: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
266: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
267: my (%maps,%resources,%titles);
268: if (!ref($navmap)) {
269: $r->print($errormsg.
270: &endContentScreen());
271: return '';
272: } else {
273: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
274: 'dumpdocs',$cdom,$cnum);
275: }
276: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
277: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
278: %newcontent,%has_simpleprobs);
279: foreach my $item (sort {$a <=> $b} (@todump)) {
280: my $name = $env{'form.namefor_'.$item};
281: if ($resources{$item}) {
282: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
283: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
284: $tocopy{$1} = $name;
285: $display{$item} = $1;
286: $lookup{$1} = $item;
287: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
288: $simpleproblems{$item} = {
289: symb => $resources{$item},
290: name => $name,
291: };
292: $display{$item} = 'simpleproblem_'.$name;
293: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
294: $has_simpleprobs{$1}{$id} = $item;
295: }
296: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
297: my $marker = $1;
298: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
299: $simplepages{$item} = {
300: res => $res,
301: title => $titles{$item},
302: db => $db_name,
303: marker => $marker,
304: symb => $resources{$item},
305: name => $name,
306: };
307: $display{$item} = '/'.$res;
308: }
309: } elsif ($maps{$item}) {
310: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
311: $tocopy{$1} = $name;
312: $display{$item} = $1;
313: $lookup{$1} = $item;
314: }
315: } else {
316: next;
317: }
318: }
1.329 droeschl 319: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
320: $crs=~s/\_/\//g;
1.484.2.43 raeburn 321: my $mm = new File::MMagic;
322: my $prefix = "/uploaded/$cdom/$cnum/";
323: %replacehash = %tocopy;
324: foreach my $item (sort(keys(%simpleproblems))) {
325: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
326: $newcontent{$display{$item}} = $content;
327: }
328: my $gateway = Apache::lonhtmlgateway->new('web');
329: foreach my $item (sort(keys(%simplepages))) {
330: if (ref($simplepages{$item}) eq 'HASH') {
331: my $pagetitle = $simplepages{$item}{'title'};
332: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
333: my %contents;
334: foreach my $field (keys(%fields)) {
335: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
336: my $name = $1;
337: my $msg = $fields{$field};
338: if ($name eq 'webreferences') {
339: if ($msg =~ m{^https?://}) {
340: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
341: }
342: } else {
343: $msg = &Encode::decode('utf8',$msg);
344: $msg = $gateway->process_outgoing_html($msg,1);
345: $contents{$name} = $msg;
346: }
347: } elsif ($field eq 'uploaded.photourl') {
348: my $marker = $simplepages{$item}{marker};
349: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
350: my $filepath = $1;
351: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
352: if ($fname ne '') {
353: $fname=~s/\.(\w+)$//;
354: my $ext=$1;
355: $fname = &clean($fname);
356: $fname.='.'.$ext;
357: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
358: $replacehash{$filepath} = $relpath.$fname;
359: $deps{$item}{$filepath} = 1;
360: }
361: }
362: }
363: }
364: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
365: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
366: my $content = '
367: <html>
368: <head>
369: <title>'.$pagetitle.'</title>
370: </head>
371: <body bgcolor="#ffffff">';
372: if ($contents{title}) {
373: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
374: }
375: if ($contents{image}) {
376: $content .= "\n".$contents{image};
377: }
378: if ($contents{content}) {
379: $content .= '
380: <div class="LC_Box">
1.484.2.50 raeburn 381: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.484.2.43 raeburn 382: $contents{content}.'
383: </div>';
384: }
385: if ($contents{webreferences}) {
386: $content .= '
387: <div class="LC_Box">
1.484.2.50 raeburn 388: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.484.2.43 raeburn 389: $contents{webreferences}.'
390: </div>';
391: }
392: $content .= '
393: </body>
394: </html>
395: ';
396: $newcontent{'/'.$simplepages{$item}{res}} = $content;
397: }
398: }
399: foreach my $item (keys(%tocopy)) {
400: unless ($item=~/\.(sequence|page)$/) {
401: my $currurlpath = $prefix.$item;
402: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
403: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
404: }
405: }
406: foreach my $num (sort {$a <=> $b} (@todump)) {
407: my $src = $display{$num};
408: next if ($src eq '');
409: my @needcopy = ();
410: if ($replacehash{$src}) {
411: push(@needcopy,$src);
412: if (ref($deps{$num}) eq 'HASH') {
413: foreach my $dep (sort(keys(%{$deps{$num}}))) {
414: if ($replacehash{$dep}) {
415: push(@needcopy,$dep);
416: }
417: }
418: }
419: } elsif ($src =~ /^simpleproblem_/) {
420: push(@needcopy,$src);
421: }
422: next if (@needcopy == 0);
423: my ($result,$depresult);
424: for (my $i=0; $i<@needcopy; $i++) {
425: my $item = $needcopy[$i];
426: my $newfilename;
427: if ($simpleproblems{$num}) {
428: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
429: } else {
430: $newfilename=$title.'/'.$replacehash{$item};
431: }
432: $newfilename=~s/\.(\w+)$//;
433: my $ext=$1;
434: $newfilename=&clean($newfilename);
435: $newfilename.='.'.$ext;
436: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
437: if ($newrelpath ne $replacehash{$item}) {
438: $replacehash{$item} = $newrelpath;
439: }
440: my @dirs=split(/\//,$newfilename);
441: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
442: my $makepath=$path;
443: my $fail;
444: my $origin;
445: for (my $i=0;$i<$#dirs;$i++) {
446: $makepath.='/'.$dirs[$i];
447: unless (-e $makepath) {
448: unless(mkdir($makepath,0755)) {
449: $fail = &mt('Directory creation failed.');
450: }
451: }
452: }
453: if ($i == 0) {
454: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
455: } else {
456: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
457: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
458: &mt('(dependency)').'</span>: ';
459: }
460: if (-e $path.'/'.$newfilename) {
461: $fail = &mt('Destination already exists -- not overwriting.');
462: } else {
463: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
464: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
465: ($item =~ /^simpleproblem_/)) {
466: print $fh $newcontent{$item};
467: } else {
468: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
469: if (-e $fileloc) {
470: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
471: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
472: (ref($has_simpleprobs{$item}) eq 'HASH')) {
473: my %changes = %{$has_simpleprobs{$item}};
474: my $content = &Apache::lonclonecourse::rewritefile(
475: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
476: (%replacehash,$crs => '')
477: );
478: my $updatedcontent = '';
479: my $parser = HTML::TokeParser->new(\$content);
480: $parser->attr_encoded(1);
481: while (my $token = $parser->get_token) {
482: if ($token->[0] eq 'S') {
483: if (($token->[1] eq 'resource') &&
484: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
485: ($changes{$token->[2]->{'id'}})) {
486: my $id = $token->[2]->{'id'};
487: $updatedcontent .= '<'.$token->[1];
488: foreach my $attrib (@{$token->[3]}) {
489: next unless ($attrib =~ /^(src|type|title|id)$/);
490: if ($attrib eq 'src') {
491: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
492: if ($file) {
493: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
494: } else {
495: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
496: }
497: } else {
498: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
499: }
500: }
501: $updatedcontent .= ' />'."\n";
502: } else {
503: $updatedcontent .= $token->[4]."\n";
504: }
505: } else {
506: $updatedcontent .= $token->[2];
507: }
508: }
509: print $fh $updatedcontent;
510: } else {
511: print $fh &Apache::lonclonecourse::rewritefile(
512: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
513: (%replacehash,$crs => '')
514: );
515: }
516: } else {
517: print $fh
518: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
519: }
520: } else {
521: $fail = &mt('Source does not exist.');
522: }
523: }
524: $fh->close();
525: } else {
526: $fail = &mt('Could not write to destination.');
527: }
528: }
529: my $text;
530: if ($fail) {
531: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
532: } else {
533: $text = '<span class="LC_success">'.&mt('ok').'</span>';
534: }
535: if ($i == 0) {
536: $result .= $text;
537: } else {
538: $depresult .= $text.'</li>';
539: }
540: }
541: $r->print($result);
542: if ($depresult) {
543: $r->print('<ul>'.$depresult.'</ul>');
544: }
545: }
1.329 droeschl 546: } else {
1.484.2.43 raeburn 547: my ($navmap,$errormsg) =
548: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
549: if (!ref($navmap)) {
550: $r->print($errormsg);
551: } else {
552: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
553: $r->rflush();
554: my ($preamble,$formname);
555: $formname = 'dumpdoc';
556: unless ($home==1) {
557: $preamble = '<div class="LC_left_float">'.
558: '<fieldset><legend>'.
559: &mt('Select the Authoring Space').
560: '</legend><select name="authorspace">';
561: }
562: my @orderspaces = ();
563: foreach my $key (sort(keys(%outhash))) {
564: if ($key=~/^home_(.+)$/) {
565: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
566: unshift(@orderspaces,$1);
567: } else {
568: push(@orderspaces,$1);
569: }
570: }
571: }
572: if ($home>1) {
573: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
574: }
575: foreach my $user (@orderspaces) {
576: if ($home==1) {
577: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
578: } else {
579: $preamble .= '<option value="'.$user.'">'.$user.' - '.
580: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
581: }
582: }
583: unless ($home==1) {
584: $preamble .= '</select></fieldset></div>'."\n";
585: }
586: my $title=$origcrsdata{'description'};
587: $title=~s/[\/\s]+/\_/gs;
588: $title=&clean($title);
589: $preamble .= '<div class="LC_left_float">'.
590: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
591: '<input type="text" size="50" name="authorfolder" value="'.
592: $title.'" />'.
593: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
594: my %uploadedfiles;
595: &tiehash();
596: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
597: my ($ext)=($file=~/\.(\w+)$/);
598: # FIXME Check supplemental here
599: my $title=$hash{'title_'.$hash{
600: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
601: if (!$title) {
602: $title=$file;
603: } else {
604: $title=~s|/|_|g;
605: }
606: $title=~s/\.(\w+)$//;
607: $title=&clean($title);
608: $title.='.'.$ext;
609: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
610: $uploadedfiles{$file} = $title;
611: }
612: &untiehash();
613: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
614: undef,undef,$preamble,$home,\%uploadedfiles));
615: }
1.329 droeschl 616: }
1.484 raeburn 617: $r->print(&endContentScreen());
1.329 droeschl 618: }
619:
1.484.2.43 raeburn 620: sub recurse_html {
621: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
622: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
623: my (%allfiles,%codebase);
624: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
625: if (keys(%allfiles)) {
626: foreach my $dependency (keys(%allfiles)) {
627: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
628: my ($depurl,$relfile,$newcontainer);
629: if ($dependency =~ m{^/}) {
630: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
631: $relfile = $1;
632: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
633: $newcontainer = $1;
634: next if ($replacehash->{$newcontainer});
635: }
636: $depurl = $dependency;
637: } else {
638: next;
639: }
640: } else {
641: $relfile = $dependency;
642: $depurl = $currurlpath;
643: $depurl =~ s{[^/]+$}{};
644: $depurl .= $dependency;
645: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
646: }
647: next if ($relfile eq '');
648: my $newname = $replacehash->{$container};
649: $newname =~ s{[^/]+$}{};
650: $replacehash->{$newcontainer} = $newname.$relfile;
651: $deps->{$item}{$newcontainer} = 1;
652: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
653: my $depfile = &Apache::lonnet::filelocation('',$depurl);
654: my $type = $mm->checktype_filename($depfile);
655: if ($type eq 'text/html') {
656: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
657: }
658: }
659: }
660: }
661: return;
662: }
663:
1.329 droeschl 664: sub group_import {
1.484.2.93.2. (raeburn 665:): my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.484.2.23 raeburn 666: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
667: %removeparam,$importuploaded,$fixuperrors);
668: $allmaps = {};
1.329 droeschl 669: while (@files) {
670: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 671: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 672: && ($caller eq 'londocs')
673: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 674:
1.329 droeschl 675: my $errtext = '';
676: my $fatal = 0;
677: my $newmapstr = '<map>'."\n".
678: '<resource id="1" src="" type="start"></resource>'."\n".
679: '<link from="1" to="2" index="1"></link>'."\n".
680: '<resource id="2" src="" type="finish"></resource>'."\n".
681: '</map>';
682: $env{'form.output'}=$newmapstr;
683: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
684: 'output',$1.$2);
1.484.2.27 raeburn 685: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 686: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
687: $fatal = 2;
688: }
689: if ($fatal) {
690: return ($errtext,$fatal);
691: }
692: }
693: if ($url) {
1.484.2.93.2. (raeburn 694:): if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
695:): $url = $1;
696:): my $marker = $2;
697:): my $info = $3;
698:): my ($toolid,%toolhash,%toolsettings);
699:): my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
700:): my @toolinfo = split(/:/,$info);
701:): if ($residx) {
702:): %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
703:): $toolid = $toolsettings{'id'};
704:): } else {
705:): $toolid = shift(@toolinfo);
706:): }
707:): $toolid =~ s/\D//g;
708:): ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
709:): $toolhash{'linktext'},$toolhash{'explanation'},
710:): $toolhash{'crslabel'},$toolhash{'crstitle'},$toolhash{'crsappend'}) = @toolinfo;
711:): foreach my $item (@extras) {
712:): $toolhash{$item} = &unescape($toolhash{$item});
713:): }
714:): if (ref($ltitoolsref) eq 'HASH') {
715:): my @deleted;
716:): if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
717:): $toolhash{'id'} = $toolid;
718:): if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
719:): ($toolhash{'target'} eq 'window')) {
720:): if ($toolhash{'target'} eq 'window') {
721:): foreach my $item ('width','height') {
722:): $toolhash{$item} =~ s/^\s+//;
723:): $toolhash{$item} =~ s/\s+$//;
724:): if ($toolhash{$item} =~ /\D/) {
725:): delete($toolhash{$item});
726:): if ($residx) {
727:): if ($toolsettings{$item}) {
728:): push(@deleted,$item);
729:): }
730:): }
731:): }
732:): }
733:): }
734:): } elsif ($residx) {
735:): $toolhash{'target'} = $toolsettings{'target'};
736:): if ($toolhash{'target'} eq 'window') {
737:): foreach my $item ('width','height') {
738:): $toolhash{$item} = $toolsettings{$item};
739:): }
740:): }
741:): } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
742:): $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
743:): if ($toolhash{'target'} eq 'window') {
744:): $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
745:): $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
746:): }
747:): }
748:): if ($toolhash{'target'} eq 'iframe') {
749:): foreach my $item ('width','height','linktext','explanation') {
750:): delete($toolhash{$item});
751:): if ($residx) {
752:): if ($toolsettings{$item}) {
753:): push(@deleted,$item);
754:): }
755:): }
756:): }
757:): } elsif ($toolhash{'target'} eq 'tab') {
758:): foreach my $item ('width','height') {
759:): delete($toolhash{$item});
760:): if ($residx) {
761:): if ($toolsettings{$item}) {
762:): push(@deleted,$item);
763:): }
764:): }
765:): }
766:): }
767:): if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
768:): foreach my $item ('label','title','linktext','explanation') {
769:): my $crsitem;
770:): if (($item eq 'label') || ($item eq 'title')) {
771:): $crsitem = 'crs'.$item;
772:): } else {
773:): $crsitem = $item;
774:): }
775:): if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
776:): $toolhash{$crsitem} =~ s/^\s+//;
777:): $toolhash{$crsitem} =~ s/\s+$//;
778:): if ($toolhash{$crsitem} eq '') {
779:): delete($toolhash{$crsitem});
780:): }
781:): } else {
782:): delete($toolhash{$crsitem});
783:): }
784:): if (($residx) && (exists($toolsettings{$crsitem}))) {
785:): unless (exists($toolhash{$crsitem})) {
786:): push(@deleted,$crsitem);
787:): }
788:): }
789:): }
790:): }
791:): my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
792:): if ($putres eq 'ok') {
793:): if (@deleted) {
794:): &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
795:): }
796:): } else {
797:): return (&mt('Failed to save update to external tool.'),1);
798:): }
799:): }
800:): }
801:): }
1.484.2.23 raeburn 802: if (($caller eq 'londocs') &&
803: ($folder =~ /^default/)) {
1.484.2.27 raeburn 804: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 805: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
806: my $cid = $coursedom.'_'.$coursenum;
807: $allmaps =
808: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
809: $chome,$cid);
810: $donechk = 1;
811: }
812: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.484.2.93.2. (raeburn 813:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
814:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.484.2.23 raeburn 815: $importuploaded = 1;
816: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
817: next if ($allmaps->{$url});
818: }
819: }
1.344 bisitz 820: if (!$residx
1.329 droeschl 821: || defined($LONCAPA::map::zombies[$residx])) {
822: $residx = &LONCAPA::map::getresidx($url,$residx);
823: push(@LONCAPA::map::order, $residx);
824: }
825: my $ext = 'false';
826: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.484.2.27 raeburn 827: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
828: my $filepath = $1;
1.484.2.91 raeburn 829: my $fname;
830: if ($name eq '') {
831: $name = &mt('Web Page');
1.484.2.27 raeburn 832: $fname = 'web';
833: } else {
1.484.2.91 raeburn 834: $fname = $name;
835: $fname=&Apache::lonnet::clean_filename($fname);
836: if ($fname eq '') {
837: $fname = 'web';
838: } elsif (length($fname) > 15) {
839: $fname = substr($fname,0,14);
840: }
1.484.2.27 raeburn 841: }
1.484.2.91 raeburn 842: my $title = &Apache::loncommon::cleanup_html($name);
1.484.2.27 raeburn 843: my $initialtext = &mt('Replace with your own content.');
844: my $newhtml = <<END;
1.484.2.31 raeburn 845: <html>
1.484.2.27 raeburn 846: <head>
1.484.2.91 raeburn 847: <title>$title</title>
1.484.2.27 raeburn 848: </head>
849: <body bgcolor="#ffffff">
850: $initialtext
851: </body>
852: </html>
853: END
854: $env{'form.output'}=$newhtml;
855: my $result =
856: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
857: 'output',
858: "$filepath/$residx/$fname.html");
859: if ($result =~ m{^/uploaded/}) {
860: $url = $result;
861: if ($filepath =~ /^supplemental/) {
862: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
863: $env{'user.domain'}.'___&&&___'.$name;
864: }
865: } else {
866: return (&mt('Failed to save new web page.'),1);
867: }
868: }
1.484.2.91 raeburn 869: $name = &LONCAPA::map::qtunescape($name);
1.484.2.30 raeburn 870: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 871: $LONCAPA::map::resources[$residx] =
1.329 droeschl 872: join(':', ($name, $url, $ext, 'normal', 'res'));
873: }
874: }
1.484.2.23 raeburn 875: if ($importuploaded) {
876: my %import_errors;
877: my %updated = (
878: removefrommap => \%removefrommap,
879: removeparam => \%removeparam,
880: );
1.484.2.26 raeburn 881: my ($result,$msgsarray,$lockerror) =
882: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 883: if (keys(%import_errors) > 0) {
884: $fixuperrors =
885: '<p span class="LC_warning">'."\n".
886: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
887: '<ul>'."\n";
888: foreach my $key (sort(keys(%import_errors))) {
889: $fixuperrors .= '<li>'.$key.'</li>'."\n";
890: }
891: $fixuperrors .= '</ul></p>'."\n";
892: }
1.484.2.26 raeburn 893: if (ref($msgsarray) eq 'ARRAY') {
894: if (@{$msgsarray} > 0) {
895: $fixuperrors .= '<p class="LC_info">'.
896: join('<br />',@{$msgsarray}).
897: '</p>';
898: }
899: }
900: if ($lockerror) {
901: $fixuperrors .= '<p class="LC_error">'.
902: $lockerror.
903: '</p>';
904: }
1.484.2.23 raeburn 905: }
906: my ($errtext,$fatal) =
907: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 908: unless ($fatal) {
909: if ($folder =~ /^supplemental/) {
910: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 911: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
912: $folder.'.'.$container);
1.484.2.37 raeburn 913: }
914: }
1.484.2.23 raeburn 915: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 916: }
917:
918: sub log_docs {
1.484.2.8 raeburn 919: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 920: }
921:
922: {
923: my @oldresources=();
924: my @oldorder=();
925: my $parmidx;
926: my %parmaction=();
927: my %parmvalue=();
928: my $changedflag;
929:
930: sub snapshotbefore {
931: @oldresources=@LONCAPA::map::resources;
932: @oldorder=@LONCAPA::map::order;
933: $parmidx=undef;
934: %parmaction=();
935: %parmvalue=();
936: $changedflag=0;
937: }
938:
939: sub remember_parms {
940: my ($idx,$parameter,$action,$value)=@_;
941: $parmidx=$idx;
942: $parmaction{$parameter}=$action;
943: $parmvalue{$parameter}=$value;
944: $changedflag=1;
945: }
946:
947: sub log_differences {
948: my ($plain)=@_;
949: my %storehash=('folder' => $plain,
950: 'currentfolder' => $env{'form.folder'});
951: if ($parmidx) {
952: $storehash{'parameter_res'}=$oldresources[$parmidx];
953: foreach my $parm (keys(%parmaction)) {
954: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
955: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
956: }
957: }
958: my $maxidx=$#oldresources;
959: if ($#LONCAPA::map::resources>$#oldresources) {
960: $maxidx=$#LONCAPA::map::resources;
961: }
962: for (my $idx=0; $idx<=$maxidx; $idx++) {
963: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
964: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
965: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
966: $changedflag=1;
967: }
968: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
969: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
970: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
971: $changedflag=1;
972: }
973: }
974: $storehash{'maxidx'}=$maxidx;
975: if ($changedflag) { &log_docs(\%storehash); }
976: }
977: }
978:
979: sub docs_change_log {
1.484.2.67 raeburn 980: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 981: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 982: my $navmap;
1.483 raeburn 983: my $js = '<script type="text/javascript">'."\n".
984: '// <![CDATA['."\n".
985: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 986: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.93.2. (raeburn 987:): $coursedom,$coursenum,'',$canedit,'',\$navmap)."\n".
1.483 raeburn 988: &history_tab_js()."\n".
1.484 raeburn 989: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 990: '// ]]>'."\n".
991: '</script>'."\n";
1.484 raeburn 992: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
993: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 994: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 995: my %orderhash;
996: my $container='sequence';
997: my $pathitem;
1.484.2.19 raeburn 998: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 999: $container='page';
1000: }
1.484.2.19 raeburn 1001: my $folderpath=$env{'form.folderpath'};
1002: if ($folderpath eq '') {
1.484.2.67 raeburn 1003: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 1004: }
1.484.2.67 raeburn 1005: undef($navmap);
1.484.2.19 raeburn 1006: $pathitem = '<input type="hidden" name="folderpath" value="'.
1007: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1008: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1009: my $jumpto = $readfile;
1010: $jumpto =~ s{^/}{};
1011: my $tid = 1;
1.484.2.7 raeburn 1012: if ($supplementalflag) {
1013: $tid = 2;
1014: }
1.484.2.19 raeburn 1015: my ($breadcrumbtrail) =
1.484.2.18 raeburn 1016: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1017: $r->print($breadcrumbtrail.
1018: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1019: $readfile));
1.329 droeschl 1020: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1021: $env{'course.'.$env{'request.course.id'}.'.domain'},
1022: $env{'course.'.$env{'request.course.id'}.'.num'});
1023:
1024: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1025:
1026: my %saveable_parameters = ('show' => 'scalar',);
1027: &Apache::loncommon::store_course_settings('docs_log',
1028: \%saveable_parameters);
1029: &Apache::loncommon::restore_course_settings('docs_log',
1030: \%saveable_parameters);
1031: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1032: # FIXME: internationalization seems wrong here
1.329 droeschl 1033: my %lt=('hiddenresource' => 'Resources hidden',
1034: 'encrypturl' => 'URL hidden',
1035: 'randompick' => 'Randomly pick',
1036: 'randomorder' => 'Randomly ordered',
1037: 'set' => 'set to',
1038: 'del' => 'deleted');
1.484 raeburn 1039: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1040: $pathitem."\n".
1041: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1042: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1043: $r->print('<div class="LC_left_float">'.
1044: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1045: &makedocslogform($filter,1).
1046: '</fieldset></div><br clear="all" />');
1.329 droeschl 1047: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1048: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1049: &mt('After').'</th>'.
1050: &Apache::loncommon::end_data_table_header_row());
1051: my $shown=0;
1052: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1053: if ($env{'form.displayfilter'} eq 'currentfolder') {
1054: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1055: }
1056: my @changes=keys(%{$docslog{$id}{'logentry'}});
1057: if ($env{'form.displayfilter'} eq 'containing') {
1058: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1059: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1060: foreach my $key (@changes) {
1061: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1062: }
1.344 bisitz 1063: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1064: }
1065: my $count = 0;
1066: my $time =
1067: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1068: my $plainname =
1069: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1070: $docslog{$id}{'exe_udom'});
1071: my $about_me_link =
1072: &Apache::loncommon::aboutmewrapper($plainname,
1073: $docslog{$id}{'exe_uname'},
1074: $docslog{$id}{'exe_udom'});
1075: my $send_msg_link='';
1076: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1077: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1078: $send_msg_link ='<br />'.
1079: &Apache::loncommon::messagewrapper(&mt('Send message'),
1080: $docslog{$id}{'exe_uname'},
1081: $docslog{$id}{'exe_udom'});
1082: }
1083: $r->print(&Apache::loncommon::start_data_table_row());
1084: $r->print('<td>'.$time.'</td>
1085: <td>'.$about_me_link.
1086: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1087: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1088: $send_msg_link.'</td><td>'.
1089: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 1090: my $is_supp = 0;
1.484.2.7 raeburn 1091: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1092: $is_supp = 1;
1093: }
1.329 droeschl 1094: # Before
1095: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1096: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1097: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1098: if ($oldname ne $newname) {
1.484.2.7 raeburn 1099: my $shown = &LONCAPA::map::qtescape($oldname);
1100: if ($is_supp) {
1101: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1102: }
1103: $r->print($shown);
1.329 droeschl 1104: }
1105: }
1106: $r->print('<ul>');
1107: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1108: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 1109: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1110: if ($is_supp) {
1111: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1112: }
1.484.2.19 raeburn 1113: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1114: }
1115: }
1116: $r->print('</ul>');
1117: # After
1118: $r->print('</td><td>');
1119:
1120: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1121: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1122: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1123: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 1124: my $shown = &LONCAPA::map::qtescape($newname);
1125: if ($is_supp) {
1126: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1127: }
1128: $r->print($shown);
1.329 droeschl 1129: }
1.364 bisitz 1130: }
1.329 droeschl 1131: $r->print('<ul>');
1132: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1133: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 1134: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1135: if ($is_supp) {
1136: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1137: }
1138: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1139: }
1140: }
1141: $r->print('</ul>');
1142: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1143: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1144: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1145: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1146: # FIXME: internationalization seems wrong here
1.329 droeschl 1147: $r->print('<li>'.
1148: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1149: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1150: .'</li>');
1151: }
1152: }
1153: $r->print('</ul>');
1154: }
1155: # End
1156: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1157: $shown++;
1158: if (!($env{'form.show'} eq &mt('all')
1159: || $shown<=$env{'form.show'})) { last; }
1160: }
1.484 raeburn 1161: $r->print(&Apache::loncommon::end_data_table()."\n".
1162: &makesimpleeditform($pathitem)."\n".
1163: '</div></div>');
1164: $r->print(&endContentScreen());
1.329 droeschl 1165: }
1166:
1167: sub update_paste_buffer {
1.484.2.7 raeburn 1168: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1169: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1170: if ($env{'form.multiremove'}) {
1171: $env{'form.multiremove'} =~ s/,$//;
1172: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1173: }
1174: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1175: if ($env{'form.multicut'}) {
1176: $env{'form.multicut'} =~ s/,$//;
1177: foreach my $item (split(/,/,$env{'form.multicut'})) {
1178: unless ($removals{$item}) {
1179: $cuts{$item} = 1;
1180: push(@possibles,$item.':cut');
1181: }
1182: }
1183: }
1184: if ($env{'form.multicopy'}) {
1185: $env{'form.multicopy'} =~ s/,$//;
1186: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1187: unless ($removals{$item} || $cuts{$item}) {
1188: push(@possibles,$item.':copy');
1189: }
1190: }
1191: }
1192: } elsif ($env{'form.markcopy'}) {
1193: @possibles = split(/,/,$env{'form.markcopy'});
1194: }
1.329 droeschl 1195:
1.484.2.30 raeburn 1196: return if (@possibles == 0);
1.329 droeschl 1197: return if (!defined($env{'form.copyfolder'}));
1198:
1199: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1200: $env{'form.copyfolder'});
1201: return if ($fatal);
1202:
1.484.2.30 raeburn 1203: my %curr_groups = &Apache::longroup::coursegroups();
1204:
1205: # Retrieve current paste buffer suffixes.
1206: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1207: my (%pasteurls,@newpaste);
1208:
1209: # Construct identifiers for current contents of user's paste buffer
1210: if (@currpaste) {
1211: foreach my $suffix (@currpaste) {
1.484.2.87 raeburn 1212: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1213: my $url = $env{'docs.markedcopy_url_'.$suffix};
1214: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1215: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1216: ($url ne '')) {
1217: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1218: $pasteurls{$cid.'_'.$mapidx} = 1;
1219: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1220: $pasteurls{$url} = 1;
1221: } else {
1222: $pasteurls{$cid.'_'.$url} = 1;
1223: }
1224: }
1.484.2.30 raeburn 1225: }
1226: }
1227:
1228: # Mark items for copying (skip any items already in user's paste buffer)
1229: my %addtoenv;
1.484.2.82 raeburn 1230:
1231: my @pathitems = split(/\&/,$env{'form.folderpath'});
1232: my @folderconf = split(/\:/,$pathitems[-1]);
1.484.2.87 raeburn 1233: my $ispage = $folderconf[5];
1.484.2.82 raeburn 1234:
1.484.2.30 raeburn 1235: foreach my $item (@possibles) {
1236: my ($orderidx,$cmd) = split(/:/,$item);
1237: next if ($orderidx =~ /\D/);
1238: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1239: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1240: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1241: my %denied = &action_restrictions($coursenum,$coursedom,
1242: &LONCAPA::map::qtescape($url),
1243: $env{'form.folderpath'},\%curr_groups);
1244: next if ($denied{'copy'});
1245: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 1246: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1247: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1248: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1249: next if (exists($pasteurls{$url}));
1250: } else {
1251: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1252: }
1.484.2.30 raeburn 1253: my ($suffix,$errortxt,$locknotfreed) =
1254: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1255: if ($suffix ne '') {
1256: push(@newpaste,$suffix);
1257: } else {
1258: if ($locknotfreed) {
1259: return $locknotfreed;
1260: }
1.484.2.30 raeburn 1261: }
1262: if (&is_supplemental_title($title)) {
1263: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1264: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1265: }
1266:
1267: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1268: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1269: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1270: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1271: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1272: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1273: my $prefix = $1;
1274: my $subdir =$2;
1275: if ($subdir eq '') {
1276: $subdir = $prefix;
1.484.2.7 raeburn 1277: }
1.484.2.30 raeburn 1278: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.484.2.93.2. (raeburn 1279:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1280:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.484.2.30 raeburn 1281: if (ref($hierarchy{$url}) eq 'HASH') {
1282: my ($nested,$nestednames);
1283: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1284: $nested =~ s/\&$//;
1285: $nestednames =~ s/\Q___&&&___\E$//;
1286: if ($nested ne '') {
1287: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1288: }
1289: if ($nestednames ne '') {
1290: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1291: }
1.484.2.7 raeburn 1292: }
1293: }
1.484.2.57 raeburn 1294: if ($locknotfreed) {
1295: $output = $locknotfreed;
1296: last;
1297: }
1.484.2.7 raeburn 1298: }
1.484.2.30 raeburn 1299: if (@newpaste) {
1300: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1301: }
1.484.2.7 raeburn 1302: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1303: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1304: return $output;
1.329 droeschl 1305: }
1306:
1.484.2.7 raeburn 1307: sub recurse_uploaded_maps {
1308: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1309: if (ref($hierarchy->{$url}) eq 'HASH') {
1310: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1311: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1312: my (@uploaded,@names,%shorter);
1313: for (my $i=0; $i<@maps; $i++) {
1314: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1315: if ($inner ne '') {
1316: push(@uploaded,$inner);
1317: push(@names,&escape($titles[$i]));
1318: $shorter{$maps[$i]} = $inner;
1319: }
1320: }
1321: $$nestref .= "$dir:".join(',',@uploaded).'&';
1322: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1323: foreach my $map (@maps) {
1324: if ($shorter{$map} ne '') {
1325: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1326: }
1327: }
1328: }
1329: return;
1330: }
1331:
1.329 droeschl 1332: sub print_paste_buffer {
1.484.2.7 raeburn 1333: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1334: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1335:
1.484.2.30 raeburn 1336: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1337: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1338: }
1339:
1.484.2.30 raeburn 1340: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1341: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1342: my $clipboardcount = 0;
1.484.2.7 raeburn 1343:
1.484.2.30 raeburn 1344: # Construct identifiers for current contents of user's paste buffer
1345: foreach my $suffix (@currpaste) {
1346: next if ($suffix =~ /\D/);
1347: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1348: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1349: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1350: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1351: ($url ne '')) {
1.484.2.47 raeburn 1352: $clipboardcount ++;
1.484.2.30 raeburn 1353: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.484.2.93.2. (raeburn 1354:): $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.484.2.30 raeburn 1355: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1356: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1357: $is_external = 1;
1.484.2.93.2. (raeburn 1358:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1359:): $is_exttool = 1;
1.484.2.7 raeburn 1360: }
1.484.2.30 raeburn 1361: if ($folder =~ /^supplemental/) {
1362: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1363: unless ($canpaste) {
1364: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1365: }
1.484.2.30 raeburn 1366: } else {
1367: $canpaste = 1;
1.484.2.7 raeburn 1368: }
1.484.2.30 raeburn 1369: if ($canpaste) {
1370: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1371: my $srcdom = $1;
1372: my $srcnum = $2;
1373: my $rem = $3;
1374: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1375: $othercourse = 1;
1376: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1377: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1378: } else {
1379: $canpaste = 0;
1380: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1381: }
1382: }
1.484.2.30 raeburn 1383: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1384: my $prefix = $1;
1385: $parent = $2;
1386: if ($folder !~ /^\Q$prefix\E/) {
1387: $areachange = 1;
1388: }
1389: $is_uploaded_map = 1;
1390: }
1.484.2.82 raeburn 1391: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.484.2.93.2. (raeburn 1392:): ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.484.2.76 raeburn 1393: if ($cid ne $env{'request.course.id'}) {
1394: my ($srcdom,$srcnum) = split(/_/,$cid);
1395: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.93.2. (raeburn 1396:): if (($is_exttool) && ($srcdom ne $coursedom)) {
1397:): $canpaste = 0;
1398:): $nopaste = &mt('Paste from another domain unavailable.');
1399:): } else {
1400:): $othercrs = '<br />'.&mt('(from another course)');
1401:): }
1.484.2.76 raeburn 1402: } else {
1403: $canpaste = 0;
1404: $nopaste = &mt('Paste from another course unavailable.');
1405: }
1406: }
1407: }
1408: if ($canpaste) {
1409: push(@pasteable,$suffix);
1.484.2.30 raeburn 1410: }
1411: }
1412: my $buffer;
1413: if ($is_external) {
1414: $buffer = &mt('External Resource').': '.
1415: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1416: &LONCAPA::map::qtescape($url).')';
1.484.2.93.2. (raeburn 1417:): } elsif ($is_exttool) {
1418:): $buffer = &mt('External Tool').': '.
1419:): &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.30 raeburn 1420: } else {
1421: my $icon = &Apache::loncommon::icon($extension);
1422: if ($extension eq 'sequence' &&
1423: $url =~ m{/default_\d+\.sequence$}x) {
1424: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1425: $icon .= '/navmap.folder.closed.gif';
1426: }
1.484.2.57 raeburn 1427: my $title = $env{'docs.markedcopy_title_'.$suffix};
1428: if ($title eq '') {
1429: ($title) = ($url =~ m{/([^/]+)$});
1430: }
1.484.2.30 raeburn 1431: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1432: ': '.
1433: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1434: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1435: }
1436: $pasteitems .= '<div class="LC_left_float">';
1437: my ($options,$onclick);
1438: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1439: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1440: if (($is_uploaded_map) ||
1441: ($url =~ /(bulletinboard|smppg)$/) ||
1442: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1443: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1444: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1445: }
1446: }
1447: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1448: if ($nopaste) {
1449: $pasteitems .= $nopaste;
1450: } else {
1451: if ($othercrs) {
1452: $pasteitems .= $othercrs;
1453: }
1454: if ($options) {
1455: $pasteitems .= $options;
1.484.2.7 raeburn 1456: }
1457: }
1.484.2.30 raeburn 1458: $pasteitems .= '</div>';
1459: }
1460: }
1461: if ($pasteitems eq '') {
1462: &Apache::lonnet::delenv('docs.markedcopies');
1463: }
1464: my ($pasteform,$form_start,$buttons,$form_end);
1465: if ($pasteitems) {
1466: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1467: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1468: if (@pasteable) {
1.484.2.47 raeburn 1469: my $value = &mt('Paste to current folder');
1470: if ($container eq 'page') {
1471: $value = &mt('Paste to current page');
1472: }
1473: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1474: }
1.484.2.93.2. (raeburn 1475:): $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1.484.2.47 raeburn 1476: if ($clipboardcount > 1) {
1477: $buttons .=
1478: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1479: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1480: (' 'x2).
1481: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1482: (' 'x2);
1.484.2.7 raeburn 1483: }
1.484.2.48 raeburn 1484: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1485: '</form>';
1.484.2.30 raeburn 1486: } else {
1487: $pasteitems = &mt('Clipboard is empty');
1488: }
1489: $r->print($form_start
1490: .'<fieldset>'
1491: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1492: .$pasteitems
1493: .'</fieldset>'
1494: .$form_end);
1495: }
1496:
1497: sub paste_options {
1498: my ($suffix,$is_uploaded_map,$parent) = @_;
1499: my ($copytext,$movetext);
1500: if ($is_uploaded_map) {
1501: $copytext = &mt('Copy to new folder');
1502: $movetext = &mt('Move old');
1503: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1504: $copytext = &mt('Copy to new board');
1505: $movetext = &mt('Move (not posts)');
1506: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1507: $copytext = &mt('Copy to new page');
1508: $movetext = &mt('Move');
1.484.2.7 raeburn 1509: } else {
1.484.2.30 raeburn 1510: $copytext = &mt('Copy to new file');
1511: $movetext = &mt('Move');
1512: }
1513: my $output = '<br />'.
1514: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1515: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1516: '<label>'.
1517: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1518: $copytext.'</label></span>'.(' 'x2).' '.
1519: '<span class="LC_nobreak"><label>'.
1520: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1521: $movetext.'</label></span>';
1522: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1523: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1524: '</legend><table border="0">';
1525: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1526: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1527: my $lastdir = $parent;
1528: my %depths = (
1529: $lastdir => 0,
1530: );
1531: my (%display,%deps);
1532: for (my $i=0; $i<@pastemaps; $i++) {
1533: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1534: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1535: my @subfolders = split(/,/,$subfolderstr);
1536: $deps{$lastdir} = \@subfolders;
1537: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1538: my $depth = $depths{$lastdir} + 1;
1539: my $offset = int($depth * 4);
1540: my $indent = (' ' x $offset);
1541: for (my $j=0; $j<@subfolders; $j++) {
1542: $depths{$subfolders[$j]} = $depth;
1543: $display{$subfolders[$j]} =
1544: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1545: '<td><label>'.
1546: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1547: '<label>'.
1548: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1549: &mt('Move old').'</label>'.
1550: '</td></tr>';
1551: }
1552: }
1553: &recurse_print(\$output,$parent,\%deps,\%display);
1554: $output .= '</table></fieldset>';
1.329 droeschl 1555: }
1.484.2.30 raeburn 1556: $output .= '</div>';
1557: return $output;
1.329 droeschl 1558: }
1559:
1.484.2.7 raeburn 1560: sub recurse_print {
1.484.2.30 raeburn 1561: my ($outputref,$dir,$deps,$display) = @_;
1562: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1563: if (ref($deps->{$dir}) eq 'ARRAY') {
1564: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1565: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1566: }
1567: }
1568: }
1569:
1570: sub supp_pasteable {
1571: my ($url) = @_;
1572: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1573: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1574: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1575: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.484.2.93.2. (raeburn 1576:): ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1577:): ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.484.2.7 raeburn 1578: return 1;
1579: }
1580: return;
1581: }
1582:
1583: sub paste_popup_js {
1.484.2.61 raeburn 1584: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1585: show => 'Show Options',
1586: hide => 'Hide Options',
1.484.2.61 raeburn 1587: );
1588: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1589: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1590: );
1.484.2.61 raeburn 1591: &html_escape(\%html_js_lt);
1592: &js_escape(\%html_js_lt);
1593: &js_escape(\%js_lt);
1.484.2.7 raeburn 1594: return <<"END";
1595:
1.484.2.30 raeburn 1596: function showPasteOptions(suffix) {
1597: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1598: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1599: return;
1600: }
1601:
1.484.2.30 raeburn 1602: function hidePasteOptions(suffix) {
1603: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1604: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1605: return;
1606: }
1607:
1.484.2.30 raeburn 1608: function showOptions(caller,suffix) {
1609: if (document.getElementById('pasteoptionstext_'+suffix)) {
1610: if (caller.checked) {
1.484.2.61 raeburn 1611: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1612: } else {
1613: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1614: }
1615: if (document.getElementById('pasteoptions_'+suffix)) {
1616: document.getElementById('pasteoptions_'+suffix).style.display='none';
1617: }
1618: }
1619: return;
1620: }
1.484.2.7 raeburn 1621:
1.484.2.30 raeburn 1622: function validateClipboard() {
1623: var numchk = 0;
1624: if (document.pasteform.pasting.length > 1) {
1625: for (var i=0; i<document.pasteform.pasting.length; i++) {
1626: if (document.pasteform.pasting[i].checked) {
1627: numchk ++;
1628: }
1629: }
1630: } else {
1631: if (document.pasteform.pasting.type == 'checkbox') {
1632: if (document.pasteform.pasting.checked) {
1633: numchk ++;
1634: }
1635: }
1636: }
1637: if (numchk > 0) {
1638: return true;
1639: } else {
1.484.2.61 raeburn 1640: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1641: return false;
1642: }
1.484.2.7 raeburn 1643: }
1644:
1.484.2.47 raeburn 1645: function checkClipboard() {
1646: if (document.pasteform.pasting.length > 1) {
1647: for (var i=0; i<document.pasteform.pasting.length; i++) {
1648: document.pasteform.pasting[i].checked = true;
1649: }
1650: }
1651: return;
1652: }
1653:
1654: function uncheckClipboard() {
1655: if (document.pasteform.pasting.length >1) {
1656: for (var i=0; i<document.pasteform.pasting.length; i++) {
1657: document.pasteform.pasting[i].checked = false;
1658: }
1659: }
1660: return;
1661: }
1662:
1.484.2.30 raeburn 1663: END
1664:
1665: }
1.484.2.7 raeburn 1666:
1.329 droeschl 1667: sub do_paste_from_buffer {
1.484.2.7 raeburn 1668: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1669:
1.484.2.30 raeburn 1670: # Array of items in paste buffer
1671: my (@currpaste,%pastebuffer,%allerrors);
1672: @currpaste = split(/,/,$env{'docs.markedcopies'});
1673:
1.484.2.7 raeburn 1674: # Early out if paste buffer is empty
1.484.2.30 raeburn 1675: if (@currpaste == 0) {
1.484.2.7 raeburn 1676: return ();
1.484.2.30 raeburn 1677: }
1678: map { $pastebuffer{$_} = 1; } @currpaste;
1679:
1680: # Array of items selected items to paste
1681: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1682:
1683: # Early out if nothing selected to paste
1684: if (@reqpaste == 0) {
1685: return();
1686: }
1687: my @topaste;
1688: foreach my $suffix (@reqpaste) {
1689: next if ($suffix =~ /\D/);
1690: next unless (exists($pastebuffer{$suffix}));
1691: push(@topaste,$suffix);
1.484.2.7 raeburn 1692: }
1693:
1.484.2.30 raeburn 1694: # Early out if nothing available to paste
1695: if (@topaste == 0) {
1696: return();
1.329 droeschl 1697: }
1698:
1.484.2.93.2. (raeburn 1699:): my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.484.2.82 raeburn 1700: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1701:
1.484.2.30 raeburn 1702: foreach my $suffix (@topaste) {
1703: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1704: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1705: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1706: # Supplemental content may only include certain types of content
1707: # Early out if pasted content is not supported in Supplemental area
1708: if ($folder =~ /^supplemental/) {
1709: unless (&supp_pasteable($url)) {
1710: $notinsupp{$suffix} = 1;
1711: next;
1712: }
1713: }
1714: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1715: my $srcd = $1;
1716: my $srcn = $2;
1.484.2.7 raeburn 1717: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1718: # check for mdc privilege in the course from which the resource was pasted
1719: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1720: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1721: $notincrs{$suffix} = 1;
1722: next;
1723: }
1.329 droeschl 1724: }
1.484.2.30 raeburn 1725: $srcdom{$suffix} = $srcd;
1726: $srcnum{$suffix} = $srcn;
1.484.2.93.2. (raeburn 1727:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1728:): my ($srcd,$srcn) = split(/_/,$cid);
1729:): # When paste buffer was populated using an active role in a different course
1730:): # check for mdc privilege in the course from which the resource was pasted
1731:): if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1732:): unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1733:): $notincrs{$suffix} = 1;
1734:): next;
1735:): }
1736:): }
1737:): # When buffer was populated using an active role in a different course
1738:): # disallow pasting of External Tool if course is in a different domain.
1739:): if ($srcd ne $coursedom) {
1740:): $notindom{$suffix} = 1;
1741:): next;
1742:): }
1743:): $srcdom{$suffix} = $srcd;
1744:): $srcnum{$suffix} = $srcn;
1.484.2.82 raeburn 1745: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1746: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1747: my ($srcd,$srcn) = split(/_/,$cid);
1748: # When paste buffer was populated using an active role in a different course
1749: # check for mdc privilege in the course from which the resource was pasted
1750: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1751: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1752: $notincrs{$suffix} = 1;
1753: next;
1754: }
1755: }
1756: $srcdom{$suffix} = $srcd;
1757: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1758: }
1.484.2.82 raeburn 1759: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1760: push(@dopaste,$suffix);
1761: if ($url=~/\.(page|sequence)$/) {
1762: $is_map{$suffix} = 1;
1.329 droeschl 1763: }
1.484.2.30 raeburn 1764:
1765: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1766: my $oldprefix = $1;
1.484.2.19 raeburn 1767: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1768: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1769: # a folder/page or a document).
1.484.2.30 raeburn 1770: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1771: $prefixchg{$suffix} = 'docstosupp';
1772: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1773: $prefixchg{$suffix} = 'supptodocs';
1774: }
1.484.2.7 raeburn 1775:
1776: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1777: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1778: my @nested;
1779: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1780: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1781: my @deps = map { /\d+:([\d,]+$)/ } @items;
1782: foreach my $dep (@deps) {
1783: if ($dep =~ /,/) {
1784: push(@nested,split(/,/,$dep));
1785: } else {
1786: push(@nested,$dep);
1787: }
1.484.2.7 raeburn 1788: }
1.484.2.30 raeburn 1789: foreach my $item (@nested) {
1790: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1791: push(@{$marktomove{$suffix}},$type.'_'.$item);
1792: }
1.484.2.7 raeburn 1793: }
1794: }
1.329 droeschl 1795: }
1.484.2.7 raeburn 1796: }
1797:
1.484.2.30 raeburn 1798: # Early out if nothing available to paste
1799: if (@dopaste == 0) {
1800: return ();
1801: }
1802:
1803: # Populate message hash and hashes used for main content <=> supplemental content
1804: # changes
1805:
1806: %msgs = &Apache::lonlocal::texthash (
1807: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1808: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.484.2.93.2. (raeburn 1809:): notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.484.2.30 raeburn 1810: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1811: );
1812:
1813: %before = (
1814: docstosupp => {
1815: map => 'default',
1816: doc => 'docs',
1817: },
1818: supptodocs => {
1819: map => 'supplemental',
1820: doc => 'supplemental',
1821: },
1822: );
1823:
1824: %after = (
1825: docstosupp => {
1826: map => 'supplemental',
1827: doc => 'supplemental'
1828: },
1829: supptodocs => {
1830: map => 'default',
1831: doc => 'docs',
1832: },
1833: );
1834:
1835: # Retrieve information about all course maps in main content area
1836:
1837: my $allmaps = {};
1.484.2.79 raeburn 1838: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1839:
1840: # Loop over the items to paste
1841: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1842: # Maps need to be copied first
1.484.2.30 raeburn 1843: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1844: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1845: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1846: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1847: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1848: }
1849: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1850: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1851: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1852: my $oldurl = $url;
1853: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1854: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1855: my (%hierarchy,%titles);
1.484.2.79 raeburn 1856: if (($folder =~ /^default/) && (!$donechk)) {
1857: $allmaps =
1858: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1859: $env{"course.$env{'request.course.id'}.home"},
1860: $env{'request.course.id'});
1861: $donechk = 1;
1862: }
1.484.2.93.2. (raeburn 1863:): &contained_map_check($url,$folder,$coursenum,$coursedom,
1864:): \%removefrommap,\%removeparam,\%addedmaps,
1865:): \%hierarchy,\%titles,$allmaps);
1.484.2.30 raeburn 1866: if ($url=~ m{^/uploaded/}) {
1867: my $newurl;
1868: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1869: ($newurl,my $error) =
1870: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1871: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1872: \$title,$allmaps,\%newurls);
1873: if ($error) {
1874: $allerrors{$suffix} = $error;
1875: next;
1876: }
1877: if ($newurl ne '') {
1878: if ($newurl ne $url) {
1879: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1880: $newsubdir{$url} = $1;
1881: }
1882: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1883: }
1884: }
1885: }
1.484.2.30 raeburn 1886: if (($srcdom{$suffix} ne $coursedom) ||
1887: ($srcnum{$suffix} ne $coursenum) ||
1888: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1889: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1890: $coursedom,$coursenum,$srcdom{$suffix},
1891: $srcnum{$suffix},$allmaps,\%rewrites,
1892: \%retitles,\%copies,\%dbcopies,
1893: \%zombies,\%params,\%mapmoves,
1894: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 1895: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 1896: $mapmoves{$url} = 1;
1897: }
1898: $url = $newurl;
1899: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1900: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1901: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1902: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1903: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 1904: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 1905: }
1906: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 1907: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1908: push(@toclear,$suffix);
1909: # if pasting published map (main content area only) check map not already in course
1910: if ($folder =~ /^default/) {
1911: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1912: $duplicate{$suffix} = 1;
1913: next;
1914: }
1.484.2.7 raeburn 1915: }
1916: }
1917: }
1.484.2.93.2. (raeburn 1918:): if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.484.2.30 raeburn 1919: my $prefix = $1;
1.484.2.76 raeburn 1920: my $fromothercrs;
1.484.2.30 raeburn 1921: #need to copy the db contents to a new one, unless this is a move.
1922: my %info = (
1923: src => $url,
1924: cdom => $coursedom,
1925: cnum => $coursenum,
1.484.2.76 raeburn 1926: );
1927: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1928: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1929: $fromothercrs = 1;
1930: $info{'cdom'} = $srcdom{$suffix};
1931: $info{'cnum'} = $srcnum{$suffix};
1932: }
1933: }
1934: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1935: my (%lockerr,$msg);
1936: my ($newurl,$result,$errtext) =
1937: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1938: if ($result eq 'ok') {
1939: $url = $newurl;
1940: $title=&mt('Copy of').' '.$title;
1941: } else {
1942: if ($prefix eq 'smppg') {
1943: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1944: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1945: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.93.2. (raeburn 1946:): } elsif ($prefix eq 'ext.tool') {
1947:): $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.484.2.30 raeburn 1948: }
1949: $results{$suffix} = $result;
1950: $msgerrs{$suffix} = $msg;
1951: $lockerrs{$suffix} = $lockerr{$prefix};
1952: next;
1953: }
1954: if ($lockerr{$prefix}) {
1955: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1956: }
1.484.2.7 raeburn 1957: }
1.484.2.30 raeburn 1958: }
1959: $title = &LONCAPA::map::qtunescape($title);
1960: my $ext='false';
1961: if ($url=~m{^http(|s)://}) { $ext='true'; }
1962: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1963: if ($folder !~ /^supplemental/) {
1964: (undef,undef,$title) =
1965: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1966: }
1967: } else {
1968: if ($folder=~/^supplemental/) {
1969: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1970: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1971: }
1972: }
1.484.2.7 raeburn 1973:
1974: # For uploaded files (excluding pages/sequences) path in copied file is changed
1975: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1976: # courses.
1977:
1.484.2.30 raeburn 1978: unless ($is_map{$suffix}) {
1979: my $newidx;
1.329 droeschl 1980: # Now insert the URL at the bottom
1.484.2.30 raeburn 1981: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1982: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1983: my $relpath = $1;
1984: if ($relpath ne '') {
1985: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1986: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1987: my $newprefix = $newloc;
1988: if ($newloc eq 'default') {
1989: $newprefix = 'docs';
1990: }
1991: if ($newdocsdir eq '') {
1992: $newdocsdir = 'default';
1993: }
1994: if (($prefixchg{$suffix}) ||
1995: ($srcdom{$suffix} ne $coursedom) ||
1996: ($srcnum{$suffix} ne $coursenum) ||
1997: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1998: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1999: $url =
2000: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2001: &Apache::lonnet::getfile($oldurl));
2002: if ($url eq '/adm/notfound.html') {
2003: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2004: next;
2005: } else {
2006: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2007: $newsubpath =~ s{/+$}{/};
2008: $docmoves{$oldurl} = $newsubpath;
2009: }
1.484.2.7 raeburn 2010: }
2011: }
1.484.2.82 raeburn 2012: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2013: my $template = $1;
2014: if ($newidx) {
2015: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2016: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2017: }
1.484.2.7 raeburn 2018: }
1.484.2.30 raeburn 2019: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2020: ':'.$ext.':normal:res';
2021: push(@LONCAPA::map::order,$newidx);
2022: # Store the result
2023: my ($errtext,$fatal) =
2024: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2025: if ($fatal) {
2026: $save_err .= $errtext;
2027: $allresult = 'fail';
1.484.2.7 raeburn 2028: }
1.329 droeschl 2029: }
1.484.2.30 raeburn 2030:
1.484.2.82 raeburn 2031: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2032: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 2033: unless ($allresult eq 'fail') {
2034: my %updated = (
2035: rewrites => \%rewrites,
2036: zombies => \%zombies,
2037: removefrommap => \%removefrommap,
2038: removeparam => \%removeparam,
2039: dbcopies => \%dbcopies,
1.484.2.82 raeburn 2040: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 2041: retitles => \%retitles,
2042: );
2043: my %info = (
2044: newsubdir => \%newsubdir,
2045: params => \%params,
2046: );
2047: if ($prefixchg{$suffix}) {
2048: $info{'before'} = $before{$prefixchg{$suffix}};
2049: $info{'after'} = $after{$prefixchg{$suffix}};
2050: }
2051: my %moves = (
2052: copies => \%copies,
2053: docmoves => \%docmoves,
2054: mapmoves => \%mapmoves,
2055: );
2056: (my $result,$msgs{$suffix},my $lockerror) =
2057: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2058: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2059: $url,'paste');
2060: $lockerrors .= $lockerror;
2061: if ($result eq 'ok') {
2062: if ($is_map{$suffix}) {
2063: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2064: $folder.'.'.$container);
2065: if ($fatal) {
2066: $allresult = 'failread';
2067: } else {
2068: if ($#LONCAPA::map::order<1) {
2069: my $idx=&LONCAPA::map::getresidx();
2070: if ($idx<=0) { $idx=1; }
2071: $LONCAPA::map::order[0]=$idx;
2072: $LONCAPA::map::resources[$idx]='';
2073: }
2074: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2075: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2076: ':'.$ext.':normal:res';
2077: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 2078:
2079: # Store the result
1.484.2.30 raeburn 2080: my ($errtext,$fatal) =
2081: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2082: if ($fatal) {
2083: $save_err .= $errtext;
2084: $allresult = 'failstore';
2085: }
2086: }
2087: }
2088: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2089: push(@toclear,$suffix);
2090: }
2091: }
1.329 droeschl 2092: }
2093: }
1.484.2.30 raeburn 2094: &clear_from_buffer(\@toclear,\@currpaste);
2095: my $msgsarray;
2096: foreach my $suffix (keys(%msgs)) {
2097: if (ref($msgs{$suffix}) eq 'ARRAY') {
2098: $msgsarray .= join(',',@{$msgs{$suffix}});
2099: }
2100: }
2101: return ($allresult,$save_err,$msgsarray,$lockerrors);
2102: }
2103:
2104: sub do_buffer_empty {
2105: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2106: if (@currpaste == 0) {
2107: return &mt('Clipboard is already empty');
2108: }
2109: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2110: if (@toclear == 0) {
2111: return &mt('Nothing selected to clear from clipboard');
2112: }
2113: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2114: if ($numdel) {
2115: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2116: } else {
2117: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 2118: }
1.484.2.30 raeburn 2119: return;
2120: }
2121:
2122: sub clear_from_buffer {
2123: my ($toclear,$currpaste) = @_;
2124: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2125: my %pastebuffer;
2126: map { $pastebuffer{$_} = 1; } @{$currpaste};
2127: my $numdel = 0;
2128: foreach my $suffix (@{$toclear}) {
2129: next if ($suffix =~ /\D/);
2130: next unless (exists($pastebuffer{$suffix}));
2131: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2132: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2133: delete($pastebuffer{$suffix});
2134: $numdel ++;
2135: }
2136: }
2137: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2138: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2139: return $numdel;
1.484.2.7 raeburn 2140: }
2141:
2142: sub get_newmap_url {
2143: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2144: $titleref,$allmaps,$newurls) = @_;
2145: my $newurl;
2146: if ($url=~ m{^/uploaded/}) {
2147: $$titleref=&mt('Copy of').' '.$$titleref;
2148: }
2149: my $now = time;
2150: my $suffix=$$.int(rand(100)).$now;
2151: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2152: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2153: my $path = $1;
2154: my $prefix = $2;
2155: my $ancestor = $3;
2156: if (length($ancestor) > 10) {
2157: $ancestor = substr($ancestor,-10,10);
2158: }
2159: my $newid;
2160: if ($prefixchg) {
2161: if ($folder =~ /^supplemental/) {
2162: $prefix =~ s/^default/supplemental/;
2163: } else {
2164: $prefix =~ s/^supplemental/default/;
2165: }
2166: }
2167: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2168: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2169: } else {
2170: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2171: }
2172: my $counter = 0;
2173: my $is_unique = &uniqueness_check($newurl);
2174: if ($folder =~ /^default/) {
2175: if ($allmaps->{$newurl}) {
2176: $is_unique = 0;
2177: }
2178: }
2179: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2180: $counter ++;
2181: $suffix ++;
2182: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2183: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2184: } else {
2185: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2186: }
2187: $is_unique = &uniqueness_check($newurl);
2188: }
2189: if ($is_unique) {
2190: $newurls->{$newurl} = 1;
2191: } else {
2192: if ($url=~/\.page$/) {
2193: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2194: } else {
2195: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2196: }
2197: }
2198: }
2199: return ($newurl);
2200: }
2201:
2202: sub dbcopy {
1.484.2.26 raeburn 2203: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2204: my ($url,$result,$errtext);
2205: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2206: $url = $dbref->{'src'};
1.484.2.93.2. (raeburn 2207:): if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.484.2.26 raeburn 2208: my $prefix = $1;
1.484.2.93.2. (raeburn 2209:): if ($prefix eq 'ext.tool') {
2210:): $prefix = 'exttool';
2211:): }
1.484.2.26 raeburn 2212: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2213: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2214: my $db_name;
2215: my $marker = (split(m{/},$url))[4];
2216: $marker=~s/\D//g;
2217: if ($dbref->{'src'} =~ m{/smppg$}) {
2218: $db_name =
2219: &Apache::lonsimplepage::get_db_name($url,$marker,
2220: $dbref->{'cdom'},
2221: $dbref->{'cnum'});
1.484.2.93.2. (raeburn 2222:): } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2223:): $db_name = 'exttool_'.$marker;
1.484.2.26 raeburn 2224: } else {
2225: $db_name = 'bulletinpage_'.$marker;
2226: }
2227: my ($suffix,$freedlock,$error) =
2228: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2229: $coursedom,$coursenum,
2230: 'concat');
2231: if (!$suffix) {
2232: if ($prefix eq 'smppg') {
2233: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.484.2.93.2. (raeburn 2234:): } elsif ($prefix eq 'exttool') {
2235:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.484.2.26 raeburn 2236: } else {
1.484.2.42 raeburn 2237: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2238: }
2239: if ($error) {
2240: $errtext .= '<br />'.$error;
2241: }
2242: } else {
2243: #need to copy the db contents to a new one.
2244: my %contents=&Apache::lonnet::dump($db_name,
2245: $dbref->{'cdom'},
2246: $dbref->{'cnum'});
2247: if (exists($contents{'uploaded.photourl'})) {
2248: my $photo = $contents{'uploaded.photourl'};
2249: my ($subdir,$fname) =
2250: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2251: my $newphoto;
2252: if ($fname ne '') {
2253: my $content = &Apache::lonnet::getfile($photo);
2254: unless ($content eq '-1') {
2255: $env{'form.'.$suffix.'.photourl'} = $content;
2256: $newphoto =
2257: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2258: delete($env{'form.'.$suffix.'.photourl'});
2259: }
2260: }
2261: if ($newphoto =~ m{^/uploaded/}) {
2262: $contents{'uploaded.photourl'} = $newphoto;
2263: }
2264: }
2265: $db_name =~ s{_\d*$ }{_$suffix}x;
2266: $result=&Apache::lonnet::put($db_name,\%contents,
2267: $coursedom,$coursenum);
2268: if ($result eq 'ok') {
1.484.2.93.2. (raeburn 2269:): $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.484.2.26 raeburn 2270: }
2271: }
2272: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2273: $lockerrorsref->{$prefix} =
2274: '<div class="LC_error">'.
2275: &mt('There was a problem removing a lockfile.');
2276: if ($prefix eq 'smppg') {
2277: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2278: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.93.2. (raeburn 2279:): } elsif ($prefix eq 'exttool') {
2280:): $lockerrorsref->{$prefix} .=
2281:): ' '.&mt('This will prevent addition of more external tools to this course.');
1.484.2.26 raeburn 2282: } else {
1.484.2.42 raeburn 2283: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2284: }
1.484.2.38 raeburn 2285: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2286: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2287: '</div>';
1.484.2.26 raeburn 2288: }
2289: }
2290: } elsif ($url =~ m{/syllabus$}) {
2291: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2292: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2293: if (($dbref->{'cdom'} ne $coursedom) ||
2294: ($dbref->{'cnum'} ne $coursenum)) {
2295: my %contents=&Apache::lonnet::dump('syllabus',
2296: $dbref->{'cdom'},
2297: $dbref->{'cnum'});
2298: $result=&Apache::lonnet::put('syllabus',\%contents,
2299: $coursedom,$coursenum);
2300: }
2301: }
1.484.2.7 raeburn 2302: }
2303: }
1.484.2.26 raeburn 2304: return ($url,$result,$errtext);
1.329 droeschl 2305: }
2306:
1.484.2.82 raeburn 2307: sub copy_templated_files {
2308: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2309: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2310: my $srccontainer = 'sequence';
2311: if ($srcwaspage) {
2312: $srccontainer = 'page';
2313: }
2314: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2315: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2316: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2317: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2318: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2319: $template.'.problem';
2320: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2321: if ($template eq 'simpleproblem') {
2322: $srcprefix .= '.0.';
2323: my $weightprefix = $newprefix;
2324: $newprefix .= '.0.';
2325: my @simpleprobqtypes = qw(radio option string essay numerical);
2326: my $qtype=$srcparms{$srcprefix.'questiontype'};
2327: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2328: my %newdata = (
2329: $newprefix.'questiontype' => $qtype,
1.484.2.84 raeburn 2330: );
1.484.2.82 raeburn 2331: foreach my $type (@simpleprobqtypes) {
2332: if ($type eq $qtype) {
2333: $newdata{"$weightprefix.$type.weight"}=1;
2334: } else {
2335: $newdata{"$weightprefix.$type.weight"}=0;
2336: }
2337: }
2338: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2339: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2340: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2341: if ($qtype eq 'numerical') {
2342: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2343: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2344: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2345: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2346: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2347: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2348: unless (defined($maxfoils)) { $maxfoils=10; }
2349: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2350: if ($maxfoils<=0) { $maxfoils=10; }
2351: my $randomize=$srcparms{$srcprefix.'randomize'};
2352: unless (defined($randomize)) { $randomize='yes'; }
2353: unless ($randomize eq 'no') { $randomize='yes'; }
2354: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2355: $newdata{$newprefix.'randomize'} = $randomize;
2356: if ($qtype eq 'option') {
2357: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2358: }
2359: for (my $i=1; $i<=10; $i++) {
2360: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2361: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2362: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2363: }
2364:
2365: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2366: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2367: unless (defined($maxfoils)) { $maxfoils=10; }
2368: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2369: if ($maxfoils<=0) { $maxfoils=10; }
2370: my $randomize=$srcparms{$srcprefix.'randomize'};
2371: unless (defined($randomize)) { $randomize='yes'; }
2372: unless ($randomize eq 'no') { $randomize='yes'; }
2373: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2374: $newdata{$newprefix.'randomize'} = $randomize;
2375: if ($qtype eq 'option') {
2376: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2377: }
2378: for (my $i=1; $i<=10; $i++) {
2379: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2380: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2381: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2382: }
2383: } elsif ($qtype eq 'string') {
2384: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2385: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2386: }
2387: if (keys(%newdata)) {
2388: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2389: $coursenum);
2390: if ($putres eq 'ok') {
2391: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2392: }
2393: }
2394: }
2395: }
2396: }
2397:
1.329 droeschl 2398: sub uniqueness_check {
2399: my ($newurl) = @_;
2400: my $unique = 1;
2401: foreach my $res (@LONCAPA::map::order) {
2402: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2403: $url=&LONCAPA::map::qtescape($url);
2404: if ($newurl eq $url) {
2405: $unique = 0;
1.344 bisitz 2406: last;
1.329 droeschl 2407: }
2408: }
2409: return $unique;
2410: }
2411:
1.484.2.7 raeburn 2412: sub contained_map_check {
1.484.2.93.2. (raeburn 2413:): my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2414:): $hierarchy,$titles,$allmaps) = @_;
1.484.2.7 raeburn 2415: my $content = &Apache::lonnet::getfile($url);
2416: unless ($content eq '-1') {
2417: my $parser = HTML::TokeParser->new(\$content);
2418: $parser->attr_encoded(1);
2419: while (my $token = $parser->get_token) {
2420: next if ($token->[0] ne 'S');
2421: if ($token->[1] eq 'resource') {
2422: next if ($token->[2]->{'type'} eq 'zombie');
2423: my $ressrc = $token->[2]->{'src'};
2424: if ($folder =~ /^supplemental/) {
2425: unless (&supp_pasteable($ressrc)) {
2426: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2427: next;
2428: }
2429: }
2430: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2431: if ($1 eq 'uploaded') {
2432: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2433: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2434: } else {
2435: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2436: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2437: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2438: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2439: } else {
2440: $addedmaps->{$ressrc} = [$url];
2441: }
2442: }
1.484.2.93.2. (raeburn 2443:): &contained_map_check($ressrc,$folder,$coursenum,$coursedom,
2444:): $removefrommap,$removeparam,
1.484.2.7 raeburn 2445: $addedmaps,$hierarchy,$titles,$allmaps);
2446: }
2447: } elsif ($token->[1] eq 'param') {
2448: if ($folder =~ /^supplemental/) {
2449: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2450: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2451: } else {
1.484.2.19 raeburn 2452: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2453: }
2454: }
2455: }
2456: }
2457: }
2458: return;
2459: }
2460:
2461: sub url_paste_fixups {
1.484.2.26 raeburn 2462: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2463: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2464: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2465: my $checktitle;
2466: if (($prefixchg) &&
2467: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2468: $checktitle = 1;
2469: }
2470: my $skip;
2471: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2472: my $mapid = $1.$2;
2473: if ($tomove->{$mapid}) {
2474: $skip = 1;
2475: }
2476: }
2477: my $file = &Apache::lonnet::getfile($oldurl);
2478: return if ($file eq '-1');
2479: my $parser = HTML::TokeParser->new(\$file);
2480: $parser->attr_encoded(1);
2481: my $changed = 0;
2482: while (my $token = $parser->get_token) {
2483: next if ($token->[0] ne 'S');
2484: if ($token->[1] eq 'resource') {
2485: my $ressrc = $token->[2]->{'src'};
2486: next if ($ressrc eq '');
2487: my $id = $token->[2]->{'id'};
2488: my $title = $token->[2]->{'title'};
2489: if ($checktitle) {
2490: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2491: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2492: }
2493: }
2494: next if ($token->[2]->{'type'} eq 'external');
2495: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2496: next if ($skip);
1.484.2.25 raeburn 2497: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2498: $changed = 1;
2499: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2500: my $srcdom = $1;
2501: my $srcnum = $2;
2502: my $rem = $3;
2503: my $newurl;
2504: my $mapname;
2505: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2506: my $prefix = $1;
2507: $mapname = $prefix.$2;
2508: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2509: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2510: $srcdom,$srcnum,$allmaps,$rewrites,
2511: $retitles,$copies,$dbcopies,$zombies,
2512: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2513: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2514: next;
2515: } else {
2516: ($newurl,my $error) =
2517: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2518: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2519: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2520: $newsubdir->{$ressrc} = $1;
2521: }
2522: if ($error) {
2523: next;
2524: }
2525: }
2526: }
2527: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2528: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2529:
1.484.2.7 raeburn 2530: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2531: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2532: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2533: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2534: $cnum,$srcdom,$srcnum,$allmaps,
2535: $rewrites,$retitles,$copies,$dbcopies,
2536: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2537: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2538: $mapmoves->{$ressrc} = 1;
2539: }
2540: $changed = 1;
2541: } else {
1.484.2.25 raeburn 2542: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2543: $copies->{$oldurl}{$ressrc} = $id;
2544: $changed = 1;
2545: }
2546: }
1.484.2.26 raeburn 2547: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2548: next if ($skip);
1.484.2.7 raeburn 2549: my $srcdom = $1;
2550: my $srcnum = $2;
2551: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2552: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2553: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2554: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2555: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2556: $changed = 1;
2557: }
2558: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2559: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2560: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2561: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2562: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2563: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2564: $changed = 1;
2565: }
1.484.2.82 raeburn 2566: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2567: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2568: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2569: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2570: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2571: }
1.484.2.7 raeburn 2572: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2573: next if ($skip);
2574: my $srcdom = $1;
2575: my $srcnum = $2;
2576: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2577: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2578: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2579: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2580: $changed = 1;
2581: }
2582: }
2583: } elsif ($token->[1] eq 'param') {
2584: next if ($skip);
1.484.2.19 raeburn 2585: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2586: if ($to ne '') {
2587: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2588: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2589: } else {
2590: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2591: }
2592: }
2593: }
2594: }
2595: return $changed;
2596: }
2597:
2598: sub apply_fixups {
1.484.2.23 raeburn 2599: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2600: $oldurl,$url,$caller) = @_;
2601: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2602: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.82 raeburn 2603: %resdatacopy,%lockerrors,$lockmsg);
1.484.2.23 raeburn 2604: if (ref($updated) eq 'HASH') {
2605: if (ref($updated->{'rewrites'}) eq 'HASH') {
2606: %rewrites = %{$updated->{'rewrites'}};
2607: }
2608: if (ref($updated->{'zombies'}) eq 'HASH') {
2609: %zombies = %{$updated->{'zombies'}};
2610: }
2611: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2612: %removefrommap = %{$updated->{'removefrommap'}};
2613: }
2614: if (ref($updated->{'removeparam'}) eq 'HASH') {
2615: %removeparam = %{$updated->{'removeparam'}};
2616: }
2617: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2618: %dbcopies = %{$updated->{'dbcopies'}};
2619: }
2620: if (ref($updated->{'retitles'}) eq 'HASH') {
2621: %retitles = %{$updated->{'retitles'}};
2622: }
1.484.2.82 raeburn 2623: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2624: %resdatacopy = %{$updated->{'resdatacopy'}};
2625: }
1.484.2.23 raeburn 2626: }
2627: if (ref($info) eq 'HASH') {
2628: if (ref($info->{'newsubdir'}) eq 'HASH') {
2629: %newsubdir = %{$info->{'newsubdir'}};
2630: }
2631: if (ref($info->{'params'}) eq 'HASH') {
2632: %params = %{$info->{'params'}};
2633: }
2634: if (ref($info->{'before'}) eq 'HASH') {
2635: %before = %{$info->{'before'}};
2636: }
2637: if (ref($info->{'after'}) eq 'HASH') {
2638: %after = %{$info->{'after'}};
2639: }
2640: }
2641: if (ref($moves) eq 'HASH') {
2642: if (ref($moves->{'copies'}) eq 'HASH') {
2643: %copies = %{$moves->{'copies'}};
2644: }
2645: if (ref($moves->{'docmoves'}) eq 'HASH') {
2646: %docmoves = %{$moves->{'docmoves'}};
2647: }
2648: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2649: %mapmoves = %{$moves->{'mapmoves'}};
2650: }
2651: }
2652: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2653: my @allcopies;
1.484.2.23 raeburn 2654: if (exists($copies{$key})) {
2655: if (ref($copies{$key}) eq 'HASH') {
2656: my %added;
2657: foreach my $innerkey (keys(%{$copies{$key}})) {
2658: if (($innerkey ne '') && (!$added{$innerkey})) {
2659: push(@allcopies,$innerkey);
2660: $added{$innerkey} = 1;
2661: }
1.484.2.7 raeburn 2662: }
1.484.2.23 raeburn 2663: undef(%added);
1.484.2.7 raeburn 2664: }
2665: }
2666: if ($key eq $oldurl) {
1.484.2.23 raeburn 2667: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2668: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2669: push(@allcopies,$oldurl);
2670: }
2671: }
2672: }
2673: if (@allcopies > 0) {
2674: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2675: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2676: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2677: if ($fname ne '') {
2678: my $content = &Apache::lonnet::getfile($item);
2679: unless ($content eq '-1') {
2680: my $storefn;
1.484.2.23 raeburn 2681: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2682: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2683: } else {
2684: $storefn = $relpath;
2685: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2686: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2687: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2688: }
1.484.2.23 raeburn 2689: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2690: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2691: }
2692: }
2693: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2694: my $copyurl =
1.484.2.7 raeburn 2695: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2696: $storefn.$fname,$content);
2697: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2698: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2699: return &mt('Paste failed: an error occurred copying the file.');
2700: } elsif (ref($errors) eq 'HASH') {
2701: $errors->{$item} = 1;
2702: }
2703: }
2704: }
2705: }
2706: }
2707: }
2708: }
1.484.2.23 raeburn 2709: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2710: my $storefn=$key;
2711: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2712: if ($prefixchg && $before{'map'} && $after{'map'}) {
2713: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2714: }
1.484.2.23 raeburn 2715: if ($newsubdir{$key}) {
2716: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2717: }
2718: my $mapcontent = &Apache::lonnet::getfile($key);
2719: if ($mapcontent eq '-1') {
2720: if (ref($errors) eq 'HASH') {
2721: $errors->{$key} = 1;
2722: }
2723: } else {
2724: my $newmap =
2725: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2726: $mapcontent);
2727: if ($newmap eq '/adm/notfound.html') {
2728: if (ref($errors) eq 'HASH') {
2729: $errors->{$key} = 1;
2730: }
2731: }
2732: }
2733: }
2734: my %updates;
2735: if ($is_map) {
1.484.2.23 raeburn 2736: if (ref($updated) eq 'HASH') {
2737: foreach my $type (keys(%{$updated})) {
2738: if (ref($updated->{$type}) eq 'HASH') {
2739: foreach my $key (keys(%{$updated->{$type}})) {
2740: $updates{$key} = 1;
2741: }
2742: }
2743: }
1.484.2.7 raeburn 2744: }
2745: foreach my $key (keys(%updates)) {
2746: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2747: if (ref($rewrites{$key}) eq 'HASH') {
2748: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2749: }
1.484.2.23 raeburn 2750: if (ref($retitles{$key}) eq 'HASH') {
2751: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2752: }
1.484.2.23 raeburn 2753: if (ref($removefrommap{$key}) eq 'HASH') {
2754: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2755: }
1.484.2.23 raeburn 2756: if (ref($removeparam{$key}) eq 'HASH') {
2757: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2758: }
1.484.2.23 raeburn 2759: if (ref($zombies{$key}) eq 'HASH') {
2760: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2761: }
1.484.2.23 raeburn 2762: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2763: foreach my $idx (keys(%{$dbcopies{$key}})) {
2764: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2765: my ($newurl,$result,$errtext) =
2766: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2767: if ($result eq 'ok') {
2768: $newdb{$idx} = $newurl;
2769: } elsif (ref($errors) eq 'HASH') {
2770: $errors->{$key} = 1;
2771: }
2772: push(@msgs,$errtext);
2773: }
1.484.2.7 raeburn 2774: }
2775: }
1.484.2.82 raeburn 2776: if (ref($resdatacopy{$key}) eq 'HASH') {
2777: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2778: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2779: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2780: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2781: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2782: my $template = $1;
2783: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2784: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2785: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2786: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2787: unless ($gotnewmapname) {
2788: ($newmapname) = ($key =~ m{/([^/]+)$});
2789: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2790: if ($newsubdir{$key}) {
2791: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2792: }
2793: $gotnewmapname = 1;
2794: }
2795: my $srcmapinfo = $srcfolder.':'.$idx;
2796: if ($srccontainer eq 'page') {
2797: $srcmapinfo .= ':1';
2798: }
2799: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2800: $cnum,$template,$idx,$newmapname);
2801: }
2802: }
2803: }
2804: }
2805: }
1.484.2.23 raeburn 2806: if (ref($params{$key}) eq 'HASH') {
2807: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2808: }
2809: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2810: if ($fatal) {
1.484.2.26 raeburn 2811: return ($errtext);
1.484.2.7 raeburn 2812: }
2813: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2814: if (defined($LONCAPA::map::zombies[$i])) {
2815: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2816: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2817: undef($LONCAPA::map::zombies[$i]);
2818: }
2819: }
2820: }
1.484.2.77 raeburn 2821: my $total = scalar(@LONCAPA::map::order) - 1;
2822: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2823: my $idx = $LONCAPA::map::order[$i];
2824: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2825: my $changed;
1.484.2.23 raeburn 2826: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2827: if ((exists($toremove{$idx})) &&
2828: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2829: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2830: if (ref($currparam{$idx}) eq 'ARRAY') {
2831: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2832: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2833: }
2834: }
2835: next;
2836: }
2837: my $origsrc = $src;
1.484.2.25 raeburn 2838: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2839: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2840: $changed = 1;
2841: }
2842: }
1.484.2.25 raeburn 2843: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2844: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2845: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2846: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2847: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2848: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2849: } else {
1.484.2.23 raeburn 2850: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2851: }
2852: }
1.484.2.25 raeburn 2853: if ($origsrc =~ /\.(page|sequence)$/) {
2854: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2855: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2856: }
1.484.2.25 raeburn 2857: } elsif ($newsubdir{$key}) {
2858: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2859: }
2860: }
2861: $changed = 1;
1.484.2.26 raeburn 2862: } elsif ($newdb{$idx} ne '') {
2863: $src = $newdb{$idx};
1.484.2.7 raeburn 2864: $changed = 1;
2865: }
2866: if ($changed) {
1.484.2.30 raeburn 2867: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2868: }
2869: }
2870: }
2871: foreach my $idx (keys(%remparam)) {
2872: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2873: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2874: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2875: }
2876: }
2877: }
1.484.2.26 raeburn 2878: if (values(%lockerrors) > 0) {
2879: $lockmsg = join('<br />',values(%lockerrors));
2880: }
1.484.2.7 raeburn 2881: my $storefn;
2882: if ($key eq $oldurl) {
2883: $storefn = $url;
2884: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2885: } else {
2886: $storefn = $key;
2887: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2888: if ($prefixchg && $before{'map'} && $after{'map'}) {
2889: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2890: }
1.484.2.23 raeburn 2891: if ($newsubdir{$key}) {
2892: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2893: }
2894: }
2895: my $report;
2896: if ($folder !~ /^supplemental/) {
2897: $report = 1;
2898: }
1.484.2.20 raeburn 2899: (my $outtext,$errtext) =
1.484.2.7 raeburn 2900: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2901: if ($errtext) {
1.484.2.23 raeburn 2902: if ($caller eq 'paste') {
1.484.2.26 raeburn 2903: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2904: }
1.484.2.7 raeburn 2905: }
2906: }
2907: }
1.484.2.26 raeburn 2908: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2909: }
2910:
2911: sub copy_dependencies {
2912: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2913: my $content;
2914: if (ref($contentref)) {
2915: $content = $$contentref;
2916: } else {
2917: $content = &Apache::lonnet::getfile($item);
2918: }
2919: unless ($content eq '-1') {
2920: my $mm = new File::MMagic;
2921: my $mimetype = $mm->checktype_contents($content);
2922: if ($mimetype eq 'text/html') {
2923: my (%allfiles,%codebase,$state);
2924: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2925: if ($res eq 'ok') {
2926: my ($numexisting,$numpathchanges,$existing);
2927: (undef,$numexisting,$numpathchanges,$existing) =
2928: &Apache::loncommon::ask_for_embedded_content(
2929: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2930: {'error_on_invalid_names' => 1,
2931: 'ignore_remote_references' => 1,
2932: 'docs_url' => $item,
2933: 'context' => 'paste'});
2934: if ($numexisting > 0) {
2935: if (ref($existing) eq 'HASH') {
2936: foreach my $dep (keys(%{$existing})) {
2937: my $depfile = $dep;
2938: unless ($depfile =~ m{^\Q$relpath\E}) {
2939: $depfile = $relpath.$dep;
2940: }
2941: my $depcontent = &Apache::lonnet::getfile($depfile);
2942: unless ($depcontent eq '-1') {
2943: my $storedep = $dep;
2944: $storedep =~ s{^\Q$relpath\E}{};
2945: my $dep_url =
2946: &Apache::lonclonecourse::writefile(
2947: $env{'request.course.id'},
2948: $storefn.$storedep,$depcontent);
2949: if ($dep_url eq '/adm/notfound.html') {
2950: if (ref($errors) eq 'HASH') {
2951: $errors->{$depfile} = 1;
2952: }
2953: } else {
2954: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2955: }
2956: }
2957: }
2958: }
2959: }
2960: }
2961: }
2962: }
2963: return;
2964: }
2965:
1.329 droeschl 2966: my %parameter_type = ( 'randompick' => 'int_pos',
2967: 'hiddenresource' => 'string_yesno',
2968: 'encrypturl' => 'string_yesno',
2969: 'randomorder' => 'string_yesno',);
2970: my $valid_parameters_re = join('|',keys(%parameter_type));
2971: # set parameters
2972: sub update_parameter {
1.484.2.29 raeburn 2973: if ($env{'form.changeparms'} eq 'all') {
2974: my (@allidx,@allmapidx,%allchecked,%currchecked);
2975: %allchecked = (
2976: 'hiddenresource' => {},
2977: 'encrypturl' => {},
2978: 'randompick' => {},
2979: 'randomorder' => {},
2980: );
2981: foreach my $which (keys(%allchecked)) {
2982: $env{'form.all'.$which} =~ s/,$//;
2983: if ($which eq 'randompick') {
2984: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2985: my ($res,$value) = split(/:/,$item);
2986: if ($value =~ /^\d+$/) {
2987: $allchecked{$which}{$res} = $value;
2988: }
2989: }
2990: } else {
1.484.2.30 raeburn 2991: if ($env{'form.all'.$which}) {
2992: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2993: }
1.484.2.29 raeburn 2994: }
2995: }
2996: my $haschanges = 0;
2997: foreach my $res (@LONCAPA::map::order) {
2998: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2999: $name=&LONCAPA::map::qtescape($name);
3000: $url=&LONCAPA::map::qtescape($url);
3001: next unless ($name && $url);
3002: my $is_map;
3003: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3004: $is_map = 1;
3005: }
3006: foreach my $which (keys(%allchecked)) {
3007: if (($which eq 'randompick' || $which eq 'randomorder')) {
3008: next if (!$is_map);
3009: }
3010: my $oldvalue = 0;
3011: my $newvalue = 0;
3012: if ($allchecked{$which}{$res}) {
3013: $newvalue = $allchecked{$which}{$res};
3014: }
3015: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3016: if ($which eq 'randompick') {
3017: if ($current =~ /^(\d+)$/) {
3018: $oldvalue = $1;
3019: }
3020: } else {
3021: if ($current =~ /^yes$/i) {
3022: $oldvalue = 1;
3023: }
3024: }
3025: if ($oldvalue ne $newvalue) {
3026: $haschanges = 1;
3027: if ($newvalue) {
3028: my $storeval = 'yes';
3029: if ($which eq 'randompick') {
3030: $storeval = $newvalue;
3031: }
3032: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3033: $storeval,
3034: $parameter_type{$which});
3035: &remember_parms($res,$which,'set',$storeval);
3036: } elsif ($oldvalue) {
3037: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3038: &remember_parms($res,$which,'del');
3039: }
3040: }
3041: }
3042: }
3043: return $haschanges;
1.329 droeschl 3044: } else {
1.484.2.59 raeburn 3045: my $haschanges = 0;
3046: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 3047:
1.484.2.29 raeburn 3048: my $which = $env{'form.changeparms'};
3049: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 3050: my $oldvalue = 0;
3051: my $newvalue = 0;
3052: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3053: if ($which eq 'randompick') {
3054: if ($current =~ /^(\d+)$/) {
3055: $oldvalue = $1;
3056: }
3057: } elsif ($current =~ /^yes$/i) {
3058: $oldvalue = 1;
3059: }
1.484.2.29 raeburn 3060: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 3061: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3062: : 1;
1.484.2.29 raeburn 3063: }
1.484.2.59 raeburn 3064: if ($oldvalue ne $newvalue) {
3065: $haschanges = 1;
3066: if ($newvalue) {
3067: my $storeval = 'yes';
3068: if ($which eq 'randompick') {
3069: $storeval = $newvalue;
3070: }
3071: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3072: $parameter_type{$which});
3073: &remember_parms($idx,$which,'set',$storeval);
3074: } else {
3075: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3076: &remember_parms($idx,$which,'del');
3077: }
3078: }
3079: return $haschanges;
1.329 droeschl 3080: }
1.484.2.59 raeburn 3081: return;
1.329 droeschl 3082: }
3083:
3084: sub handle_edit_cmd {
3085: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 3086: if ($env{'form.cmd'} eq '') {
3087: return 0;
3088: }
1.329 droeschl 3089: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3090:
3091: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3092: my ($title, $url, @rrest) = split(':', $ratstr);
3093:
1.484.2.30 raeburn 3094: if ($cmd eq 'remove') {
1.329 droeschl 3095: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3096: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3097: &Apache::lonnet::removeuploadedurl($url);
3098: } else {
3099: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3100: }
3101: splice(@LONCAPA::map::order, $idx, 1);
3102:
3103: } elsif ($cmd eq 'cut') {
3104: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3105: splice(@LONCAPA::map::order, $idx, 1);
3106:
1.344 bisitz 3107: } elsif ($cmd eq 'up'
1.329 droeschl 3108: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3109: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3110:
3111: } elsif ($cmd eq 'down'
3112: && defined($LONCAPA::map::order[$idx+1])) {
3113: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3114:
3115: } elsif ($cmd eq 'rename') {
3116: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3117: if ($comment=~/\S/) {
3118: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3119: $comment.':'.join(':', $url, @rrest);
3120: }
3121: # Devalidate title cache
3122: my $renamed_url=&LONCAPA::map::qtescape($url);
3123: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 3124:
1.329 droeschl 3125: } else {
3126: return 0;
3127: }
3128: return 1;
3129: }
3130:
3131: sub editor {
1.458 raeburn 3132: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.93.2. (raeburn 3133:): $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3134:): $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 3135: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3136: if ($allowed) {
3137: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3138: $is_random_order,$container) =
3139: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3140: $r->print($breadcrumbtrail);
3141: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3142: $container = 'page';
3143: } else {
3144: $container = 'sequence';
3145: }
1.484 raeburn 3146:
1.484.2.21 raeburn 3147: my $jumpto;
3148:
3149: unless ($supplementalflag) {
1.484.2.32 raeburn 3150: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 3151: }
1.484 raeburn 3152:
3153: unless ($allowed) {
3154: $randompick = -1;
3155: }
3156:
1.484.2.67 raeburn 3157: my ($errtext,$fatal);
3158: if (($folder eq '') && (!$supplementalflag)) {
3159: if (@LONCAPA::map::order) {
3160: undef(@LONCAPA::map::order);
3161: undef(@LONCAPA::map::resources);
3162: undef(@LONCAPA::map::resparms);
3163: undef(@LONCAPA::map::zombies);
3164: }
3165: $folder = 'default';
3166: $container = 'sequence';
3167: } else {
3168: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3169: $folder.'.'.$container);
3170: return $errtext if ($fatal);
3171: }
1.329 droeschl 3172:
3173: if ($#LONCAPA::map::order<1) {
3174: my $idx=&LONCAPA::map::getresidx();
3175: if ($idx<=0) { $idx=1; }
3176: $LONCAPA::map::order[0]=$idx;
3177: $LONCAPA::map::resources[$idx]='';
3178: }
1.364 bisitz 3179:
1.329 droeschl 3180: # ------------------------------------------------------------ Process commands
3181:
3182: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 3183: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3184: # set parameters and change order
3185: &snapshotbefore();
3186:
3187: if (&update_parameter()) {
1.484.2.59 raeburn 3188: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3189: return $errtext if ($fatal);
3190: }
3191:
3192: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3193: # change order
3194: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3195: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3196:
3197: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3198: return $errtext if ($fatal);
3199: }
1.364 bisitz 3200:
1.329 droeschl 3201: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 3202: my %paste_errors;
1.484.2.26 raeburn 3203: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 3204: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3205: \%paste_errors);
1.484.2.30 raeburn 3206: if (ref($pastemsgarray) eq 'ARRAY') {
3207: if (@{$pastemsgarray} > 0) {
3208: $r->print('<p class="LC_info">'.
3209: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3210: '</p>');
3211: }
1.484.2.30 raeburn 3212: }
3213: if ($lockerror) {
3214: $r->print('<p class="LC_error">'.
3215: $lockerror.
3216: '</p>');
3217: }
3218: if ($save_error ne '') {
3219: return $save_error;
3220: }
3221: if ($paste_res) {
3222: my %errortext = &Apache::lonlocal::texthash (
3223: fail => 'Storage of folder contents failed',
3224: failread => 'Reading folder contents failed',
3225: failstore => 'Storage of folder contents failed',
3226: );
3227: if ($errortext{$paste_res}) {
3228: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3229: }
1.329 droeschl 3230: }
1.484.2.7 raeburn 3231: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3232: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3233: &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".
3234: '<ul>'."\n");
3235: foreach my $key (sort(keys(%paste_errors))) {
3236: $r->print('<li>'.$key.'</li>'."\n");
3237: }
3238: $r->print('</ul></p>'."\n");
3239: }
1.484.2.30 raeburn 3240: } elsif ($env{'form.clearmarked'}) {
3241: my $output = &do_buffer_empty();
3242: if ($output) {
3243: $r->print('<p class="LC_info">'.$output.'</p>');
3244: }
3245: }
1.329 droeschl 3246:
3247: $r->print($upload_output);
3248:
1.484.2.30 raeburn 3249: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3250: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3251: my $contentchg;
1.484.2.58 raeburn 3252: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3253: $contentchg = 1;
3254: }
3255: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3256: return $errtext if ($fatal);
3257: }
1.484.2.30 raeburn 3258:
3259: # Cut, copy and/or remove multiple resources
3260: if ($env{'form.multichange'}) {
3261: my %allchecked = (
3262: cut => {},
3263: remove => {},
3264: );
3265: my $needsupdate;
3266: foreach my $which (keys(%allchecked)) {
3267: $env{'form.multi'.$which} =~ s/,$//;
3268: if ($env{'form.multi'.$which}) {
3269: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3270: if (ref($allchecked{$which}) eq 'HASH') {
3271: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3272: }
3273: }
3274: }
3275: if ($needsupdate) {
3276: my $haschanges = 0;
3277: my %curr_groups = &Apache::longroup::coursegroups();
3278: my $total = scalar(@LONCAPA::map::order) - 1;
3279: for (my $i=$total; $i>=0; $i--) {
3280: my $res = $LONCAPA::map::order[$i];
3281: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3282: $name=&LONCAPA::map::qtescape($name);
3283: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3284: next unless $url;
1.484.2.30 raeburn 3285: my %denied =
3286: &action_restrictions($coursenum,$coursedom,$url,
3287: $env{'form.folderpath'},\%curr_groups);
3288: foreach my $which (keys(%allchecked)) {
3289: next if ($denied{$which});
3290: next unless ($allchecked{$which}{$res});
3291: if ($which eq 'remove') {
3292: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3293: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3294: &Apache::lonnet::removeuploadedurl($url);
3295: } else {
3296: &LONCAPA::map::makezombie($res);
3297: }
3298: splice(@LONCAPA::map::order,$i,1);
3299: $haschanges ++;
3300: } elsif ($which eq 'cut') {
3301: &LONCAPA::map::makezombie($res);
3302: splice(@LONCAPA::map::order,$i,1);
3303: $haschanges ++;
3304: }
3305: }
3306: }
3307: if ($haschanges) {
3308: ($errtext,$fatal) =
3309: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3310: return $errtext if ($fatal);
3311: }
3312: }
3313: }
3314:
1.329 droeschl 3315: # Group import/search
3316: if ($env{'form.importdetail'}) {
3317: my @imports;
3318: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3319: if (defined($item)) {
3320: my ($name,$url,$residx)=
1.484.2.26 raeburn 3321: map { &unescape($_); } split(/\=/,$item);
3322: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3323: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3324: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3325: if ($locknotfreed) {
3326: $r->print($locknotfreed);
3327: }
3328: if ($suffix) {
1.484.2.19 raeburn 3329: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3330: } else {
3331: return $errortxt;
3332: }
1.484.2.26 raeburn 3333: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3334: my $type = $1;
3335: my ($suffix,$errortxt,$locknotfreed) =
3336: &new_timebased_suffix($coursedom,$coursenum,$type);
3337: if ($locknotfreed) {
3338: $r->print($locknotfreed);
3339: }
3340: if ($suffix) {
3341: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3342: } else {
3343: return $errortxt;
3344: }
1.484.2.93.2. (raeburn 3345:): } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3346:): my ($suffix,$errortxt,$locknotfreed) =
3347:): &new_timebased_suffix($coursedom,$coursenum,'exttool');
3348:): if ($locknotfreed) {
3349:): $r->print($locknotfreed);
3350:): }
3351:): if ($suffix) {
3352:): $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3353:): } else {
3354:): return $errortxt;
3355:): }
1.484.2.27 raeburn 3356: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3357: if ($supplementalflag) {
3358: next unless ($1 eq 'supplemental');
3359: if ($folder eq 'supplemental') {
3360: next unless ($2 eq 'default');
3361: } else {
3362: next unless ($folder eq 'supplemental_'.$2);
3363: }
3364: } else {
3365: next unless ($1 eq 'docs');
3366: if ($folder eq 'default') {
3367: next unless ($2 eq 'default');
3368: } else {
3369: next unless ($folder eq 'default_'.$2);
3370: }
3371: }
1.484.2.15 raeburn 3372: }
1.329 droeschl 3373: push(@imports, [$name, $url, $residx]);
3374: }
3375: }
1.484.2.23 raeburn 3376: ($errtext,$fatal,my $fixuperrors) =
3377: &group_import($coursenum, $coursedom, $folder,$container,
1.484.2.93.2. (raeburn 3378:): 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3379: return $errtext if ($fatal);
1.484.2.23 raeburn 3380: if ($fixuperrors) {
3381: $r->print($fixuperrors);
3382: }
1.329 droeschl 3383: }
3384: # Loading a complete map
3385: if ($env{'form.loadmap'}) {
3386: if ($env{'form.importmap'}=~/\w/) {
3387: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3388: my ($title,$url,$ext,$type)=split(/\:/,$res);
3389: my $idx=&LONCAPA::map::getresidx($url);
3390: $LONCAPA::map::resources[$idx]=$res;
3391: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3392: }
3393: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3394: $folder.'.'.$container,1);
1.329 droeschl 3395: return $errtext if ($fatal);
3396: } else {
3397: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3398:
1.329 droeschl 3399: }
3400: }
3401: &log_differences($plain);
3402: }
3403: # ---------------------------------------------------------------- End commands
3404: # ---------------------------------------------------------------- Print screen
3405: my $idx=0;
3406: my $shown=0;
3407: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3408: $r->print('<div class="LC_Box">'.
1.432 raeburn 3409: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3410: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3411: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3412: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3413: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3414: '</ol>');
1.381 bisitz 3415: if ($randompick>=0) {
3416: $r->print('<p class="LC_warning">'
3417: .&mt('Caution: this folder is set to randomly pick a subset'
3418: .' of resources. Adding or removing resources from this'
3419: .' folder will change the set of resources that the'
3420: .' students see, resulting in spurious or missing credit'
3421: .' for completed problems, not limited to ones you'
3422: .' modify. Do not modify the contents of this folder if'
3423: .' it is in active student use.')
3424: .'</p>'
3425: );
3426: }
3427: if ($is_random_order) {
3428: $r->print('<p class="LC_warning">'
3429: .&mt('Caution: this folder is set to randomly order its'
3430: .' contents. Adding or removing resources from this folder'
3431: .' will change the order of resources shown.')
3432: .'</p>'
3433: );
3434: }
3435: $r->print('</div>');
1.364 bisitz 3436: }
1.381 bisitz 3437:
1.484.2.30 raeburn 3438: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3439: %filters = (
3440: canremove => [],
3441: cancut => [],
3442: cancopy => [],
3443: hiddenresource => [],
3444: encrypturl => [],
3445: randomorder => [],
3446: randompick => [],
3447: );
3448: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3449: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3450: foreach my $res (@LONCAPA::map::order) {
3451: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3452: $name=&LONCAPA::map::qtescape($name);
3453: $url=&LONCAPA::map::qtescape($url);
3454: unless ($name) { $name=(split(/\//,$url))[-1]; }
3455: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3456: push(@allidx,$res);
3457: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3458: push(@allmapidx,$res);
3459: }
1.484.2.67 raeburn 3460:
1.381 bisitz 3461: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3462: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3463: $pathitem,$supplementalflag,$container,
1.484.2.93.2. (raeburn 3464:): \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.484.2.80 raeburn 3465: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3466: $idx++;
3467: $shown++;
1.329 droeschl 3468: }
1.424 onken 3469: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3470:
1.484.2.30 raeburn 3471: my $need_save;
1.484.2.67 raeburn 3472: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3473: my $toolslink;
1.484.2.67 raeburn 3474: if ($allowed) {
1.484.2.31 raeburn 3475: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3476: .&Apache::loncommon::help_open_menu('Navigation Screen',
3477: 'Navigation_Screen',undef,'RAT')
3478: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3479: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3480: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3481: .'id="LC_content_toolbar_edittoplevel" '
3482: .'class="LC_toolbarItem" '
3483: .'title="'.&mt('Supplemental Content Editor').'">'
3484: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3485: }
1.484.2.19 raeburn 3486: if ($shown) {
3487: if ($allowed) {
3488: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3489: .&Apache::loncommon::start_data_table(undef,'contentlist')
3490: .&Apache::loncommon::start_data_table_header_row()
3491: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3492: .'<th colspan="2">'.&mt('Actions').'</th>'
3493: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3494: if ($folder !~ /^supplemental/) {
3495: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3496: }
1.484.2.29 raeburn 3497: $to_show .= &Apache::loncommon::end_data_table_header_row();
3498: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3499: $lists{'canhide'} = join(',',@allidx);
3500: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3501: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3502: 'randomorder','randompick');
3503: foreach my $item (@possfilters) {
3504: if (ref($filters{$item}) eq 'ARRAY') {
3505: if (@{$filters{$item}} > 0) {
3506: $lists{$item} = join(',',@{$filters{$item}});
3507: }
3508: }
3509: }
1.484.2.29 raeburn 3510: if (@allidx > 0) {
3511: my $path;
3512: if ($env{'form.folderpath'}) {
3513: $path =
3514: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3515: }
1.484.2.30 raeburn 3516: if (@allidx > 1) {
3517: $to_show .=
3518: &Apache::loncommon::continue_data_table_row().
3519: '<td colspan="2"> </td>'.
3520: '<td>'.
1.484.2.67 raeburn 3521: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3522: '</td>'.
3523: '<td> </td>'.
3524: '<td> </td>'.
3525: '<td colspan="4">'.
1.484.2.67 raeburn 3526: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3527: '</td>'.
3528: &Apache::loncommon::end_data_table_row();
3529: $need_save = 1;
3530: }
1.484.2.29 raeburn 3531: }
3532: }
3533: $to_show .= $output.' '
1.484.2.19 raeburn 3534: .&Apache::loncommon::end_data_table()
3535: .'<br style="line-height:2px;" />'
3536: .&Apache::loncommon::end_scrollbox();
3537: } else {
3538: $to_show .= $toolslink
3539: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3540: .$output.' '
3541: .&Apache::loncommon::end_data_table();
3542: }
3543: } else {
3544: if (!$allowed) {
3545: $to_show .= $toolslink;
1.393 raeburn 3546: }
1.484.2.67 raeburn 3547: my $noresmsg;
3548: if ($allowed && $hiddentop && !$supplementalflag) {
3549: $noresmsg = &mt('Main Content Hidden');
3550: } else {
3551: $noresmsg = &mt('Currently empty');
3552: }
1.484.2.19 raeburn 3553: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3554: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3555: .$noresmsg
1.484.2.19 raeburn 3556: .'</div>'
3557: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3558: }
3559: } else {
1.484.2.19 raeburn 3560: if ($shown) {
3561: $to_show = '<div>'
3562: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3563: .$output
3564: .&Apache::loncommon::end_data_table()
3565: .'</div>';
3566: } else {
3567: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3568: .&mt('Currently empty')
1.484.2.19 raeburn 3569: .'</div>'
3570: }
1.458 raeburn 3571: }
3572: my $tid = 1;
3573: if ($supplementalflag) {
3574: $tid = 2;
1.329 droeschl 3575: }
3576: if ($allowed) {
1.484 raeburn 3577: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3578: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3579: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3580: if ($canedit) {
1.484.2.67 raeburn 3581: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3582: }
1.460 raeburn 3583: } else {
3584: $r->print($to_show);
1.329 droeschl 3585: }
3586: return;
3587: }
3588:
1.484.2.30 raeburn 3589: sub multiple_check_form {
1.484.2.67 raeburn 3590: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3591: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3592: my $disabled;
3593: unless ($canedit) {
3594: $disabled = 'disabled="disabled"';
3595: }
1.484.2.30 raeburn 3596: my $output =
3597: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3598: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3599: '<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>'.
3600: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3601: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3602: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3603: if ($caller eq 'settings') {
3604: $output .=
3605: '<table><tr>'.
3606: '<td class="LC_docs_entry_parameter">'.
3607: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3608: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3609: '</label></span></td>'.
3610: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3611: '<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 3612: '</span></td>'.
3613: '</tr>'."\n".
3614: '<tr>'.
3615: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3616: '<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 3617: '</label></span>'.
3618: '</td></tr></table>'."\n";
3619: } else {
3620: $output .=
3621: '<table><tr>'.
3622: '<td class="LC_docs_entry_parameter">'.
3623: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3624: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3625: '</label></span></td>'.
3626: '<td class="LC_docs_entry_parameter">'.
3627: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3628: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3629: '</label></span></td>'."\n".
3630: '<td class="LC_docs_entry_parameter">'.
3631: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3632: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3633: '</label></span></td>'.
3634: '</tr></table>'."\n";
3635: }
3636: $output .=
3637: '</fieldset>'.
3638: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3639: if ($caller eq 'settings') {
3640: $output .=
3641: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3642: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3643: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3644: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3645: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3646: } elsif ($caller eq 'actions') {
3647: $output .=
3648: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3649: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3650: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3651: }
3652: $output .=
3653: '</form>'.
3654: '</div>';
3655: return $output;
3656: }
3657:
1.329 droeschl 3658: sub process_file_upload {
1.484.2.36 raeburn 3659: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3660: # upload a file, if present
1.484.2.36 raeburn 3661: my $filesize = length($env{'form.uploaddoc'});
3662: if (!$filesize) {
3663: $$upload_output = '<div class="LC_error">'.
3664: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3665: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3666: $filesize).'<br />'.
3667: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3668: '</div>';
3669: return;
3670: }
3671: my $quotatype = 'unofficial';
3672: if ($crstype eq 'Community') {
3673: $quotatype = 'community';
1.484.2.51 raeburn 3674: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3675: $quotatype = 'official';
1.484.2.45 raeburn 3676: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3677: $quotatype = 'textbook';
1.484.2.36 raeburn 3678: }
3679: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3680: $filesize = int($filesize/1000); #expressed in kb
3681: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3682: $env{'form.uploaddoc.filename'},$filesize,
3683: 'upload',$quotatype);
1.484.2.36 raeburn 3684: return if ($$upload_output);
3685: }
1.440 raeburn 3686: my ($parseaction,$showupload,$nextphase,$mimetype);
3687: if ($env{'form.parserflag'}) {
1.329 droeschl 3688: $parseaction = 'parse';
3689: }
3690: my $folder=$env{'form.folder'};
3691: if ($folder eq '') {
3692: $folder='default';
3693: }
3694: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3695: my $errtext='';
3696: my $fatal=0;
3697: my $container='sequence';
1.484.2.19 raeburn 3698: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3699: $container='page';
3700: }
3701: ($errtext,$fatal)=
1.484.2.27 raeburn 3702: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3703: if ($#LONCAPA::map::order<1) {
3704: $LONCAPA::map::order[0]=1;
3705: $LONCAPA::map::resources[1]='';
3706: }
3707: my $destination = 'docs/';
3708: if ($folder =~ /^supplemental/) {
3709: $destination = 'supplemental/';
3710: }
3711: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3712: $destination .= 'default/';
3713: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3714: $destination .= $2.'/';
3715: }
1.484.2.27 raeburn 3716: if ($fatal) {
3717: $$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>';
3718: return;
3719: }
1.440 raeburn 3720: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3721: my $newidx=&LONCAPA::map::getresidx();
3722: $destination .= $newidx;
1.439 raeburn 3723: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3724: $parseaction,$allfiles,
1.440 raeburn 3725: $codebase,undef,undef,undef,undef,
3726: undef,undef,\$mimetype);
3727: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3728: my $stored = $1;
3729: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3730: $stored.'</span>').'</p>';
3731: } else {
3732: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3733:
1.457 raeburn 3734: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3735: return;
3736: }
1.329 droeschl 3737: my $ext='false';
3738: if ($url=~m{^http://}) { $ext='true'; }
3739: $url = &LONCAPA::map::qtunescape($url);
3740: my $comment=$env{'form.comment'};
3741: $comment = &LONCAPA::map::qtunescape($comment);
3742: if ($folder=~/^supplemental/) {
3743: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3744: $env{'user.domain'}.'___&&&___'.$comment;
3745: }
3746:
3747: $LONCAPA::map::resources[$newidx]=
3748: $comment.':'.$url.':'.$ext.':normal:res';
3749: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3750: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3751: $folder.'.'.$container,1);
1.329 droeschl 3752: if ($fatal) {
1.457 raeburn 3753: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3754: return;
1.329 droeschl 3755: } else {
1.440 raeburn 3756: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3757: $$upload_output = $showupload;
1.384 raeburn 3758: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3759: if ($total_embedded > 0) {
1.440 raeburn 3760: my $uploadphase = 'upload_embedded';
3761: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3762: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3763: my ($embedded,$num) =
3764: &Apache::loncommon::ask_for_embedded_content(
3765: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3766: if ($embedded) {
3767: if ($num) {
3768: $$upload_output .=
3769: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3770: $nextphase = $uploadphase;
3771: } else {
3772: $$upload_output .= $embedded;
3773: }
3774: } else {
3775: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3776: }
1.329 droeschl 3777: } else {
1.440 raeburn 3778: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3779: }
1.457 raeburn 3780: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3781: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3782: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3783: $nextphase = 'decompress_uploaded';
3784: my $position = scalar(@LONCAPA::map::order)-1;
3785: my $noextract = &return_to_editor();
3786: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3787: my %archiveitems = (
3788: folderpath => $env{'form.folderpath'},
3789: cmd => $nextphase,
3790: newidx => $newidx,
3791: position => $position,
3792: phase => $nextphase,
1.477 raeburn 3793: comment => $comment,
1.480 raeburn 3794: );
3795: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3796: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3797: $$upload_output = $showupload.
3798: &Apache::loncommon::decompress_form($mimetype,
3799: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3800: \%archiveitems,\@current);
1.329 droeschl 3801: }
3802: }
3803: }
1.440 raeburn 3804: return $nextphase;
1.329 droeschl 3805: }
3806:
1.480 raeburn 3807: sub get_dir_list {
3808: my ($url,$coursenum,$coursedom,$newidx) = @_;
3809: my ($destination,$dir_root) = &embedded_destination();
3810: my ($dirlistref,$listerror) =
3811: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3812: my @dir_lines;
3813: my $dirptr=16384;
3814: if (ref($dirlistref) eq 'ARRAY') {
3815: foreach my $dir_line (sort
3816: {
3817: my ($afile)=split('&',$a,2);
3818: my ($bfile)=split('&',$b,2);
3819: return (lc($afile) cmp lc($bfile));
3820: } (@{$dirlistref})) {
3821: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3822: $filename =~ s/\s+$//;
3823: next if ($filename =~ /^\.\.?$/);
3824: my $isdir = 0;
3825: if ($dirptr&$testdir) {
3826: $isdir = 1;
3827: }
3828: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3829: }
3830: }
3831: return @dir_lines;
3832: }
3833:
1.329 droeschl 3834: sub is_supplemental_title {
3835: my ($title) = @_;
3836: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3837: }
3838:
3839: # --------------------------------------------------------------- An entry line
3840:
3841: sub entryline {
1.484.2.12 raeburn 3842: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3843: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.93.2. (raeburn 3844:): $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.484.2.52 raeburn 3845: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3846: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3847: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3848: } else {
3849: $title=&HTML::Entities::encode($title,'"<>&\'');
3850: $renametitle=$title;
3851: $foldertitle=$title;
3852: }
3853:
1.484.2.67 raeburn 3854: my ($disabled,$readonly,$js_lt);
3855: unless ($canedit) {
3856: $disabled = 'disabled="disabled"';
3857: $readonly = 1;
3858: }
3859:
1.329 droeschl 3860: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3861:
1.329 droeschl 3862: $renametitle=~s/\\/\\\\/g;
3863: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3864: $renametitle=~s/"/%22/g;
1.329 droeschl 3865: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3866: $oldtitle = $renametitle;
3867: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3868: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3869: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3870: # Edit commands
1.484.2.28 raeburn 3871: my ($esc_path, $path, $symb);
1.329 droeschl 3872: if ($env{'form.folderpath'}) {
3873: $esc_path=&escape($env{'form.folderpath'});
3874: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3875: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3876: }
1.484.2.16 raeburn 3877: my $isexternal;
1.484.2.19 raeburn 3878: if ($residx) {
1.484.2.12 raeburn 3879: my $currurl = $url;
3880: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3881: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3882: $isexternal = 1;
3883: }
1.484.2.19 raeburn 3884: if (!$supplementalflag) {
3885: my $path = 'uploaded/'.
3886: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3887: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3888: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3889: $residx,
3890: &Apache::lonnet::declutter($currurl));
3891: }
1.484.2.12 raeburn 3892: }
1.484.2.30 raeburn 3893: my ($renamelink,%lt,$ishash);
3894: if (ref($filtersref) eq 'HASH') {
3895: $ishash = 1;
3896: }
3897:
1.329 droeschl 3898: if ($allowed) {
1.484.2.30 raeburn 3899: $form_start = '
3900: <form action="/adm/coursedocs" method="post">
3901: ';
3902: $form_common=(<<END);
3903: <input type="hidden" name="folderpath" value="$path" />
3904: <input type="hidden" name="symb" value="$symb" />
3905: END
3906: $form_param=(<<END);
3907: <input type="hidden" name="setparms" value="$orderidx" />
3908: <input type="hidden" name="changeparms" value="0" />
3909: END
3910: $form_end = '</form>';
3911:
1.329 droeschl 3912: my $incindex=$index+1;
3913: my $selectbox='';
1.471 raeburn 3914: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3915: ((split(/\:/,
1.344 bisitz 3916: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3917: ne '') &&
1.329 droeschl 3918: ((split(/\:/,
1.344 bisitz 3919: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3920: ne '')) {
3921: $selectbox=
3922: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3923: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3924: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3925: if ($i==$incindex) {
1.358 bisitz 3926: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3927: } else {
3928: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3929: }
3930: }
3931: $selectbox.='</select>';
3932: }
1.484.2.12 raeburn 3933: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3934: 'up' => 'Move Up',
3935: 'dw' => 'Move Down',
3936: 'rm' => 'Remove',
3937: 'ct' => 'Cut',
3938: 'rn' => 'Rename',
1.484.2.12 raeburn 3939: 'cp' => 'Copy',
3940: 'ex' => 'External Resource',
1.484.2.93.2. (raeburn 3941:): 'et' => 'External Tool',
1.484.2.12 raeburn 3942: 'ed' => 'Edit',
3943: 'pr' => 'Preview',
3944: 'sv' => 'Save',
3945: 'ul' => 'URL',
1.484.2.67 raeburn 3946: 'ti' => 'Title',
3947: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3948: );
1.484.2.30 raeburn 3949: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3950: $env{'form.folderpath'},
3951: $currgroups);
1.484.2.19 raeburn 3952: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3953: my $skip_confirm = 0;
1.484.2.63 raeburn 3954: my $confirm_removal = 0;
1.329 droeschl 3955: if ( $folder =~ /^supplemental/
3956: || ($url =~ m{( /smppg$
3957: |/syllabus$
3958: |/aboutme$
3959: |/navmaps$
3960: |/bulletinboard$
1.484.2.93.2. (raeburn 3961:): |/ext\.tool$
1.484.2.16 raeburn 3962: |\.html$)}x)
1.484.2.19 raeburn 3963: || $isexternal) {
1.329 droeschl 3964: $skip_confirm = 1;
3965: }
1.484.2.63 raeburn 3966: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3967: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3968: $confirm_removal = 1;
3969: }
1.484.2.19 raeburn 3970:
1.484.2.30 raeburn 3971: if ($denied{'copy'}) {
3972: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3973: <span style="visibility: hidden;">$lt{'cp'}</span>
3974: ENDCOPY
3975: } else {
1.484.2.30 raeburn 3976: my $formname = 'edit_copy_'.$orderidx;
3977: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3978: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3979: <form name="$formname" method="post" action="/adm/coursedocs">
3980: $form_common
1.484.2.67 raeburn 3981: <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 3982: $form_end
1.329 droeschl 3983: ENDCOPY
1.484.2.30 raeburn 3984: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3985: push(@{$filtersref->{'cancopy'}},$orderidx);
3986: }
1.329 droeschl 3987: }
1.484.2.30 raeburn 3988: if ($denied{'cut'}) {
1.484.2.16 raeburn 3989: $cutlink=(<<ENDCUT);
3990: <span style="visibility: hidden;">$lt{'ct'}</span>
3991: ENDCUT
3992: } else {
1.484.2.30 raeburn 3993: my $formname = 'edit_cut_'.$orderidx;
3994: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3995: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3996: <form name="$formname" method="post" action="/adm/coursedocs">
3997: $form_common
3998: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3999: <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 4000: $form_end
1.329 droeschl 4001: ENDCUT
1.484.2.30 raeburn 4002: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4003: push(@{$filtersref->{'cancut'}},$orderidx);
4004: }
1.329 droeschl 4005: }
1.484.2.30 raeburn 4006: if ($denied{'remove'}) {
1.484.2.16 raeburn 4007: $removelink=(<<ENDREM);
4008: <span style="visibility: hidden;">$lt{'rm'}</a>
4009: ENDREM
4010: } else {
1.484.2.30 raeburn 4011: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 4012: 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 4013: $removelink=(<<ENDREM);
1.484.2.30 raeburn 4014: <form name="$formname" method="post" action="/adm/coursedocs">
4015: $form_common
4016: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 4017: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 4018: <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 4019: $form_end
1.484.2.9 raeburn 4020: ENDREM
1.484.2.30 raeburn 4021: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4022: push(@{$filtersref->{'canremove'}},$orderidx);
4023: }
1.484.2.9 raeburn 4024: }
1.484.2.35 raeburn 4025: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 4026: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 4027: ENDREN
1.484.2.67 raeburn 4028: my ($uplink,$downlink);
4029: if ($canedit) {
4030: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4031: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4032: } else {
4033: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4034: $downlink = $uplink;
4035: }
1.329 droeschl 4036: $line.=(<<END);
4037: <td>
1.379 bisitz 4038: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4039: <a href="$uplink">
1.484.2.12 raeburn 4040: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4041: </a>
4042: </div>
4043: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4044: <a href="$downlink">
1.484.2.12 raeburn 4045: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4046: </a>
4047: </div>
1.329 droeschl 4048: </td>
4049: <td>
4050: $form_start
1.484.2.30 raeburn 4051: $form_param
1.478 raeburn 4052: $form_common
1.329 droeschl 4053: $selectbox
4054: $form_end
4055: </td>
1.484.2.30 raeburn 4056: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 4057: $removelink
1.329 droeschl 4058: $cutlink
4059: $copylink
4060: </td>
4061: END
4062: }
4063: # Figure out what kind of a resource this is
4064: my ($extension)=($url=~/\.(\w+)$/);
4065: my $uploaded=($url=~/^\/*uploaded\//);
4066: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 4067: my $isfolder;
4068: my $ispage;
4069: my $containerarg;
1.484.2.67 raeburn 4070: my $folderurl;
1.329 droeschl 4071: if ($uploaded) {
1.472 raeburn 4072: if (($extension eq 'sequence') || ($extension eq 'page')) {
4073: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 4074: $containerarg = $1;
1.472 raeburn 4075: if ($extension eq 'sequence') {
4076: $icon=$iconpath.'navmap.folder.closed.gif';
4077: $isfolder=1;
4078: } else {
4079: $icon=$iconpath.'page.gif';
4080: $ispage=1;
4081: }
1.484.2.67 raeburn 4082: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4083: if ($allowed) {
4084: $url='/adm/coursedocs?';
4085: } else {
4086: $url='/adm/supplemental?';
4087: }
1.329 droeschl 4088: } else {
4089: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4090: }
4091: }
1.364 bisitz 4092:
1.484.2.70 raeburn 4093: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4094: my $orig_url = $url;
1.340 raeburn 4095: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 4096: if ($container eq 'page') {
4097: $url=~s{^http(|s)(:|:)//}{/ext/};
4098: } else {
4099: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4100: }
1.484.2.12 raeburn 4101: if (!$supplementalflag && $residx && $symb) {
4102: if ((!$isfolder) && (!$ispage)) {
4103: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.484.2.87 raeburn 4104: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4105: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4106: } else {
4107: $url=&Apache::lonnet::clutter($url);
4108: }
1.484.2.12 raeburn 4109: if ($url=~/^\/*uploaded\//) {
4110: $url=~/\.(\w+)$/;
4111: my $embstyle=&Apache::loncommon::fileembstyle($1);
4112: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4113: $url='/adm/wrapper'.$url;
4114: } elsif ($embstyle eq 'ssi') {
4115: #do nothing with these
4116: } elsif ($url!~/\.(sequence|page)$/) {
4117: $url='/adm/coursedocs/showdoc'.$url;
4118: }
1.484.2.70 raeburn 4119: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4120: my $wrapped = $1;
4121: my $exturl = $2;
1.484.2.87 raeburn 4122: if (($wrapped eq '') && ($container ne 'page')) {
1.484.2.70 raeburn 4123: $url='/adm/wrapper'.$url;
4124: }
4125: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4126: $nomodal = 1;
4127: }
1.484.2.93.2. (raeburn 4128:): } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4129:): $url='/adm/wrapper'.$url;
1.484.2.70 raeburn 4130: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4131: if (($ENV{'SERVER_PORT'} == 443) &&
4132: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 4133: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4134: $url .= '?usehttp=1';
4135: }
1.484.2.70 raeburn 4136: $nomodal = 1;
4137: }
1.484.2.19 raeburn 4138: }
1.484.2.12 raeburn 4139: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 4140: my $shownsymb = $symb;
4141: if ($isexternal) {
1.484.2.88 raeburn 4142: $url =~ s/\#[^#]+$//;
1.484.2.87 raeburn 4143: if ($container eq 'page') {
4144: $url = &Apache::lonnet::clutter($url);
4145: }
1.484.2.66 raeburn 4146: }
1.484.2.67 raeburn 4147: unless ($env{'request.role.adv'}) {
4148: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4149: $url = '';
4150: }
4151: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4152: $url = '';
4153: $hiddenres = 1;
4154: }
4155: }
4156: if ($url ne '') {
1.484.2.75 raeburn 4157: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 4158: }
4159: } elsif (!$env{'request.role.adv'}) {
4160: my $checkencrypt;
4161: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4162: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4163: $checkencrypt = 1;
1.484.2.70 raeburn 4164: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 4165: unless (ref($$navmapref)) {
4166: $$navmapref = Apache::lonnavmaps::navmap->new();
4167: }
4168: if (ref($$navmapref)) {
4169: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4170: $checkencrypt = 1;
4171: }
4172: }
4173: }
4174: if ($checkencrypt) {
4175: my $shownsymb = &Apache::lonenc::encrypted($symb);
4176: my $shownurl = &Apache::lonenc::encrypted($url);
4177: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.484.2.80 raeburn 4178: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 4179: if ($env{'request.enc'} ne '') {
4180: delete($env{'request.enc'});
4181: }
4182: } else {
4183: $url='';
4184: }
4185: } else {
4186: $url='';
4187: }
1.484.2.12 raeburn 4188: } else {
4189: $url='';
4190: }
1.484.2.19 raeburn 4191: }
1.484.2.66 raeburn 4192: } elsif ($supplementalflag) {
4193: if ($isexternal) {
4194: if ($url =~ /^([^#]+)#([^#]+)$/) {
4195: $url = $1;
4196: $anchor = $2;
1.484.2.70 raeburn 4197: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.93 raeburn 4198: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4199: if ($hostname ne '') {
4200: $url = 'http://'.$hostname.$url;
4201: }
4202: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4203: }
1.484.2.70 raeburn 4204: $nomodal = 1;
4205: }
4206: }
4207: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4208: if (($ENV{'SERVER_PORT'} == 443) &&
4209: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 4210: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4211: if ($hostname ne '') {
4212: $url = 'http://'.$hostname.$url;
4213: }
4214: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4215: }
1.484.2.70 raeburn 4216: $nomodal = 1;
1.484.2.66 raeburn 4217: }
4218: }
1.329 droeschl 4219: }
1.484.2.67 raeburn 4220: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4221: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4222: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4223: my $foldername=&escape($foldertitle);
4224: my $folderpath=$env{'form.folderpath'};
4225: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4226: if (!$allowed && $supplementalflag) {
4227: $folderpath.=$containerarg.'&'.$foldername;
4228: $url.='folderpath='.&escape($folderpath);
4229: } else {
4230: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4231: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4232: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4233: 'parameter_randomorder'))[0]=~/^yes$/i);
4234: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4235: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4236: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4237: 'parameter_encrypturl'))[0]=~/^yes$/i);
4238: unless ($hiddenmap) {
1.484.2.70 raeburn 4239: if (ref($navmapref)) {
4240: unless (ref($$navmapref)) {
4241: $$navmapref = Apache::lonnavmaps::navmap->new();
4242: }
4243: if (ref($$navmapref)) {
4244: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4245: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4246: unless (@resources) {
4247: $hiddenmap = 1;
4248: unless ($env{'request.role.adv'}) {
4249: $url = '';
4250: $hiddenfolder = 1;
4251: }
1.484.2.67 raeburn 4252: }
4253: }
4254: }
4255: }
4256: }
4257: unless ($encryptmap) {
1.484.2.70 raeburn 4258: if ((ref($navmapref)) && (ref($$navmapref))) {
4259: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4260: $encryptmap = 1;
4261: }
1.484.2.67 raeburn 4262: }
4263: }
4264:
4265: # Append randompick number, hidden, and encrypted with ":" to foldername,
4266: # so it gets transferred between levels
4267: $folderpath.=$containerarg.'&'.$foldername.
4268: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4269: unless ($url eq '') {
4270: $url.='folderpath='.&escape($folderpath);
4271: }
1.484.2.19 raeburn 4272: my $rpckchk;
4273: if ($rpicknum) {
4274: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4275: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4276: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4277: }
1.484.2.19 raeburn 4278: }
1.484.2.29 raeburn 4279: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4280: $rand_pick_text =
1.478 raeburn 4281: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4282: $form_param."\n".
1.478 raeburn 4283: $form_common."\n".
1.484.2.67 raeburn 4284: '<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 4285: if ($rpicknum ne '') {
4286: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4287: }
1.484.2.29 raeburn 4288: $rand_pick_text .= '</span></span>'.
4289: $form_end;
1.484.2.30 raeburn 4290: my $ro_set;
1.484.2.67 raeburn 4291: if ($randorder) {
1.484.2.30 raeburn 4292: $ro_set = 'checked="checked"';
4293: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4294: push(@{$filtersref->{'randomorder'}},$orderidx);
4295: }
4296: }
1.484.2.41 raeburn 4297: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4298: $rand_order_text =
1.484.2.29 raeburn 4299: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4300: $form_param."\n".
1.484.2.29 raeburn 4301: $form_common."\n".
1.484.2.67 raeburn 4302: '<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 4303: $form_end;
1.484.2.19 raeburn 4304: }
1.484.2.18 raeburn 4305: } elsif ($supplementalflag && !$allowed) {
1.484.2.93.2. (raeburn 4306:): my $isexttool;
4307:): if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4308:): $url='/adm/wrapper'.$url;
4309:): $isexttool = 1;
4310:): }
1.484.2.19 raeburn 4311: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4312: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4313: if ($title) {
4314: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4315: }
1.484.2.93.2. (raeburn 4316:): if ((($isexternal) || ($isexttool)) && $orderidx) {
1.484.2.19 raeburn 4317: $url .= '&idx='.$orderidx;
4318: }
1.484.2.66 raeburn 4319: if ($anchor ne '') {
4320: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4321: }
1.329 droeschl 4322: }
1.484.2.19 raeburn 4323: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4324: if ($allowed) {
1.484.2.19 raeburn 4325: my $fileloc =
1.484.2.12 raeburn 4326: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4327: if ($isexternal) {
4328: ($editlink,$extresform) =
1.484.2.67 raeburn 4329: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
1.484.2.93.2. (raeburn 4330:): undef,undef,undef,undef,undef,undef,
4331:): undef,$disabled);
4332:): } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4333:): ($editlink,$extresform) =
4334:): &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4335:): undef,undef,undef,'tool',$coursedom,
4336:): $coursenum,$ltitoolsref,$disabled);
1.484.2.19 raeburn 4337: } elsif (!$isfolder && !$ispage) {
4338: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4339: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4340: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4341: my $suppanchor;
4342: if ($supplementalflag) {
4343: $suppanchor = $anchor;
4344: }
1.484.2.19 raeburn 4345: my $jscall =
1.484.2.12 raeburn 4346: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4347: $switchserver,
1.484.2.14 raeburn 4348: $forceedit,
1.484.2.19 raeburn 4349: undef,$symb,
4350: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4351: $renametitle,$hostname,
4352: '','',1,$suppanchor);
1.484.2.12 raeburn 4353: if ($jscall) {
1.484.2.19 raeburn 4354: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4355: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4356: }
4357: }
4358: }
1.484.2.19 raeburn 4359: $tdalign = ' align="right" valign="top"';
4360: $tdwidth = ' width="80%"';
1.329 droeschl 4361: }
1.408 raeburn 4362: my $reinit;
4363: if ($crstype eq 'Community') {
4364: $reinit = &mt('(re-initialize community to access)');
4365: } else {
4366: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4367: }
4368: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4369: my $link;
1.472 raeburn 4370: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4371: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4372: } elsif ($url) {
1.484.2.66 raeburn 4373: if ($anchor ne '') {
4374: if ($supplementalflag) {
4375: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4376: } else {
4377: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4378: }
4379: }
1.484.2.80 raeburn 4380:
4381: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4382: $link = 'http://'.$hostname.$url;
4383: } else {
4384: $link = $url;
4385: }
4386: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4387: if ($nomodal) {
4388: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4389: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4390: } else {
4391: $line.=&Apache::loncommon::modal_link($link,
4392: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4393: }
1.469 www 4394: } else {
4395: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4396: }
1.484.2.19 raeburn 4397: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4398: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4399: $line.='<a href="'.$url.'">'.$title.'</a>';
4400: } elsif ($url) {
1.484.2.70 raeburn 4401: if ($nomodal) {
4402: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4403: $title.'</a>';
4404: } else {
4405: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4406: }
1.484.2.67 raeburn 4407: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4408: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4409: } else {
4410: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4411: }
1.484.2.19 raeburn 4412: $line.="$extresform</td>";
1.478 raeburn 4413: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4414: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4415: if (($allowed) && ($folder!~/^supplemental/)) {
4416: my %lt=&Apache::lonlocal::texthash(
4417: 'hd' => 'Hidden',
4418: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4419: my ($enctext,$hidtext);
4420: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4421: $enctext = ' checked="checked"';
4422: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4423: push(@{$filtersref->{'encrypturl'}},$orderidx);
4424: }
4425: }
4426: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4427: $hidtext = ' checked="checked"';
4428: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4429: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4430: }
4431: }
1.484.2.29 raeburn 4432: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4433: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4434: $line.=(<<ENDPARMS);
4435: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4436: <form action="/adm/coursedocs" method="post" name="$formhidden">
4437: $form_param
1.478 raeburn 4438: $form_common
1.484.2.67 raeburn 4439: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4440: $form_end
1.458 raeburn 4441: <br />
1.484.2.29 raeburn 4442: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4443: $form_param
1.478 raeburn 4444: $form_common
1.484.2.67 raeburn 4445: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4446: $form_end
4447: </td>
1.478 raeburn 4448: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4449: $rand_order_text</td>
1.329 droeschl 4450: ENDPARMS
4451: }
1.379 bisitz 4452: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4453: return $line;
4454: }
4455:
1.484.2.30 raeburn 4456: sub action_restrictions {
4457: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4458: my %denied = (
4459: cut => 0,
4460: copy => 0,
4461: remove => 0,
4462: );
4463: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4464: # no copy for published maps
4465: $denied{'copy'} = 1;
1.484.2.82 raeburn 4466: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4467: unless ($1 eq 'simpleproblem') {
4468: $denied{'copy'} = 1;
4469: }
4470: $denied{'cut'} = 1;
1.484.2.30 raeburn 4471: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4472: if ($folderpath =~ /^default&[^\&]+$/) {
4473: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4474: $denied{'remove'} = 1;
4475: }
4476: $denied{'cut'} = 1;
4477: $denied{'copy'} = 1;
4478: }
4479: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4480: my $group = $1;
4481: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4482: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4483: $denied{'remove'} = 1;
4484: }
4485: }
4486: $denied{'cut'} = 1;
4487: $denied{'copy'} = 1;
4488: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4489: my $group = $1;
4490: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4491: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4492: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4493: if (keys(%groupsettings) > 0) {
4494: $denied{'remove'} = 1;
4495: }
4496: $denied{'cut'} = 1;
4497: $denied{'copy'} = 1;
4498: }
4499: }
4500: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4501: my $group = $1;
4502: if ($url =~ /group_boards_\Q$group\E/) {
4503: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4504: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4505: if (keys(%groupsettings) > 0) {
4506: if (ref($groupsettings{'functions'}) eq 'HASH') {
4507: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4508: $denied{'remove'} = 1;
4509: }
4510: }
4511: }
4512: $denied{'cut'} = 1;
4513: $denied{'copy'} = 1;
4514: }
4515: }
4516: }
4517: return %denied;
4518: }
4519:
1.484.2.26 raeburn 4520: sub new_timebased_suffix {
1.484.2.30 raeburn 4521: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4522: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4523: if ($type eq 'paste') {
4524: $prefix = $type;
4525: $namespace = 'courseeditor';
1.484.2.56 raeburn 4526: $idtype = 'addcode';
1.484.2.30 raeburn 4527: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4528: $prefix = 'docs';
4529: if ($area eq 'supplemental') {
4530: $prefix = 'supp';
4531: }
4532: $prefix .= $container;
4533: $namespace = 'uploadedmaps';
4534: } else {
4535: $prefix = $type;
4536: $namespace = 'templated';
1.484.2.15 raeburn 4537: }
4538: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4539: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4540: if (!$suffix) {
1.484.2.30 raeburn 4541: if ($type eq 'paste') {
4542: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4543: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4544: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4545: } elsif ($type eq 'smppg') {
4546: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.484.2.93.2. (raeburn 4547:): } elsif ($type eq 'exttool') {
4548:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.484.2.26 raeburn 4549: } else {
1.484.2.42 raeburn 4550: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4551: }
1.484.2.15 raeburn 4552: if ($error) {
4553: $errtext .= '<br />'.$error;
4554: }
4555: }
4556: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4557: $locknotfreed =
4558: '<div class="LC_error">'.
4559: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4560: if ($type eq 'paste') {
1.484.2.57 raeburn 4561: if ($freedlock eq 'nolock') {
4562: $locknotfreed =
4563: '<div class="LC_error">'.
4564: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4565:
1.484.2.60 raeburn 4566: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4567: } else {
4568: $locknotfreed .=
4569: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4570: }
1.484.2.30 raeburn 4571: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4572: $locknotfreed .=
4573: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4574: } elsif ($type eq 'smppg') {
4575: $locknotfreed .=
4576: &mt('This will prevent creation of additional simple pages in this course.');
1.484.2.93.2. (raeburn 4577:): } elsif ($type eq 'exttool') {
4578:): $locknotfreed .=
4579:): &mt('This will prevent creation of additional external tools in this course.');
1.484.2.26 raeburn 4580: } else {
4581: $locknotfreed .=
1.484.2.42 raeburn 4582: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4583: }
1.484.2.30 raeburn 4584: unless ($type eq 'paste') {
4585: $locknotfreed .=
1.484.2.38 raeburn 4586: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4587: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4588: }
4589: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4590: }
4591: return ($suffix,$errtext,$locknotfreed);
4592: }
4593:
1.329 droeschl 4594: =pod
4595:
4596: =item tiehash()
4597:
4598: tie the hash
4599:
4600: =cut
4601:
4602: sub tiehash {
4603: my ($mode)=@_;
4604: $hashtied=0;
4605: if ($env{'request.course.fn'}) {
4606: if ($mode eq 'write') {
4607: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4608: &GDBM_WRCREAT(),0640)) {
4609: $hashtied=2;
4610: }
4611: } else {
4612: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4613: &GDBM_READER(),0640)) {
4614: $hashtied=1;
4615: }
4616: }
1.364 bisitz 4617: }
1.329 droeschl 4618: }
4619:
4620: sub untiehash {
4621: if ($hashtied) { untie %hash; }
4622: $hashtied=0;
4623: return OK;
4624: }
4625:
4626:
4627:
4628:
4629: sub checkonthis {
1.484.2.78 raeburn 4630: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4631: $url=&unescape($url);
4632: $alreadyseen{$url}=1;
4633: $r->rflush();
4634: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4635: $r->print("\n<br />");
4636: if ($level==0) {
4637: $r->print("<br />");
4638: }
4639: for (my $i=0;$i<=$level*5;$i++) {
4640: $r->print(' ');
4641: }
4642: $r->print('<a href="'.$url.'" target="cat">'.
4643: ($title?$title:$url).'</a> ');
4644: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4645: my $updated;
4646: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4647: ($url !~ /\.\d+\.\w+$/)) {
4648: $updated = &Apache::lonnet::remove_stale_resfile($url);
4649: }
1.329 droeschl 4650: my $result=&Apache::lonnet::repcopy(
4651: &Apache::lonnet::filelocation('',$url));
4652: if ($result eq 'ok') {
4653: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4654: if ($updated) {
4655: $r->print('<br />');
4656: for (my $i=0;$i<=$level*5;$i++) {
4657: $r->print(' ');
4658: }
4659: $r->print('- '.&mt('Outdated copy removed'));
4660: }
1.329 droeschl 4661: $r->rflush();
4662: &Apache::lonnet::countacc($url);
4663: $url=~/\.(\w+)$/;
4664: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4665: $r->print('<br />');
4666: $r->rflush();
4667: for (my $i=0;$i<=$level*5;$i++) {
4668: $r->print(' ');
4669: }
4670: $r->print('- '.&mt('Rendering:').' ');
4671: my ($errorcount,$warningcount)=split(/:/,
4672: &Apache::lonnet::ssi_body($url,
4673: ('grade_target'=>'web',
4674: 'return_only_error_and_warning_counts' => 1)));
4675: if (($errorcount) ||
4676: ($warningcount)) {
4677: if ($errorcount) {
1.369 bisitz 4678: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4679: &mt('[quant,_1,error]',$errorcount).'</span>');
4680: }
4681: if ($warningcount) {
4682: $r->print('<span class="LC_warning">'.
4683: &mt('[quant,_1,warning]',$warningcount).'</span>');
4684: }
4685: } else {
4686: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4687: }
4688: $r->rflush();
4689: }
4690: my $dependencies=
4691: &Apache::lonnet::metadata($url,'dependencies');
4692: foreach my $dep (split(/\,/,$dependencies)) {
4693: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4694: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4695: }
4696: }
4697: } elsif ($result eq 'unavailable') {
4698: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4699: } elsif ($result eq 'not_found') {
4700: unless ($url=~/\$/) {
1.484.2.19 raeburn 4701: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4702: } else {
1.366 bisitz 4703: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4704: }
4705: } else {
4706: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4707: }
1.484.2.78 raeburn 4708: if (($updated) && ($result ne 'ok')) {
4709: $r->print('<br />'.&mt('Outdated copy removed'));
4710: }
1.329 droeschl 4711: }
4712: }
4713: }
4714:
4715:
4716:
4717: =pod
4718:
4719: =item list_symbs()
4720:
1.484.2.3 raeburn 4721: List Content Identifiers
1.329 droeschl 4722:
4723: =cut
4724:
4725: sub list_symbs {
4726: my ($r) = @_;
4727:
1.408 raeburn 4728: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4729: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4730: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4731: $r->print(&startContentScreen('tools'));
1.329 droeschl 4732: my $navmap = Apache::lonnavmaps::navmap->new();
4733: if (!defined($navmap)) {
4734: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4735: '<div class="LC_error">'.
4736: &mt('Unable to retrieve information about course contents').
4737: '</div>');
1.408 raeburn 4738: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4739: } else {
1.484 raeburn 4740: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4741: &Apache::loncommon::start_data_table().
4742: &Apache::loncommon::start_data_table_header_row().
4743: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4744: &Apache::loncommon::end_data_table_header_row()."\n");
4745: my $count;
1.329 droeschl 4746: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4747: $r->print(&Apache::loncommon::start_data_table_row().
4748: '<td>'.$res->compTitle().'</td>'.
4749: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4750: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4751: $count ++;
4752: }
4753: if (!$count) {
4754: $r->print(&Apache::loncommon::start_data_table_row().
4755: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4756: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4757: }
1.484 raeburn 4758: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4759: }
1.484.2.19 raeburn 4760: $r->print(&endContentScreen());
1.329 droeschl 4761: }
4762:
1.484.2.93.2. (raeburn 4763:): sub short_urls {
4764:): my ($r,$canedit) = @_;
4765:): my $crstype = &Apache::loncommon::course_type();
4766:): my $formname = 'shortenurl';
4767:): $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4768:): $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4769:): $r->print(&startContentScreen('tools'));
4770:): my ($navmap,$errormsg) =
4771:): &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4772:): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4773:): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4774:): my (%maps,%resources,%titles);
4775:): if (!ref($navmap)) {
4776:): $r->print($errormsg.
4777:): &endContentScreen());
4778:): return '';
4779:): } else {
4780:): $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
4781:): $r->rflush();
4782:): my $readonly;
4783:): if ($canedit) {
4784:): my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
4785:): if ($numnew) {
4786:): $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4787:): }
4788:): if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4789:): $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4790:): foreach my $error (@{$errors}) {
4791:): $r->print('<li>'.$error.'</li>');
4792:): }
4793:): $r->print('</ul><br />');
4794:): }
4795:): } else {
4796:): $readonly = 1;
4797:): }
4798:): my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4799:): $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4800:): undef,undef,undef,undef,undef,\%currtiny,$readonly));
4801:): }
4802:): $r->print(&endContentScreen());
4803:): }
4804:):
1.484.2.78 raeburn 4805: sub contentverifyform {
4806: my ($r) = @_;
4807: my $crstype = &Apache::loncommon::course_type();
4808: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4809: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4810: $r->print(&startContentScreen('tools'));
4811: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4812: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4813: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4814: ' <span class="LC_nobreak">'.
4815: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4816: &mt('No').'</label>'.(' 'x2).
4817: '<label><input type="radio" name="checkstale" value="1" />'.
4818: &mt('Yes').'</label></span></p><p>'.
1.484.2.90 raeburn 4819: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.484.2.78 raeburn 4820: '<input type="hidden" value="1" name="tools" />'.
4821: '<input type="hidden" value="1" name="verify" /></p></form>');
4822: $r->print(&endContentScreen());
4823: return;
4824: }
1.329 droeschl 4825:
4826: sub verifycontent {
1.484.2.78 raeburn 4827: my ($r,$checkstale) = @_;
1.408 raeburn 4828: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4829: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4830: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4831: $r->print(&startContentScreen('tools'));
4832: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4833: $hashtied=0;
4834: undef %alreadyseen;
4835: %alreadyseen=();
4836: &tiehash();
1.484 raeburn 4837:
1.329 droeschl 4838: foreach my $key (keys(%hash)) {
4839: if ($hash{$key}=~/\.(page|sequence)$/) {
4840: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4841: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4842: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4843: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4844: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4845: }
4846: }
4847: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4848: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4849: }
4850: }
4851: &untiehash();
1.442 www 4852: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4853: $r->print(&endContentScreen());
1.329 droeschl 4854: }
4855:
4856:
4857: sub devalidateversioncache {
4858: my $src=shift;
4859: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4860: &Apache::lonnet::clutter($src));
4861: }
4862:
4863: sub checkversions {
1.484.2.67 raeburn 4864: my ($r,$canedit) = @_;
1.408 raeburn 4865: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4866: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4867: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4868: $r->print(&startContentScreen('tools'));
1.442 www 4869:
1.329 droeschl 4870: my $header='';
4871: my $startsel='';
4872: my $monthsel='';
4873: my $weeksel='';
4874: my $daysel='';
4875: my $allsel='';
4876: my %changes=();
4877: my $starttime=0;
4878: my $haschanged=0;
4879: my %setversions=&Apache::lonnet::dump('resourceversions',
4880: $env{'course.'.$env{'request.course.id'}.'.domain'},
4881: $env{'course.'.$env{'request.course.id'}.'.num'});
4882:
4883: $hashtied=0;
4884: &tiehash();
1.484.2.67 raeburn 4885: if ($canedit) {
4886: my %newsetversions=();
4887: if ($env{'form.setmostrecent'}) {
4888: $haschanged=1;
4889: foreach my $key (keys(%hash)) {
4890: if ($key=~/^ids\_(\/res\/.+)$/) {
4891: $newsetversions{$1}='mostrecent';
4892: &devalidateversioncache($1);
4893: }
1.329 droeschl 4894: }
1.484.2.67 raeburn 4895: } elsif ($env{'form.setcurrent'}) {
4896: $haschanged=1;
4897: foreach my $key (keys(%hash)) {
4898: if ($key=~/^ids\_(\/res\/.+)$/) {
4899: my $getvers=&Apache::lonnet::getversion($1);
4900: if ($getvers>0) {
4901: $newsetversions{$1}=$getvers;
4902: &devalidateversioncache($1);
4903: }
4904: }
1.329 droeschl 4905: }
1.484.2.67 raeburn 4906: } elsif ($env{'form.setversions'}) {
4907: $haschanged=1;
4908: foreach my $key (keys(%env)) {
4909: if ($key=~/^form\.set_version_(.+)$/) {
4910: my $src=$1;
4911: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4912: $newsetversions{$src}=$env{$key};
4913: &devalidateversioncache($src);
4914: }
4915: }
1.329 droeschl 4916: }
1.484.2.67 raeburn 4917: }
4918: if ($haschanged) {
4919: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4920: $env{'course.'.$env{'request.course.id'}.'.domain'},
4921: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4922: $r->print(&Apache::loncommon::confirmwrapper(
4923: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4924: } else {
4925: $r->print(&Apache::loncommon::confirmwrapper(
4926: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4927: }
4928: &mark_hash_old();
4929: }
4930: &changewarning($r,'');
1.329 droeschl 4931: }
4932: if ($env{'form.timerange'} eq 'all') {
4933: # show all documents
1.484.2.34 raeburn 4934: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4935: $allsel=' selected="selected"';
1.329 droeschl 4936: foreach my $key (keys(%hash)) {
4937: if ($key=~/^ids\_(\/res\/.+)$/) {
4938: my $src=$1;
4939: $changes{$src}=1;
4940: }
4941: }
4942: } else {
4943: # show documents which changed
4944: %changes=&Apache::lonnet::dump
4945: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4946: $env{'course.'.$env{'request.course.id'}.'.num'});
4947: my $firstkey=(keys(%changes))[0];
4948: unless ($firstkey=~/^error\:/) {
4949: unless ($env{'form.timerange'}) {
4950: $env{'form.timerange'}=604800;
4951: }
4952: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4953: .&mt('seconds');
4954: if ($env{'form.timerange'}==-1) {
4955: $seltext='since start of course';
1.484.2.19 raeburn 4956: $startsel=' selected="selected"';
1.329 droeschl 4957: $env{'form.timerange'}=time;
4958: }
4959: $starttime=time-$env{'form.timerange'};
4960: if ($env{'form.timerange'}==2592000) {
4961: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4962: $monthsel=' selected="selected"';
1.329 droeschl 4963: } elsif ($env{'form.timerange'}==604800) {
4964: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4965: $weeksel=' selected="selected"';
1.329 droeschl 4966: } elsif ($env{'form.timerange'}==86400) {
4967: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4968: $daysel=' selected="selected"';
1.329 droeschl 4969: }
4970: $header=&mt('Content changed').' '.$seltext;
4971: } else {
4972: $header=&mt('No content modifications yet.');
4973: }
4974: }
4975: %setversions=&Apache::lonnet::dump('resourceversions',
4976: $env{'course.'.$env{'request.course.id'}.'.domain'},
4977: $env{'course.'.$env{'request.course.id'}.'.num'});
4978: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4979: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4980: 'lm' => 'Version changes since last Month',
4981: 'lw' => 'Version changes since last Week',
4982: 'sy' => 'Version changes since Yesterday',
4983: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4984: 'cd' => 'Change display',
1.329 droeschl 4985: 'sd' => 'Display',
4986: 'fi' => 'File',
4987: 'md' => 'Modification Date',
4988: 'mr' => 'Most recently published Version',
1.408 raeburn 4989: 've' => 'Version used in '.$crstype,
4990: 'vu' => 'Set Version to be used in '.$crstype,
4991: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4992: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4993: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4994: 'di' => 'Differences',
1.484 raeburn 4995: 'save' => 'Save changes',
4996: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4997: 'act' => 'Actions');
1.484.2.67 raeburn 4998: my ($disabled,$readonly);
4999: unless ($canedit) {
5000: $disabled = 'disabled="disabled"';
5001: $readonly = 1;
5002: }
1.329 droeschl 5003: $r->print(<<ENDHEADERS);
1.484 raeburn 5004: <h4 class="LC_info">$header</h4>
1.329 droeschl 5005: <form action="/adm/coursedocs" method="post">
5006: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5007: <div class="LC_left_float">
1.479 golterma 5008: <fieldset>
1.484 raeburn 5009: <legend>$lt{'cd'}</legend>
1.329 droeschl 5010: <select name="timerange">
1.484.2.19 raeburn 5011: <option value='all'$allsel>$lt{'al'}</option>
5012: <option value="-1"$startsel>$lt{'st'}</option>
5013: <option value="2592000"$monthsel>$lt{'lm'}</option>
5014: <option value="604800"$weeksel>$lt{'lw'}</option>
5015: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5016: </select>
5017: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5018: </fieldset>
5019: </div>
5020: <div class="LC_left_float">
5021: <fieldset>
5022: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 5023: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5024: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5025: </fieldset>
5026: </div>
5027: <br clear="all" />
5028: <hr />
5029: <h4>$lt{'vers'}</h4>
1.329 droeschl 5030: ENDHEADERS
1.479 golterma 5031: #number of columns for version history
1.484.2.44 raeburn 5032: my %changedbytime;
5033: foreach my $key (keys(%changes)) {
5034: #excludes not versionable problems from resource version history:
5035: next if ($key =~ /^\/res\/lib\/templates/);
5036: my $chg;
5037: if ($env{'form.timerange'} eq 'all') {
5038: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5039: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5040: } else {
5041: $chg = $changes{$key};
5042: next if ($chg < $starttime);
5043: }
5044: push(@{$changedbytime{$chg}},$key);
5045: }
5046: if (keys(%changedbytime) == 0) {
5047: &untiehash();
5048: $r->print(&mt('No content changes in imported content in specified time frame').
5049: &endContentScreen());
5050: return;
5051: }
1.479 golterma 5052: $r->print(
1.484.2.67 raeburn 5053: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5054: &Apache::loncommon::start_data_table().
5055: &Apache::loncommon::start_data_table_header_row().
5056: '<th>'.&mt('Resources').'</th>'.
5057: "<th>$lt{'mr'}</th>".
5058: "<th>$lt{'ve'}</th>".
5059: "<th>$lt{'vu'}</th>".
5060: '<th>'.&mt('History').'</th>'.
5061: &Apache::loncommon::end_data_table_header_row()
5062: );
1.484.2.44 raeburn 5063: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5064: foreach my $key (sort(@{$changedbytime{$chg}})) {
5065: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5066: my $currentversion=&Apache::lonnet::getversion($key);
5067: if ($currentversion<0) {
5068: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5069: }
5070: my $linkurl=&Apache::lonnet::clutter($key);
5071: $r->print(
5072: &Apache::loncommon::start_data_table_row().
5073: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5074: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5075: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5076: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5077: '<td align="right">'
5078: );
5079: # Used in course
5080: my $usedversion=$hash{'version_'.$linkurl};
5081: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 5082: if ($usedversion != $currentversion) {
1.479 golterma 5083: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 5084: } else {
1.479 golterma 5085: $r->print($usedversion);
5086: }
1.329 droeschl 5087: } else {
1.484.2.19 raeburn 5088: $r->print($currentversion);
1.329 droeschl 5089: }
1.484.2.44 raeburn 5090: $r->print('</td><td title="'.$lt{'vu'}.'">');
5091: # Set version
5092: $r->print(&Apache::loncommon::select_form(
5093: $setversions{$linkurl},
5094: 'set_version_'.$linkurl,
5095: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5096: '' => '',
5097: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 5098: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 5099: my $lastold=1;
5100: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5101: my $url=$root.'.'.$prevvers.'.'.$extension;
5102: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5103: $lastold=$prevvers;
5104: }
5105: }
5106: $r->print('</td>');
5107: # List all available versions
5108: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5109: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5110: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 5111: $r->print(
1.484.2.44 raeburn 5112: '<span class="LC_nobreak">'
5113: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5114: .&mt('Version [_1]',$prevvers).'</a>'
5115: .' ('.&Apache::lonlocal::locallocaltime(
5116: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5117: .')');
5118: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5119: $r->print(
5120: ' <a href="/adm/diff?filename='.
5121: &Apache::lonnet::clutter($root.'.'.$extension).
5122: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5123: '" target="diffs">'.&mt('Diffs').'</a>');
5124: }
5125: $r->print('</span><br />');
1.329 droeschl 5126: }
1.484.2.44 raeburn 5127: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 5128: }
1.329 droeschl 5129: }
1.484.2.19 raeburn 5130: $r->print(
5131: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 5132: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5133: '</form>'
5134: );
1.329 droeschl 5135:
5136: &untiehash();
1.484.2.19 raeburn 5137: $r->print(&endContentScreen());
1.484.2.44 raeburn 5138: return;
1.329 droeschl 5139: }
5140:
5141: sub mark_hash_old {
5142: my $retie_hash=0;
5143: if ($hashtied) {
5144: $retie_hash=1;
5145: &untiehash();
5146: }
5147: &tiehash('write');
5148: $hash{'old'}=1;
5149: &untiehash();
5150: if ($retie_hash) { &tiehash(); }
5151: }
5152:
5153: sub is_hash_old {
5154: my $untie_hash=0;
5155: if (!$hashtied) {
5156: $untie_hash=1;
5157: &tiehash();
5158: }
5159: my $return=$hash{'old'};
5160: if ($untie_hash) { &untiehash(); }
5161: return $return;
5162: }
5163:
5164: sub changewarning {
5165: my ($r,$postexec,$message,$url)=@_;
5166: if (!&is_hash_old()) { return; }
5167: my $pathvar='folderpath';
5168: my $path=&escape($env{'form.folderpath'});
5169: if (!defined($url)) {
5170: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5171: }
5172: my $course_type = &Apache::loncommon::course_type();
5173: if (!defined($message)) {
5174: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5175: }
5176: $r->print("\n\n".
1.372 bisitz 5177: '<script type="text/javascript">'."\n".
5178: '// <![CDATA['."\n".
5179: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5180: '// ]]>'."\n".
1.369 bisitz 5181: '</script>'."\n".
1.375 tempelho 5182: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5183: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5184: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5185: &mt($message,' <input type="hidden" name="'.
5186: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5187: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5188: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5189: }
5190:
5191:
5192: sub init_breadcrumbs {
1.484.2.44 raeburn 5193: my ($form,$text,$help)=@_;
1.329 droeschl 5194: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5195: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5196: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5197: faq=>273,
5198: bug=>'Instructor Interface',
1.484.2.44 raeburn 5199: help => $help});
1.329 droeschl 5200: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5201: text=>$text,
5202: faq=>273,
5203: bug=>'Instructor Interface'});
5204: }
5205:
1.441 www 5206: # subroutine to list form elements
5207: sub create_list_elements {
5208: my @formarr = @_;
5209: my $list = '';
1.484.2.12 raeburn 5210: foreach my $button (@formarr){
5211: foreach my $picture (keys(%{$button})) {
5212: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5213: }
5214: }
5215: return $list;
5216: }
1.329 droeschl 5217:
1.441 www 5218: # subroutine to create ul from list elements
5219: sub create_form_ul {
5220: my $list = shift;
5221: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5222: return $ul;
5223: }
1.329 droeschl 5224:
1.442 www 5225: #
5226: # Start tabs
5227: #
5228:
5229: sub startContentScreen {
1.484 raeburn 5230: my ($mode) = @_;
5231: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5232: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5233: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5234: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5235: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5236: } else {
1.484.2.34 raeburn 5237: $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 5238: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5239: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5240: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5241: }
5242: $output .= "\n".'</ul>'."\n";
5243: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5244: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5245: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5246: return $output;
1.442 www 5247: }
5248:
5249: #
5250: # End tabs
5251: #
5252:
5253: sub endContentScreen {
1.484 raeburn 5254: return '</div></div></div>';
1.442 www 5255: }
1.329 droeschl 5256:
1.446 www 5257: sub supplemental_base {
1.484.2.33 raeburn 5258: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5259: }
5260:
1.329 droeschl 5261: sub handler {
5262: my $r = shift;
5263: &Apache::loncommon::content_type($r,'text/html');
5264: $r->send_http_header;
5265: return OK if $r->header_only;
1.484 raeburn 5266:
5267: # get course data
1.408 raeburn 5268: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5269: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5270: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5271:
5272: # graphics settings
5273: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5274:
1.443 www 5275: #
1.329 droeschl 5276: # --------------------------------------------- Initialize help topics for this
5277: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.484.2.93.2. (raeburn 5278:): 'Adding_External_Resource','Adding_External_Tool',
5279:): 'Navigate_Content','Adding_Folders','Docs_Overview',
5280:): 'Load_Map','Supplemental','Score_Upload_Form',
5281:): 'Adding_Pages','Importing_LON-CAPA_Resource',
5282:): 'Importing_IMS_Course',Uploading_From_Harddrive',
5283:): 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5284: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5285: }
5286: # Composite help files
5287: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5288: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5289: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5290: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5291: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5292: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5293: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5294: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5295: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5296: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5297:
1.484.2.67 raeburn 5298: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 5299: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5300: unless ($r->uri eq '/adm/supplemental') {
5301: # does this user have privileges to modify content.
1.484.2.67 raeburn 5302: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5303: $allowed = 1;
5304: $canedit = 1;
5305: $canview = 1;
5306: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5307: $allowed = 1;
5308: $canview = 1;
5309: }
5310: }
5311: unless ($canedit) {
5312: $disabled = ' disabled="disabled"';
1.472 raeburn 5313: }
1.484.2.53 raeburn 5314: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5315: if ($env{'form.inhibitmenu'}) {
5316: unless ($env{'form.inhibitmenu'} eq 'yes') {
5317: delete($env{'form.inhibitmenu'});
5318: }
5319: }
5320:
1.484.2.53 raeburn 5321: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5322: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5323: if (!$canedit) {
5324: &verifycontent($r);
5325: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5326: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5327: text=>'Results',
5328: faq=>273,
5329: bug=>'Instructor Interface'});
5330: &verifycontent($r,$env{'form.checkstale'});
5331: } else {
5332: &contentverifyform($r);
5333: }
1.329 droeschl 5334: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5335: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5336: &list_symbs($r);
1.484.2.93.2. (raeburn 5337:): } elsif ($allowed && $env{'form.shorturls'}) {
5338:): &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5339:): &short_urls($r,$canedit);
1.329 droeschl 5340: } elsif ($allowed && $env{'form.docslog'}) {
5341: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5342: my $folder = $env{'form.folder'};
5343: if ($folder eq '') {
5344: $folder='default';
5345: }
1.484.2.67 raeburn 5346: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5347: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5348: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5349: &checkversions($r,$canedit);
5350: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5351: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5352: &dumpcourse($r);
5353: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5354: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5355: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5356: } else {
1.445 www 5357: #
5358: # Done catching special calls
1.484 raeburn 5359: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5360: # Get the parameters that may be needed
5361: #
5362: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5363: ['folderpath',
5364: 'forcesupplement','forcestandard',
5365: 'tools','symb','command','supppath']);
1.445 www 5366:
1.484.2.78 raeburn 5367: foreach my $item ('forcesupplement','forcestandard','tools') {
5368: next if ($env{'form.'.$item} eq '');
5369: unless ($env{'form.'.$item} eq '1') {
5370: delete($env{'form.'.$item});
5371: }
5372: }
5373:
5374: if ($env{'form.command'}) {
5375: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5376: delete($env{'form.command'});
5377: }
5378: }
5379:
5380: if ($env{'form.symb'}) {
5381: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5382: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5383: delete($env{'form.symb'});
5384: }
5385: }
5386:
1.445 www 5387: # standard=1: this is a "new-style" course with an uploaded map as top level
5388: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5389:
5390: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5391:
1.484 raeburn 5392: # Decide whether this should display supplemental or main content or utilities
1.445 www 5393: # supplementalflag=1: show supplemental documents
5394: # supplementalflag=0: show standard documents
1.484 raeburn 5395: # toolsflag=1: show utilities
1.445 www 5396:
1.484.2.39 raeburn 5397: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5398: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5399: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5400: $supplementalflag=0;
5401: }
5402: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5403: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5404: unless ($allowed) { $supplementalflag=1; }
5405: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5406: my $toolsflag=0;
5407: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5408:
1.484.2.78 raeburn 5409: if ($env{'form.folderpath'} ne '') {
1.484.2.92 raeburn 5410: &validate_folderpath($supplementalflag);
1.484.2.78 raeburn 5411: }
5412:
5413: if ($env{'form.supppath'} ne '') {
1.484.2.92 raeburn 5414: &validate_suppath();
1.484.2.78 raeburn 5415: }
5416:
1.329 droeschl 5417: my $script='';
5418: my $showdoc=0;
1.457 raeburn 5419: my $addentries = {};
1.475 raeburn 5420: my $container;
1.329 droeschl 5421: my $containertag;
1.484.2.17 raeburn 5422: my $pathitem;
1.484.2.93.2. (raeburn 5423:): my %ltitools;
1.484.2.67 raeburn 5424: my $hiddentop;
5425: my $navmap;
5426: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5427:
1.464 www 5428: # Do we directly jump somewhere?
1.484.2.21 raeburn 5429: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5430: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5431: $env{'form.folderpath'}=
1.484.2.67 raeburn 5432: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5433: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5434: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5435: } elsif ($env{'form.supppath'} ne '') {
5436: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5437: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5438: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5439: }
1.472 raeburn 5440: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5441: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5442: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5443: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5444: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5445: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5446: } elsif ($env{'form.command'} eq 'contents') {
5447: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5448: } elsif ($env{'form.command'} eq 'home') {
5449: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5450: }
5451:
1.484.2.23 raeburn 5452:
1.445 www 5453: # Where do we store these for when we come back?
5454: my $stored_folderpath='docs_folderpath';
5455: if ($supplementalflag) {
5456: $stored_folderpath='docs_sup_folderpath';
5457: }
1.464 www 5458:
1.484.2.19 raeburn 5459: # No folderpath, and in edit mode, see if we have something stored
5460: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5461: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5462: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5463:
5464: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5465: if ($supplementalflag) {
5466: undef($env{'form.folderpath'}) if ($1 eq 'default');
5467: } else {
5468: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5469: }
5470: } else {
1.484.2.19 raeburn 5471: undef($env{'form.folderpath'});
5472: }
1.484.2.92 raeburn 5473: if ($env{'form.folderpath'} ne '') {
5474: &validate_folderpath($supplementalflag);
5475: }
1.329 droeschl 5476: }
1.446 www 5477:
5478: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5479: if (!$allowed) {
1.446 www 5480: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5481: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5482: }
5483: }
1.446 www 5484: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5485: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5486: $env{'form.folderpath'} = &supplemental_base()
5487: .'&'.
1.329 droeschl 5488: $env{'form.folderpath'};
5489: }
1.484.2.67 raeburn 5490: # If allowed and user's role is not advanced check folderpath is not hidden
5491: if (($allowed) && (!$env{'request.role.adv'}) &&
5492: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5493: my $folderurl;
5494: my @pathitems = split(/\&/,$env{'form.folderpath'});
5495: my $folder = $pathitems[-2];
5496: if ($folder eq '') {
5497: undef($env{'form.folderpath'});
5498: } else {
5499: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.87 raeburn 5500: if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 5501: $folderurl .= '.page';
5502: } else {
5503: $folderurl .= '.sequence';
5504: }
5505: unless (ref($navmap)) {
5506: $navmap = Apache::lonnavmaps::navmap->new();
5507: }
5508: if (ref($navmap)) {
5509: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5510: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5511: unless (@resources) {
5512: undef($env{'form.folderpath'});
5513: }
5514: }
5515: }
5516: }
5517: }
5518:
5519:
1.446 www 5520: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5521: unless ($env{'form.folderpath'}) {
1.446 www 5522: if ($supplementalflag) {
5523: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5524: } elsif ($allowed) {
5525: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5526: }
1.472 raeburn 5527: }
1.446 www 5528:
1.445 www 5529: # Store this
1.484 raeburn 5530: unless ($toolsflag) {
1.484.2.67 raeburn 5531: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5532: &Apache::loncommon::store_course_settings($stored_folderpath,
5533: {'folderpath' => 'scalar'});
5534: }
5535: my $folderpath;
1.484 raeburn 5536: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5537: $folderpath = $env{'form.folderpath'};
5538: my (@folders)=split('&',$env{'form.folderpath'});
5539: $env{'form.foldername'}=&unescape(pop(@folders));
5540: if ($env{'form.foldername'} =~ /\:1$/) {
5541: $container = 'page';
5542: } else {
5543: $container = 'sequence';
5544: }
5545: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5546: } else {
1.484.2.19 raeburn 5547: if ($env{'form.folder'} eq '' ||
5548: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5549: if ($env{'form.folder'} eq 'supplemental') {
5550: $folderpath=&supplemental_base();
5551: } elsif (!$hiddentop) {
5552: $folderpath='default&'.
5553: &escape(&mt('Main Content').':::::');
5554: }
1.484 raeburn 5555: }
5556: }
1.484.2.19 raeburn 5557: $containertag = '<input type="hidden" name="folderpath" value="" />';
5558: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5559: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5560: $showdoc='/'.$1;
5561: }
5562: if ($showdoc) { # got called in sequence from course
5563: $allowed=0;
5564: } else {
1.484.2.67 raeburn 5565: if ($canedit) {
1.484 raeburn 5566: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5567: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5568: }
5569: }
1.329 droeschl 5570: }
5571:
1.344 bisitz 5572: # get personal data
1.329 droeschl 5573: my $uname=$env{'user.name'};
5574: my $udom=$env{'user.domain'};
5575: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5576:
5577: if ($allowed) {
1.484 raeburn 5578: if ($toolsflag) {
5579: $script .= &inject_data_js();
5580: my ($home,$other,%outhash)=&authorhosts();
5581: if (!$home && $other) {
5582: my @hosts;
5583: foreach my $aurole (keys(%outhash)) {
5584: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5585: push(@hosts,$outhash{$aurole});
5586: }
5587: }
5588: $script .= &dump_switchserver_js(@hosts);
5589: }
1.458 raeburn 5590: } else {
1.484.2.43 raeburn 5591: my $tid = 1;
1.484 raeburn 5592: my @tabids;
5593: if ($supplementalflag) {
5594: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5595: $tid = 2;
1.484 raeburn 5596: } else {
5597: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5598: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5599: unshift(@tabids,'001');
5600: push(@tabids,('dd1','ee1'));
5601: }
1.458 raeburn 5602: }
1.484 raeburn 5603: my $tabidstr = join("','",@tabids);
1.484.2.93.2. (raeburn 5604:): %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
5605:): my $posslti = keys(%ltitools);
1.484.2.80 raeburn 5606: my $hostname = $r->hostname();
1.484.2.93.2. (raeburn 5607:): $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 5608: $canedit,$hostname,\$navmap).
1.484 raeburn 5609: &history_tab_js().
5610: &inject_data_js().
1.484.2.43 raeburn 5611: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.93.2. (raeburn 5612:): &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5613: $addentries = {
1.484.2.3 raeburn 5614: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5615: };
1.458 raeburn 5616: }
1.484.2.30 raeburn 5617: $script .= &paste_popup_js();
1.484.2.12 raeburn 5618: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5619: &mt('Switch server?');
1.484.2.19 raeburn 5620:
5621:
1.329 droeschl 5622: }
5623: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5624: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5625: .'// <![CDATA['."\n"
5626: .$script."\n"
5627: .'// ]]>'."\n"
1.484.2.81 raeburn 5628: .'</script>'."\n"
5629: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5630:
5631: # Breadcrumbs
5632: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5633:
5634: if ($showdoc) {
5635: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5636: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5637: } elsif ($toolsflag) {
1.484.2.67 raeburn 5638: my ($breadtext,$breadtitle);
5639: $breadtext = "$crstype Editor";
5640: if ($canedit) {
5641: $breadtitle = 'Editing '.$crstype.' Contents';
5642: } else {
5643: $breadtext .= ' (View-only mode)';
5644: $breadtitle = 'Viewing '.$crstype.' Contents';
5645: }
1.484.2.44 raeburn 5646: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5647: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5648: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5649: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5650: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5651: $breadtitle)
1.484.2.44 raeburn 5652: );
1.484.2.19 raeburn 5653: } elsif ($r->uri eq '/adm/supplemental') {
5654: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5655: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5656: {'bread_crumbs' => $brcrum,}));
5657: } else {
1.484.2.67 raeburn 5658: my ($breadtext,$breadtitle,$helpitem);
5659: $breadtext = "$crstype Editor";
5660: if ($canedit) {
5661: $breadtitle = 'Editing '.$crstype.' Contents';
5662: $helpitem = 'Docs_Adding_Course_Doc';
5663: } else {
5664: $breadtext .= ' (View-only mode)';
5665: $breadtitle = 'Viewing '.$crstype.' Contents';
5666: $helpitem = 'Docs_Viewing_Course_Doc';
5667: }
1.392 raeburn 5668: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5669: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5670: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5671: {'add_entries' => $addentries}
5672: )
1.392 raeburn 5673: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5674: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5675: $breadtitle,
5676: $helpitem)
1.392 raeburn 5677: );
5678: }
1.364 bisitz 5679:
1.329 droeschl 5680: my %allfiles = ();
5681: my %codebase = ();
1.440 raeburn 5682: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5683: if ($canedit) {
1.329 droeschl 5684: if (($env{'form.uploaddoc.filename'}) &&
5685: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5686: my $context = $1;
5687: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5688: undef($hadchanges);
1.440 raeburn 5689: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5690: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5691: undef($navmap);
1.329 droeschl 5692: if ($hadchanges) {
5693: &mark_hash_old();
5694: }
1.440 raeburn 5695: $r->print($upload_output);
5696: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5697: # Process file upload - phase two - upload embedded objects
5698: $uploadphase = 'check_embedded';
5699: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5700: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5701: $env{'form.newidx'});
5702: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5703: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5704: my ($destination,$dir_root) = &embedded_destination();
5705: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5706: my $actionurl = '/adm/coursedocs';
5707: my ($result,$flag) =
5708: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5709: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5710: $actionurl);
5711: $r->print($result.&return_to_editor());
5712: } elsif ($env{'form.phase'} eq 'check_embedded') {
5713: # Process file upload - phase three - modify references in HTML file
5714: $uploadphase = 'modified_orightml';
5715: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5716: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5717: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5718: my $result =
5719: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5720: $docuname,$docudom,undef,
5721: $dir_root);
5722: $r->print($result.&return_to_editor());
1.476 raeburn 5723: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5724: $uploadphase = 'decompress_phase_one';
5725: $r->print(&decompression_phase_one().
5726: &return_to_editor());
5727: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5728: $uploadphase = 'decompress_phase_two';
5729: $r->print(&decompression_phase_two().
5730: &return_to_editor());
1.329 droeschl 5731: }
5732: }
5733:
1.484 raeburn 5734: if ($allowed && $toolsflag) {
5735: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5736: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5737: $r->print(&endContentScreen());
5738: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5739: # -----------------------------------------------------------------------------
5740: my %lt=&Apache::lonlocal::texthash(
5741: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5742: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5743: 'upld' => 'Upload Content',
1.329 droeschl 5744: 'srch' => 'Search',
5745: 'impo' => 'Import',
1.484.2.19 raeburn 5746: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5747: 'impm' => 'Import from Assembled Map',
1.484.2.93.2. (raeburn 5748:): 'extr' => 'External Resource',
5749:): 'extt' => 'External Tool',
1.329 droeschl 5750: 'selm' => 'Select Map',
5751: 'load' => 'Load Map',
5752: 'newf' => 'New Folder',
5753: 'newp' => 'New Composite Page',
5754: 'syll' => 'Syllabus',
1.425 raeburn 5755: 'navc' => 'Table of Contents',
1.343 biermanm 5756: 'sipa' => 'Simple Course Page',
1.329 droeschl 5757: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5758: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5759: 'drbx' => 'Drop Box',
1.451 www 5760: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5761: 'bull' => 'Discussion Board',
1.347 weissno 5762: 'mypi' => 'My Personal Information Page',
1.353 weissno 5763: 'grpo' => 'Group Portfolio',
1.329 droeschl 5764: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5765: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5766: 'imsf' => 'IMS Upload',
5767: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5768: 'cms' => 'Origin of IMS package',
5769: 'se' => 'Select',
1.484.2.19 raeburn 5770: 'file' => 'File',
1.329 droeschl 5771: 'title' => 'Title',
5772: 'comment' => 'Comment',
1.403 raeburn 5773: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5774: 'bb5' => 'Blackboard 5',
5775: 'bb6' => 'Blackboard 6',
5776: 'angel5' => 'ANGEL 5.5',
5777: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5778: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5779: );
1.329 droeschl 5780: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5781: # Calculate free quota space for a user or course. A javascript function checks
5782: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5783: my $quotatype = 'unofficial';
5784: if ($crstype eq 'Community') {
5785: $quotatype = 'community';
5786: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5787: $quotatype = 'official';
5788: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5789: $quotatype = 'textbook';
5790: }
5791: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5792: 'course',$quotatype); # expressed in MB
5793: my $current_disk_usage = 0;
5794: foreach my $subdir ('docs','supplemental') {
5795: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5796: "userfiles/$subdir",1); # expressed in kB
5797: }
5798: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5799: my $usage = $current_disk_usage/1024; # in MB
5800: my $quota = $disk_quota;
5801: my $percent;
5802: if ($disk_quota == 0) {
5803: $percent = 100.0;
5804: } else {
1.484.2.69 raeburn 5805: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5806: }
5807: $usage = sprintf("%.2f",$usage);
5808: $quota = sprintf("%.2f",$quota);
5809: $percent = sprintf("%.0f",$percent);
5810: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5811: $percent.'%',$quota.' MB').'</p>';
5812:
1.329 droeschl 5813: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5814: $quotainfo
1.329 droeschl 5815: $lt{'file'}:<br />
1.484.2.81 raeburn 5816: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
5817: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5818: FIUP
5819:
5820: my $checkbox=(<<CHBO);
5821: <!-- <label>$lt{'parse'}?
5822: <input type="checkbox" name="parserflag" />
5823: </label> -->
5824: <label>
1.484.2.67 raeburn 5825: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5826: </label>
5827: CHBO
1.484.2.12 raeburn 5828: my $imsfolder = $env{'form.folder'};
5829: if ($imsfolder eq '') {
1.484.2.19 raeburn 5830: $imsfolder = 'default';
1.484.2.12 raeburn 5831: }
5832: my $imspform=(<<IMSFORM);
5833: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5834: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5835: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5836: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5837: <legend>$lt{'imsf'}</legend>
5838: $fileupload
5839: <br />
5840: <p>
1.484.2.19 raeburn 5841: $lt{'cms'}:
1.484.2.67 raeburn 5842: <select name="source" $disabled>
1.484.2.12 raeburn 5843: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5844: <option value="bb5">$lt{'bb5'}</option>
5845: <option value="bb6">$lt{'bb6'}</option>
5846: <option value="angel5">$lt{'angel5'}</option>
5847: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5848: </select>
5849: <input type="hidden" name="folder" value="$imsfolder" />
5850: </p>
5851: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5852: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5853: </fieldset>
5854: </form>
5855: IMSFORM
5856:
1.484.2.19 raeburn 5857: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5858: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5859: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5860: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5861: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5862: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5863: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5864: $fileupload
5865: <br />
5866: $lt{'title'}:<br />
1.484.2.67 raeburn 5867: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5868: $pathitem
1.329 droeschl 5869: <input type="hidden" name="cmd" value="upload_default" />
5870: <br />
1.458 raeburn 5871: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5872: $checkbox
5873: </span>
1.484.2.12 raeburn 5874: <br clear="all" />
1.484.2.67 raeburn 5875: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5876: </fieldset>
5877: </form>
1.383 tempelho 5878: FUFORM
1.329 droeschl 5879:
1.484.2.67 raeburn 5880: my $mapimportjs;
5881: if ($canedit) {
5882: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5883: } else {
5884: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5885: }
1.484.2.19 raeburn 5886: my $importpubform=(<<SEDFFORM);
5887: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5888: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5889: <form action="/adm/coursedocs" method="post" name="mapimportform">
5890: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5891: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5892: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5893: $lt{'copm'}<br />
5894: <span class="LC_nobreak">
1.484.2.19 raeburn 5895: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5896: onfocus="this.blur();$mapimportjs" $disabled />
5897: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5898: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5899: </fieldset>
5900: </form>
5901:
1.383 tempelho 5902: SEDFFORM
1.484.2.67 raeburn 5903:
5904: my $fromstoredjs;
5905: if ($canedit) {
5906: $fromstoredjs = 'open_StoredLinks_Import()';
5907: } else {
5908: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5909: }
5910:
1.484.2.19 raeburn 5911: my @importpubforma = (
5912: { '<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 5913: { '<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 5914: { '<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 5915: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5916: );
5917: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5918: my $extresourcesform =
5919: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5920: $help{'Adding_External_Resource'},
1.484.2.93.2. (raeburn 5921:): undef,undef,undef,undef,undef,undef,$disabled);
5922:): my $exttoolform =
5923:): &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5924:): $help{'Adding_External_Tool'},undef,
5925:): undef,'tool',$coursedom,$coursenum,
5926:): \%ltitools,$disabled);
1.329 droeschl 5927: if ($allowed) {
1.484.2.7 raeburn 5928: my $folder = $env{'form.folder'};
5929: if ($folder eq '') {
5930: $folder='default';
5931: }
1.484.2.67 raeburn 5932: if ($canedit) {
5933: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5934: if ($output) {
5935: $r->print($output);
5936: }
1.484.2.30 raeburn 5937: }
1.337 ehlerst 5938: $r->print(<<HIDDENFORM);
5939: <form name="renameform" method="post" action="/adm/coursedocs">
5940: <input type="hidden" name="title" />
5941: <input type="hidden" name="cmd" />
5942: <input type="hidden" name="markcopy" />
5943: <input type="hidden" name="copyfolder" />
5944: $containertag
5945: </form>
1.484 raeburn 5946:
1.337 ehlerst 5947: HIDDENFORM
1.484.2.17 raeburn 5948: $r->print(&makesimpleeditform($pathitem)."\n".
5949: &makedocslogform($pathitem."\n".
1.484 raeburn 5950: '<input type="hidden" name="folder" value="'.
5951: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5952: }
1.442 www 5953:
5954: # Generate the tabs
1.484.2.19 raeburn 5955: my ($mode,$needs_end);
1.472 raeburn 5956: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5957: my @folders = split('&',$env{'form.folderpath'});
5958: unless (@folders > 2) {
5959: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5960: $needs_end = 1;
5961: }
1.472 raeburn 5962: } else {
1.484 raeburn 5963: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5964: $needs_end = 1;
1.472 raeburn 5965: }
1.443 www 5966:
1.442 www 5967: #
5968:
5969: my $savefolderpath;
1.484.2.86 raeburn 5970: my $hostname = $r->hostname();
1.442 www 5971:
1.395 raeburn 5972: if ($allowed) {
1.329 droeschl 5973: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5974: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5975: $folder='default';
1.356 tempelho 5976: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5977: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5978: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5979: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5980: }
5981: my $postexec='';
5982: if ($folder eq 'default') {
1.372 bisitz 5983: $r->print('<script type="text/javascript">'."\n"
5984: .'// <![CDATA['."\n"
5985: .'this.window.name="loncapaclient";'."\n"
5986: .'// ]]>'."\n"
5987: .'</script>'."\n"
1.369 bisitz 5988: );
1.329 droeschl 5989: } else {
5990: #$postexec='self.close();';
5991: }
1.484.2.15 raeburn 5992: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5993: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5994: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5995:
5996: my $newnavform=(<<NNFORM);
5997: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5998: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5999: $pathitem
1.329 droeschl 6000: <input type="hidden" name="importdetail"
6001: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 6002: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6003: $help{'Navigate_Content'}
6004: </form>
6005: NNFORM
6006: my $newsmppageform=(<<NSPFORM);
6007: <form action="/adm/coursedocs" method="post" name="newsmppg">
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" value="" />
1.423 onken 6011: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6012: $help{'Simple Page'}
1.329 droeschl 6013: </form>
6014: NSPFORM
6015:
6016: my $newsmpproblemform=(<<NSPROBFORM);
6017: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 6018: <input type="hidden" name="active" value="cc" />
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:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 6022: $help{'Simple_Problem'}
1.329 droeschl 6023: </form>
6024:
6025: NSPROBFORM
6026:
6027: my $newdropboxform=(<<NDBFORM);
6028: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 6029: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6030: $pathitem
1.329 droeschl 6031: <input type="hidden" name="importdetail" value="" />
1.423 onken 6032: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 6033: $help{'Dropbox'}
1.344 bisitz 6034: </form>
1.329 droeschl 6035: NDBFORM
6036:
6037: my $newexuploadform=(<<NEXUFORM);
6038: <form action="/adm/coursedocs" method="post" name="newexamupload">
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:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6043: $help{'Score_Upload_Form'}
6044: </form>
6045: NEXUFORM
6046:
6047: my $newbulform=(<<NBFORM);
6048: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 6049: <input type="hidden" name="active" value="dd" />
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:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6053: $help{'Bulletin Board'}
6054: </form>
6055: NBFORM
6056:
6057: my $newaboutmeform=(<<NAMFORM);
6058: <form action="/adm/coursedocs" method="post" name="newaboutme">
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"
6062: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6063: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6064: $help{'My Personal Information Page'}
1.329 droeschl 6065: </form>
6066: NAMFORM
6067:
6068: my $newaboutsomeoneform=(<<NASOFORM);
6069: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 6070: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6071: $pathitem
1.329 droeschl 6072: <input type="hidden" name="importdetail" value="" />
1.423 onken 6073: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6074: </form>
6075: NASOFORM
6076:
6077: my $newrosterform=(<<NROSTFORM);
6078: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 6079: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6080: $pathitem
1.329 droeschl 6081: <input type="hidden" name="importdetail"
6082: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 6083: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 6084: $help{'Course_Roster'}
1.329 droeschl 6085: </form>
6086: NROSTFORM
6087:
1.484.2.27 raeburn 6088: my $newwebpage;
6089: if ($folder =~ /^default_?(\d*)$/) {
6090: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6091: if ($1) {
6092: $newwebpage .= $1;
6093: } else {
6094: $newwebpage .= 'default';
6095: }
6096: $newwebpage .= '/new.html';
6097: }
6098: my $newwebpageform =(<<NWEBFORM);
6099: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 6100: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 6101: $pathitem
6102: <input type="hidden" name="importdetail" value="$newwebpage" />
6103: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 6104: $help{'Web_Page'}
1.484.2.27 raeburn 6105: </form>
6106: NWEBFORM
1.484.2.30 raeburn 6107:
1.484.2.27 raeburn 6108:
1.342 ehlerst 6109: my $specialdocumentsform;
1.383 tempelho 6110: my @specialdocumentsforma;
1.451 www 6111: my $gradingform;
6112: my @gradingforma;
6113: my $communityform;
6114: my @communityforma;
1.351 ehlerst 6115: my $newfolderform;
1.390 tempelho 6116: my $newfolderb;
1.342 ehlerst 6117:
1.451 www 6118: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6119:
1.329 droeschl 6120: my $newpageform=(<<NPFORM);
6121: <form action="/adm/coursedocs" method="post" name="newpage">
6122: <input type="hidden" name="folderpath" value="$path" />
6123: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6124: <input type="hidden" name="active" value="ee" />
1.423 onken 6125: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6126: $help{'Adding_Pages'}
1.329 droeschl 6127: </form>
6128: NPFORM
1.390 tempelho 6129:
6130:
1.351 ehlerst 6131: $newfolderform=(<<NFFORM);
1.329 droeschl 6132: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 6133: $pathitem
1.329 droeschl 6134: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6135: <input type="hidden" name="active" value="" />
1.422 onken 6136: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6137: </form>
6138: NFFORM
6139:
6140: my $newsylform=(<<NSYLFORM);
6141: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 6142: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6143: $pathitem
1.329 droeschl 6144: <input type="hidden" name="importdetail"
6145: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6146: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6147: $help{'Syllabus'}
1.383 tempelho 6148:
1.329 droeschl 6149: </form>
6150: NSYLFORM
1.364 bisitz 6151:
1.329 droeschl 6152: my $newgroupfileform=(<<NGFFORM);
6153: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 6154: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6155: $pathitem
1.329 droeschl 6156: <input type="hidden" name="importdetail"
6157: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 6158: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6159: $help{'Group Portfolio'}
1.329 droeschl 6160: </form>
6161: NGFFORM
1.484.2.89 raeburn 6162: if ($container eq 'page') {
6163: @specialdocumentsforma=(
6164: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6165: );
6166: } else {
6167: @specialdocumentsforma=(
1.421 onken 6168: {'<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 6169: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6170: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6171: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 6172: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.484.2.89 raeburn 6173: );
6174: }
1.451 www 6175: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6176:
1.434 raeburn 6177:
6178: my @importdoc = (
1.484.2.19 raeburn 6179: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6180: );
1.484.2.93.2. (raeburn 6181:): if (keys(%ltitools)) {
6182:): push(@importdoc,
6183:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6184:): );
6185:): }
1.484.2.19 raeburn 6186: unless ($container eq 'page') {
6187: push(@importdoc,
6188: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6189: );
6190: }
6191: push(@importdoc,
1.484.2.38 raeburn 6192: {'<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 6193: );
1.484.2.12 raeburn 6194: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6195:
1.451 www 6196: @gradingforma=(
6197: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6198: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6199: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6200:
6201: );
6202: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6203:
6204: @communityforma=(
6205: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6206: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6207: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 6208: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6209: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6210: );
6211: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6212:
1.330 tempelho 6213: my %orderhash = (
1.484.2.36 raeburn 6214: 'aa' => ['Upload',$fileuploadform],
6215: 'bb' => ['Import',$importpubform],
6216: 'cc' => ['Grading',$gradingform],
1.484.2.89 raeburn 6217: 'ee' => ['Other',$specialdocumentsform],
1.330 tempelho 6218: );
1.484.2.19 raeburn 6219: unless ($container eq 'page') {
1.434 raeburn 6220: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6221: $orderhash{'dd'} = ['Collaboration',$communityform];
1.434 raeburn 6222: }
6223:
1.341 ehlerst 6224: $hadchanges=0;
1.484 raeburn 6225: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6226: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6227: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.93.2. (raeburn 6228:): \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 6229: undef($navmap);
1.443 www 6230: if ($error) {
6231: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6232: }
6233: if ($hadchanges) {
1.484.2.73 raeburn 6234: unless (&is_hash_old()) {
6235: &mark_hash_old();
6236: }
1.443 www 6237: }
1.341 ehlerst 6238:
1.443 www 6239: &changewarning($r,'');
6240: }
1.458 raeburn 6241: }
1.442 www 6242:
1.443 www 6243: # Supplemental documents start here
6244:
1.329 droeschl 6245: my $folder=$env{'form.folder'};
1.443 www 6246: unless ($supplementalflag) {
1.329 droeschl 6247: $folder='supplemental';
6248: }
6249: if ($folder =~ /^supplemental$/ &&
6250: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6251: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6252: } elsif ($allowed) {
1.356 tempelho 6253: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6254: }
1.484.2.17 raeburn 6255: $pathitem = '<input type="hidden" name="folderpath" value="'.
6256: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6257: if ($allowed) {
6258: my $folderseq=
1.484.2.15 raeburn 6259: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6260:
6261: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 6262: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6263: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6264: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6265: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6266: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6267: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6268: $fileupload
6269: <br />
6270: <br />
6271: <span class="LC_nobreak">
6272: $checkbox
6273: </span>
6274: <br /><br />
6275: $lt{'comment'}:<br />
1.383 tempelho 6276: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6277: <br />
1.484.2.19 raeburn 6278: $pathitem
1.329 droeschl 6279: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6280: <input type='submit' value="$lt{'upld'}" />
6281: </form>
1.484.2.19 raeburn 6282: SUPDOCFORM
1.329 droeschl 6283:
6284: my $supnewfolderform=(<<SNFFORM);
6285: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6286: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6287: $pathitem
1.329 droeschl 6288: <input type="hidden" name="importdetail" value="" />
1.423 onken 6289: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6290: $help{'Adding_Folders'}
1.329 droeschl 6291: </form>
6292: SNFFORM
1.383 tempelho 6293:
1.484.2.19 raeburn 6294: my $supextform =
6295: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6296: $help{'Adding_External_Resource'},
6297: undef,undef,$disabled);
1.484.2.93.2. (raeburn 6298:): my $supexttoolform =
6299:): &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6300:): $help{'Adding_External_Tool'},
6301:): undef,undef,'tool',$coursedom,
6302:): $coursenum,\%ltitools,$disabled);
1.329 droeschl 6303:
6304: my $supnewsylform=(<<SNSFORM);
6305: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6306: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6307: $pathitem
1.329 droeschl 6308: <input type="hidden" name="importdetail"
6309: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6310: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6311: $help{'Syllabus'}
6312: </form>
6313: SNSFORM
6314:
6315: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6316: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6317: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6318: $pathitem
1.329 droeschl 6319: <input type="hidden" name="importdetail"
6320: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6321: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6322: $help{'My Personal Information Page'}
1.329 droeschl 6323: </form>
6324: SNAMFORM
6325:
1.484.2.27 raeburn 6326: my $supwebpage;
6327: if ($folder =~ /^supplemental_?(\d*)$/) {
6328: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6329: if ($1) {
6330: $supwebpage .= $1;
6331: } else {
6332: $supwebpage .= 'default';
6333: }
6334: $supwebpage .= '/new.html';
6335: }
6336: my $supwebpageform =(<<SWEBFORM);
6337: <form action="/adm/coursedocs" method="post" name="supwebpage">
6338: <input type="hidden" name="active" value="cc" />
6339: $pathitem
6340: <input type="hidden" name="importdetail" value="$supwebpage" />
6341: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6342: $help{'Web_Page'}
1.484.2.27 raeburn 6343: </form>
6344: SWEBFORM
6345:
1.333 muellerd 6346:
1.383 tempelho 6347: my @specialdocs = (
1.484.2.67 raeburn 6348: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6349: =>$supnewsylform},
1.484.2.67 raeburn 6350: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6351: =>$supnewaboutmeform},
1.484.2.27 raeburn 6352: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6353:
1.383 tempelho 6354: );
1.417 droeschl 6355: my @supimportdoc = (
1.484.2.19 raeburn 6356: {'<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 6357:): =>$supextform});
6358:): if (keys(%ltitools)) {
6359:): push(@supimportdoc,
6360:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6361:): =>$supexttoolform});
6362:): }
6363:): push(@supimportdoc,
1.484.2.12 raeburn 6364: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6365: =>$supupdocform},
1.484.2.93.2. (raeburn 6366:): );
1.484.2.19 raeburn 6367:
1.484.2.12 raeburn 6368: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6369: my %suporderhash = (
1.390 tempelho 6370: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6371: 'ee' => ['Upload',$supupdocform],
6372: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6373: );
1.443 www 6374: if ($supplementalflag) {
1.458 raeburn 6375: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6376: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.484.2.93.2. (raeburn 6377:): \%ltitools,$canedit,$hostname);
1.443 www 6378: if ($error) {
6379: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6380: } else {
6381: if ($suppchanges) {
6382: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6383: my @ids=&Apache::lonnet::current_machine_ids();
6384: foreach my $server (keys(%servers)) {
6385: next if (grep(/^\Q$server\E$/,@ids));
6386: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6387: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6388: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6389: }
6390: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6391: undef($suppchanges);
6392: }
1.443 www 6393: }
1.393 raeburn 6394: }
1.443 www 6395: } elsif ($supplementalflag) {
1.458 raeburn 6396: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.85 raeburn 6397: $supplementalflag,'',$iconpath,$pathitem,'',$hostname);
1.393 raeburn 6398: if ($error) {
6399: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6400: }
1.393 raeburn 6401: }
1.389 tempelho 6402:
1.484.2.19 raeburn 6403: if ($needs_end) {
6404: $r->print(&endContentScreen());
6405: }
1.383 tempelho 6406:
1.329 droeschl 6407: if ($allowed) {
6408: $r->print('
6409: <form method="post" name="extimport" action="/adm/coursedocs">
6410: <input type="hidden" name="title" />
6411: <input type="hidden" name="url" />
6412: <input type="hidden" name="useform" />
6413: <input type="hidden" name="residx" />
6414: </form>');
6415: }
1.484 raeburn 6416: } elsif ($showdoc) {
1.329 droeschl 6417: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6418: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6419: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6420: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6421: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6422: }
6423: }
6424: $r->print(&Apache::loncommon::end_page());
6425: return OK;
1.364 bisitz 6426: }
1.329 droeschl 6427:
1.440 raeburn 6428: sub embedded_form_elems {
6429: my ($phase,$primaryurl,$newidx) = @_;
6430: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6431: $newidx =~s /\D+//g;
1.440 raeburn 6432: return <<STATE;
6433: <input type="hidden" name="folderpath" value="$folderpath" />
6434: <input type="hidden" name="cmd" value="upload_embedded" />
6435: <input type="hidden" name="newidx" value="$newidx" />
6436: <input type="hidden" name="phase" value="$phase" />
6437: <input type="hidden" name="primaryurl" value="$primaryurl" />
6438: STATE
6439: }
6440:
6441: sub embedded_destination {
6442: my $folder=$env{'form.folder'};
6443: my $destination = 'docs/';
6444: if ($folder =~ /^supplemental/) {
6445: $destination = 'supplemental/';
6446: }
6447: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6448: $destination .= 'default/';
6449: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6450: $destination .= $2.'/';
6451: }
1.484.2.78 raeburn 6452: my $newidx = $env{'form.newidx'};
6453: $newidx =~s /\D+//g;
6454: if ($newidx) {
6455: $destination .= $newidx;
6456: }
1.440 raeburn 6457: my $dir_root = '/userfiles';
6458: return ($destination,$dir_root);
6459: }
6460:
6461: sub return_to_editor {
6462: my $actionurl = '/adm/coursedocs';
6463: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6464: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6465: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6466: '</a></p>';
6467: }
6468:
1.476 raeburn 6469: sub decompression_info {
6470: my ($destination,$dir_root) = &embedded_destination();
6471: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6472: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6473: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6474: my $container='sequence';
1.480 raeburn 6475: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6476: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6477: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6478: $container='page';
6479: }
1.480 raeburn 6480: unshift(@hiddens,$pathitem);
6481: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6482: if ($item eq 'newidx') {
6483: next if ($env{'form.'.$item} =~ /\D/);
6484: }
1.480 raeburn 6485: if ($env{'form.'.$item}) {
6486: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6487: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6488: }
1.477 raeburn 6489: }
1.476 raeburn 6490: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6491: $hiddenelem);
6492: }
6493:
6494: sub decompression_phase_one {
6495: my ($dir,$file,$warning,$error,$output);
6496: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6497: &decompression_info();
1.484.2.7 raeburn 6498: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6499: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6500: } else {
6501: my $file = $1;
1.481 raeburn 6502: $output =
6503: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6504: $destination,$dir_root,
6505: $hiddenelem);
6506: if ($env{'form.autoextract_camtasia'}) {
6507: $output .= &remove_archive($docudom,$docuname,$container);
6508: }
1.476 raeburn 6509: }
6510: if ($error) {
6511: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6512: $error.'</p>'."\n";
6513: }
6514: if ($warning) {
6515: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6516: }
6517: return $output;
6518: }
6519:
6520: sub decompression_phase_two {
6521: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6522: &decompression_info();
1.481 raeburn 6523: my $output;
1.480 raeburn 6524: if ($env{'form.archivedelete'}) {
1.481 raeburn 6525: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6526: }
6527: $output .=
1.481 raeburn 6528: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6529: $destination,$dir_root,$hiddenelem);
6530: return $output;
6531: }
6532:
1.480 raeburn 6533: sub remove_archive {
6534: my ($docudom,$docuname,$container) = @_;
6535: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6536: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6537: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6538: if ($fatal) {
6539: if ($container eq 'page') {
6540: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6541: } else {
6542: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6543: }
1.484.2.54 raeburn 6544: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6545: } else {
6546: my $currcmd = $env{'form.cmd'};
6547: my $position = $env{'form.position'};
1.484.2.54 raeburn 6548: my $archiveidx = $position;
6549: if ($position > 0) {
6550: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6551: $archiveidx = $position-1;
6552: }
6553: $env{'form.cmd'} = 'remove_'.$archiveidx;
6554: my ($title,$url,@rrest) =
6555: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6556: if ($url eq $env{'form.archiveurl'}) {
6557: if (&handle_edit_cmd($docuname,$docudom)) {
6558: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6559: if ($fatal) {
6560: if ($container eq 'page') {
6561: $delwarning = &mt('An error occurred updating the contents of the current page.');
6562: } else {
6563: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6564: }
1.480 raeburn 6565: } else {
1.484.2.54 raeburn 6566: $delresult = &mt('Archive file removed.');
1.480 raeburn 6567: }
6568: }
1.484.2.54 raeburn 6569: } else {
6570: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6571: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6572: }
6573: }
6574: $env{'form.cmd'} = $currcmd;
6575: }
6576: if ($delwarning) {
6577: $output = '<p class="LC_warning">'.
6578: $delwarning.
6579: '</p>';
6580: }
6581: if ($delresult) {
6582: $output .= '<p class="LC_info">'.
6583: $delresult.
6584: '</p>';
6585: }
1.481 raeburn 6586: return $output;
1.480 raeburn 6587: }
6588:
1.484 raeburn 6589: sub generate_admin_menu {
1.484.2.67 raeburn 6590: my ($crstype,$canedit) = @_;
1.484 raeburn 6591: my $lc_crstype = lc($crstype);
6592: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6593: my %lt= ( # do not translate here
1.484 raeburn 6594: 'vc' => 'Verify Content',
6595: 'cv' => 'Check/Set Resource Versions',
6596: 'ls' => 'List Resource Identifiers',
1.484.2.93.2. (raeburn 6597:): 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 6598: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6599: 'dcd' => "Copy $crstype Content to Authoring Space",
6600: );
1.484 raeburn 6601: my ($candump,$dumpurl);
6602: if ($home + $other > 0) {
6603: $candump = 'F';
6604: if ($home) {
6605: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6606: } else {
6607: my @hosts;
6608: foreach my $aurole (keys(%outhash)) {
6609: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6610: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6611: }
1.484 raeburn 6612: }
6613: if (@hosts == 1) {
6614: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6615: '&role='.
6616: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6617: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6618: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6619: } else {
6620: $dumpurl = "javascript:choose_switchserver_window()";
6621: }
6622: }
6623: }
6624: my @menu=
6625: ({ categorytitle=>'Administration',
6626: items =>[
6627: { linktext => $lt{'vc'},
6628: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6629: permission => 'F',
1.484.2.44 raeburn 6630: help => 'Docs_Verify_Content',
1.484 raeburn 6631: icon => 'verify.png',
6632: linktitle => 'Verify contents can be retrieved/rendered',
6633: },
6634: { linktext => $lt{'cv'},
6635: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6636: permission => 'F',
1.484.2.44 raeburn 6637: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6638: icon => 'resversion.png',
6639: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6640: },
6641: { linktext => $lt{'ls'},
6642: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6643: permission => 'F',
6644: #help => '',
6645: icon => 'symbs.png',
6646: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6647: },
1.484.2.93.2. (raeburn 6648:): { linktext => $lt{'ct'},
6649:): url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
6650:): permission => 'F',
6651:): help => 'Docs_Short_URLs',
6652:): icon => 'shorturls.png',
6653:): linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
6654:): },
1.484 raeburn 6655: ]
1.484.2.67 raeburn 6656: });
6657: if ($canedit) {
6658: push(@menu,
1.484 raeburn 6659: { categorytitle=>'Export',
6660: items =>[
6661: { linktext => $lt{'imse'},
6662: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6663: permission => 'F',
6664: help => 'Docs_Export_Course_Docs',
6665: icon => 'imsexport.png',
6666: linktitle => $lt{'imse'},
6667: },
6668: { linktext => $lt{'dcd'},
6669: url => $dumpurl,
6670: permission => $candump,
1.484.2.44 raeburn 6671: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6672: icon => 'dump.png',
6673: linktitle => $lt{'dcd'},
6674: },
6675: ]
6676: });
1.484.2.67 raeburn 6677: }
1.484 raeburn 6678: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6679: '<input type="hidden" id="dummy" />'."\n".
6680: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6681: '</form>';
1.329 droeschl 6682: }
6683:
6684: sub generate_edit_table {
1.484.2.30 raeburn 6685: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6686: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6687: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6688: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6689: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6690: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6691: $activetab = $env{'form.active'};
6692: }
1.484.2.67 raeburn 6693: unless ($canedit) {
6694: $disabled = ' disabled="disabled"';
6695: }
1.472 raeburn 6696: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6697: my $backtext = &mt('Exit Editor');
1.458 raeburn 6698: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6699: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6700: '<li class="goback">'.
1.484.2.32 raeburn 6701: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6702: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6703: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6704: '<li>'.
6705: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6706: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6707: if ($env{'form.docslog'}) {
6708: $form .= '<li class="active">';
6709: } else {
6710: $form .= '<li>';
6711: }
6712: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6713: &mt('History').'</a></li>'."\n";
6714: if ($env{'form.docslog'}) {
6715: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6716: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6717: }
1.458 raeburn 6718: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6719: if($name ne '00'){
1.371 tempelho 6720: if($activetab eq '' || $activetab ne $name){
6721: $active = '';
6722: }elsif($activetab eq $name){
6723: $active = 'class="active"';
6724: }
1.458 raeburn 6725: $form .= '<li style="float:right" '.$active
1.484 raeburn 6726: .' 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 6727: } else {
1.484.2.43 raeburn 6728: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6729:
6730: }
1.329 droeschl 6731: }
1.484 raeburn 6732: $form .= '</ul>'."\n";
6733: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6734:
6735: if ($to_show ne '') {
1.484.2.30 raeburn 6736: my $saveform;
6737: if ($need_save) {
6738: my $button = &mt('Make changes');
6739: my $path;
6740: if ($env{'form.folderpath'}) {
6741: $path =
6742: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6743: }
6744: $saveform = <<"END";
6745: <div id="multisave" style="display:none; clear:both;" >
6746: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6747: <input type="hidden" name="folderpath" value="$path" />
6748: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6749: <input type="hidden" name="allhiddenresource" value="" />
6750: <input type="hidden" name="allencrypturl" value="" />
6751: <input type="hidden" name="allrandompick" value="" />
6752: <input type="hidden" name="allrandomorder" value="" />
6753: <input type="hidden" name="changeparms" value="" />
6754: <input type="hidden" name="multiremove" value="" />
6755: <input type="hidden" name="multicut" value="" />
6756: <input type="hidden" name="multicopy" value="" />
6757: <input type="hidden" name="multichange" value="" />
6758: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6759: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6760: </form>
6761: </div>
6762: END
6763: }
6764: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6765: }
1.363 ehlerst 6766: foreach my $field (keys(%orderhash)){
1.390 tempelho 6767: if($field ne '00'){
1.422 onken 6768: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6769: $active = 'style="display: none;float:left"';
1.422 onken 6770: }elsif($activetab eq $field){
1.458 raeburn 6771: $active = 'style="display:block;float:left"';
1.422 onken 6772: }
6773: $form .= '<div id="'.$field.$tid.'"'
6774: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6775: .'</div>'."\n";
1.363 ehlerst 6776: }
6777: }
1.484 raeburn 6778: unless ($env{'form.docslog'}) {
6779: $form .= '</div></div>'."\n";
6780: }
1.329 droeschl 6781: return $form;
6782: }
6783:
6784: sub editing_js {
1.484.2.93.2. (raeburn 6785:): my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 6786: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6787: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6788: p_mnf => 'Name of New Folder',
6789: t_mnf => 'New Folder',
6790: p_mnp => 'Name of New Page',
6791: t_mnp => 'New Page',
1.451 www 6792: p_mxu => 'Title for the External Score',
1.349 biermanm 6793: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6794: p_msb => 'Title for the Problem',
6795: p_mdb => 'Title for the Drop Box',
1.336 schafran 6796: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6797: p_mwp => 'Title for Web Page',
1.348 weissno 6798: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6799: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6800: p_mab_alrt1 => 'Not a valid user:domain',
6801: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6802: p_chn => 'New Title',
6803: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6804: p_rmr2a => 'Remove',
6805: p_rmr2b => '?',
6806: p_rmr3a => 'Remove those',
6807: p_rmr3b => 'items?',
6808: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6809: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6810: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6811: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6812: p_ctr2a => 'Cut',
6813: p_ctr2b => '?',
6814: p_ctr3a => 'Cut those',
6815: p_ctr3b => 'items?',
1.478 raeburn 6816: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6817: imsfile => 'You must choose an IMS package for import',
6818: imscms => 'You must select which Course Management System was the source of the IMS package',
6819: invurl => 'Invalid URL',
6820: titbl => 'Title is blank',
1.484.2.30 raeburn 6821: more => '(More ...)',
6822: less => '(Less ...)',
6823: noor => 'No actions selected or changes to settings specified.',
6824: noch => 'No changes to settings specified.',
6825: noac => 'No actions selected.',
1.484.2.67 raeburn 6826: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6827: );
6828:
1.484.2.61 raeburn 6829: &js_escape(\%js_lt);
1.433 raeburn 6830: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6831: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6832: my $main_container_page;
1.484.2.19 raeburn 6833: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6834: $main_container_page = 1;
1.434 raeburn 6835: }
1.484.2.67 raeburn 6836: my $backtourl;
6837: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6838: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6839:
1.484.2.21 raeburn 6840: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6841: my $caller = $1;
6842: if ($caller =~ /^supplemental/) {
6843: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6844: } else {
6845: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6846: $res = &Apache::lonnet::clutter($res);
6847: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6848: my ($url,$anchor);
6849: if ($res =~ /^([^#]+)#([^#]+)$/) {
6850: $url = $1;
6851: $anchor = $2;
6852: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6853: $caller = $1.&escape('#').$anchor;
6854: }
1.484.2.67 raeburn 6855: } else {
6856: $url = $res;
1.484.2.66 raeburn 6857: }
1.484.2.83 raeburn 6858: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
6859: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
6860: $backtourl .= '?navmap=1';
6861: } else {
6862: $backtourl .= '?symb='.
6863: &HTML::Entities::encode($caller,'<>&"');
6864: }
1.484.2.80 raeburn 6865: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6866: if (($ENV{'SERVER_PORT'} == 443) &&
6867: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 6868: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 6869: if ($hostname ne '') {
6870: $backtourl = 'http://'.$hostname.$backtourl;
6871: }
6872: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6873: }
6874: }
6875: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6876: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.484.2.93 raeburn 6877: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 6878: if ($hostname ne '') {
6879: $backtourl = 'http://'.$hostname.$backtourl;
6880: }
6881: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6882: }
6883: }
6884: }
1.484.2.66 raeburn 6885: if ($anchor ne '') {
6886: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6887: }
1.484.2.57 raeburn 6888: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6889: } else {
6890: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6891: }
6892: }
6893: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6894: $backtourl = '/adm/menu';
6895: } elsif ($supplementalflag) {
1.472 raeburn 6896: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6897: } else {
6898: $backtourl = '/adm/navmaps';
1.472 raeburn 6899: }
6900:
1.484.2.19 raeburn 6901: my $fieldsets = "'ext','doc'";
1.484.2.93.2. (raeburn 6902:): if ($posslti) {
6903:): $fieldsets .= ",'tool'";
6904:): }
1.484.2.19 raeburn 6905: unless ($main_container_page) {
6906: $fieldsets .=",'ims'";
6907: }
1.484.2.12 raeburn 6908: if ($supplementalflag) {
6909: $fieldsets = "'suppext','suppdoc'";
1.484.2.93.2. (raeburn 6910:): if ($posslti) {
6911:): $fieldsets .= ",'supptool'";
6912:): }
1.484.2.12 raeburn 6913: }
6914:
1.484.2.67 raeburn 6915: my $jsmakefunctions;
6916: if ($canedit) {
6917: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6918: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6919: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6920: if (foldername) {
1.484.2.91 raeburn 6921: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 6922: targetform.submit();
6923: }
6924: }
6925:
6926: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6927: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6928: if (pagename) {
1.484.2.91 raeburn 6929: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 6930: targetform.submit();
6931: }
6932: }
6933:
6934: function makeexamupload() {
1.484.2.61 raeburn 6935: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6936: if (title) {
1.329 droeschl 6937: this.document.forms.newexamupload.importdetail.value=
1.484.2.91 raeburn 6938: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 6939: this.document.forms.newexamupload.submit();
6940: }
6941: }
6942:
6943: function makesmppage() {
1.484.2.61 raeburn 6944: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6945: if (title) {
1.329 droeschl 6946: this.document.forms.newsmppg.importdetail.value=
1.484.2.91 raeburn 6947: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6948: this.document.forms.newsmppg.submit();
6949: }
6950: }
6951:
1.484.2.27 raeburn 6952: function makewebpage(type) {
1.484.2.61 raeburn 6953: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6954: var formname;
6955: if (type == 'supp') {
6956: formname = this.document.forms.supwebpage;
6957: } else {
6958: formname = this.document.forms.newwebpage;
6959: }
6960: if (title) {
6961: var webpage = formname.importdetail.value;
1.484.2.91 raeburn 6962: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.484.2.27 raeburn 6963: formname.submit();
6964: }
6965: }
6966:
1.329 droeschl 6967: function makesmpproblem() {
1.484.2.61 raeburn 6968: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6969: if (title) {
1.329 droeschl 6970: this.document.forms.newsmpproblem.importdetail.value=
1.484.2.91 raeburn 6971: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 6972: this.document.forms.newsmpproblem.submit();
6973: }
6974: }
6975:
6976: function makedropbox() {
1.484.2.61 raeburn 6977: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6978: if (title) {
1.329 droeschl 6979: this.document.forms.newdropbox.importdetail.value=
1.484.2.91 raeburn 6980: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 6981: this.document.forms.newdropbox.submit();
6982: }
6983: }
6984:
6985: function makebulboard() {
1.484.2.61 raeburn 6986: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6987: if (title) {
6988: this.document.forms.newbul.importdetail.value=
1.484.2.91 raeburn 6989: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6990: this.document.forms.newbul.submit();
6991: }
6992: }
6993:
6994: function makeabout() {
1.484.2.61 raeburn 6995: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6996: if (user) {
6997: var comp=new Array();
6998: comp=user.split(':');
6999: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7000: if ((comp[0]) && (comp[1])) {
7001: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 7002: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 7003: this.document.forms.newaboutsomeone.submit();
7004: } else {
7005: alert("$js_lt{'p_mab_alrt1'}");
7006: }
7007: } else {
7008: alert("$js_lt{'p_mab_alrt2'}");
7009: }
7010: }
1.335 ehlerst 7011: }
1.484.2.67 raeburn 7012:
7013: function makenew(targetform) {
7014: targetform.submit();
1.335 ehlerst 7015: }
1.484.2.67 raeburn 7016:
7017: function changename(folderpath,index,oldtitle) {
7018: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7019: if (title) {
7020: this.document.forms.renameform.markcopy.value='';
7021: this.document.forms.renameform.title.value=title;
7022: this.document.forms.renameform.cmd.value='rename_'+index;
7023: this.document.forms.renameform.folderpath.value=folderpath;
7024: this.document.forms.renameform.submit();
7025: }
1.329 droeschl 7026: }
7027:
1.484.2.67 raeburn 7028: ENDNEWSCRIPT
7029: } else {
7030: $jsmakefunctions = <<ENDNEWSCRIPT;
7031:
7032: function makenewfolder() {
7033: alert("$js_lt{'edri'}");
7034: }
7035:
7036: function makenewpage() {
7037: alert("$js_lt{'edri'}");
7038: }
7039:
7040: function makeexamupload() {
7041: alert("$js_lt{'edri'}");
7042: }
7043:
7044: function makesmppage() {
7045: alert("$js_lt{'edri'}");
7046: }
7047:
7048: function makewebpage(type) {
7049: alert("$js_lt{'edri'}");
7050: }
7051:
7052: function makesmpproblem() {
7053: alert("$js_lt{'edri'}");
7054: }
7055:
7056: function makedropbox() {
7057: alert("$js_lt{'edri'}");
7058: }
7059:
7060: function makebulboard() {
7061: alert("$js_lt{'edri'}");
7062: }
7063:
7064: function makeabout() {
7065: alert("$js_lt{'edri'}");
7066: }
7067:
7068: function changename() {
7069: alert("$js_lt{'edri'}");
7070: }
7071:
7072: function makenew() {
7073: alert("$js_lt{'edri'}");
7074: }
7075:
7076: function groupimport() {
7077: alert("$js_lt{'edri'}");
7078: }
7079:
7080: function groupsearch() {
7081: alert("$js_lt{'edri'}");
7082: }
7083:
7084: function groupopen(url,recover) {
7085: var options="scrollbars=1,resizable=1,menubar=0";
7086: idxflag=1;
7087: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7088: idx.focus();
7089: }
7090:
7091: ENDNEWSCRIPT
7092:
7093: }
7094: return <<ENDSCRIPT;
7095:
7096: $jsmakefunctions
7097:
1.484.2.13 raeburn 7098: function toggleUpload(caller) {
7099: var blocks = Array($fieldsets);
7100: for (var i=0; i<blocks.length; i++) {
7101: var disp = 'none';
7102: if (caller == blocks[i]) {
7103: var curr = document.getElementById('upload'+caller+'form').style.display;
7104: if (curr == 'none') {
7105: disp='block';
7106: }
7107: }
7108: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.484.2.93.2. (raeburn 7109:): if ((caller == 'tool') || (caller == 'supptool')) {
7110:): if (disp == 'block') {
7111:): if (document.getElementById('LC_exttoolid')) {
7112:): var toolselector = document.getElementById('LC_exttoolid');
7113:): var suppflag = 0;
7114:): if (caller == 'supptool') {
7115:): suppflag = 1;
7116:): }
7117:): currForm = document.getElementById('new'+caller);
7118:): updateExttool(toolselector,currForm,suppflag);
7119:): }
7120:): }
7121:): }
1.484.2.13 raeburn 7122: }
7123: resize_scrollbox('contentscroll','1','1');
7124: return;
7125: }
7126:
1.484.2.19 raeburn 7127: function toggleMap(caller) {
1.484.2.13 raeburn 7128: var disp = 'none';
1.484.2.19 raeburn 7129: if (document.getElementById('importmapform')) {
7130: if (caller == 'map') {
7131: var curr = document.getElementById('importmapform').style.display;
7132: if (curr == 'none') {
7133: disp='block';
7134: }
1.484.2.12 raeburn 7135: }
1.484.2.19 raeburn 7136: document.getElementById('importmapform').style.display=disp;
7137: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 7138: }
1.484.2.19 raeburn 7139: return;
1.329 droeschl 7140: }
7141:
1.484.2.12 raeburn 7142: function makeims(imsform) {
7143: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 7144: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 7145: return;
7146: }
7147: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 7148: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 7149: return;
7150: }
7151: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7152: imsform.submit();
7153: }
7154:
1.478 raeburn 7155: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 7156: var pickitem;
7157: var picknumitem;
7158: var picknumtext;
7159: if (index == 'all') {
7160: pickitem = document.getElementById('randompickall');
7161: picknumitem = document.getElementById('rpicknumall');
7162: picknumtext = document.getElementById('rpicktextall');
7163: } else {
7164: pickitem = document.getElementById('randompick_'+index);
7165: picknumitem = document.getElementById('rpicknum_'+index);
7166: picknumtext = document.getElementById('randompicknum_'+index);
7167: }
1.478 raeburn 7168: if (pickitem.checked) {
1.484.2.61 raeburn 7169: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7170: if (picknum == '' || picknum == null) {
7171: if (caller == 'check') {
7172: pickitem.checked=false;
1.484.2.29 raeburn 7173: if (index == 'all') {
7174: picknumtext.innerHTML = '';
7175: if (caller == 'link') {
7176: propagateState(targetform,'rpicknum');
7177: }
7178: } else {
1.484.2.30 raeburn 7179: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7180: }
1.478 raeburn 7181: }
7182: } else {
7183: picknum.toString();
7184: var regexdigit=/^\\d+\$/;
7185: if (regexdigit.test(picknum)) {
7186: picknumitem.value = picknum;
1.484.2.29 raeburn 7187: if (index == 'all') {
1.484.2.30 raeburn 7188: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 7189: if (caller == 'link') {
7190: propagateState(targetform,'rpicknum');
7191: }
7192: } else {
7193: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 7194: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7195: }
1.478 raeburn 7196: } else {
7197: if (caller == 'check') {
1.484.2.29 raeburn 7198: if (index == 'all') {
7199: picknumtext.innerHTML = '';
7200: if (caller == 'link') {
7201: propagateState(targetform,'rpicknum');
7202: }
7203: } else {
7204: pickitem.checked=false;
1.484.2.30 raeburn 7205: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7206: }
1.478 raeburn 7207: }
7208: return;
7209: }
7210: }
7211: } else {
1.484.2.29 raeburn 7212: picknumitem.value = '';
7213: picknumtext.innerHTML = '';
7214: if (index == 'all') {
7215: if (caller == 'link') {
7216: propagateState(targetform,'rpicknum');
7217: }
7218: } else {
1.484.2.30 raeburn 7219: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7220: }
7221: }
7222: }
7223:
7224: function propagateState(form,param) {
7225: if (document.getElementById(param+'all')) {
7226: var setcheck = 0;
7227: var rpick = 0;
7228: if (param == 'rpicknum') {
7229: if (document.getElementById('randompickall')) {
7230: if (document.getElementById('randompickall').checked) {
7231: if (document.getElementById('rpicknumall')) {
7232: rpick = document.getElementById('rpicknumall').value;
7233: }
7234: }
7235: }
7236: } else {
7237: if (document.getElementById(param+'all').checked) {
7238: setcheck = 1;
7239: }
7240: }
1.484.2.30 raeburn 7241: var allidxlist;
7242: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7243: if (document.getElementById('all'+param+'idx')) {
7244: allidxlist = document.getElementById('all'+param+'idx').value;
7245: }
7246: var actions = new Array ('remove','cut','copy');
7247: for (var i=0; i<actions.length; i++) {
7248: if (actions[i] != param) {
7249: if (document.getElementById(actions[i]+'all')) {
7250: document.getElementById(actions[i]+'all').checked = false;
7251: }
7252: }
7253: }
7254: }
1.484.2.29 raeburn 7255: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 7256: allidxlist = form.allidx.value;
7257: }
7258: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7259: allidxlist = form.allmapidx.value;
7260: }
7261: if ((allidxlist != '') && (allidxlist != null)) {
7262: var allidxs = allidxlist.split(',');
7263: if (allidxs.length > 1) {
7264: for (var i=0; i<allidxs.length; i++) {
7265: if (document.getElementById(param+'_'+allidxs[i])) {
7266: if (param == 'rpicknum') {
7267: if (document.getElementById('randompick_'+allidxs[i])) {
7268: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7269: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7270: if (rpick > 0) {
7271: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7272: } else {
7273: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7274: }
7275: }
7276: }
7277: } else {
1.484.2.29 raeburn 7278: if (setcheck == 1) {
7279: document.getElementById(param+'_'+allidxs[i]).checked = true;
7280: } else {
7281: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 7282: if (param == 'randompick') {
7283: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7284: }
1.484.2.29 raeburn 7285: }
7286: }
7287: }
7288: }
1.484.2.30 raeburn 7289: if (setcheck == 1) {
7290: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7291: var actions = new Array('copy','cut','remove');
7292: for (var i=0; i<actions.length; i++) {
7293: var otheractions;
7294: var otheridxs;
7295: if (actions[i] === param) {
7296: continue;
7297: } else {
7298: if (document.getElementById('all'+actions[i]+'idx')) {
7299: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7300: otheridxs = otheractions.split(',');
7301: if (otheridxs.length > 1) {
7302: for (var j=0; j<otheridxs.length; j++) {
7303: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7304: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7305: }
1.484.2.29 raeburn 7306: }
7307: }
7308: }
7309: }
1.484.2.30 raeburn 7310: }
1.484.2.29 raeburn 7311: }
7312: }
7313: }
7314: }
1.478 raeburn 7315: }
1.484.2.29 raeburn 7316: return;
7317: }
7318:
1.484.2.63 raeburn 7319: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7320: var canedit = '$canedit';
7321: if (canedit == '') {
7322: alert("$js_lt{'edri'}");
7323: return;
7324: }
1.484.2.30 raeburn 7325: var dosettings;
7326: var doaction;
7327: var control = document.togglemultsettings;
7328: if (context == 'actions') {
7329: control = document.togglemultactions;
7330: doaction = 1;
7331: } else {
7332: dosettings = 1;
7333: }
7334: if (control) {
7335: if (control.showmultpick.length) {
7336: for (var i=0; i<control.showmultpick.length; i++) {
7337: if (control.showmultpick[i].checked) {
7338: if (control.showmultpick[i].value == 1) {
7339: if (context == 'settings') {
7340: dosettings = 0;
7341: } else {
7342: doaction = 0;
7343: }
7344: }
7345: }
7346: }
7347: }
7348: }
7349: if (context == 'settings') {
7350: if (dosettings == 1) {
7351: targetform.changeparms.value=param;
7352: targetform.submit();
7353: }
7354: }
7355: if (context == 'actions') {
7356: if (doaction == 1) {
7357: targetform.cmd.value=param+'_'+index;
7358: targetform.folderpath.value=folderpath;
7359: targetform.markcopy.value=idx+':'+param;
7360: targetform.copyfolder.value=folder+'.'+container;
7361: if (param == 'remove') {
1.484.2.63 raeburn 7362: var doremove = 0;
7363: if (skip_confirm) {
7364: if (confirm_removal) {
7365: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7366: doremove = 1;
7367: }
7368: } else {
7369: doremove = 1;
7370: }
7371: } else {
7372: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7373: doremove = 1;
7374: }
7375: }
7376: if (doremove) {
1.484.2.30 raeburn 7377: targetform.markcopy.value='';
7378: targetform.copyfolder.value='';
1.484.2.29 raeburn 7379: targetform.submit();
7380: }
7381: }
1.484.2.30 raeburn 7382: if (param == 'cut') {
1.484.2.61 raeburn 7383: 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 7384: targetform.submit();
7385: return;
7386: }
7387: }
7388: if (param == 'copy') {
7389: targetform.submit();
7390: return;
7391: }
7392: targetform.markcopy.value='';
7393: targetform.copyfolder.value='';
7394: targetform.cmd.value='';
7395: targetform.folderpath.value='';
7396: return;
7397: } else {
7398: if (document.getElementById(param+'_'+idx)) {
7399: item = document.getElementById(param+'_'+idx);
7400: if (item.type == 'checkbox') {
7401: if (item.checked) {
7402: item.checked = false;
7403: } else {
7404: item.checked = true;
7405: singleCheck(item,idx,param);
7406: }
7407: }
7408: }
7409: }
7410: }
7411: return;
7412: }
7413:
7414: function singleCheck(caller,idx,action) {
7415: actions = new Array('cut','copy','remove');
7416: if (caller.checked) {
7417: for (var i=0; i<actions.length; i++) {
7418: if (actions[i] != action) {
7419: if (document.getElementById(actions[i]+'_'+idx)) {
7420: if (document.getElementById(actions[i]+'_'+idx).checked) {
7421: document.getElementById(actions[i]+'_'+idx).checked = false;
7422: }
7423: }
7424: }
1.484.2.29 raeburn 7425: }
7426: }
7427: return;
1.478 raeburn 7428: }
7429:
1.334 muellerd 7430: function unselectInactive(nav) {
1.335 ehlerst 7431: currentNav = document.getElementById(nav);
7432: currentLis = currentNav.getElementsByTagName('LI');
7433: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7434: if (currentLis[i].className == 'goback') {
7435: currentLis[i].className = 'goback';
7436: } else {
7437: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7438: currentLis[i].className = 'right';
1.472 raeburn 7439: } else {
1.374 tempelho 7440: currentLis[i].className = 'i';
1.472 raeburn 7441: }
7442: }
1.335 ehlerst 7443: }
1.332 tempelho 7444: }
7445:
1.334 muellerd 7446: function hideAll(current, nav, data) {
1.335 ehlerst 7447: unselectInactive(nav);
1.484.2.43 raeburn 7448: if (current) {
7449: if (current.className == 'right'){
1.374 tempelho 7450: current.className = 'right active'
1.484.2.43 raeburn 7451: } else {
1.374 tempelho 7452: current.className = 'active';
1.484.2.43 raeburn 7453: }
1.374 tempelho 7454: }
1.335 ehlerst 7455: currentData = document.getElementById(data);
7456: currentDivs = currentData.getElementsByTagName('DIV');
7457: for (i = 0; i < currentDivs.length; i++) {
7458: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7459: currentDivs[i].style.display = 'none';
1.330 tempelho 7460: }
7461: }
1.335 ehlerst 7462: }
1.330 tempelho 7463:
1.374 tempelho 7464: function openTabs(pageId) {
7465: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7466: if(tabnav.length > 2 ){
1.389 tempelho 7467: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7468: currentLis = currentNav.getElementsByTagName('LI');
7469: for(i = 0; i< currentLis.length; i++){
7470: if(currentLis[i].className == 'active') {
1.375 tempelho 7471: funcString = currentLis[i].onclick.toString();
7472: tab = funcString.split('"');
1.420 onken 7473: if(tab.length < 2) {
7474: tab = funcString.split("'");
7475: }
1.375 tempelho 7476: currentData = document.getElementById(tab[1]);
7477: currentData.style.display = 'block';
1.374 tempelho 7478: }
7479: }
7480: }
7481: }
7482:
1.334 muellerd 7483: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7484: currstate = current.className;
1.334 muellerd 7485: hideAll(current, nav, data);
1.375 tempelho 7486: openTabs(pageId);
1.334 muellerd 7487: unselectInactive(nav);
1.484.2.43 raeburn 7488: if ((currstate == 'active') || (currstate == 'right active')) {
7489: if (currstate == 'active') {
7490: current.className = '';
7491: } else {
7492: current.className = 'right';
7493: }
7494: activeTab = '';
7495: toggleUpload();
7496: toggleMap();
7497: resize_scrollbox('contentscroll','1','0');
7498: return;
7499: } else {
7500: current.className = 'active';
7501: }
1.330 tempelho 7502: currentData = document.getElementById(pageId);
7503: currentData.style.display = 'block';
1.458 raeburn 7504: activeTab = pageId;
1.484.2.12 raeburn 7505: toggleUpload();
1.484.2.14 raeburn 7506: toggleMap();
1.433 raeburn 7507: if (nav == 'mainnav') {
7508: var storedpath = "$docs_folderpath";
1.434 raeburn 7509: var storedpage = "$main_container_page";
1.433 raeburn 7510: var reg = new RegExp("^supplemental");
7511: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7512: if (storedpage == 1) {
7513: document.simpleedit.folderpath.value = '';
7514: document.uploaddocument.folderpath.value = '';
7515: } else {
7516: if (reg.test(storedpath)) {
7517: document.simpleedit.folderpath.value = '$toplevelmain';
7518: document.uploaddocument.folderpath.value = '$toplevelmain';
7519: document.newext.folderpath.value = '$toplevelmain';
7520: } else {
7521: document.simpleedit.folderpath.value = storedpath;
7522: document.uploaddocument.folderpath.value = storedpath;
7523: document.newext.folderpath.value = storedpath;
7524: }
1.433 raeburn 7525: }
7526: } else {
1.434 raeburn 7527: if (reg.test(storedpath)) {
7528: document.simpleedit.folderpath.value = storedpath;
7529: document.supuploaddocument.folderpath.value = storedpath;
7530: document.supnewext.folderpath.value = storedpath;
7531: } else {
1.433 raeburn 7532: document.simpleedit.folderpath.value = '$toplevelsupp';
7533: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7534: document.supnewext.folderpath.value = '$toplevelsupp';
7535: }
7536: }
7537: }
1.484.2.3 raeburn 7538: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7539: return false;
7540: }
1.329 droeschl 7541:
1.472 raeburn 7542: function toContents(jumpto) {
7543: var newurl = '$backtourl';
1.484.2.21 raeburn 7544: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7545: newurl = newurl+'?postdata='+jumpto;
7546: }
7547: location.href=newurl;
7548: }
7549:
1.484.2.30 raeburn 7550: function togglePick(caller,value) {
7551: var disp = 'none';
7552: if (document.getElementById('multi'+caller)) {
7553: var curr = document.getElementById('multi'+caller).style.display;
7554: if (value == 1) {
7555: disp='block';
7556: }
7557: if (curr == disp) {
7558: return;
7559: }
7560: document.getElementById('multi'+caller).style.display=disp;
7561: if (value == 1) {
1.484.2.61 raeburn 7562: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7563: } else {
7564: document.getElementById('more'+caller).innerHTML = '';
7565: }
7566: if (caller == 'actions') {
7567: setClass(value);
7568: setBoxes(value);
7569: }
7570: }
7571: var showButton = multiSettings();
7572: if (showButton != 1) {
7573: showButton = multiActions();
7574: }
7575: if (document.getElementById('multisave')) {
7576: if (showButton == 1) {
7577: document.getElementById('multisave').style.display='block';
7578: } else {
7579: document.getElementById('multisave').style.display='none';
7580: }
7581: }
7582: resize_scrollbox('contentscroll','1','1');
7583: return;
7584: }
7585:
7586: function toggleCheckUncheck(caller,more) {
7587: if (more == 1) {
1.484.2.61 raeburn 7588: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7589: document.getElementById('allfields'+caller).style.display='block';
7590: } else {
1.484.2.61 raeburn 7591: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7592: document.getElementById('allfields'+caller).style.display='none';
7593: }
7594: resize_scrollbox('contentscroll','1','1');
7595: }
7596:
7597: function multiSettings() {
7598: var inuse = 0;
7599: var settingsform = document.togglemultsettings;
7600: if (settingsform.showmultpick.length > 1) {
7601: for (var i=0; i<settingsform.showmultpick.length; i++) {
7602: if (settingsform.showmultpick[i].checked) {
7603: if (settingsform.showmultpick[i].value == 1) {
7604: inuse = 1;
7605: }
7606: }
7607: }
7608: }
7609: return inuse;
7610: }
7611:
7612: function multiActions() {
7613: var inuse = 0;
7614: var actionsform = document.togglemultactions;
7615: if (actionsform.showmultpick.length > 1) {
7616: for (var i=0; i<actionsform.showmultpick.length; i++) {
7617: if (actionsform.showmultpick[i].checked) {
7618: if (actionsform.showmultpick[i].value == 1) {
7619: inuse = 1;
7620: }
7621: }
7622: }
7623: }
7624: return inuse;
7625: }
7626:
7627: function checkSubmits() {
7628: var numchanges = 0;
7629: var form = document.saveactions;
7630: var doactions = multiActions();
7631: var cutwarnings = 0;
7632: var remwarnings = 0;
1.484.2.63 raeburn 7633: var removalinfo = 0;
1.484.2.30 raeburn 7634: if (doactions == 1) {
7635: var remidxlist = document.cumulativeactions.allremoveidx.value;
7636: if ((remidxlist != '') && (remidxlist != null)) {
7637: var remidxs = remidxlist.split(',');
7638: for (var i=0; i<remidxs.length; i++) {
7639: if (document.getElementById('remove_'+remidxs[i])) {
7640: if (document.getElementById('remove_'+remidxs[i]).checked) {
7641: form.multiremove.value += remidxs[i]+',';
7642: numchanges ++;
7643: if (document.getElementById('skip_remove_'+remidxs[i])) {
7644: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7645: remwarnings ++;
7646: }
7647: }
1.484.2.63 raeburn 7648: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7649: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7650: removalinfo ++;
7651: }
7652: }
1.484.2.30 raeburn 7653: }
7654: }
7655: }
7656: }
7657: var cutidxlist = document.cumulativeactions.allcutidx.value;
7658: if ((cutidxlist != '') && (cutidxlist != null)) {
7659: var cutidxs = cutidxlist.split(',');
7660: for (var i=0; i<cutidxs.length; i++) {
7661: if (document.getElementById('cut_'+cutidxs[i])) {
7662: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7663: form.multicut.value += cutidxs[i]+',';
7664: numchanges ++;
7665: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7666: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7667: cutwarnings ++;
7668: }
7669: }
7670: }
7671: }
7672: }
7673: }
7674: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7675: if ((copyidxlist != '') && (copyidxlist != null)) {
7676: var copyidxs = copyidxlist.split(',');
7677: for (var i=0; i<copyidxs.length; i++) {
7678: if (document.getElementById('copy_'+copyidxs[i])) {
7679: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7680: form.multicopy.value += copyidxs[i]+',';
7681: numchanges ++;
7682: }
7683: }
7684: }
7685: }
7686: if (numchanges > 0) {
7687: form.multichange.value = numchanges;
7688: }
7689: }
7690: var dosettings = multiSettings();
7691: var haschanges = 0;
7692: if (dosettings == 1) {
7693: form.allencrypturl.value = '';
7694: form.allhiddenresource.value = '';
7695: form.changeparms.value = 'all';
7696: var patt=new RegExp(",\$");
7697: var allidxlist = document.cumulativesettings.allidx.value;
7698: if ((allidxlist != '') && (allidxlist != null)) {
7699: var allidxs = allidxlist.split(',');
7700: if (allidxs.length > 1) {
7701: for (var i=0; i<allidxs.length; i++) {
7702: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7703: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7704: form.allhiddenresource.value += allidxs[i]+',';
7705: }
7706: }
7707: if (document.getElementById('encrypturl_'+allidxs[i])) {
7708: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7709: form.allencrypturl.value += allidxs[i]+',';
7710: }
1.484.2.29 raeburn 7711: }
7712: }
1.484.2.30 raeburn 7713: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7714: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7715: }
7716: }
7717: form.allrandompick.value = '';
7718: form.allrandomorder.value = '';
7719: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7720: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7721: var allmapidxs = allmapidxlist.split(',');
7722: for (var i=0; i<allmapidxs.length; i++) {
7723: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7724: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7725: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7726: if ((randompick.checked) && (rpicknum.value != '')) {
7727: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7728: }
7729: if (randorder.checked) {
7730: form.allrandomorder.value += allmapidxs[i]+',';
7731: }
7732: }
7733: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7734: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7735: }
7736: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7737: haschanges = 1;
7738: }
7739: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7740: haschanges = 1;
7741: }
7742: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7743: haschanges = 1;
7744: }
7745: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7746: haschanges = 1;
7747: }
7748: }
7749: if (doactions == 1) {
7750: if (numchanges > 0) {
1.484.2.63 raeburn 7751: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7752: if (remwarnings > 0) {
1.484.2.61 raeburn 7753: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7754: return false;
7755: }
7756: }
1.484.2.63 raeburn 7757: if (removalinfo > 0) {
7758: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7759: return false;
7760: }
7761: }
1.484.2.30 raeburn 7762: if (cutwarnings > 0) {
1.484.2.61 raeburn 7763: 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 7764: return false;
1.484.2.29 raeburn 7765: }
7766: }
7767: }
1.484.2.30 raeburn 7768: form.submit();
7769: return true;
7770: }
7771: }
7772: if (dosettings == 1) {
7773: if (haschanges == 1) {
7774: form.submit();
7775: return true;
1.484.2.29 raeburn 7776: }
7777: }
1.484.2.30 raeburn 7778: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7779: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7780: } else {
7781: if (dosettings == 1) {
1.484.2.61 raeburn 7782: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7783: } else {
1.484.2.61 raeburn 7784: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7785: }
7786: }
7787: return false;
7788: }
7789:
7790: function setClass(value) {
7791: var cutclass = 'LC_docs_cut';
7792: var copyclass = 'LC_docs_copy';
7793: var removeclass = 'LC_docs_remove';
7794: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7795: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7796: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7797: var links = document.getElementsByTagName('a');
7798: for (var i=0; i<links.length; i++) {
7799: var classes = links[i].className;
7800: if (cutreg.test(classes)) {
7801: links[i].className = cutclass;
7802: if (value == 1) {
7803: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7804: }
1.484.2.30 raeburn 7805: } else {
7806: if (copyreg.test(classes)) {
7807: links[i].className = copyclass;
7808: if (value == 1) {
7809: links[i].className += " LC_menubuttons_link";
7810: }
7811: } else {
7812: if (removereg.test(classes)) {
7813: links[i].className = removeclass;
7814: if (value == 1) {
7815: links[i].className += " LC_menubuttons_link";
7816: }
7817: }
1.484.2.29 raeburn 7818: }
7819: }
7820: }
1.484.2.30 raeburn 7821: return;
1.484.2.29 raeburn 7822: }
7823:
1.484.2.30 raeburn 7824: function setBoxes(value) {
7825: var remidxlist = document.cumulativeactions.allremoveidx.value;
7826: if ((remidxlist != '') && (remidxlist != null)) {
7827: var remidxs = remidxlist.split(',');
7828: for (var i=0; i<remidxs.length; i++) {
7829: if (document.getElementById('remove_'+remidxs[i])) {
7830: var item = document.getElementById('remove_'+remidxs[i]);
7831: if (value == 1) {
7832: item.className = 'LC_docs_remove';
7833: } else {
7834: item.className = 'LC_hidden';
7835: }
7836: }
1.484.2.29 raeburn 7837: }
7838: }
1.484.2.30 raeburn 7839: var cutidxlist = document.cumulativeactions.allcutidx.value;
7840: if ((cutidxlist != '') && (cutidxlist != null)) {
7841: var cutidxs = cutidxlist.split(',');
7842: for (var i=0; i<cutidxs.length; i++) {
7843: if (document.getElementById('cut_'+cutidxs[i])) {
7844: var item = document.getElementById('cut_'+cutidxs[i]);
7845: if (value == 1) {
7846: item.className = 'LC_docs_cut';
7847: } else {
7848: item.className = 'LC_hidden';
7849: }
7850: }
7851: }
7852: }
7853: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7854: if ((copyidxlist != '') && (copyidxlist != null)) {
7855: var copyidxs = copyidxlist.split(',');
7856: for (var i=0; i<copyidxs.length; i++) {
7857: if (document.getElementById('copy_'+copyidxs[i])) {
7858: var item = document.getElementById('copy_'+copyidxs[i]);
7859: if (value == 1) {
7860: item.className = 'LC_docs_copy';
7861: } else {
7862: item.className = 'LC_hidden';
7863: }
7864: }
1.484.2.29 raeburn 7865: }
7866: }
7867: return;
7868: }
7869:
1.484.2.67 raeburn 7870: ENDSCRIPT
1.329 droeschl 7871: }
1.457 raeburn 7872:
1.483 raeburn 7873: sub history_tab_js {
7874: return <<"ENDHIST";
7875: function toggleHistoryDisp(choice) {
7876: document.docslogform.docslog.value = choice;
7877: document.docslogform.submit();
7878: return;
7879: }
7880:
7881: ENDHIST
7882: }
7883:
1.484 raeburn 7884: sub inject_data_js {
7885: return <<ENDINJECT;
7886:
7887: function injectData(current, hiddenField, name, value) {
7888: currentElement = document.getElementById(hiddenField);
7889: currentElement.name = name;
7890: currentElement.value = value;
7891: current.submit();
7892: }
7893:
7894: ENDINJECT
7895: }
7896:
7897: sub dump_switchserver_js {
7898: my @hosts = @_;
1.484.2.61 raeburn 7899: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7900: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7901: swit => 'Switch server?',
1.484.2.61 raeburn 7902: );
7903: my %html_js_lt = &Apache::lonlocal::texthash(
7904: swit => 'Switch server?',
1.484.2.43 raeburn 7905: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7906: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7907: chos => 'Choose server',
7908: );
1.484.2.61 raeburn 7909: &js_escape(\%js_lt);
7910: &html_escape(\%html_js_lt);
7911: &js_escape(\%html_js_lt);
1.484 raeburn 7912: my $role = $env{'request.role'};
7913: my $js = <<"ENDSWJS";
7914: <script type="text/javascript">
7915: function write_switchserver() {
7916: var server;
7917: if (document.setserver.posshosts.length > 0) {
7918: for (var i=0; i<document.setserver.posshosts.length; i++) {
7919: if (document.setserver.posshosts[i].checked) {
7920: server = document.setserver.posshosts[i].value;
7921: }
7922: }
7923: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7924: }
7925: window.close();
7926: }
7927: </script>
7928:
7929: ENDSWJS
7930:
7931: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7932: {'only_body' => 1,
7933: 'js_ready' => 1,});
7934: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7935:
7936: my $hostpicker;
7937: my $count = 0;
7938: foreach my $host (sort(@hosts)) {
7939: my $checked;
7940: if ($count == 0) {
7941: $checked = ' checked="checked"';
7942: }
7943: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7944: $host.'"'.$checked.' />'.$host.'</label> ';
7945: $count++;
7946: }
7947:
7948: return <<"ENDSWITCHJS";
7949:
7950: function dump_needs_switchserver(url) {
7951: if (url!='' && url!= null) {
1.484.2.61 raeburn 7952: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7953: go(url);
7954: }
7955: }
7956: return;
7957: }
7958:
7959: function choose_switchserver_window() {
7960: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7961: newWindow.document.open();
7962: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7963: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7964: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7965: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7966: '<form name="setserver" method="post" action="" \\/>\\n'+
7967: '$hostpicker\\n'+
7968: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7969: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7970: 'onclick="write_switchserver();" \\/>\\n'+
7971: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7972: newWindow.document.writeln('$endpage');
7973: newWindow.document.close();
7974: newWindow.focus();
7975: }
7976:
7977: ENDSWITCHJS
7978: }
7979:
7980: sub makedocslogform {
7981: my ($formelems,$docslog) = @_;
7982: return <<"LOGSFORM";
7983: <form action="/adm/coursedocs" method="post" name="docslogform">
7984: <input type="hidden" name="docslog" value="$docslog" />
7985: $formelems
7986: </form>
7987: LOGSFORM
7988: }
7989:
7990: sub makesimpleeditform {
7991: my ($formelems) = @_;
7992: return <<"SIMPFORM";
7993: <form name="simpleedit" method="post" action="/adm/coursedocs">
7994: <input type="hidden" name="importdetail" value="" />
7995: $formelems
7996: </form>
7997: SIMPFORM
7998: }
7999:
1.329 droeschl 8000: 1;
8001: __END__
8002:
8003:
8004: =head1 NAME
8005:
8006: Apache::londocs.pm
8007:
8008: =head1 SYNOPSIS
8009:
8010: This is part of the LearningOnline Network with CAPA project
8011: described at http://www.lon-capa.org.
8012:
8013: =head1 SUBROUTINES
8014:
8015: =over
8016:
8017: =item %help=()
8018:
8019: Available help topics
8020:
8021: =item mapread()
8022:
1.344 bisitz 8023: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8024: @order and @resources, determines status
8025: sets @order - pointer to resources in right order
8026: sets @resources - array with the resources with correct idx
8027:
8028: =item authorhosts()
8029:
8030: Return hash with valid author names
8031:
8032: =item clean()
8033:
8034: =item dumpcourse()
8035:
8036: Actually dump course
8037:
8038: =item group_import()
8039:
8040: Imports the given (name, url) resources into the course
8041: coursenum, coursedom, and folder must precede the list
8042:
8043: =item breadcrumbs()
8044:
8045: =item log_docs()
8046:
8047: =item docs_change_log()
8048:
8049: =item update_paste_buffer()
8050:
8051: =item print_paste_buffer()
8052:
8053: =item do_paste_from_buffer()
8054:
1.484.2.30 raeburn 8055: =item do_buffer_empty()
8056:
8057: =item clear_from_buffer()
8058:
1.484.2.7 raeburn 8059: =item get_newmap_url()
8060:
8061: =item dbcopy()
8062:
8063: =item uniqueness_check()
8064:
8065: =item contained_map_check()
8066:
8067: =item url_paste_fixups()
8068:
8069: =item apply_fixups()
8070:
8071: =item copy_dependencies()
8072:
1.329 droeschl 8073: =item update_parameter()
8074:
8075: =item handle_edit_cmd()
8076:
8077: =item editor()
8078:
8079: =item process_file_upload()
8080:
8081: =item process_secondary_uploads()
8082:
8083: =item is_supplemental_title()
8084:
8085: =item entryline()
8086:
8087: =item tiehash()
8088:
8089: =item untiehash()
8090:
8091: =item checkonthis()
8092:
8093: check on this
8094:
8095: =item verifycontent()
8096:
8097: Verify Content
8098:
1.484.2.78 raeburn 8099: =item devalidateversioncache()
8100:
8101: =item checkversions()
1.329 droeschl 8102:
8103: Check Versions
8104:
8105: =item mark_hash_old()
8106:
8107: =item is_hash_old()
8108:
8109: =item changewarning()
8110:
8111: =item init_breadcrumbs()
8112:
8113: Breadcrumbs for special functions
8114:
1.484 raeburn 8115: =item create_list_elements()
8116:
8117: =item create_form_ul()
8118:
8119: =item startContentScreen()
8120:
8121: =item endContentScreen()
8122:
8123: =item supplemental_base()
8124:
8125: =item embedded_form_elems()
8126:
8127: =item embedded_destination()
8128:
8129: =item return_to_editor()
8130:
8131: =item decompression_info()
8132:
8133: =item decompression_phase_one()
8134:
8135: =item decompression_phase_two()
8136:
8137: =item remove_archive()
8138:
8139: =item generate_admin_menu()
8140:
8141: =item generate_edit_table()
8142:
8143: =item editing_js()
8144:
8145: =item history_tab_js()
8146:
8147: =item inject_data_js()
8148:
8149: =item dump_switchserver_js()
8150:
1.484.2.3 raeburn 8151: =item resize_scrollbox_js()
1.484 raeburn 8152:
8153: =item makedocslogform()
8154:
1.484.2.3 raeburn 8155: =item makesimpleeditform()
8156:
1.329 droeschl 8157: =back
8158:
8159: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>