Annotation of loncom/interface/londocs.pm, revision 1.484.2.95
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.95! raeburn 4: # $Id: londocs.pm,v 1.484.2.94 2024/07/01 18:29:41 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.329 droeschl 46: use HTML::Entities;
1.484.2.7 raeburn 47: use HTML::TokeParser;
1.329 droeschl 48: use GDBM_File;
1.484.2.51 raeburn 49: use File::MMagic;
1.329 droeschl 50: use Apache::lonlocal;
51: use Cwd;
52: use LONCAPA qw(:DEFAULT :match);
53:
54: my $iconpath;
55:
56: my %hash;
57:
58: my $hashtied;
59: my %alreadyseen=();
60:
61: my $hadchanges;
1.484.2.37 raeburn 62: my $suppchanges;
1.329 droeschl 63:
64:
65: my %help=();
66:
67:
68: sub mapread {
69: my ($coursenum,$coursedom,$map)=@_;
70: return
71: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
72: $map);
73: }
74:
75: sub storemap {
1.484.2.7 raeburn 76: my ($coursenum,$coursedom,$map,$contentchg)=@_;
77: my $report;
78: if (($contentchg) && ($map =~ /^default/)) {
79: $report = 1;
80: }
1.329 droeschl 81: my ($outtext,$errtext)=
82: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.484.2.7 raeburn 83: $map,1,$report);
1.329 droeschl 84: if ($errtext) { return ($errtext,2); }
1.364 bisitz 85:
1.484.2.37 raeburn 86: if ($map =~ /^default/) {
87: $hadchanges=1;
88: } else {
89: $suppchanges=1;
90: }
1.329 droeschl 91: return ($errtext,0);
92: }
93:
94:
95:
96: sub authorhosts {
97: my %outhash=();
98: my $home=0;
99: my $other=0;
100: foreach my $key (keys(%env)) {
101: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
102: my $role=$1;
103: my $realm=$2;
104: my ($start,$end)=split(/\./,$env{$key});
105: if (($start) && ($start>time)) { next; }
106: if (($end) && (time>$end)) { next; }
107: my ($ca,$cd);
108: if ($1 eq 'au') {
109: $ca=$env{'user.name'};
110: $cd=$env{'user.domain'};
111: } else {
112: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
113: }
114: my $allowed=0;
115: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
116: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 117: foreach my $id (@ids) {
118: if ($id eq $myhome) {
119: $allowed=1;
120: last;
121: }
122: }
1.329 droeschl 123: if ($allowed) {
124: $home++;
1.484 raeburn 125: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 126: } else {
1.484 raeburn 127: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 128: $other++;
129: }
130: }
131: }
132: return ($home,$other,%outhash);
133: }
134:
135:
136: sub clean {
137: my ($title)=@_;
138: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 139: return $title;
1.329 droeschl 140: }
141:
1.484.2.67 raeburn 142: sub default_folderpath {
143: my ($coursenum,$coursedom,$navmapref) = @_;
144: return unless ($coursenum && $coursedom && ref($navmapref));
145: # Check if entire course is hidden and/or encrypted
146: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
147: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
148: unless (ref($$navmapref)) {
149: $$navmapref = Apache::lonnavmaps::navmap->new();
150: }
151: if (ref($$navmapref)) {
152: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
153: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
154: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
155: unless (@resources) {
156: $hiddenmap = 1;
157: unless ($env{'request.role.adv'}) {
158: $hiddentop = 1;
159: if ($env{'form.folder'}) {
160: undef($env{'form.folder'});
161: }
162: }
163: }
164: }
165: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
166: $encryptmap = 1;
167: }
168: }
169: unless ($hiddentop) {
170: $folderpath='default&'.&escape(&mt('Main Content')).
171: '::'.$hiddenmap.':'.$encryptmap.'::';
172: }
173: if (wantarray) {
174: return ($folderpath,$hiddentop);
175: } else {
176: return $folderpath;
177: }
178: }
1.329 droeschl 179:
1.484.2.92 raeburn 180: sub validate_folderpath {
181: my ($supplementalflag) = @_;
182: if ($env{'form.folderpath'} ne '') {
183: my @items = split(/\&/,$env{'form.folderpath'});
184: my $badpath;
185: for (my $i=0; $i<@items; $i++) {
186: my $odd = $i%2;
187: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
188: $badpath = 1;
189: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
190: $badpath = 1;
191: }
192: last if ($badpath);
193: }
194: if ($badpath) {
195: delete($env{'form.folderpath'});
196: }
197: }
198: return;
199: }
200:
201: sub validate_suppath {
202: if ($env{'form.supppath'} ne '') {
203: my @items = split(/\&/,$env{'form.supppath'});
204: my $badpath;
205: for (my $i=0; $i<@items; $i++) {
206: my $odd = $i%2;
207: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
208: $badpath = 1;
209: }
210: last if ($badpath);
211: }
212: if ($badpath) {
213: delete($env{'form.supppath'});
214: }
215: }
216: return;
217: }
218:
1.329 droeschl 219: sub dumpcourse {
220: my ($r) = @_;
1.408 raeburn 221: my $crstype = &Apache::loncommon::course_type();
1.484.2.43 raeburn 222: my ($starthash,$js);
223: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
224: $js = <<"ENDJS";
225: <script type="text/javascript">
226: // <![CDATA[
227:
228: function hide_searching() {
229: if (document.getElementById('searching')) {
230: document.getElementById('searching').style.display = 'none';
231: }
232: return;
233: }
234:
235: // ]]>
236: </script>
237: ENDJS
238: $starthash = {
239: add_entries => {'onload' => "hide_searching();"},
240: };
241: }
242: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
243: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 244: $r->print(&startContentScreen('tools'));
1.329 droeschl 245: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 246: unless ($home) {
247: $r->print(&endContentScreen());
248: return '';
249: }
1.329 droeschl 250: my $origcrsid=$env{'request.course.id'};
251: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
252: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
253: # Do the dumping
1.484 raeburn 254: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
255: $r->print(&endContentScreen());
256: return '';
257: }
1.484.2.24 raeburn 258: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 259: $r->print('<h3>'.&mt('Copying Files').'</h3>');
260: my $title=$env{'form.authorfolder'};
261: $title=&clean($title);
1.484.2.43 raeburn 262: my ($navmap,$errormsg) =
263: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
264: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
265: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
266: my (%maps,%resources,%titles);
267: if (!ref($navmap)) {
268: $r->print($errormsg.
269: &endContentScreen());
270: return '';
271: } else {
272: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
273: 'dumpdocs',$cdom,$cnum);
274: }
275: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
276: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
277: %newcontent,%has_simpleprobs);
278: foreach my $item (sort {$a <=> $b} (@todump)) {
279: my $name = $env{'form.namefor_'.$item};
280: if ($resources{$item}) {
281: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
282: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
283: $tocopy{$1} = $name;
284: $display{$item} = $1;
285: $lookup{$1} = $item;
286: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
287: $simpleproblems{$item} = {
288: symb => $resources{$item},
289: name => $name,
290: };
291: $display{$item} = 'simpleproblem_'.$name;
292: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
293: $has_simpleprobs{$1}{$id} = $item;
294: }
295: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
296: my $marker = $1;
297: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
298: $simplepages{$item} = {
299: res => $res,
300: title => $titles{$item},
301: db => $db_name,
302: marker => $marker,
303: symb => $resources{$item},
304: name => $name,
305: };
306: $display{$item} = '/'.$res;
307: }
308: } elsif ($maps{$item}) {
309: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
310: $tocopy{$1} = $name;
311: $display{$item} = $1;
312: $lookup{$1} = $item;
313: }
314: } else {
315: next;
316: }
317: }
1.329 droeschl 318: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
319: $crs=~s/\_/\//g;
1.484.2.43 raeburn 320: my $mm = new File::MMagic;
321: my $prefix = "/uploaded/$cdom/$cnum/";
322: %replacehash = %tocopy;
323: foreach my $item (sort(keys(%simpleproblems))) {
324: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
325: $newcontent{$display{$item}} = $content;
326: }
327: my $gateway = Apache::lonhtmlgateway->new('web');
328: foreach my $item (sort(keys(%simplepages))) {
329: if (ref($simplepages{$item}) eq 'HASH') {
330: my $pagetitle = $simplepages{$item}{'title'};
331: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
332: my %contents;
333: foreach my $field (keys(%fields)) {
334: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
335: my $name = $1;
336: my $msg = $fields{$field};
337: if ($name eq 'webreferences') {
338: if ($msg =~ m{^https?://}) {
339: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
340: }
341: } else {
342: $msg = &Encode::decode('utf8',$msg);
343: $msg = $gateway->process_outgoing_html($msg,1);
344: $contents{$name} = $msg;
345: }
346: } elsif ($field eq 'uploaded.photourl') {
347: my $marker = $simplepages{$item}{marker};
348: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
349: my $filepath = $1;
350: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
351: if ($fname ne '') {
352: $fname=~s/\.(\w+)$//;
353: my $ext=$1;
354: $fname = &clean($fname);
355: $fname.='.'.$ext;
356: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
357: $replacehash{$filepath} = $relpath.$fname;
358: $deps{$item}{$filepath} = 1;
359: }
360: }
361: }
362: }
363: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
364: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
365: my $content = '
366: <html>
367: <head>
368: <title>'.$pagetitle.'</title>
369: </head>
370: <body bgcolor="#ffffff">';
371: if ($contents{title}) {
372: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
373: }
374: if ($contents{image}) {
375: $content .= "\n".$contents{image};
376: }
377: if ($contents{content}) {
378: $content .= '
379: <div class="LC_Box">
1.484.2.50 raeburn 380: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.484.2.43 raeburn 381: $contents{content}.'
382: </div>';
383: }
384: if ($contents{webreferences}) {
385: $content .= '
386: <div class="LC_Box">
1.484.2.50 raeburn 387: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.484.2.43 raeburn 388: $contents{webreferences}.'
389: </div>';
390: }
391: $content .= '
392: </body>
393: </html>
394: ';
395: $newcontent{'/'.$simplepages{$item}{res}} = $content;
396: }
397: }
398: foreach my $item (keys(%tocopy)) {
399: unless ($item=~/\.(sequence|page)$/) {
400: my $currurlpath = $prefix.$item;
401: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
402: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
403: }
404: }
405: foreach my $num (sort {$a <=> $b} (@todump)) {
406: my $src = $display{$num};
407: next if ($src eq '');
408: my @needcopy = ();
409: if ($replacehash{$src}) {
410: push(@needcopy,$src);
411: if (ref($deps{$num}) eq 'HASH') {
412: foreach my $dep (sort(keys(%{$deps{$num}}))) {
413: if ($replacehash{$dep}) {
414: push(@needcopy,$dep);
415: }
416: }
417: }
418: } elsif ($src =~ /^simpleproblem_/) {
419: push(@needcopy,$src);
420: }
421: next if (@needcopy == 0);
422: my ($result,$depresult);
423: for (my $i=0; $i<@needcopy; $i++) {
424: my $item = $needcopy[$i];
425: my $newfilename;
426: if ($simpleproblems{$num}) {
427: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
428: } else {
429: $newfilename=$title.'/'.$replacehash{$item};
430: }
431: $newfilename=~s/\.(\w+)$//;
432: my $ext=$1;
433: $newfilename=&clean($newfilename);
434: $newfilename.='.'.$ext;
435: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
436: if ($newrelpath ne $replacehash{$item}) {
437: $replacehash{$item} = $newrelpath;
438: }
439: my @dirs=split(/\//,$newfilename);
440: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
441: my $makepath=$path;
442: my $fail;
443: my $origin;
444: for (my $i=0;$i<$#dirs;$i++) {
445: $makepath.='/'.$dirs[$i];
446: unless (-e $makepath) {
447: unless(mkdir($makepath,0755)) {
448: $fail = &mt('Directory creation failed.');
449: }
450: }
451: }
452: if ($i == 0) {
453: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
454: } else {
455: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
456: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
457: &mt('(dependency)').'</span>: ';
458: }
459: if (-e $path.'/'.$newfilename) {
460: $fail = &mt('Destination already exists -- not overwriting.');
461: } else {
462: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
463: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
464: ($item =~ /^simpleproblem_/)) {
465: print $fh $newcontent{$item};
466: } else {
467: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
468: if (-e $fileloc) {
469: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
470: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
471: (ref($has_simpleprobs{$item}) eq 'HASH')) {
472: my %changes = %{$has_simpleprobs{$item}};
473: my $content = &Apache::lonclonecourse::rewritefile(
474: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
475: (%replacehash,$crs => '')
476: );
477: my $updatedcontent = '';
478: my $parser = HTML::TokeParser->new(\$content);
479: $parser->attr_encoded(1);
480: while (my $token = $parser->get_token) {
481: if ($token->[0] eq 'S') {
482: if (($token->[1] eq 'resource') &&
483: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
484: ($changes{$token->[2]->{'id'}})) {
485: my $id = $token->[2]->{'id'};
486: $updatedcontent .= '<'.$token->[1];
487: foreach my $attrib (@{$token->[3]}) {
488: next unless ($attrib =~ /^(src|type|title|id)$/);
489: if ($attrib eq 'src') {
490: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
491: if ($file) {
492: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
493: } else {
494: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
495: }
496: } else {
497: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
498: }
499: }
500: $updatedcontent .= ' />'."\n";
501: } else {
502: $updatedcontent .= $token->[4]."\n";
503: }
504: } else {
505: $updatedcontent .= $token->[2];
506: }
507: }
508: print $fh $updatedcontent;
509: } else {
510: print $fh &Apache::lonclonecourse::rewritefile(
511: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
512: (%replacehash,$crs => '')
513: );
514: }
515: } else {
516: print $fh
517: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
518: }
519: } else {
520: $fail = &mt('Source does not exist.');
521: }
522: }
523: $fh->close();
524: } else {
525: $fail = &mt('Could not write to destination.');
526: }
527: }
528: my $text;
529: if ($fail) {
530: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
531: } else {
532: $text = '<span class="LC_success">'.&mt('ok').'</span>';
533: }
534: if ($i == 0) {
535: $result .= $text;
536: } else {
537: $depresult .= $text.'</li>';
538: }
539: }
540: $r->print($result);
541: if ($depresult) {
542: $r->print('<ul>'.$depresult.'</ul>');
543: }
544: }
1.329 droeschl 545: } else {
1.484.2.43 raeburn 546: my ($navmap,$errormsg) =
547: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
548: if (!ref($navmap)) {
549: $r->print($errormsg);
550: } else {
551: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
552: $r->rflush();
553: my ($preamble,$formname);
554: $formname = 'dumpdoc';
555: unless ($home==1) {
556: $preamble = '<div class="LC_left_float">'.
557: '<fieldset><legend>'.
558: &mt('Select the Authoring Space').
559: '</legend><select name="authorspace">';
560: }
561: my @orderspaces = ();
562: foreach my $key (sort(keys(%outhash))) {
563: if ($key=~/^home_(.+)$/) {
564: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
565: unshift(@orderspaces,$1);
566: } else {
567: push(@orderspaces,$1);
568: }
569: }
570: }
571: if ($home>1) {
572: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
573: }
574: foreach my $user (@orderspaces) {
575: if ($home==1) {
576: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
577: } else {
578: $preamble .= '<option value="'.$user.'">'.$user.' - '.
579: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
580: }
581: }
582: unless ($home==1) {
583: $preamble .= '</select></fieldset></div>'."\n";
584: }
585: my $title=$origcrsdata{'description'};
586: $title=~s/[\/\s]+/\_/gs;
587: $title=&clean($title);
588: $preamble .= '<div class="LC_left_float">'.
589: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
590: '<input type="text" size="50" name="authorfolder" value="'.
591: $title.'" />'.
592: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
593: my %uploadedfiles;
594: &tiehash();
595: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
596: my ($ext)=($file=~/\.(\w+)$/);
597: # FIXME Check supplemental here
598: my $title=$hash{'title_'.$hash{
599: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
600: if (!$title) {
601: $title=$file;
602: } else {
603: $title=~s|/|_|g;
604: }
605: $title=~s/\.(\w+)$//;
606: $title=&clean($title);
607: $title.='.'.$ext;
608: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
609: $uploadedfiles{$file} = $title;
610: }
611: &untiehash();
612: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
613: undef,undef,$preamble,$home,\%uploadedfiles));
614: }
1.329 droeschl 615: }
1.484 raeburn 616: $r->print(&endContentScreen());
1.329 droeschl 617: }
618:
1.484.2.43 raeburn 619: sub recurse_html {
620: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
621: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
622: my (%allfiles,%codebase);
623: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
624: if (keys(%allfiles)) {
625: foreach my $dependency (keys(%allfiles)) {
626: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
627: my ($depurl,$relfile,$newcontainer);
628: if ($dependency =~ m{^/}) {
629: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
630: $relfile = $1;
631: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
632: $newcontainer = $1;
633: next if ($replacehash->{$newcontainer});
634: }
635: $depurl = $dependency;
636: } else {
637: next;
638: }
639: } else {
640: $relfile = $dependency;
641: $depurl = $currurlpath;
642: $depurl =~ s{[^/]+$}{};
643: $depurl .= $dependency;
644: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
645: }
646: next if ($relfile eq '');
647: my $newname = $replacehash->{$container};
648: $newname =~ s{[^/]+$}{};
649: $replacehash->{$newcontainer} = $newname.$relfile;
650: $deps->{$item}{$newcontainer} = 1;
651: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
652: my $depfile = &Apache::lonnet::filelocation('',$depurl);
653: my $type = $mm->checktype_filename($depfile);
654: if ($type eq 'text/html') {
655: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
656: }
657: }
658: }
659: }
660: return;
661: }
662:
1.329 droeschl 663: sub group_import {
664: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
1.484.2.23 raeburn 665: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
666: %removeparam,$importuploaded,$fixuperrors);
667: $allmaps = {};
1.329 droeschl 668: while (@files) {
669: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 670: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 671: && ($caller eq 'londocs')
672: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 673:
1.329 droeschl 674: my $errtext = '';
675: my $fatal = 0;
676: my $newmapstr = '<map>'."\n".
677: '<resource id="1" src="" type="start"></resource>'."\n".
678: '<link from="1" to="2" index="1"></link>'."\n".
679: '<resource id="2" src="" type="finish"></resource>'."\n".
680: '</map>';
681: $env{'form.output'}=$newmapstr;
682: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
683: 'output',$1.$2);
1.484.2.27 raeburn 684: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 685: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
686: $fatal = 2;
687: }
688: if ($fatal) {
689: return ($errtext,$fatal);
690: }
691: }
692: if ($url) {
1.484.2.23 raeburn 693: if (($caller eq 'londocs') &&
694: ($folder =~ /^default/)) {
1.484.2.27 raeburn 695: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 696: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
697: my $cid = $coursedom.'_'.$coursenum;
698: $allmaps =
699: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
700: $chome,$cid);
701: $donechk = 1;
702: }
703: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
704: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
705: \%addedmaps,\%hierarchy,\%titles,$allmaps);
706: $importuploaded = 1;
707: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
708: next if ($allmaps->{$url});
709: }
710: }
1.344 bisitz 711: if (!$residx
1.329 droeschl 712: || defined($LONCAPA::map::zombies[$residx])) {
713: $residx = &LONCAPA::map::getresidx($url,$residx);
714: push(@LONCAPA::map::order, $residx);
715: }
716: my $ext = 'false';
717: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.484.2.27 raeburn 718: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
719: my $filepath = $1;
1.484.2.91 raeburn 720: my $fname;
721: if ($name eq '') {
722: $name = &mt('Web Page');
1.484.2.27 raeburn 723: $fname = 'web';
724: } else {
1.484.2.91 raeburn 725: $fname = $name;
726: $fname=&Apache::lonnet::clean_filename($fname);
727: if ($fname eq '') {
728: $fname = 'web';
729: } elsif (length($fname) > 15) {
730: $fname = substr($fname,0,14);
731: }
1.484.2.27 raeburn 732: }
1.484.2.91 raeburn 733: my $title = &Apache::loncommon::cleanup_html($name);
1.484.2.27 raeburn 734: my $initialtext = &mt('Replace with your own content.');
735: my $newhtml = <<END;
1.484.2.31 raeburn 736: <html>
1.484.2.27 raeburn 737: <head>
1.484.2.91 raeburn 738: <title>$title</title>
1.484.2.27 raeburn 739: </head>
740: <body bgcolor="#ffffff">
741: $initialtext
742: </body>
743: </html>
744: END
745: $env{'form.output'}=$newhtml;
746: my $result =
747: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
748: 'output',
749: "$filepath/$residx/$fname.html");
750: if ($result =~ m{^/uploaded/}) {
751: $url = $result;
752: if ($filepath =~ /^supplemental/) {
753: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
754: $env{'user.domain'}.'___&&&___'.$name;
755: }
756: } else {
757: return (&mt('Failed to save new web page.'),1);
758: }
759: }
1.484.2.91 raeburn 760: $name = &LONCAPA::map::qtunescape($name);
1.484.2.30 raeburn 761: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 762: $LONCAPA::map::resources[$residx] =
1.329 droeschl 763: join(':', ($name, $url, $ext, 'normal', 'res'));
764: }
765: }
1.484.2.23 raeburn 766: if ($importuploaded) {
767: my %import_errors;
768: my %updated = (
769: removefrommap => \%removefrommap,
770: removeparam => \%removeparam,
771: );
1.484.2.26 raeburn 772: my ($result,$msgsarray,$lockerror) =
773: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 774: if (keys(%import_errors) > 0) {
775: $fixuperrors =
776: '<p span class="LC_warning">'."\n".
777: &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".
778: '<ul>'."\n";
779: foreach my $key (sort(keys(%import_errors))) {
780: $fixuperrors .= '<li>'.$key.'</li>'."\n";
781: }
782: $fixuperrors .= '</ul></p>'."\n";
783: }
1.484.2.26 raeburn 784: if (ref($msgsarray) eq 'ARRAY') {
785: if (@{$msgsarray} > 0) {
786: $fixuperrors .= '<p class="LC_info">'.
787: join('<br />',@{$msgsarray}).
788: '</p>';
789: }
790: }
791: if ($lockerror) {
792: $fixuperrors .= '<p class="LC_error">'.
793: $lockerror.
794: '</p>';
795: }
1.484.2.23 raeburn 796: }
797: my ($errtext,$fatal) =
798: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 799: unless ($fatal) {
800: if ($folder =~ /^supplemental/) {
801: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 802: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
803: $folder.'.'.$container);
1.484.2.37 raeburn 804: }
805: }
1.484.2.23 raeburn 806: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 807: }
808:
809: sub log_docs {
1.484.2.8 raeburn 810: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 811: }
812:
813: {
814: my @oldresources=();
815: my @oldorder=();
816: my $parmidx;
817: my %parmaction=();
818: my %parmvalue=();
819: my $changedflag;
820:
821: sub snapshotbefore {
822: @oldresources=@LONCAPA::map::resources;
823: @oldorder=@LONCAPA::map::order;
824: $parmidx=undef;
825: %parmaction=();
826: %parmvalue=();
827: $changedflag=0;
828: }
829:
830: sub remember_parms {
831: my ($idx,$parameter,$action,$value)=@_;
832: $parmidx=$idx;
833: $parmaction{$parameter}=$action;
834: $parmvalue{$parameter}=$value;
835: $changedflag=1;
836: }
837:
838: sub log_differences {
839: my ($plain)=@_;
840: my %storehash=('folder' => $plain,
841: 'currentfolder' => $env{'form.folder'});
842: if ($parmidx) {
843: $storehash{'parameter_res'}=$oldresources[$parmidx];
844: foreach my $parm (keys(%parmaction)) {
845: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
846: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
847: }
848: }
849: my $maxidx=$#oldresources;
850: if ($#LONCAPA::map::resources>$#oldresources) {
851: $maxidx=$#LONCAPA::map::resources;
852: }
853: for (my $idx=0; $idx<=$maxidx; $idx++) {
854: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
855: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
856: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
857: $changedflag=1;
858: }
859: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
860: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
861: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
862: $changedflag=1;
863: }
864: }
865: $storehash{'maxidx'}=$maxidx;
866: if ($changedflag) { &log_docs(\%storehash); }
867: }
868: }
869:
870: sub docs_change_log {
1.484.2.67 raeburn 871: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 872: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 873: my $navmap;
1.483 raeburn 874: my $js = '<script type="text/javascript">'."\n".
875: '// <![CDATA['."\n".
876: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 877: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.80 raeburn 878: $coursedom,$coursenum,$canedit,'',\$navmap)."\n".
1.483 raeburn 879: &history_tab_js()."\n".
1.484 raeburn 880: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 881: '// ]]>'."\n".
882: '</script>'."\n";
1.484 raeburn 883: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
884: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 885: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 886: my %orderhash;
887: my $container='sequence';
888: my $pathitem;
1.484.2.19 raeburn 889: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 890: $container='page';
891: }
1.484.2.19 raeburn 892: my $folderpath=$env{'form.folderpath'};
893: if ($folderpath eq '') {
1.484.2.67 raeburn 894: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 895: }
1.484.2.67 raeburn 896: undef($navmap);
1.484.2.19 raeburn 897: $pathitem = '<input type="hidden" name="folderpath" value="'.
898: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 899: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
900: my $jumpto = $readfile;
901: $jumpto =~ s{^/}{};
902: my $tid = 1;
1.484.2.7 raeburn 903: if ($supplementalflag) {
904: $tid = 2;
905: }
1.484.2.19 raeburn 906: my ($breadcrumbtrail) =
1.484.2.18 raeburn 907: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 908: $r->print($breadcrumbtrail.
909: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
910: $readfile));
1.329 droeschl 911: my %docslog=&Apache::lonnet::dump('nohist_docslog',
912: $env{'course.'.$env{'request.course.id'}.'.domain'},
913: $env{'course.'.$env{'request.course.id'}.'.num'});
914:
915: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
916:
917: my %saveable_parameters = ('show' => 'scalar',);
918: &Apache::loncommon::store_course_settings('docs_log',
919: \%saveable_parameters);
920: &Apache::loncommon::restore_course_settings('docs_log',
921: \%saveable_parameters);
922: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 923: # FIXME: internationalization seems wrong here
1.329 droeschl 924: my %lt=('hiddenresource' => 'Resources hidden',
925: 'encrypturl' => 'URL hidden',
926: 'randompick' => 'Randomly pick',
927: 'randomorder' => 'Randomly ordered',
928: 'set' => 'set to',
929: 'del' => 'deleted');
1.484 raeburn 930: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
931: $pathitem."\n".
932: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
933: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
934: $r->print('<div class="LC_left_float">'.
935: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
936: &makedocslogform($filter,1).
937: '</fieldset></div><br clear="all" />');
1.329 droeschl 938: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
939: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
940: &mt('After').'</th>'.
941: &Apache::loncommon::end_data_table_header_row());
942: my $shown=0;
943: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
944: if ($env{'form.displayfilter'} eq 'currentfolder') {
945: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
946: }
947: my @changes=keys(%{$docslog{$id}{'logentry'}});
948: if ($env{'form.displayfilter'} eq 'containing') {
949: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
950: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
951: foreach my $key (@changes) {
952: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
953: }
1.344 bisitz 954: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 955: }
956: my $count = 0;
957: my $time =
958: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
959: my $plainname =
960: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
961: $docslog{$id}{'exe_udom'});
962: my $about_me_link =
963: &Apache::loncommon::aboutmewrapper($plainname,
964: $docslog{$id}{'exe_uname'},
965: $docslog{$id}{'exe_udom'});
966: my $send_msg_link='';
967: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
968: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
969: $send_msg_link ='<br />'.
970: &Apache::loncommon::messagewrapper(&mt('Send message'),
971: $docslog{$id}{'exe_uname'},
972: $docslog{$id}{'exe_udom'});
973: }
974: $r->print(&Apache::loncommon::start_data_table_row());
975: $r->print('<td>'.$time.'</td>
976: <td>'.$about_me_link.
977: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
978: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
979: $send_msg_link.'</td><td>'.
980: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 981: my $is_supp = 0;
1.484.2.7 raeburn 982: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
983: $is_supp = 1;
984: }
1.329 droeschl 985: # Before
986: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
987: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
988: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
989: if ($oldname ne $newname) {
1.484.2.7 raeburn 990: my $shown = &LONCAPA::map::qtescape($oldname);
991: if ($is_supp) {
992: $shown = &Apache::loncommon::parse_supplemental_title($shown);
993: }
994: $r->print($shown);
1.329 droeschl 995: }
996: }
997: $r->print('<ul>');
998: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
999: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 1000: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1001: if ($is_supp) {
1002: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1003: }
1.484.2.19 raeburn 1004: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1005: }
1006: }
1007: $r->print('</ul>');
1008: # After
1009: $r->print('</td><td>');
1010:
1011: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1012: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1013: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1014: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 1015: my $shown = &LONCAPA::map::qtescape($newname);
1016: if ($is_supp) {
1017: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1018: }
1019: $r->print($shown);
1.329 droeschl 1020: }
1.364 bisitz 1021: }
1.329 droeschl 1022: $r->print('<ul>');
1023: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1024: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 1025: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1026: if ($is_supp) {
1027: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1028: }
1029: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1030: }
1031: }
1032: $r->print('</ul>');
1033: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.484.2.95! raeburn 1034: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
! 1035: if ($title eq '') {
! 1036: ($title) = ($url =~ m{/([^/]+)$});
! 1037: }
! 1038: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.329 droeschl 1039: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1040: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1041: # FIXME: internationalization seems wrong here
1.329 droeschl 1042: $r->print('<li>'.
1043: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1044: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1045: .'</li>');
1046: }
1047: }
1048: $r->print('</ul>');
1049: }
1050: # End
1051: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1052: $shown++;
1053: if (!($env{'form.show'} eq &mt('all')
1054: || $shown<=$env{'form.show'})) { last; }
1055: }
1.484 raeburn 1056: $r->print(&Apache::loncommon::end_data_table()."\n".
1057: &makesimpleeditform($pathitem)."\n".
1058: '</div></div>');
1059: $r->print(&endContentScreen());
1.329 droeschl 1060: }
1061:
1062: sub update_paste_buffer {
1.484.2.7 raeburn 1063: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1064: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1065: if ($env{'form.multiremove'}) {
1066: $env{'form.multiremove'} =~ s/,$//;
1067: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1068: }
1069: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1070: if ($env{'form.multicut'}) {
1071: $env{'form.multicut'} =~ s/,$//;
1072: foreach my $item (split(/,/,$env{'form.multicut'})) {
1073: unless ($removals{$item}) {
1074: $cuts{$item} = 1;
1075: push(@possibles,$item.':cut');
1076: }
1077: }
1078: }
1079: if ($env{'form.multicopy'}) {
1080: $env{'form.multicopy'} =~ s/,$//;
1081: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1082: unless ($removals{$item} || $cuts{$item}) {
1083: push(@possibles,$item.':copy');
1084: }
1085: }
1086: }
1087: } elsif ($env{'form.markcopy'}) {
1088: @possibles = split(/,/,$env{'form.markcopy'});
1089: }
1.329 droeschl 1090:
1.484.2.30 raeburn 1091: return if (@possibles == 0);
1.329 droeschl 1092: return if (!defined($env{'form.copyfolder'}));
1093:
1094: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1095: $env{'form.copyfolder'});
1096: return if ($fatal);
1097:
1.484.2.30 raeburn 1098: my %curr_groups = &Apache::longroup::coursegroups();
1099:
1100: # Retrieve current paste buffer suffixes.
1101: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1102: my (%pasteurls,@newpaste);
1103:
1104: # Construct identifiers for current contents of user's paste buffer
1105: if (@currpaste) {
1106: foreach my $suffix (@currpaste) {
1.484.2.87 raeburn 1107: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1108: my $url = $env{'docs.markedcopy_url_'.$suffix};
1109: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1110: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1111: ($url ne '')) {
1112: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1113: $pasteurls{$cid.'_'.$mapidx} = 1;
1114: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1115: $pasteurls{$url} = 1;
1116: } else {
1117: $pasteurls{$cid.'_'.$url} = 1;
1118: }
1119: }
1.484.2.30 raeburn 1120: }
1121: }
1122:
1123: # Mark items for copying (skip any items already in user's paste buffer)
1124: my %addtoenv;
1.484.2.82 raeburn 1125:
1126: my @pathitems = split(/\&/,$env{'form.folderpath'});
1127: my @folderconf = split(/\:/,$pathitems[-1]);
1.484.2.87 raeburn 1128: my $ispage = $folderconf[5];
1.484.2.82 raeburn 1129:
1.484.2.30 raeburn 1130: foreach my $item (@possibles) {
1131: my ($orderidx,$cmd) = split(/:/,$item);
1132: next if ($orderidx =~ /\D/);
1133: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1134: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1135: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1136: my %denied = &action_restrictions($coursenum,$coursedom,
1137: &LONCAPA::map::qtescape($url),
1138: $env{'form.folderpath'},\%curr_groups);
1139: next if ($denied{'copy'});
1140: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 1141: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1142: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1143: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1144: next if (exists($pasteurls{$url}));
1145: } else {
1146: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1147: }
1.484.2.30 raeburn 1148: my ($suffix,$errortxt,$locknotfreed) =
1149: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1150: if ($suffix ne '') {
1151: push(@newpaste,$suffix);
1152: } else {
1153: if ($locknotfreed) {
1154: return $locknotfreed;
1155: }
1.484.2.30 raeburn 1156: }
1157: if (&is_supplemental_title($title)) {
1158: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1159: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1160: }
1161:
1162: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1163: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1164: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1165: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1166: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1167: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1168: my $prefix = $1;
1169: my $subdir =$2;
1170: if ($subdir eq '') {
1171: $subdir = $prefix;
1.484.2.7 raeburn 1172: }
1.484.2.30 raeburn 1173: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1174: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1175: \%hierarchy,\%titles,\%allmaps);
1176: if (ref($hierarchy{$url}) eq 'HASH') {
1177: my ($nested,$nestednames);
1178: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1179: $nested =~ s/\&$//;
1180: $nestednames =~ s/\Q___&&&___\E$//;
1181: if ($nested ne '') {
1182: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1183: }
1184: if ($nestednames ne '') {
1185: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1186: }
1.484.2.7 raeburn 1187: }
1188: }
1.484.2.57 raeburn 1189: if ($locknotfreed) {
1190: $output = $locknotfreed;
1191: last;
1192: }
1.484.2.7 raeburn 1193: }
1.484.2.30 raeburn 1194: if (@newpaste) {
1195: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1196: }
1.484.2.7 raeburn 1197: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1198: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1199: return $output;
1.329 droeschl 1200: }
1201:
1.484.2.7 raeburn 1202: sub recurse_uploaded_maps {
1203: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1204: if (ref($hierarchy->{$url}) eq 'HASH') {
1205: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1206: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1207: my (@uploaded,@names,%shorter);
1208: for (my $i=0; $i<@maps; $i++) {
1209: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1210: if ($inner ne '') {
1211: push(@uploaded,$inner);
1212: push(@names,&escape($titles[$i]));
1213: $shorter{$maps[$i]} = $inner;
1214: }
1215: }
1216: $$nestref .= "$dir:".join(',',@uploaded).'&';
1217: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1218: foreach my $map (@maps) {
1219: if ($shorter{$map} ne '') {
1220: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1221: }
1222: }
1223: }
1224: return;
1225: }
1226:
1.329 droeschl 1227: sub print_paste_buffer {
1.484.2.7 raeburn 1228: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1229: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1230:
1.484.2.30 raeburn 1231: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1232: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1233: }
1234:
1.484.2.30 raeburn 1235: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1236: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1237: my $clipboardcount = 0;
1.484.2.7 raeburn 1238:
1.484.2.30 raeburn 1239: # Construct identifiers for current contents of user's paste buffer
1240: foreach my $suffix (@currpaste) {
1241: next if ($suffix =~ /\D/);
1242: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1243: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1244: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1245: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1246: ($url ne '')) {
1.484.2.47 raeburn 1247: $clipboardcount ++;
1.484.2.30 raeburn 1248: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1249: $canpaste,$nopaste,$othercrs,$areachange);
1250: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1251: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1252: $is_external = 1;
1.484.2.7 raeburn 1253: }
1.484.2.30 raeburn 1254: if ($folder =~ /^supplemental/) {
1255: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1256: unless ($canpaste) {
1257: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1258: }
1.484.2.30 raeburn 1259: } else {
1260: $canpaste = 1;
1.484.2.7 raeburn 1261: }
1.484.2.30 raeburn 1262: if ($canpaste) {
1263: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1264: my $srcdom = $1;
1265: my $srcnum = $2;
1266: my $rem = $3;
1267: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1268: $othercourse = 1;
1269: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1270: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1271: } else {
1272: $canpaste = 0;
1273: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1274: }
1275: }
1.484.2.30 raeburn 1276: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1277: my $prefix = $1;
1278: $parent = $2;
1279: if ($folder !~ /^\Q$prefix\E/) {
1280: $areachange = 1;
1281: }
1282: $is_uploaded_map = 1;
1283: }
1.484.2.82 raeburn 1284: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1285: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1286: if ($cid ne $env{'request.course.id'}) {
1287: my ($srcdom,$srcnum) = split(/_/,$cid);
1288: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1289: $othercrs = '<br />'.&mt('(from another course)');
1290: } else {
1291: $canpaste = 0;
1292: $nopaste = &mt('Paste from another course unavailable.');
1293: }
1294: }
1295: }
1296: if ($canpaste) {
1297: push(@pasteable,$suffix);
1.484.2.30 raeburn 1298: }
1299: }
1300: my $buffer;
1301: if ($is_external) {
1302: $buffer = &mt('External Resource').': '.
1303: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1304: &LONCAPA::map::qtescape($url).')';
1305: } else {
1306: my $icon = &Apache::loncommon::icon($extension);
1307: if ($extension eq 'sequence' &&
1308: $url =~ m{/default_\d+\.sequence$}x) {
1309: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1310: $icon .= '/navmap.folder.closed.gif';
1311: }
1.484.2.57 raeburn 1312: my $title = $env{'docs.markedcopy_title_'.$suffix};
1313: if ($title eq '') {
1314: ($title) = ($url =~ m{/([^/]+)$});
1315: }
1.484.2.30 raeburn 1316: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1317: ': '.
1318: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1319: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1320: }
1321: $pasteitems .= '<div class="LC_left_float">';
1322: my ($options,$onclick);
1323: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1324: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1325: if (($is_uploaded_map) ||
1326: ($url =~ /(bulletinboard|smppg)$/) ||
1327: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1328: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1329: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1330: }
1331: }
1332: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1333: if ($nopaste) {
1.484.2.95! raeburn 1334: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.484.2.30 raeburn 1335: } else {
1336: if ($othercrs) {
1337: $pasteitems .= $othercrs;
1338: }
1339: if ($options) {
1340: $pasteitems .= $options;
1.484.2.7 raeburn 1341: }
1342: }
1.484.2.30 raeburn 1343: $pasteitems .= '</div>';
1344: }
1345: }
1346: if ($pasteitems eq '') {
1347: &Apache::lonnet::delenv('docs.markedcopies');
1348: }
1349: my ($pasteform,$form_start,$buttons,$form_end);
1350: if ($pasteitems) {
1351: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1352: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1353: if (@pasteable) {
1.484.2.47 raeburn 1354: my $value = &mt('Paste to current folder');
1355: if ($container eq 'page') {
1356: $value = &mt('Paste to current page');
1357: }
1358: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1359: }
1360: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Clear selected').'" />'.(' 'x2);
1361: if ($clipboardcount > 1) {
1362: $buttons .=
1363: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1364: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1365: (' 'x2).
1366: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1367: (' 'x2);
1.484.2.7 raeburn 1368: }
1.484.2.48 raeburn 1369: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1370: '</form>';
1.484.2.30 raeburn 1371: } else {
1372: $pasteitems = &mt('Clipboard is empty');
1373: }
1374: $r->print($form_start
1375: .'<fieldset>'
1376: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1377: .$pasteitems
1378: .'</fieldset>'
1379: .$form_end);
1380: }
1381:
1382: sub paste_options {
1383: my ($suffix,$is_uploaded_map,$parent) = @_;
1384: my ($copytext,$movetext);
1385: if ($is_uploaded_map) {
1386: $copytext = &mt('Copy to new folder');
1387: $movetext = &mt('Move old');
1388: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1389: $copytext = &mt('Copy to new board');
1390: $movetext = &mt('Move (not posts)');
1391: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1392: $copytext = &mt('Copy to new page');
1393: $movetext = &mt('Move');
1.484.2.7 raeburn 1394: } else {
1.484.2.30 raeburn 1395: $copytext = &mt('Copy to new file');
1396: $movetext = &mt('Move');
1397: }
1398: my $output = '<br />'.
1399: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1400: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1401: '<label>'.
1402: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1403: $copytext.'</label></span>'.(' 'x2).' '.
1404: '<span class="LC_nobreak"><label>'.
1405: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1406: $movetext.'</label></span>';
1407: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1408: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1409: '</legend><table border="0">';
1410: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1411: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1412: my $lastdir = $parent;
1413: my %depths = (
1414: $lastdir => 0,
1415: );
1416: my (%display,%deps);
1417: for (my $i=0; $i<@pastemaps; $i++) {
1418: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1419: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1420: my @subfolders = split(/,/,$subfolderstr);
1421: $deps{$lastdir} = \@subfolders;
1422: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1423: my $depth = $depths{$lastdir} + 1;
1424: my $offset = int($depth * 4);
1425: my $indent = (' ' x $offset);
1426: for (my $j=0; $j<@subfolders; $j++) {
1427: $depths{$subfolders[$j]} = $depth;
1428: $display{$subfolders[$j]} =
1429: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1430: '<td><label>'.
1431: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1432: '<label>'.
1433: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1434: &mt('Move old').'</label>'.
1435: '</td></tr>';
1436: }
1437: }
1438: &recurse_print(\$output,$parent,\%deps,\%display);
1439: $output .= '</table></fieldset>';
1.329 droeschl 1440: }
1.484.2.30 raeburn 1441: $output .= '</div>';
1442: return $output;
1.329 droeschl 1443: }
1444:
1.484.2.7 raeburn 1445: sub recurse_print {
1.484.2.30 raeburn 1446: my ($outputref,$dir,$deps,$display) = @_;
1447: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1448: if (ref($deps->{$dir}) eq 'ARRAY') {
1449: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1450: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1451: }
1452: }
1453: }
1454:
1455: sub supp_pasteable {
1456: my ($url) = @_;
1457: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1458: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1459: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1460: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1461: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
1462: return 1;
1463: }
1464: return;
1465: }
1466:
1467: sub paste_popup_js {
1.484.2.61 raeburn 1468: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1469: show => 'Show Options',
1470: hide => 'Hide Options',
1.484.2.61 raeburn 1471: );
1472: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1473: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1474: );
1.484.2.61 raeburn 1475: &html_escape(\%html_js_lt);
1476: &js_escape(\%html_js_lt);
1477: &js_escape(\%js_lt);
1.484.2.7 raeburn 1478: return <<"END";
1479:
1.484.2.30 raeburn 1480: function showPasteOptions(suffix) {
1481: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1482: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1483: return;
1484: }
1485:
1.484.2.30 raeburn 1486: function hidePasteOptions(suffix) {
1487: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1488: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1489: return;
1490: }
1491:
1.484.2.30 raeburn 1492: function showOptions(caller,suffix) {
1493: if (document.getElementById('pasteoptionstext_'+suffix)) {
1494: if (caller.checked) {
1.484.2.61 raeburn 1495: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1496: } else {
1497: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1498: }
1499: if (document.getElementById('pasteoptions_'+suffix)) {
1500: document.getElementById('pasteoptions_'+suffix).style.display='none';
1501: }
1502: }
1503: return;
1504: }
1.484.2.7 raeburn 1505:
1.484.2.30 raeburn 1506: function validateClipboard() {
1507: var numchk = 0;
1508: if (document.pasteform.pasting.length > 1) {
1509: for (var i=0; i<document.pasteform.pasting.length; i++) {
1510: if (document.pasteform.pasting[i].checked) {
1511: numchk ++;
1512: }
1513: }
1514: } else {
1515: if (document.pasteform.pasting.type == 'checkbox') {
1516: if (document.pasteform.pasting.checked) {
1517: numchk ++;
1518: }
1519: }
1520: }
1521: if (numchk > 0) {
1522: return true;
1523: } else {
1.484.2.61 raeburn 1524: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1525: return false;
1526: }
1.484.2.7 raeburn 1527: }
1528:
1.484.2.47 raeburn 1529: function checkClipboard() {
1530: if (document.pasteform.pasting.length > 1) {
1531: for (var i=0; i<document.pasteform.pasting.length; i++) {
1532: document.pasteform.pasting[i].checked = true;
1533: }
1534: }
1535: return;
1536: }
1537:
1538: function uncheckClipboard() {
1539: if (document.pasteform.pasting.length >1) {
1540: for (var i=0; i<document.pasteform.pasting.length; i++) {
1541: document.pasteform.pasting[i].checked = false;
1542: }
1543: }
1544: return;
1545: }
1546:
1.484.2.30 raeburn 1547: END
1548:
1549: }
1.484.2.7 raeburn 1550:
1.329 droeschl 1551: sub do_paste_from_buffer {
1.484.2.7 raeburn 1552: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1553:
1.484.2.30 raeburn 1554: # Array of items in paste buffer
1555: my (@currpaste,%pastebuffer,%allerrors);
1556: @currpaste = split(/,/,$env{'docs.markedcopies'});
1557:
1.484.2.7 raeburn 1558: # Early out if paste buffer is empty
1.484.2.30 raeburn 1559: if (@currpaste == 0) {
1.484.2.7 raeburn 1560: return ();
1.484.2.30 raeburn 1561: }
1562: map { $pastebuffer{$_} = 1; } @currpaste;
1563:
1564: # Array of items selected items to paste
1565: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1566:
1567: # Early out if nothing selected to paste
1568: if (@reqpaste == 0) {
1569: return();
1570: }
1571: my @topaste;
1572: foreach my $suffix (@reqpaste) {
1573: next if ($suffix =~ /\D/);
1574: next unless (exists($pastebuffer{$suffix}));
1575: push(@topaste,$suffix);
1.484.2.7 raeburn 1576: }
1577:
1.484.2.30 raeburn 1578: # Early out if nothing available to paste
1579: if (@topaste == 0) {
1580: return();
1.329 droeschl 1581: }
1582:
1.484.2.30 raeburn 1583: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.484.2.82 raeburn 1584: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1585:
1.484.2.30 raeburn 1586: foreach my $suffix (@topaste) {
1587: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1588: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1589: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1590: # Supplemental content may only include certain types of content
1591: # Early out if pasted content is not supported in Supplemental area
1592: if ($folder =~ /^supplemental/) {
1593: unless (&supp_pasteable($url)) {
1594: $notinsupp{$suffix} = 1;
1595: next;
1596: }
1597: }
1598: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1599: my $srcd = $1;
1600: my $srcn = $2;
1.484.2.7 raeburn 1601: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1602: # check for mdc privilege in the course from which the resource was pasted
1603: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1604: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1605: $notincrs{$suffix} = 1;
1606: next;
1607: }
1.329 droeschl 1608: }
1.484.2.30 raeburn 1609: $srcdom{$suffix} = $srcd;
1610: $srcnum{$suffix} = $srcn;
1.484.2.82 raeburn 1611: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1612: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1613: my ($srcd,$srcn) = split(/_/,$cid);
1614: # When paste buffer was populated using an active role in a different course
1615: # check for mdc privilege in the course from which the resource was pasted
1616: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1617: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1618: $notincrs{$suffix} = 1;
1619: next;
1620: }
1621: }
1622: $srcdom{$suffix} = $srcd;
1623: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1624: }
1.484.2.82 raeburn 1625: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1626: push(@dopaste,$suffix);
1627: if ($url=~/\.(page|sequence)$/) {
1628: $is_map{$suffix} = 1;
1.329 droeschl 1629: }
1.484.2.30 raeburn 1630:
1631: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1632: my $oldprefix = $1;
1.484.2.19 raeburn 1633: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1634: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1635: # a folder/page or a document).
1.484.2.30 raeburn 1636: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1637: $prefixchg{$suffix} = 'docstosupp';
1638: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1639: $prefixchg{$suffix} = 'supptodocs';
1640: }
1.484.2.7 raeburn 1641:
1642: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1643: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1644: my @nested;
1645: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1646: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1647: my @deps = map { /\d+:([\d,]+$)/ } @items;
1648: foreach my $dep (@deps) {
1649: if ($dep =~ /,/) {
1650: push(@nested,split(/,/,$dep));
1651: } else {
1652: push(@nested,$dep);
1653: }
1.484.2.7 raeburn 1654: }
1.484.2.30 raeburn 1655: foreach my $item (@nested) {
1656: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1657: push(@{$marktomove{$suffix}},$type.'_'.$item);
1658: }
1.484.2.7 raeburn 1659: }
1660: }
1.329 droeschl 1661: }
1.484.2.7 raeburn 1662: }
1663:
1.484.2.30 raeburn 1664: # Early out if nothing available to paste
1665: if (@dopaste == 0) {
1666: return ();
1667: }
1668:
1669: # Populate message hash and hashes used for main content <=> supplemental content
1670: # changes
1671:
1672: %msgs = &Apache::lonlocal::texthash (
1673: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1674: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1675: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1676: );
1677:
1678: %before = (
1679: docstosupp => {
1680: map => 'default',
1681: doc => 'docs',
1682: },
1683: supptodocs => {
1684: map => 'supplemental',
1685: doc => 'supplemental',
1686: },
1687: );
1688:
1689: %after = (
1690: docstosupp => {
1691: map => 'supplemental',
1692: doc => 'supplemental'
1693: },
1694: supptodocs => {
1695: map => 'default',
1696: doc => 'docs',
1697: },
1698: );
1699:
1700: # Retrieve information about all course maps in main content area
1701:
1702: my $allmaps = {};
1.484.2.79 raeburn 1703: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1704:
1705: # Loop over the items to paste
1706: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1707: # Maps need to be copied first
1.484.2.30 raeburn 1708: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1709: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1710: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1711: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1712: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1713: }
1714: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1715: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1716: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1717: my $oldurl = $url;
1718: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1719: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1720: my (%hierarchy,%titles);
1.484.2.79 raeburn 1721: if (($folder =~ /^default/) && (!$donechk)) {
1722: $allmaps =
1723: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1724: $env{"course.$env{'request.course.id'}.home"},
1725: $env{'request.course.id'});
1726: $donechk = 1;
1727: }
1.484.2.30 raeburn 1728: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1729: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1730: if ($url=~ m{^/uploaded/}) {
1731: my $newurl;
1732: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1733: ($newurl,my $error) =
1734: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1735: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1736: \$title,$allmaps,\%newurls);
1737: if ($error) {
1738: $allerrors{$suffix} = $error;
1739: next;
1740: }
1741: if ($newurl ne '') {
1742: if ($newurl ne $url) {
1743: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1744: $newsubdir{$url} = $1;
1745: }
1746: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1747: }
1748: }
1749: }
1.484.2.30 raeburn 1750: if (($srcdom{$suffix} ne $coursedom) ||
1751: ($srcnum{$suffix} ne $coursenum) ||
1752: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1753: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1754: $coursedom,$coursenum,$srcdom{$suffix},
1755: $srcnum{$suffix},$allmaps,\%rewrites,
1756: \%retitles,\%copies,\%dbcopies,
1757: \%zombies,\%params,\%mapmoves,
1758: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 1759: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 1760: $mapmoves{$url} = 1;
1761: }
1762: $url = $newurl;
1763: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1764: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1765: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1766: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1767: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 1768: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 1769: }
1770: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 1771: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1772: push(@toclear,$suffix);
1773: # if pasting published map (main content area only) check map not already in course
1774: if ($folder =~ /^default/) {
1775: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1776: $duplicate{$suffix} = 1;
1777: next;
1778: }
1.484.2.7 raeburn 1779: }
1780: }
1781: }
1.484.2.30 raeburn 1782: if ($url=~ m{/(bulletinboard|smppg)$}) {
1783: my $prefix = $1;
1.484.2.76 raeburn 1784: my $fromothercrs;
1.484.2.30 raeburn 1785: #need to copy the db contents to a new one, unless this is a move.
1786: my %info = (
1787: src => $url,
1788: cdom => $coursedom,
1789: cnum => $coursenum,
1.484.2.76 raeburn 1790: );
1791: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1792: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1793: $fromothercrs = 1;
1794: $info{'cdom'} = $srcdom{$suffix};
1795: $info{'cnum'} = $srcnum{$suffix};
1796: }
1797: }
1798: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1799: my (%lockerr,$msg);
1800: my ($newurl,$result,$errtext) =
1801: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1802: if ($result eq 'ok') {
1803: $url = $newurl;
1804: $title=&mt('Copy of').' '.$title;
1805: } else {
1806: if ($prefix eq 'smppg') {
1807: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1808: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1809: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.30 raeburn 1810: }
1811: $results{$suffix} = $result;
1812: $msgerrs{$suffix} = $msg;
1813: $lockerrs{$suffix} = $lockerr{$prefix};
1814: next;
1815: }
1816: if ($lockerr{$prefix}) {
1817: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1818: }
1.484.2.7 raeburn 1819: }
1.484.2.30 raeburn 1820: }
1821: $title = &LONCAPA::map::qtunescape($title);
1822: my $ext='false';
1823: if ($url=~m{^http(|s)://}) { $ext='true'; }
1824: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1825: if ($folder !~ /^supplemental/) {
1826: (undef,undef,$title) =
1827: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1828: }
1829: } else {
1830: if ($folder=~/^supplemental/) {
1831: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1832: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1833: }
1834: }
1.484.2.7 raeburn 1835:
1836: # For uploaded files (excluding pages/sequences) path in copied file is changed
1837: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1838: # courses.
1839:
1.484.2.30 raeburn 1840: unless ($is_map{$suffix}) {
1841: my $newidx;
1.329 droeschl 1842: # Now insert the URL at the bottom
1.484.2.30 raeburn 1843: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1844: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1845: my $relpath = $1;
1846: if ($relpath ne '') {
1847: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1848: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1849: my $newprefix = $newloc;
1850: if ($newloc eq 'default') {
1851: $newprefix = 'docs';
1852: }
1853: if ($newdocsdir eq '') {
1854: $newdocsdir = 'default';
1855: }
1856: if (($prefixchg{$suffix}) ||
1857: ($srcdom{$suffix} ne $coursedom) ||
1858: ($srcnum{$suffix} ne $coursenum) ||
1859: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1860: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1861: $url =
1862: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1863: &Apache::lonnet::getfile($oldurl));
1864: if ($url eq '/adm/notfound.html') {
1865: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1866: next;
1867: } else {
1868: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1869: $newsubpath =~ s{/+$}{/};
1870: $docmoves{$oldurl} = $newsubpath;
1871: }
1.484.2.7 raeburn 1872: }
1873: }
1.484.2.82 raeburn 1874: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1875: my $template = $1;
1876: if ($newidx) {
1877: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1878: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1879: }
1.484.2.7 raeburn 1880: }
1.484.2.30 raeburn 1881: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1882: ':'.$ext.':normal:res';
1883: push(@LONCAPA::map::order,$newidx);
1884: # Store the result
1885: my ($errtext,$fatal) =
1886: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1887: if ($fatal) {
1888: $save_err .= $errtext;
1889: $allresult = 'fail';
1.484.2.7 raeburn 1890: }
1.329 droeschl 1891: }
1.484.2.30 raeburn 1892:
1.484.2.82 raeburn 1893: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1894: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 1895: unless ($allresult eq 'fail') {
1896: my %updated = (
1897: rewrites => \%rewrites,
1898: zombies => \%zombies,
1899: removefrommap => \%removefrommap,
1900: removeparam => \%removeparam,
1901: dbcopies => \%dbcopies,
1.484.2.82 raeburn 1902: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 1903: retitles => \%retitles,
1904: );
1905: my %info = (
1906: newsubdir => \%newsubdir,
1907: params => \%params,
1908: );
1909: if ($prefixchg{$suffix}) {
1910: $info{'before'} = $before{$prefixchg{$suffix}};
1911: $info{'after'} = $after{$prefixchg{$suffix}};
1912: }
1913: my %moves = (
1914: copies => \%copies,
1915: docmoves => \%docmoves,
1916: mapmoves => \%mapmoves,
1917: );
1918: (my $result,$msgs{$suffix},my $lockerror) =
1919: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1920: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1921: $url,'paste');
1922: $lockerrors .= $lockerror;
1923: if ($result eq 'ok') {
1924: if ($is_map{$suffix}) {
1925: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1926: $folder.'.'.$container);
1927: if ($fatal) {
1928: $allresult = 'failread';
1929: } else {
1930: if ($#LONCAPA::map::order<1) {
1931: my $idx=&LONCAPA::map::getresidx();
1932: if ($idx<=0) { $idx=1; }
1933: $LONCAPA::map::order[0]=$idx;
1934: $LONCAPA::map::resources[$idx]='';
1935: }
1936: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1937: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1938: ':'.$ext.':normal:res';
1939: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 1940:
1941: # Store the result
1.484.2.30 raeburn 1942: my ($errtext,$fatal) =
1943: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1944: if ($fatal) {
1945: $save_err .= $errtext;
1946: $allresult = 'failstore';
1947: }
1948: }
1949: }
1950: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1951: push(@toclear,$suffix);
1952: }
1953: }
1.329 droeschl 1954: }
1955: }
1.484.2.30 raeburn 1956: &clear_from_buffer(\@toclear,\@currpaste);
1957: my $msgsarray;
1958: foreach my $suffix (keys(%msgs)) {
1959: if (ref($msgs{$suffix}) eq 'ARRAY') {
1960: $msgsarray .= join(',',@{$msgs{$suffix}});
1961: }
1962: }
1963: return ($allresult,$save_err,$msgsarray,$lockerrors);
1964: }
1965:
1966: sub do_buffer_empty {
1967: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1968: if (@currpaste == 0) {
1969: return &mt('Clipboard is already empty');
1970: }
1971: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1972: if (@toclear == 0) {
1973: return &mt('Nothing selected to clear from clipboard');
1974: }
1975: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1976: if ($numdel) {
1977: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1978: } else {
1979: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 1980: }
1.484.2.30 raeburn 1981: return;
1982: }
1983:
1984: sub clear_from_buffer {
1985: my ($toclear,$currpaste) = @_;
1986: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1987: my %pastebuffer;
1988: map { $pastebuffer{$_} = 1; } @{$currpaste};
1989: my $numdel = 0;
1990: foreach my $suffix (@{$toclear}) {
1991: next if ($suffix =~ /\D/);
1992: next unless (exists($pastebuffer{$suffix}));
1993: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1994: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1995: delete($pastebuffer{$suffix});
1996: $numdel ++;
1997: }
1998: }
1999: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2000: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2001: return $numdel;
1.484.2.7 raeburn 2002: }
2003:
2004: sub get_newmap_url {
2005: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2006: $titleref,$allmaps,$newurls) = @_;
2007: my $newurl;
2008: if ($url=~ m{^/uploaded/}) {
2009: $$titleref=&mt('Copy of').' '.$$titleref;
2010: }
2011: my $now = time;
2012: my $suffix=$$.int(rand(100)).$now;
2013: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2014: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2015: my $path = $1;
2016: my $prefix = $2;
2017: my $ancestor = $3;
2018: if (length($ancestor) > 10) {
2019: $ancestor = substr($ancestor,-10,10);
2020: }
2021: my $newid;
2022: if ($prefixchg) {
2023: if ($folder =~ /^supplemental/) {
2024: $prefix =~ s/^default/supplemental/;
2025: } else {
2026: $prefix =~ s/^supplemental/default/;
2027: }
2028: }
2029: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2030: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2031: } else {
2032: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2033: }
2034: my $counter = 0;
2035: my $is_unique = &uniqueness_check($newurl);
2036: if ($folder =~ /^default/) {
2037: if ($allmaps->{$newurl}) {
2038: $is_unique = 0;
2039: }
2040: }
2041: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2042: $counter ++;
2043: $suffix ++;
2044: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2045: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2046: } else {
2047: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2048: }
2049: $is_unique = &uniqueness_check($newurl);
2050: }
2051: if ($is_unique) {
2052: $newurls->{$newurl} = 1;
2053: } else {
2054: if ($url=~/\.page$/) {
2055: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2056: } else {
2057: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2058: }
2059: }
2060: }
2061: return ($newurl);
2062: }
2063:
2064: sub dbcopy {
1.484.2.26 raeburn 2065: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2066: my ($url,$result,$errtext);
2067: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2068: $url = $dbref->{'src'};
1.484.2.26 raeburn 2069: if ($url =~ m{/(smppg|bulletinboard)$}) {
2070: my $prefix = $1;
2071: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2072: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2073: my $db_name;
2074: my $marker = (split(m{/},$url))[4];
2075: $marker=~s/\D//g;
2076: if ($dbref->{'src'} =~ m{/smppg$}) {
2077: $db_name =
2078: &Apache::lonsimplepage::get_db_name($url,$marker,
2079: $dbref->{'cdom'},
2080: $dbref->{'cnum'});
2081: } else {
2082: $db_name = 'bulletinpage_'.$marker;
2083: }
2084: my ($suffix,$freedlock,$error) =
2085: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2086: $coursedom,$coursenum,
2087: 'concat');
2088: if (!$suffix) {
2089: if ($prefix eq 'smppg') {
2090: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2091: } else {
1.484.2.42 raeburn 2092: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2093: }
2094: if ($error) {
2095: $errtext .= '<br />'.$error;
2096: }
2097: } else {
2098: #need to copy the db contents to a new one.
2099: my %contents=&Apache::lonnet::dump($db_name,
2100: $dbref->{'cdom'},
2101: $dbref->{'cnum'});
2102: if (exists($contents{'uploaded.photourl'})) {
2103: my $photo = $contents{'uploaded.photourl'};
2104: my ($subdir,$fname) =
2105: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2106: my $newphoto;
2107: if ($fname ne '') {
2108: my $content = &Apache::lonnet::getfile($photo);
2109: unless ($content eq '-1') {
2110: $env{'form.'.$suffix.'.photourl'} = $content;
2111: $newphoto =
2112: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2113: delete($env{'form.'.$suffix.'.photourl'});
2114: }
2115: }
2116: if ($newphoto =~ m{^/uploaded/}) {
2117: $contents{'uploaded.photourl'} = $newphoto;
2118: }
2119: }
2120: $db_name =~ s{_\d*$ }{_$suffix}x;
2121: $result=&Apache::lonnet::put($db_name,\%contents,
2122: $coursedom,$coursenum);
2123: if ($result eq 'ok') {
2124: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2125: }
2126: }
2127: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2128: $lockerrorsref->{$prefix} =
2129: '<div class="LC_error">'.
2130: &mt('There was a problem removing a lockfile.');
2131: if ($prefix eq 'smppg') {
2132: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2133: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.26 raeburn 2134: } else {
1.484.2.42 raeburn 2135: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2136: }
1.484.2.38 raeburn 2137: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2138: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2139: '</div>';
1.484.2.26 raeburn 2140: }
2141: }
2142: } elsif ($url =~ m{/syllabus$}) {
2143: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2144: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2145: if (($dbref->{'cdom'} ne $coursedom) ||
2146: ($dbref->{'cnum'} ne $coursenum)) {
2147: my %contents=&Apache::lonnet::dump('syllabus',
2148: $dbref->{'cdom'},
2149: $dbref->{'cnum'});
2150: $result=&Apache::lonnet::put('syllabus',\%contents,
2151: $coursedom,$coursenum);
2152: }
2153: }
1.484.2.7 raeburn 2154: }
2155: }
1.484.2.26 raeburn 2156: return ($url,$result,$errtext);
1.329 droeschl 2157: }
2158:
1.484.2.82 raeburn 2159: sub copy_templated_files {
2160: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2161: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2162: my $srccontainer = 'sequence';
2163: if ($srcwaspage) {
2164: $srccontainer = 'page';
2165: }
2166: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2167: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2168: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2169: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2170: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2171: $template.'.problem';
2172: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2173: if ($template eq 'simpleproblem') {
2174: $srcprefix .= '.0.';
2175: my $weightprefix = $newprefix;
2176: $newprefix .= '.0.';
2177: my @simpleprobqtypes = qw(radio option string essay numerical);
2178: my $qtype=$srcparms{$srcprefix.'questiontype'};
2179: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2180: my %newdata = (
2181: $newprefix.'questiontype' => $qtype,
1.484.2.84 raeburn 2182: );
1.484.2.82 raeburn 2183: foreach my $type (@simpleprobqtypes) {
2184: if ($type eq $qtype) {
2185: $newdata{"$weightprefix.$type.weight"}=1;
2186: } else {
2187: $newdata{"$weightprefix.$type.weight"}=0;
2188: }
2189: }
2190: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2191: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2192: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2193: if ($qtype eq 'numerical') {
2194: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2195: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2196: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2197: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2198: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2199: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2200: unless (defined($maxfoils)) { $maxfoils=10; }
2201: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2202: if ($maxfoils<=0) { $maxfoils=10; }
2203: my $randomize=$srcparms{$srcprefix.'randomize'};
2204: unless (defined($randomize)) { $randomize='yes'; }
2205: unless ($randomize eq 'no') { $randomize='yes'; }
2206: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2207: $newdata{$newprefix.'randomize'} = $randomize;
2208: if ($qtype eq 'option') {
2209: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2210: }
2211: for (my $i=1; $i<=10; $i++) {
2212: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2213: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2214: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2215: }
2216:
2217: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2218: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2219: unless (defined($maxfoils)) { $maxfoils=10; }
2220: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2221: if ($maxfoils<=0) { $maxfoils=10; }
2222: my $randomize=$srcparms{$srcprefix.'randomize'};
2223: unless (defined($randomize)) { $randomize='yes'; }
2224: unless ($randomize eq 'no') { $randomize='yes'; }
2225: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2226: $newdata{$newprefix.'randomize'} = $randomize;
2227: if ($qtype eq 'option') {
2228: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2229: }
2230: for (my $i=1; $i<=10; $i++) {
2231: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2232: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2233: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2234: }
2235: } elsif ($qtype eq 'string') {
2236: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2237: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2238: }
2239: if (keys(%newdata)) {
2240: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2241: $coursenum);
2242: if ($putres eq 'ok') {
2243: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2244: }
2245: }
2246: }
2247: }
2248: }
2249:
1.329 droeschl 2250: sub uniqueness_check {
2251: my ($newurl) = @_;
2252: my $unique = 1;
2253: foreach my $res (@LONCAPA::map::order) {
2254: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2255: $url=&LONCAPA::map::qtescape($url);
2256: if ($newurl eq $url) {
2257: $unique = 0;
1.344 bisitz 2258: last;
1.329 droeschl 2259: }
2260: }
2261: return $unique;
2262: }
2263:
1.484.2.7 raeburn 2264: sub contained_map_check {
2265: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2266: $allmaps) = @_;
2267: my $content = &Apache::lonnet::getfile($url);
2268: unless ($content eq '-1') {
2269: my $parser = HTML::TokeParser->new(\$content);
2270: $parser->attr_encoded(1);
2271: while (my $token = $parser->get_token) {
2272: next if ($token->[0] ne 'S');
2273: if ($token->[1] eq 'resource') {
2274: next if ($token->[2]->{'type'} eq 'zombie');
2275: my $ressrc = $token->[2]->{'src'};
2276: if ($folder =~ /^supplemental/) {
2277: unless (&supp_pasteable($ressrc)) {
2278: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2279: next;
2280: }
2281: }
2282: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2283: if ($1 eq 'uploaded') {
2284: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2285: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2286: } else {
2287: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2288: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2289: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2290: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2291: } else {
2292: $addedmaps->{$ressrc} = [$url];
2293: }
2294: }
2295: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2296: $addedmaps,$hierarchy,$titles,$allmaps);
2297: }
2298: } elsif ($token->[1] eq 'param') {
2299: if ($folder =~ /^supplemental/) {
2300: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2301: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2302: } else {
1.484.2.19 raeburn 2303: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2304: }
2305: }
2306: }
2307: }
2308: }
2309: return;
2310: }
2311:
2312: sub url_paste_fixups {
1.484.2.26 raeburn 2313: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2314: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2315: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2316: my $checktitle;
2317: if (($prefixchg) &&
2318: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2319: $checktitle = 1;
2320: }
2321: my $skip;
2322: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2323: my $mapid = $1.$2;
2324: if ($tomove->{$mapid}) {
2325: $skip = 1;
2326: }
2327: }
2328: my $file = &Apache::lonnet::getfile($oldurl);
2329: return if ($file eq '-1');
2330: my $parser = HTML::TokeParser->new(\$file);
2331: $parser->attr_encoded(1);
2332: my $changed = 0;
2333: while (my $token = $parser->get_token) {
2334: next if ($token->[0] ne 'S');
2335: if ($token->[1] eq 'resource') {
2336: my $ressrc = $token->[2]->{'src'};
2337: next if ($ressrc eq '');
2338: my $id = $token->[2]->{'id'};
2339: my $title = $token->[2]->{'title'};
2340: if ($checktitle) {
2341: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2342: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2343: }
2344: }
2345: next if ($token->[2]->{'type'} eq 'external');
2346: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2347: next if ($skip);
1.484.2.25 raeburn 2348: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2349: $changed = 1;
2350: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2351: my $srcdom = $1;
2352: my $srcnum = $2;
2353: my $rem = $3;
2354: my $newurl;
2355: my $mapname;
2356: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2357: my $prefix = $1;
2358: $mapname = $prefix.$2;
2359: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2360: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2361: $srcdom,$srcnum,$allmaps,$rewrites,
2362: $retitles,$copies,$dbcopies,$zombies,
2363: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2364: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2365: next;
2366: } else {
2367: ($newurl,my $error) =
2368: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2369: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2370: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2371: $newsubdir->{$ressrc} = $1;
2372: }
2373: if ($error) {
2374: next;
2375: }
2376: }
2377: }
2378: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2379: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2380:
1.484.2.7 raeburn 2381: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2382: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2383: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2384: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2385: $cnum,$srcdom,$srcnum,$allmaps,
2386: $rewrites,$retitles,$copies,$dbcopies,
2387: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2388: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2389: $mapmoves->{$ressrc} = 1;
2390: }
2391: $changed = 1;
2392: } else {
1.484.2.25 raeburn 2393: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2394: $copies->{$oldurl}{$ressrc} = $id;
2395: $changed = 1;
2396: }
2397: }
1.484.2.26 raeburn 2398: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2399: next if ($skip);
1.484.2.7 raeburn 2400: my $srcdom = $1;
2401: my $srcnum = $2;
2402: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2403: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2404: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2405: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2406: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2407: $changed = 1;
2408: }
2409: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2410: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2411: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2412: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2413: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2414: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2415: $changed = 1;
2416: }
1.484.2.82 raeburn 2417: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2418: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2419: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2420: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2421: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2422: }
1.484.2.7 raeburn 2423: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2424: next if ($skip);
2425: my $srcdom = $1;
2426: my $srcnum = $2;
2427: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2428: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2429: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2430: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2431: $changed = 1;
2432: }
2433: }
2434: } elsif ($token->[1] eq 'param') {
2435: next if ($skip);
1.484.2.19 raeburn 2436: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2437: if ($to ne '') {
2438: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2439: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2440: } else {
2441: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2442: }
2443: }
2444: }
2445: }
2446: return $changed;
2447: }
2448:
2449: sub apply_fixups {
1.484.2.23 raeburn 2450: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2451: $oldurl,$url,$caller) = @_;
2452: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2453: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.82 raeburn 2454: %resdatacopy,%lockerrors,$lockmsg);
1.484.2.23 raeburn 2455: if (ref($updated) eq 'HASH') {
2456: if (ref($updated->{'rewrites'}) eq 'HASH') {
2457: %rewrites = %{$updated->{'rewrites'}};
2458: }
2459: if (ref($updated->{'zombies'}) eq 'HASH') {
2460: %zombies = %{$updated->{'zombies'}};
2461: }
2462: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2463: %removefrommap = %{$updated->{'removefrommap'}};
2464: }
2465: if (ref($updated->{'removeparam'}) eq 'HASH') {
2466: %removeparam = %{$updated->{'removeparam'}};
2467: }
2468: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2469: %dbcopies = %{$updated->{'dbcopies'}};
2470: }
2471: if (ref($updated->{'retitles'}) eq 'HASH') {
2472: %retitles = %{$updated->{'retitles'}};
2473: }
1.484.2.82 raeburn 2474: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2475: %resdatacopy = %{$updated->{'resdatacopy'}};
2476: }
1.484.2.23 raeburn 2477: }
2478: if (ref($info) eq 'HASH') {
2479: if (ref($info->{'newsubdir'}) eq 'HASH') {
2480: %newsubdir = %{$info->{'newsubdir'}};
2481: }
2482: if (ref($info->{'params'}) eq 'HASH') {
2483: %params = %{$info->{'params'}};
2484: }
2485: if (ref($info->{'before'}) eq 'HASH') {
2486: %before = %{$info->{'before'}};
2487: }
2488: if (ref($info->{'after'}) eq 'HASH') {
2489: %after = %{$info->{'after'}};
2490: }
2491: }
2492: if (ref($moves) eq 'HASH') {
2493: if (ref($moves->{'copies'}) eq 'HASH') {
2494: %copies = %{$moves->{'copies'}};
2495: }
2496: if (ref($moves->{'docmoves'}) eq 'HASH') {
2497: %docmoves = %{$moves->{'docmoves'}};
2498: }
2499: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2500: %mapmoves = %{$moves->{'mapmoves'}};
2501: }
2502: }
2503: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2504: my @allcopies;
1.484.2.23 raeburn 2505: if (exists($copies{$key})) {
2506: if (ref($copies{$key}) eq 'HASH') {
2507: my %added;
2508: foreach my $innerkey (keys(%{$copies{$key}})) {
2509: if (($innerkey ne '') && (!$added{$innerkey})) {
2510: push(@allcopies,$innerkey);
2511: $added{$innerkey} = 1;
2512: }
1.484.2.7 raeburn 2513: }
1.484.2.23 raeburn 2514: undef(%added);
1.484.2.7 raeburn 2515: }
2516: }
2517: if ($key eq $oldurl) {
1.484.2.23 raeburn 2518: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2519: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2520: push(@allcopies,$oldurl);
2521: }
2522: }
2523: }
2524: if (@allcopies > 0) {
2525: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2526: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2527: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2528: if ($fname ne '') {
2529: my $content = &Apache::lonnet::getfile($item);
2530: unless ($content eq '-1') {
2531: my $storefn;
1.484.2.23 raeburn 2532: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2533: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2534: } else {
2535: $storefn = $relpath;
2536: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2537: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2538: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2539: }
1.484.2.23 raeburn 2540: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2541: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2542: }
2543: }
2544: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2545: my $copyurl =
1.484.2.7 raeburn 2546: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2547: $storefn.$fname,$content);
2548: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2549: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2550: return &mt('Paste failed: an error occurred copying the file.');
2551: } elsif (ref($errors) eq 'HASH') {
2552: $errors->{$item} = 1;
2553: }
2554: }
2555: }
2556: }
2557: }
2558: }
2559: }
1.484.2.23 raeburn 2560: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2561: my $storefn=$key;
2562: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2563: if ($prefixchg && $before{'map'} && $after{'map'}) {
2564: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2565: }
1.484.2.23 raeburn 2566: if ($newsubdir{$key}) {
2567: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2568: }
2569: my $mapcontent = &Apache::lonnet::getfile($key);
1.484.2.95! raeburn 2570: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
! 2571: ($after{'map'} eq 'default') &&
! 2572: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
! 2573: $mapcontent = '<map>'."\n".
! 2574: '<resource id="1" src="" type="start" />'."\n".
! 2575: '<link from="1" to="2" index="1" />'."\n".
! 2576: '<resource id="2" src="" type="finish" />'."\n".
! 2577: '</map>';
! 2578: }
1.484.2.7 raeburn 2579: if ($mapcontent eq '-1') {
2580: if (ref($errors) eq 'HASH') {
2581: $errors->{$key} = 1;
2582: }
2583: } else {
2584: my $newmap =
2585: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2586: $mapcontent);
2587: if ($newmap eq '/adm/notfound.html') {
2588: if (ref($errors) eq 'HASH') {
2589: $errors->{$key} = 1;
2590: }
2591: }
2592: }
2593: }
2594: my %updates;
2595: if ($is_map) {
1.484.2.23 raeburn 2596: if (ref($updated) eq 'HASH') {
2597: foreach my $type (keys(%{$updated})) {
2598: if (ref($updated->{$type}) eq 'HASH') {
2599: foreach my $key (keys(%{$updated->{$type}})) {
2600: $updates{$key} = 1;
2601: }
2602: }
2603: }
1.484.2.7 raeburn 2604: }
2605: foreach my $key (keys(%updates)) {
2606: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2607: if (ref($rewrites{$key}) eq 'HASH') {
2608: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2609: }
1.484.2.23 raeburn 2610: if (ref($retitles{$key}) eq 'HASH') {
2611: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2612: }
1.484.2.23 raeburn 2613: if (ref($removefrommap{$key}) eq 'HASH') {
2614: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2615: }
1.484.2.23 raeburn 2616: if (ref($removeparam{$key}) eq 'HASH') {
2617: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2618: }
1.484.2.23 raeburn 2619: if (ref($zombies{$key}) eq 'HASH') {
2620: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2621: }
1.484.2.23 raeburn 2622: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2623: foreach my $idx (keys(%{$dbcopies{$key}})) {
2624: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2625: my ($newurl,$result,$errtext) =
2626: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2627: if ($result eq 'ok') {
2628: $newdb{$idx} = $newurl;
2629: } elsif (ref($errors) eq 'HASH') {
2630: $errors->{$key} = 1;
2631: }
2632: push(@msgs,$errtext);
2633: }
1.484.2.7 raeburn 2634: }
2635: }
1.484.2.82 raeburn 2636: if (ref($resdatacopy{$key}) eq 'HASH') {
2637: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2638: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2639: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2640: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2641: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2642: my $template = $1;
2643: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2644: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2645: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2646: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2647: unless ($gotnewmapname) {
2648: ($newmapname) = ($key =~ m{/([^/]+)$});
2649: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2650: if ($newsubdir{$key}) {
2651: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2652: }
2653: $gotnewmapname = 1;
2654: }
2655: my $srcmapinfo = $srcfolder.':'.$idx;
2656: if ($srccontainer eq 'page') {
2657: $srcmapinfo .= ':1';
2658: }
2659: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2660: $cnum,$template,$idx,$newmapname);
2661: }
2662: }
2663: }
2664: }
2665: }
1.484.2.23 raeburn 2666: if (ref($params{$key}) eq 'HASH') {
2667: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2668: }
2669: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2670: if ($fatal) {
1.484.2.26 raeburn 2671: return ($errtext);
1.484.2.7 raeburn 2672: }
2673: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2674: if (defined($LONCAPA::map::zombies[$i])) {
2675: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2676: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2677: undef($LONCAPA::map::zombies[$i]);
2678: }
2679: }
2680: }
1.484.2.77 raeburn 2681: my $total = scalar(@LONCAPA::map::order) - 1;
2682: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2683: my $idx = $LONCAPA::map::order[$i];
2684: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2685: my $changed;
1.484.2.23 raeburn 2686: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2687: if ((exists($toremove{$idx})) &&
2688: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2689: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2690: if (ref($currparam{$idx}) eq 'ARRAY') {
2691: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2692: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2693: }
2694: }
2695: next;
2696: }
2697: my $origsrc = $src;
1.484.2.25 raeburn 2698: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2699: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2700: $changed = 1;
2701: }
2702: }
1.484.2.25 raeburn 2703: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2704: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2705: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2706: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2707: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2708: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2709: } else {
1.484.2.23 raeburn 2710: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2711: }
2712: }
1.484.2.25 raeburn 2713: if ($origsrc =~ /\.(page|sequence)$/) {
2714: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2715: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2716: }
1.484.2.25 raeburn 2717: } elsif ($newsubdir{$key}) {
2718: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2719: }
2720: }
2721: $changed = 1;
1.484.2.26 raeburn 2722: } elsif ($newdb{$idx} ne '') {
2723: $src = $newdb{$idx};
1.484.2.7 raeburn 2724: $changed = 1;
2725: }
2726: if ($changed) {
1.484.2.30 raeburn 2727: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2728: }
2729: }
2730: }
2731: foreach my $idx (keys(%remparam)) {
2732: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2733: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2734: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2735: }
2736: }
2737: }
1.484.2.26 raeburn 2738: if (values(%lockerrors) > 0) {
2739: $lockmsg = join('<br />',values(%lockerrors));
2740: }
1.484.2.7 raeburn 2741: my $storefn;
2742: if ($key eq $oldurl) {
2743: $storefn = $url;
2744: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2745: } else {
2746: $storefn = $key;
2747: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2748: if ($prefixchg && $before{'map'} && $after{'map'}) {
2749: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2750: }
1.484.2.23 raeburn 2751: if ($newsubdir{$key}) {
2752: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2753: }
2754: }
2755: my $report;
2756: if ($folder !~ /^supplemental/) {
2757: $report = 1;
2758: }
1.484.2.20 raeburn 2759: (my $outtext,$errtext) =
1.484.2.7 raeburn 2760: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2761: if ($errtext) {
1.484.2.23 raeburn 2762: if ($caller eq 'paste') {
1.484.2.26 raeburn 2763: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2764: }
1.484.2.7 raeburn 2765: }
2766: }
2767: }
1.484.2.26 raeburn 2768: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2769: }
2770:
2771: sub copy_dependencies {
2772: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2773: my $content;
2774: if (ref($contentref)) {
2775: $content = $$contentref;
2776: } else {
2777: $content = &Apache::lonnet::getfile($item);
2778: }
2779: unless ($content eq '-1') {
2780: my $mm = new File::MMagic;
2781: my $mimetype = $mm->checktype_contents($content);
2782: if ($mimetype eq 'text/html') {
2783: my (%allfiles,%codebase,$state);
2784: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2785: if ($res eq 'ok') {
2786: my ($numexisting,$numpathchanges,$existing);
2787: (undef,$numexisting,$numpathchanges,$existing) =
2788: &Apache::loncommon::ask_for_embedded_content(
2789: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2790: {'error_on_invalid_names' => 1,
2791: 'ignore_remote_references' => 1,
2792: 'docs_url' => $item,
2793: 'context' => 'paste'});
2794: if ($numexisting > 0) {
2795: if (ref($existing) eq 'HASH') {
2796: foreach my $dep (keys(%{$existing})) {
2797: my $depfile = $dep;
2798: unless ($depfile =~ m{^\Q$relpath\E}) {
2799: $depfile = $relpath.$dep;
2800: }
2801: my $depcontent = &Apache::lonnet::getfile($depfile);
2802: unless ($depcontent eq '-1') {
2803: my $storedep = $dep;
2804: $storedep =~ s{^\Q$relpath\E}{};
2805: my $dep_url =
2806: &Apache::lonclonecourse::writefile(
2807: $env{'request.course.id'},
2808: $storefn.$storedep,$depcontent);
2809: if ($dep_url eq '/adm/notfound.html') {
2810: if (ref($errors) eq 'HASH') {
2811: $errors->{$depfile} = 1;
2812: }
2813: } else {
2814: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2815: }
2816: }
2817: }
2818: }
2819: }
2820: }
2821: }
2822: }
2823: return;
2824: }
2825:
1.329 droeschl 2826: my %parameter_type = ( 'randompick' => 'int_pos',
2827: 'hiddenresource' => 'string_yesno',
2828: 'encrypturl' => 'string_yesno',
2829: 'randomorder' => 'string_yesno',);
2830: my $valid_parameters_re = join('|',keys(%parameter_type));
2831: # set parameters
2832: sub update_parameter {
1.484.2.29 raeburn 2833: if ($env{'form.changeparms'} eq 'all') {
2834: my (@allidx,@allmapidx,%allchecked,%currchecked);
2835: %allchecked = (
2836: 'hiddenresource' => {},
2837: 'encrypturl' => {},
2838: 'randompick' => {},
2839: 'randomorder' => {},
2840: );
2841: foreach my $which (keys(%allchecked)) {
2842: $env{'form.all'.$which} =~ s/,$//;
2843: if ($which eq 'randompick') {
2844: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2845: my ($res,$value) = split(/:/,$item);
2846: if ($value =~ /^\d+$/) {
2847: $allchecked{$which}{$res} = $value;
2848: }
2849: }
2850: } else {
1.484.2.30 raeburn 2851: if ($env{'form.all'.$which}) {
2852: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2853: }
1.484.2.29 raeburn 2854: }
2855: }
2856: my $haschanges = 0;
2857: foreach my $res (@LONCAPA::map::order) {
2858: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2859: $name=&LONCAPA::map::qtescape($name);
2860: $url=&LONCAPA::map::qtescape($url);
1.484.2.94 raeburn 2861: next unless ($url);
1.484.2.29 raeburn 2862: my $is_map;
2863: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2864: $is_map = 1;
2865: }
2866: foreach my $which (keys(%allchecked)) {
2867: if (($which eq 'randompick' || $which eq 'randomorder')) {
2868: next if (!$is_map);
2869: }
2870: my $oldvalue = 0;
2871: my $newvalue = 0;
2872: if ($allchecked{$which}{$res}) {
2873: $newvalue = $allchecked{$which}{$res};
2874: }
2875: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2876: if ($which eq 'randompick') {
2877: if ($current =~ /^(\d+)$/) {
2878: $oldvalue = $1;
2879: }
2880: } else {
2881: if ($current =~ /^yes$/i) {
2882: $oldvalue = 1;
2883: }
2884: }
2885: if ($oldvalue ne $newvalue) {
2886: $haschanges = 1;
2887: if ($newvalue) {
2888: my $storeval = 'yes';
2889: if ($which eq 'randompick') {
2890: $storeval = $newvalue;
2891: }
2892: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2893: $storeval,
2894: $parameter_type{$which});
2895: &remember_parms($res,$which,'set',$storeval);
2896: } elsif ($oldvalue) {
2897: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2898: &remember_parms($res,$which,'del');
2899: }
2900: }
2901: }
2902: }
2903: return $haschanges;
1.329 droeschl 2904: } else {
1.484.2.59 raeburn 2905: my $haschanges = 0;
2906: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 2907:
1.484.2.29 raeburn 2908: my $which = $env{'form.changeparms'};
2909: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 2910: my $oldvalue = 0;
2911: my $newvalue = 0;
2912: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2913: if ($which eq 'randompick') {
2914: if ($current =~ /^(\d+)$/) {
2915: $oldvalue = $1;
2916: }
2917: } elsif ($current =~ /^yes$/i) {
2918: $oldvalue = 1;
2919: }
1.484.2.29 raeburn 2920: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 2921: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2922: : 1;
1.484.2.29 raeburn 2923: }
1.484.2.59 raeburn 2924: if ($oldvalue ne $newvalue) {
2925: $haschanges = 1;
2926: if ($newvalue) {
2927: my $storeval = 'yes';
2928: if ($which eq 'randompick') {
2929: $storeval = $newvalue;
2930: }
2931: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2932: $parameter_type{$which});
2933: &remember_parms($idx,$which,'set',$storeval);
2934: } else {
2935: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2936: &remember_parms($idx,$which,'del');
2937: }
2938: }
2939: return $haschanges;
1.329 droeschl 2940: }
1.484.2.59 raeburn 2941: return;
1.329 droeschl 2942: }
2943:
2944: sub handle_edit_cmd {
2945: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 2946: if ($env{'form.cmd'} eq '') {
2947: return 0;
2948: }
1.329 droeschl 2949: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2950:
2951: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2952: my ($title, $url, @rrest) = split(':', $ratstr);
2953:
1.484.2.30 raeburn 2954: if ($cmd eq 'remove') {
1.329 droeschl 2955: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2956: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2957: &Apache::lonnet::removeuploadedurl($url);
2958: } else {
2959: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2960: }
2961: splice(@LONCAPA::map::order, $idx, 1);
2962:
2963: } elsif ($cmd eq 'cut') {
2964: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2965: splice(@LONCAPA::map::order, $idx, 1);
2966:
1.344 bisitz 2967: } elsif ($cmd eq 'up'
1.329 droeschl 2968: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2969: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2970:
2971: } elsif ($cmd eq 'down'
2972: && defined($LONCAPA::map::order[$idx+1])) {
2973: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2974:
2975: } elsif ($cmd eq 'rename') {
2976: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2977: if ($comment=~/\S/) {
2978: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2979: $comment.':'.join(':', $url, @rrest);
2980: }
2981: # Devalidate title cache
2982: my $renamed_url=&LONCAPA::map::qtescape($url);
2983: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 2984:
1.329 droeschl 2985: } else {
2986: return 0;
2987: }
2988: return 1;
2989: }
2990:
2991: sub editor {
1.458 raeburn 2992: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.80 raeburn 2993: $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,
2994: $hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 2995: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
2996: if ($allowed) {
2997: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2998: $is_random_order,$container) =
2999: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3000: $r->print($breadcrumbtrail);
3001: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3002: $container = 'page';
3003: } else {
3004: $container = 'sequence';
3005: }
1.484 raeburn 3006:
1.484.2.21 raeburn 3007: my $jumpto;
3008:
3009: unless ($supplementalflag) {
1.484.2.32 raeburn 3010: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 3011: }
1.484 raeburn 3012:
3013: unless ($allowed) {
3014: $randompick = -1;
3015: }
3016:
1.484.2.67 raeburn 3017: my ($errtext,$fatal);
3018: if (($folder eq '') && (!$supplementalflag)) {
3019: if (@LONCAPA::map::order) {
3020: undef(@LONCAPA::map::order);
3021: undef(@LONCAPA::map::resources);
3022: undef(@LONCAPA::map::resparms);
3023: undef(@LONCAPA::map::zombies);
3024: }
3025: $folder = 'default';
3026: $container = 'sequence';
3027: } else {
3028: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3029: $folder.'.'.$container);
3030: return $errtext if ($fatal);
3031: }
1.329 droeschl 3032:
3033: if ($#LONCAPA::map::order<1) {
3034: my $idx=&LONCAPA::map::getresidx();
3035: if ($idx<=0) { $idx=1; }
3036: $LONCAPA::map::order[0]=$idx;
3037: $LONCAPA::map::resources[$idx]='';
3038: }
1.364 bisitz 3039:
1.329 droeschl 3040: # ------------------------------------------------------------ Process commands
3041:
3042: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 3043: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3044: # set parameters and change order
3045: &snapshotbefore();
3046:
3047: if (&update_parameter()) {
1.484.2.59 raeburn 3048: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3049: return $errtext if ($fatal);
3050: }
3051:
3052: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3053: # change order
3054: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3055: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3056:
3057: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3058: return $errtext if ($fatal);
3059: }
1.364 bisitz 3060:
1.329 droeschl 3061: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 3062: my %paste_errors;
1.484.2.26 raeburn 3063: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 3064: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3065: \%paste_errors);
1.484.2.30 raeburn 3066: if (ref($pastemsgarray) eq 'ARRAY') {
3067: if (@{$pastemsgarray} > 0) {
3068: $r->print('<p class="LC_info">'.
3069: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3070: '</p>');
3071: }
1.484.2.30 raeburn 3072: }
3073: if ($lockerror) {
3074: $r->print('<p class="LC_error">'.
3075: $lockerror.
3076: '</p>');
3077: }
3078: if ($save_error ne '') {
3079: return $save_error;
3080: }
3081: if ($paste_res) {
3082: my %errortext = &Apache::lonlocal::texthash (
3083: fail => 'Storage of folder contents failed',
3084: failread => 'Reading folder contents failed',
3085: failstore => 'Storage of folder contents failed',
3086: );
3087: if ($errortext{$paste_res}) {
3088: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3089: }
1.329 droeschl 3090: }
1.484.2.7 raeburn 3091: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3092: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3093: &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".
3094: '<ul>'."\n");
3095: foreach my $key (sort(keys(%paste_errors))) {
3096: $r->print('<li>'.$key.'</li>'."\n");
3097: }
3098: $r->print('</ul></p>'."\n");
3099: }
1.484.2.30 raeburn 3100: } elsif ($env{'form.clearmarked'}) {
3101: my $output = &do_buffer_empty();
3102: if ($output) {
3103: $r->print('<p class="LC_info">'.$output.'</p>');
3104: }
3105: }
1.329 droeschl 3106:
3107: $r->print($upload_output);
3108:
1.484.2.30 raeburn 3109: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3110: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3111: my $contentchg;
1.484.2.58 raeburn 3112: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3113: $contentchg = 1;
3114: }
3115: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3116: return $errtext if ($fatal);
3117: }
1.484.2.30 raeburn 3118:
3119: # Cut, copy and/or remove multiple resources
3120: if ($env{'form.multichange'}) {
3121: my %allchecked = (
3122: cut => {},
3123: remove => {},
3124: );
3125: my $needsupdate;
3126: foreach my $which (keys(%allchecked)) {
3127: $env{'form.multi'.$which} =~ s/,$//;
3128: if ($env{'form.multi'.$which}) {
3129: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3130: if (ref($allchecked{$which}) eq 'HASH') {
3131: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3132: }
3133: }
3134: }
3135: if ($needsupdate) {
3136: my $haschanges = 0;
3137: my %curr_groups = &Apache::longroup::coursegroups();
3138: my $total = scalar(@LONCAPA::map::order) - 1;
3139: for (my $i=$total; $i>=0; $i--) {
3140: my $res = $LONCAPA::map::order[$i];
3141: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3142: $name=&LONCAPA::map::qtescape($name);
3143: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3144: next unless $url;
1.484.2.30 raeburn 3145: my %denied =
3146: &action_restrictions($coursenum,$coursedom,$url,
3147: $env{'form.folderpath'},\%curr_groups);
3148: foreach my $which (keys(%allchecked)) {
3149: next if ($denied{$which});
3150: next unless ($allchecked{$which}{$res});
3151: if ($which eq 'remove') {
3152: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3153: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3154: &Apache::lonnet::removeuploadedurl($url);
3155: } else {
3156: &LONCAPA::map::makezombie($res);
3157: }
3158: splice(@LONCAPA::map::order,$i,1);
3159: $haschanges ++;
3160: } elsif ($which eq 'cut') {
3161: &LONCAPA::map::makezombie($res);
3162: splice(@LONCAPA::map::order,$i,1);
3163: $haschanges ++;
3164: }
3165: }
3166: }
3167: if ($haschanges) {
3168: ($errtext,$fatal) =
3169: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3170: return $errtext if ($fatal);
3171: }
3172: }
3173: }
3174:
1.329 droeschl 3175: # Group import/search
3176: if ($env{'form.importdetail'}) {
3177: my @imports;
3178: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3179: if (defined($item)) {
3180: my ($name,$url,$residx)=
1.484.2.26 raeburn 3181: map { &unescape($_); } split(/\=/,$item);
3182: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3183: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3184: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3185: if ($locknotfreed) {
3186: $r->print($locknotfreed);
3187: }
3188: if ($suffix) {
1.484.2.19 raeburn 3189: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3190: } else {
3191: return $errortxt;
3192: }
1.484.2.26 raeburn 3193: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3194: my $type = $1;
3195: my ($suffix,$errortxt,$locknotfreed) =
3196: &new_timebased_suffix($coursedom,$coursenum,$type);
3197: if ($locknotfreed) {
3198: $r->print($locknotfreed);
3199: }
3200: if ($suffix) {
3201: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3202: } else {
3203: return $errortxt;
3204: }
1.484.2.27 raeburn 3205: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3206: if ($supplementalflag) {
3207: next unless ($1 eq 'supplemental');
3208: if ($folder eq 'supplemental') {
3209: next unless ($2 eq 'default');
3210: } else {
3211: next unless ($folder eq 'supplemental_'.$2);
3212: }
3213: } else {
3214: next unless ($1 eq 'docs');
3215: if ($folder eq 'default') {
3216: next unless ($2 eq 'default');
3217: } else {
3218: next unless ($folder eq 'default_'.$2);
3219: }
3220: }
1.484.2.15 raeburn 3221: }
1.329 droeschl 3222: push(@imports, [$name, $url, $residx]);
3223: }
3224: }
1.484.2.23 raeburn 3225: ($errtext,$fatal,my $fixuperrors) =
3226: &group_import($coursenum, $coursedom, $folder,$container,
3227: 'londocs',@imports);
1.329 droeschl 3228: return $errtext if ($fatal);
1.484.2.23 raeburn 3229: if ($fixuperrors) {
3230: $r->print($fixuperrors);
3231: }
1.329 droeschl 3232: }
3233: # Loading a complete map
3234: if ($env{'form.loadmap'}) {
3235: if ($env{'form.importmap'}=~/\w/) {
3236: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3237: my ($title,$url,$ext,$type)=split(/\:/,$res);
3238: my $idx=&LONCAPA::map::getresidx($url);
3239: $LONCAPA::map::resources[$idx]=$res;
3240: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3241: }
3242: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3243: $folder.'.'.$container,1);
1.329 droeschl 3244: return $errtext if ($fatal);
3245: } else {
3246: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3247:
1.329 droeschl 3248: }
3249: }
3250: &log_differences($plain);
3251: }
3252: # ---------------------------------------------------------------- End commands
3253: # ---------------------------------------------------------------- Print screen
3254: my $idx=0;
3255: my $shown=0;
3256: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3257: $r->print('<div class="LC_Box">'.
1.432 raeburn 3258: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3259: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3260: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3261: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3262: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3263: '</ol>');
1.381 bisitz 3264: if ($randompick>=0) {
3265: $r->print('<p class="LC_warning">'
3266: .&mt('Caution: this folder is set to randomly pick a subset'
3267: .' of resources. Adding or removing resources from this'
3268: .' folder will change the set of resources that the'
3269: .' students see, resulting in spurious or missing credit'
3270: .' for completed problems, not limited to ones you'
3271: .' modify. Do not modify the contents of this folder if'
3272: .' it is in active student use.')
3273: .'</p>'
3274: );
3275: }
3276: if ($is_random_order) {
3277: $r->print('<p class="LC_warning">'
3278: .&mt('Caution: this folder is set to randomly order its'
3279: .' contents. Adding or removing resources from this folder'
3280: .' will change the order of resources shown.')
3281: .'</p>'
3282: );
3283: }
3284: $r->print('</div>');
1.364 bisitz 3285: }
1.381 bisitz 3286:
1.484.2.30 raeburn 3287: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3288: %filters = (
3289: canremove => [],
3290: cancut => [],
3291: cancopy => [],
3292: hiddenresource => [],
3293: encrypturl => [],
3294: randomorder => [],
3295: randompick => [],
3296: );
3297: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3298: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3299: foreach my $res (@LONCAPA::map::order) {
3300: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3301: $name=&LONCAPA::map::qtescape($name);
3302: $url=&LONCAPA::map::qtescape($url);
3303: unless ($name) { $name=(split(/\//,$url))[-1]; }
3304: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3305: push(@allidx,$res);
3306: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3307: push(@allmapidx,$res);
3308: }
1.484.2.67 raeburn 3309:
1.381 bisitz 3310: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3311: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3312: $pathitem,$supplementalflag,$container,
1.484.2.70 raeburn 3313: \%filters,\%curr_groups,$canedit,
1.484.2.80 raeburn 3314: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3315: $idx++;
3316: $shown++;
1.329 droeschl 3317: }
1.424 onken 3318: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3319:
1.484.2.30 raeburn 3320: my $need_save;
1.484.2.67 raeburn 3321: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3322: my $toolslink;
1.484.2.67 raeburn 3323: if ($allowed) {
1.484.2.31 raeburn 3324: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3325: .&Apache::loncommon::help_open_menu('Navigation Screen',
3326: 'Navigation_Screen',undef,'RAT')
3327: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3328: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3329: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3330: .'id="LC_content_toolbar_edittoplevel" '
3331: .'class="LC_toolbarItem" '
3332: .'title="'.&mt('Supplemental Content Editor').'">'
3333: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3334: }
1.484.2.19 raeburn 3335: if ($shown) {
3336: if ($allowed) {
3337: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3338: .&Apache::loncommon::start_data_table(undef,'contentlist')
3339: .&Apache::loncommon::start_data_table_header_row()
3340: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3341: .'<th colspan="2">'.&mt('Actions').'</th>'
3342: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3343: if ($folder !~ /^supplemental/) {
3344: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3345: }
1.484.2.29 raeburn 3346: $to_show .= &Apache::loncommon::end_data_table_header_row();
3347: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3348: $lists{'canhide'} = join(',',@allidx);
3349: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3350: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3351: 'randomorder','randompick');
3352: foreach my $item (@possfilters) {
3353: if (ref($filters{$item}) eq 'ARRAY') {
3354: if (@{$filters{$item}} > 0) {
3355: $lists{$item} = join(',',@{$filters{$item}});
3356: }
3357: }
3358: }
1.484.2.29 raeburn 3359: if (@allidx > 0) {
3360: my $path;
3361: if ($env{'form.folderpath'}) {
3362: $path =
3363: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3364: }
1.484.2.30 raeburn 3365: if (@allidx > 1) {
3366: $to_show .=
3367: &Apache::loncommon::continue_data_table_row().
3368: '<td colspan="2"> </td>'.
3369: '<td>'.
1.484.2.67 raeburn 3370: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3371: '</td>'.
3372: '<td> </td>'.
3373: '<td> </td>'.
3374: '<td colspan="4">'.
1.484.2.67 raeburn 3375: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3376: '</td>'.
3377: &Apache::loncommon::end_data_table_row();
3378: $need_save = 1;
3379: }
1.484.2.29 raeburn 3380: }
3381: }
3382: $to_show .= $output.' '
1.484.2.19 raeburn 3383: .&Apache::loncommon::end_data_table()
3384: .'<br style="line-height:2px;" />'
3385: .&Apache::loncommon::end_scrollbox();
3386: } else {
3387: $to_show .= $toolslink
3388: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3389: .$output.' '
3390: .&Apache::loncommon::end_data_table();
3391: }
3392: } else {
3393: if (!$allowed) {
3394: $to_show .= $toolslink;
1.393 raeburn 3395: }
1.484.2.67 raeburn 3396: my $noresmsg;
3397: if ($allowed && $hiddentop && !$supplementalflag) {
3398: $noresmsg = &mt('Main Content Hidden');
3399: } else {
3400: $noresmsg = &mt('Currently empty');
3401: }
1.484.2.19 raeburn 3402: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3403: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3404: .$noresmsg
1.484.2.19 raeburn 3405: .'</div>'
3406: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3407: }
3408: } else {
1.484.2.19 raeburn 3409: if ($shown) {
3410: $to_show = '<div>'
3411: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3412: .$output
3413: .&Apache::loncommon::end_data_table()
3414: .'</div>';
3415: } else {
3416: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3417: .&mt('Currently empty')
1.484.2.19 raeburn 3418: .'</div>'
3419: }
1.458 raeburn 3420: }
3421: my $tid = 1;
3422: if ($supplementalflag) {
3423: $tid = 2;
1.329 droeschl 3424: }
3425: if ($allowed) {
1.484 raeburn 3426: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3427: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3428: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3429: if ($canedit) {
1.484.2.67 raeburn 3430: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3431: }
1.460 raeburn 3432: } else {
3433: $r->print($to_show);
1.329 droeschl 3434: }
3435: return;
3436: }
3437:
1.484.2.30 raeburn 3438: sub multiple_check_form {
1.484.2.67 raeburn 3439: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3440: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3441: my $disabled;
3442: unless ($canedit) {
1.484.2.95! raeburn 3443: $disabled = ' disabled="disabled"';
1.484.2.67 raeburn 3444: }
1.484.2.30 raeburn 3445: my $output =
3446: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3447: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3448: '<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>'.
3449: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3450: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3451: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3452: if ($caller eq 'settings') {
3453: $output .=
3454: '<table><tr>'.
3455: '<td class="LC_docs_entry_parameter">'.
3456: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3457: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3458: '</label></span></td>'.
3459: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3460: '<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 3461: '</span></td>'.
3462: '</tr>'."\n".
3463: '<tr>'.
3464: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3465: '<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 3466: '</label></span>'.
3467: '</td></tr></table>'."\n";
3468: } else {
3469: $output .=
3470: '<table><tr>'.
3471: '<td class="LC_docs_entry_parameter">'.
3472: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3473: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3474: '</label></span></td>'.
3475: '<td class="LC_docs_entry_parameter">'.
3476: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3477: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3478: '</label></span></td>'."\n".
3479: '<td class="LC_docs_entry_parameter">'.
3480: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3481: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3482: '</label></span></td>'.
3483: '</tr></table>'."\n";
3484: }
3485: $output .=
3486: '</fieldset>'.
3487: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3488: if ($caller eq 'settings') {
3489: $output .=
3490: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3491: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3492: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3493: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3494: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3495: } elsif ($caller eq 'actions') {
3496: $output .=
3497: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3498: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3499: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3500: }
3501: $output .=
3502: '</form>'.
3503: '</div>';
3504: return $output;
3505: }
3506:
1.329 droeschl 3507: sub process_file_upload {
1.484.2.36 raeburn 3508: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3509: # upload a file, if present
1.484.2.36 raeburn 3510: my $filesize = length($env{'form.uploaddoc'});
3511: if (!$filesize) {
3512: $$upload_output = '<div class="LC_error">'.
3513: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3514: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3515: $filesize).'<br />'.
3516: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3517: '</div>';
3518: return;
3519: }
3520: my $quotatype = 'unofficial';
3521: if ($crstype eq 'Community') {
3522: $quotatype = 'community';
1.484.2.51 raeburn 3523: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3524: $quotatype = 'official';
1.484.2.45 raeburn 3525: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3526: $quotatype = 'textbook';
1.484.2.36 raeburn 3527: }
3528: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3529: $filesize = int($filesize/1000); #expressed in kb
3530: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3531: $env{'form.uploaddoc.filename'},$filesize,
3532: 'upload',$quotatype);
1.484.2.36 raeburn 3533: return if ($$upload_output);
3534: }
1.440 raeburn 3535: my ($parseaction,$showupload,$nextphase,$mimetype);
3536: if ($env{'form.parserflag'}) {
1.329 droeschl 3537: $parseaction = 'parse';
3538: }
3539: my $folder=$env{'form.folder'};
3540: if ($folder eq '') {
3541: $folder='default';
3542: }
3543: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3544: my $errtext='';
3545: my $fatal=0;
3546: my $container='sequence';
1.484.2.19 raeburn 3547: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3548: $container='page';
3549: }
3550: ($errtext,$fatal)=
1.484.2.27 raeburn 3551: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3552: if ($#LONCAPA::map::order<1) {
3553: $LONCAPA::map::order[0]=1;
3554: $LONCAPA::map::resources[1]='';
3555: }
3556: my $destination = 'docs/';
3557: if ($folder =~ /^supplemental/) {
3558: $destination = 'supplemental/';
3559: }
3560: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3561: $destination .= 'default/';
3562: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3563: $destination .= $2.'/';
3564: }
1.484.2.27 raeburn 3565: if ($fatal) {
3566: $$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>';
3567: return;
3568: }
1.440 raeburn 3569: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3570: my $newidx=&LONCAPA::map::getresidx();
3571: $destination .= $newidx;
1.439 raeburn 3572: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3573: $parseaction,$allfiles,
1.440 raeburn 3574: $codebase,undef,undef,undef,undef,
3575: undef,undef,\$mimetype);
3576: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3577: my $stored = $1;
3578: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3579: $stored.'</span>').'</p>';
3580: } else {
3581: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3582:
1.457 raeburn 3583: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3584: return;
3585: }
1.329 droeschl 3586: my $ext='false';
3587: if ($url=~m{^http://}) { $ext='true'; }
3588: $url = &LONCAPA::map::qtunescape($url);
3589: my $comment=$env{'form.comment'};
3590: $comment = &LONCAPA::map::qtunescape($comment);
3591: if ($folder=~/^supplemental/) {
3592: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3593: $env{'user.domain'}.'___&&&___'.$comment;
3594: }
3595:
3596: $LONCAPA::map::resources[$newidx]=
3597: $comment.':'.$url.':'.$ext.':normal:res';
3598: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3599: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3600: $folder.'.'.$container,1);
1.329 droeschl 3601: if ($fatal) {
1.457 raeburn 3602: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3603: return;
1.329 droeschl 3604: } else {
1.440 raeburn 3605: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3606: $$upload_output = $showupload;
1.384 raeburn 3607: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3608: if ($total_embedded > 0) {
1.440 raeburn 3609: my $uploadphase = 'upload_embedded';
3610: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3611: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3612: my ($embedded,$num) =
3613: &Apache::loncommon::ask_for_embedded_content(
3614: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3615: if ($embedded) {
3616: if ($num) {
3617: $$upload_output .=
3618: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3619: $nextphase = $uploadphase;
3620: } else {
3621: $$upload_output .= $embedded;
3622: }
3623: } else {
3624: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3625: }
1.329 droeschl 3626: } else {
1.440 raeburn 3627: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3628: }
1.457 raeburn 3629: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3630: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3631: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3632: $nextphase = 'decompress_uploaded';
3633: my $position = scalar(@LONCAPA::map::order)-1;
3634: my $noextract = &return_to_editor();
3635: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3636: my %archiveitems = (
3637: folderpath => $env{'form.folderpath'},
3638: cmd => $nextphase,
3639: newidx => $newidx,
3640: position => $position,
3641: phase => $nextphase,
1.477 raeburn 3642: comment => $comment,
1.480 raeburn 3643: );
3644: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3645: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3646: $$upload_output = $showupload.
3647: &Apache::loncommon::decompress_form($mimetype,
3648: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3649: \%archiveitems,\@current);
1.329 droeschl 3650: }
3651: }
3652: }
1.440 raeburn 3653: return $nextphase;
1.329 droeschl 3654: }
3655:
1.480 raeburn 3656: sub get_dir_list {
3657: my ($url,$coursenum,$coursedom,$newidx) = @_;
3658: my ($destination,$dir_root) = &embedded_destination();
3659: my ($dirlistref,$listerror) =
3660: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3661: my @dir_lines;
3662: my $dirptr=16384;
3663: if (ref($dirlistref) eq 'ARRAY') {
3664: foreach my $dir_line (sort
3665: {
3666: my ($afile)=split('&',$a,2);
3667: my ($bfile)=split('&',$b,2);
3668: return (lc($afile) cmp lc($bfile));
3669: } (@{$dirlistref})) {
3670: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3671: $filename =~ s/\s+$//;
3672: next if ($filename =~ /^\.\.?$/);
3673: my $isdir = 0;
3674: if ($dirptr&$testdir) {
3675: $isdir = 1;
3676: }
3677: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3678: }
3679: }
3680: return @dir_lines;
3681: }
3682:
1.329 droeschl 3683: sub is_supplemental_title {
3684: my ($title) = @_;
3685: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3686: }
3687:
3688: # --------------------------------------------------------------- An entry line
3689:
3690: sub entryline {
1.484.2.12 raeburn 3691: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3692: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.80 raeburn 3693: $canedit,$isencrypted,$navmapref,$hostname)=@_;
1.484.2.52 raeburn 3694: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3695: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3696: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3697: } else {
3698: $title=&HTML::Entities::encode($title,'"<>&\'');
3699: $renametitle=$title;
3700: $foldertitle=$title;
3701: }
3702:
1.484.2.67 raeburn 3703: my ($disabled,$readonly,$js_lt);
3704: unless ($canedit) {
3705: $disabled = 'disabled="disabled"';
3706: $readonly = 1;
3707: }
3708:
1.329 droeschl 3709: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3710:
1.329 droeschl 3711: $renametitle=~s/\\/\\\\/g;
3712: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3713: $renametitle=~s/"/%22/g;
1.329 droeschl 3714: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3715: $oldtitle = $renametitle;
3716: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3717: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3718: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3719: # Edit commands
1.484.2.95! raeburn 3720: my ($esc_path, $path, $symb, $shownsymb);
1.329 droeschl 3721: if ($env{'form.folderpath'}) {
3722: $esc_path=&escape($env{'form.folderpath'});
3723: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3724: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3725: }
1.484.2.16 raeburn 3726: my $isexternal;
1.484.2.19 raeburn 3727: if ($residx) {
1.484.2.12 raeburn 3728: my $currurl = $url;
3729: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3730: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3731: $isexternal = 1;
3732: }
1.484.2.19 raeburn 3733: if (!$supplementalflag) {
3734: my $path = 'uploaded/'.
3735: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3736: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3737: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3738: $residx,
3739: &Apache::lonnet::declutter($currurl));
3740: }
1.484.2.12 raeburn 3741: }
1.484.2.30 raeburn 3742: my ($renamelink,%lt,$ishash);
3743: if (ref($filtersref) eq 'HASH') {
3744: $ishash = 1;
3745: }
3746:
1.329 droeschl 3747: if ($allowed) {
1.484.2.30 raeburn 3748: $form_start = '
3749: <form action="/adm/coursedocs" method="post">
3750: ';
3751: $form_common=(<<END);
3752: <input type="hidden" name="folderpath" value="$path" />
3753: <input type="hidden" name="symb" value="$symb" />
3754: END
3755: $form_param=(<<END);
3756: <input type="hidden" name="setparms" value="$orderidx" />
3757: <input type="hidden" name="changeparms" value="0" />
3758: END
3759: $form_end = '</form>';
3760:
1.329 droeschl 3761: my $incindex=$index+1;
3762: my $selectbox='';
1.471 raeburn 3763: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3764: ((split(/\:/,
1.344 bisitz 3765: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3766: ne '') &&
1.329 droeschl 3767: ((split(/\:/,
1.344 bisitz 3768: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3769: ne '')) {
3770: $selectbox=
3771: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3772: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3773: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3774: if ($i==$incindex) {
1.358 bisitz 3775: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3776: } else {
3777: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3778: }
3779: }
3780: $selectbox.='</select>';
3781: }
1.484.2.12 raeburn 3782: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3783: 'up' => 'Move Up',
3784: 'dw' => 'Move Down',
3785: 'rm' => 'Remove',
3786: 'ct' => 'Cut',
3787: 'rn' => 'Rename',
1.484.2.12 raeburn 3788: 'cp' => 'Copy',
3789: 'ex' => 'External Resource',
3790: 'ed' => 'Edit',
3791: 'pr' => 'Preview',
3792: 'sv' => 'Save',
3793: 'ul' => 'URL',
1.484.2.67 raeburn 3794: 'ti' => 'Title',
3795: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3796: );
1.484.2.30 raeburn 3797: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3798: $env{'form.folderpath'},
3799: $currgroups);
1.484.2.19 raeburn 3800: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3801: my $skip_confirm = 0;
1.484.2.63 raeburn 3802: my $confirm_removal = 0;
1.329 droeschl 3803: if ( $folder =~ /^supplemental/
3804: || ($url =~ m{( /smppg$
3805: |/syllabus$
3806: |/aboutme$
3807: |/navmaps$
3808: |/bulletinboard$
1.484.2.16 raeburn 3809: |\.html$)}x)
1.484.2.19 raeburn 3810: || $isexternal) {
1.329 droeschl 3811: $skip_confirm = 1;
3812: }
1.484.2.63 raeburn 3813: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3814: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3815: $confirm_removal = 1;
3816: }
1.484.2.19 raeburn 3817:
1.484.2.30 raeburn 3818: if ($denied{'copy'}) {
3819: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3820: <span style="visibility: hidden;">$lt{'cp'}</span>
3821: ENDCOPY
3822: } else {
1.484.2.30 raeburn 3823: my $formname = 'edit_copy_'.$orderidx;
3824: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3825: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3826: <form name="$formname" method="post" action="/adm/coursedocs">
3827: $form_common
1.484.2.67 raeburn 3828: <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 3829: $form_end
1.329 droeschl 3830: ENDCOPY
1.484.2.30 raeburn 3831: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3832: push(@{$filtersref->{'cancopy'}},$orderidx);
3833: }
1.329 droeschl 3834: }
1.484.2.30 raeburn 3835: if ($denied{'cut'}) {
1.484.2.16 raeburn 3836: $cutlink=(<<ENDCUT);
3837: <span style="visibility: hidden;">$lt{'ct'}</span>
3838: ENDCUT
3839: } else {
1.484.2.30 raeburn 3840: my $formname = 'edit_cut_'.$orderidx;
3841: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3842: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3843: <form name="$formname" method="post" action="/adm/coursedocs">
3844: $form_common
3845: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3846: <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 3847: $form_end
1.329 droeschl 3848: ENDCUT
1.484.2.30 raeburn 3849: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3850: push(@{$filtersref->{'cancut'}},$orderidx);
3851: }
1.329 droeschl 3852: }
1.484.2.30 raeburn 3853: if ($denied{'remove'}) {
1.484.2.16 raeburn 3854: $removelink=(<<ENDREM);
3855: <span style="visibility: hidden;">$lt{'rm'}</a>
3856: ENDREM
3857: } else {
1.484.2.30 raeburn 3858: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 3859: 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 3860: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3861: <form name="$formname" method="post" action="/adm/coursedocs">
3862: $form_common
3863: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 3864: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 3865: <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 3866: $form_end
1.484.2.9 raeburn 3867: ENDREM
1.484.2.30 raeburn 3868: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3869: push(@{$filtersref->{'canremove'}},$orderidx);
3870: }
1.484.2.9 raeburn 3871: }
1.484.2.35 raeburn 3872: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 3873: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3874: ENDREN
1.484.2.67 raeburn 3875: my ($uplink,$downlink);
3876: if ($canedit) {
3877: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3878: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3879: } else {
3880: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3881: $downlink = $uplink;
3882: }
1.329 droeschl 3883: $line.=(<<END);
3884: <td>
1.379 bisitz 3885: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3886: <a href="$uplink">
1.484.2.12 raeburn 3887: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3888: </a>
3889: </div>
3890: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3891: <a href="$downlink">
1.484.2.12 raeburn 3892: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3893: </a>
3894: </div>
1.329 droeschl 3895: </td>
3896: <td>
3897: $form_start
1.484.2.30 raeburn 3898: $form_param
1.478 raeburn 3899: $form_common
1.329 droeschl 3900: $selectbox
3901: $form_end
3902: </td>
1.484.2.30 raeburn 3903: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 3904: $removelink
1.329 droeschl 3905: $cutlink
3906: $copylink
3907: </td>
3908: END
3909: }
3910: # Figure out what kind of a resource this is
3911: my ($extension)=($url=~/\.(\w+)$/);
3912: my $uploaded=($url=~/^\/*uploaded\//);
3913: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 3914: my $isfolder;
3915: my $ispage;
3916: my $containerarg;
1.484.2.67 raeburn 3917: my $folderurl;
1.329 droeschl 3918: if ($uploaded) {
1.472 raeburn 3919: if (($extension eq 'sequence') || ($extension eq 'page')) {
3920: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 3921: $containerarg = $1;
1.472 raeburn 3922: if ($extension eq 'sequence') {
3923: $icon=$iconpath.'navmap.folder.closed.gif';
3924: $isfolder=1;
3925: } else {
3926: $icon=$iconpath.'page.gif';
3927: $ispage=1;
3928: }
1.484.2.67 raeburn 3929: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3930: if ($allowed) {
3931: $url='/adm/coursedocs?';
3932: } else {
3933: $url='/adm/supplemental?';
3934: }
1.329 droeschl 3935: } else {
3936: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3937: }
3938: }
1.364 bisitz 3939:
1.484.2.70 raeburn 3940: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3941: my $orig_url = $url;
1.340 raeburn 3942: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 3943: if ($container eq 'page') {
3944: $url=~s{^http(|s)(:|:)//}{/ext/};
3945: } else {
3946: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
3947: }
1.484.2.12 raeburn 3948: if (!$supplementalflag && $residx && $symb) {
3949: if ((!$isfolder) && (!$ispage)) {
3950: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.484.2.87 raeburn 3951: if (($url =~ m{^ext/}) && ($container eq 'page')) {
3952: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
3953: } else {
3954: $url=&Apache::lonnet::clutter($url);
3955: }
1.484.2.12 raeburn 3956: if ($url=~/^\/*uploaded\//) {
3957: $url=~/\.(\w+)$/;
3958: my $embstyle=&Apache::loncommon::fileembstyle($1);
3959: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3960: $url='/adm/wrapper'.$url;
3961: } elsif ($embstyle eq 'ssi') {
3962: #do nothing with these
3963: } elsif ($url!~/\.(sequence|page)$/) {
3964: $url='/adm/coursedocs/showdoc'.$url;
3965: }
1.484.2.70 raeburn 3966: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
3967: my $wrapped = $1;
3968: my $exturl = $2;
1.484.2.87 raeburn 3969: if (($wrapped eq '') && ($container ne 'page')) {
1.484.2.70 raeburn 3970: $url='/adm/wrapper'.$url;
3971: }
3972: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
3973: $nomodal = 1;
3974: }
3975: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
3976: if (($ENV{'SERVER_PORT'} == 443) &&
3977: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 3978: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 3979: $url .= '?usehttp=1';
3980: }
1.484.2.70 raeburn 3981: $nomodal = 1;
3982: }
1.484.2.19 raeburn 3983: }
1.484.2.12 raeburn 3984: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.95! raeburn 3985: $shownsymb = $symb;
1.484.2.66 raeburn 3986: if ($isexternal) {
1.484.2.88 raeburn 3987: $url =~ s/\#[^#]+$//;
1.484.2.87 raeburn 3988: if ($container eq 'page') {
3989: $url = &Apache::lonnet::clutter($url);
3990: }
1.484.2.66 raeburn 3991: }
1.484.2.67 raeburn 3992: unless ($env{'request.role.adv'}) {
3993: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3994: $url = '';
3995: }
3996: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
3997: $url = '';
3998: $hiddenres = 1;
3999: }
4000: }
4001: if ($url ne '') {
1.484.2.75 raeburn 4002: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 4003: }
4004: } elsif (!$env{'request.role.adv'}) {
4005: my $checkencrypt;
4006: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4007: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4008: $checkencrypt = 1;
1.484.2.70 raeburn 4009: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 4010: unless (ref($$navmapref)) {
4011: $$navmapref = Apache::lonnavmaps::navmap->new();
4012: }
4013: if (ref($$navmapref)) {
4014: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4015: $checkencrypt = 1;
4016: }
4017: }
4018: }
4019: if ($checkencrypt) {
1.484.2.95! raeburn 4020: $shownsymb = &Apache::lonenc::encrypted($symb);
1.484.2.67 raeburn 4021: my $shownurl = &Apache::lonenc::encrypted($url);
4022: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.484.2.80 raeburn 4023: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 4024: if ($env{'request.enc'} ne '') {
4025: delete($env{'request.enc'});
4026: }
4027: } else {
4028: $url='';
4029: }
4030: } else {
4031: $url='';
4032: }
1.484.2.12 raeburn 4033: } else {
4034: $url='';
4035: }
1.484.2.19 raeburn 4036: }
1.484.2.66 raeburn 4037: } elsif ($supplementalflag) {
4038: if ($isexternal) {
4039: if ($url =~ /^([^#]+)#([^#]+)$/) {
4040: $url = $1;
4041: $anchor = $2;
1.484.2.70 raeburn 4042: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.93 raeburn 4043: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4044: if ($hostname ne '') {
4045: $url = 'http://'.$hostname.$url;
4046: }
4047: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4048: }
1.484.2.70 raeburn 4049: $nomodal = 1;
4050: }
4051: }
4052: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4053: if (($ENV{'SERVER_PORT'} == 443) &&
4054: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 4055: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4056: if ($hostname ne '') {
4057: $url = 'http://'.$hostname.$url;
4058: }
4059: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4060: }
1.484.2.70 raeburn 4061: $nomodal = 1;
1.484.2.66 raeburn 4062: }
4063: }
1.329 droeschl 4064: }
1.484.2.67 raeburn 4065: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4066: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4067: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4068: my $foldername=&escape($foldertitle);
4069: my $folderpath=$env{'form.folderpath'};
4070: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4071: if (!$allowed && $supplementalflag) {
4072: $folderpath.=$containerarg.'&'.$foldername;
4073: $url.='folderpath='.&escape($folderpath);
4074: } else {
4075: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4076: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4077: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4078: 'parameter_randomorder'))[0]=~/^yes$/i);
4079: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4080: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4081: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4082: 'parameter_encrypturl'))[0]=~/^yes$/i);
4083: unless ($hiddenmap) {
1.484.2.70 raeburn 4084: if (ref($navmapref)) {
4085: unless (ref($$navmapref)) {
4086: $$navmapref = Apache::lonnavmaps::navmap->new();
4087: }
4088: if (ref($$navmapref)) {
4089: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4090: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4091: unless (@resources) {
4092: $hiddenmap = 1;
4093: unless ($env{'request.role.adv'}) {
4094: $url = '';
4095: $hiddenfolder = 1;
4096: }
1.484.2.67 raeburn 4097: }
4098: }
4099: }
4100: }
4101: }
4102: unless ($encryptmap) {
1.484.2.70 raeburn 4103: if ((ref($navmapref)) && (ref($$navmapref))) {
4104: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4105: $encryptmap = 1;
4106: }
1.484.2.67 raeburn 4107: }
4108: }
4109:
4110: # Append randompick number, hidden, and encrypted with ":" to foldername,
4111: # so it gets transferred between levels
4112: $folderpath.=$containerarg.'&'.$foldername.
4113: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4114: unless ($url eq '') {
4115: $url.='folderpath='.&escape($folderpath);
4116: }
1.484.2.19 raeburn 4117: my $rpckchk;
4118: if ($rpicknum) {
4119: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4120: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4121: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4122: }
1.484.2.19 raeburn 4123: }
1.484.2.29 raeburn 4124: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4125: $rand_pick_text =
1.478 raeburn 4126: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4127: $form_param."\n".
1.478 raeburn 4128: $form_common."\n".
1.484.2.67 raeburn 4129: '<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 4130: if ($rpicknum ne '') {
4131: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4132: }
1.484.2.29 raeburn 4133: $rand_pick_text .= '</span></span>'.
4134: $form_end;
1.484.2.30 raeburn 4135: my $ro_set;
1.484.2.67 raeburn 4136: if ($randorder) {
1.484.2.30 raeburn 4137: $ro_set = 'checked="checked"';
4138: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4139: push(@{$filtersref->{'randomorder'}},$orderidx);
4140: }
4141: }
1.484.2.41 raeburn 4142: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4143: $rand_order_text =
1.484.2.29 raeburn 4144: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4145: $form_param."\n".
1.484.2.29 raeburn 4146: $form_common."\n".
1.484.2.67 raeburn 4147: '<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 4148: $form_end;
1.484.2.19 raeburn 4149: }
1.484.2.18 raeburn 4150: } elsif ($supplementalflag && !$allowed) {
1.484.2.19 raeburn 4151: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4152: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4153: if ($title) {
4154: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4155: }
4156: if ($isexternal && $orderidx) {
4157: $url .= '&idx='.$orderidx;
4158: }
1.484.2.66 raeburn 4159: if ($anchor ne '') {
4160: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4161: }
1.329 droeschl 4162: }
1.484.2.19 raeburn 4163: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4164: if ($allowed) {
1.484.2.19 raeburn 4165: my $fileloc =
1.484.2.12 raeburn 4166: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4167: if ($isexternal) {
4168: ($editlink,$extresform) =
1.484.2.67 raeburn 4169: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4170: undef,undef,undef,$disabled);
1.484.2.19 raeburn 4171: } elsif (!$isfolder && !$ispage) {
4172: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4173: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4174: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4175: my $suppanchor;
4176: if ($supplementalflag) {
4177: $suppanchor = $anchor;
4178: }
1.484.2.19 raeburn 4179: my $jscall =
1.484.2.12 raeburn 4180: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4181: $switchserver,
1.484.2.14 raeburn 4182: $forceedit,
1.484.2.95! raeburn 4183: undef,$symb,$shownsymb,
1.484.2.19 raeburn 4184: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4185: $renametitle,$hostname,
4186: '','',1,$suppanchor);
1.484.2.12 raeburn 4187: if ($jscall) {
1.484.2.19 raeburn 4188: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4189: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4190: }
4191: }
4192: }
1.484.2.19 raeburn 4193: $tdalign = ' align="right" valign="top"';
4194: $tdwidth = ' width="80%"';
1.329 droeschl 4195: }
1.408 raeburn 4196: my $reinit;
4197: if ($crstype eq 'Community') {
4198: $reinit = &mt('(re-initialize community to access)');
4199: } else {
4200: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4201: }
4202: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4203: my $link;
1.472 raeburn 4204: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4205: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4206: } elsif ($url) {
1.484.2.66 raeburn 4207: if ($anchor ne '') {
4208: if ($supplementalflag) {
4209: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4210: } else {
4211: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4212: }
4213: }
1.484.2.80 raeburn 4214:
4215: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4216: $link = 'http://'.$hostname.$url;
4217: } else {
4218: $link = $url;
4219: }
4220: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4221: if ($nomodal) {
4222: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4223: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4224: } else {
4225: $line.=&Apache::loncommon::modal_link($link,
4226: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4227: }
1.469 www 4228: } else {
4229: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4230: }
1.484.2.19 raeburn 4231: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4232: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4233: $line.='<a href="'.$url.'">'.$title.'</a>';
4234: } elsif ($url) {
1.484.2.70 raeburn 4235: if ($nomodal) {
4236: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4237: $title.'</a>';
4238: } else {
4239: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4240: }
1.484.2.67 raeburn 4241: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4242: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4243: } else {
4244: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4245: }
1.484.2.19 raeburn 4246: $line.="$extresform</td>";
1.478 raeburn 4247: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4248: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4249: if (($allowed) && ($folder!~/^supplemental/)) {
4250: my %lt=&Apache::lonlocal::texthash(
4251: 'hd' => 'Hidden',
4252: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4253: my ($enctext,$hidtext);
4254: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4255: $enctext = ' checked="checked"';
4256: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4257: push(@{$filtersref->{'encrypturl'}},$orderidx);
4258: }
4259: }
4260: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4261: $hidtext = ' checked="checked"';
1.484.2.95! raeburn 4262: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.484.2.30 raeburn 4263: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4264: }
4265: }
1.484.2.29 raeburn 4266: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4267: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4268: $line.=(<<ENDPARMS);
4269: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4270: <form action="/adm/coursedocs" method="post" name="$formhidden">
4271: $form_param
1.478 raeburn 4272: $form_common
1.484.2.67 raeburn 4273: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4274: $form_end
1.458 raeburn 4275: <br />
1.484.2.29 raeburn 4276: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4277: $form_param
1.478 raeburn 4278: $form_common
1.484.2.67 raeburn 4279: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4280: $form_end
4281: </td>
1.478 raeburn 4282: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4283: $rand_order_text</td>
1.329 droeschl 4284: ENDPARMS
4285: }
1.379 bisitz 4286: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4287: return $line;
4288: }
4289:
1.484.2.30 raeburn 4290: sub action_restrictions {
4291: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4292: my %denied = (
4293: cut => 0,
4294: copy => 0,
4295: remove => 0,
4296: );
4297: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4298: # no copy for published maps
4299: $denied{'copy'} = 1;
1.484.2.82 raeburn 4300: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4301: unless ($1 eq 'simpleproblem') {
4302: $denied{'copy'} = 1;
4303: }
4304: $denied{'cut'} = 1;
1.484.2.30 raeburn 4305: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4306: if ($folderpath =~ /^default&[^\&]+$/) {
4307: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4308: $denied{'remove'} = 1;
4309: }
4310: $denied{'cut'} = 1;
4311: $denied{'copy'} = 1;
4312: }
4313: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4314: my $group = $1;
4315: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4316: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4317: $denied{'remove'} = 1;
4318: }
4319: }
4320: $denied{'cut'} = 1;
4321: $denied{'copy'} = 1;
4322: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4323: my $group = $1;
4324: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4325: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4326: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4327: if (keys(%groupsettings) > 0) {
4328: $denied{'remove'} = 1;
4329: }
4330: $denied{'cut'} = 1;
4331: $denied{'copy'} = 1;
4332: }
4333: }
4334: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4335: my $group = $1;
4336: if ($url =~ /group_boards_\Q$group\E/) {
4337: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4338: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4339: if (keys(%groupsettings) > 0) {
4340: if (ref($groupsettings{'functions'}) eq 'HASH') {
4341: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4342: $denied{'remove'} = 1;
4343: }
4344: }
4345: }
4346: $denied{'cut'} = 1;
4347: $denied{'copy'} = 1;
4348: }
4349: }
4350: }
4351: return %denied;
4352: }
4353:
1.484.2.26 raeburn 4354: sub new_timebased_suffix {
1.484.2.30 raeburn 4355: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4356: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4357: if ($type eq 'paste') {
4358: $prefix = $type;
4359: $namespace = 'courseeditor';
1.484.2.56 raeburn 4360: $idtype = 'addcode';
1.484.2.30 raeburn 4361: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4362: $prefix = 'docs';
4363: if ($area eq 'supplemental') {
4364: $prefix = 'supp';
4365: }
4366: $prefix .= $container;
4367: $namespace = 'uploadedmaps';
4368: } else {
4369: $prefix = $type;
4370: $namespace = 'templated';
1.484.2.15 raeburn 4371: }
4372: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4373: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4374: if (!$suffix) {
1.484.2.30 raeburn 4375: if ($type eq 'paste') {
4376: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4377: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4378: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4379: } elsif ($type eq 'smppg') {
4380: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4381: } else {
1.484.2.42 raeburn 4382: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4383: }
1.484.2.15 raeburn 4384: if ($error) {
4385: $errtext .= '<br />'.$error;
4386: }
4387: }
4388: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4389: $locknotfreed =
4390: '<div class="LC_error">'.
4391: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4392: if ($type eq 'paste') {
1.484.2.57 raeburn 4393: if ($freedlock eq 'nolock') {
4394: $locknotfreed =
4395: '<div class="LC_error">'.
4396: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4397:
1.484.2.60 raeburn 4398: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4399: } else {
4400: $locknotfreed .=
4401: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4402: }
1.484.2.30 raeburn 4403: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4404: $locknotfreed .=
4405: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4406: } elsif ($type eq 'smppg') {
4407: $locknotfreed .=
4408: &mt('This will prevent creation of additional simple pages in this course.');
4409: } else {
4410: $locknotfreed .=
1.484.2.42 raeburn 4411: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4412: }
1.484.2.30 raeburn 4413: unless ($type eq 'paste') {
4414: $locknotfreed .=
1.484.2.38 raeburn 4415: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4416: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4417: }
4418: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4419: }
4420: return ($suffix,$errtext,$locknotfreed);
4421: }
4422:
1.329 droeschl 4423: =pod
4424:
4425: =item tiehash()
4426:
4427: tie the hash
4428:
4429: =cut
4430:
4431: sub tiehash {
4432: my ($mode)=@_;
4433: $hashtied=0;
4434: if ($env{'request.course.fn'}) {
4435: if ($mode eq 'write') {
4436: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4437: &GDBM_WRCREAT(),0640)) {
4438: $hashtied=2;
4439: }
4440: } else {
4441: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4442: &GDBM_READER(),0640)) {
4443: $hashtied=1;
4444: }
4445: }
1.364 bisitz 4446: }
1.329 droeschl 4447: }
4448:
4449: sub untiehash {
4450: if ($hashtied) { untie %hash; }
4451: $hashtied=0;
4452: return OK;
4453: }
4454:
4455:
4456:
4457:
4458: sub checkonthis {
1.484.2.78 raeburn 4459: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4460: $url=&unescape($url);
4461: $alreadyseen{$url}=1;
4462: $r->rflush();
4463: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4464: $r->print("\n<br />");
4465: if ($level==0) {
4466: $r->print("<br />");
4467: }
4468: for (my $i=0;$i<=$level*5;$i++) {
4469: $r->print(' ');
4470: }
4471: $r->print('<a href="'.$url.'" target="cat">'.
4472: ($title?$title:$url).'</a> ');
4473: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4474: my $updated;
4475: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4476: ($url !~ /\.\d+\.\w+$/)) {
4477: $updated = &Apache::lonnet::remove_stale_resfile($url);
4478: }
1.329 droeschl 4479: my $result=&Apache::lonnet::repcopy(
4480: &Apache::lonnet::filelocation('',$url));
4481: if ($result eq 'ok') {
4482: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4483: if ($updated) {
4484: $r->print('<br />');
4485: for (my $i=0;$i<=$level*5;$i++) {
4486: $r->print(' ');
4487: }
4488: $r->print('- '.&mt('Outdated copy removed'));
4489: }
1.329 droeschl 4490: $r->rflush();
4491: &Apache::lonnet::countacc($url);
4492: $url=~/\.(\w+)$/;
4493: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4494: $r->print('<br />');
4495: $r->rflush();
4496: for (my $i=0;$i<=$level*5;$i++) {
4497: $r->print(' ');
4498: }
4499: $r->print('- '.&mt('Rendering:').' ');
4500: my ($errorcount,$warningcount)=split(/:/,
4501: &Apache::lonnet::ssi_body($url,
4502: ('grade_target'=>'web',
4503: 'return_only_error_and_warning_counts' => 1)));
4504: if (($errorcount) ||
4505: ($warningcount)) {
4506: if ($errorcount) {
1.369 bisitz 4507: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4508: &mt('[quant,_1,error]',$errorcount).'</span>');
4509: }
4510: if ($warningcount) {
4511: $r->print('<span class="LC_warning">'.
4512: &mt('[quant,_1,warning]',$warningcount).'</span>');
4513: }
4514: } else {
4515: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4516: }
4517: $r->rflush();
4518: }
4519: my $dependencies=
4520: &Apache::lonnet::metadata($url,'dependencies');
4521: foreach my $dep (split(/\,/,$dependencies)) {
4522: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4523: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4524: }
4525: }
4526: } elsif ($result eq 'unavailable') {
4527: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4528: } elsif ($result eq 'not_found') {
4529: unless ($url=~/\$/) {
1.484.2.19 raeburn 4530: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4531: } else {
1.366 bisitz 4532: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4533: }
4534: } else {
4535: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4536: }
1.484.2.78 raeburn 4537: if (($updated) && ($result ne 'ok')) {
4538: $r->print('<br />'.&mt('Outdated copy removed'));
4539: }
1.329 droeschl 4540: }
4541: }
4542: }
4543:
4544:
4545:
4546: =pod
4547:
4548: =item list_symbs()
4549:
1.484.2.3 raeburn 4550: List Content Identifiers
1.329 droeschl 4551:
4552: =cut
4553:
4554: sub list_symbs {
4555: my ($r) = @_;
4556:
1.408 raeburn 4557: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4558: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4559: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4560: $r->print(&startContentScreen('tools'));
1.329 droeschl 4561: my $navmap = Apache::lonnavmaps::navmap->new();
4562: if (!defined($navmap)) {
4563: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4564: '<div class="LC_error">'.
4565: &mt('Unable to retrieve information about course contents').
4566: '</div>');
1.408 raeburn 4567: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4568: } else {
1.484 raeburn 4569: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4570: &Apache::loncommon::start_data_table().
4571: &Apache::loncommon::start_data_table_header_row().
4572: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4573: &Apache::loncommon::end_data_table_header_row()."\n");
4574: my $count;
1.329 droeschl 4575: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4576: $r->print(&Apache::loncommon::start_data_table_row().
4577: '<td>'.$res->compTitle().'</td>'.
4578: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4579: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4580: $count ++;
4581: }
4582: if (!$count) {
4583: $r->print(&Apache::loncommon::start_data_table_row().
4584: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4585: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4586: }
1.484 raeburn 4587: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4588: }
1.484.2.19 raeburn 4589: $r->print(&endContentScreen());
1.329 droeschl 4590: }
4591:
1.484.2.78 raeburn 4592: sub contentverifyform {
4593: my ($r) = @_;
4594: my $crstype = &Apache::loncommon::course_type();
4595: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4596: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4597: $r->print(&startContentScreen('tools'));
4598: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4599: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4600: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4601: ' <span class="LC_nobreak">'.
4602: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4603: &mt('No').'</label>'.(' 'x2).
4604: '<label><input type="radio" name="checkstale" value="1" />'.
4605: &mt('Yes').'</label></span></p><p>'.
1.484.2.90 raeburn 4606: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.484.2.78 raeburn 4607: '<input type="hidden" value="1" name="tools" />'.
4608: '<input type="hidden" value="1" name="verify" /></p></form>');
4609: $r->print(&endContentScreen());
4610: return;
4611: }
1.329 droeschl 4612:
4613: sub verifycontent {
1.484.2.78 raeburn 4614: my ($r,$checkstale) = @_;
1.408 raeburn 4615: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4616: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4617: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4618: $r->print(&startContentScreen('tools'));
4619: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4620: $hashtied=0;
4621: undef %alreadyseen;
4622: %alreadyseen=();
4623: &tiehash();
1.484 raeburn 4624:
1.329 droeschl 4625: foreach my $key (keys(%hash)) {
4626: if ($hash{$key}=~/\.(page|sequence)$/) {
4627: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4628: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4629: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4630: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4631: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4632: }
4633: }
4634: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4635: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4636: }
4637: }
4638: &untiehash();
1.442 www 4639: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4640: $r->print(&endContentScreen());
1.329 droeschl 4641: }
4642:
4643:
4644: sub devalidateversioncache {
4645: my $src=shift;
4646: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4647: &Apache::lonnet::clutter($src));
4648: }
4649:
4650: sub checkversions {
1.484.2.67 raeburn 4651: my ($r,$canedit) = @_;
1.408 raeburn 4652: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4653: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4654: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4655: $r->print(&startContentScreen('tools'));
1.442 www 4656:
1.329 droeschl 4657: my $header='';
4658: my $startsel='';
4659: my $monthsel='';
4660: my $weeksel='';
4661: my $daysel='';
4662: my $allsel='';
4663: my %changes=();
4664: my $starttime=0;
4665: my $haschanged=0;
4666: my %setversions=&Apache::lonnet::dump('resourceversions',
4667: $env{'course.'.$env{'request.course.id'}.'.domain'},
4668: $env{'course.'.$env{'request.course.id'}.'.num'});
4669:
4670: $hashtied=0;
4671: &tiehash();
1.484.2.67 raeburn 4672: if ($canedit) {
4673: my %newsetversions=();
4674: if ($env{'form.setmostrecent'}) {
4675: $haschanged=1;
4676: foreach my $key (keys(%hash)) {
4677: if ($key=~/^ids\_(\/res\/.+)$/) {
4678: $newsetversions{$1}='mostrecent';
4679: &devalidateversioncache($1);
4680: }
1.329 droeschl 4681: }
1.484.2.67 raeburn 4682: } elsif ($env{'form.setcurrent'}) {
4683: $haschanged=1;
4684: foreach my $key (keys(%hash)) {
4685: if ($key=~/^ids\_(\/res\/.+)$/) {
4686: my $getvers=&Apache::lonnet::getversion($1);
4687: if ($getvers>0) {
4688: $newsetversions{$1}=$getvers;
4689: &devalidateversioncache($1);
4690: }
4691: }
1.329 droeschl 4692: }
1.484.2.67 raeburn 4693: } elsif ($env{'form.setversions'}) {
4694: $haschanged=1;
4695: foreach my $key (keys(%env)) {
4696: if ($key=~/^form\.set_version_(.+)$/) {
4697: my $src=$1;
4698: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4699: $newsetversions{$src}=$env{$key};
4700: &devalidateversioncache($src);
4701: }
4702: }
1.329 droeschl 4703: }
1.484.2.67 raeburn 4704: }
4705: if ($haschanged) {
4706: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4707: $env{'course.'.$env{'request.course.id'}.'.domain'},
4708: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4709: $r->print(&Apache::loncommon::confirmwrapper(
4710: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4711: } else {
4712: $r->print(&Apache::loncommon::confirmwrapper(
4713: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4714: }
4715: &mark_hash_old();
4716: }
4717: &changewarning($r,'');
1.329 droeschl 4718: }
4719: if ($env{'form.timerange'} eq 'all') {
4720: # show all documents
1.484.2.34 raeburn 4721: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4722: $allsel=' selected="selected"';
1.329 droeschl 4723: foreach my $key (keys(%hash)) {
4724: if ($key=~/^ids\_(\/res\/.+)$/) {
4725: my $src=$1;
4726: $changes{$src}=1;
4727: }
4728: }
4729: } else {
4730: # show documents which changed
4731: %changes=&Apache::lonnet::dump
4732: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4733: $env{'course.'.$env{'request.course.id'}.'.num'});
4734: my $firstkey=(keys(%changes))[0];
4735: unless ($firstkey=~/^error\:/) {
4736: unless ($env{'form.timerange'}) {
4737: $env{'form.timerange'}=604800;
4738: }
4739: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4740: .&mt('seconds');
4741: if ($env{'form.timerange'}==-1) {
4742: $seltext='since start of course';
1.484.2.19 raeburn 4743: $startsel=' selected="selected"';
1.329 droeschl 4744: $env{'form.timerange'}=time;
4745: }
4746: $starttime=time-$env{'form.timerange'};
4747: if ($env{'form.timerange'}==2592000) {
4748: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4749: $monthsel=' selected="selected"';
1.329 droeschl 4750: } elsif ($env{'form.timerange'}==604800) {
4751: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4752: $weeksel=' selected="selected"';
1.329 droeschl 4753: } elsif ($env{'form.timerange'}==86400) {
4754: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4755: $daysel=' selected="selected"';
1.329 droeschl 4756: }
4757: $header=&mt('Content changed').' '.$seltext;
4758: } else {
4759: $header=&mt('No content modifications yet.');
4760: }
4761: }
4762: %setversions=&Apache::lonnet::dump('resourceversions',
4763: $env{'course.'.$env{'request.course.id'}.'.domain'},
4764: $env{'course.'.$env{'request.course.id'}.'.num'});
4765: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4766: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4767: 'lm' => 'Version changes since last Month',
4768: 'lw' => 'Version changes since last Week',
4769: 'sy' => 'Version changes since Yesterday',
4770: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4771: 'cd' => 'Change display',
1.329 droeschl 4772: 'sd' => 'Display',
4773: 'fi' => 'File',
4774: 'md' => 'Modification Date',
4775: 'mr' => 'Most recently published Version',
1.408 raeburn 4776: 've' => 'Version used in '.$crstype,
4777: 'vu' => 'Set Version to be used in '.$crstype,
4778: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4779: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4780: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4781: 'di' => 'Differences',
1.484 raeburn 4782: 'save' => 'Save changes',
4783: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4784: 'act' => 'Actions');
1.484.2.67 raeburn 4785: my ($disabled,$readonly);
4786: unless ($canedit) {
4787: $disabled = 'disabled="disabled"';
4788: $readonly = 1;
4789: }
1.329 droeschl 4790: $r->print(<<ENDHEADERS);
1.484 raeburn 4791: <h4 class="LC_info">$header</h4>
1.329 droeschl 4792: <form action="/adm/coursedocs" method="post">
4793: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4794: <div class="LC_left_float">
1.479 golterma 4795: <fieldset>
1.484 raeburn 4796: <legend>$lt{'cd'}</legend>
1.329 droeschl 4797: <select name="timerange">
1.484.2.19 raeburn 4798: <option value='all'$allsel>$lt{'al'}</option>
4799: <option value="-1"$startsel>$lt{'st'}</option>
4800: <option value="2592000"$monthsel>$lt{'lm'}</option>
4801: <option value="604800"$weeksel>$lt{'lw'}</option>
4802: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4803: </select>
4804: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4805: </fieldset>
4806: </div>
4807: <div class="LC_left_float">
4808: <fieldset>
4809: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4810: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4811: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4812: </fieldset>
4813: </div>
4814: <br clear="all" />
4815: <hr />
4816: <h4>$lt{'vers'}</h4>
1.329 droeschl 4817: ENDHEADERS
1.479 golterma 4818: #number of columns for version history
1.484.2.44 raeburn 4819: my %changedbytime;
4820: foreach my $key (keys(%changes)) {
4821: #excludes not versionable problems from resource version history:
4822: next if ($key =~ /^\/res\/lib\/templates/);
4823: my $chg;
4824: if ($env{'form.timerange'} eq 'all') {
4825: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4826: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4827: } else {
4828: $chg = $changes{$key};
4829: next if ($chg < $starttime);
4830: }
4831: push(@{$changedbytime{$chg}},$key);
4832: }
4833: if (keys(%changedbytime) == 0) {
4834: &untiehash();
4835: $r->print(&mt('No content changes in imported content in specified time frame').
4836: &endContentScreen());
4837: return;
4838: }
1.479 golterma 4839: $r->print(
1.484.2.67 raeburn 4840: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4841: &Apache::loncommon::start_data_table().
4842: &Apache::loncommon::start_data_table_header_row().
4843: '<th>'.&mt('Resources').'</th>'.
4844: "<th>$lt{'mr'}</th>".
4845: "<th>$lt{'ve'}</th>".
4846: "<th>$lt{'vu'}</th>".
4847: '<th>'.&mt('History').'</th>'.
4848: &Apache::loncommon::end_data_table_header_row()
4849: );
1.484.2.44 raeburn 4850: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4851: foreach my $key (sort(@{$changedbytime{$chg}})) {
4852: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4853: my $currentversion=&Apache::lonnet::getversion($key);
4854: if ($currentversion<0) {
4855: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4856: }
4857: my $linkurl=&Apache::lonnet::clutter($key);
4858: $r->print(
4859: &Apache::loncommon::start_data_table_row().
4860: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4861: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4862: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4863: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4864: '<td align="right">'
4865: );
4866: # Used in course
4867: my $usedversion=$hash{'version_'.$linkurl};
4868: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 4869: if ($usedversion != $currentversion) {
1.479 golterma 4870: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 4871: } else {
1.479 golterma 4872: $r->print($usedversion);
4873: }
1.329 droeschl 4874: } else {
1.484.2.19 raeburn 4875: $r->print($currentversion);
1.329 droeschl 4876: }
1.484.2.44 raeburn 4877: $r->print('</td><td title="'.$lt{'vu'}.'">');
4878: # Set version
4879: $r->print(&Apache::loncommon::select_form(
4880: $setversions{$linkurl},
4881: 'set_version_'.$linkurl,
4882: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4883: '' => '',
4884: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 4885: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 4886: my $lastold=1;
4887: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4888: my $url=$root.'.'.$prevvers.'.'.$extension;
4889: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4890: $lastold=$prevvers;
4891: }
4892: }
4893: $r->print('</td>');
4894: # List all available versions
4895: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4896: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4897: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 4898: $r->print(
1.484.2.44 raeburn 4899: '<span class="LC_nobreak">'
4900: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4901: .&mt('Version [_1]',$prevvers).'</a>'
4902: .' ('.&Apache::lonlocal::locallocaltime(
4903: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4904: .')');
4905: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4906: $r->print(
4907: ' <a href="/adm/diff?filename='.
4908: &Apache::lonnet::clutter($root.'.'.$extension).
4909: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4910: '" target="diffs">'.&mt('Diffs').'</a>');
4911: }
4912: $r->print('</span><br />');
1.329 droeschl 4913: }
1.484.2.44 raeburn 4914: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 4915: }
1.329 droeschl 4916: }
1.484.2.19 raeburn 4917: $r->print(
4918: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 4919: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4920: '</form>'
4921: );
1.329 droeschl 4922:
4923: &untiehash();
1.484.2.19 raeburn 4924: $r->print(&endContentScreen());
1.484.2.44 raeburn 4925: return;
1.329 droeschl 4926: }
4927:
4928: sub mark_hash_old {
4929: my $retie_hash=0;
4930: if ($hashtied) {
4931: $retie_hash=1;
4932: &untiehash();
4933: }
4934: &tiehash('write');
4935: $hash{'old'}=1;
4936: &untiehash();
4937: if ($retie_hash) { &tiehash(); }
4938: }
4939:
4940: sub is_hash_old {
4941: my $untie_hash=0;
4942: if (!$hashtied) {
4943: $untie_hash=1;
4944: &tiehash();
4945: }
4946: my $return=$hash{'old'};
4947: if ($untie_hash) { &untiehash(); }
4948: return $return;
4949: }
4950:
4951: sub changewarning {
4952: my ($r,$postexec,$message,$url)=@_;
4953: if (!&is_hash_old()) { return; }
4954: my $pathvar='folderpath';
4955: my $path=&escape($env{'form.folderpath'});
4956: if (!defined($url)) {
4957: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4958: }
4959: my $course_type = &Apache::loncommon::course_type();
4960: if (!defined($message)) {
4961: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4962: }
4963: $r->print("\n\n".
1.372 bisitz 4964: '<script type="text/javascript">'."\n".
4965: '// <![CDATA['."\n".
4966: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4967: '// ]]>'."\n".
1.369 bisitz 4968: '</script>'."\n".
1.375 tempelho 4969: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4970: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4971: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4972: &mt($message,' <input type="hidden" name="'.
4973: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4974: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4975: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4976: }
4977:
4978:
4979: sub init_breadcrumbs {
1.484.2.44 raeburn 4980: my ($form,$text,$help)=@_;
1.329 droeschl 4981: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4982: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4983: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4984: faq=>273,
4985: bug=>'Instructor Interface',
1.484.2.44 raeburn 4986: help => $help});
1.329 droeschl 4987: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4988: text=>$text,
4989: faq=>273,
4990: bug=>'Instructor Interface'});
4991: }
4992:
1.441 www 4993: # subroutine to list form elements
4994: sub create_list_elements {
4995: my @formarr = @_;
4996: my $list = '';
1.484.2.12 raeburn 4997: foreach my $button (@formarr){
4998: foreach my $picture (keys(%{$button})) {
4999: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5000: }
5001: }
5002: return $list;
5003: }
1.329 droeschl 5004:
1.441 www 5005: # subroutine to create ul from list elements
5006: sub create_form_ul {
5007: my $list = shift;
5008: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5009: return $ul;
5010: }
1.329 droeschl 5011:
1.442 www 5012: #
5013: # Start tabs
5014: #
5015:
5016: sub startContentScreen {
1.484 raeburn 5017: my ($mode) = @_;
5018: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5019: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5020: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5021: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5022: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5023: } else {
1.484.2.34 raeburn 5024: $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 5025: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5026: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5027: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5028: }
5029: $output .= "\n".'</ul>'."\n";
5030: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5031: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5032: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5033: return $output;
1.442 www 5034: }
5035:
5036: #
5037: # End tabs
5038: #
5039:
5040: sub endContentScreen {
1.484 raeburn 5041: return '</div></div></div>';
1.442 www 5042: }
1.329 droeschl 5043:
1.446 www 5044: sub supplemental_base {
1.484.2.33 raeburn 5045: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5046: }
5047:
1.329 droeschl 5048: sub handler {
5049: my $r = shift;
5050: &Apache::loncommon::content_type($r,'text/html');
5051: $r->send_http_header;
5052: return OK if $r->header_only;
1.484 raeburn 5053:
5054: # get course data
1.408 raeburn 5055: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5056: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5057: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5058:
5059: # graphics settings
5060: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5061:
1.443 www 5062: #
1.329 droeschl 5063: # --------------------------------------------- Initialize help topics for this
5064: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5065: 'Adding_External_Resource','Navigate_Content',
5066: 'Adding_Folders','Docs_Overview', 'Load_Map',
5067: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.484.2.19 raeburn 5068: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.484.2.44 raeburn 5069: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
5070: 'Dropbox','Simple_Problem') {
1.329 droeschl 5071: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5072: }
5073: # Composite help files
5074: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5075: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5076: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5077: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5078: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5079: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5080: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5081: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5082: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5083: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5084:
1.484.2.67 raeburn 5085: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 5086: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5087: unless ($r->uri eq '/adm/supplemental') {
5088: # does this user have privileges to modify content.
1.484.2.67 raeburn 5089: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5090: $allowed = 1;
5091: $canedit = 1;
5092: $canview = 1;
5093: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5094: $allowed = 1;
5095: $canview = 1;
5096: }
5097: }
5098: unless ($canedit) {
5099: $disabled = ' disabled="disabled"';
1.472 raeburn 5100: }
1.484.2.53 raeburn 5101: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5102: if ($env{'form.inhibitmenu'}) {
5103: unless ($env{'form.inhibitmenu'} eq 'yes') {
5104: delete($env{'form.inhibitmenu'});
5105: }
5106: }
5107:
1.484.2.53 raeburn 5108: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5109: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5110: if (!$canedit) {
5111: &verifycontent($r);
5112: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5113: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5114: text=>'Results',
5115: faq=>273,
5116: bug=>'Instructor Interface'});
5117: &verifycontent($r,$env{'form.checkstale'});
5118: } else {
5119: &contentverifyform($r);
5120: }
1.329 droeschl 5121: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5122: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5123: &list_symbs($r);
5124: } elsif ($allowed && $env{'form.docslog'}) {
5125: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5126: my $folder = $env{'form.folder'};
5127: if ($folder eq '') {
5128: $folder='default';
5129: }
1.484.2.67 raeburn 5130: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5131: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5132: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5133: &checkversions($r,$canedit);
5134: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5135: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5136: &dumpcourse($r);
5137: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5138: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5139: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5140: } else {
1.445 www 5141: #
5142: # Done catching special calls
1.484 raeburn 5143: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5144: # Get the parameters that may be needed
5145: #
5146: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5147: ['folderpath',
5148: 'forcesupplement','forcestandard',
5149: 'tools','symb','command','supppath']);
1.445 www 5150:
1.484.2.78 raeburn 5151: foreach my $item ('forcesupplement','forcestandard','tools') {
5152: next if ($env{'form.'.$item} eq '');
5153: unless ($env{'form.'.$item} eq '1') {
5154: delete($env{'form.'.$item});
5155: }
5156: }
5157:
5158: if ($env{'form.command'}) {
5159: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5160: delete($env{'form.command'});
5161: }
5162: }
5163:
5164: if ($env{'form.symb'}) {
5165: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5166: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5167: delete($env{'form.symb'});
5168: }
5169: }
5170:
1.445 www 5171: # standard=1: this is a "new-style" course with an uploaded map as top level
5172: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5173:
5174: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5175:
1.484 raeburn 5176: # Decide whether this should display supplemental or main content or utilities
1.445 www 5177: # supplementalflag=1: show supplemental documents
5178: # supplementalflag=0: show standard documents
1.484 raeburn 5179: # toolsflag=1: show utilities
1.445 www 5180:
1.484.2.39 raeburn 5181: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5182: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5183: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5184: $supplementalflag=0;
5185: }
5186: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5187: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5188: unless ($allowed) { $supplementalflag=1; }
5189: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5190: my $toolsflag=0;
5191: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5192:
1.484.2.78 raeburn 5193: if ($env{'form.folderpath'} ne '') {
1.484.2.92 raeburn 5194: &validate_folderpath($supplementalflag);
1.484.2.78 raeburn 5195: }
5196:
5197: if ($env{'form.supppath'} ne '') {
1.484.2.92 raeburn 5198: &validate_suppath();
1.484.2.78 raeburn 5199: }
5200:
1.329 droeschl 5201: my $script='';
5202: my $showdoc=0;
1.457 raeburn 5203: my $addentries = {};
1.475 raeburn 5204: my $container;
1.329 droeschl 5205: my $containertag;
1.484.2.17 raeburn 5206: my $pathitem;
1.484.2.67 raeburn 5207: my $hiddentop;
5208: my $navmap;
5209: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5210:
1.464 www 5211: # Do we directly jump somewhere?
1.484.2.21 raeburn 5212: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5213: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5214: $env{'form.folderpath'}=
1.484.2.67 raeburn 5215: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5216: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5217: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5218: } elsif ($env{'form.supppath'} ne '') {
5219: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5220: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5221: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5222: }
1.472 raeburn 5223: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5224: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5225: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5226: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5227: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5228: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5229: } elsif ($env{'form.command'} eq 'contents') {
5230: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5231: } elsif ($env{'form.command'} eq 'home') {
5232: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5233: }
5234:
1.484.2.23 raeburn 5235:
1.445 www 5236: # Where do we store these for when we come back?
5237: my $stored_folderpath='docs_folderpath';
5238: if ($supplementalflag) {
5239: $stored_folderpath='docs_sup_folderpath';
5240: }
1.464 www 5241:
1.484.2.19 raeburn 5242: # No folderpath, and in edit mode, see if we have something stored
5243: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5244: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5245: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5246:
5247: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5248: if ($supplementalflag) {
5249: undef($env{'form.folderpath'}) if ($1 eq 'default');
5250: } else {
5251: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5252: }
5253: } else {
1.484.2.19 raeburn 5254: undef($env{'form.folderpath'});
5255: }
1.484.2.92 raeburn 5256: if ($env{'form.folderpath'} ne '') {
5257: &validate_folderpath($supplementalflag);
5258: }
1.329 droeschl 5259: }
1.446 www 5260:
5261: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5262: if (!$allowed) {
1.446 www 5263: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5264: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5265: }
5266: }
1.446 www 5267: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5268: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5269: $env{'form.folderpath'} = &supplemental_base()
5270: .'&'.
1.329 droeschl 5271: $env{'form.folderpath'};
5272: }
1.484.2.67 raeburn 5273: # If allowed and user's role is not advanced check folderpath is not hidden
5274: if (($allowed) && (!$env{'request.role.adv'}) &&
5275: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5276: my $folderurl;
5277: my @pathitems = split(/\&/,$env{'form.folderpath'});
5278: my $folder = $pathitems[-2];
5279: if ($folder eq '') {
5280: undef($env{'form.folderpath'});
5281: } else {
5282: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.87 raeburn 5283: if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 5284: $folderurl .= '.page';
5285: } else {
5286: $folderurl .= '.sequence';
5287: }
5288: unless (ref($navmap)) {
5289: $navmap = Apache::lonnavmaps::navmap->new();
5290: }
5291: if (ref($navmap)) {
5292: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5293: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5294: unless (@resources) {
5295: undef($env{'form.folderpath'});
5296: }
5297: }
5298: }
5299: }
5300: }
5301:
5302:
1.446 www 5303: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5304: unless ($env{'form.folderpath'}) {
1.446 www 5305: if ($supplementalflag) {
5306: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5307: } elsif ($allowed) {
5308: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5309: }
1.472 raeburn 5310: }
1.446 www 5311:
1.445 www 5312: # Store this
1.484 raeburn 5313: unless ($toolsflag) {
1.484.2.67 raeburn 5314: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5315: &Apache::loncommon::store_course_settings($stored_folderpath,
5316: {'folderpath' => 'scalar'});
5317: }
5318: my $folderpath;
1.484 raeburn 5319: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5320: $folderpath = $env{'form.folderpath'};
5321: my (@folders)=split('&',$env{'form.folderpath'});
5322: $env{'form.foldername'}=&unescape(pop(@folders));
5323: if ($env{'form.foldername'} =~ /\:1$/) {
5324: $container = 'page';
5325: } else {
5326: $container = 'sequence';
5327: }
5328: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5329: } else {
1.484.2.19 raeburn 5330: if ($env{'form.folder'} eq '' ||
5331: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5332: if ($env{'form.folder'} eq 'supplemental') {
5333: $folderpath=&supplemental_base();
5334: } elsif (!$hiddentop) {
5335: $folderpath='default&'.
5336: &escape(&mt('Main Content').':::::');
5337: }
1.484 raeburn 5338: }
5339: }
1.484.2.19 raeburn 5340: $containertag = '<input type="hidden" name="folderpath" value="" />';
5341: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5342: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5343: $showdoc='/'.$1;
5344: }
5345: if ($showdoc) { # got called in sequence from course
5346: $allowed=0;
5347: } else {
1.484.2.67 raeburn 5348: if ($canedit) {
1.484 raeburn 5349: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5350: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5351: }
5352: }
1.329 droeschl 5353: }
5354:
1.344 bisitz 5355: # get personal data
1.329 droeschl 5356: my $uname=$env{'user.name'};
5357: my $udom=$env{'user.domain'};
5358: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5359:
5360: if ($allowed) {
1.484 raeburn 5361: if ($toolsflag) {
5362: $script .= &inject_data_js();
5363: my ($home,$other,%outhash)=&authorhosts();
5364: if (!$home && $other) {
5365: my @hosts;
5366: foreach my $aurole (keys(%outhash)) {
5367: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5368: push(@hosts,$outhash{$aurole});
5369: }
5370: }
5371: $script .= &dump_switchserver_js(@hosts);
5372: }
1.458 raeburn 5373: } else {
1.484.2.43 raeburn 5374: my $tid = 1;
1.484 raeburn 5375: my @tabids;
5376: if ($supplementalflag) {
5377: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5378: $tid = 2;
1.484 raeburn 5379: } else {
5380: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5381: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5382: unshift(@tabids,'001');
5383: push(@tabids,('dd1','ee1'));
5384: }
1.458 raeburn 5385: }
1.484 raeburn 5386: my $tabidstr = join("','",@tabids);
1.484.2.80 raeburn 5387: my $hostname = $r->hostname();
1.484.2.68 raeburn 5388: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,
1.484.2.80 raeburn 5389: $canedit,$hostname,\$navmap).
1.484 raeburn 5390: &history_tab_js().
5391: &inject_data_js().
1.484.2.43 raeburn 5392: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.19 raeburn 5393: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 5394: $addentries = {
1.484.2.3 raeburn 5395: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5396: };
1.458 raeburn 5397: }
1.484.2.30 raeburn 5398: $script .= &paste_popup_js();
1.484.2.12 raeburn 5399: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5400: &mt('Switch server?');
1.484.2.19 raeburn 5401:
5402:
1.329 droeschl 5403: }
5404: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5405: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5406: .'// <![CDATA['."\n"
5407: .$script."\n"
5408: .'// ]]>'."\n"
1.484.2.81 raeburn 5409: .'</script>'."\n"
5410: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5411:
5412: # Breadcrumbs
5413: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5414:
5415: if ($showdoc) {
5416: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5417: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5418: } elsif ($toolsflag) {
1.484.2.67 raeburn 5419: my ($breadtext,$breadtitle);
5420: $breadtext = "$crstype Editor";
5421: if ($canedit) {
5422: $breadtitle = 'Editing '.$crstype.' Contents';
5423: } else {
5424: $breadtext .= ' (View-only mode)';
5425: $breadtitle = 'Viewing '.$crstype.' Contents';
5426: }
1.484.2.44 raeburn 5427: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5428: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5429: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5430: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5431: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5432: $breadtitle)
1.484.2.44 raeburn 5433: );
1.484.2.19 raeburn 5434: } elsif ($r->uri eq '/adm/supplemental') {
5435: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5436: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5437: {'bread_crumbs' => $brcrum,}));
5438: } else {
1.484.2.67 raeburn 5439: my ($breadtext,$breadtitle,$helpitem);
5440: $breadtext = "$crstype Editor";
5441: if ($canedit) {
5442: $breadtitle = 'Editing '.$crstype.' Contents';
5443: $helpitem = 'Docs_Adding_Course_Doc';
5444: } else {
5445: $breadtext .= ' (View-only mode)';
5446: $breadtitle = 'Viewing '.$crstype.' Contents';
5447: $helpitem = 'Docs_Viewing_Course_Doc';
5448: }
1.392 raeburn 5449: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5450: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5451: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5452: {'add_entries' => $addentries}
5453: )
1.392 raeburn 5454: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5455: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5456: $breadtitle,
5457: $helpitem)
1.392 raeburn 5458: );
5459: }
1.364 bisitz 5460:
1.329 droeschl 5461: my %allfiles = ();
5462: my %codebase = ();
1.440 raeburn 5463: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5464: if ($canedit) {
1.329 droeschl 5465: if (($env{'form.uploaddoc.filename'}) &&
5466: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5467: my $context = $1;
5468: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5469: undef($hadchanges);
1.440 raeburn 5470: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5471: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5472: undef($navmap);
1.329 droeschl 5473: if ($hadchanges) {
5474: &mark_hash_old();
5475: }
1.440 raeburn 5476: $r->print($upload_output);
5477: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5478: # Process file upload - phase two - upload embedded objects
5479: $uploadphase = 'check_embedded';
5480: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5481: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5482: $env{'form.newidx'});
5483: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5484: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5485: my ($destination,$dir_root) = &embedded_destination();
5486: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5487: my $actionurl = '/adm/coursedocs';
5488: my ($result,$flag) =
5489: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5490: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5491: $actionurl);
5492: $r->print($result.&return_to_editor());
5493: } elsif ($env{'form.phase'} eq 'check_embedded') {
5494: # Process file upload - phase three - modify references in HTML file
5495: $uploadphase = 'modified_orightml';
5496: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5497: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5498: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5499: my $result =
5500: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5501: $docuname,$docudom,undef,
5502: $dir_root);
5503: $r->print($result.&return_to_editor());
1.476 raeburn 5504: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5505: $uploadphase = 'decompress_phase_one';
5506: $r->print(&decompression_phase_one().
5507: &return_to_editor());
5508: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5509: $uploadphase = 'decompress_phase_two';
5510: $r->print(&decompression_phase_two().
5511: &return_to_editor());
1.329 droeschl 5512: }
5513: }
5514:
1.484 raeburn 5515: if ($allowed && $toolsflag) {
5516: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5517: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5518: $r->print(&endContentScreen());
5519: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5520: # -----------------------------------------------------------------------------
5521: my %lt=&Apache::lonlocal::texthash(
5522: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5523: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5524: 'upld' => 'Upload Content',
1.329 droeschl 5525: 'srch' => 'Search',
5526: 'impo' => 'Import',
1.484.2.19 raeburn 5527: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5528: 'impm' => 'Import from Assembled Map',
1.329 droeschl 5529: 'selm' => 'Select Map',
5530: 'load' => 'Load Map',
5531: 'newf' => 'New Folder',
5532: 'newp' => 'New Composite Page',
5533: 'syll' => 'Syllabus',
1.425 raeburn 5534: 'navc' => 'Table of Contents',
1.343 biermanm 5535: 'sipa' => 'Simple Course Page',
1.329 droeschl 5536: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5537: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5538: 'drbx' => 'Drop Box',
1.451 www 5539: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5540: 'bull' => 'Discussion Board',
1.347 weissno 5541: 'mypi' => 'My Personal Information Page',
1.353 weissno 5542: 'grpo' => 'Group Portfolio',
1.329 droeschl 5543: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5544: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5545: 'imsf' => 'IMS Upload',
5546: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5547: 'cms' => 'Origin of IMS package',
5548: 'se' => 'Select',
1.484.2.19 raeburn 5549: 'file' => 'File',
1.329 droeschl 5550: 'title' => 'Title',
5551: 'comment' => 'Comment',
1.403 raeburn 5552: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5553: 'bb5' => 'Blackboard 5',
5554: 'bb6' => 'Blackboard 6',
5555: 'angel5' => 'ANGEL 5.5',
5556: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5557: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5558: );
1.329 droeschl 5559: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5560: # Calculate free quota space for a user or course. A javascript function checks
5561: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5562: my $quotatype = 'unofficial';
5563: if ($crstype eq 'Community') {
5564: $quotatype = 'community';
5565: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5566: $quotatype = 'official';
5567: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5568: $quotatype = 'textbook';
5569: }
5570: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5571: 'course',$quotatype); # expressed in MB
5572: my $current_disk_usage = 0;
5573: foreach my $subdir ('docs','supplemental') {
5574: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5575: "userfiles/$subdir",1); # expressed in kB
5576: }
5577: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5578: my $usage = $current_disk_usage/1024; # in MB
5579: my $quota = $disk_quota;
5580: my $percent;
5581: if ($disk_quota == 0) {
5582: $percent = 100.0;
5583: } else {
1.484.2.69 raeburn 5584: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5585: }
5586: $usage = sprintf("%.2f",$usage);
5587: $quota = sprintf("%.2f",$quota);
5588: $percent = sprintf("%.0f",$percent);
5589: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5590: $percent.'%',$quota.' MB').'</p>';
5591:
1.329 droeschl 5592: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5593: $quotainfo
1.329 droeschl 5594: $lt{'file'}:<br />
5595: FIUP
5596: my $checkbox=(<<CHBO);
5597: <!-- <label>$lt{'parse'}?
5598: <input type="checkbox" name="parserflag" />
5599: </label> -->
5600: <label>
1.484.2.67 raeburn 5601: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5602: </label>
5603: CHBO
1.484.2.12 raeburn 5604: my $imsfolder = $env{'form.folder'};
5605: if ($imsfolder eq '') {
1.484.2.19 raeburn 5606: $imsfolder = 'default';
1.484.2.12 raeburn 5607: }
5608: my $imspform=(<<IMSFORM);
5609: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5610: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5611: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5612: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5613: <legend>$lt{'imsf'}</legend>
5614: $fileupload
1.484.2.95! raeburn 5615: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
! 5616: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.484.2.12 raeburn 5617: <br />
5618: <p>
1.484.2.19 raeburn 5619: $lt{'cms'}:
1.484.2.67 raeburn 5620: <select name="source" $disabled>
1.484.2.12 raeburn 5621: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5622: <option value="bb5">$lt{'bb5'}</option>
5623: <option value="bb6">$lt{'bb6'}</option>
5624: <option value="angel5">$lt{'angel5'}</option>
5625: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5626: </select>
5627: <input type="hidden" name="folder" value="$imsfolder" />
5628: </p>
5629: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5630: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5631: </fieldset>
5632: </form>
5633: IMSFORM
5634:
1.484.2.19 raeburn 5635: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5636: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5637: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5638: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5639: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5640: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5641: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5642: $fileupload
1.484.2.95! raeburn 5643: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
! 5644: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5645: <br />
5646: $lt{'title'}:<br />
1.484.2.67 raeburn 5647: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5648: $pathitem
1.329 droeschl 5649: <input type="hidden" name="cmd" value="upload_default" />
5650: <br />
1.458 raeburn 5651: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5652: $checkbox
5653: </span>
1.484.2.12 raeburn 5654: <br clear="all" />
1.484.2.67 raeburn 5655: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5656: </fieldset>
5657: </form>
1.383 tempelho 5658: FUFORM
1.329 droeschl 5659:
1.484.2.67 raeburn 5660: my $mapimportjs;
5661: if ($canedit) {
5662: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5663: } else {
5664: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5665: }
1.484.2.19 raeburn 5666: my $importpubform=(<<SEDFFORM);
5667: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5668: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5669: <form action="/adm/coursedocs" method="post" name="mapimportform">
5670: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5671: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5672: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5673: $lt{'copm'}<br />
5674: <span class="LC_nobreak">
1.484.2.19 raeburn 5675: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5676: onfocus="this.blur();$mapimportjs" $disabled />
5677: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5678: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5679: </fieldset>
5680: </form>
5681:
1.383 tempelho 5682: SEDFFORM
1.484.2.67 raeburn 5683:
5684: my $fromstoredjs;
5685: if ($canedit) {
5686: $fromstoredjs = 'open_StoredLinks_Import()';
5687: } else {
5688: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5689: }
5690:
1.484.2.19 raeburn 5691: my @importpubforma = (
5692: { '<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 5693: { '<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 5694: { '<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 5695: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5696: );
5697: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5698: my $extresourcesform =
5699: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5700: $help{'Adding_External_Resource'},
5701: undef,undef,$disabled);
1.329 droeschl 5702: if ($allowed) {
1.484.2.7 raeburn 5703: my $folder = $env{'form.folder'};
5704: if ($folder eq '') {
5705: $folder='default';
5706: }
1.484.2.67 raeburn 5707: if ($canedit) {
5708: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5709: if ($output) {
5710: $r->print($output);
5711: }
1.484.2.30 raeburn 5712: }
1.337 ehlerst 5713: $r->print(<<HIDDENFORM);
5714: <form name="renameform" method="post" action="/adm/coursedocs">
5715: <input type="hidden" name="title" />
5716: <input type="hidden" name="cmd" />
5717: <input type="hidden" name="markcopy" />
5718: <input type="hidden" name="copyfolder" />
5719: $containertag
5720: </form>
1.484 raeburn 5721:
1.337 ehlerst 5722: HIDDENFORM
1.484.2.17 raeburn 5723: $r->print(&makesimpleeditform($pathitem)."\n".
5724: &makedocslogform($pathitem."\n".
1.484 raeburn 5725: '<input type="hidden" name="folder" value="'.
5726: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5727: }
1.442 www 5728:
5729: # Generate the tabs
1.484.2.19 raeburn 5730: my ($mode,$needs_end);
1.472 raeburn 5731: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5732: my @folders = split('&',$env{'form.folderpath'});
5733: unless (@folders > 2) {
5734: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5735: $needs_end = 1;
5736: }
1.472 raeburn 5737: } else {
1.484 raeburn 5738: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5739: $needs_end = 1;
1.472 raeburn 5740: }
1.443 www 5741:
1.442 www 5742: #
5743:
5744: my $savefolderpath;
1.484.2.86 raeburn 5745: my $hostname = $r->hostname();
1.442 www 5746:
1.395 raeburn 5747: if ($allowed) {
1.329 droeschl 5748: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5749: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5750: $folder='default';
1.356 tempelho 5751: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5752: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5753: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5754: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5755: }
5756: my $postexec='';
5757: if ($folder eq 'default') {
1.372 bisitz 5758: $r->print('<script type="text/javascript">'."\n"
5759: .'// <![CDATA['."\n"
5760: .'this.window.name="loncapaclient";'."\n"
5761: .'// ]]>'."\n"
5762: .'</script>'."\n"
1.369 bisitz 5763: );
1.329 droeschl 5764: } else {
5765: #$postexec='self.close();';
5766: }
1.484.2.15 raeburn 5767: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5768: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5769: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5770:
5771: my $newnavform=(<<NNFORM);
5772: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5773: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5774: $pathitem
1.329 droeschl 5775: <input type="hidden" name="importdetail"
5776: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5777: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5778: $help{'Navigate_Content'}
5779: </form>
5780: NNFORM
5781: my $newsmppageform=(<<NSPFORM);
5782: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5783: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5784: $pathitem
1.329 droeschl 5785: <input type="hidden" name="importdetail" value="" />
1.423 onken 5786: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5787: $help{'Simple Page'}
1.329 droeschl 5788: </form>
5789: NSPFORM
5790:
5791: my $newsmpproblemform=(<<NSPROBFORM);
5792: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5793: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5794: $pathitem
1.329 droeschl 5795: <input type="hidden" name="importdetail" value="" />
1.423 onken 5796: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 5797: $help{'Simple_Problem'}
1.329 droeschl 5798: </form>
5799:
5800: NSPROBFORM
5801:
5802: my $newdropboxform=(<<NDBFORM);
5803: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5804: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5805: $pathitem
1.329 droeschl 5806: <input type="hidden" name="importdetail" value="" />
1.423 onken 5807: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 5808: $help{'Dropbox'}
1.344 bisitz 5809: </form>
1.329 droeschl 5810: NDBFORM
5811:
5812: my $newexuploadform=(<<NEXUFORM);
5813: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5814: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5815: $pathitem
1.329 droeschl 5816: <input type="hidden" name="importdetail" value="" />
1.423 onken 5817: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5818: $help{'Score_Upload_Form'}
5819: </form>
5820: NEXUFORM
5821:
5822: my $newbulform=(<<NBFORM);
5823: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 5824: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5825: $pathitem
1.329 droeschl 5826: <input type="hidden" name="importdetail" value="" />
1.423 onken 5827: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5828: $help{'Bulletin Board'}
5829: </form>
5830: NBFORM
5831:
5832: my $newaboutmeform=(<<NAMFORM);
5833: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 5834: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5835: $pathitem
1.329 droeschl 5836: <input type="hidden" name="importdetail"
5837: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5838: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5839: $help{'My Personal Information Page'}
1.329 droeschl 5840: </form>
5841: NAMFORM
5842:
5843: my $newaboutsomeoneform=(<<NASOFORM);
5844: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 5845: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5846: $pathitem
1.329 droeschl 5847: <input type="hidden" name="importdetail" value="" />
1.423 onken 5848: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5849: </form>
5850: NASOFORM
5851:
5852: my $newrosterform=(<<NROSTFORM);
5853: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 5854: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5855: $pathitem
1.329 droeschl 5856: <input type="hidden" name="importdetail"
5857: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 5858: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 5859: $help{'Course_Roster'}
1.329 droeschl 5860: </form>
5861: NROSTFORM
5862:
1.484.2.27 raeburn 5863: my $newwebpage;
5864: if ($folder =~ /^default_?(\d*)$/) {
5865: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5866: if ($1) {
5867: $newwebpage .= $1;
5868: } else {
5869: $newwebpage .= 'default';
5870: }
5871: $newwebpage .= '/new.html';
5872: }
5873: my $newwebpageform =(<<NWEBFORM);
5874: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 5875: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 5876: $pathitem
5877: <input type="hidden" name="importdetail" value="$newwebpage" />
5878: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 5879: $help{'Web_Page'}
1.484.2.27 raeburn 5880: </form>
5881: NWEBFORM
1.484.2.30 raeburn 5882:
1.484.2.27 raeburn 5883:
1.342 ehlerst 5884: my $specialdocumentsform;
1.383 tempelho 5885: my @specialdocumentsforma;
1.451 www 5886: my $gradingform;
5887: my @gradingforma;
5888: my $communityform;
5889: my @communityforma;
1.351 ehlerst 5890: my $newfolderform;
1.390 tempelho 5891: my $newfolderb;
1.342 ehlerst 5892:
1.451 www 5893: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5894:
1.329 droeschl 5895: my $newpageform=(<<NPFORM);
5896: <form action="/adm/coursedocs" method="post" name="newpage">
5897: <input type="hidden" name="folderpath" value="$path" />
5898: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5899: <input type="hidden" name="active" value="ee" />
1.423 onken 5900: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5901: $help{'Adding_Pages'}
1.329 droeschl 5902: </form>
5903: NPFORM
1.390 tempelho 5904:
5905:
1.351 ehlerst 5906: $newfolderform=(<<NFFORM);
1.329 droeschl 5907: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 5908: $pathitem
1.329 droeschl 5909: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5910: <input type="hidden" name="active" value="" />
1.422 onken 5911: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5912: </form>
5913: NFFORM
5914:
5915: my $newsylform=(<<NSYLFORM);
5916: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 5917: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5918: $pathitem
1.329 droeschl 5919: <input type="hidden" name="importdetail"
5920: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5921: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5922: $help{'Syllabus'}
1.383 tempelho 5923:
1.329 droeschl 5924: </form>
5925: NSYLFORM
1.364 bisitz 5926:
1.329 droeschl 5927: my $newgroupfileform=(<<NGFFORM);
5928: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 5929: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5930: $pathitem
1.329 droeschl 5931: <input type="hidden" name="importdetail"
5932: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 5933: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 5934: $help{'Group Portfolio'}
1.329 droeschl 5935: </form>
5936: NGFFORM
1.484.2.89 raeburn 5937: if ($container eq 'page') {
5938: @specialdocumentsforma=(
5939: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
5940: );
5941: } else {
5942: @specialdocumentsforma=(
1.421 onken 5943: {'<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 5944: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
5945: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 5946: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 5947: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.484.2.89 raeburn 5948: );
5949: }
1.451 www 5950: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5951:
1.434 raeburn 5952:
5953: my @importdoc = (
1.484.2.19 raeburn 5954: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5955: );
5956: unless ($container eq 'page') {
5957: push(@importdoc,
5958: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5959: );
5960: }
5961: push(@importdoc,
1.484.2.38 raeburn 5962: {'<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 5963: );
1.484.2.12 raeburn 5964: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5965:
1.451 www 5966: @gradingforma=(
5967: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5968: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5969: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5970:
5971: );
5972: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5973:
5974: @communityforma=(
5975: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5976: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5977: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 5978: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
5979: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 5980: );
5981: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5982:
1.330 tempelho 5983: my %orderhash = (
1.484.2.36 raeburn 5984: 'aa' => ['Upload',$fileuploadform],
5985: 'bb' => ['Import',$importpubform],
5986: 'cc' => ['Grading',$gradingform],
1.484.2.89 raeburn 5987: 'ee' => ['Other',$specialdocumentsform],
1.330 tempelho 5988: );
1.484.2.19 raeburn 5989: unless ($container eq 'page') {
1.434 raeburn 5990: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5991: $orderhash{'dd'} = ['Collaboration',$communityform];
1.434 raeburn 5992: }
5993:
1.341 ehlerst 5994: $hadchanges=0;
1.484 raeburn 5995: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5996: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5997: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.85 raeburn 5998: $canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 5999: undef($navmap);
1.443 www 6000: if ($error) {
6001: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6002: }
6003: if ($hadchanges) {
1.484.2.73 raeburn 6004: unless (&is_hash_old()) {
6005: &mark_hash_old();
6006: }
1.443 www 6007: }
1.341 ehlerst 6008:
1.443 www 6009: &changewarning($r,'');
6010: }
1.458 raeburn 6011: }
1.442 www 6012:
1.443 www 6013: # Supplemental documents start here
6014:
1.329 droeschl 6015: my $folder=$env{'form.folder'};
1.443 www 6016: unless ($supplementalflag) {
1.329 droeschl 6017: $folder='supplemental';
6018: }
6019: if ($folder =~ /^supplemental$/ &&
6020: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6021: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6022: } elsif ($allowed) {
1.356 tempelho 6023: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6024: }
1.484.2.17 raeburn 6025: $pathitem = '<input type="hidden" name="folderpath" value="'.
6026: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6027: if ($allowed) {
6028: my $folderseq=
1.484.2.15 raeburn 6029: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6030:
6031: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 6032: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6033: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6034: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6035: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6036: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6037: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6038: $fileupload
1.484.2.95! raeburn 6039: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
! 6040: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 6041: <br />
6042: <br />
6043: <span class="LC_nobreak">
6044: $checkbox
6045: </span>
6046: <br /><br />
6047: $lt{'comment'}:<br />
1.383 tempelho 6048: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6049: <br />
1.484.2.19 raeburn 6050: $pathitem
1.329 droeschl 6051: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6052: <input type='submit' value="$lt{'upld'}" />
1.484.2.95! raeburn 6053: </fieldset>
1.484.2.12 raeburn 6054: </form>
1.484.2.19 raeburn 6055: SUPDOCFORM
1.329 droeschl 6056:
6057: my $supnewfolderform=(<<SNFFORM);
6058: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6059: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6060: $pathitem
1.329 droeschl 6061: <input type="hidden" name="importdetail" value="" />
1.423 onken 6062: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6063: $help{'Adding_Folders'}
1.329 droeschl 6064: </form>
6065: SNFFORM
1.383 tempelho 6066:
1.484.2.19 raeburn 6067: my $supextform =
6068: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6069: $help{'Adding_External_Resource'},
6070: undef,undef,$disabled);
1.329 droeschl 6071:
6072: my $supnewsylform=(<<SNSFORM);
6073: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6074: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6075: $pathitem
1.329 droeschl 6076: <input type="hidden" name="importdetail"
6077: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6078: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6079: $help{'Syllabus'}
6080: </form>
6081: SNSFORM
6082:
6083: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6084: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6085: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6086: $pathitem
1.329 droeschl 6087: <input type="hidden" name="importdetail"
6088: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6089: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6090: $help{'My Personal Information Page'}
1.329 droeschl 6091: </form>
6092: SNAMFORM
6093:
1.484.2.27 raeburn 6094: my $supwebpage;
6095: if ($folder =~ /^supplemental_?(\d*)$/) {
6096: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6097: if ($1) {
6098: $supwebpage .= $1;
6099: } else {
6100: $supwebpage .= 'default';
6101: }
6102: $supwebpage .= '/new.html';
6103: }
6104: my $supwebpageform =(<<SWEBFORM);
6105: <form action="/adm/coursedocs" method="post" name="supwebpage">
6106: <input type="hidden" name="active" value="cc" />
6107: $pathitem
6108: <input type="hidden" name="importdetail" value="$supwebpage" />
6109: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6110: $help{'Web_Page'}
1.484.2.27 raeburn 6111: </form>
6112: SWEBFORM
6113:
1.333 muellerd 6114:
1.383 tempelho 6115: my @specialdocs = (
1.484.2.67 raeburn 6116: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6117: =>$supnewsylform},
1.484.2.67 raeburn 6118: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6119: =>$supnewaboutmeform},
1.484.2.27 raeburn 6120: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6121:
1.383 tempelho 6122: );
1.417 droeschl 6123: my @supimportdoc = (
1.484.2.19 raeburn 6124: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.12 raeburn 6125: =>$supextform},
6126: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6127: =>$supupdocform},
1.484.2.19 raeburn 6128: );
6129:
1.484.2.12 raeburn 6130: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6131: my %suporderhash = (
1.390 tempelho 6132: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6133: 'ee' => ['Upload',$supupdocform],
6134: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6135: );
1.443 www 6136: if ($supplementalflag) {
1.458 raeburn 6137: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6138: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.484.2.85 raeburn 6139: $canedit,$hostname);
1.443 www 6140: if ($error) {
6141: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6142: } else {
6143: if ($suppchanges) {
6144: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6145: my @ids=&Apache::lonnet::current_machine_ids();
6146: foreach my $server (keys(%servers)) {
6147: next if (grep(/^\Q$server\E$/,@ids));
6148: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6149: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6150: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6151: }
6152: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6153: undef($suppchanges);
6154: }
1.443 www 6155: }
1.393 raeburn 6156: }
1.443 www 6157: } elsif ($supplementalflag) {
1.458 raeburn 6158: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.85 raeburn 6159: $supplementalflag,'',$iconpath,$pathitem,'',$hostname);
1.393 raeburn 6160: if ($error) {
6161: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6162: }
1.393 raeburn 6163: }
1.389 tempelho 6164:
1.484.2.19 raeburn 6165: if ($needs_end) {
6166: $r->print(&endContentScreen());
6167: }
1.383 tempelho 6168:
1.329 droeschl 6169: if ($allowed) {
6170: $r->print('
6171: <form method="post" name="extimport" action="/adm/coursedocs">
6172: <input type="hidden" name="title" />
6173: <input type="hidden" name="url" />
6174: <input type="hidden" name="useform" />
6175: <input type="hidden" name="residx" />
6176: </form>');
6177: }
1.484 raeburn 6178: } elsif ($showdoc) {
1.329 droeschl 6179: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6180: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6181: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6182: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6183: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6184: }
6185: }
6186: $r->print(&Apache::loncommon::end_page());
6187: return OK;
1.364 bisitz 6188: }
1.329 droeschl 6189:
1.440 raeburn 6190: sub embedded_form_elems {
6191: my ($phase,$primaryurl,$newidx) = @_;
6192: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6193: $newidx =~s /\D+//g;
1.440 raeburn 6194: return <<STATE;
6195: <input type="hidden" name="folderpath" value="$folderpath" />
6196: <input type="hidden" name="cmd" value="upload_embedded" />
6197: <input type="hidden" name="newidx" value="$newidx" />
6198: <input type="hidden" name="phase" value="$phase" />
6199: <input type="hidden" name="primaryurl" value="$primaryurl" />
6200: STATE
6201: }
6202:
6203: sub embedded_destination {
6204: my $folder=$env{'form.folder'};
6205: my $destination = 'docs/';
6206: if ($folder =~ /^supplemental/) {
6207: $destination = 'supplemental/';
6208: }
6209: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6210: $destination .= 'default/';
6211: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6212: $destination .= $2.'/';
6213: }
1.484.2.78 raeburn 6214: my $newidx = $env{'form.newidx'};
6215: $newidx =~s /\D+//g;
6216: if ($newidx) {
6217: $destination .= $newidx;
6218: }
1.440 raeburn 6219: my $dir_root = '/userfiles';
6220: return ($destination,$dir_root);
6221: }
6222:
6223: sub return_to_editor {
6224: my $actionurl = '/adm/coursedocs';
6225: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6226: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6227: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6228: '</a></p>';
6229: }
6230:
1.476 raeburn 6231: sub decompression_info {
6232: my ($destination,$dir_root) = &embedded_destination();
6233: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6234: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6235: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6236: my $container='sequence';
1.480 raeburn 6237: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6238: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6239: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6240: $container='page';
6241: }
1.480 raeburn 6242: unshift(@hiddens,$pathitem);
6243: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6244: if ($item eq 'newidx') {
6245: next if ($env{'form.'.$item} =~ /\D/);
6246: }
1.480 raeburn 6247: if ($env{'form.'.$item}) {
6248: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6249: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6250: }
1.477 raeburn 6251: }
1.476 raeburn 6252: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6253: $hiddenelem);
6254: }
6255:
6256: sub decompression_phase_one {
6257: my ($dir,$file,$warning,$error,$output);
6258: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6259: &decompression_info();
1.484.2.7 raeburn 6260: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6261: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6262: } else {
6263: my $file = $1;
1.481 raeburn 6264: $output =
6265: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6266: $destination,$dir_root,
6267: $hiddenelem);
6268: if ($env{'form.autoextract_camtasia'}) {
6269: $output .= &remove_archive($docudom,$docuname,$container);
6270: }
1.476 raeburn 6271: }
6272: if ($error) {
6273: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6274: $error.'</p>'."\n";
6275: }
6276: if ($warning) {
6277: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6278: }
6279: return $output;
6280: }
6281:
6282: sub decompression_phase_two {
6283: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6284: &decompression_info();
1.481 raeburn 6285: my $output;
1.480 raeburn 6286: if ($env{'form.archivedelete'}) {
1.481 raeburn 6287: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6288: }
6289: $output .=
1.481 raeburn 6290: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6291: $destination,$dir_root,$hiddenelem);
6292: return $output;
6293: }
6294:
1.480 raeburn 6295: sub remove_archive {
6296: my ($docudom,$docuname,$container) = @_;
6297: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6298: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6299: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6300: if ($fatal) {
6301: if ($container eq 'page') {
6302: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6303: } else {
6304: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6305: }
1.484.2.54 raeburn 6306: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6307: } else {
6308: my $currcmd = $env{'form.cmd'};
6309: my $position = $env{'form.position'};
1.484.2.54 raeburn 6310: my $archiveidx = $position;
6311: if ($position > 0) {
6312: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6313: $archiveidx = $position-1;
6314: }
6315: $env{'form.cmd'} = 'remove_'.$archiveidx;
6316: my ($title,$url,@rrest) =
6317: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6318: if ($url eq $env{'form.archiveurl'}) {
6319: if (&handle_edit_cmd($docuname,$docudom)) {
6320: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6321: if ($fatal) {
6322: if ($container eq 'page') {
6323: $delwarning = &mt('An error occurred updating the contents of the current page.');
6324: } else {
6325: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6326: }
1.480 raeburn 6327: } else {
1.484.2.54 raeburn 6328: $delresult = &mt('Archive file removed.');
1.480 raeburn 6329: }
6330: }
1.484.2.54 raeburn 6331: } else {
6332: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6333: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6334: }
6335: }
6336: $env{'form.cmd'} = $currcmd;
6337: }
6338: if ($delwarning) {
6339: $output = '<p class="LC_warning">'.
6340: $delwarning.
6341: '</p>';
6342: }
6343: if ($delresult) {
6344: $output .= '<p class="LC_info">'.
6345: $delresult.
6346: '</p>';
6347: }
1.481 raeburn 6348: return $output;
1.480 raeburn 6349: }
6350:
1.484 raeburn 6351: sub generate_admin_menu {
1.484.2.67 raeburn 6352: my ($crstype,$canedit) = @_;
1.484 raeburn 6353: my $lc_crstype = lc($crstype);
6354: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6355: my %lt= ( # do not translate here
1.484 raeburn 6356: 'vc' => 'Verify Content',
6357: 'cv' => 'Check/Set Resource Versions',
6358: 'ls' => 'List Resource Identifiers',
6359: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6360: 'dcd' => "Copy $crstype Content to Authoring Space",
6361: );
1.484 raeburn 6362: my ($candump,$dumpurl);
6363: if ($home + $other > 0) {
6364: $candump = 'F';
6365: if ($home) {
6366: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6367: } else {
6368: my @hosts;
6369: foreach my $aurole (keys(%outhash)) {
6370: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6371: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6372: }
1.484 raeburn 6373: }
6374: if (@hosts == 1) {
6375: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6376: '&role='.
6377: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6378: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6379: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6380: } else {
6381: $dumpurl = "javascript:choose_switchserver_window()";
6382: }
6383: }
6384: }
6385: my @menu=
6386: ({ categorytitle=>'Administration',
6387: items =>[
6388: { linktext => $lt{'vc'},
6389: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6390: permission => 'F',
1.484.2.44 raeburn 6391: help => 'Docs_Verify_Content',
1.484 raeburn 6392: icon => 'verify.png',
6393: linktitle => 'Verify contents can be retrieved/rendered',
6394: },
6395: { linktext => $lt{'cv'},
6396: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6397: permission => 'F',
1.484.2.44 raeburn 6398: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6399: icon => 'resversion.png',
6400: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6401: },
6402: { linktext => $lt{'ls'},
6403: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6404: permission => 'F',
6405: #help => '',
6406: icon => 'symbs.png',
6407: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6408: },
6409: ]
1.484.2.67 raeburn 6410: });
6411: if ($canedit) {
6412: push(@menu,
1.484 raeburn 6413: { categorytitle=>'Export',
6414: items =>[
6415: { linktext => $lt{'imse'},
6416: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6417: permission => 'F',
6418: help => 'Docs_Export_Course_Docs',
6419: icon => 'imsexport.png',
6420: linktitle => $lt{'imse'},
6421: },
6422: { linktext => $lt{'dcd'},
6423: url => $dumpurl,
6424: permission => $candump,
1.484.2.44 raeburn 6425: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6426: icon => 'dump.png',
6427: linktitle => $lt{'dcd'},
6428: },
6429: ]
6430: });
1.484.2.67 raeburn 6431: }
1.484 raeburn 6432: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6433: '<input type="hidden" id="dummy" />'."\n".
6434: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6435: '</form>';
1.329 droeschl 6436: }
6437:
6438: sub generate_edit_table {
1.484.2.30 raeburn 6439: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6440: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6441: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6442: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6443: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6444: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6445: $activetab = $env{'form.active'};
6446: }
1.484.2.67 raeburn 6447: unless ($canedit) {
6448: $disabled = ' disabled="disabled"';
6449: }
1.472 raeburn 6450: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6451: my $backtext = &mt('Exit Editor');
1.458 raeburn 6452: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6453: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6454: '<li class="goback">'.
1.484.2.32 raeburn 6455: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6456: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6457: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6458: '<li>'.
6459: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6460: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6461: if ($env{'form.docslog'}) {
6462: $form .= '<li class="active">';
6463: } else {
6464: $form .= '<li>';
6465: }
6466: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6467: &mt('History').'</a></li>'."\n";
6468: if ($env{'form.docslog'}) {
6469: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6470: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6471: }
1.458 raeburn 6472: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6473: if($name ne '00'){
1.371 tempelho 6474: if($activetab eq '' || $activetab ne $name){
6475: $active = '';
6476: }elsif($activetab eq $name){
6477: $active = 'class="active"';
6478: }
1.458 raeburn 6479: $form .= '<li style="float:right" '.$active
1.484 raeburn 6480: .' 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 6481: } else {
1.484.2.43 raeburn 6482: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6483:
6484: }
1.329 droeschl 6485: }
1.484 raeburn 6486: $form .= '</ul>'."\n";
6487: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6488:
6489: if ($to_show ne '') {
1.484.2.30 raeburn 6490: my $saveform;
6491: if ($need_save) {
6492: my $button = &mt('Make changes');
6493: my $path;
6494: if ($env{'form.folderpath'}) {
6495: $path =
6496: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6497: }
6498: $saveform = <<"END";
6499: <div id="multisave" style="display:none; clear:both;" >
6500: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6501: <input type="hidden" name="folderpath" value="$path" />
6502: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6503: <input type="hidden" name="allhiddenresource" value="" />
6504: <input type="hidden" name="allencrypturl" value="" />
6505: <input type="hidden" name="allrandompick" value="" />
6506: <input type="hidden" name="allrandomorder" value="" />
6507: <input type="hidden" name="changeparms" value="" />
6508: <input type="hidden" name="multiremove" value="" />
6509: <input type="hidden" name="multicut" value="" />
6510: <input type="hidden" name="multicopy" value="" />
6511: <input type="hidden" name="multichange" value="" />
6512: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6513: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6514: </form>
6515: </div>
6516: END
6517: }
6518: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6519: }
1.363 ehlerst 6520: foreach my $field (keys(%orderhash)){
1.390 tempelho 6521: if($field ne '00'){
1.422 onken 6522: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6523: $active = 'style="display: none;float:left"';
1.422 onken 6524: }elsif($activetab eq $field){
1.458 raeburn 6525: $active = 'style="display:block;float:left"';
1.422 onken 6526: }
6527: $form .= '<div id="'.$field.$tid.'"'
6528: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6529: .'</div>'."\n";
1.363 ehlerst 6530: }
6531: }
1.484 raeburn 6532: unless ($env{'form.docslog'}) {
6533: $form .= '</div></div>'."\n";
6534: }
1.329 droeschl 6535: return $form;
6536: }
6537:
6538: sub editing_js {
1.484.2.80 raeburn 6539: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,
6540: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6541: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6542: p_mnf => 'Name of New Folder',
6543: t_mnf => 'New Folder',
6544: p_mnp => 'Name of New Page',
6545: t_mnp => 'New Page',
1.451 www 6546: p_mxu => 'Title for the External Score',
1.349 biermanm 6547: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6548: p_msb => 'Title for the Problem',
6549: p_mdb => 'Title for the Drop Box',
1.336 schafran 6550: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6551: p_mwp => 'Title for Web Page',
1.348 weissno 6552: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6553: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6554: p_mab_alrt1 => 'Not a valid user:domain',
6555: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6556: p_chn => 'New Title',
6557: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6558: p_rmr2a => 'Remove',
6559: p_rmr2b => '?',
6560: p_rmr3a => 'Remove those',
6561: p_rmr3b => 'items?',
6562: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6563: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6564: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6565: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6566: p_ctr2a => 'Cut',
6567: p_ctr2b => '?',
6568: p_ctr3a => 'Cut those',
6569: p_ctr3b => 'items?',
1.478 raeburn 6570: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6571: imsfile => 'You must choose an IMS package for import',
6572: imscms => 'You must select which Course Management System was the source of the IMS package',
6573: invurl => 'Invalid URL',
6574: titbl => 'Title is blank',
1.484.2.30 raeburn 6575: more => '(More ...)',
6576: less => '(Less ...)',
6577: noor => 'No actions selected or changes to settings specified.',
6578: noch => 'No changes to settings specified.',
6579: noac => 'No actions selected.',
1.484.2.67 raeburn 6580: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6581: );
6582:
1.484.2.61 raeburn 6583: &js_escape(\%js_lt);
1.433 raeburn 6584: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6585: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6586: my $main_container_page;
1.484.2.19 raeburn 6587: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6588: $main_container_page = 1;
1.434 raeburn 6589: }
1.484.2.67 raeburn 6590: my $backtourl;
6591: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6592: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6593:
1.484.2.21 raeburn 6594: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6595: my $caller = $1;
6596: if ($caller =~ /^supplemental/) {
6597: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6598: } else {
6599: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6600: $res = &Apache::lonnet::clutter($res);
6601: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6602: my ($url,$anchor);
6603: if ($res =~ /^([^#]+)#([^#]+)$/) {
6604: $url = $1;
6605: $anchor = $2;
6606: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6607: $caller = $1.&escape('#').$anchor;
6608: }
1.484.2.67 raeburn 6609: } else {
6610: $url = $res;
1.484.2.66 raeburn 6611: }
1.484.2.83 raeburn 6612: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
6613: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
6614: $backtourl .= '?navmap=1';
6615: } else {
6616: $backtourl .= '?symb='.
6617: &HTML::Entities::encode($caller,'<>&"');
6618: }
1.484.2.80 raeburn 6619: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6620: if (($ENV{'SERVER_PORT'} == 443) &&
6621: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 6622: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 6623: if ($hostname ne '') {
6624: $backtourl = 'http://'.$hostname.$backtourl;
6625: }
6626: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6627: }
6628: }
6629: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6630: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.484.2.93 raeburn 6631: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 6632: if ($hostname ne '') {
6633: $backtourl = 'http://'.$hostname.$backtourl;
6634: }
6635: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6636: }
6637: }
6638: }
1.484.2.66 raeburn 6639: if ($anchor ne '') {
6640: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6641: }
1.484.2.57 raeburn 6642: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6643: } else {
6644: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6645: }
6646: }
6647: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6648: $backtourl = '/adm/menu';
6649: } elsif ($supplementalflag) {
1.472 raeburn 6650: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6651: } else {
6652: $backtourl = '/adm/navmaps';
1.472 raeburn 6653: }
6654:
1.484.2.19 raeburn 6655: my $fieldsets = "'ext','doc'";
6656: unless ($main_container_page) {
6657: $fieldsets .=",'ims'";
6658: }
1.484.2.12 raeburn 6659: if ($supplementalflag) {
6660: $fieldsets = "'suppext','suppdoc'";
6661: }
6662:
1.484.2.67 raeburn 6663: my $jsmakefunctions;
6664: if ($canedit) {
6665: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6666: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6667: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6668: if (foldername) {
1.484.2.91 raeburn 6669: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 6670: targetform.submit();
6671: }
6672: }
6673:
6674: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6675: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6676: if (pagename) {
1.484.2.91 raeburn 6677: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 6678: targetform.submit();
6679: }
6680: }
6681:
6682: function makeexamupload() {
1.484.2.61 raeburn 6683: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6684: if (title) {
1.329 droeschl 6685: this.document.forms.newexamupload.importdetail.value=
1.484.2.91 raeburn 6686: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 6687: this.document.forms.newexamupload.submit();
6688: }
6689: }
6690:
6691: function makesmppage() {
1.484.2.61 raeburn 6692: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6693: if (title) {
1.329 droeschl 6694: this.document.forms.newsmppg.importdetail.value=
1.484.2.91 raeburn 6695: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6696: this.document.forms.newsmppg.submit();
6697: }
6698: }
6699:
1.484.2.27 raeburn 6700: function makewebpage(type) {
1.484.2.61 raeburn 6701: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6702: var formname;
6703: if (type == 'supp') {
6704: formname = this.document.forms.supwebpage;
6705: } else {
6706: formname = this.document.forms.newwebpage;
6707: }
6708: if (title) {
6709: var webpage = formname.importdetail.value;
1.484.2.91 raeburn 6710: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.484.2.27 raeburn 6711: formname.submit();
6712: }
6713: }
6714:
1.329 droeschl 6715: function makesmpproblem() {
1.484.2.61 raeburn 6716: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6717: if (title) {
1.329 droeschl 6718: this.document.forms.newsmpproblem.importdetail.value=
1.484.2.91 raeburn 6719: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 6720: this.document.forms.newsmpproblem.submit();
6721: }
6722: }
6723:
6724: function makedropbox() {
1.484.2.61 raeburn 6725: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6726: if (title) {
1.329 droeschl 6727: this.document.forms.newdropbox.importdetail.value=
1.484.2.91 raeburn 6728: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 6729: this.document.forms.newdropbox.submit();
6730: }
6731: }
6732:
6733: function makebulboard() {
1.484.2.61 raeburn 6734: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6735: if (title) {
6736: this.document.forms.newbul.importdetail.value=
1.484.2.91 raeburn 6737: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6738: this.document.forms.newbul.submit();
6739: }
6740: }
6741:
6742: function makeabout() {
1.484.2.61 raeburn 6743: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6744: if (user) {
6745: var comp=new Array();
6746: comp=user.split(':');
6747: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6748: if ((comp[0]) && (comp[1])) {
6749: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6750: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6751: this.document.forms.newaboutsomeone.submit();
6752: } else {
6753: alert("$js_lt{'p_mab_alrt1'}");
6754: }
6755: } else {
6756: alert("$js_lt{'p_mab_alrt2'}");
6757: }
6758: }
1.335 ehlerst 6759: }
1.484.2.67 raeburn 6760:
6761: function makenew(targetform) {
6762: targetform.submit();
1.335 ehlerst 6763: }
1.484.2.67 raeburn 6764:
6765: function changename(folderpath,index,oldtitle) {
6766: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6767: if (title) {
6768: this.document.forms.renameform.markcopy.value='';
6769: this.document.forms.renameform.title.value=title;
6770: this.document.forms.renameform.cmd.value='rename_'+index;
6771: this.document.forms.renameform.folderpath.value=folderpath;
6772: this.document.forms.renameform.submit();
6773: }
1.329 droeschl 6774: }
6775:
1.484.2.67 raeburn 6776: ENDNEWSCRIPT
6777: } else {
6778: $jsmakefunctions = <<ENDNEWSCRIPT;
6779:
6780: function makenewfolder() {
6781: alert("$js_lt{'edri'}");
6782: }
6783:
6784: function makenewpage() {
6785: alert("$js_lt{'edri'}");
6786: }
6787:
6788: function makeexamupload() {
6789: alert("$js_lt{'edri'}");
6790: }
6791:
6792: function makesmppage() {
6793: alert("$js_lt{'edri'}");
6794: }
6795:
6796: function makewebpage(type) {
6797: alert("$js_lt{'edri'}");
6798: }
6799:
6800: function makesmpproblem() {
6801: alert("$js_lt{'edri'}");
6802: }
6803:
6804: function makedropbox() {
6805: alert("$js_lt{'edri'}");
6806: }
6807:
6808: function makebulboard() {
6809: alert("$js_lt{'edri'}");
6810: }
6811:
6812: function makeabout() {
6813: alert("$js_lt{'edri'}");
6814: }
6815:
6816: function changename() {
6817: alert("$js_lt{'edri'}");
6818: }
6819:
6820: function makenew() {
6821: alert("$js_lt{'edri'}");
6822: }
6823:
6824: function groupimport() {
6825: alert("$js_lt{'edri'}");
6826: }
6827:
6828: function groupsearch() {
6829: alert("$js_lt{'edri'}");
6830: }
6831:
6832: function groupopen(url,recover) {
6833: var options="scrollbars=1,resizable=1,menubar=0";
6834: idxflag=1;
6835: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6836: idx.focus();
6837: }
6838:
6839: ENDNEWSCRIPT
6840:
6841: }
6842: return <<ENDSCRIPT;
6843:
6844: $jsmakefunctions
6845:
1.484.2.13 raeburn 6846: function toggleUpload(caller) {
6847: var blocks = Array($fieldsets);
6848: for (var i=0; i<blocks.length; i++) {
6849: var disp = 'none';
6850: if (caller == blocks[i]) {
6851: var curr = document.getElementById('upload'+caller+'form').style.display;
6852: if (curr == 'none') {
6853: disp='block';
6854: }
6855: }
6856: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6857: }
6858: resize_scrollbox('contentscroll','1','1');
6859: return;
6860: }
6861:
1.484.2.19 raeburn 6862: function toggleMap(caller) {
1.484.2.13 raeburn 6863: var disp = 'none';
1.484.2.19 raeburn 6864: if (document.getElementById('importmapform')) {
6865: if (caller == 'map') {
6866: var curr = document.getElementById('importmapform').style.display;
6867: if (curr == 'none') {
6868: disp='block';
6869: }
1.484.2.12 raeburn 6870: }
1.484.2.19 raeburn 6871: document.getElementById('importmapform').style.display=disp;
6872: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 6873: }
1.484.2.19 raeburn 6874: return;
1.329 droeschl 6875: }
6876:
1.484.2.12 raeburn 6877: function makeims(imsform) {
6878: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 6879: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 6880: return;
6881: }
6882: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 6883: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 6884: return;
6885: }
6886: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6887: imsform.submit();
6888: }
6889:
1.478 raeburn 6890: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 6891: var pickitem;
6892: var picknumitem;
6893: var picknumtext;
6894: if (index == 'all') {
6895: pickitem = document.getElementById('randompickall');
6896: picknumitem = document.getElementById('rpicknumall');
6897: picknumtext = document.getElementById('rpicktextall');
6898: } else {
6899: pickitem = document.getElementById('randompick_'+index);
6900: picknumitem = document.getElementById('rpicknum_'+index);
6901: picknumtext = document.getElementById('randompicknum_'+index);
6902: }
1.478 raeburn 6903: if (pickitem.checked) {
1.484.2.61 raeburn 6904: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6905: if (picknum == '' || picknum == null) {
6906: if (caller == 'check') {
6907: pickitem.checked=false;
1.484.2.29 raeburn 6908: if (index == 'all') {
6909: picknumtext.innerHTML = '';
6910: if (caller == 'link') {
6911: propagateState(targetform,'rpicknum');
6912: }
6913: } else {
1.484.2.30 raeburn 6914: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6915: }
1.478 raeburn 6916: }
6917: } else {
6918: picknum.toString();
6919: var regexdigit=/^\\d+\$/;
6920: if (regexdigit.test(picknum)) {
6921: picknumitem.value = picknum;
1.484.2.29 raeburn 6922: if (index == 'all') {
1.484.2.30 raeburn 6923: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 6924: if (caller == 'link') {
6925: propagateState(targetform,'rpicknum');
6926: }
6927: } else {
6928: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 6929: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6930: }
1.478 raeburn 6931: } else {
6932: if (caller == 'check') {
1.484.2.29 raeburn 6933: if (index == 'all') {
6934: picknumtext.innerHTML = '';
6935: if (caller == 'link') {
6936: propagateState(targetform,'rpicknum');
6937: }
6938: } else {
6939: pickitem.checked=false;
1.484.2.30 raeburn 6940: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6941: }
1.478 raeburn 6942: }
6943: return;
6944: }
6945: }
6946: } else {
1.484.2.29 raeburn 6947: picknumitem.value = '';
6948: picknumtext.innerHTML = '';
6949: if (index == 'all') {
6950: if (caller == 'link') {
6951: propagateState(targetform,'rpicknum');
6952: }
6953: } else {
1.484.2.30 raeburn 6954: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6955: }
6956: }
6957: }
6958:
6959: function propagateState(form,param) {
6960: if (document.getElementById(param+'all')) {
6961: var setcheck = 0;
6962: var rpick = 0;
6963: if (param == 'rpicknum') {
6964: if (document.getElementById('randompickall')) {
6965: if (document.getElementById('randompickall').checked) {
6966: if (document.getElementById('rpicknumall')) {
6967: rpick = document.getElementById('rpicknumall').value;
6968: }
6969: }
6970: }
6971: } else {
6972: if (document.getElementById(param+'all').checked) {
6973: setcheck = 1;
6974: }
6975: }
1.484.2.30 raeburn 6976: var allidxlist;
6977: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6978: if (document.getElementById('all'+param+'idx')) {
6979: allidxlist = document.getElementById('all'+param+'idx').value;
6980: }
6981: var actions = new Array ('remove','cut','copy');
6982: for (var i=0; i<actions.length; i++) {
6983: if (actions[i] != param) {
6984: if (document.getElementById(actions[i]+'all')) {
6985: document.getElementById(actions[i]+'all').checked = false;
6986: }
6987: }
6988: }
6989: }
1.484.2.29 raeburn 6990: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 6991: allidxlist = form.allidx.value;
6992: }
6993: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6994: allidxlist = form.allmapidx.value;
6995: }
6996: if ((allidxlist != '') && (allidxlist != null)) {
6997: var allidxs = allidxlist.split(',');
6998: if (allidxs.length > 1) {
6999: for (var i=0; i<allidxs.length; i++) {
7000: if (document.getElementById(param+'_'+allidxs[i])) {
7001: if (param == 'rpicknum') {
7002: if (document.getElementById('randompick_'+allidxs[i])) {
7003: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7004: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7005: if (rpick > 0) {
7006: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7007: } else {
7008: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7009: }
7010: }
7011: }
7012: } else {
1.484.2.29 raeburn 7013: if (setcheck == 1) {
7014: document.getElementById(param+'_'+allidxs[i]).checked = true;
7015: } else {
7016: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 7017: if (param == 'randompick') {
7018: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7019: }
1.484.2.29 raeburn 7020: }
7021: }
7022: }
7023: }
1.484.2.30 raeburn 7024: if (setcheck == 1) {
7025: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7026: var actions = new Array('copy','cut','remove');
7027: for (var i=0; i<actions.length; i++) {
7028: var otheractions;
7029: var otheridxs;
7030: if (actions[i] === param) {
7031: continue;
7032: } else {
7033: if (document.getElementById('all'+actions[i]+'idx')) {
7034: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7035: otheridxs = otheractions.split(',');
7036: if (otheridxs.length > 1) {
7037: for (var j=0; j<otheridxs.length; j++) {
7038: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7039: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7040: }
1.484.2.29 raeburn 7041: }
7042: }
7043: }
7044: }
1.484.2.30 raeburn 7045: }
1.484.2.29 raeburn 7046: }
7047: }
7048: }
7049: }
1.478 raeburn 7050: }
1.484.2.29 raeburn 7051: return;
7052: }
7053:
1.484.2.63 raeburn 7054: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7055: var canedit = '$canedit';
7056: if (canedit == '') {
7057: alert("$js_lt{'edri'}");
7058: return;
7059: }
1.484.2.30 raeburn 7060: var dosettings;
7061: var doaction;
7062: var control = document.togglemultsettings;
7063: if (context == 'actions') {
7064: control = document.togglemultactions;
7065: doaction = 1;
7066: } else {
7067: dosettings = 1;
7068: }
7069: if (control) {
7070: if (control.showmultpick.length) {
7071: for (var i=0; i<control.showmultpick.length; i++) {
7072: if (control.showmultpick[i].checked) {
7073: if (control.showmultpick[i].value == 1) {
7074: if (context == 'settings') {
7075: dosettings = 0;
7076: } else {
7077: doaction = 0;
7078: }
7079: }
7080: }
7081: }
7082: }
7083: }
7084: if (context == 'settings') {
7085: if (dosettings == 1) {
7086: targetform.changeparms.value=param;
7087: targetform.submit();
7088: }
7089: }
7090: if (context == 'actions') {
7091: if (doaction == 1) {
7092: targetform.cmd.value=param+'_'+index;
7093: targetform.folderpath.value=folderpath;
7094: targetform.markcopy.value=idx+':'+param;
7095: targetform.copyfolder.value=folder+'.'+container;
7096: if (param == 'remove') {
1.484.2.63 raeburn 7097: var doremove = 0;
7098: if (skip_confirm) {
7099: if (confirm_removal) {
7100: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7101: doremove = 1;
7102: }
7103: } else {
7104: doremove = 1;
7105: }
7106: } else {
7107: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7108: doremove = 1;
7109: }
7110: }
7111: if (doremove) {
1.484.2.30 raeburn 7112: targetform.markcopy.value='';
7113: targetform.copyfolder.value='';
1.484.2.29 raeburn 7114: targetform.submit();
7115: }
7116: }
1.484.2.30 raeburn 7117: if (param == 'cut') {
1.484.2.61 raeburn 7118: 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 7119: targetform.submit();
7120: return;
7121: }
7122: }
7123: if (param == 'copy') {
7124: targetform.submit();
7125: return;
7126: }
7127: targetform.markcopy.value='';
7128: targetform.copyfolder.value='';
7129: targetform.cmd.value='';
7130: targetform.folderpath.value='';
7131: return;
7132: } else {
7133: if (document.getElementById(param+'_'+idx)) {
7134: item = document.getElementById(param+'_'+idx);
7135: if (item.type == 'checkbox') {
7136: if (item.checked) {
7137: item.checked = false;
7138: } else {
7139: item.checked = true;
7140: singleCheck(item,idx,param);
7141: }
7142: }
7143: }
7144: }
7145: }
7146: return;
7147: }
7148:
7149: function singleCheck(caller,idx,action) {
7150: actions = new Array('cut','copy','remove');
7151: if (caller.checked) {
7152: for (var i=0; i<actions.length; i++) {
7153: if (actions[i] != action) {
7154: if (document.getElementById(actions[i]+'_'+idx)) {
7155: if (document.getElementById(actions[i]+'_'+idx).checked) {
7156: document.getElementById(actions[i]+'_'+idx).checked = false;
7157: }
7158: }
7159: }
1.484.2.29 raeburn 7160: }
7161: }
7162: return;
1.478 raeburn 7163: }
7164:
1.334 muellerd 7165: function unselectInactive(nav) {
1.335 ehlerst 7166: currentNav = document.getElementById(nav);
7167: currentLis = currentNav.getElementsByTagName('LI');
7168: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7169: if (currentLis[i].className == 'goback') {
7170: currentLis[i].className = 'goback';
7171: } else {
7172: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7173: currentLis[i].className = 'right';
1.472 raeburn 7174: } else {
1.374 tempelho 7175: currentLis[i].className = 'i';
1.472 raeburn 7176: }
7177: }
1.335 ehlerst 7178: }
1.332 tempelho 7179: }
7180:
1.334 muellerd 7181: function hideAll(current, nav, data) {
1.335 ehlerst 7182: unselectInactive(nav);
1.484.2.43 raeburn 7183: if (current) {
7184: if (current.className == 'right'){
1.374 tempelho 7185: current.className = 'right active'
1.484.2.43 raeburn 7186: } else {
1.374 tempelho 7187: current.className = 'active';
1.484.2.43 raeburn 7188: }
1.374 tempelho 7189: }
1.335 ehlerst 7190: currentData = document.getElementById(data);
7191: currentDivs = currentData.getElementsByTagName('DIV');
7192: for (i = 0; i < currentDivs.length; i++) {
7193: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7194: currentDivs[i].style.display = 'none';
1.330 tempelho 7195: }
7196: }
1.335 ehlerst 7197: }
1.330 tempelho 7198:
1.374 tempelho 7199: function openTabs(pageId) {
7200: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7201: if(tabnav.length > 2 ){
1.389 tempelho 7202: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7203: currentLis = currentNav.getElementsByTagName('LI');
7204: for(i = 0; i< currentLis.length; i++){
7205: if(currentLis[i].className == 'active') {
1.375 tempelho 7206: funcString = currentLis[i].onclick.toString();
7207: tab = funcString.split('"');
1.420 onken 7208: if(tab.length < 2) {
7209: tab = funcString.split("'");
7210: }
1.375 tempelho 7211: currentData = document.getElementById(tab[1]);
7212: currentData.style.display = 'block';
1.374 tempelho 7213: }
7214: }
7215: }
7216: }
7217:
1.334 muellerd 7218: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7219: currstate = current.className;
1.334 muellerd 7220: hideAll(current, nav, data);
1.375 tempelho 7221: openTabs(pageId);
1.334 muellerd 7222: unselectInactive(nav);
1.484.2.43 raeburn 7223: if ((currstate == 'active') || (currstate == 'right active')) {
7224: if (currstate == 'active') {
7225: current.className = '';
7226: } else {
7227: current.className = 'right';
7228: }
7229: activeTab = '';
7230: toggleUpload();
7231: toggleMap();
7232: resize_scrollbox('contentscroll','1','0');
7233: return;
7234: } else {
7235: current.className = 'active';
7236: }
1.330 tempelho 7237: currentData = document.getElementById(pageId);
7238: currentData.style.display = 'block';
1.458 raeburn 7239: activeTab = pageId;
1.484.2.12 raeburn 7240: toggleUpload();
1.484.2.14 raeburn 7241: toggleMap();
1.433 raeburn 7242: if (nav == 'mainnav') {
7243: var storedpath = "$docs_folderpath";
1.434 raeburn 7244: var storedpage = "$main_container_page";
1.433 raeburn 7245: var reg = new RegExp("^supplemental");
7246: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7247: if (storedpage == 1) {
7248: document.simpleedit.folderpath.value = '';
7249: document.uploaddocument.folderpath.value = '';
7250: } else {
7251: if (reg.test(storedpath)) {
7252: document.simpleedit.folderpath.value = '$toplevelmain';
7253: document.uploaddocument.folderpath.value = '$toplevelmain';
7254: document.newext.folderpath.value = '$toplevelmain';
7255: } else {
7256: document.simpleedit.folderpath.value = storedpath;
7257: document.uploaddocument.folderpath.value = storedpath;
7258: document.newext.folderpath.value = storedpath;
7259: }
1.433 raeburn 7260: }
7261: } else {
1.434 raeburn 7262: if (reg.test(storedpath)) {
7263: document.simpleedit.folderpath.value = storedpath;
7264: document.supuploaddocument.folderpath.value = storedpath;
7265: document.supnewext.folderpath.value = storedpath;
7266: } else {
1.433 raeburn 7267: document.simpleedit.folderpath.value = '$toplevelsupp';
7268: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7269: document.supnewext.folderpath.value = '$toplevelsupp';
7270: }
7271: }
7272: }
1.484.2.3 raeburn 7273: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7274: return false;
7275: }
1.329 droeschl 7276:
1.472 raeburn 7277: function toContents(jumpto) {
7278: var newurl = '$backtourl';
1.484.2.21 raeburn 7279: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7280: newurl = newurl+'?postdata='+jumpto;
7281: }
7282: location.href=newurl;
7283: }
7284:
1.484.2.30 raeburn 7285: function togglePick(caller,value) {
7286: var disp = 'none';
7287: if (document.getElementById('multi'+caller)) {
7288: var curr = document.getElementById('multi'+caller).style.display;
7289: if (value == 1) {
7290: disp='block';
7291: }
7292: if (curr == disp) {
7293: return;
7294: }
7295: document.getElementById('multi'+caller).style.display=disp;
7296: if (value == 1) {
1.484.2.61 raeburn 7297: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7298: } else {
7299: document.getElementById('more'+caller).innerHTML = '';
7300: }
7301: if (caller == 'actions') {
7302: setClass(value);
7303: setBoxes(value);
7304: }
7305: }
7306: var showButton = multiSettings();
7307: if (showButton != 1) {
7308: showButton = multiActions();
7309: }
7310: if (document.getElementById('multisave')) {
7311: if (showButton == 1) {
7312: document.getElementById('multisave').style.display='block';
7313: } else {
7314: document.getElementById('multisave').style.display='none';
7315: }
7316: }
7317: resize_scrollbox('contentscroll','1','1');
7318: return;
7319: }
7320:
7321: function toggleCheckUncheck(caller,more) {
7322: if (more == 1) {
1.484.2.61 raeburn 7323: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7324: document.getElementById('allfields'+caller).style.display='block';
7325: } else {
1.484.2.61 raeburn 7326: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7327: document.getElementById('allfields'+caller).style.display='none';
7328: }
7329: resize_scrollbox('contentscroll','1','1');
7330: }
7331:
7332: function multiSettings() {
7333: var inuse = 0;
7334: var settingsform = document.togglemultsettings;
7335: if (settingsform.showmultpick.length > 1) {
7336: for (var i=0; i<settingsform.showmultpick.length; i++) {
7337: if (settingsform.showmultpick[i].checked) {
7338: if (settingsform.showmultpick[i].value == 1) {
7339: inuse = 1;
7340: }
7341: }
7342: }
7343: }
7344: return inuse;
7345: }
7346:
7347: function multiActions() {
7348: var inuse = 0;
7349: var actionsform = document.togglemultactions;
7350: if (actionsform.showmultpick.length > 1) {
7351: for (var i=0; i<actionsform.showmultpick.length; i++) {
7352: if (actionsform.showmultpick[i].checked) {
7353: if (actionsform.showmultpick[i].value == 1) {
7354: inuse = 1;
7355: }
7356: }
7357: }
7358: }
7359: return inuse;
7360: }
7361:
7362: function checkSubmits() {
7363: var numchanges = 0;
7364: var form = document.saveactions;
7365: var doactions = multiActions();
7366: var cutwarnings = 0;
7367: var remwarnings = 0;
1.484.2.63 raeburn 7368: var removalinfo = 0;
1.484.2.30 raeburn 7369: if (doactions == 1) {
7370: var remidxlist = document.cumulativeactions.allremoveidx.value;
7371: if ((remidxlist != '') && (remidxlist != null)) {
7372: var remidxs = remidxlist.split(',');
7373: for (var i=0; i<remidxs.length; i++) {
7374: if (document.getElementById('remove_'+remidxs[i])) {
7375: if (document.getElementById('remove_'+remidxs[i]).checked) {
7376: form.multiremove.value += remidxs[i]+',';
7377: numchanges ++;
7378: if (document.getElementById('skip_remove_'+remidxs[i])) {
7379: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7380: remwarnings ++;
7381: }
7382: }
1.484.2.63 raeburn 7383: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7384: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7385: removalinfo ++;
7386: }
7387: }
1.484.2.30 raeburn 7388: }
7389: }
7390: }
7391: }
7392: var cutidxlist = document.cumulativeactions.allcutidx.value;
7393: if ((cutidxlist != '') && (cutidxlist != null)) {
7394: var cutidxs = cutidxlist.split(',');
7395: for (var i=0; i<cutidxs.length; i++) {
7396: if (document.getElementById('cut_'+cutidxs[i])) {
7397: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7398: form.multicut.value += cutidxs[i]+',';
7399: numchanges ++;
7400: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7401: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7402: cutwarnings ++;
7403: }
7404: }
7405: }
7406: }
7407: }
7408: }
7409: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7410: if ((copyidxlist != '') && (copyidxlist != null)) {
7411: var copyidxs = copyidxlist.split(',');
7412: for (var i=0; i<copyidxs.length; i++) {
7413: if (document.getElementById('copy_'+copyidxs[i])) {
7414: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7415: form.multicopy.value += copyidxs[i]+',';
7416: numchanges ++;
7417: }
7418: }
7419: }
7420: }
7421: if (numchanges > 0) {
7422: form.multichange.value = numchanges;
7423: }
7424: }
7425: var dosettings = multiSettings();
7426: var haschanges = 0;
7427: if (dosettings == 1) {
7428: form.allencrypturl.value = '';
7429: form.allhiddenresource.value = '';
7430: form.changeparms.value = 'all';
7431: var patt=new RegExp(",\$");
7432: var allidxlist = document.cumulativesettings.allidx.value;
7433: if ((allidxlist != '') && (allidxlist != null)) {
7434: var allidxs = allidxlist.split(',');
7435: if (allidxs.length > 1) {
7436: for (var i=0; i<allidxs.length; i++) {
7437: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7438: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7439: form.allhiddenresource.value += allidxs[i]+',';
7440: }
7441: }
7442: if (document.getElementById('encrypturl_'+allidxs[i])) {
7443: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7444: form.allencrypturl.value += allidxs[i]+',';
7445: }
1.484.2.29 raeburn 7446: }
7447: }
1.484.2.30 raeburn 7448: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7449: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7450: }
7451: }
7452: form.allrandompick.value = '';
7453: form.allrandomorder.value = '';
7454: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7455: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7456: var allmapidxs = allmapidxlist.split(',');
7457: for (var i=0; i<allmapidxs.length; i++) {
7458: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7459: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7460: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7461: if ((randompick.checked) && (rpicknum.value != '')) {
7462: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7463: }
7464: if (randorder.checked) {
7465: form.allrandomorder.value += allmapidxs[i]+',';
7466: }
7467: }
7468: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7469: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7470: }
7471: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7472: haschanges = 1;
7473: }
7474: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7475: haschanges = 1;
7476: }
7477: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7478: haschanges = 1;
7479: }
7480: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7481: haschanges = 1;
7482: }
7483: }
7484: if (doactions == 1) {
7485: if (numchanges > 0) {
1.484.2.63 raeburn 7486: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7487: if (remwarnings > 0) {
1.484.2.61 raeburn 7488: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7489: return false;
7490: }
7491: }
1.484.2.63 raeburn 7492: if (removalinfo > 0) {
7493: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7494: return false;
7495: }
7496: }
1.484.2.30 raeburn 7497: if (cutwarnings > 0) {
1.484.2.61 raeburn 7498: 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 7499: return false;
1.484.2.29 raeburn 7500: }
7501: }
7502: }
1.484.2.30 raeburn 7503: form.submit();
7504: return true;
7505: }
7506: }
7507: if (dosettings == 1) {
7508: if (haschanges == 1) {
7509: form.submit();
7510: return true;
1.484.2.29 raeburn 7511: }
7512: }
1.484.2.30 raeburn 7513: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7514: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7515: } else {
7516: if (dosettings == 1) {
1.484.2.61 raeburn 7517: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7518: } else {
1.484.2.61 raeburn 7519: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7520: }
7521: }
7522: return false;
7523: }
7524:
7525: function setClass(value) {
7526: var cutclass = 'LC_docs_cut';
7527: var copyclass = 'LC_docs_copy';
7528: var removeclass = 'LC_docs_remove';
7529: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7530: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7531: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7532: var links = document.getElementsByTagName('a');
7533: for (var i=0; i<links.length; i++) {
7534: var classes = links[i].className;
7535: if (cutreg.test(classes)) {
7536: links[i].className = cutclass;
7537: if (value == 1) {
7538: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7539: }
1.484.2.30 raeburn 7540: } else {
7541: if (copyreg.test(classes)) {
7542: links[i].className = copyclass;
7543: if (value == 1) {
7544: links[i].className += " LC_menubuttons_link";
7545: }
7546: } else {
7547: if (removereg.test(classes)) {
7548: links[i].className = removeclass;
7549: if (value == 1) {
7550: links[i].className += " LC_menubuttons_link";
7551: }
7552: }
1.484.2.29 raeburn 7553: }
7554: }
7555: }
1.484.2.30 raeburn 7556: return;
1.484.2.29 raeburn 7557: }
7558:
1.484.2.30 raeburn 7559: function setBoxes(value) {
7560: var remidxlist = document.cumulativeactions.allremoveidx.value;
7561: if ((remidxlist != '') && (remidxlist != null)) {
7562: var remidxs = remidxlist.split(',');
7563: for (var i=0; i<remidxs.length; i++) {
7564: if (document.getElementById('remove_'+remidxs[i])) {
7565: var item = document.getElementById('remove_'+remidxs[i]);
7566: if (value == 1) {
7567: item.className = 'LC_docs_remove';
7568: } else {
7569: item.className = 'LC_hidden';
7570: }
7571: }
1.484.2.29 raeburn 7572: }
7573: }
1.484.2.30 raeburn 7574: var cutidxlist = document.cumulativeactions.allcutidx.value;
7575: if ((cutidxlist != '') && (cutidxlist != null)) {
7576: var cutidxs = cutidxlist.split(',');
7577: for (var i=0; i<cutidxs.length; i++) {
7578: if (document.getElementById('cut_'+cutidxs[i])) {
7579: var item = document.getElementById('cut_'+cutidxs[i]);
7580: if (value == 1) {
7581: item.className = 'LC_docs_cut';
7582: } else {
7583: item.className = 'LC_hidden';
7584: }
7585: }
7586: }
7587: }
7588: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7589: if ((copyidxlist != '') && (copyidxlist != null)) {
7590: var copyidxs = copyidxlist.split(',');
7591: for (var i=0; i<copyidxs.length; i++) {
7592: if (document.getElementById('copy_'+copyidxs[i])) {
7593: var item = document.getElementById('copy_'+copyidxs[i]);
7594: if (value == 1) {
7595: item.className = 'LC_docs_copy';
7596: } else {
7597: item.className = 'LC_hidden';
7598: }
7599: }
1.484.2.29 raeburn 7600: }
7601: }
7602: return;
7603: }
7604:
1.484.2.67 raeburn 7605: ENDSCRIPT
1.329 droeschl 7606: }
1.457 raeburn 7607:
1.483 raeburn 7608: sub history_tab_js {
7609: return <<"ENDHIST";
7610: function toggleHistoryDisp(choice) {
7611: document.docslogform.docslog.value = choice;
7612: document.docslogform.submit();
7613: return;
7614: }
7615:
7616: ENDHIST
7617: }
7618:
1.484 raeburn 7619: sub inject_data_js {
7620: return <<ENDINJECT;
7621:
7622: function injectData(current, hiddenField, name, value) {
7623: currentElement = document.getElementById(hiddenField);
7624: currentElement.name = name;
7625: currentElement.value = value;
7626: current.submit();
7627: }
7628:
7629: ENDINJECT
7630: }
7631:
7632: sub dump_switchserver_js {
7633: my @hosts = @_;
1.484.2.61 raeburn 7634: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7635: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7636: swit => 'Switch server?',
1.484.2.61 raeburn 7637: );
7638: my %html_js_lt = &Apache::lonlocal::texthash(
7639: swit => 'Switch server?',
1.484.2.43 raeburn 7640: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7641: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7642: chos => 'Choose server',
7643: );
1.484.2.61 raeburn 7644: &js_escape(\%js_lt);
7645: &html_escape(\%html_js_lt);
7646: &js_escape(\%html_js_lt);
1.484 raeburn 7647: my $role = $env{'request.role'};
7648: my $js = <<"ENDSWJS";
7649: <script type="text/javascript">
7650: function write_switchserver() {
7651: var server;
7652: if (document.setserver.posshosts.length > 0) {
7653: for (var i=0; i<document.setserver.posshosts.length; i++) {
7654: if (document.setserver.posshosts[i].checked) {
7655: server = document.setserver.posshosts[i].value;
7656: }
7657: }
7658: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7659: }
7660: window.close();
7661: }
7662: </script>
7663:
7664: ENDSWJS
7665:
7666: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7667: {'only_body' => 1,
7668: 'js_ready' => 1,});
7669: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7670:
7671: my $hostpicker;
7672: my $count = 0;
7673: foreach my $host (sort(@hosts)) {
7674: my $checked;
7675: if ($count == 0) {
7676: $checked = ' checked="checked"';
7677: }
7678: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7679: $host.'"'.$checked.' />'.$host.'</label> ';
7680: $count++;
7681: }
7682:
7683: return <<"ENDSWITCHJS";
7684:
7685: function dump_needs_switchserver(url) {
7686: if (url!='' && url!= null) {
1.484.2.61 raeburn 7687: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7688: go(url);
7689: }
7690: }
7691: return;
7692: }
7693:
7694: function choose_switchserver_window() {
7695: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7696: newWindow.document.open();
7697: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7698: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7699: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7700: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7701: '<form name="setserver" method="post" action="" \\/>\\n'+
7702: '$hostpicker\\n'+
7703: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7704: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7705: 'onclick="write_switchserver();" \\/>\\n'+
7706: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7707: newWindow.document.writeln('$endpage');
7708: newWindow.document.close();
7709: newWindow.focus();
7710: }
7711:
7712: ENDSWITCHJS
7713: }
7714:
7715: sub makedocslogform {
7716: my ($formelems,$docslog) = @_;
7717: return <<"LOGSFORM";
7718: <form action="/adm/coursedocs" method="post" name="docslogform">
7719: <input type="hidden" name="docslog" value="$docslog" />
7720: $formelems
7721: </form>
7722: LOGSFORM
7723: }
7724:
7725: sub makesimpleeditform {
7726: my ($formelems) = @_;
7727: return <<"SIMPFORM";
7728: <form name="simpleedit" method="post" action="/adm/coursedocs">
7729: <input type="hidden" name="importdetail" value="" />
7730: $formelems
7731: </form>
7732: SIMPFORM
7733: }
7734:
1.329 droeschl 7735: 1;
7736: __END__
7737:
7738:
7739: =head1 NAME
7740:
7741: Apache::londocs.pm
7742:
7743: =head1 SYNOPSIS
7744:
7745: This is part of the LearningOnline Network with CAPA project
7746: described at http://www.lon-capa.org.
7747:
7748: =head1 SUBROUTINES
7749:
7750: =over
7751:
7752: =item %help=()
7753:
7754: Available help topics
7755:
7756: =item mapread()
7757:
1.344 bisitz 7758: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7759: @order and @resources, determines status
7760: sets @order - pointer to resources in right order
7761: sets @resources - array with the resources with correct idx
7762:
7763: =item authorhosts()
7764:
7765: Return hash with valid author names
7766:
7767: =item clean()
7768:
7769: =item dumpcourse()
7770:
7771: Actually dump course
7772:
7773: =item group_import()
7774:
7775: Imports the given (name, url) resources into the course
7776: coursenum, coursedom, and folder must precede the list
7777:
7778: =item breadcrumbs()
7779:
7780: =item log_docs()
7781:
7782: =item docs_change_log()
7783:
7784: =item update_paste_buffer()
7785:
7786: =item print_paste_buffer()
7787:
7788: =item do_paste_from_buffer()
7789:
1.484.2.30 raeburn 7790: =item do_buffer_empty()
7791:
7792: =item clear_from_buffer()
7793:
1.484.2.7 raeburn 7794: =item get_newmap_url()
7795:
7796: =item dbcopy()
7797:
7798: =item uniqueness_check()
7799:
7800: =item contained_map_check()
7801:
7802: =item url_paste_fixups()
7803:
7804: =item apply_fixups()
7805:
7806: =item copy_dependencies()
7807:
1.329 droeschl 7808: =item update_parameter()
7809:
7810: =item handle_edit_cmd()
7811:
7812: =item editor()
7813:
7814: =item process_file_upload()
7815:
7816: =item process_secondary_uploads()
7817:
7818: =item is_supplemental_title()
7819:
7820: =item entryline()
7821:
7822: =item tiehash()
7823:
7824: =item untiehash()
7825:
7826: =item checkonthis()
7827:
7828: check on this
7829:
7830: =item verifycontent()
7831:
7832: Verify Content
7833:
1.484.2.78 raeburn 7834: =item devalidateversioncache()
7835:
7836: =item checkversions()
1.329 droeschl 7837:
7838: Check Versions
7839:
7840: =item mark_hash_old()
7841:
7842: =item is_hash_old()
7843:
7844: =item changewarning()
7845:
7846: =item init_breadcrumbs()
7847:
7848: Breadcrumbs for special functions
7849:
1.484 raeburn 7850: =item create_list_elements()
7851:
7852: =item create_form_ul()
7853:
7854: =item startContentScreen()
7855:
7856: =item endContentScreen()
7857:
7858: =item supplemental_base()
7859:
7860: =item embedded_form_elems()
7861:
7862: =item embedded_destination()
7863:
7864: =item return_to_editor()
7865:
7866: =item decompression_info()
7867:
7868: =item decompression_phase_one()
7869:
7870: =item decompression_phase_two()
7871:
7872: =item remove_archive()
7873:
7874: =item generate_admin_menu()
7875:
7876: =item generate_edit_table()
7877:
7878: =item editing_js()
7879:
7880: =item history_tab_js()
7881:
7882: =item inject_data_js()
7883:
7884: =item dump_switchserver_js()
7885:
1.484.2.3 raeburn 7886: =item resize_scrollbox_js()
1.484 raeburn 7887:
7888: =item makedocslogform()
7889:
1.484.2.3 raeburn 7890: =item makesimpleeditform()
7891:
1.329 droeschl 7892: =back
7893:
7894: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>