Annotation of loncom/interface/londocs.pm, revision 1.484.2.85.2.9
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.85.2. (raeburn 4:): # $Id: londocs.pm,v 1.484.2.85.2.8 2021/02/10 13:34:22 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.85.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.85.2. (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.85.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.85.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:): }
797:): }
798:): }
799:): }
1.484.2.23 raeburn 800: if (($caller eq 'londocs') &&
801: ($folder =~ /^default/)) {
1.484.2.27 raeburn 802: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 803: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
804: my $cid = $coursedom.'_'.$coursenum;
805: $allmaps =
806: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
807: $chome,$cid);
808: $donechk = 1;
809: }
810: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.484.2.85.2. (raeburn 811:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
812:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.484.2.23 raeburn 813: $importuploaded = 1;
814: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
815: next if ($allmaps->{$url});
816: }
817: }
1.344 bisitz 818: if (!$residx
1.329 droeschl 819: || defined($LONCAPA::map::zombies[$residx])) {
820: $residx = &LONCAPA::map::getresidx($url,$residx);
821: push(@LONCAPA::map::order, $residx);
822: }
823: my $ext = 'false';
824: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.484.2.27 raeburn 825: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
826: my $filepath = $1;
1.484.2.85.2. (raeburn 827:): my $fname;
828:): if ($name eq '') {
829:): $name = &mt('Web Page');
1.484.2.27 raeburn 830: $fname = 'web';
831: } else {
1.484.2.85.2. (raeburn 832:): $fname = $name;
833:): $fname=&Apache::lonnet::clean_filename($fname);
834:): if ($fname eq '') {
835:): $fname = 'web';
836:): } elsif (length($fname) > 15) {
837:): $fname = substr($fname,0,14);
838:): }
1.484.2.27 raeburn 839: }
1.484.2.85.2. (raeburn 840:): my $title = &Apache::loncommon::cleanup_html($name);
1.484.2.27 raeburn 841: my $initialtext = &mt('Replace with your own content.');
842: my $newhtml = <<END;
1.484.2.31 raeburn 843: <html>
1.484.2.27 raeburn 844: <head>
1.484.2.85.2. (raeburn 845:): <title>$title</title>
1.484.2.27 raeburn 846: </head>
847: <body bgcolor="#ffffff">
848: $initialtext
849: </body>
850: </html>
851: END
852: $env{'form.output'}=$newhtml;
853: my $result =
854: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
855: 'output',
856: "$filepath/$residx/$fname.html");
857: if ($result =~ m{^/uploaded/}) {
858: $url = $result;
859: if ($filepath =~ /^supplemental/) {
860: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
861: $env{'user.domain'}.'___&&&___'.$name;
862: }
863: } else {
864: return (&mt('Failed to save new web page.'),1);
865: }
866: }
1.484.2.85.2. (raeburn 867:): $name = &LONCAPA::map::qtunescape($name);
1.484.2.30 raeburn 868: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 869: $LONCAPA::map::resources[$residx] =
1.329 droeschl 870: join(':', ($name, $url, $ext, 'normal', 'res'));
871: }
872: }
1.484.2.23 raeburn 873: if ($importuploaded) {
874: my %import_errors;
875: my %updated = (
876: removefrommap => \%removefrommap,
877: removeparam => \%removeparam,
878: );
1.484.2.26 raeburn 879: my ($result,$msgsarray,$lockerror) =
880: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 881: if (keys(%import_errors) > 0) {
882: $fixuperrors =
883: '<p span class="LC_warning">'."\n".
884: &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".
885: '<ul>'."\n";
886: foreach my $key (sort(keys(%import_errors))) {
887: $fixuperrors .= '<li>'.$key.'</li>'."\n";
888: }
889: $fixuperrors .= '</ul></p>'."\n";
890: }
1.484.2.26 raeburn 891: if (ref($msgsarray) eq 'ARRAY') {
892: if (@{$msgsarray} > 0) {
893: $fixuperrors .= '<p class="LC_info">'.
894: join('<br />',@{$msgsarray}).
895: '</p>';
896: }
897: }
898: if ($lockerror) {
899: $fixuperrors .= '<p class="LC_error">'.
900: $lockerror.
901: '</p>';
902: }
1.484.2.23 raeburn 903: }
904: my ($errtext,$fatal) =
905: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 906: unless ($fatal) {
907: if ($folder =~ /^supplemental/) {
908: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 909: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
910: $folder.'.'.$container);
1.484.2.37 raeburn 911: }
912: }
1.484.2.23 raeburn 913: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 914: }
915:
916: sub log_docs {
1.484.2.8 raeburn 917: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 918: }
919:
920: {
921: my @oldresources=();
922: my @oldorder=();
923: my $parmidx;
924: my %parmaction=();
925: my %parmvalue=();
926: my $changedflag;
927:
928: sub snapshotbefore {
929: @oldresources=@LONCAPA::map::resources;
930: @oldorder=@LONCAPA::map::order;
931: $parmidx=undef;
932: %parmaction=();
933: %parmvalue=();
934: $changedflag=0;
935: }
936:
937: sub remember_parms {
938: my ($idx,$parameter,$action,$value)=@_;
939: $parmidx=$idx;
940: $parmaction{$parameter}=$action;
941: $parmvalue{$parameter}=$value;
942: $changedflag=1;
943: }
944:
945: sub log_differences {
946: my ($plain)=@_;
947: my %storehash=('folder' => $plain,
948: 'currentfolder' => $env{'form.folder'});
949: if ($parmidx) {
950: $storehash{'parameter_res'}=$oldresources[$parmidx];
951: foreach my $parm (keys(%parmaction)) {
952: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
953: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
954: }
955: }
956: my $maxidx=$#oldresources;
957: if ($#LONCAPA::map::resources>$#oldresources) {
958: $maxidx=$#LONCAPA::map::resources;
959: }
960: for (my $idx=0; $idx<=$maxidx; $idx++) {
961: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
962: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
963: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
964: $changedflag=1;
965: }
966: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
967: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
968: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
969: $changedflag=1;
970: }
971: }
972: $storehash{'maxidx'}=$maxidx;
973: if ($changedflag) { &log_docs(\%storehash); }
974: }
975: }
976:
977: sub docs_change_log {
1.484.2.67 raeburn 978: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 979: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 980: my $navmap;
1.483 raeburn 981: my $js = '<script type="text/javascript">'."\n".
982: '// <![CDATA['."\n".
983: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 984: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.85.2. (raeburn 985:): $coursedom,$coursenum,'',$canedit,'',\$navmap)."\n".
1.483 raeburn 986: &history_tab_js()."\n".
1.484 raeburn 987: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 988: '// ]]>'."\n".
989: '</script>'."\n";
1.484 raeburn 990: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
991: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 992: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 993: my %orderhash;
994: my $container='sequence';
995: my $pathitem;
1.484.2.19 raeburn 996: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 997: $container='page';
998: }
1.484.2.19 raeburn 999: my $folderpath=$env{'form.folderpath'};
1000: if ($folderpath eq '') {
1.484.2.67 raeburn 1001: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 1002: }
1.484.2.67 raeburn 1003: undef($navmap);
1.484.2.19 raeburn 1004: $pathitem = '<input type="hidden" name="folderpath" value="'.
1005: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1006: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1007: my $jumpto = $readfile;
1008: $jumpto =~ s{^/}{};
1009: my $tid = 1;
1.484.2.7 raeburn 1010: if ($supplementalflag) {
1011: $tid = 2;
1012: }
1.484.2.19 raeburn 1013: my ($breadcrumbtrail) =
1.484.2.18 raeburn 1014: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1015: $r->print($breadcrumbtrail.
1016: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1017: $readfile));
1.329 droeschl 1018: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1019: $env{'course.'.$env{'request.course.id'}.'.domain'},
1020: $env{'course.'.$env{'request.course.id'}.'.num'});
1021:
1022: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1023:
1024: my %saveable_parameters = ('show' => 'scalar',);
1025: &Apache::loncommon::store_course_settings('docs_log',
1026: \%saveable_parameters);
1027: &Apache::loncommon::restore_course_settings('docs_log',
1028: \%saveable_parameters);
1029: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1030: # FIXME: internationalization seems wrong here
1.329 droeschl 1031: my %lt=('hiddenresource' => 'Resources hidden',
1032: 'encrypturl' => 'URL hidden',
1033: 'randompick' => 'Randomly pick',
1034: 'randomorder' => 'Randomly ordered',
1035: 'set' => 'set to',
1036: 'del' => 'deleted');
1.484 raeburn 1037: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1038: $pathitem."\n".
1039: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1040: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1041: $r->print('<div class="LC_left_float">'.
1042: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1043: &makedocslogform($filter,1).
1044: '</fieldset></div><br clear="all" />');
1.329 droeschl 1045: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1046: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1047: &mt('After').'</th>'.
1048: &Apache::loncommon::end_data_table_header_row());
1049: my $shown=0;
1050: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1051: if ($env{'form.displayfilter'} eq 'currentfolder') {
1052: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1053: }
1054: my @changes=keys(%{$docslog{$id}{'logentry'}});
1055: if ($env{'form.displayfilter'} eq 'containing') {
1056: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1057: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1058: foreach my $key (@changes) {
1059: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1060: }
1.344 bisitz 1061: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1062: }
1063: my $count = 0;
1064: my $time =
1065: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1066: my $plainname =
1067: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1068: $docslog{$id}{'exe_udom'});
1069: my $about_me_link =
1070: &Apache::loncommon::aboutmewrapper($plainname,
1071: $docslog{$id}{'exe_uname'},
1072: $docslog{$id}{'exe_udom'});
1073: my $send_msg_link='';
1074: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1075: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1076: $send_msg_link ='<br />'.
1077: &Apache::loncommon::messagewrapper(&mt('Send message'),
1078: $docslog{$id}{'exe_uname'},
1079: $docslog{$id}{'exe_udom'});
1080: }
1081: $r->print(&Apache::loncommon::start_data_table_row());
1082: $r->print('<td>'.$time.'</td>
1083: <td>'.$about_me_link.
1084: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1085: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1086: $send_msg_link.'</td><td>'.
1087: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 1088: my $is_supp = 0;
1.484.2.7 raeburn 1089: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1090: $is_supp = 1;
1091: }
1.329 droeschl 1092: # Before
1093: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1094: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1095: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1096: if ($oldname ne $newname) {
1.484.2.7 raeburn 1097: my $shown = &LONCAPA::map::qtescape($oldname);
1098: if ($is_supp) {
1099: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1100: }
1101: $r->print($shown);
1.329 droeschl 1102: }
1103: }
1104: $r->print('<ul>');
1105: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1106: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 1107: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1108: if ($is_supp) {
1109: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1110: }
1.484.2.19 raeburn 1111: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1112: }
1113: }
1114: $r->print('</ul>');
1115: # After
1116: $r->print('</td><td>');
1117:
1118: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1119: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1120: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1121: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 1122: my $shown = &LONCAPA::map::qtescape($newname);
1123: if ($is_supp) {
1124: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1125: }
1126: $r->print($shown);
1.329 droeschl 1127: }
1.364 bisitz 1128: }
1.329 droeschl 1129: $r->print('<ul>');
1130: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1131: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 1132: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1133: if ($is_supp) {
1134: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1135: }
1136: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1137: }
1138: }
1139: $r->print('</ul>');
1140: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1141: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1142: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1143: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1144: # FIXME: internationalization seems wrong here
1.329 droeschl 1145: $r->print('<li>'.
1146: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1147: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1148: .'</li>');
1149: }
1150: }
1151: $r->print('</ul>');
1152: }
1153: # End
1154: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1155: $shown++;
1156: if (!($env{'form.show'} eq &mt('all')
1157: || $shown<=$env{'form.show'})) { last; }
1158: }
1.484 raeburn 1159: $r->print(&Apache::loncommon::end_data_table()."\n".
1160: &makesimpleeditform($pathitem)."\n".
1161: '</div></div>');
1162: $r->print(&endContentScreen());
1.329 droeschl 1163: }
1164:
1165: sub update_paste_buffer {
1.484.2.7 raeburn 1166: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1167: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1168: if ($env{'form.multiremove'}) {
1169: $env{'form.multiremove'} =~ s/,$//;
1170: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1171: }
1172: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1173: if ($env{'form.multicut'}) {
1174: $env{'form.multicut'} =~ s/,$//;
1175: foreach my $item (split(/,/,$env{'form.multicut'})) {
1176: unless ($removals{$item}) {
1177: $cuts{$item} = 1;
1178: push(@possibles,$item.':cut');
1179: }
1180: }
1181: }
1182: if ($env{'form.multicopy'}) {
1183: $env{'form.multicopy'} =~ s/,$//;
1184: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1185: unless ($removals{$item} || $cuts{$item}) {
1186: push(@possibles,$item.':copy');
1187: }
1188: }
1189: }
1190: } elsif ($env{'form.markcopy'}) {
1191: @possibles = split(/,/,$env{'form.markcopy'});
1192: }
1.329 droeschl 1193:
1.484.2.30 raeburn 1194: return if (@possibles == 0);
1.329 droeschl 1195: return if (!defined($env{'form.copyfolder'}));
1196:
1197: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1198: $env{'form.copyfolder'});
1199: return if ($fatal);
1200:
1.484.2.30 raeburn 1201: my %curr_groups = &Apache::longroup::coursegroups();
1202:
1203: # Retrieve current paste buffer suffixes.
1204: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1205: my (%pasteurls,@newpaste);
1206:
1207: # Construct identifiers for current contents of user's paste buffer
1208: if (@currpaste) {
1209: foreach my $suffix (@currpaste) {
1.484.2.85.2. (raeburn 1210:): my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1211:): my $url = $env{'docs.markedcopy_url_'.$suffix};
1212:): my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1213:): if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1214:): ($url ne '')) {
1215:): if ($url eq '/res/lib/templates/simpleproblem.problem') {
1216:): $pasteurls{$cid.'_'.$mapidx} = 1;
1217:): } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1218:): $pasteurls{$url} = 1;
1219:): } else {
1220:): $pasteurls{$cid.'_'.$url} = 1;
1221:): }
1222:): }
1.484.2.30 raeburn 1223: }
1224: }
1225:
1226: # Mark items for copying (skip any items already in user's paste buffer)
1227: my %addtoenv;
1.484.2.82 raeburn 1228:
1229: my @pathitems = split(/\&/,$env{'form.folderpath'});
1230: my @folderconf = split(/\:/,$pathitems[-1]);
1.484.2.85.2. (raeburn 1231:): my $ispage = $folderconf[5];
1.484.2.82 raeburn 1232:
1.484.2.30 raeburn 1233: foreach my $item (@possibles) {
1234: my ($orderidx,$cmd) = split(/:/,$item);
1235: next if ($orderidx =~ /\D/);
1236: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1237: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1238: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1239: my %denied = &action_restrictions($coursenum,$coursedom,
1240: &LONCAPA::map::qtescape($url),
1241: $env{'form.folderpath'},\%curr_groups);
1242: next if ($denied{'copy'});
1243: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.85.2. (raeburn 1244:): if ($url eq '/res/lib/templates/simpleproblem.problem') {
1245:): next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1246:): } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1247:): next if (exists($pasteurls{$url}));
1248:): } else {
1249:): next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1250:): }
1.484.2.30 raeburn 1251: my ($suffix,$errortxt,$locknotfreed) =
1252: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1253: if ($suffix ne '') {
1254: push(@newpaste,$suffix);
1255: } else {
1256: if ($locknotfreed) {
1257: return $locknotfreed;
1258: }
1.484.2.30 raeburn 1259: }
1260: if (&is_supplemental_title($title)) {
1261: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1262: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1263: }
1264:
1265: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1266: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1267: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1268: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1269: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1270: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1271: my $prefix = $1;
1272: my $subdir =$2;
1273: if ($subdir eq '') {
1274: $subdir = $prefix;
1.484.2.7 raeburn 1275: }
1.484.2.30 raeburn 1276: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.484.2.85.2. (raeburn 1277:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1278:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.484.2.30 raeburn 1279: if (ref($hierarchy{$url}) eq 'HASH') {
1280: my ($nested,$nestednames);
1281: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1282: $nested =~ s/\&$//;
1283: $nestednames =~ s/\Q___&&&___\E$//;
1284: if ($nested ne '') {
1285: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1286: }
1287: if ($nestednames ne '') {
1288: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1289: }
1.484.2.7 raeburn 1290: }
1291: }
1.484.2.57 raeburn 1292: if ($locknotfreed) {
1293: $output = $locknotfreed;
1294: last;
1295: }
1.484.2.7 raeburn 1296: }
1.484.2.30 raeburn 1297: if (@newpaste) {
1298: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1299: }
1.484.2.7 raeburn 1300: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1301: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1302: return $output;
1.329 droeschl 1303: }
1304:
1.484.2.7 raeburn 1305: sub recurse_uploaded_maps {
1306: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1307: if (ref($hierarchy->{$url}) eq 'HASH') {
1308: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1309: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1310: my (@uploaded,@names,%shorter);
1311: for (my $i=0; $i<@maps; $i++) {
1312: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1313: if ($inner ne '') {
1314: push(@uploaded,$inner);
1315: push(@names,&escape($titles[$i]));
1316: $shorter{$maps[$i]} = $inner;
1317: }
1318: }
1319: $$nestref .= "$dir:".join(',',@uploaded).'&';
1320: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1321: foreach my $map (@maps) {
1322: if ($shorter{$map} ne '') {
1323: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1324: }
1325: }
1326: }
1327: return;
1328: }
1329:
1.329 droeschl 1330: sub print_paste_buffer {
1.484.2.7 raeburn 1331: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1332: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1333:
1.484.2.30 raeburn 1334: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1335: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1336: }
1337:
1.484.2.30 raeburn 1338: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1339: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1340: my $clipboardcount = 0;
1.484.2.7 raeburn 1341:
1.484.2.30 raeburn 1342: # Construct identifiers for current contents of user's paste buffer
1343: foreach my $suffix (@currpaste) {
1344: next if ($suffix =~ /\D/);
1345: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1346: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1347: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1348: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1349: ($url ne '')) {
1.484.2.47 raeburn 1350: $clipboardcount ++;
1.484.2.30 raeburn 1351: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.484.2.85.2. (raeburn 1352:): $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.484.2.30 raeburn 1353: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1354: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1355: $is_external = 1;
1.484.2.85.2. (raeburn 1356:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1357:): $is_exttool = 1;
1.484.2.7 raeburn 1358: }
1.484.2.30 raeburn 1359: if ($folder =~ /^supplemental/) {
1360: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1361: unless ($canpaste) {
1362: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1363: }
1.484.2.30 raeburn 1364: } else {
1365: $canpaste = 1;
1.484.2.7 raeburn 1366: }
1.484.2.30 raeburn 1367: if ($canpaste) {
1368: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1369: my $srcdom = $1;
1370: my $srcnum = $2;
1371: my $rem = $3;
1372: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1373: $othercourse = 1;
1374: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1375: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1376: } else {
1377: $canpaste = 0;
1378: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1379: }
1380: }
1.484.2.30 raeburn 1381: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1382: my $prefix = $1;
1383: $parent = $2;
1384: if ($folder !~ /^\Q$prefix\E/) {
1385: $areachange = 1;
1386: }
1387: $is_uploaded_map = 1;
1388: }
1.484.2.82 raeburn 1389: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.484.2.85.2. (raeburn 1390:): ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.484.2.76 raeburn 1391: if ($cid ne $env{'request.course.id'}) {
1392: my ($srcdom,$srcnum) = split(/_/,$cid);
1393: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.85.2. (raeburn 1394:): if (($is_exttool) && ($srcdom ne $coursedom)) {
1395:): $canpaste = 0;
1396:): $nopaste = &mt('Paste from another domain unavailable.');
1397:): } else {
1398:): $othercrs = '<br />'.&mt('(from another course)');
1399:): }
1.484.2.76 raeburn 1400: } else {
1401: $canpaste = 0;
1402: $nopaste = &mt('Paste from another course unavailable.');
1403: }
1404: }
1405: }
1406: if ($canpaste) {
1407: push(@pasteable,$suffix);
1.484.2.30 raeburn 1408: }
1409: }
1410: my $buffer;
1411: if ($is_external) {
1412: $buffer = &mt('External Resource').': '.
1413: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1414: &LONCAPA::map::qtescape($url).')';
1.484.2.85.2. (raeburn 1415:): } elsif ($is_exttool) {
1416:): $buffer = &mt('External Tool').': '.
1417:): &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.30 raeburn 1418: } else {
1419: my $icon = &Apache::loncommon::icon($extension);
1420: if ($extension eq 'sequence' &&
1421: $url =~ m{/default_\d+\.sequence$}x) {
1422: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1423: $icon .= '/navmap.folder.closed.gif';
1424: }
1.484.2.57 raeburn 1425: my $title = $env{'docs.markedcopy_title_'.$suffix};
1426: if ($title eq '') {
1427: ($title) = ($url =~ m{/([^/]+)$});
1428: }
1.484.2.30 raeburn 1429: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1430: ': '.
1431: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1432: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1433: }
1434: $pasteitems .= '<div class="LC_left_float">';
1435: my ($options,$onclick);
1436: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1437: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1438: if (($is_uploaded_map) ||
1439: ($url =~ /(bulletinboard|smppg)$/) ||
1440: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1441: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1442: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1443: }
1444: }
1445: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1446: if ($nopaste) {
1447: $pasteitems .= $nopaste;
1448: } else {
1449: if ($othercrs) {
1450: $pasteitems .= $othercrs;
1451: }
1452: if ($options) {
1453: $pasteitems .= $options;
1.484.2.7 raeburn 1454: }
1455: }
1.484.2.30 raeburn 1456: $pasteitems .= '</div>';
1457: }
1458: }
1459: if ($pasteitems eq '') {
1460: &Apache::lonnet::delenv('docs.markedcopies');
1461: }
1462: my ($pasteform,$form_start,$buttons,$form_end);
1463: if ($pasteitems) {
1464: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1465: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1466: if (@pasteable) {
1.484.2.47 raeburn 1467: my $value = &mt('Paste to current folder');
1468: if ($container eq 'page') {
1469: $value = &mt('Paste to current page');
1470: }
1471: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1472: }
1.484.2.85.2. (raeburn 1473:): $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1.484.2.47 raeburn 1474: if ($clipboardcount > 1) {
1475: $buttons .=
1476: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1477: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1478: (' 'x2).
1479: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1480: (' 'x2);
1.484.2.7 raeburn 1481: }
1.484.2.48 raeburn 1482: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1483: '</form>';
1.484.2.30 raeburn 1484: } else {
1485: $pasteitems = &mt('Clipboard is empty');
1486: }
1487: $r->print($form_start
1488: .'<fieldset>'
1489: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1490: .$pasteitems
1491: .'</fieldset>'
1492: .$form_end);
1493: }
1494:
1495: sub paste_options {
1496: my ($suffix,$is_uploaded_map,$parent) = @_;
1497: my ($copytext,$movetext);
1498: if ($is_uploaded_map) {
1499: $copytext = &mt('Copy to new folder');
1500: $movetext = &mt('Move old');
1501: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1502: $copytext = &mt('Copy to new board');
1503: $movetext = &mt('Move (not posts)');
1504: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1505: $copytext = &mt('Copy to new page');
1506: $movetext = &mt('Move');
1.484.2.7 raeburn 1507: } else {
1.484.2.30 raeburn 1508: $copytext = &mt('Copy to new file');
1509: $movetext = &mt('Move');
1510: }
1511: my $output = '<br />'.
1512: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1513: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1514: '<label>'.
1515: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1516: $copytext.'</label></span>'.(' 'x2).' '.
1517: '<span class="LC_nobreak"><label>'.
1518: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1519: $movetext.'</label></span>';
1520: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1521: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1522: '</legend><table border="0">';
1523: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1524: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1525: my $lastdir = $parent;
1526: my %depths = (
1527: $lastdir => 0,
1528: );
1529: my (%display,%deps);
1530: for (my $i=0; $i<@pastemaps; $i++) {
1531: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1532: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1533: my @subfolders = split(/,/,$subfolderstr);
1534: $deps{$lastdir} = \@subfolders;
1535: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1536: my $depth = $depths{$lastdir} + 1;
1537: my $offset = int($depth * 4);
1538: my $indent = (' ' x $offset);
1539: for (my $j=0; $j<@subfolders; $j++) {
1540: $depths{$subfolders[$j]} = $depth;
1541: $display{$subfolders[$j]} =
1542: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1543: '<td><label>'.
1544: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1545: '<label>'.
1546: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1547: &mt('Move old').'</label>'.
1548: '</td></tr>';
1549: }
1550: }
1551: &recurse_print(\$output,$parent,\%deps,\%display);
1552: $output .= '</table></fieldset>';
1.329 droeschl 1553: }
1.484.2.30 raeburn 1554: $output .= '</div>';
1555: return $output;
1.329 droeschl 1556: }
1557:
1.484.2.7 raeburn 1558: sub recurse_print {
1.484.2.30 raeburn 1559: my ($outputref,$dir,$deps,$display) = @_;
1560: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1561: if (ref($deps->{$dir}) eq 'ARRAY') {
1562: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1563: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1564: }
1565: }
1566: }
1567:
1568: sub supp_pasteable {
1569: my ($url) = @_;
1570: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1571: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1572: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1573: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.484.2.85.2. (raeburn 1574:): ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1575:): ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.484.2.7 raeburn 1576: return 1;
1577: }
1578: return;
1579: }
1580:
1581: sub paste_popup_js {
1.484.2.61 raeburn 1582: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1583: show => 'Show Options',
1584: hide => 'Hide Options',
1.484.2.61 raeburn 1585: );
1586: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1587: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1588: );
1.484.2.61 raeburn 1589: &html_escape(\%html_js_lt);
1590: &js_escape(\%html_js_lt);
1591: &js_escape(\%js_lt);
1.484.2.7 raeburn 1592: return <<"END";
1593:
1.484.2.30 raeburn 1594: function showPasteOptions(suffix) {
1595: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1596: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1597: return;
1598: }
1599:
1.484.2.30 raeburn 1600: function hidePasteOptions(suffix) {
1601: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1602: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1603: return;
1604: }
1605:
1.484.2.30 raeburn 1606: function showOptions(caller,suffix) {
1607: if (document.getElementById('pasteoptionstext_'+suffix)) {
1608: if (caller.checked) {
1.484.2.61 raeburn 1609: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1610: } else {
1611: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1612: }
1613: if (document.getElementById('pasteoptions_'+suffix)) {
1614: document.getElementById('pasteoptions_'+suffix).style.display='none';
1615: }
1616: }
1617: return;
1618: }
1.484.2.7 raeburn 1619:
1.484.2.30 raeburn 1620: function validateClipboard() {
1621: var numchk = 0;
1622: if (document.pasteform.pasting.length > 1) {
1623: for (var i=0; i<document.pasteform.pasting.length; i++) {
1624: if (document.pasteform.pasting[i].checked) {
1625: numchk ++;
1626: }
1627: }
1628: } else {
1629: if (document.pasteform.pasting.type == 'checkbox') {
1630: if (document.pasteform.pasting.checked) {
1631: numchk ++;
1632: }
1633: }
1634: }
1635: if (numchk > 0) {
1636: return true;
1637: } else {
1.484.2.61 raeburn 1638: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1639: return false;
1640: }
1.484.2.7 raeburn 1641: }
1642:
1.484.2.47 raeburn 1643: function checkClipboard() {
1644: if (document.pasteform.pasting.length > 1) {
1645: for (var i=0; i<document.pasteform.pasting.length; i++) {
1646: document.pasteform.pasting[i].checked = true;
1647: }
1648: }
1649: return;
1650: }
1651:
1652: function uncheckClipboard() {
1653: if (document.pasteform.pasting.length >1) {
1654: for (var i=0; i<document.pasteform.pasting.length; i++) {
1655: document.pasteform.pasting[i].checked = false;
1656: }
1657: }
1658: return;
1659: }
1660:
1.484.2.30 raeburn 1661: END
1662:
1663: }
1.484.2.7 raeburn 1664:
1.329 droeschl 1665: sub do_paste_from_buffer {
1.484.2.7 raeburn 1666: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1667:
1.484.2.30 raeburn 1668: # Array of items in paste buffer
1669: my (@currpaste,%pastebuffer,%allerrors);
1670: @currpaste = split(/,/,$env{'docs.markedcopies'});
1671:
1.484.2.7 raeburn 1672: # Early out if paste buffer is empty
1.484.2.30 raeburn 1673: if (@currpaste == 0) {
1.484.2.7 raeburn 1674: return ();
1.484.2.30 raeburn 1675: }
1676: map { $pastebuffer{$_} = 1; } @currpaste;
1677:
1678: # Array of items selected items to paste
1679: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1680:
1681: # Early out if nothing selected to paste
1682: if (@reqpaste == 0) {
1683: return();
1684: }
1685: my @topaste;
1686: foreach my $suffix (@reqpaste) {
1687: next if ($suffix =~ /\D/);
1688: next unless (exists($pastebuffer{$suffix}));
1689: push(@topaste,$suffix);
1.484.2.7 raeburn 1690: }
1691:
1.484.2.30 raeburn 1692: # Early out if nothing available to paste
1693: if (@topaste == 0) {
1694: return();
1.329 droeschl 1695: }
1696:
1.484.2.85.2. (raeburn 1697:): my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.484.2.82 raeburn 1698: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1699:
1.484.2.30 raeburn 1700: foreach my $suffix (@topaste) {
1701: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1702: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1703: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1704: # Supplemental content may only include certain types of content
1705: # Early out if pasted content is not supported in Supplemental area
1706: if ($folder =~ /^supplemental/) {
1707: unless (&supp_pasteable($url)) {
1708: $notinsupp{$suffix} = 1;
1709: next;
1710: }
1711: }
1712: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1713: my $srcd = $1;
1714: my $srcn = $2;
1.484.2.7 raeburn 1715: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1716: # check for mdc privilege in the course from which the resource was pasted
1717: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1718: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1719: $notincrs{$suffix} = 1;
1720: next;
1721: }
1.329 droeschl 1722: }
1.484.2.30 raeburn 1723: $srcdom{$suffix} = $srcd;
1724: $srcnum{$suffix} = $srcn;
1.484.2.85.2. (raeburn 1725:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1726:): my ($srcd,$srcn) = split(/_/,$cid);
1727:): # When paste buffer was populated using an active role in a different course
1728:): # check for mdc privilege in the course from which the resource was pasted
1729:): if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1730:): unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1731:): $notincrs{$suffix} = 1;
1732:): next;
1733:): }
1734:): }
1735:): # When buffer was populated using an active role in a different course
1736:): # disallow pasting of External Tool if course is in a different domain.
1737:): if ($srcd ne $coursedom) {
1738:): $notindom{$suffix} = 1;
1739:): next;
1740:): }
1741:): $srcdom{$suffix} = $srcd;
1742:): $srcnum{$suffix} = $srcn;
1.484.2.82 raeburn 1743: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1744: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1745: my ($srcd,$srcn) = split(/_/,$cid);
1746: # When paste buffer was populated using an active role in a different course
1747: # check for mdc privilege in the course from which the resource was pasted
1748: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1749: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1750: $notincrs{$suffix} = 1;
1751: next;
1752: }
1753: }
1754: $srcdom{$suffix} = $srcd;
1755: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1756: }
1.484.2.82 raeburn 1757: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1758: push(@dopaste,$suffix);
1759: if ($url=~/\.(page|sequence)$/) {
1760: $is_map{$suffix} = 1;
1.329 droeschl 1761: }
1.484.2.30 raeburn 1762:
1763: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1764: my $oldprefix = $1;
1.484.2.19 raeburn 1765: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1766: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1767: # a folder/page or a document).
1.484.2.30 raeburn 1768: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1769: $prefixchg{$suffix} = 'docstosupp';
1770: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1771: $prefixchg{$suffix} = 'supptodocs';
1772: }
1.484.2.7 raeburn 1773:
1774: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1775: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1776: my @nested;
1777: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1778: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1779: my @deps = map { /\d+:([\d,]+$)/ } @items;
1780: foreach my $dep (@deps) {
1781: if ($dep =~ /,/) {
1782: push(@nested,split(/,/,$dep));
1783: } else {
1784: push(@nested,$dep);
1785: }
1.484.2.7 raeburn 1786: }
1.484.2.30 raeburn 1787: foreach my $item (@nested) {
1788: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1789: push(@{$marktomove{$suffix}},$type.'_'.$item);
1790: }
1.484.2.7 raeburn 1791: }
1792: }
1.329 droeschl 1793: }
1.484.2.7 raeburn 1794: }
1795:
1.484.2.30 raeburn 1796: # Early out if nothing available to paste
1797: if (@dopaste == 0) {
1798: return ();
1799: }
1800:
1801: # Populate message hash and hashes used for main content <=> supplemental content
1802: # changes
1803:
1804: %msgs = &Apache::lonlocal::texthash (
1805: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1806: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.484.2.85.2. (raeburn 1807:): notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.484.2.30 raeburn 1808: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1809: );
1810:
1811: %before = (
1812: docstosupp => {
1813: map => 'default',
1814: doc => 'docs',
1815: },
1816: supptodocs => {
1817: map => 'supplemental',
1818: doc => 'supplemental',
1819: },
1820: );
1821:
1822: %after = (
1823: docstosupp => {
1824: map => 'supplemental',
1825: doc => 'supplemental'
1826: },
1827: supptodocs => {
1828: map => 'default',
1829: doc => 'docs',
1830: },
1831: );
1832:
1833: # Retrieve information about all course maps in main content area
1834:
1835: my $allmaps = {};
1.484.2.79 raeburn 1836: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1837:
1838: # Loop over the items to paste
1839: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1840: # Maps need to be copied first
1.484.2.30 raeburn 1841: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1842: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1843: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1844: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1845: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1846: }
1847: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1848: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1849: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1850: my $oldurl = $url;
1851: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1852: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1853: my (%hierarchy,%titles);
1.484.2.79 raeburn 1854: if (($folder =~ /^default/) && (!$donechk)) {
1855: $allmaps =
1856: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1857: $env{"course.$env{'request.course.id'}.home"},
1858: $env{'request.course.id'});
1859: $donechk = 1;
1860: }
1.484.2.85.2. (raeburn 1861:): &contained_map_check($url,$folder,$coursenum,$coursedom,
1862:): \%removefrommap,\%removeparam,\%addedmaps,
1863:): \%hierarchy,\%titles,$allmaps);
1.484.2.30 raeburn 1864: if ($url=~ m{^/uploaded/}) {
1865: my $newurl;
1866: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1867: ($newurl,my $error) =
1868: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1869: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1870: \$title,$allmaps,\%newurls);
1871: if ($error) {
1872: $allerrors{$suffix} = $error;
1873: next;
1874: }
1875: if ($newurl ne '') {
1876: if ($newurl ne $url) {
1877: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1878: $newsubdir{$url} = $1;
1879: }
1880: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1881: }
1882: }
1883: }
1.484.2.30 raeburn 1884: if (($srcdom{$suffix} ne $coursedom) ||
1885: ($srcnum{$suffix} ne $coursenum) ||
1886: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1887: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1888: $coursedom,$coursenum,$srcdom{$suffix},
1889: $srcnum{$suffix},$allmaps,\%rewrites,
1890: \%retitles,\%copies,\%dbcopies,
1891: \%zombies,\%params,\%mapmoves,
1892: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 1893: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 1894: $mapmoves{$url} = 1;
1895: }
1896: $url = $newurl;
1897: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1898: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1899: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1900: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1901: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 1902: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 1903: }
1904: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 1905: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1906: push(@toclear,$suffix);
1907: # if pasting published map (main content area only) check map not already in course
1908: if ($folder =~ /^default/) {
1909: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1910: $duplicate{$suffix} = 1;
1911: next;
1912: }
1.484.2.7 raeburn 1913: }
1914: }
1915: }
1.484.2.85.2. (raeburn 1916:): if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.484.2.30 raeburn 1917: my $prefix = $1;
1.484.2.76 raeburn 1918: my $fromothercrs;
1.484.2.30 raeburn 1919: #need to copy the db contents to a new one, unless this is a move.
1920: my %info = (
1921: src => $url,
1922: cdom => $coursedom,
1923: cnum => $coursenum,
1.484.2.76 raeburn 1924: );
1925: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1926: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1927: $fromothercrs = 1;
1928: $info{'cdom'} = $srcdom{$suffix};
1929: $info{'cnum'} = $srcnum{$suffix};
1930: }
1931: }
1932: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1933: my (%lockerr,$msg);
1934: my ($newurl,$result,$errtext) =
1935: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1936: if ($result eq 'ok') {
1937: $url = $newurl;
1938: $title=&mt('Copy of').' '.$title;
1939: } else {
1940: if ($prefix eq 'smppg') {
1941: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1942: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1943: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.85.2. (raeburn 1944:): } elsif ($prefix eq 'ext.tool') {
1945:): $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.484.2.30 raeburn 1946: }
1947: $results{$suffix} = $result;
1948: $msgerrs{$suffix} = $msg;
1949: $lockerrs{$suffix} = $lockerr{$prefix};
1950: next;
1951: }
1952: if ($lockerr{$prefix}) {
1953: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1954: }
1.484.2.7 raeburn 1955: }
1.484.2.30 raeburn 1956: }
1957: $title = &LONCAPA::map::qtunescape($title);
1958: my $ext='false';
1959: if ($url=~m{^http(|s)://}) { $ext='true'; }
1960: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1961: if ($folder !~ /^supplemental/) {
1962: (undef,undef,$title) =
1963: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1964: }
1965: } else {
1966: if ($folder=~/^supplemental/) {
1967: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1968: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1969: }
1970: }
1.484.2.7 raeburn 1971:
1972: # For uploaded files (excluding pages/sequences) path in copied file is changed
1973: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1974: # courses.
1975:
1.484.2.30 raeburn 1976: unless ($is_map{$suffix}) {
1977: my $newidx;
1.329 droeschl 1978: # Now insert the URL at the bottom
1.484.2.30 raeburn 1979: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1980: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1981: my $relpath = $1;
1982: if ($relpath ne '') {
1983: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1984: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1985: my $newprefix = $newloc;
1986: if ($newloc eq 'default') {
1987: $newprefix = 'docs';
1988: }
1989: if ($newdocsdir eq '') {
1990: $newdocsdir = 'default';
1991: }
1992: if (($prefixchg{$suffix}) ||
1993: ($srcdom{$suffix} ne $coursedom) ||
1994: ($srcnum{$suffix} ne $coursenum) ||
1995: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1996: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1997: $url =
1998: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1999: &Apache::lonnet::getfile($oldurl));
2000: if ($url eq '/adm/notfound.html') {
2001: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2002: next;
2003: } else {
2004: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2005: $newsubpath =~ s{/+$}{/};
2006: $docmoves{$oldurl} = $newsubpath;
2007: }
1.484.2.7 raeburn 2008: }
2009: }
1.484.2.82 raeburn 2010: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2011: my $template = $1;
2012: if ($newidx) {
2013: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2014: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2015: }
1.484.2.7 raeburn 2016: }
1.484.2.30 raeburn 2017: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2018: ':'.$ext.':normal:res';
2019: push(@LONCAPA::map::order,$newidx);
2020: # Store the result
2021: my ($errtext,$fatal) =
2022: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2023: if ($fatal) {
2024: $save_err .= $errtext;
2025: $allresult = 'fail';
1.484.2.7 raeburn 2026: }
1.329 droeschl 2027: }
1.484.2.30 raeburn 2028:
1.484.2.82 raeburn 2029: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2030: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 2031: unless ($allresult eq 'fail') {
2032: my %updated = (
2033: rewrites => \%rewrites,
2034: zombies => \%zombies,
2035: removefrommap => \%removefrommap,
2036: removeparam => \%removeparam,
2037: dbcopies => \%dbcopies,
1.484.2.82 raeburn 2038: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 2039: retitles => \%retitles,
2040: );
2041: my %info = (
2042: newsubdir => \%newsubdir,
2043: params => \%params,
2044: );
2045: if ($prefixchg{$suffix}) {
2046: $info{'before'} = $before{$prefixchg{$suffix}};
2047: $info{'after'} = $after{$prefixchg{$suffix}};
2048: }
2049: my %moves = (
2050: copies => \%copies,
2051: docmoves => \%docmoves,
2052: mapmoves => \%mapmoves,
2053: );
2054: (my $result,$msgs{$suffix},my $lockerror) =
2055: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2056: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2057: $url,'paste');
2058: $lockerrors .= $lockerror;
2059: if ($result eq 'ok') {
2060: if ($is_map{$suffix}) {
2061: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2062: $folder.'.'.$container);
2063: if ($fatal) {
2064: $allresult = 'failread';
2065: } else {
2066: if ($#LONCAPA::map::order<1) {
2067: my $idx=&LONCAPA::map::getresidx();
2068: if ($idx<=0) { $idx=1; }
2069: $LONCAPA::map::order[0]=$idx;
2070: $LONCAPA::map::resources[$idx]='';
2071: }
2072: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2073: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2074: ':'.$ext.':normal:res';
2075: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 2076:
2077: # Store the result
1.484.2.30 raeburn 2078: my ($errtext,$fatal) =
2079: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2080: if ($fatal) {
2081: $save_err .= $errtext;
2082: $allresult = 'failstore';
2083: }
2084: }
2085: }
2086: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2087: push(@toclear,$suffix);
2088: }
2089: }
1.329 droeschl 2090: }
2091: }
1.484.2.30 raeburn 2092: &clear_from_buffer(\@toclear,\@currpaste);
2093: my $msgsarray;
2094: foreach my $suffix (keys(%msgs)) {
2095: if (ref($msgs{$suffix}) eq 'ARRAY') {
2096: $msgsarray .= join(',',@{$msgs{$suffix}});
2097: }
2098: }
2099: return ($allresult,$save_err,$msgsarray,$lockerrors);
2100: }
2101:
2102: sub do_buffer_empty {
2103: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2104: if (@currpaste == 0) {
2105: return &mt('Clipboard is already empty');
2106: }
2107: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2108: if (@toclear == 0) {
2109: return &mt('Nothing selected to clear from clipboard');
2110: }
2111: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2112: if ($numdel) {
2113: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2114: } else {
2115: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 2116: }
1.484.2.30 raeburn 2117: return;
2118: }
2119:
2120: sub clear_from_buffer {
2121: my ($toclear,$currpaste) = @_;
2122: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2123: my %pastebuffer;
2124: map { $pastebuffer{$_} = 1; } @{$currpaste};
2125: my $numdel = 0;
2126: foreach my $suffix (@{$toclear}) {
2127: next if ($suffix =~ /\D/);
2128: next unless (exists($pastebuffer{$suffix}));
2129: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2130: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2131: delete($pastebuffer{$suffix});
2132: $numdel ++;
2133: }
2134: }
2135: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2136: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2137: return $numdel;
1.484.2.7 raeburn 2138: }
2139:
2140: sub get_newmap_url {
2141: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2142: $titleref,$allmaps,$newurls) = @_;
2143: my $newurl;
2144: if ($url=~ m{^/uploaded/}) {
2145: $$titleref=&mt('Copy of').' '.$$titleref;
2146: }
2147: my $now = time;
2148: my $suffix=$$.int(rand(100)).$now;
2149: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2150: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2151: my $path = $1;
2152: my $prefix = $2;
2153: my $ancestor = $3;
2154: if (length($ancestor) > 10) {
2155: $ancestor = substr($ancestor,-10,10);
2156: }
2157: my $newid;
2158: if ($prefixchg) {
2159: if ($folder =~ /^supplemental/) {
2160: $prefix =~ s/^default/supplemental/;
2161: } else {
2162: $prefix =~ s/^supplemental/default/;
2163: }
2164: }
2165: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2166: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2167: } else {
2168: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2169: }
2170: my $counter = 0;
2171: my $is_unique = &uniqueness_check($newurl);
2172: if ($folder =~ /^default/) {
2173: if ($allmaps->{$newurl}) {
2174: $is_unique = 0;
2175: }
2176: }
2177: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2178: $counter ++;
2179: $suffix ++;
2180: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2181: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2182: } else {
2183: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2184: }
2185: $is_unique = &uniqueness_check($newurl);
2186: }
2187: if ($is_unique) {
2188: $newurls->{$newurl} = 1;
2189: } else {
2190: if ($url=~/\.page$/) {
2191: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2192: } else {
2193: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2194: }
2195: }
2196: }
2197: return ($newurl);
2198: }
2199:
2200: sub dbcopy {
1.484.2.26 raeburn 2201: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2202: my ($url,$result,$errtext);
2203: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2204: $url = $dbref->{'src'};
1.484.2.85.2. (raeburn 2205:): if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.484.2.26 raeburn 2206: my $prefix = $1;
1.484.2.85.2. (raeburn 2207:): if ($prefix eq 'ext.tool') {
2208:): $prefix = 'exttool';
2209:): }
1.484.2.26 raeburn 2210: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2211: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2212: my $db_name;
2213: my $marker = (split(m{/},$url))[4];
2214: $marker=~s/\D//g;
2215: if ($dbref->{'src'} =~ m{/smppg$}) {
2216: $db_name =
2217: &Apache::lonsimplepage::get_db_name($url,$marker,
2218: $dbref->{'cdom'},
2219: $dbref->{'cnum'});
1.484.2.85.2. (raeburn 2220:): } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2221:): $db_name = 'exttool_'.$marker;
1.484.2.26 raeburn 2222: } else {
2223: $db_name = 'bulletinpage_'.$marker;
2224: }
2225: my ($suffix,$freedlock,$error) =
2226: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2227: $coursedom,$coursenum,
2228: 'concat');
2229: if (!$suffix) {
2230: if ($prefix eq 'smppg') {
2231: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.484.2.85.2. (raeburn 2232:): } elsif ($prefix eq 'exttool') {
2233:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.484.2.26 raeburn 2234: } else {
1.484.2.42 raeburn 2235: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2236: }
2237: if ($error) {
2238: $errtext .= '<br />'.$error;
2239: }
2240: } else {
2241: #need to copy the db contents to a new one.
2242: my %contents=&Apache::lonnet::dump($db_name,
2243: $dbref->{'cdom'},
2244: $dbref->{'cnum'});
2245: if (exists($contents{'uploaded.photourl'})) {
2246: my $photo = $contents{'uploaded.photourl'};
2247: my ($subdir,$fname) =
2248: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2249: my $newphoto;
2250: if ($fname ne '') {
2251: my $content = &Apache::lonnet::getfile($photo);
2252: unless ($content eq '-1') {
2253: $env{'form.'.$suffix.'.photourl'} = $content;
2254: $newphoto =
2255: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2256: delete($env{'form.'.$suffix.'.photourl'});
2257: }
2258: }
2259: if ($newphoto =~ m{^/uploaded/}) {
2260: $contents{'uploaded.photourl'} = $newphoto;
2261: }
2262: }
2263: $db_name =~ s{_\d*$ }{_$suffix}x;
2264: $result=&Apache::lonnet::put($db_name,\%contents,
2265: $coursedom,$coursenum);
2266: if ($result eq 'ok') {
1.484.2.85.2. (raeburn 2267:): $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.484.2.26 raeburn 2268: }
2269: }
2270: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2271: $lockerrorsref->{$prefix} =
2272: '<div class="LC_error">'.
2273: &mt('There was a problem removing a lockfile.');
2274: if ($prefix eq 'smppg') {
2275: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2276: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.85.2. (raeburn 2277:): } elsif ($prefix eq 'exttool') {
2278:): $lockerrorsref->{$prefix} .=
2279:): ' '.&mt('This will prevent addition of more external tools to this course.');
1.484.2.26 raeburn 2280: } else {
1.484.2.42 raeburn 2281: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2282: }
1.484.2.38 raeburn 2283: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2284: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2285: '</div>';
1.484.2.26 raeburn 2286: }
2287: }
2288: } elsif ($url =~ m{/syllabus$}) {
2289: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2290: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2291: if (($dbref->{'cdom'} ne $coursedom) ||
2292: ($dbref->{'cnum'} ne $coursenum)) {
2293: my %contents=&Apache::lonnet::dump('syllabus',
2294: $dbref->{'cdom'},
2295: $dbref->{'cnum'});
2296: $result=&Apache::lonnet::put('syllabus',\%contents,
2297: $coursedom,$coursenum);
2298: }
2299: }
1.484.2.7 raeburn 2300: }
2301: }
1.484.2.26 raeburn 2302: return ($url,$result,$errtext);
1.329 droeschl 2303: }
2304:
1.484.2.82 raeburn 2305: sub copy_templated_files {
2306: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2307: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2308: my $srccontainer = 'sequence';
2309: if ($srcwaspage) {
2310: $srccontainer = 'page';
2311: }
2312: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2313: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2314: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2315: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2316: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2317: $template.'.problem';
2318: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2319: if ($template eq 'simpleproblem') {
2320: $srcprefix .= '.0.';
2321: my $weightprefix = $newprefix;
2322: $newprefix .= '.0.';
2323: my @simpleprobqtypes = qw(radio option string essay numerical);
2324: my $qtype=$srcparms{$srcprefix.'questiontype'};
2325: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2326: my %newdata = (
2327: $newprefix.'questiontype' => $qtype,
1.484.2.84 raeburn 2328: );
1.484.2.82 raeburn 2329: foreach my $type (@simpleprobqtypes) {
2330: if ($type eq $qtype) {
2331: $newdata{"$weightprefix.$type.weight"}=1;
2332: } else {
2333: $newdata{"$weightprefix.$type.weight"}=0;
2334: }
2335: }
2336: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2337: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2338: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2339: if ($qtype eq 'numerical') {
2340: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2341: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2342: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2343: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2344: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2345: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2346: unless (defined($maxfoils)) { $maxfoils=10; }
2347: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2348: if ($maxfoils<=0) { $maxfoils=10; }
2349: my $randomize=$srcparms{$srcprefix.'randomize'};
2350: unless (defined($randomize)) { $randomize='yes'; }
2351: unless ($randomize eq 'no') { $randomize='yes'; }
2352: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2353: $newdata{$newprefix.'randomize'} = $randomize;
2354: if ($qtype eq 'option') {
2355: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2356: }
2357: for (my $i=1; $i<=10; $i++) {
2358: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2359: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2360: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2361: }
2362:
2363: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2364: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2365: unless (defined($maxfoils)) { $maxfoils=10; }
2366: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2367: if ($maxfoils<=0) { $maxfoils=10; }
2368: my $randomize=$srcparms{$srcprefix.'randomize'};
2369: unless (defined($randomize)) { $randomize='yes'; }
2370: unless ($randomize eq 'no') { $randomize='yes'; }
2371: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2372: $newdata{$newprefix.'randomize'} = $randomize;
2373: if ($qtype eq 'option') {
2374: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2375: }
2376: for (my $i=1; $i<=10; $i++) {
2377: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2378: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2379: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2380: }
2381: } elsif ($qtype eq 'string') {
2382: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2383: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2384: }
2385: if (keys(%newdata)) {
2386: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2387: $coursenum);
2388: if ($putres eq 'ok') {
2389: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2390: }
2391: }
2392: }
2393: }
2394: }
2395:
1.329 droeschl 2396: sub uniqueness_check {
2397: my ($newurl) = @_;
2398: my $unique = 1;
2399: foreach my $res (@LONCAPA::map::order) {
2400: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2401: $url=&LONCAPA::map::qtescape($url);
2402: if ($newurl eq $url) {
2403: $unique = 0;
1.344 bisitz 2404: last;
1.329 droeschl 2405: }
2406: }
2407: return $unique;
2408: }
2409:
1.484.2.7 raeburn 2410: sub contained_map_check {
1.484.2.85.2. (raeburn 2411:): my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2412:): $hierarchy,$titles,$allmaps) = @_;
1.484.2.7 raeburn 2413: my $content = &Apache::lonnet::getfile($url);
2414: unless ($content eq '-1') {
2415: my $parser = HTML::TokeParser->new(\$content);
2416: $parser->attr_encoded(1);
2417: while (my $token = $parser->get_token) {
2418: next if ($token->[0] ne 'S');
2419: if ($token->[1] eq 'resource') {
2420: next if ($token->[2]->{'type'} eq 'zombie');
2421: my $ressrc = $token->[2]->{'src'};
2422: if ($folder =~ /^supplemental/) {
2423: unless (&supp_pasteable($ressrc)) {
2424: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2425: next;
2426: }
2427: }
2428: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2429: if ($1 eq 'uploaded') {
2430: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2431: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2432: } else {
2433: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2434: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2435: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2436: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2437: } else {
2438: $addedmaps->{$ressrc} = [$url];
2439: }
2440: }
1.484.2.85.2. (raeburn 2441:): &contained_map_check($ressrc,$folder,$coursenum,$coursedom,
2442:): $removefrommap,$removeparam,
1.484.2.7 raeburn 2443: $addedmaps,$hierarchy,$titles,$allmaps);
2444: }
2445: } elsif ($token->[1] eq 'param') {
2446: if ($folder =~ /^supplemental/) {
2447: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2448: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2449: } else {
1.484.2.19 raeburn 2450: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2451: }
2452: }
2453: }
2454: }
2455: }
2456: return;
2457: }
2458:
2459: sub url_paste_fixups {
1.484.2.26 raeburn 2460: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2461: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2462: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2463: my $checktitle;
2464: if (($prefixchg) &&
2465: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2466: $checktitle = 1;
2467: }
2468: my $skip;
2469: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2470: my $mapid = $1.$2;
2471: if ($tomove->{$mapid}) {
2472: $skip = 1;
2473: }
2474: }
2475: my $file = &Apache::lonnet::getfile($oldurl);
2476: return if ($file eq '-1');
2477: my $parser = HTML::TokeParser->new(\$file);
2478: $parser->attr_encoded(1);
2479: my $changed = 0;
2480: while (my $token = $parser->get_token) {
2481: next if ($token->[0] ne 'S');
2482: if ($token->[1] eq 'resource') {
2483: my $ressrc = $token->[2]->{'src'};
2484: next if ($ressrc eq '');
2485: my $id = $token->[2]->{'id'};
2486: my $title = $token->[2]->{'title'};
2487: if ($checktitle) {
2488: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2489: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2490: }
2491: }
2492: next if ($token->[2]->{'type'} eq 'external');
2493: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2494: next if ($skip);
1.484.2.25 raeburn 2495: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2496: $changed = 1;
2497: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2498: my $srcdom = $1;
2499: my $srcnum = $2;
2500: my $rem = $3;
2501: my $newurl;
2502: my $mapname;
2503: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2504: my $prefix = $1;
2505: $mapname = $prefix.$2;
2506: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2507: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2508: $srcdom,$srcnum,$allmaps,$rewrites,
2509: $retitles,$copies,$dbcopies,$zombies,
2510: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2511: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2512: next;
2513: } else {
2514: ($newurl,my $error) =
2515: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2516: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2517: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2518: $newsubdir->{$ressrc} = $1;
2519: }
2520: if ($error) {
2521: next;
2522: }
2523: }
2524: }
2525: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2526: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2527:
1.484.2.7 raeburn 2528: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2529: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2530: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2531: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2532: $cnum,$srcdom,$srcnum,$allmaps,
2533: $rewrites,$retitles,$copies,$dbcopies,
2534: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2535: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2536: $mapmoves->{$ressrc} = 1;
2537: }
2538: $changed = 1;
2539: } else {
1.484.2.25 raeburn 2540: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2541: $copies->{$oldurl}{$ressrc} = $id;
2542: $changed = 1;
2543: }
2544: }
1.484.2.26 raeburn 2545: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2546: next if ($skip);
1.484.2.7 raeburn 2547: my $srcdom = $1;
2548: my $srcnum = $2;
2549: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2550: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2551: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2552: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2553: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2554: $changed = 1;
2555: }
2556: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2557: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2558: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2559: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2560: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2561: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2562: $changed = 1;
2563: }
1.484.2.82 raeburn 2564: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2565: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2566: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2567: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2568: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2569: }
1.484.2.7 raeburn 2570: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2571: next if ($skip);
2572: my $srcdom = $1;
2573: my $srcnum = $2;
2574: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2575: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2576: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2577: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2578: $changed = 1;
2579: }
2580: }
2581: } elsif ($token->[1] eq 'param') {
2582: next if ($skip);
1.484.2.19 raeburn 2583: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2584: if ($to ne '') {
2585: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2586: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2587: } else {
2588: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2589: }
2590: }
2591: }
2592: }
2593: return $changed;
2594: }
2595:
2596: sub apply_fixups {
1.484.2.23 raeburn 2597: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2598: $oldurl,$url,$caller) = @_;
2599: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2600: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.82 raeburn 2601: %resdatacopy,%lockerrors,$lockmsg);
1.484.2.23 raeburn 2602: if (ref($updated) eq 'HASH') {
2603: if (ref($updated->{'rewrites'}) eq 'HASH') {
2604: %rewrites = %{$updated->{'rewrites'}};
2605: }
2606: if (ref($updated->{'zombies'}) eq 'HASH') {
2607: %zombies = %{$updated->{'zombies'}};
2608: }
2609: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2610: %removefrommap = %{$updated->{'removefrommap'}};
2611: }
2612: if (ref($updated->{'removeparam'}) eq 'HASH') {
2613: %removeparam = %{$updated->{'removeparam'}};
2614: }
2615: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2616: %dbcopies = %{$updated->{'dbcopies'}};
2617: }
2618: if (ref($updated->{'retitles'}) eq 'HASH') {
2619: %retitles = %{$updated->{'retitles'}};
2620: }
1.484.2.82 raeburn 2621: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2622: %resdatacopy = %{$updated->{'resdatacopy'}};
2623: }
1.484.2.23 raeburn 2624: }
2625: if (ref($info) eq 'HASH') {
2626: if (ref($info->{'newsubdir'}) eq 'HASH') {
2627: %newsubdir = %{$info->{'newsubdir'}};
2628: }
2629: if (ref($info->{'params'}) eq 'HASH') {
2630: %params = %{$info->{'params'}};
2631: }
2632: if (ref($info->{'before'}) eq 'HASH') {
2633: %before = %{$info->{'before'}};
2634: }
2635: if (ref($info->{'after'}) eq 'HASH') {
2636: %after = %{$info->{'after'}};
2637: }
2638: }
2639: if (ref($moves) eq 'HASH') {
2640: if (ref($moves->{'copies'}) eq 'HASH') {
2641: %copies = %{$moves->{'copies'}};
2642: }
2643: if (ref($moves->{'docmoves'}) eq 'HASH') {
2644: %docmoves = %{$moves->{'docmoves'}};
2645: }
2646: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2647: %mapmoves = %{$moves->{'mapmoves'}};
2648: }
2649: }
2650: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2651: my @allcopies;
1.484.2.23 raeburn 2652: if (exists($copies{$key})) {
2653: if (ref($copies{$key}) eq 'HASH') {
2654: my %added;
2655: foreach my $innerkey (keys(%{$copies{$key}})) {
2656: if (($innerkey ne '') && (!$added{$innerkey})) {
2657: push(@allcopies,$innerkey);
2658: $added{$innerkey} = 1;
2659: }
1.484.2.7 raeburn 2660: }
1.484.2.23 raeburn 2661: undef(%added);
1.484.2.7 raeburn 2662: }
2663: }
2664: if ($key eq $oldurl) {
1.484.2.23 raeburn 2665: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2666: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2667: push(@allcopies,$oldurl);
2668: }
2669: }
2670: }
2671: if (@allcopies > 0) {
2672: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2673: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2674: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2675: if ($fname ne '') {
2676: my $content = &Apache::lonnet::getfile($item);
2677: unless ($content eq '-1') {
2678: my $storefn;
1.484.2.23 raeburn 2679: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2680: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2681: } else {
2682: $storefn = $relpath;
2683: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2684: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2685: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2686: }
1.484.2.23 raeburn 2687: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2688: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2689: }
2690: }
2691: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2692: my $copyurl =
1.484.2.7 raeburn 2693: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2694: $storefn.$fname,$content);
2695: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2696: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2697: return &mt('Paste failed: an error occurred copying the file.');
2698: } elsif (ref($errors) eq 'HASH') {
2699: $errors->{$item} = 1;
2700: }
2701: }
2702: }
2703: }
2704: }
2705: }
2706: }
1.484.2.23 raeburn 2707: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2708: my $storefn=$key;
2709: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2710: if ($prefixchg && $before{'map'} && $after{'map'}) {
2711: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2712: }
1.484.2.23 raeburn 2713: if ($newsubdir{$key}) {
2714: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2715: }
2716: my $mapcontent = &Apache::lonnet::getfile($key);
2717: if ($mapcontent eq '-1') {
2718: if (ref($errors) eq 'HASH') {
2719: $errors->{$key} = 1;
2720: }
2721: } else {
2722: my $newmap =
2723: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2724: $mapcontent);
2725: if ($newmap eq '/adm/notfound.html') {
2726: if (ref($errors) eq 'HASH') {
2727: $errors->{$key} = 1;
2728: }
2729: }
2730: }
2731: }
2732: my %updates;
2733: if ($is_map) {
1.484.2.23 raeburn 2734: if (ref($updated) eq 'HASH') {
2735: foreach my $type (keys(%{$updated})) {
2736: if (ref($updated->{$type}) eq 'HASH') {
2737: foreach my $key (keys(%{$updated->{$type}})) {
2738: $updates{$key} = 1;
2739: }
2740: }
2741: }
1.484.2.7 raeburn 2742: }
2743: foreach my $key (keys(%updates)) {
2744: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2745: if (ref($rewrites{$key}) eq 'HASH') {
2746: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2747: }
1.484.2.23 raeburn 2748: if (ref($retitles{$key}) eq 'HASH') {
2749: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2750: }
1.484.2.23 raeburn 2751: if (ref($removefrommap{$key}) eq 'HASH') {
2752: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2753: }
1.484.2.23 raeburn 2754: if (ref($removeparam{$key}) eq 'HASH') {
2755: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2756: }
1.484.2.23 raeburn 2757: if (ref($zombies{$key}) eq 'HASH') {
2758: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2759: }
1.484.2.23 raeburn 2760: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2761: foreach my $idx (keys(%{$dbcopies{$key}})) {
2762: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2763: my ($newurl,$result,$errtext) =
2764: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2765: if ($result eq 'ok') {
2766: $newdb{$idx} = $newurl;
2767: } elsif (ref($errors) eq 'HASH') {
2768: $errors->{$key} = 1;
2769: }
2770: push(@msgs,$errtext);
2771: }
1.484.2.7 raeburn 2772: }
2773: }
1.484.2.82 raeburn 2774: if (ref($resdatacopy{$key}) eq 'HASH') {
2775: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2776: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2777: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2778: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2779: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2780: my $template = $1;
2781: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2782: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2783: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2784: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2785: unless ($gotnewmapname) {
2786: ($newmapname) = ($key =~ m{/([^/]+)$});
2787: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2788: if ($newsubdir{$key}) {
2789: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2790: }
2791: $gotnewmapname = 1;
2792: }
2793: my $srcmapinfo = $srcfolder.':'.$idx;
2794: if ($srccontainer eq 'page') {
2795: $srcmapinfo .= ':1';
2796: }
2797: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2798: $cnum,$template,$idx,$newmapname);
2799: }
2800: }
2801: }
2802: }
2803: }
1.484.2.23 raeburn 2804: if (ref($params{$key}) eq 'HASH') {
2805: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2806: }
2807: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2808: if ($fatal) {
1.484.2.26 raeburn 2809: return ($errtext);
1.484.2.7 raeburn 2810: }
2811: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2812: if (defined($LONCAPA::map::zombies[$i])) {
2813: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2814: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2815: undef($LONCAPA::map::zombies[$i]);
2816: }
2817: }
2818: }
1.484.2.77 raeburn 2819: my $total = scalar(@LONCAPA::map::order) - 1;
2820: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2821: my $idx = $LONCAPA::map::order[$i];
2822: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2823: my $changed;
1.484.2.23 raeburn 2824: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2825: if ((exists($toremove{$idx})) &&
2826: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2827: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2828: if (ref($currparam{$idx}) eq 'ARRAY') {
2829: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2830: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2831: }
2832: }
2833: next;
2834: }
2835: my $origsrc = $src;
1.484.2.25 raeburn 2836: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2837: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2838: $changed = 1;
2839: }
2840: }
1.484.2.25 raeburn 2841: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2842: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2843: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2844: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2845: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2846: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2847: } else {
1.484.2.23 raeburn 2848: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2849: }
2850: }
1.484.2.25 raeburn 2851: if ($origsrc =~ /\.(page|sequence)$/) {
2852: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2853: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2854: }
1.484.2.25 raeburn 2855: } elsif ($newsubdir{$key}) {
2856: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2857: }
2858: }
2859: $changed = 1;
1.484.2.26 raeburn 2860: } elsif ($newdb{$idx} ne '') {
2861: $src = $newdb{$idx};
1.484.2.7 raeburn 2862: $changed = 1;
2863: }
2864: if ($changed) {
1.484.2.30 raeburn 2865: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2866: }
2867: }
2868: }
2869: foreach my $idx (keys(%remparam)) {
2870: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2871: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2872: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2873: }
2874: }
2875: }
1.484.2.26 raeburn 2876: if (values(%lockerrors) > 0) {
2877: $lockmsg = join('<br />',values(%lockerrors));
2878: }
1.484.2.7 raeburn 2879: my $storefn;
2880: if ($key eq $oldurl) {
2881: $storefn = $url;
2882: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2883: } else {
2884: $storefn = $key;
2885: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2886: if ($prefixchg && $before{'map'} && $after{'map'}) {
2887: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2888: }
1.484.2.23 raeburn 2889: if ($newsubdir{$key}) {
2890: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2891: }
2892: }
2893: my $report;
2894: if ($folder !~ /^supplemental/) {
2895: $report = 1;
2896: }
1.484.2.20 raeburn 2897: (my $outtext,$errtext) =
1.484.2.7 raeburn 2898: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2899: if ($errtext) {
1.484.2.23 raeburn 2900: if ($caller eq 'paste') {
1.484.2.26 raeburn 2901: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2902: }
1.484.2.7 raeburn 2903: }
2904: }
2905: }
1.484.2.26 raeburn 2906: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2907: }
2908:
2909: sub copy_dependencies {
2910: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2911: my $content;
2912: if (ref($contentref)) {
2913: $content = $$contentref;
2914: } else {
2915: $content = &Apache::lonnet::getfile($item);
2916: }
2917: unless ($content eq '-1') {
2918: my $mm = new File::MMagic;
2919: my $mimetype = $mm->checktype_contents($content);
2920: if ($mimetype eq 'text/html') {
2921: my (%allfiles,%codebase,$state);
2922: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2923: if ($res eq 'ok') {
2924: my ($numexisting,$numpathchanges,$existing);
2925: (undef,$numexisting,$numpathchanges,$existing) =
2926: &Apache::loncommon::ask_for_embedded_content(
2927: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2928: {'error_on_invalid_names' => 1,
2929: 'ignore_remote_references' => 1,
2930: 'docs_url' => $item,
2931: 'context' => 'paste'});
2932: if ($numexisting > 0) {
2933: if (ref($existing) eq 'HASH') {
2934: foreach my $dep (keys(%{$existing})) {
2935: my $depfile = $dep;
2936: unless ($depfile =~ m{^\Q$relpath\E}) {
2937: $depfile = $relpath.$dep;
2938: }
2939: my $depcontent = &Apache::lonnet::getfile($depfile);
2940: unless ($depcontent eq '-1') {
2941: my $storedep = $dep;
2942: $storedep =~ s{^\Q$relpath\E}{};
2943: my $dep_url =
2944: &Apache::lonclonecourse::writefile(
2945: $env{'request.course.id'},
2946: $storefn.$storedep,$depcontent);
2947: if ($dep_url eq '/adm/notfound.html') {
2948: if (ref($errors) eq 'HASH') {
2949: $errors->{$depfile} = 1;
2950: }
2951: } else {
2952: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2953: }
2954: }
2955: }
2956: }
2957: }
2958: }
2959: }
2960: }
2961: return;
2962: }
2963:
1.329 droeschl 2964: my %parameter_type = ( 'randompick' => 'int_pos',
2965: 'hiddenresource' => 'string_yesno',
2966: 'encrypturl' => 'string_yesno',
2967: 'randomorder' => 'string_yesno',);
2968: my $valid_parameters_re = join('|',keys(%parameter_type));
2969: # set parameters
2970: sub update_parameter {
1.484.2.29 raeburn 2971: if ($env{'form.changeparms'} eq 'all') {
2972: my (@allidx,@allmapidx,%allchecked,%currchecked);
2973: %allchecked = (
2974: 'hiddenresource' => {},
2975: 'encrypturl' => {},
2976: 'randompick' => {},
2977: 'randomorder' => {},
2978: );
2979: foreach my $which (keys(%allchecked)) {
2980: $env{'form.all'.$which} =~ s/,$//;
2981: if ($which eq 'randompick') {
2982: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2983: my ($res,$value) = split(/:/,$item);
2984: if ($value =~ /^\d+$/) {
2985: $allchecked{$which}{$res} = $value;
2986: }
2987: }
2988: } else {
1.484.2.30 raeburn 2989: if ($env{'form.all'.$which}) {
2990: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2991: }
1.484.2.29 raeburn 2992: }
2993: }
2994: my $haschanges = 0;
2995: foreach my $res (@LONCAPA::map::order) {
2996: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2997: $name=&LONCAPA::map::qtescape($name);
2998: $url=&LONCAPA::map::qtescape($url);
2999: next unless ($name && $url);
3000: my $is_map;
3001: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3002: $is_map = 1;
3003: }
3004: foreach my $which (keys(%allchecked)) {
3005: if (($which eq 'randompick' || $which eq 'randomorder')) {
3006: next if (!$is_map);
3007: }
3008: my $oldvalue = 0;
3009: my $newvalue = 0;
3010: if ($allchecked{$which}{$res}) {
3011: $newvalue = $allchecked{$which}{$res};
3012: }
3013: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3014: if ($which eq 'randompick') {
3015: if ($current =~ /^(\d+)$/) {
3016: $oldvalue = $1;
3017: }
3018: } else {
3019: if ($current =~ /^yes$/i) {
3020: $oldvalue = 1;
3021: }
3022: }
3023: if ($oldvalue ne $newvalue) {
3024: $haschanges = 1;
3025: if ($newvalue) {
3026: my $storeval = 'yes';
3027: if ($which eq 'randompick') {
3028: $storeval = $newvalue;
3029: }
3030: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3031: $storeval,
3032: $parameter_type{$which});
3033: &remember_parms($res,$which,'set',$storeval);
3034: } elsif ($oldvalue) {
3035: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3036: &remember_parms($res,$which,'del');
3037: }
3038: }
3039: }
3040: }
3041: return $haschanges;
1.329 droeschl 3042: } else {
1.484.2.59 raeburn 3043: my $haschanges = 0;
3044: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 3045:
1.484.2.29 raeburn 3046: my $which = $env{'form.changeparms'};
3047: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 3048: my $oldvalue = 0;
3049: my $newvalue = 0;
3050: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3051: if ($which eq 'randompick') {
3052: if ($current =~ /^(\d+)$/) {
3053: $oldvalue = $1;
3054: }
3055: } elsif ($current =~ /^yes$/i) {
3056: $oldvalue = 1;
3057: }
1.484.2.29 raeburn 3058: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 3059: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3060: : 1;
1.484.2.29 raeburn 3061: }
1.484.2.59 raeburn 3062: if ($oldvalue ne $newvalue) {
3063: $haschanges = 1;
3064: if ($newvalue) {
3065: my $storeval = 'yes';
3066: if ($which eq 'randompick') {
3067: $storeval = $newvalue;
3068: }
3069: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3070: $parameter_type{$which});
3071: &remember_parms($idx,$which,'set',$storeval);
3072: } else {
3073: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3074: &remember_parms($idx,$which,'del');
3075: }
3076: }
3077: return $haschanges;
1.329 droeschl 3078: }
1.484.2.59 raeburn 3079: return;
1.329 droeschl 3080: }
3081:
3082: sub handle_edit_cmd {
3083: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 3084: if ($env{'form.cmd'} eq '') {
3085: return 0;
3086: }
1.329 droeschl 3087: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3088:
3089: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3090: my ($title, $url, @rrest) = split(':', $ratstr);
3091:
1.484.2.30 raeburn 3092: if ($cmd eq 'remove') {
1.329 droeschl 3093: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3094: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3095: &Apache::lonnet::removeuploadedurl($url);
3096: } else {
3097: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3098: }
3099: splice(@LONCAPA::map::order, $idx, 1);
3100:
3101: } elsif ($cmd eq 'cut') {
3102: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3103: splice(@LONCAPA::map::order, $idx, 1);
3104:
1.344 bisitz 3105: } elsif ($cmd eq 'up'
1.329 droeschl 3106: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3107: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3108:
3109: } elsif ($cmd eq 'down'
3110: && defined($LONCAPA::map::order[$idx+1])) {
3111: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3112:
3113: } elsif ($cmd eq 'rename') {
3114: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3115: if ($comment=~/\S/) {
3116: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3117: $comment.':'.join(':', $url, @rrest);
3118: }
3119: # Devalidate title cache
3120: my $renamed_url=&LONCAPA::map::qtescape($url);
3121: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 3122:
1.329 droeschl 3123: } else {
3124: return 0;
3125: }
3126: return 1;
3127: }
3128:
3129: sub editor {
1.458 raeburn 3130: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.85.2. (raeburn 3131:): $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3132:): $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 3133: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3134: if ($allowed) {
3135: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3136: $is_random_order,$container) =
3137: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3138: $r->print($breadcrumbtrail);
3139: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3140: $container = 'page';
3141: } else {
3142: $container = 'sequence';
3143: }
1.484 raeburn 3144:
1.484.2.21 raeburn 3145: my $jumpto;
3146:
3147: unless ($supplementalflag) {
1.484.2.32 raeburn 3148: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 3149: }
1.484 raeburn 3150:
3151: unless ($allowed) {
3152: $randompick = -1;
3153: }
3154:
1.484.2.67 raeburn 3155: my ($errtext,$fatal);
3156: if (($folder eq '') && (!$supplementalflag)) {
3157: if (@LONCAPA::map::order) {
3158: undef(@LONCAPA::map::order);
3159: undef(@LONCAPA::map::resources);
3160: undef(@LONCAPA::map::resparms);
3161: undef(@LONCAPA::map::zombies);
3162: }
3163: $folder = 'default';
3164: $container = 'sequence';
3165: } else {
3166: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3167: $folder.'.'.$container);
3168: return $errtext if ($fatal);
3169: }
1.329 droeschl 3170:
3171: if ($#LONCAPA::map::order<1) {
3172: my $idx=&LONCAPA::map::getresidx();
3173: if ($idx<=0) { $idx=1; }
3174: $LONCAPA::map::order[0]=$idx;
3175: $LONCAPA::map::resources[$idx]='';
3176: }
1.364 bisitz 3177:
1.329 droeschl 3178: # ------------------------------------------------------------ Process commands
3179:
3180: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 3181: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3182: # set parameters and change order
3183: &snapshotbefore();
3184:
3185: if (&update_parameter()) {
1.484.2.59 raeburn 3186: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3187: return $errtext if ($fatal);
3188: }
3189:
3190: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3191: # change order
3192: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3193: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3194:
3195: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3196: return $errtext if ($fatal);
3197: }
1.364 bisitz 3198:
1.329 droeschl 3199: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 3200: my %paste_errors;
1.484.2.26 raeburn 3201: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 3202: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3203: \%paste_errors);
1.484.2.30 raeburn 3204: if (ref($pastemsgarray) eq 'ARRAY') {
3205: if (@{$pastemsgarray} > 0) {
3206: $r->print('<p class="LC_info">'.
3207: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3208: '</p>');
3209: }
1.484.2.30 raeburn 3210: }
3211: if ($lockerror) {
3212: $r->print('<p class="LC_error">'.
3213: $lockerror.
3214: '</p>');
3215: }
3216: if ($save_error ne '') {
3217: return $save_error;
3218: }
3219: if ($paste_res) {
3220: my %errortext = &Apache::lonlocal::texthash (
3221: fail => 'Storage of folder contents failed',
3222: failread => 'Reading folder contents failed',
3223: failstore => 'Storage of folder contents failed',
3224: );
3225: if ($errortext{$paste_res}) {
3226: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3227: }
1.329 droeschl 3228: }
1.484.2.7 raeburn 3229: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3230: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3231: &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".
3232: '<ul>'."\n");
3233: foreach my $key (sort(keys(%paste_errors))) {
3234: $r->print('<li>'.$key.'</li>'."\n");
3235: }
3236: $r->print('</ul></p>'."\n");
3237: }
1.484.2.30 raeburn 3238: } elsif ($env{'form.clearmarked'}) {
3239: my $output = &do_buffer_empty();
3240: if ($output) {
3241: $r->print('<p class="LC_info">'.$output.'</p>');
3242: }
3243: }
1.329 droeschl 3244:
3245: $r->print($upload_output);
3246:
1.484.2.30 raeburn 3247: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3248: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3249: my $contentchg;
1.484.2.58 raeburn 3250: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3251: $contentchg = 1;
3252: }
3253: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3254: return $errtext if ($fatal);
3255: }
1.484.2.30 raeburn 3256:
3257: # Cut, copy and/or remove multiple resources
3258: if ($env{'form.multichange'}) {
3259: my %allchecked = (
3260: cut => {},
3261: remove => {},
3262: );
3263: my $needsupdate;
3264: foreach my $which (keys(%allchecked)) {
3265: $env{'form.multi'.$which} =~ s/,$//;
3266: if ($env{'form.multi'.$which}) {
3267: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3268: if (ref($allchecked{$which}) eq 'HASH') {
3269: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3270: }
3271: }
3272: }
3273: if ($needsupdate) {
3274: my $haschanges = 0;
3275: my %curr_groups = &Apache::longroup::coursegroups();
3276: my $total = scalar(@LONCAPA::map::order) - 1;
3277: for (my $i=$total; $i>=0; $i--) {
3278: my $res = $LONCAPA::map::order[$i];
3279: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3280: $name=&LONCAPA::map::qtescape($name);
3281: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3282: next unless $url;
1.484.2.30 raeburn 3283: my %denied =
3284: &action_restrictions($coursenum,$coursedom,$url,
3285: $env{'form.folderpath'},\%curr_groups);
3286: foreach my $which (keys(%allchecked)) {
3287: next if ($denied{$which});
3288: next unless ($allchecked{$which}{$res});
3289: if ($which eq 'remove') {
3290: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3291: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3292: &Apache::lonnet::removeuploadedurl($url);
3293: } else {
3294: &LONCAPA::map::makezombie($res);
3295: }
3296: splice(@LONCAPA::map::order,$i,1);
3297: $haschanges ++;
3298: } elsif ($which eq 'cut') {
3299: &LONCAPA::map::makezombie($res);
3300: splice(@LONCAPA::map::order,$i,1);
3301: $haschanges ++;
3302: }
3303: }
3304: }
3305: if ($haschanges) {
3306: ($errtext,$fatal) =
3307: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3308: return $errtext if ($fatal);
3309: }
3310: }
3311: }
3312:
1.329 droeschl 3313: # Group import/search
3314: if ($env{'form.importdetail'}) {
3315: my @imports;
3316: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3317: if (defined($item)) {
3318: my ($name,$url,$residx)=
1.484.2.26 raeburn 3319: map { &unescape($_); } split(/\=/,$item);
3320: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3321: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3322: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3323: if ($locknotfreed) {
3324: $r->print($locknotfreed);
3325: }
3326: if ($suffix) {
1.484.2.19 raeburn 3327: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3328: } else {
3329: return $errortxt;
3330: }
1.484.2.26 raeburn 3331: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3332: my $type = $1;
3333: my ($suffix,$errortxt,$locknotfreed) =
3334: &new_timebased_suffix($coursedom,$coursenum,$type);
3335: if ($locknotfreed) {
3336: $r->print($locknotfreed);
3337: }
3338: if ($suffix) {
3339: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3340: } else {
3341: return $errortxt;
3342: }
1.484.2.85.2. (raeburn 3343:): } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3344:): my ($suffix,$errortxt,$locknotfreed) =
3345:): &new_timebased_suffix($coursedom,$coursenum,'exttool');
3346:): if ($locknotfreed) {
3347:): $r->print($locknotfreed);
3348:): }
3349:): if ($suffix) {
3350:): $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3351:): } else {
3352:): return $errortxt;
3353:): }
1.484.2.27 raeburn 3354: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3355: if ($supplementalflag) {
3356: next unless ($1 eq 'supplemental');
3357: if ($folder eq 'supplemental') {
3358: next unless ($2 eq 'default');
3359: } else {
3360: next unless ($folder eq 'supplemental_'.$2);
3361: }
3362: } else {
3363: next unless ($1 eq 'docs');
3364: if ($folder eq 'default') {
3365: next unless ($2 eq 'default');
3366: } else {
3367: next unless ($folder eq 'default_'.$2);
3368: }
3369: }
1.484.2.15 raeburn 3370: }
1.329 droeschl 3371: push(@imports, [$name, $url, $residx]);
3372: }
3373: }
1.484.2.23 raeburn 3374: ($errtext,$fatal,my $fixuperrors) =
3375: &group_import($coursenum, $coursedom, $folder,$container,
1.484.2.85.2. (raeburn 3376:): 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3377: return $errtext if ($fatal);
1.484.2.23 raeburn 3378: if ($fixuperrors) {
3379: $r->print($fixuperrors);
3380: }
1.329 droeschl 3381: }
3382: # Loading a complete map
3383: if ($env{'form.loadmap'}) {
3384: if ($env{'form.importmap'}=~/\w/) {
3385: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3386: my ($title,$url,$ext,$type)=split(/\:/,$res);
3387: my $idx=&LONCAPA::map::getresidx($url);
3388: $LONCAPA::map::resources[$idx]=$res;
3389: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3390: }
3391: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3392: $folder.'.'.$container,1);
1.329 droeschl 3393: return $errtext if ($fatal);
3394: } else {
3395: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3396:
1.329 droeschl 3397: }
3398: }
3399: &log_differences($plain);
3400: }
3401: # ---------------------------------------------------------------- End commands
3402: # ---------------------------------------------------------------- Print screen
3403: my $idx=0;
3404: my $shown=0;
3405: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3406: $r->print('<div class="LC_Box">'.
1.432 raeburn 3407: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3408: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3409: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3410: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3411: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3412: '</ol>');
1.381 bisitz 3413: if ($randompick>=0) {
3414: $r->print('<p class="LC_warning">'
3415: .&mt('Caution: this folder is set to randomly pick a subset'
3416: .' of resources. Adding or removing resources from this'
3417: .' folder will change the set of resources that the'
3418: .' students see, resulting in spurious or missing credit'
3419: .' for completed problems, not limited to ones you'
3420: .' modify. Do not modify the contents of this folder if'
3421: .' it is in active student use.')
3422: .'</p>'
3423: );
3424: }
3425: if ($is_random_order) {
3426: $r->print('<p class="LC_warning">'
3427: .&mt('Caution: this folder is set to randomly order its'
3428: .' contents. Adding or removing resources from this folder'
3429: .' will change the order of resources shown.')
3430: .'</p>'
3431: );
3432: }
3433: $r->print('</div>');
1.364 bisitz 3434: }
1.381 bisitz 3435:
1.484.2.30 raeburn 3436: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3437: %filters = (
3438: canremove => [],
3439: cancut => [],
3440: cancopy => [],
3441: hiddenresource => [],
3442: encrypturl => [],
3443: randomorder => [],
3444: randompick => [],
3445: );
3446: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3447: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3448: foreach my $res (@LONCAPA::map::order) {
3449: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3450: $name=&LONCAPA::map::qtescape($name);
3451: $url=&LONCAPA::map::qtescape($url);
3452: unless ($name) { $name=(split(/\//,$url))[-1]; }
3453: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3454: push(@allidx,$res);
3455: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3456: push(@allmapidx,$res);
3457: }
1.484.2.67 raeburn 3458:
1.381 bisitz 3459: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3460: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3461: $pathitem,$supplementalflag,$container,
1.484.2.85.2. (raeburn 3462:): \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.484.2.80 raeburn 3463: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3464: $idx++;
3465: $shown++;
1.329 droeschl 3466: }
1.424 onken 3467: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3468:
1.484.2.30 raeburn 3469: my $need_save;
1.484.2.67 raeburn 3470: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3471: my $toolslink;
1.484.2.67 raeburn 3472: if ($allowed) {
1.484.2.31 raeburn 3473: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3474: .&Apache::loncommon::help_open_menu('Navigation Screen',
3475: 'Navigation_Screen',undef,'RAT')
3476: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3477: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3478: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3479: .'id="LC_content_toolbar_edittoplevel" '
3480: .'class="LC_toolbarItem" '
3481: .'title="'.&mt('Supplemental Content Editor').'">'
3482: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3483: }
1.484.2.19 raeburn 3484: if ($shown) {
3485: if ($allowed) {
3486: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3487: .&Apache::loncommon::start_data_table(undef,'contentlist')
3488: .&Apache::loncommon::start_data_table_header_row()
3489: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3490: .'<th colspan="2">'.&mt('Actions').'</th>'
3491: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3492: if ($folder !~ /^supplemental/) {
3493: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3494: }
1.484.2.29 raeburn 3495: $to_show .= &Apache::loncommon::end_data_table_header_row();
3496: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3497: $lists{'canhide'} = join(',',@allidx);
3498: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3499: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3500: 'randomorder','randompick');
3501: foreach my $item (@possfilters) {
3502: if (ref($filters{$item}) eq 'ARRAY') {
3503: if (@{$filters{$item}} > 0) {
3504: $lists{$item} = join(',',@{$filters{$item}});
3505: }
3506: }
3507: }
1.484.2.29 raeburn 3508: if (@allidx > 0) {
3509: my $path;
3510: if ($env{'form.folderpath'}) {
3511: $path =
3512: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3513: }
1.484.2.30 raeburn 3514: if (@allidx > 1) {
3515: $to_show .=
3516: &Apache::loncommon::continue_data_table_row().
3517: '<td colspan="2"> </td>'.
3518: '<td>'.
1.484.2.67 raeburn 3519: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3520: '</td>'.
3521: '<td> </td>'.
3522: '<td> </td>'.
3523: '<td colspan="4">'.
1.484.2.67 raeburn 3524: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3525: '</td>'.
3526: &Apache::loncommon::end_data_table_row();
3527: $need_save = 1;
3528: }
1.484.2.29 raeburn 3529: }
3530: }
3531: $to_show .= $output.' '
1.484.2.19 raeburn 3532: .&Apache::loncommon::end_data_table()
3533: .'<br style="line-height:2px;" />'
3534: .&Apache::loncommon::end_scrollbox();
3535: } else {
3536: $to_show .= $toolslink
3537: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3538: .$output.' '
3539: .&Apache::loncommon::end_data_table();
3540: }
3541: } else {
3542: if (!$allowed) {
3543: $to_show .= $toolslink;
1.393 raeburn 3544: }
1.484.2.67 raeburn 3545: my $noresmsg;
3546: if ($allowed && $hiddentop && !$supplementalflag) {
3547: $noresmsg = &mt('Main Content Hidden');
3548: } else {
3549: $noresmsg = &mt('Currently empty');
3550: }
1.484.2.19 raeburn 3551: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3552: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3553: .$noresmsg
1.484.2.19 raeburn 3554: .'</div>'
3555: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3556: }
3557: } else {
1.484.2.19 raeburn 3558: if ($shown) {
3559: $to_show = '<div>'
3560: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3561: .$output
3562: .&Apache::loncommon::end_data_table()
3563: .'</div>';
3564: } else {
3565: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3566: .&mt('Currently empty')
1.484.2.19 raeburn 3567: .'</div>'
3568: }
1.458 raeburn 3569: }
3570: my $tid = 1;
3571: if ($supplementalflag) {
3572: $tid = 2;
1.329 droeschl 3573: }
3574: if ($allowed) {
1.484 raeburn 3575: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3576: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3577: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3578: if ($canedit) {
1.484.2.67 raeburn 3579: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3580: }
1.460 raeburn 3581: } else {
3582: $r->print($to_show);
1.329 droeschl 3583: }
3584: return;
3585: }
3586:
1.484.2.30 raeburn 3587: sub multiple_check_form {
1.484.2.67 raeburn 3588: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3589: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3590: my $disabled;
3591: unless ($canedit) {
3592: $disabled = 'disabled="disabled"';
3593: }
1.484.2.30 raeburn 3594: my $output =
3595: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3596: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3597: '<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>'.
3598: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3599: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3600: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3601: if ($caller eq 'settings') {
3602: $output .=
3603: '<table><tr>'.
3604: '<td class="LC_docs_entry_parameter">'.
3605: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3606: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3607: '</label></span></td>'.
3608: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3609: '<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 3610: '</span></td>'.
3611: '</tr>'."\n".
3612: '<tr>'.
3613: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3614: '<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 3615: '</label></span>'.
3616: '</td></tr></table>'."\n";
3617: } else {
3618: $output .=
3619: '<table><tr>'.
3620: '<td class="LC_docs_entry_parameter">'.
3621: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3622: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3623: '</label></span></td>'.
3624: '<td class="LC_docs_entry_parameter">'.
3625: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3626: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3627: '</label></span></td>'."\n".
3628: '<td class="LC_docs_entry_parameter">'.
3629: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3630: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3631: '</label></span></td>'.
3632: '</tr></table>'."\n";
3633: }
3634: $output .=
3635: '</fieldset>'.
3636: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3637: if ($caller eq 'settings') {
3638: $output .=
3639: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3640: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3641: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3642: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3643: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3644: } elsif ($caller eq 'actions') {
3645: $output .=
3646: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3647: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3648: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3649: }
3650: $output .=
3651: '</form>'.
3652: '</div>';
3653: return $output;
3654: }
3655:
1.329 droeschl 3656: sub process_file_upload {
1.484.2.36 raeburn 3657: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3658: # upload a file, if present
1.484.2.36 raeburn 3659: my $filesize = length($env{'form.uploaddoc'});
3660: if (!$filesize) {
3661: $$upload_output = '<div class="LC_error">'.
3662: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3663: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3664: $filesize).'<br />'.
3665: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3666: '</div>';
3667: return;
3668: }
3669: my $quotatype = 'unofficial';
3670: if ($crstype eq 'Community') {
3671: $quotatype = 'community';
1.484.2.51 raeburn 3672: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3673: $quotatype = 'official';
1.484.2.45 raeburn 3674: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3675: $quotatype = 'textbook';
1.484.2.36 raeburn 3676: }
3677: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3678: $filesize = int($filesize/1000); #expressed in kb
3679: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3680: $env{'form.uploaddoc.filename'},$filesize,
3681: 'upload',$quotatype);
1.484.2.36 raeburn 3682: return if ($$upload_output);
3683: }
1.440 raeburn 3684: my ($parseaction,$showupload,$nextphase,$mimetype);
3685: if ($env{'form.parserflag'}) {
1.329 droeschl 3686: $parseaction = 'parse';
3687: }
3688: my $folder=$env{'form.folder'};
3689: if ($folder eq '') {
3690: $folder='default';
3691: }
3692: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3693: my $errtext='';
3694: my $fatal=0;
3695: my $container='sequence';
1.484.2.19 raeburn 3696: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3697: $container='page';
3698: }
3699: ($errtext,$fatal)=
1.484.2.27 raeburn 3700: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3701: if ($#LONCAPA::map::order<1) {
3702: $LONCAPA::map::order[0]=1;
3703: $LONCAPA::map::resources[1]='';
3704: }
3705: my $destination = 'docs/';
3706: if ($folder =~ /^supplemental/) {
3707: $destination = 'supplemental/';
3708: }
3709: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3710: $destination .= 'default/';
3711: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3712: $destination .= $2.'/';
3713: }
1.484.2.27 raeburn 3714: if ($fatal) {
3715: $$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>';
3716: return;
3717: }
1.440 raeburn 3718: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3719: my $newidx=&LONCAPA::map::getresidx();
3720: $destination .= $newidx;
1.439 raeburn 3721: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3722: $parseaction,$allfiles,
1.440 raeburn 3723: $codebase,undef,undef,undef,undef,
3724: undef,undef,\$mimetype);
3725: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3726: my $stored = $1;
3727: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3728: $stored.'</span>').'</p>';
3729: } else {
3730: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3731:
1.457 raeburn 3732: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3733: return;
3734: }
1.329 droeschl 3735: my $ext='false';
3736: if ($url=~m{^http://}) { $ext='true'; }
3737: $url = &LONCAPA::map::qtunescape($url);
3738: my $comment=$env{'form.comment'};
3739: $comment = &LONCAPA::map::qtunescape($comment);
3740: if ($folder=~/^supplemental/) {
3741: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3742: $env{'user.domain'}.'___&&&___'.$comment;
3743: }
3744:
3745: $LONCAPA::map::resources[$newidx]=
3746: $comment.':'.$url.':'.$ext.':normal:res';
3747: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3748: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3749: $folder.'.'.$container,1);
1.329 droeschl 3750: if ($fatal) {
1.457 raeburn 3751: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3752: return;
1.329 droeschl 3753: } else {
1.440 raeburn 3754: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3755: $$upload_output = $showupload;
1.384 raeburn 3756: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3757: if ($total_embedded > 0) {
1.440 raeburn 3758: my $uploadphase = 'upload_embedded';
3759: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3760: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3761: my ($embedded,$num) =
3762: &Apache::loncommon::ask_for_embedded_content(
3763: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3764: if ($embedded) {
3765: if ($num) {
3766: $$upload_output .=
3767: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3768: $nextphase = $uploadphase;
3769: } else {
3770: $$upload_output .= $embedded;
3771: }
3772: } else {
3773: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3774: }
1.329 droeschl 3775: } else {
1.440 raeburn 3776: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3777: }
1.457 raeburn 3778: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3779: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3780: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3781: $nextphase = 'decompress_uploaded';
3782: my $position = scalar(@LONCAPA::map::order)-1;
3783: my $noextract = &return_to_editor();
3784: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3785: my %archiveitems = (
3786: folderpath => $env{'form.folderpath'},
3787: cmd => $nextphase,
3788: newidx => $newidx,
3789: position => $position,
3790: phase => $nextphase,
1.477 raeburn 3791: comment => $comment,
1.480 raeburn 3792: );
3793: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3794: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3795: $$upload_output = $showupload.
3796: &Apache::loncommon::decompress_form($mimetype,
3797: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3798: \%archiveitems,\@current);
1.329 droeschl 3799: }
3800: }
3801: }
1.440 raeburn 3802: return $nextphase;
1.329 droeschl 3803: }
3804:
1.480 raeburn 3805: sub get_dir_list {
3806: my ($url,$coursenum,$coursedom,$newidx) = @_;
3807: my ($destination,$dir_root) = &embedded_destination();
3808: my ($dirlistref,$listerror) =
3809: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3810: my @dir_lines;
3811: my $dirptr=16384;
3812: if (ref($dirlistref) eq 'ARRAY') {
3813: foreach my $dir_line (sort
3814: {
3815: my ($afile)=split('&',$a,2);
3816: my ($bfile)=split('&',$b,2);
3817: return (lc($afile) cmp lc($bfile));
3818: } (@{$dirlistref})) {
3819: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3820: $filename =~ s/\s+$//;
3821: next if ($filename =~ /^\.\.?$/);
3822: my $isdir = 0;
3823: if ($dirptr&$testdir) {
3824: $isdir = 1;
3825: }
3826: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3827: }
3828: }
3829: return @dir_lines;
3830: }
3831:
1.329 droeschl 3832: sub is_supplemental_title {
3833: my ($title) = @_;
3834: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3835: }
3836:
3837: # --------------------------------------------------------------- An entry line
3838:
3839: sub entryline {
1.484.2.12 raeburn 3840: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3841: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.85.2. (raeburn 3842:): $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.484.2.52 raeburn 3843: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3844: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3845: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3846: } else {
3847: $title=&HTML::Entities::encode($title,'"<>&\'');
3848: $renametitle=$title;
3849: $foldertitle=$title;
3850: }
3851:
1.484.2.67 raeburn 3852: my ($disabled,$readonly,$js_lt);
3853: unless ($canedit) {
3854: $disabled = 'disabled="disabled"';
3855: $readonly = 1;
3856: }
3857:
1.329 droeschl 3858: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3859:
1.329 droeschl 3860: $renametitle=~s/\\/\\\\/g;
3861: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3862: $renametitle=~s/"/%22/g;
1.329 droeschl 3863: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3864: $oldtitle = $renametitle;
3865: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3866: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3867: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3868: # Edit commands
1.484.2.28 raeburn 3869: my ($esc_path, $path, $symb);
1.329 droeschl 3870: if ($env{'form.folderpath'}) {
3871: $esc_path=&escape($env{'form.folderpath'});
3872: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3873: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3874: }
1.484.2.16 raeburn 3875: my $isexternal;
1.484.2.19 raeburn 3876: if ($residx) {
1.484.2.12 raeburn 3877: my $currurl = $url;
3878: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3879: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3880: $isexternal = 1;
3881: }
1.484.2.19 raeburn 3882: if (!$supplementalflag) {
3883: my $path = 'uploaded/'.
3884: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3885: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3886: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3887: $residx,
3888: &Apache::lonnet::declutter($currurl));
3889: }
1.484.2.12 raeburn 3890: }
1.484.2.30 raeburn 3891: my ($renamelink,%lt,$ishash);
3892: if (ref($filtersref) eq 'HASH') {
3893: $ishash = 1;
3894: }
3895:
1.329 droeschl 3896: if ($allowed) {
1.484.2.30 raeburn 3897: $form_start = '
3898: <form action="/adm/coursedocs" method="post">
3899: ';
3900: $form_common=(<<END);
3901: <input type="hidden" name="folderpath" value="$path" />
3902: <input type="hidden" name="symb" value="$symb" />
3903: END
3904: $form_param=(<<END);
3905: <input type="hidden" name="setparms" value="$orderidx" />
3906: <input type="hidden" name="changeparms" value="0" />
3907: END
3908: $form_end = '</form>';
3909:
1.329 droeschl 3910: my $incindex=$index+1;
3911: my $selectbox='';
1.471 raeburn 3912: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3913: ((split(/\:/,
1.344 bisitz 3914: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3915: ne '') &&
1.329 droeschl 3916: ((split(/\:/,
1.344 bisitz 3917: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3918: ne '')) {
3919: $selectbox=
3920: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3921: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3922: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3923: if ($i==$incindex) {
1.358 bisitz 3924: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3925: } else {
3926: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3927: }
3928: }
3929: $selectbox.='</select>';
3930: }
1.484.2.12 raeburn 3931: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3932: 'up' => 'Move Up',
3933: 'dw' => 'Move Down',
3934: 'rm' => 'Remove',
3935: 'ct' => 'Cut',
3936: 'rn' => 'Rename',
1.484.2.12 raeburn 3937: 'cp' => 'Copy',
3938: 'ex' => 'External Resource',
1.484.2.85.2. (raeburn 3939:): 'et' => 'External Tool',
1.484.2.12 raeburn 3940: 'ed' => 'Edit',
3941: 'pr' => 'Preview',
3942: 'sv' => 'Save',
3943: 'ul' => 'URL',
1.484.2.67 raeburn 3944: 'ti' => 'Title',
3945: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3946: );
1.484.2.30 raeburn 3947: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3948: $env{'form.folderpath'},
3949: $currgroups);
1.484.2.19 raeburn 3950: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3951: my $skip_confirm = 0;
1.484.2.63 raeburn 3952: my $confirm_removal = 0;
1.329 droeschl 3953: if ( $folder =~ /^supplemental/
3954: || ($url =~ m{( /smppg$
3955: |/syllabus$
3956: |/aboutme$
3957: |/navmaps$
3958: |/bulletinboard$
1.484.2.85.2. (raeburn 3959:): |/ext\.tool$
1.484.2.16 raeburn 3960: |\.html$)}x)
1.484.2.19 raeburn 3961: || $isexternal) {
1.329 droeschl 3962: $skip_confirm = 1;
3963: }
1.484.2.63 raeburn 3964: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3965: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3966: $confirm_removal = 1;
3967: }
1.484.2.19 raeburn 3968:
1.484.2.30 raeburn 3969: if ($denied{'copy'}) {
3970: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3971: <span style="visibility: hidden;">$lt{'cp'}</span>
3972: ENDCOPY
3973: } else {
1.484.2.30 raeburn 3974: my $formname = 'edit_copy_'.$orderidx;
3975: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3976: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3977: <form name="$formname" method="post" action="/adm/coursedocs">
3978: $form_common
1.484.2.67 raeburn 3979: <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 3980: $form_end
1.329 droeschl 3981: ENDCOPY
1.484.2.30 raeburn 3982: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3983: push(@{$filtersref->{'cancopy'}},$orderidx);
3984: }
1.329 droeschl 3985: }
1.484.2.30 raeburn 3986: if ($denied{'cut'}) {
1.484.2.16 raeburn 3987: $cutlink=(<<ENDCUT);
3988: <span style="visibility: hidden;">$lt{'ct'}</span>
3989: ENDCUT
3990: } else {
1.484.2.30 raeburn 3991: my $formname = 'edit_cut_'.$orderidx;
3992: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3993: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3994: <form name="$formname" method="post" action="/adm/coursedocs">
3995: $form_common
3996: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3997: <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 3998: $form_end
1.329 droeschl 3999: ENDCUT
1.484.2.30 raeburn 4000: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4001: push(@{$filtersref->{'cancut'}},$orderidx);
4002: }
1.329 droeschl 4003: }
1.484.2.30 raeburn 4004: if ($denied{'remove'}) {
1.484.2.16 raeburn 4005: $removelink=(<<ENDREM);
4006: <span style="visibility: hidden;">$lt{'rm'}</a>
4007: ENDREM
4008: } else {
1.484.2.30 raeburn 4009: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 4010: 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 4011: $removelink=(<<ENDREM);
1.484.2.30 raeburn 4012: <form name="$formname" method="post" action="/adm/coursedocs">
4013: $form_common
4014: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 4015: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 4016: <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 4017: $form_end
1.484.2.9 raeburn 4018: ENDREM
1.484.2.30 raeburn 4019: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4020: push(@{$filtersref->{'canremove'}},$orderidx);
4021: }
1.484.2.9 raeburn 4022: }
1.484.2.35 raeburn 4023: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 4024: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 4025: ENDREN
1.484.2.67 raeburn 4026: my ($uplink,$downlink);
4027: if ($canedit) {
4028: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4029: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4030: } else {
4031: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4032: $downlink = $uplink;
4033: }
1.329 droeschl 4034: $line.=(<<END);
4035: <td>
1.379 bisitz 4036: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4037: <a href="$uplink">
1.484.2.12 raeburn 4038: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4039: </a>
4040: </div>
4041: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4042: <a href="$downlink">
1.484.2.12 raeburn 4043: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4044: </a>
4045: </div>
1.329 droeschl 4046: </td>
4047: <td>
4048: $form_start
1.484.2.30 raeburn 4049: $form_param
1.478 raeburn 4050: $form_common
1.329 droeschl 4051: $selectbox
4052: $form_end
4053: </td>
1.484.2.30 raeburn 4054: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 4055: $removelink
1.329 droeschl 4056: $cutlink
4057: $copylink
4058: </td>
4059: END
4060: }
4061: # Figure out what kind of a resource this is
4062: my ($extension)=($url=~/\.(\w+)$/);
4063: my $uploaded=($url=~/^\/*uploaded\//);
4064: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 4065: my $isfolder;
4066: my $ispage;
4067: my $containerarg;
1.484.2.67 raeburn 4068: my $folderurl;
1.329 droeschl 4069: if ($uploaded) {
1.472 raeburn 4070: if (($extension eq 'sequence') || ($extension eq 'page')) {
4071: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 4072: $containerarg = $1;
1.472 raeburn 4073: if ($extension eq 'sequence') {
4074: $icon=$iconpath.'navmap.folder.closed.gif';
4075: $isfolder=1;
4076: } else {
4077: $icon=$iconpath.'page.gif';
4078: $ispage=1;
4079: }
1.484.2.67 raeburn 4080: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4081: if ($allowed) {
4082: $url='/adm/coursedocs?';
4083: } else {
4084: $url='/adm/supplemental?';
4085: }
1.329 droeschl 4086: } else {
4087: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4088: }
4089: }
1.364 bisitz 4090:
1.484.2.70 raeburn 4091: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4092: my $orig_url = $url;
1.340 raeburn 4093: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.85.2. (raeburn 4094:): if ($container eq 'page') {
4095:): $url=~s{^http(|s)(:|:)//}{/ext/};
4096:): } else {
4097:): $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4098:): }
1.484.2.12 raeburn 4099: if (!$supplementalflag && $residx && $symb) {
4100: if ((!$isfolder) && (!$ispage)) {
4101: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.484.2.85.2. (raeburn 4102:): if (($url =~ m{^ext/}) && ($container eq 'page')) {
4103:): $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4104:): } else {
4105:): $url=&Apache::lonnet::clutter($url);
4106:): }
1.484.2.12 raeburn 4107: if ($url=~/^\/*uploaded\//) {
4108: $url=~/\.(\w+)$/;
4109: my $embstyle=&Apache::loncommon::fileembstyle($1);
4110: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4111: $url='/adm/wrapper'.$url;
4112: } elsif ($embstyle eq 'ssi') {
4113: #do nothing with these
4114: } elsif ($url!~/\.(sequence|page)$/) {
4115: $url='/adm/coursedocs/showdoc'.$url;
4116: }
1.484.2.70 raeburn 4117: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4118: my $wrapped = $1;
4119: my $exturl = $2;
1.484.2.85.2. (raeburn 4120:): if (($wrapped eq '') && ($container ne 'page')) {
1.484.2.70 raeburn 4121: $url='/adm/wrapper'.$url;
4122: }
4123: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4124: $nomodal = 1;
4125: }
1.484.2.85.2. (raeburn 4126:): } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4127:): $url='/adm/wrapper'.$url;
1.484.2.70 raeburn 4128: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4129: if (($ENV{'SERVER_PORT'} == 443) &&
4130: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 4131: unless (&Apache::lonnet::uses_sts()) {
4132: $url .= '?usehttp=1';
4133: }
1.484.2.70 raeburn 4134: $nomodal = 1;
4135: }
1.484.2.19 raeburn 4136: }
1.484.2.12 raeburn 4137: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 4138: my $shownsymb = $symb;
4139: if ($isexternal) {
1.484.2.85.2. (raeburn 4140:): $url =~ s/\#[^#]+$//;
4141:): if ($container eq 'page') {
4142:): $url = &Apache::lonnet::clutter($url);
1.484.2.66 raeburn 4143: }
4144: }
1.484.2.67 raeburn 4145: unless ($env{'request.role.adv'}) {
4146: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4147: $url = '';
4148: }
4149: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4150: $url = '';
4151: $hiddenres = 1;
4152: }
4153: }
4154: if ($url ne '') {
1.484.2.75 raeburn 4155: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 4156: }
4157: } elsif (!$env{'request.role.adv'}) {
4158: my $checkencrypt;
4159: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4160: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4161: $checkencrypt = 1;
1.484.2.70 raeburn 4162: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 4163: unless (ref($$navmapref)) {
4164: $$navmapref = Apache::lonnavmaps::navmap->new();
4165: }
4166: if (ref($$navmapref)) {
4167: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4168: $checkencrypt = 1;
4169: }
4170: }
4171: }
4172: if ($checkencrypt) {
4173: my $shownsymb = &Apache::lonenc::encrypted($symb);
4174: my $shownurl = &Apache::lonenc::encrypted($url);
4175: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.484.2.80 raeburn 4176: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 4177: if ($env{'request.enc'} ne '') {
4178: delete($env{'request.enc'});
4179: }
4180: } else {
4181: $url='';
4182: }
4183: } else {
4184: $url='';
4185: }
1.484.2.12 raeburn 4186: } else {
4187: $url='';
4188: }
1.484.2.19 raeburn 4189: }
1.484.2.66 raeburn 4190: } elsif ($supplementalflag) {
4191: if ($isexternal) {
4192: if ($url =~ /^([^#]+)#([^#]+)$/) {
4193: $url = $1;
4194: $anchor = $2;
1.484.2.70 raeburn 4195: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.80 raeburn 4196: unless (&Apache::lonnet::uses_sts()) {
4197: if ($hostname ne '') {
4198: $url = 'http://'.$hostname.$url;
4199: }
4200: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4201: }
1.484.2.70 raeburn 4202: $nomodal = 1;
4203: }
4204: }
4205: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4206: if (($ENV{'SERVER_PORT'} == 443) &&
4207: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 4208: unless (&Apache::lonnet::uses_sts()) {
4209: if ($hostname ne '') {
4210: $url = 'http://'.$hostname.$url;
4211: }
4212: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4213: }
1.484.2.70 raeburn 4214: $nomodal = 1;
1.484.2.66 raeburn 4215: }
4216: }
1.329 droeschl 4217: }
1.484.2.67 raeburn 4218: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4219: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4220: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4221: my $foldername=&escape($foldertitle);
4222: my $folderpath=$env{'form.folderpath'};
4223: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4224: if (!$allowed && $supplementalflag) {
4225: $folderpath.=$containerarg.'&'.$foldername;
4226: $url.='folderpath='.&escape($folderpath);
4227: } else {
4228: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4229: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4230: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4231: 'parameter_randomorder'))[0]=~/^yes$/i);
4232: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4233: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4234: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4235: 'parameter_encrypturl'))[0]=~/^yes$/i);
4236: unless ($hiddenmap) {
1.484.2.70 raeburn 4237: if (ref($navmapref)) {
4238: unless (ref($$navmapref)) {
4239: $$navmapref = Apache::lonnavmaps::navmap->new();
4240: }
4241: if (ref($$navmapref)) {
4242: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4243: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4244: unless (@resources) {
4245: $hiddenmap = 1;
4246: unless ($env{'request.role.adv'}) {
4247: $url = '';
4248: $hiddenfolder = 1;
4249: }
1.484.2.67 raeburn 4250: }
4251: }
4252: }
4253: }
4254: }
4255: unless ($encryptmap) {
1.484.2.70 raeburn 4256: if ((ref($navmapref)) && (ref($$navmapref))) {
4257: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4258: $encryptmap = 1;
4259: }
1.484.2.67 raeburn 4260: }
4261: }
4262:
4263: # Append randompick number, hidden, and encrypted with ":" to foldername,
4264: # so it gets transferred between levels
4265: $folderpath.=$containerarg.'&'.$foldername.
4266: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4267: unless ($url eq '') {
4268: $url.='folderpath='.&escape($folderpath);
4269: }
1.484.2.19 raeburn 4270: my $rpckchk;
4271: if ($rpicknum) {
4272: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4273: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4274: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4275: }
1.484.2.19 raeburn 4276: }
1.484.2.29 raeburn 4277: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4278: $rand_pick_text =
1.478 raeburn 4279: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4280: $form_param."\n".
1.478 raeburn 4281: $form_common."\n".
1.484.2.67 raeburn 4282: '<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 4283: if ($rpicknum ne '') {
4284: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4285: }
1.484.2.29 raeburn 4286: $rand_pick_text .= '</span></span>'.
4287: $form_end;
1.484.2.30 raeburn 4288: my $ro_set;
1.484.2.67 raeburn 4289: if ($randorder) {
1.484.2.30 raeburn 4290: $ro_set = 'checked="checked"';
4291: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4292: push(@{$filtersref->{'randomorder'}},$orderidx);
4293: }
4294: }
1.484.2.41 raeburn 4295: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4296: $rand_order_text =
1.484.2.29 raeburn 4297: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4298: $form_param."\n".
1.484.2.29 raeburn 4299: $form_common."\n".
1.484.2.67 raeburn 4300: '<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 4301: $form_end;
1.484.2.19 raeburn 4302: }
1.484.2.18 raeburn 4303: } elsif ($supplementalflag && !$allowed) {
1.484.2.85.2. (raeburn 4304:): my $isexttool;
4305:): if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4306:): $url='/adm/wrapper'.$url;
4307:): $isexttool = 1;
4308:): }
1.484.2.19 raeburn 4309: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4310: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4311: if ($title) {
4312: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4313: }
1.484.2.85.2. (raeburn 4314:): if ((($isexternal) || ($isexttool)) && $orderidx) {
1.484.2.19 raeburn 4315: $url .= '&idx='.$orderidx;
4316: }
1.484.2.66 raeburn 4317: if ($anchor ne '') {
4318: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4319: }
1.329 droeschl 4320: }
1.484.2.19 raeburn 4321: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4322: if ($allowed) {
1.484.2.19 raeburn 4323: my $fileloc =
1.484.2.12 raeburn 4324: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4325: if ($isexternal) {
4326: ($editlink,$extresform) =
1.484.2.67 raeburn 4327: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
1.484.2.85.2. (raeburn 4328:): undef,undef,undef,undef,undef,undef,
4329:): undef,$disabled);
4330:): } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4331:): ($editlink,$extresform) =
4332:): &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4333:): undef,undef,undef,'tool',$coursedom,
4334:): $coursenum,$ltitoolsref,$disabled);
1.484.2.19 raeburn 4335: } elsif (!$isfolder && !$ispage) {
4336: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4337: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4338: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4339: my $suppanchor;
4340: if ($supplementalflag) {
4341: $suppanchor = $anchor;
4342: }
1.484.2.19 raeburn 4343: my $jscall =
1.484.2.12 raeburn 4344: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4345: $switchserver,
1.484.2.14 raeburn 4346: $forceedit,
1.484.2.19 raeburn 4347: undef,$symb,
4348: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4349: $renametitle,$hostname,
4350: '','',1,$suppanchor);
1.484.2.12 raeburn 4351: if ($jscall) {
1.484.2.19 raeburn 4352: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4353: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4354: }
4355: }
4356: }
1.484.2.19 raeburn 4357: $tdalign = ' align="right" valign="top"';
4358: $tdwidth = ' width="80%"';
1.329 droeschl 4359: }
1.408 raeburn 4360: my $reinit;
4361: if ($crstype eq 'Community') {
4362: $reinit = &mt('(re-initialize community to access)');
4363: } else {
4364: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4365: }
4366: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4367: my $link;
1.472 raeburn 4368: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4369: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4370: } elsif ($url) {
1.484.2.66 raeburn 4371: if ($anchor ne '') {
4372: if ($supplementalflag) {
4373: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4374: } else {
4375: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4376: }
4377: }
1.484.2.80 raeburn 4378:
4379: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4380: $link = 'http://'.$hostname.$url;
4381: } else {
4382: $link = $url;
4383: }
4384: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4385: if ($nomodal) {
4386: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4387: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4388: } else {
4389: $line.=&Apache::loncommon::modal_link($link,
4390: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4391: }
1.469 www 4392: } else {
4393: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4394: }
1.484.2.19 raeburn 4395: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4396: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4397: $line.='<a href="'.$url.'">'.$title.'</a>';
4398: } elsif ($url) {
1.484.2.70 raeburn 4399: if ($nomodal) {
4400: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4401: $title.'</a>';
4402: } else {
4403: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4404: }
1.484.2.67 raeburn 4405: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4406: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4407: } else {
4408: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4409: }
1.484.2.19 raeburn 4410: $line.="$extresform</td>";
1.478 raeburn 4411: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4412: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4413: if (($allowed) && ($folder!~/^supplemental/)) {
4414: my %lt=&Apache::lonlocal::texthash(
4415: 'hd' => 'Hidden',
4416: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4417: my ($enctext,$hidtext);
4418: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4419: $enctext = ' checked="checked"';
4420: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4421: push(@{$filtersref->{'encrypturl'}},$orderidx);
4422: }
4423: }
4424: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4425: $hidtext = ' checked="checked"';
4426: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4427: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4428: }
4429: }
1.484.2.29 raeburn 4430: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4431: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4432: $line.=(<<ENDPARMS);
4433: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4434: <form action="/adm/coursedocs" method="post" name="$formhidden">
4435: $form_param
1.478 raeburn 4436: $form_common
1.484.2.67 raeburn 4437: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4438: $form_end
1.458 raeburn 4439: <br />
1.484.2.29 raeburn 4440: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4441: $form_param
1.478 raeburn 4442: $form_common
1.484.2.67 raeburn 4443: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4444: $form_end
4445: </td>
1.478 raeburn 4446: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4447: $rand_order_text</td>
1.329 droeschl 4448: ENDPARMS
4449: }
1.379 bisitz 4450: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4451: return $line;
4452: }
4453:
1.484.2.30 raeburn 4454: sub action_restrictions {
4455: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4456: my %denied = (
4457: cut => 0,
4458: copy => 0,
4459: remove => 0,
4460: );
4461: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4462: # no copy for published maps
4463: $denied{'copy'} = 1;
1.484.2.82 raeburn 4464: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4465: unless ($1 eq 'simpleproblem') {
4466: $denied{'copy'} = 1;
4467: }
4468: $denied{'cut'} = 1;
1.484.2.30 raeburn 4469: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4470: if ($folderpath =~ /^default&[^\&]+$/) {
4471: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4472: $denied{'remove'} = 1;
4473: }
4474: $denied{'cut'} = 1;
4475: $denied{'copy'} = 1;
4476: }
4477: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4478: my $group = $1;
4479: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4480: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4481: $denied{'remove'} = 1;
4482: }
4483: }
4484: $denied{'cut'} = 1;
4485: $denied{'copy'} = 1;
4486: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4487: my $group = $1;
4488: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4489: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4490: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4491: if (keys(%groupsettings) > 0) {
4492: $denied{'remove'} = 1;
4493: }
4494: $denied{'cut'} = 1;
4495: $denied{'copy'} = 1;
4496: }
4497: }
4498: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4499: my $group = $1;
4500: if ($url =~ /group_boards_\Q$group\E/) {
4501: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4502: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4503: if (keys(%groupsettings) > 0) {
4504: if (ref($groupsettings{'functions'}) eq 'HASH') {
4505: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4506: $denied{'remove'} = 1;
4507: }
4508: }
4509: }
4510: $denied{'cut'} = 1;
4511: $denied{'copy'} = 1;
4512: }
4513: }
4514: }
4515: return %denied;
4516: }
4517:
1.484.2.26 raeburn 4518: sub new_timebased_suffix {
1.484.2.30 raeburn 4519: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4520: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4521: if ($type eq 'paste') {
4522: $prefix = $type;
4523: $namespace = 'courseeditor';
1.484.2.56 raeburn 4524: $idtype = 'addcode';
1.484.2.30 raeburn 4525: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4526: $prefix = 'docs';
4527: if ($area eq 'supplemental') {
4528: $prefix = 'supp';
4529: }
4530: $prefix .= $container;
4531: $namespace = 'uploadedmaps';
4532: } else {
4533: $prefix = $type;
4534: $namespace = 'templated';
1.484.2.15 raeburn 4535: }
4536: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4537: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4538: if (!$suffix) {
1.484.2.30 raeburn 4539: if ($type eq 'paste') {
4540: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4541: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4542: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4543: } elsif ($type eq 'smppg') {
4544: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.484.2.85.2. (raeburn 4545:): } elsif ($type eq 'exttool') {
4546:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.484.2.26 raeburn 4547: } else {
1.484.2.42 raeburn 4548: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4549: }
1.484.2.15 raeburn 4550: if ($error) {
4551: $errtext .= '<br />'.$error;
4552: }
4553: }
4554: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4555: $locknotfreed =
4556: '<div class="LC_error">'.
4557: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4558: if ($type eq 'paste') {
1.484.2.57 raeburn 4559: if ($freedlock eq 'nolock') {
4560: $locknotfreed =
4561: '<div class="LC_error">'.
4562: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4563:
1.484.2.60 raeburn 4564: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4565: } else {
4566: $locknotfreed .=
4567: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4568: }
1.484.2.30 raeburn 4569: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4570: $locknotfreed .=
4571: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4572: } elsif ($type eq 'smppg') {
4573: $locknotfreed .=
4574: &mt('This will prevent creation of additional simple pages in this course.');
1.484.2.85.2. (raeburn 4575:): } elsif ($type eq 'exttool') {
4576:): $locknotfreed .=
4577:): &mt('This will prevent creation of additional external tools in this course.');
1.484.2.26 raeburn 4578: } else {
4579: $locknotfreed .=
1.484.2.42 raeburn 4580: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4581: }
1.484.2.30 raeburn 4582: unless ($type eq 'paste') {
4583: $locknotfreed .=
1.484.2.38 raeburn 4584: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4585: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4586: }
4587: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4588: }
4589: return ($suffix,$errtext,$locknotfreed);
4590: }
4591:
1.329 droeschl 4592: =pod
4593:
4594: =item tiehash()
4595:
4596: tie the hash
4597:
4598: =cut
4599:
4600: sub tiehash {
4601: my ($mode)=@_;
4602: $hashtied=0;
4603: if ($env{'request.course.fn'}) {
4604: if ($mode eq 'write') {
4605: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4606: &GDBM_WRCREAT(),0640)) {
4607: $hashtied=2;
4608: }
4609: } else {
4610: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4611: &GDBM_READER(),0640)) {
4612: $hashtied=1;
4613: }
4614: }
1.364 bisitz 4615: }
1.329 droeschl 4616: }
4617:
4618: sub untiehash {
4619: if ($hashtied) { untie %hash; }
4620: $hashtied=0;
4621: return OK;
4622: }
4623:
4624:
4625:
4626:
4627: sub checkonthis {
1.484.2.78 raeburn 4628: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4629: $url=&unescape($url);
4630: $alreadyseen{$url}=1;
4631: $r->rflush();
4632: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4633: $r->print("\n<br />");
4634: if ($level==0) {
4635: $r->print("<br />");
4636: }
4637: for (my $i=0;$i<=$level*5;$i++) {
4638: $r->print(' ');
4639: }
4640: $r->print('<a href="'.$url.'" target="cat">'.
4641: ($title?$title:$url).'</a> ');
4642: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4643: my $updated;
4644: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4645: ($url !~ /\.\d+\.\w+$/)) {
4646: $updated = &Apache::lonnet::remove_stale_resfile($url);
4647: }
1.329 droeschl 4648: my $result=&Apache::lonnet::repcopy(
4649: &Apache::lonnet::filelocation('',$url));
4650: if ($result eq 'ok') {
4651: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4652: if ($updated) {
4653: $r->print('<br />');
4654: for (my $i=0;$i<=$level*5;$i++) {
4655: $r->print(' ');
4656: }
4657: $r->print('- '.&mt('Outdated copy removed'));
4658: }
1.329 droeschl 4659: $r->rflush();
4660: &Apache::lonnet::countacc($url);
4661: $url=~/\.(\w+)$/;
4662: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4663: $r->print('<br />');
4664: $r->rflush();
4665: for (my $i=0;$i<=$level*5;$i++) {
4666: $r->print(' ');
4667: }
4668: $r->print('- '.&mt('Rendering:').' ');
4669: my ($errorcount,$warningcount)=split(/:/,
4670: &Apache::lonnet::ssi_body($url,
4671: ('grade_target'=>'web',
4672: 'return_only_error_and_warning_counts' => 1)));
4673: if (($errorcount) ||
4674: ($warningcount)) {
4675: if ($errorcount) {
1.369 bisitz 4676: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4677: &mt('[quant,_1,error]',$errorcount).'</span>');
4678: }
4679: if ($warningcount) {
4680: $r->print('<span class="LC_warning">'.
4681: &mt('[quant,_1,warning]',$warningcount).'</span>');
4682: }
4683: } else {
4684: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4685: }
4686: $r->rflush();
4687: }
4688: my $dependencies=
4689: &Apache::lonnet::metadata($url,'dependencies');
4690: foreach my $dep (split(/\,/,$dependencies)) {
4691: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4692: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4693: }
4694: }
4695: } elsif ($result eq 'unavailable') {
4696: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4697: } elsif ($result eq 'not_found') {
4698: unless ($url=~/\$/) {
1.484.2.19 raeburn 4699: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4700: } else {
1.366 bisitz 4701: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4702: }
4703: } else {
4704: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4705: }
1.484.2.78 raeburn 4706: if (($updated) && ($result ne 'ok')) {
4707: $r->print('<br />'.&mt('Outdated copy removed'));
4708: }
1.329 droeschl 4709: }
4710: }
4711: }
4712:
4713:
4714:
4715: =pod
4716:
4717: =item list_symbs()
4718:
1.484.2.3 raeburn 4719: List Content Identifiers
1.329 droeschl 4720:
4721: =cut
4722:
4723: sub list_symbs {
4724: my ($r) = @_;
4725:
1.408 raeburn 4726: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4727: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4728: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4729: $r->print(&startContentScreen('tools'));
1.329 droeschl 4730: my $navmap = Apache::lonnavmaps::navmap->new();
4731: if (!defined($navmap)) {
4732: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4733: '<div class="LC_error">'.
4734: &mt('Unable to retrieve information about course contents').
4735: '</div>');
1.408 raeburn 4736: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4737: } else {
1.484 raeburn 4738: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4739: &Apache::loncommon::start_data_table().
4740: &Apache::loncommon::start_data_table_header_row().
4741: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4742: &Apache::loncommon::end_data_table_header_row()."\n");
4743: my $count;
1.329 droeschl 4744: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4745: $r->print(&Apache::loncommon::start_data_table_row().
4746: '<td>'.$res->compTitle().'</td>'.
4747: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4748: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4749: $count ++;
4750: }
4751: if (!$count) {
4752: $r->print(&Apache::loncommon::start_data_table_row().
4753: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4754: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4755: }
1.484 raeburn 4756: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4757: }
1.484.2.19 raeburn 4758: $r->print(&endContentScreen());
1.329 droeschl 4759: }
4760:
1.484.2.85.2. (raeburn 4761:): sub short_urls {
4762:): my ($r,$canedit) = @_;
4763:): my $crstype = &Apache::loncommon::course_type();
4764:): my $formname = 'shortenurl';
4765:): $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4766:): $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4767:): $r->print(&startContentScreen('tools'));
4768:): my ($navmap,$errormsg) =
4769:): &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4770:): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4771:): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4772:): my (%maps,%resources,%titles);
4773:): if (!ref($navmap)) {
4774:): $r->print($errormsg.
4775:): &endContentScreen());
4776:): return '';
4777:): } else {
4778:): $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
4779:): $r->rflush();
4780:): my $readonly;
4781:): if ($canedit) {
4782:): my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
4783:): if ($numnew) {
4784:): $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4785:): }
4786:): if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4787:): $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4788:): foreach my $error (@{$errors}) {
4789:): $r->print('<li>'.$error.'</li>');
4790:): }
4791:): $r->print('</ul><br />');
4792:): }
4793:): } else {
4794:): $readonly = 1;
4795:): }
4796:): my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4797:): $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4798:): undef,undef,undef,undef,undef,\%currtiny,$readonly));
4799:): }
4800:): $r->print(&endContentScreen());
4801:): }
4802:):
1.484.2.78 raeburn 4803: sub contentverifyform {
4804: my ($r) = @_;
4805: my $crstype = &Apache::loncommon::course_type();
4806: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4807: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4808: $r->print(&startContentScreen('tools'));
4809: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4810: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4811: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4812: ' <span class="LC_nobreak">'.
4813: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4814: &mt('No').'</label>'.(' 'x2).
4815: '<label><input type="radio" name="checkstale" value="1" />'.
4816: &mt('Yes').'</label></span></p><p>'.
1.484.2.85.2. (raeburn 4817:): '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.484.2.78 raeburn 4818: '<input type="hidden" value="1" name="tools" />'.
4819: '<input type="hidden" value="1" name="verify" /></p></form>');
4820: $r->print(&endContentScreen());
4821: return;
4822: }
1.329 droeschl 4823:
4824: sub verifycontent {
1.484.2.78 raeburn 4825: my ($r,$checkstale) = @_;
1.408 raeburn 4826: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4827: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4828: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4829: $r->print(&startContentScreen('tools'));
4830: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4831: $hashtied=0;
4832: undef %alreadyseen;
4833: %alreadyseen=();
4834: &tiehash();
1.484 raeburn 4835:
1.329 droeschl 4836: foreach my $key (keys(%hash)) {
4837: if ($hash{$key}=~/\.(page|sequence)$/) {
4838: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4839: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4840: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4841: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4842: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4843: }
4844: }
4845: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4846: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4847: }
4848: }
4849: &untiehash();
1.442 www 4850: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4851: $r->print(&endContentScreen());
1.329 droeschl 4852: }
4853:
4854:
4855: sub devalidateversioncache {
4856: my $src=shift;
4857: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4858: &Apache::lonnet::clutter($src));
4859: }
4860:
4861: sub checkversions {
1.484.2.67 raeburn 4862: my ($r,$canedit) = @_;
1.408 raeburn 4863: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4864: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4865: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4866: $r->print(&startContentScreen('tools'));
1.442 www 4867:
1.329 droeschl 4868: my $header='';
4869: my $startsel='';
4870: my $monthsel='';
4871: my $weeksel='';
4872: my $daysel='';
4873: my $allsel='';
4874: my %changes=();
4875: my $starttime=0;
4876: my $haschanged=0;
4877: my %setversions=&Apache::lonnet::dump('resourceversions',
4878: $env{'course.'.$env{'request.course.id'}.'.domain'},
4879: $env{'course.'.$env{'request.course.id'}.'.num'});
4880:
4881: $hashtied=0;
4882: &tiehash();
1.484.2.67 raeburn 4883: if ($canedit) {
4884: my %newsetversions=();
4885: if ($env{'form.setmostrecent'}) {
4886: $haschanged=1;
4887: foreach my $key (keys(%hash)) {
4888: if ($key=~/^ids\_(\/res\/.+)$/) {
4889: $newsetversions{$1}='mostrecent';
4890: &devalidateversioncache($1);
4891: }
1.329 droeschl 4892: }
1.484.2.67 raeburn 4893: } elsif ($env{'form.setcurrent'}) {
4894: $haschanged=1;
4895: foreach my $key (keys(%hash)) {
4896: if ($key=~/^ids\_(\/res\/.+)$/) {
4897: my $getvers=&Apache::lonnet::getversion($1);
4898: if ($getvers>0) {
4899: $newsetversions{$1}=$getvers;
4900: &devalidateversioncache($1);
4901: }
4902: }
1.329 droeschl 4903: }
1.484.2.67 raeburn 4904: } elsif ($env{'form.setversions'}) {
4905: $haschanged=1;
4906: foreach my $key (keys(%env)) {
4907: if ($key=~/^form\.set_version_(.+)$/) {
4908: my $src=$1;
4909: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4910: $newsetversions{$src}=$env{$key};
4911: &devalidateversioncache($src);
4912: }
4913: }
1.329 droeschl 4914: }
1.484.2.67 raeburn 4915: }
4916: if ($haschanged) {
4917: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4918: $env{'course.'.$env{'request.course.id'}.'.domain'},
4919: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4920: $r->print(&Apache::loncommon::confirmwrapper(
4921: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4922: } else {
4923: $r->print(&Apache::loncommon::confirmwrapper(
4924: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4925: }
4926: &mark_hash_old();
4927: }
4928: &changewarning($r,'');
1.329 droeschl 4929: }
4930: if ($env{'form.timerange'} eq 'all') {
4931: # show all documents
1.484.2.34 raeburn 4932: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4933: $allsel=' selected="selected"';
1.329 droeschl 4934: foreach my $key (keys(%hash)) {
4935: if ($key=~/^ids\_(\/res\/.+)$/) {
4936: my $src=$1;
4937: $changes{$src}=1;
4938: }
4939: }
4940: } else {
4941: # show documents which changed
4942: %changes=&Apache::lonnet::dump
4943: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4944: $env{'course.'.$env{'request.course.id'}.'.num'});
4945: my $firstkey=(keys(%changes))[0];
4946: unless ($firstkey=~/^error\:/) {
4947: unless ($env{'form.timerange'}) {
4948: $env{'form.timerange'}=604800;
4949: }
4950: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4951: .&mt('seconds');
4952: if ($env{'form.timerange'}==-1) {
4953: $seltext='since start of course';
1.484.2.19 raeburn 4954: $startsel=' selected="selected"';
1.329 droeschl 4955: $env{'form.timerange'}=time;
4956: }
4957: $starttime=time-$env{'form.timerange'};
4958: if ($env{'form.timerange'}==2592000) {
4959: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4960: $monthsel=' selected="selected"';
1.329 droeschl 4961: } elsif ($env{'form.timerange'}==604800) {
4962: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4963: $weeksel=' selected="selected"';
1.329 droeschl 4964: } elsif ($env{'form.timerange'}==86400) {
4965: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4966: $daysel=' selected="selected"';
1.329 droeschl 4967: }
4968: $header=&mt('Content changed').' '.$seltext;
4969: } else {
4970: $header=&mt('No content modifications yet.');
4971: }
4972: }
4973: %setversions=&Apache::lonnet::dump('resourceversions',
4974: $env{'course.'.$env{'request.course.id'}.'.domain'},
4975: $env{'course.'.$env{'request.course.id'}.'.num'});
4976: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4977: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4978: 'lm' => 'Version changes since last Month',
4979: 'lw' => 'Version changes since last Week',
4980: 'sy' => 'Version changes since Yesterday',
4981: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4982: 'cd' => 'Change display',
1.329 droeschl 4983: 'sd' => 'Display',
4984: 'fi' => 'File',
4985: 'md' => 'Modification Date',
4986: 'mr' => 'Most recently published Version',
1.408 raeburn 4987: 've' => 'Version used in '.$crstype,
4988: 'vu' => 'Set Version to be used in '.$crstype,
4989: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4990: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4991: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4992: 'di' => 'Differences',
1.484 raeburn 4993: 'save' => 'Save changes',
4994: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4995: 'act' => 'Actions');
1.484.2.67 raeburn 4996: my ($disabled,$readonly);
4997: unless ($canedit) {
4998: $disabled = 'disabled="disabled"';
4999: $readonly = 1;
5000: }
1.329 droeschl 5001: $r->print(<<ENDHEADERS);
1.484 raeburn 5002: <h4 class="LC_info">$header</h4>
1.329 droeschl 5003: <form action="/adm/coursedocs" method="post">
5004: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5005: <div class="LC_left_float">
1.479 golterma 5006: <fieldset>
1.484 raeburn 5007: <legend>$lt{'cd'}</legend>
1.329 droeschl 5008: <select name="timerange">
1.484.2.19 raeburn 5009: <option value='all'$allsel>$lt{'al'}</option>
5010: <option value="-1"$startsel>$lt{'st'}</option>
5011: <option value="2592000"$monthsel>$lt{'lm'}</option>
5012: <option value="604800"$weeksel>$lt{'lw'}</option>
5013: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5014: </select>
5015: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5016: </fieldset>
5017: </div>
5018: <div class="LC_left_float">
5019: <fieldset>
5020: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 5021: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5022: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5023: </fieldset>
5024: </div>
5025: <br clear="all" />
5026: <hr />
5027: <h4>$lt{'vers'}</h4>
1.329 droeschl 5028: ENDHEADERS
1.479 golterma 5029: #number of columns for version history
1.484.2.44 raeburn 5030: my %changedbytime;
5031: foreach my $key (keys(%changes)) {
5032: #excludes not versionable problems from resource version history:
5033: next if ($key =~ /^\/res\/lib\/templates/);
5034: my $chg;
5035: if ($env{'form.timerange'} eq 'all') {
5036: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5037: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5038: } else {
5039: $chg = $changes{$key};
5040: next if ($chg < $starttime);
5041: }
5042: push(@{$changedbytime{$chg}},$key);
5043: }
5044: if (keys(%changedbytime) == 0) {
5045: &untiehash();
5046: $r->print(&mt('No content changes in imported content in specified time frame').
5047: &endContentScreen());
5048: return;
5049: }
1.479 golterma 5050: $r->print(
1.484.2.67 raeburn 5051: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5052: &Apache::loncommon::start_data_table().
5053: &Apache::loncommon::start_data_table_header_row().
5054: '<th>'.&mt('Resources').'</th>'.
5055: "<th>$lt{'mr'}</th>".
5056: "<th>$lt{'ve'}</th>".
5057: "<th>$lt{'vu'}</th>".
5058: '<th>'.&mt('History').'</th>'.
5059: &Apache::loncommon::end_data_table_header_row()
5060: );
1.484.2.44 raeburn 5061: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5062: foreach my $key (sort(@{$changedbytime{$chg}})) {
5063: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5064: my $currentversion=&Apache::lonnet::getversion($key);
5065: if ($currentversion<0) {
5066: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5067: }
5068: my $linkurl=&Apache::lonnet::clutter($key);
5069: $r->print(
5070: &Apache::loncommon::start_data_table_row().
5071: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5072: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5073: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5074: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5075: '<td align="right">'
5076: );
5077: # Used in course
5078: my $usedversion=$hash{'version_'.$linkurl};
5079: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 5080: if ($usedversion != $currentversion) {
1.479 golterma 5081: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 5082: } else {
1.479 golterma 5083: $r->print($usedversion);
5084: }
1.329 droeschl 5085: } else {
1.484.2.19 raeburn 5086: $r->print($currentversion);
1.329 droeschl 5087: }
1.484.2.44 raeburn 5088: $r->print('</td><td title="'.$lt{'vu'}.'">');
5089: # Set version
5090: $r->print(&Apache::loncommon::select_form(
5091: $setversions{$linkurl},
5092: 'set_version_'.$linkurl,
5093: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5094: '' => '',
5095: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 5096: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 5097: my $lastold=1;
5098: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5099: my $url=$root.'.'.$prevvers.'.'.$extension;
5100: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5101: $lastold=$prevvers;
5102: }
5103: }
5104: $r->print('</td>');
5105: # List all available versions
5106: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5107: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5108: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 5109: $r->print(
1.484.2.44 raeburn 5110: '<span class="LC_nobreak">'
5111: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5112: .&mt('Version [_1]',$prevvers).'</a>'
5113: .' ('.&Apache::lonlocal::locallocaltime(
5114: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5115: .')');
5116: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5117: $r->print(
5118: ' <a href="/adm/diff?filename='.
5119: &Apache::lonnet::clutter($root.'.'.$extension).
5120: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5121: '" target="diffs">'.&mt('Diffs').'</a>');
5122: }
5123: $r->print('</span><br />');
1.329 droeschl 5124: }
1.484.2.44 raeburn 5125: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 5126: }
1.329 droeschl 5127: }
1.484.2.19 raeburn 5128: $r->print(
5129: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 5130: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5131: '</form>'
5132: );
1.329 droeschl 5133:
5134: &untiehash();
1.484.2.19 raeburn 5135: $r->print(&endContentScreen());
1.484.2.44 raeburn 5136: return;
1.329 droeschl 5137: }
5138:
5139: sub mark_hash_old {
5140: my $retie_hash=0;
5141: if ($hashtied) {
5142: $retie_hash=1;
5143: &untiehash();
5144: }
5145: &tiehash('write');
5146: $hash{'old'}=1;
5147: &untiehash();
5148: if ($retie_hash) { &tiehash(); }
5149: }
5150:
5151: sub is_hash_old {
5152: my $untie_hash=0;
5153: if (!$hashtied) {
5154: $untie_hash=1;
5155: &tiehash();
5156: }
5157: my $return=$hash{'old'};
5158: if ($untie_hash) { &untiehash(); }
5159: return $return;
5160: }
5161:
5162: sub changewarning {
5163: my ($r,$postexec,$message,$url)=@_;
5164: if (!&is_hash_old()) { return; }
5165: my $pathvar='folderpath';
5166: my $path=&escape($env{'form.folderpath'});
5167: if (!defined($url)) {
5168: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5169: }
5170: my $course_type = &Apache::loncommon::course_type();
5171: if (!defined($message)) {
5172: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5173: }
5174: $r->print("\n\n".
1.372 bisitz 5175: '<script type="text/javascript">'."\n".
5176: '// <![CDATA['."\n".
5177: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5178: '// ]]>'."\n".
1.369 bisitz 5179: '</script>'."\n".
1.375 tempelho 5180: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5181: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5182: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5183: &mt($message,' <input type="hidden" name="'.
5184: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5185: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5186: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5187: }
5188:
5189:
5190: sub init_breadcrumbs {
1.484.2.44 raeburn 5191: my ($form,$text,$help)=@_;
1.329 droeschl 5192: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5193: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5194: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5195: faq=>273,
5196: bug=>'Instructor Interface',
1.484.2.44 raeburn 5197: help => $help});
1.329 droeschl 5198: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5199: text=>$text,
5200: faq=>273,
5201: bug=>'Instructor Interface'});
5202: }
5203:
1.441 www 5204: # subroutine to list form elements
5205: sub create_list_elements {
5206: my @formarr = @_;
5207: my $list = '';
1.484.2.12 raeburn 5208: foreach my $button (@formarr){
5209: foreach my $picture (keys(%{$button})) {
5210: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5211: }
5212: }
5213: return $list;
5214: }
1.329 droeschl 5215:
1.441 www 5216: # subroutine to create ul from list elements
5217: sub create_form_ul {
5218: my $list = shift;
5219: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5220: return $ul;
5221: }
1.329 droeschl 5222:
1.442 www 5223: #
5224: # Start tabs
5225: #
5226:
5227: sub startContentScreen {
1.484 raeburn 5228: my ($mode) = @_;
5229: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5230: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5231: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5232: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5233: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5234: } else {
1.484.2.34 raeburn 5235: $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 5236: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5237: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5238: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5239: }
5240: $output .= "\n".'</ul>'."\n";
5241: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5242: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5243: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5244: return $output;
1.442 www 5245: }
5246:
5247: #
5248: # End tabs
5249: #
5250:
5251: sub endContentScreen {
1.484 raeburn 5252: return '</div></div></div>';
1.442 www 5253: }
1.329 droeschl 5254:
1.446 www 5255: sub supplemental_base {
1.484.2.33 raeburn 5256: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5257: }
5258:
1.329 droeschl 5259: sub handler {
5260: my $r = shift;
5261: &Apache::loncommon::content_type($r,'text/html');
5262: $r->send_http_header;
5263: return OK if $r->header_only;
1.484 raeburn 5264:
5265: # get course data
1.408 raeburn 5266: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5267: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5268: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5269:
5270: # graphics settings
5271: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5272:
1.443 www 5273: #
1.329 droeschl 5274: # --------------------------------------------- Initialize help topics for this
5275: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.484.2.85.2. (raeburn 5276:): 'Adding_External_Resource','Adding_External_Tool',
5277:): 'Navigate_Content','Adding_Folders','Docs_Overview',
5278:): 'Load_Map','Supplemental','Score_Upload_Form',
5279:): 'Adding_Pages','Importing_LON-CAPA_Resource',
5280:): 'Importing_IMS_Course','Uploading_From_Harddrive',
5281:): 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5282: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5283: }
5284: # Composite help files
5285: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5286: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5287: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5288: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5289: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5290: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5291: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5292: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5293: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5294: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5295:
1.484.2.67 raeburn 5296: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 5297: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5298: unless ($r->uri eq '/adm/supplemental') {
5299: # does this user have privileges to modify content.
1.484.2.67 raeburn 5300: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5301: $allowed = 1;
5302: $canedit = 1;
5303: $canview = 1;
5304: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5305: $allowed = 1;
5306: $canview = 1;
5307: }
5308: }
5309: unless ($canedit) {
5310: $disabled = ' disabled="disabled"';
1.472 raeburn 5311: }
1.484.2.53 raeburn 5312: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5313: if ($env{'form.inhibitmenu'}) {
5314: unless ($env{'form.inhibitmenu'} eq 'yes') {
5315: delete($env{'form.inhibitmenu'});
5316: }
5317: }
5318:
1.484.2.53 raeburn 5319: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5320: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5321: if (!$canedit) {
5322: &verifycontent($r);
5323: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5324: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5325: text=>'Results',
5326: faq=>273,
5327: bug=>'Instructor Interface'});
5328: &verifycontent($r,$env{'form.checkstale'});
5329: } else {
5330: &contentverifyform($r);
5331: }
1.329 droeschl 5332: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5333: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5334: &list_symbs($r);
1.484.2.85.2. (raeburn 5335:): } elsif ($allowed && $env{'form.shorturls'}) {
5336:): &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5337:): &short_urls($r,$canedit);
1.329 droeschl 5338: } elsif ($allowed && $env{'form.docslog'}) {
5339: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5340: my $folder = $env{'form.folder'};
5341: if ($folder eq '') {
5342: $folder='default';
5343: }
1.484.2.67 raeburn 5344: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5345: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5346: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5347: &checkversions($r,$canedit);
5348: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5349: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5350: &dumpcourse($r);
5351: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5352: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5353: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5354: } else {
1.445 www 5355: #
5356: # Done catching special calls
1.484 raeburn 5357: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5358: # Get the parameters that may be needed
5359: #
5360: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5361: ['folderpath',
5362: 'forcesupplement','forcestandard',
5363: 'tools','symb','command','supppath']);
1.445 www 5364:
1.484.2.78 raeburn 5365: foreach my $item ('forcesupplement','forcestandard','tools') {
5366: next if ($env{'form.'.$item} eq '');
5367: unless ($env{'form.'.$item} eq '1') {
5368: delete($env{'form.'.$item});
5369: }
5370: }
5371:
5372: if ($env{'form.command'}) {
5373: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5374: delete($env{'form.command'});
5375: }
5376: }
5377:
5378: if ($env{'form.symb'}) {
5379: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5380: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5381: delete($env{'form.symb'});
5382: }
5383: }
5384:
1.445 www 5385: # standard=1: this is a "new-style" course with an uploaded map as top level
5386: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5387:
5388: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5389:
1.484 raeburn 5390: # Decide whether this should display supplemental or main content or utilities
1.445 www 5391: # supplementalflag=1: show supplemental documents
5392: # supplementalflag=0: show standard documents
1.484 raeburn 5393: # toolsflag=1: show utilities
1.445 www 5394:
1.484.2.39 raeburn 5395: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5396: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5397: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5398: $supplementalflag=0;
5399: }
5400: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5401: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5402: unless ($allowed) { $supplementalflag=1; }
5403: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5404: my $toolsflag=0;
5405: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5406:
1.484.2.78 raeburn 5407: if ($env{'form.folderpath'} ne '') {
1.484.2.85.2. (raeburn 5408:): &validate_folderpath($supplementalflag);
1.484.2.78 raeburn 5409: }
5410:
5411: if ($env{'form.supppath'} ne '') {
1.484.2.85.2. (raeburn 5412:): &validate_suppath();
1.484.2.78 raeburn 5413: }
5414:
1.329 droeschl 5415: my $script='';
5416: my $showdoc=0;
1.457 raeburn 5417: my $addentries = {};
1.475 raeburn 5418: my $container;
1.329 droeschl 5419: my $containertag;
1.484.2.17 raeburn 5420: my $pathitem;
1.484.2.85.2. (raeburn 5421:): my %ltitools;
1.484.2.67 raeburn 5422: my $hiddentop;
5423: my $navmap;
5424: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5425:
1.464 www 5426: # Do we directly jump somewhere?
1.484.2.21 raeburn 5427: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5428: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5429: $env{'form.folderpath'}=
1.484.2.67 raeburn 5430: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5431: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5432: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5433: } elsif ($env{'form.supppath'} ne '') {
5434: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5435: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5436: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5437: }
1.472 raeburn 5438: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5439: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5440: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5441: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5442: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5443: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5444: } elsif ($env{'form.command'} eq 'contents') {
5445: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5446: } elsif ($env{'form.command'} eq 'home') {
5447: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5448: }
5449:
1.484.2.23 raeburn 5450:
1.445 www 5451: # Where do we store these for when we come back?
5452: my $stored_folderpath='docs_folderpath';
5453: if ($supplementalflag) {
5454: $stored_folderpath='docs_sup_folderpath';
5455: }
1.464 www 5456:
1.484.2.19 raeburn 5457: # No folderpath, and in edit mode, see if we have something stored
5458: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5459: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5460: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5461:
5462: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5463: if ($supplementalflag) {
5464: undef($env{'form.folderpath'}) if ($1 eq 'default');
5465: } else {
5466: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5467: }
5468: } else {
1.484.2.19 raeburn 5469: undef($env{'form.folderpath'});
5470: }
1.484.2.85.2. (raeburn 5471:): if ($env{'form.folderpath'} ne '') {
5472:): &validate_folderpath($supplementalflag);
5473:): }
1.329 droeschl 5474: }
1.446 www 5475:
5476: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5477: if (!$allowed) {
1.446 www 5478: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5479: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5480: }
5481: }
1.446 www 5482: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5483: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5484: $env{'form.folderpath'} = &supplemental_base()
5485: .'&'.
1.329 droeschl 5486: $env{'form.folderpath'};
5487: }
1.484.2.67 raeburn 5488: # If allowed and user's role is not advanced check folderpath is not hidden
5489: if (($allowed) && (!$env{'request.role.adv'}) &&
5490: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5491: my $folderurl;
5492: my @pathitems = split(/\&/,$env{'form.folderpath'});
5493: my $folder = $pathitems[-2];
5494: if ($folder eq '') {
5495: undef($env{'form.folderpath'});
5496: } else {
5497: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.85.2. (raeburn 5498:): if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 5499: $folderurl .= '.page';
5500: } else {
5501: $folderurl .= '.sequence';
5502: }
5503: unless (ref($navmap)) {
5504: $navmap = Apache::lonnavmaps::navmap->new();
5505: }
5506: if (ref($navmap)) {
5507: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5508: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5509: unless (@resources) {
5510: undef($env{'form.folderpath'});
5511: }
5512: }
5513: }
5514: }
5515: }
5516:
5517:
1.446 www 5518: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5519: unless ($env{'form.folderpath'}) {
1.446 www 5520: if ($supplementalflag) {
5521: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5522: } elsif ($allowed) {
5523: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5524: }
1.472 raeburn 5525: }
1.446 www 5526:
1.445 www 5527: # Store this
1.484 raeburn 5528: unless ($toolsflag) {
1.484.2.67 raeburn 5529: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5530: &Apache::loncommon::store_course_settings($stored_folderpath,
5531: {'folderpath' => 'scalar'});
5532: }
5533: my $folderpath;
1.484 raeburn 5534: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5535: $folderpath = $env{'form.folderpath'};
5536: my (@folders)=split('&',$env{'form.folderpath'});
5537: $env{'form.foldername'}=&unescape(pop(@folders));
5538: if ($env{'form.foldername'} =~ /\:1$/) {
5539: $container = 'page';
5540: } else {
5541: $container = 'sequence';
5542: }
5543: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5544: } else {
1.484.2.19 raeburn 5545: if ($env{'form.folder'} eq '' ||
5546: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5547: if ($env{'form.folder'} eq 'supplemental') {
5548: $folderpath=&supplemental_base();
5549: } elsif (!$hiddentop) {
5550: $folderpath='default&'.
5551: &escape(&mt('Main Content').':::::');
5552: }
1.484 raeburn 5553: }
5554: }
1.484.2.19 raeburn 5555: $containertag = '<input type="hidden" name="folderpath" value="" />';
5556: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5557: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5558: $showdoc='/'.$1;
5559: }
5560: if ($showdoc) { # got called in sequence from course
5561: $allowed=0;
5562: } else {
1.484.2.67 raeburn 5563: if ($canedit) {
1.484 raeburn 5564: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5565: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5566: }
5567: }
1.329 droeschl 5568: }
5569:
1.344 bisitz 5570: # get personal data
1.329 droeschl 5571: my $uname=$env{'user.name'};
5572: my $udom=$env{'user.domain'};
5573: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5574:
5575: if ($allowed) {
1.484 raeburn 5576: if ($toolsflag) {
5577: $script .= &inject_data_js();
5578: my ($home,$other,%outhash)=&authorhosts();
5579: if (!$home && $other) {
5580: my @hosts;
5581: foreach my $aurole (keys(%outhash)) {
5582: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5583: push(@hosts,$outhash{$aurole});
5584: }
5585: }
5586: $script .= &dump_switchserver_js(@hosts);
5587: }
1.458 raeburn 5588: } else {
1.484.2.43 raeburn 5589: my $tid = 1;
1.484 raeburn 5590: my @tabids;
5591: if ($supplementalflag) {
5592: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5593: $tid = 2;
1.484 raeburn 5594: } else {
5595: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5596: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5597: unshift(@tabids,'001');
5598: push(@tabids,('dd1','ee1'));
5599: }
1.458 raeburn 5600: }
1.484 raeburn 5601: my $tabidstr = join("','",@tabids);
1.484.2.85.2. (raeburn 5602:): %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
5603:): my $posslti = keys(%ltitools);
1.484.2.80 raeburn 5604: my $hostname = $r->hostname();
1.484.2.85.2. (raeburn 5605:): $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 5606: $canedit,$hostname,\$navmap).
1.484 raeburn 5607: &history_tab_js().
5608: &inject_data_js().
1.484.2.43 raeburn 5609: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.85.2. (raeburn 5610:): &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5611: $addentries = {
1.484.2.3 raeburn 5612: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5613: };
1.458 raeburn 5614: }
1.484.2.30 raeburn 5615: $script .= &paste_popup_js();
1.484.2.12 raeburn 5616: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5617: &mt('Switch server?');
1.484.2.19 raeburn 5618:
5619:
1.329 droeschl 5620: }
5621: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5622: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5623: .'// <![CDATA['."\n"
5624: .$script."\n"
5625: .'// ]]>'."\n"
1.484.2.81 raeburn 5626: .'</script>'."\n"
5627: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5628:
5629: # Breadcrumbs
5630: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5631:
5632: if ($showdoc) {
5633: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5634: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5635: } elsif ($toolsflag) {
1.484.2.67 raeburn 5636: my ($breadtext,$breadtitle);
5637: $breadtext = "$crstype Editor";
5638: if ($canedit) {
5639: $breadtitle = 'Editing '.$crstype.' Contents';
5640: } else {
5641: $breadtext .= ' (View-only mode)';
5642: $breadtitle = 'Viewing '.$crstype.' Contents';
5643: }
1.484.2.44 raeburn 5644: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5645: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5646: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5647: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5648: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5649: $breadtitle)
1.484.2.44 raeburn 5650: );
1.484.2.19 raeburn 5651: } elsif ($r->uri eq '/adm/supplemental') {
5652: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5653: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5654: {'bread_crumbs' => $brcrum,}));
5655: } else {
1.484.2.67 raeburn 5656: my ($breadtext,$breadtitle,$helpitem);
5657: $breadtext = "$crstype Editor";
5658: if ($canedit) {
5659: $breadtitle = 'Editing '.$crstype.' Contents';
5660: $helpitem = 'Docs_Adding_Course_Doc';
5661: } else {
5662: $breadtext .= ' (View-only mode)';
5663: $breadtitle = 'Viewing '.$crstype.' Contents';
5664: $helpitem = 'Docs_Viewing_Course_Doc';
5665: }
1.392 raeburn 5666: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5667: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5668: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5669: {'add_entries' => $addentries}
5670: )
1.392 raeburn 5671: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5672: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5673: $breadtitle,
5674: $helpitem)
1.392 raeburn 5675: );
5676: }
1.364 bisitz 5677:
1.329 droeschl 5678: my %allfiles = ();
5679: my %codebase = ();
1.440 raeburn 5680: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5681: if ($canedit) {
1.329 droeschl 5682: if (($env{'form.uploaddoc.filename'}) &&
5683: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5684: my $context = $1;
5685: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5686: undef($hadchanges);
1.440 raeburn 5687: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5688: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5689: undef($navmap);
1.329 droeschl 5690: if ($hadchanges) {
5691: &mark_hash_old();
5692: }
1.440 raeburn 5693: $r->print($upload_output);
5694: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5695: # Process file upload - phase two - upload embedded objects
5696: $uploadphase = 'check_embedded';
5697: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5698: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5699: $env{'form.newidx'});
5700: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5701: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5702: my ($destination,$dir_root) = &embedded_destination();
5703: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5704: my $actionurl = '/adm/coursedocs';
5705: my ($result,$flag) =
5706: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5707: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5708: $actionurl);
5709: $r->print($result.&return_to_editor());
5710: } elsif ($env{'form.phase'} eq 'check_embedded') {
5711: # Process file upload - phase three - modify references in HTML file
5712: $uploadphase = 'modified_orightml';
5713: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5714: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5715: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5716: my $result =
5717: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5718: $docuname,$docudom,undef,
5719: $dir_root);
5720: $r->print($result.&return_to_editor());
1.476 raeburn 5721: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5722: $uploadphase = 'decompress_phase_one';
5723: $r->print(&decompression_phase_one().
5724: &return_to_editor());
5725: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5726: $uploadphase = 'decompress_phase_two';
5727: $r->print(&decompression_phase_two().
5728: &return_to_editor());
1.329 droeschl 5729: }
5730: }
5731:
1.484 raeburn 5732: if ($allowed && $toolsflag) {
5733: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5734: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5735: $r->print(&endContentScreen());
5736: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5737: # -----------------------------------------------------------------------------
5738: my %lt=&Apache::lonlocal::texthash(
5739: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5740: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5741: 'upld' => 'Upload Content',
1.329 droeschl 5742: 'srch' => 'Search',
5743: 'impo' => 'Import',
1.484.2.19 raeburn 5744: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5745: 'impm' => 'Import from Assembled Map',
1.484.2.85.2. (raeburn 5746:): 'extr' => 'External Resource',
5747:): 'extt' => 'External Tool',
1.329 droeschl 5748: 'selm' => 'Select Map',
5749: 'load' => 'Load Map',
5750: 'newf' => 'New Folder',
5751: 'newp' => 'New Composite Page',
5752: 'syll' => 'Syllabus',
1.425 raeburn 5753: 'navc' => 'Table of Contents',
1.343 biermanm 5754: 'sipa' => 'Simple Course Page',
1.329 droeschl 5755: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5756: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5757: 'drbx' => 'Drop Box',
1.451 www 5758: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5759: 'bull' => 'Discussion Board',
1.347 weissno 5760: 'mypi' => 'My Personal Information Page',
1.353 weissno 5761: 'grpo' => 'Group Portfolio',
1.329 droeschl 5762: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5763: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5764: 'imsf' => 'IMS Upload',
5765: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5766: 'cms' => 'Origin of IMS package',
5767: 'se' => 'Select',
1.484.2.19 raeburn 5768: 'file' => 'File',
1.329 droeschl 5769: 'title' => 'Title',
5770: 'comment' => 'Comment',
1.403 raeburn 5771: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5772: 'bb5' => 'Blackboard 5',
5773: 'bb6' => 'Blackboard 6',
5774: 'angel5' => 'ANGEL 5.5',
5775: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5776: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5777: );
1.329 droeschl 5778: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5779: # Calculate free quota space for a user or course. A javascript function checks
5780: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5781: my $quotatype = 'unofficial';
5782: if ($crstype eq 'Community') {
5783: $quotatype = 'community';
5784: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5785: $quotatype = 'official';
5786: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5787: $quotatype = 'textbook';
5788: }
5789: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5790: 'course',$quotatype); # expressed in MB
5791: my $current_disk_usage = 0;
5792: foreach my $subdir ('docs','supplemental') {
5793: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5794: "userfiles/$subdir",1); # expressed in kB
5795: }
5796: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5797: my $usage = $current_disk_usage/1024; # in MB
5798: my $quota = $disk_quota;
5799: my $percent;
5800: if ($disk_quota == 0) {
5801: $percent = 100.0;
5802: } else {
1.484.2.69 raeburn 5803: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5804: }
5805: $usage = sprintf("%.2f",$usage);
5806: $quota = sprintf("%.2f",$quota);
5807: $percent = sprintf("%.0f",$percent);
5808: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5809: $percent.'%',$quota.' MB').'</p>';
5810:
1.329 droeschl 5811: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5812: $quotainfo
1.329 droeschl 5813: $lt{'file'}:<br />
1.484.2.81 raeburn 5814: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
5815: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5816: FIUP
5817:
5818: my $checkbox=(<<CHBO);
5819: <!-- <label>$lt{'parse'}?
5820: <input type="checkbox" name="parserflag" />
5821: </label> -->
5822: <label>
1.484.2.67 raeburn 5823: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5824: </label>
5825: CHBO
1.484.2.12 raeburn 5826: my $imsfolder = $env{'form.folder'};
5827: if ($imsfolder eq '') {
1.484.2.19 raeburn 5828: $imsfolder = 'default';
1.484.2.12 raeburn 5829: }
5830: my $imspform=(<<IMSFORM);
5831: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5832: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5833: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5834: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5835: <legend>$lt{'imsf'}</legend>
5836: $fileupload
5837: <br />
5838: <p>
1.484.2.19 raeburn 5839: $lt{'cms'}:
1.484.2.67 raeburn 5840: <select name="source" $disabled>
1.484.2.12 raeburn 5841: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5842: <option value="bb5">$lt{'bb5'}</option>
5843: <option value="bb6">$lt{'bb6'}</option>
5844: <option value="angel5">$lt{'angel5'}</option>
5845: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5846: </select>
5847: <input type="hidden" name="folder" value="$imsfolder" />
5848: </p>
5849: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5850: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5851: </fieldset>
5852: </form>
5853: IMSFORM
5854:
1.484.2.19 raeburn 5855: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5856: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5857: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5858: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5859: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5860: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5861: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5862: $fileupload
5863: <br />
5864: $lt{'title'}:<br />
1.484.2.67 raeburn 5865: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5866: $pathitem
1.329 droeschl 5867: <input type="hidden" name="cmd" value="upload_default" />
5868: <br />
1.458 raeburn 5869: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5870: $checkbox
5871: </span>
1.484.2.12 raeburn 5872: <br clear="all" />
1.484.2.67 raeburn 5873: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5874: </fieldset>
5875: </form>
1.383 tempelho 5876: FUFORM
1.329 droeschl 5877:
1.484.2.67 raeburn 5878: my $mapimportjs;
5879: if ($canedit) {
5880: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5881: } else {
5882: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5883: }
1.484.2.19 raeburn 5884: my $importpubform=(<<SEDFFORM);
5885: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5886: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5887: <form action="/adm/coursedocs" method="post" name="mapimportform">
5888: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5889: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5890: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5891: $lt{'copm'}<br />
5892: <span class="LC_nobreak">
1.484.2.19 raeburn 5893: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5894: onfocus="this.blur();$mapimportjs" $disabled />
5895: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5896: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5897: </fieldset>
5898: </form>
5899:
1.383 tempelho 5900: SEDFFORM
1.484.2.67 raeburn 5901:
5902: my $fromstoredjs;
5903: if ($canedit) {
5904: $fromstoredjs = 'open_StoredLinks_Import()';
5905: } else {
5906: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5907: }
5908:
1.484.2.19 raeburn 5909: my @importpubforma = (
5910: { '<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 5911: { '<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 5912: { '<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 5913: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5914: );
5915: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5916: my $extresourcesform =
5917: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5918: $help{'Adding_External_Resource'},
1.484.2.85.2. (raeburn 5919:): undef,undef,undef,undef,undef,undef,$disabled);
5920:): my $exttoolform =
5921:): &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5922:): $help{'Adding_External_Tool'},undef,
5923:): undef,'tool',$coursedom,$coursenum,
5924:): \%ltitools,$disabled);
1.329 droeschl 5925: if ($allowed) {
1.484.2.7 raeburn 5926: my $folder = $env{'form.folder'};
5927: if ($folder eq '') {
5928: $folder='default';
5929: }
1.484.2.67 raeburn 5930: if ($canedit) {
5931: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5932: if ($output) {
5933: $r->print($output);
5934: }
1.484.2.30 raeburn 5935: }
1.337 ehlerst 5936: $r->print(<<HIDDENFORM);
5937: <form name="renameform" method="post" action="/adm/coursedocs">
5938: <input type="hidden" name="title" />
5939: <input type="hidden" name="cmd" />
5940: <input type="hidden" name="markcopy" />
5941: <input type="hidden" name="copyfolder" />
5942: $containertag
5943: </form>
1.484 raeburn 5944:
1.337 ehlerst 5945: HIDDENFORM
1.484.2.17 raeburn 5946: $r->print(&makesimpleeditform($pathitem)."\n".
5947: &makedocslogform($pathitem."\n".
1.484 raeburn 5948: '<input type="hidden" name="folder" value="'.
5949: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5950: }
1.442 www 5951:
5952: # Generate the tabs
1.484.2.19 raeburn 5953: my ($mode,$needs_end);
1.472 raeburn 5954: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5955: my @folders = split('&',$env{'form.folderpath'});
5956: unless (@folders > 2) {
5957: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5958: $needs_end = 1;
5959: }
1.472 raeburn 5960: } else {
1.484 raeburn 5961: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5962: $needs_end = 1;
1.472 raeburn 5963: }
1.443 www 5964:
1.442 www 5965: #
5966:
5967: my $savefolderpath;
1.484.2.85.2. (raeburn 5968:): my $hostname = $r->hostname();
1.442 www 5969:
1.395 raeburn 5970: if ($allowed) {
1.329 droeschl 5971: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5972: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5973: $folder='default';
1.356 tempelho 5974: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5975: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5976: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5977: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5978: }
5979: my $postexec='';
5980: if ($folder eq 'default') {
1.372 bisitz 5981: $r->print('<script type="text/javascript">'."\n"
5982: .'// <![CDATA['."\n"
5983: .'this.window.name="loncapaclient";'."\n"
5984: .'// ]]>'."\n"
5985: .'</script>'."\n"
1.369 bisitz 5986: );
1.329 droeschl 5987: } else {
5988: #$postexec='self.close();';
5989: }
1.484.2.15 raeburn 5990: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5991: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5992: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5993:
5994: my $newnavform=(<<NNFORM);
5995: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5996: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5997: $pathitem
1.329 droeschl 5998: <input type="hidden" name="importdetail"
5999: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 6000: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6001: $help{'Navigate_Content'}
6002: </form>
6003: NNFORM
6004: my $newsmppageform=(<<NSPFORM);
6005: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 6006: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6007: $pathitem
1.329 droeschl 6008: <input type="hidden" name="importdetail" value="" />
1.423 onken 6009: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6010: $help{'Simple Page'}
1.329 droeschl 6011: </form>
6012: NSPFORM
6013:
6014: my $newsmpproblemform=(<<NSPROBFORM);
6015: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 6016: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6017: $pathitem
1.329 droeschl 6018: <input type="hidden" name="importdetail" value="" />
1.423 onken 6019: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 6020: $help{'Simple_Problem'}
1.329 droeschl 6021: </form>
6022:
6023: NSPROBFORM
6024:
6025: my $newdropboxform=(<<NDBFORM);
6026: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 6027: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6028: $pathitem
1.329 droeschl 6029: <input type="hidden" name="importdetail" value="" />
1.423 onken 6030: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 6031: $help{'Dropbox'}
1.344 bisitz 6032: </form>
1.329 droeschl 6033: NDBFORM
6034:
6035: my $newexuploadform=(<<NEXUFORM);
6036: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 6037: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6038: $pathitem
1.329 droeschl 6039: <input type="hidden" name="importdetail" value="" />
1.423 onken 6040: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6041: $help{'Score_Upload_Form'}
6042: </form>
6043: NEXUFORM
6044:
6045: my $newbulform=(<<NBFORM);
6046: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 6047: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6048: $pathitem
1.329 droeschl 6049: <input type="hidden" name="importdetail" value="" />
1.423 onken 6050: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6051: $help{'Bulletin Board'}
6052: </form>
6053: NBFORM
6054:
6055: my $newaboutmeform=(<<NAMFORM);
6056: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 6057: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6058: $pathitem
1.329 droeschl 6059: <input type="hidden" name="importdetail"
6060: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6061: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6062: $help{'My Personal Information Page'}
1.329 droeschl 6063: </form>
6064: NAMFORM
6065:
6066: my $newaboutsomeoneform=(<<NASOFORM);
6067: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 6068: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6069: $pathitem
1.329 droeschl 6070: <input type="hidden" name="importdetail" value="" />
1.423 onken 6071: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6072: </form>
6073: NASOFORM
6074:
6075: my $newrosterform=(<<NROSTFORM);
6076: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 6077: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6078: $pathitem
1.329 droeschl 6079: <input type="hidden" name="importdetail"
6080: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 6081: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 6082: $help{'Course_Roster'}
1.329 droeschl 6083: </form>
6084: NROSTFORM
6085:
1.484.2.27 raeburn 6086: my $newwebpage;
6087: if ($folder =~ /^default_?(\d*)$/) {
6088: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6089: if ($1) {
6090: $newwebpage .= $1;
6091: } else {
6092: $newwebpage .= 'default';
6093: }
6094: $newwebpage .= '/new.html';
6095: }
6096: my $newwebpageform =(<<NWEBFORM);
6097: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 6098: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 6099: $pathitem
6100: <input type="hidden" name="importdetail" value="$newwebpage" />
6101: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 6102: $help{'Web_Page'}
1.484.2.27 raeburn 6103: </form>
6104: NWEBFORM
1.484.2.30 raeburn 6105:
1.484.2.27 raeburn 6106:
1.342 ehlerst 6107: my $specialdocumentsform;
1.383 tempelho 6108: my @specialdocumentsforma;
1.451 www 6109: my $gradingform;
6110: my @gradingforma;
6111: my $communityform;
6112: my @communityforma;
1.351 ehlerst 6113: my $newfolderform;
1.390 tempelho 6114: my $newfolderb;
1.342 ehlerst 6115:
1.451 www 6116: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6117:
1.329 droeschl 6118: my $newpageform=(<<NPFORM);
6119: <form action="/adm/coursedocs" method="post" name="newpage">
6120: <input type="hidden" name="folderpath" value="$path" />
6121: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6122: <input type="hidden" name="active" value="ee" />
1.423 onken 6123: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6124: $help{'Adding_Pages'}
1.329 droeschl 6125: </form>
6126: NPFORM
1.390 tempelho 6127:
6128:
1.351 ehlerst 6129: $newfolderform=(<<NFFORM);
1.329 droeschl 6130: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 6131: $pathitem
1.329 droeschl 6132: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6133: <input type="hidden" name="active" value="" />
1.422 onken 6134: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6135: </form>
6136: NFFORM
6137:
6138: my $newsylform=(<<NSYLFORM);
6139: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 6140: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6141: $pathitem
1.329 droeschl 6142: <input type="hidden" name="importdetail"
6143: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6144: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6145: $help{'Syllabus'}
1.383 tempelho 6146:
1.329 droeschl 6147: </form>
6148: NSYLFORM
1.364 bisitz 6149:
1.329 droeschl 6150: my $newgroupfileform=(<<NGFFORM);
6151: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 6152: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6153: $pathitem
1.329 droeschl 6154: <input type="hidden" name="importdetail"
6155: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 6156: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6157: $help{'Group Portfolio'}
1.329 droeschl 6158: </form>
6159: NGFFORM
1.484.2.85.2. (raeburn 6160:): if ($container eq 'page') {
6161:): @specialdocumentsforma=(
6162:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6163:): );
6164:): } else {
6165:): @specialdocumentsforma=(
1.421 onken 6166: {'<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 6167: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6168: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6169: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 6170: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.484.2.85.2. (raeburn 6171:): );
6172:): }
1.451 www 6173: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6174:
1.434 raeburn 6175:
6176: my @importdoc = (
1.484.2.19 raeburn 6177: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6178: );
1.484.2.85.2. (raeburn 6179:): if (keys(%ltitools)) {
6180:): push(@importdoc,
6181:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6182:): );
6183:): }
1.484.2.19 raeburn 6184: unless ($container eq 'page') {
6185: push(@importdoc,
6186: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6187: );
6188: }
6189: push(@importdoc,
1.484.2.38 raeburn 6190: {'<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 6191: );
1.484.2.12 raeburn 6192: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6193:
1.451 www 6194: @gradingforma=(
6195: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6196: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6197: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6198:
6199: );
6200: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6201:
6202: @communityforma=(
6203: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6204: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6205: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 6206: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6207: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6208: );
6209: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6210:
1.330 tempelho 6211: my %orderhash = (
1.484.2.36 raeburn 6212: 'aa' => ['Upload',$fileuploadform],
6213: 'bb' => ['Import',$importpubform],
6214: 'cc' => ['Grading',$gradingform],
1.484.2.85.2. (raeburn 6215:): 'ee' => ['Other',$specialdocumentsform],
1.330 tempelho 6216: );
1.484.2.19 raeburn 6217: unless ($container eq 'page') {
1.434 raeburn 6218: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6219: $orderhash{'dd'} = ['Collaboration',$communityform];
1.434 raeburn 6220: }
6221:
1.341 ehlerst 6222: $hadchanges=0;
1.484 raeburn 6223: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6224: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6225: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.85.2. (raeburn 6226:): \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 6227: undef($navmap);
1.443 www 6228: if ($error) {
6229: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6230: }
6231: if ($hadchanges) {
1.484.2.73 raeburn 6232: unless (&is_hash_old()) {
6233: &mark_hash_old();
6234: }
1.443 www 6235: }
1.341 ehlerst 6236:
1.443 www 6237: &changewarning($r,'');
6238: }
1.458 raeburn 6239: }
1.442 www 6240:
1.443 www 6241: # Supplemental documents start here
6242:
1.329 droeschl 6243: my $folder=$env{'form.folder'};
1.443 www 6244: unless ($supplementalflag) {
1.329 droeschl 6245: $folder='supplemental';
6246: }
6247: if ($folder =~ /^supplemental$/ &&
6248: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6249: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6250: } elsif ($allowed) {
1.356 tempelho 6251: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6252: }
1.484.2.17 raeburn 6253: $pathitem = '<input type="hidden" name="folderpath" value="'.
6254: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6255: if ($allowed) {
6256: my $folderseq=
1.484.2.15 raeburn 6257: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6258:
6259: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 6260: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6261: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6262: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6263: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6264: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6265: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6266: $fileupload
6267: <br />
6268: <br />
6269: <span class="LC_nobreak">
6270: $checkbox
6271: </span>
6272: <br /><br />
6273: $lt{'comment'}:<br />
1.383 tempelho 6274: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6275: <br />
1.484.2.19 raeburn 6276: $pathitem
1.329 droeschl 6277: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6278: <input type='submit' value="$lt{'upld'}" />
6279: </form>
1.484.2.19 raeburn 6280: SUPDOCFORM
1.329 droeschl 6281:
6282: my $supnewfolderform=(<<SNFFORM);
6283: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6284: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6285: $pathitem
1.329 droeschl 6286: <input type="hidden" name="importdetail" value="" />
1.423 onken 6287: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6288: $help{'Adding_Folders'}
1.329 droeschl 6289: </form>
6290: SNFFORM
1.383 tempelho 6291:
1.484.2.19 raeburn 6292: my $supextform =
6293: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6294: $help{'Adding_External_Resource'},
6295: undef,undef,$disabled);
1.484.2.85.2. (raeburn 6296:): my $supexttoolform =
6297:): &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6298:): $help{'Adding_External_Tool'},
6299:): undef,undef,'tool',$coursedom,
6300:): $coursenum,\%ltitools,$disabled);
1.329 droeschl 6301:
6302: my $supnewsylform=(<<SNSFORM);
6303: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6304: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6305: $pathitem
1.329 droeschl 6306: <input type="hidden" name="importdetail"
6307: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6308: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6309: $help{'Syllabus'}
6310: </form>
6311: SNSFORM
6312:
6313: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6314: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6315: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6316: $pathitem
1.329 droeschl 6317: <input type="hidden" name="importdetail"
6318: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6319: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6320: $help{'My Personal Information Page'}
1.329 droeschl 6321: </form>
6322: SNAMFORM
6323:
1.484.2.27 raeburn 6324: my $supwebpage;
6325: if ($folder =~ /^supplemental_?(\d*)$/) {
6326: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6327: if ($1) {
6328: $supwebpage .= $1;
6329: } else {
6330: $supwebpage .= 'default';
6331: }
6332: $supwebpage .= '/new.html';
6333: }
6334: my $supwebpageform =(<<SWEBFORM);
6335: <form action="/adm/coursedocs" method="post" name="supwebpage">
6336: <input type="hidden" name="active" value="cc" />
6337: $pathitem
6338: <input type="hidden" name="importdetail" value="$supwebpage" />
6339: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6340: $help{'Web_Page'}
1.484.2.27 raeburn 6341: </form>
6342: SWEBFORM
6343:
1.333 muellerd 6344:
1.383 tempelho 6345: my @specialdocs = (
1.484.2.67 raeburn 6346: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6347: =>$supnewsylform},
1.484.2.67 raeburn 6348: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6349: =>$supnewaboutmeform},
1.484.2.27 raeburn 6350: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6351:
1.383 tempelho 6352: );
1.417 droeschl 6353: my @supimportdoc = (
1.484.2.19 raeburn 6354: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.85.2. (raeburn 6355:): =>$supextform});
6356:): if (keys(%ltitools)) {
6357:): push(@supimportdoc,
6358:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6359:): =>$supexttoolform});
6360:): }
6361:): push(@supimportdoc,
1.484.2.12 raeburn 6362: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6363: =>$supupdocform},
1.484.2.85.2. (raeburn 6364:): );
1.484.2.19 raeburn 6365:
1.484.2.12 raeburn 6366: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6367: my %suporderhash = (
1.390 tempelho 6368: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6369: 'ee' => ['Upload',$supupdocform],
6370: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6371: );
1.443 www 6372: if ($supplementalflag) {
1.458 raeburn 6373: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6374: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.484.2.85.2. (raeburn 6375:): \%ltitools,$canedit,$hostname);
1.443 www 6376: if ($error) {
6377: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6378: } else {
6379: if ($suppchanges) {
6380: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6381: my @ids=&Apache::lonnet::current_machine_ids();
6382: foreach my $server (keys(%servers)) {
6383: next if (grep(/^\Q$server\E$/,@ids));
6384: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6385: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6386: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6387: }
6388: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6389: undef($suppchanges);
6390: }
1.443 www 6391: }
1.393 raeburn 6392: }
1.443 www 6393: } elsif ($supplementalflag) {
1.458 raeburn 6394: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.85 raeburn 6395: $supplementalflag,'',$iconpath,$pathitem,'',$hostname);
1.393 raeburn 6396: if ($error) {
6397: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6398: }
1.393 raeburn 6399: }
1.389 tempelho 6400:
1.484.2.19 raeburn 6401: if ($needs_end) {
6402: $r->print(&endContentScreen());
6403: }
1.383 tempelho 6404:
1.329 droeschl 6405: if ($allowed) {
6406: $r->print('
6407: <form method="post" name="extimport" action="/adm/coursedocs">
6408: <input type="hidden" name="title" />
6409: <input type="hidden" name="url" />
6410: <input type="hidden" name="useform" />
6411: <input type="hidden" name="residx" />
6412: </form>');
6413: }
1.484 raeburn 6414: } elsif ($showdoc) {
1.329 droeschl 6415: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6416: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6417: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6418: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6419: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6420: }
6421: }
6422: $r->print(&Apache::loncommon::end_page());
6423: return OK;
1.364 bisitz 6424: }
1.329 droeschl 6425:
1.440 raeburn 6426: sub embedded_form_elems {
6427: my ($phase,$primaryurl,$newidx) = @_;
6428: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6429: $newidx =~s /\D+//g;
1.440 raeburn 6430: return <<STATE;
6431: <input type="hidden" name="folderpath" value="$folderpath" />
6432: <input type="hidden" name="cmd" value="upload_embedded" />
6433: <input type="hidden" name="newidx" value="$newidx" />
6434: <input type="hidden" name="phase" value="$phase" />
6435: <input type="hidden" name="primaryurl" value="$primaryurl" />
6436: STATE
6437: }
6438:
6439: sub embedded_destination {
6440: my $folder=$env{'form.folder'};
6441: my $destination = 'docs/';
6442: if ($folder =~ /^supplemental/) {
6443: $destination = 'supplemental/';
6444: }
6445: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6446: $destination .= 'default/';
6447: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6448: $destination .= $2.'/';
6449: }
1.484.2.78 raeburn 6450: my $newidx = $env{'form.newidx'};
6451: $newidx =~s /\D+//g;
6452: if ($newidx) {
6453: $destination .= $newidx;
6454: }
1.440 raeburn 6455: my $dir_root = '/userfiles';
6456: return ($destination,$dir_root);
6457: }
6458:
6459: sub return_to_editor {
6460: my $actionurl = '/adm/coursedocs';
6461: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6462: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6463: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6464: '</a></p>';
6465: }
6466:
1.476 raeburn 6467: sub decompression_info {
6468: my ($destination,$dir_root) = &embedded_destination();
6469: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6470: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6471: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6472: my $container='sequence';
1.480 raeburn 6473: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6474: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6475: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6476: $container='page';
6477: }
1.480 raeburn 6478: unshift(@hiddens,$pathitem);
6479: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6480: if ($item eq 'newidx') {
6481: next if ($env{'form.'.$item} =~ /\D/);
6482: }
1.480 raeburn 6483: if ($env{'form.'.$item}) {
6484: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6485: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6486: }
1.477 raeburn 6487: }
1.476 raeburn 6488: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6489: $hiddenelem);
6490: }
6491:
6492: sub decompression_phase_one {
6493: my ($dir,$file,$warning,$error,$output);
6494: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6495: &decompression_info();
1.484.2.7 raeburn 6496: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6497: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6498: } else {
6499: my $file = $1;
1.481 raeburn 6500: $output =
6501: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6502: $destination,$dir_root,
6503: $hiddenelem);
6504: if ($env{'form.autoextract_camtasia'}) {
6505: $output .= &remove_archive($docudom,$docuname,$container);
6506: }
1.476 raeburn 6507: }
6508: if ($error) {
6509: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6510: $error.'</p>'."\n";
6511: }
6512: if ($warning) {
6513: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6514: }
6515: return $output;
6516: }
6517:
6518: sub decompression_phase_two {
6519: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6520: &decompression_info();
1.481 raeburn 6521: my $output;
1.480 raeburn 6522: if ($env{'form.archivedelete'}) {
1.481 raeburn 6523: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6524: }
6525: $output .=
1.481 raeburn 6526: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6527: $destination,$dir_root,$hiddenelem);
6528: return $output;
6529: }
6530:
1.480 raeburn 6531: sub remove_archive {
6532: my ($docudom,$docuname,$container) = @_;
6533: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6534: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6535: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6536: if ($fatal) {
6537: if ($container eq 'page') {
6538: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6539: } else {
6540: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6541: }
1.484.2.54 raeburn 6542: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6543: } else {
6544: my $currcmd = $env{'form.cmd'};
6545: my $position = $env{'form.position'};
1.484.2.54 raeburn 6546: my $archiveidx = $position;
6547: if ($position > 0) {
6548: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6549: $archiveidx = $position-1;
6550: }
6551: $env{'form.cmd'} = 'remove_'.$archiveidx;
6552: my ($title,$url,@rrest) =
6553: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6554: if ($url eq $env{'form.archiveurl'}) {
6555: if (&handle_edit_cmd($docuname,$docudom)) {
6556: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6557: if ($fatal) {
6558: if ($container eq 'page') {
6559: $delwarning = &mt('An error occurred updating the contents of the current page.');
6560: } else {
6561: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6562: }
1.480 raeburn 6563: } else {
1.484.2.54 raeburn 6564: $delresult = &mt('Archive file removed.');
1.480 raeburn 6565: }
6566: }
1.484.2.54 raeburn 6567: } else {
6568: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6569: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6570: }
6571: }
6572: $env{'form.cmd'} = $currcmd;
6573: }
6574: if ($delwarning) {
6575: $output = '<p class="LC_warning">'.
6576: $delwarning.
6577: '</p>';
6578: }
6579: if ($delresult) {
6580: $output .= '<p class="LC_info">'.
6581: $delresult.
6582: '</p>';
6583: }
1.481 raeburn 6584: return $output;
1.480 raeburn 6585: }
6586:
1.484 raeburn 6587: sub generate_admin_menu {
1.484.2.67 raeburn 6588: my ($crstype,$canedit) = @_;
1.484 raeburn 6589: my $lc_crstype = lc($crstype);
6590: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6591: my %lt= ( # do not translate here
1.484 raeburn 6592: 'vc' => 'Verify Content',
6593: 'cv' => 'Check/Set Resource Versions',
6594: 'ls' => 'List Resource Identifiers',
1.484.2.85.2. (raeburn 6595:): 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 6596: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6597: 'dcd' => "Copy $crstype Content to Authoring Space",
6598: );
1.484 raeburn 6599: my ($candump,$dumpurl);
6600: if ($home + $other > 0) {
6601: $candump = 'F';
6602: if ($home) {
6603: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6604: } else {
6605: my @hosts;
6606: foreach my $aurole (keys(%outhash)) {
6607: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6608: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6609: }
1.484 raeburn 6610: }
6611: if (@hosts == 1) {
6612: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6613: '&role='.
6614: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6615: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6616: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6617: } else {
6618: $dumpurl = "javascript:choose_switchserver_window()";
6619: }
6620: }
6621: }
6622: my @menu=
6623: ({ categorytitle=>'Administration',
6624: items =>[
6625: { linktext => $lt{'vc'},
6626: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6627: permission => 'F',
1.484.2.44 raeburn 6628: help => 'Docs_Verify_Content',
1.484 raeburn 6629: icon => 'verify.png',
6630: linktitle => 'Verify contents can be retrieved/rendered',
6631: },
6632: { linktext => $lt{'cv'},
6633: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6634: permission => 'F',
1.484.2.44 raeburn 6635: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6636: icon => 'resversion.png',
6637: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6638: },
6639: { linktext => $lt{'ls'},
6640: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6641: permission => 'F',
6642: #help => '',
6643: icon => 'symbs.png',
6644: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6645: },
1.484.2.85.2. (raeburn 6646:): { linktext => $lt{'ct'},
6647:): url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
6648:): permission => 'F',
6649:): help => 'Docs_Short_URLs',
6650:): icon => 'shorturls.png',
6651:): linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
6652:): },
1.484 raeburn 6653: ]
1.484.2.67 raeburn 6654: });
6655: if ($canedit) {
6656: push(@menu,
1.484 raeburn 6657: { categorytitle=>'Export',
6658: items =>[
6659: { linktext => $lt{'imse'},
6660: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6661: permission => 'F',
6662: help => 'Docs_Export_Course_Docs',
6663: icon => 'imsexport.png',
6664: linktitle => $lt{'imse'},
6665: },
6666: { linktext => $lt{'dcd'},
6667: url => $dumpurl,
6668: permission => $candump,
1.484.2.44 raeburn 6669: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6670: icon => 'dump.png',
6671: linktitle => $lt{'dcd'},
6672: },
6673: ]
6674: });
1.484.2.67 raeburn 6675: }
1.484 raeburn 6676: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6677: '<input type="hidden" id="dummy" />'."\n".
6678: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6679: '</form>';
1.329 droeschl 6680: }
6681:
6682: sub generate_edit_table {
1.484.2.30 raeburn 6683: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6684: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6685: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6686: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6687: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6688: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6689: $activetab = $env{'form.active'};
6690: }
1.484.2.67 raeburn 6691: unless ($canedit) {
6692: $disabled = ' disabled="disabled"';
6693: }
1.472 raeburn 6694: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6695: my $backtext = &mt('Exit Editor');
1.458 raeburn 6696: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6697: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6698: '<li class="goback">'.
1.484.2.32 raeburn 6699: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6700: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6701: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6702: '<li>'.
6703: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6704: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6705: if ($env{'form.docslog'}) {
6706: $form .= '<li class="active">';
6707: } else {
6708: $form .= '<li>';
6709: }
6710: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6711: &mt('History').'</a></li>'."\n";
6712: if ($env{'form.docslog'}) {
6713: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6714: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6715: }
1.458 raeburn 6716: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6717: if($name ne '00'){
1.371 tempelho 6718: if($activetab eq '' || $activetab ne $name){
6719: $active = '';
6720: }elsif($activetab eq $name){
6721: $active = 'class="active"';
6722: }
1.458 raeburn 6723: $form .= '<li style="float:right" '.$active
1.484 raeburn 6724: .' 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 6725: } else {
1.484.2.43 raeburn 6726: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6727:
6728: }
1.329 droeschl 6729: }
1.484 raeburn 6730: $form .= '</ul>'."\n";
6731: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6732:
6733: if ($to_show ne '') {
1.484.2.30 raeburn 6734: my $saveform;
6735: if ($need_save) {
6736: my $button = &mt('Make changes');
6737: my $path;
6738: if ($env{'form.folderpath'}) {
6739: $path =
6740: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6741: }
6742: $saveform = <<"END";
6743: <div id="multisave" style="display:none; clear:both;" >
6744: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6745: <input type="hidden" name="folderpath" value="$path" />
6746: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6747: <input type="hidden" name="allhiddenresource" value="" />
6748: <input type="hidden" name="allencrypturl" value="" />
6749: <input type="hidden" name="allrandompick" value="" />
6750: <input type="hidden" name="allrandomorder" value="" />
6751: <input type="hidden" name="changeparms" value="" />
6752: <input type="hidden" name="multiremove" value="" />
6753: <input type="hidden" name="multicut" value="" />
6754: <input type="hidden" name="multicopy" value="" />
6755: <input type="hidden" name="multichange" value="" />
6756: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6757: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6758: </form>
6759: </div>
6760: END
6761: }
6762: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6763: }
1.363 ehlerst 6764: foreach my $field (keys(%orderhash)){
1.390 tempelho 6765: if($field ne '00'){
1.422 onken 6766: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6767: $active = 'style="display: none;float:left"';
1.422 onken 6768: }elsif($activetab eq $field){
1.458 raeburn 6769: $active = 'style="display:block;float:left"';
1.422 onken 6770: }
6771: $form .= '<div id="'.$field.$tid.'"'
6772: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6773: .'</div>'."\n";
1.363 ehlerst 6774: }
6775: }
1.484 raeburn 6776: unless ($env{'form.docslog'}) {
6777: $form .= '</div></div>'."\n";
6778: }
1.329 droeschl 6779: return $form;
6780: }
6781:
6782: sub editing_js {
1.484.2.85.2. (raeburn 6783:): my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 6784: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6785: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6786: p_mnf => 'Name of New Folder',
6787: t_mnf => 'New Folder',
6788: p_mnp => 'Name of New Page',
6789: t_mnp => 'New Page',
1.451 www 6790: p_mxu => 'Title for the External Score',
1.349 biermanm 6791: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6792: p_msb => 'Title for the Problem',
6793: p_mdb => 'Title for the Drop Box',
1.336 schafran 6794: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6795: p_mwp => 'Title for Web Page',
1.348 weissno 6796: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6797: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6798: p_mab_alrt1 => 'Not a valid user:domain',
6799: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6800: p_chn => 'New Title',
6801: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6802: p_rmr2a => 'Remove',
6803: p_rmr2b => '?',
6804: p_rmr3a => 'Remove those',
6805: p_rmr3b => 'items?',
6806: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6807: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6808: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6809: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6810: p_ctr2a => 'Cut',
6811: p_ctr2b => '?',
6812: p_ctr3a => 'Cut those',
6813: p_ctr3b => 'items?',
1.478 raeburn 6814: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6815: imsfile => 'You must choose an IMS package for import',
6816: imscms => 'You must select which Course Management System was the source of the IMS package',
6817: invurl => 'Invalid URL',
6818: titbl => 'Title is blank',
1.484.2.30 raeburn 6819: more => '(More ...)',
6820: less => '(Less ...)',
6821: noor => 'No actions selected or changes to settings specified.',
6822: noch => 'No changes to settings specified.',
6823: noac => 'No actions selected.',
1.484.2.67 raeburn 6824: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6825: );
6826:
1.484.2.61 raeburn 6827: &js_escape(\%js_lt);
1.433 raeburn 6828: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6829: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6830: my $main_container_page;
1.484.2.19 raeburn 6831: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6832: $main_container_page = 1;
1.434 raeburn 6833: }
1.484.2.67 raeburn 6834: my $backtourl;
6835: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6836: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6837:
1.484.2.21 raeburn 6838: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6839: my $caller = $1;
6840: if ($caller =~ /^supplemental/) {
6841: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6842: } else {
6843: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6844: $res = &Apache::lonnet::clutter($res);
6845: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6846: my ($url,$anchor);
6847: if ($res =~ /^([^#]+)#([^#]+)$/) {
6848: $url = $1;
6849: $anchor = $2;
6850: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6851: $caller = $1.&escape('#').$anchor;
6852: }
1.484.2.67 raeburn 6853: } else {
6854: $url = $res;
1.484.2.66 raeburn 6855: }
1.484.2.83 raeburn 6856: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
6857: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
6858: $backtourl .= '?navmap=1';
6859: } else {
6860: $backtourl .= '?symb='.
6861: &HTML::Entities::encode($caller,'<>&"');
6862: }
1.484.2.80 raeburn 6863: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6864: if (($ENV{'SERVER_PORT'} == 443) &&
6865: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6866: unless (&Apache::lonnet::uses_sts()) {
6867: if ($hostname ne '') {
6868: $backtourl = 'http://'.$hostname.$backtourl;
6869: }
6870: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6871: }
6872: }
6873: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6874: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
6875: unless (&Apache::lonnet::uses_sts()) {
6876: if ($hostname ne '') {
6877: $backtourl = 'http://'.$hostname.$backtourl;
6878: }
6879: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6880: }
6881: }
6882: }
1.484.2.66 raeburn 6883: if ($anchor ne '') {
6884: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6885: }
1.484.2.57 raeburn 6886: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6887: } else {
6888: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6889: }
6890: }
6891: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6892: $backtourl = '/adm/menu';
6893: } elsif ($supplementalflag) {
1.472 raeburn 6894: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6895: } else {
6896: $backtourl = '/adm/navmaps';
1.472 raeburn 6897: }
6898:
1.484.2.19 raeburn 6899: my $fieldsets = "'ext','doc'";
1.484.2.85.2. (raeburn 6900:): if ($posslti) {
6901:): $fieldsets .= ",'tool'";
6902:): }
1.484.2.19 raeburn 6903: unless ($main_container_page) {
6904: $fieldsets .=",'ims'";
6905: }
1.484.2.12 raeburn 6906: if ($supplementalflag) {
6907: $fieldsets = "'suppext','suppdoc'";
1.484.2.85.2. (raeburn 6908:): if ($posslti) {
6909:): $fieldsets .= ",'supptool'";
6910:): }
1.484.2.12 raeburn 6911: }
6912:
1.484.2.67 raeburn 6913: my $jsmakefunctions;
6914: if ($canedit) {
6915: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6916: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6917: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6918: if (foldername) {
1.484.2.85.2. (raeburn 6919:): targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 6920: targetform.submit();
6921: }
6922: }
6923:
6924: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6925: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6926: if (pagename) {
1.484.2.85.2. (raeburn 6927:): targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 6928: targetform.submit();
6929: }
6930: }
6931:
6932: function makeexamupload() {
1.484.2.61 raeburn 6933: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6934: if (title) {
1.329 droeschl 6935: this.document.forms.newexamupload.importdetail.value=
1.484.2.85.2. (raeburn 6936:): encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 6937: this.document.forms.newexamupload.submit();
6938: }
6939: }
6940:
6941: function makesmppage() {
1.484.2.61 raeburn 6942: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6943: if (title) {
1.329 droeschl 6944: this.document.forms.newsmppg.importdetail.value=
1.484.2.85.2. (raeburn 6945:): encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6946: this.document.forms.newsmppg.submit();
6947: }
6948: }
6949:
1.484.2.27 raeburn 6950: function makewebpage(type) {
1.484.2.61 raeburn 6951: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6952: var formname;
6953: if (type == 'supp') {
6954: formname = this.document.forms.supwebpage;
6955: } else {
6956: formname = this.document.forms.newwebpage;
6957: }
6958: if (title) {
6959: var webpage = formname.importdetail.value;
1.484.2.85.2. (raeburn 6960:): formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.484.2.27 raeburn 6961: formname.submit();
6962: }
6963: }
6964:
1.329 droeschl 6965: function makesmpproblem() {
1.484.2.61 raeburn 6966: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6967: if (title) {
1.329 droeschl 6968: this.document.forms.newsmpproblem.importdetail.value=
1.484.2.85.2. (raeburn 6969:): encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 6970: this.document.forms.newsmpproblem.submit();
6971: }
6972: }
6973:
6974: function makedropbox() {
1.484.2.61 raeburn 6975: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6976: if (title) {
1.329 droeschl 6977: this.document.forms.newdropbox.importdetail.value=
1.484.2.85.2. (raeburn 6978:): encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 6979: this.document.forms.newdropbox.submit();
6980: }
6981: }
6982:
6983: function makebulboard() {
1.484.2.61 raeburn 6984: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6985: if (title) {
6986: this.document.forms.newbul.importdetail.value=
1.484.2.85.2. (raeburn 6987:): encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6988: this.document.forms.newbul.submit();
6989: }
6990: }
6991:
6992: function makeabout() {
1.484.2.61 raeburn 6993: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6994: if (user) {
6995: var comp=new Array();
6996: comp=user.split(':');
6997: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6998: if ((comp[0]) && (comp[1])) {
6999: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 7000: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 7001: this.document.forms.newaboutsomeone.submit();
7002: } else {
7003: alert("$js_lt{'p_mab_alrt1'}");
7004: }
7005: } else {
7006: alert("$js_lt{'p_mab_alrt2'}");
7007: }
7008: }
1.335 ehlerst 7009: }
1.484.2.67 raeburn 7010:
7011: function makenew(targetform) {
7012: targetform.submit();
1.335 ehlerst 7013: }
1.484.2.67 raeburn 7014:
7015: function changename(folderpath,index,oldtitle) {
7016: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7017: if (title) {
7018: this.document.forms.renameform.markcopy.value='';
7019: this.document.forms.renameform.title.value=title;
7020: this.document.forms.renameform.cmd.value='rename_'+index;
7021: this.document.forms.renameform.folderpath.value=folderpath;
7022: this.document.forms.renameform.submit();
7023: }
1.329 droeschl 7024: }
7025:
1.484.2.67 raeburn 7026: ENDNEWSCRIPT
7027: } else {
7028: $jsmakefunctions = <<ENDNEWSCRIPT;
7029:
7030: function makenewfolder() {
7031: alert("$js_lt{'edri'}");
7032: }
7033:
7034: function makenewpage() {
7035: alert("$js_lt{'edri'}");
7036: }
7037:
7038: function makeexamupload() {
7039: alert("$js_lt{'edri'}");
7040: }
7041:
7042: function makesmppage() {
7043: alert("$js_lt{'edri'}");
7044: }
7045:
7046: function makewebpage(type) {
7047: alert("$js_lt{'edri'}");
7048: }
7049:
7050: function makesmpproblem() {
7051: alert("$js_lt{'edri'}");
7052: }
7053:
7054: function makedropbox() {
7055: alert("$js_lt{'edri'}");
7056: }
7057:
7058: function makebulboard() {
7059: alert("$js_lt{'edri'}");
7060: }
7061:
7062: function makeabout() {
7063: alert("$js_lt{'edri'}");
7064: }
7065:
7066: function changename() {
7067: alert("$js_lt{'edri'}");
7068: }
7069:
7070: function makenew() {
7071: alert("$js_lt{'edri'}");
7072: }
7073:
7074: function groupimport() {
7075: alert("$js_lt{'edri'}");
7076: }
7077:
7078: function groupsearch() {
7079: alert("$js_lt{'edri'}");
7080: }
7081:
7082: function groupopen(url,recover) {
7083: var options="scrollbars=1,resizable=1,menubar=0";
7084: idxflag=1;
7085: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7086: idx.focus();
7087: }
7088:
7089: ENDNEWSCRIPT
7090:
7091: }
7092: return <<ENDSCRIPT;
7093:
7094: $jsmakefunctions
7095:
1.484.2.13 raeburn 7096: function toggleUpload(caller) {
7097: var blocks = Array($fieldsets);
7098: for (var i=0; i<blocks.length; i++) {
7099: var disp = 'none';
7100: if (caller == blocks[i]) {
7101: var curr = document.getElementById('upload'+caller+'form').style.display;
7102: if (curr == 'none') {
7103: disp='block';
7104: }
7105: }
7106: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.484.2.85.2. (raeburn 7107:): if ((caller == 'tool') || (caller == 'supptool')) {
7108:): if (disp == 'block') {
7109:): if (document.getElementById('LC_exttoolid')) {
7110:): var toolselector = document.getElementById('LC_exttoolid');
7111:): var suppflag = 0;
7112:): if (caller == 'supptool') {
7113:): suppflag = 1;
7114:): }
7115:): currForm = document.getElementById('new'+caller);
7116:): updateExttool(toolselector,currForm,suppflag);
7117:): }
7118:): }
7119:): }
1.484.2.13 raeburn 7120: }
7121: resize_scrollbox('contentscroll','1','1');
7122: return;
7123: }
7124:
1.484.2.19 raeburn 7125: function toggleMap(caller) {
1.484.2.13 raeburn 7126: var disp = 'none';
1.484.2.19 raeburn 7127: if (document.getElementById('importmapform')) {
7128: if (caller == 'map') {
7129: var curr = document.getElementById('importmapform').style.display;
7130: if (curr == 'none') {
7131: disp='block';
7132: }
1.484.2.12 raeburn 7133: }
1.484.2.19 raeburn 7134: document.getElementById('importmapform').style.display=disp;
7135: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 7136: }
1.484.2.19 raeburn 7137: return;
1.329 droeschl 7138: }
7139:
1.484.2.12 raeburn 7140: function makeims(imsform) {
7141: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 7142: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 7143: return;
7144: }
7145: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 7146: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 7147: return;
7148: }
7149: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7150: imsform.submit();
7151: }
7152:
1.478 raeburn 7153: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 7154: var pickitem;
7155: var picknumitem;
7156: var picknumtext;
7157: if (index == 'all') {
7158: pickitem = document.getElementById('randompickall');
7159: picknumitem = document.getElementById('rpicknumall');
7160: picknumtext = document.getElementById('rpicktextall');
7161: } else {
7162: pickitem = document.getElementById('randompick_'+index);
7163: picknumitem = document.getElementById('rpicknum_'+index);
7164: picknumtext = document.getElementById('randompicknum_'+index);
7165: }
1.478 raeburn 7166: if (pickitem.checked) {
1.484.2.61 raeburn 7167: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7168: if (picknum == '' || picknum == null) {
7169: if (caller == 'check') {
7170: pickitem.checked=false;
1.484.2.29 raeburn 7171: if (index == 'all') {
7172: picknumtext.innerHTML = '';
7173: if (caller == 'link') {
7174: propagateState(targetform,'rpicknum');
7175: }
7176: } else {
1.484.2.30 raeburn 7177: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7178: }
1.478 raeburn 7179: }
7180: } else {
7181: picknum.toString();
7182: var regexdigit=/^\\d+\$/;
7183: if (regexdigit.test(picknum)) {
7184: picknumitem.value = picknum;
1.484.2.29 raeburn 7185: if (index == 'all') {
1.484.2.30 raeburn 7186: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 7187: if (caller == 'link') {
7188: propagateState(targetform,'rpicknum');
7189: }
7190: } else {
7191: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 7192: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7193: }
1.478 raeburn 7194: } else {
7195: if (caller == 'check') {
1.484.2.29 raeburn 7196: if (index == 'all') {
7197: picknumtext.innerHTML = '';
7198: if (caller == 'link') {
7199: propagateState(targetform,'rpicknum');
7200: }
7201: } else {
7202: pickitem.checked=false;
1.484.2.30 raeburn 7203: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7204: }
1.478 raeburn 7205: }
7206: return;
7207: }
7208: }
7209: } else {
1.484.2.29 raeburn 7210: picknumitem.value = '';
7211: picknumtext.innerHTML = '';
7212: if (index == 'all') {
7213: if (caller == 'link') {
7214: propagateState(targetform,'rpicknum');
7215: }
7216: } else {
1.484.2.30 raeburn 7217: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7218: }
7219: }
7220: }
7221:
7222: function propagateState(form,param) {
7223: if (document.getElementById(param+'all')) {
7224: var setcheck = 0;
7225: var rpick = 0;
7226: if (param == 'rpicknum') {
7227: if (document.getElementById('randompickall')) {
7228: if (document.getElementById('randompickall').checked) {
7229: if (document.getElementById('rpicknumall')) {
7230: rpick = document.getElementById('rpicknumall').value;
7231: }
7232: }
7233: }
7234: } else {
7235: if (document.getElementById(param+'all').checked) {
7236: setcheck = 1;
7237: }
7238: }
1.484.2.30 raeburn 7239: var allidxlist;
7240: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7241: if (document.getElementById('all'+param+'idx')) {
7242: allidxlist = document.getElementById('all'+param+'idx').value;
7243: }
7244: var actions = new Array ('remove','cut','copy');
7245: for (var i=0; i<actions.length; i++) {
7246: if (actions[i] != param) {
7247: if (document.getElementById(actions[i]+'all')) {
7248: document.getElementById(actions[i]+'all').checked = false;
7249: }
7250: }
7251: }
7252: }
1.484.2.29 raeburn 7253: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 7254: allidxlist = form.allidx.value;
7255: }
7256: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7257: allidxlist = form.allmapidx.value;
7258: }
7259: if ((allidxlist != '') && (allidxlist != null)) {
7260: var allidxs = allidxlist.split(',');
7261: if (allidxs.length > 1) {
7262: for (var i=0; i<allidxs.length; i++) {
7263: if (document.getElementById(param+'_'+allidxs[i])) {
7264: if (param == 'rpicknum') {
7265: if (document.getElementById('randompick_'+allidxs[i])) {
7266: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7267: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7268: if (rpick > 0) {
7269: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7270: } else {
7271: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7272: }
7273: }
7274: }
7275: } else {
1.484.2.29 raeburn 7276: if (setcheck == 1) {
7277: document.getElementById(param+'_'+allidxs[i]).checked = true;
7278: } else {
7279: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 7280: if (param == 'randompick') {
7281: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7282: }
1.484.2.29 raeburn 7283: }
7284: }
7285: }
7286: }
1.484.2.30 raeburn 7287: if (setcheck == 1) {
7288: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7289: var actions = new Array('copy','cut','remove');
7290: for (var i=0; i<actions.length; i++) {
7291: var otheractions;
7292: var otheridxs;
7293: if (actions[i] === param) {
7294: continue;
7295: } else {
7296: if (document.getElementById('all'+actions[i]+'idx')) {
7297: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7298: otheridxs = otheractions.split(',');
7299: if (otheridxs.length > 1) {
7300: for (var j=0; j<otheridxs.length; j++) {
7301: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7302: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7303: }
1.484.2.29 raeburn 7304: }
7305: }
7306: }
7307: }
1.484.2.30 raeburn 7308: }
1.484.2.29 raeburn 7309: }
7310: }
7311: }
7312: }
1.478 raeburn 7313: }
1.484.2.29 raeburn 7314: return;
7315: }
7316:
1.484.2.63 raeburn 7317: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7318: var canedit = '$canedit';
7319: if (canedit == '') {
7320: alert("$js_lt{'edri'}");
7321: return;
7322: }
1.484.2.30 raeburn 7323: var dosettings;
7324: var doaction;
7325: var control = document.togglemultsettings;
7326: if (context == 'actions') {
7327: control = document.togglemultactions;
7328: doaction = 1;
7329: } else {
7330: dosettings = 1;
7331: }
7332: if (control) {
7333: if (control.showmultpick.length) {
7334: for (var i=0; i<control.showmultpick.length; i++) {
7335: if (control.showmultpick[i].checked) {
7336: if (control.showmultpick[i].value == 1) {
7337: if (context == 'settings') {
7338: dosettings = 0;
7339: } else {
7340: doaction = 0;
7341: }
7342: }
7343: }
7344: }
7345: }
7346: }
7347: if (context == 'settings') {
7348: if (dosettings == 1) {
7349: targetform.changeparms.value=param;
7350: targetform.submit();
7351: }
7352: }
7353: if (context == 'actions') {
7354: if (doaction == 1) {
7355: targetform.cmd.value=param+'_'+index;
7356: targetform.folderpath.value=folderpath;
7357: targetform.markcopy.value=idx+':'+param;
7358: targetform.copyfolder.value=folder+'.'+container;
7359: if (param == 'remove') {
1.484.2.63 raeburn 7360: var doremove = 0;
7361: if (skip_confirm) {
7362: if (confirm_removal) {
7363: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7364: doremove = 1;
7365: }
7366: } else {
7367: doremove = 1;
7368: }
7369: } else {
7370: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7371: doremove = 1;
7372: }
7373: }
7374: if (doremove) {
1.484.2.30 raeburn 7375: targetform.markcopy.value='';
7376: targetform.copyfolder.value='';
1.484.2.29 raeburn 7377: targetform.submit();
7378: }
7379: }
1.484.2.30 raeburn 7380: if (param == 'cut') {
1.484.2.61 raeburn 7381: 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 7382: targetform.submit();
7383: return;
7384: }
7385: }
7386: if (param == 'copy') {
7387: targetform.submit();
7388: return;
7389: }
7390: targetform.markcopy.value='';
7391: targetform.copyfolder.value='';
7392: targetform.cmd.value='';
7393: targetform.folderpath.value='';
7394: return;
7395: } else {
7396: if (document.getElementById(param+'_'+idx)) {
7397: item = document.getElementById(param+'_'+idx);
7398: if (item.type == 'checkbox') {
7399: if (item.checked) {
7400: item.checked = false;
7401: } else {
7402: item.checked = true;
7403: singleCheck(item,idx,param);
7404: }
7405: }
7406: }
7407: }
7408: }
7409: return;
7410: }
7411:
7412: function singleCheck(caller,idx,action) {
7413: actions = new Array('cut','copy','remove');
7414: if (caller.checked) {
7415: for (var i=0; i<actions.length; i++) {
7416: if (actions[i] != action) {
7417: if (document.getElementById(actions[i]+'_'+idx)) {
7418: if (document.getElementById(actions[i]+'_'+idx).checked) {
7419: document.getElementById(actions[i]+'_'+idx).checked = false;
7420: }
7421: }
7422: }
1.484.2.29 raeburn 7423: }
7424: }
7425: return;
1.478 raeburn 7426: }
7427:
1.334 muellerd 7428: function unselectInactive(nav) {
1.335 ehlerst 7429: currentNav = document.getElementById(nav);
7430: currentLis = currentNav.getElementsByTagName('LI');
7431: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7432: if (currentLis[i].className == 'goback') {
7433: currentLis[i].className = 'goback';
7434: } else {
7435: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7436: currentLis[i].className = 'right';
1.472 raeburn 7437: } else {
1.374 tempelho 7438: currentLis[i].className = 'i';
1.472 raeburn 7439: }
7440: }
1.335 ehlerst 7441: }
1.332 tempelho 7442: }
7443:
1.334 muellerd 7444: function hideAll(current, nav, data) {
1.335 ehlerst 7445: unselectInactive(nav);
1.484.2.43 raeburn 7446: if (current) {
7447: if (current.className == 'right'){
1.374 tempelho 7448: current.className = 'right active'
1.484.2.43 raeburn 7449: } else {
1.374 tempelho 7450: current.className = 'active';
1.484.2.43 raeburn 7451: }
1.374 tempelho 7452: }
1.335 ehlerst 7453: currentData = document.getElementById(data);
7454: currentDivs = currentData.getElementsByTagName('DIV');
7455: for (i = 0; i < currentDivs.length; i++) {
7456: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7457: currentDivs[i].style.display = 'none';
1.330 tempelho 7458: }
7459: }
1.335 ehlerst 7460: }
1.330 tempelho 7461:
1.374 tempelho 7462: function openTabs(pageId) {
7463: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7464: if(tabnav.length > 2 ){
1.389 tempelho 7465: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7466: currentLis = currentNav.getElementsByTagName('LI');
7467: for(i = 0; i< currentLis.length; i++){
7468: if(currentLis[i].className == 'active') {
1.375 tempelho 7469: funcString = currentLis[i].onclick.toString();
7470: tab = funcString.split('"');
1.420 onken 7471: if(tab.length < 2) {
7472: tab = funcString.split("'");
7473: }
1.375 tempelho 7474: currentData = document.getElementById(tab[1]);
7475: currentData.style.display = 'block';
1.374 tempelho 7476: }
7477: }
7478: }
7479: }
7480:
1.334 muellerd 7481: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7482: currstate = current.className;
1.334 muellerd 7483: hideAll(current, nav, data);
1.375 tempelho 7484: openTabs(pageId);
1.334 muellerd 7485: unselectInactive(nav);
1.484.2.43 raeburn 7486: if ((currstate == 'active') || (currstate == 'right active')) {
7487: if (currstate == 'active') {
7488: current.className = '';
7489: } else {
7490: current.className = 'right';
7491: }
7492: activeTab = '';
7493: toggleUpload();
7494: toggleMap();
7495: resize_scrollbox('contentscroll','1','0');
7496: return;
7497: } else {
7498: current.className = 'active';
7499: }
1.330 tempelho 7500: currentData = document.getElementById(pageId);
7501: currentData.style.display = 'block';
1.458 raeburn 7502: activeTab = pageId;
1.484.2.12 raeburn 7503: toggleUpload();
1.484.2.14 raeburn 7504: toggleMap();
1.433 raeburn 7505: if (nav == 'mainnav') {
7506: var storedpath = "$docs_folderpath";
1.434 raeburn 7507: var storedpage = "$main_container_page";
1.433 raeburn 7508: var reg = new RegExp("^supplemental");
7509: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7510: if (storedpage == 1) {
7511: document.simpleedit.folderpath.value = '';
7512: document.uploaddocument.folderpath.value = '';
7513: } else {
7514: if (reg.test(storedpath)) {
7515: document.simpleedit.folderpath.value = '$toplevelmain';
7516: document.uploaddocument.folderpath.value = '$toplevelmain';
7517: document.newext.folderpath.value = '$toplevelmain';
7518: } else {
7519: document.simpleedit.folderpath.value = storedpath;
7520: document.uploaddocument.folderpath.value = storedpath;
7521: document.newext.folderpath.value = storedpath;
7522: }
1.433 raeburn 7523: }
7524: } else {
1.434 raeburn 7525: if (reg.test(storedpath)) {
7526: document.simpleedit.folderpath.value = storedpath;
7527: document.supuploaddocument.folderpath.value = storedpath;
7528: document.supnewext.folderpath.value = storedpath;
7529: } else {
1.433 raeburn 7530: document.simpleedit.folderpath.value = '$toplevelsupp';
7531: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7532: document.supnewext.folderpath.value = '$toplevelsupp';
7533: }
7534: }
7535: }
1.484.2.3 raeburn 7536: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7537: return false;
7538: }
1.329 droeschl 7539:
1.472 raeburn 7540: function toContents(jumpto) {
7541: var newurl = '$backtourl';
1.484.2.21 raeburn 7542: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7543: newurl = newurl+'?postdata='+jumpto;
7544: }
7545: location.href=newurl;
7546: }
7547:
1.484.2.30 raeburn 7548: function togglePick(caller,value) {
7549: var disp = 'none';
7550: if (document.getElementById('multi'+caller)) {
7551: var curr = document.getElementById('multi'+caller).style.display;
7552: if (value == 1) {
7553: disp='block';
7554: }
7555: if (curr == disp) {
7556: return;
7557: }
7558: document.getElementById('multi'+caller).style.display=disp;
7559: if (value == 1) {
1.484.2.61 raeburn 7560: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7561: } else {
7562: document.getElementById('more'+caller).innerHTML = '';
7563: }
7564: if (caller == 'actions') {
7565: setClass(value);
7566: setBoxes(value);
7567: }
7568: }
7569: var showButton = multiSettings();
7570: if (showButton != 1) {
7571: showButton = multiActions();
7572: }
7573: if (document.getElementById('multisave')) {
7574: if (showButton == 1) {
7575: document.getElementById('multisave').style.display='block';
7576: } else {
7577: document.getElementById('multisave').style.display='none';
7578: }
7579: }
7580: resize_scrollbox('contentscroll','1','1');
7581: return;
7582: }
7583:
7584: function toggleCheckUncheck(caller,more) {
7585: if (more == 1) {
1.484.2.61 raeburn 7586: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7587: document.getElementById('allfields'+caller).style.display='block';
7588: } else {
1.484.2.61 raeburn 7589: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7590: document.getElementById('allfields'+caller).style.display='none';
7591: }
7592: resize_scrollbox('contentscroll','1','1');
7593: }
7594:
7595: function multiSettings() {
7596: var inuse = 0;
7597: var settingsform = document.togglemultsettings;
7598: if (settingsform.showmultpick.length > 1) {
7599: for (var i=0; i<settingsform.showmultpick.length; i++) {
7600: if (settingsform.showmultpick[i].checked) {
7601: if (settingsform.showmultpick[i].value == 1) {
7602: inuse = 1;
7603: }
7604: }
7605: }
7606: }
7607: return inuse;
7608: }
7609:
7610: function multiActions() {
7611: var inuse = 0;
7612: var actionsform = document.togglemultactions;
7613: if (actionsform.showmultpick.length > 1) {
7614: for (var i=0; i<actionsform.showmultpick.length; i++) {
7615: if (actionsform.showmultpick[i].checked) {
7616: if (actionsform.showmultpick[i].value == 1) {
7617: inuse = 1;
7618: }
7619: }
7620: }
7621: }
7622: return inuse;
7623: }
7624:
7625: function checkSubmits() {
7626: var numchanges = 0;
7627: var form = document.saveactions;
7628: var doactions = multiActions();
7629: var cutwarnings = 0;
7630: var remwarnings = 0;
1.484.2.63 raeburn 7631: var removalinfo = 0;
1.484.2.30 raeburn 7632: if (doactions == 1) {
7633: var remidxlist = document.cumulativeactions.allremoveidx.value;
7634: if ((remidxlist != '') && (remidxlist != null)) {
7635: var remidxs = remidxlist.split(',');
7636: for (var i=0; i<remidxs.length; i++) {
7637: if (document.getElementById('remove_'+remidxs[i])) {
7638: if (document.getElementById('remove_'+remidxs[i]).checked) {
7639: form.multiremove.value += remidxs[i]+',';
7640: numchanges ++;
7641: if (document.getElementById('skip_remove_'+remidxs[i])) {
7642: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7643: remwarnings ++;
7644: }
7645: }
1.484.2.63 raeburn 7646: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7647: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7648: removalinfo ++;
7649: }
7650: }
1.484.2.30 raeburn 7651: }
7652: }
7653: }
7654: }
7655: var cutidxlist = document.cumulativeactions.allcutidx.value;
7656: if ((cutidxlist != '') && (cutidxlist != null)) {
7657: var cutidxs = cutidxlist.split(',');
7658: for (var i=0; i<cutidxs.length; i++) {
7659: if (document.getElementById('cut_'+cutidxs[i])) {
7660: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7661: form.multicut.value += cutidxs[i]+',';
7662: numchanges ++;
7663: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7664: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7665: cutwarnings ++;
7666: }
7667: }
7668: }
7669: }
7670: }
7671: }
7672: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7673: if ((copyidxlist != '') && (copyidxlist != null)) {
7674: var copyidxs = copyidxlist.split(',');
7675: for (var i=0; i<copyidxs.length; i++) {
7676: if (document.getElementById('copy_'+copyidxs[i])) {
7677: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7678: form.multicopy.value += copyidxs[i]+',';
7679: numchanges ++;
7680: }
7681: }
7682: }
7683: }
7684: if (numchanges > 0) {
7685: form.multichange.value = numchanges;
7686: }
7687: }
7688: var dosettings = multiSettings();
7689: var haschanges = 0;
7690: if (dosettings == 1) {
7691: form.allencrypturl.value = '';
7692: form.allhiddenresource.value = '';
7693: form.changeparms.value = 'all';
7694: var patt=new RegExp(",\$");
7695: var allidxlist = document.cumulativesettings.allidx.value;
7696: if ((allidxlist != '') && (allidxlist != null)) {
7697: var allidxs = allidxlist.split(',');
7698: if (allidxs.length > 1) {
7699: for (var i=0; i<allidxs.length; i++) {
7700: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7701: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7702: form.allhiddenresource.value += allidxs[i]+',';
7703: }
7704: }
7705: if (document.getElementById('encrypturl_'+allidxs[i])) {
7706: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7707: form.allencrypturl.value += allidxs[i]+',';
7708: }
1.484.2.29 raeburn 7709: }
7710: }
1.484.2.30 raeburn 7711: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7712: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7713: }
7714: }
7715: form.allrandompick.value = '';
7716: form.allrandomorder.value = '';
7717: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7718: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7719: var allmapidxs = allmapidxlist.split(',');
7720: for (var i=0; i<allmapidxs.length; i++) {
7721: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7722: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7723: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7724: if ((randompick.checked) && (rpicknum.value != '')) {
7725: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7726: }
7727: if (randorder.checked) {
7728: form.allrandomorder.value += allmapidxs[i]+',';
7729: }
7730: }
7731: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7732: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7733: }
7734: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7735: haschanges = 1;
7736: }
7737: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7738: haschanges = 1;
7739: }
7740: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7741: haschanges = 1;
7742: }
7743: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7744: haschanges = 1;
7745: }
7746: }
7747: if (doactions == 1) {
7748: if (numchanges > 0) {
1.484.2.63 raeburn 7749: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7750: if (remwarnings > 0) {
1.484.2.61 raeburn 7751: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7752: return false;
7753: }
7754: }
1.484.2.63 raeburn 7755: if (removalinfo > 0) {
7756: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7757: return false;
7758: }
7759: }
1.484.2.30 raeburn 7760: if (cutwarnings > 0) {
1.484.2.61 raeburn 7761: 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 7762: return false;
1.484.2.29 raeburn 7763: }
7764: }
7765: }
1.484.2.30 raeburn 7766: form.submit();
7767: return true;
7768: }
7769: }
7770: if (dosettings == 1) {
7771: if (haschanges == 1) {
7772: form.submit();
7773: return true;
1.484.2.29 raeburn 7774: }
7775: }
1.484.2.30 raeburn 7776: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7777: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7778: } else {
7779: if (dosettings == 1) {
1.484.2.61 raeburn 7780: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7781: } else {
1.484.2.61 raeburn 7782: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7783: }
7784: }
7785: return false;
7786: }
7787:
7788: function setClass(value) {
7789: var cutclass = 'LC_docs_cut';
7790: var copyclass = 'LC_docs_copy';
7791: var removeclass = 'LC_docs_remove';
7792: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7793: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7794: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7795: var links = document.getElementsByTagName('a');
7796: for (var i=0; i<links.length; i++) {
7797: var classes = links[i].className;
7798: if (cutreg.test(classes)) {
7799: links[i].className = cutclass;
7800: if (value == 1) {
7801: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7802: }
1.484.2.30 raeburn 7803: } else {
7804: if (copyreg.test(classes)) {
7805: links[i].className = copyclass;
7806: if (value == 1) {
7807: links[i].className += " LC_menubuttons_link";
7808: }
7809: } else {
7810: if (removereg.test(classes)) {
7811: links[i].className = removeclass;
7812: if (value == 1) {
7813: links[i].className += " LC_menubuttons_link";
7814: }
7815: }
1.484.2.29 raeburn 7816: }
7817: }
7818: }
1.484.2.30 raeburn 7819: return;
1.484.2.29 raeburn 7820: }
7821:
1.484.2.30 raeburn 7822: function setBoxes(value) {
7823: var remidxlist = document.cumulativeactions.allremoveidx.value;
7824: if ((remidxlist != '') && (remidxlist != null)) {
7825: var remidxs = remidxlist.split(',');
7826: for (var i=0; i<remidxs.length; i++) {
7827: if (document.getElementById('remove_'+remidxs[i])) {
7828: var item = document.getElementById('remove_'+remidxs[i]);
7829: if (value == 1) {
7830: item.className = 'LC_docs_remove';
7831: } else {
7832: item.className = 'LC_hidden';
7833: }
7834: }
1.484.2.29 raeburn 7835: }
7836: }
1.484.2.30 raeburn 7837: var cutidxlist = document.cumulativeactions.allcutidx.value;
7838: if ((cutidxlist != '') && (cutidxlist != null)) {
7839: var cutidxs = cutidxlist.split(',');
7840: for (var i=0; i<cutidxs.length; i++) {
7841: if (document.getElementById('cut_'+cutidxs[i])) {
7842: var item = document.getElementById('cut_'+cutidxs[i]);
7843: if (value == 1) {
7844: item.className = 'LC_docs_cut';
7845: } else {
7846: item.className = 'LC_hidden';
7847: }
7848: }
7849: }
7850: }
7851: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7852: if ((copyidxlist != '') && (copyidxlist != null)) {
7853: var copyidxs = copyidxlist.split(',');
7854: for (var i=0; i<copyidxs.length; i++) {
7855: if (document.getElementById('copy_'+copyidxs[i])) {
7856: var item = document.getElementById('copy_'+copyidxs[i]);
7857: if (value == 1) {
7858: item.className = 'LC_docs_copy';
7859: } else {
7860: item.className = 'LC_hidden';
7861: }
7862: }
1.484.2.29 raeburn 7863: }
7864: }
7865: return;
7866: }
7867:
1.484.2.67 raeburn 7868: ENDSCRIPT
1.329 droeschl 7869: }
1.457 raeburn 7870:
1.483 raeburn 7871: sub history_tab_js {
7872: return <<"ENDHIST";
7873: function toggleHistoryDisp(choice) {
7874: document.docslogform.docslog.value = choice;
7875: document.docslogform.submit();
7876: return;
7877: }
7878:
7879: ENDHIST
7880: }
7881:
1.484 raeburn 7882: sub inject_data_js {
7883: return <<ENDINJECT;
7884:
7885: function injectData(current, hiddenField, name, value) {
7886: currentElement = document.getElementById(hiddenField);
7887: currentElement.name = name;
7888: currentElement.value = value;
7889: current.submit();
7890: }
7891:
7892: ENDINJECT
7893: }
7894:
7895: sub dump_switchserver_js {
7896: my @hosts = @_;
1.484.2.61 raeburn 7897: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7898: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7899: swit => 'Switch server?',
1.484.2.61 raeburn 7900: );
7901: my %html_js_lt = &Apache::lonlocal::texthash(
7902: swit => 'Switch server?',
1.484.2.43 raeburn 7903: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7904: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7905: chos => 'Choose server',
7906: );
1.484.2.61 raeburn 7907: &js_escape(\%js_lt);
7908: &html_escape(\%html_js_lt);
7909: &js_escape(\%html_js_lt);
1.484 raeburn 7910: my $role = $env{'request.role'};
7911: my $js = <<"ENDSWJS";
7912: <script type="text/javascript">
7913: function write_switchserver() {
7914: var server;
7915: if (document.setserver.posshosts.length > 0) {
7916: for (var i=0; i<document.setserver.posshosts.length; i++) {
7917: if (document.setserver.posshosts[i].checked) {
7918: server = document.setserver.posshosts[i].value;
7919: }
7920: }
7921: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7922: }
7923: window.close();
7924: }
7925: </script>
7926:
7927: ENDSWJS
7928:
7929: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7930: {'only_body' => 1,
7931: 'js_ready' => 1,});
7932: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7933:
7934: my $hostpicker;
7935: my $count = 0;
7936: foreach my $host (sort(@hosts)) {
7937: my $checked;
7938: if ($count == 0) {
7939: $checked = ' checked="checked"';
7940: }
7941: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7942: $host.'"'.$checked.' />'.$host.'</label> ';
7943: $count++;
7944: }
7945:
7946: return <<"ENDSWITCHJS";
7947:
7948: function dump_needs_switchserver(url) {
7949: if (url!='' && url!= null) {
1.484.2.61 raeburn 7950: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7951: go(url);
7952: }
7953: }
7954: return;
7955: }
7956:
7957: function choose_switchserver_window() {
7958: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7959: newWindow.document.open();
7960: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7961: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7962: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7963: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7964: '<form name="setserver" method="post" action="" \\/>\\n'+
7965: '$hostpicker\\n'+
7966: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7967: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7968: 'onclick="write_switchserver();" \\/>\\n'+
7969: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7970: newWindow.document.writeln('$endpage');
7971: newWindow.document.close();
7972: newWindow.focus();
7973: }
7974:
7975: ENDSWITCHJS
7976: }
7977:
7978: sub makedocslogform {
7979: my ($formelems,$docslog) = @_;
7980: return <<"LOGSFORM";
7981: <form action="/adm/coursedocs" method="post" name="docslogform">
7982: <input type="hidden" name="docslog" value="$docslog" />
7983: $formelems
7984: </form>
7985: LOGSFORM
7986: }
7987:
7988: sub makesimpleeditform {
7989: my ($formelems) = @_;
7990: return <<"SIMPFORM";
7991: <form name="simpleedit" method="post" action="/adm/coursedocs">
7992: <input type="hidden" name="importdetail" value="" />
7993: $formelems
7994: </form>
7995: SIMPFORM
7996: }
7997:
1.329 droeschl 7998: 1;
7999: __END__
8000:
8001:
8002: =head1 NAME
8003:
8004: Apache::londocs.pm
8005:
8006: =head1 SYNOPSIS
8007:
8008: This is part of the LearningOnline Network with CAPA project
8009: described at http://www.lon-capa.org.
8010:
8011: =head1 SUBROUTINES
8012:
8013: =over
8014:
8015: =item %help=()
8016:
8017: Available help topics
8018:
8019: =item mapread()
8020:
1.344 bisitz 8021: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8022: @order and @resources, determines status
8023: sets @order - pointer to resources in right order
8024: sets @resources - array with the resources with correct idx
8025:
8026: =item authorhosts()
8027:
8028: Return hash with valid author names
8029:
8030: =item clean()
8031:
8032: =item dumpcourse()
8033:
8034: Actually dump course
8035:
8036: =item group_import()
8037:
8038: Imports the given (name, url) resources into the course
8039: coursenum, coursedom, and folder must precede the list
8040:
8041: =item breadcrumbs()
8042:
8043: =item log_docs()
8044:
8045: =item docs_change_log()
8046:
8047: =item update_paste_buffer()
8048:
8049: =item print_paste_buffer()
8050:
8051: =item do_paste_from_buffer()
8052:
1.484.2.30 raeburn 8053: =item do_buffer_empty()
8054:
8055: =item clear_from_buffer()
8056:
1.484.2.7 raeburn 8057: =item get_newmap_url()
8058:
8059: =item dbcopy()
8060:
8061: =item uniqueness_check()
8062:
8063: =item contained_map_check()
8064:
8065: =item url_paste_fixups()
8066:
8067: =item apply_fixups()
8068:
8069: =item copy_dependencies()
8070:
1.329 droeschl 8071: =item update_parameter()
8072:
8073: =item handle_edit_cmd()
8074:
8075: =item editor()
8076:
8077: =item process_file_upload()
8078:
8079: =item process_secondary_uploads()
8080:
8081: =item is_supplemental_title()
8082:
8083: =item entryline()
8084:
8085: =item tiehash()
8086:
8087: =item untiehash()
8088:
8089: =item checkonthis()
8090:
8091: check on this
8092:
8093: =item verifycontent()
8094:
8095: Verify Content
8096:
1.484.2.78 raeburn 8097: =item devalidateversioncache()
8098:
8099: =item checkversions()
1.329 droeschl 8100:
8101: Check Versions
8102:
8103: =item mark_hash_old()
8104:
8105: =item is_hash_old()
8106:
8107: =item changewarning()
8108:
8109: =item init_breadcrumbs()
8110:
8111: Breadcrumbs for special functions
8112:
1.484 raeburn 8113: =item create_list_elements()
8114:
8115: =item create_form_ul()
8116:
8117: =item startContentScreen()
8118:
8119: =item endContentScreen()
8120:
8121: =item supplemental_base()
8122:
8123: =item embedded_form_elems()
8124:
8125: =item embedded_destination()
8126:
8127: =item return_to_editor()
8128:
8129: =item decompression_info()
8130:
8131: =item decompression_phase_one()
8132:
8133: =item decompression_phase_two()
8134:
8135: =item remove_archive()
8136:
8137: =item generate_admin_menu()
8138:
8139: =item generate_edit_table()
8140:
8141: =item editing_js()
8142:
8143: =item history_tab_js()
8144:
8145: =item inject_data_js()
8146:
8147: =item dump_switchserver_js()
8148:
1.484.2.3 raeburn 8149: =item resize_scrollbox_js()
1.484 raeburn 8150:
8151: =item makedocslogform()
8152:
1.484.2.3 raeburn 8153: =item makesimpleeditform()
8154:
1.329 droeschl 8155: =back
8156:
8157: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>