Annotation of loncom/interface/londocs.pm, revision 1.703
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.703 ! raeburn 4: # $Id: londocs.pm,v 1.702 2023/07/11 22:24:29 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.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.606 raeburn 46: use Apache::lonhomework();
47: use Apache::lonpublisher();
1.651 raeburn 48: use Apache::loncourserespicker();
1.329 droeschl 49: use HTML::Entities;
1.488 raeburn 50: use HTML::TokeParser;
1.329 droeschl 51: use GDBM_File;
1.578 raeburn 52: use File::MMagic;
1.606 raeburn 53: use File::Copy;
1.329 droeschl 54: use Apache::lonlocal;
55: use Cwd;
1.643 raeburn 56: use UUID::Tiny ':std';
1.329 droeschl 57: use LONCAPA qw(:DEFAULT :match);
58:
59: my $iconpath;
60:
61: my %hash;
62:
63: my $hashtied;
64: my %alreadyseen=();
65:
66: my $hadchanges;
1.557 raeburn 67: my $suppchanges;
1.329 droeschl 68:
69:
70: my %help=();
71:
72:
73: sub mapread {
74: my ($coursenum,$coursedom,$map)=@_;
75: return
76: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
77: $map);
78: }
79:
80: sub storemap {
1.492 raeburn 81: my ($coursenum,$coursedom,$map,$contentchg)=@_;
82: my $report;
83: if (($contentchg) && ($map =~ /^default/)) {
84: $report = 1;
85: }
1.329 droeschl 86: my ($outtext,$errtext)=
87: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 88: $map,1,$report);
1.329 droeschl 89: if ($errtext) { return ($errtext,2); }
1.364 bisitz 90:
1.557 raeburn 91: if ($map =~ /^default/) {
92: $hadchanges=1;
1.682 raeburn 93: } elsif ($contentchg) {
1.557 raeburn 94: $suppchanges=1;
95: }
1.329 droeschl 96: return ($errtext,0);
97: }
98:
99:
100:
101: sub authorhosts {
102: my %outhash=();
103: my $home=0;
104: my $other=0;
105: foreach my $key (keys(%env)) {
106: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
107: my $role=$1;
108: my $realm=$2;
109: my ($start,$end)=split(/\./,$env{$key});
110: if (($start) && ($start>time)) { next; }
111: if (($end) && (time>$end)) { next; }
112: my ($ca,$cd);
113: if ($1 eq 'au') {
114: $ca=$env{'user.name'};
115: $cd=$env{'user.domain'};
116: } else {
117: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
118: }
119: my $allowed=0;
120: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
121: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 122: foreach my $id (@ids) {
123: if ($id eq $myhome) {
124: $allowed=1;
125: last;
126: }
127: }
1.329 droeschl 128: if ($allowed) {
129: $home++;
1.484 raeburn 130: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 131: } else {
1.484 raeburn 132: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 133: $other++;
134: }
135: }
136: }
137: return ($home,$other,%outhash);
138: }
139:
140:
141: sub clean {
142: my ($title)=@_;
143: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 144: return $title;
1.329 droeschl 145: }
146:
1.617 raeburn 147: sub default_folderpath {
148: my ($coursenum,$coursedom,$navmapref) = @_;
149: return unless ($coursenum && $coursedom && ref($navmapref));
150: # Check if entire course is hidden and/or encrypted
151: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
152: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
153: unless (ref($$navmapref)) {
154: $$navmapref = Apache::lonnavmaps::navmap->new();
155: }
156: if (ref($$navmapref)) {
157: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
158: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
159: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
160: unless (@resources) {
161: $hiddenmap = 1;
162: unless ($env{'request.role.adv'}) {
163: $hiddentop = 1;
164: if ($env{'form.folder'}) {
165: undef($env{'form.folder'});
166: }
167: }
168: }
169: }
170: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
171: $encryptmap = 1;
172: }
173: }
174: unless ($hiddentop) {
175: $folderpath='default&'.&escape(&mt('Main Content')).
176: '::'.$hiddenmap.':'.$encryptmap.'::';
177: }
178: if (wantarray) {
179: return ($folderpath,$hiddentop);
180: } else {
181: return $folderpath;
182: }
183: }
1.329 droeschl 184:
1.685 raeburn 185: sub validate_supppath {
186: my ($coursenum,$coursedom) = @_;
187: my $backto;
1.677 raeburn 188: if ($env{'form.supppath'} ne '') {
189: my @items = split(/\&/,$env{'form.supppath'});
1.685 raeburn 190: my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
1.677 raeburn 191: for (my $i=0; $i<@items; $i++) {
192: my $odd = $i%2;
193: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
194: $badpath = 1;
1.685 raeburn 195: last;
196: } elsif ($odd) {
197: my $suffix;
198: my $idx = $i-1;
199: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
200: $backto .= '&'.$1;
201: } elsif ($items[$idx] eq 'supplemental') {
202: $backto .= '&'.$items[$i];
203: } else {
204: $backto .= '&'.$items[$i];
205: my $is_hidden;
206: unless ($got_supp) {
1.688 raeburn 207: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 208: if (ref($supplemental) eq 'HASH') {
209: if (ref($supplemental->{'hidden'}) eq 'HASH') {
210: %supphidden = %{$supplemental->{'hidden'}};
211: }
212: if (ref($supplemental->{'ids'}) eq 'HASH') {
213: %suppids = %{$supplemental->{'ids'}};
214: }
215: }
216: $got_supp = 1;
217: }
218: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
219: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
220: if ($supphidden{$mapid}) {
221: $is_hidden = 1;
222: }
223: }
224: $suffix = '::'.$is_hidden.':::';
225: }
226: $supppath .= '&'.$items[$i].$suffix;
227: } else {
228: $supppath .= '&'.$items[$i];
229: $backto .= '&'.$items[$i];
1.677 raeburn 230: }
231: }
232: if ($badpath) {
233: delete($env{'form.supppath'});
1.685 raeburn 234: } else {
235: $supppath =~ s/^\&//;
236: $backto =~ s/^\&//;
237: $env{'form.supppath'} = $supppath;
1.677 raeburn 238: }
239: }
1.685 raeburn 240: return $backto;
1.677 raeburn 241: }
242:
1.329 droeschl 243: sub dumpcourse {
244: my ($r) = @_;
1.408 raeburn 245: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 246: my ($starthash,$js);
247: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
248: $js = <<"ENDJS";
249: <script type="text/javascript">
250: // <![CDATA[
251:
252: function hide_searching() {
253: if (document.getElementById('searching')) {
254: document.getElementById('searching').style.display = 'none';
255: }
256: return;
257: }
258:
259: // ]]>
260: </script>
261: ENDJS
262: $starthash = {
263: add_entries => {'onload' => "hide_searching();"},
264: };
265: }
1.568 raeburn 266: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
267: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 268: $r->print(&startContentScreen('tools'));
1.329 droeschl 269: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 270: unless ($home) {
271: $r->print(&endContentScreen());
272: return '';
273: }
1.329 droeschl 274: my $origcrsid=$env{'request.course.id'};
275: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
276: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
277: # Do the dumping
1.484 raeburn 278: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
279: $r->print(&endContentScreen());
280: return '';
281: }
1.531 raeburn 282: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 283: $r->print('<h3>'.&mt('Copying Files').'</h3>');
284: my $title=$env{'form.authorfolder'};
285: $title=&clean($title);
1.567 raeburn 286: my ($navmap,$errormsg) =
287: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
288: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
289: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
290: my (%maps,%resources,%titles);
291: if (!ref($navmap)) {
292: $r->print($errormsg.
293: &endContentScreen());
294: return '';
295: } else {
296: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
297: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 298: }
1.567 raeburn 299: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
300: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
301: %newcontent,%has_simpleprobs);
302: foreach my $item (sort {$a <=> $b} (@todump)) {
303: my $name = $env{'form.namefor_'.$item};
304: if ($resources{$item}) {
305: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
306: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
307: $tocopy{$1} = $name;
308: $display{$item} = $1;
309: $lookup{$1} = $item;
310: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
311: $simpleproblems{$item} = {
312: symb => $resources{$item},
313: name => $name,
314: };
315: $display{$item} = 'simpleproblem_'.$name;
316: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
317: $has_simpleprobs{$1}{$id} = $item;
318: }
319: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
320: my $marker = $1;
321: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
322: $simplepages{$item} = {
323: res => $res,
324: title => $titles{$item},
325: db => $db_name,
326: marker => $marker,
327: symb => $resources{$item},
328: name => $name,
329: };
330: $display{$item} = '/'.$res;
331: }
332: } elsif ($maps{$item}) {
333: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
334: $tocopy{$1} = $name;
335: $display{$item} = $1;
336: $lookup{$1} = $item;
337: }
338: } else {
339: next;
340: }
341: }
1.329 droeschl 342: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
343: $crs=~s/\_/\//g;
1.567 raeburn 344: my $mm = new File::MMagic;
345: my $prefix = "/uploaded/$cdom/$cnum/";
346: %replacehash = %tocopy;
347: foreach my $item (sort(keys(%simpleproblems))) {
348: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
349: $newcontent{$display{$item}} = $content;
350: }
351: my $gateway = Apache::lonhtmlgateway->new('web');
352: foreach my $item (sort(keys(%simplepages))) {
353: if (ref($simplepages{$item}) eq 'HASH') {
354: my $pagetitle = $simplepages{$item}{'title'};
355: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
356: my %contents;
357: foreach my $field (keys(%fields)) {
358: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
359: my $name = $1;
360: my $msg = $fields{$field};
361: if ($name eq 'webreferences') {
362: if ($msg =~ m{^https?://}) {
363: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
364: }
365: } else {
366: $msg = &Encode::decode('utf8',$msg);
367: $msg = $gateway->process_outgoing_html($msg,1);
368: $contents{$name} = $msg;
369: }
370: } elsif ($field eq 'uploaded.photourl') {
371: my $marker = $simplepages{$item}{marker};
372: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
373: my $filepath = $1;
374: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
375: if ($fname ne '') {
376: $fname=~s/\.(\w+)$//;
377: my $ext=$1;
378: $fname = &clean($fname);
379: $fname.='.'.$ext;
380: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
381: $replacehash{$filepath} = $relpath.$fname;
382: $deps{$item}{$filepath} = 1;
383: }
384: }
385: }
386: }
387: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
388: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
389: my $content = '
390: <html>
391: <head>
392: <title>'.$pagetitle.'</title>
393: </head>
394: <body bgcolor="#ffffff">';
395: if ($contents{title}) {
396: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
397: }
398: if ($contents{image}) {
399: $content .= "\n".$contents{image};
400: }
401: if ($contents{content}) {
402: $content .= '
403: <div class="LC_Box">
1.577 bisitz 404: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 405: $contents{content}.'
406: </div>';
407: }
408: if ($contents{webreferences}) {
409: $content .= '
410: <div class="LC_Box">
1.577 bisitz 411: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 412: $contents{webreferences}.'
413: </div>';
414: }
415: $content .= '
416: </body>
417: </html>
418: ';
419: $newcontent{'/'.$simplepages{$item}{res}} = $content;
420: }
421: }
422: foreach my $item (keys(%tocopy)) {
423: unless ($item=~/\.(sequence|page)$/) {
424: my $currurlpath = $prefix.$item;
425: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
426: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
427: }
428: }
429: foreach my $num (sort {$a <=> $b} (@todump)) {
430: my $src = $display{$num};
431: next if ($src eq '');
432: my @needcopy = ();
433: if ($replacehash{$src}) {
434: push(@needcopy,$src);
435: if (ref($deps{$num}) eq 'HASH') {
436: foreach my $dep (sort(keys(%{$deps{$num}}))) {
437: if ($replacehash{$dep}) {
438: push(@needcopy,$dep);
439: }
440: }
441: }
442: } elsif ($src =~ /^simpleproblem_/) {
443: push(@needcopy,$src);
444: }
445: next if (@needcopy == 0);
446: my ($result,$depresult);
447: for (my $i=0; $i<@needcopy; $i++) {
448: my $item = $needcopy[$i];
449: my $newfilename;
450: if ($simpleproblems{$num}) {
451: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
452: } else {
453: $newfilename=$title.'/'.$replacehash{$item};
454: }
455: $newfilename=~s/\.(\w+)$//;
456: my $ext=$1;
457: $newfilename=&clean($newfilename);
458: $newfilename.='.'.$ext;
459: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
460: if ($newrelpath ne $replacehash{$item}) {
461: $replacehash{$item} = $newrelpath;
462: }
463: my @dirs=split(/\//,$newfilename);
464: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
465: my $makepath=$path;
466: my $fail;
467: my $origin;
468: for (my $i=0;$i<$#dirs;$i++) {
469: $makepath.='/'.$dirs[$i];
470: unless (-e $makepath) {
471: unless(mkdir($makepath,0755)) {
472: $fail = &mt('Directory creation failed.');
473: }
474: }
475: }
476: if ($i == 0) {
477: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
478: } else {
479: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
480: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
481: &mt('(dependency)').'</span>: ';
482: }
483: if (-e $path.'/'.$newfilename) {
484: $fail = &mt('Destination already exists -- not overwriting.');
485: } else {
486: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
487: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
488: ($item =~ /^simpleproblem_/)) {
489: print $fh $newcontent{$item};
490: } else {
491: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
492: if (-e $fileloc) {
493: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
494: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
495: (ref($has_simpleprobs{$item}) eq 'HASH')) {
496: my %changes = %{$has_simpleprobs{$item}};
497: my $content = &Apache::lonclonecourse::rewritefile(
498: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
499: (%replacehash,$crs => '')
500: );
501: my $updatedcontent = '';
502: my $parser = HTML::TokeParser->new(\$content);
503: $parser->attr_encoded(1);
504: while (my $token = $parser->get_token) {
505: if ($token->[0] eq 'S') {
506: if (($token->[1] eq 'resource') &&
507: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
508: ($changes{$token->[2]->{'id'}})) {
509: my $id = $token->[2]->{'id'};
510: $updatedcontent .= '<'.$token->[1];
511: foreach my $attrib (@{$token->[3]}) {
512: next unless ($attrib =~ /^(src|type|title|id)$/);
513: if ($attrib eq 'src') {
514: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
515: if ($file) {
516: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
517: } else {
518: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
519: }
520: } else {
521: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
522: }
523: }
524: $updatedcontent .= ' />'."\n";
525: } else {
526: $updatedcontent .= $token->[4]."\n";
527: }
528: } else {
529: $updatedcontent .= $token->[2];
530: }
531: }
532: print $fh $updatedcontent;
533: } else {
534: print $fh &Apache::lonclonecourse::rewritefile(
535: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
536: (%replacehash,$crs => '')
537: );
538: }
539: } else {
540: print $fh
541: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
542: }
543: } else {
544: $fail = &mt('Source does not exist.');
545: }
546: }
547: $fh->close();
548: } else {
549: $fail = &mt('Could not write to destination.');
550: }
551: }
552: my $text;
553: if ($fail) {
554: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
555: } else {
556: $text = '<span class="LC_success">'.&mt('ok').'</span>';
557: }
558: if ($i == 0) {
559: $result .= $text;
560: } else {
561: $depresult .= $text.'</li>';
562: }
563: }
564: $r->print($result);
565: if ($depresult) {
566: $r->print('<ul>'.$depresult.'</ul>');
567: }
568: }
569: } else {
570: my ($navmap,$errormsg) =
571: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
572: if (!ref($navmap)) {
573: $r->print($errormsg);
574: } else {
575: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
576: $r->rflush();
577: my ($preamble,$formname);
578: $formname = 'dumpdoc';
579: unless ($home==1) {
580: $preamble = '<div class="LC_left_float">'.
581: '<fieldset><legend>'.
582: &mt('Select the Authoring Space').
583: '</legend><select name="authorspace">';
1.329 droeschl 584: }
1.567 raeburn 585: my @orderspaces = ();
586: foreach my $key (sort(keys(%outhash))) {
587: if ($key=~/^home_(.+)$/) {
588: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
589: unshift(@orderspaces,$1);
590: } else {
591: push(@orderspaces,$1);
592: }
593: }
594: }
1.569 raeburn 595: if ($home>1) {
596: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
597: }
1.567 raeburn 598: foreach my $user (@orderspaces) {
1.329 droeschl 599: if ($home==1) {
1.567 raeburn 600: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 601: } else {
1.567 raeburn 602: $preamble .= '<option value="'.$user.'">'.$user.' - '.
603: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
604: }
1.329 droeschl 605: }
1.567 raeburn 606: unless ($home==1) {
607: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 608: }
1.567 raeburn 609: my $title=$origcrsdata{'description'};
610: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 611: $title=&clean($title);
1.567 raeburn 612: $preamble .= '<div class="LC_left_float">'.
613: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
614: '<input type="text" size="50" name="authorfolder" value="'.
615: $title.'" />'.
616: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
617: my %uploadedfiles;
618: &tiehash();
619: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
620: my ($ext)=($file=~/\.(\w+)$/);
621: # FIXME Check supplemental here
622: my $title=$hash{'title_'.$hash{
623: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
624: if (!$title) {
625: $title=$file;
626: } else {
627: $title=~s|/|_|g;
628: }
629: $title=~s/\.(\w+)$//;
630: $title=&clean($title);
631: $title.='.'.$ext;
632: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
633: $uploadedfiles{$file} = $title;
634: }
635: &untiehash();
636: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
637: undef,undef,$preamble,$home,\%uploadedfiles));
638: }
1.329 droeschl 639: }
1.484 raeburn 640: $r->print(&endContentScreen());
1.329 droeschl 641: }
642:
1.567 raeburn 643: sub recurse_html {
644: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
645: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
646: my (%allfiles,%codebase);
647: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
648: if (keys(%allfiles)) {
649: foreach my $dependency (keys(%allfiles)) {
650: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
651: my ($depurl,$relfile,$newcontainer);
652: if ($dependency =~ m{^/}) {
653: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
654: $relfile = $1;
655: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
656: $newcontainer = $1;
657: next if ($replacehash->{$newcontainer});
658: }
659: $depurl = $dependency;
660: } else {
661: next;
662: }
663: } else {
664: $relfile = $dependency;
665: $depurl = $currurlpath;
1.630 raeburn 666: $depurl =~ s{[^/]+$}{};
1.567 raeburn 667: $depurl .= $dependency;
1.630 raeburn 668: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 669: }
670: next if ($relfile eq '');
671: my $newname = $replacehash->{$container};
672: $newname =~ s{[^/]+$}{};
673: $replacehash->{$newcontainer} = $newname.$relfile;
674: $deps->{$item}{$newcontainer} = 1;
675: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
676: my $depfile = &Apache::lonnet::filelocation('',$depurl);
677: my $type = $mm->checktype_filename($depfile);
678: if ($type eq 'text/html') {
679: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
680: }
681: }
682: }
683: }
684: return;
685: }
686:
1.329 droeschl 687: sub group_import {
1.598 raeburn 688: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 689: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
690: %removeparam,$importuploaded,$fixuperrors);
691: $allmaps = {};
1.329 droeschl 692: while (@files) {
693: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 694: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 695: && ($caller eq 'londocs')
696: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 697:
1.329 droeschl 698: my $errtext = '';
699: my $fatal = 0;
700: my $newmapstr = '<map>'."\n".
701: '<resource id="1" src="" type="start"></resource>'."\n".
702: '<link from="1" to="2" index="1"></link>'."\n".
703: '<resource id="2" src="" type="finish"></resource>'."\n".
704: '</map>';
705: $env{'form.output'}=$newmapstr;
706: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
707: 'output',$1.$2);
1.534 raeburn 708: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 709: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
710: $fatal = 2;
711: }
712: if ($fatal) {
713: return ($errtext,$fatal);
714: }
715: }
716: if ($url) {
1.626 raeburn 717: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 718: $url = $1;
719: my $marker = $2;
720: my $info = $3;
1.699 raeburn 721: my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.642 raeburn 722: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 723: my @toolinfo = split(/:/,$info);
724: if ($residx) {
1.604 raeburn 725: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 726: $toolid = $toolsettings{'id'};
727: } else {
1.604 raeburn 728: $toolid = shift(@toolinfo);
1.598 raeburn 729: }
1.699 raeburn 730: if ($toolid =~ /^c/) {
731: $tooltype = 'crs';
732: $toolprefix = 'c';
733: } else {
734: $tooltype = 'dom';
735: }
1.598 raeburn 736: $toolid =~ s/\D//g;
1.604 raeburn 737: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 738: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
739: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 740: foreach my $item (@extras) {
741: $toolhash{$item} = &unescape($toolhash{$item});
742: }
1.645 raeburn 743: if ($folder =~ /^supplemental/) {
1.648 raeburn 744: delete($toolhash{'gradable'});
745: } else {
746: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 747: }
1.598 raeburn 748: if (ref($ltitoolsref) eq 'HASH') {
1.699 raeburn 749: if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
750: if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
751: my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
752: my @deleted;
753: $toolhash{'id'} = $toolprefix.$toolid;
754: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
755: ($toolhash{'target'} eq 'window')) {
756: if ($toolhash{'target'} eq 'window') {
757: foreach my $item ('width','height') {
758: $toolhash{$item} =~ s/^\s+//;
759: $toolhash{$item} =~ s/\s+$//;
760: if ($toolhash{$item} =~ /\D/) {
761: delete($toolhash{$item});
762: if ($residx) {
763: if ($toolsettings{$item}) {
764: push(@deleted,$item);
765: }
1.624 raeburn 766: }
767: }
768: }
1.604 raeburn 769: }
1.699 raeburn 770: } elsif ($residx) {
771: $toolhash{'target'} = $toolsettings{'target'};
772: if ($toolhash{'target'} eq 'window') {
773: foreach my $item ('width','height') {
774: $toolhash{$item} = $toolsettings{$item};
775: }
776: }
777: } elsif (ref($tools{'display'}) eq 'HASH') {
778: $toolhash{'target'} = $tools{'display'}{'target'};
779: if ($toolhash{'target'} eq 'window') {
780: $toolhash{'width'} = $tools{'display'}{'width'};
781: $toolhash{'height'} = $tools{'display'}{'height'};
1.624 raeburn 782: }
1.604 raeburn 783: }
1.699 raeburn 784: if ($toolhash{'target'} eq 'iframe') {
785: foreach my $item ('width','height','linktext','explanation') {
786: delete($toolhash{$item});
787: if ($residx) {
788: if ($toolsettings{$item}) {
789: push(@deleted,$item);
790: }
1.624 raeburn 791: }
1.604 raeburn 792: }
1.699 raeburn 793: } elsif ($toolhash{'target'} eq 'tab') {
794: foreach my $item ('width','height') {
795: delete($toolhash{$item});
796: if ($residx) {
797: if ($toolsettings{$item}) {
798: push(@deleted,$item);
799: }
1.628 raeburn 800: }
801: }
802: }
1.699 raeburn 803: if (ref($tools{'crsconf'}) eq 'HASH') {
804: foreach my $item ('label','title','linktext','explanation') {
805: my $crsitem;
806: if (($item eq 'label') || ($item eq 'title')) {
807: $crsitem = 'crs'.$item;
808: } else {
809: $crsitem = $item;
810: }
811: if ($tools{'crsconf'}{$item}) {
812: $toolhash{$crsitem} =~ s/^\s+//;
813: $toolhash{$crsitem} =~ s/\s+$//;
814: if ($toolhash{$crsitem} eq '') {
815: delete($toolhash{$crsitem});
816: }
817: } else {
1.624 raeburn 818: delete($toolhash{$crsitem});
1.604 raeburn 819: }
1.699 raeburn 820: if (($residx) && (exists($toolsettings{$crsitem}))) {
821: unless (exists($toolhash{$crsitem})) {
822: push(@deleted,$crsitem);
823: }
824: }
1.604 raeburn 825: }
1.699 raeburn 826: }
827: if ($toolhash{'passback'}) {
828: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
829: $toolhash{'gradesecret'} = $gradesecret;
830: $toolhash{'gradesecretdate'} = time;
831: }
832: if ($toolhash{'roster'}) {
833: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
834: $toolhash{'rostersecret'} = $rostersecret;
835: $toolhash{'rostersecretdate'} = time;
836: }
837: my $changegradable;
838: if (($residx) && ($folder =~ /^default/)) {
839: if ($toolsettings{'gradable'}) {
840: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
841: push(@deleted,'gradable');
842: $changegradable = 1;
1.604 raeburn 843: }
1.699 raeburn 844: } elsif ($toolhash{'gradable'}) {
845: $changegradable = 1;
1.604 raeburn 846: }
1.699 raeburn 847: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 848: $changegradable = 1;
1.699 raeburn 849: if ($toolsettings{'gradable'}) {
850: $toolhash{'gradable'} = 1;
851: }
1.645 raeburn 852: }
1.648 raeburn 853: }
1.699 raeburn 854: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
855: if ($putres eq 'ok') {
856: if (@deleted) {
857: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648 raeburn 858: }
1.699 raeburn 859: if (($changegradable) && ($folder =~ /^default/)) {
860: my $val;
861: if ($toolhash{'gradable'}) {
862: $val = 'yes';
863: } else {
864: $val = 'no';
865: }
866: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
867: 'string_yesno');
868: &remember_parms($residx,'gradable','set',$val);
1.645 raeburn 869: }
1.699 raeburn 870: } else {
871: return (&mt('Failed to save update to external tool.'),1);
1.645 raeburn 872: }
1.604 raeburn 873: }
1.598 raeburn 874: }
875: }
876: }
1.529 raeburn 877: if (($caller eq 'londocs') &&
878: ($folder =~ /^default/)) {
1.534 raeburn 879: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 880: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
881: my $cid = $coursedom.'_'.$coursenum;
882: $allmaps =
883: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
884: $chome,$cid);
885: $donechk = 1;
886: }
887: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 888: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
889: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 890: $importuploaded = 1;
891: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
892: next if ($allmaps->{$url});
893: }
894: }
1.344 bisitz 895: if (!$residx
1.329 droeschl 896: || defined($LONCAPA::map::zombies[$residx])) {
897: $residx = &LONCAPA::map::getresidx($url,$residx);
898: push(@LONCAPA::map::order, $residx);
899: }
900: my $ext = 'false';
901: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 902: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
903: my $filepath = $1;
1.675 raeburn 904: my $fname;
905: if ($name eq '') {
906: $name = &mt('Web Page');
1.534 raeburn 907: $fname = 'web';
908: } else {
1.675 raeburn 909: $fname = $name;
910: $fname=&Apache::lonnet::clean_filename($fname);
911: if ($fname eq '') {
912: $fname = 'web';
913: } elsif (length($fname) > 15) {
914: $fname = substr($fname,0,14);
915: }
1.534 raeburn 916: }
1.675 raeburn 917: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 918: my $initialtext = &mt('Replace with your own content.');
919: my $newhtml = <<END;
1.545 raeburn 920: <html>
1.534 raeburn 921: <head>
1.675 raeburn 922: <title>$title</title>
1.534 raeburn 923: </head>
924: <body bgcolor="#ffffff">
925: $initialtext
926: </body>
927: </html>
928: END
929: $env{'form.output'}=$newhtml;
1.630 raeburn 930: my $result =
1.534 raeburn 931: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
932: 'output',
933: "$filepath/$residx/$fname.html");
934: if ($result =~ m{^/uploaded/}) {
935: $url = $result;
936: if ($filepath =~ /^supplemental/) {
937: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
938: $env{'user.domain'}.'___&&&___'.$name;
939: }
940: } else {
941: return (&mt('Failed to save new web page.'),1);
942: }
943: }
1.675 raeburn 944: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 945: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 946: $LONCAPA::map::resources[$residx] =
1.329 droeschl 947: join(':', ($name, $url, $ext, 'normal', 'res'));
948: }
949: }
1.529 raeburn 950: if ($importuploaded) {
951: my %import_errors;
952: my %updated = (
953: removefrommap => \%removefrommap,
954: removeparam => \%removeparam,
955: );
1.533 raeburn 956: my ($result,$msgsarray,$lockerror) =
957: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 958: if (keys(%import_errors) > 0) {
1.530 raeburn 959: $fixuperrors =
1.529 raeburn 960: '<p span class="LC_warning">'."\n".
961: &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".
962: '<ul>'."\n";
963: foreach my $key (sort(keys(%import_errors))) {
964: $fixuperrors .= '<li>'.$key.'</li>'."\n";
965: }
966: $fixuperrors .= '</ul></p>'."\n";
967: }
1.533 raeburn 968: if (ref($msgsarray) eq 'ARRAY') {
969: if (@{$msgsarray} > 0) {
970: $fixuperrors .= '<p class="LC_info">'.
971: join('<br />',@{$msgsarray}).
972: '</p>';
973: }
974: }
975: if ($lockerror) {
976: $fixuperrors .= '<p class="LC_error">'.
977: $lockerror.
978: '</p>';
979: }
1.529 raeburn 980: }
981: my ($errtext,$fatal) =
982: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 983: unless ($fatal) {
984: if ($folder =~ /^supplemental/) {
1.561 raeburn 985: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
986: $folder.'.'.$container);
1.557 raeburn 987: }
988: }
1.529 raeburn 989: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 990: }
991:
992: sub log_docs {
1.494 raeburn 993: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 994: }
995:
996: {
997: my @oldresources=();
998: my @oldorder=();
999: my $parmidx;
1000: my %parmaction=();
1001: my %parmvalue=();
1002: my $changedflag;
1003:
1004: sub snapshotbefore {
1005: @oldresources=@LONCAPA::map::resources;
1006: @oldorder=@LONCAPA::map::order;
1007: $parmidx=undef;
1008: %parmaction=();
1009: %parmvalue=();
1010: $changedflag=0;
1011: }
1012:
1013: sub remember_parms {
1014: my ($idx,$parameter,$action,$value)=@_;
1015: $parmidx=$idx;
1016: $parmaction{$parameter}=$action;
1017: $parmvalue{$parameter}=$value;
1018: $changedflag=1;
1019: }
1020:
1021: sub log_differences {
1022: my ($plain)=@_;
1023: my %storehash=('folder' => $plain,
1024: 'currentfolder' => $env{'form.folder'});
1025: if ($parmidx) {
1026: $storehash{'parameter_res'}=$oldresources[$parmidx];
1027: foreach my $parm (keys(%parmaction)) {
1028: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1029: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1030: }
1031: }
1032: my $maxidx=$#oldresources;
1033: if ($#LONCAPA::map::resources>$#oldresources) {
1034: $maxidx=$#LONCAPA::map::resources;
1035: }
1036: for (my $idx=0; $idx<=$maxidx; $idx++) {
1037: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1038: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1039: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1040: $changedflag=1;
1041: }
1042: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1043: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1044: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1045: $changedflag=1;
1046: }
1047: }
1048: $storehash{'maxidx'}=$maxidx;
1049: if ($changedflag) { &log_docs(\%storehash); }
1050: }
1051: }
1052:
1053: sub docs_change_log {
1.611 raeburn 1054: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 1055: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 1056: my $navmap;
1.483 raeburn 1057: my $js = '<script type="text/javascript">'."\n".
1058: '// <![CDATA['."\n".
1059: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 1060: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 1061: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 1062: &history_tab_js()."\n".
1.484 raeburn 1063: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 1064: '// ]]>'."\n".
1065: '</script>'."\n";
1.484 raeburn 1066: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1067: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1068: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1069: my %orderhash;
1070: my $container='sequence';
1071: my $pathitem;
1.519 raeburn 1072: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1073: $container='page';
1074: }
1.519 raeburn 1075: my $folderpath=$env{'form.folderpath'};
1076: if ($folderpath eq '') {
1.617 raeburn 1077: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1078: }
1.617 raeburn 1079: undef($navmap);
1.519 raeburn 1080: $pathitem = '<input type="hidden" name="folderpath" value="'.
1081: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1082: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1083: my $jumpto = $readfile;
1084: $jumpto =~ s{^/}{};
1085: my $tid = 1;
1.489 raeburn 1086: if ($supplementalflag) {
1087: $tid = 2;
1088: }
1.630 raeburn 1089: my ($breadcrumbtrail) =
1.509 raeburn 1090: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1091: $r->print($breadcrumbtrail.
1092: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1093: $readfile));
1.329 droeschl 1094: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1095: $env{'course.'.$env{'request.course.id'}.'.domain'},
1096: $env{'course.'.$env{'request.course.id'}.'.num'});
1097:
1098: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1099:
1100: my %saveable_parameters = ('show' => 'scalar',);
1101: &Apache::loncommon::store_course_settings('docs_log',
1102: \%saveable_parameters);
1103: &Apache::loncommon::restore_course_settings('docs_log',
1104: \%saveable_parameters);
1105: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1106: # FIXME: internationalization seems wrong here
1.329 droeschl 1107: my %lt=('hiddenresource' => 'Resources hidden',
1108: 'encrypturl' => 'URL hidden',
1109: 'randompick' => 'Randomly pick',
1110: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1111: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1112: 'set' => 'set to',
1113: 'del' => 'deleted');
1.484 raeburn 1114: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1115: $pathitem."\n".
1116: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1117: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1118: $r->print('<div class="LC_left_float">'.
1119: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1120: &makedocslogform($filter,1).
1121: '</fieldset></div><br clear="all" />');
1.329 droeschl 1122: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1123: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1124: &mt('After').'</th>'.
1125: &Apache::loncommon::end_data_table_header_row());
1126: my $shown=0;
1127: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1128: if ($env{'form.displayfilter'} eq 'currentfolder') {
1129: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1130: }
1131: my @changes=keys(%{$docslog{$id}{'logentry'}});
1132: if ($env{'form.displayfilter'} eq 'containing') {
1133: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1134: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1135: foreach my $key (@changes) {
1136: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1137: }
1.344 bisitz 1138: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1139: }
1140: my $count = 0;
1141: my $time =
1142: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1143: my $plainname =
1144: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1145: $docslog{$id}{'exe_udom'});
1146: my $about_me_link =
1147: &Apache::loncommon::aboutmewrapper($plainname,
1148: $docslog{$id}{'exe_uname'},
1149: $docslog{$id}{'exe_udom'});
1150: my $send_msg_link='';
1151: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1152: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1153: $send_msg_link ='<br />'.
1154: &Apache::loncommon::messagewrapper(&mt('Send message'),
1155: $docslog{$id}{'exe_uname'},
1156: $docslog{$id}{'exe_udom'});
1157: }
1158: $r->print(&Apache::loncommon::start_data_table_row());
1159: $r->print('<td>'.$time.'</td>
1160: <td>'.$about_me_link.
1161: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1162: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1163: $send_msg_link.'</td><td>'.
1164: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1165: my $is_supp = 0;
1166: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1167: $is_supp = 1;
1168: }
1.329 droeschl 1169: # Before
1170: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1171: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1172: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1173: if ($oldname ne $newname) {
1.488 raeburn 1174: my $shown = &LONCAPA::map::qtescape($oldname);
1175: if ($is_supp) {
1176: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1177: }
1178: $r->print($shown);
1.329 droeschl 1179: }
1180: }
1181: $r->print('<ul>');
1182: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1183: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1184: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1185: if ($is_supp) {
1186: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1187: }
1188: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1189: }
1190: }
1191: $r->print('</ul>');
1192: # After
1193: $r->print('</td><td>');
1194:
1195: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1196: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1197: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1198: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1199: my $shown = &LONCAPA::map::qtescape($newname);
1200: if ($is_supp) {
1201: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1202: }
1203: $r->print($shown);
1.329 droeschl 1204: }
1.364 bisitz 1205: }
1.329 droeschl 1206: $r->print('<ul>');
1207: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1208: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1209: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1210: if ($is_supp) {
1211: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1212: }
1213: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1214: }
1215: }
1216: $r->print('</ul>');
1217: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 1218: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1219: if ($title eq '') {
1220: ($title) = ($url =~ m{/([^/]+)$});
1.695 raeburn 1221: } elsif ($is_supp) {
1222: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 1223: }
1224: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 1225: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1226: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1227: # FIXME: internationalization seems wrong here
1.329 droeschl 1228: $r->print('<li>'.
1229: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1230: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1231: .'</li>');
1232: }
1233: }
1234: $r->print('</ul>');
1235: }
1236: # End
1237: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1238: $shown++;
1239: if (!($env{'form.show'} eq &mt('all')
1240: || $shown<=$env{'form.show'})) { last; }
1241: }
1.484 raeburn 1242: $r->print(&Apache::loncommon::end_data_table()."\n".
1243: &makesimpleeditform($pathitem)."\n".
1244: '</div></div>');
1245: $r->print(&endContentScreen());
1.329 droeschl 1246: }
1247:
1248: sub update_paste_buffer {
1.492 raeburn 1249: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1250: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1251: if ($env{'form.multiremove'}) {
1252: $env{'form.multiremove'} =~ s/,$//;
1253: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1254: }
1255: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1256: if ($env{'form.multicut'}) {
1257: $env{'form.multicut'} =~ s/,$//;
1258: foreach my $item (split(/,/,$env{'form.multicut'})) {
1259: unless ($removals{$item}) {
1260: $cuts{$item} = 1;
1261: push(@possibles,$item.':cut');
1262: }
1263: }
1264: }
1265: if ($env{'form.multicopy'}) {
1266: $env{'form.multicopy'} =~ s/,$//;
1267: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1268: unless ($removals{$item} || $cuts{$item}) {
1269: push(@possibles,$item.':copy');
1270: }
1271: }
1272: }
1273: } elsif ($env{'form.markcopy'}) {
1274: @possibles = split(/,/,$env{'form.markcopy'});
1275: }
1.329 droeschl 1276:
1.538 raeburn 1277: return if (@possibles == 0);
1.329 droeschl 1278: return if (!defined($env{'form.copyfolder'}));
1279:
1280: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1281: $env{'form.copyfolder'});
1.538 raeburn 1282: return if ($fatal);
1283:
1284: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1285:
1.538 raeburn 1286: # Retrieve current paste buffer suffixes.
1287: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1288: my (%pasteurls,@newpaste);
1289:
1290: # Construct identifiers for current contents of user's paste buffer
1291: if (@currpaste) {
1292: foreach my $suffix (@currpaste) {
1.667 raeburn 1293: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1294: my $url = $env{'docs.markedcopy_url_'.$suffix};
1295: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1296: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1297: ($url ne '')) {
1298: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1299: $pasteurls{$cid.'_'.$mapidx} = 1;
1300: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1301: $pasteurls{$url} = 1;
1302: } else {
1.669 raeburn 1303: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 1304: }
1305: }
1.538 raeburn 1306: }
1307: }
1308:
1309: # Mark items for copying (skip any items already in user's paste buffer)
1310: my %addtoenv;
1.597 raeburn 1311:
1312: my @pathitems = split(/\&/,$env{'form.folderpath'});
1313: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 1314: my $ispage = $folderconf[5];
1.597 raeburn 1315:
1.538 raeburn 1316: foreach my $item (@possibles) {
1317: my ($orderidx,$cmd) = split(/:/,$item);
1318: next if ($orderidx =~ /\D/);
1319: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1320: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1321: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1322: my %denied = &action_restrictions($coursenum,$coursedom,
1323: &LONCAPA::map::qtescape($url),
1324: $env{'form.folderpath'},\%curr_groups);
1325: next if ($denied{'copy'});
1326: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 1327: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1328: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1329: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1330: next if (exists($pasteurls{$url}));
1331: } else {
1332: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1333: }
1.538 raeburn 1334: my ($suffix,$errortxt,$locknotfreed) =
1335: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1336: if ($suffix ne '') {
1337: push(@newpaste,$suffix);
1338: } else {
1339: if ($locknotfreed) {
1340: return $locknotfreed;
1341: }
1.538 raeburn 1342: }
1343: if (&is_supplemental_title($title)) {
1344: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1345: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1346: }
1.329 droeschl 1347:
1.538 raeburn 1348: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1349: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1350: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1351: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1352: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1353: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1354: my $prefix = $1;
1355: my $subdir =$2;
1356: if ($subdir eq '') {
1357: $subdir = $prefix;
1.492 raeburn 1358: }
1.538 raeburn 1359: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1360: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1361: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1362: if (ref($hierarchy{$url}) eq 'HASH') {
1363: my ($nested,$nestednames);
1364: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1365: $nested =~ s/\&$//;
1366: $nestednames =~ s/\Q___&&&___\E$//;
1367: if ($nested ne '') {
1368: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1369: }
1370: if ($nestednames ne '') {
1371: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1372: }
1.492 raeburn 1373: }
1374: }
1.591 raeburn 1375: if ($locknotfreed) {
1376: $output = $locknotfreed;
1377: last;
1378: }
1.492 raeburn 1379: }
1.538 raeburn 1380: if (@newpaste) {
1381: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1382: }
1.492 raeburn 1383: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1384: delete($env{'form.markcopy'});
1.591 raeburn 1385: return $output;
1.329 droeschl 1386: }
1387:
1.492 raeburn 1388: sub recurse_uploaded_maps {
1389: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1390: if (ref($hierarchy->{$url}) eq 'HASH') {
1391: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1392: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1393: my (@uploaded,@names,%shorter);
1394: for (my $i=0; $i<@maps; $i++) {
1395: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1396: if ($inner ne '') {
1397: push(@uploaded,$inner);
1398: push(@names,&escape($titles[$i]));
1399: $shorter{$maps[$i]} = $inner;
1400: }
1401: }
1402: $$nestref .= "$dir:".join(',',@uploaded).'&';
1403: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1404: foreach my $map (@maps) {
1405: if ($shorter{$map} ne '') {
1406: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1407: }
1408: }
1409: }
1410: return;
1411: }
1412:
1.329 droeschl 1413: sub print_paste_buffer {
1.492 raeburn 1414: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1415: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1416:
1.538 raeburn 1417: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1418: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1419: }
1420:
1.538 raeburn 1421: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1422: my ($pasteitems,@pasteable);
1.575 raeburn 1423: my $clipboardcount = 0;
1.488 raeburn 1424:
1.538 raeburn 1425: # Construct identifiers for current contents of user's paste buffer
1426: foreach my $suffix (@currpaste) {
1427: next if ($suffix =~ /\D/);
1428: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1429: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1430: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1431: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1432: ($url ne '')) {
1.575 raeburn 1433: $clipboardcount ++;
1.538 raeburn 1434: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1435: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1436: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1437: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1438: $is_external = 1;
1.626 raeburn 1439: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1440: $is_exttool = 1;
1.538 raeburn 1441: }
1442: if ($folder =~ /^supplemental/) {
1443: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1444: unless ($canpaste) {
1445: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1446: }
1447: } else {
1448: $canpaste = 1;
1449: }
1450: if ($canpaste) {
1451: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1452: my $srcdom = $1;
1453: my $srcnum = $2;
1454: my $rem = $3;
1455: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1456: $othercourse = 1;
1457: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1458: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1459: } else {
1460: $canpaste = 0;
1461: $nopaste = &mt('Paste from another course unavailable.');
1462: }
1463: }
1464: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1465: my $prefix = $1;
1466: $parent = $2;
1467: if ($folder !~ /^\Q$prefix\E/) {
1468: $areachange = 1;
1469: }
1470: $is_uploaded_map = 1;
1.492 raeburn 1471: }
1.597 raeburn 1472: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1473: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1474: if ($cid ne $env{'request.course.id'}) {
1475: my ($srcdom,$srcnum) = split(/_/,$cid);
1476: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1477: if (($is_exttool) && ($srcdom ne $coursedom)) {
1478: $canpaste = 0;
1479: $nopaste = &mt('Paste from another domain unavailable.');
1480: } else {
1481: $othercrs = '<br />'.&mt('(from another course)');
1482: }
1.596 raeburn 1483: } else {
1484: $canpaste = 0;
1485: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1486: }
1.596 raeburn 1487: }
1.703 ! raeburn 1488: } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
! 1489: my ($audom,$auname) = ($1,$2);
! 1490: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
! 1491: if (&Apache::lonnet::is_course($audom,$auname)) {
! 1492: $canpaste = 0;
! 1493: $nopaste = &mt('Paste from another course unavailable.');
! 1494: }
! 1495: }
1.492 raeburn 1496: }
1.596 raeburn 1497: if ($canpaste) {
1498: push(@pasteable,$suffix);
1.629 raeburn 1499: }
1.538 raeburn 1500: }
1501: my $buffer;
1.627 raeburn 1502: if ($is_external) {
1.538 raeburn 1503: $buffer = &mt('External Resource').': '.
1504: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1505: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1506: } elsif ($is_exttool) {
1507: $buffer = &mt('External Tool').': '.
1508: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1509: } else {
1510: my $icon = &Apache::loncommon::icon($extension);
1511: if ($extension eq 'sequence' &&
1512: $url =~ m{/default_\d+\.sequence$}x) {
1513: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1514: $icon .= '/navmap.folder.closed.gif';
1515: }
1.589 raeburn 1516: my $title = $env{'docs.markedcopy_title_'.$suffix};
1517: if ($title eq '') {
1518: ($title) = ($url =~ m{/([^/]+)$});
1519: }
1.538 raeburn 1520: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1521: ': '.
1522: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1523: &LONCAPA::map::qtescape($title));
1.538 raeburn 1524: }
1525: $pasteitems .= '<div class="LC_left_float">';
1526: my ($options,$onclick);
1527: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1528: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1529: if (($is_uploaded_map) ||
1530: ($url =~ /(bulletinboard|smppg)$/) ||
1531: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1532: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1533: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1534: }
1535: }
1536: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1537: if ($nopaste) {
1.681 raeburn 1538: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 1539: } else {
1540: if ($othercrs) {
1541: $pasteitems .= $othercrs;
1542: }
1543: if ($options) {
1544: $pasteitems .= $options;
1.492 raeburn 1545: }
1546: }
1.538 raeburn 1547: $pasteitems .= '</div>';
1548: }
1549: }
1550: if ($pasteitems eq '') {
1551: &Apache::lonnet::delenv('docs.markedcopies');
1552: }
1553: my ($pasteform,$form_start,$buttons,$form_end);
1554: if ($pasteitems) {
1555: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1556: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1557: if (@pasteable) {
1.575 raeburn 1558: my $value = &mt('Paste to current folder');
1559: if ($container eq 'page') {
1560: $value = &mt('Paste to current page');
1561: }
1562: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1563: }
1564: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1565: if ($clipboardcount > 1) {
1566: $buttons .=
1567: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1568: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1569: (' 'x2).
1570: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1571: (' 'x2);
1.492 raeburn 1572: }
1.575 raeburn 1573: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1574: '</form>';
1.538 raeburn 1575: } else {
1576: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1577: }
1.538 raeburn 1578: $r->print($form_start
1579: .'<fieldset>'
1580: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1581: .$pasteitems
1582: .'</fieldset>'
1583: .$form_end);
1584: }
1585:
1586: sub paste_options {
1587: my ($suffix,$is_uploaded_map,$parent) = @_;
1588: my ($copytext,$movetext);
1589: if ($is_uploaded_map) {
1590: $copytext = &mt('Copy to new folder');
1591: $movetext = &mt('Move old');
1592: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1593: $copytext = &mt('Copy to new board');
1594: $movetext = &mt('Move (not posts)');
1595: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1596: $copytext = &mt('Copy to new page');
1597: $movetext = &mt('Move');
1.533 raeburn 1598: } else {
1.538 raeburn 1599: $copytext = &mt('Copy to new file');
1600: $movetext = &mt('Move');
1601: }
1602: my $output = '<br />'.
1603: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1604: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1605: '<label>'.
1606: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1607: $copytext.'</label></span>'.(' 'x2).' '.
1608: '<span class="LC_nobreak"><label>'.
1609: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1610: $movetext.'</label></span>';
1611: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1612: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1613: '</legend><table border="0">';
1614: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1615: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1616: my $lastdir = $parent;
1617: my %depths = (
1618: $lastdir => 0,
1619: );
1620: my (%display,%deps);
1621: for (my $i=0; $i<@pastemaps; $i++) {
1622: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1623: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1624: my @subfolders = split(/,/,$subfolderstr);
1625: $deps{$lastdir} = \@subfolders;
1626: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1627: my $depth = $depths{$lastdir} + 1;
1628: my $offset = int($depth * 4);
1629: my $indent = (' ' x $offset);
1630: for (my $j=0; $j<@subfolders; $j++) {
1631: $depths{$subfolders[$j]} = $depth;
1632: $display{$subfolders[$j]} =
1633: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1634: '<td><label>'.
1635: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1636: '<label>'.
1637: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1638: &mt('Move old').'</label>'.
1639: '</td></tr>';
1640: }
1.492 raeburn 1641: }
1.538 raeburn 1642: &recurse_print(\$output,$parent,\%deps,\%display);
1643: $output .= '</table></fieldset>';
1.329 droeschl 1644: }
1.538 raeburn 1645: $output .= '</div>';
1646: return $output;
1.488 raeburn 1647: }
1648:
1.492 raeburn 1649: sub recurse_print {
1.538 raeburn 1650: my ($outputref,$dir,$deps,$display) = @_;
1651: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1652: if (ref($deps->{$dir}) eq 'ARRAY') {
1653: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1654: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1655: }
1656: }
1657: }
1658:
1.488 raeburn 1659: sub supp_pasteable {
1660: my ($url) = @_;
1661: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1662: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1663: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1664: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1665: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1666: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1667: return 1;
1668: }
1669: return;
1.329 droeschl 1670: }
1671:
1.492 raeburn 1672: sub paste_popup_js {
1.594 damieng 1673: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1674: show => 'Show Options',
1675: hide => 'Hide Options',
1.594 damieng 1676: );
1677: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1678: none => 'No items selected from clipboard.',
1.492 raeburn 1679: );
1.594 damieng 1680: &html_escape(\%html_js_lt);
1681: &js_escape(\%html_js_lt);
1682: &js_escape(\%js_lt);
1.492 raeburn 1683: return <<"END";
1684:
1.538 raeburn 1685: function showPasteOptions(suffix) {
1686: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1687: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1688: return;
1689: }
1690:
1.538 raeburn 1691: function hidePasteOptions(suffix) {
1692: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1693: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1694: return;
1695: }
1696:
1697: function showOptions(caller,suffix) {
1698: if (document.getElementById('pasteoptionstext_'+suffix)) {
1699: if (caller.checked) {
1.594 damieng 1700: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1701: } else {
1702: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1703: }
1704: if (document.getElementById('pasteoptions_'+suffix)) {
1705: document.getElementById('pasteoptions_'+suffix).style.display='none';
1706: }
1707: }
1.492 raeburn 1708: return;
1709: }
1710:
1.541 raeburn 1711: function validateClipboard() {
1712: var numchk = 0;
1713: if (document.pasteform.pasting.length > 1) {
1714: for (var i=0; i<document.pasteform.pasting.length; i++) {
1715: if (document.pasteform.pasting[i].checked) {
1716: numchk ++;
1717: }
1718: }
1719: } else {
1720: if (document.pasteform.pasting.type == 'checkbox') {
1721: if (document.pasteform.pasting.checked) {
1722: numchk ++;
1723: }
1724: }
1725: }
1726: if (numchk > 0) {
1727: return true;
1728: } else {
1.594 damieng 1729: alert("$js_lt{'none'}");
1.541 raeburn 1730: return false;
1731: }
1732: }
1733:
1.575 raeburn 1734: function checkClipboard() {
1735: if (document.pasteform.pasting.length > 1) {
1736: for (var i=0; i<document.pasteform.pasting.length; i++) {
1737: document.pasteform.pasting[i].checked = true;
1738: }
1739: }
1740: return;
1741: }
1742:
1743: function uncheckClipboard() {
1744: if (document.pasteform.pasting.length >1) {
1745: for (var i=0; i<document.pasteform.pasting.length; i++) {
1746: document.pasteform.pasting[i].checked = false;
1747: }
1748: }
1749: return;
1750: }
1751:
1.492 raeburn 1752: END
1753:
1754: }
1755:
1.329 droeschl 1756: sub do_paste_from_buffer {
1.492 raeburn 1757: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1758:
1.538 raeburn 1759: # Array of items in paste buffer
1760: my (@currpaste,%pastebuffer,%allerrors);
1761: @currpaste = split(/,/,$env{'docs.markedcopies'});
1762:
1.492 raeburn 1763: # Early out if paste buffer is empty
1.538 raeburn 1764: if (@currpaste == 0) {
1.492 raeburn 1765: return ();
1.538 raeburn 1766: }
1767: map { $pastebuffer{$_} = 1; } @currpaste;
1768:
1769: # Array of items selected items to paste
1770: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1771:
1772: # Early out if nothing selected to paste
1773: if (@reqpaste == 0) {
1774: return();
1775: }
1776: my @topaste;
1777: foreach my $suffix (@reqpaste) {
1778: next if ($suffix =~ /\D/);
1779: next unless (exists($pastebuffer{$suffix}));
1780: push(@topaste,$suffix);
1781: }
1782:
1783: # Early out if nothing available to paste
1784: if (@topaste == 0) {
1785: return();
1.329 droeschl 1786: }
1787:
1.627 raeburn 1788: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1789: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1790:
1791: foreach my $suffix (@topaste) {
1792: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1793: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1794: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1795: # Supplemental content may only include certain types of content
1796: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1797: if ($folder =~ /^supplemental/) {
1798: unless (&supp_pasteable($url)) {
1799: $notinsupp{$suffix} = 1;
1800: next;
1801: }
1.492 raeburn 1802: }
1.538 raeburn 1803: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1804: my $srcd = $1;
1805: my $srcn = $2;
1.492 raeburn 1806: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1807: # check for mdc privilege in the course from which the resource was pasted
1808: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1809: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1810: $notincrs{$suffix} = 1;
1811: next;
1812: }
1.491 raeburn 1813: }
1.538 raeburn 1814: $srcdom{$suffix} = $srcd;
1815: $srcnum{$suffix} = $srcn;
1.597 raeburn 1816: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1817: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1818: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1819: my ($srcd,$srcn) = split(/_/,$cid);
1820: # When paste buffer was populated using an active role in a different course
1821: # check for mdc privilege in the course from which the resource was pasted
1822: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1823: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1824: $notincrs{$suffix} = 1;
1825: next;
1826: }
1827: }
1.632 raeburn 1828: # When buffer was populated using an active role in a different course
1829: # disallow pasting of External Tool if course is in a different domain.
1830: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1831: $notindom{$suffix} = 1;
1832: next;
1833: }
1.596 raeburn 1834: $srcdom{$suffix} = $srcd;
1835: $srcnum{$suffix} = $srcn;
1.703 ! raeburn 1836: } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
! 1837: my ($audom,$auname) = ($1,$2);
! 1838: # When buffer was populated using an active role in a different course
! 1839: # disallow pasting of published resources from Course Authoring Space
! 1840: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
! 1841: if (&Apache::lonnet::is_course($audom,$auname)) {
! 1842: $othcrsres{$suffix} = 1;
! 1843: next;
! 1844: }
! 1845: }
1.491 raeburn 1846: }
1.597 raeburn 1847: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1848: push(@dopaste,$suffix);
1849: if ($url=~/\.(page|sequence)$/) {
1850: $is_map{$suffix} = 1;
1851: }
1852: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1853: my $oldprefix = $1;
1.492 raeburn 1854: # When pasting content from Main Content to Supplemental Content and vice versa
1855: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1856: # a folder/page or a document).
1.538 raeburn 1857: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1858: $prefixchg{$suffix} = 'docstosupp';
1859: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1860: $prefixchg{$suffix} = 'supptodocs';
1861: }
1.491 raeburn 1862:
1.492 raeburn 1863: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1864: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1865: my @nested;
1866: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1867: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1868: my @deps = map { /\d+:([\d,]+$)/ } @items;
1869: foreach my $dep (@deps) {
1870: if ($dep =~ /,/) {
1871: push(@nested,split(/,/,$dep));
1872: } else {
1873: push(@nested,$dep);
1874: }
1.492 raeburn 1875: }
1.538 raeburn 1876: foreach my $item (@nested) {
1877: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1878: push(@{$marktomove{$suffix}},$type.'_'.$item);
1879: }
1.492 raeburn 1880: }
1881: }
1.488 raeburn 1882: }
1883: }
1884:
1.538 raeburn 1885: # Early out if nothing available to paste
1886: if (@dopaste == 0) {
1887: return ();
1888: }
1889:
1890: # Populate message hash and hashes used for main content <=> supplemental content
1891: # changes
1892:
1893: %msgs = &Apache::lonlocal::texthash (
1894: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1895: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 1896: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.703 ! raeburn 1897: othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538 raeburn 1898: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1899: );
1900:
1901: %before = (
1902: docstosupp => {
1903: map => 'default',
1904: doc => 'docs',
1905: },
1906: supptodocs => {
1907: map => 'supplemental',
1908: doc => 'supplemental',
1909: },
1910: );
1911:
1912: %after = (
1913: docstosupp => {
1914: map => 'supplemental',
1915: doc => 'supplemental'
1916: },
1917: supptodocs => {
1918: map => 'default',
1919: doc => 'docs',
1920: },
1921: );
1922:
1923: # Retrieve information about all course maps in main content area
1924:
1925: my $allmaps = {};
1.660 raeburn 1926: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.538 raeburn 1927:
1928: # Loop over the items to paste
1929: foreach my $suffix (@dopaste) {
1.329 droeschl 1930: # Maps need to be copied first
1.538 raeburn 1931: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1932: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1933: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1934: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1935: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1936: }
1937: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1938: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1939: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1940: my $oldurl = $url;
1941: if ($is_map{$suffix}) {
1.491 raeburn 1942: # If pasting a map, check if map contains other maps
1.538 raeburn 1943: my (%hierarchy,%titles);
1.660 raeburn 1944: if (($folder =~ /^default/) && (!$donechk)) {
1945: $allmaps =
1946: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1947: $env{"course.$env{'request.course.id'}.home"},
1948: $env{'request.course.id'});
1949: $donechk = 1;
1950: }
1.627 raeburn 1951: &contained_map_check($url,$folder,$coursenum,$coursedom,
1952: \%removefrommap,\%removeparam,\%addedmaps,
1953: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1954: if ($url=~ m{^/uploaded/}) {
1955: my $newurl;
1956: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1957: ($newurl,my $error) =
1958: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1959: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1960: \$title,$allmaps,\%newurls);
1961: if ($error) {
1962: $allerrors{$suffix} = $error;
1963: next;
1964: }
1965: if ($newurl ne '') {
1966: if ($newurl ne $url) {
1967: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1968: $newsubdir{$url} = $1;
1969: }
1970: $mapchanges{$url} = 1;
1.492 raeburn 1971: }
1.538 raeburn 1972: }
1973: }
1974: if (($srcdom{$suffix} ne $coursedom) ||
1975: ($srcnum{$suffix} ne $coursenum) ||
1976: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1977: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1978: $coursedom,$coursenum,$srcdom{$suffix},
1979: $srcnum{$suffix},$allmaps,\%rewrites,
1980: \%retitles,\%copies,\%dbcopies,
1981: \%zombies,\%params,\%mapmoves,
1982: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1983: \%newurls,\%resdatacopy)) {
1.538 raeburn 1984: $mapmoves{$url} = 1;
1985: }
1986: $url = $newurl;
1987: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1988: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1989: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1990: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1991: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1992: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1993: }
1994: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1995: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1996: push(@toclear,$suffix);
1997: # if pasting published map (main content area only) check map not already in course
1998: if ($folder =~ /^default/) {
1999: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
2000: $duplicate{$suffix} = 1;
2001: next;
1.492 raeburn 2002: }
1.491 raeburn 2003: }
2004: }
1.538 raeburn 2005: }
1.627 raeburn 2006: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 2007: my $prefix = $1;
1.648 raeburn 2008: my $fromothercrs;
1.538 raeburn 2009: #need to copy the db contents to a new one, unless this is a move.
2010: my %info = (
2011: src => $url,
2012: cdom => $coursedom,
2013: cnum => $coursenum,
1.596 raeburn 2014: );
1.649 raeburn 2015: if ($prefix eq 'ext.tool') {
1.655 raeburn 2016: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 2017: $info{'delgradable'} = 1;
2018: }
2019: }
1.596 raeburn 2020: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
2021: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
2022: $fromothercrs = 1;
2023: $info{'cdom'} = $srcdom{$suffix};
2024: $info{'cnum'} = $srcnum{$suffix};
2025: }
2026: }
2027: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 2028: my (%lockerr,$msg);
1.538 raeburn 2029: my ($newurl,$result,$errtext) =
2030: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
2031: if ($result eq 'ok') {
2032: $url = $newurl;
2033: $title=&mt('Copy of').' '.$title;
2034: } else {
2035: if ($prefix eq 'smppg') {
2036: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2037: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 2038: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 2039: } elsif ($prefix eq 'ext.tool') {
2040: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 2041: }
2042: $results{$suffix} = $result;
2043: $msgerrs{$suffix} = $msg;
2044: $lockerrs{$suffix} = $lockerr{$prefix};
2045: next;
2046: }
2047: if ($lockerr{$prefix}) {
2048: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 2049: }
1.489 raeburn 2050: }
2051: }
1.538 raeburn 2052: $title = &LONCAPA::map::qtunescape($title);
2053: my $ext='false';
2054: if ($url=~m{^http(|s)://}) { $ext='true'; }
2055: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2056: if ($folder !~ /^supplemental/) {
2057: (undef,undef,$title) =
2058: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2059: }
2060: } else {
2061: if ($folder=~/^supplemental/) {
2062: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2063: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2064: }
1.533 raeburn 2065: }
1.491 raeburn 2066:
2067: # For uploaded files (excluding pages/sequences) path in copied file is changed
2068: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2069: # courses.
2070:
1.538 raeburn 2071: unless ($is_map{$suffix}) {
2072: my $newidx;
1.492 raeburn 2073: # Now insert the URL at the bottom
1.538 raeburn 2074: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2075: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2076: my $relpath = $1;
2077: if ($relpath ne '') {
2078: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2079: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2080: my $newprefix = $newloc;
2081: if ($newloc eq 'default') {
2082: $newprefix = 'docs';
2083: }
2084: if ($newdocsdir eq '') {
2085: $newdocsdir = 'default';
2086: }
1.630 raeburn 2087: if (($prefixchg{$suffix}) ||
2088: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2089: ($srcnum{$suffix} ne $coursenum) ||
2090: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2091: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2092: $url =
2093: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2094: &Apache::lonnet::getfile($oldurl));
2095: if ($url eq '/adm/notfound.html') {
2096: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2097: next;
2098: } else {
2099: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2100: $newsubpath =~ s{/+$}{/};
2101: $docmoves{$oldurl} = $newsubpath;
2102: }
1.491 raeburn 2103: }
2104: }
1.597 raeburn 2105: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2106: my $template = $1;
2107: if ($newidx) {
2108: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2109: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2110: }
1.649 raeburn 2111: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2112: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2113: my $marker = (split(m{/},$url))[4];
2114: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2115: my $val = 'no';
2116: if ($toolsettings{'gradable'}) {
2117: $val = 'yes';
2118: }
2119: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2120: 'string_yesno');
2121: &remember_parms($newidx,'gradable','set',$val);
2122: }
1.491 raeburn 2123: }
1.538 raeburn 2124: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2125: ':'.$ext.':normal:res';
2126: push(@LONCAPA::map::order,$newidx);
2127: # Store the result
2128: my ($errtext,$fatal) =
2129: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2130: if ($fatal) {
2131: $save_err .= $errtext;
2132: $allresult = 'fail';
2133: }
1.488 raeburn 2134: }
1.538 raeburn 2135:
1.597 raeburn 2136: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2137: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2138: unless ($allresult eq 'fail') {
2139: my %updated = (
2140: rewrites => \%rewrites,
2141: zombies => \%zombies,
2142: removefrommap => \%removefrommap,
2143: removeparam => \%removeparam,
2144: dbcopies => \%dbcopies,
1.597 raeburn 2145: resdatacopy => \%resdatacopy,
1.538 raeburn 2146: retitles => \%retitles,
2147: );
2148: my %info = (
2149: newsubdir => \%newsubdir,
2150: params => \%params,
2151: );
2152: if ($prefixchg{$suffix}) {
2153: $info{'before'} = $before{$prefixchg{$suffix}};
2154: $info{'after'} = $after{$prefixchg{$suffix}};
2155: }
2156: my %moves = (
2157: copies => \%copies,
2158: docmoves => \%docmoves,
2159: mapmoves => \%mapmoves,
2160: );
2161: (my $result,$msgs{$suffix},my $lockerror) =
2162: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2163: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2164: $url,'paste');
2165: $lockerrors .= $lockerror;
2166: if ($result eq 'ok') {
2167: if ($is_map{$suffix}) {
2168: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2169: $folder.'.'.$container);
2170: if ($fatal) {
2171: $allresult = 'failread';
2172: } else {
2173: if ($#LONCAPA::map::order<1) {
2174: my $idx=&LONCAPA::map::getresidx();
2175: if ($idx<=0) { $idx=1; }
2176: $LONCAPA::map::order[0]=$idx;
2177: $LONCAPA::map::resources[$idx]='';
2178: }
2179: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2180: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2181: ':'.$ext.':normal:res';
2182: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2183:
2184: # Store the result
1.538 raeburn 2185: my ($errtext,$fatal) =
2186: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2187: if ($fatal) {
2188: $save_err .= $errtext;
2189: $allresult = 'failstore';
2190: }
2191: }
2192: }
2193: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2194: push(@toclear,$suffix);
2195: }
2196: }
1.492 raeburn 2197: }
2198: }
1.538 raeburn 2199: &clear_from_buffer(\@toclear,\@currpaste);
2200: my $msgsarray;
2201: foreach my $suffix (keys(%msgs)) {
2202: if (ref($msgs{$suffix}) eq 'ARRAY') {
2203: $msgsarray .= join(',',@{$msgs{$suffix}});
2204: }
2205: }
2206: return ($allresult,$save_err,$msgsarray,$lockerrors);
2207: }
1.533 raeburn 2208:
1.538 raeburn 2209: sub do_buffer_empty {
2210: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2211: if (@currpaste == 0) {
2212: return &mt('Clipboard is already empty');
2213: }
2214: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2215: if (@toclear == 0) {
2216: return &mt('Nothing selected to clear from clipboard');
2217: }
2218: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2219: if ($numdel) {
2220: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2221: } else {
2222: return &mt('Clipboard unchanged');
1.492 raeburn 2223: }
1.538 raeburn 2224: return;
2225: }
2226:
2227: sub clear_from_buffer {
2228: my ($toclear,$currpaste) = @_;
2229: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2230: my %pastebuffer;
2231: map { $pastebuffer{$_} = 1; } @{$currpaste};
2232: my $numdel = 0;
2233: foreach my $suffix (@{$toclear}) {
2234: next if ($suffix =~ /\D/);
2235: next unless (exists($pastebuffer{$suffix}));
2236: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2237: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2238: delete($pastebuffer{$suffix});
2239: $numdel ++;
2240: }
2241: }
2242: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2243: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2244: return $numdel;
1.492 raeburn 2245: }
2246:
2247: sub get_newmap_url {
2248: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2249: $titleref,$allmaps,$newurls) = @_;
2250: my $newurl;
2251: if ($url=~ m{^/uploaded/}) {
2252: $$titleref=&mt('Copy of').' '.$$titleref;
2253: }
2254: my $now = time;
2255: my $suffix=$$.int(rand(100)).$now;
2256: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2257: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2258: my $path = $1;
2259: my $prefix = $2;
2260: my $ancestor = $3;
2261: if (length($ancestor) > 10) {
2262: $ancestor = substr($ancestor,-10,10);
2263: }
2264: my $newid;
2265: if ($prefixchg) {
2266: if ($folder =~ /^supplemental/) {
2267: $prefix =~ s/^default/supplemental/;
2268: } else {
2269: $prefix =~ s/^supplemental/default/;
2270: }
2271: }
2272: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2273: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2274: } else {
2275: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2276: }
2277: my $counter = 0;
2278: my $is_unique = &uniqueness_check($newurl);
2279: if ($folder =~ /^default/) {
2280: if ($allmaps->{$newurl}) {
2281: $is_unique = 0;
2282: }
2283: }
2284: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2285: $counter ++;
2286: $suffix ++;
2287: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2288: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2289: } else {
2290: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2291: }
2292: $is_unique = &uniqueness_check($newurl);
2293: }
2294: if ($is_unique) {
2295: $newurls->{$newurl} = 1;
2296: } else {
2297: if ($url=~/\.page$/) {
2298: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2299: } else {
2300: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2301: }
2302: }
1.329 droeschl 2303: }
1.492 raeburn 2304: return ($newurl);
1.329 droeschl 2305: }
2306:
1.488 raeburn 2307: sub dbcopy {
1.533 raeburn 2308: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2309: my ($url,$result,$errtext);
2310: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2311: $url = $dbref->{'src'};
1.627 raeburn 2312: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2313: my $prefix = $1;
1.627 raeburn 2314: if ($prefix eq 'ext.tool') {
2315: $prefix = 'exttool';
2316: }
1.533 raeburn 2317: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2318: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2319: my $db_name;
2320: my $marker = (split(m{/},$url))[4];
2321: $marker=~s/\D//g;
2322: if ($dbref->{'src'} =~ m{/smppg$}) {
2323: $db_name =
2324: &Apache::lonsimplepage::get_db_name($url,$marker,
2325: $dbref->{'cdom'},
2326: $dbref->{'cnum'});
1.627 raeburn 2327: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2328: $db_name = 'exttool_'.$marker;
1.533 raeburn 2329: } else {
2330: $db_name = 'bulletinpage_'.$marker;
2331: }
2332: my ($suffix,$freedlock,$error) =
2333: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2334: $coursedom,$coursenum,
2335: 'concat');
2336: if (!$suffix) {
2337: if ($prefix eq 'smppg') {
2338: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2339: } elsif ($prefix eq 'exttool') {
2340: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2341: } else {
1.565 bisitz 2342: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2343: }
2344: if ($error) {
2345: $errtext .= '<br />'.$error;
2346: }
2347: } else {
2348: #need to copy the db contents to a new one.
2349: my %contents=&Apache::lonnet::dump($db_name,
2350: $dbref->{'cdom'},
2351: $dbref->{'cnum'});
2352: if (exists($contents{'uploaded.photourl'})) {
2353: my $photo = $contents{'uploaded.photourl'};
2354: my ($subdir,$fname) =
2355: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2356: my $newphoto;
1.533 raeburn 2357: if ($fname ne '') {
2358: my $content = &Apache::lonnet::getfile($photo);
2359: unless ($content eq '-1') {
2360: $env{'form.'.$suffix.'.photourl'} = $content;
2361: $newphoto =
2362: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2363: delete($env{'form.'.$suffix.'.photourl'});
2364: }
2365: }
2366: if ($newphoto =~ m{^/uploaded/}) {
2367: $contents{'uploaded.photourl'} = $newphoto;
2368: }
2369: }
2370: $db_name =~ s{_\d*$ }{_$suffix}x;
1.649 raeburn 2371: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2372: delete($contents{'gradable'});
2373: }
1.533 raeburn 2374: $result=&Apache::lonnet::put($db_name,\%contents,
2375: $coursedom,$coursenum);
2376: if ($result eq 'ok') {
1.627 raeburn 2377: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2378: }
2379: }
2380: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2381: $lockerrorsref->{$prefix} =
1.533 raeburn 2382: '<div class="LC_error">'.
2383: &mt('There was a problem removing a lockfile.');
2384: if ($prefix eq 'smppg') {
1.560 raeburn 2385: $lockerrorsref->{$prefix} .=
1.559 raeburn 2386: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2387: } elsif ($prefix eq 'exttool') {
2388: $lockerrorsref->{$prefix} .=
2389: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2390: } else {
1.565 bisitz 2391: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2392: }
1.560 raeburn 2393: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2394: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2395: '</div>';
1.533 raeburn 2396: }
2397: }
2398: } elsif ($url =~ m{/syllabus$}) {
2399: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2400: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2401: if (($dbref->{'cdom'} ne $coursedom) ||
2402: ($dbref->{'cnum'} ne $coursenum)) {
2403: my %contents=&Apache::lonnet::dump('syllabus',
2404: $dbref->{'cdom'},
2405: $dbref->{'cnum'});
2406: $result=&Apache::lonnet::put('syllabus',\%contents,
2407: $coursedom,$coursenum);
2408: }
2409: }
1.488 raeburn 2410: }
2411: }
1.533 raeburn 2412: return ($url,$result,$errtext);
1.488 raeburn 2413: }
2414:
1.597 raeburn 2415: sub copy_templated_files {
2416: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2417: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2418: my $srccontainer = 'sequence';
2419: if ($srcwaspage) {
2420: $srccontainer = 'page';
2421: }
2422: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2423: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2424: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2425: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2426: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2427: $template.'.problem';
2428: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2429: if ($template eq 'simpleproblem') {
2430: $srcprefix .= '.0.';
2431: my $weightprefix = $newprefix;
2432: $newprefix .= '.0.';
2433: my @simpleprobqtypes = qw(radio option string essay numerical);
2434: my $qtype=$srcparms{$srcprefix.'questiontype'};
2435: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 2436: my %newdata = (
2437: $newprefix.'questiontype' => $qtype,
2438: );
1.597 raeburn 2439: foreach my $type (@simpleprobqtypes) {
2440: if ($type eq $qtype) {
2441: $newdata{"$weightprefix.$type.weight"}=1;
2442: } else {
2443: $newdata{"$weightprefix.$type.weight"}=0;
2444: }
2445: }
2446: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2447: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2448: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2449: if ($qtype eq 'numerical') {
2450: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2451: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2452: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2453: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2454: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2455: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2456: unless (defined($maxfoils)) { $maxfoils=10; }
2457: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2458: if ($maxfoils<=0) { $maxfoils=10; }
2459: my $randomize=$srcparms{$srcprefix.'randomize'};
2460: unless (defined($randomize)) { $randomize='yes'; }
2461: unless ($randomize eq 'no') { $randomize='yes'; }
2462: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2463: $newdata{$newprefix.'randomize'} = $randomize;
2464: if ($qtype eq 'option') {
2465: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2466: }
2467: for (my $i=1; $i<=10; $i++) {
2468: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2469: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2470: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2471: }
2472:
2473: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2474: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2475: unless (defined($maxfoils)) { $maxfoils=10; }
2476: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2477: if ($maxfoils<=0) { $maxfoils=10; }
2478: my $randomize=$srcparms{$srcprefix.'randomize'};
2479: unless (defined($randomize)) { $randomize='yes'; }
2480: unless ($randomize eq 'no') { $randomize='yes'; }
2481: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2482: $newdata{$newprefix.'randomize'} = $randomize;
2483: if ($qtype eq 'option') {
2484: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2485: }
2486: for (my $i=1; $i<=10; $i++) {
2487: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2488: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2489: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2490: }
2491: } elsif ($qtype eq 'string') {
2492: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2493: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2494: }
2495: if (keys(%newdata)) {
2496: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2497: $coursenum);
2498: if ($putres eq 'ok') {
2499: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2500: }
2501: }
2502: }
2503: }
2504: }
2505:
1.329 droeschl 2506: sub uniqueness_check {
2507: my ($newurl) = @_;
2508: my $unique = 1;
2509: foreach my $res (@LONCAPA::map::order) {
2510: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2511: $url=&LONCAPA::map::qtescape($url);
2512: if ($newurl eq $url) {
2513: $unique = 0;
1.344 bisitz 2514: last;
1.329 droeschl 2515: }
2516: }
2517: return $unique;
2518: }
2519:
1.488 raeburn 2520: sub contained_map_check {
1.627 raeburn 2521: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2522: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2523: my $content = &Apache::lonnet::getfile($url);
2524: unless ($content eq '-1') {
2525: my $parser = HTML::TokeParser->new(\$content);
2526: $parser->attr_encoded(1);
2527: while (my $token = $parser->get_token) {
2528: next if ($token->[0] ne 'S');
2529: if ($token->[1] eq 'resource') {
2530: next if ($token->[2]->{'type'} eq 'zombie');
2531: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2532: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2533: my $srcdom = $1;
2534: unless ($srcdom eq $coursedom) {
2535: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2536: next;
2537: }
2538: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2539: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2540: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2541: next;
2542: }
2543: }
1.703 ! raeburn 2544: if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
! 2545: my ($srcdom,$srcnum) = ($1,$2);
! 2546: unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
! 2547: if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
! 2548: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
! 2549: next;
! 2550: }
! 2551: }
! 2552: }
1.492 raeburn 2553: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2554: if ($1 eq 'uploaded') {
2555: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2556: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2557: } else {
1.492 raeburn 2558: if ($allmaps->{$ressrc}) {
1.529 raeburn 2559: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2560: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2561: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2562: } else {
2563: $addedmaps->{$ressrc} = [$url];
2564: }
1.488 raeburn 2565: }
1.627 raeburn 2566: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2567: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2568: }
1.492 raeburn 2569: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2570: if ($folder =~ /^supplemental/) {
1.492 raeburn 2571: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2572: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2573: } else {
2574: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2575: }
1.488 raeburn 2576: }
2577: }
2578: }
2579: }
2580: return;
2581: }
2582:
2583: sub url_paste_fixups {
1.533 raeburn 2584: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2585: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2586: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2587: my $checktitle;
2588: if (($prefixchg) &&
1.492 raeburn 2589: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2590: $checktitle = 1;
2591: }
1.492 raeburn 2592: my $skip;
2593: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2594: my $mapid = $1.$2;
2595: if ($tomove->{$mapid}) {
2596: $skip = 1;
2597: }
2598: }
1.491 raeburn 2599: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2600: return if ($file eq '-1');
2601: my $parser = HTML::TokeParser->new(\$file);
2602: $parser->attr_encoded(1);
1.491 raeburn 2603: my $changed = 0;
1.488 raeburn 2604: while (my $token = $parser->get_token) {
2605: next if ($token->[0] ne 'S');
2606: if ($token->[1] eq 'resource') {
2607: my $ressrc = $token->[2]->{'src'};
2608: next if ($ressrc eq '');
1.491 raeburn 2609: my $id = $token->[2]->{'id'};
1.492 raeburn 2610: my $title = $token->[2]->{'title'};
1.491 raeburn 2611: if ($checktitle) {
2612: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2613: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2614: }
2615: }
1.488 raeburn 2616: next if ($token->[2]->{'type'} eq 'external');
2617: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2618: next if ($skip);
1.532 raeburn 2619: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2620: $changed = 1;
2621: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2622: my $srcdom = $1;
2623: my $srcnum = $2;
1.488 raeburn 2624: my $rem = $3;
1.492 raeburn 2625: my $newurl;
2626: my $mapname;
2627: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2628: my $prefix = $1;
2629: $mapname = $prefix.$2;
2630: if ($tomove->{$mapname}) {
1.533 raeburn 2631: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2632: $srcdom,$srcnum,$allmaps,$rewrites,
2633: $retitles,$copies,$dbcopies,$zombies,
2634: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2635: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2636: next;
2637: } else {
2638: ($newurl,my $error) =
2639: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2640: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2641: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2642: $newsubdir->{$ressrc} = $1;
2643: }
2644: if ($error) {
2645: next;
2646: }
2647: }
2648: }
2649: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2650: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2651:
1.488 raeburn 2652: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2653: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2654: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2655: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2656: $cnum,$srcdom,$srcnum,$allmaps,
2657: $rewrites,$retitles,$copies,$dbcopies,
2658: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2659: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2660: $mapmoves->{$ressrc} = 1;
2661: }
2662: $changed = 1;
1.488 raeburn 2663: } else {
1.532 raeburn 2664: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2665: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2666: $changed = 1;
1.488 raeburn 2667: }
2668: }
1.649 raeburn 2669: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 2670: next if ($skip);
1.492 raeburn 2671: my $srcdom = $1;
2672: my $srcnum = $2;
1.649 raeburn 2673: my $rem = $3;
2674: my ($is_exttool,$exttoolchg);
2675: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 2676: $is_exttool = 1;
1.649 raeburn 2677: }
1.492 raeburn 2678: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2679: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2680: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2681: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2682: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2683: $changed = 1;
1.649 raeburn 2684: if ($is_exttool) {
2685: $exttoolchg = 1;
2686: }
1.700 raeburn 2687: } elsif (($is_exttool) &&
1.649 raeburn 2688: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2689: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2690: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2691: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2692: $changed = 1;
2693: $exttoolchg = 1;
2694: }
2695: if (($is_exttool) && ($prefixchg)) {
2696: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2697: if ($exttoolchg) {
2698: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2699: }
2700: }
1.533 raeburn 2701: }
2702: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2703: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2704: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2705: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2706: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2707: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2708: $changed = 1;
1.488 raeburn 2709: }
1.597 raeburn 2710: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2711: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2712: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2713: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2714: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2715: }
1.488 raeburn 2716: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2717: next if ($skip);
2718: my $srcdom = $1;
2719: my $srcnum = $2;
2720: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2721: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2722: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2723: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2724: $changed = 1;
1.488 raeburn 2725: }
2726: }
2727: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2728: next if ($skip);
1.488 raeburn 2729: my $to = $token->[2]->{'to'};
2730: if ($to ne '') {
2731: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2732: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2733: } else {
2734: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2735: }
2736: }
2737: }
2738: }
1.491 raeburn 2739: return $changed;
1.488 raeburn 2740: }
2741:
2742: sub apply_fixups {
1.529 raeburn 2743: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2744: $oldurl,$url,$caller) = @_;
2745: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2746: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2747: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2748: if (ref($updated) eq 'HASH') {
2749: if (ref($updated->{'rewrites'}) eq 'HASH') {
2750: %rewrites = %{$updated->{'rewrites'}};
2751: }
2752: if (ref($updated->{'zombies'}) eq 'HASH') {
2753: %zombies = %{$updated->{'zombies'}};
2754: }
2755: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2756: %removefrommap = %{$updated->{'removefrommap'}};
2757: }
2758: if (ref($updated->{'removeparam'}) eq 'HASH') {
2759: %removeparam = %{$updated->{'removeparam'}};
2760: }
2761: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2762: %dbcopies = %{$updated->{'dbcopies'}};
2763: }
2764: if (ref($updated->{'retitles'}) eq 'HASH') {
2765: %retitles = %{$updated->{'retitles'}};
2766: }
1.597 raeburn 2767: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2768: %resdatacopy = %{$updated->{'resdatacopy'}};
2769: }
1.529 raeburn 2770: }
2771: if (ref($info) eq 'HASH') {
2772: if (ref($info->{'newsubdir'}) eq 'HASH') {
2773: %newsubdir = %{$info->{'newsubdir'}};
2774: }
2775: if (ref($info->{'params'}) eq 'HASH') {
2776: %params = %{$info->{'params'}};
2777: }
2778: if (ref($info->{'before'}) eq 'HASH') {
2779: %before = %{$info->{'before'}};
2780: }
2781: if (ref($info->{'after'}) eq 'HASH') {
2782: %after = %{$info->{'after'}};
2783: }
2784: }
2785: if (ref($moves) eq 'HASH') {
2786: if (ref($moves->{'copies'}) eq 'HASH') {
2787: %copies = %{$moves->{'copies'}};
2788: }
2789: if (ref($moves->{'docmoves'}) eq 'HASH') {
2790: %docmoves = %{$moves->{'docmoves'}};
2791: }
2792: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2793: %mapmoves = %{$moves->{'mapmoves'}};
2794: }
2795: }
2796: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2797: my @allcopies;
1.529 raeburn 2798: if (exists($copies{$key})) {
2799: if (ref($copies{$key}) eq 'HASH') {
2800: my %added;
2801: foreach my $innerkey (keys(%{$copies{$key}})) {
2802: if (($innerkey ne '') && (!$added{$innerkey})) {
2803: push(@allcopies,$innerkey);
2804: $added{$innerkey} = 1;
2805: }
1.491 raeburn 2806: }
1.529 raeburn 2807: undef(%added);
1.491 raeburn 2808: }
2809: }
2810: if ($key eq $oldurl) {
1.529 raeburn 2811: if ((exists($docmoves{$key}))) {
1.532 raeburn 2812: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2813: push(@allcopies,$oldurl);
2814: }
2815: }
2816: }
2817: if (@allcopies > 0) {
2818: foreach my $item (@allcopies) {
1.492 raeburn 2819: my ($relpath,$oldsubdir,$fname) =
2820: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2821: if ($fname ne '') {
2822: my $content = &Apache::lonnet::getfile($item);
2823: unless ($content eq '-1') {
2824: my $storefn;
1.529 raeburn 2825: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2826: $storefn = $docmoves{$key};
1.491 raeburn 2827: } else {
2828: $storefn = $relpath;
2829: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2830: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2831: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2832: }
1.529 raeburn 2833: if ($newsubdir{$key}) {
1.532 raeburn 2834: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2835: }
2836: }
2837: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2838: my $copyurl =
2839: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2840: $storefn.$fname,$content);
2841: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2842: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2843: return &mt('Paste failed: an error occurred copying the file.');
2844: } elsif (ref($errors) eq 'HASH') {
2845: $errors->{$item} = 1;
1.489 raeburn 2846: }
2847: }
1.488 raeburn 2848: }
2849: }
1.491 raeburn 2850: }
2851: }
2852: }
1.529 raeburn 2853: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2854: my $storefn=$key;
2855: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2856: if ($prefixchg && $before{'map'} && $after{'map'}) {
2857: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2858: }
1.529 raeburn 2859: if ($newsubdir{$key}) {
2860: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2861: }
1.491 raeburn 2862: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 2863: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
2864: ($after{'map'} eq 'default') &&
2865: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
2866: $mapcontent = '<map>'."\n".
2867: '<resource id="1" src="" type="start" />'."\n".
2868: '<link from="1" to="2" index="1" />'."\n".
2869: '<resource id="2" src="" type="finish" />'."\n".
2870: '</map>';
2871: }
1.491 raeburn 2872: if ($mapcontent eq '-1') {
2873: if (ref($errors) eq 'HASH') {
2874: $errors->{$key} = 1;
2875: }
2876: } else {
2877: my $newmap =
2878: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2879: $mapcontent);
2880: if ($newmap eq '/adm/notfound.html') {
2881: if (ref($errors) eq 'HASH') {
2882: $errors->{$key} = 1;
1.489 raeburn 2883: }
1.488 raeburn 2884: }
2885: }
2886: }
1.491 raeburn 2887: my %updates;
2888: if ($is_map) {
1.529 raeburn 2889: if (ref($updated) eq 'HASH') {
2890: foreach my $type (keys(%{$updated})) {
2891: if (ref($updated->{$type}) eq 'HASH') {
2892: foreach my $key (keys(%{$updated->{$type}})) {
2893: $updates{$key} = 1;
2894: }
2895: }
2896: }
1.491 raeburn 2897: }
2898: foreach my $key (keys(%updates)) {
1.492 raeburn 2899: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2900: if (ref($rewrites{$key}) eq 'HASH') {
2901: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2902: }
1.529 raeburn 2903: if (ref($retitles{$key}) eq 'HASH') {
2904: %toretitle = %{$retitles{$key}};
1.491 raeburn 2905: }
1.529 raeburn 2906: if (ref($removefrommap{$key}) eq 'HASH') {
2907: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2908: }
1.529 raeburn 2909: if (ref($removeparam{$key}) eq 'HASH') {
2910: %remparam = %{$removeparam{$key}};
1.492 raeburn 2911: }
1.529 raeburn 2912: if (ref($zombies{$key}) eq 'HASH') {
2913: %zombie = %{$zombies{$key}};
1.491 raeburn 2914: }
1.529 raeburn 2915: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2916: foreach my $idx (keys(%{$dbcopies{$key}})) {
2917: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2918: my ($newurl,$result,$errtext) =
2919: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2920: if ($result eq 'ok') {
2921: $newdb{$idx} = $newurl;
2922: } elsif (ref($errors) eq 'HASH') {
2923: $errors->{$key} = 1;
2924: }
2925: push(@msgs,$errtext);
2926: }
1.491 raeburn 2927: }
2928: }
1.597 raeburn 2929: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 2930: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 2931: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2932: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2933: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2934: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2935: my $template = $1;
2936: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2937: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2938: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2939: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 2940: unless ($gotnewmapname) {
2941: ($newmapname) = ($key =~ m{/([^/]+)$});
2942: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2943: if ($newsubdir{$key}) {
2944: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2945: }
2946: $gotnewmapname = 1;
2947: }
1.597 raeburn 2948: my $srcmapinfo = $srcfolder.':'.$idx;
2949: if ($srccontainer eq 'page') {
2950: $srcmapinfo .= ':1';
2951: }
2952: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2953: $cnum,$template,$idx,$newmapname);
2954: }
2955: }
2956: }
2957: }
2958: }
1.529 raeburn 2959: if (ref($params{$key}) eq 'HASH') {
2960: %currparam = %{$params{$key}};
1.492 raeburn 2961: }
2962: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2963: if ($fatal) {
1.533 raeburn 2964: return ($errtext);
1.492 raeburn 2965: }
2966: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2967: if (defined($LONCAPA::map::zombies[$i])) {
2968: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2969: if ($zombie{$i} eq $src) {
1.492 raeburn 2970: undef($LONCAPA::map::zombies[$i]);
2971: }
2972: }
2973: }
1.646 raeburn 2974: my $total = scalar(@LONCAPA::map::order) - 1;
2975: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 2976: my $idx = $LONCAPA::map::order[$i];
2977: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2978: my $changed;
1.529 raeburn 2979: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2980: if ((exists($toremove{$idx})) &&
2981: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2982: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2983: if (ref($currparam{$idx}) eq 'ARRAY') {
2984: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 2985: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 2986: }
2987: }
2988: next;
2989: }
2990: my $origsrc = $src;
1.532 raeburn 2991: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2992: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2993: $changed = 1;
1.491 raeburn 2994: }
1.492 raeburn 2995: }
1.532 raeburn 2996: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2997: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2998: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2999: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 3000: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 3001: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 3002: } else {
1.529 raeburn 3003: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 3004: }
1.491 raeburn 3005: }
1.532 raeburn 3006: if ($origsrc =~ /\.(page|sequence)$/) {
3007: if ($newsubdir{$origsrc}) {
1.529 raeburn 3008: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 3009: }
1.532 raeburn 3010: } elsif ($newsubdir{$key}) {
3011: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 3012: }
3013: }
1.492 raeburn 3014: $changed = 1;
1.533 raeburn 3015: } elsif ($newdb{$idx} ne '') {
3016: $src = $newdb{$idx};
1.492 raeburn 3017: $changed = 1;
3018: }
3019: if ($changed) {
1.538 raeburn 3020: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 3021: }
3022: }
3023: }
3024: foreach my $idx (keys(%remparam)) {
3025: if (ref($remparam{$idx}) eq 'ARRAY') {
3026: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 3027: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 3028: }
3029: }
3030: }
1.533 raeburn 3031: if (values(%lockerrors) > 0) {
3032: $lockmsg = join('<br />',values(%lockerrors));
3033: }
1.491 raeburn 3034: my $storefn;
3035: if ($key eq $oldurl) {
3036: $storefn = $url;
3037: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3038: } else {
3039: $storefn = $key;
3040: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3041: if ($prefixchg && $before{'map'} && $after{'map'}) {
3042: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3043: }
1.529 raeburn 3044: if ($newsubdir{$key}) {
3045: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3046: }
1.491 raeburn 3047: }
1.492 raeburn 3048: my $report;
3049: if ($folder !~ /^supplemental/) {
3050: $report = 1;
3051: }
1.527 raeburn 3052: (my $outtext,$errtext) =
1.492 raeburn 3053: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3054: if ($errtext) {
1.529 raeburn 3055: if ($caller eq 'paste') {
1.533 raeburn 3056: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 3057: }
1.491 raeburn 3058: }
3059: }
3060: }
1.533 raeburn 3061: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 3062: }
3063:
3064: sub copy_dependencies {
3065: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3066: my $content;
3067: if (ref($contentref)) {
3068: $content = $$contentref;
3069: } else {
3070: $content = &Apache::lonnet::getfile($item);
3071: }
3072: unless ($content eq '-1') {
3073: my $mm = new File::MMagic;
3074: my $mimetype = $mm->checktype_contents($content);
3075: if ($mimetype eq 'text/html') {
3076: my (%allfiles,%codebase,$state);
3077: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3078: if ($res eq 'ok') {
3079: my ($numexisting,$numpathchanges,$existing);
3080: (undef,$numexisting,$numpathchanges,$existing) =
3081: &Apache::loncommon::ask_for_embedded_content(
3082: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3083: {'error_on_invalid_names' => 1,
3084: 'ignore_remote_references' => 1,
3085: 'docs_url' => $item,
3086: 'context' => 'paste'});
3087: if ($numexisting > 0) {
3088: if (ref($existing) eq 'HASH') {
3089: foreach my $dep (keys(%{$existing})) {
3090: my $depfile = $dep;
3091: unless ($depfile =~ m{^\Q$relpath\E}) {
3092: $depfile = $relpath.$dep;
3093: }
3094: my $depcontent = &Apache::lonnet::getfile($depfile);
3095: unless ($depcontent eq '-1') {
3096: my $storedep = $dep;
3097: $storedep =~ s{^\Q$relpath\E}{};
3098: my $dep_url =
3099: &Apache::lonclonecourse::writefile(
3100: $env{'request.course.id'},
3101: $storefn.$storedep,$depcontent);
3102: if ($dep_url eq '/adm/notfound.html') {
3103: if (ref($errors) eq 'HASH') {
3104: $errors->{$depfile} = 1;
3105: }
3106: } else {
3107: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3108: }
3109: }
3110: }
1.488 raeburn 3111: }
3112: }
3113: }
3114: }
3115: }
3116: return;
3117: }
3118:
1.329 droeschl 3119: my %parameter_type = ( 'randompick' => 'int_pos',
3120: 'hiddenresource' => 'string_yesno',
3121: 'encrypturl' => 'string_yesno',
3122: 'randomorder' => 'string_yesno',);
3123: my $valid_parameters_re = join('|',keys(%parameter_type));
3124: # set parameters
3125: sub update_parameter {
1.537 raeburn 3126: if ($env{'form.changeparms'} eq 'all') {
3127: my (@allidx,@allmapidx,%allchecked,%currchecked);
3128: %allchecked = (
3129: 'hiddenresource' => {},
3130: 'encrypturl' => {},
3131: 'randompick' => {},
3132: 'randomorder' => {},
3133: );
3134: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3135: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3136: if ($which eq 'randompick') {
3137: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3138: my ($res,$value) = split(/:/,$item);
3139: if ($value =~ /^\d+$/) {
3140: $allchecked{$which}{$res} = $value;
3141: }
3142: }
3143: } else {
1.539 raeburn 3144: if ($env{'form.all'.$which}) {
3145: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3146: }
1.537 raeburn 3147: }
3148: }
3149: my $haschanges = 0;
3150: foreach my $res (@LONCAPA::map::order) {
3151: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3152: $name=&LONCAPA::map::qtescape($name);
3153: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 3154: next unless $url;
1.537 raeburn 3155: my $is_map;
3156: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3157: $is_map = 1;
3158: }
3159: foreach my $which (keys(%allchecked)) {
3160: if (($which eq 'randompick' || $which eq 'randomorder')) {
3161: next if (!$is_map);
3162: }
3163: my $oldvalue = 0;
3164: my $newvalue = 0;
3165: if ($allchecked{$which}{$res}) {
3166: $newvalue = $allchecked{$which}{$res};
3167: }
3168: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3169: if ($which eq 'randompick') {
3170: if ($current =~ /^(\d+)$/) {
3171: $oldvalue = $1;
3172: }
3173: } else {
3174: if ($current =~ /^yes$/i) {
3175: $oldvalue = 1;
3176: }
3177: }
3178: if ($oldvalue ne $newvalue) {
3179: $haschanges = 1;
3180: if ($newvalue) {
3181: my $storeval = 'yes';
3182: if ($which eq 'randompick') {
3183: $storeval = $newvalue;
3184: }
3185: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3186: $storeval,
3187: $parameter_type{$which});
3188: &remember_parms($res,$which,'set',$storeval);
3189: } elsif ($oldvalue) {
3190: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3191: &remember_parms($res,$which,'del');
3192: }
3193: }
3194: }
3195: }
3196: return $haschanges;
3197: } else {
1.588 raeburn 3198: my $haschanges = 0;
3199: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3200:
1.537 raeburn 3201: my $which = $env{'form.changeparms'};
3202: my $idx = $env{'form.setparms'};
1.588 raeburn 3203: my $oldvalue = 0;
3204: my $newvalue = 0;
3205: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3206: if ($which eq 'randompick') {
3207: if ($current =~ /^(\d+)$/) {
3208: $oldvalue = $1;
3209: }
3210: } elsif ($current =~ /^yes$/i) {
3211: $oldvalue = 1;
3212: }
1.537 raeburn 3213: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3214: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3215: : 1;
3216: }
3217: if ($oldvalue ne $newvalue) {
3218: $haschanges = 1;
3219: if ($newvalue) {
3220: my $storeval = 'yes';
3221: if ($which eq 'randompick') {
3222: $storeval = $newvalue;
3223: }
3224: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3225: $parameter_type{$which});
3226: &remember_parms($idx,$which,'set',$storeval);
3227: } else {
3228: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3229: &remember_parms($idx,$which,'del');
3230: }
1.537 raeburn 3231: }
1.588 raeburn 3232: return $haschanges;
1.329 droeschl 3233: }
3234: }
3235:
3236: sub handle_edit_cmd {
3237: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3238: my $haschanges = 0;
1.543 raeburn 3239: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3240: return $haschanges;
1.543 raeburn 3241: }
1.329 droeschl 3242: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3243:
3244: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3245: my ($title, $url, @rrest) = split(':', $ratstr);
3246:
1.538 raeburn 3247: if ($cmd eq 'remove') {
1.329 droeschl 3248: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3249: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3250: &Apache::lonnet::removeuploadedurl($url);
3251: } else {
3252: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3253: }
3254: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3255: $haschanges = 1;
1.329 droeschl 3256: } elsif ($cmd eq 'cut') {
3257: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3258: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3259: $haschanges = 1;
1.344 bisitz 3260: } elsif ($cmd eq 'up'
1.329 droeschl 3261: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3262: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3263: $haschanges = 1;
1.329 droeschl 3264: } elsif ($cmd eq 'down'
3265: && defined($LONCAPA::map::order[$idx+1])) {
3266: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3267: $haschanges = 1;
1.329 droeschl 3268: } elsif ($cmd eq 'rename') {
3269: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3270: if ($comment=~/\S/) {
3271: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3272: $comment.':'.join(':', $url, @rrest);
3273: }
3274: # Devalidate title cache
3275: my $renamed_url=&LONCAPA::map::qtescape($url);
3276: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3277: $haschanges = 1;
3278: } elsif ($cmd eq 'setalias') {
3279: my $newvalue = $env{'form.alias'};
3280: if ($newvalue ne '') {
3281: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3282: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3283: 'string');
3284: &remember_parms($idx,'mapalias','set',$newvalue);
3285: $haschanges = 1;
3286: }
3287: }
3288: } elsif ($cmd eq 'delalias') {
3289: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3290: if ($current ne '') {
3291: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3292: &remember_parms($idx,'mapalias','del');
3293: $haschanges = 1;
3294: }
1.329 droeschl 3295: }
1.633 raeburn 3296: return $haschanges;
1.329 droeschl 3297: }
3298:
3299: sub editor {
1.458 raeburn 3300: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3301: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3302: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3303: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3304: if ($allowed) {
1.519 raeburn 3305: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3306: $is_random_order,$container) =
1.510 raeburn 3307: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3308: $r->print($breadcrumbtrail);
1.519 raeburn 3309: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3310: $container = 'page';
3311: } else {
3312: $container = 'sequence';
1.510 raeburn 3313: }
1.484 raeburn 3314:
1.525 raeburn 3315: my $jumpto;
3316:
3317: unless ($supplementalflag) {
1.546 raeburn 3318: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3319: }
1.484 raeburn 3320:
3321: unless ($allowed) {
3322: $randompick = -1;
3323: }
3324:
1.615 raeburn 3325: my ($errtext,$fatal);
3326: if (($folder eq '') && (!$supplementalflag)) {
3327: if (@LONCAPA::map::order) {
3328: undef(@LONCAPA::map::order);
3329: undef(@LONCAPA::map::resources);
3330: undef(@LONCAPA::map::resparms);
3331: undef(@LONCAPA::map::zombies);
3332: }
3333: $folder = 'default';
3334: $container = 'sequence';
3335: } else {
3336: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3337: $folder.'.'.$container);
3338: return $errtext if ($fatal);
3339: }
1.329 droeschl 3340:
3341: if ($#LONCAPA::map::order<1) {
3342: my $idx=&LONCAPA::map::getresidx();
3343: if ($idx<=0) { $idx=1; }
3344: $LONCAPA::map::order[0]=$idx;
3345: $LONCAPA::map::resources[$idx]='';
3346: }
1.364 bisitz 3347:
1.329 droeschl 3348: # ------------------------------------------------------------ Process commands
3349:
3350: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3351: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3352: # set parameters and change order
3353: &snapshotbefore();
3354:
3355: if (&update_parameter()) {
1.588 raeburn 3356: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3357: return $errtext if ($fatal);
3358: }
3359:
3360: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3361: # change order
3362: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3363: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3364:
3365: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3366: return $errtext if ($fatal);
3367: }
1.364 bisitz 3368:
1.329 droeschl 3369: if ($env{'form.pastemarked'}) {
1.491 raeburn 3370: my %paste_errors;
1.533 raeburn 3371: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3372: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3373: \%paste_errors);
1.541 raeburn 3374: if (ref($pastemsgarray) eq 'ARRAY') {
3375: if (@{$pastemsgarray} > 0) {
3376: $r->print('<p class="LC_info">'.
3377: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3378: '</p>');
3379: }
1.541 raeburn 3380: }
3381: if ($lockerror) {
3382: $r->print('<p class="LC_error">'.
3383: $lockerror.
3384: '</p>');
3385: }
3386: if ($save_error ne '') {
3387: return $save_error;
3388: }
3389: if ($paste_res) {
3390: my %errortext = &Apache::lonlocal::texthash (
3391: fail => 'Storage of folder contents failed',
3392: failread => 'Reading folder contents failed',
3393: failstore => 'Storage of folder contents failed',
3394: );
3395: if ($errortext{$paste_res}) {
3396: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3397: }
1.329 droeschl 3398: }
1.491 raeburn 3399: if (keys(%paste_errors) > 0) {
1.538 raeburn 3400: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3401: &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".
3402: '<ul>'."\n");
3403: foreach my $key (sort(keys(%paste_errors))) {
3404: $r->print('<li>'.$key.'</li>'."\n");
3405: }
3406: $r->print('</ul></p>'."\n");
3407: }
1.538 raeburn 3408: } elsif ($env{'form.clearmarked'}) {
3409: my $output = &do_buffer_empty();
3410: if ($output) {
3411: $r->print('<p class="LC_info">'.$output.'</p>');
3412: }
3413: }
1.329 droeschl 3414:
3415: $r->print($upload_output);
3416:
1.538 raeburn 3417: # Rename, cut, copy or remove a single resource
1.602 raeburn 3418: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3419: my $contentchg;
1.633 raeburn 3420: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3421: $contentchg = 1;
3422: }
3423: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3424: return $errtext if ($fatal);
3425: }
1.538 raeburn 3426:
3427: # Cut, copy and/or remove multiple resources
3428: if ($env{'form.multichange'}) {
3429: my %allchecked = (
3430: cut => {},
3431: remove => {},
3432: );
3433: my $needsupdate;
3434: foreach my $which (keys(%allchecked)) {
3435: $env{'form.multi'.$which} =~ s/,$//;
3436: if ($env{'form.multi'.$which}) {
3437: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3438: if (ref($allchecked{$which}) eq 'HASH') {
3439: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3440: }
3441: }
3442: }
3443: if ($needsupdate) {
3444: my $haschanges = 0;
3445: my %curr_groups = &Apache::longroup::coursegroups();
3446: my $total = scalar(@LONCAPA::map::order) - 1;
3447: for (my $i=$total; $i>=0; $i--) {
3448: my $res = $LONCAPA::map::order[$i];
3449: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3450: $name=&LONCAPA::map::qtescape($name);
3451: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3452: next unless $url;
1.538 raeburn 3453: my %denied =
3454: &action_restrictions($coursenum,$coursedom,$url,
3455: $env{'form.folderpath'},\%curr_groups);
3456: foreach my $which (keys(%allchecked)) {
3457: next if ($denied{$which});
3458: next unless ($allchecked{$which}{$res});
3459: if ($which eq 'remove') {
3460: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3461: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3462: &Apache::lonnet::removeuploadedurl($url);
3463: } else {
3464: &LONCAPA::map::makezombie($res);
3465: }
3466: splice(@LONCAPA::map::order,$i,1);
3467: $haschanges ++;
3468: } elsif ($which eq 'cut') {
3469: &LONCAPA::map::makezombie($res);
3470: splice(@LONCAPA::map::order,$i,1);
3471: $haschanges ++;
3472: }
3473: }
3474: }
3475: if ($haschanges) {
3476: ($errtext,$fatal) =
3477: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3478: return $errtext if ($fatal);
3479: }
3480: }
3481: }
3482:
1.329 droeschl 3483: # Group import/search
3484: if ($env{'form.importdetail'}) {
3485: my @imports;
3486: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3487: if (defined($item)) {
3488: my ($name,$url,$residx)=
1.533 raeburn 3489: map { &unescape($_); } split(/\=/,$item);
3490: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3491: my ($suffix,$errortxt,$locknotfreed) =
3492: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3493: if ($locknotfreed) {
3494: $r->print($locknotfreed);
3495: }
3496: if ($suffix) {
3497: $url =~ s/_new\./_$suffix./;
3498: } else {
3499: return $errortxt;
3500: }
1.533 raeburn 3501: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3502: my $type = $1;
3503: my ($suffix,$errortxt,$locknotfreed) =
3504: &new_timebased_suffix($coursedom,$coursenum,$type);
3505: if ($locknotfreed) {
3506: $r->print($locknotfreed);
3507: }
3508: if ($suffix) {
3509: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3510: } else {
3511: return $errortxt;
3512: }
1.626 raeburn 3513: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3514: my ($suffix,$errortxt,$locknotfreed) =
3515: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3516: if ($locknotfreed) {
3517: $r->print($locknotfreed);
3518: }
3519: if ($suffix) {
3520: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3521: } else {
3522: return $errortxt;
3523: }
1.534 raeburn 3524: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3525: if ($supplementalflag) {
3526: next unless ($1 eq 'supplemental');
3527: if ($folder eq 'supplemental') {
3528: next unless ($2 eq 'default');
3529: } else {
3530: next unless ($folder eq 'supplemental_'.$2);
3531: }
3532: } else {
3533: next unless ($1 eq 'docs');
3534: if ($folder eq 'default') {
3535: next unless ($2 eq 'default');
3536: } else {
3537: next unless ($folder eq 'default_'.$2);
3538: }
3539: }
1.504 raeburn 3540: }
1.329 droeschl 3541: push(@imports, [$name, $url, $residx]);
3542: }
3543: }
1.530 raeburn 3544: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3545: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3546: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3547: return $errtext if ($fatal);
1.529 raeburn 3548: if ($fixuperrors) {
3549: $r->print($fixuperrors);
3550: }
1.329 droeschl 3551: }
3552: # Loading a complete map
3553: if ($env{'form.loadmap'}) {
3554: if ($env{'form.importmap'}=~/\w/) {
3555: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3556: my ($title,$url,$ext,$type)=split(/\:/,$res);
3557: my $idx=&LONCAPA::map::getresidx($url);
3558: $LONCAPA::map::resources[$idx]=$res;
3559: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3560: }
3561: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3562: $folder.'.'.$container,1);
1.329 droeschl 3563: return $errtext if ($fatal);
3564: } else {
3565: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3566:
1.329 droeschl 3567: }
3568: }
3569: &log_differences($plain);
3570: }
3571: # ---------------------------------------------------------------- End commands
3572: # ---------------------------------------------------------------- Print screen
3573: my $idx=0;
3574: my $shown=0;
3575: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3576: $r->print('<div class="LC_Box">'.
1.432 raeburn 3577: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3578: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3579: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3580: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3581: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3582: '</ol>');
1.381 bisitz 3583: if ($randompick>=0) {
3584: $r->print('<p class="LC_warning">'
3585: .&mt('Caution: this folder is set to randomly pick a subset'
3586: .' of resources. Adding or removing resources from this'
3587: .' folder will change the set of resources that the'
3588: .' students see, resulting in spurious or missing credit'
3589: .' for completed problems, not limited to ones you'
3590: .' modify. Do not modify the contents of this folder if'
3591: .' it is in active student use.')
3592: .'</p>'
3593: );
3594: }
3595: if ($is_random_order) {
3596: $r->print('<p class="LC_warning">'
3597: .&mt('Caution: this folder is set to randomly order its'
3598: .' contents. Adding or removing resources from this folder'
3599: .' will change the order of resources shown.')
3600: .'</p>'
3601: );
3602: }
3603: $r->print('</div>');
1.364 bisitz 3604: }
1.381 bisitz 3605:
1.685 raeburn 3606: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 3607: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 3608: if (ref($supplemental) eq 'HASH') {
3609: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
3610: (ref($supplemental->{'ids'}) eq 'HASH')) {
3611: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
3612: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
3613: if ($supplemental->{'hidden'}->{$mapnum}) {
3614: $ishidden = 1;
3615: }
3616: }
3617: }
3618: }
3619: }
3620:
1.538 raeburn 3621: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3622: %filters = (
1.543 raeburn 3623: canremove => [],
3624: cancut => [],
3625: cancopy => [],
3626: hiddenresource => [],
3627: encrypturl => [],
3628: randomorder => [],
3629: randompick => [],
1.538 raeburn 3630: );
3631: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3632: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3633: foreach my $res (@LONCAPA::map::order) {
3634: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3635: $name=&LONCAPA::map::qtescape($name);
3636: $url=&LONCAPA::map::qtescape($url);
3637: unless ($name) { $name=(split(/\//,$url))[-1]; }
3638: unless ($name) { $idx++; next; }
1.537 raeburn 3639: push(@allidx,$res);
3640: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3641: push(@allmapidx,$res);
3642: }
1.617 raeburn 3643:
1.682 raeburn 3644: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 3645: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
3646: $idx++;
3647: next;
3648: }
1.682 raeburn 3649: }
1.381 bisitz 3650: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3651: $coursenum,$coursedom,$crstype,
1.538 raeburn 3652: $pathitem,$supplementalflag,$container,
1.620 raeburn 3653: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 3654: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 3655: $idx++;
3656: $shown++;
1.329 droeschl 3657: }
1.424 onken 3658: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3659:
1.538 raeburn 3660: my $need_save;
1.611 raeburn 3661: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3662: my $toolslink;
1.682 raeburn 3663: if ($allowed || $canedit) {
3664: my $helpitem = 'Navigation_Screen';
3665: if (!$allowed) {
3666: $helpitem = 'Supplemental_Navigation';
3667: }
1.544 raeburn 3668: $toolslink = '<table><tr><td>'
1.520 raeburn 3669: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 3670: $helpitem,undef,'RAT')
1.520 raeburn 3671: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3672: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3673: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3674: .'id="LC_content_toolbar_edittoplevel" '
3675: .'class="LC_toolbarItem" '
3676: .'title="'.&mt('Supplemental Content Editor').'">'
3677: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3678: }
1.510 raeburn 3679: if ($shown) {
3680: if ($allowed) {
3681: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3682: .&Apache::loncommon::start_data_table(undef,'contentlist')
3683: .&Apache::loncommon::start_data_table_header_row()
3684: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3685: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 3686: .'<th>'.&mt('Document').'</th>'
3687: .'<th colspan="2">'.&mt('Settings').'</th>'
3688: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 3689: if ($folder !~ /^supplemental/) {
1.538 raeburn 3690: $lists{'canhide'} = join(',',@allidx);
3691: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3692: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3693: 'randomorder','randompick');
3694: foreach my $item (@possfilters) {
1.538 raeburn 3695: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3696: if (@{$filters{$item}} > 0) {
3697: $lists{$item} = join(',',@{$filters{$item}});
3698: }
1.538 raeburn 3699: }
3700: }
1.537 raeburn 3701: if (@allidx > 0) {
3702: my $path;
3703: if ($env{'form.folderpath'}) {
1.630 raeburn 3704: $path =
1.537 raeburn 3705: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3706: }
1.538 raeburn 3707: if (@allidx > 1) {
1.630 raeburn 3708: $to_show .=
1.538 raeburn 3709: &Apache::loncommon::continue_data_table_row().
3710: '<td colspan="2"> </td>'.
3711: '<td>'.
1.611 raeburn 3712: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3713: '</td>'.
1.633 raeburn 3714: '<td colspan="3"> </td>'.
3715: '<td colspan="2">'.
1.611 raeburn 3716: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3717: '</td>'.
3718: &Apache::loncommon::end_data_table_row();
3719: $need_save = 1;
3720: }
1.537 raeburn 3721: }
3722: }
3723: $to_show .= $output.' '
1.510 raeburn 3724: .&Apache::loncommon::end_data_table()
3725: .'<br style="line-height:2px;" />'
3726: .&Apache::loncommon::end_scrollbox();
3727: } else {
1.520 raeburn 3728: $to_show .= $toolslink
1.510 raeburn 3729: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3730: .$output.' '
3731: .&Apache::loncommon::end_data_table();
1.393 raeburn 3732: }
1.510 raeburn 3733: } else {
1.520 raeburn 3734: if (!$allowed) {
3735: $to_show .= $toolslink;
3736: }
1.615 raeburn 3737: my $noresmsg;
3738: if ($allowed && $hiddentop && !$supplementalflag) {
3739: $noresmsg = &mt('Main Content Hidden');
3740: } else {
3741: $noresmsg = &mt('Currently empty');
3742: }
1.510 raeburn 3743: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3744: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3745: .$noresmsg
1.510 raeburn 3746: .'</div>'
3747: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3748: }
3749: } else {
1.510 raeburn 3750: if ($shown) {
3751: $to_show = '<div>'
3752: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3753: .$output
3754: .&Apache::loncommon::end_data_table()
3755: .'</div>';
3756: } else {
3757: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3758: .&mt('Currently empty')
1.510 raeburn 3759: .'</div>'
3760: }
1.458 raeburn 3761: }
3762: my $tid = 1;
3763: if ($supplementalflag) {
3764: $tid = 2;
1.329 droeschl 3765: }
3766: if ($allowed) {
1.484 raeburn 3767: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3768: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3769: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3770: if ($canedit) {
3771: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3772: }
1.460 raeburn 3773: } else {
3774: $r->print($to_show);
1.329 droeschl 3775: }
3776: return;
3777: }
3778:
1.538 raeburn 3779: sub multiple_check_form {
1.611 raeburn 3780: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3781: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3782: my $disabled;
3783: unless ($canedit) {
1.700 raeburn 3784: $disabled = ' disabled="disabled"';
1.611 raeburn 3785: }
1.538 raeburn 3786: my $output =
3787: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3788: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3789: '<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>'.
3790: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3791: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3792: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3793: if ($caller eq 'settings') {
3794: $output .=
3795: '<table><tr>'.
3796: '<td class="LC_docs_entry_parameter">'.
3797: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3798: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3799: '</label></span></td>'.
3800: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3801: '<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.538 raeburn 3802: '</span></td>'.
3803: '</tr>'."\n".
3804: '<tr>'.
3805: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3806: '<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.538 raeburn 3807: '</label></span>'.
3808: '</td></tr></table>'."\n";
3809: } else {
3810: $output .=
3811: '<table><tr>'.
3812: '<td class="LC_docs_entry_parameter">'.
3813: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3814: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3815: '</label></span></td>'.
3816: '<td class="LC_docs_entry_parameter">'.
3817: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3818: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3819: '</label></span></td>'."\n".
3820: '<td class="LC_docs_entry_parameter">'.
3821: '<span class="LC_nobreak LC_docs_copy">'.
1.700 raeburn 3822: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538 raeburn 3823: '</label></span></td>'.
3824: '</tr></table>'."\n";
3825: }
3826: $output .=
3827: '</fieldset>'.
3828: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3829: if ($caller eq 'settings') {
3830: $output .=
1.543 raeburn 3831: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3832: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3833: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3834: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3835: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3836: } elsif ($caller eq 'actions') {
3837: $output .=
3838: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3839: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3840: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3841: }
3842: $output .=
3843: '</form>'.
3844: '</div>';
3845: return $output;
3846: }
3847:
1.329 droeschl 3848: sub process_file_upload {
1.552 raeburn 3849: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3850: # upload a file, if present
1.552 raeburn 3851: my $filesize = length($env{'form.uploaddoc'});
3852: if (!$filesize) {
3853: $$upload_output = '<div class="LC_error">'.
3854: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3855: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3856: $filesize).'<br />'.
3857: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3858: '</div>';
3859: return;
3860: }
3861: my $quotatype = 'unofficial';
3862: if ($crstype eq 'Community') {
1.601 raeburn 3863: $quotatype = 'community';
3864: } elsif ($crstype eq 'Placement') {
3865: $quotatype = 'placement';
1.580 raeburn 3866: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3867: $quotatype = 'official';
1.573 raeburn 3868: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3869: $quotatype = 'textbook';
1.552 raeburn 3870: }
3871: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3872: $filesize = int($filesize/1000); #expressed in kb
3873: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3874: $env{'form.uploaddoc.filename'},$filesize,
3875: 'upload',$quotatype);
1.552 raeburn 3876: return if ($$upload_output);
3877: }
1.440 raeburn 3878: my ($parseaction,$showupload,$nextphase,$mimetype);
3879: if ($env{'form.parserflag'}) {
1.329 droeschl 3880: $parseaction = 'parse';
3881: }
3882: my $folder=$env{'form.folder'};
3883: if ($folder eq '') {
3884: $folder='default';
3885: }
3886: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3887: my $errtext='';
3888: my $fatal=0;
3889: my $container='sequence';
1.519 raeburn 3890: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3891: $container='page';
3892: }
3893: ($errtext,$fatal)=
1.534 raeburn 3894: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3895: if ($#LONCAPA::map::order<1) {
3896: $LONCAPA::map::order[0]=1;
3897: $LONCAPA::map::resources[1]='';
3898: }
3899: my $destination = 'docs/';
3900: if ($folder =~ /^supplemental/) {
3901: $destination = 'supplemental/';
3902: }
3903: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3904: $destination .= 'default/';
3905: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3906: $destination .= $2.'/';
3907: }
1.534 raeburn 3908: if ($fatal) {
3909: $$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>';
3910: return;
3911: }
1.440 raeburn 3912: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3913: my $newidx=&LONCAPA::map::getresidx();
3914: $destination .= $newidx;
1.439 raeburn 3915: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3916: $parseaction,$allfiles,
1.440 raeburn 3917: $codebase,undef,undef,undef,undef,
3918: undef,undef,\$mimetype);
3919: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3920: my $stored = $1;
3921: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3922: $stored.'</span>').'</p>';
3923: } else {
3924: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3925:
1.457 raeburn 3926: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3927: return;
3928: }
1.329 droeschl 3929: my $ext='false';
3930: if ($url=~m{^http://}) { $ext='true'; }
3931: $url = &LONCAPA::map::qtunescape($url);
3932: my $comment=$env{'form.comment'};
3933: $comment = &LONCAPA::map::qtunescape($comment);
3934: if ($folder=~/^supplemental/) {
3935: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3936: $env{'user.domain'}.'___&&&___'.$comment;
3937: }
3938:
3939: $LONCAPA::map::resources[$newidx]=
3940: $comment.':'.$url.':'.$ext.':normal:res';
3941: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3942: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3943: $folder.'.'.$container,1);
1.329 droeschl 3944: if ($fatal) {
1.457 raeburn 3945: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3946: return;
1.329 droeschl 3947: } else {
1.440 raeburn 3948: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3949: $$upload_output = $showupload;
1.384 raeburn 3950: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3951: if ($total_embedded > 0) {
1.440 raeburn 3952: my $uploadphase = 'upload_embedded';
3953: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3954: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3955: my ($embedded,$num) =
1.440 raeburn 3956: &Apache::loncommon::ask_for_embedded_content(
3957: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3958: if ($embedded) {
3959: if ($num) {
3960: $$upload_output .=
3961: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3962: $nextphase = $uploadphase;
3963: } else {
3964: $$upload_output .= $embedded;
3965: }
3966: } else {
3967: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3968: }
1.329 droeschl 3969: } else {
1.440 raeburn 3970: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3971: }
1.457 raeburn 3972: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3973: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3974: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3975: $nextphase = 'decompress_uploaded';
3976: my $position = scalar(@LONCAPA::map::order)-1;
3977: my $noextract = &return_to_editor();
3978: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3979: my %archiveitems = (
3980: folderpath => $env{'form.folderpath'},
3981: cmd => $nextphase,
3982: newidx => $newidx,
3983: position => $position,
3984: phase => $nextphase,
1.477 raeburn 3985: comment => $comment,
1.480 raeburn 3986: );
3987: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3988: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3989: $$upload_output = $showupload.
3990: &Apache::loncommon::decompress_form($mimetype,
3991: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3992: \%archiveitems,\@current);
1.329 droeschl 3993: }
3994: }
3995: }
1.440 raeburn 3996: return $nextphase;
1.329 droeschl 3997: }
3998:
1.480 raeburn 3999: sub get_dir_list {
4000: my ($url,$coursenum,$coursedom,$newidx) = @_;
4001: my ($destination,$dir_root) = &embedded_destination();
4002: my ($dirlistref,$listerror) =
4003: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
4004: my @dir_lines;
4005: my $dirptr=16384;
4006: if (ref($dirlistref) eq 'ARRAY') {
4007: foreach my $dir_line (sort
4008: {
4009: my ($afile)=split('&',$a,2);
4010: my ($bfile)=split('&',$b,2);
4011: return (lc($afile) cmp lc($bfile));
4012: } (@{$dirlistref})) {
4013: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
4014: $filename =~ s/\s+$//;
4015: next if ($filename =~ /^\.\.?$/);
4016: my $isdir = 0;
4017: if ($dirptr&$testdir) {
4018: $isdir = 1;
4019: }
4020: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
4021: }
4022: }
4023: return @dir_lines;
4024: }
4025:
1.329 droeschl 4026: sub is_supplemental_title {
4027: my ($title) = @_;
4028: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
4029: }
4030:
4031: # --------------------------------------------------------------- An entry line
4032:
4033: sub entryline {
1.501 raeburn 4034: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 4035: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 4036: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 4037: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 4038: if (&is_supplemental_title($title)) {
1.488 raeburn 4039: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 4040: $encodedtitle=$title;
1.329 droeschl 4041: } else {
4042: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 4043: $encodedtitle=$title;
1.329 droeschl 4044: $renametitle=$title;
4045: $foldertitle=$title;
4046: }
4047:
1.611 raeburn 4048: my ($disabled,$readonly,$js_lt);
4049: unless ($canedit) {
4050: $disabled = 'disabled="disabled"';
4051: $readonly = 1;
4052: }
4053:
1.329 droeschl 4054: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 4055:
1.329 droeschl 4056: $renametitle=~s/\\/\\\\/g;
4057: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 4058: $renametitle=~s/"/%22/g;
1.581 raeburn 4059: $renametitle=~s/ /%20/g;
4060: $oldtitle = $renametitle;
1.576 raeburn 4061: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 4062: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 4063: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 4064: # Edit commands
1.679 raeburn 4065: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 4066: if ($env{'form.folderpath'}) {
4067: $esc_path=&escape($env{'form.folderpath'});
4068: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4069: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4070: }
1.505 raeburn 4071: my $isexternal;
1.510 raeburn 4072: if ($residx) {
1.501 raeburn 4073: my $currurl = $url;
4074: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 4075: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4076: $isexternal = 1;
4077: }
1.510 raeburn 4078: if (!$supplementalflag) {
4079: my $path = 'uploaded/'.
4080: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4081: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4082: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4083: $residx,
4084: &Apache::lonnet::declutter($currurl));
4085: }
1.501 raeburn 4086: }
1.538 raeburn 4087: my ($renamelink,%lt,$ishash);
4088: if (ref($filtersref) eq 'HASH') {
4089: $ishash = 1;
4090: }
4091:
1.329 droeschl 4092: if ($allowed) {
1.538 raeburn 4093: $form_start = '
4094: <form action="/adm/coursedocs" method="post">
4095: ';
4096: $form_common=(<<END);
4097: <input type="hidden" name="folderpath" value="$path" />
4098: <input type="hidden" name="symb" value="$symb" />
4099: END
4100: $form_param=(<<END);
4101: <input type="hidden" name="setparms" value="$orderidx" />
4102: <input type="hidden" name="changeparms" value="0" />
4103: END
4104: $form_end = '</form>';
4105:
1.329 droeschl 4106: my $incindex=$index+1;
4107: my $selectbox='';
1.471 raeburn 4108: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 4109: ((split(/\:/,
1.344 bisitz 4110: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4111: ne '') &&
1.329 droeschl 4112: ((split(/\:/,
1.344 bisitz 4113: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 4114: ne '')) {
4115: $selectbox=
4116: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 4117: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 4118: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4119: if ($i==$incindex) {
1.358 bisitz 4120: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 4121: } else {
4122: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4123: }
4124: }
4125: $selectbox.='</select>';
4126: }
1.501 raeburn 4127: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 4128: 'up' => 'Move Up',
4129: 'dw' => 'Move Down',
4130: 'rm' => 'Remove',
4131: 'ct' => 'Cut',
4132: 'rn' => 'Rename',
1.501 raeburn 4133: 'cp' => 'Copy',
1.633 raeburn 4134: 'da' => 'Unset alias',
4135: 'sa' => 'Set alias',
1.501 raeburn 4136: 'ex' => 'External Resource',
1.598 raeburn 4137: 'et' => 'External Tool',
1.501 raeburn 4138: 'ed' => 'Edit',
4139: 'pr' => 'Preview',
4140: 'sv' => 'Save',
4141: 'ul' => 'URL',
1.611 raeburn 4142: 'ti' => 'Title',
1.618 raeburn 4143: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 4144: );
1.538 raeburn 4145: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4146: $env{'form.folderpath'},
4147: $currgroups);
1.517 raeburn 4148: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4149: my $skip_confirm = 0;
1.603 raeburn 4150: my $confirm_removal = 0;
1.329 droeschl 4151: if ( $folder =~ /^supplemental/
4152: || ($url =~ m{( /smppg$
4153: |/syllabus$
4154: |/aboutme$
4155: |/navmaps$
4156: |/bulletinboard$
1.626 raeburn 4157: |/ext\.tool$
1.505 raeburn 4158: |\.html$)}x)
4159: || $isexternal) {
1.329 droeschl 4160: $skip_confirm = 1;
4161: }
1.603 raeburn 4162: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4163: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4164: $confirm_removal = 1;
4165: }
1.633 raeburn 4166: if ($url =~ /$LONCAPA::assess_re/) {
4167: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4168: }
1.329 droeschl 4169:
1.538 raeburn 4170: if ($denied{'copy'}) {
1.543 raeburn 4171: $copylink=(<<ENDCOPY)
1.507 raeburn 4172: <span style="visibility: hidden;">$lt{'cp'}</span>
4173: ENDCOPY
4174: } else {
1.538 raeburn 4175: my $formname = 'edit_copy_'.$orderidx;
4176: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4177: $copylink=(<<ENDCOPY);
1.538 raeburn 4178: <form name="$formname" method="post" action="/adm/coursedocs">
4179: $form_common
1.611 raeburn 4180: <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.538 raeburn 4181: $form_end
1.329 droeschl 4182: ENDCOPY
1.538 raeburn 4183: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4184: push(@{$filtersref->{'cancopy'}},$orderidx);
4185: }
1.329 droeschl 4186: }
1.538 raeburn 4187: if ($denied{'cut'}) {
1.507 raeburn 4188: $cutlink=(<<ENDCUT);
4189: <span style="visibility: hidden;">$lt{'ct'}</span>
4190: ENDCUT
4191: } else {
1.538 raeburn 4192: my $formname = 'edit_cut_'.$orderidx;
4193: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4194: $cutlink=(<<ENDCUT);
1.538 raeburn 4195: <form name="$formname" method="post" action="/adm/coursedocs">
4196: $form_common
1.542 raeburn 4197: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4198: <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.538 raeburn 4199: $form_end
1.329 droeschl 4200: ENDCUT
1.538 raeburn 4201: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4202: push(@{$filtersref->{'cancut'}},$orderidx);
4203: }
1.329 droeschl 4204: }
1.538 raeburn 4205: if ($denied{'remove'}) {
1.507 raeburn 4206: $removelink=(<<ENDREM);
4207: <span style="visibility: hidden;">$lt{'rm'}</a>
4208: ENDREM
4209: } else {
1.538 raeburn 4210: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4211: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4212: $removelink=(<<ENDREM);
1.538 raeburn 4213: <form name="$formname" method="post" action="/adm/coursedocs">
4214: $form_common
1.542 raeburn 4215: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4216: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4217: <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.538 raeburn 4218: $form_end
1.497 raeburn 4219: ENDREM
1.538 raeburn 4220: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4221: push(@{$filtersref->{'canremove'}},$orderidx);
4222: }
1.497 raeburn 4223: }
1.551 raeburn 4224: $renamelink=(<<ENDREN);
1.581 raeburn 4225: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4226: ENDREN
1.611 raeburn 4227: my ($uplink,$downlink);
4228: if ($canedit) {
4229: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4230: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4231: } else {
4232: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4233: $downlink = $uplink;
4234: }
1.329 droeschl 4235: $line.=(<<END);
4236: <td>
1.379 bisitz 4237: <div class="LC_docs_entry_move">
1.611 raeburn 4238: <a href="$uplink">
1.501 raeburn 4239: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4240: </a>
4241: </div>
4242: <div class="LC_docs_entry_move">
1.611 raeburn 4243: <a href="$downlink">
1.501 raeburn 4244: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4245: </a>
4246: </div>
1.329 droeschl 4247: </td>
4248: <td>
4249: $form_start
1.538 raeburn 4250: $form_param
1.478 raeburn 4251: $form_common
1.329 droeschl 4252: $selectbox
4253: $form_end
4254: </td>
1.540 raeburn 4255: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4256: $removelink
1.329 droeschl 4257: $cutlink
4258: $copylink
4259: </td>
4260: END
4261: }
4262: # Figure out what kind of a resource this is
4263: my ($extension)=($url=~/\.(\w+)$/);
4264: my $uploaded=($url=~/^\/*uploaded\//);
4265: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4266: my $isfolder;
4267: my $ispage;
4268: my $containerarg;
1.615 raeburn 4269: my $folderurl;
1.685 raeburn 4270: my $plainurl;
1.329 droeschl 4271: if ($uploaded) {
1.472 raeburn 4272: if (($extension eq 'sequence') || ($extension eq 'page')) {
4273: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4274: $containerarg = $1;
1.472 raeburn 4275: if ($extension eq 'sequence') {
4276: $icon=$iconpath.'navmap.folder.closed.gif';
4277: $isfolder=1;
4278: } else {
4279: $icon=$iconpath.'page.gif';
4280: $ispage=1;
4281: }
1.615 raeburn 4282: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4283: if ($allowed) {
4284: $url='/adm/coursedocs?';
4285: } else {
4286: $url='/adm/supplemental?';
4287: }
1.329 droeschl 4288: } else {
1.685 raeburn 4289: $plainurl = $url;
1.329 droeschl 4290: }
4291: }
1.364 bisitz 4292:
1.621 raeburn 4293: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4294: my $orig_url = $url;
1.340 raeburn 4295: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 4296: if ($container eq 'page') {
4297: $url=~s{^http(|s)(:|:)//}{/ext/};
4298: } else {
4299: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4300: }
1.501 raeburn 4301: if (!$supplementalflag && $residx && $symb) {
4302: if ((!$isfolder) && (!$ispage)) {
4303: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 4304: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4305: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4306: } else {
4307: $url=&Apache::lonnet::clutter($url);
4308: }
1.501 raeburn 4309: if ($url=~/^\/*uploaded\//) {
4310: $url=~/\.(\w+)$/;
4311: my $embstyle=&Apache::loncommon::fileembstyle($1);
4312: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4313: $url='/adm/wrapper'.$url;
4314: } elsif ($embstyle eq 'ssi') {
4315: #do nothing with these
4316: } elsif ($url!~/\.(sequence|page)$/) {
4317: $url='/adm/coursedocs/showdoc'.$url;
4318: }
1.623 raeburn 4319: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4320: my $wrapped = $1;
4321: my $exturl = $2;
1.668 raeburn 4322: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 4323: $url='/adm/wrapper'.$url;
4324: }
4325: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4326: $nomodal = 1;
4327: }
1.626 raeburn 4328: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4329: $url='/adm/wrapper'.$url;
1.621 raeburn 4330: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4331: if (($ENV{'SERVER_PORT'} == 443) &&
4332: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4333: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4334: $url .= '?usehttp=1';
4335: }
1.621 raeburn 4336: $nomodal = 1;
4337: }
1.598 raeburn 4338: }
1.696 raeburn 4339: my $checkencrypt;
1.680 raeburn 4340: if (!$env{'request.role.adv'}) {
1.615 raeburn 4341: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 4342: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 4343: $checkencrypt = 1;
1.620 raeburn 4344: } elsif (ref($navmapref)) {
1.615 raeburn 4345: unless (ref($$navmapref)) {
4346: $$navmapref = Apache::lonnavmaps::navmap->new();
4347: }
4348: if (ref($$navmapref)) {
4349: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 4350: $checkencrypt = 1;
1.615 raeburn 4351: }
4352: }
4353: }
1.680 raeburn 4354: }
4355: if ($checkencrypt) {
4356: my $currenc = $env{'request.enc'};
4357: $env{'request.enc'} = 1;
4358: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 4359: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 4360: if (&Apache::lonnet::symbverify($symb,$url)) {
4361: $url = $shownurl;
4362: } else {
4363: $url = '';
4364: }
4365: $env{'request.enc'} = $currenc;
4366: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4367: $shownsymb = $symb;
4368: if ($isexternal) {
4369: $url =~ s/\#[^#]+$//;
4370: if ($container eq 'page') {
4371: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 4372: }
1.612 raeburn 4373: }
1.696 raeburn 4374: } else {
4375: $url = '';
1.680 raeburn 4376: }
4377: unless ($env{'request.role.adv'}) {
4378: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4379: $url = '';
4380: }
4381: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4382: $url = '';
4383: $hiddenres = 1;
4384: }
4385: }
1.696 raeburn 4386: if (($url ne '') && ($shownsymb ne '')) {
4387: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 4388: }
1.329 droeschl 4389: }
1.621 raeburn 4390: } elsif ($supplementalflag) {
1.610 raeburn 4391: if ($isexternal) {
4392: if ($url =~ /^([^#]+)#([^#]+)$/) {
4393: $url = $1;
4394: $anchor = $2;
1.623 raeburn 4395: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 4396: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4397: if ($hostname ne '') {
4398: $url = 'http://'.$hostname.$url;
4399: }
4400: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 4401: }
4402: $nomodal = 1;
4403: }
1.610 raeburn 4404: }
1.621 raeburn 4405: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4406: if (($ENV{'SERVER_PORT'} == 443) &&
4407: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4408: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4409: if ($hostname ne '') {
4410: $url = 'http://'.$hostname.$url;
4411: }
4412: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 4413: }
1.621 raeburn 4414: $nomodal = 1;
4415: }
1.686 raeburn 4416: } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
4417: my $embstyle=&Apache::loncommon::fileembstyle($extension);
4418: unless ($embstyle eq 'ssi') {
4419: if (($embstyle eq 'img')
4420: || ($embstyle eq 'emb')
4421: || ($embstyle eq 'wrp')) {
4422: $url='/adm/wrapper'.$url;
4423: } elsif ($url !~ /\.(sequence|page)$/) {
4424: $url='/adm/coursedocs/showdoc'.$url;
4425: }
4426: }
1.610 raeburn 4427: }
1.685 raeburn 4428: unless ($allowed && $env{'request.role.adv'}) {
4429: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4430: $hiddenres = 1;
4431: }
4432: }
1.329 droeschl 4433: }
1.615 raeburn 4434: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4435: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4436: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4437: my $foldername=&escape($foldertitle);
4438: my $folderpath=$env{'form.folderpath'};
4439: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4440: if (!$allowed && $supplementalflag) {
1.519 raeburn 4441: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4442: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 4443: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4444: $hiddenfolder = 1;
1.682 raeburn 4445: }
1.510 raeburn 4446: } else {
1.617 raeburn 4447: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4448: 'parameter_randompick'))[0];
4449: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4450: 'parameter_randomorder'))[0]=~/^yes$/i);
4451: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4452: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4453: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4454: 'parameter_encrypturl'))[0]=~/^yes$/i);
4455: unless ($hiddenmap) {
1.620 raeburn 4456: if (ref($navmapref)) {
4457: unless (ref($$navmapref)) {
4458: $$navmapref = Apache::lonnavmaps::navmap->new();
4459: }
4460: if (ref($$navmapref)) {
4461: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4462: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4463: unless (@resources) {
4464: $hiddenmap = 1;
4465: unless ($env{'request.role.adv'}) {
4466: $url = '';
4467: $hiddenfolder = 1;
4468: }
1.617 raeburn 4469: }
1.615 raeburn 4470: }
4471: }
4472: }
4473: }
1.617 raeburn 4474: unless ($encryptmap) {
1.620 raeburn 4475: if ((ref($navmapref)) && (ref($$navmapref))) {
4476: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4477: $encryptmap = 1;
4478: }
1.617 raeburn 4479: }
4480: }
1.630 raeburn 4481:
1.617 raeburn 4482: # Append randompick number, hidden, and encrypted with ":" to foldername,
4483: # so it gets transferred between levels
4484: $folderpath.=$containerarg.'&'.$foldername.
4485: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4486: unless ($url eq '') {
1.612 raeburn 4487: $url.='folderpath='.&escape($folderpath);
4488: }
1.510 raeburn 4489: my $rpckchk;
4490: if ($rpicknum) {
4491: $rpckchk = ' checked="checked"';
1.543 raeburn 4492: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4493: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4494: }
1.510 raeburn 4495: }
1.537 raeburn 4496: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4497: $rand_pick_text =
1.478 raeburn 4498: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4499: $form_param."\n".
1.478 raeburn 4500: $form_common."\n".
1.611 raeburn 4501: '<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.510 raeburn 4502: if ($rpicknum ne '') {
4503: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4504: }
1.537 raeburn 4505: $rand_pick_text .= '</span></span>'.
4506: $form_end;
1.543 raeburn 4507: my $ro_set;
1.617 raeburn 4508: if ($randorder) {
1.543 raeburn 4509: $ro_set = 'checked="checked"';
4510: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4511: push(@{$filtersref->{'randomorder'}},$orderidx);
4512: }
4513: }
1.564 raeburn 4514: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4515: $rand_order_text =
1.537 raeburn 4516: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4517: $form_param."\n".
1.537 raeburn 4518: $form_common."\n".
1.611 raeburn 4519: '<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.537 raeburn 4520: $form_end;
1.510 raeburn 4521: }
1.509 raeburn 4522: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4523: my $isexttool;
1.626 raeburn 4524: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4525: $url='/adm/wrapper'.$url;
4526: $isexttool = 1;
4527: }
1.510 raeburn 4528: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4529: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4530: if ($title) {
1.687 raeburn 4531: $url .= '&title='.$encodedtitle;
1.510 raeburn 4532: }
1.598 raeburn 4533: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4534: $url .= '&idx='.$orderidx;
4535: }
1.610 raeburn 4536: if ($anchor ne '') {
4537: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4538: }
1.329 droeschl 4539: }
1.519 raeburn 4540: my ($tdalign,$tdwidth);
1.501 raeburn 4541: if ($allowed) {
1.630 raeburn 4542: my $fileloc =
1.501 raeburn 4543: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4544: if ($isexternal) {
1.630 raeburn 4545: ($editlink,$extresform) =
1.611 raeburn 4546: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4547: undef,undef,undef,undef,undef,undef,
4548: undef,$disabled);
1.626 raeburn 4549: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4550: ($editlink,$extresform) =
4551: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4552: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4553: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4554: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4555: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4556: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4557: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4558: my $suppanchor;
4559: if ($supplementalflag) {
4560: $suppanchor = $anchor;
4561: }
1.630 raeburn 4562: my $jscall =
1.501 raeburn 4563: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4564: $switchserver,
1.503 raeburn 4565: $forceedit,
1.679 raeburn 4566: undef,$symb,$shownsymb,
1.511 raeburn 4567: &escape($env{'form.folderpath'}),
1.622 raeburn 4568: $renametitle,$hostname,
4569: '','',1,$suppanchor);
1.501 raeburn 4570: if ($jscall) {
1.518 raeburn 4571: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4572: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4573: }
4574: }
4575: }
1.519 raeburn 4576: $tdalign = ' align="right" valign="top"';
4577: $tdwidth = ' width="80%"';
1.329 droeschl 4578: }
1.408 raeburn 4579: my $reinit;
4580: if ($crstype eq 'Community') {
4581: $reinit = &mt('(re-initialize community to access)');
4582: } else {
4583: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4584: }
1.702 raeburn 4585: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
1.650 raeburn 4586: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 4587: $line.= '<br />';
4588: if ($curralias ne '') {
4589: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4590: $lt{'da'}.'</a></span>';
4591: } else {
4592: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4593: $lt{'sa'}.'</a></span>';
4594: }
4595: }
1.701 raeburn 4596: $line.='</td><td><span class="LC_nobreak">';
1.685 raeburn 4597: my ($link,$nolink);
1.472 raeburn 4598: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4599: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
4600: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4601: $nolink = 1;
4602: }
4603: }
4604: if ($nolink) {
4605: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4606: } else {
4607: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4608: }
1.469 www 4609: } elsif ($url) {
1.610 raeburn 4610: if ($anchor ne '') {
4611: if ($supplementalflag) {
4612: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4613: } else {
4614: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4615: }
4616: }
1.622 raeburn 4617: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4618: $link = 'http://'.$hostname.$url;
4619: } else {
4620: $link = $url;
4621: }
1.659 raeburn 4622: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.685 raeburn 4623: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
4624: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4625: $nolink = 1;
4626: }
4627: }
4628: if ($nolink) {
4629: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4630: } elsif ($nomodal) {
1.621 raeburn 4631: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4632: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4633: } else {
4634: $line.=&Apache::loncommon::modal_link($link,
4635: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4636: }
1.469 www 4637: } else {
4638: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4639: }
1.519 raeburn 4640: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4641: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4642: if ($nolink) {
4643: $line.=$title;
4644: } else {
4645: $line.='<a href="'.$url.'">'.$title.'</a>';
4646: }
1.682 raeburn 4647: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4648: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4649: my $editurl = $url;
4650: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4651: $line .= ' '.'<a href="'.$editurl.'">'.
4652: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4653: '</a>';
4654: }
4655: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4656: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4657: }
1.469 www 4658: } elsif ($url) {
1.685 raeburn 4659: if ($nolink) {
4660: $line.=$title;
4661: } elsif ($nomodal) {
1.621 raeburn 4662: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4663: $title.'</a>';
4664: } else {
4665: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4666: }
1.617 raeburn 4667: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4668: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4669: } else {
4670: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4671: }
1.633 raeburn 4672: if (($allowed) && ($curralias ne '')) {
4673: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4674: } else {
4675: $line .= $extresform;
4676: }
4677: $line .= '</td>';
1.478 raeburn 4678: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4679: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 4680: if ($uploaded && $url && !$isfolder && !$ispage) {
4681: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
4682: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
4683: }
4684: }
1.682 raeburn 4685: if ($allowed) {
4686: my %lt=&Apache::lonlocal::texthash(
4687: 'hd' => 'Hidden',
4688: 'ec' => 'URL hidden');
4689: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 4690: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4691: $hidtext = ' checked="checked"';
1.694 raeburn 4692: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 4693: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4694: }
4695: }
1.682 raeburn 4696: $formhidden = 'edit_hiddenresource_'.$orderidx;
4697: $line.=(<<ENDPARMS);
1.329 droeschl 4698: <td class="LC_docs_entry_parameter">
1.537 raeburn 4699: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4700: $form_param
1.478 raeburn 4701: $form_common
1.611 raeburn 4702: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4703: $form_end
1.682 raeburn 4704: ENDPARMS
4705: if ($folder =~/^supplemental/) {
4706: $line.= "\n <td>";
4707: } else {
4708: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4709: $enctext = ' checked="checked"';
4710: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4711: push(@{$filtersref->{'encrypturl'}},$orderidx);
4712: }
4713: }
4714: $formurlhidden = 'edit_encrypturl_'.$orderidx;
4715: $line.=(<<ENDPARMS);
1.458 raeburn 4716: <br />
1.537 raeburn 4717: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4718: $form_param
1.478 raeburn 4719: $form_common
1.611 raeburn 4720: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4721: $form_end
4722: </td>
1.478 raeburn 4723: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4724: $rand_order_text</td>
1.329 droeschl 4725: ENDPARMS
1.682 raeburn 4726: }
1.329 droeschl 4727: }
1.379 bisitz 4728: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4729: return $line;
4730: }
4731:
1.538 raeburn 4732: sub action_restrictions {
4733: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4734: my %denied = (
4735: cut => 0,
4736: copy => 0,
4737: remove => 0,
4738: );
4739: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4740: # no copy for published maps
4741: $denied{'copy'} = 1;
1.597 raeburn 4742: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4743: unless ($1 eq 'simpleproblem') {
4744: $denied{'copy'} = 1;
4745: }
4746: $denied{'cut'} = 1;
1.538 raeburn 4747: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4748: if ($folderpath =~ /^default&[^\&]+$/) {
4749: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4750: $denied{'remove'} = 1;
4751: }
4752: $denied{'cut'} = 1;
4753: $denied{'copy'} = 1;
4754: }
4755: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4756: my $group = $1;
4757: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4758: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4759: $denied{'remove'} = 1;
4760: }
4761: }
4762: $denied{'cut'} = 1;
4763: $denied{'copy'} = 1;
4764: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4765: my $group = $1;
4766: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4767: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4768: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4769: if (keys(%groupsettings) > 0) {
4770: $denied{'remove'} = 1;
4771: }
4772: $denied{'cut'} = 1;
4773: $denied{'copy'} = 1;
4774: }
4775: }
4776: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4777: my $group = $1;
4778: if ($url =~ /group_boards_\Q$group\E/) {
4779: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4780: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4781: if (keys(%groupsettings) > 0) {
4782: if (ref($groupsettings{'functions'}) eq 'HASH') {
4783: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4784: $denied{'remove'} = 1;
4785: }
4786: }
4787: }
4788: $denied{'cut'} = 1;
4789: $denied{'copy'} = 1;
4790: }
4791: }
4792: }
4793: return %denied;
4794: }
4795:
1.533 raeburn 4796: sub new_timebased_suffix {
1.538 raeburn 4797: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4798: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4799: if ($type eq 'paste') {
4800: $prefix = $type;
4801: $namespace = 'courseeditor';
1.587 raeburn 4802: $idtype = 'addcode';
1.538 raeburn 4803: } elsif ($type eq 'map') {
1.533 raeburn 4804: $prefix = 'docs';
4805: if ($area eq 'supplemental') {
4806: $prefix = 'supp';
4807: }
4808: $prefix .= $container;
4809: $namespace = 'uploadedmaps';
4810: } else {
4811: $prefix = $type;
4812: $namespace = 'templated';
1.504 raeburn 4813: }
4814: my ($suffix,$freedlock,$error) =
1.587 raeburn 4815: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4816: if (!$suffix) {
1.538 raeburn 4817: if ($type eq 'paste') {
4818: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4819: } elsif ($type eq 'map') {
1.533 raeburn 4820: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4821: } elsif ($type eq 'smppg') {
4822: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4823: } elsif ($type eq 'exttool') {
4824: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4825: } else {
1.565 bisitz 4826: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4827: }
1.504 raeburn 4828: if ($error) {
4829: $errtext .= '<br />'.$error;
4830: }
4831: }
4832: if ($freedlock ne 'ok') {
1.630 raeburn 4833: $locknotfreed =
1.533 raeburn 4834: '<div class="LC_error">'.
4835: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4836: if ($type eq 'paste') {
1.591 raeburn 4837: if ($freedlock eq 'nolock') {
4838: $locknotfreed =
4839: '<div class="LC_error">'.
4840: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4841:
1.593 droeschl 4842: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4843: } else {
4844: $locknotfreed .=
4845: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4846: }
1.538 raeburn 4847: } elsif ($type eq 'map') {
1.591 raeburn 4848: $locknotfreed .=
4849: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4850: } elsif ($type eq 'smppg') {
4851: $locknotfreed .=
4852: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4853: } elsif ($type eq 'exttool') {
4854: $locknotfreed .=
4855: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4856: } else {
4857: $locknotfreed .=
1.565 bisitz 4858: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4859: }
1.538 raeburn 4860: unless ($type eq 'paste') {
4861: $locknotfreed .=
1.560 raeburn 4862: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4863: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4864: }
4865: $locknotfreed .= '</div>';
1.504 raeburn 4866: }
4867: return ($suffix,$errtext,$locknotfreed);
4868: }
4869:
1.329 droeschl 4870: =pod
4871:
4872: =item tiehash()
4873:
4874: tie the hash
4875:
4876: =cut
4877:
4878: sub tiehash {
4879: my ($mode)=@_;
4880: $hashtied=0;
4881: if ($env{'request.course.fn'}) {
4882: if ($mode eq 'write') {
4883: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4884: &GDBM_WRCREAT(),0640)) {
4885: $hashtied=2;
4886: }
4887: } else {
4888: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4889: &GDBM_READER(),0640)) {
4890: $hashtied=1;
4891: }
4892: }
1.364 bisitz 4893: }
1.329 droeschl 4894: }
4895:
4896: sub untiehash {
4897: if ($hashtied) { untie %hash; }
4898: $hashtied=0;
4899: return OK;
4900: }
4901:
4902:
4903:
4904:
4905: sub checkonthis {
1.637 raeburn 4906: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4907: $url=&unescape($url);
4908: $alreadyseen{$url}=1;
4909: $r->rflush();
4910: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4911: $r->print("\n<br />");
4912: if ($level==0) {
4913: $r->print("<br />");
4914: }
4915: for (my $i=0;$i<=$level*5;$i++) {
4916: $r->print(' ');
4917: }
4918: $r->print('<a href="'.$url.'" target="cat">'.
4919: ($title?$title:$url).'</a> ');
4920: if ($url=~/^\/res\//) {
1.637 raeburn 4921: my $updated;
4922: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4923: ($url !~ /\.\d+\.\w+$/)) {
4924: $updated = &Apache::lonnet::remove_stale_resfile($url);
4925: }
1.329 droeschl 4926: my $result=&Apache::lonnet::repcopy(
4927: &Apache::lonnet::filelocation('',$url));
4928: if ($result eq 'ok') {
4929: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4930: if ($updated) {
4931: $r->print('<br />');
4932: for (my $i=0;$i<=$level*5;$i++) {
4933: $r->print(' ');
4934: }
4935: $r->print('- '.&mt('Outdated copy removed'));
4936: }
1.329 droeschl 4937: $r->rflush();
4938: &Apache::lonnet::countacc($url);
4939: $url=~/\.(\w+)$/;
4940: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4941: $r->print('<br />');
4942: $r->rflush();
4943: for (my $i=0;$i<=$level*5;$i++) {
4944: $r->print(' ');
4945: }
4946: $r->print('- '.&mt('Rendering:').' ');
4947: my ($errorcount,$warningcount)=split(/:/,
4948: &Apache::lonnet::ssi_body($url,
4949: ('grade_target'=>'web',
4950: 'return_only_error_and_warning_counts' => 1)));
4951: if (($errorcount) ||
4952: ($warningcount)) {
4953: if ($errorcount) {
1.369 bisitz 4954: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4955: &mt('[quant,_1,error]',$errorcount).'</span>');
4956: }
4957: if ($warningcount) {
4958: $r->print('<span class="LC_warning">'.
4959: &mt('[quant,_1,warning]',$warningcount).'</span>');
4960: }
4961: } else {
4962: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4963: }
4964: $r->rflush();
4965: }
4966: my $dependencies=
4967: &Apache::lonnet::metadata($url,'dependencies');
4968: foreach my $dep (split(/\,/,$dependencies)) {
4969: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4970: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4971: }
4972: }
4973: } elsif ($result eq 'unavailable') {
4974: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4975: } elsif ($result eq 'not_found') {
4976: unless ($url=~/\$/) {
1.521 bisitz 4977: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4978: } else {
1.366 bisitz 4979: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4980: }
4981: } else {
4982: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4983: }
1.637 raeburn 4984: if (($updated) && ($result ne 'ok')) {
4985: $r->print('<br />'.&mt('Outdated copy removed'));
4986: }
1.329 droeschl 4987: }
4988: }
4989: }
4990:
4991:
4992:
4993: =pod
4994:
4995: =item list_symbs()
4996:
1.485 raeburn 4997: List Content Identifiers
1.329 droeschl 4998:
4999: =cut
5000:
5001: sub list_symbs {
5002: my ($r) = @_;
5003:
1.408 raeburn 5004: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5005: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
5006: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
5007: $r->print(&startContentScreen('tools'));
1.329 droeschl 5008: my $navmap = Apache::lonnavmaps::navmap->new();
5009: if (!defined($navmap)) {
5010: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
5011: '<div class="LC_error">'.
5012: &mt('Unable to retrieve information about course contents').
5013: '</div>');
1.408 raeburn 5014: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 5015: } else {
1.484 raeburn 5016: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
5017: &Apache::loncommon::start_data_table().
5018: &Apache::loncommon::start_data_table_header_row().
5019: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
5020: &Apache::loncommon::end_data_table_header_row()."\n");
5021: my $count;
1.329 droeschl 5022: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 5023: $r->print(&Apache::loncommon::start_data_table_row().
5024: '<td>'.$res->compTitle().'</td>'.
5025: '<td>'.$res->symb().'</td>'.
1.521 bisitz 5026: &Apache::loncommon::end_data_table_row());
1.484 raeburn 5027: $count ++;
5028: }
5029: if (!$count) {
5030: $r->print(&Apache::loncommon::start_data_table_row().
5031: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
5032: &Apache::loncommon::end_data_table_row());
1.329 droeschl 5033: }
1.484 raeburn 5034: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 5035: }
1.521 bisitz 5036: $r->print(&endContentScreen());
1.329 droeschl 5037: }
5038:
1.651 raeburn 5039: sub short_urls {
5040: my ($r,$canedit) = @_;
5041: my $crstype = &Apache::loncommon::course_type();
5042: my $formname = 'shortenurl';
5043: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5044: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5045: $r->print(&startContentScreen('tools'));
5046: my ($navmap,$errormsg) =
5047: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5048: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5049: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5050: my (%maps,%resources,%titles);
5051: if (!ref($navmap)) {
5052: $r->print($errormsg.
5053: &endContentScreen());
5054: return '';
5055: } else {
1.652 raeburn 5056: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 5057: $r->rflush();
5058: my $readonly;
5059: if ($canedit) {
1.671 raeburn 5060: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 5061: if ($numnew) {
5062: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
5063: }
5064: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
5065: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
5066: foreach my $error (@{$errors}) {
5067: $r->print('<li>'.$error.'</li>');
5068: }
5069: $r->print('</ul><br />');
5070: }
5071: } else {
5072: $readonly = 1;
5073: }
5074: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
5075: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
5076: undef,undef,undef,undef,undef,\%currtiny,$readonly));
5077: }
5078: $r->print(&endContentScreen());
5079: }
5080:
1.637 raeburn 5081: sub contentverifyform {
5082: my ($r) = @_;
5083: my $crstype = &Apache::loncommon::course_type();
5084: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5085: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5086: $r->print(&startContentScreen('tools'));
5087: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5088: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
5089: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
5090: ' <span class="LC_nobreak">'.
5091: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
5092: &mt('No').'</label>'.(' 'x2).
5093: '<label><input type="radio" name="checkstale" value="1" />'.
5094: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 5095: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 5096: '<input type="hidden" value="1" name="tools" />'.
5097: '<input type="hidden" value="1" name="verify" /></p></form>');
5098: $r->print(&endContentScreen());
5099: return;
5100: }
1.329 droeschl 5101:
5102: sub verifycontent {
1.637 raeburn 5103: my ($r,$checkstale) = @_;
1.408 raeburn 5104: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 5105: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5106: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 5107: $r->print(&startContentScreen('tools'));
5108: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 5109: $hashtied=0;
5110: undef %alreadyseen;
5111: %alreadyseen=();
5112: &tiehash();
1.484 raeburn 5113:
1.329 droeschl 5114: foreach my $key (keys(%hash)) {
5115: if ($hash{$key}=~/\.(page|sequence)$/) {
5116: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5117: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 5118: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 5119: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 5120: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 5121: }
5122: }
5123: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 5124: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 5125: }
5126: }
5127: &untiehash();
1.442 www 5128: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 5129: $r->print(&endContentScreen());
1.329 droeschl 5130: }
5131:
5132: sub devalidateversioncache {
5133: my $src=shift;
5134: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5135: &Apache::lonnet::clutter($src));
5136: }
5137:
5138: sub checkversions {
1.611 raeburn 5139: my ($r,$canedit) = @_;
1.408 raeburn 5140: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 5141: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5142: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 5143: $r->print(&startContentScreen('tools'));
1.442 www 5144:
1.329 droeschl 5145: my $header='';
5146: my $startsel='';
5147: my $monthsel='';
5148: my $weeksel='';
5149: my $daysel='';
5150: my $allsel='';
5151: my %changes=();
5152: my $starttime=0;
5153: my $haschanged=0;
5154: my %setversions=&Apache::lonnet::dump('resourceversions',
5155: $env{'course.'.$env{'request.course.id'}.'.domain'},
5156: $env{'course.'.$env{'request.course.id'}.'.num'});
5157:
5158: $hashtied=0;
5159: &tiehash();
1.611 raeburn 5160: if ($canedit) {
5161: my %newsetversions=();
5162: if ($env{'form.setmostrecent'}) {
5163: $haschanged=1;
5164: foreach my $key (keys(%hash)) {
5165: if ($key=~/^ids\_(\/res\/.+)$/) {
5166: $newsetversions{$1}='mostrecent';
5167: &devalidateversioncache($1);
5168: }
5169: }
5170: } elsif ($env{'form.setcurrent'}) {
5171: $haschanged=1;
5172: foreach my $key (keys(%hash)) {
5173: if ($key=~/^ids\_(\/res\/.+)$/) {
5174: my $getvers=&Apache::lonnet::getversion($1);
5175: if ($getvers>0) {
5176: $newsetversions{$1}=$getvers;
5177: &devalidateversioncache($1);
5178: }
5179: }
1.329 droeschl 5180: }
1.611 raeburn 5181: } elsif ($env{'form.setversions'}) {
5182: $haschanged=1;
5183: foreach my $key (keys(%env)) {
5184: if ($key=~/^form\.set_version_(.+)$/) {
5185: my $src=$1;
5186: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5187: $newsetversions{$src}=$env{$key};
5188: &devalidateversioncache($src);
5189: }
5190: }
1.329 droeschl 5191: }
1.611 raeburn 5192: }
5193: if ($haschanged) {
5194: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5195: $env{'course.'.$env{'request.course.id'}.'.domain'},
5196: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5197: $r->print(&Apache::loncommon::confirmwrapper(
5198: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5199: } else {
5200: $r->print(&Apache::loncommon::confirmwrapper(
5201: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 5202: }
1.611 raeburn 5203: &mark_hash_old();
5204: }
5205: &changewarning($r,'');
1.329 droeschl 5206: }
5207: if ($env{'form.timerange'} eq 'all') {
5208: # show all documents
1.549 raeburn 5209: $header=&mt('All content in '.$crstype);
1.521 bisitz 5210: $allsel=' selected="selected"';
1.329 droeschl 5211: foreach my $key (keys(%hash)) {
5212: if ($key=~/^ids\_(\/res\/.+)$/) {
5213: my $src=$1;
5214: $changes{$src}=1;
5215: }
5216: }
5217: } else {
5218: # show documents which changed
5219: %changes=&Apache::lonnet::dump
5220: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5221: $env{'course.'.$env{'request.course.id'}.'.num'});
5222: my $firstkey=(keys(%changes))[0];
5223: unless ($firstkey=~/^error\:/) {
5224: unless ($env{'form.timerange'}) {
5225: $env{'form.timerange'}=604800;
5226: }
5227: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5228: .&mt('seconds');
5229: if ($env{'form.timerange'}==-1) {
5230: $seltext='since start of course';
1.521 bisitz 5231: $startsel=' selected="selected"';
1.329 droeschl 5232: $env{'form.timerange'}=time;
5233: }
5234: $starttime=time-$env{'form.timerange'};
5235: if ($env{'form.timerange'}==2592000) {
5236: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5237: $monthsel=' selected="selected"';
1.329 droeschl 5238: } elsif ($env{'form.timerange'}==604800) {
5239: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5240: $weeksel=' selected="selected"';
1.329 droeschl 5241: } elsif ($env{'form.timerange'}==86400) {
5242: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5243: $daysel=' selected="selected"';
1.329 droeschl 5244: }
5245: $header=&mt('Content changed').' '.$seltext;
5246: } else {
5247: $header=&mt('No content modifications yet.');
5248: }
5249: }
5250: %setversions=&Apache::lonnet::dump('resourceversions',
5251: $env{'course.'.$env{'request.course.id'}.'.domain'},
5252: $env{'course.'.$env{'request.course.id'}.'.num'});
5253: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5254: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5255: 'lm' => 'Version changes since last Month',
5256: 'lw' => 'Version changes since last Week',
5257: 'sy' => 'Version changes since Yesterday',
5258: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5259: 'cd' => 'Change display',
1.329 droeschl 5260: 'sd' => 'Display',
5261: 'fi' => 'File',
5262: 'md' => 'Modification Date',
5263: 'mr' => 'Most recently published Version',
1.408 raeburn 5264: 've' => 'Version used in '.$crstype,
5265: 'vu' => 'Set Version to be used in '.$crstype,
5266: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5267: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5268: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5269: 'di' => 'Differences',
1.484 raeburn 5270: 'save' => 'Save changes',
5271: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5272: 'act' => 'Actions');
1.611 raeburn 5273: my ($disabled,$readonly);
5274: unless ($canedit) {
5275: $disabled = 'disabled="disabled"';
5276: $readonly = 1;
5277: }
1.329 droeschl 5278: $r->print(<<ENDHEADERS);
1.484 raeburn 5279: <h4 class="LC_info">$header</h4>
1.329 droeschl 5280: <form action="/adm/coursedocs" method="post">
5281: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5282: <div class="LC_left_float">
1.479 golterma 5283: <fieldset>
1.484 raeburn 5284: <legend>$lt{'cd'}</legend>
1.329 droeschl 5285: <select name="timerange">
1.521 bisitz 5286: <option value='all'$allsel>$lt{'al'}</option>
5287: <option value="-1"$startsel>$lt{'st'}</option>
5288: <option value="2592000"$monthsel>$lt{'lm'}</option>
5289: <option value="604800"$weeksel>$lt{'lw'}</option>
5290: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5291: </select>
5292: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5293: </fieldset>
5294: </div>
5295: <div class="LC_left_float">
5296: <fieldset>
5297: <legend>$lt{'act'}</legend>
1.611 raeburn 5298: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5299: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5300: </fieldset>
5301: </div>
5302: <br clear="all" />
5303: <hr />
5304: <h4>$lt{'vers'}</h4>
1.329 droeschl 5305: ENDHEADERS
1.479 golterma 5306: #number of columns for version history
1.571 raeburn 5307: my %changedbytime;
5308: foreach my $key (keys(%changes)) {
5309: #excludes not versionable problems from resource version history:
5310: next if ($key =~ /^\/res\/lib\/templates/);
5311: my $chg;
5312: if ($env{'form.timerange'} eq 'all') {
5313: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5314: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5315: } else {
5316: $chg = $changes{$key};
5317: next if ($chg < $starttime);
5318: }
5319: push(@{$changedbytime{$chg}},$key);
5320: }
5321: if (keys(%changedbytime) == 0) {
5322: &untiehash();
5323: $r->print(&mt('No content changes in imported content in specified time frame').
5324: &endContentScreen());
5325: return;
5326: }
1.479 golterma 5327: $r->print(
1.611 raeburn 5328: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5329: &Apache::loncommon::start_data_table().
5330: &Apache::loncommon::start_data_table_header_row().
5331: '<th>'.&mt('Resources').'</th>'.
5332: "<th>$lt{'mr'}</th>".
5333: "<th>$lt{'ve'}</th>".
5334: "<th>$lt{'vu'}</th>".
5335: '<th>'.&mt('History').'</th>'.
5336: &Apache::loncommon::end_data_table_header_row()
5337: );
1.571 raeburn 5338: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5339: foreach my $key (sort(@{$changedbytime{$chg}})) {
5340: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5341: my $currentversion=&Apache::lonnet::getversion($key);
5342: if ($currentversion<0) {
5343: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5344: }
5345: my $linkurl=&Apache::lonnet::clutter($key);
5346: $r->print(
5347: &Apache::loncommon::start_data_table_row().
5348: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5349: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5350: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5351: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5352: '<td align="right">'
5353: );
5354: # Used in course
5355: my $usedversion=$hash{'version_'.$linkurl};
5356: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5357: if ($usedversion != $currentversion) {
1.479 golterma 5358: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5359: } else {
1.479 golterma 5360: $r->print($usedversion);
5361: }
1.329 droeschl 5362: } else {
1.521 bisitz 5363: $r->print($currentversion);
1.329 droeschl 5364: }
1.571 raeburn 5365: $r->print('</td><td title="'.$lt{'vu'}.'">');
5366: # Set version
5367: $r->print(&Apache::loncommon::select_form(
5368: $setversions{$linkurl},
5369: 'set_version_'.$linkurl,
5370: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5371: '' => '',
5372: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5373: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5374: my $lastold=1;
5375: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5376: my $url=$root.'.'.$prevvers.'.'.$extension;
5377: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5378: $lastold=$prevvers;
5379: }
5380: }
5381: $r->print('</td>');
5382: # List all available versions
5383: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5384: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5385: my $url=$root.'.'.$prevvers.'.'.$extension;
5386: $r->print(
5387: '<span class="LC_nobreak">'
5388: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5389: .&mt('Version [_1]',$prevvers).'</a>'
5390: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5391: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5392: .')');
5393: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5394: $r->print(
5395: ' <a href="/adm/diff?filename='.
5396: &Apache::lonnet::clutter($root.'.'.$extension).
5397: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5398: '" target="diffs">'.&mt('Diffs').'</a>');
5399: }
5400: $r->print('</span><br />');
1.329 droeschl 5401: }
1.571 raeburn 5402: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5403: }
1.329 droeschl 5404: }
1.521 bisitz 5405: $r->print(
5406: &Apache::loncommon::end_data_table().
1.611 raeburn 5407: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5408: '</form>'
5409: );
1.329 droeschl 5410:
5411: &untiehash();
1.521 bisitz 5412: $r->print(&endContentScreen());
1.571 raeburn 5413: return;
1.329 droeschl 5414: }
5415:
5416: sub mark_hash_old {
5417: my $retie_hash=0;
5418: if ($hashtied) {
5419: $retie_hash=1;
5420: &untiehash();
5421: }
5422: &tiehash('write');
5423: $hash{'old'}=1;
5424: &untiehash();
5425: if ($retie_hash) { &tiehash(); }
5426: }
5427:
5428: sub is_hash_old {
5429: my $untie_hash=0;
5430: if (!$hashtied) {
5431: $untie_hash=1;
5432: &tiehash();
5433: }
5434: my $return=$hash{'old'};
5435: if ($untie_hash) { &untiehash(); }
5436: return $return;
5437: }
5438:
5439: sub changewarning {
5440: my ($r,$postexec,$message,$url)=@_;
5441: if (!&is_hash_old()) { return; }
5442: my $pathvar='folderpath';
5443: my $path=&escape($env{'form.folderpath'});
5444: if (!defined($url)) {
5445: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5446: }
5447: my $course_type = &Apache::loncommon::course_type();
5448: if (!defined($message)) {
5449: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5450: }
1.653 raeburn 5451: my $windowname = 'loncapaclient';
5452: if ($env{'request.lti.login'}) {
5453: $windowname .= 'lti';
5454: }
1.329 droeschl 5455: $r->print("\n\n".
1.372 bisitz 5456: '<script type="text/javascript">'."\n".
5457: '// <![CDATA['."\n".
5458: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5459: '// ]]>'."\n".
1.369 bisitz 5460: '</script>'."\n".
1.653 raeburn 5461: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5462: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5463: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5464: &mt($message,' <input type="hidden" name="'.
5465: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5466: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5467: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5468: }
5469:
5470:
5471: sub init_breadcrumbs {
1.571 raeburn 5472: my ($form,$text,$help)=@_;
1.329 droeschl 5473: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5474: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5475: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5476: faq=>273,
5477: bug=>'Instructor Interface',
1.571 raeburn 5478: help => $help});
1.329 droeschl 5479: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5480: text=>$text,
5481: faq=>273,
5482: bug=>'Instructor Interface'});
5483: }
5484:
1.441 www 5485: # subroutine to list form elements
5486: sub create_list_elements {
5487: my @formarr = @_;
5488: my $list = '';
1.501 raeburn 5489: foreach my $button (@formarr){
5490: foreach my $picture (keys(%{$button})) {
5491: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5492: }
5493: }
5494: return $list;
5495: }
1.329 droeschl 5496:
1.441 www 5497: # subroutine to create ul from list elements
5498: sub create_form_ul {
5499: my $list = shift;
5500: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5501: return $ul;
5502: }
1.329 droeschl 5503:
1.442 www 5504: #
5505: # Start tabs
5506: #
5507:
5508: sub startContentScreen {
1.484 raeburn 5509: my ($mode) = @_;
5510: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5511: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5512: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5513: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5514: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5515: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5516: } else {
1.549 raeburn 5517: $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 5518: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5519: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5520: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5521: }
5522: $output .= "\n".'</ul>'."\n";
5523: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5524: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5525: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5526: return $output;
1.442 www 5527: }
5528:
5529: #
5530: # End tabs
5531: #
5532:
5533: sub endContentScreen {
1.484 raeburn 5534: return '</div></div></div>';
1.442 www 5535: }
1.329 droeschl 5536:
1.446 www 5537: sub supplemental_base {
1.548 raeburn 5538: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5539: }
5540:
1.329 droeschl 5541: sub handler {
5542: my $r = shift;
5543: &Apache::loncommon::content_type($r,'text/html');
5544: $r->send_http_header;
5545: return OK if $r->header_only;
1.484 raeburn 5546:
5547: # get course data
1.408 raeburn 5548: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5549: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5550: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5551:
1.606 raeburn 5552: # get docroot
5553: my $londocroot = $r->dir_config('lonDocRoot');
5554:
1.484 raeburn 5555: # graphics settings
5556: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5557:
1.443 www 5558: #
1.329 droeschl 5559: # --------------------------------------------- Initialize help topics for this
5560: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5561: 'Adding_External_Resource','Adding_External_Tool',
5562: 'Navigate_Content','Adding_Folders','Docs_Overview',
5563: 'Load_Map','Supplemental','Score_Upload_Form',
5564: 'Adding_Pages','Importing_LON-CAPA_Resource',
5565: 'Importing_IMS_Course','Uploading_From_Harddrive',
5566: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5567: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5568: }
5569: # Composite help files
5570: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5571: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5572: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5573: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5574: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5575: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5576: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5577: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5578: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5579: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5580:
1.611 raeburn 5581: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 5582: # does this user have privileges to modify content.
5583: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 5584: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 5585: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5586: $allowed = 1;
1.682 raeburn 5587: }
5588: $canedit = 1;
5589: $canview = 1;
5590: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5591: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5592: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5593: $allowed = 1;
5594: }
1.682 raeburn 5595: $canview = 1;
1.611 raeburn 5596: }
5597: unless ($canedit) {
5598: $disabled = ' disabled="disabled"';
1.472 raeburn 5599: }
1.582 raeburn 5600: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5601: if ($env{'form.inhibitmenu'}) {
5602: unless ($env{'form.inhibitmenu'} eq 'yes') {
5603: delete($env{'form.inhibitmenu'});
5604: }
5605: }
5606:
1.582 raeburn 5607: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5608: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5609: if (!$canedit) {
5610: &verifycontent($r);
5611: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5612: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5613: text=>'Results',
5614: faq=>273,
5615: bug=>'Instructor Interface'});
5616: &verifycontent($r,$env{'form.checkstale'});
5617: } else {
5618: &contentverifyform($r);
5619: }
1.329 droeschl 5620: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5621: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5622: &list_symbs($r);
1.651 raeburn 5623: } elsif ($allowed && $env{'form.shorturls'}) {
5624: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5625: &short_urls($r,$canedit);
1.329 droeschl 5626: } elsif ($allowed && $env{'form.docslog'}) {
5627: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5628: my $folder = $env{'form.folder'};
5629: if ($folder eq '') {
5630: $folder='default';
5631: }
1.611 raeburn 5632: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5633: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5634: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5635: &checkversions($r,$canedit);
5636: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5637: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5638: &dumpcourse($r);
1.611 raeburn 5639: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5640: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5641: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5642: } else {
1.611 raeburn 5643: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5644: $noendpage = 1;
5645: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5646: if ($redirect) {
5647: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5648: my $container = 'sequence';
5649: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5650: $is_random_order,$container) =
5651: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5652: my (@folders)=split('&',$env{'form.folderpath'});
5653: $env{'form.foldername'}=&unescape(pop(@folders));
5654: my $folder=pop(@folders);
5655: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5656: $folder.'.'.$container);
5657: my $warning;
5658: if ($fatal) {
5659: if ($container eq 'page') {
5660: $warning = &mt('An error occurred retrieving the contents of the current page.');
5661: } else {
5662: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5663: }
5664: } else {
5665: my $url = $redirect;
5666: my $srcfile = $londocroot.$url;
5667: $url =~ s{^/priv/}{/res/};
5668: my $targetfile = $londocroot.$url;
5669: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5670: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5671: $env{'form.folder'} = $folder;
5672: &snapshotbefore();
5673: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5674: my $ext = 'false';
5675: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5676: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5677: ':'.$ext.':normal:res';
5678: push(@LONCAPA::map::order,$newidx);
5679: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5680: 'string_yesno');
5681: &remember_parms($newidx,'hiddenresource','set','yes');
5682: ($errtext,$fatal) =
5683: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5684: &log_differences($plain);
5685: &mark_hash_old();
5686: $r->internal_redirect($redirect);
5687: return OK;
5688: }
1.654 raeburn 5689: } else {
5690: $r->internal_redirect($redirect);
1.606 raeburn 5691: }
5692: }
5693: }
1.445 www 5694: #
5695: # Done catching special calls
1.484 raeburn 5696: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5697: # Get the parameters that may be needed
5698: #
5699: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 5700: ['folderpath','title',
1.519 raeburn 5701: 'forcesupplement','forcestandard',
1.510 raeburn 5702: 'tools','symb','command','supppath']);
1.445 www 5703:
1.635 raeburn 5704: foreach my $item ('forcesupplement','forcestandard','tools') {
5705: next if ($env{'form.'.$item} eq '');
5706: unless ($env{'form.'.$item} eq '1') {
5707: delete($env{'form.'.$item});
5708: }
5709: }
5710:
5711: if ($env{'form.command'}) {
5712: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5713: delete($env{'form.command'});
5714: }
5715: }
5716:
5717: if ($env{'form.symb'}) {
5718: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5719: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5720: delete($env{'form.symb'});
5721: }
5722: }
5723:
1.445 www 5724: # standard=1: this is a "new-style" course with an uploaded map as top level
5725: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5726:
5727: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5728:
1.484 raeburn 5729: # Decide whether this should display supplemental or main content or utilities
1.445 www 5730: # supplementalflag=1: show supplemental documents
5731: # supplementalflag=0: show standard documents
1.484 raeburn 5732: # toolsflag=1: show utilities
1.445 www 5733:
1.561 raeburn 5734: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5735: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5736: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5737: $supplementalflag=0;
5738: }
5739: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5740: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5741: unless ($allowed) { $supplementalflag=1; }
5742: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5743: my $toolsflag=0;
5744: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5745:
1.635 raeburn 5746: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5747: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 5748: }
5749:
1.685 raeburn 5750: my $backto_supppath;
1.635 raeburn 5751: if ($env{'form.supppath'} ne '') {
1.685 raeburn 5752: if ($supplementalflag && $allowed) {
5753: $backto_supppath = &validate_supppath($coursenum,$coursedom);
5754: }
1.635 raeburn 5755: }
5756:
1.329 droeschl 5757: my $script='';
5758: my $showdoc=0;
1.457 raeburn 5759: my $addentries = {};
1.475 raeburn 5760: my $container;
1.329 droeschl 5761: my $containertag;
1.508 raeburn 5762: my $pathitem;
1.598 raeburn 5763: my %ltitools;
1.699 raeburn 5764: my $posslti;
1.617 raeburn 5765: my $hiddentop;
1.615 raeburn 5766: my $navmap;
1.617 raeburn 5767: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5768:
1.464 www 5769: # Do we directly jump somewhere?
1.525 raeburn 5770: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5771: if ($env{'form.symb'} ne '') {
1.522 raeburn 5772: $env{'form.folderpath'}=
1.617 raeburn 5773: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5774: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5775: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 5776: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 5777: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5778: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 5779: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 5780: }
1.472 raeburn 5781: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5782: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5783: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5784: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5785: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5786: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5787: } elsif ($env{'form.command'} eq 'contents') {
5788: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5789: } elsif ($env{'form.command'} eq 'home') {
5790: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5791: }
5792:
1.525 raeburn 5793:
1.445 www 5794: # Where do we store these for when we come back?
5795: my $stored_folderpath='docs_folderpath';
5796: if ($supplementalflag) {
5797: $stored_folderpath='docs_sup_folderpath';
5798: }
1.464 www 5799:
1.519 raeburn 5800: # No folderpath, and in edit mode, see if we have something stored
5801: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5802: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5803: {'folderpath' => 'scalar'});
1.615 raeburn 5804:
5805: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5806: if ($supplementalflag) {
5807: undef($env{'form.folderpath'}) if ($1 eq 'default');
5808: } else {
5809: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5810: }
5811: } else {
1.523 raeburn 5812: undef($env{'form.folderpath'});
5813: }
1.677 raeburn 5814: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5815: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 5816: }
1.329 droeschl 5817: }
1.446 www 5818:
5819: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5820: if (!$allowed) {
1.446 www 5821: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5822: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5823: }
5824: }
1.446 www 5825: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5826: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5827: $env{'form.folderpath'} = &supplemental_base()
5828: .'&'.
1.329 droeschl 5829: $env{'form.folderpath'};
5830: }
1.685 raeburn 5831: # If allowed and user's role is not advanced check folderpath is not hidden
5832: my $hidden_and_empty;
1.687 raeburn 5833: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 5834: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 5835: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5836: my $folder = $pathitems[-2];
5837: if ($folder eq '') {
5838: undef($env{'form.folderpath'});
5839: } else {
5840: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 5841: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 5842: $folderurl .= '.page';
5843: } else {
5844: $folderurl .= '.sequence';
5845: }
1.685 raeburn 5846: if ($supplementalflag) {
5847: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
5848: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 5849: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 5850: if (ref($supplemental) eq 'HASH') {
5851: my ($suppmap,$suppmapnum);
5852: if ($folder eq 'supplemental') {
5853: $suppmap = 'default';
5854: $suppmapnum = 0;
5855: } elsif ($folder =~ /^supplemental_(\d+)$/) {
5856: $suppmap = $1;
5857: $suppmapnum = $suppmap;
5858: }
5859: if ($hiddenfolder) {
5860: my $hascontent;
5861: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
5862: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
5863: $hascontent = 1;
5864: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
5865: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
5866: if ($id =~ /^$suppmapnum\:/) {
5867: $hascontent = 1;
5868: last;
5869: }
5870: }
5871: }
5872: last if ($hascontent);
5873: }
5874: unless ($hascontent) {
5875: if ($foldername ne '') {
5876: $hidden_and_empty = $foldername;
5877: } else {
5878: $hidden_and_empty = $folder;
5879: }
5880: }
5881: }
5882: }
5883: } else {
5884: unless (ref($navmap)) {
5885: $navmap = Apache::lonnavmaps::navmap->new();
5886: }
5887: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
5888: $foldername = &HTML::Entities::decode(&unescape($foldername));
5889: if (ref($navmap)) {
5890: if ($hiddenfolder ||
5891: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
5892: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5893: unless (@resources) {
5894: if ($foldername ne '') {
5895: $hidden_and_empty = $foldername;
5896: } else {
5897: $hidden_and_empty = $folder;
5898: }
5899: }
5900: }
5901: }
1.617 raeburn 5902: }
1.685 raeburn 5903: if ($hidden_and_empty ne '') {
5904: splice(@pathitems,-2);
5905: if (@pathitems) {
5906: $env{'form.folderpath'} = join('&',@pathitems);
5907: } else {
5908: undef($env{'form.folderpath'});
1.615 raeburn 5909: }
5910: }
5911: }
5912: }
5913:
1.446 www 5914: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5915: unless ($env{'form.folderpath'}) {
1.446 www 5916: if ($supplementalflag) {
5917: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5918: } elsif ($allowed) {
5919: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5920: }
1.472 raeburn 5921: }
1.446 www 5922:
1.445 www 5923: # Store this
1.484 raeburn 5924: unless ($toolsflag) {
1.615 raeburn 5925: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5926: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5927: {'folderpath' => 'scalar'});
1.510 raeburn 5928: }
1.519 raeburn 5929: my $folderpath;
1.484 raeburn 5930: if ($env{'form.folderpath'}) {
1.519 raeburn 5931: $folderpath = $env{'form.folderpath'};
5932: my (@folders)=split('&',$env{'form.folderpath'});
5933: $env{'form.foldername'}=&unescape(pop(@folders));
5934: if ($env{'form.foldername'} =~ /\:1$/) {
5935: $container = 'page';
5936: } else {
5937: $container = 'sequence';
5938: }
5939: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5940: } else {
1.519 raeburn 5941: if ($env{'form.folder'} eq '' ||
5942: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5943: if ($env{'form.folder'} eq 'supplemental') {
5944: $folderpath=&supplemental_base();
5945: } elsif (!$hiddentop) {
5946: $folderpath='default&'.
5947: &escape(&mt('Main Content').':::::');
5948: }
1.484 raeburn 5949: }
5950: }
1.519 raeburn 5951: $containertag = '<input type="hidden" name="folderpath" value="" />';
5952: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5953: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5954: $showdoc='/'.$1;
5955: }
5956: if ($showdoc) { # got called in sequence from course
5957: $allowed=0;
5958: } else {
1.611 raeburn 5959: if ($canedit) {
1.484 raeburn 5960: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5961: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5962: }
5963: }
1.329 droeschl 5964: }
5965:
1.344 bisitz 5966: # get personal data
1.329 droeschl 5967: my $uname=$env{'user.name'};
5968: my $udom=$env{'user.domain'};
5969: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5970:
5971: if ($allowed) {
1.484 raeburn 5972: if ($toolsflag) {
5973: $script .= &inject_data_js();
5974: my ($home,$other,%outhash)=&authorhosts();
5975: if (!$home && $other) {
5976: my @hosts;
5977: foreach my $aurole (keys(%outhash)) {
5978: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5979: push(@hosts,$outhash{$aurole});
5980: }
5981: }
5982: $script .= &dump_switchserver_js(@hosts);
5983: }
1.458 raeburn 5984: } else {
1.570 raeburn 5985: my $tid = 1;
1.484 raeburn 5986: my @tabids;
5987: if ($supplementalflag) {
1.655 raeburn 5988: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 5989: $tid = 2;
1.484 raeburn 5990: } else {
5991: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5992: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5993: unshift(@tabids,'001');
5994: push(@tabids,('dd1','ee1'));
5995: }
1.458 raeburn 5996: }
1.484 raeburn 5997: my $tabidstr = join("','",@tabids);
1.699 raeburn 5998: my (%domtools,%crstools);
5999: my %tooltypes = &Apache::loncommon::usable_exttools();
6000: if ($tooltypes{'dom'}) {
6001: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
6002: }
6003: if ($tooltypes{'crs'}) {
6004: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
6005: }
6006: %ltitools = (
6007: dom => \%domtools,
6008: crs => \%crstools,
6009: );
6010: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622 raeburn 6011: my $hostname = $r->hostname();
1.606 raeburn 6012: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 6013: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 6014: &history_tab_js().
6015: &inject_data_js().
1.570 raeburn 6016: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 6017: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 6018: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
6019: if ($hidden_and_empty ne '') {
6020: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
6021: $hidden_and_empty);
6022: $onload .= "javascript:alert('".&js_escape($alert)."');";
6023: }
1.484 raeburn 6024: $addentries = {
1.685 raeburn 6025: onload => $onload,
1.484 raeburn 6026: };
1.458 raeburn 6027: }
1.538 raeburn 6028: $script .= &paste_popup_js();
1.501 raeburn 6029: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
6030: &mt('Switch server?');
6031:
6032:
1.329 droeschl 6033: }
6034: # -------------------------------------------------------------------- Body tag
1.369 bisitz 6035: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 6036: .'// <![CDATA['."\n"
6037: .$script."\n"
6038: .'// ]]>'."\n"
1.595 musolffc 6039: .'</script>'."\n"
6040: .'<script type="text/javascript"
6041: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 6042:
6043: # Breadcrumbs
6044: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 6045:
6046: if ($showdoc) {
1.682 raeburn 6047: my $args;
6048: if ($supplementalflag) {
1.687 raeburn 6049: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
6050: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.682 raeburn 6051: $args = {'bread_crumbs' => $brcrum};
6052: } else {
6053: $args = {'force_register' => $showdoc};
6054: }
6055: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 6056: } elsif ($toolsflag) {
1.611 raeburn 6057: my ($breadtext,$breadtitle);
1.617 raeburn 6058: $breadtext = "$crstype Editor";
1.611 raeburn 6059: if ($canedit) {
6060: $breadtitle = 'Editing '.$crstype.' Contents';
6061: } else {
6062: $breadtext .= ' (View-only mode)';
6063: $breadtitle = 'Viewing '.$crstype.' Contents';
6064: }
1.571 raeburn 6065: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6066: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 6067: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
6068: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6069: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6070: $breadtitle)
1.571 raeburn 6071: );
1.510 raeburn 6072: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 6073: unless ($env{'request.role.adv'}) {
6074: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
6075: $r->internal_redirect('/adm/navmaps');
6076: return OK;
6077: }
6078: }
1.510 raeburn 6079: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
6080: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
6081: {'bread_crumbs' => $brcrum,}));
6082: } else {
1.611 raeburn 6083: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 6084: $breadtext = "$crstype Editor";
1.611 raeburn 6085: if ($canedit) {
6086: $breadtitle = 'Editing '.$crstype.' Contents';
6087: $helpitem = 'Docs_Adding_Course_Doc';
6088: } else {
6089: $breadtext .= ' (View-only mode)';
6090: $breadtitle = 'Viewing '.$crstype.' Contents';
6091: $helpitem = 'Docs_Viewing_Course_Doc';
6092: }
1.392 raeburn 6093: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6094: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 6095: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 6096: {'add_entries' => $addentries}
6097: )
1.392 raeburn 6098: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6099: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6100: $breadtitle,
6101: $helpitem)
1.392 raeburn 6102: );
6103: }
1.364 bisitz 6104:
1.329 droeschl 6105: my %allfiles = ();
6106: my %codebase = ();
1.440 raeburn 6107: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 6108: if ($canedit) {
1.684 raeburn 6109: undef($suppchanges);
1.329 droeschl 6110: if (($env{'form.uploaddoc.filename'}) &&
6111: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 6112: my $context = $1;
6113: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 6114: undef($hadchanges);
1.440 raeburn 6115: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 6116: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 6117: undef($navmap);
1.329 droeschl 6118: if ($hadchanges) {
6119: &mark_hash_old();
6120: }
1.684 raeburn 6121: if ($suppchanges) {
6122: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6123: undef($suppchanges);
6124: }
1.440 raeburn 6125: $r->print($upload_output);
6126: } elsif ($env{'form.phase'} eq 'upload_embedded') {
6127: # Process file upload - phase two - upload embedded objects
6128: $uploadphase = 'check_embedded';
6129: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
6130: my $state = &embedded_form_elems($uploadphase,$primaryurl,
6131: $env{'form.newidx'});
6132: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6133: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6134: my ($destination,$dir_root) = &embedded_destination();
6135: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
6136: my $actionurl = '/adm/coursedocs';
1.630 raeburn 6137: my ($result,$flag) =
1.440 raeburn 6138: &Apache::loncommon::upload_embedded('coursedoc',$destination,
6139: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
6140: $actionurl);
6141: $r->print($result.&return_to_editor());
6142: } elsif ($env{'form.phase'} eq 'check_embedded') {
6143: # Process file upload - phase three - modify references in HTML file
6144: $uploadphase = 'modified_orightml';
6145: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6146: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6147: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 6148: my $result =
1.482 raeburn 6149: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
6150: $docuname,$docudom,undef,
6151: $dir_root);
1.630 raeburn 6152: $r->print($result.&return_to_editor());
1.476 raeburn 6153: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
6154: $uploadphase = 'decompress_phase_one';
6155: $r->print(&decompression_phase_one().
6156: &return_to_editor());
6157: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
6158: $uploadphase = 'decompress_phase_two';
6159: $r->print(&decompression_phase_two().
6160: &return_to_editor());
1.329 droeschl 6161: }
6162: }
6163:
1.484 raeburn 6164: if ($allowed && $toolsflag) {
6165: $r->print(&startContentScreen('tools'));
1.611 raeburn 6166: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 6167: $r->print(&endContentScreen());
6168: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 6169: # -----------------------------------------------------------------------------
6170: my %lt=&Apache::lonlocal::texthash(
6171: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 6172: 'upfi' => 'Upload File',
1.553 raeburn 6173: 'upld' => 'Upload Content',
1.329 droeschl 6174: 'srch' => 'Search',
6175: 'impo' => 'Import',
1.487 raeburn 6176: 'lnks' => 'Import from Stored Links',
1.502 raeburn 6177: 'impm' => 'Import from Assembled Map',
1.630 raeburn 6178: 'imcr' => 'Import from Course Resources',
1.598 raeburn 6179: 'extr' => 'External Resource',
6180: 'extt' => 'External Tool',
1.329 droeschl 6181: 'selm' => 'Select Map',
6182: 'load' => 'Load Map',
6183: 'newf' => 'New Folder',
6184: 'newp' => 'New Composite Page',
6185: 'syll' => 'Syllabus',
1.425 raeburn 6186: 'navc' => 'Table of Contents',
1.343 biermanm 6187: 'sipa' => 'Simple Course Page',
1.329 droeschl 6188: 'sipr' => 'Simple Problem',
1.630 raeburn 6189: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 6190: 'stpr' => 'Standard Problem',
6191: 'news' => 'New sub-directory',
6192: 'crpr' => 'Create Problem',
1.689 raeburn 6193: 'swit' => 'Switch Server',
1.329 droeschl 6194: 'drbx' => 'Drop Box',
1.451 www 6195: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 6196: 'bull' => 'Discussion Board',
1.347 weissno 6197: 'mypi' => 'My Personal Information Page',
1.353 weissno 6198: 'grpo' => 'Group Portfolio',
1.329 droeschl 6199: 'rost' => 'Course Roster',
1.528 raeburn 6200: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 6201: 'imsf' => 'IMS Upload',
6202: 'imsl' => 'Upload IMS package',
1.501 raeburn 6203: 'cms' => 'Origin of IMS package',
6204: 'se' => 'Select',
1.329 droeschl 6205: 'file' => 'File',
6206: 'title' => 'Title',
1.606 raeburn 6207: 'addp' => 'Add Placeholder to course?',
6208: 'uste' => 'Use Template?',
6209: 'fnam' => 'File Name:',
6210: 'loca' => 'Location:',
6211: 'dire' => 'Directory:',
6212: 'cate' => 'Category:',
6213: 'tmpl' => 'Template:',
1.698 raeburn 6214: 'empd' => 'No resources found',
1.329 droeschl 6215: 'comment' => 'Comment',
1.403 raeburn 6216: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 6217: 'bb5' => 'Blackboard 5',
6218: 'bb6' => 'Blackboard 6',
6219: 'angel5' => 'ANGEL 5.5',
6220: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 6221: 'yes' => 'Yes',
6222: 'no' => 'No',
1.618 raeburn 6223: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 6224: );
1.329 droeschl 6225: # -----------------------------------------------------------------------------
1.595 musolffc 6226:
6227: # Calculate free quota space for a user or course. A javascript function checks
6228: # file size to determine if upload should be allowed.
6229: my $quotatype = 'unofficial';
6230: if ($crstype eq 'Community') {
1.601 raeburn 6231: $quotatype = 'community';
6232: } elsif ($crstype eq 'Placement') {
6233: $quotatype = 'placement';
1.595 musolffc 6234: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6235: $quotatype = 'official';
6236: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6237: $quotatype = 'textbook';
6238: }
6239: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6240: 'course',$quotatype); # expressed in MB
6241: my $current_disk_usage = 0;
6242: foreach my $subdir ('docs','supplemental') {
6243: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6244: "userfiles/$subdir",1); # expressed in kB
6245: }
6246: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 6247: my $usage = $current_disk_usage/1024; # in MB
6248: my $quota = $disk_quota;
6249: my $percent;
6250: if ($disk_quota == 0) {
6251: $percent = 100.0;
6252: } else {
1.619 raeburn 6253: $percent = 100*($usage/$disk_quota);
1.605 raeburn 6254: }
6255: $usage = sprintf("%.2f",$usage);
6256: $quota = sprintf("%.2f",$quota);
6257: $percent = sprintf("%.0f",$percent);
6258: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6259: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 6260:
1.329 droeschl 6261: my $fileupload=(<<FIUP);
1.605 raeburn 6262: $quotainfo
1.329 droeschl 6263: $lt{'file'}:<br />
6264: FIUP
6265: my $checkbox=(<<CHBO);
6266: <!-- <label>$lt{'parse'}?
6267: <input type="checkbox" name="parserflag" />
6268: </label> -->
6269: <label>
1.611 raeburn 6270: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6271: </label>
6272: CHBO
1.501 raeburn 6273: my $imsfolder = $env{'form.folder'};
6274: if ($imsfolder eq '') {
6275: $imsfolder = 'default';
6276: }
6277: my $imspform=(<<IMSFORM);
6278: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6279: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6280: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 6281: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 6282: <legend>$lt{'imsf'}</legend>
6283: $fileupload
1.702 raeburn 6284: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
6285: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501 raeburn 6286: <br />
6287: <p>
6288: $lt{'cms'}:
1.611 raeburn 6289: <select name="source" $disabled>
1.501 raeburn 6290: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 6291: <option value="bb5">$lt{'bb5'}</option>
6292: <option value="bb6">$lt{'bb6'}</option>
6293: <option value="angel5">$lt{'angel5'}</option>
6294: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 6295: </select>
6296: <input type="hidden" name="folder" value="$imsfolder" />
6297: </p>
6298: <input type="hidden" name="phase" value="one" />
1.611 raeburn 6299: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 6300: </fieldset>
6301: </form>
6302: IMSFORM
1.329 droeschl 6303:
6304: my $fileuploadform=(<<FUFORM);
1.501 raeburn 6305: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6306: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6307: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 6308: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 6309: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6310: <input type="hidden" name="active" value="aa" />
1.595 musolffc 6311: $fileupload
1.702 raeburn 6312: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
6313: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 6314: <br />
6315: $lt{'title'}:<br />
1.611 raeburn 6316: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 6317: $pathitem
1.329 droeschl 6318: <input type="hidden" name="cmd" value="upload_default" />
6319: <br />
1.458 raeburn 6320: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6321: $checkbox
6322: </span>
1.501 raeburn 6323: <br clear="all" />
1.611 raeburn 6324: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 6325: </fieldset>
6326: </form>
1.383 tempelho 6327: FUFORM
1.329 droeschl 6328:
1.611 raeburn 6329: my $mapimportjs;
6330: if ($canedit) {
6331: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6332: } else {
6333: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6334: }
1.502 raeburn 6335: my $importpubform=(<<SEDFFORM);
1.514 raeburn 6336: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 6337: $lt{'impm'}</a>$help{'Load_Map'}
6338: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 6339: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 6340: <legend>$lt{'impm'}</legend>
1.371 tempelho 6341: <input type="hidden" name="active" value="bb" />
1.502 raeburn 6342: $lt{'copm'}<br />
6343: <span class="LC_nobreak">
6344: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 6345: onfocus="this.blur();$mapimportjs" $disabled />
6346: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6347: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 6348: </fieldset>
6349: </form>
6350:
1.383 tempelho 6351: SEDFFORM
1.606 raeburn 6352: my $importcrsresform;
1.608 raeburn 6353: my ($numdirs,$pickfile) =
1.690 raeburn 6354: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
1.608 raeburn 6355: "resize_scrollbox('contentscroll','1','0');",
6356: undef,'res');
1.606 raeburn 6357: if ($pickfile) {
6358: $importcrsresform=(<<CRSFORM);
1.690 raeburn 6359: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 6360: $lt{'imcr'}</a>$help{'Course_Resources'}
6361: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6362: <fieldset id="importcrsresform" style="display: none;">
6363: <legend>$lt{'imcr'}</legend>
1.698 raeburn 6364: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 6365: <input type="hidden" name="active" value="bb" />
6366: $pickfile
6367: <p>
1.699 raeburn 6368: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606 raeburn 6369: </p>
6370: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 6371: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 raeburn 6372: </div>
6373: <div id="importcrsresempty" style="display: none;">
6374: <p>
6375: $lt{'empd'}
6376: </p>
6377: </div>
1.606 raeburn 6378: </fieldset>
6379: </form>
6380: CRSFORM
6381: }
6382:
1.611 raeburn 6383: my $fromstoredjs;
6384: if ($canedit) {
6385: $fromstoredjs = 'open_StoredLinks_Import()';
6386: } else {
6387: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6388: }
6389:
1.502 raeburn 6390: my @importpubforma = (
1.508 raeburn 6391: { '<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 6392: { '<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.611 raeburn 6393: { '<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.606 raeburn 6394: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6395: );
6396: if ($pickfile) {
1.690 raeburn 6397: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\');" />' => $importcrsresform});
1.606 raeburn 6398: }
1.502 raeburn 6399: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 6400: my $extresourcesform =
6401: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6402: $help{'Adding_External_Resource'},
6403: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6404: my $exttoolform =
6405: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6406: $help{'Adding_External_Tool'},undef,
6407: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6408: \%ltitools,$disabled);
1.329 droeschl 6409: if ($allowed) {
1.492 raeburn 6410: my $folder = $env{'form.folder'};
6411: if ($folder eq '') {
6412: $folder='default';
6413: }
1.615 raeburn 6414: if ($canedit) {
6415: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6416: if ($output) {
6417: $r->print($output);
6418: }
1.538 raeburn 6419: }
1.337 ehlerst 6420: $r->print(<<HIDDENFORM);
6421: <form name="renameform" method="post" action="/adm/coursedocs">
6422: <input type="hidden" name="title" />
6423: <input type="hidden" name="cmd" />
6424: <input type="hidden" name="markcopy" />
6425: <input type="hidden" name="copyfolder" />
6426: $containertag
6427: </form>
1.633 raeburn 6428: <form name="aliasform" method="post" action="/adm/coursedocs">
6429: <input type="hidden" name="alias" />
6430: <input type="hidden" name="cmd" />
6431: $containertag
6432: </form>
1.484 raeburn 6433:
1.337 ehlerst 6434: HIDDENFORM
1.508 raeburn 6435: $r->print(&makesimpleeditform($pathitem)."\n".
6436: &makedocslogform($pathitem."\n".
1.484 raeburn 6437: '<input type="hidden" name="folder" value="'.
6438: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6439: }
1.442 www 6440:
6441: # Generate the tabs
1.510 raeburn 6442: my ($mode,$needs_end);
1.472 raeburn 6443: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6444: my @folders = split('&',$env{'form.folderpath'});
6445: unless (@folders > 2) {
6446: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6447: $needs_end = 1;
6448: }
1.472 raeburn 6449: } else {
1.484 raeburn 6450: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6451: $needs_end = 1;
1.472 raeburn 6452: }
1.443 www 6453:
1.442 www 6454: #
1.622 raeburn 6455: my $hostname = $r->hostname();
1.442 www 6456: my $savefolderpath;
6457:
1.395 raeburn 6458: if ($allowed) {
1.329 droeschl 6459: my $folder=$env{'form.folder'};
1.615 raeburn 6460: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6461: $folder='default';
1.356 tempelho 6462: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6463: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6464: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6465: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6466: }
6467: my $postexec='';
6468: if ($folder eq 'default') {
1.653 raeburn 6469: my $windowname = 'loncapaclient';
6470: if ($env{'request.lti.login'}) {
6471: $windowname .= 'lti';
6472: }
1.372 bisitz 6473: $r->print('<script type="text/javascript">'."\n"
6474: .'// <![CDATA['."\n"
1.653 raeburn 6475: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 6476: .'// ]]>'."\n"
6477: .'</script>'."\n"
1.369 bisitz 6478: );
1.329 droeschl 6479: } else {
6480: #$postexec='self.close();';
6481: }
1.504 raeburn 6482: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6483: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6484: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6485:
6486: my $newnavform=(<<NNFORM);
6487: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 6488: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6489: $pathitem
1.329 droeschl 6490: <input type="hidden" name="importdetail"
6491: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6492: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6493: $help{'Navigate_Content'}
6494: </form>
6495: NNFORM
6496: my $newsmppageform=(<<NSPFORM);
6497: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 6498: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6499: $pathitem
1.329 droeschl 6500: <input type="hidden" name="importdetail" value="" />
1.423 onken 6501: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6502: $help{'Simple Page'}
1.329 droeschl 6503: </form>
6504: NSPFORM
6505:
6506: my $newsmpproblemform=(<<NSPROBFORM);
6507: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 6508: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6509: $pathitem
1.329 droeschl 6510: <input type="hidden" name="importdetail" value="" />
1.423 onken 6511: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6512: $help{'Simple_Problem'}
1.329 droeschl 6513: </form>
6514:
6515: NSPROBFORM
6516:
6517: my $newdropboxform=(<<NDBFORM);
6518: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 6519: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6520: $pathitem
1.329 droeschl 6521: <input type="hidden" name="importdetail" value="" />
1.423 onken 6522: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6523: $help{'Dropbox'}
1.344 bisitz 6524: </form>
1.329 droeschl 6525: NDBFORM
6526:
6527: my $newexuploadform=(<<NEXUFORM);
6528: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 6529: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6530: $pathitem
1.329 droeschl 6531: <input type="hidden" name="importdetail" value="" />
1.423 onken 6532: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6533: $help{'Score_Upload_Form'}
6534: </form>
6535: NEXUFORM
6536:
6537: my $newbulform=(<<NBFORM);
6538: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 6539: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6540: $pathitem
1.329 droeschl 6541: <input type="hidden" name="importdetail" value="" />
1.423 onken 6542: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6543: $help{'Bulletin Board'}
6544: </form>
6545: NBFORM
6546:
6547: my $newaboutmeform=(<<NAMFORM);
6548: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 6549: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6550: $pathitem
1.329 droeschl 6551: <input type="hidden" name="importdetail"
6552: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6553: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6554: $help{'My Personal Information Page'}
1.329 droeschl 6555: </form>
6556: NAMFORM
6557:
6558: my $newaboutsomeoneform=(<<NASOFORM);
6559: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 6560: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6561: $pathitem
1.329 droeschl 6562: <input type="hidden" name="importdetail" value="" />
1.423 onken 6563: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6564: </form>
6565: NASOFORM
6566:
6567: my $newrosterform=(<<NROSTFORM);
6568: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 6569: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6570: $pathitem
1.329 droeschl 6571: <input type="hidden" name="importdetail"
6572: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6573: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6574: $help{'Course_Roster'}
1.329 droeschl 6575: </form>
6576: NROSTFORM
6577:
1.534 raeburn 6578: my $newwebpage;
6579: if ($folder =~ /^default_?(\d*)$/) {
6580: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6581: if ($1) {
6582: $newwebpage .= $1;
6583: } else {
6584: $newwebpage .= 'default';
6585: }
6586: $newwebpage .= '/new.html';
6587: }
6588: my $newwebpageform =(<<NWEBFORM);
6589: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 6590: <input type="hidden" name="active" value="ff" />
1.534 raeburn 6591: $pathitem
6592: <input type="hidden" name="importdetail" value="$newwebpage" />
6593: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6594: $help{'Web_Page'}
1.534 raeburn 6595: </form>
6596: NWEBFORM
1.701 raeburn 6597: my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606 raeburn 6598: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 6599: my $machines_str = "'".join("','",@ids)."'";
6600: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 6601: if ($env{'user.author'}) {
6602: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 6603: $is_home{'author'} = 1;
1.606 raeburn 6604: }
1.691 raeburn 6605: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 6606: }
6607: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6608: ['active'],['ca','aa']);
1.691 raeburn 6609: my %by_roletype;
1.606 raeburn 6610: if (keys(%roleshash)) {
6611: foreach my $entry (keys(%roleshash)) {
6612: my ($auname,$audom,$roletype) = split(/:/,$entry);
6613: my $key = $entry;
6614: $key =~ s/:/___/g;
1.691 raeburn 6615: my $author = $auname.'___'.$audom;
6616: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 6617: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 6618: $toppath{$author} = "/priv/$audom/$auname";
6619: if (grep(/^\Q$rolehome\E$/,@ids)) {
6620: $is_home{$author} = 1;
1.606 raeburn 6621: }
1.691 raeburn 6622: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
6623: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 6624: }
1.691 raeburn 6625: }
6626: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6627: if (grep(/^\Q$crshome\E$/,@ids)) {
6628: $is_home{'course'} = 1;
6629: }
6630: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
6631: my $pickdir = $lt{'loca'}.
6632: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
6633: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
6634: if ($env{'user.author'}) {
6635: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
6636: }
6637: if (keys(%by_roletype)) {
6638: foreach my $possrole ('ca','aa') {
6639: if (ref($by_roletype{$possrole}) eq 'HASH') {
6640: my $roletitle = &Apache::lonnet::plaintext($possrole);
6641: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6642: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
6643: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
6644: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 6645: }
6646: }
6647: }
6648: }
1.691 raeburn 6649: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n".
6650: '</select><br />'."\n".
6651: $lt{'dire'}.
6652: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
6653: '<option value=""></option>'.
6654: '</select><br />'."\n";
1.606 raeburn 6655:
6656: my %seltemplate_menus;
6657: my @files = &Apache::lonhomework::get_template_list('problem');
6658: my @noexamplelink = ('blank.problem','blank.library','script.library');
6659: my $currentcategory = '';
6660: my @ordered = ('');
6661: my %templatehelp;
6662: my $defcategory = '';
6663: my @catorder = ($defcategory);
6664: $seltemplate_menus{$defcategory}->{'order'} = [''];
6665: $seltemplate_menus{$defcategory}->{'text'} = '';
6666: foreach my $file (@files) {
6667: if (ref($file) eq 'ARRAY') {
6668: my ($path,$title,$category,$help) = @{$file};
6669: next if ($title !~ /\S/);
6670: if (&js_escape($category) ne $currentcategory) {
6671: $currentcategory = &js_escape($category);
6672: push(@catorder,&js_escape($currentcategory));
6673: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6674: $seltemplate_menus{$currentcategory}->{'default'} = '';
6675: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6676: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6677: }
6678: if ($path) {
6679: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6680: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6681: if ($help) {
6682: $templatehelp{$path} = $help;
6683: }
6684: }
6685: }
6686: }
6687:
6688: my $templates = $lt{'cate'}.' '.
6689: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6690: $defcategory,'tempcategory','template',
6691: \%seltemplate_menus,\@catorder,
6692: "resize_scrollbox('contentscroll','1','0');",
6693: "toggleExampleText();",'template').'<br />';
6694: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
1.701 raeburn 6695: '<span id="newresexample">'.&mt('Example').'</span></a>';
1.606 raeburn 6696: my $crsresform=(<<RESFORM);
1.691 raeburn 6697: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.606 raeburn 6698: $lt{'stpr'}</a>$help{'Course_Resource'}
6699: <form action="/adm/coursedocs" method="post" name="courseresform">
6700: <fieldset id="crsresform" style="display:none;">
6701: <legend>$lt{'stpr'}</legend>
1.655 raeburn 6702: <input type="hidden" name="active" value="bb" />
1.606 raeburn 6703: <p>
6704: $pickdir
1.701 raeburn 6705: </p>
1.691 raeburn 6706: <div id="newstdproblem" style="display:none;">
1.701 raeburn 6707: <p>
1.606 raeburn 6708: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6709: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6710:
1.611 raeburn 6711: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6712: </span><span id="newsubdir"></span>
6713: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701 raeburn 6714: </p>
1.699 raeburn 6715: </div>
1.606 raeburn 6716: $lt{'fnam'}
1.611 raeburn 6717: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.701 raeburn 6718: <div id="newresource" style="display:none">
1.606 raeburn 6719: <p>
6720: $lt{'addp'}
1.611 raeburn 6721: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6722: $lt{'no'}</label>
1.611 raeburn 6723: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6724: $lt{'yes'}</label>
6725: <span id="newrestitle"></span>
1.611 raeburn 6726: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701 raeburn 6727: </p>
1.606 raeburn 6728: </div>
6729: <p>
6730: $lt{'uste'}
1.611 raeburn 6731: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6732: $lt{'no'}</label>
1.611 raeburn 6733: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6734: $lt{'yes'}</label>
1.701 raeburn 6735: </p>
1.606 raeburn 6736: <div id="newrestemplate" style="display:none">
6737: $templates
6738: $templatepreview
6739: </div>
6740: <span class="LC_nobreak">
1.701 raeburn 6741: <input type="hidden" name="folderpath" value="$showpath" />
1.611 raeburn 6742: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6743: </span>
1.691 raeburn 6744: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 6745: $rolehomes
6746: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
6747: </div>
1.606 raeburn 6748: </fieldset>
6749: </form>
6750:
6751: RESFORM
1.534 raeburn 6752:
1.342 ehlerst 6753: my $specialdocumentsform;
1.383 tempelho 6754: my @specialdocumentsforma;
1.451 www 6755: my $gradingform;
6756: my @gradingforma;
6757: my $communityform;
6758: my @communityforma;
1.351 ehlerst 6759: my $newfolderform;
1.390 tempelho 6760: my $newfolderb;
1.342 ehlerst 6761:
1.451 www 6762: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6763:
1.329 droeschl 6764: my $newpageform=(<<NPFORM);
6765: <form action="/adm/coursedocs" method="post" name="newpage">
6766: <input type="hidden" name="folderpath" value="$path" />
6767: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6768: <input type="hidden" name="active" value="ee" />
1.423 onken 6769: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6770: $help{'Adding_Pages'}
1.329 droeschl 6771: </form>
6772: NPFORM
1.390 tempelho 6773:
6774:
1.351 ehlerst 6775: $newfolderform=(<<NFFORM);
1.329 droeschl 6776: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6777: $pathitem
1.329 droeschl 6778: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6779: <input type="hidden" name="active" value="" />
1.422 onken 6780: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6781: </form>
6782: NFFORM
6783:
6784: my $newsylform=(<<NSYLFORM);
6785: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6786: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6787: $pathitem
1.329 droeschl 6788: <input type="hidden" name="importdetail"
6789: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6790: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6791: $help{'Syllabus'}
1.383 tempelho 6792:
1.329 droeschl 6793: </form>
6794: NSYLFORM
1.364 bisitz 6795:
1.329 droeschl 6796: my $newgroupfileform=(<<NGFFORM);
6797: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 6798: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6799: $pathitem
1.329 droeschl 6800: <input type="hidden" name="importdetail"
6801: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6802: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6803: $help{'Group Portfolio'}
1.329 droeschl 6804: </form>
6805: NGFFORM
1.672 raeburn 6806: if ($container eq 'page') {
6807: @specialdocumentsforma=(
6808: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6809: );
6810: } else {
6811: @specialdocumentsforma=(
1.421 onken 6812: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.618 raeburn 6813: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6814: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6815: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6816: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 6817: );
6818: }
1.451 www 6819: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6820:
1.655 raeburn 6821: my @external = (
6822: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 6823: );
1.699 raeburn 6824: if ($posslti) {
1.655 raeburn 6825: push(@external,
6826: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6827: );
1.598 raeburn 6828: }
1.655 raeburn 6829: my $externalform = &create_form_ul(&create_list_elements(@external));
6830:
6831: my @importdoc = ();
1.519 raeburn 6832: unless ($container eq 'page') {
6833: push(@importdoc,
6834: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6835: );
6836: }
6837: push(@importdoc,
1.558 raeburn 6838: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6839: );
1.501 raeburn 6840: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6841:
1.451 www 6842: @gradingforma=(
6843: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6844: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6845: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.691 raeburn 6846: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform},
1.451 www 6847: );
6848: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6849:
6850: @communityforma=(
6851: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6852: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6853: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6854: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6855: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6856: );
6857: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6858:
1.330 tempelho 6859: my %orderhash = (
1.553 raeburn 6860: 'aa' => ['Upload',$fileuploadform],
6861: 'bb' => ['Import',$importpubform],
1.655 raeburn 6862: 'cc' => ['External',$externalform],
1.701 raeburn 6863: 'dd' => ['Assessment',$gradingform],
1.673 raeburn 6864: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 6865: );
1.519 raeburn 6866: unless ($container eq 'page') {
1.434 raeburn 6867: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 6868: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 6869: }
6870:
1.341 ehlerst 6871: $hadchanges=0;
1.484 raeburn 6872: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6873: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6874: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6875: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6876: undef($navmap);
1.443 www 6877: if ($error) {
6878: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6879: }
1.639 raeburn 6880: if ($hadchanges) {
6881: unless (&is_hash_old()) {
1.638 raeburn 6882: &mark_hash_old();
6883: }
6884: }
1.341 ehlerst 6885:
1.443 www 6886: &changewarning($r,'');
6887: }
1.458 raeburn 6888: }
1.442 www 6889:
1.443 www 6890: # Supplemental documents start here
6891:
1.329 droeschl 6892: my $folder=$env{'form.folder'};
1.443 www 6893: unless ($supplementalflag) {
1.329 droeschl 6894: $folder='supplemental';
6895: }
1.685 raeburn 6896: if (($folder eq 'supplemental') &&
1.329 droeschl 6897: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6898: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6899: } elsif ($allowed) {
1.356 tempelho 6900: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6901: }
1.508 raeburn 6902: $pathitem = '<input type="hidden" name="folderpath" value="'.
6903: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6904: if ($allowed) {
6905: my $folderseq=
1.504 raeburn 6906: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6907:
6908: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6909: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6910: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6911: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6912: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6913: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6914: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6915: $fileupload
1.702 raeburn 6916: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
6917: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 6918: <br />
6919: <br />
6920: <span class="LC_nobreak">
6921: $checkbox
6922: </span>
6923: <br /><br />
6924: $lt{'comment'}:<br />
1.383 tempelho 6925: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6926: <br />
1.508 raeburn 6927: $pathitem
1.329 droeschl 6928: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6929: <input type='submit' value="$lt{'upld'}" />
1.700 raeburn 6930: </fieldset>
1.501 raeburn 6931: </form>
1.329 droeschl 6932: SUPDOCFORM
6933:
6934: my $supnewfolderform=(<<SNFFORM);
6935: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6936: <input type="hidden" name="active" value="" />
1.508 raeburn 6937: $pathitem
1.329 droeschl 6938: <input type="hidden" name="importdetail" value="" />
1.423 onken 6939: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6940: $help{'Adding_Folders'}
1.329 droeschl 6941: </form>
6942: SNFFORM
1.383 tempelho 6943:
1.510 raeburn 6944: my $supextform =
6945: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6946: $help{'Adding_External_Resource'},
6947: undef,undef,undef,undef,undef,undef,
6948: $disabled);
1.329 droeschl 6949:
1.598 raeburn 6950: my $supexttoolform =
6951: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6952: $help{'Adding_External_Tool'},
6953: undef,undef,'tool',$coursedom,
1.611 raeburn 6954: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6955:
1.329 droeschl 6956: my $supnewsylform=(<<SNSFORM);
6957: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6958: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6959: $pathitem
1.329 droeschl 6960: <input type="hidden" name="importdetail"
6961: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6962: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6963: $help{'Syllabus'}
6964: </form>
6965: SNSFORM
6966:
6967: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6968: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6969: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6970: $pathitem
1.329 droeschl 6971: <input type="hidden" name="importdetail"
6972: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6973: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6974: $help{'My Personal Information Page'}
1.329 droeschl 6975: </form>
6976: SNAMFORM
6977:
1.534 raeburn 6978: my $supwebpage;
6979: if ($folder =~ /^supplemental_?(\d*)$/) {
6980: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6981: if ($1) {
6982: $supwebpage .= $1;
6983: } else {
6984: $supwebpage .= 'default';
6985: }
6986: $supwebpage .= '/new.html';
6987: }
6988: my $supwebpageform =(<<SWEBFORM);
6989: <form action="/adm/coursedocs" method="post" name="supwebpage">
6990: <input type="hidden" name="active" value="cc" />
6991: $pathitem
6992: <input type="hidden" name="importdetail" value="$supwebpage" />
6993: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6994: $help{'Web_Page'}
1.534 raeburn 6995: </form>
6996: SWEBFORM
6997:
1.333 muellerd 6998:
1.383 tempelho 6999: my @specialdocs = (
1.618 raeburn 7000: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 7001: =>$supnewsylform},
1.611 raeburn 7002: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 7003: =>$supnewaboutmeform},
1.534 raeburn 7004: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
7005:
1.383 tempelho 7006: );
1.655 raeburn 7007: my @supexternal = (
7008: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
7009: =>$supextform});
1.699 raeburn 7010: if ($posslti) {
1.655 raeburn 7011: push(@supexternal,
7012: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 7013: =>$supexttoolform});
7014: }
1.655 raeburn 7015: my @supimportdoc = (
1.598 raeburn 7016: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 7017: =>$supupdocform},
1.598 raeburn 7018: );
1.501 raeburn 7019:
7020: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 7021: my %suporderhash = (
1.390 tempelho 7022: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 7023: 'dd' => ['Upload',$supupdocform],
7024: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 7025: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 7026: );
1.443 www 7027: if ($supplementalflag) {
1.682 raeburn 7028: $suppchanges = 0;
7029: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
7030: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
7031: \%ltitools,$canedit,$hostname);
7032: if ($error) {
7033: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7034: }
7035: if ($suppchanges) {
1.684 raeburn 7036: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 7037: undef($suppchanges);
7038: }
1.393 raeburn 7039: }
1.443 www 7040: } elsif ($supplementalflag) {
1.458 raeburn 7041: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 7042: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
7043: $hostname);
1.393 raeburn 7044: if ($error) {
7045: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 7046: }
1.393 raeburn 7047: }
1.389 tempelho 7048:
1.510 raeburn 7049: if ($needs_end) {
7050: $r->print(&endContentScreen());
7051: }
1.383 tempelho 7052:
1.329 droeschl 7053: if ($allowed) {
7054: $r->print('
7055: <form method="post" name="extimport" action="/adm/coursedocs">
7056: <input type="hidden" name="title" />
7057: <input type="hidden" name="url" />
7058: <input type="hidden" name="useform" />
7059: <input type="hidden" name="residx" />
7060: </form>');
7061: }
1.484 raeburn 7062: } elsif ($showdoc) {
1.329 droeschl 7063: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 7064: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 7065: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 7066: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 7067: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 7068: }
7069: }
1.630 raeburn 7070: unless ($noendpage) {
1.606 raeburn 7071: $r->print(&Apache::loncommon::end_page());
7072: }
1.329 droeschl 7073: return OK;
1.364 bisitz 7074: }
1.329 droeschl 7075:
1.440 raeburn 7076: sub embedded_form_elems {
7077: my ($phase,$primaryurl,$newidx) = @_;
7078: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 7079: $newidx =~s /\D+//g;
1.440 raeburn 7080: return <<STATE;
7081: <input type="hidden" name="folderpath" value="$folderpath" />
7082: <input type="hidden" name="cmd" value="upload_embedded" />
7083: <input type="hidden" name="newidx" value="$newidx" />
7084: <input type="hidden" name="phase" value="$phase" />
7085: <input type="hidden" name="primaryurl" value="$primaryurl" />
7086: STATE
7087: }
7088:
7089: sub embedded_destination {
7090: my $folder=$env{'form.folder'};
7091: my $destination = 'docs/';
7092: if ($folder =~ /^supplemental/) {
7093: $destination = 'supplemental/';
7094: }
7095: if (($folder eq 'default') || ($folder eq 'supplemental')) {
7096: $destination .= 'default/';
7097: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
7098: $destination .= $2.'/';
7099: }
1.634 raeburn 7100: my $newidx = $env{'form.newidx'};
7101: $newidx =~s /\D+//g;
7102: if ($newidx) {
7103: $destination .= $newidx;
7104: }
1.440 raeburn 7105: my $dir_root = '/userfiles';
7106: return ($destination,$dir_root);
7107: }
7108:
7109: sub return_to_editor {
7110: my $actionurl = '/adm/coursedocs';
7111: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7112: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7113: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7114: '</a></p>';
7115: }
7116:
1.476 raeburn 7117: sub decompression_info {
7118: my ($destination,$dir_root) = &embedded_destination();
7119: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7120: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7121: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7122: my $container='sequence';
1.480 raeburn 7123: my ($pathitem,$hiddenelem);
1.583 raeburn 7124: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 7125: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 7126: $container='page';
7127: }
1.480 raeburn 7128: unshift(@hiddens,$pathitem);
7129: foreach my $item (@hiddens) {
1.634 raeburn 7130: if ($item eq 'newidx') {
7131: next if ($env{'form.'.$item} =~ /\D/);
7132: }
1.480 raeburn 7133: if ($env{'form.'.$item}) {
7134: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 7135: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 7136: }
1.477 raeburn 7137: }
1.476 raeburn 7138: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7139: $hiddenelem);
7140: }
7141:
7142: sub decompression_phase_one {
7143: my ($dir,$file,$warning,$error,$output);
7144: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7145: &decompression_info();
1.490 raeburn 7146: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 7147: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7148: } else {
7149: my $file = $1;
1.630 raeburn 7150: $output =
1.481 raeburn 7151: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7152: $destination,$dir_root,
7153: $hiddenelem);
7154: if ($env{'form.autoextract_camtasia'}) {
7155: $output .= &remove_archive($docudom,$docuname,$container);
7156: }
1.476 raeburn 7157: }
7158: if ($error) {
7159: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7160: $error.'</p>'."\n";
7161: }
7162: if ($warning) {
7163: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7164: }
7165: return $output;
7166: }
7167:
7168: sub decompression_phase_two {
7169: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7170: &decompression_info();
1.481 raeburn 7171: my $output;
1.480 raeburn 7172: if ($env{'form.archivedelete'}) {
1.481 raeburn 7173: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 7174: }
7175: $output .=
1.481 raeburn 7176: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 7177: $destination,$dir_root,$hiddenelem);
7178: return $output;
7179: }
7180:
1.480 raeburn 7181: sub remove_archive {
7182: my ($docudom,$docuname,$container) = @_;
7183: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 7184: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 7185: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7186: if ($fatal) {
7187: if ($container eq 'page') {
7188: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7189: } else {
7190: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7191: }
1.583 raeburn 7192: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7193: } else {
7194: my $currcmd = $env{'form.cmd'};
7195: my $position = $env{'form.position'};
1.583 raeburn 7196: my $archiveidx = $position;
1.563 raeburn 7197: if ($position > 0) {
1.583 raeburn 7198: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7199: $archiveidx = $position-1;
7200: }
7201: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 7202: my ($title,$url,@rrest) =
1.583 raeburn 7203: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7204: if ($url eq $env{'form.archiveurl'}) {
7205: if (&handle_edit_cmd($docuname,$docudom)) {
7206: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 7207: if ($suppchanges) {
7208: &Apache::lonnet::update_supp_caches($docudom,$docuname);
7209: undef($suppchanges);
7210: }
1.583 raeburn 7211: if ($fatal) {
7212: if ($container eq 'page') {
7213: $delwarning = &mt('An error occurred updating the contents of the current page.');
7214: } else {
7215: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7216: }
1.480 raeburn 7217: } else {
1.583 raeburn 7218: $delresult = &mt('Archive file removed.');
1.480 raeburn 7219: }
7220: }
1.583 raeburn 7221: } else {
7222: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7223: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7224: }
7225: }
7226: $env{'form.cmd'} = $currcmd;
7227: }
7228: if ($delwarning) {
7229: $output = '<p class="LC_warning">'.
7230: $delwarning.
7231: '</p>';
7232: }
7233: if ($delresult) {
7234: $output .= '<p class="LC_info">'.
7235: $delresult.
7236: '</p>';
7237: }
1.481 raeburn 7238: return $output;
1.480 raeburn 7239: }
7240:
1.484 raeburn 7241: sub generate_admin_menu {
1.611 raeburn 7242: my ($crstype,$canedit) = @_;
1.484 raeburn 7243: my $lc_crstype = lc($crstype);
7244: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 7245: my %lt= ( # do not translate here
1.484 raeburn 7246: 'vc' => 'Verify Content',
7247: 'cv' => 'Check/Set Resource Versions',
7248: 'ls' => 'List Resource Identifiers',
1.651 raeburn 7249: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 7250: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 7251: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 7252: );
1.484 raeburn 7253: my ($candump,$dumpurl);
7254: if ($home + $other > 0) {
7255: $candump = 'F';
7256: if ($home) {
7257: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7258: } else {
7259: my @hosts;
7260: foreach my $aurole (keys(%outhash)) {
7261: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7262: push(@hosts,$outhash{$aurole});
1.538 raeburn 7263: }
1.484 raeburn 7264: }
7265: if (@hosts == 1) {
7266: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7267: '&role='.
7268: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7269: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7270: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7271: } else {
7272: $dumpurl = "javascript:choose_switchserver_window()";
7273: }
7274: }
7275: }
7276: my @menu=
7277: ({ categorytitle=>'Administration',
7278: items =>[
7279: { linktext => $lt{'vc'},
7280: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7281: permission => 'F',
1.571 raeburn 7282: help => 'Docs_Verify_Content',
1.484 raeburn 7283: icon => 'verify.png',
7284: linktitle => 'Verify contents can be retrieved/rendered',
7285: },
7286: { linktext => $lt{'cv'},
7287: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7288: permission => 'F',
1.571 raeburn 7289: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7290: icon => 'resversion.png',
7291: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7292: },
7293: { linktext => $lt{'ls'},
7294: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7295: permission => 'F',
7296: #help => '',
7297: icon => 'symbs.png',
7298: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7299: },
1.651 raeburn 7300: { linktext => $lt{'ct'},
7301: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7302: permission => 'F',
7303: help => 'Docs_Short_URLs',
7304: icon => 'shorturls.png',
7305: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7306: },
1.484 raeburn 7307: ]
1.611 raeburn 7308: });
7309: if ($canedit) {
7310: push(@menu,
1.484 raeburn 7311: { categorytitle=>'Export',
7312: items =>[
7313: { linktext => $lt{'imse'},
7314: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7315: permission => 'F',
7316: help => 'Docs_Export_Course_Docs',
7317: icon => 'imsexport.png',
7318: linktitle => $lt{'imse'},
7319: },
7320: { linktext => $lt{'dcd'},
7321: url => $dumpurl,
7322: permission => $candump,
1.571 raeburn 7323: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7324: icon => 'dump.png',
7325: linktitle => $lt{'dcd'},
7326: },
7327: ]
7328: });
1.611 raeburn 7329: }
1.484 raeburn 7330: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7331: '<input type="hidden" id="dummy" />'."\n".
7332: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7333: '</form>';
1.329 droeschl 7334: }
7335:
7336: sub generate_edit_table {
1.538 raeburn 7337: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 7338: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7339: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7340: my %orderhash = %{$orderhash_ref};
1.611 raeburn 7341: my ($form, $activetab, $active, $disabled);
1.570 raeburn 7342: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7343: $activetab = $env{'form.active'};
7344: }
1.611 raeburn 7345: unless ($canedit) {
7346: $disabled = ' disabled="disabled"';
7347: }
1.472 raeburn 7348: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 7349: my $backtext = &mt('Exit Editor');
1.458 raeburn 7350: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 7351: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7352: '<li class="goback">'.
1.546 raeburn 7353: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 7354: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7355: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7356: '<li>'.
7357: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7358: &mt('Undo Delete').'</a></li>'."\n";
7359: if ($env{'form.docslog'}) {
7360: $form .= '<li class="active">';
7361: } else {
7362: $form .= '<li>';
7363: }
7364: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7365: &mt('History').'</a></li>'."\n";
7366: if ($env{'form.docslog'}) {
7367: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7368: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7369: }
1.458 raeburn 7370: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7371: if($name ne '00'){
1.371 tempelho 7372: if($activetab eq '' || $activetab ne $name){
7373: $active = '';
7374: }elsif($activetab eq $name){
7375: $active = 'class="active"';
7376: }
1.458 raeburn 7377: $form .= '<li style="float:right" '.$active
1.484 raeburn 7378: .' 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 7379: } else {
1.570 raeburn 7380: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7381:
7382: }
1.329 droeschl 7383: }
1.484 raeburn 7384: $form .= '</ul>'."\n";
7385: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7386:
7387: if ($to_show ne '') {
1.538 raeburn 7388: my $saveform;
7389: if ($need_save) {
7390: my $button = &mt('Make changes');
7391: my $path;
7392: if ($env{'form.folderpath'}) {
7393: $path =
7394: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7395: }
7396: $saveform = <<"END";
7397: <div id="multisave" style="display:none; clear:both;" >
7398: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7399: <input type="hidden" name="folderpath" value="$path" />
7400: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7401: <input type="hidden" name="allhiddenresource" value="" />
7402: <input type="hidden" name="allencrypturl" value="" />
7403: <input type="hidden" name="allrandompick" value="" />
7404: <input type="hidden" name="allrandomorder" value="" />
7405: <input type="hidden" name="changeparms" value="" />
7406: <input type="hidden" name="multiremove" value="" />
7407: <input type="hidden" name="multicut" value="" />
7408: <input type="hidden" name="multicopy" value="" />
7409: <input type="hidden" name="multichange" value="" />
7410: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7411: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7412: </form>
7413: </div>
7414: END
7415: }
7416: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7417: }
1.363 ehlerst 7418: foreach my $field (keys(%orderhash)){
1.390 tempelho 7419: if($field ne '00'){
1.422 onken 7420: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7421: $active = 'style="display: none;float:left"';
1.422 onken 7422: }elsif($activetab eq $field){
1.458 raeburn 7423: $active = 'style="display:block;float:left"';
1.422 onken 7424: }
7425: $form .= '<div id="'.$field.$tid.'"'
7426: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7427: .'</div>'."\n";
1.363 ehlerst 7428: }
7429: }
1.484 raeburn 7430: unless ($env{'form.docslog'}) {
7431: $form .= '</div></div>'."\n";
7432: }
1.329 droeschl 7433: return $form;
7434: }
7435:
7436: sub editing_js {
1.622 raeburn 7437: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7438: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7439: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7440: p_mnf => 'Name of New Folder',
7441: t_mnf => 'New Folder',
7442: p_mnp => 'Name of New Page',
7443: t_mnp => 'New Page',
1.451 www 7444: p_mxu => 'Title for the External Score',
1.349 biermanm 7445: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7446: p_msb => 'Title for the Problem',
7447: p_mdb => 'Title for the Drop Box',
1.336 schafran 7448: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7449: p_mwp => 'Title for Web Page',
1.606 raeburn 7450: p_mnr => 'Title for the Resource',
1.348 weissno 7451: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7452: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7453: p_mab_alrt1 => 'Not a valid user:domain',
7454: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7455: p_chn => 'New Title',
7456: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7457: p_rmr2a => 'Remove',
7458: p_rmr2b => '?',
7459: p_rmr3a => 'Remove those',
7460: p_rmr3b => 'items?',
7461: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7462: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7463: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7464: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7465: p_ctr2a => 'Cut',
7466: p_ctr2b => '?',
7467: p_ctr3a => 'Cut those',
7468: p_ctr3b => 'items?',
1.633 raeburn 7469: setal => 'Enter a (unique) alias',
7470: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7471: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7472: imsfile => 'You must choose an IMS package for import',
7473: imscms => 'You must select which Course Management System was the source of the IMS package',
7474: invurl => 'Invalid URL',
7475: titbl => 'Title is blank',
1.538 raeburn 7476: more => '(More ...)',
7477: less => '(Less ...)',
1.543 raeburn 7478: noor => 'No actions selected or changes to settings specified.',
7479: noch => 'No changes to settings specified.',
7480: noac => 'No actions selected.',
1.606 raeburn 7481: nofi => 'No file selected',
7482: tinc => 'Title in course',
7483: sunm => 'Sub-directory name',
1.618 raeburn 7484: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 7485: sele => 'Select',
7486: swit => 'Switch server required',
1.329 droeschl 7487: );
1.594 damieng 7488: &js_escape(\%js_lt);
1.433 raeburn 7489: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7490: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7491: my $main_container_page;
1.519 raeburn 7492: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7493: $main_container_page = 1;
1.434 raeburn 7494: }
1.617 raeburn 7495: my $backtourl;
7496: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7497: my $toplevelsupp = &supplemental_base();
1.690 raeburn 7498: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 7499: my @ids=&Apache::lonnet::current_machine_ids();
7500: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 7501: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7502: my $caller = $1;
1.525 raeburn 7503: if ($caller =~ /^supplemental/) {
7504: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7505: } else {
7506: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7507: $res = &Apache::lonnet::clutter($res);
7508: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7509: my ($url,$anchor);
7510: if ($res =~ /^([^#]+)#([^#]+)$/) {
7511: $url = $1;
7512: $anchor = $2;
7513: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7514: $caller = $1.&escape('#').$anchor;
7515: }
1.614 raeburn 7516: } else {
7517: $url = $res;
1.609 raeburn 7518: }
1.640 raeburn 7519: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7520: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7521: $backtourl .= '?navmap=1';
7522: } else {
7523: $backtourl .= '?symb='.
7524: &HTML::Entities::encode($caller,'<>&"');
7525: }
1.622 raeburn 7526: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7527: if (($ENV{'SERVER_PORT'} == 443) &&
7528: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 7529: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 7530: if ($hostname ne '') {
7531: $backtourl = 'http://'.$hostname.$backtourl;
7532: }
7533: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7534: }
7535: }
1.623 raeburn 7536: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7537: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 7538: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 7539: if ($hostname ne '') {
7540: $backtourl = 'http://'.$hostname.$backtourl;
7541: }
7542: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 7543: }
1.623 raeburn 7544: }
1.622 raeburn 7545: }
1.609 raeburn 7546: if ($anchor ne '') {
7547: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7548: }
1.590 raeburn 7549: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7550: } else {
7551: $backtourl = '/adm/navmaps';
1.525 raeburn 7552: }
7553: }
7554: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7555: $backtourl = '/adm/menu';
7556: } elsif ($supplementalflag) {
1.682 raeburn 7557: if (($env{'request.role.adv'}) ||
7558: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7559: $backtourl = '/adm/supplemental';
7560: } else {
7561: $backtourl = '/adm/navmaps';
7562: }
1.525 raeburn 7563: } else {
7564: $backtourl = '/adm/navmaps';
1.472 raeburn 7565: }
7566:
1.655 raeburn 7567: my $fieldsets = "'doc'";
1.519 raeburn 7568: unless ($main_container_page) {
7569: $fieldsets .=",'ims'";
7570: }
1.655 raeburn 7571: my $extfieldsets = "'ext'";
7572: if ($posslti) {
7573: $extfieldsets .= ",'tool'";
7574: }
1.501 raeburn 7575: if ($supplementalflag) {
1.655 raeburn 7576: $fieldsets = "'suppdoc'";
7577: $extfieldsets = "'suppext'";
1.600 raeburn 7578: if ($posslti) {
1.655 raeburn 7579: $extfieldsets .= ",'supptool'";
1.600 raeburn 7580: }
1.501 raeburn 7581: }
1.655 raeburn 7582:
1.611 raeburn 7583: my $jsmakefunctions;
7584: if ($canedit) {
7585: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7586: function makenewfolder(targetform,folderseq) {
1.594 damieng 7587: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7588: if (foldername) {
1.676 raeburn 7589: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 7590: targetform.submit();
7591: }
7592: }
7593:
7594: function makenewpage(targetform,folderseq) {
1.594 damieng 7595: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7596: if (pagename) {
1.676 raeburn 7597: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 7598: targetform.submit();
7599: }
7600: }
7601:
7602: function makeexamupload() {
1.594 damieng 7603: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7604: if (title) {
1.329 droeschl 7605: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 7606: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 7607: this.document.forms.newexamupload.submit();
7608: }
7609: }
7610:
7611: function makesmppage() {
1.594 damieng 7612: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7613: if (title) {
1.329 droeschl 7614: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 7615: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7616: this.document.forms.newsmppg.submit();
7617: }
7618: }
7619:
1.534 raeburn 7620: function makewebpage(type) {
1.594 damieng 7621: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7622: var formname;
7623: if (type == 'supp') {
7624: formname = this.document.forms.supwebpage;
7625: } else {
7626: formname = this.document.forms.newwebpage;
7627: }
7628: if (title) {
7629: var webpage = formname.importdetail.value;
1.675 raeburn 7630: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 7631: formname.submit();
7632: }
7633: }
7634:
1.329 droeschl 7635: function makesmpproblem() {
1.594 damieng 7636: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7637: if (title) {
1.329 droeschl 7638: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 7639: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 7640: this.document.forms.newsmpproblem.submit();
7641: }
7642: }
7643:
7644: function makedropbox() {
1.594 damieng 7645: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7646: if (title) {
1.329 droeschl 7647: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 7648: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 7649: this.document.forms.newdropbox.submit();
7650: }
7651: }
7652:
7653: function makebulboard() {
1.594 damieng 7654: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7655: if (title) {
7656: this.document.forms.newbul.importdetail.value=
1.676 raeburn 7657: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7658: this.document.forms.newbul.submit();
7659: }
7660: }
7661:
7662: function makeabout() {
1.594 damieng 7663: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7664: if (user) {
7665: var comp=new Array();
7666: comp=user.split(':');
7667: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7668: if ((comp[0]) && (comp[1])) {
7669: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7670: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7671: this.document.forms.newaboutsomeone.submit();
7672: } else {
7673: alert("$js_lt{'p_mab_alrt1'}");
7674: }
7675: } else {
7676: alert("$js_lt{'p_mab_alrt2'}");
7677: }
7678: }
7679: }
7680:
7681: function makenew(targetform) {
7682: targetform.submit();
7683: }
7684:
7685: function changename(folderpath,index,oldtitle) {
7686: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7687: if (title) {
7688: this.document.forms.renameform.markcopy.value='';
7689: this.document.forms.renameform.title.value=title;
7690: this.document.forms.renameform.cmd.value='rename_'+index;
7691: this.document.forms.renameform.folderpath.value=folderpath;
7692: this.document.forms.renameform.submit();
7693: }
7694: }
7695:
1.633 raeburn 7696: function setalias(folderpath,index) {
7697: var alias = prompt('$js_lt{"setal"}');
7698: if ((alias != null) && (alias != '')) {
7699: this.document.forms.aliasform.alias.value=alias;
7700: this.document.forms.aliasform.cmd.value='setalias_'+index;
7701: this.document.forms.aliasform.folderpath.value=folderpath;
7702: this.document.forms.aliasform.submit();
7703: }
7704: }
7705:
7706: function delalias(folderpath,index) {
7707: if (confirm('$js_lt{"delal"}')) {
7708: this.document.forms.aliasform.cmd.value='delalias_'+index;
7709: this.document.forms.aliasform.folderpath.value=folderpath;
7710: this.document.forms.aliasform.submit();
7711: }
7712: }
7713:
1.611 raeburn 7714: ENDNEWSCRIPT
7715: } else {
7716: $jsmakefunctions = <<ENDNEWSCRIPT;
7717:
7718: function makenewfolder() {
7719: alert("$js_lt{'edri'}");
7720: }
7721:
7722: function makenewpage() {
7723: alert("$js_lt{'edri'}");
7724: }
7725:
7726: function makeexamupload() {
7727: alert("$js_lt{'edri'}");
7728: }
7729:
7730: function makesmppage() {
7731: alert("$js_lt{'edri'}");
7732: }
7733:
7734: function makewebpage(type) {
7735: alert("$js_lt{'edri'}");
7736: }
7737:
7738: function makesmpproblem() {
7739: alert("$js_lt{'edri'}");
7740: }
7741:
7742: function makedropbox() {
7743: alert("$js_lt{'edri'}");
7744: }
7745:
7746: function makebulboard() {
7747: alert("$js_lt{'edri'}");
7748: }
7749:
7750: function makeabout() {
7751: alert("$js_lt{'edri'}");
7752: }
7753:
7754: function changename() {
7755: alert("$js_lt{'edri'}");
7756: }
7757:
1.633 raeburn 7758: function setalias() {
7759: alert("$js_lt{'edri'}");
7760: }
7761:
7762: function delalias() {
7763: alert("$js_lt{'edri'}");
7764: }
7765:
1.611 raeburn 7766: function makenew() {
7767: alert("$js_lt{'edri'}");
7768: }
7769:
7770: function groupimport() {
7771: alert("$js_lt{'edri'}");
1.335 ehlerst 7772: }
1.611 raeburn 7773:
7774: function groupsearch() {
7775: alert("$js_lt{'edri'}");
1.335 ehlerst 7776: }
1.611 raeburn 7777:
7778: function groupopen(url,recover) {
7779: var options="scrollbars=1,resizable=1,menubar=0";
7780: idxflag=1;
7781: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7782: idx.focus();
1.329 droeschl 7783: }
7784:
1.611 raeburn 7785: ENDNEWSCRIPT
7786:
7787: }
7788: return <<ENDSCRIPT;
7789:
7790: $jsmakefunctions
7791:
1.501 raeburn 7792: function toggleUpload(caller) {
7793: var blocks = Array($fieldsets);
7794: for (var i=0; i<blocks.length; i++) {
7795: var disp = 'none';
7796: if (caller == blocks[i]) {
7797: var curr = document.getElementById('upload'+caller+'form').style.display;
7798: if (curr == 'none') {
7799: disp='block';
7800: }
7801: }
7802: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 7803: }
7804: resize_scrollbox('contentscroll','1','1');
7805: return;
7806: }
7807:
7808: function toggleExternal(caller) {
7809: var blocks = Array($extfieldsets);
7810: for (var i=0; i<blocks.length; i++) {
7811: var disp = 'none';
7812: if (caller == blocks[i]) {
7813: var curr = document.getElementById('external'+caller+'form').style.display;
7814: if (curr == 'none') {
7815: disp='block';
7816: }
7817: }
7818: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7819: if ((caller == 'tool') || (caller == 'supptool')) {
7820: if (disp == 'block') {
1.655 raeburn 7821: if (document.getElementById('LC_exttoolid')) {
7822: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 7823: var suppflag = 0;
7824: if (caller == 'supptool') {
7825: suppflag = 1;
7826: }
7827: currForm = document.getElementById('new'+caller);
1.655 raeburn 7828: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 7829: }
7830: }
7831: }
1.501 raeburn 7832: }
1.502 raeburn 7833: resize_scrollbox('contentscroll','1','1');
7834: return;
7835: }
7836:
1.514 raeburn 7837: function toggleMap(caller) {
1.502 raeburn 7838: var disp = 'none';
1.510 raeburn 7839: if (document.getElementById('importmapform')) {
1.514 raeburn 7840: if (caller == 'map') {
7841: var curr = document.getElementById('importmapform').style.display;
7842: if (curr == 'none') {
7843: disp='block';
7844: }
1.510 raeburn 7845: }
7846: document.getElementById('importmapform').style.display=disp;
7847: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7848: }
1.501 raeburn 7849: return;
1.329 droeschl 7850: }
7851:
1.691 raeburn 7852: function toggleCrsRes(caller) {
1.606 raeburn 7853: var disp = 'none';
7854: if (document.getElementById('crsresform')) {
7855: if (caller == 'res') {
1.691 raeburn 7856: var form = document.getElementById('crsresform');
7857: var curr = form.style.display;
1.606 raeburn 7858: if (curr == 'none') {
7859: disp='block';
1.691 raeburn 7860: document.courseresform.authorrole.selectedIndex = 0;
7861: document.courseresform.authorpath.selectedIndex = 0;
7862: document.courseresform.newresourceadd.selectedIndex = 0;
7863: populateDirSelects(form,'authorrole','authorpath',1,0,0);
7864: toggleNewInCourse(document.courseresform);
7865: if (document.getElementById('newresource')) {
7866: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 7867: }
7868: if (document.courseresform.newresusetemp.length) {
7869: document.courseresform.newresusetemp[0].checked = true;
7870: toggleWithTemplate(document.courseresform);
7871: }
7872: document.courseresform.newresourcename.value = '';
7873: }
7874: }
7875: if (document.courseresform.newsubdir.length) {
7876: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7877: if (document.courseresform.newsubdir[j].value == 0) {
7878: document.courseresform.newsubdir[j].checked = true;
7879: }
7880: break;
7881: }
7882: if (document.getElementById('newsubdirname')) {
7883: document.getElementById('newsubdirname').type = "hidden";
7884: document.getElementById('newsubdirname').value = "";
7885: }
7886: if (document.getElementById('newsubdir')) {
7887: document.getElementById('newsubdir').innerHTML = "";
7888: }
7889: }
7890: document.getElementById('crsresform').style.display=disp;
7891: resize_scrollbox('contentscroll','1','0');
7892: }
7893: return;
7894: }
7895:
7896: function toggleNewsubdir(form) {
7897: if (form.newsubdir.length) {
7898: for (var j=0; j<form.newsubdir.length; j++) {
7899: if (form.newsubdir[j].checked) {
7900: if (document.getElementById('newsubdirname')) {
7901: if (form.newsubdir[j].value == '1') {
7902: document.getElementById('newsubdirname').type = "text";
7903: if (document.getElementById('newsubdir')) {
7904: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7905: }
7906: } else {
7907: document.getElementById('newsubdirname').type = "hidden";
7908: document.getElementById('newsubdirname').value = "";
7909: document.getElementById('newsubdir').innerHTML = "";
7910: }
7911: }
7912: break;
7913: }
7914: }
7915: }
7916: }
7917:
7918: function toggleCrsResTitle() {
7919: if (document.getElementById('newresource')) {
1.691 raeburn 7920: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
7921: if (selloc == 'course') {
1.606 raeburn 7922: document.getElementById('newresource').style.display = 'inline';
7923: document.courseresform.newresourceadd[0].checked = true;
7924: toggleNewInCourse(document.courseresform);
7925: } else {
7926: document.getElementById('newresource').style.display = 'none';
7927: }
1.689 raeburn 7928: }
7929: if (document.getElementById('newstdproblem')) {
7930: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
7931: document.getElementById('newstdproblem').style.display = 'none';
7932: if (document.getElementById('stdprobswitch')) {
7933: document.getElementById('stdprobswitch').style.display = 'block';
7934: }
7935: } else {
7936: document.getElementById('newstdproblem').style.display = 'block';
7937: if (document.getElementById('stdprobswitch')) {
7938: document.getElementById('stdprobswitch').style.display = 'none';
7939: }
7940: }
7941: }
1.606 raeburn 7942: }
7943:
7944: function toggleNewInCourse(form) {
7945: if (form.newresourceadd.length) {
7946: for (var i=0; i<form.newresourceadd.length; i++) {
7947: if (form.newresourceadd[i].checked) {
7948: if (document.getElementById('newresourcetitle')) {
7949: if (form.newresourceadd[i].value == '1') {
7950: document.getElementById('newresourcetitle').type = 'text';
7951: if (document.getElementById('newrestitle')) {
7952: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7953: }
7954: } else {
7955: document.getElementById('newresourcetitle').type = 'hidden';
7956: document.getElementById('newresourcetitle').value = '';
7957: if (document.getElementById('newrestitle')) {
7958: document.getElementById('newrestitle').innerHTML = '';
7959: }
7960: }
7961: }
7962: break;
7963: }
7964: }
7965: }
7966: }
7967:
7968: function toggleWithTemplate(form) {
7969: if (form.newresusetemp.length) {
7970: for (var i=0; i<form.newresusetemp.length; i++) {
7971: if (form.newresusetemp[i].checked) {
7972: if (document.getElementById('newrestemplate')) {
7973: if (form.newresusetemp[i].value == '1') {
7974: document.getElementById('newrestemplate').style.display = 'inline';
7975: toggleExampleText();
7976: } else {
7977: form.tempcategory.selectedIndex = 0;
7978: select1template_changed();
7979: document.getElementById('newrestemplate').style.display = 'none';
7980: }
7981: }
7982: }
7983: }
7984: }
7985: }
7986:
7987: function toggleExampleText() {
7988: if (document.getElementById('newresexample')) {
7989: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7990: if (url == '') {
7991: document.getElementById('newresexample').style.fontWeight = 'normal';
7992: } else {
7993: document.getElementById('newresexample').style.fontWeight = 'bold';
7994: }
7995: }
7996: }
7997:
7998: function getExample(width,height,scrolling,transparency) {
7999: var url;
8000: if (document.courseresform.newresusetemp.length) {
8001: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
8002: if (document.courseresform.newresusetemp[i].checked) {
8003: if (document.courseresform.newresusetemp[i].value == '1') {
8004: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
8005: if (url == '') {
8006: alert('Pick a category and template');
8007: } else {
8008: url = url.replace("$londocroot","");
8009: url += '?inhibitmenu=yes';
8010: }
8011: }
8012: break;
8013: }
8014: }
8015: }
8016: if (url != '') {
8017: openMyModal(url,width,height,scrolling,transparency,'');
8018: }
8019: }
8020:
1.690 raeburn 8021: function toggleImportCrsres(caller) {
1.606 raeburn 8022: var disp = 'none';
8023: if (document.getElementById('importcrsresform')) {
8024: if (caller == 'res') {
8025: var curr = document.getElementById('importcrsresform').style.display;
8026: if (curr == 'none') {
8027: disp='block';
1.698 raeburn 8028: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
8029: if ((document.getElementById('importcrsrescontent')) &&
8030: (document.getElementById('importcrsresempty'))) {
8031: var selelem = document.crsresimportform.elements['coursepath'];
8032: var numdirs = 0;
8033: if (selelem.options.length) {
8034: numdirs = selelem.options.length - 1;
8035: }
8036: if (numdirs) {
8037: document.getElementById('importcrsrescontent').style.display='block';
8038: document.getElementById('importcrsresempty').style.display='none';
8039: } else {
8040: document.getElementById('importcrsrescontent').style.display='none';
8041: document.getElementById('importcrsresempty').style.display='block';
8042: }
8043: }
1.606 raeburn 8044: }
8045: }
8046: document.getElementById('importcrsresform').style.display=disp;
8047: resize_scrollbox('contentscroll','1','0');
8048: }
8049: return;
8050: }
8051:
1.690 raeburn 8052: $showfile_js
8053:
1.691 raeburn 8054: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
8055: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
8056: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
8057: var selelem = form.elements[dirsel];
8058: var i, numfiles = selelem.options.length -1;
8059: if (numfiles >=0) {
8060: for (i = numfiles; i >= 0; i--) {
8061: selelem.remove(i);
8062: }
8063: }
8064: if ((location == '') || (location == null) || (location == 'undefined')) {
8065: if (selelem.options.length == 0) {
8066: selelem.options[selelem.options.length] = new Option('','');
8067: selelem.selectedIndex = 0;
8068: }
8069: if (document.getElementById('newstdproblem')) {
8070: document.getElementById('newstdproblem').style.display = 'none';
8071: }
8072: return;
8073: }
8074: var machineIds = new Array($machines_str);
8075: var athome = 0;
8076: var role = location;
8077: if ((location == 'author') || (location == 'course')) {
8078: if (document.getElementById('rolehome_'+location)) {
8079: var currhome = document.getElementById('rolehome_'+location).value;
8080: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8081: if (machineIds.includes(currhome)) {
8082: athome = 1;
8083: }
8084: }
8085: }
8086: } else {
8087: const roleinfo = location.split('___');
8088: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
8089: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
8090: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
8091: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8092: if (machineIds.includes(currhome)) {
8093: athome = 1;
8094: }
8095: }
8096: }
8097: }
8098: if (athome) {
8099: if (document.getElementById('stdprobswitch')) {
8100: document.getElementById('stdprobswitch').style.display = 'none';
8101: }
8102: if (document.getElementById('newstdproblem')) {
8103: document.getElementById('newstdproblem').style.display = 'none';
8104: }
8105: var http = new XMLHttpRequest();
8106: var url = "/adm/courseauthor";
1.698 raeburn 8107: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 8108: http.open("POST", url, true);
8109: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
8110: http.onreadystatechange = function() {
8111: if (http.readyState == 4 && http.status == 200) {
8112: var data = JSON.parse(http.responseText);
8113: if (Array.isArray(data.dirs)) {
8114: var len = data.dirs.length;
8115: if (len) {
8116: if (len > 1) {
8117: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
8118: }
8119: }
8120: if (len) {
8121: var j;
8122: for (j = 0; j < len; j++) {
8123: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
8124: }
8125: selelem.selectedIndex = 0;
1.697 raeburn 8126: if (len == 1) {
8127: toggleCrsResTitle();
8128: }
1.691 raeburn 8129: }
8130: }
8131: }
8132: }
8133: http.send(params);
8134: } else {
8135: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
8136: selelem.selectedIndex = 0;
8137: if (document.getElementById('stdprobswitch')) {
8138: document.getElementById('stdprobswitch').style.display = 'block';
8139: }
8140: if (document.getElementById('newstdproblem')) {
8141: document.getElementById('newstdproblem').style.display = 'none';
8142: }
8143: }
8144: }
8145: return;
8146: }
8147:
1.689 raeburn 8148: function switchForProb() {
8149: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8150: var url = '/adm/switchserver?otherserver=';
8151: var newhostid = '';
8152: var role = '';
8153: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8154: if (selloc == 'author') {
8155: newhostid = document.courseresform.rolehome_author.value;
8156: role = "au./&js_escape($env{'user.domain'})/";
8157: } else if (selloc == 'course') {
8158: newhostid = document.courseresform.rolehome_course.value;
8159: role = "&js_escape($env{'request.role'})";
8160: } else {
8161: var items = new Array();
8162: items = selloc.split('___');
8163: var len = document.courseresform.rolehome_coauthor.length;
8164: if (null == len) {
8165: var currval = document.courseresform.rolehome_coauthor.value;
8166: if (null != currval) {
8167: var info = new Array();
8168: info = currval.split('=');
8169: newhostid = info[2];
8170: role = info[0]+'./'+info[1];
8171: }
8172: } else {
8173: for (var i=0; i<len; i++) {
8174: var currval = document.courseresform.rolehome_coauthor[i].value;
8175: if (null != currval) {
8176: var info = new Array();
8177: info = currval.split('=');
8178: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
8179: newhostid = info[2];
8180: role = info[0]+'./'+info[1];
8181: break;
8182: }
8183: }
8184: }
8185: }
8186: }
8187: if (newhostid != '') {
8188: url += newhostid;
8189: if (role != '') {
8190: url += '&role='+role;
8191: }
8192: document.location.href = url;
8193: }
8194: }
8195: return;
8196: }
8197:
1.501 raeburn 8198: function makeims(imsform) {
8199: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 8200: alert("$js_lt{'imsfile'}");
1.501 raeburn 8201: return;
8202: }
8203: if (imsform.source.selectedIndex == 0) {
1.594 damieng 8204: alert("$js_lt{'imscms'}");
1.501 raeburn 8205: return;
8206: }
8207: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
8208: imsform.submit();
8209: }
8210:
1.478 raeburn 8211: function updatePick(targetform,index,caller) {
1.537 raeburn 8212: var pickitem;
8213: var picknumitem;
8214: var picknumtext;
8215: if (index == 'all') {
8216: pickitem = document.getElementById('randompickall');
8217: picknumitem = document.getElementById('rpicknumall');
8218: picknumtext = document.getElementById('rpicktextall');
8219: } else {
8220: pickitem = document.getElementById('randompick_'+index);
8221: picknumitem = document.getElementById('rpicknum_'+index);
8222: picknumtext = document.getElementById('randompicknum_'+index);
8223: }
1.478 raeburn 8224: if (pickitem.checked) {
1.594 damieng 8225: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 8226: if (picknum == '' || picknum == null) {
8227: if (caller == 'check') {
8228: pickitem.checked=false;
1.537 raeburn 8229: if (index == 'all') {
8230: picknumtext.innerHTML = '';
8231: if (caller == 'link') {
8232: propagateState(targetform,'rpicknum');
8233: }
8234: } else {
1.538 raeburn 8235: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8236: }
1.478 raeburn 8237: }
8238: } else {
8239: picknum.toString();
8240: var regexdigit=/^\\d+\$/;
8241: if (regexdigit.test(picknum)) {
8242: picknumitem.value = picknum;
1.537 raeburn 8243: if (index == 'all') {
1.538 raeburn 8244: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 8245: if (caller == 'link') {
8246: propagateState(targetform,'rpicknum');
8247: }
8248: } else {
8249: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 8250: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8251: }
1.478 raeburn 8252: } else {
8253: if (caller == 'check') {
1.537 raeburn 8254: if (index == 'all') {
8255: picknumtext.innerHTML = '';
8256: if (caller == 'link') {
8257: propagateState(targetform,'rpicknum');
8258: }
8259: } else {
8260: pickitem.checked=false;
1.538 raeburn 8261: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8262: }
1.478 raeburn 8263: }
8264: return;
8265: }
8266: }
8267: } else {
1.537 raeburn 8268: picknumitem.value = '';
8269: picknumtext.innerHTML = '';
8270: if (index == 'all') {
8271: if (caller == 'link') {
8272: propagateState(targetform,'rpicknum');
8273: }
8274: } else {
1.538 raeburn 8275: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8276: }
8277: }
8278: }
8279:
8280: function propagateState(form,param) {
8281: if (document.getElementById(param+'all')) {
8282: var setcheck = 0;
8283: var rpick = 0;
8284: if (param == 'rpicknum') {
8285: if (document.getElementById('randompickall')) {
8286: if (document.getElementById('randompickall').checked) {
8287: if (document.getElementById('rpicknumall')) {
8288: rpick = document.getElementById('rpicknumall').value;
8289: }
8290: }
8291: }
8292: } else {
8293: if (document.getElementById(param+'all').checked) {
8294: setcheck = 1;
8295: }
8296: }
1.538 raeburn 8297: var allidxlist;
8298: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8299: if (document.getElementById('all'+param+'idx')) {
8300: allidxlist = document.getElementById('all'+param+'idx').value;
8301: }
8302: var actions = new Array ('remove','cut','copy');
8303: for (var i=0; i<actions.length; i++) {
8304: if (actions[i] != param) {
8305: if (document.getElementById(actions[i]+'all')) {
8306: document.getElementById(actions[i]+'all').checked = false;
8307: }
8308: }
8309: }
8310: }
1.537 raeburn 8311: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 8312: allidxlist = form.allidx.value;
8313: }
8314: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
8315: allidxlist = form.allmapidx.value;
8316: }
8317: if ((allidxlist != '') && (allidxlist != null)) {
8318: var allidxs = allidxlist.split(',');
8319: if (allidxs.length > 1) {
8320: for (var i=0; i<allidxs.length; i++) {
8321: if (document.getElementById(param+'_'+allidxs[i])) {
8322: if (param == 'rpicknum') {
8323: if (document.getElementById('randompick_'+allidxs[i])) {
8324: if (document.getElementById('randompick_'+allidxs[i]).checked) {
8325: document.getElementById(param+'_'+allidxs[i]).value = rpick;
8326: if (rpick > 0) {
8327: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
8328: } else {
8329: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8330: }
8331: }
8332: }
8333: } else {
1.537 raeburn 8334: if (setcheck == 1) {
8335: document.getElementById(param+'_'+allidxs[i]).checked = true;
8336: } else {
8337: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 8338: if (param == 'randompick') {
8339: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8340: }
1.537 raeburn 8341: }
8342: }
8343: }
8344: }
1.538 raeburn 8345: if (setcheck == 1) {
8346: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8347: var actions = new Array('copy','cut','remove');
8348: for (var i=0; i<actions.length; i++) {
8349: var otheractions;
8350: var otheridxs;
8351: if (actions[i] === param) {
8352: continue;
8353: } else {
8354: if (document.getElementById('all'+actions[i]+'idx')) {
8355: otheractions = document.getElementById('all'+actions[i]+'idx').value;
8356: otheridxs = otheractions.split(',');
8357: if (otheridxs.length > 1) {
8358: for (var j=0; j<otheridxs.length; j++) {
8359: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
8360: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
8361: }
1.537 raeburn 8362: }
8363: }
8364: }
1.538 raeburn 8365: }
8366: }
8367: }
8368: }
8369: }
8370: }
8371: }
8372: return;
8373: }
8374:
1.603 raeburn 8375: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 8376: var canedit = '$canedit';
8377: if (canedit == '') {
8378: alert("$js_lt{'edri'}");
8379: return;
8380: }
1.539 raeburn 8381: var dosettings;
8382: var doaction;
1.538 raeburn 8383: var control = document.togglemultsettings;
8384: if (context == 'actions') {
8385: control = document.togglemultactions;
1.539 raeburn 8386: doaction = 1;
8387: } else {
8388: dosettings = 1;
1.538 raeburn 8389: }
1.539 raeburn 8390: if (control) {
8391: if (control.showmultpick.length) {
8392: for (var i=0; i<control.showmultpick.length; i++) {
8393: if (control.showmultpick[i].checked) {
8394: if (control.showmultpick[i].value == 1) {
8395: if (context == 'settings') {
8396: dosettings = 0;
8397: } else {
8398: doaction = 0;
1.538 raeburn 8399: }
8400: }
8401: }
1.537 raeburn 8402: }
8403: }
1.539 raeburn 8404: }
8405: if (context == 'settings') {
8406: if (dosettings == 1) {
1.538 raeburn 8407: targetform.changeparms.value=param;
8408: targetform.submit();
8409: }
1.537 raeburn 8410: }
1.539 raeburn 8411: if (context == 'actions') {
8412: if (doaction == 1) {
8413: targetform.cmd.value=param+'_'+index;
8414: targetform.folderpath.value=folderpath;
8415: targetform.markcopy.value=idx+':'+param;
8416: targetform.copyfolder.value=folder+'.'+container;
8417: if (param == 'remove') {
1.603 raeburn 8418: var doremove = 0;
8419: if (skip_confirm) {
8420: if (confirm_removal) {
8421: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8422: doremove = 1;
8423: }
8424: } else {
8425: doremove = 1;
8426: }
8427: } else {
8428: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8429: doremove = 1;
8430: }
8431: }
8432: if (doremove) {
1.539 raeburn 8433: targetform.markcopy.value='';
8434: targetform.copyfolder.value='';
8435: targetform.submit();
8436: }
8437: }
8438: if (param == 'cut') {
1.594 damieng 8439: 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.539 raeburn 8440: targetform.submit();
8441: return;
8442: }
8443: }
8444: if (param == 'copy') {
8445: targetform.submit();
8446: return;
8447: }
8448: targetform.markcopy.value='';
8449: targetform.copyfolder.value='';
8450: targetform.cmd.value='';
8451: targetform.folderpath.value='';
8452: return;
8453: } else {
8454: if (document.getElementById(param+'_'+idx)) {
8455: item = document.getElementById(param+'_'+idx);
8456: if (item.type == 'checkbox') {
8457: if (item.checked) {
8458: item.checked = false;
8459: } else {
8460: item.checked = true;
8461: singleCheck(item,idx,param);
8462: }
8463: }
8464: }
8465: }
8466: }
1.537 raeburn 8467: return;
8468: }
8469:
1.538 raeburn 8470: function singleCheck(caller,idx,action) {
8471: actions = new Array('cut','copy','remove');
8472: if (caller.checked) {
8473: for (var i=0; i<actions.length; i++) {
8474: if (actions[i] != action) {
8475: if (document.getElementById(actions[i]+'_'+idx)) {
8476: if (document.getElementById(actions[i]+'_'+idx).checked) {
8477: document.getElementById(actions[i]+'_'+idx).checked = false;
8478: }
1.537 raeburn 8479: }
8480: }
8481: }
1.478 raeburn 8482: }
1.537 raeburn 8483: return;
1.478 raeburn 8484: }
8485:
1.334 muellerd 8486: function unselectInactive(nav) {
1.335 ehlerst 8487: currentNav = document.getElementById(nav);
8488: currentLis = currentNav.getElementsByTagName('LI');
8489: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8490: if (currentLis[i].className == 'goback') {
8491: currentLis[i].className = 'goback';
8492: } else {
8493: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8494: currentLis[i].className = 'right';
1.472 raeburn 8495: } else {
1.374 tempelho 8496: currentLis[i].className = 'i';
1.472 raeburn 8497: }
8498: }
1.335 ehlerst 8499: }
1.332 tempelho 8500: }
8501:
1.334 muellerd 8502: function hideAll(current, nav, data) {
1.335 ehlerst 8503: unselectInactive(nav);
1.570 raeburn 8504: if (current) {
8505: if (current.className == 'right'){
8506: current.className = 'right active'
8507: } else {
8508: current.className = 'active';
8509: }
1.374 tempelho 8510: }
1.335 ehlerst 8511: currentData = document.getElementById(data);
8512: currentDivs = currentData.getElementsByTagName('DIV');
8513: for (i = 0; i < currentDivs.length; i++) {
8514: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8515: currentDivs[i].style.display = 'none';
1.330 tempelho 8516: }
8517: }
1.335 ehlerst 8518: }
1.330 tempelho 8519:
1.374 tempelho 8520: function openTabs(pageId) {
8521: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8522: if(tabnav.length > 2 ){
1.389 tempelho 8523: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8524: currentLis = currentNav.getElementsByTagName('LI');
8525: for(i = 0; i< currentLis.length; i++){
8526: if(currentLis[i].className == 'active') {
1.375 tempelho 8527: funcString = currentLis[i].onclick.toString();
8528: tab = funcString.split('"');
1.420 onken 8529: if(tab.length < 2) {
8530: tab = funcString.split("'");
8531: }
1.375 tempelho 8532: currentData = document.getElementById(tab[1]);
8533: currentData.style.display = 'block';
1.374 tempelho 8534: }
8535: }
8536: }
8537: }
8538:
1.334 muellerd 8539: function showPage(current, pageId, nav, data) {
1.570 raeburn 8540: currstate = current.className;
1.334 muellerd 8541: hideAll(current, nav, data);
1.375 tempelho 8542: openTabs(pageId);
1.334 muellerd 8543: unselectInactive(nav);
1.570 raeburn 8544: if ((currstate == 'active') || (currstate == 'right active')) {
8545: if (currstate == 'active') {
8546: current.className = '';
8547: } else {
8548: current.className = 'right';
8549: }
8550: activeTab = '';
1.656 raeburn 8551: toggleExternal();
1.570 raeburn 8552: toggleUpload();
8553: toggleMap();
1.606 raeburn 8554: toggleCrsRes();
8555: toggleImportCrsres();
1.570 raeburn 8556: resize_scrollbox('contentscroll','1','0');
8557: return;
8558: } else {
8559: current.className = 'active';
8560: }
1.330 tempelho 8561: currentData = document.getElementById(pageId);
8562: currentData.style.display = 'block';
1.458 raeburn 8563: activeTab = pageId;
1.656 raeburn 8564: toggleExternal();
1.501 raeburn 8565: toggleUpload();
1.503 raeburn 8566: toggleMap();
1.606 raeburn 8567: toggleCrsRes();
8568: toggleImportCrsres();
1.433 raeburn 8569: if (nav == 'mainnav') {
8570: var storedpath = "$docs_folderpath";
1.434 raeburn 8571: var storedpage = "$main_container_page";
1.433 raeburn 8572: var reg = new RegExp("^supplemental");
8573: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8574: if (storedpage == 1) {
8575: document.simpleedit.folderpath.value = '';
8576: document.uploaddocument.folderpath.value = '';
8577: } else {
8578: if (reg.test(storedpath)) {
8579: document.simpleedit.folderpath.value = '$toplevelmain';
8580: document.uploaddocument.folderpath.value = '$toplevelmain';
8581: document.newext.folderpath.value = '$toplevelmain';
8582: } else {
8583: document.simpleedit.folderpath.value = storedpath;
8584: document.uploaddocument.folderpath.value = storedpath;
8585: document.newext.folderpath.value = storedpath;
8586: }
1.433 raeburn 8587: }
8588: } else {
1.434 raeburn 8589: if (reg.test(storedpath)) {
8590: document.simpleedit.folderpath.value = storedpath;
8591: document.supuploaddocument.folderpath.value = storedpath;
8592: document.supnewext.folderpath.value = storedpath;
8593: } else {
1.433 raeburn 8594: document.simpleedit.folderpath.value = '$toplevelsupp';
8595: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8596: document.supnewext.folderpath.value = '$toplevelsupp';
8597: }
8598: }
8599: }
1.485 raeburn 8600: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8601: return false;
8602: }
1.329 droeschl 8603:
1.472 raeburn 8604: function toContents(jumpto) {
8605: var newurl = '$backtourl';
1.525 raeburn 8606: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8607: newurl = newurl+'?postdata='+jumpto;
8608: }
8609: location.href=newurl;
8610: }
8611:
1.538 raeburn 8612: function togglePick(caller,value) {
8613: var disp = 'none';
8614: if (document.getElementById('multi'+caller)) {
8615: var curr = document.getElementById('multi'+caller).style.display;
8616: if (value == 1) {
8617: disp='block';
8618: }
8619: if (curr == disp) {
8620: return;
8621: }
8622: document.getElementById('multi'+caller).style.display=disp;
8623: if (value == 1) {
1.594 damieng 8624: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8625: } else {
8626: document.getElementById('more'+caller).innerHTML = '';
8627: }
8628: if (caller == 'actions') {
8629: setClass(value);
8630: setBoxes(value);
8631: }
8632: }
8633: var showButton = multiSettings();
8634: if (showButton != 1) {
8635: showButton = multiActions();
8636: }
8637: if (document.getElementById('multisave')) {
8638: if (showButton == 1) {
8639: document.getElementById('multisave').style.display='block';
8640: } else {
8641: document.getElementById('multisave').style.display='none';
8642: }
8643: }
8644: resize_scrollbox('contentscroll','1','1');
8645: return;
8646: }
8647:
8648: function toggleCheckUncheck(caller,more) {
8649: if (more == 1) {
1.594 damieng 8650: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8651: document.getElementById('allfields'+caller).style.display='block';
8652: } else {
1.594 damieng 8653: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8654: document.getElementById('allfields'+caller).style.display='none';
8655: }
8656: resize_scrollbox('contentscroll','1','1');
8657: }
8658:
8659: function multiSettings() {
8660: var inuse = 0;
8661: var settingsform = document.togglemultsettings;
8662: if (settingsform.showmultpick.length > 1) {
8663: for (var i=0; i<settingsform.showmultpick.length; i++) {
8664: if (settingsform.showmultpick[i].checked) {
8665: if (settingsform.showmultpick[i].value == 1) {
8666: inuse = 1;
8667: }
8668: }
8669: }
8670: }
8671: return inuse;
8672: }
8673:
8674: function multiActions() {
8675: var inuse = 0;
8676: var actionsform = document.togglemultactions;
8677: if (actionsform.showmultpick.length > 1) {
8678: for (var i=0; i<actionsform.showmultpick.length; i++) {
8679: if (actionsform.showmultpick[i].checked) {
8680: if (actionsform.showmultpick[i].value == 1) {
8681: inuse = 1;
8682: }
8683: }
8684: }
8685: }
8686: return inuse;
8687: }
8688:
8689: function checkSubmits() {
8690: var numchanges = 0;
8691: var form = document.saveactions;
8692: var doactions = multiActions();
1.542 raeburn 8693: var cutwarnings = 0;
8694: var remwarnings = 0;
1.603 raeburn 8695: var removalinfo = 0;
1.538 raeburn 8696: if (doactions == 1) {
8697: var remidxlist = document.cumulativeactions.allremoveidx.value;
8698: if ((remidxlist != '') && (remidxlist != null)) {
8699: var remidxs = remidxlist.split(',');
8700: for (var i=0; i<remidxs.length; i++) {
8701: if (document.getElementById('remove_'+remidxs[i])) {
8702: if (document.getElementById('remove_'+remidxs[i]).checked) {
8703: form.multiremove.value += remidxs[i]+',';
8704: numchanges ++;
1.542 raeburn 8705: if (document.getElementById('skip_remove_'+remidxs[i])) {
8706: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8707: remwarnings ++;
8708: }
8709: }
1.603 raeburn 8710: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8711: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8712: removalinfo ++;
8713: }
8714: }
1.537 raeburn 8715: }
8716: }
1.538 raeburn 8717: }
8718: }
8719: var cutidxlist = document.cumulativeactions.allcutidx.value;
8720: if ((cutidxlist != '') && (cutidxlist != null)) {
8721: var cutidxs = cutidxlist.split(',');
8722: for (var i=0; i<cutidxs.length; i++) {
8723: if (document.getElementById('cut_'+cutidxs[i])) {
8724: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8725: form.multicut.value += cutidxs[i]+',';
8726: numchanges ++;
1.542 raeburn 8727: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8728: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8729: cutwarnings ++;
8730: }
8731: }
1.537 raeburn 8732: }
8733: }
8734: }
8735: }
1.538 raeburn 8736: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8737: if ((copyidxlist != '') && (copyidxlist != null)) {
8738: var copyidxs = copyidxlist.split(',');
8739: for (var i=0; i<copyidxs.length; i++) {
8740: if (document.getElementById('copy_'+copyidxs[i])) {
8741: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8742: form.multicopy.value += copyidxs[i]+',';
8743: numchanges ++;
8744: }
8745: }
8746: }
8747: }
8748: if (numchanges > 0) {
8749: form.multichange.value = numchanges;
8750: }
1.537 raeburn 8751: }
1.538 raeburn 8752: var dosettings = multiSettings();
1.543 raeburn 8753: var haschanges = 0;
1.538 raeburn 8754: if (dosettings == 1) {
8755: form.allencrypturl.value = '';
8756: form.allhiddenresource.value = '';
1.543 raeburn 8757: form.changeparms.value = 'all';
8758: var patt=new RegExp(",\$");
1.538 raeburn 8759: var allidxlist = document.cumulativesettings.allidx.value;
8760: if ((allidxlist != '') && (allidxlist != null)) {
8761: var allidxs = allidxlist.split(',');
8762: if (allidxs.length > 1) {
8763: for (var i=0; i<allidxs.length; i++) {
8764: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8765: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8766: form.allhiddenresource.value += allidxs[i]+',';
8767: }
8768: }
8769: if (document.getElementById('encrypturl_'+allidxs[i])) {
8770: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8771: form.allencrypturl.value += allidxs[i]+',';
8772: }
8773: }
8774: }
1.543 raeburn 8775: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8776: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8777: }
1.538 raeburn 8778: }
8779: form.allrandompick.value = '';
8780: form.allrandomorder.value = '';
8781: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8782: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8783: var allmapidxs = allmapidxlist.split(',');
8784: for (var i=0; i<allmapidxs.length; i++) {
8785: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8786: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8787: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8788: if ((randompick.checked) && (rpicknum.value != '')) {
8789: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8790: }
8791: if (randorder.checked) {
8792: form.allrandomorder.value += allmapidxs[i]+',';
8793: }
1.537 raeburn 8794: }
1.543 raeburn 8795: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8796: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8797: }
8798: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8799: haschanges = 1;
8800: }
8801: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8802: haschanges = 1;
8803: }
8804: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8805: haschanges = 1;
8806: }
8807: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8808: haschanges = 1;
1.537 raeburn 8809: }
8810: }
1.543 raeburn 8811: if (doactions == 1) {
1.542 raeburn 8812: if (numchanges > 0) {
1.603 raeburn 8813: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8814: if (remwarnings > 0) {
1.594 damieng 8815: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8816: return false;
8817: }
8818: }
1.603 raeburn 8819: if (removalinfo > 0) {
8820: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8821: return false;
8822: }
8823: }
1.542 raeburn 8824: if (cutwarnings > 0) {
1.594 damieng 8825: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
1.542 raeburn 8826: return false;
8827: }
8828: }
8829: }
8830: form.submit();
8831: return true;
1.543 raeburn 8832: }
8833: }
8834: if (dosettings == 1) {
8835: if (haschanges == 1) {
1.542 raeburn 8836: form.submit();
8837: return true;
8838: }
1.543 raeburn 8839: }
8840: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8841: alert("$js_lt{'noor'}");
1.543 raeburn 8842: } else {
8843: if (dosettings == 1) {
1.594 damieng 8844: alert("$js_lt{'noch'}");
1.543 raeburn 8845: } else {
1.594 damieng 8846: alert("$js_lt{'noac'}");
1.543 raeburn 8847: }
8848: }
1.538 raeburn 8849: return false;
8850: }
8851:
8852: function setClass(value) {
8853: var cutclass = 'LC_docs_cut';
8854: var copyclass = 'LC_docs_copy';
8855: var removeclass = 'LC_docs_remove';
8856: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8857: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8858: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8859: var links = document.getElementsByTagName('a');
8860: for (var i=0; i<links.length; i++) {
8861: var classes = links[i].className;
8862: if (cutreg.test(classes)) {
8863: links[i].className = cutclass;
8864: if (value == 1) {
8865: links[i].className += " LC_menubuttons_link";
8866: }
8867: } else {
8868: if (copyreg.test(classes)) {
8869: links[i].className = copyclass;
8870: if (value == 1) {
8871: links[i].className += " LC_menubuttons_link";
8872: }
8873: } else {
8874: if (removereg.test(classes)) {
8875: links[i].className = removeclass;
8876: if (value == 1) {
8877: links[i].className += " LC_menubuttons_link";
8878: }
8879: }
8880: }
8881: }
8882: }
8883: return;
1.537 raeburn 8884: }
8885:
1.538 raeburn 8886: function setBoxes(value) {
8887: var remidxlist = document.cumulativeactions.allremoveidx.value;
8888: if ((remidxlist != '') && (remidxlist != null)) {
8889: var remidxs = remidxlist.split(',');
8890: for (var i=0; i<remidxs.length; i++) {
8891: if (document.getElementById('remove_'+remidxs[i])) {
8892: var item = document.getElementById('remove_'+remidxs[i]);
8893: if (value == 1) {
8894: item.className = 'LC_docs_remove';
8895: } else {
8896: item.className = 'LC_hidden';
8897: }
8898: }
8899: }
8900: }
8901: var cutidxlist = document.cumulativeactions.allcutidx.value;
8902: if ((cutidxlist != '') && (cutidxlist != null)) {
8903: var cutidxs = cutidxlist.split(',');
8904: for (var i=0; i<cutidxs.length; i++) {
8905: if (document.getElementById('cut_'+cutidxs[i])) {
8906: var item = document.getElementById('cut_'+cutidxs[i]);
8907: if (value == 1) {
8908: item.className = 'LC_docs_cut';
8909: } else {
8910: item.className = 'LC_hidden';
8911: }
8912: }
1.537 raeburn 8913: }
8914: }
1.538 raeburn 8915: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8916: if ((copyidxlist != '') && (copyidxlist != null)) {
8917: var copyidxs = copyidxlist.split(',');
8918: for (var i=0; i<copyidxs.length; i++) {
8919: if (document.getElementById('copy_'+copyidxs[i])) {
8920: var item = document.getElementById('copy_'+copyidxs[i]);
8921: if (value == 1) {
8922: item.className = 'LC_docs_copy';
8923: } else {
8924: item.className = 'LC_hidden';
8925: }
8926: }
1.537 raeburn 8927: }
8928: }
8929: return;
8930: }
8931:
1.606 raeburn 8932: function validImportCrsRes() {
8933: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8934: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8935: if ((fname == '') || (fname == null)) {
8936: alert("$js_lt{'nofi'}");
8937: return false;
8938: }
8939: var url = '/res/$coursedom/$coursenum/';
8940: if (path && path != '/') {
8941: url += path+'/';
8942: }
8943: if (fname != '') {
8944: url += fname;
8945: }
8946: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 8947: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 8948: return true;
8949: }
8950:
8951: function validateNewRes(caller) {
8952: if (caller == 'single') {
8953: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8954: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8955: var resname = document.courseresform.newresourcename.value;
8956: }
8957: }
8958:
1.611 raeburn 8959: ENDSCRIPT
1.329 droeschl 8960: }
1.457 raeburn 8961:
1.483 raeburn 8962: sub history_tab_js {
8963: return <<"ENDHIST";
8964: function toggleHistoryDisp(choice) {
8965: document.docslogform.docslog.value = choice;
8966: document.docslogform.submit();
8967: return;
8968: }
8969:
8970: ENDHIST
8971: }
8972:
1.484 raeburn 8973: sub inject_data_js {
8974: return <<ENDINJECT;
8975:
8976: function injectData(current, hiddenField, name, value) {
8977: currentElement = document.getElementById(hiddenField);
8978: currentElement.name = name;
8979: currentElement.value = value;
8980: current.submit();
8981: }
8982:
8983: ENDINJECT
8984: }
8985:
8986: sub dump_switchserver_js {
8987: my @hosts = @_;
1.594 damieng 8988: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8989: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8990: swit => 'Switch server?',
1.594 damieng 8991: );
8992: my %html_js_lt = &Apache::lonlocal::texthash(
8993: swit => 'Switch server?',
1.568 raeburn 8994: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8995: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8996: chos => 'Choose server',
8997: );
1.594 damieng 8998: &js_escape(\%js_lt);
8999: &html_escape(\%html_js_lt);
9000: &js_escape(\%html_js_lt);
1.484 raeburn 9001: my $role = $env{'request.role'};
9002: my $js = <<"ENDSWJS";
9003: <script type="text/javascript">
9004: function write_switchserver() {
9005: var server;
9006: if (document.setserver.posshosts.length > 0) {
9007: for (var i=0; i<document.setserver.posshosts.length; i++) {
9008: if (document.setserver.posshosts[i].checked) {
9009: server = document.setserver.posshosts[i].value;
9010: }
9011: }
9012: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
9013: }
9014: window.close();
9015: }
9016: </script>
9017:
9018: ENDSWJS
9019:
9020: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
9021: {'only_body' => 1,
9022: 'js_ready' => 1,});
9023: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
9024:
9025: my $hostpicker;
9026: my $count = 0;
9027: foreach my $host (sort(@hosts)) {
9028: my $checked;
9029: if ($count == 0) {
9030: $checked = ' checked="checked"';
9031: }
9032: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
9033: $host.'"'.$checked.' />'.$host.'</label> ';
9034: $count++;
9035: }
9036:
9037: return <<"ENDSWITCHJS";
9038:
9039: function dump_needs_switchserver(url) {
9040: if (url!='' && url!= null) {
1.594 damieng 9041: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 9042: go(url);
9043: }
9044: }
9045: return;
9046: }
9047:
9048: function choose_switchserver_window() {
9049: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
9050: newWindow.document.open();
9051: newWindow.document.writeln('$startpage');
1.594 damieng 9052: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
9053: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
9054: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 9055: '<form name="setserver" method="post" action="" \\/>\\n'+
9056: '$hostpicker\\n'+
9057: '<br \\/><br \\/>\\n'+
1.594 damieng 9058: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 9059: 'onclick="write_switchserver();" \\/>\\n'+
9060: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
9061: newWindow.document.writeln('$endpage');
9062: newWindow.document.close();
9063: newWindow.focus();
9064: }
9065:
9066: ENDSWITCHJS
9067: }
9068:
9069: sub makedocslogform {
9070: my ($formelems,$docslog) = @_;
9071: return <<"LOGSFORM";
9072: <form action="/adm/coursedocs" method="post" name="docslogform">
9073: <input type="hidden" name="docslog" value="$docslog" />
9074: $formelems
9075: </form>
9076: LOGSFORM
9077: }
9078:
9079: sub makesimpleeditform {
9080: my ($formelems) = @_;
9081: return <<"SIMPFORM";
9082: <form name="simpleedit" method="post" action="/adm/coursedocs">
9083: <input type="hidden" name="importdetail" value="" />
9084: $formelems
9085: </form>
9086: SIMPFORM
9087: }
9088:
1.606 raeburn 9089: sub makenewproblem {
9090: my ($r,$coursedom,$coursenum) = @_;
9091: # Creating a new problem
9092: my ($redirect,$error);
9093: if ($env{'form.authorrole'}) {
9094: my ($newsubdir,$filename);
9095: if ($env{'form.newsubdir'}) {
9096: if ($env{'form.newsubdirname'} ne '') {
9097: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 9098: }
1.606 raeburn 9099: }
9100: if ($env{'form.newresourcename'}) {
9101: $filename = $env{'form.newresourcename'};
9102: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
9103: $filename =~ s/`//g;
9104: $filename =~ s{/\.\./}{_}g;
9105: $filename =~ s/\.+/./g;
9106: $filename =~ s{/+}{_}g;
9107: if ($filename ne '') {
9108: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
9109: if (($ext) && ($ext ne '.problem')) {
9110: $filename = $name.'.problem';
9111: } elsif ($ext eq '') {
9112: $filename .= '.problem';
9113: }
9114: my $docroot = $r->dir_config('lonDocRoot');
9115: my @ids=&Apache::lonnet::current_machine_ids();
9116: if ($env{'form.authorrole'} eq 'author') {
9117: if ($env{'user.author'}) {
9118: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
9119: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
9120: my $path = $docroot.$url;
9121: my $subdir = $env{'form.authorpath'};
9122: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9123: }
9124: }
9125: } elsif ($env{'form.authorrole'} eq 'course') {
9126: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
9127: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
9128: my $url = "/priv/$coursedom/$coursenum";
9129: my $path=$docroot.$url;
9130: my $subdir = $env{'form.authorpath'};
9131: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9132: if ($redirect) {
9133: my $rightsfile = 'default.rights';
9134: my $sourcerights = "$path/$rightsfile";
9135: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
9136: my $now = time;
9137: if (!-e $sourcerights) {
9138: my $cid = $coursedom.'_'.$coursenum;
9139: if (open(my $fh,">$sourcerights")) {
9140: print $fh <<END;
9141: <accessrule effect="deny" realm="" type="course" role="" />
9142: <accessrule effect="allow" realm="$cid" type="course" role="" />
9143: END
9144: close($fh);
9145: }
9146: }
9147: if (!-e "$sourcerights.meta") {
9148: if (open(my $fh,">$sourcerights.meta")) {
9149: my $author=$env{'environment.firstname'}.' '.
9150: $env{'environment.middlename'}.' '.
9151: $env{'environment.lastname'}.' '.
9152: $env{'environment.generation'};
9153: $author =~ s/\s+$//;
9154: print $fh <<"END";
9155:
9156: <abstract></abstract>
9157: <author>$author</author>
9158: <authorspace>$coursenum:$coursedom</authorspace>
9159: <copyright>private</copyright>
9160: <creationdate>$now</creationdate>
9161: <customdistributionfile></customdistributionfile>
9162: <dependencies></dependencies>
9163: <domain>$coursedom</domain>
9164: <highestgradelevel>0</highestgradelevel>
9165: <keywords></keywords>
9166: <language>notset </language>
9167: <lastrevisiondate>$now</lastrevisiondate>
9168: <lowestgradelevel>0</lowestgradelevel>
9169: <mime>rights</mime>
9170: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
9171: <notes></notes>
9172: <obsolete></obsolete>
9173: <obsoletereplacement></obsoletereplacement>
9174: <owner>$coursenum:$coursedom</owner>
9175: <rule>deny:::course,allow:$cid::course</rule>
9176: <sourceavail></sourceavail>
9177: <standards></standards>
9178: <subject></subject>
1.703 ! raeburn 9179: <title>Course Authoring Rights</title>
1.606 raeburn 9180: END
1.654 raeburn 9181: close($fh);
9182: }
9183: }
9184: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
9185: if (!-e "$docroot/res/$coursedom") {
9186: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 9187: }
1.654 raeburn 9188: if (!-e "$docroot/res/$coursedom/$coursenum") {
9189: mkdir("$docroot/res/$coursedom/$coursenum",0755);
9190: }
9191: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
9192: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
9193: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 9194: }
9195: }
1.654 raeburn 9196: my $source = $docroot.$redirect;
9197: if (!-e "$source.meta") {
9198: my $cid = $coursedom.'_'.$coursenum;
9199: my $now = time;
9200: if (open(my $fh,">$source.meta")) {
9201: my $author=$env{'environment.firstname'}.' '.
9202: $env{'environment.middlename'}.' '.
9203: $env{'environment.lastname'}.' '.
9204: $env{'environment.generation'};
9205: $author =~ s/\s+$//;
9206: my $title = $env{'form.newresourcetitle'};
9207: $title =~ s/^\s+|\s+$//g;
9208: print $fh <<END;
1.606 raeburn 9209:
9210: <abstract></abstract>
9211: <author>$author</author>
9212: <authorspace>$coursenum:$coursedom</authorspace>
9213: <copyright>custom</copyright>
9214: <creationdate>$now</creationdate>
9215: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
9216: <dependencies></dependencies>
9217: <domain>$coursedom</domain>
9218: <highestgradelevel>0</highestgradelevel>
9219: <keywords></keywords>
9220: <language>notset </language>
9221: <lastrevisiondate>$now</lastrevisiondate>
9222: <lowestgradelevel>0</lowestgradelevel>
9223: <mime>problem</mime>
9224: <modifyinguser>$coursenum:$coursedom</modifyinguser>
9225: <notes></notes>
9226: <obsolete></obsolete>
9227: <obsoletereplacement></obsoletereplacement>
9228: <owner>$coursenum:$coursedom</owner>
9229: <sourceavail></sourceavail>
9230: <standards></standards>
9231: <subject></subject>
9232: <title>$title</title>
9233: END
1.654 raeburn 9234: close($fh);
1.606 raeburn 9235: }
9236: }
9237: }
9238: }
9239: } else {
9240: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
9241: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
9242: if (grep(/^\Q$rolehome\E$/,@ids)) {
9243: my $now = time;
9244: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
9245: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
9246: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
9247: my $url = "/priv/$audom/$auname";
9248: my $path = $r->dir_config('lonDocRoot').$url;
9249: my $subdir = $env{'form.authorpath'};
9250: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9251: }
9252: }
9253: }
9254: }
9255: }
9256: }
9257: }
9258: return ($redirect,$error);
9259: }
9260:
9261: sub finishnewprob {
1.654 raeburn 9262: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 9263: unless (-d $path) {
9264: unless (mkdir($path,02770)) {
9265: return;
9266: }
9267: }
1.606 raeburn 9268: my $redirect;
9269: if ($subdir ne '/') {
9270: $subdir = &cleandir($subdir);
9271: if (($subdir ne '') && (-d "$path/$subdir")) {
9272: $path .= "/$subdir";
9273: $url .= "/$subdir";
9274: }
9275: }
9276: my $dest;
9277: if ($newsubdir ne '') {
9278: $newsubdir = &cleandir($newsubdir);
9279: }
9280: if ($newsubdir ne '') {
9281: if (-d "$path/$newsubdir") {
9282: $dest = "$path/$newsubdir/$filename";
9283: } else {
9284: my $dirok;
9285: unless (-e "$path/$newsubdir") {
9286: if (mkdir("$path/$newsubdir",02770)) {
9287: if (chmod(02770,"$path/$newsubdir")) {
9288: $dirok = 1;
9289: }
9290: }
9291: }
9292: if ($dirok) {
9293: $dest = "$path/$newsubdir/$filename";
9294: }
9295: }
9296: if (($dest ne '') && (!-e $dest)) {
9297: $redirect = "$url/$newsubdir/$filename";
9298: }
9299: } else {
9300: $dest = "$path/$filename";
9301: if (($dest ne '') && (!-e $dest)) {
9302: $redirect = "$url/$filename";
9303: }
9304: }
1.654 raeburn 9305: if ((!-e $dest) && ($context ne 'upload')) {
9306: my $template = $env{'form.template'};
9307: my $copyfrom;
9308: if ($template ne '') {
9309: my %templates;
9310: my @files = &Apache::lonhomework::get_template_list('problem');
9311: foreach my $poss (@files) {
9312: if (ref($poss) eq 'ARRAY') {
9313: if ($template eq $poss->[0]) {
9314: $templates{$template} = 1;
9315: last;
9316: }
9317: }
9318: }
9319: if ($templates{$template}) {
9320: $copyfrom = $template;
9321: }
9322: }
9323: if ($filename =~ /\.problem$/) {
9324: unless ($copyfrom) {
9325: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
9326: }
9327: &File::Copy::copy($copyfrom,$dest);
9328: }
9329: }
1.606 raeburn 9330: return $redirect;
9331: }
9332:
9333: sub cleandir {
9334: my ($dir) = @_;
9335: $dir =~ s/^\s+//;
9336: $dir =~ s/\s+$//;
9337: $dir =~ s/\.+//g;
9338: $dir =~ s/[\#\?&%\":]//g;
9339: return $dir;
9340: }
9341:
1.329 droeschl 9342: 1;
9343: __END__
9344:
9345:
9346: =head1 NAME
9347:
9348: Apache::londocs.pm
9349:
9350: =head1 SYNOPSIS
9351:
9352: This is part of the LearningOnline Network with CAPA project
9353: described at http://www.lon-capa.org.
9354:
9355: =head1 SUBROUTINES
9356:
9357: =over
9358:
9359: =item %help=()
9360:
9361: Available help topics
9362:
9363: =item mapread()
9364:
1.344 bisitz 9365: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 9366: @order and @resources, determines status
9367: sets @order - pointer to resources in right order
9368: sets @resources - array with the resources with correct idx
9369:
9370: =item authorhosts()
9371:
9372: Return hash with valid author names
9373:
9374: =item clean()
9375:
9376: =item dumpcourse()
9377:
9378: Actually dump course
9379:
9380: =item group_import()
9381:
9382: Imports the given (name, url) resources into the course
9383: coursenum, coursedom, and folder must precede the list
9384:
9385: =item breadcrumbs()
9386:
9387: =item log_docs()
9388:
9389: =item docs_change_log()
9390:
9391: =item update_paste_buffer()
9392:
9393: =item print_paste_buffer()
9394:
9395: =item do_paste_from_buffer()
9396:
1.538 raeburn 9397: =item do_buffer_empty()
9398:
9399: =item clear_from_buffer()
9400:
1.492 raeburn 9401: =item get_newmap_url()
9402:
9403: =item dbcopy()
9404:
9405: =item uniqueness_check()
9406:
9407: =item contained_map_check()
9408:
9409: =item url_paste_fixups()
9410:
9411: =item apply_fixups()
9412:
9413: =item copy_dependencies()
9414:
1.329 droeschl 9415: =item update_parameter()
9416:
9417: =item handle_edit_cmd()
9418:
9419: =item editor()
9420:
9421: =item process_file_upload()
9422:
9423: =item process_secondary_uploads()
9424:
9425: =item is_supplemental_title()
9426:
9427: =item entryline()
9428:
9429: =item tiehash()
9430:
9431: =item untiehash()
9432:
9433: =item checkonthis()
9434:
9435: check on this
9436:
9437: =item verifycontent()
9438:
9439: Verify Content
9440:
1.636 raeburn 9441: =item devalidateversioncache()
9442:
9443: =item checkversions()
1.329 droeschl 9444:
9445: Check Versions
9446:
9447: =item mark_hash_old()
9448:
9449: =item is_hash_old()
9450:
9451: =item changewarning()
9452:
9453: =item init_breadcrumbs()
9454:
9455: Breadcrumbs for special functions
9456:
1.484 raeburn 9457: =item create_list_elements()
9458:
9459: =item create_form_ul()
9460:
9461: =item startContentScreen()
9462:
9463: =item endContentScreen()
9464:
9465: =item supplemental_base()
9466:
9467: =item embedded_form_elems()
9468:
9469: =item embedded_destination()
9470:
9471: =item return_to_editor()
9472:
9473: =item decompression_info()
9474:
9475: =item decompression_phase_one()
9476:
9477: =item decompression_phase_two()
9478:
9479: =item remove_archive()
9480:
9481: =item generate_admin_menu()
9482:
9483: =item generate_edit_table()
9484:
9485: =item editing_js()
9486:
9487: =item history_tab_js()
9488:
9489: =item inject_data_js()
9490:
9491: =item dump_switchserver_js()
9492:
1.485 raeburn 9493: =item resize_scrollbox_js()
1.484 raeburn 9494:
9495: =item makedocslogform()
9496:
1.485 raeburn 9497: =item makesimpleeditform()
9498:
1.329 droeschl 9499: =back
9500:
9501: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>