Annotation of loncom/interface/londocs.pm, revision 1.484.2.93.2.15
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.93.2. 5(raebur 4:3): # $Id: londocs.pm,v 1.484.2.93.2.14 2023/09/02 21:52:40 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.484.2.19 raeburn 43: use Apache::lonextresedit();
1.484.2.43 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.484.2.93.2. (raeburn 46:): use Apache::loncourserespicker();
1.329 droeschl 47: use HTML::Entities;
1.484.2.7 raeburn 48: use HTML::TokeParser;
1.329 droeschl 49: use GDBM_File;
1.484.2.51 raeburn 50: use File::MMagic;
1.329 droeschl 51: use Apache::lonlocal;
52: use Cwd;
1.484.2.93.2. 2(raebur 53:3): use UUID::Tiny ':std';
1.329 droeschl 54: use LONCAPA qw(:DEFAULT :match);
55:
56: my $iconpath;
57:
58: my %hash;
59:
60: my $hashtied;
61: my %alreadyseen=();
62:
63: my $hadchanges;
1.484.2.37 raeburn 64: my $suppchanges;
1.329 droeschl 65:
66:
67: my %help=();
68:
69:
70: sub mapread {
71: my ($coursenum,$coursedom,$map)=@_;
72: return
73: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
74: $map);
75: }
76:
77: sub storemap {
1.484.2.7 raeburn 78: my ($coursenum,$coursedom,$map,$contentchg)=@_;
79: my $report;
80: if (($contentchg) && ($map =~ /^default/)) {
81: $report = 1;
82: }
1.329 droeschl 83: my ($outtext,$errtext)=
84: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.484.2.7 raeburn 85: $map,1,$report);
1.329 droeschl 86: if ($errtext) { return ($errtext,2); }
1.364 bisitz 87:
1.484.2.37 raeburn 88: if ($map =~ /^default/) {
89: $hadchanges=1;
1.484.2.93.2. 0(raebur 90:3): } elsif ($contentchg) {
1.484.2.37 raeburn 91: $suppchanges=1;
92: }
1.329 droeschl 93: return ($errtext,0);
94: }
95:
96:
97:
98: sub authorhosts {
99: my %outhash=();
100: my $home=0;
101: my $other=0;
102: foreach my $key (keys(%env)) {
103: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
104: my $role=$1;
105: my $realm=$2;
106: my ($start,$end)=split(/\./,$env{$key});
107: if (($start) && ($start>time)) { next; }
108: if (($end) && (time>$end)) { next; }
109: my ($ca,$cd);
110: if ($1 eq 'au') {
111: $ca=$env{'user.name'};
112: $cd=$env{'user.domain'};
113: } else {
114: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
115: }
116: my $allowed=0;
117: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
118: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 119: foreach my $id (@ids) {
120: if ($id eq $myhome) {
121: $allowed=1;
122: last;
123: }
124: }
1.329 droeschl 125: if ($allowed) {
126: $home++;
1.484 raeburn 127: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 128: } else {
1.484 raeburn 129: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 130: $other++;
131: }
132: }
133: }
134: return ($home,$other,%outhash);
135: }
136:
137:
138: sub clean {
139: my ($title)=@_;
140: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 141: return $title;
1.329 droeschl 142: }
143:
1.484.2.67 raeburn 144: sub default_folderpath {
145: my ($coursenum,$coursedom,$navmapref) = @_;
146: return unless ($coursenum && $coursedom && ref($navmapref));
147: # Check if entire course is hidden and/or encrypted
148: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
149: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
150: unless (ref($$navmapref)) {
151: $$navmapref = Apache::lonnavmaps::navmap->new();
152: }
153: if (ref($$navmapref)) {
154: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
155: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
156: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
157: unless (@resources) {
158: $hiddenmap = 1;
159: unless ($env{'request.role.adv'}) {
160: $hiddentop = 1;
161: if ($env{'form.folder'}) {
162: undef($env{'form.folder'});
163: }
164: }
165: }
166: }
167: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
168: $encryptmap = 1;
169: }
170: }
171: unless ($hiddentop) {
172: $folderpath='default&'.&escape(&mt('Main Content')).
173: '::'.$hiddenmap.':'.$encryptmap.'::';
174: }
175: if (wantarray) {
176: return ($folderpath,$hiddentop);
177: } else {
178: return $folderpath;
179: }
180: }
1.329 droeschl 181:
1.484.2.93.2. 0(raebur 182:3): sub validate_supppath {
183:3): my ($coursenum,$coursedom) = @_;
184:3): my $backto;
1.484.2.92 raeburn 185: if ($env{'form.supppath'} ne '') {
186: my @items = split(/\&/,$env{'form.supppath'});
1.484.2.93.2. 0(raebur 187:3): my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
1.484.2.92 raeburn 188: for (my $i=0; $i<@items; $i++) {
189: my $odd = $i%2;
190: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
191: $badpath = 1;
1.484.2.93.2. 0(raebur 192:3): last;
193:3): } elsif ($odd) {
194:3): my $suffix;
195:3): my $idx = $i-1;
196:3): if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
197:3): $backto .= '&'.$1;
198:3): } elsif ($items[$idx] eq 'supplemental') {
199:3): $backto .= '&'.$items[$i];
200:3): } else {
201:3): $backto .= '&'.$items[$i];
202:3): my $is_hidden;
203:3): unless ($got_supp) {
204:3): my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
205:3): if (ref($supplemental) eq 'HASH') {
206:3): if (ref($supplemental->{'hidden'}) eq 'HASH') {
207:3): %supphidden = %{$supplemental->{'hidden'}};
208:3): }
209:3): if (ref($supplemental->{'ids'}) eq 'HASH') {
210:3): %suppids = %{$supplemental->{'ids'}};
211:3): }
212:3): }
213:3): $got_supp = 1;
214:3): }
215:3): if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
216:3): my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
217:3): if ($supphidden{$mapid}) {
218:3): $is_hidden = 1;
219:3): }
220:3): }
221:3): $suffix = '::'.$is_hidden.':::';
222:3): }
223:3): $supppath .= '&'.$items[$i].$suffix;
224:3): } else {
225:3): $supppath .= '&'.$items[$i];
226:3): $backto .= '&'.$items[$i];
1.484.2.92 raeburn 227: }
228: }
229: if ($badpath) {
230: delete($env{'form.supppath'});
1.484.2.93.2. 0(raebur 231:3): } else {
232:3): $supppath =~ s/^\&//;
233:3): $backto =~ s/^\&//;
234:3): $env{'form.supppath'} = $supppath;
1.484.2.92 raeburn 235: }
236: }
1.484.2.93.2. 0(raebur 237:3): return $backto;
1.484.2.92 raeburn 238: }
239:
1.329 droeschl 240: sub dumpcourse {
241: my ($r) = @_;
1.408 raeburn 242: my $crstype = &Apache::loncommon::course_type();
1.484.2.43 raeburn 243: my ($starthash,$js);
244: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
245: $js = <<"ENDJS";
246: <script type="text/javascript">
247: // <![CDATA[
248:
249: function hide_searching() {
250: if (document.getElementById('searching')) {
251: document.getElementById('searching').style.display = 'none';
252: }
253: return;
254: }
255:
256: // ]]>
257: </script>
258: ENDJS
259: $starthash = {
260: add_entries => {'onload' => "hide_searching();"},
261: };
262: }
263: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
264: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 265: $r->print(&startContentScreen('tools'));
1.329 droeschl 266: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 267: unless ($home) {
268: $r->print(&endContentScreen());
269: return '';
270: }
1.329 droeschl 271: my $origcrsid=$env{'request.course.id'};
272: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
273: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
274: # Do the dumping
1.484 raeburn 275: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
276: $r->print(&endContentScreen());
277: return '';
278: }
1.484.2.24 raeburn 279: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 280: $r->print('<h3>'.&mt('Copying Files').'</h3>');
281: my $title=$env{'form.authorfolder'};
282: $title=&clean($title);
1.484.2.43 raeburn 283: my ($navmap,$errormsg) =
284: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
285: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
286: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
287: my (%maps,%resources,%titles);
288: if (!ref($navmap)) {
289: $r->print($errormsg.
290: &endContentScreen());
291: return '';
292: } else {
293: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
294: 'dumpdocs',$cdom,$cnum);
295: }
296: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
297: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
298: %newcontent,%has_simpleprobs);
299: foreach my $item (sort {$a <=> $b} (@todump)) {
300: my $name = $env{'form.namefor_'.$item};
301: if ($resources{$item}) {
302: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
303: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
304: $tocopy{$1} = $name;
305: $display{$item} = $1;
306: $lookup{$1} = $item;
307: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
308: $simpleproblems{$item} = {
309: symb => $resources{$item},
310: name => $name,
311: };
312: $display{$item} = 'simpleproblem_'.$name;
313: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
314: $has_simpleprobs{$1}{$id} = $item;
315: }
316: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
317: my $marker = $1;
318: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
319: $simplepages{$item} = {
320: res => $res,
321: title => $titles{$item},
322: db => $db_name,
323: marker => $marker,
324: symb => $resources{$item},
325: name => $name,
326: };
327: $display{$item} = '/'.$res;
328: }
329: } elsif ($maps{$item}) {
330: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
331: $tocopy{$1} = $name;
332: $display{$item} = $1;
333: $lookup{$1} = $item;
334: }
335: } else {
336: next;
337: }
338: }
1.329 droeschl 339: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
340: $crs=~s/\_/\//g;
1.484.2.43 raeburn 341: my $mm = new File::MMagic;
342: my $prefix = "/uploaded/$cdom/$cnum/";
343: %replacehash = %tocopy;
344: foreach my $item (sort(keys(%simpleproblems))) {
345: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
346: $newcontent{$display{$item}} = $content;
347: }
348: my $gateway = Apache::lonhtmlgateway->new('web');
349: foreach my $item (sort(keys(%simplepages))) {
350: if (ref($simplepages{$item}) eq 'HASH') {
351: my $pagetitle = $simplepages{$item}{'title'};
352: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
353: my %contents;
354: foreach my $field (keys(%fields)) {
355: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
356: my $name = $1;
357: my $msg = $fields{$field};
358: if ($name eq 'webreferences') {
359: if ($msg =~ m{^https?://}) {
360: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
361: }
362: } else {
363: $msg = &Encode::decode('utf8',$msg);
364: $msg = $gateway->process_outgoing_html($msg,1);
365: $contents{$name} = $msg;
366: }
367: } elsif ($field eq 'uploaded.photourl') {
368: my $marker = $simplepages{$item}{marker};
369: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
370: my $filepath = $1;
371: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
372: if ($fname ne '') {
373: $fname=~s/\.(\w+)$//;
374: my $ext=$1;
375: $fname = &clean($fname);
376: $fname.='.'.$ext;
377: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
378: $replacehash{$filepath} = $relpath.$fname;
379: $deps{$item}{$filepath} = 1;
380: }
381: }
382: }
383: }
384: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
385: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
386: my $content = '
387: <html>
388: <head>
389: <title>'.$pagetitle.'</title>
390: </head>
391: <body bgcolor="#ffffff">';
392: if ($contents{title}) {
393: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
394: }
395: if ($contents{image}) {
396: $content .= "\n".$contents{image};
397: }
398: if ($contents{content}) {
399: $content .= '
400: <div class="LC_Box">
1.484.2.50 raeburn 401: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.484.2.43 raeburn 402: $contents{content}.'
403: </div>';
404: }
405: if ($contents{webreferences}) {
406: $content .= '
407: <div class="LC_Box">
1.484.2.50 raeburn 408: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.484.2.43 raeburn 409: $contents{webreferences}.'
410: </div>';
411: }
412: $content .= '
413: </body>
414: </html>
415: ';
416: $newcontent{'/'.$simplepages{$item}{res}} = $content;
417: }
418: }
419: foreach my $item (keys(%tocopy)) {
420: unless ($item=~/\.(sequence|page)$/) {
421: my $currurlpath = $prefix.$item;
422: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
423: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
424: }
425: }
426: foreach my $num (sort {$a <=> $b} (@todump)) {
427: my $src = $display{$num};
428: next if ($src eq '');
429: my @needcopy = ();
430: if ($replacehash{$src}) {
431: push(@needcopy,$src);
432: if (ref($deps{$num}) eq 'HASH') {
433: foreach my $dep (sort(keys(%{$deps{$num}}))) {
434: if ($replacehash{$dep}) {
435: push(@needcopy,$dep);
436: }
437: }
438: }
439: } elsif ($src =~ /^simpleproblem_/) {
440: push(@needcopy,$src);
441: }
442: next if (@needcopy == 0);
443: my ($result,$depresult);
444: for (my $i=0; $i<@needcopy; $i++) {
445: my $item = $needcopy[$i];
446: my $newfilename;
447: if ($simpleproblems{$num}) {
448: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
449: } else {
450: $newfilename=$title.'/'.$replacehash{$item};
451: }
452: $newfilename=~s/\.(\w+)$//;
453: my $ext=$1;
454: $newfilename=&clean($newfilename);
455: $newfilename.='.'.$ext;
456: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
457: if ($newrelpath ne $replacehash{$item}) {
458: $replacehash{$item} = $newrelpath;
459: }
460: my @dirs=split(/\//,$newfilename);
461: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
462: my $makepath=$path;
463: my $fail;
464: my $origin;
465: for (my $i=0;$i<$#dirs;$i++) {
466: $makepath.='/'.$dirs[$i];
467: unless (-e $makepath) {
468: unless(mkdir($makepath,0755)) {
469: $fail = &mt('Directory creation failed.');
470: }
471: }
472: }
473: if ($i == 0) {
474: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
475: } else {
476: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
477: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
478: &mt('(dependency)').'</span>: ';
479: }
480: if (-e $path.'/'.$newfilename) {
481: $fail = &mt('Destination already exists -- not overwriting.');
482: } else {
483: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
484: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
485: ($item =~ /^simpleproblem_/)) {
486: print $fh $newcontent{$item};
487: } else {
488: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
489: if (-e $fileloc) {
490: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
491: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
492: (ref($has_simpleprobs{$item}) eq 'HASH')) {
493: my %changes = %{$has_simpleprobs{$item}};
494: my $content = &Apache::lonclonecourse::rewritefile(
495: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
496: (%replacehash,$crs => '')
497: );
498: my $updatedcontent = '';
499: my $parser = HTML::TokeParser->new(\$content);
500: $parser->attr_encoded(1);
501: while (my $token = $parser->get_token) {
502: if ($token->[0] eq 'S') {
503: if (($token->[1] eq 'resource') &&
504: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
505: ($changes{$token->[2]->{'id'}})) {
506: my $id = $token->[2]->{'id'};
507: $updatedcontent .= '<'.$token->[1];
508: foreach my $attrib (@{$token->[3]}) {
509: next unless ($attrib =~ /^(src|type|title|id)$/);
510: if ($attrib eq 'src') {
511: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
512: if ($file) {
513: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
514: } else {
515: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
516: }
517: } else {
518: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
519: }
520: }
521: $updatedcontent .= ' />'."\n";
522: } else {
523: $updatedcontent .= $token->[4]."\n";
524: }
525: } else {
526: $updatedcontent .= $token->[2];
527: }
528: }
529: print $fh $updatedcontent;
530: } else {
531: print $fh &Apache::lonclonecourse::rewritefile(
532: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
533: (%replacehash,$crs => '')
534: );
535: }
536: } else {
537: print $fh
538: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
539: }
540: } else {
541: $fail = &mt('Source does not exist.');
542: }
543: }
544: $fh->close();
545: } else {
546: $fail = &mt('Could not write to destination.');
547: }
548: }
549: my $text;
550: if ($fail) {
551: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
552: } else {
553: $text = '<span class="LC_success">'.&mt('ok').'</span>';
554: }
555: if ($i == 0) {
556: $result .= $text;
557: } else {
558: $depresult .= $text.'</li>';
559: }
560: }
561: $r->print($result);
562: if ($depresult) {
563: $r->print('<ul>'.$depresult.'</ul>');
564: }
565: }
1.329 droeschl 566: } else {
1.484.2.43 raeburn 567: my ($navmap,$errormsg) =
568: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
569: if (!ref($navmap)) {
570: $r->print($errormsg);
571: } else {
572: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
573: $r->rflush();
574: my ($preamble,$formname);
575: $formname = 'dumpdoc';
576: unless ($home==1) {
577: $preamble = '<div class="LC_left_float">'.
578: '<fieldset><legend>'.
579: &mt('Select the Authoring Space').
580: '</legend><select name="authorspace">';
581: }
582: my @orderspaces = ();
583: foreach my $key (sort(keys(%outhash))) {
584: if ($key=~/^home_(.+)$/) {
585: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
586: unshift(@orderspaces,$1);
587: } else {
588: push(@orderspaces,$1);
589: }
590: }
591: }
592: if ($home>1) {
593: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
594: }
595: foreach my $user (@orderspaces) {
596: if ($home==1) {
597: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
598: } else {
599: $preamble .= '<option value="'.$user.'">'.$user.' - '.
600: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
601: }
602: }
603: unless ($home==1) {
604: $preamble .= '</select></fieldset></div>'."\n";
605: }
606: my $title=$origcrsdata{'description'};
607: $title=~s/[\/\s]+/\_/gs;
608: $title=&clean($title);
609: $preamble .= '<div class="LC_left_float">'.
610: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
611: '<input type="text" size="50" name="authorfolder" value="'.
612: $title.'" />'.
613: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
614: my %uploadedfiles;
615: &tiehash();
616: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
617: my ($ext)=($file=~/\.(\w+)$/);
618: # FIXME Check supplemental here
619: my $title=$hash{'title_'.$hash{
620: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
621: if (!$title) {
622: $title=$file;
623: } else {
624: $title=~s|/|_|g;
625: }
626: $title=~s/\.(\w+)$//;
627: $title=&clean($title);
628: $title.='.'.$ext;
629: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
630: $uploadedfiles{$file} = $title;
631: }
632: &untiehash();
633: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
634: undef,undef,$preamble,$home,\%uploadedfiles));
635: }
1.329 droeschl 636: }
1.484 raeburn 637: $r->print(&endContentScreen());
1.329 droeschl 638: }
639:
1.484.2.43 raeburn 640: sub recurse_html {
641: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
642: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
643: my (%allfiles,%codebase);
644: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
645: if (keys(%allfiles)) {
646: foreach my $dependency (keys(%allfiles)) {
647: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
648: my ($depurl,$relfile,$newcontainer);
649: if ($dependency =~ m{^/}) {
650: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
651: $relfile = $1;
652: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
653: $newcontainer = $1;
654: next if ($replacehash->{$newcontainer});
655: }
656: $depurl = $dependency;
657: } else {
658: next;
659: }
660: } else {
661: $relfile = $dependency;
662: $depurl = $currurlpath;
663: $depurl =~ s{[^/]+$}{};
664: $depurl .= $dependency;
665: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
666: }
667: next if ($relfile eq '');
668: my $newname = $replacehash->{$container};
669: $newname =~ s{[^/]+$}{};
670: $replacehash->{$newcontainer} = $newname.$relfile;
671: $deps->{$item}{$newcontainer} = 1;
672: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
673: my $depfile = &Apache::lonnet::filelocation('',$depurl);
674: my $type = $mm->checktype_filename($depfile);
675: if ($type eq 'text/html') {
676: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
677: }
678: }
679: }
680: }
681: return;
682: }
683:
1.329 droeschl 684: sub group_import {
1.484.2.93.2. (raeburn 685:): my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.484.2.23 raeburn 686: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
687: %removeparam,$importuploaded,$fixuperrors);
688: $allmaps = {};
1.329 droeschl 689: while (@files) {
690: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 691: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 692: && ($caller eq 'londocs')
693: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 694:
1.329 droeschl 695: my $errtext = '';
696: my $fatal = 0;
697: my $newmapstr = '<map>'."\n".
698: '<resource id="1" src="" type="start"></resource>'."\n".
699: '<link from="1" to="2" index="1"></link>'."\n".
700: '<resource id="2" src="" type="finish"></resource>'."\n".
701: '</map>';
702: $env{'form.output'}=$newmapstr;
703: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
704: 'output',$1.$2);
1.484.2.27 raeburn 705: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 706: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
707: $fatal = 2;
708: }
709: if ($fatal) {
710: return ($errtext,$fatal);
711: }
712: }
713: if ($url) {
1.484.2.93.2. (raeburn 714:): if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
715:): $url = $1;
716:): my $marker = $2;
717:): my $info = $3;
2(raebur 718:3): my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
(raeburn 719:): my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
720:): my @toolinfo = split(/:/,$info);
721:): if ($residx) {
722:): %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
723:): $toolid = $toolsettings{'id'};
724:): } else {
725:): $toolid = shift(@toolinfo);
726:): }
2(raebur 727:3): if ($toolid =~ /^c/) {
728:3): $tooltype = 'crs';
729:3): $toolprefix = 'c';
730:3): } else {
731:3): $tooltype = 'dom';
732:3): }
(raeburn 733:): $toolid =~ s/\D//g;
734:): ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
2(raebur 735:3): $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
736:3): $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
(raeburn 737:): foreach my $item (@extras) {
738:): $toolhash{$item} = &unescape($toolhash{$item});
739:): }
2(raebur 740:3): if ($folder =~ /^supplemental/) {
741:3): delete($toolhash{'gradable'});
742:3): } else {
743:3): $toolhash{'gradable'} =~ s/\D+//g;
744:3): }
(raeburn 745:): if (ref($ltitoolsref) eq 'HASH') {
2(raebur 746:3): if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
747:3): if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
748:3): my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
749:3): my @deleted;
750:3): $toolhash{'id'} = $toolprefix.$toolid;
751:3): if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
752:3): ($toolhash{'target'} eq 'window')) {
753:3): if ($toolhash{'target'} eq 'window') {
754:3): foreach my $item ('width','height') {
755:3): $toolhash{$item} =~ s/^\s+//;
756:3): $toolhash{$item} =~ s/\s+$//;
757:3): if ($toolhash{$item} =~ /\D/) {
758:3): delete($toolhash{$item});
759:3): if ($residx) {
760:3): if ($toolsettings{$item}) {
761:3): push(@deleted,$item);
762:3): }
(raeburn 763:): }
764:): }
765:): }
766:): }
2(raebur 767:3): } elsif ($residx) {
768:3): $toolhash{'target'} = $toolsettings{'target'};
769:3): if ($toolhash{'target'} eq 'window') {
770:3): foreach my $item ('width','height') {
771:3): $toolhash{$item} = $toolsettings{$item};
772:3): }
773:3): }
774:3): } elsif (ref($tools{'display'}) eq 'HASH') {
775:3): $toolhash{'target'} = $tools{'display'}{'target'};
776:3): if ($toolhash{'target'} eq 'window') {
777:3): $toolhash{'width'} = $tools{'display'}{'width'};
778:3): $toolhash{'height'} = $tools{'display'}{'height'};
(raeburn 779:): }
780:): }
2(raebur 781:3): if ($toolhash{'target'} eq 'iframe') {
782:3): foreach my $item ('width','height','linktext','explanation') {
783:3): delete($toolhash{$item});
784:3): if ($residx) {
785:3): if ($toolsettings{$item}) {
786:3): push(@deleted,$item);
787:3): }
(raeburn 788:): }
789:): }
2(raebur 790:3): } elsif ($toolhash{'target'} eq 'tab') {
791:3): foreach my $item ('width','height') {
792:3): delete($toolhash{$item});
793:3): if ($residx) {
794:3): if ($toolsettings{$item}) {
795:3): push(@deleted,$item);
796:3): }
(raeburn 797:): }
798:): }
799:): }
2(raebur 800:3): if (ref($tools{'crsconf'}) eq 'HASH') {
801:3): foreach my $item ('label','title','linktext','explanation') {
802:3): my $crsitem;
803:3): if (($item eq 'label') || ($item eq 'title')) {
804:3): $crsitem = 'crs'.$item;
805:3): } else {
806:3): $crsitem = $item;
807:3): }
808:3): if ($tools{'crsconf'}{$item}) {
809:3): $toolhash{$crsitem} =~ s/^\s+//;
810:3): $toolhash{$crsitem} =~ s/\s+$//;
811:3): if ($toolhash{$crsitem} eq '') {
812:3): delete($toolhash{$crsitem});
813:3): }
814:3): } else {
(raeburn 815:): delete($toolhash{$crsitem});
816:): }
2(raebur 817:3): if (($residx) && (exists($toolsettings{$crsitem}))) {
818:3): unless (exists($toolhash{$crsitem})) {
819:3): push(@deleted,$crsitem);
820:3): }
821:3): }
(raeburn 822:): }
2(raebur 823:3): }
824:3): if ($toolhash{'passback'}) {
825:3): my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
826:3): $toolhash{'gradesecret'} = $gradesecret;
827:3): $toolhash{'gradesecretdate'} = time;
828:3): }
829:3): if ($toolhash{'roster'}) {
830:3): my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
831:3): $toolhash{'rostersecret'} = $rostersecret;
832:3): $toolhash{'rostersecretdate'} = time;
833:3): }
834:3): my $changegradable;
835:3): if (($residx) && ($folder =~ /^default/)) {
836:3): if ($toolsettings{'gradable'}) {
837:3): unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
838:3): push(@deleted,'gradable');
839:3): $changegradable = 1;
840:3): }
841:3): } elsif ($toolhash{'gradable'}) {
842:3): $changegradable = 1;
843:3): }
844:3): if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
845:3): $changegradable = 1;
846:3): if ($toolsettings{'gradable'}) {
847:3): $toolhash{'gradable'} = 1;
(raeburn 848:): }
849:): }
850:): }
2(raebur 851:3): my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
852:3): if ($putres eq 'ok') {
853:3): if (@deleted) {
854:3): &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
855:3): }
856:3): if (($changegradable) && ($folder =~ /^default/)) {
857:3): my $val;
858:3): if ($toolhash{'gradable'}) {
859:3): $val = 'yes';
860:3): } else {
861:3): $val = 'no';
862:3): }
863:3): &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
864:3): 'string_yesno');
865:3): &remember_parms($residx,'gradable','set',$val);
866:3): }
867:3): } else {
868:3): return (&mt('Failed to save update to external tool.'),1);
(raeburn 869:): }
870:): }
871:): }
872:): }
873:): }
1.484.2.23 raeburn 874: if (($caller eq 'londocs') &&
875: ($folder =~ /^default/)) {
1.484.2.27 raeburn 876: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 877: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
878: my $cid = $coursedom.'_'.$coursenum;
879: $allmaps =
880: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
881: $chome,$cid);
882: $donechk = 1;
883: }
884: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.484.2.93.2. (raeburn 885:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
886:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.484.2.23 raeburn 887: $importuploaded = 1;
888: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
889: next if ($allmaps->{$url});
890: }
891: }
1.344 bisitz 892: if (!$residx
1.329 droeschl 893: || defined($LONCAPA::map::zombies[$residx])) {
894: $residx = &LONCAPA::map::getresidx($url,$residx);
895: push(@LONCAPA::map::order, $residx);
896: }
897: my $ext = 'false';
898: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.484.2.27 raeburn 899: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
900: my $filepath = $1;
1.484.2.91 raeburn 901: my $fname;
902: if ($name eq '') {
903: $name = &mt('Web Page');
1.484.2.27 raeburn 904: $fname = 'web';
905: } else {
1.484.2.91 raeburn 906: $fname = $name;
907: $fname=&Apache::lonnet::clean_filename($fname);
908: if ($fname eq '') {
909: $fname = 'web';
910: } elsif (length($fname) > 15) {
911: $fname = substr($fname,0,14);
912: }
1.484.2.27 raeburn 913: }
1.484.2.91 raeburn 914: my $title = &Apache::loncommon::cleanup_html($name);
1.484.2.27 raeburn 915: my $initialtext = &mt('Replace with your own content.');
916: my $newhtml = <<END;
1.484.2.31 raeburn 917: <html>
1.484.2.27 raeburn 918: <head>
1.484.2.91 raeburn 919: <title>$title</title>
1.484.2.27 raeburn 920: </head>
921: <body bgcolor="#ffffff">
922: $initialtext
923: </body>
924: </html>
925: END
926: $env{'form.output'}=$newhtml;
927: my $result =
928: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
929: 'output',
930: "$filepath/$residx/$fname.html");
931: if ($result =~ m{^/uploaded/}) {
932: $url = $result;
933: if ($filepath =~ /^supplemental/) {
934: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
935: $env{'user.domain'}.'___&&&___'.$name;
936: }
937: } else {
938: return (&mt('Failed to save new web page.'),1);
939: }
940: }
1.484.2.91 raeburn 941: $name = &LONCAPA::map::qtunescape($name);
1.484.2.30 raeburn 942: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 943: $LONCAPA::map::resources[$residx] =
1.329 droeschl 944: join(':', ($name, $url, $ext, 'normal', 'res'));
945: }
946: }
1.484.2.23 raeburn 947: if ($importuploaded) {
948: my %import_errors;
949: my %updated = (
950: removefrommap => \%removefrommap,
951: removeparam => \%removeparam,
952: );
1.484.2.26 raeburn 953: my ($result,$msgsarray,$lockerror) =
954: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 955: if (keys(%import_errors) > 0) {
956: $fixuperrors =
957: '<p span class="LC_warning">'."\n".
958: &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".
959: '<ul>'."\n";
960: foreach my $key (sort(keys(%import_errors))) {
961: $fixuperrors .= '<li>'.$key.'</li>'."\n";
962: }
963: $fixuperrors .= '</ul></p>'."\n";
964: }
1.484.2.26 raeburn 965: if (ref($msgsarray) eq 'ARRAY') {
966: if (@{$msgsarray} > 0) {
967: $fixuperrors .= '<p class="LC_info">'.
968: join('<br />',@{$msgsarray}).
969: '</p>';
970: }
971: }
972: if ($lockerror) {
973: $fixuperrors .= '<p class="LC_error">'.
974: $lockerror.
975: '</p>';
976: }
1.484.2.23 raeburn 977: }
978: my ($errtext,$fatal) =
979: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 980: unless ($fatal) {
981: if ($folder =~ /^supplemental/) {
1.484.2.39 raeburn 982: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
983: $folder.'.'.$container);
1.484.2.37 raeburn 984: }
985: }
1.484.2.23 raeburn 986: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 987: }
988:
989: sub log_docs {
1.484.2.8 raeburn 990: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 991: }
992:
993: {
994: my @oldresources=();
995: my @oldorder=();
996: my $parmidx;
997: my %parmaction=();
998: my %parmvalue=();
999: my $changedflag;
1000:
1001: sub snapshotbefore {
1002: @oldresources=@LONCAPA::map::resources;
1003: @oldorder=@LONCAPA::map::order;
1004: $parmidx=undef;
1005: %parmaction=();
1006: %parmvalue=();
1007: $changedflag=0;
1008: }
1009:
1010: sub remember_parms {
1011: my ($idx,$parameter,$action,$value)=@_;
1012: $parmidx=$idx;
1013: $parmaction{$parameter}=$action;
1014: $parmvalue{$parameter}=$value;
1015: $changedflag=1;
1016: }
1017:
1018: sub log_differences {
1019: my ($plain)=@_;
1020: my %storehash=('folder' => $plain,
1021: 'currentfolder' => $env{'form.folder'});
1022: if ($parmidx) {
1023: $storehash{'parameter_res'}=$oldresources[$parmidx];
1024: foreach my $parm (keys(%parmaction)) {
1025: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1026: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1027: }
1028: }
1029: my $maxidx=$#oldresources;
1030: if ($#LONCAPA::map::resources>$#oldresources) {
1031: $maxidx=$#LONCAPA::map::resources;
1032: }
1033: for (my $idx=0; $idx<=$maxidx; $idx++) {
1034: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1035: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1036: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1037: $changedflag=1;
1038: }
1039: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1040: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1041: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1042: $changedflag=1;
1043: }
1044: }
1045: $storehash{'maxidx'}=$maxidx;
1046: if ($changedflag) { &log_docs(\%storehash); }
1047: }
1048: }
1049:
1050: sub docs_change_log {
1.484.2.67 raeburn 1051: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 1052: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 1053: my $navmap;
1.483 raeburn 1054: my $js = '<script type="text/javascript">'."\n".
1055: '// <![CDATA['."\n".
1056: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 1057: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.93.2. 2(raebur 1058:3): $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 1059: &history_tab_js()."\n".
1.484 raeburn 1060: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 1061: '// ]]>'."\n".
1062: '</script>'."\n";
1.484 raeburn 1063: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1064: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 1065: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1066: my %orderhash;
1067: my $container='sequence';
1068: my $pathitem;
1.484.2.19 raeburn 1069: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1070: $container='page';
1071: }
1.484.2.19 raeburn 1072: my $folderpath=$env{'form.folderpath'};
1073: if ($folderpath eq '') {
1.484.2.67 raeburn 1074: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 1075: }
1.484.2.67 raeburn 1076: undef($navmap);
1.484.2.19 raeburn 1077: $pathitem = '<input type="hidden" name="folderpath" value="'.
1078: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1079: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1080: my $jumpto = $readfile;
1081: $jumpto =~ s{^/}{};
1082: my $tid = 1;
1.484.2.7 raeburn 1083: if ($supplementalflag) {
1084: $tid = 2;
1085: }
1.484.2.19 raeburn 1086: my ($breadcrumbtrail) =
1.484.2.18 raeburn 1087: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1088: $r->print($breadcrumbtrail.
1089: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1090: $readfile));
1.329 droeschl 1091: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1092: $env{'course.'.$env{'request.course.id'}.'.domain'},
1093: $env{'course.'.$env{'request.course.id'}.'.num'});
1094:
1095: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1096:
1097: my %saveable_parameters = ('show' => 'scalar',);
1098: &Apache::loncommon::store_course_settings('docs_log',
1099: \%saveable_parameters);
1100: &Apache::loncommon::restore_course_settings('docs_log',
1101: \%saveable_parameters);
1102: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1103: # FIXME: internationalization seems wrong here
1.329 droeschl 1104: my %lt=('hiddenresource' => 'Resources hidden',
1105: 'encrypturl' => 'URL hidden',
1106: 'randompick' => 'Randomly pick',
1107: 'randomorder' => 'Randomly ordered',
1.484.2.93.2. 2(raebur 1108:3): 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1109: 'set' => 'set to',
1110: 'del' => 'deleted');
1.484 raeburn 1111: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1112: $pathitem."\n".
1113: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1114: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1115: $r->print('<div class="LC_left_float">'.
1116: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1117: &makedocslogform($filter,1).
1118: '</fieldset></div><br clear="all" />');
1.329 droeschl 1119: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1120: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1121: &mt('After').'</th>'.
1122: &Apache::loncommon::end_data_table_header_row());
1123: my $shown=0;
1124: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1125: if ($env{'form.displayfilter'} eq 'currentfolder') {
1126: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1127: }
1128: my @changes=keys(%{$docslog{$id}{'logentry'}});
1129: if ($env{'form.displayfilter'} eq 'containing') {
1130: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1131: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1132: foreach my $key (@changes) {
1133: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1134: }
1.344 bisitz 1135: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1136: }
1137: my $count = 0;
1138: my $time =
1139: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1140: my $plainname =
1141: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1142: $docslog{$id}{'exe_udom'});
1143: my $about_me_link =
1144: &Apache::loncommon::aboutmewrapper($plainname,
1145: $docslog{$id}{'exe_uname'},
1146: $docslog{$id}{'exe_udom'});
1147: my $send_msg_link='';
1148: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1149: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1150: $send_msg_link ='<br />'.
1151: &Apache::loncommon::messagewrapper(&mt('Send message'),
1152: $docslog{$id}{'exe_uname'},
1153: $docslog{$id}{'exe_udom'});
1154: }
1155: $r->print(&Apache::loncommon::start_data_table_row());
1156: $r->print('<td>'.$time.'</td>
1157: <td>'.$about_me_link.
1158: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1159: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1160: $send_msg_link.'</td><td>'.
1161: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 1162: my $is_supp = 0;
1.484.2.7 raeburn 1163: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1164: $is_supp = 1;
1165: }
1.329 droeschl 1166: # Before
1167: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1168: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1169: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1170: if ($oldname ne $newname) {
1.484.2.7 raeburn 1171: my $shown = &LONCAPA::map::qtescape($oldname);
1172: if ($is_supp) {
1173: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1174: }
1175: $r->print($shown);
1.329 droeschl 1176: }
1177: }
1178: $r->print('<ul>');
1179: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1180: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 1181: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1182: if ($is_supp) {
1183: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1184: }
1.484.2.19 raeburn 1185: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1186: }
1187: }
1188: $r->print('</ul>');
1189: # After
1190: $r->print('</td><td>');
1191:
1192: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1193: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1194: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1195: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 1196: my $shown = &LONCAPA::map::qtescape($newname);
1197: if ($is_supp) {
1198: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1199: }
1200: $r->print($shown);
1.329 droeschl 1201: }
1.364 bisitz 1202: }
1.329 droeschl 1203: $r->print('<ul>');
1204: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1205: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 1206: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1207: if ($is_supp) {
1208: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1209: }
1210: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1211: }
1212: }
1213: $r->print('</ul>');
1214: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.484.2.93.2. (raeburn 1215:): my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1216:): if ($title eq '') {
1217:): ($title) = ($url =~ m{/([^/]+)$});
1(raebur 1218:3): } elsif ($is_supp) {
1219:3): $title = &Apache::loncommon::parse_supplemental_title($title);
(raeburn 1220:): }
1221:): $r->print(&LONCAPA::map::qtescape($title).':<ul>');
2(raebur 1222:3): foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1223: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1224: # FIXME: internationalization seems wrong here
1.329 droeschl 1225: $r->print('<li>'.
1226: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1227: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1228: .'</li>');
1229: }
1230: }
1231: $r->print('</ul>');
1232: }
1233: # End
1234: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1235: $shown++;
1236: if (!($env{'form.show'} eq &mt('all')
1237: || $shown<=$env{'form.show'})) { last; }
1238: }
1.484 raeburn 1239: $r->print(&Apache::loncommon::end_data_table()."\n".
1240: &makesimpleeditform($pathitem)."\n".
1241: '</div></div>');
1242: $r->print(&endContentScreen());
1.329 droeschl 1243: }
1244:
1245: sub update_paste_buffer {
1.484.2.7 raeburn 1246: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1247: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1248: if ($env{'form.multiremove'}) {
1249: $env{'form.multiremove'} =~ s/,$//;
1250: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1251: }
1252: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1253: if ($env{'form.multicut'}) {
1254: $env{'form.multicut'} =~ s/,$//;
1255: foreach my $item (split(/,/,$env{'form.multicut'})) {
1256: unless ($removals{$item}) {
1257: $cuts{$item} = 1;
1258: push(@possibles,$item.':cut');
1259: }
1260: }
1261: }
1262: if ($env{'form.multicopy'}) {
1263: $env{'form.multicopy'} =~ s/,$//;
1264: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1265: unless ($removals{$item} || $cuts{$item}) {
1266: push(@possibles,$item.':copy');
1267: }
1268: }
1269: }
1270: } elsif ($env{'form.markcopy'}) {
1271: @possibles = split(/,/,$env{'form.markcopy'});
1272: }
1.329 droeschl 1273:
1.484.2.30 raeburn 1274: return if (@possibles == 0);
1.329 droeschl 1275: return if (!defined($env{'form.copyfolder'}));
1276:
1277: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1278: $env{'form.copyfolder'});
1279: return if ($fatal);
1280:
1.484.2.30 raeburn 1281: my %curr_groups = &Apache::longroup::coursegroups();
1282:
1283: # Retrieve current paste buffer suffixes.
1284: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1285: my (%pasteurls,@newpaste);
1286:
1287: # Construct identifiers for current contents of user's paste buffer
1288: if (@currpaste) {
1289: foreach my $suffix (@currpaste) {
1.484.2.87 raeburn 1290: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1291: my $url = $env{'docs.markedcopy_url_'.$suffix};
1292: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1293: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1294: ($url ne '')) {
1295: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1296: $pasteurls{$cid.'_'.$mapidx} = 1;
1297: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1298: $pasteurls{$url} = 1;
1299: } else {
1300: $pasteurls{$cid.'_'.$url} = 1;
1301: }
1302: }
1.484.2.30 raeburn 1303: }
1304: }
1305:
1306: # Mark items for copying (skip any items already in user's paste buffer)
1307: my %addtoenv;
1.484.2.82 raeburn 1308:
1309: my @pathitems = split(/\&/,$env{'form.folderpath'});
1310: my @folderconf = split(/\:/,$pathitems[-1]);
1.484.2.87 raeburn 1311: my $ispage = $folderconf[5];
1.484.2.82 raeburn 1312:
1.484.2.30 raeburn 1313: foreach my $item (@possibles) {
1314: my ($orderidx,$cmd) = split(/:/,$item);
1315: next if ($orderidx =~ /\D/);
1316: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1317: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1318: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1319: my %denied = &action_restrictions($coursenum,$coursedom,
1320: &LONCAPA::map::qtescape($url),
1321: $env{'form.folderpath'},\%curr_groups);
1322: next if ($denied{'copy'});
1323: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 1324: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1325: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1326: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1327: next if (exists($pasteurls{$url}));
1328: } else {
1329: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1330: }
1.484.2.30 raeburn 1331: my ($suffix,$errortxt,$locknotfreed) =
1332: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1333: if ($suffix ne '') {
1334: push(@newpaste,$suffix);
1335: } else {
1336: if ($locknotfreed) {
1337: return $locknotfreed;
1338: }
1.484.2.30 raeburn 1339: }
1340: if (&is_supplemental_title($title)) {
1341: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1342: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1343: }
1344:
1345: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1346: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1347: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1348: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1349: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1350: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1351: my $prefix = $1;
1352: my $subdir =$2;
1353: if ($subdir eq '') {
1354: $subdir = $prefix;
1.484.2.7 raeburn 1355: }
1.484.2.30 raeburn 1356: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.484.2.93.2. (raeburn 1357:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1358:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.484.2.30 raeburn 1359: if (ref($hierarchy{$url}) eq 'HASH') {
1360: my ($nested,$nestednames);
1361: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1362: $nested =~ s/\&$//;
1363: $nestednames =~ s/\Q___&&&___\E$//;
1364: if ($nested ne '') {
1365: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1366: }
1367: if ($nestednames ne '') {
1368: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1369: }
1.484.2.7 raeburn 1370: }
1371: }
1.484.2.57 raeburn 1372: if ($locknotfreed) {
1373: $output = $locknotfreed;
1374: last;
1375: }
1.484.2.7 raeburn 1376: }
1.484.2.30 raeburn 1377: if (@newpaste) {
1378: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1379: }
1.484.2.7 raeburn 1380: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1381: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1382: return $output;
1.329 droeschl 1383: }
1384:
1.484.2.7 raeburn 1385: sub recurse_uploaded_maps {
1386: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1387: if (ref($hierarchy->{$url}) eq 'HASH') {
1388: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1389: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1390: my (@uploaded,@names,%shorter);
1391: for (my $i=0; $i<@maps; $i++) {
1392: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1393: if ($inner ne '') {
1394: push(@uploaded,$inner);
1395: push(@names,&escape($titles[$i]));
1396: $shorter{$maps[$i]} = $inner;
1397: }
1398: }
1399: $$nestref .= "$dir:".join(',',@uploaded).'&';
1400: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1401: foreach my $map (@maps) {
1402: if ($shorter{$map} ne '') {
1403: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1404: }
1405: }
1406: }
1407: return;
1408: }
1409:
1.329 droeschl 1410: sub print_paste_buffer {
1.484.2.7 raeburn 1411: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1412: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1413:
1.484.2.30 raeburn 1414: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1415: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1416: }
1417:
1.484.2.30 raeburn 1418: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1.484.2.93.2. 5(raebur 1419:3): my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
1.484.2.47 raeburn 1420: my $clipboardcount = 0;
1.484.2.7 raeburn 1421:
1.484.2.30 raeburn 1422: # Construct identifiers for current contents of user's paste buffer
1423: foreach my $suffix (@currpaste) {
1424: next if ($suffix =~ /\D/);
1425: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1426: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1427: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1428: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1429: ($url ne '')) {
1.484.2.47 raeburn 1430: $clipboardcount ++;
1.484.2.30 raeburn 1431: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.484.2.93.2. 5(raebur 1432:3): $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
1433:3): $toolcnum,$marker);
1.484.2.30 raeburn 1434: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1435: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1436: $is_external = 1;
1.484.2.93.2. 5(raebur 1437:3): } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
1438:3): ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
(raeburn 1439:): $is_exttool = 1;
1.484.2.7 raeburn 1440: }
1.484.2.30 raeburn 1441: if ($folder =~ /^supplemental/) {
1442: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1443: unless ($canpaste) {
1444: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1445: }
1.484.2.30 raeburn 1446: } else {
1447: $canpaste = 1;
1.484.2.7 raeburn 1448: }
1.484.2.30 raeburn 1449: if ($canpaste) {
1450: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1451: my $srcdom = $1;
1452: my $srcnum = $2;
1453: my $rem = $3;
1454: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1455: $othercourse = 1;
1456: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1457: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1458: } else {
1459: $canpaste = 0;
1460: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1461: }
1462: }
1.484.2.30 raeburn 1463: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1464: my $prefix = $1;
1465: $parent = $2;
1466: if ($folder !~ /^\Q$prefix\E/) {
1467: $areachange = 1;
1468: }
1469: $is_uploaded_map = 1;
1470: }
1.484.2.82 raeburn 1471: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.484.2.93.2. (raeburn 1472:): ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.484.2.76 raeburn 1473: if ($cid ne $env{'request.course.id'}) {
1474: my ($srcdom,$srcnum) = split(/_/,$cid);
1475: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.93.2. 5(raebur 1476:3): if ($is_exttool) {
1477:3): if ($toolcdom ne $coursedom) {
1478:3): $canpaste = 0;
1479:3): $nopaste = &mt('Paste from another domain unavailable.');
1480:3): } elsif ($toolcnum ne $coursenum) {
1481:3): my %toolsettings =
1482:3): &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
1483:3): my %tooltypes = &Apache::loncommon::usable_exttools();
1484:3): if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
1485:3): (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
1486:3): $canpaste = 0;
1487:3): $nopaste = &mt('Paste from another course unavailable.');
1488:3): } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
1489:3): unless ($checkedsameinst) {
1490:3): my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
1491:3): my $intdom = &Apache::lonnet::internet_dom($primary_id);
1492:3): if ($intdom ne '') {
1493:3): my $internet_names =
1494:3): &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
1495:3): if (ref($internet_names) eq 'ARRAY') {
1496:3): if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
1497:3): $same_institution = 1;
1498:3): }
1499:3): }
1500:3): }
1501:3): $checkedsameinst = 1;
1502:3): }
1503:3): if ($same_institution) {
1504:3): $othercrs = '<br />'.&mt('(from another course)');
1505:3): } else {
1506:3): $nopaste = &mt('Paste from another course unavailable.');
1507:3): }
1508:3): } else {
1509:3): $othercrs = '<br />'.&mt('(from another course)');
1510:3): }
1511:3): }
(raeburn 1512:): }
1.484.2.76 raeburn 1513: } else {
1514: $canpaste = 0;
1515: $nopaste = &mt('Paste from another course unavailable.');
1516: }
1517: }
1518: }
1519: if ($canpaste) {
1520: push(@pasteable,$suffix);
1.484.2.30 raeburn 1521: }
1522: }
1523: my $buffer;
1524: if ($is_external) {
1525: $buffer = &mt('External Resource').': '.
1526: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1527: &LONCAPA::map::qtescape($url).')';
1.484.2.93.2. (raeburn 1528:): } elsif ($is_exttool) {
1529:): $buffer = &mt('External Tool').': '.
1530:): &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.30 raeburn 1531: } else {
1532: my $icon = &Apache::loncommon::icon($extension);
1533: if ($extension eq 'sequence' &&
1534: $url =~ m{/default_\d+\.sequence$}x) {
1535: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1536: $icon .= '/navmap.folder.closed.gif';
1537: }
1.484.2.57 raeburn 1538: my $title = $env{'docs.markedcopy_title_'.$suffix};
1539: if ($title eq '') {
1540: ($title) = ($url =~ m{/([^/]+)$});
1541: }
1.484.2.30 raeburn 1542: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1543: ': '.
1544: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1545: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1546: }
1547: $pasteitems .= '<div class="LC_left_float">';
1548: my ($options,$onclick);
1549: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1550: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1551: if (($is_uploaded_map) ||
1552: ($url =~ /(bulletinboard|smppg)$/) ||
1553: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1554: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1555: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1556: }
1557: }
1558: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1559: if ($nopaste) {
1.484.2.93.2. (raeburn 1560:): $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.484.2.30 raeburn 1561: } else {
1562: if ($othercrs) {
1563: $pasteitems .= $othercrs;
1564: }
1565: if ($options) {
1566: $pasteitems .= $options;
1.484.2.7 raeburn 1567: }
1568: }
1.484.2.30 raeburn 1569: $pasteitems .= '</div>';
1570: }
1571: }
1572: if ($pasteitems eq '') {
1573: &Apache::lonnet::delenv('docs.markedcopies');
1574: }
1575: my ($pasteform,$form_start,$buttons,$form_end);
1576: if ($pasteitems) {
1577: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1578: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1579: if (@pasteable) {
1.484.2.47 raeburn 1580: my $value = &mt('Paste to current folder');
1581: if ($container eq 'page') {
1582: $value = &mt('Paste to current page');
1583: }
1584: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1585: }
1.484.2.93.2. (raeburn 1586:): $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1.484.2.47 raeburn 1587: if ($clipboardcount > 1) {
1588: $buttons .=
1589: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1590: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1591: (' 'x2).
1592: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1593: (' 'x2);
1.484.2.7 raeburn 1594: }
1.484.2.48 raeburn 1595: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1596: '</form>';
1.484.2.30 raeburn 1597: } else {
1598: $pasteitems = &mt('Clipboard is empty');
1599: }
1600: $r->print($form_start
1601: .'<fieldset>'
1602: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1603: .$pasteitems
1604: .'</fieldset>'
1605: .$form_end);
1606: }
1607:
1608: sub paste_options {
1609: my ($suffix,$is_uploaded_map,$parent) = @_;
1610: my ($copytext,$movetext);
1611: if ($is_uploaded_map) {
1612: $copytext = &mt('Copy to new folder');
1613: $movetext = &mt('Move old');
1614: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1615: $copytext = &mt('Copy to new board');
1616: $movetext = &mt('Move (not posts)');
1617: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1618: $copytext = &mt('Copy to new page');
1619: $movetext = &mt('Move');
1.484.2.7 raeburn 1620: } else {
1.484.2.30 raeburn 1621: $copytext = &mt('Copy to new file');
1622: $movetext = &mt('Move');
1623: }
1624: my $output = '<br />'.
1625: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1626: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1627: '<label>'.
1628: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1629: $copytext.'</label></span>'.(' 'x2).' '.
1630: '<span class="LC_nobreak"><label>'.
1631: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1632: $movetext.'</label></span>';
1633: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1634: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1635: '</legend><table border="0">';
1636: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1637: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1638: my $lastdir = $parent;
1639: my %depths = (
1640: $lastdir => 0,
1641: );
1642: my (%display,%deps);
1643: for (my $i=0; $i<@pastemaps; $i++) {
1644: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1645: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1646: my @subfolders = split(/,/,$subfolderstr);
1647: $deps{$lastdir} = \@subfolders;
1648: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1649: my $depth = $depths{$lastdir} + 1;
1650: my $offset = int($depth * 4);
1651: my $indent = (' ' x $offset);
1652: for (my $j=0; $j<@subfolders; $j++) {
1653: $depths{$subfolders[$j]} = $depth;
1654: $display{$subfolders[$j]} =
1655: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1656: '<td><label>'.
1657: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1658: '<label>'.
1659: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1660: &mt('Move old').'</label>'.
1661: '</td></tr>';
1662: }
1663: }
1664: &recurse_print(\$output,$parent,\%deps,\%display);
1665: $output .= '</table></fieldset>';
1.329 droeschl 1666: }
1.484.2.30 raeburn 1667: $output .= '</div>';
1668: return $output;
1.329 droeschl 1669: }
1670:
1.484.2.7 raeburn 1671: sub recurse_print {
1.484.2.30 raeburn 1672: my ($outputref,$dir,$deps,$display) = @_;
1673: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1674: if (ref($deps->{$dir}) eq 'ARRAY') {
1675: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1676: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1677: }
1678: }
1679: }
1680:
1681: sub supp_pasteable {
1682: my ($url) = @_;
1683: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1684: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1685: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1686: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.484.2.93.2. (raeburn 1687:): ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1688:): ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.484.2.7 raeburn 1689: return 1;
1690: }
1691: return;
1692: }
1693:
1694: sub paste_popup_js {
1.484.2.61 raeburn 1695: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1696: show => 'Show Options',
1697: hide => 'Hide Options',
1.484.2.61 raeburn 1698: );
1699: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1700: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1701: );
1.484.2.61 raeburn 1702: &html_escape(\%html_js_lt);
1703: &js_escape(\%html_js_lt);
1704: &js_escape(\%js_lt);
1.484.2.7 raeburn 1705: return <<"END";
1706:
1.484.2.30 raeburn 1707: function showPasteOptions(suffix) {
1708: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1709: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1710: return;
1711: }
1712:
1.484.2.30 raeburn 1713: function hidePasteOptions(suffix) {
1714: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1715: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1716: return;
1717: }
1718:
1.484.2.30 raeburn 1719: function showOptions(caller,suffix) {
1720: if (document.getElementById('pasteoptionstext_'+suffix)) {
1721: if (caller.checked) {
1.484.2.61 raeburn 1722: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1723: } else {
1724: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1725: }
1726: if (document.getElementById('pasteoptions_'+suffix)) {
1727: document.getElementById('pasteoptions_'+suffix).style.display='none';
1728: }
1729: }
1730: return;
1731: }
1.484.2.7 raeburn 1732:
1.484.2.30 raeburn 1733: function validateClipboard() {
1734: var numchk = 0;
1735: if (document.pasteform.pasting.length > 1) {
1736: for (var i=0; i<document.pasteform.pasting.length; i++) {
1737: if (document.pasteform.pasting[i].checked) {
1738: numchk ++;
1739: }
1740: }
1741: } else {
1742: if (document.pasteform.pasting.type == 'checkbox') {
1743: if (document.pasteform.pasting.checked) {
1744: numchk ++;
1745: }
1746: }
1747: }
1748: if (numchk > 0) {
1749: return true;
1750: } else {
1.484.2.61 raeburn 1751: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1752: return false;
1753: }
1.484.2.7 raeburn 1754: }
1755:
1.484.2.47 raeburn 1756: function checkClipboard() {
1757: if (document.pasteform.pasting.length > 1) {
1758: for (var i=0; i<document.pasteform.pasting.length; i++) {
1759: document.pasteform.pasting[i].checked = true;
1760: }
1761: }
1762: return;
1763: }
1764:
1765: function uncheckClipboard() {
1766: if (document.pasteform.pasting.length >1) {
1767: for (var i=0; i<document.pasteform.pasting.length; i++) {
1768: document.pasteform.pasting[i].checked = false;
1769: }
1770: }
1771: return;
1772: }
1773:
1.484.2.30 raeburn 1774: END
1775:
1776: }
1.484.2.7 raeburn 1777:
1.329 droeschl 1778: sub do_paste_from_buffer {
1.484.2.7 raeburn 1779: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1780:
1.484.2.30 raeburn 1781: # Array of items in paste buffer
1782: my (@currpaste,%pastebuffer,%allerrors);
1783: @currpaste = split(/,/,$env{'docs.markedcopies'});
1784:
1.484.2.7 raeburn 1785: # Early out if paste buffer is empty
1.484.2.30 raeburn 1786: if (@currpaste == 0) {
1.484.2.7 raeburn 1787: return ();
1.484.2.30 raeburn 1788: }
1789: map { $pastebuffer{$_} = 1; } @currpaste;
1790:
1791: # Array of items selected items to paste
1792: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1793:
1794: # Early out if nothing selected to paste
1795: if (@reqpaste == 0) {
1796: return();
1797: }
1798: my @topaste;
1799: foreach my $suffix (@reqpaste) {
1800: next if ($suffix =~ /\D/);
1801: next unless (exists($pastebuffer{$suffix}));
1802: push(@topaste,$suffix);
1.484.2.7 raeburn 1803: }
1804:
1.484.2.30 raeburn 1805: # Early out if nothing available to paste
1806: if (@topaste == 0) {
1807: return();
1.329 droeschl 1808: }
1809:
1.484.2.93.2. 5(raebur 1810:3): my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
1811:3): %othcrstool,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
1812:3): %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
1813:3): %currltititles,$currltimax,$gotcrsltitools);
1814:3): $currltimax = 0;
1815:3): $gotcrsltitools = 0;
1.484.2.30 raeburn 1816: foreach my $suffix (@topaste) {
1817: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1818: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1819: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1820: # Supplemental content may only include certain types of content
1821: # Early out if pasted content is not supported in Supplemental area
1822: if ($folder =~ /^supplemental/) {
1823: unless (&supp_pasteable($url)) {
1824: $notinsupp{$suffix} = 1;
1825: next;
1826: }
1827: }
1828: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1829: my $srcd = $1;
1830: my $srcn = $2;
1.484.2.7 raeburn 1831: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1832: # check for mdc privilege in the course from which the resource was pasted
1833: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1834: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1835: $notincrs{$suffix} = 1;
1836: next;
1837: }
1.329 droeschl 1838: }
1.484.2.30 raeburn 1839: $srcdom{$suffix} = $srcd;
1840: $srcnum{$suffix} = $srcn;
1.484.2.93.2. 2(raebur 1841:3): } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1842:3): ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1843:3): ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
(raeburn 1844:): my ($srcd,$srcn) = split(/_/,$cid);
1845:): # When paste buffer was populated using an active role in a different course
1846:): # check for mdc privilege in the course from which the resource was pasted
1847:): if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1848:): unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1849:): $notincrs{$suffix} = 1;
1850:): next;
1851:): }
1852:): }
1853:): # When buffer was populated using an active role in a different course
5(raebur 1854:3): # disallow pasting of External Tool if course is in a different domain,
1855:3): # or if External Tool use is not permitted in this course.
1856:3): if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
1857:3): my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1858:3): if ($toolcdom ne $coursedom) {
1859:3): $notindom{$suffix} = 1;
1860:3): next;
1861:3): } elsif ($toolcnum ne $coursenum) {
1862:3): my %toolsettings =
1863:3): &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
1864:3): my %tooltypes = &Apache::loncommon::usable_exttools();
1865:3): if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
1866:3): (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
1867:3): $othcrstool{$suffix} = 1;
1868:3): next;
1869:3): }
1870:3): if ($toolsettings{'id'} =~ /^c\d+$/) {
1871:3): unless ($gotcrsltitools) {
1872:3): %currcrsltitools =
1873:3): &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
1874:3): foreach my $item (sort(keys(%currcrsltitools))) {
1875:3): if (ref($currcrsltitools{$item}) eq 'HASH') {
1876:3): $currltimax ++;
1877:3): if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
1878:3): push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
1879:3): } else {
1880:3): $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
1881:3): }
1882:3): }
1883:3): }
1884:3): $gotcrsltitools = 1;
1885:3): }
1886:3): }
1887:3): }
(raeburn 1888:): }
1889:): $srcdom{$suffix} = $srcd;
1890:): $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1891: }
1.484.2.82 raeburn 1892: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1893: push(@dopaste,$suffix);
1894: if ($url=~/\.(page|sequence)$/) {
1895: $is_map{$suffix} = 1;
1.329 droeschl 1896: }
1.484.2.30 raeburn 1897: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1898: my $oldprefix = $1;
1.484.2.19 raeburn 1899: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1900: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1901: # a folder/page or a document).
1.484.2.30 raeburn 1902: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1903: $prefixchg{$suffix} = 'docstosupp';
1904: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1905: $prefixchg{$suffix} = 'supptodocs';
1906: }
1.484.2.7 raeburn 1907:
1908: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1909: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1910: my @nested;
1911: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1912: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1913: my @deps = map { /\d+:([\d,]+$)/ } @items;
1914: foreach my $dep (@deps) {
1915: if ($dep =~ /,/) {
1916: push(@nested,split(/,/,$dep));
1917: } else {
1918: push(@nested,$dep);
1919: }
1.484.2.7 raeburn 1920: }
1.484.2.30 raeburn 1921: foreach my $item (@nested) {
1922: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1923: push(@{$marktomove{$suffix}},$type.'_'.$item);
1924: }
1.484.2.7 raeburn 1925: }
1926: }
1.329 droeschl 1927: }
1.484.2.7 raeburn 1928: }
1929:
1.484.2.30 raeburn 1930: # Early out if nothing available to paste
1931: if (@dopaste == 0) {
1932: return ();
1933: }
1934:
1935: # Populate message hash and hashes used for main content <=> supplemental content
1936: # changes
1937:
1938: %msgs = &Apache::lonlocal::texthash (
1939: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1940: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.484.2.93.2. 2(raebur 1941:3): notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
5(raebur 1942:3): othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.484.2.30 raeburn 1943: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1944: );
1945:
1946: %before = (
1947: docstosupp => {
1948: map => 'default',
1949: doc => 'docs',
1950: },
1951: supptodocs => {
1952: map => 'supplemental',
1953: doc => 'supplemental',
1954: },
1955: );
1956:
1957: %after = (
1958: docstosupp => {
1959: map => 'supplemental',
1960: doc => 'supplemental'
1961: },
1962: supptodocs => {
1963: map => 'default',
1964: doc => 'docs',
1965: },
1966: );
1967:
1968: # Retrieve information about all course maps in main content area
1969:
1970: my $allmaps = {};
1.484.2.93.2. 5(raebur 1971:3): my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
1972:3): @updatetoolsenc,$updatetoolscache,$checkedsameinst,
1973:3): $same_institution);
1.484.2.30 raeburn 1974:
1975: # Loop over the items to paste
1976: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1977: # Maps need to be copied first
1.484.2.30 raeburn 1978: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1979: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1980: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1981: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1982: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1983: }
1984: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1985: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1986: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1987: my $oldurl = $url;
1988: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1989: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1990: my (%hierarchy,%titles);
1.484.2.79 raeburn 1991: if (($folder =~ /^default/) && (!$donechk)) {
1992: $allmaps =
1993: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1994: $env{"course.$env{'request.course.id'}.home"},
1995: $env{'request.course.id'});
1996: $donechk = 1;
1997: }
1.484.2.93.2. (raeburn 1998:): &contained_map_check($url,$folder,$coursenum,$coursedom,
1999:): \%removefrommap,\%removeparam,\%addedmaps,
2000:): \%hierarchy,\%titles,$allmaps);
1.484.2.30 raeburn 2001: if ($url=~ m{^/uploaded/}) {
2002: my $newurl;
2003: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2004: ($newurl,my $error) =
2005: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
2006: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2007: \$title,$allmaps,\%newurls);
2008: if ($error) {
2009: $allerrors{$suffix} = $error;
2010: next;
2011: }
2012: if ($newurl ne '') {
2013: if ($newurl ne $url) {
2014: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
2015: $newsubdir{$url} = $1;
2016: }
2017: $mapchanges{$url} = 1;
1.484.2.7 raeburn 2018: }
2019: }
2020: }
1.484.2.30 raeburn 2021: if (($srcdom{$suffix} ne $coursedom) ||
2022: ($srcnum{$suffix} ne $coursenum) ||
2023: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
2024: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
2025: $coursedom,$coursenum,$srcdom{$suffix},
2026: $srcnum{$suffix},$allmaps,\%rewrites,
2027: \%retitles,\%copies,\%dbcopies,
2028: \%zombies,\%params,\%mapmoves,
2029: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 2030: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 2031: $mapmoves{$url} = 1;
2032: }
2033: $url = $newurl;
2034: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
2035: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
2036: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2037: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
2038: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 2039: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 2040: }
2041: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 2042: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 2043: push(@toclear,$suffix);
2044: # if pasting published map (main content area only) check map not already in course
2045: if ($folder =~ /^default/) {
2046: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
2047: $duplicate{$suffix} = 1;
2048: next;
2049: }
1.484.2.7 raeburn 2050: }
2051: }
2052: }
1.484.2.93.2. (raeburn 2053:): if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.484.2.30 raeburn 2054: my $prefix = $1;
1.484.2.76 raeburn 2055: my $fromothercrs;
1.484.2.30 raeburn 2056: #need to copy the db contents to a new one, unless this is a move.
2057: my %info = (
2058: src => $url,
2059: cdom => $coursedom,
2060: cnum => $coursenum,
1.484.2.76 raeburn 2061: );
1.484.2.93.2. 2(raebur 2062:3): if ($prefix eq 'ext.tool') {
2063:3): if ($prefixchg{$suffix} eq 'docstosupp') {
2064:3): $info{'delgradable'} = 1;
2065:3): }
2066:3): }
1.484.2.76 raeburn 2067: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
2068: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
2069: $fromothercrs = 1;
2070: $info{'cdom'} = $srcdom{$suffix};
2071: $info{'cnum'} = $srcnum{$suffix};
1.484.2.93.2. 5(raebur 2072:3): unless ($checkedsameinst) {
2073:3): my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2074:3): my $intdom = &Apache::lonnet::internet_dom($primary_id);
2075:3): if ($intdom ne '') {
2076:3): my $internet_names =
2077:3): &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2078:3): if (ref($internet_names) eq 'ARRAY') {
2079:3): if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2080:3): $same_institution = 1;
2081:3): }
2082:3): }
2083:3): }
2084:3): $checkedsameinst = 1;
2085:3): }
1.484.2.76 raeburn 2086: }
2087: }
2088: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 2089: my (%lockerr,$msg);
2090: my ($newurl,$result,$errtext) =
1.484.2.93.2. 5(raebur 2091:3): &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
2092:3): \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.484.2.30 raeburn 2093: if ($result eq 'ok') {
2094: $url = $newurl;
2095: $title=&mt('Copy of').' '.$title;
2096: } else {
2097: if ($prefix eq 'smppg') {
2098: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2099: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 2100: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.93.2. (raeburn 2101:): } elsif ($prefix eq 'ext.tool') {
2102:): $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.484.2.30 raeburn 2103: }
2104: $results{$suffix} = $result;
2105: $msgerrs{$suffix} = $msg;
2106: $lockerrs{$suffix} = $lockerr{$prefix};
2107: next;
2108: }
2109: if ($lockerr{$prefix}) {
2110: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 2111: }
1.484.2.7 raeburn 2112: }
1.484.2.30 raeburn 2113: }
2114: $title = &LONCAPA::map::qtunescape($title);
2115: my $ext='false';
2116: if ($url=~m{^http(|s)://}) { $ext='true'; }
2117: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2118: if ($folder !~ /^supplemental/) {
2119: (undef,undef,$title) =
2120: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2121: }
2122: } else {
2123: if ($folder=~/^supplemental/) {
2124: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2125: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 2126: }
2127: }
1.484.2.7 raeburn 2128:
2129: # For uploaded files (excluding pages/sequences) path in copied file is changed
2130: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2131: # courses.
2132:
1.484.2.30 raeburn 2133: unless ($is_map{$suffix}) {
2134: my $newidx;
1.329 droeschl 2135: # Now insert the URL at the bottom
1.484.2.30 raeburn 2136: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2137: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2138: my $relpath = $1;
2139: if ($relpath ne '') {
2140: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2141: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2142: my $newprefix = $newloc;
2143: if ($newloc eq 'default') {
2144: $newprefix = 'docs';
2145: }
2146: if ($newdocsdir eq '') {
2147: $newdocsdir = 'default';
2148: }
2149: if (($prefixchg{$suffix}) ||
2150: ($srcdom{$suffix} ne $coursedom) ||
2151: ($srcnum{$suffix} ne $coursenum) ||
2152: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2153: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2154: $url =
2155: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2156: &Apache::lonnet::getfile($oldurl));
2157: if ($url eq '/adm/notfound.html') {
2158: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2159: next;
2160: } else {
2161: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2162: $newsubpath =~ s{/+$}{/};
2163: $docmoves{$oldurl} = $newsubpath;
2164: }
1.484.2.7 raeburn 2165: }
2166: }
1.484.2.82 raeburn 2167: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2168: my $template = $1;
2169: if ($newidx) {
2170: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2171: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2172: }
1.484.2.93.2. 2(raebur 2173:3): } elsif ($url =~ /ext\.tool$/) {
2174:3): if (($newidx) && ($folder=~/^default/)) {
2175:3): my $marker = (split(m{/},$url))[4];
2176:3): my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2177:3): my $val = 'no';
2178:3): if ($toolsettings{'gradable'}) {
2179:3): $val = 'yes';
2180:3): }
2181:3): &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2182:3): 'string_yesno');
2183:3): &remember_parms($newidx,'gradable','set',$val);
2184:3): }
1.484.2.7 raeburn 2185: }
1.484.2.30 raeburn 2186: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2187: ':'.$ext.':normal:res';
2188: push(@LONCAPA::map::order,$newidx);
2189: # Store the result
2190: my ($errtext,$fatal) =
2191: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2192: if ($fatal) {
2193: $save_err .= $errtext;
2194: $allresult = 'fail';
1.484.2.7 raeburn 2195: }
1.329 droeschl 2196: }
1.484.2.30 raeburn 2197:
1.484.2.82 raeburn 2198: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2199: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 2200: unless ($allresult eq 'fail') {
2201: my %updated = (
2202: rewrites => \%rewrites,
2203: zombies => \%zombies,
2204: removefrommap => \%removefrommap,
2205: removeparam => \%removeparam,
2206: dbcopies => \%dbcopies,
1.484.2.82 raeburn 2207: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 2208: retitles => \%retitles,
2209: );
2210: my %info = (
2211: newsubdir => \%newsubdir,
2212: params => \%params,
2213: );
2214: if ($prefixchg{$suffix}) {
2215: $info{'before'} = $before{$prefixchg{$suffix}};
2216: $info{'after'} = $after{$prefixchg{$suffix}};
2217: }
2218: my %moves = (
2219: copies => \%copies,
2220: docmoves => \%docmoves,
2221: mapmoves => \%mapmoves,
2222: );
2223: (my $result,$msgs{$suffix},my $lockerror) =
2224: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2225: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2226: $url,'paste');
2227: $lockerrors .= $lockerror;
2228: if ($result eq 'ok') {
2229: if ($is_map{$suffix}) {
2230: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2231: $folder.'.'.$container);
2232: if ($fatal) {
2233: $allresult = 'failread';
2234: } else {
2235: if ($#LONCAPA::map::order<1) {
2236: my $idx=&LONCAPA::map::getresidx();
2237: if ($idx<=0) { $idx=1; }
2238: $LONCAPA::map::order[0]=$idx;
2239: $LONCAPA::map::resources[$idx]='';
2240: }
2241: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2242: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2243: ':'.$ext.':normal:res';
2244: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 2245:
2246: # Store the result
1.484.2.30 raeburn 2247: my ($errtext,$fatal) =
2248: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2249: if ($fatal) {
2250: $save_err .= $errtext;
2251: $allresult = 'failstore';
2252: }
2253: }
2254: }
2255: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2256: push(@toclear,$suffix);
2257: }
2258: }
1.329 droeschl 2259: }
2260: }
1.484.2.93.2. 5(raebur 2261:3): if (($updatetoolscache) || (@updatetoolsenc)) {
2262:3): &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
2263:3): \@updatetoolsenc);
2264:3): }
1.484.2.30 raeburn 2265: &clear_from_buffer(\@toclear,\@currpaste);
2266: my $msgsarray;
2267: foreach my $suffix (keys(%msgs)) {
2268: if (ref($msgs{$suffix}) eq 'ARRAY') {
2269: $msgsarray .= join(',',@{$msgs{$suffix}});
2270: }
2271: }
2272: return ($allresult,$save_err,$msgsarray,$lockerrors);
2273: }
2274:
2275: sub do_buffer_empty {
2276: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2277: if (@currpaste == 0) {
2278: return &mt('Clipboard is already empty');
2279: }
2280: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2281: if (@toclear == 0) {
2282: return &mt('Nothing selected to clear from clipboard');
2283: }
2284: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2285: if ($numdel) {
2286: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2287: } else {
2288: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 2289: }
1.484.2.30 raeburn 2290: return;
2291: }
2292:
2293: sub clear_from_buffer {
2294: my ($toclear,$currpaste) = @_;
2295: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2296: my %pastebuffer;
2297: map { $pastebuffer{$_} = 1; } @{$currpaste};
2298: my $numdel = 0;
2299: foreach my $suffix (@{$toclear}) {
2300: next if ($suffix =~ /\D/);
2301: next unless (exists($pastebuffer{$suffix}));
2302: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2303: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2304: delete($pastebuffer{$suffix});
2305: $numdel ++;
2306: }
2307: }
2308: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2309: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2310: return $numdel;
1.484.2.7 raeburn 2311: }
2312:
1.484.2.93.2. 5(raebur 2313:3): sub update_ltitools_caches {
2314:3): my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
2315:3): my $hashid=$coursedom.'_'.$coursenum;
2316:3): if ($updatetoolscache) {
2317:3): &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
2318:3): }
2319:3): if ((ref($updatetoolsenc) eq 'ARRAY') &&
2320:3): (@{$updatetoolsenc})) {
2321:3): my @ids=&Apache::lonnet::current_machine_ids();
2322:3): my $updatedone;
2323:3): foreach my $lonhost (@{$updatetoolsenc}) {
2324:3): if (grep(/^\Q$lonhost\E$/,@ids)) {
2325:3): unless ($updatedone) {
2326:3): &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
2327:3): }
2328:3): $updatedone = 1;
2329:3): } else {
2330:3): &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
2331:3): }
2332:3): }
2333:3): }
2334:3): return;
2335:3): }
2336:3):
1.484.2.7 raeburn 2337: sub get_newmap_url {
2338: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2339: $titleref,$allmaps,$newurls) = @_;
2340: my $newurl;
2341: if ($url=~ m{^/uploaded/}) {
2342: $$titleref=&mt('Copy of').' '.$$titleref;
2343: }
2344: my $now = time;
2345: my $suffix=$$.int(rand(100)).$now;
2346: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2347: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2348: my $path = $1;
2349: my $prefix = $2;
2350: my $ancestor = $3;
2351: if (length($ancestor) > 10) {
2352: $ancestor = substr($ancestor,-10,10);
2353: }
2354: my $newid;
2355: if ($prefixchg) {
2356: if ($folder =~ /^supplemental/) {
2357: $prefix =~ s/^default/supplemental/;
2358: } else {
2359: $prefix =~ s/^supplemental/default/;
2360: }
2361: }
2362: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2363: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2364: } else {
2365: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2366: }
2367: my $counter = 0;
2368: my $is_unique = &uniqueness_check($newurl);
2369: if ($folder =~ /^default/) {
2370: if ($allmaps->{$newurl}) {
2371: $is_unique = 0;
2372: }
2373: }
2374: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2375: $counter ++;
2376: $suffix ++;
2377: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2378: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2379: } else {
2380: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2381: }
2382: $is_unique = &uniqueness_check($newurl);
2383: }
2384: if ($is_unique) {
2385: $newurls->{$newurl} = 1;
2386: } else {
2387: if ($url=~/\.page$/) {
2388: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2389: } else {
2390: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2391: }
2392: }
2393: }
2394: return ($newurl);
2395: }
2396:
2397: sub dbcopy {
1.484.2.93.2. 5(raebur 2398:3): my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
2399:3): $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.484.2.26 raeburn 2400: my ($url,$result,$errtext);
2401: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2402: $url = $dbref->{'src'};
1.484.2.93.2. (raeburn 2403:): if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.484.2.26 raeburn 2404: my $prefix = $1;
1.484.2.93.2. (raeburn 2405:): if ($prefix eq 'ext.tool') {
2406:): $prefix = 'exttool';
2407:): }
1.484.2.26 raeburn 2408: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2409: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2410: my $db_name;
2411: my $marker = (split(m{/},$url))[4];
2412: $marker=~s/\D//g;
2413: if ($dbref->{'src'} =~ m{/smppg$}) {
2414: $db_name =
2415: &Apache::lonsimplepage::get_db_name($url,$marker,
2416: $dbref->{'cdom'},
2417: $dbref->{'cnum'});
1.484.2.93.2. (raeburn 2418:): } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2419:): $db_name = 'exttool_'.$marker;
1.484.2.26 raeburn 2420: } else {
2421: $db_name = 'bulletinpage_'.$marker;
2422: }
2423: my ($suffix,$freedlock,$error) =
2424: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2425: $coursedom,$coursenum,
2426: 'concat');
2427: if (!$suffix) {
2428: if ($prefix eq 'smppg') {
2429: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.484.2.93.2. (raeburn 2430:): } elsif ($prefix eq 'exttool') {
2431:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.484.2.26 raeburn 2432: } else {
1.484.2.42 raeburn 2433: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2434: }
2435: if ($error) {
2436: $errtext .= '<br />'.$error;
2437: }
2438: } else {
2439: #need to copy the db contents to a new one.
2440: my %contents=&Apache::lonnet::dump($db_name,
2441: $dbref->{'cdom'},
2442: $dbref->{'cnum'});
1.484.2.93.2. 5(raebur 2443:3): my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
2444:3): if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
2445:3): if ($contents{'id'} =~ /^(|c)(\d+)$/) {
2446:3): $oldtoolid = $2;
2447:3): if ($1 eq 'c') {
2448:3): $defincrs = 1;
2449:3): %toolinfo =
2450:3): &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
2451:3): } else {
2452:3): %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
2453:3): }
2454:3): if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
2455:3): if ($toolinfo{$oldtoolid}{'passback'}) {
2456:3): $toolpassback = 1;
2457:3): }
2458:3): if ($toolinfo{$oldtoolid}{'roster'}) {
2459:3): $toolroster = 1;
2460:3): }
2461:3): } else {
2462:3): $toolcopyerror = 1;
2463:3): $errtext = &mt('Could not retrieve original settings for pasted external tool.');
2464:3): }
2465:3): }
2466:3): unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
2467:3): $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
2468:3): if ($contents{'crstitle'} ne '') {
2469:3): $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
2470:3): }
2471:3): if (($defincrs) && (!$toolcopyerror)) {
2472:3): my %newtool;
2473:3): my $oldcdom = $dbref->{'cdom'};
2474:3): my $oldcnum = $dbref->{'cnum'};
2475:3): my $title = $toolinfo{$oldtoolid}{'title'};
2476:3): if (ref($currltititles) eq 'HASH') {
2477:3): if (exists($currltititles->{$title})) {
2478:3): $title .= ' (copied from another course)';
2479:3): }
2480:3): }
2481:3): my ($newid,$iderror) =
2482:3): &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
2483:3): if ($newid =~ /^\d+$/) {
2484:3): %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
2485:3): $newtool{$newid}{'title'} = $title;
2486:3): if (ref($currltimax)) {
2487:3): $newtool{$newid}{'order'} = $$currltimax;
2488:3): }
2489:3): if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
2490:3): my $fname = $1;
2491:3): my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
2492:3): if ($content eq '-1') {
2493:3): delete($newtool{$newid}{'image'});
2494:3): } else {
2495:3): $env{'form.'.$suffix.'.image'} = $content;
2496:3): my $newlogo =
2497:3): &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
2498:3): delete($env{'form.'.$suffix.'.image'});
2499:3): if ($newlogo =~ m{^/uploaded/}) {
2500:3): $newtool{$newid}{'image'} = $newlogo;
2501:3): } else {
2502:3): delete($newtool{$newid}{'image'});
2503:3): }
2504:3): }
2505:3): }
2506:3): my $newusable;
2507:3): if ($same_institution) {
2508:3): my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
2509:3): if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
2510:3): my %newtoolsenc;
2511:3): %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
2512:3): my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
2513:3): if ($putres eq 'ok') {
2514:3): if (ref($updatetoolsenc) eq 'ARRAY') {
2515:3): my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
2516:3): unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
2517:3): push(@{$updatetoolsenc},$newhome);
2518:3): }
2519:3): }
2520:3): $newusable = 1;
2521:3): }
2522:3): }
2523:3): }
2524:3): if ($newtool{$newid}{'usable'}) {
2525:3): unless ($newusable) {
2526:3): delete($newtool{$newid}{'usable'});
2527:3): }
2528:3): }
2529:3): my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
2530:3): if ($putres eq 'ok') {
2531:3): $contents{'id'} = "c$newid";
2532:3): if (ref($updatetoolscache)) {
2533:3): $$updatetoolscache ++;
2534:3): }
2535:3): if (ref($currltititles->{$title}) eq 'ARRAY') {
2536:3): push(@{$currltititles->{$title}},$newid);
2537:3): } else {
2538:3): $currltititles->{$title} = [$newid];
2539:3): }
2540:3): if (ref($currltimax)) {
2541:3): $$currltimax ++;
2542:3): }
2543:3): } else {
2544:3): $toolcopyerror = 1;
2545:3): $errtext = &mt('Unable to save external tool definition in Course Settings.');
2546:3): }
2547:3): } else {
2548:3): $toolcopyerror = 1;
2549:3): $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
2550:3): }
2551:3): }
2552:3): }
2553:3): }
1.484.2.26 raeburn 2554: if (exists($contents{'uploaded.photourl'})) {
2555: my $photo = $contents{'uploaded.photourl'};
2556: my ($subdir,$fname) =
2557: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2558: my $newphoto;
2559: if ($fname ne '') {
2560: my $content = &Apache::lonnet::getfile($photo);
2561: unless ($content eq '-1') {
2562: $env{'form.'.$suffix.'.photourl'} = $content;
2563: $newphoto =
2564: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2565: delete($env{'form.'.$suffix.'.photourl'});
2566: }
2567: }
2568: if ($newphoto =~ m{^/uploaded/}) {
2569: $contents{'uploaded.photourl'} = $newphoto;
2570: }
2571: }
2572: $db_name =~ s{_\d*$ }{_$suffix}x;
1.484.2.93.2. 5(raebur 2573:3): if ($prefix eq 'exttool') {
2574:3): unless ($toolcopyerror) {
2575:3): foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
2576:3): if (exists($contents{$key})) {
2577:3): delete($contents{$key});
2578:3): }
2579:3): }
2580:3): if ($dbref->{'delgradable'}) {
2581:3): if (exists($contents{'gradable'})) {
2582:3): delete($contents{'gradable'});
2583:3): }
2584:3): }
2585:3): if ($toolpassback) {
2586:3): if ($contents{'gradable'}) {
2587:3): my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
2588:3): $contents{'gradesecret'} = $gradesecret;
2589:3): $contents{'gradesecretdate'} = time;
2590:3): }
2591:3): }
2592:3): if ($toolroster) {
2593:3): my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
2594:3): $contents{'rostersecret'} = $rostersecret;
2595:3): $contents{'rostersecretdate'} = time;
2596:3): }
2597:3): }
2(raebur 2598:3): }
5(raebur 2599:3): if (($prefix eq 'exttool') && ($toolcopyerror)) {
2600:3): $result = 'error';
2601:3): } else {
2602:3): $result=&Apache::lonnet::put($db_name,\%contents,
2603:3): $coursedom,$coursenum);
2604:3): if ($result eq 'ok') {
2605:3): $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
2606:3): }
1.484.2.26 raeburn 2607: }
2608: }
2609: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2610: $lockerrorsref->{$prefix} =
2611: '<div class="LC_error">'.
2612: &mt('There was a problem removing a lockfile.');
2613: if ($prefix eq 'smppg') {
2614: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2615: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.93.2. (raeburn 2616:): } elsif ($prefix eq 'exttool') {
2617:): $lockerrorsref->{$prefix} .=
2618:): ' '.&mt('This will prevent addition of more external tools to this course.');
1.484.2.26 raeburn 2619: } else {
1.484.2.42 raeburn 2620: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2621: }
1.484.2.38 raeburn 2622: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2623: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2624: '</div>';
1.484.2.26 raeburn 2625: }
2626: }
2627: } elsif ($url =~ m{/syllabus$}) {
2628: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2629: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2630: if (($dbref->{'cdom'} ne $coursedom) ||
2631: ($dbref->{'cnum'} ne $coursenum)) {
2632: my %contents=&Apache::lonnet::dump('syllabus',
2633: $dbref->{'cdom'},
2634: $dbref->{'cnum'});
2635: $result=&Apache::lonnet::put('syllabus',\%contents,
2636: $coursedom,$coursenum);
2637: }
2638: }
1.484.2.7 raeburn 2639: }
2640: }
1.484.2.26 raeburn 2641: return ($url,$result,$errtext);
1.329 droeschl 2642: }
2643:
1.484.2.82 raeburn 2644: sub copy_templated_files {
2645: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2646: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2647: my $srccontainer = 'sequence';
2648: if ($srcwaspage) {
2649: $srccontainer = 'page';
2650: }
2651: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2652: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2653: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2654: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2655: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2656: $template.'.problem';
2657: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2658: if ($template eq 'simpleproblem') {
2659: $srcprefix .= '.0.';
2660: my $weightprefix = $newprefix;
2661: $newprefix .= '.0.';
2662: my @simpleprobqtypes = qw(radio option string essay numerical);
2663: my $qtype=$srcparms{$srcprefix.'questiontype'};
2664: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2665: my %newdata = (
2666: $newprefix.'questiontype' => $qtype,
1.484.2.84 raeburn 2667: );
1.484.2.82 raeburn 2668: foreach my $type (@simpleprobqtypes) {
2669: if ($type eq $qtype) {
2670: $newdata{"$weightprefix.$type.weight"}=1;
2671: } else {
2672: $newdata{"$weightprefix.$type.weight"}=0;
2673: }
2674: }
2675: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2676: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2677: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2678: if ($qtype eq 'numerical') {
2679: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2680: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2681: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2682: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2683: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2684: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2685: unless (defined($maxfoils)) { $maxfoils=10; }
2686: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2687: if ($maxfoils<=0) { $maxfoils=10; }
2688: my $randomize=$srcparms{$srcprefix.'randomize'};
2689: unless (defined($randomize)) { $randomize='yes'; }
2690: unless ($randomize eq 'no') { $randomize='yes'; }
2691: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2692: $newdata{$newprefix.'randomize'} = $randomize;
2693: if ($qtype eq 'option') {
2694: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2695: }
2696: for (my $i=1; $i<=10; $i++) {
2697: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2698: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2699: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2700: }
2701:
2702: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2703: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2704: unless (defined($maxfoils)) { $maxfoils=10; }
2705: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2706: if ($maxfoils<=0) { $maxfoils=10; }
2707: my $randomize=$srcparms{$srcprefix.'randomize'};
2708: unless (defined($randomize)) { $randomize='yes'; }
2709: unless ($randomize eq 'no') { $randomize='yes'; }
2710: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2711: $newdata{$newprefix.'randomize'} = $randomize;
2712: if ($qtype eq 'option') {
2713: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2714: }
2715: for (my $i=1; $i<=10; $i++) {
2716: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2717: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2718: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2719: }
2720: } elsif ($qtype eq 'string') {
2721: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2722: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2723: }
2724: if (keys(%newdata)) {
2725: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2726: $coursenum);
2727: if ($putres eq 'ok') {
2728: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2729: }
2730: }
2731: }
2732: }
2733: }
2734:
1.329 droeschl 2735: sub uniqueness_check {
2736: my ($newurl) = @_;
2737: my $unique = 1;
2738: foreach my $res (@LONCAPA::map::order) {
2739: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2740: $url=&LONCAPA::map::qtescape($url);
2741: if ($newurl eq $url) {
2742: $unique = 0;
1.344 bisitz 2743: last;
1.329 droeschl 2744: }
2745: }
2746: return $unique;
2747: }
2748:
1.484.2.7 raeburn 2749: sub contained_map_check {
1.484.2.93.2. (raeburn 2750:): my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2751:): $hierarchy,$titles,$allmaps) = @_;
1.484.2.7 raeburn 2752: my $content = &Apache::lonnet::getfile($url);
2753: unless ($content eq '-1') {
2754: my $parser = HTML::TokeParser->new(\$content);
2755: $parser->attr_encoded(1);
2756: while (my $token = $parser->get_token) {
2757: next if ($token->[0] ne 'S');
2758: if ($token->[1] eq 'resource') {
2759: next if ($token->[2]->{'type'} eq 'zombie');
2760: my $ressrc = $token->[2]->{'src'};
1.484.2.93.2. 5(raebur 2761:3): if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2762:3): my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
2(raebur 2763:3): unless ($srcdom eq $coursedom) {
2764:3): $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2765:3): next;
2766:3): }
5(raebur 2767:3): unless ($srcnum eq $coursenum) {
2768:3): my %toolsettings =
2769:3): &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
2770:3): my %tooltypes = &Apache::loncommon::usable_exttools();
2771:3): if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2772:3): (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2773:3): $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2774:3): next;
2775:3): }
2776:3): }
2(raebur 2777:3): } elsif ($folder =~ /^supplemental/) {
1.484.2.7 raeburn 2778: unless (&supp_pasteable($ressrc)) {
2779: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2780: next;
2781: }
2782: }
2783: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2784: if ($1 eq 'uploaded') {
2785: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2786: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2787: } else {
2788: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2789: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2790: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2791: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2792: } else {
2793: $addedmaps->{$ressrc} = [$url];
2794: }
2795: }
1.484.2.93.2. (raeburn 2796:): &contained_map_check($ressrc,$folder,$coursenum,$coursedom,
2797:): $removefrommap,$removeparam,
1.484.2.7 raeburn 2798: $addedmaps,$hierarchy,$titles,$allmaps);
2799: }
2800: } elsif ($token->[1] eq 'param') {
2801: if ($folder =~ /^supplemental/) {
2802: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2803: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2804: } else {
1.484.2.19 raeburn 2805: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2806: }
2807: }
2808: }
2809: }
2810: }
2811: return;
2812: }
2813:
2814: sub url_paste_fixups {
1.484.2.26 raeburn 2815: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2816: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2817: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2818: my $checktitle;
2819: if (($prefixchg) &&
2820: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2821: $checktitle = 1;
2822: }
2823: my $skip;
2824: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2825: my $mapid = $1.$2;
2826: if ($tomove->{$mapid}) {
2827: $skip = 1;
2828: }
2829: }
2830: my $file = &Apache::lonnet::getfile($oldurl);
2831: return if ($file eq '-1');
2832: my $parser = HTML::TokeParser->new(\$file);
2833: $parser->attr_encoded(1);
2834: my $changed = 0;
2835: while (my $token = $parser->get_token) {
2836: next if ($token->[0] ne 'S');
2837: if ($token->[1] eq 'resource') {
2838: my $ressrc = $token->[2]->{'src'};
2839: next if ($ressrc eq '');
2840: my $id = $token->[2]->{'id'};
2841: my $title = $token->[2]->{'title'};
2842: if ($checktitle) {
2843: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2844: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2845: }
2846: }
2847: next if ($token->[2]->{'type'} eq 'external');
2848: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2849: next if ($skip);
1.484.2.25 raeburn 2850: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2851: $changed = 1;
2852: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2853: my $srcdom = $1;
2854: my $srcnum = $2;
2855: my $rem = $3;
2856: my $newurl;
2857: my $mapname;
2858: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2859: my $prefix = $1;
2860: $mapname = $prefix.$2;
2861: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2862: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2863: $srcdom,$srcnum,$allmaps,$rewrites,
2864: $retitles,$copies,$dbcopies,$zombies,
2865: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2866: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2867: next;
2868: } else {
2869: ($newurl,my $error) =
2870: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2871: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2872: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2873: $newsubdir->{$ressrc} = $1;
2874: }
2875: if ($error) {
2876: next;
2877: }
2878: }
2879: }
2880: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2881: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2882:
1.484.2.7 raeburn 2883: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2884: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2885: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2886: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2887: $cnum,$srcdom,$srcnum,$allmaps,
2888: $rewrites,$retitles,$copies,$dbcopies,
2889: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2890: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2891: $mapmoves->{$ressrc} = 1;
2892: }
2893: $changed = 1;
2894: } else {
1.484.2.25 raeburn 2895: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2896: $copies->{$oldurl}{$ressrc} = $id;
2897: $changed = 1;
2898: }
2899: }
1.484.2.93.2. 2(raebur 2900:3): } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.484.2.30 raeburn 2901: next if ($skip);
1.484.2.7 raeburn 2902: my $srcdom = $1;
2903: my $srcnum = $2;
1.484.2.93.2. 2(raebur 2904:3): my $rem = $3;
2905:3): my ($is_exttool,$exttoolchg);
2906:3): if ($rem =~ m{\d+/ext\.tool$}) {
2907:3): $is_exttool = 1;
2908:3): }
1.484.2.7 raeburn 2909: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2910: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2911: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2912: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2913: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2914: $changed = 1;
1.484.2.93.2. 2(raebur 2915:3): if ($is_exttool) {
2916:3): $exttoolchg = 1;
2917:3): }
2918:3): } elsif (($is_exttool) &&
2919:3): ($env{'form.docs.markedcopy_options'} ne 'move')) {
2920:3): $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2921:3): $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2922:3): $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2923:3): $changed = 1;
2924:3): $exttoolchg = 1;
2925:3): }
2926:3): if (($is_exttool) && ($prefixchg)) {
2927:3): if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2928:3): if ($exttoolchg) {
2929:3): $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2930:3): }
2931:3): }
1.484.2.26 raeburn 2932: }
2933: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2934: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2935: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2936: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2937: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2938: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2939: $changed = 1;
2940: }
1.484.2.82 raeburn 2941: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2942: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2943: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2944: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2945: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2946: }
1.484.2.7 raeburn 2947: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2948: next if ($skip);
2949: my $srcdom = $1;
2950: my $srcnum = $2;
2951: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2952: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2953: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2954: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2955: $changed = 1;
2956: }
2957: }
2958: } elsif ($token->[1] eq 'param') {
2959: next if ($skip);
1.484.2.19 raeburn 2960: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2961: if ($to ne '') {
2962: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2963: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2964: } else {
2965: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2966: }
2967: }
2968: }
2969: }
2970: return $changed;
2971: }
2972:
2973: sub apply_fixups {
1.484.2.23 raeburn 2974: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2975: $oldurl,$url,$caller) = @_;
2976: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2977: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.93.2. 5(raebur 2978:3): %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
2979:3): %currltititles,$currltimax);
2980:3): $currltimax = 0;
1.484.2.23 raeburn 2981: if (ref($updated) eq 'HASH') {
2982: if (ref($updated->{'rewrites'}) eq 'HASH') {
2983: %rewrites = %{$updated->{'rewrites'}};
2984: }
2985: if (ref($updated->{'zombies'}) eq 'HASH') {
2986: %zombies = %{$updated->{'zombies'}};
2987: }
2988: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2989: %removefrommap = %{$updated->{'removefrommap'}};
2990: }
2991: if (ref($updated->{'removeparam'}) eq 'HASH') {
2992: %removeparam = %{$updated->{'removeparam'}};
2993: }
2994: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2995: %dbcopies = %{$updated->{'dbcopies'}};
2996: }
2997: if (ref($updated->{'retitles'}) eq 'HASH') {
2998: %retitles = %{$updated->{'retitles'}};
2999: }
1.484.2.82 raeburn 3000: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
3001: %resdatacopy = %{$updated->{'resdatacopy'}};
3002: }
1.484.2.23 raeburn 3003: }
3004: if (ref($info) eq 'HASH') {
3005: if (ref($info->{'newsubdir'}) eq 'HASH') {
3006: %newsubdir = %{$info->{'newsubdir'}};
3007: }
3008: if (ref($info->{'params'}) eq 'HASH') {
3009: %params = %{$info->{'params'}};
3010: }
3011: if (ref($info->{'before'}) eq 'HASH') {
3012: %before = %{$info->{'before'}};
3013: }
3014: if (ref($info->{'after'}) eq 'HASH') {
3015: %after = %{$info->{'after'}};
3016: }
3017: }
3018: if (ref($moves) eq 'HASH') {
3019: if (ref($moves->{'copies'}) eq 'HASH') {
3020: %copies = %{$moves->{'copies'}};
3021: }
3022: if (ref($moves->{'docmoves'}) eq 'HASH') {
3023: %docmoves = %{$moves->{'docmoves'}};
3024: }
3025: if (ref($moves->{'mapmoves'}) eq 'HASH') {
3026: %mapmoves = %{$moves->{'mapmoves'}};
3027: }
3028: }
3029: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 3030: my @allcopies;
1.484.2.23 raeburn 3031: if (exists($copies{$key})) {
3032: if (ref($copies{$key}) eq 'HASH') {
3033: my %added;
3034: foreach my $innerkey (keys(%{$copies{$key}})) {
3035: if (($innerkey ne '') && (!$added{$innerkey})) {
3036: push(@allcopies,$innerkey);
3037: $added{$innerkey} = 1;
3038: }
1.484.2.7 raeburn 3039: }
1.484.2.23 raeburn 3040: undef(%added);
1.484.2.7 raeburn 3041: }
3042: }
3043: if ($key eq $oldurl) {
1.484.2.23 raeburn 3044: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 3045: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 3046: push(@allcopies,$oldurl);
3047: }
3048: }
3049: }
3050: if (@allcopies > 0) {
3051: foreach my $item (@allcopies) {
1.484.2.19 raeburn 3052: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 3053: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
3054: if ($fname ne '') {
3055: my $content = &Apache::lonnet::getfile($item);
3056: unless ($content eq '-1') {
3057: my $storefn;
1.484.2.23 raeburn 3058: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
3059: $storefn = $docmoves{$key};
1.484.2.7 raeburn 3060: } else {
3061: $storefn = $relpath;
3062: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 3063: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
3064: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 3065: }
1.484.2.23 raeburn 3066: if ($newsubdir{$key}) {
1.484.2.25 raeburn 3067: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 3068: }
3069: }
3070: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 3071: my $copyurl =
1.484.2.7 raeburn 3072: &Apache::lonclonecourse::writefile($env{'request.course.id'},
3073: $storefn.$fname,$content);
3074: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 3075: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 3076: return &mt('Paste failed: an error occurred copying the file.');
3077: } elsif (ref($errors) eq 'HASH') {
3078: $errors->{$item} = 1;
3079: }
3080: }
3081: }
3082: }
3083: }
3084: }
3085: }
1.484.2.23 raeburn 3086: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 3087: my $storefn=$key;
3088: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 3089: if ($prefixchg && $before{'map'} && $after{'map'}) {
3090: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 3091: }
1.484.2.23 raeburn 3092: if ($newsubdir{$key}) {
3093: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 3094: }
3095: my $mapcontent = &Apache::lonnet::getfile($key);
1.484.2.93.2. (raeburn 3096:): if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
3097:): ($after{'map'} eq 'default') &&
3098:): ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
3099:): $mapcontent = '<map>'."\n".
3100:): '<resource id="1" src="" type="start" />'."\n".
3101:): '<link from="1" to="2" index="1" />'."\n".
3102:): '<resource id="2" src="" type="finish" />'."\n".
3103:): '</map>';
3104:): }
1.484.2.7 raeburn 3105: if ($mapcontent eq '-1') {
3106: if (ref($errors) eq 'HASH') {
3107: $errors->{$key} = 1;
3108: }
3109: } else {
3110: my $newmap =
3111: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
3112: $mapcontent);
3113: if ($newmap eq '/adm/notfound.html') {
3114: if (ref($errors) eq 'HASH') {
3115: $errors->{$key} = 1;
3116: }
3117: }
3118: }
3119: }
3120: my %updates;
3121: if ($is_map) {
1.484.2.23 raeburn 3122: if (ref($updated) eq 'HASH') {
3123: foreach my $type (keys(%{$updated})) {
3124: if (ref($updated->{$type}) eq 'HASH') {
3125: foreach my $key (keys(%{$updated->{$type}})) {
3126: $updates{$key} = 1;
3127: }
3128: }
3129: }
1.484.2.7 raeburn 3130: }
1.484.2.93.2. 5(raebur 3131:3): my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.484.2.7 raeburn 3132: foreach my $key (keys(%updates)) {
3133: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 3134: if (ref($rewrites{$key}) eq 'HASH') {
3135: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 3136: }
1.484.2.23 raeburn 3137: if (ref($retitles{$key}) eq 'HASH') {
3138: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 3139: }
1.484.2.23 raeburn 3140: if (ref($removefrommap{$key}) eq 'HASH') {
3141: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 3142: }
1.484.2.23 raeburn 3143: if (ref($removeparam{$key}) eq 'HASH') {
3144: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 3145: }
1.484.2.23 raeburn 3146: if (ref($zombies{$key}) eq 'HASH') {
3147: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 3148: }
1.484.2.23 raeburn 3149: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 3150: foreach my $idx (keys(%{$dbcopies{$key}})) {
3151: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.484.2.93.2. 5(raebur 3152:3): my $oldurl = $dbcopies{$key}{$idx}{'src'};
3153:3): my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
3154:3): my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
3155:3): my $oldmarker;
3156:3): if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
3157:3): $oldmarker = $1;
3158:3): unless (($gotcrsltitools) ||
3159:3): (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
3160:3): my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
3161:3): if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
3162:3): unless ($gotcrsltitools) {
3163:3): %currcrsltitools =
3164:3): &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
3165:3): foreach my $item (sort(keys(%currcrsltitools))) {
3166:3): if (ref($currcrsltitools{$item}) eq 'HASH') {
3167:3): $currltimax ++;
3168:3): if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
3169:3): push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
3170:3): } else {
3171:3): $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
3172:3): }
3173:3): }
3174:3): }
3175:3): $gotcrsltitools = 1;
3176:3): }
3177:3): unless ($checkedsameinst) {
3178:3): my $primary_id = &Apache::lonnet::domain($cdom,'primary');
3179:3): my $intdom = &Apache::lonnet::internet_dom($primary_id);
3180:3): if ($intdom ne '') {
3181:3): my $internet_names =
3182:3): &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
3183:3): if (ref($internet_names) eq 'ARRAY') {
3184:3): if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
3185:3): $same_institution = 1;
3186:3): }
3187:3): }
3188:3): }
3189:3): $checkedsameinst = 1;
3190:3): }
3191:3): }
3192:3): }
3193:3): }
1.484.2.26 raeburn 3194: my ($newurl,$result,$errtext) =
1.484.2.93.2. 5(raebur 3195:3): &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
3196:3): \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.484.2.26 raeburn 3197: if ($result eq 'ok') {
3198: $newdb{$idx} = $newurl;
1.484.2.93.2. 5(raebur 3199:3): if ($newurl =~ /ext\.tool$/) {
3200:3): if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
3201:3): if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
3202:3): my $newmarker = $1;
3203:3): unless ($oldmarker eq $newmarker) {
3204:3): $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
3205:3): }
3206:3): }
3207:3): }
3208:3): }
1.484.2.26 raeburn 3209: } elsif (ref($errors) eq 'HASH') {
3210: $errors->{$key} = 1;
3211: }
3212: push(@msgs,$errtext);
3213: }
1.484.2.7 raeburn 3214: }
3215: }
1.484.2.82 raeburn 3216: if (ref($resdatacopy{$key}) eq 'HASH') {
3217: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
3218: foreach my $idx (keys(%{$resdatacopy{$key}})) {
3219: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
3220: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
3221: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
3222: my $template = $1;
3223: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
3224: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
3225: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
3226: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
3227: unless ($gotnewmapname) {
3228: ($newmapname) = ($key =~ m{/([^/]+)$});
3229: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
3230: if ($newsubdir{$key}) {
3231: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
3232: }
3233: $gotnewmapname = 1;
3234: }
3235: my $srcmapinfo = $srcfolder.':'.$idx;
3236: if ($srccontainer eq 'page') {
3237: $srcmapinfo .= ':1';
3238: }
3239: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
3240: $cnum,$template,$idx,$newmapname);
3241: }
3242: }
3243: }
3244: }
3245: }
1.484.2.23 raeburn 3246: if (ref($params{$key}) eq 'HASH') {
3247: %currparam = %{$params{$key}};
1.484.2.7 raeburn 3248: }
3249: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
3250: if ($fatal) {
1.484.2.26 raeburn 3251: return ($errtext);
1.484.2.7 raeburn 3252: }
3253: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
3254: if (defined($LONCAPA::map::zombies[$i])) {
3255: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 3256: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 3257: undef($LONCAPA::map::zombies[$i]);
3258: }
3259: }
3260: }
1.484.2.77 raeburn 3261: my $total = scalar(@LONCAPA::map::order) - 1;
3262: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 3263: my $idx = $LONCAPA::map::order[$i];
3264: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 3265: my $changed;
1.484.2.23 raeburn 3266: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 3267: if ((exists($toremove{$idx})) &&
3268: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 3269: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 3270: if (ref($currparam{$idx}) eq 'ARRAY') {
3271: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 3272: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 3273: }
3274: }
3275: next;
3276: }
3277: my $origsrc = $src;
1.484.2.25 raeburn 3278: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 3279: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
3280: $changed = 1;
3281: }
3282: }
1.484.2.25 raeburn 3283: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 3284: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
3285: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 3286: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 3287: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 3288: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 3289: } else {
1.484.2.23 raeburn 3290: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 3291: }
3292: }
1.484.2.25 raeburn 3293: if ($origsrc =~ /\.(page|sequence)$/) {
3294: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 3295: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 3296: }
1.484.2.25 raeburn 3297: } elsif ($newsubdir{$key}) {
3298: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 3299: }
3300: }
3301: $changed = 1;
1.484.2.26 raeburn 3302: } elsif ($newdb{$idx} ne '') {
3303: $src = $newdb{$idx};
1.484.2.7 raeburn 3304: $changed = 1;
3305: }
3306: if ($changed) {
1.484.2.30 raeburn 3307: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 3308: }
3309: }
3310: }
3311: foreach my $idx (keys(%remparam)) {
3312: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 3313: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 3314: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 3315: }
3316: }
3317: }
1.484.2.26 raeburn 3318: if (values(%lockerrors) > 0) {
3319: $lockmsg = join('<br />',values(%lockerrors));
3320: }
1.484.2.7 raeburn 3321: my $storefn;
3322: if ($key eq $oldurl) {
3323: $storefn = $url;
3324: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3325: } else {
3326: $storefn = $key;
3327: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 3328: if ($prefixchg && $before{'map'} && $after{'map'}) {
3329: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 3330: }
1.484.2.23 raeburn 3331: if ($newsubdir{$key}) {
3332: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 3333: }
3334: }
3335: my $report;
3336: if ($folder !~ /^supplemental/) {
3337: $report = 1;
3338: }
1.484.2.20 raeburn 3339: (my $outtext,$errtext) =
1.484.2.7 raeburn 3340: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3341: if ($errtext) {
1.484.2.23 raeburn 3342: if ($caller eq 'paste') {
1.484.2.26 raeburn 3343: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 3344: }
1.484.2.7 raeburn 3345: }
3346: }
1.484.2.93.2. 5(raebur 3347:3): if (($updatetoolscache) || (@updatetoolsenc)) {
3348:3): &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
3349:3): \@updatetoolsenc);
3350:3): }
1.484.2.7 raeburn 3351: }
1.484.2.26 raeburn 3352: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 3353: }
3354:
3355: sub copy_dependencies {
3356: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3357: my $content;
3358: if (ref($contentref)) {
3359: $content = $$contentref;
3360: } else {
3361: $content = &Apache::lonnet::getfile($item);
3362: }
3363: unless ($content eq '-1') {
3364: my $mm = new File::MMagic;
3365: my $mimetype = $mm->checktype_contents($content);
3366: if ($mimetype eq 'text/html') {
3367: my (%allfiles,%codebase,$state);
3368: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3369: if ($res eq 'ok') {
3370: my ($numexisting,$numpathchanges,$existing);
3371: (undef,$numexisting,$numpathchanges,$existing) =
3372: &Apache::loncommon::ask_for_embedded_content(
3373: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3374: {'error_on_invalid_names' => 1,
3375: 'ignore_remote_references' => 1,
3376: 'docs_url' => $item,
3377: 'context' => 'paste'});
3378: if ($numexisting > 0) {
3379: if (ref($existing) eq 'HASH') {
3380: foreach my $dep (keys(%{$existing})) {
3381: my $depfile = $dep;
3382: unless ($depfile =~ m{^\Q$relpath\E}) {
3383: $depfile = $relpath.$dep;
3384: }
3385: my $depcontent = &Apache::lonnet::getfile($depfile);
3386: unless ($depcontent eq '-1') {
3387: my $storedep = $dep;
3388: $storedep =~ s{^\Q$relpath\E}{};
3389: my $dep_url =
3390: &Apache::lonclonecourse::writefile(
3391: $env{'request.course.id'},
3392: $storefn.$storedep,$depcontent);
3393: if ($dep_url eq '/adm/notfound.html') {
3394: if (ref($errors) eq 'HASH') {
3395: $errors->{$depfile} = 1;
3396: }
3397: } else {
3398: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3399: }
3400: }
3401: }
3402: }
3403: }
3404: }
3405: }
3406: }
3407: return;
3408: }
3409:
1.329 droeschl 3410: my %parameter_type = ( 'randompick' => 'int_pos',
3411: 'hiddenresource' => 'string_yesno',
3412: 'encrypturl' => 'string_yesno',
3413: 'randomorder' => 'string_yesno',);
3414: my $valid_parameters_re = join('|',keys(%parameter_type));
3415: # set parameters
3416: sub update_parameter {
1.484.2.29 raeburn 3417: if ($env{'form.changeparms'} eq 'all') {
3418: my (@allidx,@allmapidx,%allchecked,%currchecked);
3419: %allchecked = (
3420: 'hiddenresource' => {},
3421: 'encrypturl' => {},
3422: 'randompick' => {},
3423: 'randomorder' => {},
3424: );
3425: foreach my $which (keys(%allchecked)) {
3426: $env{'form.all'.$which} =~ s/,$//;
3427: if ($which eq 'randompick') {
3428: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3429: my ($res,$value) = split(/:/,$item);
3430: if ($value =~ /^\d+$/) {
3431: $allchecked{$which}{$res} = $value;
3432: }
3433: }
3434: } else {
1.484.2.30 raeburn 3435: if ($env{'form.all'.$which}) {
3436: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3437: }
1.484.2.29 raeburn 3438: }
3439: }
3440: my $haschanges = 0;
3441: foreach my $res (@LONCAPA::map::order) {
3442: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3443: $name=&LONCAPA::map::qtescape($name);
3444: $url=&LONCAPA::map::qtescape($url);
1.484.2.93.2. (raeburn 3445:): next unless $url;
1.484.2.29 raeburn 3446: my $is_map;
3447: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3448: $is_map = 1;
3449: }
3450: foreach my $which (keys(%allchecked)) {
3451: if (($which eq 'randompick' || $which eq 'randomorder')) {
3452: next if (!$is_map);
3453: }
3454: my $oldvalue = 0;
3455: my $newvalue = 0;
3456: if ($allchecked{$which}{$res}) {
3457: $newvalue = $allchecked{$which}{$res};
3458: }
3459: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3460: if ($which eq 'randompick') {
3461: if ($current =~ /^(\d+)$/) {
3462: $oldvalue = $1;
3463: }
3464: } else {
3465: if ($current =~ /^yes$/i) {
3466: $oldvalue = 1;
3467: }
3468: }
3469: if ($oldvalue ne $newvalue) {
3470: $haschanges = 1;
3471: if ($newvalue) {
3472: my $storeval = 'yes';
3473: if ($which eq 'randompick') {
3474: $storeval = $newvalue;
3475: }
3476: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3477: $storeval,
3478: $parameter_type{$which});
3479: &remember_parms($res,$which,'set',$storeval);
3480: } elsif ($oldvalue) {
3481: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3482: &remember_parms($res,$which,'del');
3483: }
3484: }
3485: }
3486: }
3487: return $haschanges;
1.329 droeschl 3488: } else {
1.484.2.59 raeburn 3489: my $haschanges = 0;
3490: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 3491:
1.484.2.29 raeburn 3492: my $which = $env{'form.changeparms'};
3493: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 3494: my $oldvalue = 0;
3495: my $newvalue = 0;
3496: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3497: if ($which eq 'randompick') {
3498: if ($current =~ /^(\d+)$/) {
3499: $oldvalue = $1;
3500: }
3501: } elsif ($current =~ /^yes$/i) {
3502: $oldvalue = 1;
3503: }
1.484.2.29 raeburn 3504: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 3505: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3506: : 1;
1.484.2.29 raeburn 3507: }
1.484.2.59 raeburn 3508: if ($oldvalue ne $newvalue) {
3509: $haschanges = 1;
3510: if ($newvalue) {
3511: my $storeval = 'yes';
3512: if ($which eq 'randompick') {
3513: $storeval = $newvalue;
3514: }
3515: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3516: $parameter_type{$which});
3517: &remember_parms($idx,$which,'set',$storeval);
3518: } else {
3519: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3520: &remember_parms($idx,$which,'del');
3521: }
3522: }
3523: return $haschanges;
1.329 droeschl 3524: }
1.484.2.59 raeburn 3525: return;
1.329 droeschl 3526: }
3527:
3528: sub handle_edit_cmd {
3529: my ($coursenum,$coursedom) =@_;
1.484.2.93.2. 2(raebur 3530:3): my $haschanges = 0;
1.484.2.30 raeburn 3531: if ($env{'form.cmd'} eq '') {
1.484.2.93.2. 2(raebur 3532:3): return $haschanges;
1.484.2.30 raeburn 3533: }
1.329 droeschl 3534: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3535:
3536: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3537: my ($title, $url, @rrest) = split(':', $ratstr);
3538:
1.484.2.30 raeburn 3539: if ($cmd eq 'remove') {
1.329 droeschl 3540: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3541: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3542: &Apache::lonnet::removeuploadedurl($url);
3543: } else {
3544: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3545: }
3546: splice(@LONCAPA::map::order, $idx, 1);
1.484.2.93.2. 2(raebur 3547:3): $haschanges = 1;
1.329 droeschl 3548: } elsif ($cmd eq 'cut') {
3549: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3550: splice(@LONCAPA::map::order, $idx, 1);
1.484.2.93.2. 2(raebur 3551:3): $haschanges = 1;
1.344 bisitz 3552: } elsif ($cmd eq 'up'
1.329 droeschl 3553: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3554: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.484.2.93.2. 2(raebur 3555:3): $haschanges = 1;
1.329 droeschl 3556: } elsif ($cmd eq 'down'
3557: && defined($LONCAPA::map::order[$idx+1])) {
3558: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.484.2.93.2. 2(raebur 3559:3): $haschanges = 1;
1.329 droeschl 3560: } elsif ($cmd eq 'rename') {
3561: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3562: if ($comment=~/\S/) {
3563: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3564: $comment.':'.join(':', $url, @rrest);
3565: }
3566: # Devalidate title cache
3567: my $renamed_url=&LONCAPA::map::qtescape($url);
3568: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.93.2. 2(raebur 3569:3): $haschanges = 1;
1.329 droeschl 3570: }
1.484.2.93.2. 2(raebur 3571:3): return $haschanges;
1.329 droeschl 3572: }
3573:
3574: sub editor {
1.458 raeburn 3575: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.93.2. (raeburn 3576:): $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3577:): $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 3578: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3579: if ($allowed) {
3580: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3581: $is_random_order,$container) =
3582: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3583: $r->print($breadcrumbtrail);
3584: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3585: $container = 'page';
3586: } else {
3587: $container = 'sequence';
3588: }
1.484 raeburn 3589:
1.484.2.21 raeburn 3590: my $jumpto;
3591:
3592: unless ($supplementalflag) {
1.484.2.32 raeburn 3593: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 3594: }
1.484 raeburn 3595:
3596: unless ($allowed) {
3597: $randompick = -1;
3598: }
3599:
1.484.2.67 raeburn 3600: my ($errtext,$fatal);
3601: if (($folder eq '') && (!$supplementalflag)) {
3602: if (@LONCAPA::map::order) {
3603: undef(@LONCAPA::map::order);
3604: undef(@LONCAPA::map::resources);
3605: undef(@LONCAPA::map::resparms);
3606: undef(@LONCAPA::map::zombies);
3607: }
3608: $folder = 'default';
3609: $container = 'sequence';
3610: } else {
3611: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3612: $folder.'.'.$container);
3613: return $errtext if ($fatal);
3614: }
1.329 droeschl 3615:
3616: if ($#LONCAPA::map::order<1) {
3617: my $idx=&LONCAPA::map::getresidx();
3618: if ($idx<=0) { $idx=1; }
3619: $LONCAPA::map::order[0]=$idx;
3620: $LONCAPA::map::resources[$idx]='';
3621: }
1.364 bisitz 3622:
1.329 droeschl 3623: # ------------------------------------------------------------ Process commands
3624:
3625: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 3626: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3627: # set parameters and change order
3628: &snapshotbefore();
3629:
3630: if (&update_parameter()) {
1.484.2.59 raeburn 3631: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3632: return $errtext if ($fatal);
3633: }
3634:
3635: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3636: # change order
3637: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3638: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3639:
3640: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3641: return $errtext if ($fatal);
3642: }
1.364 bisitz 3643:
1.329 droeschl 3644: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 3645: my %paste_errors;
1.484.2.26 raeburn 3646: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 3647: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3648: \%paste_errors);
1.484.2.30 raeburn 3649: if (ref($pastemsgarray) eq 'ARRAY') {
3650: if (@{$pastemsgarray} > 0) {
3651: $r->print('<p class="LC_info">'.
3652: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3653: '</p>');
3654: }
1.484.2.30 raeburn 3655: }
3656: if ($lockerror) {
3657: $r->print('<p class="LC_error">'.
3658: $lockerror.
3659: '</p>');
3660: }
3661: if ($save_error ne '') {
3662: return $save_error;
3663: }
3664: if ($paste_res) {
3665: my %errortext = &Apache::lonlocal::texthash (
3666: fail => 'Storage of folder contents failed',
3667: failread => 'Reading folder contents failed',
3668: failstore => 'Storage of folder contents failed',
3669: );
3670: if ($errortext{$paste_res}) {
3671: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3672: }
1.329 droeschl 3673: }
1.484.2.7 raeburn 3674: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3675: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3676: &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".
3677: '<ul>'."\n");
3678: foreach my $key (sort(keys(%paste_errors))) {
3679: $r->print('<li>'.$key.'</li>'."\n");
3680: }
3681: $r->print('</ul></p>'."\n");
3682: }
1.484.2.30 raeburn 3683: } elsif ($env{'form.clearmarked'}) {
3684: my $output = &do_buffer_empty();
3685: if ($output) {
3686: $r->print('<p class="LC_info">'.$output.'</p>');
3687: }
3688: }
1.329 droeschl 3689:
3690: $r->print($upload_output);
3691:
1.484.2.30 raeburn 3692: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3693: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3694: my $contentchg;
1.484.2.58 raeburn 3695: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3696: $contentchg = 1;
3697: }
3698: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3699: return $errtext if ($fatal);
3700: }
1.484.2.30 raeburn 3701:
3702: # Cut, copy and/or remove multiple resources
3703: if ($env{'form.multichange'}) {
3704: my %allchecked = (
3705: cut => {},
3706: remove => {},
3707: );
3708: my $needsupdate;
3709: foreach my $which (keys(%allchecked)) {
3710: $env{'form.multi'.$which} =~ s/,$//;
3711: if ($env{'form.multi'.$which}) {
3712: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3713: if (ref($allchecked{$which}) eq 'HASH') {
3714: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3715: }
3716: }
3717: }
3718: if ($needsupdate) {
3719: my $haschanges = 0;
3720: my %curr_groups = &Apache::longroup::coursegroups();
3721: my $total = scalar(@LONCAPA::map::order) - 1;
3722: for (my $i=$total; $i>=0; $i--) {
3723: my $res = $LONCAPA::map::order[$i];
3724: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3725: $name=&LONCAPA::map::qtescape($name);
3726: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3727: next unless $url;
1.484.2.30 raeburn 3728: my %denied =
3729: &action_restrictions($coursenum,$coursedom,$url,
3730: $env{'form.folderpath'},\%curr_groups);
3731: foreach my $which (keys(%allchecked)) {
3732: next if ($denied{$which});
3733: next unless ($allchecked{$which}{$res});
3734: if ($which eq 'remove') {
3735: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3736: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3737: &Apache::lonnet::removeuploadedurl($url);
3738: } else {
3739: &LONCAPA::map::makezombie($res);
3740: }
3741: splice(@LONCAPA::map::order,$i,1);
3742: $haschanges ++;
3743: } elsif ($which eq 'cut') {
3744: &LONCAPA::map::makezombie($res);
3745: splice(@LONCAPA::map::order,$i,1);
3746: $haschanges ++;
3747: }
3748: }
3749: }
3750: if ($haschanges) {
3751: ($errtext,$fatal) =
3752: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3753: return $errtext if ($fatal);
3754: }
3755: }
3756: }
3757:
1.329 droeschl 3758: # Group import/search
3759: if ($env{'form.importdetail'}) {
3760: my @imports;
3761: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3762: if (defined($item)) {
3763: my ($name,$url,$residx)=
1.484.2.26 raeburn 3764: map { &unescape($_); } split(/\=/,$item);
3765: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3766: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3767: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3768: if ($locknotfreed) {
3769: $r->print($locknotfreed);
3770: }
3771: if ($suffix) {
1.484.2.19 raeburn 3772: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3773: } else {
3774: return $errortxt;
3775: }
1.484.2.26 raeburn 3776: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3777: my $type = $1;
3778: my ($suffix,$errortxt,$locknotfreed) =
3779: &new_timebased_suffix($coursedom,$coursenum,$type);
3780: if ($locknotfreed) {
3781: $r->print($locknotfreed);
3782: }
3783: if ($suffix) {
3784: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3785: } else {
3786: return $errortxt;
3787: }
1.484.2.93.2. (raeburn 3788:): } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3789:): my ($suffix,$errortxt,$locknotfreed) =
3790:): &new_timebased_suffix($coursedom,$coursenum,'exttool');
3791:): if ($locknotfreed) {
3792:): $r->print($locknotfreed);
3793:): }
3794:): if ($suffix) {
3795:): $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3796:): } else {
3797:): return $errortxt;
3798:): }
1.484.2.27 raeburn 3799: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3800: if ($supplementalflag) {
3801: next unless ($1 eq 'supplemental');
3802: if ($folder eq 'supplemental') {
3803: next unless ($2 eq 'default');
3804: } else {
3805: next unless ($folder eq 'supplemental_'.$2);
3806: }
3807: } else {
3808: next unless ($1 eq 'docs');
3809: if ($folder eq 'default') {
3810: next unless ($2 eq 'default');
3811: } else {
3812: next unless ($folder eq 'default_'.$2);
3813: }
3814: }
1.484.2.15 raeburn 3815: }
1.329 droeschl 3816: push(@imports, [$name, $url, $residx]);
3817: }
3818: }
1.484.2.23 raeburn 3819: ($errtext,$fatal,my $fixuperrors) =
3820: &group_import($coursenum, $coursedom, $folder,$container,
1.484.2.93.2. (raeburn 3821:): 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3822: return $errtext if ($fatal);
1.484.2.23 raeburn 3823: if ($fixuperrors) {
3824: $r->print($fixuperrors);
3825: }
1.329 droeschl 3826: }
3827: # Loading a complete map
3828: if ($env{'form.loadmap'}) {
3829: if ($env{'form.importmap'}=~/\w/) {
3830: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3831: my ($title,$url,$ext,$type)=split(/\:/,$res);
3832: my $idx=&LONCAPA::map::getresidx($url);
3833: $LONCAPA::map::resources[$idx]=$res;
3834: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3835: }
3836: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3837: $folder.'.'.$container,1);
1.329 droeschl 3838: return $errtext if ($fatal);
3839: } else {
3840: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3841:
1.329 droeschl 3842: }
3843: }
3844: &log_differences($plain);
3845: }
3846: # ---------------------------------------------------------------- End commands
3847: # ---------------------------------------------------------------- Print screen
3848: my $idx=0;
3849: my $shown=0;
3850: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3851: $r->print('<div class="LC_Box">'.
1.432 raeburn 3852: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3853: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3854: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3855: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3856: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3857: '</ol>');
1.381 bisitz 3858: if ($randompick>=0) {
3859: $r->print('<p class="LC_warning">'
3860: .&mt('Caution: this folder is set to randomly pick a subset'
3861: .' of resources. Adding or removing resources from this'
3862: .' folder will change the set of resources that the'
3863: .' students see, resulting in spurious or missing credit'
3864: .' for completed problems, not limited to ones you'
3865: .' modify. Do not modify the contents of this folder if'
3866: .' it is in active student use.')
3867: .'</p>'
3868: );
3869: }
3870: if ($is_random_order) {
3871: $r->print('<p class="LC_warning">'
3872: .&mt('Caution: this folder is set to randomly order its'
3873: .' contents. Adding or removing resources from this folder'
3874: .' will change the order of resources shown.')
3875: .'</p>'
3876: );
3877: }
3878: $r->print('</div>');
1.364 bisitz 3879: }
1.381 bisitz 3880:
1.484.2.93.2. 0(raebur 3881:3): if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
3882:3): my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
3883:3): if (ref($supplemental) eq 'HASH') {
3884:3): if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
3885:3): (ref($supplemental->{'ids'}) eq 'HASH')) {
3886:3): if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
3887:3): my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
3888:3): if ($supplemental->{'hidden'}->{$mapnum}) {
3889:3): $ishidden = 1;
3890:3): }
3891:3): }
3892:3): }
3893:3): }
3894:3): }
3895:3):
1.484.2.30 raeburn 3896: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3897: %filters = (
3898: canremove => [],
3899: cancut => [],
3900: cancopy => [],
3901: hiddenresource => [],
3902: encrypturl => [],
3903: randomorder => [],
3904: randompick => [],
3905: );
3906: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3907: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3908: foreach my $res (@LONCAPA::map::order) {
3909: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3910: $name=&LONCAPA::map::qtescape($name);
3911: $url=&LONCAPA::map::qtescape($url);
3912: unless ($name) { $name=(split(/\//,$url))[-1]; }
3913: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3914: push(@allidx,$res);
3915: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3916: push(@allmapidx,$res);
3917: }
1.484.2.67 raeburn 3918:
1.484.2.93.2. 0(raebur 3919:3): if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
3920:3): if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
3921:3): $idx++;
3922:3): next;
3923:3): }
3924:3): }
1.381 bisitz 3925: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3926: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3927: $pathitem,$supplementalflag,$container,
1.484.2.93.2. (raeburn 3928:): \%filters,\%curr_groups,$ltitoolsref,$canedit,
0(raebur 3929:3): $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 3930: $idx++;
3931: $shown++;
1.329 droeschl 3932: }
1.424 onken 3933: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3934:
1.484.2.30 raeburn 3935: my $need_save;
1.484.2.67 raeburn 3936: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3937: my $toolslink;
1.484.2.93.2. 0(raebur 3938:3): if ($allowed || $canedit) {
3939:3): my $helpitem = 'Navigation_Screen';
3940:3): if (!$allowed) {
3941:3): $helpitem = 'Supplemental_Navigation';
3942:3): }
1.484.2.31 raeburn 3943: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3944: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.484.2.93.2. 0(raebur 3945:3): $helpitem,undef,'RAT')
1.484.2.19 raeburn 3946: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3947: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3948: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3949: .'id="LC_content_toolbar_edittoplevel" '
3950: .'class="LC_toolbarItem" '
3951: .'title="'.&mt('Supplemental Content Editor').'">'
3952: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3953: }
1.484.2.19 raeburn 3954: if ($shown) {
3955: if ($allowed) {
3956: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3957: .&Apache::loncommon::start_data_table(undef,'contentlist')
3958: .&Apache::loncommon::start_data_table_header_row()
3959: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3960: .'<th colspan="2">'.&mt('Actions').'</th>'
1.484.2.93.2. 0(raebur 3961:3): .'<th>'.&mt('Document').'</th>'
3962:3): .'<th colspan="2">'.&mt('Settings').'</th>'
3963:3): .&Apache::loncommon::end_data_table_header_row();
1.484.2.29 raeburn 3964: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3965: $lists{'canhide'} = join(',',@allidx);
3966: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3967: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3968: 'randomorder','randompick');
3969: foreach my $item (@possfilters) {
3970: if (ref($filters{$item}) eq 'ARRAY') {
3971: if (@{$filters{$item}} > 0) {
3972: $lists{$item} = join(',',@{$filters{$item}});
3973: }
3974: }
3975: }
1.484.2.29 raeburn 3976: if (@allidx > 0) {
3977: my $path;
3978: if ($env{'form.folderpath'}) {
3979: $path =
3980: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3981: }
1.484.2.30 raeburn 3982: if (@allidx > 1) {
3983: $to_show .=
3984: &Apache::loncommon::continue_data_table_row().
3985: '<td colspan="2"> </td>'.
3986: '<td>'.
1.484.2.67 raeburn 3987: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3988: '</td>'.
3989: '<td> </td>'.
3990: '<td> </td>'.
1.484.2.93.2. 0(raebur 3991:3): '<td colspan="2">'.
1.484.2.67 raeburn 3992: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3993: '</td>'.
3994: &Apache::loncommon::end_data_table_row();
3995: $need_save = 1;
3996: }
1.484.2.29 raeburn 3997: }
3998: }
3999: $to_show .= $output.' '
1.484.2.19 raeburn 4000: .&Apache::loncommon::end_data_table()
4001: .'<br style="line-height:2px;" />'
4002: .&Apache::loncommon::end_scrollbox();
4003: } else {
4004: $to_show .= $toolslink
4005: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4006: .$output.' '
4007: .&Apache::loncommon::end_data_table();
4008: }
4009: } else {
4010: if (!$allowed) {
4011: $to_show .= $toolslink;
1.393 raeburn 4012: }
1.484.2.67 raeburn 4013: my $noresmsg;
4014: if ($allowed && $hiddentop && !$supplementalflag) {
4015: $noresmsg = &mt('Main Content Hidden');
4016: } else {
4017: $noresmsg = &mt('Currently empty');
4018: }
1.484.2.19 raeburn 4019: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
4020: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 4021: .$noresmsg
1.484.2.19 raeburn 4022: .'</div>'
4023: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 4024: }
4025: } else {
1.484.2.19 raeburn 4026: if ($shown) {
4027: $to_show = '<div>'
4028: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4029: .$output
4030: .&Apache::loncommon::end_data_table()
4031: .'</div>';
4032: } else {
4033: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 4034: .&mt('Currently empty')
1.484.2.19 raeburn 4035: .'</div>'
4036: }
1.458 raeburn 4037: }
4038: my $tid = 1;
4039: if ($supplementalflag) {
4040: $tid = 2;
1.329 droeschl 4041: }
4042: if ($allowed) {
1.484 raeburn 4043: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 4044: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 4045: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 4046: if ($canedit) {
1.484.2.67 raeburn 4047: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
4048: }
1.460 raeburn 4049: } else {
4050: $r->print($to_show);
1.329 droeschl 4051: }
4052: return;
4053: }
4054:
1.484.2.30 raeburn 4055: sub multiple_check_form {
1.484.2.67 raeburn 4056: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 4057: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 4058: my $disabled;
4059: unless ($canedit) {
1.484.2.93.2. 2(raebur 4060:3): $disabled = ' disabled="disabled"';
1.484.2.67 raeburn 4061: }
1.484.2.30 raeburn 4062: my $output =
4063: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
4064: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
4065: '<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>'.
4066: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
4067: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
4068: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
4069: if ($caller eq 'settings') {
4070: $output .=
4071: '<table><tr>'.
4072: '<td class="LC_docs_entry_parameter">'.
4073: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 4074: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 4075: '</label></span></td>'.
4076: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 4077: '<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 4078: '</span></td>'.
4079: '</tr>'."\n".
4080: '<tr>'.
4081: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 4082: '<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 4083: '</label></span>'.
4084: '</td></tr></table>'."\n";
4085: } else {
4086: $output .=
4087: '<table><tr>'.
4088: '<td class="LC_docs_entry_parameter">'.
4089: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 4090: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 4091: '</label></span></td>'.
4092: '<td class="LC_docs_entry_parameter">'.
4093: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 4094: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 4095: '</label></span></td>'."\n".
4096: '<td class="LC_docs_entry_parameter">'.
4097: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 4098: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 4099: '</label></span></td>'.
4100: '</tr></table>'."\n";
4101: }
4102: $output .=
4103: '</fieldset>'.
4104: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
4105: if ($caller eq 'settings') {
4106: $output .=
4107: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
4108: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
4109: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
4110: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
4111: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
4112: } elsif ($caller eq 'actions') {
4113: $output .=
4114: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
4115: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
4116: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
4117: }
4118: $output .=
4119: '</form>'.
4120: '</div>';
4121: return $output;
4122: }
4123:
1.329 droeschl 4124: sub process_file_upload {
1.484.2.36 raeburn 4125: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 4126: # upload a file, if present
1.484.2.36 raeburn 4127: my $filesize = length($env{'form.uploaddoc'});
4128: if (!$filesize) {
4129: $$upload_output = '<div class="LC_error">'.
4130: &mt('Unable to upload [_1]. (size = [_2] bytes)',
4131: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
4132: $filesize).'<br />'.
4133: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
4134: '</div>';
4135: return;
4136: }
4137: my $quotatype = 'unofficial';
4138: if ($crstype eq 'Community') {
4139: $quotatype = 'community';
1.484.2.51 raeburn 4140: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 4141: $quotatype = 'official';
1.484.2.45 raeburn 4142: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
4143: $quotatype = 'textbook';
1.484.2.36 raeburn 4144: }
4145: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
4146: $filesize = int($filesize/1000); #expressed in kb
4147: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 4148: $env{'form.uploaddoc.filename'},$filesize,
4149: 'upload',$quotatype);
1.484.2.36 raeburn 4150: return if ($$upload_output);
4151: }
1.440 raeburn 4152: my ($parseaction,$showupload,$nextphase,$mimetype);
4153: if ($env{'form.parserflag'}) {
1.329 droeschl 4154: $parseaction = 'parse';
4155: }
4156: my $folder=$env{'form.folder'};
4157: if ($folder eq '') {
4158: $folder='default';
4159: }
4160: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
4161: my $errtext='';
4162: my $fatal=0;
4163: my $container='sequence';
1.484.2.19 raeburn 4164: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 4165: $container='page';
4166: }
4167: ($errtext,$fatal)=
1.484.2.27 raeburn 4168: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 4169: if ($#LONCAPA::map::order<1) {
4170: $LONCAPA::map::order[0]=1;
4171: $LONCAPA::map::resources[1]='';
4172: }
4173: my $destination = 'docs/';
4174: if ($folder =~ /^supplemental/) {
4175: $destination = 'supplemental/';
4176: }
4177: if (($folder eq 'default') || ($folder eq 'supplemental')) {
4178: $destination .= 'default/';
4179: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
4180: $destination .= $2.'/';
4181: }
1.484.2.27 raeburn 4182: if ($fatal) {
4183: $$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>';
4184: return;
4185: }
1.440 raeburn 4186: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 4187: my $newidx=&LONCAPA::map::getresidx();
4188: $destination .= $newidx;
1.439 raeburn 4189: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 4190: $parseaction,$allfiles,
1.440 raeburn 4191: $codebase,undef,undef,undef,undef,
4192: undef,undef,\$mimetype);
4193: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
4194: my $stored = $1;
4195: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
4196: $stored.'</span>').'</p>';
4197: } else {
4198: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
4199:
1.457 raeburn 4200: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 4201: return;
4202: }
1.329 droeschl 4203: my $ext='false';
4204: if ($url=~m{^http://}) { $ext='true'; }
4205: $url = &LONCAPA::map::qtunescape($url);
4206: my $comment=$env{'form.comment'};
4207: $comment = &LONCAPA::map::qtunescape($comment);
4208: if ($folder=~/^supplemental/) {
4209: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
4210: $env{'user.domain'}.'___&&&___'.$comment;
4211: }
4212:
4213: $LONCAPA::map::resources[$newidx]=
4214: $comment.':'.$url.':'.$ext.':normal:res';
4215: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
4216: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 4217: $folder.'.'.$container,1);
1.329 droeschl 4218: if ($fatal) {
1.457 raeburn 4219: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 4220: return;
1.329 droeschl 4221: } else {
1.440 raeburn 4222: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
4223: $$upload_output = $showupload;
1.384 raeburn 4224: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 4225: if ($total_embedded > 0) {
1.440 raeburn 4226: my $uploadphase = 'upload_embedded';
4227: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
4228: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
4229: my ($embedded,$num) =
4230: &Apache::loncommon::ask_for_embedded_content(
4231: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
4232: if ($embedded) {
4233: if ($num) {
4234: $$upload_output .=
4235: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
4236: $nextphase = $uploadphase;
4237: } else {
4238: $$upload_output .= $embedded;
4239: }
4240: } else {
4241: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
4242: }
1.329 droeschl 4243: } else {
1.440 raeburn 4244: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 4245: }
1.457 raeburn 4246: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 4247: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
4248: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 4249: $nextphase = 'decompress_uploaded';
4250: my $position = scalar(@LONCAPA::map::order)-1;
4251: my $noextract = &return_to_editor();
4252: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
4253: my %archiveitems = (
4254: folderpath => $env{'form.folderpath'},
4255: cmd => $nextphase,
4256: newidx => $newidx,
4257: position => $position,
4258: phase => $nextphase,
1.477 raeburn 4259: comment => $comment,
1.480 raeburn 4260: );
4261: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
4262: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 4263: $$upload_output = $showupload.
4264: &Apache::loncommon::decompress_form($mimetype,
4265: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 4266: \%archiveitems,\@current);
1.329 droeschl 4267: }
4268: }
4269: }
1.440 raeburn 4270: return $nextphase;
1.329 droeschl 4271: }
4272:
1.480 raeburn 4273: sub get_dir_list {
4274: my ($url,$coursenum,$coursedom,$newidx) = @_;
4275: my ($destination,$dir_root) = &embedded_destination();
4276: my ($dirlistref,$listerror) =
4277: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
4278: my @dir_lines;
4279: my $dirptr=16384;
4280: if (ref($dirlistref) eq 'ARRAY') {
4281: foreach my $dir_line (sort
4282: {
4283: my ($afile)=split('&',$a,2);
4284: my ($bfile)=split('&',$b,2);
4285: return (lc($afile) cmp lc($bfile));
4286: } (@{$dirlistref})) {
4287: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
4288: $filename =~ s/\s+$//;
4289: next if ($filename =~ /^\.\.?$/);
4290: my $isdir = 0;
4291: if ($dirptr&$testdir) {
4292: $isdir = 1;
4293: }
4294: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
4295: }
4296: }
4297: return @dir_lines;
4298: }
4299:
1.329 droeschl 4300: sub is_supplemental_title {
4301: my ($title) = @_;
4302: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
4303: }
4304:
4305: # --------------------------------------------------------------- An entry line
4306:
4307: sub entryline {
1.484.2.12 raeburn 4308: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 4309: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.93.2. 0(raebur 4310:3): $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
4311:3): my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 4312: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 4313: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.484.2.93.2. 0(raebur 4314:3): $encodedtitle=$title;
1.329 droeschl 4315: } else {
4316: $title=&HTML::Entities::encode($title,'"<>&\'');
1.484.2.93.2. 0(raebur 4317:3): $encodedtitle=$title;
1.329 droeschl 4318: $renametitle=$title;
4319: $foldertitle=$title;
4320: }
4321:
1.484.2.67 raeburn 4322: my ($disabled,$readonly,$js_lt);
4323: unless ($canedit) {
4324: $disabled = 'disabled="disabled"';
4325: $readonly = 1;
4326: }
4327:
1.329 droeschl 4328: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 4329:
1.329 droeschl 4330: $renametitle=~s/\\/\\\\/g;
4331: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 4332: $renametitle=~s/"/%22/g;
1.329 droeschl 4333: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 4334: $oldtitle = $renametitle;
4335: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 4336: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 4337: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 4338: # Edit commands
1.484.2.93.2. (raeburn 4339:): my ($esc_path, $path, $symb, $shownsymb);
1.329 droeschl 4340: if ($env{'form.folderpath'}) {
4341: $esc_path=&escape($env{'form.folderpath'});
4342: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4343: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4344: }
1.484.2.16 raeburn 4345: my $isexternal;
1.484.2.19 raeburn 4346: if ($residx) {
1.484.2.12 raeburn 4347: my $currurl = $url;
4348: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 4349: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4350: $isexternal = 1;
4351: }
1.484.2.19 raeburn 4352: if (!$supplementalflag) {
4353: my $path = 'uploaded/'.
4354: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4355: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4356: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4357: $residx,
4358: &Apache::lonnet::declutter($currurl));
4359: }
1.484.2.12 raeburn 4360: }
1.484.2.30 raeburn 4361: my ($renamelink,%lt,$ishash);
4362: if (ref($filtersref) eq 'HASH') {
4363: $ishash = 1;
4364: }
4365:
1.329 droeschl 4366: if ($allowed) {
1.484.2.30 raeburn 4367: $form_start = '
4368: <form action="/adm/coursedocs" method="post">
4369: ';
4370: $form_common=(<<END);
4371: <input type="hidden" name="folderpath" value="$path" />
4372: <input type="hidden" name="symb" value="$symb" />
4373: END
4374: $form_param=(<<END);
4375: <input type="hidden" name="setparms" value="$orderidx" />
4376: <input type="hidden" name="changeparms" value="0" />
4377: END
4378: $form_end = '</form>';
4379:
1.329 droeschl 4380: my $incindex=$index+1;
4381: my $selectbox='';
1.471 raeburn 4382: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 4383: ((split(/\:/,
1.344 bisitz 4384: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4385: ne '') &&
1.329 droeschl 4386: ((split(/\:/,
1.344 bisitz 4387: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 4388: ne '')) {
4389: $selectbox=
4390: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 4391: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 4392: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4393: if ($i==$incindex) {
1.358 bisitz 4394: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 4395: } else {
4396: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4397: }
4398: }
4399: $selectbox.='</select>';
4400: }
1.484.2.12 raeburn 4401: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 4402: 'up' => 'Move Up',
4403: 'dw' => 'Move Down',
4404: 'rm' => 'Remove',
4405: 'ct' => 'Cut',
4406: 'rn' => 'Rename',
1.484.2.12 raeburn 4407: 'cp' => 'Copy',
4408: 'ex' => 'External Resource',
1.484.2.93.2. (raeburn 4409:): 'et' => 'External Tool',
1.484.2.12 raeburn 4410: 'ed' => 'Edit',
4411: 'pr' => 'Preview',
4412: 'sv' => 'Save',
4413: 'ul' => 'URL',
1.484.2.67 raeburn 4414: 'ti' => 'Title',
4415: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 4416: );
1.484.2.30 raeburn 4417: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4418: $env{'form.folderpath'},
4419: $currgroups);
1.484.2.19 raeburn 4420: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4421: my $skip_confirm = 0;
1.484.2.63 raeburn 4422: my $confirm_removal = 0;
1.329 droeschl 4423: if ( $folder =~ /^supplemental/
4424: || ($url =~ m{( /smppg$
4425: |/syllabus$
4426: |/aboutme$
4427: |/navmaps$
4428: |/bulletinboard$
1.484.2.93.2. (raeburn 4429:): |/ext\.tool$
1.484.2.16 raeburn 4430: |\.html$)}x)
1.484.2.19 raeburn 4431: || $isexternal) {
1.329 droeschl 4432: $skip_confirm = 1;
4433: }
1.484.2.63 raeburn 4434: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4435: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4436: $confirm_removal = 1;
4437: }
1.484.2.19 raeburn 4438:
1.484.2.30 raeburn 4439: if ($denied{'copy'}) {
4440: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 4441: <span style="visibility: hidden;">$lt{'cp'}</span>
4442: ENDCOPY
4443: } else {
1.484.2.30 raeburn 4444: my $formname = 'edit_copy_'.$orderidx;
4445: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 4446: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 4447: <form name="$formname" method="post" action="/adm/coursedocs">
4448: $form_common
1.484.2.67 raeburn 4449: <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 4450: $form_end
1.329 droeschl 4451: ENDCOPY
1.484.2.30 raeburn 4452: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4453: push(@{$filtersref->{'cancopy'}},$orderidx);
4454: }
1.329 droeschl 4455: }
1.484.2.30 raeburn 4456: if ($denied{'cut'}) {
1.484.2.16 raeburn 4457: $cutlink=(<<ENDCUT);
4458: <span style="visibility: hidden;">$lt{'ct'}</span>
4459: ENDCUT
4460: } else {
1.484.2.30 raeburn 4461: my $formname = 'edit_cut_'.$orderidx;
4462: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 4463: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 4464: <form name="$formname" method="post" action="/adm/coursedocs">
4465: $form_common
4466: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 4467: <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 4468: $form_end
1.329 droeschl 4469: ENDCUT
1.484.2.30 raeburn 4470: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4471: push(@{$filtersref->{'cancut'}},$orderidx);
4472: }
1.329 droeschl 4473: }
1.484.2.30 raeburn 4474: if ($denied{'remove'}) {
1.484.2.16 raeburn 4475: $removelink=(<<ENDREM);
4476: <span style="visibility: hidden;">$lt{'rm'}</a>
4477: ENDREM
4478: } else {
1.484.2.30 raeburn 4479: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 4480: 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 4481: $removelink=(<<ENDREM);
1.484.2.30 raeburn 4482: <form name="$formname" method="post" action="/adm/coursedocs">
4483: $form_common
4484: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 4485: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 4486: <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 4487: $form_end
1.484.2.9 raeburn 4488: ENDREM
1.484.2.30 raeburn 4489: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4490: push(@{$filtersref->{'canremove'}},$orderidx);
4491: }
1.484.2.9 raeburn 4492: }
1.484.2.35 raeburn 4493: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 4494: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 4495: ENDREN
1.484.2.67 raeburn 4496: my ($uplink,$downlink);
4497: if ($canedit) {
4498: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4499: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4500: } else {
4501: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4502: $downlink = $uplink;
4503: }
1.329 droeschl 4504: $line.=(<<END);
4505: <td>
1.379 bisitz 4506: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4507: <a href="$uplink">
1.484.2.12 raeburn 4508: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4509: </a>
4510: </div>
4511: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4512: <a href="$downlink">
1.484.2.12 raeburn 4513: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4514: </a>
4515: </div>
1.329 droeschl 4516: </td>
4517: <td>
4518: $form_start
1.484.2.30 raeburn 4519: $form_param
1.478 raeburn 4520: $form_common
1.329 droeschl 4521: $selectbox
4522: $form_end
4523: </td>
1.484.2.30 raeburn 4524: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 4525: $removelink
1.329 droeschl 4526: $cutlink
4527: $copylink
4528: </td>
4529: END
4530: }
4531: # Figure out what kind of a resource this is
4532: my ($extension)=($url=~/\.(\w+)$/);
4533: my $uploaded=($url=~/^\/*uploaded\//);
4534: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 4535: my $isfolder;
4536: my $ispage;
4537: my $containerarg;
1.484.2.67 raeburn 4538: my $folderurl;
1.484.2.93.2. 0(raebur 4539:3): my $plainurl;
1.329 droeschl 4540: if ($uploaded) {
1.472 raeburn 4541: if (($extension eq 'sequence') || ($extension eq 'page')) {
4542: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 4543: $containerarg = $1;
1.472 raeburn 4544: if ($extension eq 'sequence') {
4545: $icon=$iconpath.'navmap.folder.closed.gif';
4546: $isfolder=1;
4547: } else {
4548: $icon=$iconpath.'page.gif';
4549: $ispage=1;
4550: }
1.484.2.67 raeburn 4551: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4552: if ($allowed) {
4553: $url='/adm/coursedocs?';
4554: } else {
4555: $url='/adm/supplemental?';
4556: }
1.329 droeschl 4557: } else {
1.484.2.93.2. 0(raebur 4558:3): $plainurl = $url;
1.329 droeschl 4559: }
4560: }
1.364 bisitz 4561:
1.484.2.70 raeburn 4562: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4563: my $orig_url = $url;
1.340 raeburn 4564: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 4565: if ($container eq 'page') {
4566: $url=~s{^http(|s)(:|:)//}{/ext/};
4567: } else {
4568: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4569: }
1.484.2.12 raeburn 4570: if (!$supplementalflag && $residx && $symb) {
4571: if ((!$isfolder) && (!$ispage)) {
4572: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.484.2.87 raeburn 4573: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4574: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4575: } else {
4576: $url=&Apache::lonnet::clutter($url);
4577: }
1.484.2.12 raeburn 4578: if ($url=~/^\/*uploaded\//) {
4579: $url=~/\.(\w+)$/;
4580: my $embstyle=&Apache::loncommon::fileembstyle($1);
4581: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4582: $url='/adm/wrapper'.$url;
4583: } elsif ($embstyle eq 'ssi') {
4584: #do nothing with these
4585: } elsif ($url!~/\.(sequence|page)$/) {
4586: $url='/adm/coursedocs/showdoc'.$url;
4587: }
1.484.2.70 raeburn 4588: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4589: my $wrapped = $1;
4590: my $exturl = $2;
1.484.2.87 raeburn 4591: if (($wrapped eq '') && ($container ne 'page')) {
1.484.2.70 raeburn 4592: $url='/adm/wrapper'.$url;
4593: }
4594: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4595: $nomodal = 1;
4596: }
1.484.2.93.2. (raeburn 4597:): } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4598:): $url='/adm/wrapper'.$url;
1.484.2.70 raeburn 4599: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4600: if (($ENV{'SERVER_PORT'} == 443) &&
4601: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 4602: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4603: $url .= '?usehttp=1';
4604: }
1.484.2.70 raeburn 4605: $nomodal = 1;
4606: }
1.484.2.19 raeburn 4607: }
1.484.2.93.2. (raeburn 4608:): my ($checkencrypt,$shownurl);
4609:): if (!$env{'request.role.adv'}) {
1.484.2.67 raeburn 4610: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.484.2.93.2. (raeburn 4611:): ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.484.2.67 raeburn 4612: $checkencrypt = 1;
1.484.2.70 raeburn 4613: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 4614: unless (ref($$navmapref)) {
4615: $$navmapref = Apache::lonnavmaps::navmap->new();
4616: }
4617: if (ref($$navmapref)) {
4618: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4619: $checkencrypt = 1;
4620: }
4621: }
4622: }
1.484.2.93.2. (raeburn 4623:): }
4624:): if ($checkencrypt) {
4625:): my $currenc = $env{'request.enc'};
4626:): $env{'request.enc'} = 1;
4627:): $shownsymb = &Apache::lonenc::encrypted($symb);
4628:): $shownurl = &Apache::lonenc::encrypted($url);
4629:): if (&Apache::lonnet::symbverify($symb,$url)) {
4630:): $url = $shownurl;
1.484.2.67 raeburn 4631: } else {
1.484.2.93.2. (raeburn 4632:): $url = '';
1.484.2.67 raeburn 4633: }
1.484.2.93.2. (raeburn 4634:): $env{'request.enc'} = $currenc;
4635:): } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4636:): $shownsymb = $symb;
4637:): if ($isexternal) {
4638:): $url =~ s/\#[^#]+$//;
4639:): if ($container eq 'page') {
4640:): $url = &Apache::lonnet::clutter($url);
4641:): }
4642:): }
4643:): $shownurl = $url;
4644:): }
4645:): unless ($env{'request.role.adv'}) {
4646:): if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4647:): $url = '';
4648:): }
4649:): if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4650:): $url = '';
4651:): $hiddenres = 1;
4652:): }
4653:): }
4654:): if ($url ne '') {
4655:): $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.12 raeburn 4656: }
1.484.2.19 raeburn 4657: }
1.484.2.66 raeburn 4658: } elsif ($supplementalflag) {
4659: if ($isexternal) {
4660: if ($url =~ /^([^#]+)#([^#]+)$/) {
4661: $url = $1;
4662: $anchor = $2;
1.484.2.70 raeburn 4663: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.93 raeburn 4664: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4665: if ($hostname ne '') {
4666: $url = 'http://'.$hostname.$url;
4667: }
4668: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4669: }
1.484.2.70 raeburn 4670: $nomodal = 1;
4671: }
4672: }
4673: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4674: if (($ENV{'SERVER_PORT'} == 443) &&
4675: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 4676: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4677: if ($hostname ne '') {
4678: $url = 'http://'.$hostname.$url;
4679: }
4680: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4681: }
1.484.2.70 raeburn 4682: $nomodal = 1;
1.484.2.66 raeburn 4683: }
1.484.2.93.2. 0(raebur 4684:3): } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
4685:3): my $embstyle=&Apache::loncommon::fileembstyle($extension);
4686:3): unless ($embstyle eq 'ssi') {
4687:3): if (($embstyle eq 'img')
4688:3): || ($embstyle eq 'emb')
4689:3): || ($embstyle eq 'wrp')) {
4690:3): $url='/adm/wrapper'.$url;
4691:3): } elsif ($url !~ /\.(sequence|page)$/) {
4692:3): $url='/adm/coursedocs/showdoc'.$url;
4693:3): }
4694:3): }
4695:3): }
4696:3): unless ($allowed && $env{'request.role.adv'}) {
4697:3): if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4698:3): $hiddenres = 1;
4699:3): }
1.484.2.66 raeburn 4700: }
1.329 droeschl 4701: }
1.484.2.67 raeburn 4702: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4703: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4704: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4705: my $foldername=&escape($foldertitle);
4706: my $folderpath=$env{'form.folderpath'};
4707: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4708: if (!$allowed && $supplementalflag) {
4709: $folderpath.=$containerarg.'&'.$foldername;
4710: $url.='folderpath='.&escape($folderpath);
1.484.2.93.2. 0(raebur 4711:3): if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4712:3): $hiddenfolder = 1;
4713:3): }
1.484.2.19 raeburn 4714: } else {
4715: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4716: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4717: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4718: 'parameter_randomorder'))[0]=~/^yes$/i);
4719: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4720: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4721: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4722: 'parameter_encrypturl'))[0]=~/^yes$/i);
4723: unless ($hiddenmap) {
1.484.2.70 raeburn 4724: if (ref($navmapref)) {
4725: unless (ref($$navmapref)) {
4726: $$navmapref = Apache::lonnavmaps::navmap->new();
4727: }
4728: if (ref($$navmapref)) {
4729: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4730: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4731: unless (@resources) {
4732: $hiddenmap = 1;
4733: unless ($env{'request.role.adv'}) {
4734: $url = '';
4735: $hiddenfolder = 1;
4736: }
1.484.2.67 raeburn 4737: }
4738: }
4739: }
4740: }
4741: }
4742: unless ($encryptmap) {
1.484.2.70 raeburn 4743: if ((ref($navmapref)) && (ref($$navmapref))) {
4744: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4745: $encryptmap = 1;
4746: }
1.484.2.67 raeburn 4747: }
4748: }
4749:
4750: # Append randompick number, hidden, and encrypted with ":" to foldername,
4751: # so it gets transferred between levels
4752: $folderpath.=$containerarg.'&'.$foldername.
4753: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4754: unless ($url eq '') {
4755: $url.='folderpath='.&escape($folderpath);
4756: }
1.484.2.19 raeburn 4757: my $rpckchk;
4758: if ($rpicknum) {
4759: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4760: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4761: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4762: }
1.484.2.19 raeburn 4763: }
1.484.2.29 raeburn 4764: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4765: $rand_pick_text =
1.478 raeburn 4766: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4767: $form_param."\n".
1.478 raeburn 4768: $form_common."\n".
1.484.2.67 raeburn 4769: '<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 4770: if ($rpicknum ne '') {
4771: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4772: }
1.484.2.29 raeburn 4773: $rand_pick_text .= '</span></span>'.
4774: $form_end;
1.484.2.30 raeburn 4775: my $ro_set;
1.484.2.67 raeburn 4776: if ($randorder) {
1.484.2.30 raeburn 4777: $ro_set = 'checked="checked"';
4778: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4779: push(@{$filtersref->{'randomorder'}},$orderidx);
4780: }
4781: }
1.484.2.41 raeburn 4782: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4783: $rand_order_text =
1.484.2.29 raeburn 4784: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4785: $form_param."\n".
1.484.2.29 raeburn 4786: $form_common."\n".
1.484.2.67 raeburn 4787: '<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 4788: $form_end;
1.484.2.19 raeburn 4789: }
1.484.2.18 raeburn 4790: } elsif ($supplementalflag && !$allowed) {
1.484.2.93.2. (raeburn 4791:): my $isexttool;
4792:): if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4793:): $url='/adm/wrapper'.$url;
4794:): $isexttool = 1;
4795:): }
1.484.2.19 raeburn 4796: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4797: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4798: if ($title) {
1.484.2.93.2. 0(raebur 4799:3): $url .= '&title='.$encodedtitle;
1.484.2.19 raeburn 4800: }
1.484.2.93.2. (raeburn 4801:): if ((($isexternal) || ($isexttool)) && $orderidx) {
1.484.2.19 raeburn 4802: $url .= '&idx='.$orderidx;
4803: }
1.484.2.66 raeburn 4804: if ($anchor ne '') {
4805: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4806: }
1.329 droeschl 4807: }
1.484.2.19 raeburn 4808: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4809: if ($allowed) {
1.484.2.19 raeburn 4810: my $fileloc =
1.484.2.12 raeburn 4811: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4812: if ($isexternal) {
4813: ($editlink,$extresform) =
1.484.2.67 raeburn 4814: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
1.484.2.93.2. (raeburn 4815:): undef,undef,undef,undef,undef,undef,
4816:): undef,$disabled);
4817:): } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4818:): ($editlink,$extresform) =
4819:): &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4820:): undef,undef,undef,'tool',$coursedom,
4821:): $coursenum,$ltitoolsref,$disabled);
1.484.2.19 raeburn 4822: } elsif (!$isfolder && !$ispage) {
4823: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4824: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4825: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4826: my $suppanchor;
4827: if ($supplementalflag) {
4828: $suppanchor = $anchor;
4829: }
1.484.2.19 raeburn 4830: my $jscall =
1.484.2.12 raeburn 4831: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4832: $switchserver,
1.484.2.14 raeburn 4833: $forceedit,
1.484.2.93.2. (raeburn 4834:): undef,$symb,$shownsymb,
1.484.2.19 raeburn 4835: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4836: $renametitle,$hostname,
4837: '','',1,$suppanchor);
1.484.2.12 raeburn 4838: if ($jscall) {
1.484.2.19 raeburn 4839: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4840: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4841: }
4842: }
4843: }
1.484.2.19 raeburn 4844: $tdalign = ' align="right" valign="top"';
4845: $tdwidth = ' width="80%"';
1.329 droeschl 4846: }
1.408 raeburn 4847: my $reinit;
4848: if ($crstype eq 'Community') {
4849: $reinit = &mt('(re-initialize community to access)');
4850: } else {
4851: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4852: }
4853: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.93.2. 0(raebur 4854:3): my ($link,$nolink);
1.472 raeburn 4855: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.484.2.93.2. 0(raebur 4856:3): if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
4857:3): if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4858:3): $nolink = 1;
4859:3): }
4860:3): }
4861:3): if ($nolink) {
4862:3): $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4863:3): } else {
4864:3): $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4865:3): }
1.469 www 4866: } elsif ($url) {
1.484.2.66 raeburn 4867: if ($anchor ne '') {
4868: if ($supplementalflag) {
4869: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4870: } else {
4871: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4872: }
4873: }
1.484.2.80 raeburn 4874: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4875: $link = 'http://'.$hostname.$url;
4876: } else {
4877: $link = $url;
4878: }
4879: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.93.2. 0(raebur 4880:3): if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
4881:3): if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4882:3): $nolink = 1;
4883:3): }
4884:3): }
4885:3): if ($nolink) {
4886:3): $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4887:3): } elsif ($nomodal) {
1.484.2.70 raeburn 4888: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4889: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4890: } else {
4891: $line.=&Apache::loncommon::modal_link($link,
4892: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4893: }
1.469 www 4894: } else {
4895: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4896: }
1.484.2.19 raeburn 4897: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4898: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.484.2.93.2. 0(raebur 4899:3): if ($nolink) {
4900:3): $line.=$title;
4901:3): } else {
4902:3): $line.='<a href="'.$url.'">'.$title.'</a>';
4903:3): }
4904:3): if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4905:3): my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4906:3): my $editurl = $url;
4907:3): $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4908:3): $line .= ' '.'<a href="'.$editurl.'">'.
4909:3): '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4910:3): '</a>';
4911:3): }
4912:3): if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4913:3): $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4914:3): }
1.469 www 4915: } elsif ($url) {
1.484.2.93.2. 0(raebur 4916:3): if ($nolink) {
4917:3): $line.=$title;
4918:3): } elsif ($nomodal) {
1.484.2.70 raeburn 4919: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4920: $title.'</a>';
4921: } else {
4922: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4923: }
1.484.2.67 raeburn 4924: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4925: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4926: } else {
4927: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4928: }
1.484.2.19 raeburn 4929: $line.="$extresform</td>";
1.478 raeburn 4930: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4931: $rand_order_text = ' ' if ($rand_order_text eq '');
1.484.2.93.2. 0(raebur 4932:3): if ($uploaded && $url && !$isfolder && !$ispage) {
4933:3): if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
4934:3): &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
1.484.2.30 raeburn 4935: }
1.484.2.93.2. 0(raebur 4936:3): }
4937:3): if ($allowed) {
4938:3): my %lt=&Apache::lonlocal::texthash(
4939:3): 'hd' => 'Hidden',
4940:3): 'ec' => 'URL hidden');
4941:3): my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.484.2.30 raeburn 4942: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4943: $hidtext = ' checked="checked"';
1.484.2.93.2. (raeburn 4944:): if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.484.2.30 raeburn 4945: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4946: }
4947: }
1.484.2.93.2. 0(raebur 4948:3): $formhidden = 'edit_hiddenresource_'.$orderidx;
4949:3): $line.=(<<ENDPARMS);
1.329 droeschl 4950: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4951: <form action="/adm/coursedocs" method="post" name="$formhidden">
4952: $form_param
1.478 raeburn 4953: $form_common
1.484.2.67 raeburn 4954: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4955: $form_end
1.484.2.93.2. 0(raebur 4956:3): ENDPARMS
4957:3): if ($folder =~/^supplemental/) {
4958:3): $line.= "\n <td>";
4959:3): } else {
4960:3): if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4961:3): $enctext = ' checked="checked"';
4962:3): if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4963:3): push(@{$filtersref->{'encrypturl'}},$orderidx);
4964:3): }
4965:3): }
4966:3): $formurlhidden = 'edit_encrypturl_'.$orderidx;
4967:3): $line.=(<<ENDPARMS);
1.458 raeburn 4968: <br />
1.484.2.29 raeburn 4969: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4970: $form_param
1.478 raeburn 4971: $form_common
1.484.2.67 raeburn 4972: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4973: $form_end
4974: </td>
1.478 raeburn 4975: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4976: $rand_order_text</td>
1.329 droeschl 4977: ENDPARMS
1.484.2.93.2. 0(raebur 4978:3): }
1.329 droeschl 4979: }
1.379 bisitz 4980: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4981: return $line;
4982: }
4983:
1.484.2.30 raeburn 4984: sub action_restrictions {
4985: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4986: my %denied = (
4987: cut => 0,
4988: copy => 0,
4989: remove => 0,
4990: );
4991: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4992: # no copy for published maps
4993: $denied{'copy'} = 1;
1.484.2.82 raeburn 4994: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4995: unless ($1 eq 'simpleproblem') {
4996: $denied{'copy'} = 1;
4997: }
4998: $denied{'cut'} = 1;
1.484.2.30 raeburn 4999: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
5000: if ($folderpath =~ /^default&[^\&]+$/) {
5001: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
5002: $denied{'remove'} = 1;
5003: }
5004: $denied{'cut'} = 1;
5005: $denied{'copy'} = 1;
5006: }
5007: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
5008: my $group = $1;
5009: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
5010: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5011: $denied{'remove'} = 1;
5012: }
5013: }
5014: $denied{'cut'} = 1;
5015: $denied{'copy'} = 1;
5016: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
5017: my $group = $1;
5018: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
5019: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5020: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5021: if (keys(%groupsettings) > 0) {
5022: $denied{'remove'} = 1;
5023: }
5024: $denied{'cut'} = 1;
5025: $denied{'copy'} = 1;
5026: }
5027: }
5028: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
5029: my $group = $1;
5030: if ($url =~ /group_boards_\Q$group\E/) {
5031: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5032: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5033: if (keys(%groupsettings) > 0) {
5034: if (ref($groupsettings{'functions'}) eq 'HASH') {
5035: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
5036: $denied{'remove'} = 1;
5037: }
5038: }
5039: }
5040: $denied{'cut'} = 1;
5041: $denied{'copy'} = 1;
5042: }
5043: }
5044: }
5045: return %denied;
5046: }
5047:
1.484.2.26 raeburn 5048: sub new_timebased_suffix {
1.484.2.30 raeburn 5049: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 5050: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 5051: if ($type eq 'paste') {
5052: $prefix = $type;
5053: $namespace = 'courseeditor';
1.484.2.56 raeburn 5054: $idtype = 'addcode';
1.484.2.30 raeburn 5055: } elsif ($type eq 'map') {
1.484.2.26 raeburn 5056: $prefix = 'docs';
5057: if ($area eq 'supplemental') {
5058: $prefix = 'supp';
5059: }
5060: $prefix .= $container;
5061: $namespace = 'uploadedmaps';
5062: } else {
5063: $prefix = $type;
5064: $namespace = 'templated';
1.484.2.15 raeburn 5065: }
5066: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 5067: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 5068: if (!$suffix) {
1.484.2.30 raeburn 5069: if ($type eq 'paste') {
5070: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
5071: } elsif ($type eq 'map') {
1.484.2.26 raeburn 5072: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
5073: } elsif ($type eq 'smppg') {
5074: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.484.2.93.2. (raeburn 5075:): } elsif ($type eq 'exttool') {
5076:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.484.2.26 raeburn 5077: } else {
1.484.2.42 raeburn 5078: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 5079: }
1.484.2.15 raeburn 5080: if ($error) {
5081: $errtext .= '<br />'.$error;
5082: }
5083: }
5084: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 5085: $locknotfreed =
5086: '<div class="LC_error">'.
5087: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 5088: if ($type eq 'paste') {
1.484.2.57 raeburn 5089: if ($freedlock eq 'nolock') {
5090: $locknotfreed =
5091: '<div class="LC_error">'.
5092: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
5093:
1.484.2.60 raeburn 5094: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 5095: } else {
5096: $locknotfreed .=
5097: &mt('This will prevent addition of items to the clipboard until your next log-in.');
5098: }
1.484.2.30 raeburn 5099: } elsif ($type eq 'map') {
1.484.2.57 raeburn 5100: $locknotfreed .=
5101: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 5102: } elsif ($type eq 'smppg') {
5103: $locknotfreed .=
5104: &mt('This will prevent creation of additional simple pages in this course.');
1.484.2.93.2. (raeburn 5105:): } elsif ($type eq 'exttool') {
5106:): $locknotfreed .=
5107:): &mt('This will prevent creation of additional external tools in this course.');
1.484.2.26 raeburn 5108: } else {
5109: $locknotfreed .=
1.484.2.42 raeburn 5110: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 5111: }
1.484.2.30 raeburn 5112: unless ($type eq 'paste') {
5113: $locknotfreed .=
1.484.2.38 raeburn 5114: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
5115: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 5116: }
5117: $locknotfreed .= '</div>';
1.484.2.15 raeburn 5118: }
5119: return ($suffix,$errtext,$locknotfreed);
5120: }
5121:
1.329 droeschl 5122: =pod
5123:
5124: =item tiehash()
5125:
5126: tie the hash
5127:
5128: =cut
5129:
5130: sub tiehash {
5131: my ($mode)=@_;
5132: $hashtied=0;
5133: if ($env{'request.course.fn'}) {
5134: if ($mode eq 'write') {
5135: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5136: &GDBM_WRCREAT(),0640)) {
5137: $hashtied=2;
5138: }
5139: } else {
5140: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5141: &GDBM_READER(),0640)) {
5142: $hashtied=1;
5143: }
5144: }
1.364 bisitz 5145: }
1.329 droeschl 5146: }
5147:
5148: sub untiehash {
5149: if ($hashtied) { untie %hash; }
5150: $hashtied=0;
5151: return OK;
5152: }
5153:
5154:
5155:
5156:
5157: sub checkonthis {
1.484.2.78 raeburn 5158: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 5159: $url=&unescape($url);
5160: $alreadyseen{$url}=1;
5161: $r->rflush();
5162: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
5163: $r->print("\n<br />");
5164: if ($level==0) {
5165: $r->print("<br />");
5166: }
5167: for (my $i=0;$i<=$level*5;$i++) {
5168: $r->print(' ');
5169: }
5170: $r->print('<a href="'.$url.'" target="cat">'.
5171: ($title?$title:$url).'</a> ');
5172: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 5173: my $updated;
5174: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
5175: ($url !~ /\.\d+\.\w+$/)) {
5176: $updated = &Apache::lonnet::remove_stale_resfile($url);
5177: }
1.329 droeschl 5178: my $result=&Apache::lonnet::repcopy(
5179: &Apache::lonnet::filelocation('',$url));
5180: if ($result eq 'ok') {
5181: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 5182: if ($updated) {
5183: $r->print('<br />');
5184: for (my $i=0;$i<=$level*5;$i++) {
5185: $r->print(' ');
5186: }
5187: $r->print('- '.&mt('Outdated copy removed'));
5188: }
1.329 droeschl 5189: $r->rflush();
5190: &Apache::lonnet::countacc($url);
5191: $url=~/\.(\w+)$/;
5192: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
5193: $r->print('<br />');
5194: $r->rflush();
5195: for (my $i=0;$i<=$level*5;$i++) {
5196: $r->print(' ');
5197: }
5198: $r->print('- '.&mt('Rendering:').' ');
5199: my ($errorcount,$warningcount)=split(/:/,
5200: &Apache::lonnet::ssi_body($url,
5201: ('grade_target'=>'web',
5202: 'return_only_error_and_warning_counts' => 1)));
5203: if (($errorcount) ||
5204: ($warningcount)) {
5205: if ($errorcount) {
1.369 bisitz 5206: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 5207: &mt('[quant,_1,error]',$errorcount).'</span>');
5208: }
5209: if ($warningcount) {
5210: $r->print('<span class="LC_warning">'.
5211: &mt('[quant,_1,warning]',$warningcount).'</span>');
5212: }
5213: } else {
5214: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
5215: }
5216: $r->rflush();
5217: }
5218: my $dependencies=
5219: &Apache::lonnet::metadata($url,'dependencies');
5220: foreach my $dep (split(/\,/,$dependencies)) {
5221: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 5222: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 5223: }
5224: }
5225: } elsif ($result eq 'unavailable') {
5226: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
5227: } elsif ($result eq 'not_found') {
5228: unless ($url=~/\$/) {
1.484.2.19 raeburn 5229: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 5230: } else {
1.366 bisitz 5231: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 5232: }
5233: } else {
5234: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
5235: }
1.484.2.78 raeburn 5236: if (($updated) && ($result ne 'ok')) {
5237: $r->print('<br />'.&mt('Outdated copy removed'));
5238: }
1.329 droeschl 5239: }
5240: }
5241: }
5242:
5243:
5244:
5245: =pod
5246:
5247: =item list_symbs()
5248:
1.484.2.3 raeburn 5249: List Content Identifiers
1.329 droeschl 5250:
5251: =cut
5252:
5253: sub list_symbs {
5254: my ($r) = @_;
5255:
1.408 raeburn 5256: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5257: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
5258: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
5259: $r->print(&startContentScreen('tools'));
1.329 droeschl 5260: my $navmap = Apache::lonnavmaps::navmap->new();
5261: if (!defined($navmap)) {
5262: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
5263: '<div class="LC_error">'.
5264: &mt('Unable to retrieve information about course contents').
5265: '</div>');
1.408 raeburn 5266: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 5267: } else {
1.484 raeburn 5268: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
5269: &Apache::loncommon::start_data_table().
5270: &Apache::loncommon::start_data_table_header_row().
5271: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
5272: &Apache::loncommon::end_data_table_header_row()."\n");
5273: my $count;
1.329 droeschl 5274: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 5275: $r->print(&Apache::loncommon::start_data_table_row().
5276: '<td>'.$res->compTitle().'</td>'.
5277: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 5278: &Apache::loncommon::end_data_table_row());
1.484 raeburn 5279: $count ++;
5280: }
5281: if (!$count) {
5282: $r->print(&Apache::loncommon::start_data_table_row().
5283: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
5284: &Apache::loncommon::end_data_table_row());
1.329 droeschl 5285: }
1.484 raeburn 5286: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 5287: }
1.484.2.19 raeburn 5288: $r->print(&endContentScreen());
1.329 droeschl 5289: }
5290:
1.484.2.93.2. (raeburn 5291:): sub short_urls {
5292:): my ($r,$canedit) = @_;
5293:): my $crstype = &Apache::loncommon::course_type();
5294:): my $formname = 'shortenurl';
5295:): $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5296:): $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5297:): $r->print(&startContentScreen('tools'));
5298:): my ($navmap,$errormsg) =
5299:): &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5300:): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5301:): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5302:): my (%maps,%resources,%titles);
5303:): if (!ref($navmap)) {
5304:): $r->print($errormsg.
5305:): &endContentScreen());
5306:): return '';
5307:): } else {
5308:): $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
5309:): $r->rflush();
5310:): my $readonly;
5311:): if ($canedit) {
5312:): my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
5313:): if ($numnew) {
5314:): $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
5315:): }
5316:): if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
5317:): $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
5318:): foreach my $error (@{$errors}) {
5319:): $r->print('<li>'.$error.'</li>');
5320:): }
5321:): $r->print('</ul><br />');
5322:): }
5323:): } else {
5324:): $readonly = 1;
5325:): }
5326:): my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
5327:): $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
5328:): undef,undef,undef,undef,undef,\%currtiny,$readonly));
5329:): }
5330:): $r->print(&endContentScreen());
5331:): }
5332:):
1.484.2.78 raeburn 5333: sub contentverifyform {
5334: my ($r) = @_;
5335: my $crstype = &Apache::loncommon::course_type();
5336: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5337: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5338: $r->print(&startContentScreen('tools'));
5339: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5340: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
5341: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
5342: ' <span class="LC_nobreak">'.
5343: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
5344: &mt('No').'</label>'.(' 'x2).
5345: '<label><input type="radio" name="checkstale" value="1" />'.
5346: &mt('Yes').'</label></span></p><p>'.
1.484.2.90 raeburn 5347: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.484.2.78 raeburn 5348: '<input type="hidden" value="1" name="tools" />'.
5349: '<input type="hidden" value="1" name="verify" /></p></form>');
5350: $r->print(&endContentScreen());
5351: return;
5352: }
1.329 droeschl 5353:
5354: sub verifycontent {
1.484.2.78 raeburn 5355: my ($r,$checkstale) = @_;
1.408 raeburn 5356: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 5357: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5358: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 5359: $r->print(&startContentScreen('tools'));
5360: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 5361: $hashtied=0;
5362: undef %alreadyseen;
5363: %alreadyseen=();
5364: &tiehash();
1.484 raeburn 5365:
1.329 droeschl 5366: foreach my $key (keys(%hash)) {
5367: if ($hash{$key}=~/\.(page|sequence)$/) {
5368: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5369: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 5370: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 5371: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 5372: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 5373: }
5374: }
5375: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 5376: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 5377: }
5378: }
5379: &untiehash();
1.442 www 5380: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 5381: $r->print(&endContentScreen());
1.329 droeschl 5382: }
5383:
5384:
5385: sub devalidateversioncache {
5386: my $src=shift;
5387: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5388: &Apache::lonnet::clutter($src));
5389: }
5390:
5391: sub checkversions {
1.484.2.67 raeburn 5392: my ($r,$canedit) = @_;
1.408 raeburn 5393: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 5394: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5395: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 5396: $r->print(&startContentScreen('tools'));
1.442 www 5397:
1.329 droeschl 5398: my $header='';
5399: my $startsel='';
5400: my $monthsel='';
5401: my $weeksel='';
5402: my $daysel='';
5403: my $allsel='';
5404: my %changes=();
5405: my $starttime=0;
5406: my $haschanged=0;
5407: my %setversions=&Apache::lonnet::dump('resourceversions',
5408: $env{'course.'.$env{'request.course.id'}.'.domain'},
5409: $env{'course.'.$env{'request.course.id'}.'.num'});
5410:
5411: $hashtied=0;
5412: &tiehash();
1.484.2.67 raeburn 5413: if ($canedit) {
5414: my %newsetversions=();
5415: if ($env{'form.setmostrecent'}) {
5416: $haschanged=1;
5417: foreach my $key (keys(%hash)) {
5418: if ($key=~/^ids\_(\/res\/.+)$/) {
5419: $newsetversions{$1}='mostrecent';
5420: &devalidateversioncache($1);
5421: }
1.329 droeschl 5422: }
1.484.2.67 raeburn 5423: } elsif ($env{'form.setcurrent'}) {
5424: $haschanged=1;
5425: foreach my $key (keys(%hash)) {
5426: if ($key=~/^ids\_(\/res\/.+)$/) {
5427: my $getvers=&Apache::lonnet::getversion($1);
5428: if ($getvers>0) {
5429: $newsetversions{$1}=$getvers;
5430: &devalidateversioncache($1);
5431: }
5432: }
1.329 droeschl 5433: }
1.484.2.67 raeburn 5434: } elsif ($env{'form.setversions'}) {
5435: $haschanged=1;
5436: foreach my $key (keys(%env)) {
5437: if ($key=~/^form\.set_version_(.+)$/) {
5438: my $src=$1;
5439: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5440: $newsetversions{$src}=$env{$key};
5441: &devalidateversioncache($src);
5442: }
5443: }
1.329 droeschl 5444: }
1.484.2.67 raeburn 5445: }
5446: if ($haschanged) {
5447: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5448: $env{'course.'.$env{'request.course.id'}.'.domain'},
5449: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5450: $r->print(&Apache::loncommon::confirmwrapper(
5451: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5452: } else {
5453: $r->print(&Apache::loncommon::confirmwrapper(
5454: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
5455: }
5456: &mark_hash_old();
5457: }
5458: &changewarning($r,'');
1.329 droeschl 5459: }
5460: if ($env{'form.timerange'} eq 'all') {
5461: # show all documents
1.484.2.34 raeburn 5462: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 5463: $allsel=' selected="selected"';
1.329 droeschl 5464: foreach my $key (keys(%hash)) {
5465: if ($key=~/^ids\_(\/res\/.+)$/) {
5466: my $src=$1;
5467: $changes{$src}=1;
5468: }
5469: }
5470: } else {
5471: # show documents which changed
5472: %changes=&Apache::lonnet::dump
5473: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5474: $env{'course.'.$env{'request.course.id'}.'.num'});
5475: my $firstkey=(keys(%changes))[0];
5476: unless ($firstkey=~/^error\:/) {
5477: unless ($env{'form.timerange'}) {
5478: $env{'form.timerange'}=604800;
5479: }
5480: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5481: .&mt('seconds');
5482: if ($env{'form.timerange'}==-1) {
5483: $seltext='since start of course';
1.484.2.19 raeburn 5484: $startsel=' selected="selected"';
1.329 droeschl 5485: $env{'form.timerange'}=time;
5486: }
5487: $starttime=time-$env{'form.timerange'};
5488: if ($env{'form.timerange'}==2592000) {
5489: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 5490: $monthsel=' selected="selected"';
1.329 droeschl 5491: } elsif ($env{'form.timerange'}==604800) {
5492: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 5493: $weeksel=' selected="selected"';
1.329 droeschl 5494: } elsif ($env{'form.timerange'}==86400) {
5495: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 5496: $daysel=' selected="selected"';
1.329 droeschl 5497: }
5498: $header=&mt('Content changed').' '.$seltext;
5499: } else {
5500: $header=&mt('No content modifications yet.');
5501: }
5502: }
5503: %setversions=&Apache::lonnet::dump('resourceversions',
5504: $env{'course.'.$env{'request.course.id'}.'.domain'},
5505: $env{'course.'.$env{'request.course.id'}.'.num'});
5506: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5507: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5508: 'lm' => 'Version changes since last Month',
5509: 'lw' => 'Version changes since last Week',
5510: 'sy' => 'Version changes since Yesterday',
5511: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5512: 'cd' => 'Change display',
1.329 droeschl 5513: 'sd' => 'Display',
5514: 'fi' => 'File',
5515: 'md' => 'Modification Date',
5516: 'mr' => 'Most recently published Version',
1.408 raeburn 5517: 've' => 'Version used in '.$crstype,
5518: 'vu' => 'Set Version to be used in '.$crstype,
5519: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5520: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5521: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5522: 'di' => 'Differences',
1.484 raeburn 5523: 'save' => 'Save changes',
5524: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5525: 'act' => 'Actions');
1.484.2.67 raeburn 5526: my ($disabled,$readonly);
5527: unless ($canedit) {
5528: $disabled = 'disabled="disabled"';
5529: $readonly = 1;
5530: }
1.329 droeschl 5531: $r->print(<<ENDHEADERS);
1.484 raeburn 5532: <h4 class="LC_info">$header</h4>
1.329 droeschl 5533: <form action="/adm/coursedocs" method="post">
5534: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5535: <div class="LC_left_float">
1.479 golterma 5536: <fieldset>
1.484 raeburn 5537: <legend>$lt{'cd'}</legend>
1.329 droeschl 5538: <select name="timerange">
1.484.2.19 raeburn 5539: <option value='all'$allsel>$lt{'al'}</option>
5540: <option value="-1"$startsel>$lt{'st'}</option>
5541: <option value="2592000"$monthsel>$lt{'lm'}</option>
5542: <option value="604800"$weeksel>$lt{'lw'}</option>
5543: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5544: </select>
5545: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5546: </fieldset>
5547: </div>
5548: <div class="LC_left_float">
5549: <fieldset>
5550: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 5551: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5552: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5553: </fieldset>
5554: </div>
5555: <br clear="all" />
5556: <hr />
5557: <h4>$lt{'vers'}</h4>
1.329 droeschl 5558: ENDHEADERS
1.479 golterma 5559: #number of columns for version history
1.484.2.44 raeburn 5560: my %changedbytime;
5561: foreach my $key (keys(%changes)) {
5562: #excludes not versionable problems from resource version history:
5563: next if ($key =~ /^\/res\/lib\/templates/);
5564: my $chg;
5565: if ($env{'form.timerange'} eq 'all') {
5566: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5567: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5568: } else {
5569: $chg = $changes{$key};
5570: next if ($chg < $starttime);
5571: }
5572: push(@{$changedbytime{$chg}},$key);
5573: }
5574: if (keys(%changedbytime) == 0) {
5575: &untiehash();
5576: $r->print(&mt('No content changes in imported content in specified time frame').
5577: &endContentScreen());
5578: return;
5579: }
1.479 golterma 5580: $r->print(
1.484.2.67 raeburn 5581: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5582: &Apache::loncommon::start_data_table().
5583: &Apache::loncommon::start_data_table_header_row().
5584: '<th>'.&mt('Resources').'</th>'.
5585: "<th>$lt{'mr'}</th>".
5586: "<th>$lt{'ve'}</th>".
5587: "<th>$lt{'vu'}</th>".
5588: '<th>'.&mt('History').'</th>'.
5589: &Apache::loncommon::end_data_table_header_row()
5590: );
1.484.2.44 raeburn 5591: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5592: foreach my $key (sort(@{$changedbytime{$chg}})) {
5593: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5594: my $currentversion=&Apache::lonnet::getversion($key);
5595: if ($currentversion<0) {
5596: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5597: }
5598: my $linkurl=&Apache::lonnet::clutter($key);
5599: $r->print(
5600: &Apache::loncommon::start_data_table_row().
5601: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5602: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5603: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5604: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5605: '<td align="right">'
5606: );
5607: # Used in course
5608: my $usedversion=$hash{'version_'.$linkurl};
5609: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 5610: if ($usedversion != $currentversion) {
1.479 golterma 5611: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 5612: } else {
1.479 golterma 5613: $r->print($usedversion);
5614: }
1.329 droeschl 5615: } else {
1.484.2.19 raeburn 5616: $r->print($currentversion);
1.329 droeschl 5617: }
1.484.2.44 raeburn 5618: $r->print('</td><td title="'.$lt{'vu'}.'">');
5619: # Set version
5620: $r->print(&Apache::loncommon::select_form(
5621: $setversions{$linkurl},
5622: 'set_version_'.$linkurl,
5623: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5624: '' => '',
5625: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 5626: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 5627: my $lastold=1;
5628: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5629: my $url=$root.'.'.$prevvers.'.'.$extension;
5630: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5631: $lastold=$prevvers;
5632: }
5633: }
5634: $r->print('</td>');
5635: # List all available versions
5636: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5637: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5638: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 5639: $r->print(
1.484.2.44 raeburn 5640: '<span class="LC_nobreak">'
5641: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5642: .&mt('Version [_1]',$prevvers).'</a>'
5643: .' ('.&Apache::lonlocal::locallocaltime(
5644: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5645: .')');
5646: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5647: $r->print(
5648: ' <a href="/adm/diff?filename='.
5649: &Apache::lonnet::clutter($root.'.'.$extension).
5650: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5651: '" target="diffs">'.&mt('Diffs').'</a>');
5652: }
5653: $r->print('</span><br />');
1.329 droeschl 5654: }
1.484.2.44 raeburn 5655: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 5656: }
1.329 droeschl 5657: }
1.484.2.19 raeburn 5658: $r->print(
5659: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 5660: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5661: '</form>'
5662: );
1.329 droeschl 5663:
5664: &untiehash();
1.484.2.19 raeburn 5665: $r->print(&endContentScreen());
1.484.2.44 raeburn 5666: return;
1.329 droeschl 5667: }
5668:
5669: sub mark_hash_old {
5670: my $retie_hash=0;
5671: if ($hashtied) {
5672: $retie_hash=1;
5673: &untiehash();
5674: }
5675: &tiehash('write');
5676: $hash{'old'}=1;
5677: &untiehash();
5678: if ($retie_hash) { &tiehash(); }
5679: }
5680:
5681: sub is_hash_old {
5682: my $untie_hash=0;
5683: if (!$hashtied) {
5684: $untie_hash=1;
5685: &tiehash();
5686: }
5687: my $return=$hash{'old'};
5688: if ($untie_hash) { &untiehash(); }
5689: return $return;
5690: }
5691:
5692: sub changewarning {
5693: my ($r,$postexec,$message,$url)=@_;
5694: if (!&is_hash_old()) { return; }
5695: my $pathvar='folderpath';
5696: my $path=&escape($env{'form.folderpath'});
5697: if (!defined($url)) {
5698: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5699: }
5700: my $course_type = &Apache::loncommon::course_type();
5701: if (!defined($message)) {
5702: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5703: }
1.484.2.93.2. 2(raebur 5704:3): my $windowname = 'loncapaclient';
5705:3): if ($env{'request.lti.login'}) {
5706:3): $windowname .= 'lti';
5707:3): }
1.329 droeschl 5708: $r->print("\n\n".
1.372 bisitz 5709: '<script type="text/javascript">'."\n".
5710: '// <![CDATA['."\n".
5711: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5712: '// ]]>'."\n".
1.369 bisitz 5713: '</script>'."\n".
1.484.2.93.2. 2(raebur 5714:3): '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5715: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5716: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5717: &mt($message,' <input type="hidden" name="'.
5718: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5719: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5720: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5721: }
5722:
5723:
5724: sub init_breadcrumbs {
1.484.2.44 raeburn 5725: my ($form,$text,$help)=@_;
1.329 droeschl 5726: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5727: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5728: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5729: faq=>273,
5730: bug=>'Instructor Interface',
1.484.2.44 raeburn 5731: help => $help});
1.329 droeschl 5732: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5733: text=>$text,
5734: faq=>273,
5735: bug=>'Instructor Interface'});
5736: }
5737:
1.441 www 5738: # subroutine to list form elements
5739: sub create_list_elements {
5740: my @formarr = @_;
5741: my $list = '';
1.484.2.12 raeburn 5742: foreach my $button (@formarr){
5743: foreach my $picture (keys(%{$button})) {
5744: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5745: }
5746: }
5747: return $list;
5748: }
1.329 droeschl 5749:
1.441 www 5750: # subroutine to create ul from list elements
5751: sub create_form_ul {
5752: my $list = shift;
5753: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5754: return $ul;
5755: }
1.329 droeschl 5756:
1.442 www 5757: #
5758: # Start tabs
5759: #
5760:
5761: sub startContentScreen {
1.484 raeburn 5762: my ($mode) = @_;
5763: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5764: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5765: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5766: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5767: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5768: } else {
1.484.2.34 raeburn 5769: $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 5770: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5771: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5772: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5773: }
5774: $output .= "\n".'</ul>'."\n";
5775: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5776: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5777: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5778: return $output;
1.442 www 5779: }
5780:
5781: #
5782: # End tabs
5783: #
5784:
5785: sub endContentScreen {
1.484 raeburn 5786: return '</div></div></div>';
1.442 www 5787: }
1.329 droeschl 5788:
1.446 www 5789: sub supplemental_base {
1.484.2.33 raeburn 5790: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5791: }
5792:
1.329 droeschl 5793: sub handler {
5794: my $r = shift;
5795: &Apache::loncommon::content_type($r,'text/html');
5796: $r->send_http_header;
5797: return OK if $r->header_only;
1.484 raeburn 5798:
5799: # get course data
1.408 raeburn 5800: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5801: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5802: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5803:
5804: # graphics settings
5805: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5806:
1.443 www 5807: #
1.329 droeschl 5808: # --------------------------------------------- Initialize help topics for this
5809: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.484.2.93.2. (raeburn 5810:): 'Adding_External_Resource','Adding_External_Tool',
5811:): 'Navigate_Content','Adding_Folders','Docs_Overview',
5812:): 'Load_Map','Supplemental','Score_Upload_Form',
5813:): 'Adding_Pages','Importing_LON-CAPA_Resource',
5814:): 'Importing_IMS_Course','Uploading_From_Harddrive',
5815:): 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5816: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5817: }
5818: # Composite help files
5819: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5820: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5821: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5822: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5823: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5824: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5825: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5826: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5827: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5828: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5829:
1.484.2.67 raeburn 5830: my ($allowed,$canedit,$canview,$disabled);
1.484.2.93.2. 0(raebur 5831:3): # does this user have privileges to modify content.
5832:3): if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 5833: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.484.2.93.2. 0(raebur 5834:3): unless ($r->uri eq '/adm/supplemental') {
1.484.2.67 raeburn 5835: $allowed = 1;
1.484.2.93.2. 0(raebur 5836:3): }
5837:3): $canedit = 1;
5838:3): $canview = 1;
5839:3): } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5840:3): # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5841:3): unless ($r->uri eq '/adm/supplemental') {
1.484.2.67 raeburn 5842: $allowed = 1;
5843: }
1.484.2.93.2. 0(raebur 5844:3): $canview = 1;
1.484.2.67 raeburn 5845: }
5846: unless ($canedit) {
5847: $disabled = ' disabled="disabled"';
1.472 raeburn 5848: }
1.484.2.53 raeburn 5849: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5850: if ($env{'form.inhibitmenu'}) {
5851: unless ($env{'form.inhibitmenu'} eq 'yes') {
5852: delete($env{'form.inhibitmenu'});
5853: }
5854: }
5855:
1.484.2.53 raeburn 5856: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5857: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5858: if (!$canedit) {
5859: &verifycontent($r);
5860: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5861: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5862: text=>'Results',
5863: faq=>273,
5864: bug=>'Instructor Interface'});
5865: &verifycontent($r,$env{'form.checkstale'});
5866: } else {
5867: &contentverifyform($r);
5868: }
1.329 droeschl 5869: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5870: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5871: &list_symbs($r);
1.484.2.93.2. (raeburn 5872:): } elsif ($allowed && $env{'form.shorturls'}) {
5873:): &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5874:): &short_urls($r,$canedit);
1.329 droeschl 5875: } elsif ($allowed && $env{'form.docslog'}) {
5876: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5877: my $folder = $env{'form.folder'};
5878: if ($folder eq '') {
5879: $folder='default';
5880: }
1.484.2.67 raeburn 5881: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5882: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5883: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5884: &checkversions($r,$canedit);
5885: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5886: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5887: &dumpcourse($r);
5888: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5889: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5890: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5891: } else {
1.445 www 5892: #
5893: # Done catching special calls
1.484 raeburn 5894: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5895: # Get the parameters that may be needed
5896: #
5897: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.93.2. 0(raebur 5898:3): ['folderpath','title',
1.484.2.19 raeburn 5899: 'forcesupplement','forcestandard',
5900: 'tools','symb','command','supppath']);
1.445 www 5901:
1.484.2.78 raeburn 5902: foreach my $item ('forcesupplement','forcestandard','tools') {
5903: next if ($env{'form.'.$item} eq '');
5904: unless ($env{'form.'.$item} eq '1') {
5905: delete($env{'form.'.$item});
5906: }
5907: }
5908:
5909: if ($env{'form.command'}) {
5910: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5911: delete($env{'form.command'});
5912: }
5913: }
5914:
5915: if ($env{'form.symb'}) {
5916: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5917: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5918: delete($env{'form.symb'});
5919: }
5920: }
5921:
1.445 www 5922: # standard=1: this is a "new-style" course with an uploaded map as top level
5923: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5924:
5925: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5926:
1.484 raeburn 5927: # Decide whether this should display supplemental or main content or utilities
1.445 www 5928: # supplementalflag=1: show supplemental documents
5929: # supplementalflag=0: show standard documents
1.484 raeburn 5930: # toolsflag=1: show utilities
1.445 www 5931:
1.484.2.39 raeburn 5932: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5933: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5934: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5935: $supplementalflag=0;
5936: }
5937: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5938: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5939: unless ($allowed) { $supplementalflag=1; }
5940: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5941: my $toolsflag=0;
5942: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5943:
1.484.2.78 raeburn 5944: if ($env{'form.folderpath'} ne '') {
1.484.2.93.2. 0(raebur 5945:3): &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.484.2.78 raeburn 5946: }
5947:
1.484.2.93.2. 0(raebur 5948:3): my $backto_supppath;
1.484.2.78 raeburn 5949: if ($env{'form.supppath'} ne '') {
1.484.2.93.2. 0(raebur 5950:3): if ($supplementalflag && $allowed) {
5951:3): $backto_supppath = &validate_supppath($coursenum,$coursedom);
5952:3): }
1.484.2.78 raeburn 5953: }
5954:
1.329 droeschl 5955: my $script='';
5956: my $showdoc=0;
1.457 raeburn 5957: my $addentries = {};
1.475 raeburn 5958: my $container;
1.329 droeschl 5959: my $containertag;
1.484.2.17 raeburn 5960: my $pathitem;
1.484.2.93.2. (raeburn 5961:): my %ltitools;
2(raebur 5962:3): my $posslti;
1.484.2.67 raeburn 5963: my $hiddentop;
5964: my $navmap;
5965: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5966:
1.464 www 5967: # Do we directly jump somewhere?
1.484.2.21 raeburn 5968: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5969: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5970: $env{'form.folderpath'}=
1.484.2.67 raeburn 5971: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5972: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5973: $env{'form.command'}.'_'.$env{'form.symb'}});
1.484.2.93.2. 0(raebur 5974:3): } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 5975: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5976: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.484.2.93.2. 0(raebur 5977:3): $env{'form.command'}.'_'.$backto_supppath});
1.466 www 5978: }
1.472 raeburn 5979: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5980: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5981: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5982: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5983: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5984: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5985: } elsif ($env{'form.command'} eq 'contents') {
5986: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5987: } elsif ($env{'form.command'} eq 'home') {
5988: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5989: }
5990:
1.484.2.23 raeburn 5991:
1.445 www 5992: # Where do we store these for when we come back?
5993: my $stored_folderpath='docs_folderpath';
5994: if ($supplementalflag) {
5995: $stored_folderpath='docs_sup_folderpath';
5996: }
1.464 www 5997:
1.484.2.19 raeburn 5998: # No folderpath, and in edit mode, see if we have something stored
5999: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 6000: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 6001: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 6002:
6003: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
6004: if ($supplementalflag) {
6005: undef($env{'form.folderpath'}) if ($1 eq 'default');
6006: } else {
6007: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
6008: }
6009: } else {
1.484.2.19 raeburn 6010: undef($env{'form.folderpath'});
6011: }
1.484.2.92 raeburn 6012: if ($env{'form.folderpath'} ne '') {
1.484.2.93.2. 0(raebur 6013:3): &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.484.2.92 raeburn 6014: }
1.329 droeschl 6015: }
1.446 www 6016:
6017: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 6018: if (!$allowed) {
1.446 www 6019: unless ($env{'form.folderpath'} =~ /^supplemental/) {
6020: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 6021: }
6022: }
1.446 www 6023: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 6024: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 6025: $env{'form.folderpath'} = &supplemental_base()
6026: .'&'.
1.329 droeschl 6027: $env{'form.folderpath'};
6028: }
1.484.2.67 raeburn 6029: # If allowed and user's role is not advanced check folderpath is not hidden
1.484.2.93.2. 0(raebur 6030:3): my $hidden_and_empty;
6031:3): if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
6032:3): my ($folderurl,$foldername,$hiddenfolder);
1.484.2.67 raeburn 6033: my @pathitems = split(/\&/,$env{'form.folderpath'});
6034: my $folder = $pathitems[-2];
6035: if ($folder eq '') {
6036: undef($env{'form.folderpath'});
6037: } else {
6038: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.87 raeburn 6039: if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 6040: $folderurl .= '.page';
6041: } else {
6042: $folderurl .= '.sequence';
6043: }
1.484.2.93.2. 0(raebur 6044:3): if ($supplementalflag) {
6045:3): ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
6046:3): $foldername = &HTML::Entities::decode(&unescape($foldername));
6047:3): my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
6048:3): if (ref($supplemental) eq 'HASH') {
6049:3): my ($suppmap,$suppmapnum);
6050:3): if ($folder eq 'supplemental') {
6051:3): $suppmap = 'default';
6052:3): $suppmapnum = 0;
6053:3): } elsif ($folder =~ /^supplemental_(\d+)$/) {
6054:3): $suppmap = $1;
6055:3): $suppmapnum = $suppmap;
6056:3): }
6057:3): if ($hiddenfolder) {
6058:3): my $hascontent;
6059:3): foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
6060:3): if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
6061:3): $hascontent = 1;
6062:3): } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
6063:3): foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
6064:3): if ($id =~ /^$suppmapnum\:/) {
6065:3): $hascontent = 1;
6066:3): last;
6067:3): }
6068:3): }
6069:3): }
6070:3): last if ($hascontent);
6071:3): }
6072:3): unless ($hascontent) {
6073:3): if ($foldername ne '') {
6074:3): $hidden_and_empty = $foldername;
6075:3): } else {
6076:3): $hidden_and_empty = $folder;
6077:3): }
6078:3): }
1.484.2.67 raeburn 6079: }
6080: }
1.484.2.93.2. 0(raebur 6081:3): } else {
6082:3): unless (ref($navmap)) {
6083:3): $navmap = Apache::lonnavmaps::navmap->new();
6084:3): }
6085:3): ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
6086:3): $foldername = &HTML::Entities::decode(&unescape($foldername));
6087:3): if (ref($navmap)) {
6088:3): if ($hiddenfolder ||
6089:3): (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
6090:3): my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
6091:3): unless (@resources) {
6092:3): if ($foldername ne '') {
6093:3): $hidden_and_empty = $foldername;
6094:3): } else {
6095:3): $hidden_and_empty = $folder;
6096:3): }
6097:3): }
6098:3): }
6099:3): }
6100:3): }
6101:3): if ($hidden_and_empty ne '') {
6102:3): splice(@pathitems,-2);
6103:3): if (@pathitems) {
6104:3): $env{'form.folderpath'} = join('&',@pathitems);
6105:3): } else {
6106:3): undef($env{'form.folderpath'});
6107:3): }
1.484.2.67 raeburn 6108: }
6109: }
6110: }
6111:
1.446 www 6112: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 6113: unless ($env{'form.folderpath'}) {
1.446 www 6114: if ($supplementalflag) {
6115: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 6116: } elsif ($allowed) {
6117: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 6118: }
1.472 raeburn 6119: }
1.446 www 6120:
1.445 www 6121: # Store this
1.484 raeburn 6122: unless ($toolsflag) {
1.484.2.67 raeburn 6123: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 6124: &Apache::loncommon::store_course_settings($stored_folderpath,
6125: {'folderpath' => 'scalar'});
6126: }
6127: my $folderpath;
1.484 raeburn 6128: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 6129: $folderpath = $env{'form.folderpath'};
6130: my (@folders)=split('&',$env{'form.folderpath'});
6131: $env{'form.foldername'}=&unescape(pop(@folders));
6132: if ($env{'form.foldername'} =~ /\:1$/) {
6133: $container = 'page';
6134: } else {
6135: $container = 'sequence';
6136: }
6137: $env{'form.folder'}=pop(@folders);
1.484 raeburn 6138: } else {
1.484.2.19 raeburn 6139: if ($env{'form.folder'} eq '' ||
6140: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 6141: if ($env{'form.folder'} eq 'supplemental') {
6142: $folderpath=&supplemental_base();
6143: } elsif (!$hiddentop) {
6144: $folderpath='default&'.
6145: &escape(&mt('Main Content').':::::');
6146: }
1.484 raeburn 6147: }
6148: }
1.484.2.19 raeburn 6149: $containertag = '<input type="hidden" name="folderpath" value="" />';
6150: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 6151: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
6152: $showdoc='/'.$1;
6153: }
6154: if ($showdoc) { # got called in sequence from course
6155: $allowed=0;
6156: } else {
1.484.2.67 raeburn 6157: if ($canedit) {
1.484 raeburn 6158: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
6159: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 6160: }
6161: }
1.329 droeschl 6162: }
6163:
1.344 bisitz 6164: # get personal data
1.329 droeschl 6165: my $uname=$env{'user.name'};
6166: my $udom=$env{'user.domain'};
6167: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
6168:
6169: if ($allowed) {
1.484 raeburn 6170: if ($toolsflag) {
6171: $script .= &inject_data_js();
6172: my ($home,$other,%outhash)=&authorhosts();
6173: if (!$home && $other) {
6174: my @hosts;
6175: foreach my $aurole (keys(%outhash)) {
6176: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6177: push(@hosts,$outhash{$aurole});
6178: }
6179: }
6180: $script .= &dump_switchserver_js(@hosts);
6181: }
1.458 raeburn 6182: } else {
1.484.2.43 raeburn 6183: my $tid = 1;
1.484 raeburn 6184: my @tabids;
6185: if ($supplementalflag) {
6186: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 6187: $tid = 2;
1.484 raeburn 6188: } else {
6189: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 6190: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 6191: unshift(@tabids,'001');
6192: push(@tabids,('dd1','ee1'));
6193: }
1.458 raeburn 6194: }
1.484 raeburn 6195: my $tabidstr = join("','",@tabids);
1.484.2.93.2. 2(raebur 6196:3): my (%domtools,%crstools);
6197:3): my %tooltypes = &Apache::loncommon::usable_exttools();
6198:3): if ($tooltypes{'dom'}) {
6199:3): %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
6200:3): }
6201:3): if ($tooltypes{'crs'}) {
6202:3): %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
6203:3): }
6204:3): %ltitools = (
6205:3): dom => \%domtools,
6206:3): crs => \%crstools,
6207:3): );
6208:3): $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.484.2.80 raeburn 6209: my $hostname = $r->hostname();
1.484.2.93.2. (raeburn 6210:): $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 6211: $canedit,$hostname,\$navmap).
1.484 raeburn 6212: &history_tab_js().
6213: &inject_data_js().
1.484.2.43 raeburn 6214: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.93.2. (raeburn 6215:): &Apache::lonextresedit::extedit_javascript(\%ltitools);
0(raebur 6216:3): my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
6217:3): if ($hidden_and_empty ne '') {
6218:3): my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
6219:3): $hidden_and_empty);
6220:3): $onload .= "javascript:alert('".&js_escape($alert)."');";
6221:3): }
1.484 raeburn 6222: $addentries = {
1.484.2.93.2. 0(raebur 6223:3): onload => $onload,
1.484 raeburn 6224: };
1.458 raeburn 6225: }
1.484.2.30 raeburn 6226: $script .= &paste_popup_js();
1.484.2.12 raeburn 6227: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
6228: &mt('Switch server?');
1.484.2.19 raeburn 6229:
6230:
1.329 droeschl 6231: }
6232: # -------------------------------------------------------------------- Body tag
1.369 bisitz 6233: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 6234: .'// <![CDATA['."\n"
6235: .$script."\n"
6236: .'// ]]>'."\n"
1.484.2.81 raeburn 6237: .'</script>'."\n"
6238: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 6239:
6240: # Breadcrumbs
6241: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 6242:
6243: if ($showdoc) {
1.484.2.93.2. 0(raebur 6244:3): my $args;
6245:3): if ($supplementalflag) {
6246:3): my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
6247:3): my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
6248:3): $args = {'bread_crumbs' => $brcrum};
6249:3): } else {
6250:3): $args = {'force_register' => $showdoc};
6251:3): }
6252:3): $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.484.2.44 raeburn 6253: } elsif ($toolsflag) {
1.484.2.67 raeburn 6254: my ($breadtext,$breadtitle);
6255: $breadtext = "$crstype Editor";
6256: if ($canedit) {
6257: $breadtitle = 'Editing '.$crstype.' Contents';
6258: } else {
6259: $breadtext .= ' (View-only mode)';
6260: $breadtitle = 'Viewing '.$crstype.' Contents';
6261: }
1.484.2.44 raeburn 6262: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 6263: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 6264: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
6265: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6266: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 6267: $breadtitle)
1.484.2.44 raeburn 6268: );
1.484.2.19 raeburn 6269: } elsif ($r->uri eq '/adm/supplemental') {
1.484.2.93.2. 0(raebur 6270:3): unless ($env{'request.role.adv'}) {
6271:3): unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
6272:3): $r->internal_redirect('/adm/navmaps');
6273:3): return OK;
6274:3): }
6275:3): }
1.484.2.19 raeburn 6276: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
6277: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
6278: {'bread_crumbs' => $brcrum,}));
6279: } else {
1.484.2.67 raeburn 6280: my ($breadtext,$breadtitle,$helpitem);
6281: $breadtext = "$crstype Editor";
6282: if ($canedit) {
6283: $breadtitle = 'Editing '.$crstype.' Contents';
6284: $helpitem = 'Docs_Adding_Course_Doc';
6285: } else {
6286: $breadtext .= ' (View-only mode)';
6287: $breadtitle = 'Viewing '.$crstype.' Contents';
6288: $helpitem = 'Docs_Viewing_Course_Doc';
6289: }
1.392 raeburn 6290: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 6291: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 6292: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 6293: {'add_entries' => $addentries}
6294: )
1.392 raeburn 6295: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6296: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 6297: $breadtitle,
6298: $helpitem)
1.392 raeburn 6299: );
6300: }
1.364 bisitz 6301:
1.329 droeschl 6302: my %allfiles = ();
6303: my %codebase = ();
1.440 raeburn 6304: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 6305: if ($canedit) {
1.484.2.93.2. 0(raebur 6306:3): undef($suppchanges);
1.329 droeschl 6307: if (($env{'form.uploaddoc.filename'}) &&
6308: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 6309: my $context = $1;
6310: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 6311: undef($hadchanges);
1.440 raeburn 6312: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 6313: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 6314: undef($navmap);
1.329 droeschl 6315: if ($hadchanges) {
6316: &mark_hash_old();
6317: }
1.484.2.93.2. 0(raebur 6318:3): if ($suppchanges) {
6319:3): &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6320:3): undef($suppchanges);
6321:3): }
1.440 raeburn 6322: $r->print($upload_output);
6323: } elsif ($env{'form.phase'} eq 'upload_embedded') {
6324: # Process file upload - phase two - upload embedded objects
6325: $uploadphase = 'check_embedded';
6326: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
6327: my $state = &embedded_form_elems($uploadphase,$primaryurl,
6328: $env{'form.newidx'});
6329: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6330: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6331: my ($destination,$dir_root) = &embedded_destination();
6332: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
6333: my $actionurl = '/adm/coursedocs';
6334: my ($result,$flag) =
6335: &Apache::loncommon::upload_embedded('coursedoc',$destination,
6336: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
6337: $actionurl);
6338: $r->print($result.&return_to_editor());
6339: } elsif ($env{'form.phase'} eq 'check_embedded') {
6340: # Process file upload - phase three - modify references in HTML file
6341: $uploadphase = 'modified_orightml';
6342: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6343: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6344: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 6345: my $result =
6346: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
6347: $docuname,$docudom,undef,
6348: $dir_root);
6349: $r->print($result.&return_to_editor());
1.476 raeburn 6350: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
6351: $uploadphase = 'decompress_phase_one';
6352: $r->print(&decompression_phase_one().
6353: &return_to_editor());
6354: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
6355: $uploadphase = 'decompress_phase_two';
6356: $r->print(&decompression_phase_two().
6357: &return_to_editor());
1.329 droeschl 6358: }
6359: }
6360:
1.484 raeburn 6361: if ($allowed && $toolsflag) {
6362: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 6363: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 6364: $r->print(&endContentScreen());
6365: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 6366: # -----------------------------------------------------------------------------
6367: my %lt=&Apache::lonlocal::texthash(
6368: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 6369: 'upfi' => 'Upload File',
1.484.2.36 raeburn 6370: 'upld' => 'Upload Content',
1.329 droeschl 6371: 'srch' => 'Search',
6372: 'impo' => 'Import',
1.484.2.19 raeburn 6373: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 6374: 'impm' => 'Import from Assembled Map',
1.484.2.93.2. (raeburn 6375:): 'extr' => 'External Resource',
6376:): 'extt' => 'External Tool',
1.329 droeschl 6377: 'selm' => 'Select Map',
6378: 'load' => 'Load Map',
6379: 'newf' => 'New Folder',
6380: 'newp' => 'New Composite Page',
6381: 'syll' => 'Syllabus',
1.425 raeburn 6382: 'navc' => 'Table of Contents',
1.343 biermanm 6383: 'sipa' => 'Simple Course Page',
1.329 droeschl 6384: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 6385: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 6386: 'drbx' => 'Drop Box',
1.451 www 6387: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 6388: 'bull' => 'Discussion Board',
1.347 weissno 6389: 'mypi' => 'My Personal Information Page',
1.353 weissno 6390: 'grpo' => 'Group Portfolio',
1.329 droeschl 6391: 'rost' => 'Course Roster',
1.484.2.22 raeburn 6392: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 6393: 'imsf' => 'IMS Upload',
6394: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 6395: 'cms' => 'Origin of IMS package',
6396: 'se' => 'Select',
1.484.2.19 raeburn 6397: 'file' => 'File',
1.329 droeschl 6398: 'title' => 'Title',
6399: 'comment' => 'Comment',
1.403 raeburn 6400: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 6401: 'bb5' => 'Blackboard 5',
6402: 'bb6' => 'Blackboard 6',
6403: 'angel5' => 'ANGEL 5.5',
6404: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 6405: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 6406: );
1.329 droeschl 6407: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 6408: # Calculate free quota space for a user or course. A javascript function checks
6409: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 6410: my $quotatype = 'unofficial';
6411: if ($crstype eq 'Community') {
6412: $quotatype = 'community';
6413: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6414: $quotatype = 'official';
6415: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6416: $quotatype = 'textbook';
6417: }
6418: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6419: 'course',$quotatype); # expressed in MB
6420: my $current_disk_usage = 0;
6421: foreach my $subdir ('docs','supplemental') {
6422: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6423: "userfiles/$subdir",1); # expressed in kB
6424: }
6425: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
6426: my $usage = $current_disk_usage/1024; # in MB
6427: my $quota = $disk_quota;
6428: my $percent;
6429: if ($disk_quota == 0) {
6430: $percent = 100.0;
6431: } else {
1.484.2.69 raeburn 6432: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 6433: }
6434: $usage = sprintf("%.2f",$usage);
6435: $quota = sprintf("%.2f",$quota);
6436: $percent = sprintf("%.0f",$percent);
6437: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6438: $percent.'%',$quota.' MB').'</p>';
6439:
1.329 droeschl 6440: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 6441: $quotainfo
1.329 droeschl 6442: $lt{'file'}:<br />
6443: FIUP
6444: my $checkbox=(<<CHBO);
6445: <!-- <label>$lt{'parse'}?
6446: <input type="checkbox" name="parserflag" />
6447: </label> -->
6448: <label>
1.484.2.67 raeburn 6449: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6450: </label>
6451: CHBO
1.484.2.12 raeburn 6452: my $imsfolder = $env{'form.folder'};
6453: if ($imsfolder eq '') {
1.484.2.19 raeburn 6454: $imsfolder = 'default';
1.484.2.12 raeburn 6455: }
6456: my $imspform=(<<IMSFORM);
6457: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6458: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6459: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 6460: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 6461: <legend>$lt{'imsf'}</legend>
6462: $fileupload
1.484.2.93.2. 3(raebur 6463:3): <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
6464:3): <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.484.2.12 raeburn 6465: <br />
6466: <p>
1.484.2.19 raeburn 6467: $lt{'cms'}:
1.484.2.67 raeburn 6468: <select name="source" $disabled>
1.484.2.12 raeburn 6469: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 6470: <option value="bb5">$lt{'bb5'}</option>
6471: <option value="bb6">$lt{'bb6'}</option>
6472: <option value="angel5">$lt{'angel5'}</option>
6473: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 6474: </select>
6475: <input type="hidden" name="folder" value="$imsfolder" />
6476: </p>
6477: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 6478: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 6479: </fieldset>
6480: </form>
6481: IMSFORM
6482:
1.484.2.19 raeburn 6483: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 6484: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6485: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6486: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 6487: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 6488: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6489: <input type="hidden" name="active" value="aa" />
1.329 droeschl 6490: $fileupload
1.484.2.93.2. 3(raebur 6491:3): <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
6492:3): <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 6493: <br />
6494: $lt{'title'}:<br />
1.484.2.67 raeburn 6495: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 6496: $pathitem
1.329 droeschl 6497: <input type="hidden" name="cmd" value="upload_default" />
6498: <br />
1.458 raeburn 6499: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6500: $checkbox
6501: </span>
1.484.2.12 raeburn 6502: <br clear="all" />
1.484.2.67 raeburn 6503: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 6504: </fieldset>
6505: </form>
1.383 tempelho 6506: FUFORM
1.329 droeschl 6507:
1.484.2.67 raeburn 6508: my $mapimportjs;
6509: if ($canedit) {
6510: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6511: } else {
6512: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6513: }
1.484.2.19 raeburn 6514: my $importpubform=(<<SEDFFORM);
6515: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 6516: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 6517: <form action="/adm/coursedocs" method="post" name="mapimportform">
6518: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 6519: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 6520: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 6521: $lt{'copm'}<br />
6522: <span class="LC_nobreak">
1.484.2.19 raeburn 6523: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 6524: onfocus="this.blur();$mapimportjs" $disabled />
6525: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6526: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 6527: </fieldset>
6528: </form>
6529:
1.383 tempelho 6530: SEDFFORM
1.484.2.67 raeburn 6531:
6532: my $fromstoredjs;
6533: if ($canedit) {
6534: $fromstoredjs = 'open_StoredLinks_Import()';
6535: } else {
6536: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6537: }
6538:
1.484.2.19 raeburn 6539: my @importpubforma = (
6540: { '<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 6541: { '<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 6542: { '<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 6543: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
6544: );
6545: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
6546: my $extresourcesform =
6547: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6548: $help{'Adding_External_Resource'},
1.484.2.93.2. (raeburn 6549:): undef,undef,undef,undef,undef,undef,$disabled);
6550:): my $exttoolform =
6551:): &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6552:): $help{'Adding_External_Tool'},undef,
6553:): undef,'tool',$coursedom,$coursenum,
6554:): \%ltitools,$disabled);
1.329 droeschl 6555: if ($allowed) {
1.484.2.7 raeburn 6556: my $folder = $env{'form.folder'};
6557: if ($folder eq '') {
6558: $folder='default';
6559: }
1.484.2.67 raeburn 6560: if ($canedit) {
6561: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6562: if ($output) {
6563: $r->print($output);
6564: }
1.484.2.30 raeburn 6565: }
1.337 ehlerst 6566: $r->print(<<HIDDENFORM);
6567: <form name="renameform" method="post" action="/adm/coursedocs">
6568: <input type="hidden" name="title" />
6569: <input type="hidden" name="cmd" />
6570: <input type="hidden" name="markcopy" />
6571: <input type="hidden" name="copyfolder" />
6572: $containertag
6573: </form>
1.484 raeburn 6574:
1.337 ehlerst 6575: HIDDENFORM
1.484.2.17 raeburn 6576: $r->print(&makesimpleeditform($pathitem)."\n".
6577: &makedocslogform($pathitem."\n".
1.484 raeburn 6578: '<input type="hidden" name="folder" value="'.
6579: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6580: }
1.442 www 6581:
6582: # Generate the tabs
1.484.2.19 raeburn 6583: my ($mode,$needs_end);
1.472 raeburn 6584: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 6585: my @folders = split('&',$env{'form.folderpath'});
6586: unless (@folders > 2) {
6587: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6588: $needs_end = 1;
6589: }
1.472 raeburn 6590: } else {
1.484 raeburn 6591: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 6592: $needs_end = 1;
1.472 raeburn 6593: }
1.443 www 6594:
1.442 www 6595: #
6596:
6597: my $savefolderpath;
1.484.2.86 raeburn 6598: my $hostname = $r->hostname();
1.442 www 6599:
1.395 raeburn 6600: if ($allowed) {
1.329 droeschl 6601: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 6602: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6603: $folder='default';
1.356 tempelho 6604: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 6605: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 6606: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6607: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6608: }
6609: my $postexec='';
6610: if ($folder eq 'default') {
1.484.2.93.2. 2(raebur 6611:3): my $windowname = 'loncapaclient';
6612:3): if ($env{'request.lti.login'}) {
6613:3): $windowname .= 'lti';
6614:3): }
1.372 bisitz 6615: $r->print('<script type="text/javascript">'."\n"
6616: .'// <![CDATA['."\n"
1.484.2.93.2. 2(raebur 6617:3): .'this.window.name="$windowname";'."\n"
1.372 bisitz 6618: .'// ]]>'."\n"
6619: .'</script>'."\n"
1.369 bisitz 6620: );
1.329 droeschl 6621: } else {
6622: #$postexec='self.close();';
6623: }
1.484.2.15 raeburn 6624: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6625: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6626: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6627:
6628: my $newnavform=(<<NNFORM);
6629: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 6630: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6631: $pathitem
1.329 droeschl 6632: <input type="hidden" name="importdetail"
6633: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 6634: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6635: $help{'Navigate_Content'}
6636: </form>
6637: NNFORM
6638: my $newsmppageform=(<<NSPFORM);
6639: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 6640: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6641: $pathitem
1.329 droeschl 6642: <input type="hidden" name="importdetail" value="" />
1.423 onken 6643: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6644: $help{'Simple Page'}
1.329 droeschl 6645: </form>
6646: NSPFORM
6647:
6648: my $newsmpproblemform=(<<NSPROBFORM);
6649: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 6650: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6651: $pathitem
1.329 droeschl 6652: <input type="hidden" name="importdetail" value="" />
1.423 onken 6653: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 6654: $help{'Simple_Problem'}
1.329 droeschl 6655: </form>
6656:
6657: NSPROBFORM
6658:
6659: my $newdropboxform=(<<NDBFORM);
6660: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 6661: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6662: $pathitem
1.329 droeschl 6663: <input type="hidden" name="importdetail" value="" />
1.423 onken 6664: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 6665: $help{'Dropbox'}
1.344 bisitz 6666: </form>
1.329 droeschl 6667: NDBFORM
6668:
6669: my $newexuploadform=(<<NEXUFORM);
6670: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 6671: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6672: $pathitem
1.329 droeschl 6673: <input type="hidden" name="importdetail" value="" />
1.423 onken 6674: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6675: $help{'Score_Upload_Form'}
6676: </form>
6677: NEXUFORM
6678:
6679: my $newbulform=(<<NBFORM);
6680: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 6681: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6682: $pathitem
1.329 droeschl 6683: <input type="hidden" name="importdetail" value="" />
1.423 onken 6684: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6685: $help{'Bulletin Board'}
6686: </form>
6687: NBFORM
6688:
6689: my $newaboutmeform=(<<NAMFORM);
6690: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 6691: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6692: $pathitem
1.329 droeschl 6693: <input type="hidden" name="importdetail"
6694: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6695: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6696: $help{'My Personal Information Page'}
1.329 droeschl 6697: </form>
6698: NAMFORM
6699:
6700: my $newaboutsomeoneform=(<<NASOFORM);
6701: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 6702: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6703: $pathitem
1.329 droeschl 6704: <input type="hidden" name="importdetail" value="" />
1.423 onken 6705: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6706: </form>
6707: NASOFORM
6708:
6709: my $newrosterform=(<<NROSTFORM);
6710: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 6711: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6712: $pathitem
1.329 droeschl 6713: <input type="hidden" name="importdetail"
6714: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 6715: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 6716: $help{'Course_Roster'}
1.329 droeschl 6717: </form>
6718: NROSTFORM
6719:
1.484.2.27 raeburn 6720: my $newwebpage;
6721: if ($folder =~ /^default_?(\d*)$/) {
6722: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6723: if ($1) {
6724: $newwebpage .= $1;
6725: } else {
6726: $newwebpage .= 'default';
6727: }
6728: $newwebpage .= '/new.html';
6729: }
6730: my $newwebpageform =(<<NWEBFORM);
6731: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 6732: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 6733: $pathitem
6734: <input type="hidden" name="importdetail" value="$newwebpage" />
6735: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 6736: $help{'Web_Page'}
1.484.2.27 raeburn 6737: </form>
6738: NWEBFORM
1.484.2.30 raeburn 6739:
1.484.2.27 raeburn 6740:
1.342 ehlerst 6741: my $specialdocumentsform;
1.383 tempelho 6742: my @specialdocumentsforma;
1.451 www 6743: my $gradingform;
6744: my @gradingforma;
6745: my $communityform;
6746: my @communityforma;
1.351 ehlerst 6747: my $newfolderform;
1.390 tempelho 6748: my $newfolderb;
1.342 ehlerst 6749:
1.451 www 6750: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6751:
1.329 droeschl 6752: my $newpageform=(<<NPFORM);
6753: <form action="/adm/coursedocs" method="post" name="newpage">
6754: <input type="hidden" name="folderpath" value="$path" />
6755: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6756: <input type="hidden" name="active" value="ee" />
1.423 onken 6757: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6758: $help{'Adding_Pages'}
1.329 droeschl 6759: </form>
6760: NPFORM
1.390 tempelho 6761:
6762:
1.351 ehlerst 6763: $newfolderform=(<<NFFORM);
1.329 droeschl 6764: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 6765: $pathitem
1.329 droeschl 6766: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6767: <input type="hidden" name="active" value="" />
1.422 onken 6768: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6769: </form>
6770: NFFORM
6771:
6772: my $newsylform=(<<NSYLFORM);
6773: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 6774: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6775: $pathitem
1.329 droeschl 6776: <input type="hidden" name="importdetail"
6777: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6778: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6779: $help{'Syllabus'}
1.383 tempelho 6780:
1.329 droeschl 6781: </form>
6782: NSYLFORM
1.364 bisitz 6783:
1.329 droeschl 6784: my $newgroupfileform=(<<NGFFORM);
6785: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 6786: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6787: $pathitem
1.329 droeschl 6788: <input type="hidden" name="importdetail"
6789: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 6790: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6791: $help{'Group Portfolio'}
1.329 droeschl 6792: </form>
6793: NGFFORM
1.484.2.89 raeburn 6794: if ($container eq 'page') {
6795: @specialdocumentsforma=(
6796: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6797: );
6798: } else {
6799: @specialdocumentsforma=(
1.421 onken 6800: {'<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 6801: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6802: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6803: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 6804: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.484.2.89 raeburn 6805: );
6806: }
1.451 www 6807: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6808:
1.434 raeburn 6809:
6810: my @importdoc = (
1.484.2.19 raeburn 6811: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6812: );
1.484.2.93.2. 2(raebur 6813:3): if ($posslti) {
(raeburn 6814:): push(@importdoc,
6815:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6816:): );
6817:): }
1.484.2.19 raeburn 6818: unless ($container eq 'page') {
6819: push(@importdoc,
6820: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6821: );
6822: }
6823: push(@importdoc,
1.484.2.38 raeburn 6824: {'<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 6825: );
1.484.2.12 raeburn 6826: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6827:
1.451 www 6828: @gradingforma=(
6829: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6830: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6831: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6832:
6833: );
6834: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6835:
6836: @communityforma=(
6837: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6838: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6839: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 6840: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6841: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6842: );
6843: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6844:
1.330 tempelho 6845: my %orderhash = (
1.484.2.36 raeburn 6846: 'aa' => ['Upload',$fileuploadform],
6847: 'bb' => ['Import',$importpubform],
6848: 'cc' => ['Grading',$gradingform],
1.484.2.89 raeburn 6849: 'ee' => ['Other',$specialdocumentsform],
1.330 tempelho 6850: );
1.484.2.19 raeburn 6851: unless ($container eq 'page') {
1.434 raeburn 6852: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6853: $orderhash{'dd'} = ['Collaboration',$communityform];
1.434 raeburn 6854: }
6855:
1.341 ehlerst 6856: $hadchanges=0;
1.484 raeburn 6857: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6858: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6859: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.93.2. (raeburn 6860:): \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 6861: undef($navmap);
1.443 www 6862: if ($error) {
6863: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6864: }
6865: if ($hadchanges) {
1.484.2.73 raeburn 6866: unless (&is_hash_old()) {
6867: &mark_hash_old();
6868: }
1.443 www 6869: }
1.341 ehlerst 6870:
1.443 www 6871: &changewarning($r,'');
6872: }
1.458 raeburn 6873: }
1.442 www 6874:
1.443 www 6875: # Supplemental documents start here
6876:
1.329 droeschl 6877: my $folder=$env{'form.folder'};
1.443 www 6878: unless ($supplementalflag) {
1.329 droeschl 6879: $folder='supplemental';
6880: }
1.484.2.93.2. 0(raebur 6881:3): if (($folder eq 'supplemental') &&
1.329 droeschl 6882: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6883: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6884: } elsif ($allowed) {
1.356 tempelho 6885: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6886: }
1.484.2.17 raeburn 6887: $pathitem = '<input type="hidden" name="folderpath" value="'.
6888: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6889: if ($allowed) {
6890: my $folderseq=
1.484.2.15 raeburn 6891: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6892:
6893: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 6894: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6895: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6896: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6897: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6898: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6899: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6900: $fileupload
1.484.2.93.2. 3(raebur 6901:3): <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
6902:3): <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 6903: <br />
6904: <br />
6905: <span class="LC_nobreak">
6906: $checkbox
6907: </span>
6908: <br /><br />
6909: $lt{'comment'}:<br />
1.383 tempelho 6910: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6911: <br />
1.484.2.19 raeburn 6912: $pathitem
1.329 droeschl 6913: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6914: <input type='submit' value="$lt{'upld'}" />
1.484.2.93.2. 4(raebur 6915:3): </fieldset>
1.484.2.12 raeburn 6916: </form>
1.484.2.19 raeburn 6917: SUPDOCFORM
1.329 droeschl 6918:
6919: my $supnewfolderform=(<<SNFFORM);
6920: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6921: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6922: $pathitem
1.329 droeschl 6923: <input type="hidden" name="importdetail" value="" />
1.423 onken 6924: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6925: $help{'Adding_Folders'}
1.329 droeschl 6926: </form>
6927: SNFFORM
1.383 tempelho 6928:
1.484.2.19 raeburn 6929: my $supextform =
6930: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6931: $help{'Adding_External_Resource'},
6932: undef,undef,$disabled);
1.484.2.93.2. (raeburn 6933:): my $supexttoolform =
6934:): &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6935:): $help{'Adding_External_Tool'},
6936:): undef,undef,'tool',$coursedom,
6937:): $coursenum,\%ltitools,$disabled);
1.329 droeschl 6938:
6939: my $supnewsylform=(<<SNSFORM);
6940: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6941: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6942: $pathitem
1.329 droeschl 6943: <input type="hidden" name="importdetail"
6944: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6945: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6946: $help{'Syllabus'}
6947: </form>
6948: SNSFORM
6949:
6950: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6951: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6952: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6953: $pathitem
1.329 droeschl 6954: <input type="hidden" name="importdetail"
6955: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6956: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6957: $help{'My Personal Information Page'}
1.329 droeschl 6958: </form>
6959: SNAMFORM
6960:
1.484.2.27 raeburn 6961: my $supwebpage;
6962: if ($folder =~ /^supplemental_?(\d*)$/) {
6963: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6964: if ($1) {
6965: $supwebpage .= $1;
6966: } else {
6967: $supwebpage .= 'default';
6968: }
6969: $supwebpage .= '/new.html';
6970: }
6971: my $supwebpageform =(<<SWEBFORM);
6972: <form action="/adm/coursedocs" method="post" name="supwebpage">
6973: <input type="hidden" name="active" value="cc" />
6974: $pathitem
6975: <input type="hidden" name="importdetail" value="$supwebpage" />
6976: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6977: $help{'Web_Page'}
1.484.2.27 raeburn 6978: </form>
6979: SWEBFORM
6980:
1.333 muellerd 6981:
1.383 tempelho 6982: my @specialdocs = (
1.484.2.67 raeburn 6983: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6984: =>$supnewsylform},
1.484.2.67 raeburn 6985: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6986: =>$supnewaboutmeform},
1.484.2.27 raeburn 6987: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6988:
1.383 tempelho 6989: );
1.417 droeschl 6990: my @supimportdoc = (
1.484.2.19 raeburn 6991: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.93.2. (raeburn 6992:): =>$supextform});
6993:): if (keys(%ltitools)) {
6994:): push(@supimportdoc,
6995:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6996:): =>$supexttoolform});
6997:): }
6998:): push(@supimportdoc,
1.484.2.12 raeburn 6999: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
7000: =>$supupdocform},
1.484.2.93.2. (raeburn 7001:): );
1.484.2.19 raeburn 7002:
1.484.2.12 raeburn 7003: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 7004: my %suporderhash = (
1.390 tempelho 7005: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 7006: 'ee' => ['Upload',$supupdocform],
7007: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 7008: );
1.443 www 7009: if ($supplementalflag) {
1.484.2.93.2. 0(raebur 7010:3): $suppchanges = 0;
7011:3): my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
7012:3): $supplementalflag,\%suporderhash,$iconpath,$pathitem,
7013:3): \%ltitools,$canedit,$hostname);
7014:3): if ($error) {
7015:3): $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7016:3): }
7017:3): if ($suppchanges) {
7018:3): &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
7019:3): undef($suppchanges);
7020:3): }
1.393 raeburn 7021: }
1.443 www 7022: } elsif ($supplementalflag) {
1.458 raeburn 7023: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.93.2. (raeburn 7024:): $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
7025:): $hostname);
1.393 raeburn 7026: if ($error) {
7027: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 7028: }
1.393 raeburn 7029: }
1.389 tempelho 7030:
1.484.2.19 raeburn 7031: if ($needs_end) {
7032: $r->print(&endContentScreen());
7033: }
1.383 tempelho 7034:
1.329 droeschl 7035: if ($allowed) {
7036: $r->print('
7037: <form method="post" name="extimport" action="/adm/coursedocs">
7038: <input type="hidden" name="title" />
7039: <input type="hidden" name="url" />
7040: <input type="hidden" name="useform" />
7041: <input type="hidden" name="residx" />
7042: </form>');
7043: }
1.484 raeburn 7044: } elsif ($showdoc) {
1.329 droeschl 7045: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 7046: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 7047: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 7048: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 7049: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 7050: }
7051: }
7052: $r->print(&Apache::loncommon::end_page());
7053: return OK;
1.364 bisitz 7054: }
1.329 droeschl 7055:
1.440 raeburn 7056: sub embedded_form_elems {
7057: my ($phase,$primaryurl,$newidx) = @_;
7058: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 7059: $newidx =~s /\D+//g;
1.440 raeburn 7060: return <<STATE;
7061: <input type="hidden" name="folderpath" value="$folderpath" />
7062: <input type="hidden" name="cmd" value="upload_embedded" />
7063: <input type="hidden" name="newidx" value="$newidx" />
7064: <input type="hidden" name="phase" value="$phase" />
7065: <input type="hidden" name="primaryurl" value="$primaryurl" />
7066: STATE
7067: }
7068:
7069: sub embedded_destination {
7070: my $folder=$env{'form.folder'};
7071: my $destination = 'docs/';
7072: if ($folder =~ /^supplemental/) {
7073: $destination = 'supplemental/';
7074: }
7075: if (($folder eq 'default') || ($folder eq 'supplemental')) {
7076: $destination .= 'default/';
7077: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
7078: $destination .= $2.'/';
7079: }
1.484.2.78 raeburn 7080: my $newidx = $env{'form.newidx'};
7081: $newidx =~s /\D+//g;
7082: if ($newidx) {
7083: $destination .= $newidx;
7084: }
1.440 raeburn 7085: my $dir_root = '/userfiles';
7086: return ($destination,$dir_root);
7087: }
7088:
7089: sub return_to_editor {
7090: my $actionurl = '/adm/coursedocs';
7091: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7092: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7093: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7094: '</a></p>';
7095: }
7096:
1.476 raeburn 7097: sub decompression_info {
7098: my ($destination,$dir_root) = &embedded_destination();
7099: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7100: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7101: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7102: my $container='sequence';
1.480 raeburn 7103: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 7104: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 7105: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 7106: $container='page';
7107: }
1.480 raeburn 7108: unshift(@hiddens,$pathitem);
7109: foreach my $item (@hiddens) {
1.484.2.78 raeburn 7110: if ($item eq 'newidx') {
7111: next if ($env{'form.'.$item} =~ /\D/);
7112: }
1.480 raeburn 7113: if ($env{'form.'.$item}) {
7114: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 7115: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 7116: }
1.477 raeburn 7117: }
1.476 raeburn 7118: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7119: $hiddenelem);
7120: }
7121:
7122: sub decompression_phase_one {
7123: my ($dir,$file,$warning,$error,$output);
7124: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7125: &decompression_info();
1.484.2.7 raeburn 7126: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 7127: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7128: } else {
7129: my $file = $1;
1.481 raeburn 7130: $output =
7131: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7132: $destination,$dir_root,
7133: $hiddenelem);
7134: if ($env{'form.autoextract_camtasia'}) {
7135: $output .= &remove_archive($docudom,$docuname,$container);
7136: }
1.476 raeburn 7137: }
7138: if ($error) {
7139: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7140: $error.'</p>'."\n";
7141: }
7142: if ($warning) {
7143: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7144: }
7145: return $output;
7146: }
7147:
7148: sub decompression_phase_two {
7149: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7150: &decompression_info();
1.481 raeburn 7151: my $output;
1.480 raeburn 7152: if ($env{'form.archivedelete'}) {
1.481 raeburn 7153: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 7154: }
7155: $output .=
1.481 raeburn 7156: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 7157: $destination,$dir_root,$hiddenelem);
7158: return $output;
7159: }
7160:
1.480 raeburn 7161: sub remove_archive {
7162: my ($docudom,$docuname,$container) = @_;
7163: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 7164: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 7165: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7166: if ($fatal) {
7167: if ($container eq 'page') {
7168: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7169: } else {
7170: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7171: }
1.484.2.54 raeburn 7172: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7173: } else {
7174: my $currcmd = $env{'form.cmd'};
7175: my $position = $env{'form.position'};
1.484.2.54 raeburn 7176: my $archiveidx = $position;
7177: if ($position > 0) {
7178: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7179: $archiveidx = $position-1;
7180: }
7181: $env{'form.cmd'} = 'remove_'.$archiveidx;
7182: my ($title,$url,@rrest) =
7183: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7184: if ($url eq $env{'form.archiveurl'}) {
7185: if (&handle_edit_cmd($docuname,$docudom)) {
7186: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.484.2.93.2. 0(raebur 7187:3): if ($suppchanges) {
7188:3): &Apache::lonnet::update_supp_caches($docudom,$docuname);
7189:3): undef($suppchanges);
7190:3): }
1.484.2.54 raeburn 7191: if ($fatal) {
7192: if ($container eq 'page') {
7193: $delwarning = &mt('An error occurred updating the contents of the current page.');
7194: } else {
7195: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7196: }
1.480 raeburn 7197: } else {
1.484.2.54 raeburn 7198: $delresult = &mt('Archive file removed.');
1.480 raeburn 7199: }
7200: }
1.484.2.54 raeburn 7201: } else {
7202: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7203: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7204: }
7205: }
7206: $env{'form.cmd'} = $currcmd;
7207: }
7208: if ($delwarning) {
7209: $output = '<p class="LC_warning">'.
7210: $delwarning.
7211: '</p>';
7212: }
7213: if ($delresult) {
7214: $output .= '<p class="LC_info">'.
7215: $delresult.
7216: '</p>';
7217: }
1.481 raeburn 7218: return $output;
1.480 raeburn 7219: }
7220:
1.484 raeburn 7221: sub generate_admin_menu {
1.484.2.67 raeburn 7222: my ($crstype,$canedit) = @_;
1.484 raeburn 7223: my $lc_crstype = lc($crstype);
7224: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 7225: my %lt= ( # do not translate here
1.484 raeburn 7226: 'vc' => 'Verify Content',
7227: 'cv' => 'Check/Set Resource Versions',
7228: 'ls' => 'List Resource Identifiers',
1.484.2.93.2. (raeburn 7229:): 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 7230: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 7231: 'dcd' => "Copy $crstype Content to Authoring Space",
7232: );
1.484 raeburn 7233: my ($candump,$dumpurl);
7234: if ($home + $other > 0) {
7235: $candump = 'F';
7236: if ($home) {
7237: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7238: } else {
7239: my @hosts;
7240: foreach my $aurole (keys(%outhash)) {
7241: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7242: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 7243: }
1.484 raeburn 7244: }
7245: if (@hosts == 1) {
7246: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7247: '&role='.
7248: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7249: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7250: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7251: } else {
7252: $dumpurl = "javascript:choose_switchserver_window()";
7253: }
7254: }
7255: }
7256: my @menu=
7257: ({ categorytitle=>'Administration',
7258: items =>[
7259: { linktext => $lt{'vc'},
7260: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7261: permission => 'F',
1.484.2.44 raeburn 7262: help => 'Docs_Verify_Content',
1.484 raeburn 7263: icon => 'verify.png',
7264: linktitle => 'Verify contents can be retrieved/rendered',
7265: },
7266: { linktext => $lt{'cv'},
7267: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7268: permission => 'F',
1.484.2.44 raeburn 7269: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7270: icon => 'resversion.png',
7271: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7272: },
7273: { linktext => $lt{'ls'},
7274: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7275: permission => 'F',
7276: #help => '',
7277: icon => 'symbs.png',
7278: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7279: },
1.484.2.93.2. (raeburn 7280:): { linktext => $lt{'ct'},
7281:): url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7282:): permission => 'F',
7283:): help => 'Docs_Short_URLs',
7284:): icon => 'shorturls.png',
7285:): linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7286:): },
1.484 raeburn 7287: ]
1.484.2.67 raeburn 7288: });
7289: if ($canedit) {
7290: push(@menu,
1.484 raeburn 7291: { categorytitle=>'Export',
7292: items =>[
7293: { linktext => $lt{'imse'},
7294: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7295: permission => 'F',
7296: help => 'Docs_Export_Course_Docs',
7297: icon => 'imsexport.png',
7298: linktitle => $lt{'imse'},
7299: },
7300: { linktext => $lt{'dcd'},
7301: url => $dumpurl,
7302: permission => $candump,
1.484.2.44 raeburn 7303: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7304: icon => 'dump.png',
7305: linktitle => $lt{'dcd'},
7306: },
7307: ]
7308: });
1.484.2.67 raeburn 7309: }
1.484 raeburn 7310: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7311: '<input type="hidden" id="dummy" />'."\n".
7312: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7313: '</form>';
1.329 droeschl 7314: }
7315:
7316: sub generate_edit_table {
1.484.2.30 raeburn 7317: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 7318: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7319: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7320: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 7321: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 7322: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7323: $activetab = $env{'form.active'};
7324: }
1.484.2.67 raeburn 7325: unless ($canedit) {
7326: $disabled = ' disabled="disabled"';
7327: }
1.472 raeburn 7328: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 7329: my $backtext = &mt('Exit Editor');
1.458 raeburn 7330: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 7331: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7332: '<li class="goback">'.
1.484.2.32 raeburn 7333: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 7334: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7335: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7336: '<li>'.
7337: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7338: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 7339: if ($env{'form.docslog'}) {
7340: $form .= '<li class="active">';
7341: } else {
7342: $form .= '<li>';
7343: }
7344: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7345: &mt('History').'</a></li>'."\n";
7346: if ($env{'form.docslog'}) {
7347: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7348: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7349: }
1.458 raeburn 7350: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7351: if($name ne '00'){
1.371 tempelho 7352: if($activetab eq '' || $activetab ne $name){
7353: $active = '';
7354: }elsif($activetab eq $name){
7355: $active = 'class="active"';
7356: }
1.458 raeburn 7357: $form .= '<li style="float:right" '.$active
1.484 raeburn 7358: .' 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 7359: } else {
1.484.2.43 raeburn 7360: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7361:
7362: }
1.329 droeschl 7363: }
1.484 raeburn 7364: $form .= '</ul>'."\n";
7365: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7366:
7367: if ($to_show ne '') {
1.484.2.30 raeburn 7368: my $saveform;
7369: if ($need_save) {
7370: my $button = &mt('Make changes');
7371: my $path;
7372: if ($env{'form.folderpath'}) {
7373: $path =
7374: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7375: }
7376: $saveform = <<"END";
7377: <div id="multisave" style="display:none; clear:both;" >
7378: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7379: <input type="hidden" name="folderpath" value="$path" />
7380: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7381: <input type="hidden" name="allhiddenresource" value="" />
7382: <input type="hidden" name="allencrypturl" value="" />
7383: <input type="hidden" name="allrandompick" value="" />
7384: <input type="hidden" name="allrandomorder" value="" />
7385: <input type="hidden" name="changeparms" value="" />
7386: <input type="hidden" name="multiremove" value="" />
7387: <input type="hidden" name="multicut" value="" />
7388: <input type="hidden" name="multicopy" value="" />
7389: <input type="hidden" name="multichange" value="" />
7390: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 7391: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 7392: </form>
7393: </div>
7394: END
7395: }
7396: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7397: }
1.363 ehlerst 7398: foreach my $field (keys(%orderhash)){
1.390 tempelho 7399: if($field ne '00'){
1.422 onken 7400: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7401: $active = 'style="display: none;float:left"';
1.422 onken 7402: }elsif($activetab eq $field){
1.458 raeburn 7403: $active = 'style="display:block;float:left"';
1.422 onken 7404: }
7405: $form .= '<div id="'.$field.$tid.'"'
7406: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7407: .'</div>'."\n";
1.363 ehlerst 7408: }
7409: }
1.484 raeburn 7410: unless ($env{'form.docslog'}) {
7411: $form .= '</div></div>'."\n";
7412: }
1.329 droeschl 7413: return $form;
7414: }
7415:
7416: sub editing_js {
1.484.2.93.2. (raeburn 7417:): my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 7418: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 7419: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7420: p_mnf => 'Name of New Folder',
7421: t_mnf => 'New Folder',
7422: p_mnp => 'Name of New Page',
7423: t_mnp => 'New Page',
1.451 www 7424: p_mxu => 'Title for the External Score',
1.349 biermanm 7425: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7426: p_msb => 'Title for the Problem',
7427: p_mdb => 'Title for the Drop Box',
1.336 schafran 7428: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 7429: p_mwp => 'Title for Web Page',
1.348 weissno 7430: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7431: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7432: p_mab_alrt1 => 'Not a valid user:domain',
7433: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7434: p_chn => 'New Title',
7435: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 7436: p_rmr2a => 'Remove',
7437: p_rmr2b => '?',
7438: p_rmr3a => 'Remove those',
7439: p_rmr3b => 'items?',
7440: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7441: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7442: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7443: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 7444: p_ctr2a => 'Cut',
7445: p_ctr2b => '?',
7446: p_ctr3a => 'Cut those',
7447: p_ctr3b => 'items?',
1.478 raeburn 7448: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 7449: imsfile => 'You must choose an IMS package for import',
7450: imscms => 'You must select which Course Management System was the source of the IMS package',
7451: invurl => 'Invalid URL',
7452: titbl => 'Title is blank',
1.484.2.30 raeburn 7453: more => '(More ...)',
7454: less => '(Less ...)',
7455: noor => 'No actions selected or changes to settings specified.',
7456: noch => 'No changes to settings specified.',
7457: noac => 'No actions selected.',
1.484.2.67 raeburn 7458: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 7459: );
7460:
1.484.2.61 raeburn 7461: &js_escape(\%js_lt);
1.433 raeburn 7462: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7463: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7464: my $main_container_page;
1.484.2.19 raeburn 7465: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7466: $main_container_page = 1;
1.434 raeburn 7467: }
1.484.2.67 raeburn 7468: my $backtourl;
7469: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7470: my $toplevelsupp = &supplemental_base();
1.433 raeburn 7471:
1.484.2.21 raeburn 7472: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7473: my $caller = $1;
7474: if ($caller =~ /^supplemental/) {
7475: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7476: } else {
7477: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7478: $res = &Apache::lonnet::clutter($res);
7479: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 7480: my ($url,$anchor);
7481: if ($res =~ /^([^#]+)#([^#]+)$/) {
7482: $url = $1;
7483: $anchor = $2;
7484: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7485: $caller = $1.&escape('#').$anchor;
7486: }
1.484.2.67 raeburn 7487: } else {
7488: $url = $res;
1.484.2.66 raeburn 7489: }
1.484.2.83 raeburn 7490: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7491: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7492: $backtourl .= '?navmap=1';
7493: } else {
7494: $backtourl .= '?symb='.
7495: &HTML::Entities::encode($caller,'<>&"');
7496: }
1.484.2.80 raeburn 7497: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7498: if (($ENV{'SERVER_PORT'} == 443) &&
7499: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 7500: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 7501: if ($hostname ne '') {
7502: $backtourl = 'http://'.$hostname.$backtourl;
7503: }
7504: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7505: }
7506: }
7507: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7508: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.484.2.93 raeburn 7509: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 7510: if ($hostname ne '') {
7511: $backtourl = 'http://'.$hostname.$backtourl;
7512: }
7513: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7514: }
7515: }
7516: }
1.484.2.66 raeburn 7517: if ($anchor ne '') {
7518: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7519: }
1.484.2.57 raeburn 7520: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 7521: } else {
7522: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 7523: }
7524: }
7525: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7526: $backtourl = '/adm/menu';
7527: } elsif ($supplementalflag) {
1.484.2.93.2. 0(raebur 7528:3): if (($env{'request.role.adv'}) ||
7529:3): (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7530:3): $backtourl = '/adm/supplemental';
7531:3): } else {
7532:3): $backtourl = '/adm/navmaps';
7533:3): }
1.484.2.21 raeburn 7534: } else {
7535: $backtourl = '/adm/navmaps';
1.472 raeburn 7536: }
7537:
1.484.2.19 raeburn 7538: my $fieldsets = "'ext','doc'";
1.484.2.93.2. (raeburn 7539:): if ($posslti) {
7540:): $fieldsets .= ",'tool'";
7541:): }
1.484.2.19 raeburn 7542: unless ($main_container_page) {
7543: $fieldsets .=",'ims'";
7544: }
1.484.2.12 raeburn 7545: if ($supplementalflag) {
7546: $fieldsets = "'suppext','suppdoc'";
1.484.2.93.2. (raeburn 7547:): if ($posslti) {
7548:): $fieldsets .= ",'supptool'";
7549:): }
1.484.2.12 raeburn 7550: }
7551:
1.484.2.67 raeburn 7552: my $jsmakefunctions;
7553: if ($canedit) {
7554: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7555: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 7556: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7557: if (foldername) {
1.484.2.91 raeburn 7558: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 7559: targetform.submit();
7560: }
7561: }
7562:
7563: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 7564: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7565: if (pagename) {
1.484.2.91 raeburn 7566: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 7567: targetform.submit();
7568: }
7569: }
7570:
7571: function makeexamupload() {
1.484.2.61 raeburn 7572: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7573: if (title) {
1.329 droeschl 7574: this.document.forms.newexamupload.importdetail.value=
1.484.2.91 raeburn 7575: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 7576: this.document.forms.newexamupload.submit();
7577: }
7578: }
7579:
7580: function makesmppage() {
1.484.2.61 raeburn 7581: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7582: if (title) {
1.329 droeschl 7583: this.document.forms.newsmppg.importdetail.value=
1.484.2.91 raeburn 7584: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7585: this.document.forms.newsmppg.submit();
7586: }
7587: }
7588:
1.484.2.27 raeburn 7589: function makewebpage(type) {
1.484.2.61 raeburn 7590: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 7591: var formname;
7592: if (type == 'supp') {
7593: formname = this.document.forms.supwebpage;
7594: } else {
7595: formname = this.document.forms.newwebpage;
7596: }
7597: if (title) {
7598: var webpage = formname.importdetail.value;
1.484.2.91 raeburn 7599: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.484.2.27 raeburn 7600: formname.submit();
7601: }
7602: }
7603:
1.329 droeschl 7604: function makesmpproblem() {
1.484.2.61 raeburn 7605: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7606: if (title) {
1.329 droeschl 7607: this.document.forms.newsmpproblem.importdetail.value=
1.484.2.91 raeburn 7608: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 7609: this.document.forms.newsmpproblem.submit();
7610: }
7611: }
7612:
7613: function makedropbox() {
1.484.2.61 raeburn 7614: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7615: if (title) {
1.329 droeschl 7616: this.document.forms.newdropbox.importdetail.value=
1.484.2.91 raeburn 7617: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 7618: this.document.forms.newdropbox.submit();
7619: }
7620: }
7621:
7622: function makebulboard() {
1.484.2.61 raeburn 7623: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7624: if (title) {
7625: this.document.forms.newbul.importdetail.value=
1.484.2.91 raeburn 7626: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7627: this.document.forms.newbul.submit();
7628: }
7629: }
7630:
7631: function makeabout() {
1.484.2.61 raeburn 7632: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7633: if (user) {
7634: var comp=new Array();
7635: comp=user.split(':');
7636: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7637: if ((comp[0]) && (comp[1])) {
7638: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 7639: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 7640: this.document.forms.newaboutsomeone.submit();
7641: } else {
7642: alert("$js_lt{'p_mab_alrt1'}");
7643: }
7644: } else {
7645: alert("$js_lt{'p_mab_alrt2'}");
7646: }
7647: }
1.335 ehlerst 7648: }
1.484.2.67 raeburn 7649:
7650: function makenew(targetform) {
7651: targetform.submit();
1.335 ehlerst 7652: }
1.484.2.67 raeburn 7653:
7654: function changename(folderpath,index,oldtitle) {
7655: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7656: if (title) {
7657: this.document.forms.renameform.markcopy.value='';
7658: this.document.forms.renameform.title.value=title;
7659: this.document.forms.renameform.cmd.value='rename_'+index;
7660: this.document.forms.renameform.folderpath.value=folderpath;
7661: this.document.forms.renameform.submit();
7662: }
1.329 droeschl 7663: }
7664:
1.484.2.67 raeburn 7665: ENDNEWSCRIPT
7666: } else {
7667: $jsmakefunctions = <<ENDNEWSCRIPT;
7668:
7669: function makenewfolder() {
7670: alert("$js_lt{'edri'}");
7671: }
7672:
7673: function makenewpage() {
7674: alert("$js_lt{'edri'}");
7675: }
7676:
7677: function makeexamupload() {
7678: alert("$js_lt{'edri'}");
7679: }
7680:
7681: function makesmppage() {
7682: alert("$js_lt{'edri'}");
7683: }
7684:
7685: function makewebpage(type) {
7686: alert("$js_lt{'edri'}");
7687: }
7688:
7689: function makesmpproblem() {
7690: alert("$js_lt{'edri'}");
7691: }
7692:
7693: function makedropbox() {
7694: alert("$js_lt{'edri'}");
7695: }
7696:
7697: function makebulboard() {
7698: alert("$js_lt{'edri'}");
7699: }
7700:
7701: function makeabout() {
7702: alert("$js_lt{'edri'}");
7703: }
7704:
7705: function changename() {
7706: alert("$js_lt{'edri'}");
7707: }
7708:
7709: function makenew() {
7710: alert("$js_lt{'edri'}");
7711: }
7712:
7713: function groupimport() {
7714: alert("$js_lt{'edri'}");
7715: }
7716:
7717: function groupsearch() {
7718: alert("$js_lt{'edri'}");
7719: }
7720:
7721: function groupopen(url,recover) {
7722: var options="scrollbars=1,resizable=1,menubar=0";
7723: idxflag=1;
7724: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7725: idx.focus();
7726: }
7727:
7728: ENDNEWSCRIPT
7729:
7730: }
7731: return <<ENDSCRIPT;
7732:
7733: $jsmakefunctions
7734:
1.484.2.13 raeburn 7735: function toggleUpload(caller) {
7736: var blocks = Array($fieldsets);
7737: for (var i=0; i<blocks.length; i++) {
7738: var disp = 'none';
7739: if (caller == blocks[i]) {
7740: var curr = document.getElementById('upload'+caller+'form').style.display;
7741: if (curr == 'none') {
7742: disp='block';
7743: }
7744: }
7745: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.484.2.93.2. (raeburn 7746:): if ((caller == 'tool') || (caller == 'supptool')) {
7747:): if (disp == 'block') {
7748:): if (document.getElementById('LC_exttoolid')) {
7749:): var toolselector = document.getElementById('LC_exttoolid');
7750:): var suppflag = 0;
7751:): if (caller == 'supptool') {
7752:): suppflag = 1;
7753:): }
7754:): currForm = document.getElementById('new'+caller);
7755:): updateExttool(toolselector,currForm,suppflag);
7756:): }
7757:): }
7758:): }
1.484.2.13 raeburn 7759: }
7760: resize_scrollbox('contentscroll','1','1');
7761: return;
7762: }
7763:
1.484.2.19 raeburn 7764: function toggleMap(caller) {
1.484.2.13 raeburn 7765: var disp = 'none';
1.484.2.19 raeburn 7766: if (document.getElementById('importmapform')) {
7767: if (caller == 'map') {
7768: var curr = document.getElementById('importmapform').style.display;
7769: if (curr == 'none') {
7770: disp='block';
7771: }
1.484.2.12 raeburn 7772: }
1.484.2.19 raeburn 7773: document.getElementById('importmapform').style.display=disp;
7774: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 7775: }
1.484.2.19 raeburn 7776: return;
1.329 droeschl 7777: }
7778:
1.484.2.12 raeburn 7779: function makeims(imsform) {
7780: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 7781: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 7782: return;
7783: }
7784: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 7785: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 7786: return;
7787: }
7788: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7789: imsform.submit();
7790: }
7791:
1.478 raeburn 7792: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 7793: var pickitem;
7794: var picknumitem;
7795: var picknumtext;
7796: if (index == 'all') {
7797: pickitem = document.getElementById('randompickall');
7798: picknumitem = document.getElementById('rpicknumall');
7799: picknumtext = document.getElementById('rpicktextall');
7800: } else {
7801: pickitem = document.getElementById('randompick_'+index);
7802: picknumitem = document.getElementById('rpicknum_'+index);
7803: picknumtext = document.getElementById('randompicknum_'+index);
7804: }
1.478 raeburn 7805: if (pickitem.checked) {
1.484.2.61 raeburn 7806: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7807: if (picknum == '' || picknum == null) {
7808: if (caller == 'check') {
7809: pickitem.checked=false;
1.484.2.29 raeburn 7810: if (index == 'all') {
7811: picknumtext.innerHTML = '';
7812: if (caller == 'link') {
7813: propagateState(targetform,'rpicknum');
7814: }
7815: } else {
1.484.2.30 raeburn 7816: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7817: }
1.478 raeburn 7818: }
7819: } else {
7820: picknum.toString();
7821: var regexdigit=/^\\d+\$/;
7822: if (regexdigit.test(picknum)) {
7823: picknumitem.value = picknum;
1.484.2.29 raeburn 7824: if (index == 'all') {
1.484.2.30 raeburn 7825: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 7826: if (caller == 'link') {
7827: propagateState(targetform,'rpicknum');
7828: }
7829: } else {
7830: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 7831: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7832: }
1.478 raeburn 7833: } else {
7834: if (caller == 'check') {
1.484.2.29 raeburn 7835: if (index == 'all') {
7836: picknumtext.innerHTML = '';
7837: if (caller == 'link') {
7838: propagateState(targetform,'rpicknum');
7839: }
7840: } else {
7841: pickitem.checked=false;
1.484.2.30 raeburn 7842: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7843: }
1.478 raeburn 7844: }
7845: return;
7846: }
7847: }
7848: } else {
1.484.2.29 raeburn 7849: picknumitem.value = '';
7850: picknumtext.innerHTML = '';
7851: if (index == 'all') {
7852: if (caller == 'link') {
7853: propagateState(targetform,'rpicknum');
7854: }
7855: } else {
1.484.2.30 raeburn 7856: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7857: }
7858: }
7859: }
7860:
7861: function propagateState(form,param) {
7862: if (document.getElementById(param+'all')) {
7863: var setcheck = 0;
7864: var rpick = 0;
7865: if (param == 'rpicknum') {
7866: if (document.getElementById('randompickall')) {
7867: if (document.getElementById('randompickall').checked) {
7868: if (document.getElementById('rpicknumall')) {
7869: rpick = document.getElementById('rpicknumall').value;
7870: }
7871: }
7872: }
7873: } else {
7874: if (document.getElementById(param+'all').checked) {
7875: setcheck = 1;
7876: }
7877: }
1.484.2.30 raeburn 7878: var allidxlist;
7879: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7880: if (document.getElementById('all'+param+'idx')) {
7881: allidxlist = document.getElementById('all'+param+'idx').value;
7882: }
7883: var actions = new Array ('remove','cut','copy');
7884: for (var i=0; i<actions.length; i++) {
7885: if (actions[i] != param) {
7886: if (document.getElementById(actions[i]+'all')) {
7887: document.getElementById(actions[i]+'all').checked = false;
7888: }
7889: }
7890: }
7891: }
1.484.2.29 raeburn 7892: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 7893: allidxlist = form.allidx.value;
7894: }
7895: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7896: allidxlist = form.allmapidx.value;
7897: }
7898: if ((allidxlist != '') && (allidxlist != null)) {
7899: var allidxs = allidxlist.split(',');
7900: if (allidxs.length > 1) {
7901: for (var i=0; i<allidxs.length; i++) {
7902: if (document.getElementById(param+'_'+allidxs[i])) {
7903: if (param == 'rpicknum') {
7904: if (document.getElementById('randompick_'+allidxs[i])) {
7905: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7906: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7907: if (rpick > 0) {
7908: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7909: } else {
7910: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7911: }
7912: }
7913: }
7914: } else {
1.484.2.29 raeburn 7915: if (setcheck == 1) {
7916: document.getElementById(param+'_'+allidxs[i]).checked = true;
7917: } else {
7918: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 7919: if (param == 'randompick') {
7920: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7921: }
1.484.2.29 raeburn 7922: }
7923: }
7924: }
7925: }
1.484.2.30 raeburn 7926: if (setcheck == 1) {
7927: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7928: var actions = new Array('copy','cut','remove');
7929: for (var i=0; i<actions.length; i++) {
7930: var otheractions;
7931: var otheridxs;
7932: if (actions[i] === param) {
7933: continue;
7934: } else {
7935: if (document.getElementById('all'+actions[i]+'idx')) {
7936: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7937: otheridxs = otheractions.split(',');
7938: if (otheridxs.length > 1) {
7939: for (var j=0; j<otheridxs.length; j++) {
7940: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7941: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7942: }
1.484.2.29 raeburn 7943: }
7944: }
7945: }
7946: }
1.484.2.30 raeburn 7947: }
1.484.2.29 raeburn 7948: }
7949: }
7950: }
7951: }
1.478 raeburn 7952: }
1.484.2.29 raeburn 7953: return;
7954: }
7955:
1.484.2.63 raeburn 7956: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7957: var canedit = '$canedit';
7958: if (canedit == '') {
7959: alert("$js_lt{'edri'}");
7960: return;
7961: }
1.484.2.30 raeburn 7962: var dosettings;
7963: var doaction;
7964: var control = document.togglemultsettings;
7965: if (context == 'actions') {
7966: control = document.togglemultactions;
7967: doaction = 1;
7968: } else {
7969: dosettings = 1;
7970: }
7971: if (control) {
7972: if (control.showmultpick.length) {
7973: for (var i=0; i<control.showmultpick.length; i++) {
7974: if (control.showmultpick[i].checked) {
7975: if (control.showmultpick[i].value == 1) {
7976: if (context == 'settings') {
7977: dosettings = 0;
7978: } else {
7979: doaction = 0;
7980: }
7981: }
7982: }
7983: }
7984: }
7985: }
7986: if (context == 'settings') {
7987: if (dosettings == 1) {
7988: targetform.changeparms.value=param;
7989: targetform.submit();
7990: }
7991: }
7992: if (context == 'actions') {
7993: if (doaction == 1) {
7994: targetform.cmd.value=param+'_'+index;
7995: targetform.folderpath.value=folderpath;
7996: targetform.markcopy.value=idx+':'+param;
7997: targetform.copyfolder.value=folder+'.'+container;
7998: if (param == 'remove') {
1.484.2.63 raeburn 7999: var doremove = 0;
8000: if (skip_confirm) {
8001: if (confirm_removal) {
8002: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8003: doremove = 1;
8004: }
8005: } else {
8006: doremove = 1;
8007: }
8008: } else {
8009: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8010: doremove = 1;
8011: }
8012: }
8013: if (doremove) {
1.484.2.30 raeburn 8014: targetform.markcopy.value='';
8015: targetform.copyfolder.value='';
1.484.2.29 raeburn 8016: targetform.submit();
8017: }
8018: }
1.484.2.30 raeburn 8019: if (param == 'cut') {
1.484.2.61 raeburn 8020: 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 8021: targetform.submit();
8022: return;
8023: }
8024: }
8025: if (param == 'copy') {
8026: targetform.submit();
8027: return;
8028: }
8029: targetform.markcopy.value='';
8030: targetform.copyfolder.value='';
8031: targetform.cmd.value='';
8032: targetform.folderpath.value='';
8033: return;
8034: } else {
8035: if (document.getElementById(param+'_'+idx)) {
8036: item = document.getElementById(param+'_'+idx);
8037: if (item.type == 'checkbox') {
8038: if (item.checked) {
8039: item.checked = false;
8040: } else {
8041: item.checked = true;
8042: singleCheck(item,idx,param);
8043: }
8044: }
8045: }
8046: }
8047: }
8048: return;
8049: }
8050:
8051: function singleCheck(caller,idx,action) {
8052: actions = new Array('cut','copy','remove');
8053: if (caller.checked) {
8054: for (var i=0; i<actions.length; i++) {
8055: if (actions[i] != action) {
8056: if (document.getElementById(actions[i]+'_'+idx)) {
8057: if (document.getElementById(actions[i]+'_'+idx).checked) {
8058: document.getElementById(actions[i]+'_'+idx).checked = false;
8059: }
8060: }
8061: }
1.484.2.29 raeburn 8062: }
8063: }
8064: return;
1.478 raeburn 8065: }
8066:
1.334 muellerd 8067: function unselectInactive(nav) {
1.335 ehlerst 8068: currentNav = document.getElementById(nav);
8069: currentLis = currentNav.getElementsByTagName('LI');
8070: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8071: if (currentLis[i].className == 'goback') {
8072: currentLis[i].className = 'goback';
8073: } else {
8074: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8075: currentLis[i].className = 'right';
1.472 raeburn 8076: } else {
1.374 tempelho 8077: currentLis[i].className = 'i';
1.472 raeburn 8078: }
8079: }
1.335 ehlerst 8080: }
1.332 tempelho 8081: }
8082:
1.334 muellerd 8083: function hideAll(current, nav, data) {
1.335 ehlerst 8084: unselectInactive(nav);
1.484.2.43 raeburn 8085: if (current) {
8086: if (current.className == 'right'){
1.374 tempelho 8087: current.className = 'right active'
1.484.2.43 raeburn 8088: } else {
1.374 tempelho 8089: current.className = 'active';
1.484.2.43 raeburn 8090: }
1.374 tempelho 8091: }
1.335 ehlerst 8092: currentData = document.getElementById(data);
8093: currentDivs = currentData.getElementsByTagName('DIV');
8094: for (i = 0; i < currentDivs.length; i++) {
8095: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8096: currentDivs[i].style.display = 'none';
1.330 tempelho 8097: }
8098: }
1.335 ehlerst 8099: }
1.330 tempelho 8100:
1.374 tempelho 8101: function openTabs(pageId) {
8102: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8103: if(tabnav.length > 2 ){
1.389 tempelho 8104: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8105: currentLis = currentNav.getElementsByTagName('LI');
8106: for(i = 0; i< currentLis.length; i++){
8107: if(currentLis[i].className == 'active') {
1.375 tempelho 8108: funcString = currentLis[i].onclick.toString();
8109: tab = funcString.split('"');
1.420 onken 8110: if(tab.length < 2) {
8111: tab = funcString.split("'");
8112: }
1.375 tempelho 8113: currentData = document.getElementById(tab[1]);
8114: currentData.style.display = 'block';
1.374 tempelho 8115: }
8116: }
8117: }
8118: }
8119:
1.334 muellerd 8120: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 8121: currstate = current.className;
1.334 muellerd 8122: hideAll(current, nav, data);
1.375 tempelho 8123: openTabs(pageId);
1.334 muellerd 8124: unselectInactive(nav);
1.484.2.43 raeburn 8125: if ((currstate == 'active') || (currstate == 'right active')) {
8126: if (currstate == 'active') {
8127: current.className = '';
8128: } else {
8129: current.className = 'right';
8130: }
8131: activeTab = '';
8132: toggleUpload();
8133: toggleMap();
8134: resize_scrollbox('contentscroll','1','0');
8135: return;
8136: } else {
8137: current.className = 'active';
8138: }
1.330 tempelho 8139: currentData = document.getElementById(pageId);
8140: currentData.style.display = 'block';
1.458 raeburn 8141: activeTab = pageId;
1.484.2.12 raeburn 8142: toggleUpload();
1.484.2.14 raeburn 8143: toggleMap();
1.433 raeburn 8144: if (nav == 'mainnav') {
8145: var storedpath = "$docs_folderpath";
1.434 raeburn 8146: var storedpage = "$main_container_page";
1.433 raeburn 8147: var reg = new RegExp("^supplemental");
8148: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8149: if (storedpage == 1) {
8150: document.simpleedit.folderpath.value = '';
8151: document.uploaddocument.folderpath.value = '';
8152: } else {
8153: if (reg.test(storedpath)) {
8154: document.simpleedit.folderpath.value = '$toplevelmain';
8155: document.uploaddocument.folderpath.value = '$toplevelmain';
8156: document.newext.folderpath.value = '$toplevelmain';
8157: } else {
8158: document.simpleedit.folderpath.value = storedpath;
8159: document.uploaddocument.folderpath.value = storedpath;
8160: document.newext.folderpath.value = storedpath;
8161: }
1.433 raeburn 8162: }
8163: } else {
1.434 raeburn 8164: if (reg.test(storedpath)) {
8165: document.simpleedit.folderpath.value = storedpath;
8166: document.supuploaddocument.folderpath.value = storedpath;
8167: document.supnewext.folderpath.value = storedpath;
8168: } else {
1.433 raeburn 8169: document.simpleedit.folderpath.value = '$toplevelsupp';
8170: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8171: document.supnewext.folderpath.value = '$toplevelsupp';
8172: }
8173: }
8174: }
1.484.2.3 raeburn 8175: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8176: return false;
8177: }
1.329 droeschl 8178:
1.472 raeburn 8179: function toContents(jumpto) {
8180: var newurl = '$backtourl';
1.484.2.21 raeburn 8181: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8182: newurl = newurl+'?postdata='+jumpto;
8183: }
8184: location.href=newurl;
8185: }
8186:
1.484.2.30 raeburn 8187: function togglePick(caller,value) {
8188: var disp = 'none';
8189: if (document.getElementById('multi'+caller)) {
8190: var curr = document.getElementById('multi'+caller).style.display;
8191: if (value == 1) {
8192: disp='block';
8193: }
8194: if (curr == disp) {
8195: return;
8196: }
8197: document.getElementById('multi'+caller).style.display=disp;
8198: if (value == 1) {
1.484.2.61 raeburn 8199: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 8200: } else {
8201: document.getElementById('more'+caller).innerHTML = '';
8202: }
8203: if (caller == 'actions') {
8204: setClass(value);
8205: setBoxes(value);
8206: }
8207: }
8208: var showButton = multiSettings();
8209: if (showButton != 1) {
8210: showButton = multiActions();
8211: }
8212: if (document.getElementById('multisave')) {
8213: if (showButton == 1) {
8214: document.getElementById('multisave').style.display='block';
8215: } else {
8216: document.getElementById('multisave').style.display='none';
8217: }
8218: }
8219: resize_scrollbox('contentscroll','1','1');
8220: return;
8221: }
8222:
8223: function toggleCheckUncheck(caller,more) {
8224: if (more == 1) {
1.484.2.61 raeburn 8225: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 8226: document.getElementById('allfields'+caller).style.display='block';
8227: } else {
1.484.2.61 raeburn 8228: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 8229: document.getElementById('allfields'+caller).style.display='none';
8230: }
8231: resize_scrollbox('contentscroll','1','1');
8232: }
8233:
8234: function multiSettings() {
8235: var inuse = 0;
8236: var settingsform = document.togglemultsettings;
8237: if (settingsform.showmultpick.length > 1) {
8238: for (var i=0; i<settingsform.showmultpick.length; i++) {
8239: if (settingsform.showmultpick[i].checked) {
8240: if (settingsform.showmultpick[i].value == 1) {
8241: inuse = 1;
8242: }
8243: }
8244: }
8245: }
8246: return inuse;
8247: }
8248:
8249: function multiActions() {
8250: var inuse = 0;
8251: var actionsform = document.togglemultactions;
8252: if (actionsform.showmultpick.length > 1) {
8253: for (var i=0; i<actionsform.showmultpick.length; i++) {
8254: if (actionsform.showmultpick[i].checked) {
8255: if (actionsform.showmultpick[i].value == 1) {
8256: inuse = 1;
8257: }
8258: }
8259: }
8260: }
8261: return inuse;
8262: }
8263:
8264: function checkSubmits() {
8265: var numchanges = 0;
8266: var form = document.saveactions;
8267: var doactions = multiActions();
8268: var cutwarnings = 0;
8269: var remwarnings = 0;
1.484.2.63 raeburn 8270: var removalinfo = 0;
1.484.2.30 raeburn 8271: if (doactions == 1) {
8272: var remidxlist = document.cumulativeactions.allremoveidx.value;
8273: if ((remidxlist != '') && (remidxlist != null)) {
8274: var remidxs = remidxlist.split(',');
8275: for (var i=0; i<remidxs.length; i++) {
8276: if (document.getElementById('remove_'+remidxs[i])) {
8277: if (document.getElementById('remove_'+remidxs[i]).checked) {
8278: form.multiremove.value += remidxs[i]+',';
8279: numchanges ++;
8280: if (document.getElementById('skip_remove_'+remidxs[i])) {
8281: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8282: remwarnings ++;
8283: }
8284: }
1.484.2.63 raeburn 8285: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8286: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8287: removalinfo ++;
8288: }
8289: }
1.484.2.30 raeburn 8290: }
8291: }
8292: }
8293: }
8294: var cutidxlist = document.cumulativeactions.allcutidx.value;
8295: if ((cutidxlist != '') && (cutidxlist != null)) {
8296: var cutidxs = cutidxlist.split(',');
8297: for (var i=0; i<cutidxs.length; i++) {
8298: if (document.getElementById('cut_'+cutidxs[i])) {
8299: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8300: form.multicut.value += cutidxs[i]+',';
8301: numchanges ++;
8302: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8303: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8304: cutwarnings ++;
8305: }
8306: }
8307: }
8308: }
8309: }
8310: }
8311: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8312: if ((copyidxlist != '') && (copyidxlist != null)) {
8313: var copyidxs = copyidxlist.split(',');
8314: for (var i=0; i<copyidxs.length; i++) {
8315: if (document.getElementById('copy_'+copyidxs[i])) {
8316: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8317: form.multicopy.value += copyidxs[i]+',';
8318: numchanges ++;
8319: }
8320: }
8321: }
8322: }
8323: if (numchanges > 0) {
8324: form.multichange.value = numchanges;
8325: }
8326: }
8327: var dosettings = multiSettings();
8328: var haschanges = 0;
8329: if (dosettings == 1) {
8330: form.allencrypturl.value = '';
8331: form.allhiddenresource.value = '';
8332: form.changeparms.value = 'all';
8333: var patt=new RegExp(",\$");
8334: var allidxlist = document.cumulativesettings.allidx.value;
8335: if ((allidxlist != '') && (allidxlist != null)) {
8336: var allidxs = allidxlist.split(',');
8337: if (allidxs.length > 1) {
8338: for (var i=0; i<allidxs.length; i++) {
8339: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8340: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8341: form.allhiddenresource.value += allidxs[i]+',';
8342: }
8343: }
8344: if (document.getElementById('encrypturl_'+allidxs[i])) {
8345: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8346: form.allencrypturl.value += allidxs[i]+',';
8347: }
1.484.2.29 raeburn 8348: }
8349: }
1.484.2.30 raeburn 8350: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8351: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
8352: }
8353: }
8354: form.allrandompick.value = '';
8355: form.allrandomorder.value = '';
8356: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8357: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8358: var allmapidxs = allmapidxlist.split(',');
8359: for (var i=0; i<allmapidxs.length; i++) {
8360: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8361: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8362: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8363: if ((randompick.checked) && (rpicknum.value != '')) {
8364: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8365: }
8366: if (randorder.checked) {
8367: form.allrandomorder.value += allmapidxs[i]+',';
8368: }
8369: }
8370: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8371: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8372: }
8373: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8374: haschanges = 1;
8375: }
8376: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8377: haschanges = 1;
8378: }
8379: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8380: haschanges = 1;
8381: }
8382: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8383: haschanges = 1;
8384: }
8385: }
8386: if (doactions == 1) {
8387: if (numchanges > 0) {
1.484.2.63 raeburn 8388: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 8389: if (remwarnings > 0) {
1.484.2.61 raeburn 8390: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 8391: return false;
8392: }
8393: }
1.484.2.63 raeburn 8394: if (removalinfo > 0) {
8395: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8396: return false;
8397: }
8398: }
1.484.2.30 raeburn 8399: if (cutwarnings > 0) {
1.484.2.61 raeburn 8400: 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 8401: return false;
1.484.2.29 raeburn 8402: }
8403: }
8404: }
1.484.2.30 raeburn 8405: form.submit();
8406: return true;
8407: }
8408: }
8409: if (dosettings == 1) {
8410: if (haschanges == 1) {
8411: form.submit();
8412: return true;
1.484.2.29 raeburn 8413: }
8414: }
1.484.2.30 raeburn 8415: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 8416: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 8417: } else {
8418: if (dosettings == 1) {
1.484.2.61 raeburn 8419: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 8420: } else {
1.484.2.61 raeburn 8421: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 8422: }
8423: }
8424: return false;
8425: }
8426:
8427: function setClass(value) {
8428: var cutclass = 'LC_docs_cut';
8429: var copyclass = 'LC_docs_copy';
8430: var removeclass = 'LC_docs_remove';
8431: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8432: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8433: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8434: var links = document.getElementsByTagName('a');
8435: for (var i=0; i<links.length; i++) {
8436: var classes = links[i].className;
8437: if (cutreg.test(classes)) {
8438: links[i].className = cutclass;
8439: if (value == 1) {
8440: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 8441: }
1.484.2.30 raeburn 8442: } else {
8443: if (copyreg.test(classes)) {
8444: links[i].className = copyclass;
8445: if (value == 1) {
8446: links[i].className += " LC_menubuttons_link";
8447: }
8448: } else {
8449: if (removereg.test(classes)) {
8450: links[i].className = removeclass;
8451: if (value == 1) {
8452: links[i].className += " LC_menubuttons_link";
8453: }
8454: }
1.484.2.29 raeburn 8455: }
8456: }
8457: }
1.484.2.30 raeburn 8458: return;
1.484.2.29 raeburn 8459: }
8460:
1.484.2.30 raeburn 8461: function setBoxes(value) {
8462: var remidxlist = document.cumulativeactions.allremoveidx.value;
8463: if ((remidxlist != '') && (remidxlist != null)) {
8464: var remidxs = remidxlist.split(',');
8465: for (var i=0; i<remidxs.length; i++) {
8466: if (document.getElementById('remove_'+remidxs[i])) {
8467: var item = document.getElementById('remove_'+remidxs[i]);
8468: if (value == 1) {
8469: item.className = 'LC_docs_remove';
8470: } else {
8471: item.className = 'LC_hidden';
8472: }
8473: }
1.484.2.29 raeburn 8474: }
8475: }
1.484.2.30 raeburn 8476: var cutidxlist = document.cumulativeactions.allcutidx.value;
8477: if ((cutidxlist != '') && (cutidxlist != null)) {
8478: var cutidxs = cutidxlist.split(',');
8479: for (var i=0; i<cutidxs.length; i++) {
8480: if (document.getElementById('cut_'+cutidxs[i])) {
8481: var item = document.getElementById('cut_'+cutidxs[i]);
8482: if (value == 1) {
8483: item.className = 'LC_docs_cut';
8484: } else {
8485: item.className = 'LC_hidden';
8486: }
8487: }
8488: }
8489: }
8490: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8491: if ((copyidxlist != '') && (copyidxlist != null)) {
8492: var copyidxs = copyidxlist.split(',');
8493: for (var i=0; i<copyidxs.length; i++) {
8494: if (document.getElementById('copy_'+copyidxs[i])) {
8495: var item = document.getElementById('copy_'+copyidxs[i]);
8496: if (value == 1) {
8497: item.className = 'LC_docs_copy';
8498: } else {
8499: item.className = 'LC_hidden';
8500: }
8501: }
1.484.2.29 raeburn 8502: }
8503: }
8504: return;
8505: }
8506:
1.484.2.67 raeburn 8507: ENDSCRIPT
1.329 droeschl 8508: }
1.457 raeburn 8509:
1.483 raeburn 8510: sub history_tab_js {
8511: return <<"ENDHIST";
8512: function toggleHistoryDisp(choice) {
8513: document.docslogform.docslog.value = choice;
8514: document.docslogform.submit();
8515: return;
8516: }
8517:
8518: ENDHIST
8519: }
8520:
1.484 raeburn 8521: sub inject_data_js {
8522: return <<ENDINJECT;
8523:
8524: function injectData(current, hiddenField, name, value) {
8525: currentElement = document.getElementById(hiddenField);
8526: currentElement.name = name;
8527: currentElement.value = value;
8528: current.submit();
8529: }
8530:
8531: ENDINJECT
8532: }
8533:
8534: sub dump_switchserver_js {
8535: my @hosts = @_;
1.484.2.61 raeburn 8536: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 8537: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8538: swit => 'Switch server?',
1.484.2.61 raeburn 8539: );
8540: my %html_js_lt = &Apache::lonlocal::texthash(
8541: swit => 'Switch server?',
1.484.2.43 raeburn 8542: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8543: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8544: chos => 'Choose server',
8545: );
1.484.2.61 raeburn 8546: &js_escape(\%js_lt);
8547: &html_escape(\%html_js_lt);
8548: &js_escape(\%html_js_lt);
1.484 raeburn 8549: my $role = $env{'request.role'};
8550: my $js = <<"ENDSWJS";
8551: <script type="text/javascript">
8552: function write_switchserver() {
8553: var server;
8554: if (document.setserver.posshosts.length > 0) {
8555: for (var i=0; i<document.setserver.posshosts.length; i++) {
8556: if (document.setserver.posshosts[i].checked) {
8557: server = document.setserver.posshosts[i].value;
8558: }
8559: }
8560: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8561: }
8562: window.close();
8563: }
8564: </script>
8565:
8566: ENDSWJS
8567:
8568: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8569: {'only_body' => 1,
8570: 'js_ready' => 1,});
8571: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8572:
8573: my $hostpicker;
8574: my $count = 0;
8575: foreach my $host (sort(@hosts)) {
8576: my $checked;
8577: if ($count == 0) {
8578: $checked = ' checked="checked"';
8579: }
8580: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8581: $host.'"'.$checked.' />'.$host.'</label> ';
8582: $count++;
8583: }
8584:
8585: return <<"ENDSWITCHJS";
8586:
8587: function dump_needs_switchserver(url) {
8588: if (url!='' && url!= null) {
1.484.2.61 raeburn 8589: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8590: go(url);
8591: }
8592: }
8593: return;
8594: }
8595:
8596: function choose_switchserver_window() {
8597: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8598: newWindow.document.open();
8599: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 8600: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8601: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8602: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8603: '<form name="setserver" method="post" action="" \\/>\\n'+
8604: '$hostpicker\\n'+
8605: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 8606: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8607: 'onclick="write_switchserver();" \\/>\\n'+
8608: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8609: newWindow.document.writeln('$endpage');
8610: newWindow.document.close();
8611: newWindow.focus();
8612: }
8613:
8614: ENDSWITCHJS
8615: }
8616:
8617: sub makedocslogform {
8618: my ($formelems,$docslog) = @_;
8619: return <<"LOGSFORM";
8620: <form action="/adm/coursedocs" method="post" name="docslogform">
8621: <input type="hidden" name="docslog" value="$docslog" />
8622: $formelems
8623: </form>
8624: LOGSFORM
8625: }
8626:
8627: sub makesimpleeditform {
8628: my ($formelems) = @_;
8629: return <<"SIMPFORM";
8630: <form name="simpleedit" method="post" action="/adm/coursedocs">
8631: <input type="hidden" name="importdetail" value="" />
8632: $formelems
8633: </form>
8634: SIMPFORM
8635: }
8636:
1.329 droeschl 8637: 1;
8638: __END__
8639:
8640:
8641: =head1 NAME
8642:
8643: Apache::londocs.pm
8644:
8645: =head1 SYNOPSIS
8646:
8647: This is part of the LearningOnline Network with CAPA project
8648: described at http://www.lon-capa.org.
8649:
8650: =head1 SUBROUTINES
8651:
8652: =over
8653:
8654: =item %help=()
8655:
8656: Available help topics
8657:
8658: =item mapread()
8659:
1.344 bisitz 8660: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8661: @order and @resources, determines status
8662: sets @order - pointer to resources in right order
8663: sets @resources - array with the resources with correct idx
8664:
8665: =item authorhosts()
8666:
8667: Return hash with valid author names
8668:
8669: =item clean()
8670:
8671: =item dumpcourse()
8672:
8673: Actually dump course
8674:
8675: =item group_import()
8676:
8677: Imports the given (name, url) resources into the course
8678: coursenum, coursedom, and folder must precede the list
8679:
8680: =item breadcrumbs()
8681:
8682: =item log_docs()
8683:
8684: =item docs_change_log()
8685:
8686: =item update_paste_buffer()
8687:
8688: =item print_paste_buffer()
8689:
8690: =item do_paste_from_buffer()
8691:
1.484.2.30 raeburn 8692: =item do_buffer_empty()
8693:
8694: =item clear_from_buffer()
8695:
1.484.2.7 raeburn 8696: =item get_newmap_url()
8697:
8698: =item dbcopy()
8699:
8700: =item uniqueness_check()
8701:
8702: =item contained_map_check()
8703:
8704: =item url_paste_fixups()
8705:
8706: =item apply_fixups()
8707:
8708: =item copy_dependencies()
8709:
1.329 droeschl 8710: =item update_parameter()
8711:
8712: =item handle_edit_cmd()
8713:
8714: =item editor()
8715:
8716: =item process_file_upload()
8717:
8718: =item process_secondary_uploads()
8719:
8720: =item is_supplemental_title()
8721:
8722: =item entryline()
8723:
8724: =item tiehash()
8725:
8726: =item untiehash()
8727:
8728: =item checkonthis()
8729:
8730: check on this
8731:
8732: =item verifycontent()
8733:
8734: Verify Content
8735:
1.484.2.78 raeburn 8736: =item devalidateversioncache()
8737:
8738: =item checkversions()
1.329 droeschl 8739:
8740: Check Versions
8741:
8742: =item mark_hash_old()
8743:
8744: =item is_hash_old()
8745:
8746: =item changewarning()
8747:
8748: =item init_breadcrumbs()
8749:
8750: Breadcrumbs for special functions
8751:
1.484 raeburn 8752: =item create_list_elements()
8753:
8754: =item create_form_ul()
8755:
8756: =item startContentScreen()
8757:
8758: =item endContentScreen()
8759:
8760: =item supplemental_base()
8761:
8762: =item embedded_form_elems()
8763:
8764: =item embedded_destination()
8765:
8766: =item return_to_editor()
8767:
8768: =item decompression_info()
8769:
8770: =item decompression_phase_one()
8771:
8772: =item decompression_phase_two()
8773:
8774: =item remove_archive()
8775:
8776: =item generate_admin_menu()
8777:
8778: =item generate_edit_table()
8779:
8780: =item editing_js()
8781:
8782: =item history_tab_js()
8783:
8784: =item inject_data_js()
8785:
8786: =item dump_switchserver_js()
8787:
1.484.2.3 raeburn 8788: =item resize_scrollbox_js()
1.484 raeburn 8789:
8790: =item makedocslogform()
8791:
1.484.2.3 raeburn 8792: =item makesimpleeditform()
8793:
1.329 droeschl 8794: =back
8795:
8796: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>