Annotation of loncom/interface/londocs.pm, revision 1.484.2.93.2.11
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.93.2. 1(raebur 4:3): # $Id: londocs.pm,v 1.484.2.93.2.10 2023/01/20 16:55:44 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.484.2.19 raeburn 43: use Apache::lonextresedit();
1.484.2.43 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.484.2.93.2. (raeburn 46:): use Apache::loncourserespicker();
1.329 droeschl 47: use HTML::Entities;
1.484.2.7 raeburn 48: use HTML::TokeParser;
1.329 droeschl 49: use GDBM_File;
1.484.2.51 raeburn 50: use File::MMagic;
1.329 droeschl 51: use Apache::lonlocal;
52: use Cwd;
53: use LONCAPA qw(:DEFAULT :match);
54:
55: my $iconpath;
56:
57: my %hash;
58:
59: my $hashtied;
60: my %alreadyseen=();
61:
62: my $hadchanges;
1.484.2.37 raeburn 63: my $suppchanges;
1.329 droeschl 64:
65:
66: my %help=();
67:
68:
69: sub mapread {
70: my ($coursenum,$coursedom,$map)=@_;
71: return
72: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
73: $map);
74: }
75:
76: sub storemap {
1.484.2.7 raeburn 77: my ($coursenum,$coursedom,$map,$contentchg)=@_;
78: my $report;
79: if (($contentchg) && ($map =~ /^default/)) {
80: $report = 1;
81: }
1.329 droeschl 82: my ($outtext,$errtext)=
83: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.484.2.7 raeburn 84: $map,1,$report);
1.329 droeschl 85: if ($errtext) { return ($errtext,2); }
1.364 bisitz 86:
1.484.2.37 raeburn 87: if ($map =~ /^default/) {
88: $hadchanges=1;
1.484.2.93.2. 0(raebur 89:3): } elsif ($contentchg) {
1.484.2.37 raeburn 90: $suppchanges=1;
91: }
1.329 droeschl 92: return ($errtext,0);
93: }
94:
95:
96:
97: sub authorhosts {
98: my %outhash=();
99: my $home=0;
100: my $other=0;
101: foreach my $key (keys(%env)) {
102: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
103: my $role=$1;
104: my $realm=$2;
105: my ($start,$end)=split(/\./,$env{$key});
106: if (($start) && ($start>time)) { next; }
107: if (($end) && (time>$end)) { next; }
108: my ($ca,$cd);
109: if ($1 eq 'au') {
110: $ca=$env{'user.name'};
111: $cd=$env{'user.domain'};
112: } else {
113: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
114: }
115: my $allowed=0;
116: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
117: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 118: foreach my $id (@ids) {
119: if ($id eq $myhome) {
120: $allowed=1;
121: last;
122: }
123: }
1.329 droeschl 124: if ($allowed) {
125: $home++;
1.484 raeburn 126: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 127: } else {
1.484 raeburn 128: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 129: $other++;
130: }
131: }
132: }
133: return ($home,$other,%outhash);
134: }
135:
136:
137: sub clean {
138: my ($title)=@_;
139: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 140: return $title;
1.329 droeschl 141: }
142:
1.484.2.67 raeburn 143: sub default_folderpath {
144: my ($coursenum,$coursedom,$navmapref) = @_;
145: return unless ($coursenum && $coursedom && ref($navmapref));
146: # Check if entire course is hidden and/or encrypted
147: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
148: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
149: unless (ref($$navmapref)) {
150: $$navmapref = Apache::lonnavmaps::navmap->new();
151: }
152: if (ref($$navmapref)) {
153: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
154: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
155: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
156: unless (@resources) {
157: $hiddenmap = 1;
158: unless ($env{'request.role.adv'}) {
159: $hiddentop = 1;
160: if ($env{'form.folder'}) {
161: undef($env{'form.folder'});
162: }
163: }
164: }
165: }
166: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
167: $encryptmap = 1;
168: }
169: }
170: unless ($hiddentop) {
171: $folderpath='default&'.&escape(&mt('Main Content')).
172: '::'.$hiddenmap.':'.$encryptmap.'::';
173: }
174: if (wantarray) {
175: return ($folderpath,$hiddentop);
176: } else {
177: return $folderpath;
178: }
179: }
1.329 droeschl 180:
1.484.2.93.2. 0(raebur 181:3): sub validate_supppath {
182:3): my ($coursenum,$coursedom) = @_;
183:3): my $backto;
1.484.2.92 raeburn 184: if ($env{'form.supppath'} ne '') {
185: my @items = split(/\&/,$env{'form.supppath'});
1.484.2.93.2. 0(raebur 186:3): my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
1.484.2.92 raeburn 187: for (my $i=0; $i<@items; $i++) {
188: my $odd = $i%2;
189: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
190: $badpath = 1;
1.484.2.93.2. 0(raebur 191:3): last;
192:3): } elsif ($odd) {
193:3): my $suffix;
194:3): my $idx = $i-1;
195:3): if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
196:3): $backto .= '&'.$1;
197:3): } elsif ($items[$idx] eq 'supplemental') {
198:3): $backto .= '&'.$items[$i];
199:3): } else {
200:3): $backto .= '&'.$items[$i];
201:3): my $is_hidden;
202:3): unless ($got_supp) {
203:3): my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
204:3): if (ref($supplemental) eq 'HASH') {
205:3): if (ref($supplemental->{'hidden'}) eq 'HASH') {
206:3): %supphidden = %{$supplemental->{'hidden'}};
207:3): }
208:3): if (ref($supplemental->{'ids'}) eq 'HASH') {
209:3): %suppids = %{$supplemental->{'ids'}};
210:3): }
211:3): }
212:3): $got_supp = 1;
213:3): }
214:3): if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
215:3): my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
216:3): if ($supphidden{$mapid}) {
217:3): $is_hidden = 1;
218:3): }
219:3): }
220:3): $suffix = '::'.$is_hidden.':::';
221:3): }
222:3): $supppath .= '&'.$items[$i].$suffix;
223:3): } else {
224:3): $supppath .= '&'.$items[$i];
225:3): $backto .= '&'.$items[$i];
1.484.2.92 raeburn 226: }
227: }
228: if ($badpath) {
229: delete($env{'form.supppath'});
1.484.2.93.2. 0(raebur 230:3): } else {
231:3): $supppath =~ s/^\&//;
232:3): $backto =~ s/^\&//;
233:3): $env{'form.supppath'} = $supppath;
1.484.2.92 raeburn 234: }
235: }
1.484.2.93.2. 0(raebur 236:3): return $backto;
1.484.2.92 raeburn 237: }
238:
1.329 droeschl 239: sub dumpcourse {
240: my ($r) = @_;
1.408 raeburn 241: my $crstype = &Apache::loncommon::course_type();
1.484.2.43 raeburn 242: my ($starthash,$js);
243: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
244: $js = <<"ENDJS";
245: <script type="text/javascript">
246: // <![CDATA[
247:
248: function hide_searching() {
249: if (document.getElementById('searching')) {
250: document.getElementById('searching').style.display = 'none';
251: }
252: return;
253: }
254:
255: // ]]>
256: </script>
257: ENDJS
258: $starthash = {
259: add_entries => {'onload' => "hide_searching();"},
260: };
261: }
262: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
263: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 264: $r->print(&startContentScreen('tools'));
1.329 droeschl 265: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 266: unless ($home) {
267: $r->print(&endContentScreen());
268: return '';
269: }
1.329 droeschl 270: my $origcrsid=$env{'request.course.id'};
271: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
272: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
273: # Do the dumping
1.484 raeburn 274: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
275: $r->print(&endContentScreen());
276: return '';
277: }
1.484.2.24 raeburn 278: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 279: $r->print('<h3>'.&mt('Copying Files').'</h3>');
280: my $title=$env{'form.authorfolder'};
281: $title=&clean($title);
1.484.2.43 raeburn 282: my ($navmap,$errormsg) =
283: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
284: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
285: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
286: my (%maps,%resources,%titles);
287: if (!ref($navmap)) {
288: $r->print($errormsg.
289: &endContentScreen());
290: return '';
291: } else {
292: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
293: 'dumpdocs',$cdom,$cnum);
294: }
295: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
296: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
297: %newcontent,%has_simpleprobs);
298: foreach my $item (sort {$a <=> $b} (@todump)) {
299: my $name = $env{'form.namefor_'.$item};
300: if ($resources{$item}) {
301: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
302: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
303: $tocopy{$1} = $name;
304: $display{$item} = $1;
305: $lookup{$1} = $item;
306: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
307: $simpleproblems{$item} = {
308: symb => $resources{$item},
309: name => $name,
310: };
311: $display{$item} = 'simpleproblem_'.$name;
312: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
313: $has_simpleprobs{$1}{$id} = $item;
314: }
315: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
316: my $marker = $1;
317: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
318: $simplepages{$item} = {
319: res => $res,
320: title => $titles{$item},
321: db => $db_name,
322: marker => $marker,
323: symb => $resources{$item},
324: name => $name,
325: };
326: $display{$item} = '/'.$res;
327: }
328: } elsif ($maps{$item}) {
329: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
330: $tocopy{$1} = $name;
331: $display{$item} = $1;
332: $lookup{$1} = $item;
333: }
334: } else {
335: next;
336: }
337: }
1.329 droeschl 338: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
339: $crs=~s/\_/\//g;
1.484.2.43 raeburn 340: my $mm = new File::MMagic;
341: my $prefix = "/uploaded/$cdom/$cnum/";
342: %replacehash = %tocopy;
343: foreach my $item (sort(keys(%simpleproblems))) {
344: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
345: $newcontent{$display{$item}} = $content;
346: }
347: my $gateway = Apache::lonhtmlgateway->new('web');
348: foreach my $item (sort(keys(%simplepages))) {
349: if (ref($simplepages{$item}) eq 'HASH') {
350: my $pagetitle = $simplepages{$item}{'title'};
351: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
352: my %contents;
353: foreach my $field (keys(%fields)) {
354: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
355: my $name = $1;
356: my $msg = $fields{$field};
357: if ($name eq 'webreferences') {
358: if ($msg =~ m{^https?://}) {
359: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
360: }
361: } else {
362: $msg = &Encode::decode('utf8',$msg);
363: $msg = $gateway->process_outgoing_html($msg,1);
364: $contents{$name} = $msg;
365: }
366: } elsif ($field eq 'uploaded.photourl') {
367: my $marker = $simplepages{$item}{marker};
368: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
369: my $filepath = $1;
370: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
371: if ($fname ne '') {
372: $fname=~s/\.(\w+)$//;
373: my $ext=$1;
374: $fname = &clean($fname);
375: $fname.='.'.$ext;
376: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
377: $replacehash{$filepath} = $relpath.$fname;
378: $deps{$item}{$filepath} = 1;
379: }
380: }
381: }
382: }
383: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
384: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
385: my $content = '
386: <html>
387: <head>
388: <title>'.$pagetitle.'</title>
389: </head>
390: <body bgcolor="#ffffff">';
391: if ($contents{title}) {
392: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
393: }
394: if ($contents{image}) {
395: $content .= "\n".$contents{image};
396: }
397: if ($contents{content}) {
398: $content .= '
399: <div class="LC_Box">
1.484.2.50 raeburn 400: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.484.2.43 raeburn 401: $contents{content}.'
402: </div>';
403: }
404: if ($contents{webreferences}) {
405: $content .= '
406: <div class="LC_Box">
1.484.2.50 raeburn 407: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.484.2.43 raeburn 408: $contents{webreferences}.'
409: </div>';
410: }
411: $content .= '
412: </body>
413: </html>
414: ';
415: $newcontent{'/'.$simplepages{$item}{res}} = $content;
416: }
417: }
418: foreach my $item (keys(%tocopy)) {
419: unless ($item=~/\.(sequence|page)$/) {
420: my $currurlpath = $prefix.$item;
421: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
422: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
423: }
424: }
425: foreach my $num (sort {$a <=> $b} (@todump)) {
426: my $src = $display{$num};
427: next if ($src eq '');
428: my @needcopy = ();
429: if ($replacehash{$src}) {
430: push(@needcopy,$src);
431: if (ref($deps{$num}) eq 'HASH') {
432: foreach my $dep (sort(keys(%{$deps{$num}}))) {
433: if ($replacehash{$dep}) {
434: push(@needcopy,$dep);
435: }
436: }
437: }
438: } elsif ($src =~ /^simpleproblem_/) {
439: push(@needcopy,$src);
440: }
441: next if (@needcopy == 0);
442: my ($result,$depresult);
443: for (my $i=0; $i<@needcopy; $i++) {
444: my $item = $needcopy[$i];
445: my $newfilename;
446: if ($simpleproblems{$num}) {
447: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
448: } else {
449: $newfilename=$title.'/'.$replacehash{$item};
450: }
451: $newfilename=~s/\.(\w+)$//;
452: my $ext=$1;
453: $newfilename=&clean($newfilename);
454: $newfilename.='.'.$ext;
455: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
456: if ($newrelpath ne $replacehash{$item}) {
457: $replacehash{$item} = $newrelpath;
458: }
459: my @dirs=split(/\//,$newfilename);
460: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
461: my $makepath=$path;
462: my $fail;
463: my $origin;
464: for (my $i=0;$i<$#dirs;$i++) {
465: $makepath.='/'.$dirs[$i];
466: unless (-e $makepath) {
467: unless(mkdir($makepath,0755)) {
468: $fail = &mt('Directory creation failed.');
469: }
470: }
471: }
472: if ($i == 0) {
473: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
474: } else {
475: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
476: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
477: &mt('(dependency)').'</span>: ';
478: }
479: if (-e $path.'/'.$newfilename) {
480: $fail = &mt('Destination already exists -- not overwriting.');
481: } else {
482: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
483: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
484: ($item =~ /^simpleproblem_/)) {
485: print $fh $newcontent{$item};
486: } else {
487: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
488: if (-e $fileloc) {
489: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
490: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
491: (ref($has_simpleprobs{$item}) eq 'HASH')) {
492: my %changes = %{$has_simpleprobs{$item}};
493: my $content = &Apache::lonclonecourse::rewritefile(
494: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
495: (%replacehash,$crs => '')
496: );
497: my $updatedcontent = '';
498: my $parser = HTML::TokeParser->new(\$content);
499: $parser->attr_encoded(1);
500: while (my $token = $parser->get_token) {
501: if ($token->[0] eq 'S') {
502: if (($token->[1] eq 'resource') &&
503: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
504: ($changes{$token->[2]->{'id'}})) {
505: my $id = $token->[2]->{'id'};
506: $updatedcontent .= '<'.$token->[1];
507: foreach my $attrib (@{$token->[3]}) {
508: next unless ($attrib =~ /^(src|type|title|id)$/);
509: if ($attrib eq 'src') {
510: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
511: if ($file) {
512: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
513: } else {
514: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
515: }
516: } else {
517: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
518: }
519: }
520: $updatedcontent .= ' />'."\n";
521: } else {
522: $updatedcontent .= $token->[4]."\n";
523: }
524: } else {
525: $updatedcontent .= $token->[2];
526: }
527: }
528: print $fh $updatedcontent;
529: } else {
530: print $fh &Apache::lonclonecourse::rewritefile(
531: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
532: (%replacehash,$crs => '')
533: );
534: }
535: } else {
536: print $fh
537: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
538: }
539: } else {
540: $fail = &mt('Source does not exist.');
541: }
542: }
543: $fh->close();
544: } else {
545: $fail = &mt('Could not write to destination.');
546: }
547: }
548: my $text;
549: if ($fail) {
550: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
551: } else {
552: $text = '<span class="LC_success">'.&mt('ok').'</span>';
553: }
554: if ($i == 0) {
555: $result .= $text;
556: } else {
557: $depresult .= $text.'</li>';
558: }
559: }
560: $r->print($result);
561: if ($depresult) {
562: $r->print('<ul>'.$depresult.'</ul>');
563: }
564: }
1.329 droeschl 565: } else {
1.484.2.43 raeburn 566: my ($navmap,$errormsg) =
567: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
568: if (!ref($navmap)) {
569: $r->print($errormsg);
570: } else {
571: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
572: $r->rflush();
573: my ($preamble,$formname);
574: $formname = 'dumpdoc';
575: unless ($home==1) {
576: $preamble = '<div class="LC_left_float">'.
577: '<fieldset><legend>'.
578: &mt('Select the Authoring Space').
579: '</legend><select name="authorspace">';
580: }
581: my @orderspaces = ();
582: foreach my $key (sort(keys(%outhash))) {
583: if ($key=~/^home_(.+)$/) {
584: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
585: unshift(@orderspaces,$1);
586: } else {
587: push(@orderspaces,$1);
588: }
589: }
590: }
591: if ($home>1) {
592: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
593: }
594: foreach my $user (@orderspaces) {
595: if ($home==1) {
596: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
597: } else {
598: $preamble .= '<option value="'.$user.'">'.$user.' - '.
599: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
600: }
601: }
602: unless ($home==1) {
603: $preamble .= '</select></fieldset></div>'."\n";
604: }
605: my $title=$origcrsdata{'description'};
606: $title=~s/[\/\s]+/\_/gs;
607: $title=&clean($title);
608: $preamble .= '<div class="LC_left_float">'.
609: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
610: '<input type="text" size="50" name="authorfolder" value="'.
611: $title.'" />'.
612: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
613: my %uploadedfiles;
614: &tiehash();
615: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
616: my ($ext)=($file=~/\.(\w+)$/);
617: # FIXME Check supplemental here
618: my $title=$hash{'title_'.$hash{
619: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
620: if (!$title) {
621: $title=$file;
622: } else {
623: $title=~s|/|_|g;
624: }
625: $title=~s/\.(\w+)$//;
626: $title=&clean($title);
627: $title.='.'.$ext;
628: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
629: $uploadedfiles{$file} = $title;
630: }
631: &untiehash();
632: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
633: undef,undef,$preamble,$home,\%uploadedfiles));
634: }
1.329 droeschl 635: }
1.484 raeburn 636: $r->print(&endContentScreen());
1.329 droeschl 637: }
638:
1.484.2.43 raeburn 639: sub recurse_html {
640: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
641: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
642: my (%allfiles,%codebase);
643: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
644: if (keys(%allfiles)) {
645: foreach my $dependency (keys(%allfiles)) {
646: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
647: my ($depurl,$relfile,$newcontainer);
648: if ($dependency =~ m{^/}) {
649: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
650: $relfile = $1;
651: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
652: $newcontainer = $1;
653: next if ($replacehash->{$newcontainer});
654: }
655: $depurl = $dependency;
656: } else {
657: next;
658: }
659: } else {
660: $relfile = $dependency;
661: $depurl = $currurlpath;
662: $depurl =~ s{[^/]+$}{};
663: $depurl .= $dependency;
664: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
665: }
666: next if ($relfile eq '');
667: my $newname = $replacehash->{$container};
668: $newname =~ s{[^/]+$}{};
669: $replacehash->{$newcontainer} = $newname.$relfile;
670: $deps->{$item}{$newcontainer} = 1;
671: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
672: my $depfile = &Apache::lonnet::filelocation('',$depurl);
673: my $type = $mm->checktype_filename($depfile);
674: if ($type eq 'text/html') {
675: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
676: }
677: }
678: }
679: }
680: return;
681: }
682:
1.329 droeschl 683: sub group_import {
1.484.2.93.2. (raeburn 684:): my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.484.2.23 raeburn 685: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
686: %removeparam,$importuploaded,$fixuperrors);
687: $allmaps = {};
1.329 droeschl 688: while (@files) {
689: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 690: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 691: && ($caller eq 'londocs')
692: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 693:
1.329 droeschl 694: my $errtext = '';
695: my $fatal = 0;
696: my $newmapstr = '<map>'."\n".
697: '<resource id="1" src="" type="start"></resource>'."\n".
698: '<link from="1" to="2" index="1"></link>'."\n".
699: '<resource id="2" src="" type="finish"></resource>'."\n".
700: '</map>';
701: $env{'form.output'}=$newmapstr;
702: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
703: 'output',$1.$2);
1.484.2.27 raeburn 704: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 705: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
706: $fatal = 2;
707: }
708: if ($fatal) {
709: return ($errtext,$fatal);
710: }
711: }
712: if ($url) {
1.484.2.93.2. (raeburn 713:): if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
714:): $url = $1;
715:): my $marker = $2;
716:): my $info = $3;
717:): my ($toolid,%toolhash,%toolsettings);
718:): my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
719:): my @toolinfo = split(/:/,$info);
720:): if ($residx) {
721:): %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
722:): $toolid = $toolsettings{'id'};
723:): } else {
724:): $toolid = shift(@toolinfo);
725:): }
726:): $toolid =~ s/\D//g;
727:): ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
728:): $toolhash{'linktext'},$toolhash{'explanation'},
729:): $toolhash{'crslabel'},$toolhash{'crstitle'},$toolhash{'crsappend'}) = @toolinfo;
730:): foreach my $item (@extras) {
731:): $toolhash{$item} = &unescape($toolhash{$item});
732:): }
733:): if (ref($ltitoolsref) eq 'HASH') {
734:): my @deleted;
735:): if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
736:): $toolhash{'id'} = $toolid;
737:): if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
738:): ($toolhash{'target'} eq 'window')) {
739:): if ($toolhash{'target'} eq 'window') {
740:): foreach my $item ('width','height') {
741:): $toolhash{$item} =~ s/^\s+//;
742:): $toolhash{$item} =~ s/\s+$//;
743:): if ($toolhash{$item} =~ /\D/) {
744:): delete($toolhash{$item});
745:): if ($residx) {
746:): if ($toolsettings{$item}) {
747:): push(@deleted,$item);
748:): }
749:): }
750:): }
751:): }
752:): }
753:): } elsif ($residx) {
754:): $toolhash{'target'} = $toolsettings{'target'};
755:): if ($toolhash{'target'} eq 'window') {
756:): foreach my $item ('width','height') {
757:): $toolhash{$item} = $toolsettings{$item};
758:): }
759:): }
760:): } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
761:): $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
762:): if ($toolhash{'target'} eq 'window') {
763:): $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
764:): $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
765:): }
766:): }
767:): if ($toolhash{'target'} eq 'iframe') {
768:): foreach my $item ('width','height','linktext','explanation') {
769:): delete($toolhash{$item});
770:): if ($residx) {
771:): if ($toolsettings{$item}) {
772:): push(@deleted,$item);
773:): }
774:): }
775:): }
776:): } elsif ($toolhash{'target'} eq 'tab') {
777:): foreach my $item ('width','height') {
778:): delete($toolhash{$item});
779:): if ($residx) {
780:): if ($toolsettings{$item}) {
781:): push(@deleted,$item);
782:): }
783:): }
784:): }
785:): }
786:): if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
787:): foreach my $item ('label','title','linktext','explanation') {
788:): my $crsitem;
789:): if (($item eq 'label') || ($item eq 'title')) {
790:): $crsitem = 'crs'.$item;
791:): } else {
792:): $crsitem = $item;
793:): }
794:): if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
795:): $toolhash{$crsitem} =~ s/^\s+//;
796:): $toolhash{$crsitem} =~ s/\s+$//;
797:): if ($toolhash{$crsitem} eq '') {
798:): delete($toolhash{$crsitem});
799:): }
800:): } else {
801:): delete($toolhash{$crsitem});
802:): }
803:): if (($residx) && (exists($toolsettings{$crsitem}))) {
804:): unless (exists($toolhash{$crsitem})) {
805:): push(@deleted,$crsitem);
806:): }
807:): }
808:): }
809:): }
810:): my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
811:): if ($putres eq 'ok') {
812:): if (@deleted) {
813:): &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
814:): }
815:): } else {
816:): return (&mt('Failed to save update to external tool.'),1);
817:): }
818:): }
819:): }
820:): }
1.484.2.23 raeburn 821: if (($caller eq 'londocs') &&
822: ($folder =~ /^default/)) {
1.484.2.27 raeburn 823: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 824: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
825: my $cid = $coursedom.'_'.$coursenum;
826: $allmaps =
827: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
828: $chome,$cid);
829: $donechk = 1;
830: }
831: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.484.2.93.2. (raeburn 832:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
833:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.484.2.23 raeburn 834: $importuploaded = 1;
835: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
836: next if ($allmaps->{$url});
837: }
838: }
1.344 bisitz 839: if (!$residx
1.329 droeschl 840: || defined($LONCAPA::map::zombies[$residx])) {
841: $residx = &LONCAPA::map::getresidx($url,$residx);
842: push(@LONCAPA::map::order, $residx);
843: }
844: my $ext = 'false';
845: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.484.2.27 raeburn 846: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
847: my $filepath = $1;
1.484.2.91 raeburn 848: my $fname;
849: if ($name eq '') {
850: $name = &mt('Web Page');
1.484.2.27 raeburn 851: $fname = 'web';
852: } else {
1.484.2.91 raeburn 853: $fname = $name;
854: $fname=&Apache::lonnet::clean_filename($fname);
855: if ($fname eq '') {
856: $fname = 'web';
857: } elsif (length($fname) > 15) {
858: $fname = substr($fname,0,14);
859: }
1.484.2.27 raeburn 860: }
1.484.2.91 raeburn 861: my $title = &Apache::loncommon::cleanup_html($name);
1.484.2.27 raeburn 862: my $initialtext = &mt('Replace with your own content.');
863: my $newhtml = <<END;
1.484.2.31 raeburn 864: <html>
1.484.2.27 raeburn 865: <head>
1.484.2.91 raeburn 866: <title>$title</title>
1.484.2.27 raeburn 867: </head>
868: <body bgcolor="#ffffff">
869: $initialtext
870: </body>
871: </html>
872: END
873: $env{'form.output'}=$newhtml;
874: my $result =
875: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
876: 'output',
877: "$filepath/$residx/$fname.html");
878: if ($result =~ m{^/uploaded/}) {
879: $url = $result;
880: if ($filepath =~ /^supplemental/) {
881: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
882: $env{'user.domain'}.'___&&&___'.$name;
883: }
884: } else {
885: return (&mt('Failed to save new web page.'),1);
886: }
887: }
1.484.2.91 raeburn 888: $name = &LONCAPA::map::qtunescape($name);
1.484.2.30 raeburn 889: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 890: $LONCAPA::map::resources[$residx] =
1.329 droeschl 891: join(':', ($name, $url, $ext, 'normal', 'res'));
892: }
893: }
1.484.2.23 raeburn 894: if ($importuploaded) {
895: my %import_errors;
896: my %updated = (
897: removefrommap => \%removefrommap,
898: removeparam => \%removeparam,
899: );
1.484.2.26 raeburn 900: my ($result,$msgsarray,$lockerror) =
901: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 902: if (keys(%import_errors) > 0) {
903: $fixuperrors =
904: '<p span class="LC_warning">'."\n".
905: &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".
906: '<ul>'."\n";
907: foreach my $key (sort(keys(%import_errors))) {
908: $fixuperrors .= '<li>'.$key.'</li>'."\n";
909: }
910: $fixuperrors .= '</ul></p>'."\n";
911: }
1.484.2.26 raeburn 912: if (ref($msgsarray) eq 'ARRAY') {
913: if (@{$msgsarray} > 0) {
914: $fixuperrors .= '<p class="LC_info">'.
915: join('<br />',@{$msgsarray}).
916: '</p>';
917: }
918: }
919: if ($lockerror) {
920: $fixuperrors .= '<p class="LC_error">'.
921: $lockerror.
922: '</p>';
923: }
1.484.2.23 raeburn 924: }
925: my ($errtext,$fatal) =
926: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 927: unless ($fatal) {
928: if ($folder =~ /^supplemental/) {
1.484.2.39 raeburn 929: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
930: $folder.'.'.$container);
1.484.2.37 raeburn 931: }
932: }
1.484.2.23 raeburn 933: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 934: }
935:
936: sub log_docs {
1.484.2.8 raeburn 937: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 938: }
939:
940: {
941: my @oldresources=();
942: my @oldorder=();
943: my $parmidx;
944: my %parmaction=();
945: my %parmvalue=();
946: my $changedflag;
947:
948: sub snapshotbefore {
949: @oldresources=@LONCAPA::map::resources;
950: @oldorder=@LONCAPA::map::order;
951: $parmidx=undef;
952: %parmaction=();
953: %parmvalue=();
954: $changedflag=0;
955: }
956:
957: sub remember_parms {
958: my ($idx,$parameter,$action,$value)=@_;
959: $parmidx=$idx;
960: $parmaction{$parameter}=$action;
961: $parmvalue{$parameter}=$value;
962: $changedflag=1;
963: }
964:
965: sub log_differences {
966: my ($plain)=@_;
967: my %storehash=('folder' => $plain,
968: 'currentfolder' => $env{'form.folder'});
969: if ($parmidx) {
970: $storehash{'parameter_res'}=$oldresources[$parmidx];
971: foreach my $parm (keys(%parmaction)) {
972: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
973: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
974: }
975: }
976: my $maxidx=$#oldresources;
977: if ($#LONCAPA::map::resources>$#oldresources) {
978: $maxidx=$#LONCAPA::map::resources;
979: }
980: for (my $idx=0; $idx<=$maxidx; $idx++) {
981: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
982: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
983: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
984: $changedflag=1;
985: }
986: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
987: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
988: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
989: $changedflag=1;
990: }
991: }
992: $storehash{'maxidx'}=$maxidx;
993: if ($changedflag) { &log_docs(\%storehash); }
994: }
995: }
996:
997: sub docs_change_log {
1.484.2.67 raeburn 998: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 999: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 1000: my $navmap;
1.483 raeburn 1001: my $js = '<script type="text/javascript">'."\n".
1002: '// <![CDATA['."\n".
1003: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 1004: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.93.2. (raeburn 1005:): $coursedom,$coursenum,'',$canedit,'',\$navmap)."\n".
1.483 raeburn 1006: &history_tab_js()."\n".
1.484 raeburn 1007: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 1008: '// ]]>'."\n".
1009: '</script>'."\n";
1.484 raeburn 1010: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1011: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 1012: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1013: my %orderhash;
1014: my $container='sequence';
1015: my $pathitem;
1.484.2.19 raeburn 1016: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1017: $container='page';
1018: }
1.484.2.19 raeburn 1019: my $folderpath=$env{'form.folderpath'};
1020: if ($folderpath eq '') {
1.484.2.67 raeburn 1021: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 1022: }
1.484.2.67 raeburn 1023: undef($navmap);
1.484.2.19 raeburn 1024: $pathitem = '<input type="hidden" name="folderpath" value="'.
1025: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1026: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1027: my $jumpto = $readfile;
1028: $jumpto =~ s{^/}{};
1029: my $tid = 1;
1.484.2.7 raeburn 1030: if ($supplementalflag) {
1031: $tid = 2;
1032: }
1.484.2.19 raeburn 1033: my ($breadcrumbtrail) =
1.484.2.18 raeburn 1034: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1035: $r->print($breadcrumbtrail.
1036: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1037: $readfile));
1.329 droeschl 1038: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1039: $env{'course.'.$env{'request.course.id'}.'.domain'},
1040: $env{'course.'.$env{'request.course.id'}.'.num'});
1041:
1042: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1043:
1044: my %saveable_parameters = ('show' => 'scalar',);
1045: &Apache::loncommon::store_course_settings('docs_log',
1046: \%saveable_parameters);
1047: &Apache::loncommon::restore_course_settings('docs_log',
1048: \%saveable_parameters);
1049: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1050: # FIXME: internationalization seems wrong here
1.329 droeschl 1051: my %lt=('hiddenresource' => 'Resources hidden',
1052: 'encrypturl' => 'URL hidden',
1053: 'randompick' => 'Randomly pick',
1054: 'randomorder' => 'Randomly ordered',
1055: 'set' => 'set to',
1056: 'del' => 'deleted');
1.484 raeburn 1057: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1058: $pathitem."\n".
1059: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1060: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1061: $r->print('<div class="LC_left_float">'.
1062: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1063: &makedocslogform($filter,1).
1064: '</fieldset></div><br clear="all" />');
1.329 droeschl 1065: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1066: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1067: &mt('After').'</th>'.
1068: &Apache::loncommon::end_data_table_header_row());
1069: my $shown=0;
1070: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1071: if ($env{'form.displayfilter'} eq 'currentfolder') {
1072: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1073: }
1074: my @changes=keys(%{$docslog{$id}{'logentry'}});
1075: if ($env{'form.displayfilter'} eq 'containing') {
1076: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1077: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1078: foreach my $key (@changes) {
1079: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1080: }
1.344 bisitz 1081: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1082: }
1083: my $count = 0;
1084: my $time =
1085: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1086: my $plainname =
1087: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1088: $docslog{$id}{'exe_udom'});
1089: my $about_me_link =
1090: &Apache::loncommon::aboutmewrapper($plainname,
1091: $docslog{$id}{'exe_uname'},
1092: $docslog{$id}{'exe_udom'});
1093: my $send_msg_link='';
1094: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1095: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1096: $send_msg_link ='<br />'.
1097: &Apache::loncommon::messagewrapper(&mt('Send message'),
1098: $docslog{$id}{'exe_uname'},
1099: $docslog{$id}{'exe_udom'});
1100: }
1101: $r->print(&Apache::loncommon::start_data_table_row());
1102: $r->print('<td>'.$time.'</td>
1103: <td>'.$about_me_link.
1104: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1105: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1106: $send_msg_link.'</td><td>'.
1107: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 1108: my $is_supp = 0;
1.484.2.7 raeburn 1109: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1110: $is_supp = 1;
1111: }
1.329 droeschl 1112: # Before
1113: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1114: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1115: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1116: if ($oldname ne $newname) {
1.484.2.7 raeburn 1117: my $shown = &LONCAPA::map::qtescape($oldname);
1118: if ($is_supp) {
1119: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1120: }
1121: $r->print($shown);
1.329 droeschl 1122: }
1123: }
1124: $r->print('<ul>');
1125: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1126: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 1127: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1128: if ($is_supp) {
1129: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1130: }
1.484.2.19 raeburn 1131: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1132: }
1133: }
1134: $r->print('</ul>');
1135: # After
1136: $r->print('</td><td>');
1137:
1138: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1139: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1140: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1141: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 1142: my $shown = &LONCAPA::map::qtescape($newname);
1143: if ($is_supp) {
1144: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1145: }
1146: $r->print($shown);
1.329 droeschl 1147: }
1.364 bisitz 1148: }
1.329 droeschl 1149: $r->print('<ul>');
1150: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1151: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 1152: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1153: if ($is_supp) {
1154: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1155: }
1156: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1157: }
1158: }
1159: $r->print('</ul>');
1160: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.484.2.93.2. (raeburn 1161:): my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1162:): if ($title eq '') {
1163:): ($title) = ($url =~ m{/([^/]+)$});
1(raebur 1164:3): } elsif ($is_supp) {
1165:3): $title = &Apache::loncommon::parse_supplemental_title($title);
(raeburn 1166:): }
1167:): $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.329 droeschl 1168: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1169: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1170: # FIXME: internationalization seems wrong here
1.329 droeschl 1171: $r->print('<li>'.
1172: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1173: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1174: .'</li>');
1175: }
1176: }
1177: $r->print('</ul>');
1178: }
1179: # End
1180: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1181: $shown++;
1182: if (!($env{'form.show'} eq &mt('all')
1183: || $shown<=$env{'form.show'})) { last; }
1184: }
1.484 raeburn 1185: $r->print(&Apache::loncommon::end_data_table()."\n".
1186: &makesimpleeditform($pathitem)."\n".
1187: '</div></div>');
1188: $r->print(&endContentScreen());
1.329 droeschl 1189: }
1190:
1191: sub update_paste_buffer {
1.484.2.7 raeburn 1192: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1193: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1194: if ($env{'form.multiremove'}) {
1195: $env{'form.multiremove'} =~ s/,$//;
1196: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1197: }
1198: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1199: if ($env{'form.multicut'}) {
1200: $env{'form.multicut'} =~ s/,$//;
1201: foreach my $item (split(/,/,$env{'form.multicut'})) {
1202: unless ($removals{$item}) {
1203: $cuts{$item} = 1;
1204: push(@possibles,$item.':cut');
1205: }
1206: }
1207: }
1208: if ($env{'form.multicopy'}) {
1209: $env{'form.multicopy'} =~ s/,$//;
1210: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1211: unless ($removals{$item} || $cuts{$item}) {
1212: push(@possibles,$item.':copy');
1213: }
1214: }
1215: }
1216: } elsif ($env{'form.markcopy'}) {
1217: @possibles = split(/,/,$env{'form.markcopy'});
1218: }
1.329 droeschl 1219:
1.484.2.30 raeburn 1220: return if (@possibles == 0);
1.329 droeschl 1221: return if (!defined($env{'form.copyfolder'}));
1222:
1223: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1224: $env{'form.copyfolder'});
1225: return if ($fatal);
1226:
1.484.2.30 raeburn 1227: my %curr_groups = &Apache::longroup::coursegroups();
1228:
1229: # Retrieve current paste buffer suffixes.
1230: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1231: my (%pasteurls,@newpaste);
1232:
1233: # Construct identifiers for current contents of user's paste buffer
1234: if (@currpaste) {
1235: foreach my $suffix (@currpaste) {
1.484.2.87 raeburn 1236: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1237: my $url = $env{'docs.markedcopy_url_'.$suffix};
1238: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1239: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1240: ($url ne '')) {
1241: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1242: $pasteurls{$cid.'_'.$mapidx} = 1;
1243: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1244: $pasteurls{$url} = 1;
1245: } else {
1246: $pasteurls{$cid.'_'.$url} = 1;
1247: }
1248: }
1.484.2.30 raeburn 1249: }
1250: }
1251:
1252: # Mark items for copying (skip any items already in user's paste buffer)
1253: my %addtoenv;
1.484.2.82 raeburn 1254:
1255: my @pathitems = split(/\&/,$env{'form.folderpath'});
1256: my @folderconf = split(/\:/,$pathitems[-1]);
1.484.2.87 raeburn 1257: my $ispage = $folderconf[5];
1.484.2.82 raeburn 1258:
1.484.2.30 raeburn 1259: foreach my $item (@possibles) {
1260: my ($orderidx,$cmd) = split(/:/,$item);
1261: next if ($orderidx =~ /\D/);
1262: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1263: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1264: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1265: my %denied = &action_restrictions($coursenum,$coursedom,
1266: &LONCAPA::map::qtescape($url),
1267: $env{'form.folderpath'},\%curr_groups);
1268: next if ($denied{'copy'});
1269: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 1270: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1271: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1272: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1273: next if (exists($pasteurls{$url}));
1274: } else {
1275: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1276: }
1.484.2.30 raeburn 1277: my ($suffix,$errortxt,$locknotfreed) =
1278: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1279: if ($suffix ne '') {
1280: push(@newpaste,$suffix);
1281: } else {
1282: if ($locknotfreed) {
1283: return $locknotfreed;
1284: }
1.484.2.30 raeburn 1285: }
1286: if (&is_supplemental_title($title)) {
1287: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1288: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1289: }
1290:
1291: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1292: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1293: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1294: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1295: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1296: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1297: my $prefix = $1;
1298: my $subdir =$2;
1299: if ($subdir eq '') {
1300: $subdir = $prefix;
1.484.2.7 raeburn 1301: }
1.484.2.30 raeburn 1302: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.484.2.93.2. (raeburn 1303:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1304:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.484.2.30 raeburn 1305: if (ref($hierarchy{$url}) eq 'HASH') {
1306: my ($nested,$nestednames);
1307: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1308: $nested =~ s/\&$//;
1309: $nestednames =~ s/\Q___&&&___\E$//;
1310: if ($nested ne '') {
1311: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1312: }
1313: if ($nestednames ne '') {
1314: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1315: }
1.484.2.7 raeburn 1316: }
1317: }
1.484.2.57 raeburn 1318: if ($locknotfreed) {
1319: $output = $locknotfreed;
1320: last;
1321: }
1.484.2.7 raeburn 1322: }
1.484.2.30 raeburn 1323: if (@newpaste) {
1324: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1325: }
1.484.2.7 raeburn 1326: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1327: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1328: return $output;
1.329 droeschl 1329: }
1330:
1.484.2.7 raeburn 1331: sub recurse_uploaded_maps {
1332: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1333: if (ref($hierarchy->{$url}) eq 'HASH') {
1334: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1335: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1336: my (@uploaded,@names,%shorter);
1337: for (my $i=0; $i<@maps; $i++) {
1338: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1339: if ($inner ne '') {
1340: push(@uploaded,$inner);
1341: push(@names,&escape($titles[$i]));
1342: $shorter{$maps[$i]} = $inner;
1343: }
1344: }
1345: $$nestref .= "$dir:".join(',',@uploaded).'&';
1346: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1347: foreach my $map (@maps) {
1348: if ($shorter{$map} ne '') {
1349: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1350: }
1351: }
1352: }
1353: return;
1354: }
1355:
1.329 droeschl 1356: sub print_paste_buffer {
1.484.2.7 raeburn 1357: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1358: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1359:
1.484.2.30 raeburn 1360: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1361: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1362: }
1363:
1.484.2.30 raeburn 1364: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1365: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1366: my $clipboardcount = 0;
1.484.2.7 raeburn 1367:
1.484.2.30 raeburn 1368: # Construct identifiers for current contents of user's paste buffer
1369: foreach my $suffix (@currpaste) {
1370: next if ($suffix =~ /\D/);
1371: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1372: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1373: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1374: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1375: ($url ne '')) {
1.484.2.47 raeburn 1376: $clipboardcount ++;
1.484.2.30 raeburn 1377: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.484.2.93.2. (raeburn 1378:): $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.484.2.30 raeburn 1379: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1380: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1381: $is_external = 1;
1.484.2.93.2. (raeburn 1382:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1383:): $is_exttool = 1;
1.484.2.7 raeburn 1384: }
1.484.2.30 raeburn 1385: if ($folder =~ /^supplemental/) {
1386: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1387: unless ($canpaste) {
1388: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1389: }
1.484.2.30 raeburn 1390: } else {
1391: $canpaste = 1;
1.484.2.7 raeburn 1392: }
1.484.2.30 raeburn 1393: if ($canpaste) {
1394: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1395: my $srcdom = $1;
1396: my $srcnum = $2;
1397: my $rem = $3;
1398: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1399: $othercourse = 1;
1400: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1401: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1402: } else {
1403: $canpaste = 0;
1404: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1405: }
1406: }
1.484.2.30 raeburn 1407: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1408: my $prefix = $1;
1409: $parent = $2;
1410: if ($folder !~ /^\Q$prefix\E/) {
1411: $areachange = 1;
1412: }
1413: $is_uploaded_map = 1;
1414: }
1.484.2.82 raeburn 1415: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.484.2.93.2. (raeburn 1416:): ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.484.2.76 raeburn 1417: if ($cid ne $env{'request.course.id'}) {
1418: my ($srcdom,$srcnum) = split(/_/,$cid);
1419: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.93.2. (raeburn 1420:): if (($is_exttool) && ($srcdom ne $coursedom)) {
1421:): $canpaste = 0;
1422:): $nopaste = &mt('Paste from another domain unavailable.');
1423:): } else {
1424:): $othercrs = '<br />'.&mt('(from another course)');
1425:): }
1.484.2.76 raeburn 1426: } else {
1427: $canpaste = 0;
1428: $nopaste = &mt('Paste from another course unavailable.');
1429: }
1430: }
1431: }
1432: if ($canpaste) {
1433: push(@pasteable,$suffix);
1.484.2.30 raeburn 1434: }
1435: }
1436: my $buffer;
1437: if ($is_external) {
1438: $buffer = &mt('External Resource').': '.
1439: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1440: &LONCAPA::map::qtescape($url).')';
1.484.2.93.2. (raeburn 1441:): } elsif ($is_exttool) {
1442:): $buffer = &mt('External Tool').': '.
1443:): &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.30 raeburn 1444: } else {
1445: my $icon = &Apache::loncommon::icon($extension);
1446: if ($extension eq 'sequence' &&
1447: $url =~ m{/default_\d+\.sequence$}x) {
1448: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1449: $icon .= '/navmap.folder.closed.gif';
1450: }
1.484.2.57 raeburn 1451: my $title = $env{'docs.markedcopy_title_'.$suffix};
1452: if ($title eq '') {
1453: ($title) = ($url =~ m{/([^/]+)$});
1454: }
1.484.2.30 raeburn 1455: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1456: ': '.
1457: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1458: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1459: }
1460: $pasteitems .= '<div class="LC_left_float">';
1461: my ($options,$onclick);
1462: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1463: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1464: if (($is_uploaded_map) ||
1465: ($url =~ /(bulletinboard|smppg)$/) ||
1466: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1467: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1468: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1469: }
1470: }
1471: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1472: if ($nopaste) {
1.484.2.93.2. (raeburn 1473:): $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.484.2.30 raeburn 1474: } else {
1475: if ($othercrs) {
1476: $pasteitems .= $othercrs;
1477: }
1478: if ($options) {
1479: $pasteitems .= $options;
1.484.2.7 raeburn 1480: }
1481: }
1.484.2.30 raeburn 1482: $pasteitems .= '</div>';
1483: }
1484: }
1485: if ($pasteitems eq '') {
1486: &Apache::lonnet::delenv('docs.markedcopies');
1487: }
1488: my ($pasteform,$form_start,$buttons,$form_end);
1489: if ($pasteitems) {
1490: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1491: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1492: if (@pasteable) {
1.484.2.47 raeburn 1493: my $value = &mt('Paste to current folder');
1494: if ($container eq 'page') {
1495: $value = &mt('Paste to current page');
1496: }
1497: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1498: }
1.484.2.93.2. (raeburn 1499:): $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1.484.2.47 raeburn 1500: if ($clipboardcount > 1) {
1501: $buttons .=
1502: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1503: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1504: (' 'x2).
1505: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1506: (' 'x2);
1.484.2.7 raeburn 1507: }
1.484.2.48 raeburn 1508: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1509: '</form>';
1.484.2.30 raeburn 1510: } else {
1511: $pasteitems = &mt('Clipboard is empty');
1512: }
1513: $r->print($form_start
1514: .'<fieldset>'
1515: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1516: .$pasteitems
1517: .'</fieldset>'
1518: .$form_end);
1519: }
1520:
1521: sub paste_options {
1522: my ($suffix,$is_uploaded_map,$parent) = @_;
1523: my ($copytext,$movetext);
1524: if ($is_uploaded_map) {
1525: $copytext = &mt('Copy to new folder');
1526: $movetext = &mt('Move old');
1527: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1528: $copytext = &mt('Copy to new board');
1529: $movetext = &mt('Move (not posts)');
1530: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1531: $copytext = &mt('Copy to new page');
1532: $movetext = &mt('Move');
1.484.2.7 raeburn 1533: } else {
1.484.2.30 raeburn 1534: $copytext = &mt('Copy to new file');
1535: $movetext = &mt('Move');
1536: }
1537: my $output = '<br />'.
1538: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1539: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1540: '<label>'.
1541: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1542: $copytext.'</label></span>'.(' 'x2).' '.
1543: '<span class="LC_nobreak"><label>'.
1544: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1545: $movetext.'</label></span>';
1546: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1547: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1548: '</legend><table border="0">';
1549: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1550: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1551: my $lastdir = $parent;
1552: my %depths = (
1553: $lastdir => 0,
1554: );
1555: my (%display,%deps);
1556: for (my $i=0; $i<@pastemaps; $i++) {
1557: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1558: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1559: my @subfolders = split(/,/,$subfolderstr);
1560: $deps{$lastdir} = \@subfolders;
1561: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1562: my $depth = $depths{$lastdir} + 1;
1563: my $offset = int($depth * 4);
1564: my $indent = (' ' x $offset);
1565: for (my $j=0; $j<@subfolders; $j++) {
1566: $depths{$subfolders[$j]} = $depth;
1567: $display{$subfolders[$j]} =
1568: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1569: '<td><label>'.
1570: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1571: '<label>'.
1572: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1573: &mt('Move old').'</label>'.
1574: '</td></tr>';
1575: }
1576: }
1577: &recurse_print(\$output,$parent,\%deps,\%display);
1578: $output .= '</table></fieldset>';
1.329 droeschl 1579: }
1.484.2.30 raeburn 1580: $output .= '</div>';
1581: return $output;
1.329 droeschl 1582: }
1583:
1.484.2.7 raeburn 1584: sub recurse_print {
1.484.2.30 raeburn 1585: my ($outputref,$dir,$deps,$display) = @_;
1586: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1587: if (ref($deps->{$dir}) eq 'ARRAY') {
1588: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1589: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1590: }
1591: }
1592: }
1593:
1594: sub supp_pasteable {
1595: my ($url) = @_;
1596: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1597: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1598: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1599: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.484.2.93.2. (raeburn 1600:): ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1601:): ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.484.2.7 raeburn 1602: return 1;
1603: }
1604: return;
1605: }
1606:
1607: sub paste_popup_js {
1.484.2.61 raeburn 1608: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1609: show => 'Show Options',
1610: hide => 'Hide Options',
1.484.2.61 raeburn 1611: );
1612: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1613: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1614: );
1.484.2.61 raeburn 1615: &html_escape(\%html_js_lt);
1616: &js_escape(\%html_js_lt);
1617: &js_escape(\%js_lt);
1.484.2.7 raeburn 1618: return <<"END";
1619:
1.484.2.30 raeburn 1620: function showPasteOptions(suffix) {
1621: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1622: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1623: return;
1624: }
1625:
1.484.2.30 raeburn 1626: function hidePasteOptions(suffix) {
1627: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1628: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1629: return;
1630: }
1631:
1.484.2.30 raeburn 1632: function showOptions(caller,suffix) {
1633: if (document.getElementById('pasteoptionstext_'+suffix)) {
1634: if (caller.checked) {
1.484.2.61 raeburn 1635: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1636: } else {
1637: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1638: }
1639: if (document.getElementById('pasteoptions_'+suffix)) {
1640: document.getElementById('pasteoptions_'+suffix).style.display='none';
1641: }
1642: }
1643: return;
1644: }
1.484.2.7 raeburn 1645:
1.484.2.30 raeburn 1646: function validateClipboard() {
1647: var numchk = 0;
1648: if (document.pasteform.pasting.length > 1) {
1649: for (var i=0; i<document.pasteform.pasting.length; i++) {
1650: if (document.pasteform.pasting[i].checked) {
1651: numchk ++;
1652: }
1653: }
1654: } else {
1655: if (document.pasteform.pasting.type == 'checkbox') {
1656: if (document.pasteform.pasting.checked) {
1657: numchk ++;
1658: }
1659: }
1660: }
1661: if (numchk > 0) {
1662: return true;
1663: } else {
1.484.2.61 raeburn 1664: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1665: return false;
1666: }
1.484.2.7 raeburn 1667: }
1668:
1.484.2.47 raeburn 1669: function checkClipboard() {
1670: if (document.pasteform.pasting.length > 1) {
1671: for (var i=0; i<document.pasteform.pasting.length; i++) {
1672: document.pasteform.pasting[i].checked = true;
1673: }
1674: }
1675: return;
1676: }
1677:
1678: function uncheckClipboard() {
1679: if (document.pasteform.pasting.length >1) {
1680: for (var i=0; i<document.pasteform.pasting.length; i++) {
1681: document.pasteform.pasting[i].checked = false;
1682: }
1683: }
1684: return;
1685: }
1686:
1.484.2.30 raeburn 1687: END
1688:
1689: }
1.484.2.7 raeburn 1690:
1.329 droeschl 1691: sub do_paste_from_buffer {
1.484.2.7 raeburn 1692: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1693:
1.484.2.30 raeburn 1694: # Array of items in paste buffer
1695: my (@currpaste,%pastebuffer,%allerrors);
1696: @currpaste = split(/,/,$env{'docs.markedcopies'});
1697:
1.484.2.7 raeburn 1698: # Early out if paste buffer is empty
1.484.2.30 raeburn 1699: if (@currpaste == 0) {
1.484.2.7 raeburn 1700: return ();
1.484.2.30 raeburn 1701: }
1702: map { $pastebuffer{$_} = 1; } @currpaste;
1703:
1704: # Array of items selected items to paste
1705: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1706:
1707: # Early out if nothing selected to paste
1708: if (@reqpaste == 0) {
1709: return();
1710: }
1711: my @topaste;
1712: foreach my $suffix (@reqpaste) {
1713: next if ($suffix =~ /\D/);
1714: next unless (exists($pastebuffer{$suffix}));
1715: push(@topaste,$suffix);
1.484.2.7 raeburn 1716: }
1717:
1.484.2.30 raeburn 1718: # Early out if nothing available to paste
1719: if (@topaste == 0) {
1720: return();
1.329 droeschl 1721: }
1722:
1.484.2.93.2. (raeburn 1723:): my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.484.2.82 raeburn 1724: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1725:
1.484.2.30 raeburn 1726: foreach my $suffix (@topaste) {
1727: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1728: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1729: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1730: # Supplemental content may only include certain types of content
1731: # Early out if pasted content is not supported in Supplemental area
1732: if ($folder =~ /^supplemental/) {
1733: unless (&supp_pasteable($url)) {
1734: $notinsupp{$suffix} = 1;
1735: next;
1736: }
1737: }
1738: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1739: my $srcd = $1;
1740: my $srcn = $2;
1.484.2.7 raeburn 1741: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1742: # check for mdc privilege in the course from which the resource was pasted
1743: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1744: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1745: $notincrs{$suffix} = 1;
1746: next;
1747: }
1.329 droeschl 1748: }
1.484.2.30 raeburn 1749: $srcdom{$suffix} = $srcd;
1750: $srcnum{$suffix} = $srcn;
1.484.2.93.2. (raeburn 1751:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1752:): my ($srcd,$srcn) = split(/_/,$cid);
1753:): # When paste buffer was populated using an active role in a different course
1754:): # check for mdc privilege in the course from which the resource was pasted
1755:): if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1756:): unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1757:): $notincrs{$suffix} = 1;
1758:): next;
1759:): }
1760:): }
1761:): # When buffer was populated using an active role in a different course
1762:): # disallow pasting of External Tool if course is in a different domain.
1763:): if ($srcd ne $coursedom) {
1764:): $notindom{$suffix} = 1;
1765:): next;
1766:): }
1767:): $srcdom{$suffix} = $srcd;
1768:): $srcnum{$suffix} = $srcn;
1.484.2.82 raeburn 1769: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1770: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1771: my ($srcd,$srcn) = split(/_/,$cid);
1772: # When paste buffer was populated using an active role in a different course
1773: # check for mdc privilege in the course from which the resource was pasted
1774: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1775: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1776: $notincrs{$suffix} = 1;
1777: next;
1778: }
1779: }
1780: $srcdom{$suffix} = $srcd;
1781: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1782: }
1.484.2.82 raeburn 1783: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1784: push(@dopaste,$suffix);
1785: if ($url=~/\.(page|sequence)$/) {
1786: $is_map{$suffix} = 1;
1.329 droeschl 1787: }
1.484.2.30 raeburn 1788:
1789: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1790: my $oldprefix = $1;
1.484.2.19 raeburn 1791: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1792: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1793: # a folder/page or a document).
1.484.2.30 raeburn 1794: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1795: $prefixchg{$suffix} = 'docstosupp';
1796: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1797: $prefixchg{$suffix} = 'supptodocs';
1798: }
1.484.2.7 raeburn 1799:
1800: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1801: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1802: my @nested;
1803: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1804: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1805: my @deps = map { /\d+:([\d,]+$)/ } @items;
1806: foreach my $dep (@deps) {
1807: if ($dep =~ /,/) {
1808: push(@nested,split(/,/,$dep));
1809: } else {
1810: push(@nested,$dep);
1811: }
1.484.2.7 raeburn 1812: }
1.484.2.30 raeburn 1813: foreach my $item (@nested) {
1814: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1815: push(@{$marktomove{$suffix}},$type.'_'.$item);
1816: }
1.484.2.7 raeburn 1817: }
1818: }
1.329 droeschl 1819: }
1.484.2.7 raeburn 1820: }
1821:
1.484.2.30 raeburn 1822: # Early out if nothing available to paste
1823: if (@dopaste == 0) {
1824: return ();
1825: }
1826:
1827: # Populate message hash and hashes used for main content <=> supplemental content
1828: # changes
1829:
1830: %msgs = &Apache::lonlocal::texthash (
1831: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1832: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.484.2.93.2. (raeburn 1833:): notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.484.2.30 raeburn 1834: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1835: );
1836:
1837: %before = (
1838: docstosupp => {
1839: map => 'default',
1840: doc => 'docs',
1841: },
1842: supptodocs => {
1843: map => 'supplemental',
1844: doc => 'supplemental',
1845: },
1846: );
1847:
1848: %after = (
1849: docstosupp => {
1850: map => 'supplemental',
1851: doc => 'supplemental'
1852: },
1853: supptodocs => {
1854: map => 'default',
1855: doc => 'docs',
1856: },
1857: );
1858:
1859: # Retrieve information about all course maps in main content area
1860:
1861: my $allmaps = {};
1.484.2.79 raeburn 1862: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1863:
1864: # Loop over the items to paste
1865: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1866: # Maps need to be copied first
1.484.2.30 raeburn 1867: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1868: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1869: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1870: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1871: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1872: }
1873: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1874: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1875: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1876: my $oldurl = $url;
1877: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1878: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1879: my (%hierarchy,%titles);
1.484.2.79 raeburn 1880: if (($folder =~ /^default/) && (!$donechk)) {
1881: $allmaps =
1882: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1883: $env{"course.$env{'request.course.id'}.home"},
1884: $env{'request.course.id'});
1885: $donechk = 1;
1886: }
1.484.2.93.2. (raeburn 1887:): &contained_map_check($url,$folder,$coursenum,$coursedom,
1888:): \%removefrommap,\%removeparam,\%addedmaps,
1889:): \%hierarchy,\%titles,$allmaps);
1.484.2.30 raeburn 1890: if ($url=~ m{^/uploaded/}) {
1891: my $newurl;
1892: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1893: ($newurl,my $error) =
1894: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1895: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1896: \$title,$allmaps,\%newurls);
1897: if ($error) {
1898: $allerrors{$suffix} = $error;
1899: next;
1900: }
1901: if ($newurl ne '') {
1902: if ($newurl ne $url) {
1903: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1904: $newsubdir{$url} = $1;
1905: }
1906: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1907: }
1908: }
1909: }
1.484.2.30 raeburn 1910: if (($srcdom{$suffix} ne $coursedom) ||
1911: ($srcnum{$suffix} ne $coursenum) ||
1912: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1913: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1914: $coursedom,$coursenum,$srcdom{$suffix},
1915: $srcnum{$suffix},$allmaps,\%rewrites,
1916: \%retitles,\%copies,\%dbcopies,
1917: \%zombies,\%params,\%mapmoves,
1918: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 1919: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 1920: $mapmoves{$url} = 1;
1921: }
1922: $url = $newurl;
1923: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1924: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1925: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1926: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1927: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 1928: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 1929: }
1930: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 1931: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1932: push(@toclear,$suffix);
1933: # if pasting published map (main content area only) check map not already in course
1934: if ($folder =~ /^default/) {
1935: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1936: $duplicate{$suffix} = 1;
1937: next;
1938: }
1.484.2.7 raeburn 1939: }
1940: }
1941: }
1.484.2.93.2. (raeburn 1942:): if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.484.2.30 raeburn 1943: my $prefix = $1;
1.484.2.76 raeburn 1944: my $fromothercrs;
1.484.2.30 raeburn 1945: #need to copy the db contents to a new one, unless this is a move.
1946: my %info = (
1947: src => $url,
1948: cdom => $coursedom,
1949: cnum => $coursenum,
1.484.2.76 raeburn 1950: );
1951: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1952: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1953: $fromothercrs = 1;
1954: $info{'cdom'} = $srcdom{$suffix};
1955: $info{'cnum'} = $srcnum{$suffix};
1956: }
1957: }
1958: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1959: my (%lockerr,$msg);
1960: my ($newurl,$result,$errtext) =
1961: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1962: if ($result eq 'ok') {
1963: $url = $newurl;
1964: $title=&mt('Copy of').' '.$title;
1965: } else {
1966: if ($prefix eq 'smppg') {
1967: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1968: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1969: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.93.2. (raeburn 1970:): } elsif ($prefix eq 'ext.tool') {
1971:): $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.484.2.30 raeburn 1972: }
1973: $results{$suffix} = $result;
1974: $msgerrs{$suffix} = $msg;
1975: $lockerrs{$suffix} = $lockerr{$prefix};
1976: next;
1977: }
1978: if ($lockerr{$prefix}) {
1979: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1980: }
1.484.2.7 raeburn 1981: }
1.484.2.30 raeburn 1982: }
1983: $title = &LONCAPA::map::qtunescape($title);
1984: my $ext='false';
1985: if ($url=~m{^http(|s)://}) { $ext='true'; }
1986: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1987: if ($folder !~ /^supplemental/) {
1988: (undef,undef,$title) =
1989: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1990: }
1991: } else {
1992: if ($folder=~/^supplemental/) {
1993: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1994: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1995: }
1996: }
1.484.2.7 raeburn 1997:
1998: # For uploaded files (excluding pages/sequences) path in copied file is changed
1999: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2000: # courses.
2001:
1.484.2.30 raeburn 2002: unless ($is_map{$suffix}) {
2003: my $newidx;
1.329 droeschl 2004: # Now insert the URL at the bottom
1.484.2.30 raeburn 2005: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2006: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2007: my $relpath = $1;
2008: if ($relpath ne '') {
2009: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2010: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2011: my $newprefix = $newloc;
2012: if ($newloc eq 'default') {
2013: $newprefix = 'docs';
2014: }
2015: if ($newdocsdir eq '') {
2016: $newdocsdir = 'default';
2017: }
2018: if (($prefixchg{$suffix}) ||
2019: ($srcdom{$suffix} ne $coursedom) ||
2020: ($srcnum{$suffix} ne $coursenum) ||
2021: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2022: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2023: $url =
2024: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2025: &Apache::lonnet::getfile($oldurl));
2026: if ($url eq '/adm/notfound.html') {
2027: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2028: next;
2029: } else {
2030: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2031: $newsubpath =~ s{/+$}{/};
2032: $docmoves{$oldurl} = $newsubpath;
2033: }
1.484.2.7 raeburn 2034: }
2035: }
1.484.2.82 raeburn 2036: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2037: my $template = $1;
2038: if ($newidx) {
2039: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2040: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2041: }
1.484.2.7 raeburn 2042: }
1.484.2.30 raeburn 2043: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2044: ':'.$ext.':normal:res';
2045: push(@LONCAPA::map::order,$newidx);
2046: # Store the result
2047: my ($errtext,$fatal) =
2048: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2049: if ($fatal) {
2050: $save_err .= $errtext;
2051: $allresult = 'fail';
1.484.2.7 raeburn 2052: }
1.329 droeschl 2053: }
1.484.2.30 raeburn 2054:
1.484.2.82 raeburn 2055: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2056: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 2057: unless ($allresult eq 'fail') {
2058: my %updated = (
2059: rewrites => \%rewrites,
2060: zombies => \%zombies,
2061: removefrommap => \%removefrommap,
2062: removeparam => \%removeparam,
2063: dbcopies => \%dbcopies,
1.484.2.82 raeburn 2064: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 2065: retitles => \%retitles,
2066: );
2067: my %info = (
2068: newsubdir => \%newsubdir,
2069: params => \%params,
2070: );
2071: if ($prefixchg{$suffix}) {
2072: $info{'before'} = $before{$prefixchg{$suffix}};
2073: $info{'after'} = $after{$prefixchg{$suffix}};
2074: }
2075: my %moves = (
2076: copies => \%copies,
2077: docmoves => \%docmoves,
2078: mapmoves => \%mapmoves,
2079: );
2080: (my $result,$msgs{$suffix},my $lockerror) =
2081: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2082: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2083: $url,'paste');
2084: $lockerrors .= $lockerror;
2085: if ($result eq 'ok') {
2086: if ($is_map{$suffix}) {
2087: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2088: $folder.'.'.$container);
2089: if ($fatal) {
2090: $allresult = 'failread';
2091: } else {
2092: if ($#LONCAPA::map::order<1) {
2093: my $idx=&LONCAPA::map::getresidx();
2094: if ($idx<=0) { $idx=1; }
2095: $LONCAPA::map::order[0]=$idx;
2096: $LONCAPA::map::resources[$idx]='';
2097: }
2098: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2099: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2100: ':'.$ext.':normal:res';
2101: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 2102:
2103: # Store the result
1.484.2.30 raeburn 2104: my ($errtext,$fatal) =
2105: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2106: if ($fatal) {
2107: $save_err .= $errtext;
2108: $allresult = 'failstore';
2109: }
2110: }
2111: }
2112: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2113: push(@toclear,$suffix);
2114: }
2115: }
1.329 droeschl 2116: }
2117: }
1.484.2.30 raeburn 2118: &clear_from_buffer(\@toclear,\@currpaste);
2119: my $msgsarray;
2120: foreach my $suffix (keys(%msgs)) {
2121: if (ref($msgs{$suffix}) eq 'ARRAY') {
2122: $msgsarray .= join(',',@{$msgs{$suffix}});
2123: }
2124: }
2125: return ($allresult,$save_err,$msgsarray,$lockerrors);
2126: }
2127:
2128: sub do_buffer_empty {
2129: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2130: if (@currpaste == 0) {
2131: return &mt('Clipboard is already empty');
2132: }
2133: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2134: if (@toclear == 0) {
2135: return &mt('Nothing selected to clear from clipboard');
2136: }
2137: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2138: if ($numdel) {
2139: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2140: } else {
2141: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 2142: }
1.484.2.30 raeburn 2143: return;
2144: }
2145:
2146: sub clear_from_buffer {
2147: my ($toclear,$currpaste) = @_;
2148: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2149: my %pastebuffer;
2150: map { $pastebuffer{$_} = 1; } @{$currpaste};
2151: my $numdel = 0;
2152: foreach my $suffix (@{$toclear}) {
2153: next if ($suffix =~ /\D/);
2154: next unless (exists($pastebuffer{$suffix}));
2155: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2156: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2157: delete($pastebuffer{$suffix});
2158: $numdel ++;
2159: }
2160: }
2161: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2162: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2163: return $numdel;
1.484.2.7 raeburn 2164: }
2165:
2166: sub get_newmap_url {
2167: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2168: $titleref,$allmaps,$newurls) = @_;
2169: my $newurl;
2170: if ($url=~ m{^/uploaded/}) {
2171: $$titleref=&mt('Copy of').' '.$$titleref;
2172: }
2173: my $now = time;
2174: my $suffix=$$.int(rand(100)).$now;
2175: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2176: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2177: my $path = $1;
2178: my $prefix = $2;
2179: my $ancestor = $3;
2180: if (length($ancestor) > 10) {
2181: $ancestor = substr($ancestor,-10,10);
2182: }
2183: my $newid;
2184: if ($prefixchg) {
2185: if ($folder =~ /^supplemental/) {
2186: $prefix =~ s/^default/supplemental/;
2187: } else {
2188: $prefix =~ s/^supplemental/default/;
2189: }
2190: }
2191: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2192: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2193: } else {
2194: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2195: }
2196: my $counter = 0;
2197: my $is_unique = &uniqueness_check($newurl);
2198: if ($folder =~ /^default/) {
2199: if ($allmaps->{$newurl}) {
2200: $is_unique = 0;
2201: }
2202: }
2203: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2204: $counter ++;
2205: $suffix ++;
2206: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2207: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2208: } else {
2209: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2210: }
2211: $is_unique = &uniqueness_check($newurl);
2212: }
2213: if ($is_unique) {
2214: $newurls->{$newurl} = 1;
2215: } else {
2216: if ($url=~/\.page$/) {
2217: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2218: } else {
2219: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2220: }
2221: }
2222: }
2223: return ($newurl);
2224: }
2225:
2226: sub dbcopy {
1.484.2.26 raeburn 2227: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2228: my ($url,$result,$errtext);
2229: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2230: $url = $dbref->{'src'};
1.484.2.93.2. (raeburn 2231:): if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.484.2.26 raeburn 2232: my $prefix = $1;
1.484.2.93.2. (raeburn 2233:): if ($prefix eq 'ext.tool') {
2234:): $prefix = 'exttool';
2235:): }
1.484.2.26 raeburn 2236: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2237: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2238: my $db_name;
2239: my $marker = (split(m{/},$url))[4];
2240: $marker=~s/\D//g;
2241: if ($dbref->{'src'} =~ m{/smppg$}) {
2242: $db_name =
2243: &Apache::lonsimplepage::get_db_name($url,$marker,
2244: $dbref->{'cdom'},
2245: $dbref->{'cnum'});
1.484.2.93.2. (raeburn 2246:): } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2247:): $db_name = 'exttool_'.$marker;
1.484.2.26 raeburn 2248: } else {
2249: $db_name = 'bulletinpage_'.$marker;
2250: }
2251: my ($suffix,$freedlock,$error) =
2252: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2253: $coursedom,$coursenum,
2254: 'concat');
2255: if (!$suffix) {
2256: if ($prefix eq 'smppg') {
2257: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.484.2.93.2. (raeburn 2258:): } elsif ($prefix eq 'exttool') {
2259:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.484.2.26 raeburn 2260: } else {
1.484.2.42 raeburn 2261: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2262: }
2263: if ($error) {
2264: $errtext .= '<br />'.$error;
2265: }
2266: } else {
2267: #need to copy the db contents to a new one.
2268: my %contents=&Apache::lonnet::dump($db_name,
2269: $dbref->{'cdom'},
2270: $dbref->{'cnum'});
2271: if (exists($contents{'uploaded.photourl'})) {
2272: my $photo = $contents{'uploaded.photourl'};
2273: my ($subdir,$fname) =
2274: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2275: my $newphoto;
2276: if ($fname ne '') {
2277: my $content = &Apache::lonnet::getfile($photo);
2278: unless ($content eq '-1') {
2279: $env{'form.'.$suffix.'.photourl'} = $content;
2280: $newphoto =
2281: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2282: delete($env{'form.'.$suffix.'.photourl'});
2283: }
2284: }
2285: if ($newphoto =~ m{^/uploaded/}) {
2286: $contents{'uploaded.photourl'} = $newphoto;
2287: }
2288: }
2289: $db_name =~ s{_\d*$ }{_$suffix}x;
2290: $result=&Apache::lonnet::put($db_name,\%contents,
2291: $coursedom,$coursenum);
2292: if ($result eq 'ok') {
1.484.2.93.2. (raeburn 2293:): $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.484.2.26 raeburn 2294: }
2295: }
2296: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2297: $lockerrorsref->{$prefix} =
2298: '<div class="LC_error">'.
2299: &mt('There was a problem removing a lockfile.');
2300: if ($prefix eq 'smppg') {
2301: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2302: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.93.2. (raeburn 2303:): } elsif ($prefix eq 'exttool') {
2304:): $lockerrorsref->{$prefix} .=
2305:): ' '.&mt('This will prevent addition of more external tools to this course.');
1.484.2.26 raeburn 2306: } else {
1.484.2.42 raeburn 2307: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2308: }
1.484.2.38 raeburn 2309: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2310: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2311: '</div>';
1.484.2.26 raeburn 2312: }
2313: }
2314: } elsif ($url =~ m{/syllabus$}) {
2315: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2316: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2317: if (($dbref->{'cdom'} ne $coursedom) ||
2318: ($dbref->{'cnum'} ne $coursenum)) {
2319: my %contents=&Apache::lonnet::dump('syllabus',
2320: $dbref->{'cdom'},
2321: $dbref->{'cnum'});
2322: $result=&Apache::lonnet::put('syllabus',\%contents,
2323: $coursedom,$coursenum);
2324: }
2325: }
1.484.2.7 raeburn 2326: }
2327: }
1.484.2.26 raeburn 2328: return ($url,$result,$errtext);
1.329 droeschl 2329: }
2330:
1.484.2.82 raeburn 2331: sub copy_templated_files {
2332: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2333: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2334: my $srccontainer = 'sequence';
2335: if ($srcwaspage) {
2336: $srccontainer = 'page';
2337: }
2338: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2339: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2340: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2341: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2342: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2343: $template.'.problem';
2344: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2345: if ($template eq 'simpleproblem') {
2346: $srcprefix .= '.0.';
2347: my $weightprefix = $newprefix;
2348: $newprefix .= '.0.';
2349: my @simpleprobqtypes = qw(radio option string essay numerical);
2350: my $qtype=$srcparms{$srcprefix.'questiontype'};
2351: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2352: my %newdata = (
2353: $newprefix.'questiontype' => $qtype,
1.484.2.84 raeburn 2354: );
1.484.2.82 raeburn 2355: foreach my $type (@simpleprobqtypes) {
2356: if ($type eq $qtype) {
2357: $newdata{"$weightprefix.$type.weight"}=1;
2358: } else {
2359: $newdata{"$weightprefix.$type.weight"}=0;
2360: }
2361: }
2362: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2363: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2364: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2365: if ($qtype eq 'numerical') {
2366: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2367: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2368: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2369: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2370: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2371: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2372: unless (defined($maxfoils)) { $maxfoils=10; }
2373: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2374: if ($maxfoils<=0) { $maxfoils=10; }
2375: my $randomize=$srcparms{$srcprefix.'randomize'};
2376: unless (defined($randomize)) { $randomize='yes'; }
2377: unless ($randomize eq 'no') { $randomize='yes'; }
2378: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2379: $newdata{$newprefix.'randomize'} = $randomize;
2380: if ($qtype eq 'option') {
2381: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2382: }
2383: for (my $i=1; $i<=10; $i++) {
2384: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2385: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2386: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2387: }
2388:
2389: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2390: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2391: unless (defined($maxfoils)) { $maxfoils=10; }
2392: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2393: if ($maxfoils<=0) { $maxfoils=10; }
2394: my $randomize=$srcparms{$srcprefix.'randomize'};
2395: unless (defined($randomize)) { $randomize='yes'; }
2396: unless ($randomize eq 'no') { $randomize='yes'; }
2397: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2398: $newdata{$newprefix.'randomize'} = $randomize;
2399: if ($qtype eq 'option') {
2400: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2401: }
2402: for (my $i=1; $i<=10; $i++) {
2403: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2404: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2405: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2406: }
2407: } elsif ($qtype eq 'string') {
2408: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2409: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2410: }
2411: if (keys(%newdata)) {
2412: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2413: $coursenum);
2414: if ($putres eq 'ok') {
2415: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2416: }
2417: }
2418: }
2419: }
2420: }
2421:
1.329 droeschl 2422: sub uniqueness_check {
2423: my ($newurl) = @_;
2424: my $unique = 1;
2425: foreach my $res (@LONCAPA::map::order) {
2426: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2427: $url=&LONCAPA::map::qtescape($url);
2428: if ($newurl eq $url) {
2429: $unique = 0;
1.344 bisitz 2430: last;
1.329 droeschl 2431: }
2432: }
2433: return $unique;
2434: }
2435:
1.484.2.7 raeburn 2436: sub contained_map_check {
1.484.2.93.2. (raeburn 2437:): my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2438:): $hierarchy,$titles,$allmaps) = @_;
1.484.2.7 raeburn 2439: my $content = &Apache::lonnet::getfile($url);
2440: unless ($content eq '-1') {
2441: my $parser = HTML::TokeParser->new(\$content);
2442: $parser->attr_encoded(1);
2443: while (my $token = $parser->get_token) {
2444: next if ($token->[0] ne 'S');
2445: if ($token->[1] eq 'resource') {
2446: next if ($token->[2]->{'type'} eq 'zombie');
2447: my $ressrc = $token->[2]->{'src'};
2448: if ($folder =~ /^supplemental/) {
2449: unless (&supp_pasteable($ressrc)) {
2450: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2451: next;
2452: }
2453: }
2454: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2455: if ($1 eq 'uploaded') {
2456: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2457: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2458: } else {
2459: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2460: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2461: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2462: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2463: } else {
2464: $addedmaps->{$ressrc} = [$url];
2465: }
2466: }
1.484.2.93.2. (raeburn 2467:): &contained_map_check($ressrc,$folder,$coursenum,$coursedom,
2468:): $removefrommap,$removeparam,
1.484.2.7 raeburn 2469: $addedmaps,$hierarchy,$titles,$allmaps);
2470: }
2471: } elsif ($token->[1] eq 'param') {
2472: if ($folder =~ /^supplemental/) {
2473: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2474: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2475: } else {
1.484.2.19 raeburn 2476: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2477: }
2478: }
2479: }
2480: }
2481: }
2482: return;
2483: }
2484:
2485: sub url_paste_fixups {
1.484.2.26 raeburn 2486: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2487: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2488: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2489: my $checktitle;
2490: if (($prefixchg) &&
2491: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2492: $checktitle = 1;
2493: }
2494: my $skip;
2495: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2496: my $mapid = $1.$2;
2497: if ($tomove->{$mapid}) {
2498: $skip = 1;
2499: }
2500: }
2501: my $file = &Apache::lonnet::getfile($oldurl);
2502: return if ($file eq '-1');
2503: my $parser = HTML::TokeParser->new(\$file);
2504: $parser->attr_encoded(1);
2505: my $changed = 0;
2506: while (my $token = $parser->get_token) {
2507: next if ($token->[0] ne 'S');
2508: if ($token->[1] eq 'resource') {
2509: my $ressrc = $token->[2]->{'src'};
2510: next if ($ressrc eq '');
2511: my $id = $token->[2]->{'id'};
2512: my $title = $token->[2]->{'title'};
2513: if ($checktitle) {
2514: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2515: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2516: }
2517: }
2518: next if ($token->[2]->{'type'} eq 'external');
2519: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2520: next if ($skip);
1.484.2.25 raeburn 2521: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2522: $changed = 1;
2523: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2524: my $srcdom = $1;
2525: my $srcnum = $2;
2526: my $rem = $3;
2527: my $newurl;
2528: my $mapname;
2529: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2530: my $prefix = $1;
2531: $mapname = $prefix.$2;
2532: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2533: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2534: $srcdom,$srcnum,$allmaps,$rewrites,
2535: $retitles,$copies,$dbcopies,$zombies,
2536: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2537: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2538: next;
2539: } else {
2540: ($newurl,my $error) =
2541: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2542: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2543: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2544: $newsubdir->{$ressrc} = $1;
2545: }
2546: if ($error) {
2547: next;
2548: }
2549: }
2550: }
2551: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2552: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2553:
1.484.2.7 raeburn 2554: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2555: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2556: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2557: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2558: $cnum,$srcdom,$srcnum,$allmaps,
2559: $rewrites,$retitles,$copies,$dbcopies,
2560: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2561: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2562: $mapmoves->{$ressrc} = 1;
2563: }
2564: $changed = 1;
2565: } else {
1.484.2.25 raeburn 2566: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2567: $copies->{$oldurl}{$ressrc} = $id;
2568: $changed = 1;
2569: }
2570: }
1.484.2.26 raeburn 2571: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2572: next if ($skip);
1.484.2.7 raeburn 2573: my $srcdom = $1;
2574: my $srcnum = $2;
2575: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2576: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2577: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2578: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2579: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2580: $changed = 1;
2581: }
2582: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2583: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2584: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2585: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2586: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2587: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2588: $changed = 1;
2589: }
1.484.2.82 raeburn 2590: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2591: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2592: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2593: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2594: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2595: }
1.484.2.7 raeburn 2596: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2597: next if ($skip);
2598: my $srcdom = $1;
2599: my $srcnum = $2;
2600: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2601: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2602: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2603: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2604: $changed = 1;
2605: }
2606: }
2607: } elsif ($token->[1] eq 'param') {
2608: next if ($skip);
1.484.2.19 raeburn 2609: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2610: if ($to ne '') {
2611: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2612: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2613: } else {
2614: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2615: }
2616: }
2617: }
2618: }
2619: return $changed;
2620: }
2621:
2622: sub apply_fixups {
1.484.2.23 raeburn 2623: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2624: $oldurl,$url,$caller) = @_;
2625: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2626: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.82 raeburn 2627: %resdatacopy,%lockerrors,$lockmsg);
1.484.2.23 raeburn 2628: if (ref($updated) eq 'HASH') {
2629: if (ref($updated->{'rewrites'}) eq 'HASH') {
2630: %rewrites = %{$updated->{'rewrites'}};
2631: }
2632: if (ref($updated->{'zombies'}) eq 'HASH') {
2633: %zombies = %{$updated->{'zombies'}};
2634: }
2635: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2636: %removefrommap = %{$updated->{'removefrommap'}};
2637: }
2638: if (ref($updated->{'removeparam'}) eq 'HASH') {
2639: %removeparam = %{$updated->{'removeparam'}};
2640: }
2641: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2642: %dbcopies = %{$updated->{'dbcopies'}};
2643: }
2644: if (ref($updated->{'retitles'}) eq 'HASH') {
2645: %retitles = %{$updated->{'retitles'}};
2646: }
1.484.2.82 raeburn 2647: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2648: %resdatacopy = %{$updated->{'resdatacopy'}};
2649: }
1.484.2.23 raeburn 2650: }
2651: if (ref($info) eq 'HASH') {
2652: if (ref($info->{'newsubdir'}) eq 'HASH') {
2653: %newsubdir = %{$info->{'newsubdir'}};
2654: }
2655: if (ref($info->{'params'}) eq 'HASH') {
2656: %params = %{$info->{'params'}};
2657: }
2658: if (ref($info->{'before'}) eq 'HASH') {
2659: %before = %{$info->{'before'}};
2660: }
2661: if (ref($info->{'after'}) eq 'HASH') {
2662: %after = %{$info->{'after'}};
2663: }
2664: }
2665: if (ref($moves) eq 'HASH') {
2666: if (ref($moves->{'copies'}) eq 'HASH') {
2667: %copies = %{$moves->{'copies'}};
2668: }
2669: if (ref($moves->{'docmoves'}) eq 'HASH') {
2670: %docmoves = %{$moves->{'docmoves'}};
2671: }
2672: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2673: %mapmoves = %{$moves->{'mapmoves'}};
2674: }
2675: }
2676: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2677: my @allcopies;
1.484.2.23 raeburn 2678: if (exists($copies{$key})) {
2679: if (ref($copies{$key}) eq 'HASH') {
2680: my %added;
2681: foreach my $innerkey (keys(%{$copies{$key}})) {
2682: if (($innerkey ne '') && (!$added{$innerkey})) {
2683: push(@allcopies,$innerkey);
2684: $added{$innerkey} = 1;
2685: }
1.484.2.7 raeburn 2686: }
1.484.2.23 raeburn 2687: undef(%added);
1.484.2.7 raeburn 2688: }
2689: }
2690: if ($key eq $oldurl) {
1.484.2.23 raeburn 2691: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2692: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2693: push(@allcopies,$oldurl);
2694: }
2695: }
2696: }
2697: if (@allcopies > 0) {
2698: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2699: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2700: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2701: if ($fname ne '') {
2702: my $content = &Apache::lonnet::getfile($item);
2703: unless ($content eq '-1') {
2704: my $storefn;
1.484.2.23 raeburn 2705: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2706: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2707: } else {
2708: $storefn = $relpath;
2709: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2710: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2711: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2712: }
1.484.2.23 raeburn 2713: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2714: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2715: }
2716: }
2717: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2718: my $copyurl =
1.484.2.7 raeburn 2719: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2720: $storefn.$fname,$content);
2721: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2722: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2723: return &mt('Paste failed: an error occurred copying the file.');
2724: } elsif (ref($errors) eq 'HASH') {
2725: $errors->{$item} = 1;
2726: }
2727: }
2728: }
2729: }
2730: }
2731: }
2732: }
1.484.2.23 raeburn 2733: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2734: my $storefn=$key;
2735: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2736: if ($prefixchg && $before{'map'} && $after{'map'}) {
2737: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2738: }
1.484.2.23 raeburn 2739: if ($newsubdir{$key}) {
2740: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2741: }
2742: my $mapcontent = &Apache::lonnet::getfile($key);
1.484.2.93.2. (raeburn 2743:): if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
2744:): ($after{'map'} eq 'default') &&
2745:): ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
2746:): $mapcontent = '<map>'."\n".
2747:): '<resource id="1" src="" type="start" />'."\n".
2748:): '<link from="1" to="2" index="1" />'."\n".
2749:): '<resource id="2" src="" type="finish" />'."\n".
2750:): '</map>';
2751:): }
1.484.2.7 raeburn 2752: if ($mapcontent eq '-1') {
2753: if (ref($errors) eq 'HASH') {
2754: $errors->{$key} = 1;
2755: }
2756: } else {
2757: my $newmap =
2758: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2759: $mapcontent);
2760: if ($newmap eq '/adm/notfound.html') {
2761: if (ref($errors) eq 'HASH') {
2762: $errors->{$key} = 1;
2763: }
2764: }
2765: }
2766: }
2767: my %updates;
2768: if ($is_map) {
1.484.2.23 raeburn 2769: if (ref($updated) eq 'HASH') {
2770: foreach my $type (keys(%{$updated})) {
2771: if (ref($updated->{$type}) eq 'HASH') {
2772: foreach my $key (keys(%{$updated->{$type}})) {
2773: $updates{$key} = 1;
2774: }
2775: }
2776: }
1.484.2.7 raeburn 2777: }
2778: foreach my $key (keys(%updates)) {
2779: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2780: if (ref($rewrites{$key}) eq 'HASH') {
2781: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2782: }
1.484.2.23 raeburn 2783: if (ref($retitles{$key}) eq 'HASH') {
2784: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2785: }
1.484.2.23 raeburn 2786: if (ref($removefrommap{$key}) eq 'HASH') {
2787: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2788: }
1.484.2.23 raeburn 2789: if (ref($removeparam{$key}) eq 'HASH') {
2790: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2791: }
1.484.2.23 raeburn 2792: if (ref($zombies{$key}) eq 'HASH') {
2793: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2794: }
1.484.2.23 raeburn 2795: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2796: foreach my $idx (keys(%{$dbcopies{$key}})) {
2797: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2798: my ($newurl,$result,$errtext) =
2799: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2800: if ($result eq 'ok') {
2801: $newdb{$idx} = $newurl;
2802: } elsif (ref($errors) eq 'HASH') {
2803: $errors->{$key} = 1;
2804: }
2805: push(@msgs,$errtext);
2806: }
1.484.2.7 raeburn 2807: }
2808: }
1.484.2.82 raeburn 2809: if (ref($resdatacopy{$key}) eq 'HASH') {
2810: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2811: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2812: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2813: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2814: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2815: my $template = $1;
2816: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2817: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2818: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2819: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2820: unless ($gotnewmapname) {
2821: ($newmapname) = ($key =~ m{/([^/]+)$});
2822: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2823: if ($newsubdir{$key}) {
2824: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2825: }
2826: $gotnewmapname = 1;
2827: }
2828: my $srcmapinfo = $srcfolder.':'.$idx;
2829: if ($srccontainer eq 'page') {
2830: $srcmapinfo .= ':1';
2831: }
2832: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2833: $cnum,$template,$idx,$newmapname);
2834: }
2835: }
2836: }
2837: }
2838: }
1.484.2.23 raeburn 2839: if (ref($params{$key}) eq 'HASH') {
2840: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2841: }
2842: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2843: if ($fatal) {
1.484.2.26 raeburn 2844: return ($errtext);
1.484.2.7 raeburn 2845: }
2846: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2847: if (defined($LONCAPA::map::zombies[$i])) {
2848: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2849: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2850: undef($LONCAPA::map::zombies[$i]);
2851: }
2852: }
2853: }
1.484.2.77 raeburn 2854: my $total = scalar(@LONCAPA::map::order) - 1;
2855: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2856: my $idx = $LONCAPA::map::order[$i];
2857: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2858: my $changed;
1.484.2.23 raeburn 2859: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2860: if ((exists($toremove{$idx})) &&
2861: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2862: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2863: if (ref($currparam{$idx}) eq 'ARRAY') {
2864: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2865: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2866: }
2867: }
2868: next;
2869: }
2870: my $origsrc = $src;
1.484.2.25 raeburn 2871: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2872: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2873: $changed = 1;
2874: }
2875: }
1.484.2.25 raeburn 2876: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2877: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2878: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2879: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2880: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2881: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2882: } else {
1.484.2.23 raeburn 2883: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2884: }
2885: }
1.484.2.25 raeburn 2886: if ($origsrc =~ /\.(page|sequence)$/) {
2887: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2888: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2889: }
1.484.2.25 raeburn 2890: } elsif ($newsubdir{$key}) {
2891: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2892: }
2893: }
2894: $changed = 1;
1.484.2.26 raeburn 2895: } elsif ($newdb{$idx} ne '') {
2896: $src = $newdb{$idx};
1.484.2.7 raeburn 2897: $changed = 1;
2898: }
2899: if ($changed) {
1.484.2.30 raeburn 2900: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2901: }
2902: }
2903: }
2904: foreach my $idx (keys(%remparam)) {
2905: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2906: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2907: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2908: }
2909: }
2910: }
1.484.2.26 raeburn 2911: if (values(%lockerrors) > 0) {
2912: $lockmsg = join('<br />',values(%lockerrors));
2913: }
1.484.2.7 raeburn 2914: my $storefn;
2915: if ($key eq $oldurl) {
2916: $storefn = $url;
2917: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2918: } else {
2919: $storefn = $key;
2920: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2921: if ($prefixchg && $before{'map'} && $after{'map'}) {
2922: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2923: }
1.484.2.23 raeburn 2924: if ($newsubdir{$key}) {
2925: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2926: }
2927: }
2928: my $report;
2929: if ($folder !~ /^supplemental/) {
2930: $report = 1;
2931: }
1.484.2.20 raeburn 2932: (my $outtext,$errtext) =
1.484.2.7 raeburn 2933: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2934: if ($errtext) {
1.484.2.23 raeburn 2935: if ($caller eq 'paste') {
1.484.2.26 raeburn 2936: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2937: }
1.484.2.7 raeburn 2938: }
2939: }
2940: }
1.484.2.26 raeburn 2941: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2942: }
2943:
2944: sub copy_dependencies {
2945: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2946: my $content;
2947: if (ref($contentref)) {
2948: $content = $$contentref;
2949: } else {
2950: $content = &Apache::lonnet::getfile($item);
2951: }
2952: unless ($content eq '-1') {
2953: my $mm = new File::MMagic;
2954: my $mimetype = $mm->checktype_contents($content);
2955: if ($mimetype eq 'text/html') {
2956: my (%allfiles,%codebase,$state);
2957: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2958: if ($res eq 'ok') {
2959: my ($numexisting,$numpathchanges,$existing);
2960: (undef,$numexisting,$numpathchanges,$existing) =
2961: &Apache::loncommon::ask_for_embedded_content(
2962: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2963: {'error_on_invalid_names' => 1,
2964: 'ignore_remote_references' => 1,
2965: 'docs_url' => $item,
2966: 'context' => 'paste'});
2967: if ($numexisting > 0) {
2968: if (ref($existing) eq 'HASH') {
2969: foreach my $dep (keys(%{$existing})) {
2970: my $depfile = $dep;
2971: unless ($depfile =~ m{^\Q$relpath\E}) {
2972: $depfile = $relpath.$dep;
2973: }
2974: my $depcontent = &Apache::lonnet::getfile($depfile);
2975: unless ($depcontent eq '-1') {
2976: my $storedep = $dep;
2977: $storedep =~ s{^\Q$relpath\E}{};
2978: my $dep_url =
2979: &Apache::lonclonecourse::writefile(
2980: $env{'request.course.id'},
2981: $storefn.$storedep,$depcontent);
2982: if ($dep_url eq '/adm/notfound.html') {
2983: if (ref($errors) eq 'HASH') {
2984: $errors->{$depfile} = 1;
2985: }
2986: } else {
2987: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2988: }
2989: }
2990: }
2991: }
2992: }
2993: }
2994: }
2995: }
2996: return;
2997: }
2998:
1.329 droeschl 2999: my %parameter_type = ( 'randompick' => 'int_pos',
3000: 'hiddenresource' => 'string_yesno',
3001: 'encrypturl' => 'string_yesno',
3002: 'randomorder' => 'string_yesno',);
3003: my $valid_parameters_re = join('|',keys(%parameter_type));
3004: # set parameters
3005: sub update_parameter {
1.484.2.29 raeburn 3006: if ($env{'form.changeparms'} eq 'all') {
3007: my (@allidx,@allmapidx,%allchecked,%currchecked);
3008: %allchecked = (
3009: 'hiddenresource' => {},
3010: 'encrypturl' => {},
3011: 'randompick' => {},
3012: 'randomorder' => {},
3013: );
3014: foreach my $which (keys(%allchecked)) {
3015: $env{'form.all'.$which} =~ s/,$//;
3016: if ($which eq 'randompick') {
3017: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3018: my ($res,$value) = split(/:/,$item);
3019: if ($value =~ /^\d+$/) {
3020: $allchecked{$which}{$res} = $value;
3021: }
3022: }
3023: } else {
1.484.2.30 raeburn 3024: if ($env{'form.all'.$which}) {
3025: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3026: }
1.484.2.29 raeburn 3027: }
3028: }
3029: my $haschanges = 0;
3030: foreach my $res (@LONCAPA::map::order) {
3031: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3032: $name=&LONCAPA::map::qtescape($name);
3033: $url=&LONCAPA::map::qtescape($url);
1.484.2.93.2. (raeburn 3034:): next unless $url;
1.484.2.29 raeburn 3035: my $is_map;
3036: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3037: $is_map = 1;
3038: }
3039: foreach my $which (keys(%allchecked)) {
3040: if (($which eq 'randompick' || $which eq 'randomorder')) {
3041: next if (!$is_map);
3042: }
3043: my $oldvalue = 0;
3044: my $newvalue = 0;
3045: if ($allchecked{$which}{$res}) {
3046: $newvalue = $allchecked{$which}{$res};
3047: }
3048: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3049: if ($which eq 'randompick') {
3050: if ($current =~ /^(\d+)$/) {
3051: $oldvalue = $1;
3052: }
3053: } else {
3054: if ($current =~ /^yes$/i) {
3055: $oldvalue = 1;
3056: }
3057: }
3058: if ($oldvalue ne $newvalue) {
3059: $haschanges = 1;
3060: if ($newvalue) {
3061: my $storeval = 'yes';
3062: if ($which eq 'randompick') {
3063: $storeval = $newvalue;
3064: }
3065: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3066: $storeval,
3067: $parameter_type{$which});
3068: &remember_parms($res,$which,'set',$storeval);
3069: } elsif ($oldvalue) {
3070: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3071: &remember_parms($res,$which,'del');
3072: }
3073: }
3074: }
3075: }
3076: return $haschanges;
1.329 droeschl 3077: } else {
1.484.2.59 raeburn 3078: my $haschanges = 0;
3079: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 3080:
1.484.2.29 raeburn 3081: my $which = $env{'form.changeparms'};
3082: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 3083: my $oldvalue = 0;
3084: my $newvalue = 0;
3085: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3086: if ($which eq 'randompick') {
3087: if ($current =~ /^(\d+)$/) {
3088: $oldvalue = $1;
3089: }
3090: } elsif ($current =~ /^yes$/i) {
3091: $oldvalue = 1;
3092: }
1.484.2.29 raeburn 3093: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 3094: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3095: : 1;
1.484.2.29 raeburn 3096: }
1.484.2.59 raeburn 3097: if ($oldvalue ne $newvalue) {
3098: $haschanges = 1;
3099: if ($newvalue) {
3100: my $storeval = 'yes';
3101: if ($which eq 'randompick') {
3102: $storeval = $newvalue;
3103: }
3104: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3105: $parameter_type{$which});
3106: &remember_parms($idx,$which,'set',$storeval);
3107: } else {
3108: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3109: &remember_parms($idx,$which,'del');
3110: }
3111: }
3112: return $haschanges;
1.329 droeschl 3113: }
1.484.2.59 raeburn 3114: return;
1.329 droeschl 3115: }
3116:
3117: sub handle_edit_cmd {
3118: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 3119: if ($env{'form.cmd'} eq '') {
3120: return 0;
3121: }
1.329 droeschl 3122: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3123:
3124: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3125: my ($title, $url, @rrest) = split(':', $ratstr);
3126:
1.484.2.30 raeburn 3127: if ($cmd eq 'remove') {
1.329 droeschl 3128: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3129: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3130: &Apache::lonnet::removeuploadedurl($url);
3131: } else {
3132: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3133: }
3134: splice(@LONCAPA::map::order, $idx, 1);
3135:
3136: } elsif ($cmd eq 'cut') {
3137: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3138: splice(@LONCAPA::map::order, $idx, 1);
3139:
1.344 bisitz 3140: } elsif ($cmd eq 'up'
1.329 droeschl 3141: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3142: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3143:
3144: } elsif ($cmd eq 'down'
3145: && defined($LONCAPA::map::order[$idx+1])) {
3146: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3147:
3148: } elsif ($cmd eq 'rename') {
3149: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3150: if ($comment=~/\S/) {
3151: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3152: $comment.':'.join(':', $url, @rrest);
3153: }
3154: # Devalidate title cache
3155: my $renamed_url=&LONCAPA::map::qtescape($url);
3156: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 3157:
1.329 droeschl 3158: } else {
3159: return 0;
3160: }
3161: return 1;
3162: }
3163:
3164: sub editor {
1.458 raeburn 3165: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.93.2. (raeburn 3166:): $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3167:): $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 3168: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3169: if ($allowed) {
3170: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3171: $is_random_order,$container) =
3172: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3173: $r->print($breadcrumbtrail);
3174: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3175: $container = 'page';
3176: } else {
3177: $container = 'sequence';
3178: }
1.484 raeburn 3179:
1.484.2.21 raeburn 3180: my $jumpto;
3181:
3182: unless ($supplementalflag) {
1.484.2.32 raeburn 3183: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 3184: }
1.484 raeburn 3185:
3186: unless ($allowed) {
3187: $randompick = -1;
3188: }
3189:
1.484.2.67 raeburn 3190: my ($errtext,$fatal);
3191: if (($folder eq '') && (!$supplementalflag)) {
3192: if (@LONCAPA::map::order) {
3193: undef(@LONCAPA::map::order);
3194: undef(@LONCAPA::map::resources);
3195: undef(@LONCAPA::map::resparms);
3196: undef(@LONCAPA::map::zombies);
3197: }
3198: $folder = 'default';
3199: $container = 'sequence';
3200: } else {
3201: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3202: $folder.'.'.$container);
3203: return $errtext if ($fatal);
3204: }
1.329 droeschl 3205:
3206: if ($#LONCAPA::map::order<1) {
3207: my $idx=&LONCAPA::map::getresidx();
3208: if ($idx<=0) { $idx=1; }
3209: $LONCAPA::map::order[0]=$idx;
3210: $LONCAPA::map::resources[$idx]='';
3211: }
1.364 bisitz 3212:
1.329 droeschl 3213: # ------------------------------------------------------------ Process commands
3214:
3215: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 3216: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3217: # set parameters and change order
3218: &snapshotbefore();
3219:
3220: if (&update_parameter()) {
1.484.2.59 raeburn 3221: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3222: return $errtext if ($fatal);
3223: }
3224:
3225: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3226: # change order
3227: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3228: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3229:
3230: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3231: return $errtext if ($fatal);
3232: }
1.364 bisitz 3233:
1.329 droeschl 3234: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 3235: my %paste_errors;
1.484.2.26 raeburn 3236: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 3237: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3238: \%paste_errors);
1.484.2.30 raeburn 3239: if (ref($pastemsgarray) eq 'ARRAY') {
3240: if (@{$pastemsgarray} > 0) {
3241: $r->print('<p class="LC_info">'.
3242: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3243: '</p>');
3244: }
1.484.2.30 raeburn 3245: }
3246: if ($lockerror) {
3247: $r->print('<p class="LC_error">'.
3248: $lockerror.
3249: '</p>');
3250: }
3251: if ($save_error ne '') {
3252: return $save_error;
3253: }
3254: if ($paste_res) {
3255: my %errortext = &Apache::lonlocal::texthash (
3256: fail => 'Storage of folder contents failed',
3257: failread => 'Reading folder contents failed',
3258: failstore => 'Storage of folder contents failed',
3259: );
3260: if ($errortext{$paste_res}) {
3261: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3262: }
1.329 droeschl 3263: }
1.484.2.7 raeburn 3264: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3265: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3266: &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".
3267: '<ul>'."\n");
3268: foreach my $key (sort(keys(%paste_errors))) {
3269: $r->print('<li>'.$key.'</li>'."\n");
3270: }
3271: $r->print('</ul></p>'."\n");
3272: }
1.484.2.30 raeburn 3273: } elsif ($env{'form.clearmarked'}) {
3274: my $output = &do_buffer_empty();
3275: if ($output) {
3276: $r->print('<p class="LC_info">'.$output.'</p>');
3277: }
3278: }
1.329 droeschl 3279:
3280: $r->print($upload_output);
3281:
1.484.2.30 raeburn 3282: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3283: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3284: my $contentchg;
1.484.2.58 raeburn 3285: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3286: $contentchg = 1;
3287: }
3288: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3289: return $errtext if ($fatal);
3290: }
1.484.2.30 raeburn 3291:
3292: # Cut, copy and/or remove multiple resources
3293: if ($env{'form.multichange'}) {
3294: my %allchecked = (
3295: cut => {},
3296: remove => {},
3297: );
3298: my $needsupdate;
3299: foreach my $which (keys(%allchecked)) {
3300: $env{'form.multi'.$which} =~ s/,$//;
3301: if ($env{'form.multi'.$which}) {
3302: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3303: if (ref($allchecked{$which}) eq 'HASH') {
3304: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3305: }
3306: }
3307: }
3308: if ($needsupdate) {
3309: my $haschanges = 0;
3310: my %curr_groups = &Apache::longroup::coursegroups();
3311: my $total = scalar(@LONCAPA::map::order) - 1;
3312: for (my $i=$total; $i>=0; $i--) {
3313: my $res = $LONCAPA::map::order[$i];
3314: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3315: $name=&LONCAPA::map::qtescape($name);
3316: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3317: next unless $url;
1.484.2.30 raeburn 3318: my %denied =
3319: &action_restrictions($coursenum,$coursedom,$url,
3320: $env{'form.folderpath'},\%curr_groups);
3321: foreach my $which (keys(%allchecked)) {
3322: next if ($denied{$which});
3323: next unless ($allchecked{$which}{$res});
3324: if ($which eq 'remove') {
3325: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3326: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3327: &Apache::lonnet::removeuploadedurl($url);
3328: } else {
3329: &LONCAPA::map::makezombie($res);
3330: }
3331: splice(@LONCAPA::map::order,$i,1);
3332: $haschanges ++;
3333: } elsif ($which eq 'cut') {
3334: &LONCAPA::map::makezombie($res);
3335: splice(@LONCAPA::map::order,$i,1);
3336: $haschanges ++;
3337: }
3338: }
3339: }
3340: if ($haschanges) {
3341: ($errtext,$fatal) =
3342: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3343: return $errtext if ($fatal);
3344: }
3345: }
3346: }
3347:
1.329 droeschl 3348: # Group import/search
3349: if ($env{'form.importdetail'}) {
3350: my @imports;
3351: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3352: if (defined($item)) {
3353: my ($name,$url,$residx)=
1.484.2.26 raeburn 3354: map { &unescape($_); } split(/\=/,$item);
3355: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3356: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3357: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3358: if ($locknotfreed) {
3359: $r->print($locknotfreed);
3360: }
3361: if ($suffix) {
1.484.2.19 raeburn 3362: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3363: } else {
3364: return $errortxt;
3365: }
1.484.2.26 raeburn 3366: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3367: my $type = $1;
3368: my ($suffix,$errortxt,$locknotfreed) =
3369: &new_timebased_suffix($coursedom,$coursenum,$type);
3370: if ($locknotfreed) {
3371: $r->print($locknotfreed);
3372: }
3373: if ($suffix) {
3374: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3375: } else {
3376: return $errortxt;
3377: }
1.484.2.93.2. (raeburn 3378:): } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3379:): my ($suffix,$errortxt,$locknotfreed) =
3380:): &new_timebased_suffix($coursedom,$coursenum,'exttool');
3381:): if ($locknotfreed) {
3382:): $r->print($locknotfreed);
3383:): }
3384:): if ($suffix) {
3385:): $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3386:): } else {
3387:): return $errortxt;
3388:): }
1.484.2.27 raeburn 3389: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3390: if ($supplementalflag) {
3391: next unless ($1 eq 'supplemental');
3392: if ($folder eq 'supplemental') {
3393: next unless ($2 eq 'default');
3394: } else {
3395: next unless ($folder eq 'supplemental_'.$2);
3396: }
3397: } else {
3398: next unless ($1 eq 'docs');
3399: if ($folder eq 'default') {
3400: next unless ($2 eq 'default');
3401: } else {
3402: next unless ($folder eq 'default_'.$2);
3403: }
3404: }
1.484.2.15 raeburn 3405: }
1.329 droeschl 3406: push(@imports, [$name, $url, $residx]);
3407: }
3408: }
1.484.2.23 raeburn 3409: ($errtext,$fatal,my $fixuperrors) =
3410: &group_import($coursenum, $coursedom, $folder,$container,
1.484.2.93.2. (raeburn 3411:): 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3412: return $errtext if ($fatal);
1.484.2.23 raeburn 3413: if ($fixuperrors) {
3414: $r->print($fixuperrors);
3415: }
1.329 droeschl 3416: }
3417: # Loading a complete map
3418: if ($env{'form.loadmap'}) {
3419: if ($env{'form.importmap'}=~/\w/) {
3420: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3421: my ($title,$url,$ext,$type)=split(/\:/,$res);
3422: my $idx=&LONCAPA::map::getresidx($url);
3423: $LONCAPA::map::resources[$idx]=$res;
3424: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3425: }
3426: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3427: $folder.'.'.$container,1);
1.329 droeschl 3428: return $errtext if ($fatal);
3429: } else {
3430: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3431:
1.329 droeschl 3432: }
3433: }
3434: &log_differences($plain);
3435: }
3436: # ---------------------------------------------------------------- End commands
3437: # ---------------------------------------------------------------- Print screen
3438: my $idx=0;
3439: my $shown=0;
3440: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3441: $r->print('<div class="LC_Box">'.
1.432 raeburn 3442: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3443: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3444: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3445: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3446: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3447: '</ol>');
1.381 bisitz 3448: if ($randompick>=0) {
3449: $r->print('<p class="LC_warning">'
3450: .&mt('Caution: this folder is set to randomly pick a subset'
3451: .' of resources. Adding or removing resources from this'
3452: .' folder will change the set of resources that the'
3453: .' students see, resulting in spurious or missing credit'
3454: .' for completed problems, not limited to ones you'
3455: .' modify. Do not modify the contents of this folder if'
3456: .' it is in active student use.')
3457: .'</p>'
3458: );
3459: }
3460: if ($is_random_order) {
3461: $r->print('<p class="LC_warning">'
3462: .&mt('Caution: this folder is set to randomly order its'
3463: .' contents. Adding or removing resources from this folder'
3464: .' will change the order of resources shown.')
3465: .'</p>'
3466: );
3467: }
3468: $r->print('</div>');
1.364 bisitz 3469: }
1.381 bisitz 3470:
1.484.2.93.2. 0(raebur 3471:3): if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
3472:3): my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
3473:3): if (ref($supplemental) eq 'HASH') {
3474:3): if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
3475:3): (ref($supplemental->{'ids'}) eq 'HASH')) {
3476:3): if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
3477:3): my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
3478:3): if ($supplemental->{'hidden'}->{$mapnum}) {
3479:3): $ishidden = 1;
3480:3): }
3481:3): }
3482:3): }
3483:3): }
3484:3): }
3485:3):
1.484.2.30 raeburn 3486: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3487: %filters = (
3488: canremove => [],
3489: cancut => [],
3490: cancopy => [],
3491: hiddenresource => [],
3492: encrypturl => [],
3493: randomorder => [],
3494: randompick => [],
3495: );
3496: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3497: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3498: foreach my $res (@LONCAPA::map::order) {
3499: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3500: $name=&LONCAPA::map::qtescape($name);
3501: $url=&LONCAPA::map::qtescape($url);
3502: unless ($name) { $name=(split(/\//,$url))[-1]; }
3503: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3504: push(@allidx,$res);
3505: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3506: push(@allmapidx,$res);
3507: }
1.484.2.67 raeburn 3508:
1.484.2.93.2. 0(raebur 3509:3): if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
3510:3): if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
3511:3): $idx++;
3512:3): next;
3513:3): }
3514:3): }
1.381 bisitz 3515: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3516: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3517: $pathitem,$supplementalflag,$container,
1.484.2.93.2. (raeburn 3518:): \%filters,\%curr_groups,$ltitoolsref,$canedit,
0(raebur 3519:3): $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 3520: $idx++;
3521: $shown++;
1.329 droeschl 3522: }
1.424 onken 3523: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3524:
1.484.2.30 raeburn 3525: my $need_save;
1.484.2.67 raeburn 3526: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3527: my $toolslink;
1.484.2.93.2. 0(raebur 3528:3): if ($allowed || $canedit) {
3529:3): my $helpitem = 'Navigation_Screen';
3530:3): if (!$allowed) {
3531:3): $helpitem = 'Supplemental_Navigation';
3532:3): }
1.484.2.31 raeburn 3533: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3534: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.484.2.93.2. 0(raebur 3535:3): $helpitem,undef,'RAT')
1.484.2.19 raeburn 3536: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3537: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3538: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3539: .'id="LC_content_toolbar_edittoplevel" '
3540: .'class="LC_toolbarItem" '
3541: .'title="'.&mt('Supplemental Content Editor').'">'
3542: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3543: }
1.484.2.19 raeburn 3544: if ($shown) {
3545: if ($allowed) {
3546: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3547: .&Apache::loncommon::start_data_table(undef,'contentlist')
3548: .&Apache::loncommon::start_data_table_header_row()
3549: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3550: .'<th colspan="2">'.&mt('Actions').'</th>'
1.484.2.93.2. 0(raebur 3551:3): .'<th>'.&mt('Document').'</th>'
3552:3): .'<th colspan="2">'.&mt('Settings').'</th>'
3553:3): .&Apache::loncommon::end_data_table_header_row();
1.484.2.29 raeburn 3554: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3555: $lists{'canhide'} = join(',',@allidx);
3556: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3557: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3558: 'randomorder','randompick');
3559: foreach my $item (@possfilters) {
3560: if (ref($filters{$item}) eq 'ARRAY') {
3561: if (@{$filters{$item}} > 0) {
3562: $lists{$item} = join(',',@{$filters{$item}});
3563: }
3564: }
3565: }
1.484.2.29 raeburn 3566: if (@allidx > 0) {
3567: my $path;
3568: if ($env{'form.folderpath'}) {
3569: $path =
3570: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3571: }
1.484.2.30 raeburn 3572: if (@allidx > 1) {
3573: $to_show .=
3574: &Apache::loncommon::continue_data_table_row().
3575: '<td colspan="2"> </td>'.
3576: '<td>'.
1.484.2.67 raeburn 3577: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3578: '</td>'.
3579: '<td> </td>'.
3580: '<td> </td>'.
1.484.2.93.2. 0(raebur 3581:3): '<td colspan="2">'.
1.484.2.67 raeburn 3582: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3583: '</td>'.
3584: &Apache::loncommon::end_data_table_row();
3585: $need_save = 1;
3586: }
1.484.2.29 raeburn 3587: }
3588: }
3589: $to_show .= $output.' '
1.484.2.19 raeburn 3590: .&Apache::loncommon::end_data_table()
3591: .'<br style="line-height:2px;" />'
3592: .&Apache::loncommon::end_scrollbox();
3593: } else {
3594: $to_show .= $toolslink
3595: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3596: .$output.' '
3597: .&Apache::loncommon::end_data_table();
3598: }
3599: } else {
3600: if (!$allowed) {
3601: $to_show .= $toolslink;
1.393 raeburn 3602: }
1.484.2.67 raeburn 3603: my $noresmsg;
3604: if ($allowed && $hiddentop && !$supplementalflag) {
3605: $noresmsg = &mt('Main Content Hidden');
3606: } else {
3607: $noresmsg = &mt('Currently empty');
3608: }
1.484.2.19 raeburn 3609: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3610: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3611: .$noresmsg
1.484.2.19 raeburn 3612: .'</div>'
3613: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3614: }
3615: } else {
1.484.2.19 raeburn 3616: if ($shown) {
3617: $to_show = '<div>'
3618: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3619: .$output
3620: .&Apache::loncommon::end_data_table()
3621: .'</div>';
3622: } else {
3623: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3624: .&mt('Currently empty')
1.484.2.19 raeburn 3625: .'</div>'
3626: }
1.458 raeburn 3627: }
3628: my $tid = 1;
3629: if ($supplementalflag) {
3630: $tid = 2;
1.329 droeschl 3631: }
3632: if ($allowed) {
1.484 raeburn 3633: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3634: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3635: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3636: if ($canedit) {
1.484.2.67 raeburn 3637: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3638: }
1.460 raeburn 3639: } else {
3640: $r->print($to_show);
1.329 droeschl 3641: }
3642: return;
3643: }
3644:
1.484.2.30 raeburn 3645: sub multiple_check_form {
1.484.2.67 raeburn 3646: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3647: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3648: my $disabled;
3649: unless ($canedit) {
3650: $disabled = 'disabled="disabled"';
3651: }
1.484.2.30 raeburn 3652: my $output =
3653: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3654: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3655: '<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>'.
3656: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3657: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3658: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3659: if ($caller eq 'settings') {
3660: $output .=
3661: '<table><tr>'.
3662: '<td class="LC_docs_entry_parameter">'.
3663: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3664: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3665: '</label></span></td>'.
3666: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3667: '<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 3668: '</span></td>'.
3669: '</tr>'."\n".
3670: '<tr>'.
3671: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3672: '<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 3673: '</label></span>'.
3674: '</td></tr></table>'."\n";
3675: } else {
3676: $output .=
3677: '<table><tr>'.
3678: '<td class="LC_docs_entry_parameter">'.
3679: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3680: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3681: '</label></span></td>'.
3682: '<td class="LC_docs_entry_parameter">'.
3683: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3684: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3685: '</label></span></td>'."\n".
3686: '<td class="LC_docs_entry_parameter">'.
3687: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3688: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3689: '</label></span></td>'.
3690: '</tr></table>'."\n";
3691: }
3692: $output .=
3693: '</fieldset>'.
3694: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3695: if ($caller eq 'settings') {
3696: $output .=
3697: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3698: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3699: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3700: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3701: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3702: } elsif ($caller eq 'actions') {
3703: $output .=
3704: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3705: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3706: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3707: }
3708: $output .=
3709: '</form>'.
3710: '</div>';
3711: return $output;
3712: }
3713:
1.329 droeschl 3714: sub process_file_upload {
1.484.2.36 raeburn 3715: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3716: # upload a file, if present
1.484.2.36 raeburn 3717: my $filesize = length($env{'form.uploaddoc'});
3718: if (!$filesize) {
3719: $$upload_output = '<div class="LC_error">'.
3720: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3721: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3722: $filesize).'<br />'.
3723: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3724: '</div>';
3725: return;
3726: }
3727: my $quotatype = 'unofficial';
3728: if ($crstype eq 'Community') {
3729: $quotatype = 'community';
1.484.2.51 raeburn 3730: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3731: $quotatype = 'official';
1.484.2.45 raeburn 3732: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3733: $quotatype = 'textbook';
1.484.2.36 raeburn 3734: }
3735: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3736: $filesize = int($filesize/1000); #expressed in kb
3737: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3738: $env{'form.uploaddoc.filename'},$filesize,
3739: 'upload',$quotatype);
1.484.2.36 raeburn 3740: return if ($$upload_output);
3741: }
1.440 raeburn 3742: my ($parseaction,$showupload,$nextphase,$mimetype);
3743: if ($env{'form.parserflag'}) {
1.329 droeschl 3744: $parseaction = 'parse';
3745: }
3746: my $folder=$env{'form.folder'};
3747: if ($folder eq '') {
3748: $folder='default';
3749: }
3750: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3751: my $errtext='';
3752: my $fatal=0;
3753: my $container='sequence';
1.484.2.19 raeburn 3754: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3755: $container='page';
3756: }
3757: ($errtext,$fatal)=
1.484.2.27 raeburn 3758: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3759: if ($#LONCAPA::map::order<1) {
3760: $LONCAPA::map::order[0]=1;
3761: $LONCAPA::map::resources[1]='';
3762: }
3763: my $destination = 'docs/';
3764: if ($folder =~ /^supplemental/) {
3765: $destination = 'supplemental/';
3766: }
3767: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3768: $destination .= 'default/';
3769: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3770: $destination .= $2.'/';
3771: }
1.484.2.27 raeburn 3772: if ($fatal) {
3773: $$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>';
3774: return;
3775: }
1.440 raeburn 3776: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3777: my $newidx=&LONCAPA::map::getresidx();
3778: $destination .= $newidx;
1.439 raeburn 3779: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3780: $parseaction,$allfiles,
1.440 raeburn 3781: $codebase,undef,undef,undef,undef,
3782: undef,undef,\$mimetype);
3783: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3784: my $stored = $1;
3785: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3786: $stored.'</span>').'</p>';
3787: } else {
3788: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3789:
1.457 raeburn 3790: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3791: return;
3792: }
1.329 droeschl 3793: my $ext='false';
3794: if ($url=~m{^http://}) { $ext='true'; }
3795: $url = &LONCAPA::map::qtunescape($url);
3796: my $comment=$env{'form.comment'};
3797: $comment = &LONCAPA::map::qtunescape($comment);
3798: if ($folder=~/^supplemental/) {
3799: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3800: $env{'user.domain'}.'___&&&___'.$comment;
3801: }
3802:
3803: $LONCAPA::map::resources[$newidx]=
3804: $comment.':'.$url.':'.$ext.':normal:res';
3805: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3806: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3807: $folder.'.'.$container,1);
1.329 droeschl 3808: if ($fatal) {
1.457 raeburn 3809: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3810: return;
1.329 droeschl 3811: } else {
1.440 raeburn 3812: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3813: $$upload_output = $showupload;
1.384 raeburn 3814: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3815: if ($total_embedded > 0) {
1.440 raeburn 3816: my $uploadphase = 'upload_embedded';
3817: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3818: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3819: my ($embedded,$num) =
3820: &Apache::loncommon::ask_for_embedded_content(
3821: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3822: if ($embedded) {
3823: if ($num) {
3824: $$upload_output .=
3825: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3826: $nextphase = $uploadphase;
3827: } else {
3828: $$upload_output .= $embedded;
3829: }
3830: } else {
3831: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3832: }
1.329 droeschl 3833: } else {
1.440 raeburn 3834: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3835: }
1.457 raeburn 3836: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3837: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3838: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3839: $nextphase = 'decompress_uploaded';
3840: my $position = scalar(@LONCAPA::map::order)-1;
3841: my $noextract = &return_to_editor();
3842: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3843: my %archiveitems = (
3844: folderpath => $env{'form.folderpath'},
3845: cmd => $nextphase,
3846: newidx => $newidx,
3847: position => $position,
3848: phase => $nextphase,
1.477 raeburn 3849: comment => $comment,
1.480 raeburn 3850: );
3851: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3852: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3853: $$upload_output = $showupload.
3854: &Apache::loncommon::decompress_form($mimetype,
3855: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3856: \%archiveitems,\@current);
1.329 droeschl 3857: }
3858: }
3859: }
1.440 raeburn 3860: return $nextphase;
1.329 droeschl 3861: }
3862:
1.480 raeburn 3863: sub get_dir_list {
3864: my ($url,$coursenum,$coursedom,$newidx) = @_;
3865: my ($destination,$dir_root) = &embedded_destination();
3866: my ($dirlistref,$listerror) =
3867: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3868: my @dir_lines;
3869: my $dirptr=16384;
3870: if (ref($dirlistref) eq 'ARRAY') {
3871: foreach my $dir_line (sort
3872: {
3873: my ($afile)=split('&',$a,2);
3874: my ($bfile)=split('&',$b,2);
3875: return (lc($afile) cmp lc($bfile));
3876: } (@{$dirlistref})) {
3877: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3878: $filename =~ s/\s+$//;
3879: next if ($filename =~ /^\.\.?$/);
3880: my $isdir = 0;
3881: if ($dirptr&$testdir) {
3882: $isdir = 1;
3883: }
3884: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3885: }
3886: }
3887: return @dir_lines;
3888: }
3889:
1.329 droeschl 3890: sub is_supplemental_title {
3891: my ($title) = @_;
3892: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3893: }
3894:
3895: # --------------------------------------------------------------- An entry line
3896:
3897: sub entryline {
1.484.2.12 raeburn 3898: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3899: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.93.2. 0(raebur 3900:3): $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
3901:3): my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 3902: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3903: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.484.2.93.2. 0(raebur 3904:3): $encodedtitle=$title;
1.329 droeschl 3905: } else {
3906: $title=&HTML::Entities::encode($title,'"<>&\'');
1.484.2.93.2. 0(raebur 3907:3): $encodedtitle=$title;
1.329 droeschl 3908: $renametitle=$title;
3909: $foldertitle=$title;
3910: }
3911:
1.484.2.67 raeburn 3912: my ($disabled,$readonly,$js_lt);
3913: unless ($canedit) {
3914: $disabled = 'disabled="disabled"';
3915: $readonly = 1;
3916: }
3917:
1.329 droeschl 3918: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3919:
1.329 droeschl 3920: $renametitle=~s/\\/\\\\/g;
3921: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3922: $renametitle=~s/"/%22/g;
1.329 droeschl 3923: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3924: $oldtitle = $renametitle;
3925: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3926: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3927: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3928: # Edit commands
1.484.2.93.2. (raeburn 3929:): my ($esc_path, $path, $symb, $shownsymb);
1.329 droeschl 3930: if ($env{'form.folderpath'}) {
3931: $esc_path=&escape($env{'form.folderpath'});
3932: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3933: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3934: }
1.484.2.16 raeburn 3935: my $isexternal;
1.484.2.19 raeburn 3936: if ($residx) {
1.484.2.12 raeburn 3937: my $currurl = $url;
3938: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3939: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3940: $isexternal = 1;
3941: }
1.484.2.19 raeburn 3942: if (!$supplementalflag) {
3943: my $path = 'uploaded/'.
3944: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3945: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3946: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3947: $residx,
3948: &Apache::lonnet::declutter($currurl));
3949: }
1.484.2.12 raeburn 3950: }
1.484.2.30 raeburn 3951: my ($renamelink,%lt,$ishash);
3952: if (ref($filtersref) eq 'HASH') {
3953: $ishash = 1;
3954: }
3955:
1.329 droeschl 3956: if ($allowed) {
1.484.2.30 raeburn 3957: $form_start = '
3958: <form action="/adm/coursedocs" method="post">
3959: ';
3960: $form_common=(<<END);
3961: <input type="hidden" name="folderpath" value="$path" />
3962: <input type="hidden" name="symb" value="$symb" />
3963: END
3964: $form_param=(<<END);
3965: <input type="hidden" name="setparms" value="$orderidx" />
3966: <input type="hidden" name="changeparms" value="0" />
3967: END
3968: $form_end = '</form>';
3969:
1.329 droeschl 3970: my $incindex=$index+1;
3971: my $selectbox='';
1.471 raeburn 3972: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3973: ((split(/\:/,
1.344 bisitz 3974: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3975: ne '') &&
1.329 droeschl 3976: ((split(/\:/,
1.344 bisitz 3977: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3978: ne '')) {
3979: $selectbox=
3980: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3981: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3982: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3983: if ($i==$incindex) {
1.358 bisitz 3984: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3985: } else {
3986: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3987: }
3988: }
3989: $selectbox.='</select>';
3990: }
1.484.2.12 raeburn 3991: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3992: 'up' => 'Move Up',
3993: 'dw' => 'Move Down',
3994: 'rm' => 'Remove',
3995: 'ct' => 'Cut',
3996: 'rn' => 'Rename',
1.484.2.12 raeburn 3997: 'cp' => 'Copy',
3998: 'ex' => 'External Resource',
1.484.2.93.2. (raeburn 3999:): 'et' => 'External Tool',
1.484.2.12 raeburn 4000: 'ed' => 'Edit',
4001: 'pr' => 'Preview',
4002: 'sv' => 'Save',
4003: 'ul' => 'URL',
1.484.2.67 raeburn 4004: 'ti' => 'Title',
4005: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 4006: );
1.484.2.30 raeburn 4007: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4008: $env{'form.folderpath'},
4009: $currgroups);
1.484.2.19 raeburn 4010: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4011: my $skip_confirm = 0;
1.484.2.63 raeburn 4012: my $confirm_removal = 0;
1.329 droeschl 4013: if ( $folder =~ /^supplemental/
4014: || ($url =~ m{( /smppg$
4015: |/syllabus$
4016: |/aboutme$
4017: |/navmaps$
4018: |/bulletinboard$
1.484.2.93.2. (raeburn 4019:): |/ext\.tool$
1.484.2.16 raeburn 4020: |\.html$)}x)
1.484.2.19 raeburn 4021: || $isexternal) {
1.329 droeschl 4022: $skip_confirm = 1;
4023: }
1.484.2.63 raeburn 4024: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4025: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4026: $confirm_removal = 1;
4027: }
1.484.2.19 raeburn 4028:
1.484.2.30 raeburn 4029: if ($denied{'copy'}) {
4030: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 4031: <span style="visibility: hidden;">$lt{'cp'}</span>
4032: ENDCOPY
4033: } else {
1.484.2.30 raeburn 4034: my $formname = 'edit_copy_'.$orderidx;
4035: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 4036: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 4037: <form name="$formname" method="post" action="/adm/coursedocs">
4038: $form_common
1.484.2.67 raeburn 4039: <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 4040: $form_end
1.329 droeschl 4041: ENDCOPY
1.484.2.30 raeburn 4042: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4043: push(@{$filtersref->{'cancopy'}},$orderidx);
4044: }
1.329 droeschl 4045: }
1.484.2.30 raeburn 4046: if ($denied{'cut'}) {
1.484.2.16 raeburn 4047: $cutlink=(<<ENDCUT);
4048: <span style="visibility: hidden;">$lt{'ct'}</span>
4049: ENDCUT
4050: } else {
1.484.2.30 raeburn 4051: my $formname = 'edit_cut_'.$orderidx;
4052: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 4053: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 4054: <form name="$formname" method="post" action="/adm/coursedocs">
4055: $form_common
4056: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 4057: <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 4058: $form_end
1.329 droeschl 4059: ENDCUT
1.484.2.30 raeburn 4060: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4061: push(@{$filtersref->{'cancut'}},$orderidx);
4062: }
1.329 droeschl 4063: }
1.484.2.30 raeburn 4064: if ($denied{'remove'}) {
1.484.2.16 raeburn 4065: $removelink=(<<ENDREM);
4066: <span style="visibility: hidden;">$lt{'rm'}</a>
4067: ENDREM
4068: } else {
1.484.2.30 raeburn 4069: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 4070: 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 4071: $removelink=(<<ENDREM);
1.484.2.30 raeburn 4072: <form name="$formname" method="post" action="/adm/coursedocs">
4073: $form_common
4074: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 4075: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 4076: <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 4077: $form_end
1.484.2.9 raeburn 4078: ENDREM
1.484.2.30 raeburn 4079: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4080: push(@{$filtersref->{'canremove'}},$orderidx);
4081: }
1.484.2.9 raeburn 4082: }
1.484.2.35 raeburn 4083: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 4084: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 4085: ENDREN
1.484.2.67 raeburn 4086: my ($uplink,$downlink);
4087: if ($canedit) {
4088: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4089: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4090: } else {
4091: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4092: $downlink = $uplink;
4093: }
1.329 droeschl 4094: $line.=(<<END);
4095: <td>
1.379 bisitz 4096: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4097: <a href="$uplink">
1.484.2.12 raeburn 4098: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4099: </a>
4100: </div>
4101: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4102: <a href="$downlink">
1.484.2.12 raeburn 4103: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4104: </a>
4105: </div>
1.329 droeschl 4106: </td>
4107: <td>
4108: $form_start
1.484.2.30 raeburn 4109: $form_param
1.478 raeburn 4110: $form_common
1.329 droeschl 4111: $selectbox
4112: $form_end
4113: </td>
1.484.2.30 raeburn 4114: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 4115: $removelink
1.329 droeschl 4116: $cutlink
4117: $copylink
4118: </td>
4119: END
4120: }
4121: # Figure out what kind of a resource this is
4122: my ($extension)=($url=~/\.(\w+)$/);
4123: my $uploaded=($url=~/^\/*uploaded\//);
4124: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 4125: my $isfolder;
4126: my $ispage;
4127: my $containerarg;
1.484.2.67 raeburn 4128: my $folderurl;
1.484.2.93.2. 0(raebur 4129:3): my $plainurl;
1.329 droeschl 4130: if ($uploaded) {
1.472 raeburn 4131: if (($extension eq 'sequence') || ($extension eq 'page')) {
4132: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 4133: $containerarg = $1;
1.472 raeburn 4134: if ($extension eq 'sequence') {
4135: $icon=$iconpath.'navmap.folder.closed.gif';
4136: $isfolder=1;
4137: } else {
4138: $icon=$iconpath.'page.gif';
4139: $ispage=1;
4140: }
1.484.2.67 raeburn 4141: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4142: if ($allowed) {
4143: $url='/adm/coursedocs?';
4144: } else {
4145: $url='/adm/supplemental?';
4146: }
1.329 droeschl 4147: } else {
1.484.2.93.2. 0(raebur 4148:3): $plainurl = $url;
1.329 droeschl 4149: }
4150: }
1.364 bisitz 4151:
1.484.2.70 raeburn 4152: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4153: my $orig_url = $url;
1.340 raeburn 4154: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 4155: if ($container eq 'page') {
4156: $url=~s{^http(|s)(:|:)//}{/ext/};
4157: } else {
4158: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4159: }
1.484.2.12 raeburn 4160: if (!$supplementalflag && $residx && $symb) {
4161: if ((!$isfolder) && (!$ispage)) {
4162: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.484.2.87 raeburn 4163: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4164: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4165: } else {
4166: $url=&Apache::lonnet::clutter($url);
4167: }
1.484.2.12 raeburn 4168: if ($url=~/^\/*uploaded\//) {
4169: $url=~/\.(\w+)$/;
4170: my $embstyle=&Apache::loncommon::fileembstyle($1);
4171: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4172: $url='/adm/wrapper'.$url;
4173: } elsif ($embstyle eq 'ssi') {
4174: #do nothing with these
4175: } elsif ($url!~/\.(sequence|page)$/) {
4176: $url='/adm/coursedocs/showdoc'.$url;
4177: }
1.484.2.70 raeburn 4178: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4179: my $wrapped = $1;
4180: my $exturl = $2;
1.484.2.87 raeburn 4181: if (($wrapped eq '') && ($container ne 'page')) {
1.484.2.70 raeburn 4182: $url='/adm/wrapper'.$url;
4183: }
4184: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4185: $nomodal = 1;
4186: }
1.484.2.93.2. (raeburn 4187:): } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4188:): $url='/adm/wrapper'.$url;
1.484.2.70 raeburn 4189: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4190: if (($ENV{'SERVER_PORT'} == 443) &&
4191: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 4192: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4193: $url .= '?usehttp=1';
4194: }
1.484.2.70 raeburn 4195: $nomodal = 1;
4196: }
1.484.2.19 raeburn 4197: }
1.484.2.93.2. (raeburn 4198:): my ($checkencrypt,$shownurl);
4199:): if (!$env{'request.role.adv'}) {
1.484.2.67 raeburn 4200: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.484.2.93.2. (raeburn 4201:): ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.484.2.67 raeburn 4202: $checkencrypt = 1;
1.484.2.70 raeburn 4203: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 4204: unless (ref($$navmapref)) {
4205: $$navmapref = Apache::lonnavmaps::navmap->new();
4206: }
4207: if (ref($$navmapref)) {
4208: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4209: $checkencrypt = 1;
4210: }
4211: }
4212: }
1.484.2.93.2. (raeburn 4213:): }
4214:): if ($checkencrypt) {
4215:): my $currenc = $env{'request.enc'};
4216:): $env{'request.enc'} = 1;
4217:): $shownsymb = &Apache::lonenc::encrypted($symb);
4218:): $shownurl = &Apache::lonenc::encrypted($url);
4219:): if (&Apache::lonnet::symbverify($symb,$url)) {
4220:): $url = $shownurl;
1.484.2.67 raeburn 4221: } else {
1.484.2.93.2. (raeburn 4222:): $url = '';
1.484.2.67 raeburn 4223: }
1.484.2.93.2. (raeburn 4224:): $env{'request.enc'} = $currenc;
4225:): } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4226:): $shownsymb = $symb;
4227:): if ($isexternal) {
4228:): $url =~ s/\#[^#]+$//;
4229:): if ($container eq 'page') {
4230:): $url = &Apache::lonnet::clutter($url);
4231:): }
4232:): }
4233:): $shownurl = $url;
4234:): }
4235:): unless ($env{'request.role.adv'}) {
4236:): if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4237:): $url = '';
4238:): }
4239:): if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4240:): $url = '';
4241:): $hiddenres = 1;
4242:): }
4243:): }
4244:): if ($url ne '') {
4245:): $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.12 raeburn 4246: }
1.484.2.19 raeburn 4247: }
1.484.2.66 raeburn 4248: } elsif ($supplementalflag) {
4249: if ($isexternal) {
4250: if ($url =~ /^([^#]+)#([^#]+)$/) {
4251: $url = $1;
4252: $anchor = $2;
1.484.2.70 raeburn 4253: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.93 raeburn 4254: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4255: if ($hostname ne '') {
4256: $url = 'http://'.$hostname.$url;
4257: }
4258: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4259: }
1.484.2.70 raeburn 4260: $nomodal = 1;
4261: }
4262: }
4263: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4264: if (($ENV{'SERVER_PORT'} == 443) &&
4265: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 4266: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 4267: if ($hostname ne '') {
4268: $url = 'http://'.$hostname.$url;
4269: }
4270: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4271: }
1.484.2.70 raeburn 4272: $nomodal = 1;
1.484.2.66 raeburn 4273: }
1.484.2.93.2. 0(raebur 4274:3): } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
4275:3): my $embstyle=&Apache::loncommon::fileembstyle($extension);
4276:3): unless ($embstyle eq 'ssi') {
4277:3): if (($embstyle eq 'img')
4278:3): || ($embstyle eq 'emb')
4279:3): || ($embstyle eq 'wrp')) {
4280:3): $url='/adm/wrapper'.$url;
4281:3): } elsif ($url !~ /\.(sequence|page)$/) {
4282:3): $url='/adm/coursedocs/showdoc'.$url;
4283:3): }
4284:3): }
4285:3): }
4286:3): unless ($allowed && $env{'request.role.adv'}) {
4287:3): if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4288:3): $hiddenres = 1;
4289:3): }
1.484.2.66 raeburn 4290: }
1.329 droeschl 4291: }
1.484.2.67 raeburn 4292: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4293: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4294: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4295: my $foldername=&escape($foldertitle);
4296: my $folderpath=$env{'form.folderpath'};
4297: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4298: if (!$allowed && $supplementalflag) {
4299: $folderpath.=$containerarg.'&'.$foldername;
4300: $url.='folderpath='.&escape($folderpath);
1.484.2.93.2. 0(raebur 4301:3): if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4302:3): $hiddenfolder = 1;
4303:3): }
1.484.2.19 raeburn 4304: } else {
4305: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4306: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4307: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4308: 'parameter_randomorder'))[0]=~/^yes$/i);
4309: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4310: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4311: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4312: 'parameter_encrypturl'))[0]=~/^yes$/i);
4313: unless ($hiddenmap) {
1.484.2.70 raeburn 4314: if (ref($navmapref)) {
4315: unless (ref($$navmapref)) {
4316: $$navmapref = Apache::lonnavmaps::navmap->new();
4317: }
4318: if (ref($$navmapref)) {
4319: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4320: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4321: unless (@resources) {
4322: $hiddenmap = 1;
4323: unless ($env{'request.role.adv'}) {
4324: $url = '';
4325: $hiddenfolder = 1;
4326: }
1.484.2.67 raeburn 4327: }
4328: }
4329: }
4330: }
4331: }
4332: unless ($encryptmap) {
1.484.2.70 raeburn 4333: if ((ref($navmapref)) && (ref($$navmapref))) {
4334: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4335: $encryptmap = 1;
4336: }
1.484.2.67 raeburn 4337: }
4338: }
4339:
4340: # Append randompick number, hidden, and encrypted with ":" to foldername,
4341: # so it gets transferred between levels
4342: $folderpath.=$containerarg.'&'.$foldername.
4343: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4344: unless ($url eq '') {
4345: $url.='folderpath='.&escape($folderpath);
4346: }
1.484.2.19 raeburn 4347: my $rpckchk;
4348: if ($rpicknum) {
4349: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4350: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4351: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4352: }
1.484.2.19 raeburn 4353: }
1.484.2.29 raeburn 4354: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4355: $rand_pick_text =
1.478 raeburn 4356: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4357: $form_param."\n".
1.478 raeburn 4358: $form_common."\n".
1.484.2.67 raeburn 4359: '<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 4360: if ($rpicknum ne '') {
4361: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4362: }
1.484.2.29 raeburn 4363: $rand_pick_text .= '</span></span>'.
4364: $form_end;
1.484.2.30 raeburn 4365: my $ro_set;
1.484.2.67 raeburn 4366: if ($randorder) {
1.484.2.30 raeburn 4367: $ro_set = 'checked="checked"';
4368: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4369: push(@{$filtersref->{'randomorder'}},$orderidx);
4370: }
4371: }
1.484.2.41 raeburn 4372: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4373: $rand_order_text =
1.484.2.29 raeburn 4374: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4375: $form_param."\n".
1.484.2.29 raeburn 4376: $form_common."\n".
1.484.2.67 raeburn 4377: '<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 4378: $form_end;
1.484.2.19 raeburn 4379: }
1.484.2.18 raeburn 4380: } elsif ($supplementalflag && !$allowed) {
1.484.2.93.2. (raeburn 4381:): my $isexttool;
4382:): if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4383:): $url='/adm/wrapper'.$url;
4384:): $isexttool = 1;
4385:): }
1.484.2.19 raeburn 4386: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4387: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4388: if ($title) {
1.484.2.93.2. 0(raebur 4389:3): $url .= '&title='.$encodedtitle;
1.484.2.19 raeburn 4390: }
1.484.2.93.2. (raeburn 4391:): if ((($isexternal) || ($isexttool)) && $orderidx) {
1.484.2.19 raeburn 4392: $url .= '&idx='.$orderidx;
4393: }
1.484.2.66 raeburn 4394: if ($anchor ne '') {
4395: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4396: }
1.329 droeschl 4397: }
1.484.2.19 raeburn 4398: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4399: if ($allowed) {
1.484.2.19 raeburn 4400: my $fileloc =
1.484.2.12 raeburn 4401: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4402: if ($isexternal) {
4403: ($editlink,$extresform) =
1.484.2.67 raeburn 4404: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
1.484.2.93.2. (raeburn 4405:): undef,undef,undef,undef,undef,undef,
4406:): undef,$disabled);
4407:): } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4408:): ($editlink,$extresform) =
4409:): &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4410:): undef,undef,undef,'tool',$coursedom,
4411:): $coursenum,$ltitoolsref,$disabled);
1.484.2.19 raeburn 4412: } elsif (!$isfolder && !$ispage) {
4413: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4414: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4415: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4416: my $suppanchor;
4417: if ($supplementalflag) {
4418: $suppanchor = $anchor;
4419: }
1.484.2.19 raeburn 4420: my $jscall =
1.484.2.12 raeburn 4421: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4422: $switchserver,
1.484.2.14 raeburn 4423: $forceedit,
1.484.2.93.2. (raeburn 4424:): undef,$symb,$shownsymb,
1.484.2.19 raeburn 4425: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4426: $renametitle,$hostname,
4427: '','',1,$suppanchor);
1.484.2.12 raeburn 4428: if ($jscall) {
1.484.2.19 raeburn 4429: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4430: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4431: }
4432: }
4433: }
1.484.2.19 raeburn 4434: $tdalign = ' align="right" valign="top"';
4435: $tdwidth = ' width="80%"';
1.329 droeschl 4436: }
1.408 raeburn 4437: my $reinit;
4438: if ($crstype eq 'Community') {
4439: $reinit = &mt('(re-initialize community to access)');
4440: } else {
4441: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4442: }
4443: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.93.2. 0(raebur 4444:3): my ($link,$nolink);
1.472 raeburn 4445: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.484.2.93.2. 0(raebur 4446:3): if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
4447:3): if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4448:3): $nolink = 1;
4449:3): }
4450:3): }
4451:3): if ($nolink) {
4452:3): $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4453:3): } else {
4454:3): $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4455:3): }
1.469 www 4456: } elsif ($url) {
1.484.2.66 raeburn 4457: if ($anchor ne '') {
4458: if ($supplementalflag) {
4459: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4460: } else {
4461: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4462: }
4463: }
1.484.2.80 raeburn 4464: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4465: $link = 'http://'.$hostname.$url;
4466: } else {
4467: $link = $url;
4468: }
4469: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.93.2. 0(raebur 4470:3): if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
4471:3): if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4472:3): $nolink = 1;
4473:3): }
4474:3): }
4475:3): if ($nolink) {
4476:3): $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4477:3): } elsif ($nomodal) {
1.484.2.70 raeburn 4478: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4479: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4480: } else {
4481: $line.=&Apache::loncommon::modal_link($link,
4482: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4483: }
1.469 www 4484: } else {
4485: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4486: }
1.484.2.19 raeburn 4487: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4488: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.484.2.93.2. 0(raebur 4489:3): if ($nolink) {
4490:3): $line.=$title;
4491:3): } else {
4492:3): $line.='<a href="'.$url.'">'.$title.'</a>';
4493:3): }
4494:3): if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4495:3): my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4496:3): my $editurl = $url;
4497:3): $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4498:3): $line .= ' '.'<a href="'.$editurl.'">'.
4499:3): '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4500:3): '</a>';
4501:3): }
4502:3): if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4503:3): $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4504:3): }
1.469 www 4505: } elsif ($url) {
1.484.2.93.2. 0(raebur 4506:3): if ($nolink) {
4507:3): $line.=$title;
4508:3): } elsif ($nomodal) {
1.484.2.70 raeburn 4509: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4510: $title.'</a>';
4511: } else {
4512: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4513: }
1.484.2.67 raeburn 4514: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4515: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4516: } else {
4517: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4518: }
1.484.2.19 raeburn 4519: $line.="$extresform</td>";
1.478 raeburn 4520: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4521: $rand_order_text = ' ' if ($rand_order_text eq '');
1.484.2.93.2. 0(raebur 4522:3): if ($uploaded && $url && !$isfolder && !$ispage) {
4523:3): if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
4524:3): &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
1.484.2.30 raeburn 4525: }
1.484.2.93.2. 0(raebur 4526:3): }
4527:3): if ($allowed) {
4528:3): my %lt=&Apache::lonlocal::texthash(
4529:3): 'hd' => 'Hidden',
4530:3): 'ec' => 'URL hidden');
4531:3): my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.484.2.30 raeburn 4532: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4533: $hidtext = ' checked="checked"';
1.484.2.93.2. (raeburn 4534:): if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.484.2.30 raeburn 4535: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4536: }
4537: }
1.484.2.93.2. 0(raebur 4538:3): $formhidden = 'edit_hiddenresource_'.$orderidx;
4539:3): $line.=(<<ENDPARMS);
1.329 droeschl 4540: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4541: <form action="/adm/coursedocs" method="post" name="$formhidden">
4542: $form_param
1.478 raeburn 4543: $form_common
1.484.2.67 raeburn 4544: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4545: $form_end
1.484.2.93.2. 0(raebur 4546:3): ENDPARMS
4547:3): if ($folder =~/^supplemental/) {
4548:3): $line.= "\n <td>";
4549:3): } else {
4550:3): if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4551:3): $enctext = ' checked="checked"';
4552:3): if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4553:3): push(@{$filtersref->{'encrypturl'}},$orderidx);
4554:3): }
4555:3): }
4556:3): $formurlhidden = 'edit_encrypturl_'.$orderidx;
4557:3): $line.=(<<ENDPARMS);
1.458 raeburn 4558: <br />
1.484.2.29 raeburn 4559: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4560: $form_param
1.478 raeburn 4561: $form_common
1.484.2.67 raeburn 4562: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4563: $form_end
4564: </td>
1.478 raeburn 4565: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4566: $rand_order_text</td>
1.329 droeschl 4567: ENDPARMS
1.484.2.93.2. 0(raebur 4568:3): }
1.329 droeschl 4569: }
1.379 bisitz 4570: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4571: return $line;
4572: }
4573:
1.484.2.30 raeburn 4574: sub action_restrictions {
4575: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4576: my %denied = (
4577: cut => 0,
4578: copy => 0,
4579: remove => 0,
4580: );
4581: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4582: # no copy for published maps
4583: $denied{'copy'} = 1;
1.484.2.82 raeburn 4584: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4585: unless ($1 eq 'simpleproblem') {
4586: $denied{'copy'} = 1;
4587: }
4588: $denied{'cut'} = 1;
1.484.2.30 raeburn 4589: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4590: if ($folderpath =~ /^default&[^\&]+$/) {
4591: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4592: $denied{'remove'} = 1;
4593: }
4594: $denied{'cut'} = 1;
4595: $denied{'copy'} = 1;
4596: }
4597: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4598: my $group = $1;
4599: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4600: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4601: $denied{'remove'} = 1;
4602: }
4603: }
4604: $denied{'cut'} = 1;
4605: $denied{'copy'} = 1;
4606: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4607: my $group = $1;
4608: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4609: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4610: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4611: if (keys(%groupsettings) > 0) {
4612: $denied{'remove'} = 1;
4613: }
4614: $denied{'cut'} = 1;
4615: $denied{'copy'} = 1;
4616: }
4617: }
4618: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4619: my $group = $1;
4620: if ($url =~ /group_boards_\Q$group\E/) {
4621: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4622: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4623: if (keys(%groupsettings) > 0) {
4624: if (ref($groupsettings{'functions'}) eq 'HASH') {
4625: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4626: $denied{'remove'} = 1;
4627: }
4628: }
4629: }
4630: $denied{'cut'} = 1;
4631: $denied{'copy'} = 1;
4632: }
4633: }
4634: }
4635: return %denied;
4636: }
4637:
1.484.2.26 raeburn 4638: sub new_timebased_suffix {
1.484.2.30 raeburn 4639: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4640: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4641: if ($type eq 'paste') {
4642: $prefix = $type;
4643: $namespace = 'courseeditor';
1.484.2.56 raeburn 4644: $idtype = 'addcode';
1.484.2.30 raeburn 4645: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4646: $prefix = 'docs';
4647: if ($area eq 'supplemental') {
4648: $prefix = 'supp';
4649: }
4650: $prefix .= $container;
4651: $namespace = 'uploadedmaps';
4652: } else {
4653: $prefix = $type;
4654: $namespace = 'templated';
1.484.2.15 raeburn 4655: }
4656: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4657: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4658: if (!$suffix) {
1.484.2.30 raeburn 4659: if ($type eq 'paste') {
4660: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4661: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4662: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4663: } elsif ($type eq 'smppg') {
4664: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.484.2.93.2. (raeburn 4665:): } elsif ($type eq 'exttool') {
4666:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.484.2.26 raeburn 4667: } else {
1.484.2.42 raeburn 4668: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4669: }
1.484.2.15 raeburn 4670: if ($error) {
4671: $errtext .= '<br />'.$error;
4672: }
4673: }
4674: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4675: $locknotfreed =
4676: '<div class="LC_error">'.
4677: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4678: if ($type eq 'paste') {
1.484.2.57 raeburn 4679: if ($freedlock eq 'nolock') {
4680: $locknotfreed =
4681: '<div class="LC_error">'.
4682: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4683:
1.484.2.60 raeburn 4684: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4685: } else {
4686: $locknotfreed .=
4687: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4688: }
1.484.2.30 raeburn 4689: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4690: $locknotfreed .=
4691: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4692: } elsif ($type eq 'smppg') {
4693: $locknotfreed .=
4694: &mt('This will prevent creation of additional simple pages in this course.');
1.484.2.93.2. (raeburn 4695:): } elsif ($type eq 'exttool') {
4696:): $locknotfreed .=
4697:): &mt('This will prevent creation of additional external tools in this course.');
1.484.2.26 raeburn 4698: } else {
4699: $locknotfreed .=
1.484.2.42 raeburn 4700: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4701: }
1.484.2.30 raeburn 4702: unless ($type eq 'paste') {
4703: $locknotfreed .=
1.484.2.38 raeburn 4704: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4705: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4706: }
4707: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4708: }
4709: return ($suffix,$errtext,$locknotfreed);
4710: }
4711:
1.329 droeschl 4712: =pod
4713:
4714: =item tiehash()
4715:
4716: tie the hash
4717:
4718: =cut
4719:
4720: sub tiehash {
4721: my ($mode)=@_;
4722: $hashtied=0;
4723: if ($env{'request.course.fn'}) {
4724: if ($mode eq 'write') {
4725: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4726: &GDBM_WRCREAT(),0640)) {
4727: $hashtied=2;
4728: }
4729: } else {
4730: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4731: &GDBM_READER(),0640)) {
4732: $hashtied=1;
4733: }
4734: }
1.364 bisitz 4735: }
1.329 droeschl 4736: }
4737:
4738: sub untiehash {
4739: if ($hashtied) { untie %hash; }
4740: $hashtied=0;
4741: return OK;
4742: }
4743:
4744:
4745:
4746:
4747: sub checkonthis {
1.484.2.78 raeburn 4748: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4749: $url=&unescape($url);
4750: $alreadyseen{$url}=1;
4751: $r->rflush();
4752: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4753: $r->print("\n<br />");
4754: if ($level==0) {
4755: $r->print("<br />");
4756: }
4757: for (my $i=0;$i<=$level*5;$i++) {
4758: $r->print(' ');
4759: }
4760: $r->print('<a href="'.$url.'" target="cat">'.
4761: ($title?$title:$url).'</a> ');
4762: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4763: my $updated;
4764: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4765: ($url !~ /\.\d+\.\w+$/)) {
4766: $updated = &Apache::lonnet::remove_stale_resfile($url);
4767: }
1.329 droeschl 4768: my $result=&Apache::lonnet::repcopy(
4769: &Apache::lonnet::filelocation('',$url));
4770: if ($result eq 'ok') {
4771: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4772: if ($updated) {
4773: $r->print('<br />');
4774: for (my $i=0;$i<=$level*5;$i++) {
4775: $r->print(' ');
4776: }
4777: $r->print('- '.&mt('Outdated copy removed'));
4778: }
1.329 droeschl 4779: $r->rflush();
4780: &Apache::lonnet::countacc($url);
4781: $url=~/\.(\w+)$/;
4782: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4783: $r->print('<br />');
4784: $r->rflush();
4785: for (my $i=0;$i<=$level*5;$i++) {
4786: $r->print(' ');
4787: }
4788: $r->print('- '.&mt('Rendering:').' ');
4789: my ($errorcount,$warningcount)=split(/:/,
4790: &Apache::lonnet::ssi_body($url,
4791: ('grade_target'=>'web',
4792: 'return_only_error_and_warning_counts' => 1)));
4793: if (($errorcount) ||
4794: ($warningcount)) {
4795: if ($errorcount) {
1.369 bisitz 4796: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4797: &mt('[quant,_1,error]',$errorcount).'</span>');
4798: }
4799: if ($warningcount) {
4800: $r->print('<span class="LC_warning">'.
4801: &mt('[quant,_1,warning]',$warningcount).'</span>');
4802: }
4803: } else {
4804: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4805: }
4806: $r->rflush();
4807: }
4808: my $dependencies=
4809: &Apache::lonnet::metadata($url,'dependencies');
4810: foreach my $dep (split(/\,/,$dependencies)) {
4811: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4812: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4813: }
4814: }
4815: } elsif ($result eq 'unavailable') {
4816: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4817: } elsif ($result eq 'not_found') {
4818: unless ($url=~/\$/) {
1.484.2.19 raeburn 4819: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4820: } else {
1.366 bisitz 4821: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4822: }
4823: } else {
4824: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4825: }
1.484.2.78 raeburn 4826: if (($updated) && ($result ne 'ok')) {
4827: $r->print('<br />'.&mt('Outdated copy removed'));
4828: }
1.329 droeschl 4829: }
4830: }
4831: }
4832:
4833:
4834:
4835: =pod
4836:
4837: =item list_symbs()
4838:
1.484.2.3 raeburn 4839: List Content Identifiers
1.329 droeschl 4840:
4841: =cut
4842:
4843: sub list_symbs {
4844: my ($r) = @_;
4845:
1.408 raeburn 4846: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4847: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4848: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4849: $r->print(&startContentScreen('tools'));
1.329 droeschl 4850: my $navmap = Apache::lonnavmaps::navmap->new();
4851: if (!defined($navmap)) {
4852: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4853: '<div class="LC_error">'.
4854: &mt('Unable to retrieve information about course contents').
4855: '</div>');
1.408 raeburn 4856: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4857: } else {
1.484 raeburn 4858: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4859: &Apache::loncommon::start_data_table().
4860: &Apache::loncommon::start_data_table_header_row().
4861: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4862: &Apache::loncommon::end_data_table_header_row()."\n");
4863: my $count;
1.329 droeschl 4864: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4865: $r->print(&Apache::loncommon::start_data_table_row().
4866: '<td>'.$res->compTitle().'</td>'.
4867: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4868: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4869: $count ++;
4870: }
4871: if (!$count) {
4872: $r->print(&Apache::loncommon::start_data_table_row().
4873: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4874: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4875: }
1.484 raeburn 4876: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4877: }
1.484.2.19 raeburn 4878: $r->print(&endContentScreen());
1.329 droeschl 4879: }
4880:
1.484.2.93.2. (raeburn 4881:): sub short_urls {
4882:): my ($r,$canedit) = @_;
4883:): my $crstype = &Apache::loncommon::course_type();
4884:): my $formname = 'shortenurl';
4885:): $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4886:): $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4887:): $r->print(&startContentScreen('tools'));
4888:): my ($navmap,$errormsg) =
4889:): &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4890:): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4891:): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4892:): my (%maps,%resources,%titles);
4893:): if (!ref($navmap)) {
4894:): $r->print($errormsg.
4895:): &endContentScreen());
4896:): return '';
4897:): } else {
4898:): $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
4899:): $r->rflush();
4900:): my $readonly;
4901:): if ($canedit) {
4902:): my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
4903:): if ($numnew) {
4904:): $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4905:): }
4906:): if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4907:): $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4908:): foreach my $error (@{$errors}) {
4909:): $r->print('<li>'.$error.'</li>');
4910:): }
4911:): $r->print('</ul><br />');
4912:): }
4913:): } else {
4914:): $readonly = 1;
4915:): }
4916:): my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4917:): $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4918:): undef,undef,undef,undef,undef,\%currtiny,$readonly));
4919:): }
4920:): $r->print(&endContentScreen());
4921:): }
4922:):
1.484.2.78 raeburn 4923: sub contentverifyform {
4924: my ($r) = @_;
4925: my $crstype = &Apache::loncommon::course_type();
4926: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4927: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4928: $r->print(&startContentScreen('tools'));
4929: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4930: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4931: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4932: ' <span class="LC_nobreak">'.
4933: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4934: &mt('No').'</label>'.(' 'x2).
4935: '<label><input type="radio" name="checkstale" value="1" />'.
4936: &mt('Yes').'</label></span></p><p>'.
1.484.2.90 raeburn 4937: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.484.2.78 raeburn 4938: '<input type="hidden" value="1" name="tools" />'.
4939: '<input type="hidden" value="1" name="verify" /></p></form>');
4940: $r->print(&endContentScreen());
4941: return;
4942: }
1.329 droeschl 4943:
4944: sub verifycontent {
1.484.2.78 raeburn 4945: my ($r,$checkstale) = @_;
1.408 raeburn 4946: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4947: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4948: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4949: $r->print(&startContentScreen('tools'));
4950: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4951: $hashtied=0;
4952: undef %alreadyseen;
4953: %alreadyseen=();
4954: &tiehash();
1.484 raeburn 4955:
1.329 droeschl 4956: foreach my $key (keys(%hash)) {
4957: if ($hash{$key}=~/\.(page|sequence)$/) {
4958: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4959: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4960: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4961: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4962: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4963: }
4964: }
4965: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4966: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4967: }
4968: }
4969: &untiehash();
1.442 www 4970: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4971: $r->print(&endContentScreen());
1.329 droeschl 4972: }
4973:
4974:
4975: sub devalidateversioncache {
4976: my $src=shift;
4977: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4978: &Apache::lonnet::clutter($src));
4979: }
4980:
4981: sub checkversions {
1.484.2.67 raeburn 4982: my ($r,$canedit) = @_;
1.408 raeburn 4983: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4984: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4985: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4986: $r->print(&startContentScreen('tools'));
1.442 www 4987:
1.329 droeschl 4988: my $header='';
4989: my $startsel='';
4990: my $monthsel='';
4991: my $weeksel='';
4992: my $daysel='';
4993: my $allsel='';
4994: my %changes=();
4995: my $starttime=0;
4996: my $haschanged=0;
4997: my %setversions=&Apache::lonnet::dump('resourceversions',
4998: $env{'course.'.$env{'request.course.id'}.'.domain'},
4999: $env{'course.'.$env{'request.course.id'}.'.num'});
5000:
5001: $hashtied=0;
5002: &tiehash();
1.484.2.67 raeburn 5003: if ($canedit) {
5004: my %newsetversions=();
5005: if ($env{'form.setmostrecent'}) {
5006: $haschanged=1;
5007: foreach my $key (keys(%hash)) {
5008: if ($key=~/^ids\_(\/res\/.+)$/) {
5009: $newsetversions{$1}='mostrecent';
5010: &devalidateversioncache($1);
5011: }
1.329 droeschl 5012: }
1.484.2.67 raeburn 5013: } elsif ($env{'form.setcurrent'}) {
5014: $haschanged=1;
5015: foreach my $key (keys(%hash)) {
5016: if ($key=~/^ids\_(\/res\/.+)$/) {
5017: my $getvers=&Apache::lonnet::getversion($1);
5018: if ($getvers>0) {
5019: $newsetversions{$1}=$getvers;
5020: &devalidateversioncache($1);
5021: }
5022: }
1.329 droeschl 5023: }
1.484.2.67 raeburn 5024: } elsif ($env{'form.setversions'}) {
5025: $haschanged=1;
5026: foreach my $key (keys(%env)) {
5027: if ($key=~/^form\.set_version_(.+)$/) {
5028: my $src=$1;
5029: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5030: $newsetversions{$src}=$env{$key};
5031: &devalidateversioncache($src);
5032: }
5033: }
1.329 droeschl 5034: }
1.484.2.67 raeburn 5035: }
5036: if ($haschanged) {
5037: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5038: $env{'course.'.$env{'request.course.id'}.'.domain'},
5039: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5040: $r->print(&Apache::loncommon::confirmwrapper(
5041: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5042: } else {
5043: $r->print(&Apache::loncommon::confirmwrapper(
5044: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
5045: }
5046: &mark_hash_old();
5047: }
5048: &changewarning($r,'');
1.329 droeschl 5049: }
5050: if ($env{'form.timerange'} eq 'all') {
5051: # show all documents
1.484.2.34 raeburn 5052: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 5053: $allsel=' selected="selected"';
1.329 droeschl 5054: foreach my $key (keys(%hash)) {
5055: if ($key=~/^ids\_(\/res\/.+)$/) {
5056: my $src=$1;
5057: $changes{$src}=1;
5058: }
5059: }
5060: } else {
5061: # show documents which changed
5062: %changes=&Apache::lonnet::dump
5063: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5064: $env{'course.'.$env{'request.course.id'}.'.num'});
5065: my $firstkey=(keys(%changes))[0];
5066: unless ($firstkey=~/^error\:/) {
5067: unless ($env{'form.timerange'}) {
5068: $env{'form.timerange'}=604800;
5069: }
5070: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5071: .&mt('seconds');
5072: if ($env{'form.timerange'}==-1) {
5073: $seltext='since start of course';
1.484.2.19 raeburn 5074: $startsel=' selected="selected"';
1.329 droeschl 5075: $env{'form.timerange'}=time;
5076: }
5077: $starttime=time-$env{'form.timerange'};
5078: if ($env{'form.timerange'}==2592000) {
5079: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 5080: $monthsel=' selected="selected"';
1.329 droeschl 5081: } elsif ($env{'form.timerange'}==604800) {
5082: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 5083: $weeksel=' selected="selected"';
1.329 droeschl 5084: } elsif ($env{'form.timerange'}==86400) {
5085: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 5086: $daysel=' selected="selected"';
1.329 droeschl 5087: }
5088: $header=&mt('Content changed').' '.$seltext;
5089: } else {
5090: $header=&mt('No content modifications yet.');
5091: }
5092: }
5093: %setversions=&Apache::lonnet::dump('resourceversions',
5094: $env{'course.'.$env{'request.course.id'}.'.domain'},
5095: $env{'course.'.$env{'request.course.id'}.'.num'});
5096: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5097: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5098: 'lm' => 'Version changes since last Month',
5099: 'lw' => 'Version changes since last Week',
5100: 'sy' => 'Version changes since Yesterday',
5101: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5102: 'cd' => 'Change display',
1.329 droeschl 5103: 'sd' => 'Display',
5104: 'fi' => 'File',
5105: 'md' => 'Modification Date',
5106: 'mr' => 'Most recently published Version',
1.408 raeburn 5107: 've' => 'Version used in '.$crstype,
5108: 'vu' => 'Set Version to be used in '.$crstype,
5109: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5110: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5111: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5112: 'di' => 'Differences',
1.484 raeburn 5113: 'save' => 'Save changes',
5114: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5115: 'act' => 'Actions');
1.484.2.67 raeburn 5116: my ($disabled,$readonly);
5117: unless ($canedit) {
5118: $disabled = 'disabled="disabled"';
5119: $readonly = 1;
5120: }
1.329 droeschl 5121: $r->print(<<ENDHEADERS);
1.484 raeburn 5122: <h4 class="LC_info">$header</h4>
1.329 droeschl 5123: <form action="/adm/coursedocs" method="post">
5124: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5125: <div class="LC_left_float">
1.479 golterma 5126: <fieldset>
1.484 raeburn 5127: <legend>$lt{'cd'}</legend>
1.329 droeschl 5128: <select name="timerange">
1.484.2.19 raeburn 5129: <option value='all'$allsel>$lt{'al'}</option>
5130: <option value="-1"$startsel>$lt{'st'}</option>
5131: <option value="2592000"$monthsel>$lt{'lm'}</option>
5132: <option value="604800"$weeksel>$lt{'lw'}</option>
5133: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5134: </select>
5135: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5136: </fieldset>
5137: </div>
5138: <div class="LC_left_float">
5139: <fieldset>
5140: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 5141: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5142: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5143: </fieldset>
5144: </div>
5145: <br clear="all" />
5146: <hr />
5147: <h4>$lt{'vers'}</h4>
1.329 droeschl 5148: ENDHEADERS
1.479 golterma 5149: #number of columns for version history
1.484.2.44 raeburn 5150: my %changedbytime;
5151: foreach my $key (keys(%changes)) {
5152: #excludes not versionable problems from resource version history:
5153: next if ($key =~ /^\/res\/lib\/templates/);
5154: my $chg;
5155: if ($env{'form.timerange'} eq 'all') {
5156: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5157: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5158: } else {
5159: $chg = $changes{$key};
5160: next if ($chg < $starttime);
5161: }
5162: push(@{$changedbytime{$chg}},$key);
5163: }
5164: if (keys(%changedbytime) == 0) {
5165: &untiehash();
5166: $r->print(&mt('No content changes in imported content in specified time frame').
5167: &endContentScreen());
5168: return;
5169: }
1.479 golterma 5170: $r->print(
1.484.2.67 raeburn 5171: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5172: &Apache::loncommon::start_data_table().
5173: &Apache::loncommon::start_data_table_header_row().
5174: '<th>'.&mt('Resources').'</th>'.
5175: "<th>$lt{'mr'}</th>".
5176: "<th>$lt{'ve'}</th>".
5177: "<th>$lt{'vu'}</th>".
5178: '<th>'.&mt('History').'</th>'.
5179: &Apache::loncommon::end_data_table_header_row()
5180: );
1.484.2.44 raeburn 5181: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5182: foreach my $key (sort(@{$changedbytime{$chg}})) {
5183: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5184: my $currentversion=&Apache::lonnet::getversion($key);
5185: if ($currentversion<0) {
5186: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5187: }
5188: my $linkurl=&Apache::lonnet::clutter($key);
5189: $r->print(
5190: &Apache::loncommon::start_data_table_row().
5191: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5192: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5193: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5194: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5195: '<td align="right">'
5196: );
5197: # Used in course
5198: my $usedversion=$hash{'version_'.$linkurl};
5199: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 5200: if ($usedversion != $currentversion) {
1.479 golterma 5201: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 5202: } else {
1.479 golterma 5203: $r->print($usedversion);
5204: }
1.329 droeschl 5205: } else {
1.484.2.19 raeburn 5206: $r->print($currentversion);
1.329 droeschl 5207: }
1.484.2.44 raeburn 5208: $r->print('</td><td title="'.$lt{'vu'}.'">');
5209: # Set version
5210: $r->print(&Apache::loncommon::select_form(
5211: $setversions{$linkurl},
5212: 'set_version_'.$linkurl,
5213: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5214: '' => '',
5215: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 5216: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 5217: my $lastold=1;
5218: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5219: my $url=$root.'.'.$prevvers.'.'.$extension;
5220: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5221: $lastold=$prevvers;
5222: }
5223: }
5224: $r->print('</td>');
5225: # List all available versions
5226: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5227: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5228: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 5229: $r->print(
1.484.2.44 raeburn 5230: '<span class="LC_nobreak">'
5231: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5232: .&mt('Version [_1]',$prevvers).'</a>'
5233: .' ('.&Apache::lonlocal::locallocaltime(
5234: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5235: .')');
5236: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5237: $r->print(
5238: ' <a href="/adm/diff?filename='.
5239: &Apache::lonnet::clutter($root.'.'.$extension).
5240: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5241: '" target="diffs">'.&mt('Diffs').'</a>');
5242: }
5243: $r->print('</span><br />');
1.329 droeschl 5244: }
1.484.2.44 raeburn 5245: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 5246: }
1.329 droeschl 5247: }
1.484.2.19 raeburn 5248: $r->print(
5249: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 5250: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5251: '</form>'
5252: );
1.329 droeschl 5253:
5254: &untiehash();
1.484.2.19 raeburn 5255: $r->print(&endContentScreen());
1.484.2.44 raeburn 5256: return;
1.329 droeschl 5257: }
5258:
5259: sub mark_hash_old {
5260: my $retie_hash=0;
5261: if ($hashtied) {
5262: $retie_hash=1;
5263: &untiehash();
5264: }
5265: &tiehash('write');
5266: $hash{'old'}=1;
5267: &untiehash();
5268: if ($retie_hash) { &tiehash(); }
5269: }
5270:
5271: sub is_hash_old {
5272: my $untie_hash=0;
5273: if (!$hashtied) {
5274: $untie_hash=1;
5275: &tiehash();
5276: }
5277: my $return=$hash{'old'};
5278: if ($untie_hash) { &untiehash(); }
5279: return $return;
5280: }
5281:
5282: sub changewarning {
5283: my ($r,$postexec,$message,$url)=@_;
5284: if (!&is_hash_old()) { return; }
5285: my $pathvar='folderpath';
5286: my $path=&escape($env{'form.folderpath'});
5287: if (!defined($url)) {
5288: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5289: }
5290: my $course_type = &Apache::loncommon::course_type();
5291: if (!defined($message)) {
5292: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5293: }
5294: $r->print("\n\n".
1.372 bisitz 5295: '<script type="text/javascript">'."\n".
5296: '// <![CDATA['."\n".
5297: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5298: '// ]]>'."\n".
1.369 bisitz 5299: '</script>'."\n".
1.375 tempelho 5300: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5301: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5302: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5303: &mt($message,' <input type="hidden" name="'.
5304: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5305: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5306: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5307: }
5308:
5309:
5310: sub init_breadcrumbs {
1.484.2.44 raeburn 5311: my ($form,$text,$help)=@_;
1.329 droeschl 5312: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5313: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5314: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5315: faq=>273,
5316: bug=>'Instructor Interface',
1.484.2.44 raeburn 5317: help => $help});
1.329 droeschl 5318: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5319: text=>$text,
5320: faq=>273,
5321: bug=>'Instructor Interface'});
5322: }
5323:
1.441 www 5324: # subroutine to list form elements
5325: sub create_list_elements {
5326: my @formarr = @_;
5327: my $list = '';
1.484.2.12 raeburn 5328: foreach my $button (@formarr){
5329: foreach my $picture (keys(%{$button})) {
5330: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5331: }
5332: }
5333: return $list;
5334: }
1.329 droeschl 5335:
1.441 www 5336: # subroutine to create ul from list elements
5337: sub create_form_ul {
5338: my $list = shift;
5339: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5340: return $ul;
5341: }
1.329 droeschl 5342:
1.442 www 5343: #
5344: # Start tabs
5345: #
5346:
5347: sub startContentScreen {
1.484 raeburn 5348: my ($mode) = @_;
5349: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5350: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5351: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5352: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5353: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5354: } else {
1.484.2.34 raeburn 5355: $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 5356: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5357: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5358: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5359: }
5360: $output .= "\n".'</ul>'."\n";
5361: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5362: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5363: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5364: return $output;
1.442 www 5365: }
5366:
5367: #
5368: # End tabs
5369: #
5370:
5371: sub endContentScreen {
1.484 raeburn 5372: return '</div></div></div>';
1.442 www 5373: }
1.329 droeschl 5374:
1.446 www 5375: sub supplemental_base {
1.484.2.33 raeburn 5376: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5377: }
5378:
1.329 droeschl 5379: sub handler {
5380: my $r = shift;
5381: &Apache::loncommon::content_type($r,'text/html');
5382: $r->send_http_header;
5383: return OK if $r->header_only;
1.484 raeburn 5384:
5385: # get course data
1.408 raeburn 5386: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5387: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5388: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5389:
5390: # graphics settings
5391: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5392:
1.443 www 5393: #
1.329 droeschl 5394: # --------------------------------------------- Initialize help topics for this
5395: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.484.2.93.2. (raeburn 5396:): 'Adding_External_Resource','Adding_External_Tool',
5397:): 'Navigate_Content','Adding_Folders','Docs_Overview',
5398:): 'Load_Map','Supplemental','Score_Upload_Form',
5399:): 'Adding_Pages','Importing_LON-CAPA_Resource',
5400:): 'Importing_IMS_Course','Uploading_From_Harddrive',
5401:): 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5402: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5403: }
5404: # Composite help files
5405: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5406: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5407: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5408: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5409: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5410: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5411: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5412: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5413: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5414: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5415:
1.484.2.67 raeburn 5416: my ($allowed,$canedit,$canview,$disabled);
1.484.2.93.2. 0(raebur 5417:3): # does this user have privileges to modify content.
5418:3): if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 5419: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.484.2.93.2. 0(raebur 5420:3): unless ($r->uri eq '/adm/supplemental') {
1.484.2.67 raeburn 5421: $allowed = 1;
1.484.2.93.2. 0(raebur 5422:3): }
5423:3): $canedit = 1;
5424:3): $canview = 1;
5425:3): } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5426:3): # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5427:3): unless ($r->uri eq '/adm/supplemental') {
1.484.2.67 raeburn 5428: $allowed = 1;
5429: }
1.484.2.93.2. 0(raebur 5430:3): $canview = 1;
1.484.2.67 raeburn 5431: }
5432: unless ($canedit) {
5433: $disabled = ' disabled="disabled"';
1.472 raeburn 5434: }
1.484.2.53 raeburn 5435: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5436: if ($env{'form.inhibitmenu'}) {
5437: unless ($env{'form.inhibitmenu'} eq 'yes') {
5438: delete($env{'form.inhibitmenu'});
5439: }
5440: }
5441:
1.484.2.53 raeburn 5442: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5443: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5444: if (!$canedit) {
5445: &verifycontent($r);
5446: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5447: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5448: text=>'Results',
5449: faq=>273,
5450: bug=>'Instructor Interface'});
5451: &verifycontent($r,$env{'form.checkstale'});
5452: } else {
5453: &contentverifyform($r);
5454: }
1.329 droeschl 5455: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5456: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5457: &list_symbs($r);
1.484.2.93.2. (raeburn 5458:): } elsif ($allowed && $env{'form.shorturls'}) {
5459:): &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5460:): &short_urls($r,$canedit);
1.329 droeschl 5461: } elsif ($allowed && $env{'form.docslog'}) {
5462: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5463: my $folder = $env{'form.folder'};
5464: if ($folder eq '') {
5465: $folder='default';
5466: }
1.484.2.67 raeburn 5467: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5468: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5469: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5470: &checkversions($r,$canedit);
5471: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5472: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5473: &dumpcourse($r);
5474: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5475: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5476: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5477: } else {
1.445 www 5478: #
5479: # Done catching special calls
1.484 raeburn 5480: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5481: # Get the parameters that may be needed
5482: #
5483: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.93.2. 0(raebur 5484:3): ['folderpath','title',
1.484.2.19 raeburn 5485: 'forcesupplement','forcestandard',
5486: 'tools','symb','command','supppath']);
1.445 www 5487:
1.484.2.78 raeburn 5488: foreach my $item ('forcesupplement','forcestandard','tools') {
5489: next if ($env{'form.'.$item} eq '');
5490: unless ($env{'form.'.$item} eq '1') {
5491: delete($env{'form.'.$item});
5492: }
5493: }
5494:
5495: if ($env{'form.command'}) {
5496: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5497: delete($env{'form.command'});
5498: }
5499: }
5500:
5501: if ($env{'form.symb'}) {
5502: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5503: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5504: delete($env{'form.symb'});
5505: }
5506: }
5507:
1.445 www 5508: # standard=1: this is a "new-style" course with an uploaded map as top level
5509: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5510:
5511: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5512:
1.484 raeburn 5513: # Decide whether this should display supplemental or main content or utilities
1.445 www 5514: # supplementalflag=1: show supplemental documents
5515: # supplementalflag=0: show standard documents
1.484 raeburn 5516: # toolsflag=1: show utilities
1.445 www 5517:
1.484.2.39 raeburn 5518: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5519: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5520: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5521: $supplementalflag=0;
5522: }
5523: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5524: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5525: unless ($allowed) { $supplementalflag=1; }
5526: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5527: my $toolsflag=0;
5528: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5529:
1.484.2.78 raeburn 5530: if ($env{'form.folderpath'} ne '') {
1.484.2.93.2. 0(raebur 5531:3): &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.484.2.78 raeburn 5532: }
5533:
1.484.2.93.2. 0(raebur 5534:3): my $backto_supppath;
1.484.2.78 raeburn 5535: if ($env{'form.supppath'} ne '') {
1.484.2.93.2. 0(raebur 5536:3): if ($supplementalflag && $allowed) {
5537:3): $backto_supppath = &validate_supppath($coursenum,$coursedom);
5538:3): }
1.484.2.78 raeburn 5539: }
5540:
1.329 droeschl 5541: my $script='';
5542: my $showdoc=0;
1.457 raeburn 5543: my $addentries = {};
1.475 raeburn 5544: my $container;
1.329 droeschl 5545: my $containertag;
1.484.2.17 raeburn 5546: my $pathitem;
1.484.2.93.2. (raeburn 5547:): my %ltitools;
1.484.2.67 raeburn 5548: my $hiddentop;
5549: my $navmap;
5550: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5551:
1.464 www 5552: # Do we directly jump somewhere?
1.484.2.21 raeburn 5553: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5554: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5555: $env{'form.folderpath'}=
1.484.2.67 raeburn 5556: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5557: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5558: $env{'form.command'}.'_'.$env{'form.symb'}});
1.484.2.93.2. 0(raebur 5559:3): } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 5560: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5561: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.484.2.93.2. 0(raebur 5562:3): $env{'form.command'}.'_'.$backto_supppath});
1.466 www 5563: }
1.472 raeburn 5564: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5565: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5566: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5567: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5568: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5569: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5570: } elsif ($env{'form.command'} eq 'contents') {
5571: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5572: } elsif ($env{'form.command'} eq 'home') {
5573: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5574: }
5575:
1.484.2.23 raeburn 5576:
1.445 www 5577: # Where do we store these for when we come back?
5578: my $stored_folderpath='docs_folderpath';
5579: if ($supplementalflag) {
5580: $stored_folderpath='docs_sup_folderpath';
5581: }
1.464 www 5582:
1.484.2.19 raeburn 5583: # No folderpath, and in edit mode, see if we have something stored
5584: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5585: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5586: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5587:
5588: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5589: if ($supplementalflag) {
5590: undef($env{'form.folderpath'}) if ($1 eq 'default');
5591: } else {
5592: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5593: }
5594: } else {
1.484.2.19 raeburn 5595: undef($env{'form.folderpath'});
5596: }
1.484.2.92 raeburn 5597: if ($env{'form.folderpath'} ne '') {
1.484.2.93.2. 0(raebur 5598:3): &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.484.2.92 raeburn 5599: }
1.329 droeschl 5600: }
1.446 www 5601:
5602: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5603: if (!$allowed) {
1.446 www 5604: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5605: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5606: }
5607: }
1.446 www 5608: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5609: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5610: $env{'form.folderpath'} = &supplemental_base()
5611: .'&'.
1.329 droeschl 5612: $env{'form.folderpath'};
5613: }
1.484.2.67 raeburn 5614: # If allowed and user's role is not advanced check folderpath is not hidden
1.484.2.93.2. 0(raebur 5615:3): my $hidden_and_empty;
5616:3): if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
5617:3): my ($folderurl,$foldername,$hiddenfolder);
1.484.2.67 raeburn 5618: my @pathitems = split(/\&/,$env{'form.folderpath'});
5619: my $folder = $pathitems[-2];
5620: if ($folder eq '') {
5621: undef($env{'form.folderpath'});
5622: } else {
5623: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.87 raeburn 5624: if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 5625: $folderurl .= '.page';
5626: } else {
5627: $folderurl .= '.sequence';
5628: }
1.484.2.93.2. 0(raebur 5629:3): if ($supplementalflag) {
5630:3): ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
5631:3): $foldername = &HTML::Entities::decode(&unescape($foldername));
5632:3): my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
5633:3): if (ref($supplemental) eq 'HASH') {
5634:3): my ($suppmap,$suppmapnum);
5635:3): if ($folder eq 'supplemental') {
5636:3): $suppmap = 'default';
5637:3): $suppmapnum = 0;
5638:3): } elsif ($folder =~ /^supplemental_(\d+)$/) {
5639:3): $suppmap = $1;
5640:3): $suppmapnum = $suppmap;
5641:3): }
5642:3): if ($hiddenfolder) {
5643:3): my $hascontent;
5644:3): foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
5645:3): if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
5646:3): $hascontent = 1;
5647:3): } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
5648:3): foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
5649:3): if ($id =~ /^$suppmapnum\:/) {
5650:3): $hascontent = 1;
5651:3): last;
5652:3): }
5653:3): }
5654:3): }
5655:3): last if ($hascontent);
5656:3): }
5657:3): unless ($hascontent) {
5658:3): if ($foldername ne '') {
5659:3): $hidden_and_empty = $foldername;
5660:3): } else {
5661:3): $hidden_and_empty = $folder;
5662:3): }
5663:3): }
1.484.2.67 raeburn 5664: }
5665: }
1.484.2.93.2. 0(raebur 5666:3): } else {
5667:3): unless (ref($navmap)) {
5668:3): $navmap = Apache::lonnavmaps::navmap->new();
5669:3): }
5670:3): ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
5671:3): $foldername = &HTML::Entities::decode(&unescape($foldername));
5672:3): if (ref($navmap)) {
5673:3): if ($hiddenfolder ||
5674:3): (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
5675:3): my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5676:3): unless (@resources) {
5677:3): if ($foldername ne '') {
5678:3): $hidden_and_empty = $foldername;
5679:3): } else {
5680:3): $hidden_and_empty = $folder;
5681:3): }
5682:3): }
5683:3): }
5684:3): }
5685:3): }
5686:3): if ($hidden_and_empty ne '') {
5687:3): splice(@pathitems,-2);
5688:3): if (@pathitems) {
5689:3): $env{'form.folderpath'} = join('&',@pathitems);
5690:3): } else {
5691:3): undef($env{'form.folderpath'});
5692:3): }
1.484.2.67 raeburn 5693: }
5694: }
5695: }
5696:
1.446 www 5697: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5698: unless ($env{'form.folderpath'}) {
1.446 www 5699: if ($supplementalflag) {
5700: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5701: } elsif ($allowed) {
5702: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5703: }
1.472 raeburn 5704: }
1.446 www 5705:
1.445 www 5706: # Store this
1.484 raeburn 5707: unless ($toolsflag) {
1.484.2.67 raeburn 5708: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5709: &Apache::loncommon::store_course_settings($stored_folderpath,
5710: {'folderpath' => 'scalar'});
5711: }
5712: my $folderpath;
1.484 raeburn 5713: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5714: $folderpath = $env{'form.folderpath'};
5715: my (@folders)=split('&',$env{'form.folderpath'});
5716: $env{'form.foldername'}=&unescape(pop(@folders));
5717: if ($env{'form.foldername'} =~ /\:1$/) {
5718: $container = 'page';
5719: } else {
5720: $container = 'sequence';
5721: }
5722: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5723: } else {
1.484.2.19 raeburn 5724: if ($env{'form.folder'} eq '' ||
5725: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5726: if ($env{'form.folder'} eq 'supplemental') {
5727: $folderpath=&supplemental_base();
5728: } elsif (!$hiddentop) {
5729: $folderpath='default&'.
5730: &escape(&mt('Main Content').':::::');
5731: }
1.484 raeburn 5732: }
5733: }
1.484.2.19 raeburn 5734: $containertag = '<input type="hidden" name="folderpath" value="" />';
5735: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5736: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5737: $showdoc='/'.$1;
5738: }
5739: if ($showdoc) { # got called in sequence from course
5740: $allowed=0;
5741: } else {
1.484.2.67 raeburn 5742: if ($canedit) {
1.484 raeburn 5743: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5744: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5745: }
5746: }
1.329 droeschl 5747: }
5748:
1.344 bisitz 5749: # get personal data
1.329 droeschl 5750: my $uname=$env{'user.name'};
5751: my $udom=$env{'user.domain'};
5752: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5753:
5754: if ($allowed) {
1.484 raeburn 5755: if ($toolsflag) {
5756: $script .= &inject_data_js();
5757: my ($home,$other,%outhash)=&authorhosts();
5758: if (!$home && $other) {
5759: my @hosts;
5760: foreach my $aurole (keys(%outhash)) {
5761: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5762: push(@hosts,$outhash{$aurole});
5763: }
5764: }
5765: $script .= &dump_switchserver_js(@hosts);
5766: }
1.458 raeburn 5767: } else {
1.484.2.43 raeburn 5768: my $tid = 1;
1.484 raeburn 5769: my @tabids;
5770: if ($supplementalflag) {
5771: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5772: $tid = 2;
1.484 raeburn 5773: } else {
5774: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5775: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5776: unshift(@tabids,'001');
5777: push(@tabids,('dd1','ee1'));
5778: }
1.458 raeburn 5779: }
1.484 raeburn 5780: my $tabidstr = join("','",@tabids);
1.484.2.93.2. (raeburn 5781:): %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
5782:): my $posslti = keys(%ltitools);
1.484.2.80 raeburn 5783: my $hostname = $r->hostname();
1.484.2.93.2. (raeburn 5784:): $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 5785: $canedit,$hostname,\$navmap).
1.484 raeburn 5786: &history_tab_js().
5787: &inject_data_js().
1.484.2.43 raeburn 5788: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.93.2. (raeburn 5789:): &Apache::lonextresedit::extedit_javascript(\%ltitools);
0(raebur 5790:3): my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
5791:3): if ($hidden_and_empty ne '') {
5792:3): my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
5793:3): $hidden_and_empty);
5794:3): $onload .= "javascript:alert('".&js_escape($alert)."');";
5795:3): }
1.484 raeburn 5796: $addentries = {
1.484.2.93.2. 0(raebur 5797:3): onload => $onload,
1.484 raeburn 5798: };
1.458 raeburn 5799: }
1.484.2.30 raeburn 5800: $script .= &paste_popup_js();
1.484.2.12 raeburn 5801: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5802: &mt('Switch server?');
1.484.2.19 raeburn 5803:
5804:
1.329 droeschl 5805: }
5806: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5807: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5808: .'// <![CDATA['."\n"
5809: .$script."\n"
5810: .'// ]]>'."\n"
1.484.2.81 raeburn 5811: .'</script>'."\n"
5812: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5813:
5814: # Breadcrumbs
5815: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5816:
5817: if ($showdoc) {
1.484.2.93.2. 0(raebur 5818:3): my $args;
5819:3): if ($supplementalflag) {
5820:3): my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
5821:3): my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
5822:3): $args = {'bread_crumbs' => $brcrum};
5823:3): } else {
5824:3): $args = {'force_register' => $showdoc};
5825:3): }
5826:3): $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.484.2.44 raeburn 5827: } elsif ($toolsflag) {
1.484.2.67 raeburn 5828: my ($breadtext,$breadtitle);
5829: $breadtext = "$crstype Editor";
5830: if ($canedit) {
5831: $breadtitle = 'Editing '.$crstype.' Contents';
5832: } else {
5833: $breadtext .= ' (View-only mode)';
5834: $breadtitle = 'Viewing '.$crstype.' Contents';
5835: }
1.484.2.44 raeburn 5836: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5837: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5838: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5839: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5840: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5841: $breadtitle)
1.484.2.44 raeburn 5842: );
1.484.2.19 raeburn 5843: } elsif ($r->uri eq '/adm/supplemental') {
1.484.2.93.2. 0(raebur 5844:3): unless ($env{'request.role.adv'}) {
5845:3): unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
5846:3): $r->internal_redirect('/adm/navmaps');
5847:3): return OK;
5848:3): }
5849:3): }
1.484.2.19 raeburn 5850: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5851: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5852: {'bread_crumbs' => $brcrum,}));
5853: } else {
1.484.2.67 raeburn 5854: my ($breadtext,$breadtitle,$helpitem);
5855: $breadtext = "$crstype Editor";
5856: if ($canedit) {
5857: $breadtitle = 'Editing '.$crstype.' Contents';
5858: $helpitem = 'Docs_Adding_Course_Doc';
5859: } else {
5860: $breadtext .= ' (View-only mode)';
5861: $breadtitle = 'Viewing '.$crstype.' Contents';
5862: $helpitem = 'Docs_Viewing_Course_Doc';
5863: }
1.392 raeburn 5864: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5865: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5866: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5867: {'add_entries' => $addentries}
5868: )
1.392 raeburn 5869: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5870: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5871: $breadtitle,
5872: $helpitem)
1.392 raeburn 5873: );
5874: }
1.364 bisitz 5875:
1.329 droeschl 5876: my %allfiles = ();
5877: my %codebase = ();
1.440 raeburn 5878: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5879: if ($canedit) {
1.484.2.93.2. 0(raebur 5880:3): undef($suppchanges);
1.329 droeschl 5881: if (($env{'form.uploaddoc.filename'}) &&
5882: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5883: my $context = $1;
5884: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5885: undef($hadchanges);
1.440 raeburn 5886: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5887: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5888: undef($navmap);
1.329 droeschl 5889: if ($hadchanges) {
5890: &mark_hash_old();
5891: }
1.484.2.93.2. 0(raebur 5892:3): if ($suppchanges) {
5893:3): &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
5894:3): undef($suppchanges);
5895:3): }
1.440 raeburn 5896: $r->print($upload_output);
5897: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5898: # Process file upload - phase two - upload embedded objects
5899: $uploadphase = 'check_embedded';
5900: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5901: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5902: $env{'form.newidx'});
5903: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5904: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5905: my ($destination,$dir_root) = &embedded_destination();
5906: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5907: my $actionurl = '/adm/coursedocs';
5908: my ($result,$flag) =
5909: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5910: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5911: $actionurl);
5912: $r->print($result.&return_to_editor());
5913: } elsif ($env{'form.phase'} eq 'check_embedded') {
5914: # Process file upload - phase three - modify references in HTML file
5915: $uploadphase = 'modified_orightml';
5916: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5917: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5918: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5919: my $result =
5920: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5921: $docuname,$docudom,undef,
5922: $dir_root);
5923: $r->print($result.&return_to_editor());
1.476 raeburn 5924: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5925: $uploadphase = 'decompress_phase_one';
5926: $r->print(&decompression_phase_one().
5927: &return_to_editor());
5928: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5929: $uploadphase = 'decompress_phase_two';
5930: $r->print(&decompression_phase_two().
5931: &return_to_editor());
1.329 droeschl 5932: }
5933: }
5934:
1.484 raeburn 5935: if ($allowed && $toolsflag) {
5936: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5937: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5938: $r->print(&endContentScreen());
5939: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5940: # -----------------------------------------------------------------------------
5941: my %lt=&Apache::lonlocal::texthash(
5942: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5943: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5944: 'upld' => 'Upload Content',
1.329 droeschl 5945: 'srch' => 'Search',
5946: 'impo' => 'Import',
1.484.2.19 raeburn 5947: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5948: 'impm' => 'Import from Assembled Map',
1.484.2.93.2. (raeburn 5949:): 'extr' => 'External Resource',
5950:): 'extt' => 'External Tool',
1.329 droeschl 5951: 'selm' => 'Select Map',
5952: 'load' => 'Load Map',
5953: 'newf' => 'New Folder',
5954: 'newp' => 'New Composite Page',
5955: 'syll' => 'Syllabus',
1.425 raeburn 5956: 'navc' => 'Table of Contents',
1.343 biermanm 5957: 'sipa' => 'Simple Course Page',
1.329 droeschl 5958: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5959: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5960: 'drbx' => 'Drop Box',
1.451 www 5961: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5962: 'bull' => 'Discussion Board',
1.347 weissno 5963: 'mypi' => 'My Personal Information Page',
1.353 weissno 5964: 'grpo' => 'Group Portfolio',
1.329 droeschl 5965: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5966: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5967: 'imsf' => 'IMS Upload',
5968: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5969: 'cms' => 'Origin of IMS package',
5970: 'se' => 'Select',
1.484.2.19 raeburn 5971: 'file' => 'File',
1.329 droeschl 5972: 'title' => 'Title',
5973: 'comment' => 'Comment',
1.403 raeburn 5974: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5975: 'bb5' => 'Blackboard 5',
5976: 'bb6' => 'Blackboard 6',
5977: 'angel5' => 'ANGEL 5.5',
5978: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5979: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5980: );
1.329 droeschl 5981: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5982: # Calculate free quota space for a user or course. A javascript function checks
5983: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5984: my $quotatype = 'unofficial';
5985: if ($crstype eq 'Community') {
5986: $quotatype = 'community';
5987: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5988: $quotatype = 'official';
5989: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5990: $quotatype = 'textbook';
5991: }
5992: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5993: 'course',$quotatype); # expressed in MB
5994: my $current_disk_usage = 0;
5995: foreach my $subdir ('docs','supplemental') {
5996: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5997: "userfiles/$subdir",1); # expressed in kB
5998: }
5999: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
6000: my $usage = $current_disk_usage/1024; # in MB
6001: my $quota = $disk_quota;
6002: my $percent;
6003: if ($disk_quota == 0) {
6004: $percent = 100.0;
6005: } else {
1.484.2.69 raeburn 6006: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 6007: }
6008: $usage = sprintf("%.2f",$usage);
6009: $quota = sprintf("%.2f",$quota);
6010: $percent = sprintf("%.0f",$percent);
6011: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6012: $percent.'%',$quota.' MB').'</p>';
6013:
1.329 droeschl 6014: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 6015: $quotainfo
1.329 droeschl 6016: $lt{'file'}:<br />
1.484.2.81 raeburn 6017: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
6018: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 6019: FIUP
6020:
6021: my $checkbox=(<<CHBO);
6022: <!-- <label>$lt{'parse'}?
6023: <input type="checkbox" name="parserflag" />
6024: </label> -->
6025: <label>
1.484.2.67 raeburn 6026: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6027: </label>
6028: CHBO
1.484.2.12 raeburn 6029: my $imsfolder = $env{'form.folder'};
6030: if ($imsfolder eq '') {
1.484.2.19 raeburn 6031: $imsfolder = 'default';
1.484.2.12 raeburn 6032: }
6033: my $imspform=(<<IMSFORM);
6034: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6035: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6036: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 6037: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 6038: <legend>$lt{'imsf'}</legend>
6039: $fileupload
6040: <br />
6041: <p>
1.484.2.19 raeburn 6042: $lt{'cms'}:
1.484.2.67 raeburn 6043: <select name="source" $disabled>
1.484.2.12 raeburn 6044: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 6045: <option value="bb5">$lt{'bb5'}</option>
6046: <option value="bb6">$lt{'bb6'}</option>
6047: <option value="angel5">$lt{'angel5'}</option>
6048: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 6049: </select>
6050: <input type="hidden" name="folder" value="$imsfolder" />
6051: </p>
6052: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 6053: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 6054: </fieldset>
6055: </form>
6056: IMSFORM
6057:
1.484.2.19 raeburn 6058: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 6059: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6060: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6061: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 6062: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 6063: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6064: <input type="hidden" name="active" value="aa" />
1.329 droeschl 6065: $fileupload
6066: <br />
6067: $lt{'title'}:<br />
1.484.2.67 raeburn 6068: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 6069: $pathitem
1.329 droeschl 6070: <input type="hidden" name="cmd" value="upload_default" />
6071: <br />
1.458 raeburn 6072: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6073: $checkbox
6074: </span>
1.484.2.12 raeburn 6075: <br clear="all" />
1.484.2.67 raeburn 6076: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 6077: </fieldset>
6078: </form>
1.383 tempelho 6079: FUFORM
1.329 droeschl 6080:
1.484.2.67 raeburn 6081: my $mapimportjs;
6082: if ($canedit) {
6083: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6084: } else {
6085: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6086: }
1.484.2.19 raeburn 6087: my $importpubform=(<<SEDFFORM);
6088: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 6089: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 6090: <form action="/adm/coursedocs" method="post" name="mapimportform">
6091: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 6092: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 6093: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 6094: $lt{'copm'}<br />
6095: <span class="LC_nobreak">
1.484.2.19 raeburn 6096: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 6097: onfocus="this.blur();$mapimportjs" $disabled />
6098: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6099: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 6100: </fieldset>
6101: </form>
6102:
1.383 tempelho 6103: SEDFFORM
1.484.2.67 raeburn 6104:
6105: my $fromstoredjs;
6106: if ($canedit) {
6107: $fromstoredjs = 'open_StoredLinks_Import()';
6108: } else {
6109: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6110: }
6111:
1.484.2.19 raeburn 6112: my @importpubforma = (
6113: { '<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 6114: { '<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 6115: { '<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 6116: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
6117: );
6118: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
6119: my $extresourcesform =
6120: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6121: $help{'Adding_External_Resource'},
1.484.2.93.2. (raeburn 6122:): undef,undef,undef,undef,undef,undef,$disabled);
6123:): my $exttoolform =
6124:): &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6125:): $help{'Adding_External_Tool'},undef,
6126:): undef,'tool',$coursedom,$coursenum,
6127:): \%ltitools,$disabled);
1.329 droeschl 6128: if ($allowed) {
1.484.2.7 raeburn 6129: my $folder = $env{'form.folder'};
6130: if ($folder eq '') {
6131: $folder='default';
6132: }
1.484.2.67 raeburn 6133: if ($canedit) {
6134: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6135: if ($output) {
6136: $r->print($output);
6137: }
1.484.2.30 raeburn 6138: }
1.337 ehlerst 6139: $r->print(<<HIDDENFORM);
6140: <form name="renameform" method="post" action="/adm/coursedocs">
6141: <input type="hidden" name="title" />
6142: <input type="hidden" name="cmd" />
6143: <input type="hidden" name="markcopy" />
6144: <input type="hidden" name="copyfolder" />
6145: $containertag
6146: </form>
1.484 raeburn 6147:
1.337 ehlerst 6148: HIDDENFORM
1.484.2.17 raeburn 6149: $r->print(&makesimpleeditform($pathitem)."\n".
6150: &makedocslogform($pathitem."\n".
1.484 raeburn 6151: '<input type="hidden" name="folder" value="'.
6152: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6153: }
1.442 www 6154:
6155: # Generate the tabs
1.484.2.19 raeburn 6156: my ($mode,$needs_end);
1.472 raeburn 6157: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 6158: my @folders = split('&',$env{'form.folderpath'});
6159: unless (@folders > 2) {
6160: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6161: $needs_end = 1;
6162: }
1.472 raeburn 6163: } else {
1.484 raeburn 6164: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 6165: $needs_end = 1;
1.472 raeburn 6166: }
1.443 www 6167:
1.442 www 6168: #
6169:
6170: my $savefolderpath;
1.484.2.86 raeburn 6171: my $hostname = $r->hostname();
1.442 www 6172:
1.395 raeburn 6173: if ($allowed) {
1.329 droeschl 6174: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 6175: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6176: $folder='default';
1.356 tempelho 6177: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 6178: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 6179: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6180: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6181: }
6182: my $postexec='';
6183: if ($folder eq 'default') {
1.372 bisitz 6184: $r->print('<script type="text/javascript">'."\n"
6185: .'// <![CDATA['."\n"
6186: .'this.window.name="loncapaclient";'."\n"
6187: .'// ]]>'."\n"
6188: .'</script>'."\n"
1.369 bisitz 6189: );
1.329 droeschl 6190: } else {
6191: #$postexec='self.close();';
6192: }
1.484.2.15 raeburn 6193: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6194: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6195: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6196:
6197: my $newnavform=(<<NNFORM);
6198: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 6199: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6200: $pathitem
1.329 droeschl 6201: <input type="hidden" name="importdetail"
6202: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 6203: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6204: $help{'Navigate_Content'}
6205: </form>
6206: NNFORM
6207: my $newsmppageform=(<<NSPFORM);
6208: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 6209: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6210: $pathitem
1.329 droeschl 6211: <input type="hidden" name="importdetail" value="" />
1.423 onken 6212: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6213: $help{'Simple Page'}
1.329 droeschl 6214: </form>
6215: NSPFORM
6216:
6217: my $newsmpproblemform=(<<NSPROBFORM);
6218: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 6219: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6220: $pathitem
1.329 droeschl 6221: <input type="hidden" name="importdetail" value="" />
1.423 onken 6222: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 6223: $help{'Simple_Problem'}
1.329 droeschl 6224: </form>
6225:
6226: NSPROBFORM
6227:
6228: my $newdropboxform=(<<NDBFORM);
6229: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 6230: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6231: $pathitem
1.329 droeschl 6232: <input type="hidden" name="importdetail" value="" />
1.423 onken 6233: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 6234: $help{'Dropbox'}
1.344 bisitz 6235: </form>
1.329 droeschl 6236: NDBFORM
6237:
6238: my $newexuploadform=(<<NEXUFORM);
6239: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 6240: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6241: $pathitem
1.329 droeschl 6242: <input type="hidden" name="importdetail" value="" />
1.423 onken 6243: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6244: $help{'Score_Upload_Form'}
6245: </form>
6246: NEXUFORM
6247:
6248: my $newbulform=(<<NBFORM);
6249: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 6250: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6251: $pathitem
1.329 droeschl 6252: <input type="hidden" name="importdetail" value="" />
1.423 onken 6253: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6254: $help{'Bulletin Board'}
6255: </form>
6256: NBFORM
6257:
6258: my $newaboutmeform=(<<NAMFORM);
6259: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 6260: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6261: $pathitem
1.329 droeschl 6262: <input type="hidden" name="importdetail"
6263: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6264: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6265: $help{'My Personal Information Page'}
1.329 droeschl 6266: </form>
6267: NAMFORM
6268:
6269: my $newaboutsomeoneform=(<<NASOFORM);
6270: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 6271: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6272: $pathitem
1.329 droeschl 6273: <input type="hidden" name="importdetail" value="" />
1.423 onken 6274: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6275: </form>
6276: NASOFORM
6277:
6278: my $newrosterform=(<<NROSTFORM);
6279: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 6280: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6281: $pathitem
1.329 droeschl 6282: <input type="hidden" name="importdetail"
6283: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 6284: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 6285: $help{'Course_Roster'}
1.329 droeschl 6286: </form>
6287: NROSTFORM
6288:
1.484.2.27 raeburn 6289: my $newwebpage;
6290: if ($folder =~ /^default_?(\d*)$/) {
6291: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6292: if ($1) {
6293: $newwebpage .= $1;
6294: } else {
6295: $newwebpage .= 'default';
6296: }
6297: $newwebpage .= '/new.html';
6298: }
6299: my $newwebpageform =(<<NWEBFORM);
6300: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 6301: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 6302: $pathitem
6303: <input type="hidden" name="importdetail" value="$newwebpage" />
6304: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 6305: $help{'Web_Page'}
1.484.2.27 raeburn 6306: </form>
6307: NWEBFORM
1.484.2.30 raeburn 6308:
1.484.2.27 raeburn 6309:
1.342 ehlerst 6310: my $specialdocumentsform;
1.383 tempelho 6311: my @specialdocumentsforma;
1.451 www 6312: my $gradingform;
6313: my @gradingforma;
6314: my $communityform;
6315: my @communityforma;
1.351 ehlerst 6316: my $newfolderform;
1.390 tempelho 6317: my $newfolderb;
1.342 ehlerst 6318:
1.451 www 6319: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6320:
1.329 droeschl 6321: my $newpageform=(<<NPFORM);
6322: <form action="/adm/coursedocs" method="post" name="newpage">
6323: <input type="hidden" name="folderpath" value="$path" />
6324: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6325: <input type="hidden" name="active" value="ee" />
1.423 onken 6326: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6327: $help{'Adding_Pages'}
1.329 droeschl 6328: </form>
6329: NPFORM
1.390 tempelho 6330:
6331:
1.351 ehlerst 6332: $newfolderform=(<<NFFORM);
1.329 droeschl 6333: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 6334: $pathitem
1.329 droeschl 6335: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6336: <input type="hidden" name="active" value="" />
1.422 onken 6337: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6338: </form>
6339: NFFORM
6340:
6341: my $newsylform=(<<NSYLFORM);
6342: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 6343: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6344: $pathitem
1.329 droeschl 6345: <input type="hidden" name="importdetail"
6346: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6347: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6348: $help{'Syllabus'}
1.383 tempelho 6349:
1.329 droeschl 6350: </form>
6351: NSYLFORM
1.364 bisitz 6352:
1.329 droeschl 6353: my $newgroupfileform=(<<NGFFORM);
6354: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 6355: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6356: $pathitem
1.329 droeschl 6357: <input type="hidden" name="importdetail"
6358: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 6359: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6360: $help{'Group Portfolio'}
1.329 droeschl 6361: </form>
6362: NGFFORM
1.484.2.89 raeburn 6363: if ($container eq 'page') {
6364: @specialdocumentsforma=(
6365: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6366: );
6367: } else {
6368: @specialdocumentsforma=(
1.421 onken 6369: {'<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 6370: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6371: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6372: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 6373: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.484.2.89 raeburn 6374: );
6375: }
1.451 www 6376: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6377:
1.434 raeburn 6378:
6379: my @importdoc = (
1.484.2.19 raeburn 6380: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6381: );
1.484.2.93.2. (raeburn 6382:): if (keys(%ltitools)) {
6383:): push(@importdoc,
6384:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6385:): );
6386:): }
1.484.2.19 raeburn 6387: unless ($container eq 'page') {
6388: push(@importdoc,
6389: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6390: );
6391: }
6392: push(@importdoc,
1.484.2.38 raeburn 6393: {'<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 6394: );
1.484.2.12 raeburn 6395: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6396:
1.451 www 6397: @gradingforma=(
6398: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6399: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6400: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6401:
6402: );
6403: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6404:
6405: @communityforma=(
6406: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6407: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6408: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 6409: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6410: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6411: );
6412: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6413:
1.330 tempelho 6414: my %orderhash = (
1.484.2.36 raeburn 6415: 'aa' => ['Upload',$fileuploadform],
6416: 'bb' => ['Import',$importpubform],
6417: 'cc' => ['Grading',$gradingform],
1.484.2.89 raeburn 6418: 'ee' => ['Other',$specialdocumentsform],
1.330 tempelho 6419: );
1.484.2.19 raeburn 6420: unless ($container eq 'page') {
1.434 raeburn 6421: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6422: $orderhash{'dd'} = ['Collaboration',$communityform];
1.434 raeburn 6423: }
6424:
1.341 ehlerst 6425: $hadchanges=0;
1.484 raeburn 6426: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6427: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6428: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.93.2. (raeburn 6429:): \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 6430: undef($navmap);
1.443 www 6431: if ($error) {
6432: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6433: }
6434: if ($hadchanges) {
1.484.2.73 raeburn 6435: unless (&is_hash_old()) {
6436: &mark_hash_old();
6437: }
1.443 www 6438: }
1.341 ehlerst 6439:
1.443 www 6440: &changewarning($r,'');
6441: }
1.458 raeburn 6442: }
1.442 www 6443:
1.443 www 6444: # Supplemental documents start here
6445:
1.329 droeschl 6446: my $folder=$env{'form.folder'};
1.443 www 6447: unless ($supplementalflag) {
1.329 droeschl 6448: $folder='supplemental';
6449: }
1.484.2.93.2. 0(raebur 6450:3): if (($folder eq 'supplemental') &&
1.329 droeschl 6451: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6452: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6453: } elsif ($allowed) {
1.356 tempelho 6454: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6455: }
1.484.2.17 raeburn 6456: $pathitem = '<input type="hidden" name="folderpath" value="'.
6457: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6458: if ($allowed) {
6459: my $folderseq=
1.484.2.15 raeburn 6460: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6461:
6462: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 6463: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6464: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6465: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6466: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6467: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6468: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6469: $fileupload
6470: <br />
6471: <br />
6472: <span class="LC_nobreak">
6473: $checkbox
6474: </span>
6475: <br /><br />
6476: $lt{'comment'}:<br />
1.383 tempelho 6477: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6478: <br />
1.484.2.19 raeburn 6479: $pathitem
1.329 droeschl 6480: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6481: <input type='submit' value="$lt{'upld'}" />
6482: </form>
1.484.2.19 raeburn 6483: SUPDOCFORM
1.329 droeschl 6484:
6485: my $supnewfolderform=(<<SNFFORM);
6486: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6487: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6488: $pathitem
1.329 droeschl 6489: <input type="hidden" name="importdetail" value="" />
1.423 onken 6490: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6491: $help{'Adding_Folders'}
1.329 droeschl 6492: </form>
6493: SNFFORM
1.383 tempelho 6494:
1.484.2.19 raeburn 6495: my $supextform =
6496: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6497: $help{'Adding_External_Resource'},
6498: undef,undef,$disabled);
1.484.2.93.2. (raeburn 6499:): my $supexttoolform =
6500:): &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6501:): $help{'Adding_External_Tool'},
6502:): undef,undef,'tool',$coursedom,
6503:): $coursenum,\%ltitools,$disabled);
1.329 droeschl 6504:
6505: my $supnewsylform=(<<SNSFORM);
6506: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6507: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6508: $pathitem
1.329 droeschl 6509: <input type="hidden" name="importdetail"
6510: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6511: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6512: $help{'Syllabus'}
6513: </form>
6514: SNSFORM
6515:
6516: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6517: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6518: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6519: $pathitem
1.329 droeschl 6520: <input type="hidden" name="importdetail"
6521: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6522: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6523: $help{'My Personal Information Page'}
1.329 droeschl 6524: </form>
6525: SNAMFORM
6526:
1.484.2.27 raeburn 6527: my $supwebpage;
6528: if ($folder =~ /^supplemental_?(\d*)$/) {
6529: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6530: if ($1) {
6531: $supwebpage .= $1;
6532: } else {
6533: $supwebpage .= 'default';
6534: }
6535: $supwebpage .= '/new.html';
6536: }
6537: my $supwebpageform =(<<SWEBFORM);
6538: <form action="/adm/coursedocs" method="post" name="supwebpage">
6539: <input type="hidden" name="active" value="cc" />
6540: $pathitem
6541: <input type="hidden" name="importdetail" value="$supwebpage" />
6542: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6543: $help{'Web_Page'}
1.484.2.27 raeburn 6544: </form>
6545: SWEBFORM
6546:
1.333 muellerd 6547:
1.383 tempelho 6548: my @specialdocs = (
1.484.2.67 raeburn 6549: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6550: =>$supnewsylform},
1.484.2.67 raeburn 6551: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6552: =>$supnewaboutmeform},
1.484.2.27 raeburn 6553: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6554:
1.383 tempelho 6555: );
1.417 droeschl 6556: my @supimportdoc = (
1.484.2.19 raeburn 6557: {'<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 6558:): =>$supextform});
6559:): if (keys(%ltitools)) {
6560:): push(@supimportdoc,
6561:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6562:): =>$supexttoolform});
6563:): }
6564:): push(@supimportdoc,
1.484.2.12 raeburn 6565: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6566: =>$supupdocform},
1.484.2.93.2. (raeburn 6567:): );
1.484.2.19 raeburn 6568:
1.484.2.12 raeburn 6569: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6570: my %suporderhash = (
1.390 tempelho 6571: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6572: 'ee' => ['Upload',$supupdocform],
6573: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6574: );
1.443 www 6575: if ($supplementalflag) {
1.484.2.93.2. 0(raebur 6576:3): $suppchanges = 0;
6577:3): my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6578:3): $supplementalflag,\%suporderhash,$iconpath,$pathitem,
6579:3): \%ltitools,$canedit,$hostname);
6580:3): if ($error) {
6581:3): $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6582:3): }
6583:3): if ($suppchanges) {
6584:3): &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6585:3): undef($suppchanges);
6586:3): }
1.393 raeburn 6587: }
1.443 www 6588: } elsif ($supplementalflag) {
1.458 raeburn 6589: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.93.2. (raeburn 6590:): $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
6591:): $hostname);
1.393 raeburn 6592: if ($error) {
6593: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6594: }
1.393 raeburn 6595: }
1.389 tempelho 6596:
1.484.2.19 raeburn 6597: if ($needs_end) {
6598: $r->print(&endContentScreen());
6599: }
1.383 tempelho 6600:
1.329 droeschl 6601: if ($allowed) {
6602: $r->print('
6603: <form method="post" name="extimport" action="/adm/coursedocs">
6604: <input type="hidden" name="title" />
6605: <input type="hidden" name="url" />
6606: <input type="hidden" name="useform" />
6607: <input type="hidden" name="residx" />
6608: </form>');
6609: }
1.484 raeburn 6610: } elsif ($showdoc) {
1.329 droeschl 6611: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6612: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6613: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6614: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6615: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6616: }
6617: }
6618: $r->print(&Apache::loncommon::end_page());
6619: return OK;
1.364 bisitz 6620: }
1.329 droeschl 6621:
1.440 raeburn 6622: sub embedded_form_elems {
6623: my ($phase,$primaryurl,$newidx) = @_;
6624: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6625: $newidx =~s /\D+//g;
1.440 raeburn 6626: return <<STATE;
6627: <input type="hidden" name="folderpath" value="$folderpath" />
6628: <input type="hidden" name="cmd" value="upload_embedded" />
6629: <input type="hidden" name="newidx" value="$newidx" />
6630: <input type="hidden" name="phase" value="$phase" />
6631: <input type="hidden" name="primaryurl" value="$primaryurl" />
6632: STATE
6633: }
6634:
6635: sub embedded_destination {
6636: my $folder=$env{'form.folder'};
6637: my $destination = 'docs/';
6638: if ($folder =~ /^supplemental/) {
6639: $destination = 'supplemental/';
6640: }
6641: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6642: $destination .= 'default/';
6643: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6644: $destination .= $2.'/';
6645: }
1.484.2.78 raeburn 6646: my $newidx = $env{'form.newidx'};
6647: $newidx =~s /\D+//g;
6648: if ($newidx) {
6649: $destination .= $newidx;
6650: }
1.440 raeburn 6651: my $dir_root = '/userfiles';
6652: return ($destination,$dir_root);
6653: }
6654:
6655: sub return_to_editor {
6656: my $actionurl = '/adm/coursedocs';
6657: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6658: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6659: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6660: '</a></p>';
6661: }
6662:
1.476 raeburn 6663: sub decompression_info {
6664: my ($destination,$dir_root) = &embedded_destination();
6665: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6666: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6667: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6668: my $container='sequence';
1.480 raeburn 6669: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6670: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6671: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6672: $container='page';
6673: }
1.480 raeburn 6674: unshift(@hiddens,$pathitem);
6675: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6676: if ($item eq 'newidx') {
6677: next if ($env{'form.'.$item} =~ /\D/);
6678: }
1.480 raeburn 6679: if ($env{'form.'.$item}) {
6680: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6681: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6682: }
1.477 raeburn 6683: }
1.476 raeburn 6684: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6685: $hiddenelem);
6686: }
6687:
6688: sub decompression_phase_one {
6689: my ($dir,$file,$warning,$error,$output);
6690: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6691: &decompression_info();
1.484.2.7 raeburn 6692: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6693: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6694: } else {
6695: my $file = $1;
1.481 raeburn 6696: $output =
6697: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6698: $destination,$dir_root,
6699: $hiddenelem);
6700: if ($env{'form.autoextract_camtasia'}) {
6701: $output .= &remove_archive($docudom,$docuname,$container);
6702: }
1.476 raeburn 6703: }
6704: if ($error) {
6705: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6706: $error.'</p>'."\n";
6707: }
6708: if ($warning) {
6709: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6710: }
6711: return $output;
6712: }
6713:
6714: sub decompression_phase_two {
6715: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6716: &decompression_info();
1.481 raeburn 6717: my $output;
1.480 raeburn 6718: if ($env{'form.archivedelete'}) {
1.481 raeburn 6719: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6720: }
6721: $output .=
1.481 raeburn 6722: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6723: $destination,$dir_root,$hiddenelem);
6724: return $output;
6725: }
6726:
1.480 raeburn 6727: sub remove_archive {
6728: my ($docudom,$docuname,$container) = @_;
6729: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6730: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6731: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6732: if ($fatal) {
6733: if ($container eq 'page') {
6734: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6735: } else {
6736: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6737: }
1.484.2.54 raeburn 6738: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6739: } else {
6740: my $currcmd = $env{'form.cmd'};
6741: my $position = $env{'form.position'};
1.484.2.54 raeburn 6742: my $archiveidx = $position;
6743: if ($position > 0) {
6744: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6745: $archiveidx = $position-1;
6746: }
6747: $env{'form.cmd'} = 'remove_'.$archiveidx;
6748: my ($title,$url,@rrest) =
6749: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6750: if ($url eq $env{'form.archiveurl'}) {
6751: if (&handle_edit_cmd($docuname,$docudom)) {
6752: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.484.2.93.2. 0(raebur 6753:3): if ($suppchanges) {
6754:3): &Apache::lonnet::update_supp_caches($docudom,$docuname);
6755:3): undef($suppchanges);
6756:3): }
1.484.2.54 raeburn 6757: if ($fatal) {
6758: if ($container eq 'page') {
6759: $delwarning = &mt('An error occurred updating the contents of the current page.');
6760: } else {
6761: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6762: }
1.480 raeburn 6763: } else {
1.484.2.54 raeburn 6764: $delresult = &mt('Archive file removed.');
1.480 raeburn 6765: }
6766: }
1.484.2.54 raeburn 6767: } else {
6768: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6769: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6770: }
6771: }
6772: $env{'form.cmd'} = $currcmd;
6773: }
6774: if ($delwarning) {
6775: $output = '<p class="LC_warning">'.
6776: $delwarning.
6777: '</p>';
6778: }
6779: if ($delresult) {
6780: $output .= '<p class="LC_info">'.
6781: $delresult.
6782: '</p>';
6783: }
1.481 raeburn 6784: return $output;
1.480 raeburn 6785: }
6786:
1.484 raeburn 6787: sub generate_admin_menu {
1.484.2.67 raeburn 6788: my ($crstype,$canedit) = @_;
1.484 raeburn 6789: my $lc_crstype = lc($crstype);
6790: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6791: my %lt= ( # do not translate here
1.484 raeburn 6792: 'vc' => 'Verify Content',
6793: 'cv' => 'Check/Set Resource Versions',
6794: 'ls' => 'List Resource Identifiers',
1.484.2.93.2. (raeburn 6795:): 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 6796: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6797: 'dcd' => "Copy $crstype Content to Authoring Space",
6798: );
1.484 raeburn 6799: my ($candump,$dumpurl);
6800: if ($home + $other > 0) {
6801: $candump = 'F';
6802: if ($home) {
6803: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6804: } else {
6805: my @hosts;
6806: foreach my $aurole (keys(%outhash)) {
6807: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6808: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6809: }
1.484 raeburn 6810: }
6811: if (@hosts == 1) {
6812: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6813: '&role='.
6814: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6815: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6816: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6817: } else {
6818: $dumpurl = "javascript:choose_switchserver_window()";
6819: }
6820: }
6821: }
6822: my @menu=
6823: ({ categorytitle=>'Administration',
6824: items =>[
6825: { linktext => $lt{'vc'},
6826: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6827: permission => 'F',
1.484.2.44 raeburn 6828: help => 'Docs_Verify_Content',
1.484 raeburn 6829: icon => 'verify.png',
6830: linktitle => 'Verify contents can be retrieved/rendered',
6831: },
6832: { linktext => $lt{'cv'},
6833: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6834: permission => 'F',
1.484.2.44 raeburn 6835: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6836: icon => 'resversion.png',
6837: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6838: },
6839: { linktext => $lt{'ls'},
6840: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6841: permission => 'F',
6842: #help => '',
6843: icon => 'symbs.png',
6844: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6845: },
1.484.2.93.2. (raeburn 6846:): { linktext => $lt{'ct'},
6847:): url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
6848:): permission => 'F',
6849:): help => 'Docs_Short_URLs',
6850:): icon => 'shorturls.png',
6851:): linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
6852:): },
1.484 raeburn 6853: ]
1.484.2.67 raeburn 6854: });
6855: if ($canedit) {
6856: push(@menu,
1.484 raeburn 6857: { categorytitle=>'Export',
6858: items =>[
6859: { linktext => $lt{'imse'},
6860: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6861: permission => 'F',
6862: help => 'Docs_Export_Course_Docs',
6863: icon => 'imsexport.png',
6864: linktitle => $lt{'imse'},
6865: },
6866: { linktext => $lt{'dcd'},
6867: url => $dumpurl,
6868: permission => $candump,
1.484.2.44 raeburn 6869: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6870: icon => 'dump.png',
6871: linktitle => $lt{'dcd'},
6872: },
6873: ]
6874: });
1.484.2.67 raeburn 6875: }
1.484 raeburn 6876: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6877: '<input type="hidden" id="dummy" />'."\n".
6878: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6879: '</form>';
1.329 droeschl 6880: }
6881:
6882: sub generate_edit_table {
1.484.2.30 raeburn 6883: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6884: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6885: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6886: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6887: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6888: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6889: $activetab = $env{'form.active'};
6890: }
1.484.2.67 raeburn 6891: unless ($canedit) {
6892: $disabled = ' disabled="disabled"';
6893: }
1.472 raeburn 6894: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6895: my $backtext = &mt('Exit Editor');
1.458 raeburn 6896: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6897: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6898: '<li class="goback">'.
1.484.2.32 raeburn 6899: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6900: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6901: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6902: '<li>'.
6903: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6904: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6905: if ($env{'form.docslog'}) {
6906: $form .= '<li class="active">';
6907: } else {
6908: $form .= '<li>';
6909: }
6910: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6911: &mt('History').'</a></li>'."\n";
6912: if ($env{'form.docslog'}) {
6913: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6914: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6915: }
1.458 raeburn 6916: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6917: if($name ne '00'){
1.371 tempelho 6918: if($activetab eq '' || $activetab ne $name){
6919: $active = '';
6920: }elsif($activetab eq $name){
6921: $active = 'class="active"';
6922: }
1.458 raeburn 6923: $form .= '<li style="float:right" '.$active
1.484 raeburn 6924: .' 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 6925: } else {
1.484.2.43 raeburn 6926: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6927:
6928: }
1.329 droeschl 6929: }
1.484 raeburn 6930: $form .= '</ul>'."\n";
6931: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6932:
6933: if ($to_show ne '') {
1.484.2.30 raeburn 6934: my $saveform;
6935: if ($need_save) {
6936: my $button = &mt('Make changes');
6937: my $path;
6938: if ($env{'form.folderpath'}) {
6939: $path =
6940: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6941: }
6942: $saveform = <<"END";
6943: <div id="multisave" style="display:none; clear:both;" >
6944: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6945: <input type="hidden" name="folderpath" value="$path" />
6946: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6947: <input type="hidden" name="allhiddenresource" value="" />
6948: <input type="hidden" name="allencrypturl" value="" />
6949: <input type="hidden" name="allrandompick" value="" />
6950: <input type="hidden" name="allrandomorder" value="" />
6951: <input type="hidden" name="changeparms" value="" />
6952: <input type="hidden" name="multiremove" value="" />
6953: <input type="hidden" name="multicut" value="" />
6954: <input type="hidden" name="multicopy" value="" />
6955: <input type="hidden" name="multichange" value="" />
6956: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6957: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6958: </form>
6959: </div>
6960: END
6961: }
6962: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6963: }
1.363 ehlerst 6964: foreach my $field (keys(%orderhash)){
1.390 tempelho 6965: if($field ne '00'){
1.422 onken 6966: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6967: $active = 'style="display: none;float:left"';
1.422 onken 6968: }elsif($activetab eq $field){
1.458 raeburn 6969: $active = 'style="display:block;float:left"';
1.422 onken 6970: }
6971: $form .= '<div id="'.$field.$tid.'"'
6972: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6973: .'</div>'."\n";
1.363 ehlerst 6974: }
6975: }
1.484 raeburn 6976: unless ($env{'form.docslog'}) {
6977: $form .= '</div></div>'."\n";
6978: }
1.329 droeschl 6979: return $form;
6980: }
6981:
6982: sub editing_js {
1.484.2.93.2. (raeburn 6983:): my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 6984: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6985: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6986: p_mnf => 'Name of New Folder',
6987: t_mnf => 'New Folder',
6988: p_mnp => 'Name of New Page',
6989: t_mnp => 'New Page',
1.451 www 6990: p_mxu => 'Title for the External Score',
1.349 biermanm 6991: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6992: p_msb => 'Title for the Problem',
6993: p_mdb => 'Title for the Drop Box',
1.336 schafran 6994: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6995: p_mwp => 'Title for Web Page',
1.348 weissno 6996: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6997: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6998: p_mab_alrt1 => 'Not a valid user:domain',
6999: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7000: p_chn => 'New Title',
7001: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 7002: p_rmr2a => 'Remove',
7003: p_rmr2b => '?',
7004: p_rmr3a => 'Remove those',
7005: p_rmr3b => 'items?',
7006: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7007: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7008: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7009: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 7010: p_ctr2a => 'Cut',
7011: p_ctr2b => '?',
7012: p_ctr3a => 'Cut those',
7013: p_ctr3b => 'items?',
1.478 raeburn 7014: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 7015: imsfile => 'You must choose an IMS package for import',
7016: imscms => 'You must select which Course Management System was the source of the IMS package',
7017: invurl => 'Invalid URL',
7018: titbl => 'Title is blank',
1.484.2.30 raeburn 7019: more => '(More ...)',
7020: less => '(Less ...)',
7021: noor => 'No actions selected or changes to settings specified.',
7022: noch => 'No changes to settings specified.',
7023: noac => 'No actions selected.',
1.484.2.67 raeburn 7024: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 7025: );
7026:
1.484.2.61 raeburn 7027: &js_escape(\%js_lt);
1.433 raeburn 7028: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7029: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7030: my $main_container_page;
1.484.2.19 raeburn 7031: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7032: $main_container_page = 1;
1.434 raeburn 7033: }
1.484.2.67 raeburn 7034: my $backtourl;
7035: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7036: my $toplevelsupp = &supplemental_base();
1.433 raeburn 7037:
1.484.2.21 raeburn 7038: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7039: my $caller = $1;
7040: if ($caller =~ /^supplemental/) {
7041: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7042: } else {
7043: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7044: $res = &Apache::lonnet::clutter($res);
7045: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 7046: my ($url,$anchor);
7047: if ($res =~ /^([^#]+)#([^#]+)$/) {
7048: $url = $1;
7049: $anchor = $2;
7050: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7051: $caller = $1.&escape('#').$anchor;
7052: }
1.484.2.67 raeburn 7053: } else {
7054: $url = $res;
1.484.2.66 raeburn 7055: }
1.484.2.83 raeburn 7056: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7057: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7058: $backtourl .= '?navmap=1';
7059: } else {
7060: $backtourl .= '?symb='.
7061: &HTML::Entities::encode($caller,'<>&"');
7062: }
1.484.2.80 raeburn 7063: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7064: if (($ENV{'SERVER_PORT'} == 443) &&
7065: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.93 raeburn 7066: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 7067: if ($hostname ne '') {
7068: $backtourl = 'http://'.$hostname.$backtourl;
7069: }
7070: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7071: }
7072: }
7073: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7074: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.484.2.93 raeburn 7075: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.484.2.80 raeburn 7076: if ($hostname ne '') {
7077: $backtourl = 'http://'.$hostname.$backtourl;
7078: }
7079: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7080: }
7081: }
7082: }
1.484.2.66 raeburn 7083: if ($anchor ne '') {
7084: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7085: }
1.484.2.57 raeburn 7086: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 7087: } else {
7088: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 7089: }
7090: }
7091: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7092: $backtourl = '/adm/menu';
7093: } elsif ($supplementalflag) {
1.484.2.93.2. 0(raebur 7094:3): if (($env{'request.role.adv'}) ||
7095:3): (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7096:3): $backtourl = '/adm/supplemental';
7097:3): } else {
7098:3): $backtourl = '/adm/navmaps';
7099:3): }
1.484.2.21 raeburn 7100: } else {
7101: $backtourl = '/adm/navmaps';
1.472 raeburn 7102: }
7103:
1.484.2.19 raeburn 7104: my $fieldsets = "'ext','doc'";
1.484.2.93.2. (raeburn 7105:): if ($posslti) {
7106:): $fieldsets .= ",'tool'";
7107:): }
1.484.2.19 raeburn 7108: unless ($main_container_page) {
7109: $fieldsets .=",'ims'";
7110: }
1.484.2.12 raeburn 7111: if ($supplementalflag) {
7112: $fieldsets = "'suppext','suppdoc'";
1.484.2.93.2. (raeburn 7113:): if ($posslti) {
7114:): $fieldsets .= ",'supptool'";
7115:): }
1.484.2.12 raeburn 7116: }
7117:
1.484.2.67 raeburn 7118: my $jsmakefunctions;
7119: if ($canedit) {
7120: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7121: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 7122: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7123: if (foldername) {
1.484.2.91 raeburn 7124: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 7125: targetform.submit();
7126: }
7127: }
7128:
7129: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 7130: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7131: if (pagename) {
1.484.2.91 raeburn 7132: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 7133: targetform.submit();
7134: }
7135: }
7136:
7137: function makeexamupload() {
1.484.2.61 raeburn 7138: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7139: if (title) {
1.329 droeschl 7140: this.document.forms.newexamupload.importdetail.value=
1.484.2.91 raeburn 7141: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 7142: this.document.forms.newexamupload.submit();
7143: }
7144: }
7145:
7146: function makesmppage() {
1.484.2.61 raeburn 7147: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7148: if (title) {
1.329 droeschl 7149: this.document.forms.newsmppg.importdetail.value=
1.484.2.91 raeburn 7150: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7151: this.document.forms.newsmppg.submit();
7152: }
7153: }
7154:
1.484.2.27 raeburn 7155: function makewebpage(type) {
1.484.2.61 raeburn 7156: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 7157: var formname;
7158: if (type == 'supp') {
7159: formname = this.document.forms.supwebpage;
7160: } else {
7161: formname = this.document.forms.newwebpage;
7162: }
7163: if (title) {
7164: var webpage = formname.importdetail.value;
1.484.2.91 raeburn 7165: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.484.2.27 raeburn 7166: formname.submit();
7167: }
7168: }
7169:
1.329 droeschl 7170: function makesmpproblem() {
1.484.2.61 raeburn 7171: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7172: if (title) {
1.329 droeschl 7173: this.document.forms.newsmpproblem.importdetail.value=
1.484.2.91 raeburn 7174: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 7175: this.document.forms.newsmpproblem.submit();
7176: }
7177: }
7178:
7179: function makedropbox() {
1.484.2.61 raeburn 7180: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7181: if (title) {
1.329 droeschl 7182: this.document.forms.newdropbox.importdetail.value=
1.484.2.91 raeburn 7183: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 7184: this.document.forms.newdropbox.submit();
7185: }
7186: }
7187:
7188: function makebulboard() {
1.484.2.61 raeburn 7189: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7190: if (title) {
7191: this.document.forms.newbul.importdetail.value=
1.484.2.91 raeburn 7192: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7193: this.document.forms.newbul.submit();
7194: }
7195: }
7196:
7197: function makeabout() {
1.484.2.61 raeburn 7198: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7199: if (user) {
7200: var comp=new Array();
7201: comp=user.split(':');
7202: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7203: if ((comp[0]) && (comp[1])) {
7204: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 7205: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 7206: this.document.forms.newaboutsomeone.submit();
7207: } else {
7208: alert("$js_lt{'p_mab_alrt1'}");
7209: }
7210: } else {
7211: alert("$js_lt{'p_mab_alrt2'}");
7212: }
7213: }
1.335 ehlerst 7214: }
1.484.2.67 raeburn 7215:
7216: function makenew(targetform) {
7217: targetform.submit();
1.335 ehlerst 7218: }
1.484.2.67 raeburn 7219:
7220: function changename(folderpath,index,oldtitle) {
7221: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7222: if (title) {
7223: this.document.forms.renameform.markcopy.value='';
7224: this.document.forms.renameform.title.value=title;
7225: this.document.forms.renameform.cmd.value='rename_'+index;
7226: this.document.forms.renameform.folderpath.value=folderpath;
7227: this.document.forms.renameform.submit();
7228: }
1.329 droeschl 7229: }
7230:
1.484.2.67 raeburn 7231: ENDNEWSCRIPT
7232: } else {
7233: $jsmakefunctions = <<ENDNEWSCRIPT;
7234:
7235: function makenewfolder() {
7236: alert("$js_lt{'edri'}");
7237: }
7238:
7239: function makenewpage() {
7240: alert("$js_lt{'edri'}");
7241: }
7242:
7243: function makeexamupload() {
7244: alert("$js_lt{'edri'}");
7245: }
7246:
7247: function makesmppage() {
7248: alert("$js_lt{'edri'}");
7249: }
7250:
7251: function makewebpage(type) {
7252: alert("$js_lt{'edri'}");
7253: }
7254:
7255: function makesmpproblem() {
7256: alert("$js_lt{'edri'}");
7257: }
7258:
7259: function makedropbox() {
7260: alert("$js_lt{'edri'}");
7261: }
7262:
7263: function makebulboard() {
7264: alert("$js_lt{'edri'}");
7265: }
7266:
7267: function makeabout() {
7268: alert("$js_lt{'edri'}");
7269: }
7270:
7271: function changename() {
7272: alert("$js_lt{'edri'}");
7273: }
7274:
7275: function makenew() {
7276: alert("$js_lt{'edri'}");
7277: }
7278:
7279: function groupimport() {
7280: alert("$js_lt{'edri'}");
7281: }
7282:
7283: function groupsearch() {
7284: alert("$js_lt{'edri'}");
7285: }
7286:
7287: function groupopen(url,recover) {
7288: var options="scrollbars=1,resizable=1,menubar=0";
7289: idxflag=1;
7290: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7291: idx.focus();
7292: }
7293:
7294: ENDNEWSCRIPT
7295:
7296: }
7297: return <<ENDSCRIPT;
7298:
7299: $jsmakefunctions
7300:
1.484.2.13 raeburn 7301: function toggleUpload(caller) {
7302: var blocks = Array($fieldsets);
7303: for (var i=0; i<blocks.length; i++) {
7304: var disp = 'none';
7305: if (caller == blocks[i]) {
7306: var curr = document.getElementById('upload'+caller+'form').style.display;
7307: if (curr == 'none') {
7308: disp='block';
7309: }
7310: }
7311: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.484.2.93.2. (raeburn 7312:): if ((caller == 'tool') || (caller == 'supptool')) {
7313:): if (disp == 'block') {
7314:): if (document.getElementById('LC_exttoolid')) {
7315:): var toolselector = document.getElementById('LC_exttoolid');
7316:): var suppflag = 0;
7317:): if (caller == 'supptool') {
7318:): suppflag = 1;
7319:): }
7320:): currForm = document.getElementById('new'+caller);
7321:): updateExttool(toolselector,currForm,suppflag);
7322:): }
7323:): }
7324:): }
1.484.2.13 raeburn 7325: }
7326: resize_scrollbox('contentscroll','1','1');
7327: return;
7328: }
7329:
1.484.2.19 raeburn 7330: function toggleMap(caller) {
1.484.2.13 raeburn 7331: var disp = 'none';
1.484.2.19 raeburn 7332: if (document.getElementById('importmapform')) {
7333: if (caller == 'map') {
7334: var curr = document.getElementById('importmapform').style.display;
7335: if (curr == 'none') {
7336: disp='block';
7337: }
1.484.2.12 raeburn 7338: }
1.484.2.19 raeburn 7339: document.getElementById('importmapform').style.display=disp;
7340: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 7341: }
1.484.2.19 raeburn 7342: return;
1.329 droeschl 7343: }
7344:
1.484.2.12 raeburn 7345: function makeims(imsform) {
7346: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 7347: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 7348: return;
7349: }
7350: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 7351: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 7352: return;
7353: }
7354: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7355: imsform.submit();
7356: }
7357:
1.478 raeburn 7358: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 7359: var pickitem;
7360: var picknumitem;
7361: var picknumtext;
7362: if (index == 'all') {
7363: pickitem = document.getElementById('randompickall');
7364: picknumitem = document.getElementById('rpicknumall');
7365: picknumtext = document.getElementById('rpicktextall');
7366: } else {
7367: pickitem = document.getElementById('randompick_'+index);
7368: picknumitem = document.getElementById('rpicknum_'+index);
7369: picknumtext = document.getElementById('randompicknum_'+index);
7370: }
1.478 raeburn 7371: if (pickitem.checked) {
1.484.2.61 raeburn 7372: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7373: if (picknum == '' || picknum == null) {
7374: if (caller == 'check') {
7375: pickitem.checked=false;
1.484.2.29 raeburn 7376: if (index == 'all') {
7377: picknumtext.innerHTML = '';
7378: if (caller == 'link') {
7379: propagateState(targetform,'rpicknum');
7380: }
7381: } else {
1.484.2.30 raeburn 7382: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7383: }
1.478 raeburn 7384: }
7385: } else {
7386: picknum.toString();
7387: var regexdigit=/^\\d+\$/;
7388: if (regexdigit.test(picknum)) {
7389: picknumitem.value = picknum;
1.484.2.29 raeburn 7390: if (index == 'all') {
1.484.2.30 raeburn 7391: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 7392: if (caller == 'link') {
7393: propagateState(targetform,'rpicknum');
7394: }
7395: } else {
7396: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 7397: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7398: }
1.478 raeburn 7399: } else {
7400: if (caller == 'check') {
1.484.2.29 raeburn 7401: if (index == 'all') {
7402: picknumtext.innerHTML = '';
7403: if (caller == 'link') {
7404: propagateState(targetform,'rpicknum');
7405: }
7406: } else {
7407: pickitem.checked=false;
1.484.2.30 raeburn 7408: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7409: }
1.478 raeburn 7410: }
7411: return;
7412: }
7413: }
7414: } else {
1.484.2.29 raeburn 7415: picknumitem.value = '';
7416: picknumtext.innerHTML = '';
7417: if (index == 'all') {
7418: if (caller == 'link') {
7419: propagateState(targetform,'rpicknum');
7420: }
7421: } else {
1.484.2.30 raeburn 7422: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7423: }
7424: }
7425: }
7426:
7427: function propagateState(form,param) {
7428: if (document.getElementById(param+'all')) {
7429: var setcheck = 0;
7430: var rpick = 0;
7431: if (param == 'rpicknum') {
7432: if (document.getElementById('randompickall')) {
7433: if (document.getElementById('randompickall').checked) {
7434: if (document.getElementById('rpicknumall')) {
7435: rpick = document.getElementById('rpicknumall').value;
7436: }
7437: }
7438: }
7439: } else {
7440: if (document.getElementById(param+'all').checked) {
7441: setcheck = 1;
7442: }
7443: }
1.484.2.30 raeburn 7444: var allidxlist;
7445: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7446: if (document.getElementById('all'+param+'idx')) {
7447: allidxlist = document.getElementById('all'+param+'idx').value;
7448: }
7449: var actions = new Array ('remove','cut','copy');
7450: for (var i=0; i<actions.length; i++) {
7451: if (actions[i] != param) {
7452: if (document.getElementById(actions[i]+'all')) {
7453: document.getElementById(actions[i]+'all').checked = false;
7454: }
7455: }
7456: }
7457: }
1.484.2.29 raeburn 7458: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 7459: allidxlist = form.allidx.value;
7460: }
7461: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7462: allidxlist = form.allmapidx.value;
7463: }
7464: if ((allidxlist != '') && (allidxlist != null)) {
7465: var allidxs = allidxlist.split(',');
7466: if (allidxs.length > 1) {
7467: for (var i=0; i<allidxs.length; i++) {
7468: if (document.getElementById(param+'_'+allidxs[i])) {
7469: if (param == 'rpicknum') {
7470: if (document.getElementById('randompick_'+allidxs[i])) {
7471: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7472: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7473: if (rpick > 0) {
7474: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7475: } else {
7476: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7477: }
7478: }
7479: }
7480: } else {
1.484.2.29 raeburn 7481: if (setcheck == 1) {
7482: document.getElementById(param+'_'+allidxs[i]).checked = true;
7483: } else {
7484: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 7485: if (param == 'randompick') {
7486: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7487: }
1.484.2.29 raeburn 7488: }
7489: }
7490: }
7491: }
1.484.2.30 raeburn 7492: if (setcheck == 1) {
7493: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7494: var actions = new Array('copy','cut','remove');
7495: for (var i=0; i<actions.length; i++) {
7496: var otheractions;
7497: var otheridxs;
7498: if (actions[i] === param) {
7499: continue;
7500: } else {
7501: if (document.getElementById('all'+actions[i]+'idx')) {
7502: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7503: otheridxs = otheractions.split(',');
7504: if (otheridxs.length > 1) {
7505: for (var j=0; j<otheridxs.length; j++) {
7506: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7507: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7508: }
1.484.2.29 raeburn 7509: }
7510: }
7511: }
7512: }
1.484.2.30 raeburn 7513: }
1.484.2.29 raeburn 7514: }
7515: }
7516: }
7517: }
1.478 raeburn 7518: }
1.484.2.29 raeburn 7519: return;
7520: }
7521:
1.484.2.63 raeburn 7522: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7523: var canedit = '$canedit';
7524: if (canedit == '') {
7525: alert("$js_lt{'edri'}");
7526: return;
7527: }
1.484.2.30 raeburn 7528: var dosettings;
7529: var doaction;
7530: var control = document.togglemultsettings;
7531: if (context == 'actions') {
7532: control = document.togglemultactions;
7533: doaction = 1;
7534: } else {
7535: dosettings = 1;
7536: }
7537: if (control) {
7538: if (control.showmultpick.length) {
7539: for (var i=0; i<control.showmultpick.length; i++) {
7540: if (control.showmultpick[i].checked) {
7541: if (control.showmultpick[i].value == 1) {
7542: if (context == 'settings') {
7543: dosettings = 0;
7544: } else {
7545: doaction = 0;
7546: }
7547: }
7548: }
7549: }
7550: }
7551: }
7552: if (context == 'settings') {
7553: if (dosettings == 1) {
7554: targetform.changeparms.value=param;
7555: targetform.submit();
7556: }
7557: }
7558: if (context == 'actions') {
7559: if (doaction == 1) {
7560: targetform.cmd.value=param+'_'+index;
7561: targetform.folderpath.value=folderpath;
7562: targetform.markcopy.value=idx+':'+param;
7563: targetform.copyfolder.value=folder+'.'+container;
7564: if (param == 'remove') {
1.484.2.63 raeburn 7565: var doremove = 0;
7566: if (skip_confirm) {
7567: if (confirm_removal) {
7568: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7569: doremove = 1;
7570: }
7571: } else {
7572: doremove = 1;
7573: }
7574: } else {
7575: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7576: doremove = 1;
7577: }
7578: }
7579: if (doremove) {
1.484.2.30 raeburn 7580: targetform.markcopy.value='';
7581: targetform.copyfolder.value='';
1.484.2.29 raeburn 7582: targetform.submit();
7583: }
7584: }
1.484.2.30 raeburn 7585: if (param == 'cut') {
1.484.2.61 raeburn 7586: 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 7587: targetform.submit();
7588: return;
7589: }
7590: }
7591: if (param == 'copy') {
7592: targetform.submit();
7593: return;
7594: }
7595: targetform.markcopy.value='';
7596: targetform.copyfolder.value='';
7597: targetform.cmd.value='';
7598: targetform.folderpath.value='';
7599: return;
7600: } else {
7601: if (document.getElementById(param+'_'+idx)) {
7602: item = document.getElementById(param+'_'+idx);
7603: if (item.type == 'checkbox') {
7604: if (item.checked) {
7605: item.checked = false;
7606: } else {
7607: item.checked = true;
7608: singleCheck(item,idx,param);
7609: }
7610: }
7611: }
7612: }
7613: }
7614: return;
7615: }
7616:
7617: function singleCheck(caller,idx,action) {
7618: actions = new Array('cut','copy','remove');
7619: if (caller.checked) {
7620: for (var i=0; i<actions.length; i++) {
7621: if (actions[i] != action) {
7622: if (document.getElementById(actions[i]+'_'+idx)) {
7623: if (document.getElementById(actions[i]+'_'+idx).checked) {
7624: document.getElementById(actions[i]+'_'+idx).checked = false;
7625: }
7626: }
7627: }
1.484.2.29 raeburn 7628: }
7629: }
7630: return;
1.478 raeburn 7631: }
7632:
1.334 muellerd 7633: function unselectInactive(nav) {
1.335 ehlerst 7634: currentNav = document.getElementById(nav);
7635: currentLis = currentNav.getElementsByTagName('LI');
7636: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7637: if (currentLis[i].className == 'goback') {
7638: currentLis[i].className = 'goback';
7639: } else {
7640: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7641: currentLis[i].className = 'right';
1.472 raeburn 7642: } else {
1.374 tempelho 7643: currentLis[i].className = 'i';
1.472 raeburn 7644: }
7645: }
1.335 ehlerst 7646: }
1.332 tempelho 7647: }
7648:
1.334 muellerd 7649: function hideAll(current, nav, data) {
1.335 ehlerst 7650: unselectInactive(nav);
1.484.2.43 raeburn 7651: if (current) {
7652: if (current.className == 'right'){
1.374 tempelho 7653: current.className = 'right active'
1.484.2.43 raeburn 7654: } else {
1.374 tempelho 7655: current.className = 'active';
1.484.2.43 raeburn 7656: }
1.374 tempelho 7657: }
1.335 ehlerst 7658: currentData = document.getElementById(data);
7659: currentDivs = currentData.getElementsByTagName('DIV');
7660: for (i = 0; i < currentDivs.length; i++) {
7661: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7662: currentDivs[i].style.display = 'none';
1.330 tempelho 7663: }
7664: }
1.335 ehlerst 7665: }
1.330 tempelho 7666:
1.374 tempelho 7667: function openTabs(pageId) {
7668: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7669: if(tabnav.length > 2 ){
1.389 tempelho 7670: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7671: currentLis = currentNav.getElementsByTagName('LI');
7672: for(i = 0; i< currentLis.length; i++){
7673: if(currentLis[i].className == 'active') {
1.375 tempelho 7674: funcString = currentLis[i].onclick.toString();
7675: tab = funcString.split('"');
1.420 onken 7676: if(tab.length < 2) {
7677: tab = funcString.split("'");
7678: }
1.375 tempelho 7679: currentData = document.getElementById(tab[1]);
7680: currentData.style.display = 'block';
1.374 tempelho 7681: }
7682: }
7683: }
7684: }
7685:
1.334 muellerd 7686: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7687: currstate = current.className;
1.334 muellerd 7688: hideAll(current, nav, data);
1.375 tempelho 7689: openTabs(pageId);
1.334 muellerd 7690: unselectInactive(nav);
1.484.2.43 raeburn 7691: if ((currstate == 'active') || (currstate == 'right active')) {
7692: if (currstate == 'active') {
7693: current.className = '';
7694: } else {
7695: current.className = 'right';
7696: }
7697: activeTab = '';
7698: toggleUpload();
7699: toggleMap();
7700: resize_scrollbox('contentscroll','1','0');
7701: return;
7702: } else {
7703: current.className = 'active';
7704: }
1.330 tempelho 7705: currentData = document.getElementById(pageId);
7706: currentData.style.display = 'block';
1.458 raeburn 7707: activeTab = pageId;
1.484.2.12 raeburn 7708: toggleUpload();
1.484.2.14 raeburn 7709: toggleMap();
1.433 raeburn 7710: if (nav == 'mainnav') {
7711: var storedpath = "$docs_folderpath";
1.434 raeburn 7712: var storedpage = "$main_container_page";
1.433 raeburn 7713: var reg = new RegExp("^supplemental");
7714: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7715: if (storedpage == 1) {
7716: document.simpleedit.folderpath.value = '';
7717: document.uploaddocument.folderpath.value = '';
7718: } else {
7719: if (reg.test(storedpath)) {
7720: document.simpleedit.folderpath.value = '$toplevelmain';
7721: document.uploaddocument.folderpath.value = '$toplevelmain';
7722: document.newext.folderpath.value = '$toplevelmain';
7723: } else {
7724: document.simpleedit.folderpath.value = storedpath;
7725: document.uploaddocument.folderpath.value = storedpath;
7726: document.newext.folderpath.value = storedpath;
7727: }
1.433 raeburn 7728: }
7729: } else {
1.434 raeburn 7730: if (reg.test(storedpath)) {
7731: document.simpleedit.folderpath.value = storedpath;
7732: document.supuploaddocument.folderpath.value = storedpath;
7733: document.supnewext.folderpath.value = storedpath;
7734: } else {
1.433 raeburn 7735: document.simpleedit.folderpath.value = '$toplevelsupp';
7736: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7737: document.supnewext.folderpath.value = '$toplevelsupp';
7738: }
7739: }
7740: }
1.484.2.3 raeburn 7741: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7742: return false;
7743: }
1.329 droeschl 7744:
1.472 raeburn 7745: function toContents(jumpto) {
7746: var newurl = '$backtourl';
1.484.2.21 raeburn 7747: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7748: newurl = newurl+'?postdata='+jumpto;
7749: }
7750: location.href=newurl;
7751: }
7752:
1.484.2.30 raeburn 7753: function togglePick(caller,value) {
7754: var disp = 'none';
7755: if (document.getElementById('multi'+caller)) {
7756: var curr = document.getElementById('multi'+caller).style.display;
7757: if (value == 1) {
7758: disp='block';
7759: }
7760: if (curr == disp) {
7761: return;
7762: }
7763: document.getElementById('multi'+caller).style.display=disp;
7764: if (value == 1) {
1.484.2.61 raeburn 7765: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7766: } else {
7767: document.getElementById('more'+caller).innerHTML = '';
7768: }
7769: if (caller == 'actions') {
7770: setClass(value);
7771: setBoxes(value);
7772: }
7773: }
7774: var showButton = multiSettings();
7775: if (showButton != 1) {
7776: showButton = multiActions();
7777: }
7778: if (document.getElementById('multisave')) {
7779: if (showButton == 1) {
7780: document.getElementById('multisave').style.display='block';
7781: } else {
7782: document.getElementById('multisave').style.display='none';
7783: }
7784: }
7785: resize_scrollbox('contentscroll','1','1');
7786: return;
7787: }
7788:
7789: function toggleCheckUncheck(caller,more) {
7790: if (more == 1) {
1.484.2.61 raeburn 7791: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7792: document.getElementById('allfields'+caller).style.display='block';
7793: } else {
1.484.2.61 raeburn 7794: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7795: document.getElementById('allfields'+caller).style.display='none';
7796: }
7797: resize_scrollbox('contentscroll','1','1');
7798: }
7799:
7800: function multiSettings() {
7801: var inuse = 0;
7802: var settingsform = document.togglemultsettings;
7803: if (settingsform.showmultpick.length > 1) {
7804: for (var i=0; i<settingsform.showmultpick.length; i++) {
7805: if (settingsform.showmultpick[i].checked) {
7806: if (settingsform.showmultpick[i].value == 1) {
7807: inuse = 1;
7808: }
7809: }
7810: }
7811: }
7812: return inuse;
7813: }
7814:
7815: function multiActions() {
7816: var inuse = 0;
7817: var actionsform = document.togglemultactions;
7818: if (actionsform.showmultpick.length > 1) {
7819: for (var i=0; i<actionsform.showmultpick.length; i++) {
7820: if (actionsform.showmultpick[i].checked) {
7821: if (actionsform.showmultpick[i].value == 1) {
7822: inuse = 1;
7823: }
7824: }
7825: }
7826: }
7827: return inuse;
7828: }
7829:
7830: function checkSubmits() {
7831: var numchanges = 0;
7832: var form = document.saveactions;
7833: var doactions = multiActions();
7834: var cutwarnings = 0;
7835: var remwarnings = 0;
1.484.2.63 raeburn 7836: var removalinfo = 0;
1.484.2.30 raeburn 7837: if (doactions == 1) {
7838: var remidxlist = document.cumulativeactions.allremoveidx.value;
7839: if ((remidxlist != '') && (remidxlist != null)) {
7840: var remidxs = remidxlist.split(',');
7841: for (var i=0; i<remidxs.length; i++) {
7842: if (document.getElementById('remove_'+remidxs[i])) {
7843: if (document.getElementById('remove_'+remidxs[i]).checked) {
7844: form.multiremove.value += remidxs[i]+',';
7845: numchanges ++;
7846: if (document.getElementById('skip_remove_'+remidxs[i])) {
7847: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7848: remwarnings ++;
7849: }
7850: }
1.484.2.63 raeburn 7851: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7852: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7853: removalinfo ++;
7854: }
7855: }
1.484.2.30 raeburn 7856: }
7857: }
7858: }
7859: }
7860: var cutidxlist = document.cumulativeactions.allcutidx.value;
7861: if ((cutidxlist != '') && (cutidxlist != null)) {
7862: var cutidxs = cutidxlist.split(',');
7863: for (var i=0; i<cutidxs.length; i++) {
7864: if (document.getElementById('cut_'+cutidxs[i])) {
7865: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7866: form.multicut.value += cutidxs[i]+',';
7867: numchanges ++;
7868: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7869: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7870: cutwarnings ++;
7871: }
7872: }
7873: }
7874: }
7875: }
7876: }
7877: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7878: if ((copyidxlist != '') && (copyidxlist != null)) {
7879: var copyidxs = copyidxlist.split(',');
7880: for (var i=0; i<copyidxs.length; i++) {
7881: if (document.getElementById('copy_'+copyidxs[i])) {
7882: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7883: form.multicopy.value += copyidxs[i]+',';
7884: numchanges ++;
7885: }
7886: }
7887: }
7888: }
7889: if (numchanges > 0) {
7890: form.multichange.value = numchanges;
7891: }
7892: }
7893: var dosettings = multiSettings();
7894: var haschanges = 0;
7895: if (dosettings == 1) {
7896: form.allencrypturl.value = '';
7897: form.allhiddenresource.value = '';
7898: form.changeparms.value = 'all';
7899: var patt=new RegExp(",\$");
7900: var allidxlist = document.cumulativesettings.allidx.value;
7901: if ((allidxlist != '') && (allidxlist != null)) {
7902: var allidxs = allidxlist.split(',');
7903: if (allidxs.length > 1) {
7904: for (var i=0; i<allidxs.length; i++) {
7905: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7906: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7907: form.allhiddenresource.value += allidxs[i]+',';
7908: }
7909: }
7910: if (document.getElementById('encrypturl_'+allidxs[i])) {
7911: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7912: form.allencrypturl.value += allidxs[i]+',';
7913: }
1.484.2.29 raeburn 7914: }
7915: }
1.484.2.30 raeburn 7916: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7917: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7918: }
7919: }
7920: form.allrandompick.value = '';
7921: form.allrandomorder.value = '';
7922: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7923: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7924: var allmapidxs = allmapidxlist.split(',');
7925: for (var i=0; i<allmapidxs.length; i++) {
7926: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7927: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7928: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7929: if ((randompick.checked) && (rpicknum.value != '')) {
7930: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7931: }
7932: if (randorder.checked) {
7933: form.allrandomorder.value += allmapidxs[i]+',';
7934: }
7935: }
7936: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7937: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7938: }
7939: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7940: haschanges = 1;
7941: }
7942: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7943: haschanges = 1;
7944: }
7945: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7946: haschanges = 1;
7947: }
7948: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7949: haschanges = 1;
7950: }
7951: }
7952: if (doactions == 1) {
7953: if (numchanges > 0) {
1.484.2.63 raeburn 7954: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7955: if (remwarnings > 0) {
1.484.2.61 raeburn 7956: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7957: return false;
7958: }
7959: }
1.484.2.63 raeburn 7960: if (removalinfo > 0) {
7961: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7962: return false;
7963: }
7964: }
1.484.2.30 raeburn 7965: if (cutwarnings > 0) {
1.484.2.61 raeburn 7966: 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 7967: return false;
1.484.2.29 raeburn 7968: }
7969: }
7970: }
1.484.2.30 raeburn 7971: form.submit();
7972: return true;
7973: }
7974: }
7975: if (dosettings == 1) {
7976: if (haschanges == 1) {
7977: form.submit();
7978: return true;
1.484.2.29 raeburn 7979: }
7980: }
1.484.2.30 raeburn 7981: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7982: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7983: } else {
7984: if (dosettings == 1) {
1.484.2.61 raeburn 7985: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7986: } else {
1.484.2.61 raeburn 7987: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7988: }
7989: }
7990: return false;
7991: }
7992:
7993: function setClass(value) {
7994: var cutclass = 'LC_docs_cut';
7995: var copyclass = 'LC_docs_copy';
7996: var removeclass = 'LC_docs_remove';
7997: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7998: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7999: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8000: var links = document.getElementsByTagName('a');
8001: for (var i=0; i<links.length; i++) {
8002: var classes = links[i].className;
8003: if (cutreg.test(classes)) {
8004: links[i].className = cutclass;
8005: if (value == 1) {
8006: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 8007: }
1.484.2.30 raeburn 8008: } else {
8009: if (copyreg.test(classes)) {
8010: links[i].className = copyclass;
8011: if (value == 1) {
8012: links[i].className += " LC_menubuttons_link";
8013: }
8014: } else {
8015: if (removereg.test(classes)) {
8016: links[i].className = removeclass;
8017: if (value == 1) {
8018: links[i].className += " LC_menubuttons_link";
8019: }
8020: }
1.484.2.29 raeburn 8021: }
8022: }
8023: }
1.484.2.30 raeburn 8024: return;
1.484.2.29 raeburn 8025: }
8026:
1.484.2.30 raeburn 8027: function setBoxes(value) {
8028: var remidxlist = document.cumulativeactions.allremoveidx.value;
8029: if ((remidxlist != '') && (remidxlist != null)) {
8030: var remidxs = remidxlist.split(',');
8031: for (var i=0; i<remidxs.length; i++) {
8032: if (document.getElementById('remove_'+remidxs[i])) {
8033: var item = document.getElementById('remove_'+remidxs[i]);
8034: if (value == 1) {
8035: item.className = 'LC_docs_remove';
8036: } else {
8037: item.className = 'LC_hidden';
8038: }
8039: }
1.484.2.29 raeburn 8040: }
8041: }
1.484.2.30 raeburn 8042: var cutidxlist = document.cumulativeactions.allcutidx.value;
8043: if ((cutidxlist != '') && (cutidxlist != null)) {
8044: var cutidxs = cutidxlist.split(',');
8045: for (var i=0; i<cutidxs.length; i++) {
8046: if (document.getElementById('cut_'+cutidxs[i])) {
8047: var item = document.getElementById('cut_'+cutidxs[i]);
8048: if (value == 1) {
8049: item.className = 'LC_docs_cut';
8050: } else {
8051: item.className = 'LC_hidden';
8052: }
8053: }
8054: }
8055: }
8056: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8057: if ((copyidxlist != '') && (copyidxlist != null)) {
8058: var copyidxs = copyidxlist.split(',');
8059: for (var i=0; i<copyidxs.length; i++) {
8060: if (document.getElementById('copy_'+copyidxs[i])) {
8061: var item = document.getElementById('copy_'+copyidxs[i]);
8062: if (value == 1) {
8063: item.className = 'LC_docs_copy';
8064: } else {
8065: item.className = 'LC_hidden';
8066: }
8067: }
1.484.2.29 raeburn 8068: }
8069: }
8070: return;
8071: }
8072:
1.484.2.67 raeburn 8073: ENDSCRIPT
1.329 droeschl 8074: }
1.457 raeburn 8075:
1.483 raeburn 8076: sub history_tab_js {
8077: return <<"ENDHIST";
8078: function toggleHistoryDisp(choice) {
8079: document.docslogform.docslog.value = choice;
8080: document.docslogform.submit();
8081: return;
8082: }
8083:
8084: ENDHIST
8085: }
8086:
1.484 raeburn 8087: sub inject_data_js {
8088: return <<ENDINJECT;
8089:
8090: function injectData(current, hiddenField, name, value) {
8091: currentElement = document.getElementById(hiddenField);
8092: currentElement.name = name;
8093: currentElement.value = value;
8094: current.submit();
8095: }
8096:
8097: ENDINJECT
8098: }
8099:
8100: sub dump_switchserver_js {
8101: my @hosts = @_;
1.484.2.61 raeburn 8102: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 8103: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8104: swit => 'Switch server?',
1.484.2.61 raeburn 8105: );
8106: my %html_js_lt = &Apache::lonlocal::texthash(
8107: swit => 'Switch server?',
1.484.2.43 raeburn 8108: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8109: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8110: chos => 'Choose server',
8111: );
1.484.2.61 raeburn 8112: &js_escape(\%js_lt);
8113: &html_escape(\%html_js_lt);
8114: &js_escape(\%html_js_lt);
1.484 raeburn 8115: my $role = $env{'request.role'};
8116: my $js = <<"ENDSWJS";
8117: <script type="text/javascript">
8118: function write_switchserver() {
8119: var server;
8120: if (document.setserver.posshosts.length > 0) {
8121: for (var i=0; i<document.setserver.posshosts.length; i++) {
8122: if (document.setserver.posshosts[i].checked) {
8123: server = document.setserver.posshosts[i].value;
8124: }
8125: }
8126: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8127: }
8128: window.close();
8129: }
8130: </script>
8131:
8132: ENDSWJS
8133:
8134: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8135: {'only_body' => 1,
8136: 'js_ready' => 1,});
8137: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8138:
8139: my $hostpicker;
8140: my $count = 0;
8141: foreach my $host (sort(@hosts)) {
8142: my $checked;
8143: if ($count == 0) {
8144: $checked = ' checked="checked"';
8145: }
8146: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8147: $host.'"'.$checked.' />'.$host.'</label> ';
8148: $count++;
8149: }
8150:
8151: return <<"ENDSWITCHJS";
8152:
8153: function dump_needs_switchserver(url) {
8154: if (url!='' && url!= null) {
1.484.2.61 raeburn 8155: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8156: go(url);
8157: }
8158: }
8159: return;
8160: }
8161:
8162: function choose_switchserver_window() {
8163: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8164: newWindow.document.open();
8165: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 8166: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8167: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8168: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8169: '<form name="setserver" method="post" action="" \\/>\\n'+
8170: '$hostpicker\\n'+
8171: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 8172: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8173: 'onclick="write_switchserver();" \\/>\\n'+
8174: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8175: newWindow.document.writeln('$endpage');
8176: newWindow.document.close();
8177: newWindow.focus();
8178: }
8179:
8180: ENDSWITCHJS
8181: }
8182:
8183: sub makedocslogform {
8184: my ($formelems,$docslog) = @_;
8185: return <<"LOGSFORM";
8186: <form action="/adm/coursedocs" method="post" name="docslogform">
8187: <input type="hidden" name="docslog" value="$docslog" />
8188: $formelems
8189: </form>
8190: LOGSFORM
8191: }
8192:
8193: sub makesimpleeditform {
8194: my ($formelems) = @_;
8195: return <<"SIMPFORM";
8196: <form name="simpleedit" method="post" action="/adm/coursedocs">
8197: <input type="hidden" name="importdetail" value="" />
8198: $formelems
8199: </form>
8200: SIMPFORM
8201: }
8202:
1.329 droeschl 8203: 1;
8204: __END__
8205:
8206:
8207: =head1 NAME
8208:
8209: Apache::londocs.pm
8210:
8211: =head1 SYNOPSIS
8212:
8213: This is part of the LearningOnline Network with CAPA project
8214: described at http://www.lon-capa.org.
8215:
8216: =head1 SUBROUTINES
8217:
8218: =over
8219:
8220: =item %help=()
8221:
8222: Available help topics
8223:
8224: =item mapread()
8225:
1.344 bisitz 8226: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8227: @order and @resources, determines status
8228: sets @order - pointer to resources in right order
8229: sets @resources - array with the resources with correct idx
8230:
8231: =item authorhosts()
8232:
8233: Return hash with valid author names
8234:
8235: =item clean()
8236:
8237: =item dumpcourse()
8238:
8239: Actually dump course
8240:
8241: =item group_import()
8242:
8243: Imports the given (name, url) resources into the course
8244: coursenum, coursedom, and folder must precede the list
8245:
8246: =item breadcrumbs()
8247:
8248: =item log_docs()
8249:
8250: =item docs_change_log()
8251:
8252: =item update_paste_buffer()
8253:
8254: =item print_paste_buffer()
8255:
8256: =item do_paste_from_buffer()
8257:
1.484.2.30 raeburn 8258: =item do_buffer_empty()
8259:
8260: =item clear_from_buffer()
8261:
1.484.2.7 raeburn 8262: =item get_newmap_url()
8263:
8264: =item dbcopy()
8265:
8266: =item uniqueness_check()
8267:
8268: =item contained_map_check()
8269:
8270: =item url_paste_fixups()
8271:
8272: =item apply_fixups()
8273:
8274: =item copy_dependencies()
8275:
1.329 droeschl 8276: =item update_parameter()
8277:
8278: =item handle_edit_cmd()
8279:
8280: =item editor()
8281:
8282: =item process_file_upload()
8283:
8284: =item process_secondary_uploads()
8285:
8286: =item is_supplemental_title()
8287:
8288: =item entryline()
8289:
8290: =item tiehash()
8291:
8292: =item untiehash()
8293:
8294: =item checkonthis()
8295:
8296: check on this
8297:
8298: =item verifycontent()
8299:
8300: Verify Content
8301:
1.484.2.78 raeburn 8302: =item devalidateversioncache()
8303:
8304: =item checkversions()
1.329 droeschl 8305:
8306: Check Versions
8307:
8308: =item mark_hash_old()
8309:
8310: =item is_hash_old()
8311:
8312: =item changewarning()
8313:
8314: =item init_breadcrumbs()
8315:
8316: Breadcrumbs for special functions
8317:
1.484 raeburn 8318: =item create_list_elements()
8319:
8320: =item create_form_ul()
8321:
8322: =item startContentScreen()
8323:
8324: =item endContentScreen()
8325:
8326: =item supplemental_base()
8327:
8328: =item embedded_form_elems()
8329:
8330: =item embedded_destination()
8331:
8332: =item return_to_editor()
8333:
8334: =item decompression_info()
8335:
8336: =item decompression_phase_one()
8337:
8338: =item decompression_phase_two()
8339:
8340: =item remove_archive()
8341:
8342: =item generate_admin_menu()
8343:
8344: =item generate_edit_table()
8345:
8346: =item editing_js()
8347:
8348: =item history_tab_js()
8349:
8350: =item inject_data_js()
8351:
8352: =item dump_switchserver_js()
8353:
1.484.2.3 raeburn 8354: =item resize_scrollbox_js()
1.484 raeburn 8355:
8356: =item makedocslogform()
8357:
1.484.2.3 raeburn 8358: =item makesimpleeditform()
8359:
1.329 droeschl 8360: =back
8361:
8362: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>