Annotation of loncom/interface/londocs.pm, revision 1.681
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.681 ! raeburn 4: # $Id: londocs.pm,v 1.680 2022/09/13 13:54:02 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.645 raeburn 48: use Apache::lonparmset();
1.651 raeburn 49: use Apache::loncourserespicker();
1.329 droeschl 50: use HTML::Entities;
1.488 raeburn 51: use HTML::TokeParser;
1.329 droeschl 52: use GDBM_File;
1.578 raeburn 53: use File::MMagic;
1.606 raeburn 54: use File::Copy;
1.329 droeschl 55: use Apache::lonlocal;
56: use Cwd;
1.643 raeburn 57: use UUID::Tiny ':std';
1.329 droeschl 58: use LONCAPA qw(:DEFAULT :match);
59:
60: my $iconpath;
61:
62: my %hash;
63:
64: my $hashtied;
65: my %alreadyseen=();
66:
67: my $hadchanges;
1.557 raeburn 68: my $suppchanges;
1.329 droeschl 69:
70:
71: my %help=();
72:
73:
74: sub mapread {
75: my ($coursenum,$coursedom,$map)=@_;
76: return
77: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
78: $map);
79: }
80:
81: sub storemap {
1.492 raeburn 82: my ($coursenum,$coursedom,$map,$contentchg)=@_;
83: my $report;
84: if (($contentchg) && ($map =~ /^default/)) {
85: $report = 1;
86: }
1.329 droeschl 87: my ($outtext,$errtext)=
88: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 89: $map,1,$report);
1.329 droeschl 90: if ($errtext) { return ($errtext,2); }
1.364 bisitz 91:
1.557 raeburn 92: if ($map =~ /^default/) {
93: $hadchanges=1;
94: } else {
95: $suppchanges=1;
96: }
1.329 droeschl 97: return ($errtext,0);
98: }
99:
100:
101:
102: sub authorhosts {
103: my %outhash=();
104: my $home=0;
105: my $other=0;
106: foreach my $key (keys(%env)) {
107: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
108: my $role=$1;
109: my $realm=$2;
110: my ($start,$end)=split(/\./,$env{$key});
111: if (($start) && ($start>time)) { next; }
112: if (($end) && (time>$end)) { next; }
113: my ($ca,$cd);
114: if ($1 eq 'au') {
115: $ca=$env{'user.name'};
116: $cd=$env{'user.domain'};
117: } else {
118: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
119: }
120: my $allowed=0;
121: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
122: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 123: foreach my $id (@ids) {
124: if ($id eq $myhome) {
125: $allowed=1;
126: last;
127: }
128: }
1.329 droeschl 129: if ($allowed) {
130: $home++;
1.484 raeburn 131: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 132: } else {
1.484 raeburn 133: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 134: $other++;
135: }
136: }
137: }
138: return ($home,$other,%outhash);
139: }
140:
141:
142: sub clean {
143: my ($title)=@_;
144: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 145: return $title;
1.329 droeschl 146: }
147:
1.617 raeburn 148: sub default_folderpath {
149: my ($coursenum,$coursedom,$navmapref) = @_;
150: return unless ($coursenum && $coursedom && ref($navmapref));
151: # Check if entire course is hidden and/or encrypted
152: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
153: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
154: unless (ref($$navmapref)) {
155: $$navmapref = Apache::lonnavmaps::navmap->new();
156: }
157: if (ref($$navmapref)) {
158: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
159: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
160: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
161: unless (@resources) {
162: $hiddenmap = 1;
163: unless ($env{'request.role.adv'}) {
164: $hiddentop = 1;
165: if ($env{'form.folder'}) {
166: undef($env{'form.folder'});
167: }
168: }
169: }
170: }
171: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
172: $encryptmap = 1;
173: }
174: }
175: unless ($hiddentop) {
176: $folderpath='default&'.&escape(&mt('Main Content')).
177: '::'.$hiddenmap.':'.$encryptmap.'::';
178: }
179: if (wantarray) {
180: return ($folderpath,$hiddentop);
181: } else {
182: return $folderpath;
183: }
184: }
1.329 droeschl 185:
1.677 raeburn 186: sub validate_folderpath {
187: my ($supplementalflag) = @_;
188: if ($env{'form.folderpath'} ne '') {
189: my @items = split(/\&/,$env{'form.folderpath'});
190: my $badpath;
191: for (my $i=0; $i<@items; $i++) {
192: my $odd = $i%2;
193: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
194: $badpath = 1;
195: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
196: $badpath = 1;
197: }
198: last if ($badpath);
199: }
200: if ($badpath) {
201: delete($env{'form.folderpath'});
202: }
203: }
204: return;
205: }
206:
207: sub validate_suppath {
208: if ($env{'form.supppath'} ne '') {
209: my @items = split(/\&/,$env{'form.supppath'});
210: my $badpath;
211: for (my $i=0; $i<@items; $i++) {
212: my $odd = $i%2;
213: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
214: $badpath = 1;
215: }
216: last if ($badpath);
217: }
218: if ($badpath) {
219: delete($env{'form.supppath'});
220: }
221: }
222: return;
223: }
224:
1.329 droeschl 225: sub dumpcourse {
226: my ($r) = @_;
1.408 raeburn 227: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 228: my ($starthash,$js);
229: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
230: $js = <<"ENDJS";
231: <script type="text/javascript">
232: // <![CDATA[
233:
234: function hide_searching() {
235: if (document.getElementById('searching')) {
236: document.getElementById('searching').style.display = 'none';
237: }
238: return;
239: }
240:
241: // ]]>
242: </script>
243: ENDJS
244: $starthash = {
245: add_entries => {'onload' => "hide_searching();"},
246: };
247: }
1.568 raeburn 248: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
249: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 250: $r->print(&startContentScreen('tools'));
1.329 droeschl 251: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 252: unless ($home) {
253: $r->print(&endContentScreen());
254: return '';
255: }
1.329 droeschl 256: my $origcrsid=$env{'request.course.id'};
257: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
258: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
259: # Do the dumping
1.484 raeburn 260: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
261: $r->print(&endContentScreen());
262: return '';
263: }
1.531 raeburn 264: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 265: $r->print('<h3>'.&mt('Copying Files').'</h3>');
266: my $title=$env{'form.authorfolder'};
267: $title=&clean($title);
1.567 raeburn 268: my ($navmap,$errormsg) =
269: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
270: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
271: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
272: my (%maps,%resources,%titles);
273: if (!ref($navmap)) {
274: $r->print($errormsg.
275: &endContentScreen());
276: return '';
277: } else {
278: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
279: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 280: }
1.567 raeburn 281: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
282: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
283: %newcontent,%has_simpleprobs);
284: foreach my $item (sort {$a <=> $b} (@todump)) {
285: my $name = $env{'form.namefor_'.$item};
286: if ($resources{$item}) {
287: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
288: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
289: $tocopy{$1} = $name;
290: $display{$item} = $1;
291: $lookup{$1} = $item;
292: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
293: $simpleproblems{$item} = {
294: symb => $resources{$item},
295: name => $name,
296: };
297: $display{$item} = 'simpleproblem_'.$name;
298: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
299: $has_simpleprobs{$1}{$id} = $item;
300: }
301: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
302: my $marker = $1;
303: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
304: $simplepages{$item} = {
305: res => $res,
306: title => $titles{$item},
307: db => $db_name,
308: marker => $marker,
309: symb => $resources{$item},
310: name => $name,
311: };
312: $display{$item} = '/'.$res;
313: }
314: } elsif ($maps{$item}) {
315: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
316: $tocopy{$1} = $name;
317: $display{$item} = $1;
318: $lookup{$1} = $item;
319: }
320: } else {
321: next;
322: }
323: }
1.329 droeschl 324: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
325: $crs=~s/\_/\//g;
1.567 raeburn 326: my $mm = new File::MMagic;
327: my $prefix = "/uploaded/$cdom/$cnum/";
328: %replacehash = %tocopy;
329: foreach my $item (sort(keys(%simpleproblems))) {
330: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
331: $newcontent{$display{$item}} = $content;
332: }
333: my $gateway = Apache::lonhtmlgateway->new('web');
334: foreach my $item (sort(keys(%simplepages))) {
335: if (ref($simplepages{$item}) eq 'HASH') {
336: my $pagetitle = $simplepages{$item}{'title'};
337: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
338: my %contents;
339: foreach my $field (keys(%fields)) {
340: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
341: my $name = $1;
342: my $msg = $fields{$field};
343: if ($name eq 'webreferences') {
344: if ($msg =~ m{^https?://}) {
345: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
346: }
347: } else {
348: $msg = &Encode::decode('utf8',$msg);
349: $msg = $gateway->process_outgoing_html($msg,1);
350: $contents{$name} = $msg;
351: }
352: } elsif ($field eq 'uploaded.photourl') {
353: my $marker = $simplepages{$item}{marker};
354: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
355: my $filepath = $1;
356: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
357: if ($fname ne '') {
358: $fname=~s/\.(\w+)$//;
359: my $ext=$1;
360: $fname = &clean($fname);
361: $fname.='.'.$ext;
362: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
363: $replacehash{$filepath} = $relpath.$fname;
364: $deps{$item}{$filepath} = 1;
365: }
366: }
367: }
368: }
369: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
370: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
371: my $content = '
372: <html>
373: <head>
374: <title>'.$pagetitle.'</title>
375: </head>
376: <body bgcolor="#ffffff">';
377: if ($contents{title}) {
378: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
379: }
380: if ($contents{image}) {
381: $content .= "\n".$contents{image};
382: }
383: if ($contents{content}) {
384: $content .= '
385: <div class="LC_Box">
1.577 bisitz 386: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 387: $contents{content}.'
388: </div>';
389: }
390: if ($contents{webreferences}) {
391: $content .= '
392: <div class="LC_Box">
1.577 bisitz 393: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 394: $contents{webreferences}.'
395: </div>';
396: }
397: $content .= '
398: </body>
399: </html>
400: ';
401: $newcontent{'/'.$simplepages{$item}{res}} = $content;
402: }
403: }
404: foreach my $item (keys(%tocopy)) {
405: unless ($item=~/\.(sequence|page)$/) {
406: my $currurlpath = $prefix.$item;
407: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
408: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
409: }
410: }
411: foreach my $num (sort {$a <=> $b} (@todump)) {
412: my $src = $display{$num};
413: next if ($src eq '');
414: my @needcopy = ();
415: if ($replacehash{$src}) {
416: push(@needcopy,$src);
417: if (ref($deps{$num}) eq 'HASH') {
418: foreach my $dep (sort(keys(%{$deps{$num}}))) {
419: if ($replacehash{$dep}) {
420: push(@needcopy,$dep);
421: }
422: }
423: }
424: } elsif ($src =~ /^simpleproblem_/) {
425: push(@needcopy,$src);
426: }
427: next if (@needcopy == 0);
428: my ($result,$depresult);
429: for (my $i=0; $i<@needcopy; $i++) {
430: my $item = $needcopy[$i];
431: my $newfilename;
432: if ($simpleproblems{$num}) {
433: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
434: } else {
435: $newfilename=$title.'/'.$replacehash{$item};
436: }
437: $newfilename=~s/\.(\w+)$//;
438: my $ext=$1;
439: $newfilename=&clean($newfilename);
440: $newfilename.='.'.$ext;
441: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
442: if ($newrelpath ne $replacehash{$item}) {
443: $replacehash{$item} = $newrelpath;
444: }
445: my @dirs=split(/\//,$newfilename);
446: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
447: my $makepath=$path;
448: my $fail;
449: my $origin;
450: for (my $i=0;$i<$#dirs;$i++) {
451: $makepath.='/'.$dirs[$i];
452: unless (-e $makepath) {
453: unless(mkdir($makepath,0755)) {
454: $fail = &mt('Directory creation failed.');
455: }
456: }
457: }
458: if ($i == 0) {
459: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
460: } else {
461: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
462: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
463: &mt('(dependency)').'</span>: ';
464: }
465: if (-e $path.'/'.$newfilename) {
466: $fail = &mt('Destination already exists -- not overwriting.');
467: } else {
468: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
469: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
470: ($item =~ /^simpleproblem_/)) {
471: print $fh $newcontent{$item};
472: } else {
473: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
474: if (-e $fileloc) {
475: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
476: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
477: (ref($has_simpleprobs{$item}) eq 'HASH')) {
478: my %changes = %{$has_simpleprobs{$item}};
479: my $content = &Apache::lonclonecourse::rewritefile(
480: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
481: (%replacehash,$crs => '')
482: );
483: my $updatedcontent = '';
484: my $parser = HTML::TokeParser->new(\$content);
485: $parser->attr_encoded(1);
486: while (my $token = $parser->get_token) {
487: if ($token->[0] eq 'S') {
488: if (($token->[1] eq 'resource') &&
489: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
490: ($changes{$token->[2]->{'id'}})) {
491: my $id = $token->[2]->{'id'};
492: $updatedcontent .= '<'.$token->[1];
493: foreach my $attrib (@{$token->[3]}) {
494: next unless ($attrib =~ /^(src|type|title|id)$/);
495: if ($attrib eq 'src') {
496: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
497: if ($file) {
498: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
499: } else {
500: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
501: }
502: } else {
503: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
504: }
505: }
506: $updatedcontent .= ' />'."\n";
507: } else {
508: $updatedcontent .= $token->[4]."\n";
509: }
510: } else {
511: $updatedcontent .= $token->[2];
512: }
513: }
514: print $fh $updatedcontent;
515: } else {
516: print $fh &Apache::lonclonecourse::rewritefile(
517: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
518: (%replacehash,$crs => '')
519: );
520: }
521: } else {
522: print $fh
523: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
524: }
525: } else {
526: $fail = &mt('Source does not exist.');
527: }
528: }
529: $fh->close();
530: } else {
531: $fail = &mt('Could not write to destination.');
532: }
533: }
534: my $text;
535: if ($fail) {
536: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
537: } else {
538: $text = '<span class="LC_success">'.&mt('ok').'</span>';
539: }
540: if ($i == 0) {
541: $result .= $text;
542: } else {
543: $depresult .= $text.'</li>';
544: }
545: }
546: $r->print($result);
547: if ($depresult) {
548: $r->print('<ul>'.$depresult.'</ul>');
549: }
550: }
551: } else {
552: my ($navmap,$errormsg) =
553: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
554: if (!ref($navmap)) {
555: $r->print($errormsg);
556: } else {
557: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
558: $r->rflush();
559: my ($preamble,$formname);
560: $formname = 'dumpdoc';
561: unless ($home==1) {
562: $preamble = '<div class="LC_left_float">'.
563: '<fieldset><legend>'.
564: &mt('Select the Authoring Space').
565: '</legend><select name="authorspace">';
1.329 droeschl 566: }
1.567 raeburn 567: my @orderspaces = ();
568: foreach my $key (sort(keys(%outhash))) {
569: if ($key=~/^home_(.+)$/) {
570: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
571: unshift(@orderspaces,$1);
572: } else {
573: push(@orderspaces,$1);
574: }
575: }
576: }
1.569 raeburn 577: if ($home>1) {
578: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
579: }
1.567 raeburn 580: foreach my $user (@orderspaces) {
1.329 droeschl 581: if ($home==1) {
1.567 raeburn 582: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 583: } else {
1.567 raeburn 584: $preamble .= '<option value="'.$user.'">'.$user.' - '.
585: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
586: }
1.329 droeschl 587: }
1.567 raeburn 588: unless ($home==1) {
589: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 590: }
1.567 raeburn 591: my $title=$origcrsdata{'description'};
592: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 593: $title=&clean($title);
1.567 raeburn 594: $preamble .= '<div class="LC_left_float">'.
595: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
596: '<input type="text" size="50" name="authorfolder" value="'.
597: $title.'" />'.
598: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
599: my %uploadedfiles;
600: &tiehash();
601: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
602: my ($ext)=($file=~/\.(\w+)$/);
603: # FIXME Check supplemental here
604: my $title=$hash{'title_'.$hash{
605: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
606: if (!$title) {
607: $title=$file;
608: } else {
609: $title=~s|/|_|g;
610: }
611: $title=~s/\.(\w+)$//;
612: $title=&clean($title);
613: $title.='.'.$ext;
614: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
615: $uploadedfiles{$file} = $title;
616: }
617: &untiehash();
618: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
619: undef,undef,$preamble,$home,\%uploadedfiles));
620: }
1.329 droeschl 621: }
1.484 raeburn 622: $r->print(&endContentScreen());
1.329 droeschl 623: }
624:
1.567 raeburn 625: sub recurse_html {
626: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
627: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
628: my (%allfiles,%codebase);
629: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
630: if (keys(%allfiles)) {
631: foreach my $dependency (keys(%allfiles)) {
632: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
633: my ($depurl,$relfile,$newcontainer);
634: if ($dependency =~ m{^/}) {
635: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
636: $relfile = $1;
637: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
638: $newcontainer = $1;
639: next if ($replacehash->{$newcontainer});
640: }
641: $depurl = $dependency;
642: } else {
643: next;
644: }
645: } else {
646: $relfile = $dependency;
647: $depurl = $currurlpath;
1.630 raeburn 648: $depurl =~ s{[^/]+$}{};
1.567 raeburn 649: $depurl .= $dependency;
1.630 raeburn 650: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 651: }
652: next if ($relfile eq '');
653: my $newname = $replacehash->{$container};
654: $newname =~ s{[^/]+$}{};
655: $replacehash->{$newcontainer} = $newname.$relfile;
656: $deps->{$item}{$newcontainer} = 1;
657: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
658: my $depfile = &Apache::lonnet::filelocation('',$depurl);
659: my $type = $mm->checktype_filename($depfile);
660: if ($type eq 'text/html') {
661: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
662: }
663: }
664: }
665: }
666: return;
667: }
668:
1.329 droeschl 669: sub group_import {
1.598 raeburn 670: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 671: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
672: %removeparam,$importuploaded,$fixuperrors);
673: $allmaps = {};
1.329 droeschl 674: while (@files) {
675: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 676: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 677: && ($caller eq 'londocs')
678: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 679:
1.329 droeschl 680: my $errtext = '';
681: my $fatal = 0;
682: my $newmapstr = '<map>'."\n".
683: '<resource id="1" src="" type="start"></resource>'."\n".
684: '<link from="1" to="2" index="1"></link>'."\n".
685: '<resource id="2" src="" type="finish"></resource>'."\n".
686: '</map>';
687: $env{'form.output'}=$newmapstr;
688: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
689: 'output',$1.$2);
1.534 raeburn 690: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 691: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
692: $fatal = 2;
693: }
694: if ($fatal) {
695: return ($errtext,$fatal);
696: }
697: }
698: if ($url) {
1.626 raeburn 699: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 700: $url = $1;
701: my $marker = $2;
702: my $info = $3;
1.604 raeburn 703: my ($toolid,%toolhash,%toolsettings);
1.642 raeburn 704: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 705: my @toolinfo = split(/:/,$info);
706: if ($residx) {
1.604 raeburn 707: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 708: $toolid = $toolsettings{'id'};
709: } else {
1.604 raeburn 710: $toolid = shift(@toolinfo);
1.598 raeburn 711: }
712: $toolid =~ s/\D//g;
1.604 raeburn 713: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 714: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
715: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 716: foreach my $item (@extras) {
717: $toolhash{$item} = &unescape($toolhash{$item});
718: }
1.645 raeburn 719: if ($folder =~ /^supplemental/) {
1.648 raeburn 720: delete($toolhash{'gradable'});
721: } else {
722: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 723: }
1.598 raeburn 724: if (ref($ltitoolsref) eq 'HASH') {
725: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
1.643 raeburn 726: my @deleted;
1.598 raeburn 727: $toolhash{'id'} = $toolid;
1.628 raeburn 728: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
729: ($toolhash{'target'} eq 'window')) {
1.604 raeburn 730: if ($toolhash{'target'} eq 'window') {
731: foreach my $item ('width','height') {
732: $toolhash{$item} =~ s/^\s+//;
733: $toolhash{$item} =~ s/\s+$//;
1.624 raeburn 734: if ($toolhash{$item} =~ /\D/) {
735: delete($toolhash{$item});
736: if ($residx) {
737: if ($toolsettings{$item}) {
738: push(@deleted,$item);
739: }
740: }
741: }
1.604 raeburn 742: }
743: }
744: } elsif ($residx) {
745: $toolhash{'target'} = $toolsettings{'target'};
746: if ($toolhash{'target'} eq 'window') {
1.630 raeburn 747: foreach my $item ('width','height') {
1.624 raeburn 748: $toolhash{$item} = $toolsettings{$item};
749: }
1.604 raeburn 750: }
751: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
752: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
753: if ($toolhash{'target'} eq 'window') {
754: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
755: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
756: }
757: }
1.598 raeburn 758: if ($toolhash{'target'} eq 'iframe') {
1.624 raeburn 759: foreach my $item ('width','height','linktext','explanation') {
760: delete($toolhash{$item});
761: if ($residx) {
762: if ($toolsettings{$item}) {
763: push(@deleted,$item);
764: }
1.604 raeburn 765: }
766: }
1.628 raeburn 767: } elsif ($toolhash{'target'} eq 'tab') {
768: foreach my $item ('width','height') {
769: delete($toolhash{$item});
770: if ($residx) {
771: if ($toolsettings{$item}) {
772: push(@deleted,$item);
773: }
774: }
775: }
1.604 raeburn 776: }
777: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624 raeburn 778: foreach my $item ('label','title','linktext','explanation') {
779: my $crsitem;
780: if (($item eq 'label') || ($item eq 'title')) {
781: $crsitem = 'crs'.$item;
782: } else {
783: $crsitem = $item;
784: }
1.604 raeburn 785: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624 raeburn 786: $toolhash{$crsitem} =~ s/^\s+//;
787: $toolhash{$crsitem} =~ s/\s+$//;
788: if ($toolhash{$crsitem} eq '') {
789: delete($toolhash{$crsitem});
1.604 raeburn 790: }
791: } else {
1.624 raeburn 792: delete($toolhash{$crsitem});
1.604 raeburn 793: }
1.624 raeburn 794: if (($residx) && (exists($toolsettings{$crsitem}))) {
795: unless (exists($toolhash{$crsitem})) {
796: push(@deleted,$crsitem);
1.604 raeburn 797: }
798: }
1.598 raeburn 799: }
800: }
1.643 raeburn 801: if ($toolhash{'passback'}) {
802: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
803: $toolhash{'gradesecret'} = $gradesecret;
804: $toolhash{'gradesecretdate'} = time;
805: }
806: if ($toolhash{'roster'}) {
807: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
808: $toolhash{'rostersecret'} = $rostersecret;
809: $toolhash{'rostersecretdate'} = time;
810: }
1.645 raeburn 811: my $changegradable;
812: if (($residx) && ($folder =~ /^default/)) {
1.648 raeburn 813: if ($toolsettings{'gradable'}) {
814: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 815: push(@deleted,'gradable');
816: $changegradable = 1;
817: }
1.648 raeburn 818: } elsif ($toolhash{'gradable'}) {
819: $changegradable = 1;
820: }
821: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 822: $changegradable = 1;
1.648 raeburn 823: if ($toolsettings{'gradable'}) {
824: $toolhash{'gradable'} = 1;
825: }
1.645 raeburn 826: }
827: }
1.598 raeburn 828: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 829: if ($putres eq 'ok') {
830: if (@deleted) {
831: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.645 raeburn 832: }
833: if (($changegradable) && ($folder =~ /^default/)) {
834: my $val;
835: if ($toolhash{'gradable'}) {
836: $val = 'yes';
837: } else {
838: $val = 'no';
839: }
840: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
841: 'string_yesno');
842: &remember_parms($residx,'gradable','set',$val);
843: }
844: } else {
845: return (&mt('Failed to save update to external tool.'),1);
1.604 raeburn 846: }
1.598 raeburn 847: }
848: }
849: }
1.529 raeburn 850: if (($caller eq 'londocs') &&
851: ($folder =~ /^default/)) {
1.534 raeburn 852: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 853: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
854: my $cid = $coursedom.'_'.$coursenum;
855: $allmaps =
856: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
857: $chome,$cid);
858: $donechk = 1;
859: }
860: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 861: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
862: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 863: $importuploaded = 1;
864: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
865: next if ($allmaps->{$url});
866: }
867: }
1.344 bisitz 868: if (!$residx
1.329 droeschl 869: || defined($LONCAPA::map::zombies[$residx])) {
870: $residx = &LONCAPA::map::getresidx($url,$residx);
871: push(@LONCAPA::map::order, $residx);
872: }
873: my $ext = 'false';
874: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 875: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
876: my $filepath = $1;
1.675 raeburn 877: my $fname;
878: if ($name eq '') {
879: $name = &mt('Web Page');
1.534 raeburn 880: $fname = 'web';
881: } else {
1.675 raeburn 882: $fname = $name;
883: $fname=&Apache::lonnet::clean_filename($fname);
884: if ($fname eq '') {
885: $fname = 'web';
886: } elsif (length($fname) > 15) {
887: $fname = substr($fname,0,14);
888: }
1.534 raeburn 889: }
1.675 raeburn 890: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 891: my $initialtext = &mt('Replace with your own content.');
892: my $newhtml = <<END;
1.545 raeburn 893: <html>
1.534 raeburn 894: <head>
1.675 raeburn 895: <title>$title</title>
1.534 raeburn 896: </head>
897: <body bgcolor="#ffffff">
898: $initialtext
899: </body>
900: </html>
901: END
902: $env{'form.output'}=$newhtml;
1.630 raeburn 903: my $result =
1.534 raeburn 904: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
905: 'output',
906: "$filepath/$residx/$fname.html");
907: if ($result =~ m{^/uploaded/}) {
908: $url = $result;
909: if ($filepath =~ /^supplemental/) {
910: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
911: $env{'user.domain'}.'___&&&___'.$name;
912: }
913: } else {
914: return (&mt('Failed to save new web page.'),1);
915: }
916: }
1.675 raeburn 917: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 918: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 919: $LONCAPA::map::resources[$residx] =
1.329 droeschl 920: join(':', ($name, $url, $ext, 'normal', 'res'));
921: }
922: }
1.529 raeburn 923: if ($importuploaded) {
924: my %import_errors;
925: my %updated = (
926: removefrommap => \%removefrommap,
927: removeparam => \%removeparam,
928: );
1.533 raeburn 929: my ($result,$msgsarray,$lockerror) =
930: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 931: if (keys(%import_errors) > 0) {
1.530 raeburn 932: $fixuperrors =
1.529 raeburn 933: '<p span class="LC_warning">'."\n".
934: &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".
935: '<ul>'."\n";
936: foreach my $key (sort(keys(%import_errors))) {
937: $fixuperrors .= '<li>'.$key.'</li>'."\n";
938: }
939: $fixuperrors .= '</ul></p>'."\n";
940: }
1.533 raeburn 941: if (ref($msgsarray) eq 'ARRAY') {
942: if (@{$msgsarray} > 0) {
943: $fixuperrors .= '<p class="LC_info">'.
944: join('<br />',@{$msgsarray}).
945: '</p>';
946: }
947: }
948: if ($lockerror) {
949: $fixuperrors .= '<p class="LC_error">'.
950: $lockerror.
951: '</p>';
952: }
1.529 raeburn 953: }
954: my ($errtext,$fatal) =
955: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 956: unless ($fatal) {
957: if ($folder =~ /^supplemental/) {
958: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 959: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
960: $folder.'.'.$container);
1.557 raeburn 961: }
962: }
1.529 raeburn 963: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 964: }
965:
966: sub log_docs {
1.494 raeburn 967: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 968: }
969:
970: {
971: my @oldresources=();
972: my @oldorder=();
973: my $parmidx;
974: my %parmaction=();
975: my %parmvalue=();
976: my $changedflag;
977:
978: sub snapshotbefore {
979: @oldresources=@LONCAPA::map::resources;
980: @oldorder=@LONCAPA::map::order;
981: $parmidx=undef;
982: %parmaction=();
983: %parmvalue=();
984: $changedflag=0;
985: }
986:
987: sub remember_parms {
988: my ($idx,$parameter,$action,$value)=@_;
989: $parmidx=$idx;
990: $parmaction{$parameter}=$action;
991: $parmvalue{$parameter}=$value;
992: $changedflag=1;
993: }
994:
995: sub log_differences {
996: my ($plain)=@_;
997: my %storehash=('folder' => $plain,
998: 'currentfolder' => $env{'form.folder'});
999: if ($parmidx) {
1000: $storehash{'parameter_res'}=$oldresources[$parmidx];
1001: foreach my $parm (keys(%parmaction)) {
1002: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1003: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1004: }
1005: }
1006: my $maxidx=$#oldresources;
1007: if ($#LONCAPA::map::resources>$#oldresources) {
1008: $maxidx=$#LONCAPA::map::resources;
1009: }
1010: for (my $idx=0; $idx<=$maxidx; $idx++) {
1011: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1012: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1013: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1014: $changedflag=1;
1015: }
1016: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1017: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1018: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1019: $changedflag=1;
1020: }
1021: }
1022: $storehash{'maxidx'}=$maxidx;
1023: if ($changedflag) { &log_docs(\%storehash); }
1024: }
1025: }
1026:
1027: sub docs_change_log {
1.611 raeburn 1028: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 1029: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 1030: my $navmap;
1.483 raeburn 1031: my $js = '<script type="text/javascript">'."\n".
1032: '// <![CDATA['."\n".
1033: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 1034: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 1035: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 1036: &history_tab_js()."\n".
1.484 raeburn 1037: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 1038: '// ]]>'."\n".
1039: '</script>'."\n";
1.484 raeburn 1040: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1041: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1042: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1043: my %orderhash;
1044: my $container='sequence';
1045: my $pathitem;
1.519 raeburn 1046: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1047: $container='page';
1048: }
1.519 raeburn 1049: my $folderpath=$env{'form.folderpath'};
1050: if ($folderpath eq '') {
1.617 raeburn 1051: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1052: }
1.617 raeburn 1053: undef($navmap);
1.519 raeburn 1054: $pathitem = '<input type="hidden" name="folderpath" value="'.
1055: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1056: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1057: my $jumpto = $readfile;
1058: $jumpto =~ s{^/}{};
1059: my $tid = 1;
1.489 raeburn 1060: if ($supplementalflag) {
1061: $tid = 2;
1062: }
1.630 raeburn 1063: my ($breadcrumbtrail) =
1.509 raeburn 1064: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1065: $r->print($breadcrumbtrail.
1066: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1067: $readfile));
1.329 droeschl 1068: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1069: $env{'course.'.$env{'request.course.id'}.'.domain'},
1070: $env{'course.'.$env{'request.course.id'}.'.num'});
1071:
1072: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1073:
1074: my %saveable_parameters = ('show' => 'scalar',);
1075: &Apache::loncommon::store_course_settings('docs_log',
1076: \%saveable_parameters);
1077: &Apache::loncommon::restore_course_settings('docs_log',
1078: \%saveable_parameters);
1079: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1080: # FIXME: internationalization seems wrong here
1.329 droeschl 1081: my %lt=('hiddenresource' => 'Resources hidden',
1082: 'encrypturl' => 'URL hidden',
1083: 'randompick' => 'Randomly pick',
1084: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1085: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1086: 'set' => 'set to',
1087: 'del' => 'deleted');
1.484 raeburn 1088: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1089: $pathitem."\n".
1090: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1091: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1092: $r->print('<div class="LC_left_float">'.
1093: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1094: &makedocslogform($filter,1).
1095: '</fieldset></div><br clear="all" />');
1.329 droeschl 1096: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1097: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1098: &mt('After').'</th>'.
1099: &Apache::loncommon::end_data_table_header_row());
1100: my $shown=0;
1101: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1102: if ($env{'form.displayfilter'} eq 'currentfolder') {
1103: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1104: }
1105: my @changes=keys(%{$docslog{$id}{'logentry'}});
1106: if ($env{'form.displayfilter'} eq 'containing') {
1107: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1108: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1109: foreach my $key (@changes) {
1110: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1111: }
1.344 bisitz 1112: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1113: }
1114: my $count = 0;
1115: my $time =
1116: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1117: my $plainname =
1118: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1119: $docslog{$id}{'exe_udom'});
1120: my $about_me_link =
1121: &Apache::loncommon::aboutmewrapper($plainname,
1122: $docslog{$id}{'exe_uname'},
1123: $docslog{$id}{'exe_udom'});
1124: my $send_msg_link='';
1125: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1126: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1127: $send_msg_link ='<br />'.
1128: &Apache::loncommon::messagewrapper(&mt('Send message'),
1129: $docslog{$id}{'exe_uname'},
1130: $docslog{$id}{'exe_udom'});
1131: }
1132: $r->print(&Apache::loncommon::start_data_table_row());
1133: $r->print('<td>'.$time.'</td>
1134: <td>'.$about_me_link.
1135: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1136: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1137: $send_msg_link.'</td><td>'.
1138: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1139: my $is_supp = 0;
1140: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1141: $is_supp = 1;
1142: }
1.329 droeschl 1143: # Before
1144: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1145: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1146: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1147: if ($oldname ne $newname) {
1.488 raeburn 1148: my $shown = &LONCAPA::map::qtescape($oldname);
1149: if ($is_supp) {
1150: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1151: }
1152: $r->print($shown);
1.329 droeschl 1153: }
1154: }
1155: $r->print('<ul>');
1156: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1157: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1158: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1159: if ($is_supp) {
1160: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1161: }
1162: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1163: }
1164: }
1165: $r->print('</ul>');
1166: # After
1167: $r->print('</td><td>');
1168:
1169: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1170: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1171: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1172: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1173: my $shown = &LONCAPA::map::qtescape($newname);
1174: if ($is_supp) {
1175: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1176: }
1177: $r->print($shown);
1.329 droeschl 1178: }
1.364 bisitz 1179: }
1.329 droeschl 1180: $r->print('<ul>');
1181: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1182: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1183: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1184: if ($is_supp) {
1185: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1186: }
1187: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1188: }
1189: }
1190: $r->print('</ul>');
1191: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1192: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1.645 raeburn 1193: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1194: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1195: # FIXME: internationalization seems wrong here
1.329 droeschl 1196: $r->print('<li>'.
1197: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1198: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1199: .'</li>');
1200: }
1201: }
1202: $r->print('</ul>');
1203: }
1204: # End
1205: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1206: $shown++;
1207: if (!($env{'form.show'} eq &mt('all')
1208: || $shown<=$env{'form.show'})) { last; }
1209: }
1.484 raeburn 1210: $r->print(&Apache::loncommon::end_data_table()."\n".
1211: &makesimpleeditform($pathitem)."\n".
1212: '</div></div>');
1213: $r->print(&endContentScreen());
1.329 droeschl 1214: }
1215:
1216: sub update_paste_buffer {
1.492 raeburn 1217: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1218: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1219: if ($env{'form.multiremove'}) {
1220: $env{'form.multiremove'} =~ s/,$//;
1221: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1222: }
1223: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1224: if ($env{'form.multicut'}) {
1225: $env{'form.multicut'} =~ s/,$//;
1226: foreach my $item (split(/,/,$env{'form.multicut'})) {
1227: unless ($removals{$item}) {
1228: $cuts{$item} = 1;
1229: push(@possibles,$item.':cut');
1230: }
1231: }
1232: }
1233: if ($env{'form.multicopy'}) {
1234: $env{'form.multicopy'} =~ s/,$//;
1235: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1236: unless ($removals{$item} || $cuts{$item}) {
1237: push(@possibles,$item.':copy');
1238: }
1239: }
1240: }
1241: } elsif ($env{'form.markcopy'}) {
1242: @possibles = split(/,/,$env{'form.markcopy'});
1243: }
1.329 droeschl 1244:
1.538 raeburn 1245: return if (@possibles == 0);
1.329 droeschl 1246: return if (!defined($env{'form.copyfolder'}));
1247:
1248: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1249: $env{'form.copyfolder'});
1.538 raeburn 1250: return if ($fatal);
1251:
1252: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1253:
1.538 raeburn 1254: # Retrieve current paste buffer suffixes.
1255: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1256: my (%pasteurls,@newpaste);
1257:
1258: # Construct identifiers for current contents of user's paste buffer
1259: if (@currpaste) {
1260: foreach my $suffix (@currpaste) {
1.667 raeburn 1261: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1262: my $url = $env{'docs.markedcopy_url_'.$suffix};
1263: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1264: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1265: ($url ne '')) {
1266: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1267: $pasteurls{$cid.'_'.$mapidx} = 1;
1268: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1269: $pasteurls{$url} = 1;
1270: } else {
1.669 raeburn 1271: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 1272: }
1273: }
1.538 raeburn 1274: }
1275: }
1276:
1277: # Mark items for copying (skip any items already in user's paste buffer)
1278: my %addtoenv;
1.597 raeburn 1279:
1280: my @pathitems = split(/\&/,$env{'form.folderpath'});
1281: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 1282: my $ispage = $folderconf[5];
1.597 raeburn 1283:
1.538 raeburn 1284: foreach my $item (@possibles) {
1285: my ($orderidx,$cmd) = split(/:/,$item);
1286: next if ($orderidx =~ /\D/);
1287: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1288: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1289: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1290: my %denied = &action_restrictions($coursenum,$coursedom,
1291: &LONCAPA::map::qtescape($url),
1292: $env{'form.folderpath'},\%curr_groups);
1293: next if ($denied{'copy'});
1294: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 1295: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1296: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1297: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1298: next if (exists($pasteurls{$url}));
1299: } else {
1300: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1301: }
1.538 raeburn 1302: my ($suffix,$errortxt,$locknotfreed) =
1303: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1304: if ($suffix ne '') {
1305: push(@newpaste,$suffix);
1306: } else {
1307: if ($locknotfreed) {
1308: return $locknotfreed;
1309: }
1.538 raeburn 1310: }
1311: if (&is_supplemental_title($title)) {
1312: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1313: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1314: }
1.329 droeschl 1315:
1.538 raeburn 1316: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1317: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1318: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1319: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1320: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1321: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1322: my $prefix = $1;
1323: my $subdir =$2;
1324: if ($subdir eq '') {
1325: $subdir = $prefix;
1.492 raeburn 1326: }
1.538 raeburn 1327: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1328: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1329: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1330: if (ref($hierarchy{$url}) eq 'HASH') {
1331: my ($nested,$nestednames);
1332: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1333: $nested =~ s/\&$//;
1334: $nestednames =~ s/\Q___&&&___\E$//;
1335: if ($nested ne '') {
1336: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1337: }
1338: if ($nestednames ne '') {
1339: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1340: }
1.492 raeburn 1341: }
1342: }
1.591 raeburn 1343: if ($locknotfreed) {
1344: $output = $locknotfreed;
1345: last;
1346: }
1.492 raeburn 1347: }
1.538 raeburn 1348: if (@newpaste) {
1349: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1350: }
1.492 raeburn 1351: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1352: delete($env{'form.markcopy'});
1.591 raeburn 1353: return $output;
1.329 droeschl 1354: }
1355:
1.492 raeburn 1356: sub recurse_uploaded_maps {
1357: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1358: if (ref($hierarchy->{$url}) eq 'HASH') {
1359: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1360: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1361: my (@uploaded,@names,%shorter);
1362: for (my $i=0; $i<@maps; $i++) {
1363: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1364: if ($inner ne '') {
1365: push(@uploaded,$inner);
1366: push(@names,&escape($titles[$i]));
1367: $shorter{$maps[$i]} = $inner;
1368: }
1369: }
1370: $$nestref .= "$dir:".join(',',@uploaded).'&';
1371: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1372: foreach my $map (@maps) {
1373: if ($shorter{$map} ne '') {
1374: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1375: }
1376: }
1377: }
1378: return;
1379: }
1380:
1.329 droeschl 1381: sub print_paste_buffer {
1.492 raeburn 1382: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1383: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1384:
1.538 raeburn 1385: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1386: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1387: }
1388:
1.538 raeburn 1389: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1390: my ($pasteitems,@pasteable);
1.575 raeburn 1391: my $clipboardcount = 0;
1.488 raeburn 1392:
1.538 raeburn 1393: # Construct identifiers for current contents of user's paste buffer
1394: foreach my $suffix (@currpaste) {
1395: next if ($suffix =~ /\D/);
1396: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1397: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1398: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1399: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1400: ($url ne '')) {
1.575 raeburn 1401: $clipboardcount ++;
1.538 raeburn 1402: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1403: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1404: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1405: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1406: $is_external = 1;
1.626 raeburn 1407: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1408: $is_exttool = 1;
1.538 raeburn 1409: }
1410: if ($folder =~ /^supplemental/) {
1411: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1412: unless ($canpaste) {
1413: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1414: }
1415: } else {
1416: $canpaste = 1;
1417: }
1418: if ($canpaste) {
1419: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1420: my $srcdom = $1;
1421: my $srcnum = $2;
1422: my $rem = $3;
1423: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1424: $othercourse = 1;
1425: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1426: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1427: } else {
1428: $canpaste = 0;
1429: $nopaste = &mt('Paste from another course unavailable.');
1430: }
1431: }
1432: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1433: my $prefix = $1;
1434: $parent = $2;
1435: if ($folder !~ /^\Q$prefix\E/) {
1436: $areachange = 1;
1437: }
1438: $is_uploaded_map = 1;
1.492 raeburn 1439: }
1.597 raeburn 1440: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1441: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1442: if ($cid ne $env{'request.course.id'}) {
1443: my ($srcdom,$srcnum) = split(/_/,$cid);
1444: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1445: if (($is_exttool) && ($srcdom ne $coursedom)) {
1446: $canpaste = 0;
1447: $nopaste = &mt('Paste from another domain unavailable.');
1448: } else {
1449: $othercrs = '<br />'.&mt('(from another course)');
1450: }
1.596 raeburn 1451: } else {
1452: $canpaste = 0;
1453: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1454: }
1.596 raeburn 1455: }
1.492 raeburn 1456: }
1.596 raeburn 1457: if ($canpaste) {
1458: push(@pasteable,$suffix);
1.629 raeburn 1459: }
1.538 raeburn 1460: }
1461: my $buffer;
1.627 raeburn 1462: if ($is_external) {
1.538 raeburn 1463: $buffer = &mt('External Resource').': '.
1464: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1465: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1466: } elsif ($is_exttool) {
1467: $buffer = &mt('External Tool').': '.
1468: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1469: } else {
1470: my $icon = &Apache::loncommon::icon($extension);
1471: if ($extension eq 'sequence' &&
1472: $url =~ m{/default_\d+\.sequence$}x) {
1473: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1474: $icon .= '/navmap.folder.closed.gif';
1475: }
1.589 raeburn 1476: my $title = $env{'docs.markedcopy_title_'.$suffix};
1477: if ($title eq '') {
1478: ($title) = ($url =~ m{/([^/]+)$});
1479: }
1.538 raeburn 1480: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1481: ': '.
1482: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1483: &LONCAPA::map::qtescape($title));
1.538 raeburn 1484: }
1485: $pasteitems .= '<div class="LC_left_float">';
1486: my ($options,$onclick);
1487: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1488: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1489: if (($is_uploaded_map) ||
1490: ($url =~ /(bulletinboard|smppg)$/) ||
1491: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1492: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1493: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1494: }
1495: }
1496: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1497: if ($nopaste) {
1.681 ! raeburn 1498: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 1499: } else {
1500: if ($othercrs) {
1501: $pasteitems .= $othercrs;
1502: }
1503: if ($options) {
1504: $pasteitems .= $options;
1.492 raeburn 1505: }
1506: }
1.538 raeburn 1507: $pasteitems .= '</div>';
1508: }
1509: }
1510: if ($pasteitems eq '') {
1511: &Apache::lonnet::delenv('docs.markedcopies');
1512: }
1513: my ($pasteform,$form_start,$buttons,$form_end);
1514: if ($pasteitems) {
1515: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1516: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1517: if (@pasteable) {
1.575 raeburn 1518: my $value = &mt('Paste to current folder');
1519: if ($container eq 'page') {
1520: $value = &mt('Paste to current page');
1521: }
1522: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1523: }
1524: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1525: if ($clipboardcount > 1) {
1526: $buttons .=
1527: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1528: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1529: (' 'x2).
1530: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1531: (' 'x2);
1.492 raeburn 1532: }
1.575 raeburn 1533: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1534: '</form>';
1.538 raeburn 1535: } else {
1536: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1537: }
1.538 raeburn 1538: $r->print($form_start
1539: .'<fieldset>'
1540: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1541: .$pasteitems
1542: .'</fieldset>'
1543: .$form_end);
1544: }
1545:
1546: sub paste_options {
1547: my ($suffix,$is_uploaded_map,$parent) = @_;
1548: my ($copytext,$movetext);
1549: if ($is_uploaded_map) {
1550: $copytext = &mt('Copy to new folder');
1551: $movetext = &mt('Move old');
1552: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1553: $copytext = &mt('Copy to new board');
1554: $movetext = &mt('Move (not posts)');
1555: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1556: $copytext = &mt('Copy to new page');
1557: $movetext = &mt('Move');
1.533 raeburn 1558: } else {
1.538 raeburn 1559: $copytext = &mt('Copy to new file');
1560: $movetext = &mt('Move');
1561: }
1562: my $output = '<br />'.
1563: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1564: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1565: '<label>'.
1566: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1567: $copytext.'</label></span>'.(' 'x2).' '.
1568: '<span class="LC_nobreak"><label>'.
1569: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1570: $movetext.'</label></span>';
1571: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1572: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1573: '</legend><table border="0">';
1574: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1575: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1576: my $lastdir = $parent;
1577: my %depths = (
1578: $lastdir => 0,
1579: );
1580: my (%display,%deps);
1581: for (my $i=0; $i<@pastemaps; $i++) {
1582: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1583: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1584: my @subfolders = split(/,/,$subfolderstr);
1585: $deps{$lastdir} = \@subfolders;
1586: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1587: my $depth = $depths{$lastdir} + 1;
1588: my $offset = int($depth * 4);
1589: my $indent = (' ' x $offset);
1590: for (my $j=0; $j<@subfolders; $j++) {
1591: $depths{$subfolders[$j]} = $depth;
1592: $display{$subfolders[$j]} =
1593: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1594: '<td><label>'.
1595: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1596: '<label>'.
1597: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1598: &mt('Move old').'</label>'.
1599: '</td></tr>';
1600: }
1.492 raeburn 1601: }
1.538 raeburn 1602: &recurse_print(\$output,$parent,\%deps,\%display);
1603: $output .= '</table></fieldset>';
1.329 droeschl 1604: }
1.538 raeburn 1605: $output .= '</div>';
1606: return $output;
1.488 raeburn 1607: }
1608:
1.492 raeburn 1609: sub recurse_print {
1.538 raeburn 1610: my ($outputref,$dir,$deps,$display) = @_;
1611: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1612: if (ref($deps->{$dir}) eq 'ARRAY') {
1613: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1614: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1615: }
1616: }
1617: }
1618:
1.488 raeburn 1619: sub supp_pasteable {
1620: my ($url) = @_;
1621: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1622: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1623: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1624: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1625: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1626: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1627: return 1;
1628: }
1629: return;
1.329 droeschl 1630: }
1631:
1.492 raeburn 1632: sub paste_popup_js {
1.594 damieng 1633: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1634: show => 'Show Options',
1635: hide => 'Hide Options',
1.594 damieng 1636: );
1637: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1638: none => 'No items selected from clipboard.',
1.492 raeburn 1639: );
1.594 damieng 1640: &html_escape(\%html_js_lt);
1641: &js_escape(\%html_js_lt);
1642: &js_escape(\%js_lt);
1.492 raeburn 1643: return <<"END";
1644:
1.538 raeburn 1645: function showPasteOptions(suffix) {
1646: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1647: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1648: return;
1649: }
1650:
1.538 raeburn 1651: function hidePasteOptions(suffix) {
1652: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1653: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1654: return;
1655: }
1656:
1657: function showOptions(caller,suffix) {
1658: if (document.getElementById('pasteoptionstext_'+suffix)) {
1659: if (caller.checked) {
1.594 damieng 1660: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1661: } else {
1662: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1663: }
1664: if (document.getElementById('pasteoptions_'+suffix)) {
1665: document.getElementById('pasteoptions_'+suffix).style.display='none';
1666: }
1667: }
1.492 raeburn 1668: return;
1669: }
1670:
1.541 raeburn 1671: function validateClipboard() {
1672: var numchk = 0;
1673: if (document.pasteform.pasting.length > 1) {
1674: for (var i=0; i<document.pasteform.pasting.length; i++) {
1675: if (document.pasteform.pasting[i].checked) {
1676: numchk ++;
1677: }
1678: }
1679: } else {
1680: if (document.pasteform.pasting.type == 'checkbox') {
1681: if (document.pasteform.pasting.checked) {
1682: numchk ++;
1683: }
1684: }
1685: }
1686: if (numchk > 0) {
1687: return true;
1688: } else {
1.594 damieng 1689: alert("$js_lt{'none'}");
1.541 raeburn 1690: return false;
1691: }
1692: }
1693:
1.575 raeburn 1694: function checkClipboard() {
1695: if (document.pasteform.pasting.length > 1) {
1696: for (var i=0; i<document.pasteform.pasting.length; i++) {
1697: document.pasteform.pasting[i].checked = true;
1698: }
1699: }
1700: return;
1701: }
1702:
1703: function uncheckClipboard() {
1704: if (document.pasteform.pasting.length >1) {
1705: for (var i=0; i<document.pasteform.pasting.length; i++) {
1706: document.pasteform.pasting[i].checked = false;
1707: }
1708: }
1709: return;
1710: }
1711:
1.492 raeburn 1712: END
1713:
1714: }
1715:
1.329 droeschl 1716: sub do_paste_from_buffer {
1.492 raeburn 1717: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1718:
1.538 raeburn 1719: # Array of items in paste buffer
1720: my (@currpaste,%pastebuffer,%allerrors);
1721: @currpaste = split(/,/,$env{'docs.markedcopies'});
1722:
1.492 raeburn 1723: # Early out if paste buffer is empty
1.538 raeburn 1724: if (@currpaste == 0) {
1.492 raeburn 1725: return ();
1.538 raeburn 1726: }
1727: map { $pastebuffer{$_} = 1; } @currpaste;
1728:
1729: # Array of items selected items to paste
1730: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1731:
1732: # Early out if nothing selected to paste
1733: if (@reqpaste == 0) {
1734: return();
1735: }
1736: my @topaste;
1737: foreach my $suffix (@reqpaste) {
1738: next if ($suffix =~ /\D/);
1739: next unless (exists($pastebuffer{$suffix}));
1740: push(@topaste,$suffix);
1741: }
1742:
1743: # Early out if nothing available to paste
1744: if (@topaste == 0) {
1745: return();
1.329 droeschl 1746: }
1747:
1.627 raeburn 1748: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1749: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1750:
1751: foreach my $suffix (@topaste) {
1752: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1753: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1754: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1755: # Supplemental content may only include certain types of content
1756: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1757: if ($folder =~ /^supplemental/) {
1758: unless (&supp_pasteable($url)) {
1759: $notinsupp{$suffix} = 1;
1760: next;
1761: }
1.492 raeburn 1762: }
1.538 raeburn 1763: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1764: my $srcd = $1;
1765: my $srcn = $2;
1.492 raeburn 1766: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1767: # check for mdc privilege in the course from which the resource was pasted
1768: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1769: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1770: $notincrs{$suffix} = 1;
1771: next;
1772: }
1.491 raeburn 1773: }
1.538 raeburn 1774: $srcdom{$suffix} = $srcd;
1775: $srcnum{$suffix} = $srcn;
1.597 raeburn 1776: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1777: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1778: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1779: my ($srcd,$srcn) = split(/_/,$cid);
1780: # When paste buffer was populated using an active role in a different course
1781: # check for mdc privilege in the course from which the resource was pasted
1782: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1783: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1784: $notincrs{$suffix} = 1;
1785: next;
1786: }
1787: }
1.632 raeburn 1788: # When buffer was populated using an active role in a different course
1789: # disallow pasting of External Tool if course is in a different domain.
1790: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1791: $notindom{$suffix} = 1;
1792: next;
1793: }
1.596 raeburn 1794: $srcdom{$suffix} = $srcd;
1795: $srcnum{$suffix} = $srcn;
1.491 raeburn 1796: }
1.597 raeburn 1797: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1798: push(@dopaste,$suffix);
1799: if ($url=~/\.(page|sequence)$/) {
1800: $is_map{$suffix} = 1;
1801: }
1802: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1803: my $oldprefix = $1;
1.492 raeburn 1804: # When pasting content from Main Content to Supplemental Content and vice versa
1805: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1806: # a folder/page or a document).
1.538 raeburn 1807: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1808: $prefixchg{$suffix} = 'docstosupp';
1809: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1810: $prefixchg{$suffix} = 'supptodocs';
1811: }
1.491 raeburn 1812:
1.492 raeburn 1813: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1814: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1815: my @nested;
1816: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1817: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1818: my @deps = map { /\d+:([\d,]+$)/ } @items;
1819: foreach my $dep (@deps) {
1820: if ($dep =~ /,/) {
1821: push(@nested,split(/,/,$dep));
1822: } else {
1823: push(@nested,$dep);
1824: }
1.492 raeburn 1825: }
1.538 raeburn 1826: foreach my $item (@nested) {
1827: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1828: push(@{$marktomove{$suffix}},$type.'_'.$item);
1829: }
1.492 raeburn 1830: }
1831: }
1.488 raeburn 1832: }
1833: }
1834:
1.538 raeburn 1835: # Early out if nothing available to paste
1836: if (@dopaste == 0) {
1837: return ();
1838: }
1839:
1840: # Populate message hash and hashes used for main content <=> supplemental content
1841: # changes
1842:
1843: %msgs = &Apache::lonlocal::texthash (
1844: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1845: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 1846: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.538 raeburn 1847: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1848: );
1849:
1850: %before = (
1851: docstosupp => {
1852: map => 'default',
1853: doc => 'docs',
1854: },
1855: supptodocs => {
1856: map => 'supplemental',
1857: doc => 'supplemental',
1858: },
1859: );
1860:
1861: %after = (
1862: docstosupp => {
1863: map => 'supplemental',
1864: doc => 'supplemental'
1865: },
1866: supptodocs => {
1867: map => 'default',
1868: doc => 'docs',
1869: },
1870: );
1871:
1872: # Retrieve information about all course maps in main content area
1873:
1874: my $allmaps = {};
1.660 raeburn 1875: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.538 raeburn 1876:
1877: # Loop over the items to paste
1878: foreach my $suffix (@dopaste) {
1.329 droeschl 1879: # Maps need to be copied first
1.538 raeburn 1880: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1881: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1882: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1883: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1884: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1885: }
1886: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1887: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1888: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1889: my $oldurl = $url;
1890: if ($is_map{$suffix}) {
1.491 raeburn 1891: # If pasting a map, check if map contains other maps
1.538 raeburn 1892: my (%hierarchy,%titles);
1.660 raeburn 1893: if (($folder =~ /^default/) && (!$donechk)) {
1894: $allmaps =
1895: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1896: $env{"course.$env{'request.course.id'}.home"},
1897: $env{'request.course.id'});
1898: $donechk = 1;
1899: }
1.627 raeburn 1900: &contained_map_check($url,$folder,$coursenum,$coursedom,
1901: \%removefrommap,\%removeparam,\%addedmaps,
1902: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1903: if ($url=~ m{^/uploaded/}) {
1904: my $newurl;
1905: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1906: ($newurl,my $error) =
1907: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1908: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1909: \$title,$allmaps,\%newurls);
1910: if ($error) {
1911: $allerrors{$suffix} = $error;
1912: next;
1913: }
1914: if ($newurl ne '') {
1915: if ($newurl ne $url) {
1916: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1917: $newsubdir{$url} = $1;
1918: }
1919: $mapchanges{$url} = 1;
1.492 raeburn 1920: }
1.538 raeburn 1921: }
1922: }
1923: if (($srcdom{$suffix} ne $coursedom) ||
1924: ($srcnum{$suffix} ne $coursenum) ||
1925: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1926: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1927: $coursedom,$coursenum,$srcdom{$suffix},
1928: $srcnum{$suffix},$allmaps,\%rewrites,
1929: \%retitles,\%copies,\%dbcopies,
1930: \%zombies,\%params,\%mapmoves,
1931: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1932: \%newurls,\%resdatacopy)) {
1.538 raeburn 1933: $mapmoves{$url} = 1;
1934: }
1935: $url = $newurl;
1936: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1937: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1938: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1939: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1940: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1941: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1942: }
1943: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1944: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1945: push(@toclear,$suffix);
1946: # if pasting published map (main content area only) check map not already in course
1947: if ($folder =~ /^default/) {
1948: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1949: $duplicate{$suffix} = 1;
1950: next;
1.492 raeburn 1951: }
1.491 raeburn 1952: }
1953: }
1.538 raeburn 1954: }
1.627 raeburn 1955: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1956: my $prefix = $1;
1.648 raeburn 1957: my $fromothercrs;
1.538 raeburn 1958: #need to copy the db contents to a new one, unless this is a move.
1959: my %info = (
1960: src => $url,
1961: cdom => $coursedom,
1962: cnum => $coursenum,
1.596 raeburn 1963: );
1.649 raeburn 1964: if ($prefix eq 'ext.tool') {
1.655 raeburn 1965: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 1966: $info{'delgradable'} = 1;
1967: }
1968: }
1.596 raeburn 1969: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1970: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1971: $fromothercrs = 1;
1972: $info{'cdom'} = $srcdom{$suffix};
1973: $info{'cnum'} = $srcnum{$suffix};
1974: }
1975: }
1976: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 1977: my (%lockerr,$msg);
1.538 raeburn 1978: my ($newurl,$result,$errtext) =
1979: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1980: if ($result eq 'ok') {
1981: $url = $newurl;
1982: $title=&mt('Copy of').' '.$title;
1983: } else {
1984: if ($prefix eq 'smppg') {
1985: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1986: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1987: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 1988: } elsif ($prefix eq 'ext.tool') {
1989: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 1990: }
1991: $results{$suffix} = $result;
1992: $msgerrs{$suffix} = $msg;
1993: $lockerrs{$suffix} = $lockerr{$prefix};
1994: next;
1995: }
1996: if ($lockerr{$prefix}) {
1997: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1998: }
1.489 raeburn 1999: }
2000: }
1.538 raeburn 2001: $title = &LONCAPA::map::qtunescape($title);
2002: my $ext='false';
2003: if ($url=~m{^http(|s)://}) { $ext='true'; }
2004: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2005: if ($folder !~ /^supplemental/) {
2006: (undef,undef,$title) =
2007: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2008: }
2009: } else {
2010: if ($folder=~/^supplemental/) {
2011: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2012: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2013: }
1.533 raeburn 2014: }
1.491 raeburn 2015:
2016: # For uploaded files (excluding pages/sequences) path in copied file is changed
2017: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2018: # courses.
2019:
1.538 raeburn 2020: unless ($is_map{$suffix}) {
2021: my $newidx;
1.492 raeburn 2022: # Now insert the URL at the bottom
1.538 raeburn 2023: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2024: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2025: my $relpath = $1;
2026: if ($relpath ne '') {
2027: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2028: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2029: my $newprefix = $newloc;
2030: if ($newloc eq 'default') {
2031: $newprefix = 'docs';
2032: }
2033: if ($newdocsdir eq '') {
2034: $newdocsdir = 'default';
2035: }
1.630 raeburn 2036: if (($prefixchg{$suffix}) ||
2037: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2038: ($srcnum{$suffix} ne $coursenum) ||
2039: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2040: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2041: $url =
2042: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2043: &Apache::lonnet::getfile($oldurl));
2044: if ($url eq '/adm/notfound.html') {
2045: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2046: next;
2047: } else {
2048: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2049: $newsubpath =~ s{/+$}{/};
2050: $docmoves{$oldurl} = $newsubpath;
2051: }
1.491 raeburn 2052: }
2053: }
1.597 raeburn 2054: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2055: my $template = $1;
2056: if ($newidx) {
2057: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2058: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2059: }
1.649 raeburn 2060: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2061: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2062: my $marker = (split(m{/},$url))[4];
2063: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2064: my $val = 'no';
2065: if ($toolsettings{'gradable'}) {
2066: $val = 'yes';
2067: }
2068: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2069: 'string_yesno');
2070: &remember_parms($newidx,'gradable','set',$val);
2071: }
1.491 raeburn 2072: }
1.538 raeburn 2073: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2074: ':'.$ext.':normal:res';
2075: push(@LONCAPA::map::order,$newidx);
2076: # Store the result
2077: my ($errtext,$fatal) =
2078: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2079: if ($fatal) {
2080: $save_err .= $errtext;
2081: $allresult = 'fail';
2082: }
1.488 raeburn 2083: }
1.538 raeburn 2084:
1.597 raeburn 2085: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2086: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2087: unless ($allresult eq 'fail') {
2088: my %updated = (
2089: rewrites => \%rewrites,
2090: zombies => \%zombies,
2091: removefrommap => \%removefrommap,
2092: removeparam => \%removeparam,
2093: dbcopies => \%dbcopies,
1.597 raeburn 2094: resdatacopy => \%resdatacopy,
1.538 raeburn 2095: retitles => \%retitles,
2096: );
2097: my %info = (
2098: newsubdir => \%newsubdir,
2099: params => \%params,
2100: );
2101: if ($prefixchg{$suffix}) {
2102: $info{'before'} = $before{$prefixchg{$suffix}};
2103: $info{'after'} = $after{$prefixchg{$suffix}};
2104: }
2105: my %moves = (
2106: copies => \%copies,
2107: docmoves => \%docmoves,
2108: mapmoves => \%mapmoves,
2109: );
2110: (my $result,$msgs{$suffix},my $lockerror) =
2111: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2112: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2113: $url,'paste');
2114: $lockerrors .= $lockerror;
2115: if ($result eq 'ok') {
2116: if ($is_map{$suffix}) {
2117: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2118: $folder.'.'.$container);
2119: if ($fatal) {
2120: $allresult = 'failread';
2121: } else {
2122: if ($#LONCAPA::map::order<1) {
2123: my $idx=&LONCAPA::map::getresidx();
2124: if ($idx<=0) { $idx=1; }
2125: $LONCAPA::map::order[0]=$idx;
2126: $LONCAPA::map::resources[$idx]='';
2127: }
2128: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2129: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2130: ':'.$ext.':normal:res';
2131: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2132:
2133: # Store the result
1.538 raeburn 2134: my ($errtext,$fatal) =
2135: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2136: if ($fatal) {
2137: $save_err .= $errtext;
2138: $allresult = 'failstore';
2139: }
2140: }
2141: }
2142: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2143: push(@toclear,$suffix);
2144: }
2145: }
1.492 raeburn 2146: }
2147: }
1.538 raeburn 2148: &clear_from_buffer(\@toclear,\@currpaste);
2149: my $msgsarray;
2150: foreach my $suffix (keys(%msgs)) {
2151: if (ref($msgs{$suffix}) eq 'ARRAY') {
2152: $msgsarray .= join(',',@{$msgs{$suffix}});
2153: }
2154: }
2155: return ($allresult,$save_err,$msgsarray,$lockerrors);
2156: }
1.533 raeburn 2157:
1.538 raeburn 2158: sub do_buffer_empty {
2159: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2160: if (@currpaste == 0) {
2161: return &mt('Clipboard is already empty');
2162: }
2163: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2164: if (@toclear == 0) {
2165: return &mt('Nothing selected to clear from clipboard');
2166: }
2167: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2168: if ($numdel) {
2169: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2170: } else {
2171: return &mt('Clipboard unchanged');
1.492 raeburn 2172: }
1.538 raeburn 2173: return;
2174: }
2175:
2176: sub clear_from_buffer {
2177: my ($toclear,$currpaste) = @_;
2178: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2179: my %pastebuffer;
2180: map { $pastebuffer{$_} = 1; } @{$currpaste};
2181: my $numdel = 0;
2182: foreach my $suffix (@{$toclear}) {
2183: next if ($suffix =~ /\D/);
2184: next unless (exists($pastebuffer{$suffix}));
2185: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2186: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2187: delete($pastebuffer{$suffix});
2188: $numdel ++;
2189: }
2190: }
2191: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2192: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2193: return $numdel;
1.492 raeburn 2194: }
2195:
2196: sub get_newmap_url {
2197: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2198: $titleref,$allmaps,$newurls) = @_;
2199: my $newurl;
2200: if ($url=~ m{^/uploaded/}) {
2201: $$titleref=&mt('Copy of').' '.$$titleref;
2202: }
2203: my $now = time;
2204: my $suffix=$$.int(rand(100)).$now;
2205: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2206: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2207: my $path = $1;
2208: my $prefix = $2;
2209: my $ancestor = $3;
2210: if (length($ancestor) > 10) {
2211: $ancestor = substr($ancestor,-10,10);
2212: }
2213: my $newid;
2214: if ($prefixchg) {
2215: if ($folder =~ /^supplemental/) {
2216: $prefix =~ s/^default/supplemental/;
2217: } else {
2218: $prefix =~ s/^supplemental/default/;
2219: }
2220: }
2221: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2222: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2223: } else {
2224: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2225: }
2226: my $counter = 0;
2227: my $is_unique = &uniqueness_check($newurl);
2228: if ($folder =~ /^default/) {
2229: if ($allmaps->{$newurl}) {
2230: $is_unique = 0;
2231: }
2232: }
2233: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2234: $counter ++;
2235: $suffix ++;
2236: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2237: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2238: } else {
2239: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2240: }
2241: $is_unique = &uniqueness_check($newurl);
2242: }
2243: if ($is_unique) {
2244: $newurls->{$newurl} = 1;
2245: } else {
2246: if ($url=~/\.page$/) {
2247: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2248: } else {
2249: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2250: }
2251: }
1.329 droeschl 2252: }
1.492 raeburn 2253: return ($newurl);
1.329 droeschl 2254: }
2255:
1.488 raeburn 2256: sub dbcopy {
1.533 raeburn 2257: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2258: my ($url,$result,$errtext);
2259: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2260: $url = $dbref->{'src'};
1.627 raeburn 2261: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2262: my $prefix = $1;
1.627 raeburn 2263: if ($prefix eq 'ext.tool') {
2264: $prefix = 'exttool';
2265: }
1.533 raeburn 2266: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2267: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2268: my $db_name;
2269: my $marker = (split(m{/},$url))[4];
2270: $marker=~s/\D//g;
2271: if ($dbref->{'src'} =~ m{/smppg$}) {
2272: $db_name =
2273: &Apache::lonsimplepage::get_db_name($url,$marker,
2274: $dbref->{'cdom'},
2275: $dbref->{'cnum'});
1.627 raeburn 2276: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2277: $db_name = 'exttool_'.$marker;
1.533 raeburn 2278: } else {
2279: $db_name = 'bulletinpage_'.$marker;
2280: }
2281: my ($suffix,$freedlock,$error) =
2282: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2283: $coursedom,$coursenum,
2284: 'concat');
2285: if (!$suffix) {
2286: if ($prefix eq 'smppg') {
2287: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2288: } elsif ($prefix eq 'exttool') {
2289: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2290: } else {
1.565 bisitz 2291: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2292: }
2293: if ($error) {
2294: $errtext .= '<br />'.$error;
2295: }
2296: } else {
2297: #need to copy the db contents to a new one.
2298: my %contents=&Apache::lonnet::dump($db_name,
2299: $dbref->{'cdom'},
2300: $dbref->{'cnum'});
2301: if (exists($contents{'uploaded.photourl'})) {
2302: my $photo = $contents{'uploaded.photourl'};
2303: my ($subdir,$fname) =
2304: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2305: my $newphoto;
1.533 raeburn 2306: if ($fname ne '') {
2307: my $content = &Apache::lonnet::getfile($photo);
2308: unless ($content eq '-1') {
2309: $env{'form.'.$suffix.'.photourl'} = $content;
2310: $newphoto =
2311: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2312: delete($env{'form.'.$suffix.'.photourl'});
2313: }
2314: }
2315: if ($newphoto =~ m{^/uploaded/}) {
2316: $contents{'uploaded.photourl'} = $newphoto;
2317: }
2318: }
2319: $db_name =~ s{_\d*$ }{_$suffix}x;
1.649 raeburn 2320: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2321: delete($contents{'gradable'});
2322: }
1.533 raeburn 2323: $result=&Apache::lonnet::put($db_name,\%contents,
2324: $coursedom,$coursenum);
2325: if ($result eq 'ok') {
1.627 raeburn 2326: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2327: }
2328: }
2329: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2330: $lockerrorsref->{$prefix} =
1.533 raeburn 2331: '<div class="LC_error">'.
2332: &mt('There was a problem removing a lockfile.');
2333: if ($prefix eq 'smppg') {
1.560 raeburn 2334: $lockerrorsref->{$prefix} .=
1.559 raeburn 2335: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2336: } elsif ($prefix eq 'exttool') {
2337: $lockerrorsref->{$prefix} .=
2338: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2339: } else {
1.565 bisitz 2340: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2341: }
1.560 raeburn 2342: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2343: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2344: '</div>';
1.533 raeburn 2345: }
2346: }
2347: } elsif ($url =~ m{/syllabus$}) {
2348: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2349: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2350: if (($dbref->{'cdom'} ne $coursedom) ||
2351: ($dbref->{'cnum'} ne $coursenum)) {
2352: my %contents=&Apache::lonnet::dump('syllabus',
2353: $dbref->{'cdom'},
2354: $dbref->{'cnum'});
2355: $result=&Apache::lonnet::put('syllabus',\%contents,
2356: $coursedom,$coursenum);
2357: }
2358: }
1.488 raeburn 2359: }
2360: }
1.533 raeburn 2361: return ($url,$result,$errtext);
1.488 raeburn 2362: }
2363:
1.597 raeburn 2364: sub copy_templated_files {
2365: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2366: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2367: my $srccontainer = 'sequence';
2368: if ($srcwaspage) {
2369: $srccontainer = 'page';
2370: }
2371: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2372: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2373: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2374: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2375: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2376: $template.'.problem';
2377: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2378: if ($template eq 'simpleproblem') {
2379: $srcprefix .= '.0.';
2380: my $weightprefix = $newprefix;
2381: $newprefix .= '.0.';
2382: my @simpleprobqtypes = qw(radio option string essay numerical);
2383: my $qtype=$srcparms{$srcprefix.'questiontype'};
2384: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 2385: my %newdata = (
2386: $newprefix.'questiontype' => $qtype,
2387: );
1.597 raeburn 2388: foreach my $type (@simpleprobqtypes) {
2389: if ($type eq $qtype) {
2390: $newdata{"$weightprefix.$type.weight"}=1;
2391: } else {
2392: $newdata{"$weightprefix.$type.weight"}=0;
2393: }
2394: }
2395: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2396: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2397: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2398: if ($qtype eq 'numerical') {
2399: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2400: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2401: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2402: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2403: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2404: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2405: unless (defined($maxfoils)) { $maxfoils=10; }
2406: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2407: if ($maxfoils<=0) { $maxfoils=10; }
2408: my $randomize=$srcparms{$srcprefix.'randomize'};
2409: unless (defined($randomize)) { $randomize='yes'; }
2410: unless ($randomize eq 'no') { $randomize='yes'; }
2411: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2412: $newdata{$newprefix.'randomize'} = $randomize;
2413: if ($qtype eq 'option') {
2414: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2415: }
2416: for (my $i=1; $i<=10; $i++) {
2417: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2418: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2419: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2420: }
2421:
2422: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2423: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2424: unless (defined($maxfoils)) { $maxfoils=10; }
2425: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2426: if ($maxfoils<=0) { $maxfoils=10; }
2427: my $randomize=$srcparms{$srcprefix.'randomize'};
2428: unless (defined($randomize)) { $randomize='yes'; }
2429: unless ($randomize eq 'no') { $randomize='yes'; }
2430: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2431: $newdata{$newprefix.'randomize'} = $randomize;
2432: if ($qtype eq 'option') {
2433: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2434: }
2435: for (my $i=1; $i<=10; $i++) {
2436: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2437: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2438: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2439: }
2440: } elsif ($qtype eq 'string') {
2441: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2442: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2443: }
2444: if (keys(%newdata)) {
2445: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2446: $coursenum);
2447: if ($putres eq 'ok') {
2448: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2449: }
2450: }
2451: }
2452: }
2453: }
2454:
1.329 droeschl 2455: sub uniqueness_check {
2456: my ($newurl) = @_;
2457: my $unique = 1;
2458: foreach my $res (@LONCAPA::map::order) {
2459: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2460: $url=&LONCAPA::map::qtescape($url);
2461: if ($newurl eq $url) {
2462: $unique = 0;
1.344 bisitz 2463: last;
1.329 droeschl 2464: }
2465: }
2466: return $unique;
2467: }
2468:
1.488 raeburn 2469: sub contained_map_check {
1.627 raeburn 2470: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2471: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2472: my $content = &Apache::lonnet::getfile($url);
2473: unless ($content eq '-1') {
2474: my $parser = HTML::TokeParser->new(\$content);
2475: $parser->attr_encoded(1);
2476: while (my $token = $parser->get_token) {
2477: next if ($token->[0] ne 'S');
2478: if ($token->[1] eq 'resource') {
2479: next if ($token->[2]->{'type'} eq 'zombie');
2480: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2481: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2482: my $srcdom = $1;
2483: unless ($srcdom eq $coursedom) {
2484: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2485: next;
2486: }
2487: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2488: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2489: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2490: next;
2491: }
2492: }
1.492 raeburn 2493: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2494: if ($1 eq 'uploaded') {
2495: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2496: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2497: } else {
1.492 raeburn 2498: if ($allmaps->{$ressrc}) {
1.529 raeburn 2499: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2500: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2501: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2502: } else {
2503: $addedmaps->{$ressrc} = [$url];
2504: }
1.488 raeburn 2505: }
1.627 raeburn 2506: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2507: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2508: }
1.492 raeburn 2509: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2510: if ($folder =~ /^supplemental/) {
1.492 raeburn 2511: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2512: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2513: } else {
2514: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2515: }
1.488 raeburn 2516: }
2517: }
2518: }
2519: }
2520: return;
2521: }
2522:
2523: sub url_paste_fixups {
1.533 raeburn 2524: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2525: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2526: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2527: my $checktitle;
2528: if (($prefixchg) &&
1.492 raeburn 2529: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2530: $checktitle = 1;
2531: }
1.492 raeburn 2532: my $skip;
2533: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2534: my $mapid = $1.$2;
2535: if ($tomove->{$mapid}) {
2536: $skip = 1;
2537: }
2538: }
1.491 raeburn 2539: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2540: return if ($file eq '-1');
2541: my $parser = HTML::TokeParser->new(\$file);
2542: $parser->attr_encoded(1);
1.491 raeburn 2543: my $changed = 0;
1.488 raeburn 2544: while (my $token = $parser->get_token) {
2545: next if ($token->[0] ne 'S');
2546: if ($token->[1] eq 'resource') {
2547: my $ressrc = $token->[2]->{'src'};
2548: next if ($ressrc eq '');
1.491 raeburn 2549: my $id = $token->[2]->{'id'};
1.492 raeburn 2550: my $title = $token->[2]->{'title'};
1.491 raeburn 2551: if ($checktitle) {
2552: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2553: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2554: }
2555: }
1.488 raeburn 2556: next if ($token->[2]->{'type'} eq 'external');
2557: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2558: next if ($skip);
1.532 raeburn 2559: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2560: $changed = 1;
2561: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2562: my $srcdom = $1;
2563: my $srcnum = $2;
1.488 raeburn 2564: my $rem = $3;
1.492 raeburn 2565: my $newurl;
2566: my $mapname;
2567: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2568: my $prefix = $1;
2569: $mapname = $prefix.$2;
2570: if ($tomove->{$mapname}) {
1.533 raeburn 2571: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2572: $srcdom,$srcnum,$allmaps,$rewrites,
2573: $retitles,$copies,$dbcopies,$zombies,
2574: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2575: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2576: next;
2577: } else {
2578: ($newurl,my $error) =
2579: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2580: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2581: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2582: $newsubdir->{$ressrc} = $1;
2583: }
2584: if ($error) {
2585: next;
2586: }
2587: }
2588: }
2589: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2590: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2591:
1.488 raeburn 2592: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2593: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2594: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2595: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2596: $cnum,$srcdom,$srcnum,$allmaps,
2597: $rewrites,$retitles,$copies,$dbcopies,
2598: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2599: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2600: $mapmoves->{$ressrc} = 1;
2601: }
2602: $changed = 1;
1.488 raeburn 2603: } else {
1.532 raeburn 2604: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2605: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2606: $changed = 1;
1.488 raeburn 2607: }
2608: }
1.649 raeburn 2609: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 2610: next if ($skip);
1.492 raeburn 2611: my $srcdom = $1;
2612: my $srcnum = $2;
1.649 raeburn 2613: my $rem = $3;
2614: my ($is_exttool,$exttoolchg);
2615: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 2616: $is_exttool = 1;
1.649 raeburn 2617: }
1.492 raeburn 2618: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2619: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2620: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2621: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2622: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2623: $changed = 1;
1.649 raeburn 2624: if ($is_exttool) {
2625: $exttoolchg = 1;
2626: }
2627: } elsif (($rem =~ m{\d+/ext\.tool$}) &&
2628: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2629: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2630: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2631: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2632: $changed = 1;
2633: $exttoolchg = 1;
2634: }
2635: if (($is_exttool) && ($prefixchg)) {
2636: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2637: if ($exttoolchg) {
2638: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2639: }
2640: }
1.533 raeburn 2641: }
2642: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2643: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2644: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2645: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2646: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2647: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2648: $changed = 1;
1.488 raeburn 2649: }
1.597 raeburn 2650: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2651: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2652: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2653: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2654: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2655: }
1.488 raeburn 2656: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2657: next if ($skip);
2658: my $srcdom = $1;
2659: my $srcnum = $2;
2660: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2661: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2662: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2663: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2664: $changed = 1;
1.488 raeburn 2665: }
2666: }
2667: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2668: next if ($skip);
1.488 raeburn 2669: my $to = $token->[2]->{'to'};
2670: if ($to ne '') {
2671: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2672: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2673: } else {
2674: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2675: }
2676: }
2677: }
2678: }
1.491 raeburn 2679: return $changed;
1.488 raeburn 2680: }
2681:
2682: sub apply_fixups {
1.529 raeburn 2683: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2684: $oldurl,$url,$caller) = @_;
2685: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2686: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2687: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2688: if (ref($updated) eq 'HASH') {
2689: if (ref($updated->{'rewrites'}) eq 'HASH') {
2690: %rewrites = %{$updated->{'rewrites'}};
2691: }
2692: if (ref($updated->{'zombies'}) eq 'HASH') {
2693: %zombies = %{$updated->{'zombies'}};
2694: }
2695: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2696: %removefrommap = %{$updated->{'removefrommap'}};
2697: }
2698: if (ref($updated->{'removeparam'}) eq 'HASH') {
2699: %removeparam = %{$updated->{'removeparam'}};
2700: }
2701: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2702: %dbcopies = %{$updated->{'dbcopies'}};
2703: }
2704: if (ref($updated->{'retitles'}) eq 'HASH') {
2705: %retitles = %{$updated->{'retitles'}};
2706: }
1.597 raeburn 2707: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2708: %resdatacopy = %{$updated->{'resdatacopy'}};
2709: }
1.529 raeburn 2710: }
2711: if (ref($info) eq 'HASH') {
2712: if (ref($info->{'newsubdir'}) eq 'HASH') {
2713: %newsubdir = %{$info->{'newsubdir'}};
2714: }
2715: if (ref($info->{'params'}) eq 'HASH') {
2716: %params = %{$info->{'params'}};
2717: }
2718: if (ref($info->{'before'}) eq 'HASH') {
2719: %before = %{$info->{'before'}};
2720: }
2721: if (ref($info->{'after'}) eq 'HASH') {
2722: %after = %{$info->{'after'}};
2723: }
2724: }
2725: if (ref($moves) eq 'HASH') {
2726: if (ref($moves->{'copies'}) eq 'HASH') {
2727: %copies = %{$moves->{'copies'}};
2728: }
2729: if (ref($moves->{'docmoves'}) eq 'HASH') {
2730: %docmoves = %{$moves->{'docmoves'}};
2731: }
2732: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2733: %mapmoves = %{$moves->{'mapmoves'}};
2734: }
2735: }
2736: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2737: my @allcopies;
1.529 raeburn 2738: if (exists($copies{$key})) {
2739: if (ref($copies{$key}) eq 'HASH') {
2740: my %added;
2741: foreach my $innerkey (keys(%{$copies{$key}})) {
2742: if (($innerkey ne '') && (!$added{$innerkey})) {
2743: push(@allcopies,$innerkey);
2744: $added{$innerkey} = 1;
2745: }
1.491 raeburn 2746: }
1.529 raeburn 2747: undef(%added);
1.491 raeburn 2748: }
2749: }
2750: if ($key eq $oldurl) {
1.529 raeburn 2751: if ((exists($docmoves{$key}))) {
1.532 raeburn 2752: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2753: push(@allcopies,$oldurl);
2754: }
2755: }
2756: }
2757: if (@allcopies > 0) {
2758: foreach my $item (@allcopies) {
1.492 raeburn 2759: my ($relpath,$oldsubdir,$fname) =
2760: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2761: if ($fname ne '') {
2762: my $content = &Apache::lonnet::getfile($item);
2763: unless ($content eq '-1') {
2764: my $storefn;
1.529 raeburn 2765: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2766: $storefn = $docmoves{$key};
1.491 raeburn 2767: } else {
2768: $storefn = $relpath;
2769: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2770: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2771: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2772: }
1.529 raeburn 2773: if ($newsubdir{$key}) {
1.532 raeburn 2774: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2775: }
2776: }
2777: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2778: my $copyurl =
2779: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2780: $storefn.$fname,$content);
2781: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2782: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2783: return &mt('Paste failed: an error occurred copying the file.');
2784: } elsif (ref($errors) eq 'HASH') {
2785: $errors->{$item} = 1;
1.489 raeburn 2786: }
2787: }
1.488 raeburn 2788: }
2789: }
1.491 raeburn 2790: }
2791: }
2792: }
1.529 raeburn 2793: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2794: my $storefn=$key;
2795: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2796: if ($prefixchg && $before{'map'} && $after{'map'}) {
2797: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2798: }
1.529 raeburn 2799: if ($newsubdir{$key}) {
2800: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2801: }
1.491 raeburn 2802: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 ! raeburn 2803: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
! 2804: ($after{'map'} eq 'default') &&
! 2805: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
! 2806: $mapcontent = '<map>'."\n".
! 2807: '<resource id="1" src="" type="start" />'."\n".
! 2808: '<link from="1" to="2" index="1" />'."\n".
! 2809: '<resource id="2" src="" type="finish" />'."\n".
! 2810: '</map>';
! 2811: }
1.491 raeburn 2812: if ($mapcontent eq '-1') {
2813: if (ref($errors) eq 'HASH') {
2814: $errors->{$key} = 1;
2815: }
2816: } else {
2817: my $newmap =
2818: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2819: $mapcontent);
2820: if ($newmap eq '/adm/notfound.html') {
2821: if (ref($errors) eq 'HASH') {
2822: $errors->{$key} = 1;
1.489 raeburn 2823: }
1.488 raeburn 2824: }
2825: }
2826: }
1.491 raeburn 2827: my %updates;
2828: if ($is_map) {
1.529 raeburn 2829: if (ref($updated) eq 'HASH') {
2830: foreach my $type (keys(%{$updated})) {
2831: if (ref($updated->{$type}) eq 'HASH') {
2832: foreach my $key (keys(%{$updated->{$type}})) {
2833: $updates{$key} = 1;
2834: }
2835: }
2836: }
1.491 raeburn 2837: }
2838: foreach my $key (keys(%updates)) {
1.492 raeburn 2839: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2840: if (ref($rewrites{$key}) eq 'HASH') {
2841: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2842: }
1.529 raeburn 2843: if (ref($retitles{$key}) eq 'HASH') {
2844: %toretitle = %{$retitles{$key}};
1.491 raeburn 2845: }
1.529 raeburn 2846: if (ref($removefrommap{$key}) eq 'HASH') {
2847: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2848: }
1.529 raeburn 2849: if (ref($removeparam{$key}) eq 'HASH') {
2850: %remparam = %{$removeparam{$key}};
1.492 raeburn 2851: }
1.529 raeburn 2852: if (ref($zombies{$key}) eq 'HASH') {
2853: %zombie = %{$zombies{$key}};
1.491 raeburn 2854: }
1.529 raeburn 2855: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2856: foreach my $idx (keys(%{$dbcopies{$key}})) {
2857: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2858: my ($newurl,$result,$errtext) =
2859: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2860: if ($result eq 'ok') {
2861: $newdb{$idx} = $newurl;
2862: } elsif (ref($errors) eq 'HASH') {
2863: $errors->{$key} = 1;
2864: }
2865: push(@msgs,$errtext);
2866: }
1.491 raeburn 2867: }
2868: }
1.597 raeburn 2869: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 2870: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 2871: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2872: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2873: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2874: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2875: my $template = $1;
2876: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2877: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2878: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2879: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 2880: unless ($gotnewmapname) {
2881: ($newmapname) = ($key =~ m{/([^/]+)$});
2882: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2883: if ($newsubdir{$key}) {
2884: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2885: }
2886: $gotnewmapname = 1;
2887: }
1.597 raeburn 2888: my $srcmapinfo = $srcfolder.':'.$idx;
2889: if ($srccontainer eq 'page') {
2890: $srcmapinfo .= ':1';
2891: }
2892: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2893: $cnum,$template,$idx,$newmapname);
2894: }
2895: }
2896: }
2897: }
2898: }
1.529 raeburn 2899: if (ref($params{$key}) eq 'HASH') {
2900: %currparam = %{$params{$key}};
1.492 raeburn 2901: }
2902: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2903: if ($fatal) {
1.533 raeburn 2904: return ($errtext);
1.492 raeburn 2905: }
2906: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2907: if (defined($LONCAPA::map::zombies[$i])) {
2908: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2909: if ($zombie{$i} eq $src) {
1.492 raeburn 2910: undef($LONCAPA::map::zombies[$i]);
2911: }
2912: }
2913: }
1.646 raeburn 2914: my $total = scalar(@LONCAPA::map::order) - 1;
2915: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 2916: my $idx = $LONCAPA::map::order[$i];
2917: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2918: my $changed;
1.529 raeburn 2919: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2920: if ((exists($toremove{$idx})) &&
2921: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2922: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2923: if (ref($currparam{$idx}) eq 'ARRAY') {
2924: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 2925: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 2926: }
2927: }
2928: next;
2929: }
2930: my $origsrc = $src;
1.532 raeburn 2931: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2932: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2933: $changed = 1;
1.491 raeburn 2934: }
1.492 raeburn 2935: }
1.532 raeburn 2936: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2937: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2938: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2939: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2940: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2941: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2942: } else {
1.529 raeburn 2943: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2944: }
1.491 raeburn 2945: }
1.532 raeburn 2946: if ($origsrc =~ /\.(page|sequence)$/) {
2947: if ($newsubdir{$origsrc}) {
1.529 raeburn 2948: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2949: }
1.532 raeburn 2950: } elsif ($newsubdir{$key}) {
2951: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2952: }
2953: }
1.492 raeburn 2954: $changed = 1;
1.533 raeburn 2955: } elsif ($newdb{$idx} ne '') {
2956: $src = $newdb{$idx};
1.492 raeburn 2957: $changed = 1;
2958: }
2959: if ($changed) {
1.538 raeburn 2960: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2961: }
2962: }
2963: }
2964: foreach my $idx (keys(%remparam)) {
2965: if (ref($remparam{$idx}) eq 'ARRAY') {
2966: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 2967: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 2968: }
2969: }
2970: }
1.533 raeburn 2971: if (values(%lockerrors) > 0) {
2972: $lockmsg = join('<br />',values(%lockerrors));
2973: }
1.491 raeburn 2974: my $storefn;
2975: if ($key eq $oldurl) {
2976: $storefn = $url;
2977: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2978: } else {
2979: $storefn = $key;
2980: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2981: if ($prefixchg && $before{'map'} && $after{'map'}) {
2982: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2983: }
1.529 raeburn 2984: if ($newsubdir{$key}) {
2985: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2986: }
1.491 raeburn 2987: }
1.492 raeburn 2988: my $report;
2989: if ($folder !~ /^supplemental/) {
2990: $report = 1;
2991: }
1.527 raeburn 2992: (my $outtext,$errtext) =
1.492 raeburn 2993: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2994: if ($errtext) {
1.529 raeburn 2995: if ($caller eq 'paste') {
1.533 raeburn 2996: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2997: }
1.491 raeburn 2998: }
2999: }
3000: }
1.533 raeburn 3001: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 3002: }
3003:
3004: sub copy_dependencies {
3005: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3006: my $content;
3007: if (ref($contentref)) {
3008: $content = $$contentref;
3009: } else {
3010: $content = &Apache::lonnet::getfile($item);
3011: }
3012: unless ($content eq '-1') {
3013: my $mm = new File::MMagic;
3014: my $mimetype = $mm->checktype_contents($content);
3015: if ($mimetype eq 'text/html') {
3016: my (%allfiles,%codebase,$state);
3017: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3018: if ($res eq 'ok') {
3019: my ($numexisting,$numpathchanges,$existing);
3020: (undef,$numexisting,$numpathchanges,$existing) =
3021: &Apache::loncommon::ask_for_embedded_content(
3022: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3023: {'error_on_invalid_names' => 1,
3024: 'ignore_remote_references' => 1,
3025: 'docs_url' => $item,
3026: 'context' => 'paste'});
3027: if ($numexisting > 0) {
3028: if (ref($existing) eq 'HASH') {
3029: foreach my $dep (keys(%{$existing})) {
3030: my $depfile = $dep;
3031: unless ($depfile =~ m{^\Q$relpath\E}) {
3032: $depfile = $relpath.$dep;
3033: }
3034: my $depcontent = &Apache::lonnet::getfile($depfile);
3035: unless ($depcontent eq '-1') {
3036: my $storedep = $dep;
3037: $storedep =~ s{^\Q$relpath\E}{};
3038: my $dep_url =
3039: &Apache::lonclonecourse::writefile(
3040: $env{'request.course.id'},
3041: $storefn.$storedep,$depcontent);
3042: if ($dep_url eq '/adm/notfound.html') {
3043: if (ref($errors) eq 'HASH') {
3044: $errors->{$depfile} = 1;
3045: }
3046: } else {
3047: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3048: }
3049: }
3050: }
1.488 raeburn 3051: }
3052: }
3053: }
3054: }
3055: }
3056: return;
3057: }
3058:
1.329 droeschl 3059: my %parameter_type = ( 'randompick' => 'int_pos',
3060: 'hiddenresource' => 'string_yesno',
3061: 'encrypturl' => 'string_yesno',
3062: 'randomorder' => 'string_yesno',);
3063: my $valid_parameters_re = join('|',keys(%parameter_type));
3064: # set parameters
3065: sub update_parameter {
1.537 raeburn 3066: if ($env{'form.changeparms'} eq 'all') {
3067: my (@allidx,@allmapidx,%allchecked,%currchecked);
3068: %allchecked = (
3069: 'hiddenresource' => {},
3070: 'encrypturl' => {},
3071: 'randompick' => {},
3072: 'randomorder' => {},
3073: );
3074: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3075: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3076: if ($which eq 'randompick') {
3077: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3078: my ($res,$value) = split(/:/,$item);
3079: if ($value =~ /^\d+$/) {
3080: $allchecked{$which}{$res} = $value;
3081: }
3082: }
3083: } else {
1.539 raeburn 3084: if ($env{'form.all'.$which}) {
3085: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3086: }
1.537 raeburn 3087: }
3088: }
3089: my $haschanges = 0;
3090: foreach my $res (@LONCAPA::map::order) {
3091: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3092: $name=&LONCAPA::map::qtescape($name);
3093: $url=&LONCAPA::map::qtescape($url);
3094: next unless ($name && $url);
3095: my $is_map;
3096: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3097: $is_map = 1;
3098: }
3099: foreach my $which (keys(%allchecked)) {
3100: if (($which eq 'randompick' || $which eq 'randomorder')) {
3101: next if (!$is_map);
3102: }
3103: my $oldvalue = 0;
3104: my $newvalue = 0;
3105: if ($allchecked{$which}{$res}) {
3106: $newvalue = $allchecked{$which}{$res};
3107: }
3108: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3109: if ($which eq 'randompick') {
3110: if ($current =~ /^(\d+)$/) {
3111: $oldvalue = $1;
3112: }
3113: } else {
3114: if ($current =~ /^yes$/i) {
3115: $oldvalue = 1;
3116: }
3117: }
3118: if ($oldvalue ne $newvalue) {
3119: $haschanges = 1;
3120: if ($newvalue) {
3121: my $storeval = 'yes';
3122: if ($which eq 'randompick') {
3123: $storeval = $newvalue;
3124: }
3125: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3126: $storeval,
3127: $parameter_type{$which});
3128: &remember_parms($res,$which,'set',$storeval);
3129: } elsif ($oldvalue) {
3130: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3131: &remember_parms($res,$which,'del');
3132: }
3133: }
3134: }
3135: }
3136: return $haschanges;
3137: } else {
1.588 raeburn 3138: my $haschanges = 0;
3139: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3140:
1.537 raeburn 3141: my $which = $env{'form.changeparms'};
3142: my $idx = $env{'form.setparms'};
1.588 raeburn 3143: my $oldvalue = 0;
3144: my $newvalue = 0;
3145: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3146: if ($which eq 'randompick') {
3147: if ($current =~ /^(\d+)$/) {
3148: $oldvalue = $1;
3149: }
3150: } elsif ($current =~ /^yes$/i) {
3151: $oldvalue = 1;
3152: }
1.537 raeburn 3153: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3154: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3155: : 1;
3156: }
3157: if ($oldvalue ne $newvalue) {
3158: $haschanges = 1;
3159: if ($newvalue) {
3160: my $storeval = 'yes';
3161: if ($which eq 'randompick') {
3162: $storeval = $newvalue;
3163: }
3164: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3165: $parameter_type{$which});
3166: &remember_parms($idx,$which,'set',$storeval);
3167: } else {
3168: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3169: &remember_parms($idx,$which,'del');
3170: }
1.537 raeburn 3171: }
1.588 raeburn 3172: return $haschanges;
1.329 droeschl 3173: }
3174: }
3175:
3176: sub handle_edit_cmd {
3177: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3178: my $haschanges = 0;
1.543 raeburn 3179: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3180: return $haschanges;
1.543 raeburn 3181: }
1.329 droeschl 3182: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3183:
3184: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3185: my ($title, $url, @rrest) = split(':', $ratstr);
3186:
1.538 raeburn 3187: if ($cmd eq 'remove') {
1.329 droeschl 3188: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3189: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3190: &Apache::lonnet::removeuploadedurl($url);
3191: } else {
3192: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3193: }
3194: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3195: $haschanges = 1;
1.329 droeschl 3196: } elsif ($cmd eq 'cut') {
3197: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3198: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3199: $haschanges = 1;
1.344 bisitz 3200: } elsif ($cmd eq 'up'
1.329 droeschl 3201: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3202: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3203: $haschanges = 1;
1.329 droeschl 3204: } elsif ($cmd eq 'down'
3205: && defined($LONCAPA::map::order[$idx+1])) {
3206: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3207: $haschanges = 1;
1.329 droeschl 3208: } elsif ($cmd eq 'rename') {
3209: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3210: if ($comment=~/\S/) {
3211: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3212: $comment.':'.join(':', $url, @rrest);
3213: }
3214: # Devalidate title cache
3215: my $renamed_url=&LONCAPA::map::qtescape($url);
3216: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3217: $haschanges = 1;
3218: } elsif ($cmd eq 'setalias') {
3219: my $newvalue = $env{'form.alias'};
3220: if ($newvalue ne '') {
3221: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3222: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3223: 'string');
3224: &remember_parms($idx,'mapalias','set',$newvalue);
3225: $haschanges = 1;
3226: }
3227: }
3228: } elsif ($cmd eq 'delalias') {
3229: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3230: if ($current ne '') {
3231: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3232: &remember_parms($idx,'mapalias','del');
3233: $haschanges = 1;
3234: }
1.329 droeschl 3235: }
1.633 raeburn 3236: return $haschanges;
1.329 droeschl 3237: }
3238:
3239: sub editor {
1.458 raeburn 3240: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3241: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3242: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3243: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3244: if ($allowed) {
1.519 raeburn 3245: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3246: $is_random_order,$container) =
1.510 raeburn 3247: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3248: $r->print($breadcrumbtrail);
1.519 raeburn 3249: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3250: $container = 'page';
3251: } else {
3252: $container = 'sequence';
1.510 raeburn 3253: }
1.484 raeburn 3254:
1.525 raeburn 3255: my $jumpto;
3256:
3257: unless ($supplementalflag) {
1.546 raeburn 3258: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3259: }
1.484 raeburn 3260:
3261: unless ($allowed) {
3262: $randompick = -1;
3263: }
3264:
1.615 raeburn 3265: my ($errtext,$fatal);
3266: if (($folder eq '') && (!$supplementalflag)) {
3267: if (@LONCAPA::map::order) {
3268: undef(@LONCAPA::map::order);
3269: undef(@LONCAPA::map::resources);
3270: undef(@LONCAPA::map::resparms);
3271: undef(@LONCAPA::map::zombies);
3272: }
3273: $folder = 'default';
3274: $container = 'sequence';
3275: } else {
3276: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3277: $folder.'.'.$container);
3278: return $errtext if ($fatal);
3279: }
1.329 droeschl 3280:
3281: if ($#LONCAPA::map::order<1) {
3282: my $idx=&LONCAPA::map::getresidx();
3283: if ($idx<=0) { $idx=1; }
3284: $LONCAPA::map::order[0]=$idx;
3285: $LONCAPA::map::resources[$idx]='';
3286: }
1.364 bisitz 3287:
1.329 droeschl 3288: # ------------------------------------------------------------ Process commands
3289:
3290: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3291: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3292: # set parameters and change order
3293: &snapshotbefore();
3294:
3295: if (&update_parameter()) {
1.588 raeburn 3296: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3297: return $errtext if ($fatal);
3298: }
3299:
3300: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3301: # change order
3302: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3303: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3304:
3305: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3306: return $errtext if ($fatal);
3307: }
1.364 bisitz 3308:
1.329 droeschl 3309: if ($env{'form.pastemarked'}) {
1.491 raeburn 3310: my %paste_errors;
1.533 raeburn 3311: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3312: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3313: \%paste_errors);
1.541 raeburn 3314: if (ref($pastemsgarray) eq 'ARRAY') {
3315: if (@{$pastemsgarray} > 0) {
3316: $r->print('<p class="LC_info">'.
3317: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3318: '</p>');
3319: }
1.541 raeburn 3320: }
3321: if ($lockerror) {
3322: $r->print('<p class="LC_error">'.
3323: $lockerror.
3324: '</p>');
3325: }
3326: if ($save_error ne '') {
3327: return $save_error;
3328: }
3329: if ($paste_res) {
3330: my %errortext = &Apache::lonlocal::texthash (
3331: fail => 'Storage of folder contents failed',
3332: failread => 'Reading folder contents failed',
3333: failstore => 'Storage of folder contents failed',
3334: );
3335: if ($errortext{$paste_res}) {
3336: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3337: }
1.329 droeschl 3338: }
1.491 raeburn 3339: if (keys(%paste_errors) > 0) {
1.538 raeburn 3340: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3341: &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".
3342: '<ul>'."\n");
3343: foreach my $key (sort(keys(%paste_errors))) {
3344: $r->print('<li>'.$key.'</li>'."\n");
3345: }
3346: $r->print('</ul></p>'."\n");
3347: }
1.538 raeburn 3348: } elsif ($env{'form.clearmarked'}) {
3349: my $output = &do_buffer_empty();
3350: if ($output) {
3351: $r->print('<p class="LC_info">'.$output.'</p>');
3352: }
3353: }
1.329 droeschl 3354:
3355: $r->print($upload_output);
3356:
1.538 raeburn 3357: # Rename, cut, copy or remove a single resource
1.602 raeburn 3358: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3359: my $contentchg;
1.633 raeburn 3360: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3361: $contentchg = 1;
3362: }
3363: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3364: return $errtext if ($fatal);
3365: }
1.538 raeburn 3366:
3367: # Cut, copy and/or remove multiple resources
3368: if ($env{'form.multichange'}) {
3369: my %allchecked = (
3370: cut => {},
3371: remove => {},
3372: );
3373: my $needsupdate;
3374: foreach my $which (keys(%allchecked)) {
3375: $env{'form.multi'.$which} =~ s/,$//;
3376: if ($env{'form.multi'.$which}) {
3377: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3378: if (ref($allchecked{$which}) eq 'HASH') {
3379: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3380: }
3381: }
3382: }
3383: if ($needsupdate) {
3384: my $haschanges = 0;
3385: my %curr_groups = &Apache::longroup::coursegroups();
3386: my $total = scalar(@LONCAPA::map::order) - 1;
3387: for (my $i=$total; $i>=0; $i--) {
3388: my $res = $LONCAPA::map::order[$i];
3389: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3390: $name=&LONCAPA::map::qtescape($name);
3391: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3392: next unless $url;
1.538 raeburn 3393: my %denied =
3394: &action_restrictions($coursenum,$coursedom,$url,
3395: $env{'form.folderpath'},\%curr_groups);
3396: foreach my $which (keys(%allchecked)) {
3397: next if ($denied{$which});
3398: next unless ($allchecked{$which}{$res});
3399: if ($which eq 'remove') {
3400: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3401: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3402: &Apache::lonnet::removeuploadedurl($url);
3403: } else {
3404: &LONCAPA::map::makezombie($res);
3405: }
3406: splice(@LONCAPA::map::order,$i,1);
3407: $haschanges ++;
3408: } elsif ($which eq 'cut') {
3409: &LONCAPA::map::makezombie($res);
3410: splice(@LONCAPA::map::order,$i,1);
3411: $haschanges ++;
3412: }
3413: }
3414: }
3415: if ($haschanges) {
3416: ($errtext,$fatal) =
3417: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3418: return $errtext if ($fatal);
3419: }
3420: }
3421: }
3422:
1.329 droeschl 3423: # Group import/search
3424: if ($env{'form.importdetail'}) {
3425: my @imports;
3426: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3427: if (defined($item)) {
3428: my ($name,$url,$residx)=
1.533 raeburn 3429: map { &unescape($_); } split(/\=/,$item);
3430: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3431: my ($suffix,$errortxt,$locknotfreed) =
3432: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3433: if ($locknotfreed) {
3434: $r->print($locknotfreed);
3435: }
3436: if ($suffix) {
3437: $url =~ s/_new\./_$suffix./;
3438: } else {
3439: return $errortxt;
3440: }
1.533 raeburn 3441: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3442: my $type = $1;
3443: my ($suffix,$errortxt,$locknotfreed) =
3444: &new_timebased_suffix($coursedom,$coursenum,$type);
3445: if ($locknotfreed) {
3446: $r->print($locknotfreed);
3447: }
3448: if ($suffix) {
3449: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3450: } else {
3451: return $errortxt;
3452: }
1.626 raeburn 3453: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3454: my ($suffix,$errortxt,$locknotfreed) =
3455: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3456: if ($locknotfreed) {
3457: $r->print($locknotfreed);
3458: }
3459: if ($suffix) {
3460: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3461: } else {
3462: return $errortxt;
3463: }
1.534 raeburn 3464: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3465: if ($supplementalflag) {
3466: next unless ($1 eq 'supplemental');
3467: if ($folder eq 'supplemental') {
3468: next unless ($2 eq 'default');
3469: } else {
3470: next unless ($folder eq 'supplemental_'.$2);
3471: }
3472: } else {
3473: next unless ($1 eq 'docs');
3474: if ($folder eq 'default') {
3475: next unless ($2 eq 'default');
3476: } else {
3477: next unless ($folder eq 'default_'.$2);
3478: }
3479: }
1.504 raeburn 3480: }
1.329 droeschl 3481: push(@imports, [$name, $url, $residx]);
3482: }
3483: }
1.530 raeburn 3484: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3485: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3486: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3487: return $errtext if ($fatal);
1.529 raeburn 3488: if ($fixuperrors) {
3489: $r->print($fixuperrors);
3490: }
1.329 droeschl 3491: }
3492: # Loading a complete map
3493: if ($env{'form.loadmap'}) {
3494: if ($env{'form.importmap'}=~/\w/) {
3495: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3496: my ($title,$url,$ext,$type)=split(/\:/,$res);
3497: my $idx=&LONCAPA::map::getresidx($url);
3498: $LONCAPA::map::resources[$idx]=$res;
3499: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3500: }
3501: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3502: $folder.'.'.$container,1);
1.329 droeschl 3503: return $errtext if ($fatal);
3504: } else {
3505: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3506:
1.329 droeschl 3507: }
3508: }
3509: &log_differences($plain);
3510: }
3511: # ---------------------------------------------------------------- End commands
3512: # ---------------------------------------------------------------- Print screen
3513: my $idx=0;
3514: my $shown=0;
3515: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3516: $r->print('<div class="LC_Box">'.
1.432 raeburn 3517: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3518: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3519: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3520: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3521: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3522: '</ol>');
1.381 bisitz 3523: if ($randompick>=0) {
3524: $r->print('<p class="LC_warning">'
3525: .&mt('Caution: this folder is set to randomly pick a subset'
3526: .' of resources. Adding or removing resources from this'
3527: .' folder will change the set of resources that the'
3528: .' students see, resulting in spurious or missing credit'
3529: .' for completed problems, not limited to ones you'
3530: .' modify. Do not modify the contents of this folder if'
3531: .' it is in active student use.')
3532: .'</p>'
3533: );
3534: }
3535: if ($is_random_order) {
3536: $r->print('<p class="LC_warning">'
3537: .&mt('Caution: this folder is set to randomly order its'
3538: .' contents. Adding or removing resources from this folder'
3539: .' will change the order of resources shown.')
3540: .'</p>'
3541: );
3542: }
3543: $r->print('</div>');
1.364 bisitz 3544: }
1.381 bisitz 3545:
1.538 raeburn 3546: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3547: %filters = (
1.543 raeburn 3548: canremove => [],
3549: cancut => [],
3550: cancopy => [],
3551: hiddenresource => [],
3552: encrypturl => [],
3553: randomorder => [],
3554: randompick => [],
1.538 raeburn 3555: );
3556: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3557: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3558: foreach my $res (@LONCAPA::map::order) {
3559: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3560: $name=&LONCAPA::map::qtescape($name);
3561: $url=&LONCAPA::map::qtescape($url);
3562: unless ($name) { $name=(split(/\//,$url))[-1]; }
3563: unless ($name) { $idx++; next; }
1.537 raeburn 3564: push(@allidx,$res);
3565: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3566: push(@allmapidx,$res);
3567: }
1.617 raeburn 3568:
1.381 bisitz 3569: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3570: $coursenum,$coursedom,$crstype,
1.538 raeburn 3571: $pathitem,$supplementalflag,$container,
1.620 raeburn 3572: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622 raeburn 3573: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3574: $idx++;
3575: $shown++;
1.329 droeschl 3576: }
1.424 onken 3577: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3578:
1.538 raeburn 3579: my $need_save;
1.611 raeburn 3580: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3581: my $toolslink;
1.611 raeburn 3582: if ($allowed) {
1.544 raeburn 3583: $toolslink = '<table><tr><td>'
1.520 raeburn 3584: .&Apache::loncommon::help_open_menu('Navigation Screen',
3585: 'Navigation_Screen',undef,'RAT')
3586: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3587: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3588: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3589: .'id="LC_content_toolbar_edittoplevel" '
3590: .'class="LC_toolbarItem" '
3591: .'title="'.&mt('Supplemental Content Editor').'">'
3592: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3593: }
1.510 raeburn 3594: if ($shown) {
3595: if ($allowed) {
3596: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3597: .&Apache::loncommon::start_data_table(undef,'contentlist')
3598: .&Apache::loncommon::start_data_table_header_row()
3599: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3600: .'<th colspan="3">'.&mt('Actions').'</th>'
1.538 raeburn 3601: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3602: if ($folder !~ /^supplemental/) {
1.633 raeburn 3603: $to_show .= '<th colspan="2">'.&mt('Settings').'</th>';
1.510 raeburn 3604: }
1.537 raeburn 3605: $to_show .= &Apache::loncommon::end_data_table_header_row();
3606: if ($folder !~ /^supplemental/) {
1.538 raeburn 3607: $lists{'canhide'} = join(',',@allidx);
3608: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3609: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3610: 'randomorder','randompick');
3611: foreach my $item (@possfilters) {
1.538 raeburn 3612: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3613: if (@{$filters{$item}} > 0) {
3614: $lists{$item} = join(',',@{$filters{$item}});
3615: }
1.538 raeburn 3616: }
3617: }
1.537 raeburn 3618: if (@allidx > 0) {
3619: my $path;
3620: if ($env{'form.folderpath'}) {
1.630 raeburn 3621: $path =
1.537 raeburn 3622: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3623: }
1.538 raeburn 3624: if (@allidx > 1) {
1.630 raeburn 3625: $to_show .=
1.538 raeburn 3626: &Apache::loncommon::continue_data_table_row().
3627: '<td colspan="2"> </td>'.
3628: '<td>'.
1.611 raeburn 3629: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3630: '</td>'.
1.633 raeburn 3631: '<td colspan="3"> </td>'.
3632: '<td colspan="2">'.
1.611 raeburn 3633: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3634: '</td>'.
3635: &Apache::loncommon::end_data_table_row();
3636: $need_save = 1;
3637: }
1.537 raeburn 3638: }
3639: }
3640: $to_show .= $output.' '
1.510 raeburn 3641: .&Apache::loncommon::end_data_table()
3642: .'<br style="line-height:2px;" />'
3643: .&Apache::loncommon::end_scrollbox();
3644: } else {
1.520 raeburn 3645: $to_show .= $toolslink
1.510 raeburn 3646: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3647: .$output.' '
3648: .&Apache::loncommon::end_data_table();
1.393 raeburn 3649: }
1.510 raeburn 3650: } else {
1.520 raeburn 3651: if (!$allowed) {
3652: $to_show .= $toolslink;
3653: }
1.615 raeburn 3654: my $noresmsg;
3655: if ($allowed && $hiddentop && !$supplementalflag) {
3656: $noresmsg = &mt('Main Content Hidden');
3657: } else {
3658: $noresmsg = &mt('Currently empty');
3659: }
1.510 raeburn 3660: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3661: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3662: .$noresmsg
1.510 raeburn 3663: .'</div>'
3664: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3665: }
3666: } else {
1.510 raeburn 3667: if ($shown) {
3668: $to_show = '<div>'
3669: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3670: .$output
3671: .&Apache::loncommon::end_data_table()
3672: .'</div>';
3673: } else {
3674: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3675: .&mt('Currently empty')
1.510 raeburn 3676: .'</div>'
3677: }
1.458 raeburn 3678: }
3679: my $tid = 1;
3680: if ($supplementalflag) {
3681: $tid = 2;
1.329 droeschl 3682: }
3683: if ($allowed) {
1.484 raeburn 3684: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3685: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3686: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3687: if ($canedit) {
3688: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3689: }
1.460 raeburn 3690: } else {
3691: $r->print($to_show);
1.329 droeschl 3692: }
3693: return;
3694: }
3695:
1.538 raeburn 3696: sub multiple_check_form {
1.611 raeburn 3697: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3698: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3699: my $disabled;
3700: unless ($canedit) {
3701: $disabled = 'disabled="disabled"';
3702: }
1.538 raeburn 3703: my $output =
3704: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3705: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3706: '<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>'.
3707: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3708: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3709: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3710: if ($caller eq 'settings') {
3711: $output .=
3712: '<table><tr>'.
3713: '<td class="LC_docs_entry_parameter">'.
3714: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3715: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3716: '</label></span></td>'.
3717: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3718: '<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 3719: '</span></td>'.
3720: '</tr>'."\n".
3721: '<tr>'.
3722: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3723: '<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 3724: '</label></span>'.
3725: '</td></tr></table>'."\n";
3726: } else {
3727: $output .=
3728: '<table><tr>'.
3729: '<td class="LC_docs_entry_parameter">'.
3730: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3731: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3732: '</label></span></td>'.
3733: '<td class="LC_docs_entry_parameter">'.
3734: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3735: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3736: '</label></span></td>'."\n".
3737: '<td class="LC_docs_entry_parameter">'.
3738: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3739: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3740: '</label></span></td>'.
3741: '</tr></table>'."\n";
3742: }
3743: $output .=
3744: '</fieldset>'.
3745: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3746: if ($caller eq 'settings') {
3747: $output .=
1.543 raeburn 3748: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3749: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3750: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3751: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3752: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3753: } elsif ($caller eq 'actions') {
3754: $output .=
3755: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3756: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3757: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3758: }
3759: $output .=
3760: '</form>'.
3761: '</div>';
3762: return $output;
3763: }
3764:
1.329 droeschl 3765: sub process_file_upload {
1.552 raeburn 3766: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3767: # upload a file, if present
1.552 raeburn 3768: my $filesize = length($env{'form.uploaddoc'});
3769: if (!$filesize) {
3770: $$upload_output = '<div class="LC_error">'.
3771: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3772: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3773: $filesize).'<br />'.
3774: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3775: '</div>';
3776: return;
3777: }
3778: my $quotatype = 'unofficial';
3779: if ($crstype eq 'Community') {
1.601 raeburn 3780: $quotatype = 'community';
3781: } elsif ($crstype eq 'Placement') {
3782: $quotatype = 'placement';
1.580 raeburn 3783: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3784: $quotatype = 'official';
1.573 raeburn 3785: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3786: $quotatype = 'textbook';
1.552 raeburn 3787: }
3788: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3789: $filesize = int($filesize/1000); #expressed in kb
3790: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3791: $env{'form.uploaddoc.filename'},$filesize,
3792: 'upload',$quotatype);
1.552 raeburn 3793: return if ($$upload_output);
3794: }
1.440 raeburn 3795: my ($parseaction,$showupload,$nextphase,$mimetype);
3796: if ($env{'form.parserflag'}) {
1.329 droeschl 3797: $parseaction = 'parse';
3798: }
3799: my $folder=$env{'form.folder'};
3800: if ($folder eq '') {
3801: $folder='default';
3802: }
3803: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3804: my $errtext='';
3805: my $fatal=0;
3806: my $container='sequence';
1.519 raeburn 3807: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3808: $container='page';
3809: }
3810: ($errtext,$fatal)=
1.534 raeburn 3811: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3812: if ($#LONCAPA::map::order<1) {
3813: $LONCAPA::map::order[0]=1;
3814: $LONCAPA::map::resources[1]='';
3815: }
3816: my $destination = 'docs/';
3817: if ($folder =~ /^supplemental/) {
3818: $destination = 'supplemental/';
3819: }
3820: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3821: $destination .= 'default/';
3822: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3823: $destination .= $2.'/';
3824: }
1.534 raeburn 3825: if ($fatal) {
3826: $$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>';
3827: return;
3828: }
1.440 raeburn 3829: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3830: my $newidx=&LONCAPA::map::getresidx();
3831: $destination .= $newidx;
1.439 raeburn 3832: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3833: $parseaction,$allfiles,
1.440 raeburn 3834: $codebase,undef,undef,undef,undef,
3835: undef,undef,\$mimetype);
3836: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3837: my $stored = $1;
3838: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3839: $stored.'</span>').'</p>';
3840: } else {
3841: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3842:
1.457 raeburn 3843: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3844: return;
3845: }
1.329 droeschl 3846: my $ext='false';
3847: if ($url=~m{^http://}) { $ext='true'; }
3848: $url = &LONCAPA::map::qtunescape($url);
3849: my $comment=$env{'form.comment'};
3850: $comment = &LONCAPA::map::qtunescape($comment);
3851: if ($folder=~/^supplemental/) {
3852: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3853: $env{'user.domain'}.'___&&&___'.$comment;
3854: }
3855:
3856: $LONCAPA::map::resources[$newidx]=
3857: $comment.':'.$url.':'.$ext.':normal:res';
3858: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3859: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3860: $folder.'.'.$container,1);
1.329 droeschl 3861: if ($fatal) {
1.457 raeburn 3862: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3863: return;
1.329 droeschl 3864: } else {
1.440 raeburn 3865: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3866: $$upload_output = $showupload;
1.384 raeburn 3867: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3868: if ($total_embedded > 0) {
1.440 raeburn 3869: my $uploadphase = 'upload_embedded';
3870: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3871: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3872: my ($embedded,$num) =
1.440 raeburn 3873: &Apache::loncommon::ask_for_embedded_content(
3874: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3875: if ($embedded) {
3876: if ($num) {
3877: $$upload_output .=
3878: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3879: $nextphase = $uploadphase;
3880: } else {
3881: $$upload_output .= $embedded;
3882: }
3883: } else {
3884: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3885: }
1.329 droeschl 3886: } else {
1.440 raeburn 3887: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3888: }
1.457 raeburn 3889: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3890: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3891: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3892: $nextphase = 'decompress_uploaded';
3893: my $position = scalar(@LONCAPA::map::order)-1;
3894: my $noextract = &return_to_editor();
3895: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3896: my %archiveitems = (
3897: folderpath => $env{'form.folderpath'},
3898: cmd => $nextphase,
3899: newidx => $newidx,
3900: position => $position,
3901: phase => $nextphase,
1.477 raeburn 3902: comment => $comment,
1.480 raeburn 3903: );
3904: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3905: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3906: $$upload_output = $showupload.
3907: &Apache::loncommon::decompress_form($mimetype,
3908: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3909: \%archiveitems,\@current);
1.329 droeschl 3910: }
3911: }
3912: }
1.440 raeburn 3913: return $nextphase;
1.329 droeschl 3914: }
3915:
1.480 raeburn 3916: sub get_dir_list {
3917: my ($url,$coursenum,$coursedom,$newidx) = @_;
3918: my ($destination,$dir_root) = &embedded_destination();
3919: my ($dirlistref,$listerror) =
3920: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3921: my @dir_lines;
3922: my $dirptr=16384;
3923: if (ref($dirlistref) eq 'ARRAY') {
3924: foreach my $dir_line (sort
3925: {
3926: my ($afile)=split('&',$a,2);
3927: my ($bfile)=split('&',$b,2);
3928: return (lc($afile) cmp lc($bfile));
3929: } (@{$dirlistref})) {
3930: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3931: $filename =~ s/\s+$//;
3932: next if ($filename =~ /^\.\.?$/);
3933: my $isdir = 0;
3934: if ($dirptr&$testdir) {
3935: $isdir = 1;
3936: }
3937: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3938: }
3939: }
3940: return @dir_lines;
3941: }
3942:
1.329 droeschl 3943: sub is_supplemental_title {
3944: my ($title) = @_;
3945: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3946: }
3947:
3948: # --------------------------------------------------------------- An entry line
3949:
3950: sub entryline {
1.501 raeburn 3951: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3952: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622 raeburn 3953: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581 raeburn 3954: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3955: if (&is_supplemental_title($title)) {
1.488 raeburn 3956: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3957: } else {
3958: $title=&HTML::Entities::encode($title,'"<>&\'');
3959: $renametitle=$title;
3960: $foldertitle=$title;
3961: }
3962:
1.611 raeburn 3963: my ($disabled,$readonly,$js_lt);
3964: unless ($canedit) {
3965: $disabled = 'disabled="disabled"';
3966: $readonly = 1;
3967: }
3968:
1.329 droeschl 3969: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3970:
1.329 droeschl 3971: $renametitle=~s/\\/\\\\/g;
3972: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3973: $renametitle=~s/"/%22/g;
1.581 raeburn 3974: $renametitle=~s/ /%20/g;
3975: $oldtitle = $renametitle;
1.576 raeburn 3976: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3977: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3978: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3979: # Edit commands
1.679 raeburn 3980: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 3981: if ($env{'form.folderpath'}) {
3982: $esc_path=&escape($env{'form.folderpath'});
3983: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3984: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3985: }
1.505 raeburn 3986: my $isexternal;
1.510 raeburn 3987: if ($residx) {
1.501 raeburn 3988: my $currurl = $url;
3989: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3990: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3991: $isexternal = 1;
3992: }
1.510 raeburn 3993: if (!$supplementalflag) {
3994: my $path = 'uploaded/'.
3995: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3996: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3997: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3998: $residx,
3999: &Apache::lonnet::declutter($currurl));
4000: }
1.501 raeburn 4001: }
1.538 raeburn 4002: my ($renamelink,%lt,$ishash);
4003: if (ref($filtersref) eq 'HASH') {
4004: $ishash = 1;
4005: }
4006:
1.329 droeschl 4007: if ($allowed) {
1.538 raeburn 4008: $form_start = '
4009: <form action="/adm/coursedocs" method="post">
4010: ';
4011: $form_common=(<<END);
4012: <input type="hidden" name="folderpath" value="$path" />
4013: <input type="hidden" name="symb" value="$symb" />
4014: END
4015: $form_param=(<<END);
4016: <input type="hidden" name="setparms" value="$orderidx" />
4017: <input type="hidden" name="changeparms" value="0" />
4018: END
4019: $form_end = '</form>';
4020:
1.329 droeschl 4021: my $incindex=$index+1;
4022: my $selectbox='';
1.471 raeburn 4023: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 4024: ((split(/\:/,
1.344 bisitz 4025: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4026: ne '') &&
1.329 droeschl 4027: ((split(/\:/,
1.344 bisitz 4028: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 4029: ne '')) {
4030: $selectbox=
4031: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 4032: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 4033: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4034: if ($i==$incindex) {
1.358 bisitz 4035: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 4036: } else {
4037: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4038: }
4039: }
4040: $selectbox.='</select>';
4041: }
1.501 raeburn 4042: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 4043: 'up' => 'Move Up',
4044: 'dw' => 'Move Down',
4045: 'rm' => 'Remove',
4046: 'ct' => 'Cut',
4047: 'rn' => 'Rename',
1.501 raeburn 4048: 'cp' => 'Copy',
1.633 raeburn 4049: 'da' => 'Unset alias',
4050: 'sa' => 'Set alias',
1.501 raeburn 4051: 'ex' => 'External Resource',
1.598 raeburn 4052: 'et' => 'External Tool',
1.501 raeburn 4053: 'ed' => 'Edit',
4054: 'pr' => 'Preview',
4055: 'sv' => 'Save',
4056: 'ul' => 'URL',
1.611 raeburn 4057: 'ti' => 'Title',
1.618 raeburn 4058: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 4059: );
1.538 raeburn 4060: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4061: $env{'form.folderpath'},
4062: $currgroups);
1.517 raeburn 4063: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4064: my $skip_confirm = 0;
1.603 raeburn 4065: my $confirm_removal = 0;
1.329 droeschl 4066: if ( $folder =~ /^supplemental/
4067: || ($url =~ m{( /smppg$
4068: |/syllabus$
4069: |/aboutme$
4070: |/navmaps$
4071: |/bulletinboard$
1.626 raeburn 4072: |/ext\.tool$
1.505 raeburn 4073: |\.html$)}x)
4074: || $isexternal) {
1.329 droeschl 4075: $skip_confirm = 1;
4076: }
1.603 raeburn 4077: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4078: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4079: $confirm_removal = 1;
4080: }
1.633 raeburn 4081: if ($url =~ /$LONCAPA::assess_re/) {
4082: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4083: }
1.329 droeschl 4084:
1.538 raeburn 4085: if ($denied{'copy'}) {
1.543 raeburn 4086: $copylink=(<<ENDCOPY)
1.507 raeburn 4087: <span style="visibility: hidden;">$lt{'cp'}</span>
4088: ENDCOPY
4089: } else {
1.538 raeburn 4090: my $formname = 'edit_copy_'.$orderidx;
4091: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4092: $copylink=(<<ENDCOPY);
1.538 raeburn 4093: <form name="$formname" method="post" action="/adm/coursedocs">
4094: $form_common
1.611 raeburn 4095: <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 4096: $form_end
1.329 droeschl 4097: ENDCOPY
1.538 raeburn 4098: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4099: push(@{$filtersref->{'cancopy'}},$orderidx);
4100: }
1.329 droeschl 4101: }
1.538 raeburn 4102: if ($denied{'cut'}) {
1.507 raeburn 4103: $cutlink=(<<ENDCUT);
4104: <span style="visibility: hidden;">$lt{'ct'}</span>
4105: ENDCUT
4106: } else {
1.538 raeburn 4107: my $formname = 'edit_cut_'.$orderidx;
4108: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4109: $cutlink=(<<ENDCUT);
1.538 raeburn 4110: <form name="$formname" method="post" action="/adm/coursedocs">
4111: $form_common
1.542 raeburn 4112: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4113: <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 4114: $form_end
1.329 droeschl 4115: ENDCUT
1.538 raeburn 4116: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4117: push(@{$filtersref->{'cancut'}},$orderidx);
4118: }
1.329 droeschl 4119: }
1.538 raeburn 4120: if ($denied{'remove'}) {
1.507 raeburn 4121: $removelink=(<<ENDREM);
4122: <span style="visibility: hidden;">$lt{'rm'}</a>
4123: ENDREM
4124: } else {
1.538 raeburn 4125: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4126: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4127: $removelink=(<<ENDREM);
1.538 raeburn 4128: <form name="$formname" method="post" action="/adm/coursedocs">
4129: $form_common
1.542 raeburn 4130: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4131: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4132: <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 4133: $form_end
1.497 raeburn 4134: ENDREM
1.538 raeburn 4135: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4136: push(@{$filtersref->{'canremove'}},$orderidx);
4137: }
1.497 raeburn 4138: }
1.551 raeburn 4139: $renamelink=(<<ENDREN);
1.581 raeburn 4140: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4141: ENDREN
1.611 raeburn 4142: my ($uplink,$downlink);
4143: if ($canedit) {
4144: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4145: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4146: } else {
4147: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4148: $downlink = $uplink;
4149: }
1.329 droeschl 4150: $line.=(<<END);
4151: <td>
1.379 bisitz 4152: <div class="LC_docs_entry_move">
1.611 raeburn 4153: <a href="$uplink">
1.501 raeburn 4154: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4155: </a>
4156: </div>
4157: <div class="LC_docs_entry_move">
1.611 raeburn 4158: <a href="$downlink">
1.501 raeburn 4159: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4160: </a>
4161: </div>
1.329 droeschl 4162: </td>
4163: <td>
4164: $form_start
1.538 raeburn 4165: $form_param
1.478 raeburn 4166: $form_common
1.329 droeschl 4167: $selectbox
4168: $form_end
4169: </td>
1.540 raeburn 4170: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4171: $removelink
1.329 droeschl 4172: $cutlink
4173: $copylink
4174: </td>
4175: END
4176: }
4177: # Figure out what kind of a resource this is
4178: my ($extension)=($url=~/\.(\w+)$/);
4179: my $uploaded=($url=~/^\/*uploaded\//);
4180: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4181: my $isfolder;
4182: my $ispage;
4183: my $containerarg;
1.615 raeburn 4184: my $folderurl;
1.329 droeschl 4185: if ($uploaded) {
1.472 raeburn 4186: if (($extension eq 'sequence') || ($extension eq 'page')) {
4187: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4188: $containerarg = $1;
1.472 raeburn 4189: if ($extension eq 'sequence') {
4190: $icon=$iconpath.'navmap.folder.closed.gif';
4191: $isfolder=1;
4192: } else {
4193: $icon=$iconpath.'page.gif';
4194: $ispage=1;
4195: }
1.615 raeburn 4196: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4197: if ($allowed) {
4198: $url='/adm/coursedocs?';
4199: } else {
4200: $url='/adm/supplemental?';
4201: }
1.329 droeschl 4202: } else {
4203: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4204: }
4205: }
1.364 bisitz 4206:
1.621 raeburn 4207: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4208: my $orig_url = $url;
1.340 raeburn 4209: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 4210: if ($container eq 'page') {
4211: $url=~s{^http(|s)(:|:)//}{/ext/};
4212: } else {
4213: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4214: }
1.501 raeburn 4215: if (!$supplementalflag && $residx && $symb) {
4216: if ((!$isfolder) && (!$ispage)) {
4217: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 4218: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4219: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4220: } else {
4221: $url=&Apache::lonnet::clutter($url);
4222: }
1.501 raeburn 4223: if ($url=~/^\/*uploaded\//) {
4224: $url=~/\.(\w+)$/;
4225: my $embstyle=&Apache::loncommon::fileembstyle($1);
4226: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4227: $url='/adm/wrapper'.$url;
4228: } elsif ($embstyle eq 'ssi') {
4229: #do nothing with these
4230: } elsif ($url!~/\.(sequence|page)$/) {
4231: $url='/adm/coursedocs/showdoc'.$url;
4232: }
1.623 raeburn 4233: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4234: my $wrapped = $1;
4235: my $exturl = $2;
1.668 raeburn 4236: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 4237: $url='/adm/wrapper'.$url;
4238: }
4239: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4240: $nomodal = 1;
4241: }
1.626 raeburn 4242: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4243: $url='/adm/wrapper'.$url;
1.621 raeburn 4244: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4245: if (($ENV{'SERVER_PORT'} == 443) &&
4246: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4247: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4248: $url .= '?usehttp=1';
4249: }
1.621 raeburn 4250: $nomodal = 1;
4251: }
1.598 raeburn 4252: }
1.680 raeburn 4253: my ($checkencrypt,$shownurl);
4254: if (!$env{'request.role.adv'}) {
1.615 raeburn 4255: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 4256: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 4257: $checkencrypt = 1;
1.620 raeburn 4258: } elsif (ref($navmapref)) {
1.615 raeburn 4259: unless (ref($$navmapref)) {
4260: $$navmapref = Apache::lonnavmaps::navmap->new();
4261: }
4262: if (ref($$navmapref)) {
4263: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 4264: $checkencrypt = 1;
1.615 raeburn 4265: }
4266: }
4267: }
1.680 raeburn 4268: }
4269: if ($checkencrypt) {
4270: my $currenc = $env{'request.enc'};
4271: $env{'request.enc'} = 1;
4272: $shownsymb = &Apache::lonenc::encrypted($symb);
4273: $shownurl = &Apache::lonenc::encrypted($url);
4274: if (&Apache::lonnet::symbverify($symb,$url)) {
4275: $url = $shownurl;
4276: } else {
4277: $url = '';
4278: }
4279: $env{'request.enc'} = $currenc;
4280: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4281: $shownsymb = $symb;
4282: if ($isexternal) {
4283: $url =~ s/\#[^#]+$//;
4284: if ($container eq 'page') {
4285: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 4286: }
1.612 raeburn 4287: }
1.680 raeburn 4288: $shownurl = $url;
4289: }
4290: unless ($env{'request.role.adv'}) {
4291: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4292: $url = '';
4293: }
4294: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4295: $url = '';
4296: $hiddenres = 1;
4297: }
4298: }
4299: if ($url ne '') {
4300: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 4301: }
1.329 droeschl 4302: }
1.621 raeburn 4303: } elsif ($supplementalflag) {
1.610 raeburn 4304: if ($isexternal) {
4305: if ($url =~ /^([^#]+)#([^#]+)$/) {
4306: $url = $1;
4307: $anchor = $2;
1.623 raeburn 4308: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 4309: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4310: if ($hostname ne '') {
4311: $url = 'http://'.$hostname.$url;
4312: }
4313: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 4314: }
4315: $nomodal = 1;
4316: }
1.610 raeburn 4317: }
1.621 raeburn 4318: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4319: if (($ENV{'SERVER_PORT'} == 443) &&
4320: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4321: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4322: if ($hostname ne '') {
4323: $url = 'http://'.$hostname.$url;
4324: }
4325: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 4326: }
1.621 raeburn 4327: $nomodal = 1;
4328: }
1.610 raeburn 4329: }
1.329 droeschl 4330: }
1.615 raeburn 4331: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4332: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4333: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4334: my $foldername=&escape($foldertitle);
4335: my $folderpath=$env{'form.folderpath'};
4336: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4337: if (!$allowed && $supplementalflag) {
1.519 raeburn 4338: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4339: $url.='folderpath='.&escape($folderpath);
4340: } else {
1.617 raeburn 4341: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4342: 'parameter_randompick'))[0];
4343: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4344: 'parameter_randomorder'))[0]=~/^yes$/i);
4345: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4346: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4347: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4348: 'parameter_encrypturl'))[0]=~/^yes$/i);
4349: unless ($hiddenmap) {
1.620 raeburn 4350: if (ref($navmapref)) {
4351: unless (ref($$navmapref)) {
4352: $$navmapref = Apache::lonnavmaps::navmap->new();
4353: }
4354: if (ref($$navmapref)) {
4355: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4356: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4357: unless (@resources) {
4358: $hiddenmap = 1;
4359: unless ($env{'request.role.adv'}) {
4360: $url = '';
4361: $hiddenfolder = 1;
4362: }
1.617 raeburn 4363: }
1.615 raeburn 4364: }
4365: }
4366: }
4367: }
1.617 raeburn 4368: unless ($encryptmap) {
1.620 raeburn 4369: if ((ref($navmapref)) && (ref($$navmapref))) {
4370: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4371: $encryptmap = 1;
4372: }
1.617 raeburn 4373: }
4374: }
1.630 raeburn 4375:
1.617 raeburn 4376: # Append randompick number, hidden, and encrypted with ":" to foldername,
4377: # so it gets transferred between levels
4378: $folderpath.=$containerarg.'&'.$foldername.
4379: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4380: unless ($url eq '') {
1.612 raeburn 4381: $url.='folderpath='.&escape($folderpath);
4382: }
1.510 raeburn 4383: my $rpckchk;
4384: if ($rpicknum) {
4385: $rpckchk = ' checked="checked"';
1.543 raeburn 4386: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4387: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4388: }
1.510 raeburn 4389: }
1.537 raeburn 4390: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4391: $rand_pick_text =
1.478 raeburn 4392: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4393: $form_param."\n".
1.478 raeburn 4394: $form_common."\n".
1.611 raeburn 4395: '<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 4396: if ($rpicknum ne '') {
4397: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4398: }
1.537 raeburn 4399: $rand_pick_text .= '</span></span>'.
4400: $form_end;
1.543 raeburn 4401: my $ro_set;
1.617 raeburn 4402: if ($randorder) {
1.543 raeburn 4403: $ro_set = 'checked="checked"';
4404: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4405: push(@{$filtersref->{'randomorder'}},$orderidx);
4406: }
4407: }
1.564 raeburn 4408: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4409: $rand_order_text =
1.537 raeburn 4410: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4411: $form_param."\n".
1.537 raeburn 4412: $form_common."\n".
1.611 raeburn 4413: '<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 4414: $form_end;
1.510 raeburn 4415: }
1.509 raeburn 4416: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4417: my $isexttool;
1.626 raeburn 4418: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4419: $url='/adm/wrapper'.$url;
4420: $isexttool = 1;
4421: }
1.510 raeburn 4422: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4423: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4424: if ($title) {
4425: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4426: }
1.598 raeburn 4427: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4428: $url .= '&idx='.$orderidx;
4429: }
1.610 raeburn 4430: if ($anchor ne '') {
4431: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4432: }
1.329 droeschl 4433: }
1.519 raeburn 4434: my ($tdalign,$tdwidth);
1.501 raeburn 4435: if ($allowed) {
1.630 raeburn 4436: my $fileloc =
1.501 raeburn 4437: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4438: if ($isexternal) {
1.630 raeburn 4439: ($editlink,$extresform) =
1.611 raeburn 4440: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4441: undef,undef,undef,undef,undef,undef,
4442: undef,$disabled);
1.626 raeburn 4443: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4444: ($editlink,$extresform) =
4445: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4446: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4447: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4448: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4449: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4450: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4451: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4452: my $suppanchor;
4453: if ($supplementalflag) {
4454: $suppanchor = $anchor;
4455: }
1.630 raeburn 4456: my $jscall =
1.501 raeburn 4457: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4458: $switchserver,
1.503 raeburn 4459: $forceedit,
1.679 raeburn 4460: undef,$symb,$shownsymb,
1.511 raeburn 4461: &escape($env{'form.folderpath'}),
1.622 raeburn 4462: $renametitle,$hostname,
4463: '','',1,$suppanchor);
1.501 raeburn 4464: if ($jscall) {
1.518 raeburn 4465: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4466: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4467: }
4468: }
4469: }
1.519 raeburn 4470: $tdalign = ' align="right" valign="top"';
4471: $tdwidth = ' width="80%"';
1.329 droeschl 4472: }
1.408 raeburn 4473: my $reinit;
4474: if ($crstype eq 'Community') {
4475: $reinit = &mt('(re-initialize community to access)');
4476: } else {
4477: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4478: }
4479: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.650 raeburn 4480: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 4481: $line.= '<br />';
4482: if ($curralias ne '') {
4483: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4484: $lt{'da'}.'</a></span>';
4485: } else {
4486: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4487: $lt{'sa'}.'</a></span>';
4488: }
4489: }
4490: $line.='</td><td>';
1.621 raeburn 4491: my $link;
1.472 raeburn 4492: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4493: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4494: } elsif ($url) {
1.610 raeburn 4495: if ($anchor ne '') {
4496: if ($supplementalflag) {
4497: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4498: } else {
4499: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4500: }
4501: }
1.622 raeburn 4502: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4503: $link = 'http://'.$hostname.$url;
4504: } else {
4505: $link = $url;
4506: }
1.659 raeburn 4507: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.621 raeburn 4508: if ($nomodal) {
4509: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4510: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4511: } else {
4512: $line.=&Apache::loncommon::modal_link($link,
4513: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4514: }
1.469 www 4515: } else {
4516: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4517: }
1.519 raeburn 4518: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4519: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4520: $line.='<a href="'.$url.'">'.$title.'</a>';
4521: } elsif ($url) {
1.621 raeburn 4522: if ($nomodal) {
4523: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4524: $title.'</a>';
4525: } else {
4526: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4527: }
1.617 raeburn 4528: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4529: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4530: } else {
4531: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4532: }
1.633 raeburn 4533: if (($allowed) && ($curralias ne '')) {
4534: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4535: } else {
4536: $line .= $extresform;
4537: }
4538: $line .= '</td>';
1.478 raeburn 4539: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4540: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4541: if (($allowed) && ($folder!~/^supplemental/)) {
4542: my %lt=&Apache::lonlocal::texthash(
4543: 'hd' => 'Hidden',
4544: 'ec' => 'URL hidden');
1.543 raeburn 4545: my ($enctext,$hidtext);
4546: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4547: $enctext = ' checked="checked"';
4548: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4549: push(@{$filtersref->{'encrypturl'}},$orderidx);
4550: }
4551: }
4552: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4553: $hidtext = ' checked="checked"';
4554: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4555: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4556: }
4557: }
1.537 raeburn 4558: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4559: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4560: $line.=(<<ENDPARMS);
4561: <td class="LC_docs_entry_parameter">
1.537 raeburn 4562: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4563: $form_param
1.478 raeburn 4564: $form_common
1.611 raeburn 4565: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4566: $form_end
1.458 raeburn 4567: <br />
1.537 raeburn 4568: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4569: $form_param
1.478 raeburn 4570: $form_common
1.611 raeburn 4571: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4572: $form_end
4573: </td>
1.478 raeburn 4574: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4575: $rand_order_text</td>
1.329 droeschl 4576: ENDPARMS
4577: }
1.379 bisitz 4578: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4579: return $line;
4580: }
4581:
1.538 raeburn 4582: sub action_restrictions {
4583: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4584: my %denied = (
4585: cut => 0,
4586: copy => 0,
4587: remove => 0,
4588: );
4589: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4590: # no copy for published maps
4591: $denied{'copy'} = 1;
1.597 raeburn 4592: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4593: unless ($1 eq 'simpleproblem') {
4594: $denied{'copy'} = 1;
4595: }
4596: $denied{'cut'} = 1;
1.538 raeburn 4597: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4598: if ($folderpath =~ /^default&[^\&]+$/) {
4599: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4600: $denied{'remove'} = 1;
4601: }
4602: $denied{'cut'} = 1;
4603: $denied{'copy'} = 1;
4604: }
4605: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4606: my $group = $1;
4607: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4608: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4609: $denied{'remove'} = 1;
4610: }
4611: }
4612: $denied{'cut'} = 1;
4613: $denied{'copy'} = 1;
4614: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4615: my $group = $1;
4616: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4617: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4618: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4619: if (keys(%groupsettings) > 0) {
4620: $denied{'remove'} = 1;
4621: }
4622: $denied{'cut'} = 1;
4623: $denied{'copy'} = 1;
4624: }
4625: }
4626: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4627: my $group = $1;
4628: if ($url =~ /group_boards_\Q$group\E/) {
4629: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4630: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4631: if (keys(%groupsettings) > 0) {
4632: if (ref($groupsettings{'functions'}) eq 'HASH') {
4633: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4634: $denied{'remove'} = 1;
4635: }
4636: }
4637: }
4638: $denied{'cut'} = 1;
4639: $denied{'copy'} = 1;
4640: }
4641: }
4642: }
4643: return %denied;
4644: }
4645:
1.533 raeburn 4646: sub new_timebased_suffix {
1.538 raeburn 4647: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4648: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4649: if ($type eq 'paste') {
4650: $prefix = $type;
4651: $namespace = 'courseeditor';
1.587 raeburn 4652: $idtype = 'addcode';
1.538 raeburn 4653: } elsif ($type eq 'map') {
1.533 raeburn 4654: $prefix = 'docs';
4655: if ($area eq 'supplemental') {
4656: $prefix = 'supp';
4657: }
4658: $prefix .= $container;
4659: $namespace = 'uploadedmaps';
4660: } else {
4661: $prefix = $type;
4662: $namespace = 'templated';
1.504 raeburn 4663: }
4664: my ($suffix,$freedlock,$error) =
1.587 raeburn 4665: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4666: if (!$suffix) {
1.538 raeburn 4667: if ($type eq 'paste') {
4668: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4669: } elsif ($type eq 'map') {
1.533 raeburn 4670: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4671: } elsif ($type eq 'smppg') {
4672: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4673: } elsif ($type eq 'exttool') {
4674: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4675: } else {
1.565 bisitz 4676: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4677: }
1.504 raeburn 4678: if ($error) {
4679: $errtext .= '<br />'.$error;
4680: }
4681: }
4682: if ($freedlock ne 'ok') {
1.630 raeburn 4683: $locknotfreed =
1.533 raeburn 4684: '<div class="LC_error">'.
4685: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4686: if ($type eq 'paste') {
1.591 raeburn 4687: if ($freedlock eq 'nolock') {
4688: $locknotfreed =
4689: '<div class="LC_error">'.
4690: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4691:
1.593 droeschl 4692: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4693: } else {
4694: $locknotfreed .=
4695: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4696: }
1.538 raeburn 4697: } elsif ($type eq 'map') {
1.591 raeburn 4698: $locknotfreed .=
4699: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4700: } elsif ($type eq 'smppg') {
4701: $locknotfreed .=
4702: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4703: } elsif ($type eq 'exttool') {
4704: $locknotfreed .=
4705: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4706: } else {
4707: $locknotfreed .=
1.565 bisitz 4708: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4709: }
1.538 raeburn 4710: unless ($type eq 'paste') {
4711: $locknotfreed .=
1.560 raeburn 4712: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4713: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4714: }
4715: $locknotfreed .= '</div>';
1.504 raeburn 4716: }
4717: return ($suffix,$errtext,$locknotfreed);
4718: }
4719:
1.329 droeschl 4720: =pod
4721:
4722: =item tiehash()
4723:
4724: tie the hash
4725:
4726: =cut
4727:
4728: sub tiehash {
4729: my ($mode)=@_;
4730: $hashtied=0;
4731: if ($env{'request.course.fn'}) {
4732: if ($mode eq 'write') {
4733: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4734: &GDBM_WRCREAT(),0640)) {
4735: $hashtied=2;
4736: }
4737: } else {
4738: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4739: &GDBM_READER(),0640)) {
4740: $hashtied=1;
4741: }
4742: }
1.364 bisitz 4743: }
1.329 droeschl 4744: }
4745:
4746: sub untiehash {
4747: if ($hashtied) { untie %hash; }
4748: $hashtied=0;
4749: return OK;
4750: }
4751:
4752:
4753:
4754:
4755: sub checkonthis {
1.637 raeburn 4756: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4757: $url=&unescape($url);
4758: $alreadyseen{$url}=1;
4759: $r->rflush();
4760: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4761: $r->print("\n<br />");
4762: if ($level==0) {
4763: $r->print("<br />");
4764: }
4765: for (my $i=0;$i<=$level*5;$i++) {
4766: $r->print(' ');
4767: }
4768: $r->print('<a href="'.$url.'" target="cat">'.
4769: ($title?$title:$url).'</a> ');
4770: if ($url=~/^\/res\//) {
1.637 raeburn 4771: my $updated;
4772: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4773: ($url !~ /\.\d+\.\w+$/)) {
4774: $updated = &Apache::lonnet::remove_stale_resfile($url);
4775: }
1.329 droeschl 4776: my $result=&Apache::lonnet::repcopy(
4777: &Apache::lonnet::filelocation('',$url));
4778: if ($result eq 'ok') {
4779: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4780: if ($updated) {
4781: $r->print('<br />');
4782: for (my $i=0;$i<=$level*5;$i++) {
4783: $r->print(' ');
4784: }
4785: $r->print('- '.&mt('Outdated copy removed'));
4786: }
1.329 droeschl 4787: $r->rflush();
4788: &Apache::lonnet::countacc($url);
4789: $url=~/\.(\w+)$/;
4790: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4791: $r->print('<br />');
4792: $r->rflush();
4793: for (my $i=0;$i<=$level*5;$i++) {
4794: $r->print(' ');
4795: }
4796: $r->print('- '.&mt('Rendering:').' ');
4797: my ($errorcount,$warningcount)=split(/:/,
4798: &Apache::lonnet::ssi_body($url,
4799: ('grade_target'=>'web',
4800: 'return_only_error_and_warning_counts' => 1)));
4801: if (($errorcount) ||
4802: ($warningcount)) {
4803: if ($errorcount) {
1.369 bisitz 4804: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4805: &mt('[quant,_1,error]',$errorcount).'</span>');
4806: }
4807: if ($warningcount) {
4808: $r->print('<span class="LC_warning">'.
4809: &mt('[quant,_1,warning]',$warningcount).'</span>');
4810: }
4811: } else {
4812: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4813: }
4814: $r->rflush();
4815: }
4816: my $dependencies=
4817: &Apache::lonnet::metadata($url,'dependencies');
4818: foreach my $dep (split(/\,/,$dependencies)) {
4819: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4820: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4821: }
4822: }
4823: } elsif ($result eq 'unavailable') {
4824: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4825: } elsif ($result eq 'not_found') {
4826: unless ($url=~/\$/) {
1.521 bisitz 4827: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4828: } else {
1.366 bisitz 4829: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4830: }
4831: } else {
4832: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4833: }
1.637 raeburn 4834: if (($updated) && ($result ne 'ok')) {
4835: $r->print('<br />'.&mt('Outdated copy removed'));
4836: }
1.329 droeschl 4837: }
4838: }
4839: }
4840:
4841:
4842:
4843: =pod
4844:
4845: =item list_symbs()
4846:
1.485 raeburn 4847: List Content Identifiers
1.329 droeschl 4848:
4849: =cut
4850:
4851: sub list_symbs {
4852: my ($r) = @_;
4853:
1.408 raeburn 4854: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4855: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4856: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4857: $r->print(&startContentScreen('tools'));
1.329 droeschl 4858: my $navmap = Apache::lonnavmaps::navmap->new();
4859: if (!defined($navmap)) {
4860: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4861: '<div class="LC_error">'.
4862: &mt('Unable to retrieve information about course contents').
4863: '</div>');
1.408 raeburn 4864: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4865: } else {
1.484 raeburn 4866: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4867: &Apache::loncommon::start_data_table().
4868: &Apache::loncommon::start_data_table_header_row().
4869: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4870: &Apache::loncommon::end_data_table_header_row()."\n");
4871: my $count;
1.329 droeschl 4872: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4873: $r->print(&Apache::loncommon::start_data_table_row().
4874: '<td>'.$res->compTitle().'</td>'.
4875: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4876: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4877: $count ++;
4878: }
4879: if (!$count) {
4880: $r->print(&Apache::loncommon::start_data_table_row().
4881: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4882: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4883: }
1.484 raeburn 4884: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4885: }
1.521 bisitz 4886: $r->print(&endContentScreen());
1.329 droeschl 4887: }
4888:
1.651 raeburn 4889: sub short_urls {
4890: my ($r,$canedit) = @_;
4891: my $crstype = &Apache::loncommon::course_type();
4892: my $formname = 'shortenurl';
4893: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4894: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4895: $r->print(&startContentScreen('tools'));
4896: my ($navmap,$errormsg) =
4897: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4898: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4899: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4900: my (%maps,%resources,%titles);
4901: if (!ref($navmap)) {
4902: $r->print($errormsg.
4903: &endContentScreen());
4904: return '';
4905: } else {
1.652 raeburn 4906: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 4907: $r->rflush();
4908: my $readonly;
4909: if ($canedit) {
1.671 raeburn 4910: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 4911: if ($numnew) {
4912: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4913: }
4914: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4915: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4916: foreach my $error (@{$errors}) {
4917: $r->print('<li>'.$error.'</li>');
4918: }
4919: $r->print('</ul><br />');
4920: }
4921: } else {
4922: $readonly = 1;
4923: }
4924: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4925: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4926: undef,undef,undef,undef,undef,\%currtiny,$readonly));
4927: }
4928: $r->print(&endContentScreen());
4929: }
4930:
1.637 raeburn 4931: sub contentverifyform {
4932: my ($r) = @_;
4933: my $crstype = &Apache::loncommon::course_type();
4934: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4935: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4936: $r->print(&startContentScreen('tools'));
4937: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4938: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4939: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4940: ' <span class="LC_nobreak">'.
4941: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4942: &mt('No').'</label>'.(' 'x2).
4943: '<label><input type="radio" name="checkstale" value="1" />'.
4944: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 4945: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 4946: '<input type="hidden" value="1" name="tools" />'.
4947: '<input type="hidden" value="1" name="verify" /></p></form>');
4948: $r->print(&endContentScreen());
4949: return;
4950: }
1.329 droeschl 4951:
4952: sub verifycontent {
1.637 raeburn 4953: my ($r,$checkstale) = @_;
1.408 raeburn 4954: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4955: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4956: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4957: $r->print(&startContentScreen('tools'));
4958: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4959: $hashtied=0;
4960: undef %alreadyseen;
4961: %alreadyseen=();
4962: &tiehash();
1.484 raeburn 4963:
1.329 droeschl 4964: foreach my $key (keys(%hash)) {
4965: if ($hash{$key}=~/\.(page|sequence)$/) {
4966: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4967: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4968: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4969: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4970: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4971: }
4972: }
4973: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 4974: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4975: }
4976: }
4977: &untiehash();
1.442 www 4978: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4979: $r->print(&endContentScreen());
1.329 droeschl 4980: }
4981:
4982: sub devalidateversioncache {
4983: my $src=shift;
4984: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4985: &Apache::lonnet::clutter($src));
4986: }
4987:
4988: sub checkversions {
1.611 raeburn 4989: my ($r,$canedit) = @_;
1.408 raeburn 4990: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4991: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4992: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4993: $r->print(&startContentScreen('tools'));
1.442 www 4994:
1.329 droeschl 4995: my $header='';
4996: my $startsel='';
4997: my $monthsel='';
4998: my $weeksel='';
4999: my $daysel='';
5000: my $allsel='';
5001: my %changes=();
5002: my $starttime=0;
5003: my $haschanged=0;
5004: my %setversions=&Apache::lonnet::dump('resourceversions',
5005: $env{'course.'.$env{'request.course.id'}.'.domain'},
5006: $env{'course.'.$env{'request.course.id'}.'.num'});
5007:
5008: $hashtied=0;
5009: &tiehash();
1.611 raeburn 5010: if ($canedit) {
5011: my %newsetversions=();
5012: if ($env{'form.setmostrecent'}) {
5013: $haschanged=1;
5014: foreach my $key (keys(%hash)) {
5015: if ($key=~/^ids\_(\/res\/.+)$/) {
5016: $newsetversions{$1}='mostrecent';
5017: &devalidateversioncache($1);
5018: }
5019: }
5020: } elsif ($env{'form.setcurrent'}) {
5021: $haschanged=1;
5022: foreach my $key (keys(%hash)) {
5023: if ($key=~/^ids\_(\/res\/.+)$/) {
5024: my $getvers=&Apache::lonnet::getversion($1);
5025: if ($getvers>0) {
5026: $newsetversions{$1}=$getvers;
5027: &devalidateversioncache($1);
5028: }
5029: }
1.329 droeschl 5030: }
1.611 raeburn 5031: } elsif ($env{'form.setversions'}) {
5032: $haschanged=1;
5033: foreach my $key (keys(%env)) {
5034: if ($key=~/^form\.set_version_(.+)$/) {
5035: my $src=$1;
5036: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5037: $newsetversions{$src}=$env{$key};
5038: &devalidateversioncache($src);
5039: }
5040: }
1.329 droeschl 5041: }
1.611 raeburn 5042: }
5043: if ($haschanged) {
5044: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5045: $env{'course.'.$env{'request.course.id'}.'.domain'},
5046: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5047: $r->print(&Apache::loncommon::confirmwrapper(
5048: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5049: } else {
5050: $r->print(&Apache::loncommon::confirmwrapper(
5051: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 5052: }
1.611 raeburn 5053: &mark_hash_old();
5054: }
5055: &changewarning($r,'');
1.329 droeschl 5056: }
5057: if ($env{'form.timerange'} eq 'all') {
5058: # show all documents
1.549 raeburn 5059: $header=&mt('All content in '.$crstype);
1.521 bisitz 5060: $allsel=' selected="selected"';
1.329 droeschl 5061: foreach my $key (keys(%hash)) {
5062: if ($key=~/^ids\_(\/res\/.+)$/) {
5063: my $src=$1;
5064: $changes{$src}=1;
5065: }
5066: }
5067: } else {
5068: # show documents which changed
5069: %changes=&Apache::lonnet::dump
5070: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5071: $env{'course.'.$env{'request.course.id'}.'.num'});
5072: my $firstkey=(keys(%changes))[0];
5073: unless ($firstkey=~/^error\:/) {
5074: unless ($env{'form.timerange'}) {
5075: $env{'form.timerange'}=604800;
5076: }
5077: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5078: .&mt('seconds');
5079: if ($env{'form.timerange'}==-1) {
5080: $seltext='since start of course';
1.521 bisitz 5081: $startsel=' selected="selected"';
1.329 droeschl 5082: $env{'form.timerange'}=time;
5083: }
5084: $starttime=time-$env{'form.timerange'};
5085: if ($env{'form.timerange'}==2592000) {
5086: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5087: $monthsel=' selected="selected"';
1.329 droeschl 5088: } elsif ($env{'form.timerange'}==604800) {
5089: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5090: $weeksel=' selected="selected"';
1.329 droeschl 5091: } elsif ($env{'form.timerange'}==86400) {
5092: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5093: $daysel=' selected="selected"';
1.329 droeschl 5094: }
5095: $header=&mt('Content changed').' '.$seltext;
5096: } else {
5097: $header=&mt('No content modifications yet.');
5098: }
5099: }
5100: %setversions=&Apache::lonnet::dump('resourceversions',
5101: $env{'course.'.$env{'request.course.id'}.'.domain'},
5102: $env{'course.'.$env{'request.course.id'}.'.num'});
5103: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5104: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5105: 'lm' => 'Version changes since last Month',
5106: 'lw' => 'Version changes since last Week',
5107: 'sy' => 'Version changes since Yesterday',
5108: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5109: 'cd' => 'Change display',
1.329 droeschl 5110: 'sd' => 'Display',
5111: 'fi' => 'File',
5112: 'md' => 'Modification Date',
5113: 'mr' => 'Most recently published Version',
1.408 raeburn 5114: 've' => 'Version used in '.$crstype,
5115: 'vu' => 'Set Version to be used in '.$crstype,
5116: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5117: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5118: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5119: 'di' => 'Differences',
1.484 raeburn 5120: 'save' => 'Save changes',
5121: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5122: 'act' => 'Actions');
1.611 raeburn 5123: my ($disabled,$readonly);
5124: unless ($canedit) {
5125: $disabled = 'disabled="disabled"';
5126: $readonly = 1;
5127: }
1.329 droeschl 5128: $r->print(<<ENDHEADERS);
1.484 raeburn 5129: <h4 class="LC_info">$header</h4>
1.329 droeschl 5130: <form action="/adm/coursedocs" method="post">
5131: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5132: <div class="LC_left_float">
1.479 golterma 5133: <fieldset>
1.484 raeburn 5134: <legend>$lt{'cd'}</legend>
1.329 droeschl 5135: <select name="timerange">
1.521 bisitz 5136: <option value='all'$allsel>$lt{'al'}</option>
5137: <option value="-1"$startsel>$lt{'st'}</option>
5138: <option value="2592000"$monthsel>$lt{'lm'}</option>
5139: <option value="604800"$weeksel>$lt{'lw'}</option>
5140: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5141: </select>
5142: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5143: </fieldset>
5144: </div>
5145: <div class="LC_left_float">
5146: <fieldset>
5147: <legend>$lt{'act'}</legend>
1.611 raeburn 5148: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5149: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5150: </fieldset>
5151: </div>
5152: <br clear="all" />
5153: <hr />
5154: <h4>$lt{'vers'}</h4>
1.329 droeschl 5155: ENDHEADERS
1.479 golterma 5156: #number of columns for version history
1.571 raeburn 5157: my %changedbytime;
5158: foreach my $key (keys(%changes)) {
5159: #excludes not versionable problems from resource version history:
5160: next if ($key =~ /^\/res\/lib\/templates/);
5161: my $chg;
5162: if ($env{'form.timerange'} eq 'all') {
5163: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5164: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5165: } else {
5166: $chg = $changes{$key};
5167: next if ($chg < $starttime);
5168: }
5169: push(@{$changedbytime{$chg}},$key);
5170: }
5171: if (keys(%changedbytime) == 0) {
5172: &untiehash();
5173: $r->print(&mt('No content changes in imported content in specified time frame').
5174: &endContentScreen());
5175: return;
5176: }
1.479 golterma 5177: $r->print(
1.611 raeburn 5178: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5179: &Apache::loncommon::start_data_table().
5180: &Apache::loncommon::start_data_table_header_row().
5181: '<th>'.&mt('Resources').'</th>'.
5182: "<th>$lt{'mr'}</th>".
5183: "<th>$lt{'ve'}</th>".
5184: "<th>$lt{'vu'}</th>".
5185: '<th>'.&mt('History').'</th>'.
5186: &Apache::loncommon::end_data_table_header_row()
5187: );
1.571 raeburn 5188: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5189: foreach my $key (sort(@{$changedbytime{$chg}})) {
5190: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5191: my $currentversion=&Apache::lonnet::getversion($key);
5192: if ($currentversion<0) {
5193: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5194: }
5195: my $linkurl=&Apache::lonnet::clutter($key);
5196: $r->print(
5197: &Apache::loncommon::start_data_table_row().
5198: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5199: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5200: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5201: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5202: '<td align="right">'
5203: );
5204: # Used in course
5205: my $usedversion=$hash{'version_'.$linkurl};
5206: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5207: if ($usedversion != $currentversion) {
1.479 golterma 5208: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5209: } else {
1.479 golterma 5210: $r->print($usedversion);
5211: }
1.329 droeschl 5212: } else {
1.521 bisitz 5213: $r->print($currentversion);
1.329 droeschl 5214: }
1.571 raeburn 5215: $r->print('</td><td title="'.$lt{'vu'}.'">');
5216: # Set version
5217: $r->print(&Apache::loncommon::select_form(
5218: $setversions{$linkurl},
5219: 'set_version_'.$linkurl,
5220: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5221: '' => '',
5222: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5223: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5224: my $lastold=1;
5225: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5226: my $url=$root.'.'.$prevvers.'.'.$extension;
5227: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5228: $lastold=$prevvers;
5229: }
5230: }
5231: $r->print('</td>');
5232: # List all available versions
5233: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5234: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5235: my $url=$root.'.'.$prevvers.'.'.$extension;
5236: $r->print(
5237: '<span class="LC_nobreak">'
5238: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5239: .&mt('Version [_1]',$prevvers).'</a>'
5240: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5241: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5242: .')');
5243: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5244: $r->print(
5245: ' <a href="/adm/diff?filename='.
5246: &Apache::lonnet::clutter($root.'.'.$extension).
5247: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5248: '" target="diffs">'.&mt('Diffs').'</a>');
5249: }
5250: $r->print('</span><br />');
1.329 droeschl 5251: }
1.571 raeburn 5252: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5253: }
1.329 droeschl 5254: }
1.521 bisitz 5255: $r->print(
5256: &Apache::loncommon::end_data_table().
1.611 raeburn 5257: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5258: '</form>'
5259: );
1.329 droeschl 5260:
5261: &untiehash();
1.521 bisitz 5262: $r->print(&endContentScreen());
1.571 raeburn 5263: return;
1.329 droeschl 5264: }
5265:
5266: sub mark_hash_old {
5267: my $retie_hash=0;
5268: if ($hashtied) {
5269: $retie_hash=1;
5270: &untiehash();
5271: }
5272: &tiehash('write');
5273: $hash{'old'}=1;
5274: &untiehash();
5275: if ($retie_hash) { &tiehash(); }
5276: }
5277:
5278: sub is_hash_old {
5279: my $untie_hash=0;
5280: if (!$hashtied) {
5281: $untie_hash=1;
5282: &tiehash();
5283: }
5284: my $return=$hash{'old'};
5285: if ($untie_hash) { &untiehash(); }
5286: return $return;
5287: }
5288:
5289: sub changewarning {
5290: my ($r,$postexec,$message,$url)=@_;
5291: if (!&is_hash_old()) { return; }
5292: my $pathvar='folderpath';
5293: my $path=&escape($env{'form.folderpath'});
5294: if (!defined($url)) {
5295: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5296: }
5297: my $course_type = &Apache::loncommon::course_type();
5298: if (!defined($message)) {
5299: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5300: }
1.653 raeburn 5301: my $windowname = 'loncapaclient';
5302: if ($env{'request.lti.login'}) {
5303: $windowname .= 'lti';
5304: }
1.329 droeschl 5305: $r->print("\n\n".
1.372 bisitz 5306: '<script type="text/javascript">'."\n".
5307: '// <![CDATA['."\n".
5308: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5309: '// ]]>'."\n".
1.369 bisitz 5310: '</script>'."\n".
1.653 raeburn 5311: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5312: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5313: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5314: &mt($message,' <input type="hidden" name="'.
5315: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5316: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5317: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5318: }
5319:
5320:
5321: sub init_breadcrumbs {
1.571 raeburn 5322: my ($form,$text,$help)=@_;
1.329 droeschl 5323: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5324: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5325: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5326: faq=>273,
5327: bug=>'Instructor Interface',
1.571 raeburn 5328: help => $help});
1.329 droeschl 5329: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5330: text=>$text,
5331: faq=>273,
5332: bug=>'Instructor Interface'});
5333: }
5334:
1.441 www 5335: # subroutine to list form elements
5336: sub create_list_elements {
5337: my @formarr = @_;
5338: my $list = '';
1.501 raeburn 5339: foreach my $button (@formarr){
5340: foreach my $picture (keys(%{$button})) {
5341: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5342: }
5343: }
5344: return $list;
5345: }
1.329 droeschl 5346:
1.441 www 5347: # subroutine to create ul from list elements
5348: sub create_form_ul {
5349: my $list = shift;
5350: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5351: return $ul;
5352: }
1.329 droeschl 5353:
1.442 www 5354: #
5355: # Start tabs
5356: #
5357:
5358: sub startContentScreen {
1.484 raeburn 5359: my ($mode) = @_;
5360: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5361: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5362: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5363: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5364: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5365: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5366: } else {
1.549 raeburn 5367: $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 5368: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5369: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5370: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5371: }
5372: $output .= "\n".'</ul>'."\n";
5373: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5374: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5375: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5376: return $output;
1.442 www 5377: }
5378:
5379: #
5380: # End tabs
5381: #
5382:
5383: sub endContentScreen {
1.484 raeburn 5384: return '</div></div></div>';
1.442 www 5385: }
1.329 droeschl 5386:
1.446 www 5387: sub supplemental_base {
1.548 raeburn 5388: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5389: }
5390:
1.329 droeschl 5391: sub handler {
5392: my $r = shift;
5393: &Apache::loncommon::content_type($r,'text/html');
5394: $r->send_http_header;
5395: return OK if $r->header_only;
1.484 raeburn 5396:
5397: # get course data
1.408 raeburn 5398: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5399: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5400: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5401:
1.606 raeburn 5402: # get docroot
5403: my $londocroot = $r->dir_config('lonDocRoot');
5404:
1.484 raeburn 5405: # graphics settings
5406: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5407:
1.443 www 5408: #
1.329 droeschl 5409: # --------------------------------------------- Initialize help topics for this
5410: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5411: 'Adding_External_Resource','Adding_External_Tool',
5412: 'Navigate_Content','Adding_Folders','Docs_Overview',
5413: 'Load_Map','Supplemental','Score_Upload_Form',
5414: 'Adding_Pages','Importing_LON-CAPA_Resource',
5415: 'Importing_IMS_Course','Uploading_From_Harddrive',
5416: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5417: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5418: }
5419: # Composite help files
5420: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5421: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5422: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5423: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5424: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5425: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5426: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5427: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5428: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5429: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5430:
1.611 raeburn 5431: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5432: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5433: unless ($r->uri eq '/adm/supplemental') {
5434: # does this user have privileges to modify content.
1.611 raeburn 5435: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5436: $allowed = 1;
5437: $canedit = 1;
5438: $canview = 1;
5439: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5440: $allowed = 1;
5441: $canview = 1;
5442: }
5443: }
5444: unless ($canedit) {
5445: $disabled = ' disabled="disabled"';
1.472 raeburn 5446: }
1.582 raeburn 5447: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5448: if ($env{'form.inhibitmenu'}) {
5449: unless ($env{'form.inhibitmenu'} eq 'yes') {
5450: delete($env{'form.inhibitmenu'});
5451: }
5452: }
5453:
1.582 raeburn 5454: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5455: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5456: if (!$canedit) {
5457: &verifycontent($r);
5458: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5459: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5460: text=>'Results',
5461: faq=>273,
5462: bug=>'Instructor Interface'});
5463: &verifycontent($r,$env{'form.checkstale'});
5464: } else {
5465: &contentverifyform($r);
5466: }
1.329 droeschl 5467: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5468: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5469: &list_symbs($r);
1.651 raeburn 5470: } elsif ($allowed && $env{'form.shorturls'}) {
5471: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5472: &short_urls($r,$canedit);
1.329 droeschl 5473: } elsif ($allowed && $env{'form.docslog'}) {
5474: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5475: my $folder = $env{'form.folder'};
5476: if ($folder eq '') {
5477: $folder='default';
5478: }
1.611 raeburn 5479: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5480: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5481: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5482: &checkversions($r,$canedit);
5483: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5484: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5485: &dumpcourse($r);
1.611 raeburn 5486: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5487: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5488: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5489: } else {
1.611 raeburn 5490: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5491: $noendpage = 1;
5492: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5493: if ($redirect) {
5494: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5495: my $container = 'sequence';
5496: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5497: $is_random_order,$container) =
5498: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5499: my (@folders)=split('&',$env{'form.folderpath'});
5500: $env{'form.foldername'}=&unescape(pop(@folders));
5501: my $folder=pop(@folders);
5502: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5503: $folder.'.'.$container);
5504: my $warning;
5505: if ($fatal) {
5506: if ($container eq 'page') {
5507: $warning = &mt('An error occurred retrieving the contents of the current page.');
5508: } else {
5509: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5510: }
5511: } else {
5512: my $url = $redirect;
5513: my $srcfile = $londocroot.$url;
5514: $url =~ s{^/priv/}{/res/};
5515: my $targetfile = $londocroot.$url;
5516: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5517: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5518: $env{'form.folder'} = $folder;
5519: &snapshotbefore();
5520: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5521: my $ext = 'false';
5522: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5523: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5524: ':'.$ext.':normal:res';
5525: push(@LONCAPA::map::order,$newidx);
5526: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5527: 'string_yesno');
5528: &remember_parms($newidx,'hiddenresource','set','yes');
5529: ($errtext,$fatal) =
5530: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5531: &log_differences($plain);
5532: &mark_hash_old();
5533: $r->internal_redirect($redirect);
5534: return OK;
5535: }
1.654 raeburn 5536: } else {
5537: $r->internal_redirect($redirect);
1.606 raeburn 5538: }
5539: }
5540: }
1.445 www 5541: #
5542: # Done catching special calls
1.484 raeburn 5543: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5544: # Get the parameters that may be needed
5545: #
5546: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5547: ['folderpath',
5548: 'forcesupplement','forcestandard',
1.510 raeburn 5549: 'tools','symb','command','supppath']);
1.445 www 5550:
1.635 raeburn 5551: foreach my $item ('forcesupplement','forcestandard','tools') {
5552: next if ($env{'form.'.$item} eq '');
5553: unless ($env{'form.'.$item} eq '1') {
5554: delete($env{'form.'.$item});
5555: }
5556: }
5557:
5558: if ($env{'form.command'}) {
5559: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5560: delete($env{'form.command'});
5561: }
5562: }
5563:
5564: if ($env{'form.symb'}) {
5565: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5566: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5567: delete($env{'form.symb'});
5568: }
5569: }
5570:
1.445 www 5571: # standard=1: this is a "new-style" course with an uploaded map as top level
5572: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5573:
5574: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5575:
1.484 raeburn 5576: # Decide whether this should display supplemental or main content or utilities
1.445 www 5577: # supplementalflag=1: show supplemental documents
5578: # supplementalflag=0: show standard documents
1.484 raeburn 5579: # toolsflag=1: show utilities
1.445 www 5580:
1.561 raeburn 5581: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5582: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5583: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5584: $supplementalflag=0;
5585: }
5586: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5587: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5588: unless ($allowed) { $supplementalflag=1; }
5589: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5590: my $toolsflag=0;
5591: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5592:
1.635 raeburn 5593: if ($env{'form.folderpath'} ne '') {
1.677 raeburn 5594: &validate_folderpath($supplementalflag);
1.635 raeburn 5595: }
5596:
5597: if ($env{'form.supppath'} ne '') {
1.677 raeburn 5598: &validate_suppath();
1.635 raeburn 5599: }
5600:
1.329 droeschl 5601: my $script='';
5602: my $showdoc=0;
1.457 raeburn 5603: my $addentries = {};
1.475 raeburn 5604: my $container;
1.329 droeschl 5605: my $containertag;
1.508 raeburn 5606: my $pathitem;
1.598 raeburn 5607: my %ltitools;
1.617 raeburn 5608: my $hiddentop;
1.615 raeburn 5609: my $navmap;
1.617 raeburn 5610: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5611:
1.464 www 5612: # Do we directly jump somewhere?
1.525 raeburn 5613: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5614: if ($env{'form.symb'} ne '') {
1.522 raeburn 5615: $env{'form.folderpath'}=
1.617 raeburn 5616: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5617: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5618: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5619: } elsif ($env{'form.supppath'} ne '') {
5620: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5621: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5622: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5623: }
1.472 raeburn 5624: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5625: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5626: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5627: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5628: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5629: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5630: } elsif ($env{'form.command'} eq 'contents') {
5631: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5632: } elsif ($env{'form.command'} eq 'home') {
5633: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5634: }
5635:
1.525 raeburn 5636:
1.445 www 5637: # Where do we store these for when we come back?
5638: my $stored_folderpath='docs_folderpath';
5639: if ($supplementalflag) {
5640: $stored_folderpath='docs_sup_folderpath';
5641: }
1.464 www 5642:
1.519 raeburn 5643: # No folderpath, and in edit mode, see if we have something stored
5644: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5645: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5646: {'folderpath' => 'scalar'});
1.615 raeburn 5647:
5648: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5649: if ($supplementalflag) {
5650: undef($env{'form.folderpath'}) if ($1 eq 'default');
5651: } else {
5652: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5653: }
5654: } else {
1.523 raeburn 5655: undef($env{'form.folderpath'});
5656: }
1.677 raeburn 5657: if ($env{'form.folderpath'} ne '') {
5658: &validate_folderpath($supplementalflag);
5659: }
1.329 droeschl 5660: }
1.446 www 5661:
5662: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5663: if (!$allowed) {
1.446 www 5664: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5665: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5666: }
5667: }
1.446 www 5668: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5669: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5670: $env{'form.folderpath'} = &supplemental_base()
5671: .'&'.
1.329 droeschl 5672: $env{'form.folderpath'};
5673: }
1.615 raeburn 5674: # If allowed and user's role is not advanced check folderpath is not hidden
5675: if (($allowed) && (!$env{'request.role.adv'}) &&
5676: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5677: my $folderurl;
5678: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5679: my $folder = $pathitems[-2];
5680: if ($folder eq '') {
5681: undef($env{'form.folderpath'});
5682: } else {
5683: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 5684: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 5685: $folderurl .= '.page';
5686: } else {
5687: $folderurl .= '.sequence';
5688: }
1.617 raeburn 5689: unless (ref($navmap)) {
5690: $navmap = Apache::lonnavmaps::navmap->new();
5691: }
1.615 raeburn 5692: if (ref($navmap)) {
5693: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5694: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5695: unless (@resources) {
5696: undef($env{'form.folderpath'});
5697: }
1.615 raeburn 5698: }
5699: }
5700: }
5701: }
5702:
5703:
1.446 www 5704: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5705: unless ($env{'form.folderpath'}) {
1.446 www 5706: if ($supplementalflag) {
5707: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5708: } elsif ($allowed) {
5709: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5710: }
1.472 raeburn 5711: }
1.446 www 5712:
1.445 www 5713: # Store this
1.484 raeburn 5714: unless ($toolsflag) {
1.615 raeburn 5715: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5716: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5717: {'folderpath' => 'scalar'});
1.510 raeburn 5718: }
1.519 raeburn 5719: my $folderpath;
1.484 raeburn 5720: if ($env{'form.folderpath'}) {
1.519 raeburn 5721: $folderpath = $env{'form.folderpath'};
5722: my (@folders)=split('&',$env{'form.folderpath'});
5723: $env{'form.foldername'}=&unescape(pop(@folders));
5724: if ($env{'form.foldername'} =~ /\:1$/) {
5725: $container = 'page';
5726: } else {
5727: $container = 'sequence';
5728: }
5729: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5730: } else {
1.519 raeburn 5731: if ($env{'form.folder'} eq '' ||
5732: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5733: if ($env{'form.folder'} eq 'supplemental') {
5734: $folderpath=&supplemental_base();
5735: } elsif (!$hiddentop) {
5736: $folderpath='default&'.
5737: &escape(&mt('Main Content').':::::');
5738: }
1.484 raeburn 5739: }
5740: }
1.519 raeburn 5741: $containertag = '<input type="hidden" name="folderpath" value="" />';
5742: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5743: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5744: $showdoc='/'.$1;
5745: }
5746: if ($showdoc) { # got called in sequence from course
5747: $allowed=0;
5748: } else {
1.611 raeburn 5749: if ($canedit) {
1.484 raeburn 5750: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5751: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5752: }
5753: }
1.329 droeschl 5754: }
5755:
1.344 bisitz 5756: # get personal data
1.329 droeschl 5757: my $uname=$env{'user.name'};
5758: my $udom=$env{'user.domain'};
5759: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5760:
5761: if ($allowed) {
1.484 raeburn 5762: if ($toolsflag) {
5763: $script .= &inject_data_js();
5764: my ($home,$other,%outhash)=&authorhosts();
5765: if (!$home && $other) {
5766: my @hosts;
5767: foreach my $aurole (keys(%outhash)) {
5768: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5769: push(@hosts,$outhash{$aurole});
5770: }
5771: }
5772: $script .= &dump_switchserver_js(@hosts);
5773: }
1.458 raeburn 5774: } else {
1.570 raeburn 5775: my $tid = 1;
1.484 raeburn 5776: my @tabids;
5777: if ($supplementalflag) {
1.655 raeburn 5778: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 5779: $tid = 2;
1.484 raeburn 5780: } else {
5781: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5782: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5783: unshift(@tabids,'001');
5784: push(@tabids,('dd1','ee1'));
5785: }
1.458 raeburn 5786: }
1.484 raeburn 5787: my $tabidstr = join("','",@tabids);
1.644 raeburn 5788: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
1.600 raeburn 5789: my $posslti = keys(%ltitools);
1.622 raeburn 5790: my $hostname = $r->hostname();
1.606 raeburn 5791: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5792: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5793: &history_tab_js().
5794: &inject_data_js().
1.570 raeburn 5795: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5796: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5797: $addentries = {
1.485 raeburn 5798: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5799: };
1.458 raeburn 5800: }
1.538 raeburn 5801: $script .= &paste_popup_js();
1.501 raeburn 5802: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5803: &mt('Switch server?');
5804:
5805:
1.329 droeschl 5806: }
5807: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5808: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5809: .'// <![CDATA['."\n"
5810: .$script."\n"
5811: .'// ]]>'."\n"
1.595 musolffc 5812: .'</script>'."\n"
5813: .'<script type="text/javascript"
5814: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5815:
5816: # Breadcrumbs
5817: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5818:
5819: if ($showdoc) {
5820: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5821: {'force_register' => $showdoc,}));
1.571 raeburn 5822: } elsif ($toolsflag) {
1.611 raeburn 5823: my ($breadtext,$breadtitle);
1.617 raeburn 5824: $breadtext = "$crstype Editor";
1.611 raeburn 5825: if ($canedit) {
5826: $breadtitle = 'Editing '.$crstype.' Contents';
5827: } else {
5828: $breadtext .= ' (View-only mode)';
5829: $breadtitle = 'Viewing '.$crstype.' Contents';
5830: }
1.571 raeburn 5831: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5832: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5833: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5834: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5835: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5836: $breadtitle)
1.571 raeburn 5837: );
1.510 raeburn 5838: } elsif ($r->uri eq '/adm/supplemental') {
5839: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5840: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5841: {'bread_crumbs' => $brcrum,}));
5842: } else {
1.611 raeburn 5843: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5844: $breadtext = "$crstype Editor";
1.611 raeburn 5845: if ($canedit) {
5846: $breadtitle = 'Editing '.$crstype.' Contents';
5847: $helpitem = 'Docs_Adding_Course_Doc';
5848: } else {
5849: $breadtext .= ' (View-only mode)';
5850: $breadtitle = 'Viewing '.$crstype.' Contents';
5851: $helpitem = 'Docs_Viewing_Course_Doc';
5852: }
1.392 raeburn 5853: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5854: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5855: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5856: {'add_entries' => $addentries}
5857: )
1.392 raeburn 5858: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5859: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5860: $breadtitle,
5861: $helpitem)
1.392 raeburn 5862: );
5863: }
1.364 bisitz 5864:
1.329 droeschl 5865: my %allfiles = ();
5866: my %codebase = ();
1.440 raeburn 5867: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5868: if ($canedit) {
1.329 droeschl 5869: if (($env{'form.uploaddoc.filename'}) &&
5870: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5871: my $context = $1;
5872: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5873: undef($hadchanges);
1.440 raeburn 5874: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5875: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 5876: undef($navmap);
1.329 droeschl 5877: if ($hadchanges) {
5878: &mark_hash_old();
5879: }
1.440 raeburn 5880: $r->print($upload_output);
5881: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5882: # Process file upload - phase two - upload embedded objects
5883: $uploadphase = 'check_embedded';
5884: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5885: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5886: $env{'form.newidx'});
5887: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5888: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5889: my ($destination,$dir_root) = &embedded_destination();
5890: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5891: my $actionurl = '/adm/coursedocs';
1.630 raeburn 5892: my ($result,$flag) =
1.440 raeburn 5893: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5894: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5895: $actionurl);
5896: $r->print($result.&return_to_editor());
5897: } elsif ($env{'form.phase'} eq 'check_embedded') {
5898: # Process file upload - phase three - modify references in HTML file
5899: $uploadphase = 'modified_orightml';
5900: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5901: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5902: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 5903: my $result =
1.482 raeburn 5904: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5905: $docuname,$docudom,undef,
5906: $dir_root);
1.630 raeburn 5907: $r->print($result.&return_to_editor());
1.476 raeburn 5908: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5909: $uploadphase = 'decompress_phase_one';
5910: $r->print(&decompression_phase_one().
5911: &return_to_editor());
5912: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5913: $uploadphase = 'decompress_phase_two';
5914: $r->print(&decompression_phase_two().
5915: &return_to_editor());
1.329 droeschl 5916: }
5917: }
5918:
1.484 raeburn 5919: if ($allowed && $toolsflag) {
5920: $r->print(&startContentScreen('tools'));
1.611 raeburn 5921: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5922: $r->print(&endContentScreen());
5923: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5924: # -----------------------------------------------------------------------------
5925: my %lt=&Apache::lonlocal::texthash(
5926: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5927: 'upfi' => 'Upload File',
1.553 raeburn 5928: 'upld' => 'Upload Content',
1.329 droeschl 5929: 'srch' => 'Search',
5930: 'impo' => 'Import',
1.487 raeburn 5931: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5932: 'impm' => 'Import from Assembled Map',
1.630 raeburn 5933: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5934: 'extr' => 'External Resource',
5935: 'extt' => 'External Tool',
1.329 droeschl 5936: 'selm' => 'Select Map',
5937: 'load' => 'Load Map',
5938: 'newf' => 'New Folder',
5939: 'newp' => 'New Composite Page',
5940: 'syll' => 'Syllabus',
1.425 raeburn 5941: 'navc' => 'Table of Contents',
1.343 biermanm 5942: 'sipa' => 'Simple Course Page',
1.329 droeschl 5943: 'sipr' => 'Simple Problem',
1.630 raeburn 5944: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5945: 'stpr' => 'Standard Problem',
5946: 'news' => 'New sub-directory',
5947: 'crpr' => 'Create Problem',
1.329 droeschl 5948: 'drbx' => 'Drop Box',
1.451 www 5949: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5950: 'bull' => 'Discussion Board',
1.347 weissno 5951: 'mypi' => 'My Personal Information Page',
1.353 weissno 5952: 'grpo' => 'Group Portfolio',
1.329 droeschl 5953: 'rost' => 'Course Roster',
1.528 raeburn 5954: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5955: 'imsf' => 'IMS Upload',
5956: 'imsl' => 'Upload IMS package',
1.501 raeburn 5957: 'cms' => 'Origin of IMS package',
5958: 'se' => 'Select',
1.329 droeschl 5959: 'file' => 'File',
5960: 'title' => 'Title',
1.606 raeburn 5961: 'addp' => 'Add Placeholder to course?',
5962: 'uste' => 'Use Template?',
5963: 'fnam' => 'File Name:',
5964: 'loca' => 'Location:',
5965: 'dire' => 'Directory:',
5966: 'cate' => 'Category:',
5967: 'tmpl' => 'Template:',
1.329 droeschl 5968: 'comment' => 'Comment',
1.403 raeburn 5969: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5970: 'bb5' => 'Blackboard 5',
5971: 'bb6' => 'Blackboard 6',
5972: 'angel5' => 'ANGEL 5.5',
5973: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5974: 'yes' => 'Yes',
5975: 'no' => 'No',
1.618 raeburn 5976: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5977: );
1.329 droeschl 5978: # -----------------------------------------------------------------------------
1.595 musolffc 5979:
5980: # Calculate free quota space for a user or course. A javascript function checks
5981: # file size to determine if upload should be allowed.
5982: my $quotatype = 'unofficial';
5983: if ($crstype eq 'Community') {
1.601 raeburn 5984: $quotatype = 'community';
5985: } elsif ($crstype eq 'Placement') {
5986: $quotatype = 'placement';
1.595 musolffc 5987: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5988: $quotatype = 'official';
5989: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5990: $quotatype = 'textbook';
5991: }
5992: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5993: 'course',$quotatype); # expressed in MB
5994: my $current_disk_usage = 0;
5995: foreach my $subdir ('docs','supplemental') {
5996: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5997: "userfiles/$subdir",1); # expressed in kB
5998: }
5999: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 6000: my $usage = $current_disk_usage/1024; # in MB
6001: my $quota = $disk_quota;
6002: my $percent;
6003: if ($disk_quota == 0) {
6004: $percent = 100.0;
6005: } else {
1.619 raeburn 6006: $percent = 100*($usage/$disk_quota);
1.605 raeburn 6007: }
6008: $usage = sprintf("%.2f",$usage);
6009: $quota = sprintf("%.2f",$quota);
6010: $percent = sprintf("%.0f",$percent);
6011: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6012: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 6013:
1.329 droeschl 6014: my $fileupload=(<<FIUP);
1.605 raeburn 6015: $quotainfo
1.329 droeschl 6016: $lt{'file'}:<br />
1.662 raeburn 6017: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
1.663 raeburn 6018: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 6019: FIUP
6020:
6021: my $checkbox=(<<CHBO);
6022: <!-- <label>$lt{'parse'}?
6023: <input type="checkbox" name="parserflag" />
6024: </label> -->
6025: <label>
1.611 raeburn 6026: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6027: </label>
6028: CHBO
1.501 raeburn 6029: my $imsfolder = $env{'form.folder'};
6030: if ($imsfolder eq '') {
6031: $imsfolder = 'default';
6032: }
6033: my $imspform=(<<IMSFORM);
6034: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6035: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6036: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 6037: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 6038: <legend>$lt{'imsf'}</legend>
6039: $fileupload
6040: <br />
6041: <p>
6042: $lt{'cms'}:
1.611 raeburn 6043: <select name="source" $disabled>
1.501 raeburn 6044: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 6045: <option value="bb5">$lt{'bb5'}</option>
6046: <option value="bb6">$lt{'bb6'}</option>
6047: <option value="angel5">$lt{'angel5'}</option>
6048: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 6049: </select>
6050: <input type="hidden" name="folder" value="$imsfolder" />
6051: </p>
6052: <input type="hidden" name="phase" value="one" />
1.611 raeburn 6053: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 6054: </fieldset>
6055: </form>
6056: IMSFORM
1.329 droeschl 6057:
6058: my $fileuploadform=(<<FUFORM);
1.501 raeburn 6059: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6060: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6061: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 6062: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 6063: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6064: <input type="hidden" name="active" value="aa" />
1.595 musolffc 6065: $fileupload
1.329 droeschl 6066: <br />
6067: $lt{'title'}:<br />
1.611 raeburn 6068: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 6069: $pathitem
1.329 droeschl 6070: <input type="hidden" name="cmd" value="upload_default" />
6071: <br />
1.458 raeburn 6072: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6073: $checkbox
6074: </span>
1.501 raeburn 6075: <br clear="all" />
1.611 raeburn 6076: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 6077: </fieldset>
6078: </form>
1.383 tempelho 6079: FUFORM
1.329 droeschl 6080:
1.611 raeburn 6081: my $mapimportjs;
6082: if ($canedit) {
6083: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6084: } else {
6085: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6086: }
1.502 raeburn 6087: my $importpubform=(<<SEDFFORM);
1.514 raeburn 6088: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 6089: $lt{'impm'}</a>$help{'Load_Map'}
6090: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 6091: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 6092: <legend>$lt{'impm'}</legend>
1.371 tempelho 6093: <input type="hidden" name="active" value="bb" />
1.502 raeburn 6094: $lt{'copm'}<br />
6095: <span class="LC_nobreak">
6096: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 6097: onfocus="this.blur();$mapimportjs" $disabled />
6098: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6099: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 6100: </fieldset>
6101: </form>
6102:
1.383 tempelho 6103: SEDFFORM
1.606 raeburn 6104: my $importcrsresform;
1.608 raeburn 6105: my ($numdirs,$pickfile) =
6106: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
6107: "resize_scrollbox('contentscroll','1','0');",
6108: undef,'res');
1.606 raeburn 6109: if ($pickfile) {
6110: $importcrsresform=(<<CRSFORM);
6111: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
6112: $lt{'imcr'}</a>$help{'Course_Resources'}
6113: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6114: <fieldset id="importcrsresform" style="display: none;">
6115: <legend>$lt{'imcr'}</legend>
6116: <input type="hidden" name="active" value="bb" />
6117: $pickfile
6118: <p>
1.611 raeburn 6119: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 6120: </p>
6121: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 6122: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 6123: </fieldset>
6124: </form>
6125: CRSFORM
6126: }
6127:
1.611 raeburn 6128: my $fromstoredjs;
6129: if ($canedit) {
6130: $fromstoredjs = 'open_StoredLinks_Import()';
6131: } else {
6132: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6133: }
6134:
1.502 raeburn 6135: my @importpubforma = (
1.508 raeburn 6136: { '<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 6137: { '<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 6138: { '<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 6139: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6140: );
6141: if ($pickfile) {
6142: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
6143: }
1.502 raeburn 6144: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 6145: my $extresourcesform =
6146: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6147: $help{'Adding_External_Resource'},
6148: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6149: my $exttoolform =
6150: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6151: $help{'Adding_External_Tool'},undef,
6152: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6153: \%ltitools,$disabled);
1.329 droeschl 6154: if ($allowed) {
1.492 raeburn 6155: my $folder = $env{'form.folder'};
6156: if ($folder eq '') {
6157: $folder='default';
6158: }
1.615 raeburn 6159: if ($canedit) {
6160: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6161: if ($output) {
6162: $r->print($output);
6163: }
1.538 raeburn 6164: }
1.337 ehlerst 6165: $r->print(<<HIDDENFORM);
6166: <form name="renameform" method="post" action="/adm/coursedocs">
6167: <input type="hidden" name="title" />
6168: <input type="hidden" name="cmd" />
6169: <input type="hidden" name="markcopy" />
6170: <input type="hidden" name="copyfolder" />
6171: $containertag
6172: </form>
1.633 raeburn 6173: <form name="aliasform" method="post" action="/adm/coursedocs">
6174: <input type="hidden" name="alias" />
6175: <input type="hidden" name="cmd" />
6176: $containertag
6177: </form>
1.484 raeburn 6178:
1.337 ehlerst 6179: HIDDENFORM
1.508 raeburn 6180: $r->print(&makesimpleeditform($pathitem)."\n".
6181: &makedocslogform($pathitem."\n".
1.484 raeburn 6182: '<input type="hidden" name="folder" value="'.
6183: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6184: }
1.442 www 6185:
6186: # Generate the tabs
1.510 raeburn 6187: my ($mode,$needs_end);
1.472 raeburn 6188: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6189: my @folders = split('&',$env{'form.folderpath'});
6190: unless (@folders > 2) {
6191: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6192: $needs_end = 1;
6193: }
1.472 raeburn 6194: } else {
1.484 raeburn 6195: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6196: $needs_end = 1;
1.472 raeburn 6197: }
1.443 www 6198:
1.442 www 6199: #
1.622 raeburn 6200: my $hostname = $r->hostname();
1.442 www 6201: my $savefolderpath;
6202:
1.395 raeburn 6203: if ($allowed) {
1.329 droeschl 6204: my $folder=$env{'form.folder'};
1.615 raeburn 6205: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6206: $folder='default';
1.356 tempelho 6207: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6208: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6209: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6210: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6211: }
6212: my $postexec='';
6213: if ($folder eq 'default') {
1.653 raeburn 6214: my $windowname = 'loncapaclient';
6215: if ($env{'request.lti.login'}) {
6216: $windowname .= 'lti';
6217: }
1.372 bisitz 6218: $r->print('<script type="text/javascript">'."\n"
6219: .'// <![CDATA['."\n"
1.653 raeburn 6220: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 6221: .'// ]]>'."\n"
6222: .'</script>'."\n"
1.369 bisitz 6223: );
1.329 droeschl 6224: } else {
6225: #$postexec='self.close();';
6226: }
1.504 raeburn 6227: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6228: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6229: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6230:
6231: my $newnavform=(<<NNFORM);
6232: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 6233: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6234: $pathitem
1.329 droeschl 6235: <input type="hidden" name="importdetail"
6236: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6237: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6238: $help{'Navigate_Content'}
6239: </form>
6240: NNFORM
6241: my $newsmppageform=(<<NSPFORM);
6242: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 6243: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6244: $pathitem
1.329 droeschl 6245: <input type="hidden" name="importdetail" value="" />
1.423 onken 6246: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6247: $help{'Simple Page'}
1.329 droeschl 6248: </form>
6249: NSPFORM
6250:
6251: my $newsmpproblemform=(<<NSPROBFORM);
6252: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 6253: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6254: $pathitem
1.329 droeschl 6255: <input type="hidden" name="importdetail" value="" />
1.423 onken 6256: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6257: $help{'Simple_Problem'}
1.329 droeschl 6258: </form>
6259:
6260: NSPROBFORM
6261:
6262: my $newdropboxform=(<<NDBFORM);
6263: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 6264: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6265: $pathitem
1.329 droeschl 6266: <input type="hidden" name="importdetail" value="" />
1.423 onken 6267: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6268: $help{'Dropbox'}
1.344 bisitz 6269: </form>
1.329 droeschl 6270: NDBFORM
6271:
6272: my $newexuploadform=(<<NEXUFORM);
6273: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 6274: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6275: $pathitem
1.329 droeschl 6276: <input type="hidden" name="importdetail" value="" />
1.423 onken 6277: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6278: $help{'Score_Upload_Form'}
6279: </form>
6280: NEXUFORM
6281:
6282: my $newbulform=(<<NBFORM);
6283: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 6284: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6285: $pathitem
1.329 droeschl 6286: <input type="hidden" name="importdetail" value="" />
1.423 onken 6287: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6288: $help{'Bulletin Board'}
6289: </form>
6290: NBFORM
6291:
6292: my $newaboutmeform=(<<NAMFORM);
6293: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 6294: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6295: $pathitem
1.329 droeschl 6296: <input type="hidden" name="importdetail"
6297: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6298: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6299: $help{'My Personal Information Page'}
1.329 droeschl 6300: </form>
6301: NAMFORM
6302:
6303: my $newaboutsomeoneform=(<<NASOFORM);
6304: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 6305: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6306: $pathitem
1.329 droeschl 6307: <input type="hidden" name="importdetail" value="" />
1.423 onken 6308: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6309: </form>
6310: NASOFORM
6311:
6312: my $newrosterform=(<<NROSTFORM);
6313: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 6314: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6315: $pathitem
1.329 droeschl 6316: <input type="hidden" name="importdetail"
6317: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6318: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6319: $help{'Course_Roster'}
1.329 droeschl 6320: </form>
6321: NROSTFORM
6322:
1.534 raeburn 6323: my $newwebpage;
6324: if ($folder =~ /^default_?(\d*)$/) {
6325: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6326: if ($1) {
6327: $newwebpage .= $1;
6328: } else {
6329: $newwebpage .= 'default';
6330: }
6331: $newwebpage .= '/new.html';
6332: }
6333: my $newwebpageform =(<<NWEBFORM);
6334: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 6335: <input type="hidden" name="active" value="ff" />
1.534 raeburn 6336: $pathitem
6337: <input type="hidden" name="importdetail" value="$newwebpage" />
6338: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6339: $help{'Web_Page'}
1.534 raeburn 6340: </form>
6341: NWEBFORM
1.604 raeburn 6342:
1.606 raeburn 6343: my @ids=&Apache::lonnet::current_machine_ids();
6344: my %select_menus;
6345: my $numauthor = 0;
6346: my $numcrsdirs = 0;
6347: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
6348: if ($env{'user.author'}) {
6349: $numauthor ++;
6350: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6351: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6352: my $is_home = 1;
6353: my %subdirs;
1.608 raeburn 6354: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6355: $select_menus{'author'}->{'default'} = '/';
6356: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6357: my @ordered = ('/');
6358: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6359: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6360: push(@ordered,$relpath);
6361: }
6362: $select_menus{'author'}->{'order'} = \@ordered;
6363: } else {
6364: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6365: $select_menus{'author'}->{'default'} = 'switch';
6366: $select_menus{'author'}->{'order'} = ['switch'];
6367: }
6368: }
6369: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6370: ['active'],['ca','aa']);
6371: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6372: my %by_roletype;
6373: if (keys(%roleshash)) {
6374: foreach my $entry (keys(%roleshash)) {
6375: my ($auname,$audom,$roletype) = split(/:/,$entry);
6376: my $key = $entry;
6377: $key =~ s/:/___/g;
6378: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6379: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6380: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6381: if (grep(/^\Q$rolehome\E$/,@ids)) {
6382: my $is_home = 1;
6383: my (%subdirs,@ordered);
6384: my $toppath="/priv/$audom/$auname";
1.608 raeburn 6385: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6386: $select_menus{$key}->{'default'} = '/';
6387: $select_menus{$key}->{'select2'}->{'/'} = '/';
6388: my @ordered = ('/');
6389: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6390: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6391: push(@ordered,$relpath);
6392: }
6393: $select_menus{$key}->{'order'} = \@ordered;
6394: } else {
6395: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6396: $select_menus{$key}->{'default'} = 'switch';
6397: $select_menus{$key}->{'order'} = ['switch'];
6398: }
6399: $numauthor ++;
6400: }
6401: }
1.631 raeburn 6402: my ($pickdir,$showtitle);
1.606 raeburn 6403: if ($numauthor) {
6404: my @order;
6405: my $defrole;
6406: if ($env{'user.author'}) {
6407: push(@order,'author');
6408: $defrole = 'author';
6409: }
6410: if (keys(%by_roletype)) {
6411: foreach my $possrole ('ca','aa') {
6412: if (ref($by_roletype{$possrole}) eq 'HASH') {
6413: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6414: unless ($defrole) {
6415: $defrole = $author;
6416: }
6417: push(@order,$author.'___'.$possrole);
6418: }
6419: }
6420: }
6421: }
6422: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6423: if (grep(/^\Q$crshome\E$/,@ids)) {
6424: my $is_home = 1;
6425: my %subdirs;
6426: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6427: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6428: $numcrsdirs = keys(%subdirs);
6429: $select_menus{'course'}->{'default'} = '/';
6430: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6431: my @ordered = ('/');
6432: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6433: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6434: push(@ordered,$relpath);
6435: }
6436: $select_menus{'course'}->{'order'} = \@ordered;
6437: } else {
6438: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6439: $select_menus{'course'}->{'default'} = 'switch';
6440: $select_menus{'course'}->{'order'} = ['switch'];
6441: }
6442: push(@order,'course');
6443: $pickdir = $lt{'loca'}.
6444: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6445: $defrole,'authorrole','authorpath',
6446: \%select_menus,\@order,'toggleCrsResTitle();',
6447: '','priv').'<br />';
6448: $showtitle = 'none';
6449: } else {
6450: my $is_home;
6451: $showtitle = 'inline';
6452: if (grep(/^\Q$crshome\E$/,@ids)) {
6453: $is_home = 1;
6454: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6455: my $toppath="/priv/$coursedom/$coursenum'}";
6456: my %subdirs;
1.608 raeburn 6457: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6458: $numcrsdirs = keys(%subdirs);
6459: if ($numcrsdirs) {
6460: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6461: '<option value="/">/</option>'."\n";
6462: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6463: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6464: }
6465: $pickdir .= '</select>';
6466: } else {
6467: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6468: }
6469: }
6470: }
6471:
6472: my %seltemplate_menus;
6473: my @files = &Apache::lonhomework::get_template_list('problem');
6474: my @noexamplelink = ('blank.problem','blank.library','script.library');
6475: my $currentcategory = '';
6476: my @ordered = ('');
6477: my %templatehelp;
6478: my $defcategory = '';
6479: my @catorder = ($defcategory);
6480: $seltemplate_menus{$defcategory}->{'order'} = [''];
6481: $seltemplate_menus{$defcategory}->{'text'} = '';
6482: foreach my $file (@files) {
6483: if (ref($file) eq 'ARRAY') {
6484: my ($path,$title,$category,$help) = @{$file};
6485: next if ($title !~ /\S/);
6486: if (&js_escape($category) ne $currentcategory) {
6487: $currentcategory = &js_escape($category);
6488: push(@catorder,&js_escape($currentcategory));
6489: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6490: $seltemplate_menus{$currentcategory}->{'default'} = '';
6491: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6492: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6493: }
6494: if ($path) {
6495: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6496: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6497: if ($help) {
6498: $templatehelp{$path} = $help;
6499: }
6500: }
6501: }
6502: }
6503:
6504: my $templates = $lt{'cate'}.' '.
6505: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6506: $defcategory,'tempcategory','template',
6507: \%seltemplate_menus,\@catorder,
6508: "resize_scrollbox('contentscroll','1','0');",
6509: "toggleExampleText();",'template').'<br />';
6510: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6511: '<span id="newresexample">'.&mt('Example').'<span></a>';
6512: my $crsresform=(<<RESFORM);
6513: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6514: $lt{'stpr'}</a>$help{'Course_Resource'}
6515: <form action="/adm/coursedocs" method="post" name="courseresform">
6516: <fieldset id="crsresform" style="display:none;">
6517: <legend>$lt{'stpr'}</legend>
1.655 raeburn 6518: <input type="hidden" name="active" value="bb" />
1.606 raeburn 6519: <p>
6520: $pickdir
6521: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6522: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6523:
1.611 raeburn 6524: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6525: </span><span id="newsubdir"></span>
6526: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6527: </p>
6528: $lt{'fnam'}
1.611 raeburn 6529: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6530: <p>
6531: <div id="newresource" style="display:$showtitle">
6532: $lt{'addp'}
1.611 raeburn 6533: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6534: $lt{'no'}</label>
1.611 raeburn 6535: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6536: $lt{'yes'}</label>
6537: <span id="newrestitle"></span>
1.611 raeburn 6538: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6539: </div>
6540: </p>
6541: <p>
6542: $lt{'uste'}
1.611 raeburn 6543: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6544: $lt{'no'}</label>
1.611 raeburn 6545: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6546: $lt{'yes'}</label>
6547: <div id="newrestemplate" style="display:none">
6548: $templates
6549: $templatepreview
6550: </div>
6551: </p>
6552: <span class="LC_nobreak">
6553: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6554: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6555: </span>
6556: </fieldset>
6557: </form>
6558:
6559: RESFORM
1.534 raeburn 6560:
1.342 ehlerst 6561: my $specialdocumentsform;
1.383 tempelho 6562: my @specialdocumentsforma;
1.451 www 6563: my $gradingform;
6564: my @gradingforma;
6565: my $communityform;
6566: my @communityforma;
1.351 ehlerst 6567: my $newfolderform;
1.390 tempelho 6568: my $newfolderb;
1.342 ehlerst 6569:
1.451 www 6570: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6571:
1.329 droeschl 6572: my $newpageform=(<<NPFORM);
6573: <form action="/adm/coursedocs" method="post" name="newpage">
6574: <input type="hidden" name="folderpath" value="$path" />
6575: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6576: <input type="hidden" name="active" value="ee" />
1.423 onken 6577: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6578: $help{'Adding_Pages'}
1.329 droeschl 6579: </form>
6580: NPFORM
1.390 tempelho 6581:
6582:
1.351 ehlerst 6583: $newfolderform=(<<NFFORM);
1.329 droeschl 6584: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6585: $pathitem
1.329 droeschl 6586: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6587: <input type="hidden" name="active" value="" />
1.422 onken 6588: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6589: </form>
6590: NFFORM
6591:
6592: my $newsylform=(<<NSYLFORM);
6593: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6594: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6595: $pathitem
1.329 droeschl 6596: <input type="hidden" name="importdetail"
6597: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6598: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6599: $help{'Syllabus'}
1.383 tempelho 6600:
1.329 droeschl 6601: </form>
6602: NSYLFORM
1.364 bisitz 6603:
1.329 droeschl 6604: my $newgroupfileform=(<<NGFFORM);
6605: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 6606: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6607: $pathitem
1.329 droeschl 6608: <input type="hidden" name="importdetail"
6609: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6610: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6611: $help{'Group Portfolio'}
1.329 droeschl 6612: </form>
6613: NGFFORM
1.672 raeburn 6614: if ($container eq 'page') {
6615: @specialdocumentsforma=(
6616: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6617: );
6618: } else {
6619: @specialdocumentsforma=(
1.421 onken 6620: {'<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 6621: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6622: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6623: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6624: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 6625: );
6626: }
1.451 www 6627: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6628:
1.655 raeburn 6629: my @external = (
6630: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 6631: );
1.598 raeburn 6632: if (keys(%ltitools)) {
1.655 raeburn 6633: push(@external,
6634: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6635: );
1.598 raeburn 6636: }
1.655 raeburn 6637: my $externalform = &create_form_ul(&create_list_elements(@external));
6638:
6639: my @importdoc = ();
1.519 raeburn 6640: unless ($container eq 'page') {
6641: push(@importdoc,
6642: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6643: );
6644: }
6645: push(@importdoc,
1.558 raeburn 6646: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6647: );
1.501 raeburn 6648: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6649:
1.451 www 6650: @gradingforma=(
6651: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6652: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6653: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6654: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform},
1.451 www 6655: );
6656: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6657:
6658: @communityforma=(
6659: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6660: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6661: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6662: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6663: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6664: );
6665: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6666:
1.330 tempelho 6667: my %orderhash = (
1.553 raeburn 6668: 'aa' => ['Upload',$fileuploadform],
6669: 'bb' => ['Import',$importpubform],
1.655 raeburn 6670: 'cc' => ['External',$externalform],
6671: 'dd' => ['Grading',$gradingform],
1.673 raeburn 6672: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 6673: );
1.519 raeburn 6674: unless ($container eq 'page') {
1.434 raeburn 6675: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 6676: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 6677: }
6678:
1.341 ehlerst 6679: $hadchanges=0;
1.484 raeburn 6680: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6681: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6682: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6683: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6684: undef($navmap);
1.443 www 6685: if ($error) {
6686: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6687: }
1.639 raeburn 6688: if ($hadchanges) {
6689: unless (&is_hash_old()) {
1.638 raeburn 6690: &mark_hash_old();
6691: }
6692: }
1.341 ehlerst 6693:
1.443 www 6694: &changewarning($r,'');
6695: }
1.458 raeburn 6696: }
1.442 www 6697:
1.443 www 6698: # Supplemental documents start here
6699:
1.329 droeschl 6700: my $folder=$env{'form.folder'};
1.443 www 6701: unless ($supplementalflag) {
1.329 droeschl 6702: $folder='supplemental';
6703: }
6704: if ($folder =~ /^supplemental$/ &&
6705: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6706: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6707: } elsif ($allowed) {
1.356 tempelho 6708: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6709: }
1.508 raeburn 6710: $pathitem = '<input type="hidden" name="folderpath" value="'.
6711: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6712: if ($allowed) {
6713: my $folderseq=
1.504 raeburn 6714: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6715:
6716: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6717: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6718: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6719: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6720: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6721: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6722: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6723: $fileupload
6724: <br />
6725: <br />
6726: <span class="LC_nobreak">
6727: $checkbox
6728: </span>
6729: <br /><br />
6730: $lt{'comment'}:<br />
1.383 tempelho 6731: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6732: <br />
1.508 raeburn 6733: $pathitem
1.329 droeschl 6734: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6735: <input type='submit' value="$lt{'upld'}" />
6736: </form>
1.329 droeschl 6737: SUPDOCFORM
6738:
6739: my $supnewfolderform=(<<SNFFORM);
6740: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6741: <input type="hidden" name="active" value="" />
1.508 raeburn 6742: $pathitem
1.329 droeschl 6743: <input type="hidden" name="importdetail" value="" />
1.423 onken 6744: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6745: $help{'Adding_Folders'}
1.329 droeschl 6746: </form>
6747: SNFFORM
1.383 tempelho 6748:
1.510 raeburn 6749: my $supextform =
6750: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6751: $help{'Adding_External_Resource'},
6752: undef,undef,undef,undef,undef,undef,
6753: $disabled);
1.329 droeschl 6754:
1.598 raeburn 6755: my $supexttoolform =
6756: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6757: $help{'Adding_External_Tool'},
6758: undef,undef,'tool',$coursedom,
1.611 raeburn 6759: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6760:
1.329 droeschl 6761: my $supnewsylform=(<<SNSFORM);
6762: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6763: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6764: $pathitem
1.329 droeschl 6765: <input type="hidden" name="importdetail"
6766: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6767: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6768: $help{'Syllabus'}
6769: </form>
6770: SNSFORM
6771:
6772: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6773: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6774: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6775: $pathitem
1.329 droeschl 6776: <input type="hidden" name="importdetail"
6777: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6778: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6779: $help{'My Personal Information Page'}
1.329 droeschl 6780: </form>
6781: SNAMFORM
6782:
1.534 raeburn 6783: my $supwebpage;
6784: if ($folder =~ /^supplemental_?(\d*)$/) {
6785: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6786: if ($1) {
6787: $supwebpage .= $1;
6788: } else {
6789: $supwebpage .= 'default';
6790: }
6791: $supwebpage .= '/new.html';
6792: }
6793: my $supwebpageform =(<<SWEBFORM);
6794: <form action="/adm/coursedocs" method="post" name="supwebpage">
6795: <input type="hidden" name="active" value="cc" />
6796: $pathitem
6797: <input type="hidden" name="importdetail" value="$supwebpage" />
6798: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6799: $help{'Web_Page'}
1.534 raeburn 6800: </form>
6801: SWEBFORM
6802:
1.333 muellerd 6803:
1.383 tempelho 6804: my @specialdocs = (
1.618 raeburn 6805: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6806: =>$supnewsylform},
1.611 raeburn 6807: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6808: =>$supnewaboutmeform},
1.534 raeburn 6809: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6810:
1.383 tempelho 6811: );
1.655 raeburn 6812: my @supexternal = (
6813: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
6814: =>$supextform});
1.598 raeburn 6815: if (keys(%ltitools)) {
1.655 raeburn 6816: push(@supexternal,
6817: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 6818: =>$supexttoolform});
6819: }
1.655 raeburn 6820: my @supimportdoc = (
1.598 raeburn 6821: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6822: =>$supupdocform},
1.598 raeburn 6823: );
1.501 raeburn 6824:
6825: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6826: my %suporderhash = (
1.390 tempelho 6827: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 6828: 'dd' => ['Upload',$supupdocform],
6829: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 6830: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6831: );
1.443 www 6832: if ($supplementalflag) {
1.458 raeburn 6833: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6834: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 raeburn 6835: \%ltitools,$canedit,$hostname);
1.443 www 6836: if ($error) {
6837: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6838: } else {
6839: if ($suppchanges) {
6840: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6841: my @ids=&Apache::lonnet::current_machine_ids();
6842: foreach my $server (keys(%servers)) {
6843: next if (grep(/^\Q$server\E$/,@ids));
6844: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6845: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6846: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6847: }
6848: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6849: undef($suppchanges);
1.630 raeburn 6850: }
6851: }
1.393 raeburn 6852: }
1.443 www 6853: } elsif ($supplementalflag) {
1.458 raeburn 6854: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 raeburn 6855: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6856: if ($error) {
6857: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6858: }
1.393 raeburn 6859: }
1.389 tempelho 6860:
1.510 raeburn 6861: if ($needs_end) {
6862: $r->print(&endContentScreen());
6863: }
1.383 tempelho 6864:
1.329 droeschl 6865: if ($allowed) {
6866: $r->print('
6867: <form method="post" name="extimport" action="/adm/coursedocs">
6868: <input type="hidden" name="title" />
6869: <input type="hidden" name="url" />
6870: <input type="hidden" name="useform" />
6871: <input type="hidden" name="residx" />
6872: </form>');
6873: }
1.484 raeburn 6874: } elsif ($showdoc) {
1.329 droeschl 6875: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6876: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6877: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6878: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6879: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6880: }
6881: }
1.630 raeburn 6882: unless ($noendpage) {
1.606 raeburn 6883: $r->print(&Apache::loncommon::end_page());
6884: }
1.329 droeschl 6885: return OK;
1.364 bisitz 6886: }
1.329 droeschl 6887:
1.440 raeburn 6888: sub embedded_form_elems {
6889: my ($phase,$primaryurl,$newidx) = @_;
6890: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 6891: $newidx =~s /\D+//g;
1.440 raeburn 6892: return <<STATE;
6893: <input type="hidden" name="folderpath" value="$folderpath" />
6894: <input type="hidden" name="cmd" value="upload_embedded" />
6895: <input type="hidden" name="newidx" value="$newidx" />
6896: <input type="hidden" name="phase" value="$phase" />
6897: <input type="hidden" name="primaryurl" value="$primaryurl" />
6898: STATE
6899: }
6900:
6901: sub embedded_destination {
6902: my $folder=$env{'form.folder'};
6903: my $destination = 'docs/';
6904: if ($folder =~ /^supplemental/) {
6905: $destination = 'supplemental/';
6906: }
6907: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6908: $destination .= 'default/';
6909: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6910: $destination .= $2.'/';
6911: }
1.634 raeburn 6912: my $newidx = $env{'form.newidx'};
6913: $newidx =~s /\D+//g;
6914: if ($newidx) {
6915: $destination .= $newidx;
6916: }
1.440 raeburn 6917: my $dir_root = '/userfiles';
6918: return ($destination,$dir_root);
6919: }
6920:
6921: sub return_to_editor {
6922: my $actionurl = '/adm/coursedocs';
6923: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6924: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6925: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6926: '</a></p>';
6927: }
6928:
1.476 raeburn 6929: sub decompression_info {
6930: my ($destination,$dir_root) = &embedded_destination();
6931: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6932: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6933: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6934: my $container='sequence';
1.480 raeburn 6935: my ($pathitem,$hiddenelem);
1.583 raeburn 6936: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6937: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6938: $container='page';
6939: }
1.480 raeburn 6940: unshift(@hiddens,$pathitem);
6941: foreach my $item (@hiddens) {
1.634 raeburn 6942: if ($item eq 'newidx') {
6943: next if ($env{'form.'.$item} =~ /\D/);
6944: }
1.480 raeburn 6945: if ($env{'form.'.$item}) {
6946: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6947: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6948: }
1.477 raeburn 6949: }
1.476 raeburn 6950: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6951: $hiddenelem);
6952: }
6953:
6954: sub decompression_phase_one {
6955: my ($dir,$file,$warning,$error,$output);
6956: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6957: &decompression_info();
1.490 raeburn 6958: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6959: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6960: } else {
6961: my $file = $1;
1.630 raeburn 6962: $output =
1.481 raeburn 6963: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6964: $destination,$dir_root,
6965: $hiddenelem);
6966: if ($env{'form.autoextract_camtasia'}) {
6967: $output .= &remove_archive($docudom,$docuname,$container);
6968: }
1.476 raeburn 6969: }
6970: if ($error) {
6971: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6972: $error.'</p>'."\n";
6973: }
6974: if ($warning) {
6975: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6976: }
6977: return $output;
6978: }
6979:
6980: sub decompression_phase_two {
6981: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6982: &decompression_info();
1.481 raeburn 6983: my $output;
1.480 raeburn 6984: if ($env{'form.archivedelete'}) {
1.481 raeburn 6985: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6986: }
6987: $output .=
1.481 raeburn 6988: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6989: $destination,$dir_root,$hiddenelem);
6990: return $output;
6991: }
6992:
1.480 raeburn 6993: sub remove_archive {
6994: my ($docudom,$docuname,$container) = @_;
6995: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6996: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6997: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6998: if ($fatal) {
6999: if ($container eq 'page') {
7000: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7001: } else {
7002: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7003: }
1.583 raeburn 7004: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7005: } else {
7006: my $currcmd = $env{'form.cmd'};
7007: my $position = $env{'form.position'};
1.583 raeburn 7008: my $archiveidx = $position;
1.563 raeburn 7009: if ($position > 0) {
1.583 raeburn 7010: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7011: $archiveidx = $position-1;
7012: }
7013: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 7014: my ($title,$url,@rrest) =
1.583 raeburn 7015: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7016: if ($url eq $env{'form.archiveurl'}) {
7017: if (&handle_edit_cmd($docuname,$docudom)) {
7018: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
7019: if ($fatal) {
7020: if ($container eq 'page') {
7021: $delwarning = &mt('An error occurred updating the contents of the current page.');
7022: } else {
7023: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7024: }
1.480 raeburn 7025: } else {
1.583 raeburn 7026: $delresult = &mt('Archive file removed.');
1.480 raeburn 7027: }
7028: }
1.583 raeburn 7029: } else {
7030: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7031: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7032: }
7033: }
7034: $env{'form.cmd'} = $currcmd;
7035: }
7036: if ($delwarning) {
7037: $output = '<p class="LC_warning">'.
7038: $delwarning.
7039: '</p>';
7040: }
7041: if ($delresult) {
7042: $output .= '<p class="LC_info">'.
7043: $delresult.
7044: '</p>';
7045: }
1.481 raeburn 7046: return $output;
1.480 raeburn 7047: }
7048:
1.484 raeburn 7049: sub generate_admin_menu {
1.611 raeburn 7050: my ($crstype,$canedit) = @_;
1.484 raeburn 7051: my $lc_crstype = lc($crstype);
7052: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 7053: my %lt= ( # do not translate here
1.484 raeburn 7054: 'vc' => 'Verify Content',
7055: 'cv' => 'Check/Set Resource Versions',
7056: 'ls' => 'List Resource Identifiers',
1.651 raeburn 7057: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 7058: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 7059: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 7060: );
1.484 raeburn 7061: my ($candump,$dumpurl);
7062: if ($home + $other > 0) {
7063: $candump = 'F';
7064: if ($home) {
7065: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7066: } else {
7067: my @hosts;
7068: foreach my $aurole (keys(%outhash)) {
7069: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7070: push(@hosts,$outhash{$aurole});
1.538 raeburn 7071: }
1.484 raeburn 7072: }
7073: if (@hosts == 1) {
7074: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7075: '&role='.
7076: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7077: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7078: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7079: } else {
7080: $dumpurl = "javascript:choose_switchserver_window()";
7081: }
7082: }
7083: }
7084: my @menu=
7085: ({ categorytitle=>'Administration',
7086: items =>[
7087: { linktext => $lt{'vc'},
7088: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7089: permission => 'F',
1.571 raeburn 7090: help => 'Docs_Verify_Content',
1.484 raeburn 7091: icon => 'verify.png',
7092: linktitle => 'Verify contents can be retrieved/rendered',
7093: },
7094: { linktext => $lt{'cv'},
7095: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7096: permission => 'F',
1.571 raeburn 7097: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7098: icon => 'resversion.png',
7099: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7100: },
7101: { linktext => $lt{'ls'},
7102: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7103: permission => 'F',
7104: #help => '',
7105: icon => 'symbs.png',
7106: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7107: },
1.651 raeburn 7108: { linktext => $lt{'ct'},
7109: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7110: permission => 'F',
7111: help => 'Docs_Short_URLs',
7112: icon => 'shorturls.png',
7113: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7114: },
1.484 raeburn 7115: ]
1.611 raeburn 7116: });
7117: if ($canedit) {
7118: push(@menu,
1.484 raeburn 7119: { categorytitle=>'Export',
7120: items =>[
7121: { linktext => $lt{'imse'},
7122: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7123: permission => 'F',
7124: help => 'Docs_Export_Course_Docs',
7125: icon => 'imsexport.png',
7126: linktitle => $lt{'imse'},
7127: },
7128: { linktext => $lt{'dcd'},
7129: url => $dumpurl,
7130: permission => $candump,
1.571 raeburn 7131: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7132: icon => 'dump.png',
7133: linktitle => $lt{'dcd'},
7134: },
7135: ]
7136: });
1.611 raeburn 7137: }
1.484 raeburn 7138: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7139: '<input type="hidden" id="dummy" />'."\n".
7140: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7141: '</form>';
1.329 droeschl 7142: }
7143:
7144: sub generate_edit_table {
1.538 raeburn 7145: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 7146: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7147: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7148: my %orderhash = %{$orderhash_ref};
1.611 raeburn 7149: my ($form, $activetab, $active, $disabled);
1.570 raeburn 7150: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7151: $activetab = $env{'form.active'};
7152: }
1.611 raeburn 7153: unless ($canedit) {
7154: $disabled = ' disabled="disabled"';
7155: }
1.472 raeburn 7156: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 7157: my $backtext = &mt('Exit Editor');
1.458 raeburn 7158: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 7159: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7160: '<li class="goback">'.
1.546 raeburn 7161: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 7162: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7163: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7164: '<li>'.
7165: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7166: &mt('Undo Delete').'</a></li>'."\n";
7167: if ($env{'form.docslog'}) {
7168: $form .= '<li class="active">';
7169: } else {
7170: $form .= '<li>';
7171: }
7172: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7173: &mt('History').'</a></li>'."\n";
7174: if ($env{'form.docslog'}) {
7175: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7176: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7177: }
1.458 raeburn 7178: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7179: if($name ne '00'){
1.371 tempelho 7180: if($activetab eq '' || $activetab ne $name){
7181: $active = '';
7182: }elsif($activetab eq $name){
7183: $active = 'class="active"';
7184: }
1.458 raeburn 7185: $form .= '<li style="float:right" '.$active
1.484 raeburn 7186: .' 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 7187: } else {
1.570 raeburn 7188: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7189:
7190: }
1.329 droeschl 7191: }
1.484 raeburn 7192: $form .= '</ul>'."\n";
7193: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7194:
7195: if ($to_show ne '') {
1.538 raeburn 7196: my $saveform;
7197: if ($need_save) {
7198: my $button = &mt('Make changes');
7199: my $path;
7200: if ($env{'form.folderpath'}) {
7201: $path =
7202: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7203: }
7204: $saveform = <<"END";
7205: <div id="multisave" style="display:none; clear:both;" >
7206: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7207: <input type="hidden" name="folderpath" value="$path" />
7208: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7209: <input type="hidden" name="allhiddenresource" value="" />
7210: <input type="hidden" name="allencrypturl" value="" />
7211: <input type="hidden" name="allrandompick" value="" />
7212: <input type="hidden" name="allrandomorder" value="" />
7213: <input type="hidden" name="changeparms" value="" />
7214: <input type="hidden" name="multiremove" value="" />
7215: <input type="hidden" name="multicut" value="" />
7216: <input type="hidden" name="multicopy" value="" />
7217: <input type="hidden" name="multichange" value="" />
7218: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7219: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7220: </form>
7221: </div>
7222: END
7223: }
7224: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7225: }
1.363 ehlerst 7226: foreach my $field (keys(%orderhash)){
1.390 tempelho 7227: if($field ne '00'){
1.422 onken 7228: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7229: $active = 'style="display: none;float:left"';
1.422 onken 7230: }elsif($activetab eq $field){
1.458 raeburn 7231: $active = 'style="display:block;float:left"';
1.422 onken 7232: }
7233: $form .= '<div id="'.$field.$tid.'"'
7234: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7235: .'</div>'."\n";
1.363 ehlerst 7236: }
7237: }
1.484 raeburn 7238: unless ($env{'form.docslog'}) {
7239: $form .= '</div></div>'."\n";
7240: }
1.329 droeschl 7241: return $form;
7242: }
7243:
7244: sub editing_js {
1.622 raeburn 7245: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7246: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7247: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7248: p_mnf => 'Name of New Folder',
7249: t_mnf => 'New Folder',
7250: p_mnp => 'Name of New Page',
7251: t_mnp => 'New Page',
1.451 www 7252: p_mxu => 'Title for the External Score',
1.349 biermanm 7253: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7254: p_msb => 'Title for the Problem',
7255: p_mdb => 'Title for the Drop Box',
1.336 schafran 7256: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7257: p_mwp => 'Title for Web Page',
1.606 raeburn 7258: p_mnr => 'Title for the Resource',
1.348 weissno 7259: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7260: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7261: p_mab_alrt1 => 'Not a valid user:domain',
7262: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7263: p_chn => 'New Title',
7264: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7265: p_rmr2a => 'Remove',
7266: p_rmr2b => '?',
7267: p_rmr3a => 'Remove those',
7268: p_rmr3b => 'items?',
7269: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7270: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7271: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7272: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7273: p_ctr2a => 'Cut',
7274: p_ctr2b => '?',
7275: p_ctr3a => 'Cut those',
7276: p_ctr3b => 'items?',
1.633 raeburn 7277: setal => 'Enter a (unique) alias',
7278: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7279: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7280: imsfile => 'You must choose an IMS package for import',
7281: imscms => 'You must select which Course Management System was the source of the IMS package',
7282: invurl => 'Invalid URL',
7283: titbl => 'Title is blank',
1.538 raeburn 7284: more => '(More ...)',
7285: less => '(Less ...)',
1.543 raeburn 7286: noor => 'No actions selected or changes to settings specified.',
7287: noch => 'No changes to settings specified.',
7288: noac => 'No actions selected.',
1.606 raeburn 7289: nofi => 'No file selected',
7290: tinc => 'Title in course',
7291: sunm => 'Sub-directory name',
1.618 raeburn 7292: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 7293: );
1.594 damieng 7294: &js_escape(\%js_lt);
1.433 raeburn 7295: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7296: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7297: my $main_container_page;
1.519 raeburn 7298: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7299: $main_container_page = 1;
1.434 raeburn 7300: }
1.617 raeburn 7301: my $backtourl;
7302: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7303: my $toplevelsupp = &supplemental_base();
1.433 raeburn 7304:
1.530 raeburn 7305: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7306: my $caller = $1;
1.525 raeburn 7307: if ($caller =~ /^supplemental/) {
7308: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7309: } else {
7310: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7311: $res = &Apache::lonnet::clutter($res);
7312: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7313: my ($url,$anchor);
7314: if ($res =~ /^([^#]+)#([^#]+)$/) {
7315: $url = $1;
7316: $anchor = $2;
7317: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7318: $caller = $1.&escape('#').$anchor;
7319: }
1.614 raeburn 7320: } else {
7321: $url = $res;
1.609 raeburn 7322: }
1.640 raeburn 7323: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7324: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7325: $backtourl .= '?navmap=1';
7326: } else {
7327: $backtourl .= '?symb='.
7328: &HTML::Entities::encode($caller,'<>&"');
7329: }
1.622 raeburn 7330: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7331: if (($ENV{'SERVER_PORT'} == 443) &&
7332: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 7333: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 7334: if ($hostname ne '') {
7335: $backtourl = 'http://'.$hostname.$backtourl;
7336: }
7337: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7338: }
7339: }
1.623 raeburn 7340: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7341: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 7342: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 7343: if ($hostname ne '') {
7344: $backtourl = 'http://'.$hostname.$backtourl;
7345: }
7346: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 7347: }
1.623 raeburn 7348: }
1.622 raeburn 7349: }
1.609 raeburn 7350: if ($anchor ne '') {
7351: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7352: }
1.590 raeburn 7353: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7354: } else {
7355: $backtourl = '/adm/navmaps';
1.525 raeburn 7356: }
7357: }
7358: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7359: $backtourl = '/adm/menu';
7360: } elsif ($supplementalflag) {
1.472 raeburn 7361: $backtourl = '/adm/supplemental';
1.525 raeburn 7362: } else {
7363: $backtourl = '/adm/navmaps';
1.472 raeburn 7364: }
7365:
1.655 raeburn 7366: my $fieldsets = "'doc'";
1.519 raeburn 7367: unless ($main_container_page) {
7368: $fieldsets .=",'ims'";
7369: }
1.655 raeburn 7370: my $extfieldsets = "'ext'";
7371: if ($posslti) {
7372: $extfieldsets .= ",'tool'";
7373: }
1.501 raeburn 7374: if ($supplementalflag) {
1.655 raeburn 7375: $fieldsets = "'suppdoc'";
7376: $extfieldsets = "'suppext'";
1.600 raeburn 7377: if ($posslti) {
1.655 raeburn 7378: $extfieldsets .= ",'supptool'";
1.600 raeburn 7379: }
1.501 raeburn 7380: }
1.655 raeburn 7381:
1.611 raeburn 7382: my $jsmakefunctions;
7383: if ($canedit) {
7384: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7385: function makenewfolder(targetform,folderseq) {
1.594 damieng 7386: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7387: if (foldername) {
1.676 raeburn 7388: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 7389: targetform.submit();
7390: }
7391: }
7392:
7393: function makenewpage(targetform,folderseq) {
1.594 damieng 7394: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7395: if (pagename) {
1.676 raeburn 7396: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 7397: targetform.submit();
7398: }
7399: }
7400:
7401: function makeexamupload() {
1.594 damieng 7402: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7403: if (title) {
1.329 droeschl 7404: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 7405: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 7406: this.document.forms.newexamupload.submit();
7407: }
7408: }
7409:
7410: function makesmppage() {
1.594 damieng 7411: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7412: if (title) {
1.329 droeschl 7413: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 7414: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7415: this.document.forms.newsmppg.submit();
7416: }
7417: }
7418:
1.534 raeburn 7419: function makewebpage(type) {
1.594 damieng 7420: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7421: var formname;
7422: if (type == 'supp') {
7423: formname = this.document.forms.supwebpage;
7424: } else {
7425: formname = this.document.forms.newwebpage;
7426: }
7427: if (title) {
7428: var webpage = formname.importdetail.value;
1.675 raeburn 7429: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 7430: formname.submit();
7431: }
7432: }
7433:
1.329 droeschl 7434: function makesmpproblem() {
1.594 damieng 7435: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7436: if (title) {
1.329 droeschl 7437: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 7438: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 7439: this.document.forms.newsmpproblem.submit();
7440: }
7441: }
7442:
7443: function makedropbox() {
1.594 damieng 7444: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7445: if (title) {
1.329 droeschl 7446: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 7447: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 7448: this.document.forms.newdropbox.submit();
7449: }
7450: }
7451:
7452: function makebulboard() {
1.594 damieng 7453: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7454: if (title) {
7455: this.document.forms.newbul.importdetail.value=
1.676 raeburn 7456: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7457: this.document.forms.newbul.submit();
7458: }
7459: }
7460:
7461: function makeabout() {
1.594 damieng 7462: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7463: if (user) {
7464: var comp=new Array();
7465: comp=user.split(':');
7466: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7467: if ((comp[0]) && (comp[1])) {
7468: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7469: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7470: this.document.forms.newaboutsomeone.submit();
7471: } else {
7472: alert("$js_lt{'p_mab_alrt1'}");
7473: }
7474: } else {
7475: alert("$js_lt{'p_mab_alrt2'}");
7476: }
7477: }
7478: }
7479:
7480: function makenew(targetform) {
7481: targetform.submit();
7482: }
7483:
7484: function changename(folderpath,index,oldtitle) {
7485: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7486: if (title) {
7487: this.document.forms.renameform.markcopy.value='';
7488: this.document.forms.renameform.title.value=title;
7489: this.document.forms.renameform.cmd.value='rename_'+index;
7490: this.document.forms.renameform.folderpath.value=folderpath;
7491: this.document.forms.renameform.submit();
7492: }
7493: }
7494:
1.633 raeburn 7495: function setalias(folderpath,index) {
7496: var alias = prompt('$js_lt{"setal"}');
7497: if ((alias != null) && (alias != '')) {
7498: this.document.forms.aliasform.alias.value=alias;
7499: this.document.forms.aliasform.cmd.value='setalias_'+index;
7500: this.document.forms.aliasform.folderpath.value=folderpath;
7501: this.document.forms.aliasform.submit();
7502: }
7503: }
7504:
7505: function delalias(folderpath,index) {
7506: if (confirm('$js_lt{"delal"}')) {
7507: this.document.forms.aliasform.cmd.value='delalias_'+index;
7508: this.document.forms.aliasform.folderpath.value=folderpath;
7509: this.document.forms.aliasform.submit();
7510: }
7511: }
7512:
1.611 raeburn 7513: ENDNEWSCRIPT
7514: } else {
7515: $jsmakefunctions = <<ENDNEWSCRIPT;
7516:
7517: function makenewfolder() {
7518: alert("$js_lt{'edri'}");
7519: }
7520:
7521: function makenewpage() {
7522: alert("$js_lt{'edri'}");
7523: }
7524:
7525: function makeexamupload() {
7526: alert("$js_lt{'edri'}");
7527: }
7528:
7529: function makesmppage() {
7530: alert("$js_lt{'edri'}");
7531: }
7532:
7533: function makewebpage(type) {
7534: alert("$js_lt{'edri'}");
7535: }
7536:
7537: function makesmpproblem() {
7538: alert("$js_lt{'edri'}");
7539: }
7540:
7541: function makedropbox() {
7542: alert("$js_lt{'edri'}");
7543: }
7544:
7545: function makebulboard() {
7546: alert("$js_lt{'edri'}");
7547: }
7548:
7549: function makeabout() {
7550: alert("$js_lt{'edri'}");
7551: }
7552:
7553: function changename() {
7554: alert("$js_lt{'edri'}");
7555: }
7556:
1.633 raeburn 7557: function setalias() {
7558: alert("$js_lt{'edri'}");
7559: }
7560:
7561: function delalias() {
7562: alert("$js_lt{'edri'}");
7563: }
7564:
1.611 raeburn 7565: function makenew() {
7566: alert("$js_lt{'edri'}");
7567: }
7568:
7569: function groupimport() {
7570: alert("$js_lt{'edri'}");
1.335 ehlerst 7571: }
1.611 raeburn 7572:
7573: function groupsearch() {
7574: alert("$js_lt{'edri'}");
1.335 ehlerst 7575: }
1.611 raeburn 7576:
7577: function groupopen(url,recover) {
7578: var options="scrollbars=1,resizable=1,menubar=0";
7579: idxflag=1;
7580: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7581: idx.focus();
1.329 droeschl 7582: }
7583:
1.611 raeburn 7584: ENDNEWSCRIPT
7585:
7586: }
7587: return <<ENDSCRIPT;
7588:
7589: $jsmakefunctions
7590:
1.501 raeburn 7591: function toggleUpload(caller) {
7592: var blocks = Array($fieldsets);
7593: for (var i=0; i<blocks.length; i++) {
7594: var disp = 'none';
7595: if (caller == blocks[i]) {
7596: var curr = document.getElementById('upload'+caller+'form').style.display;
7597: if (curr == 'none') {
7598: disp='block';
7599: }
7600: }
7601: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 7602: }
7603: resize_scrollbox('contentscroll','1','1');
7604: return;
7605: }
7606:
7607: function toggleExternal(caller) {
7608: var blocks = Array($extfieldsets);
7609: for (var i=0; i<blocks.length; i++) {
7610: var disp = 'none';
7611: if (caller == blocks[i]) {
7612: var curr = document.getElementById('external'+caller+'form').style.display;
7613: if (curr == 'none') {
7614: disp='block';
7615: }
7616: }
7617: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7618: if ((caller == 'tool') || (caller == 'supptool')) {
7619: if (disp == 'block') {
1.655 raeburn 7620: if (document.getElementById('LC_exttoolid')) {
7621: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 7622: var suppflag = 0;
7623: if (caller == 'supptool') {
7624: suppflag = 1;
7625: }
7626: currForm = document.getElementById('new'+caller);
1.655 raeburn 7627: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 7628: }
7629: }
7630: }
1.501 raeburn 7631: }
1.502 raeburn 7632: resize_scrollbox('contentscroll','1','1');
7633: return;
7634: }
7635:
1.514 raeburn 7636: function toggleMap(caller) {
1.502 raeburn 7637: var disp = 'none';
1.510 raeburn 7638: if (document.getElementById('importmapform')) {
1.514 raeburn 7639: if (caller == 'map') {
7640: var curr = document.getElementById('importmapform').style.display;
7641: if (curr == 'none') {
7642: disp='block';
7643: }
1.510 raeburn 7644: }
7645: document.getElementById('importmapform').style.display=disp;
7646: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7647: }
1.501 raeburn 7648: return;
1.329 droeschl 7649: }
7650:
1.606 raeburn 7651: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7652: var disp = 'none';
7653: if (document.getElementById('crsresform')) {
7654: if (caller == 'res') {
7655: var curr = document.getElementById('crsresform').style.display;
7656: if (curr == 'none') {
7657: disp='block';
7658: numauthor = parseInt(numauthorrole);
7659: if (numauthor > 0) {
7660: document.courseresform.authorrole.selectedIndex = 0;
7661: select1priv_changed();
7662: document.courseresform.authorpath.selectedIndex = 0;
7663: document.courseresform.newresourceadd.selectedIndex = 0;
7664: toggleNewInCourse(document.courseresform);
7665: if (document.getElementById('newresource')) {
7666: document.getElementById('newresource').style.display = 'none';
7667: }
7668: } else {
7669: if (numcrsdirs) {
7670: document.courseresform.authorpath.selectedIndex = 0;
7671: }
7672: }
7673: if (document.courseresform.newresusetemp.length) {
7674: document.courseresform.newresusetemp[0].checked = true;
7675: toggleWithTemplate(document.courseresform);
7676: }
7677: document.courseresform.newresourcename.value = '';
7678: }
7679: }
7680: if (document.courseresform.newsubdir.length) {
7681: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7682: if (document.courseresform.newsubdir[j].value == 0) {
7683: document.courseresform.newsubdir[j].checked = true;
7684: }
7685: break;
7686: }
7687: if (document.getElementById('newsubdirname')) {
7688: document.getElementById('newsubdirname').type = "hidden";
7689: document.getElementById('newsubdirname').value = "";
7690: }
7691: if (document.getElementById('newsubdir')) {
7692: document.getElementById('newsubdir').innerHTML = "";
7693: }
7694: }
7695: document.getElementById('crsresform').style.display=disp;
7696: resize_scrollbox('contentscroll','1','0');
7697: }
7698: return;
7699: }
7700:
7701: function toggleNewsubdir(form) {
7702: if (form.newsubdir.length) {
7703: for (var j=0; j<form.newsubdir.length; j++) {
7704: if (form.newsubdir[j].checked) {
7705: if (document.getElementById('newsubdirname')) {
7706: if (form.newsubdir[j].value == '1') {
7707: document.getElementById('newsubdirname').type = "text";
7708: if (document.getElementById('newsubdir')) {
7709: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7710: }
7711: } else {
7712: document.getElementById('newsubdirname').type = "hidden";
7713: document.getElementById('newsubdirname').value = "";
7714: document.getElementById('newsubdir').innerHTML = "";
7715: }
7716: }
7717: break;
7718: }
7719: }
7720: }
7721: }
7722:
7723: function toggleCrsResTitle() {
7724: if (document.getElementById('newresource')) {
7725: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7726: document.getElementById('newresource').style.display = 'inline';
7727: document.courseresform.newresourceadd[0].checked = true;
7728: toggleNewInCourse(document.courseresform);
7729: } else {
7730: document.getElementById('newresource').style.display = 'none';
7731: }
7732: }
7733: }
7734:
7735: function toggleNewInCourse(form) {
7736: if (form.newresourceadd.length) {
7737: for (var i=0; i<form.newresourceadd.length; i++) {
7738: if (form.newresourceadd[i].checked) {
7739: if (document.getElementById('newresourcetitle')) {
7740: if (form.newresourceadd[i].value == '1') {
7741: document.getElementById('newresourcetitle').type = 'text';
7742: if (document.getElementById('newrestitle')) {
7743: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7744: }
7745: } else {
7746: document.getElementById('newresourcetitle').type = 'hidden';
7747: document.getElementById('newresourcetitle').value = '';
7748: if (document.getElementById('newrestitle')) {
7749: document.getElementById('newrestitle').innerHTML = '';
7750: }
7751: }
7752: }
7753: break;
7754: }
7755: }
7756: }
7757: }
7758:
7759: function toggleWithTemplate(form) {
7760: if (form.newresusetemp.length) {
7761: for (var i=0; i<form.newresusetemp.length; i++) {
7762: if (form.newresusetemp[i].checked) {
7763: if (document.getElementById('newrestemplate')) {
7764: if (form.newresusetemp[i].value == '1') {
7765: document.getElementById('newrestemplate').style.display = 'inline';
7766: toggleExampleText();
7767: } else {
7768: form.tempcategory.selectedIndex = 0;
7769: select1template_changed();
7770: document.getElementById('newrestemplate').style.display = 'none';
7771: }
7772: }
7773: }
7774: }
7775: }
7776: }
7777:
7778: function toggleExampleText() {
7779: if (document.getElementById('newresexample')) {
7780: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7781: if (url == '') {
7782: document.getElementById('newresexample').style.fontWeight = 'normal';
7783: } else {
7784: document.getElementById('newresexample').style.fontWeight = 'bold';
7785: }
7786: }
7787: }
7788:
7789: function getExample(width,height,scrolling,transparency) {
7790: var url;
7791: if (document.courseresform.newresusetemp.length) {
7792: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7793: if (document.courseresform.newresusetemp[i].checked) {
7794: if (document.courseresform.newresusetemp[i].value == '1') {
7795: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7796: if (url == '') {
7797: alert('Pick a category and template');
7798: } else {
7799: url = url.replace("$londocroot","");
7800: url += '?inhibitmenu=yes';
7801: }
7802: }
7803: break;
7804: }
7805: }
7806: }
7807: if (url != '') {
7808: openMyModal(url,width,height,scrolling,transparency,'');
7809: }
7810: }
7811:
7812: function toggleImportCrsres(caller,dircount) {
7813: var disp = 'none';
7814: if (document.getElementById('importcrsresform')) {
7815: if (caller == 'res') {
7816: var numdirs = parseInt(dircount);
7817: var curr = document.getElementById('importcrsresform').style.display;
7818: if (curr == 'none') {
7819: disp='block';
7820: if (numdirs > 1) {
7821: select1res_changed();
7822: }
7823: }
7824: }
7825: document.getElementById('importcrsresform').style.display=disp;
7826: resize_scrollbox('contentscroll','1','0');
7827: }
7828: return;
7829: }
7830:
1.501 raeburn 7831: function makeims(imsform) {
7832: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7833: alert("$js_lt{'imsfile'}");
1.501 raeburn 7834: return;
7835: }
7836: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7837: alert("$js_lt{'imscms'}");
1.501 raeburn 7838: return;
7839: }
7840: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7841: imsform.submit();
7842: }
7843:
1.478 raeburn 7844: function updatePick(targetform,index,caller) {
1.537 raeburn 7845: var pickitem;
7846: var picknumitem;
7847: var picknumtext;
7848: if (index == 'all') {
7849: pickitem = document.getElementById('randompickall');
7850: picknumitem = document.getElementById('rpicknumall');
7851: picknumtext = document.getElementById('rpicktextall');
7852: } else {
7853: pickitem = document.getElementById('randompick_'+index);
7854: picknumitem = document.getElementById('rpicknum_'+index);
7855: picknumtext = document.getElementById('randompicknum_'+index);
7856: }
1.478 raeburn 7857: if (pickitem.checked) {
1.594 damieng 7858: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7859: if (picknum == '' || picknum == null) {
7860: if (caller == 'check') {
7861: pickitem.checked=false;
1.537 raeburn 7862: if (index == 'all') {
7863: picknumtext.innerHTML = '';
7864: if (caller == 'link') {
7865: propagateState(targetform,'rpicknum');
7866: }
7867: } else {
1.538 raeburn 7868: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7869: }
1.478 raeburn 7870: }
7871: } else {
7872: picknum.toString();
7873: var regexdigit=/^\\d+\$/;
7874: if (regexdigit.test(picknum)) {
7875: picknumitem.value = picknum;
1.537 raeburn 7876: if (index == 'all') {
1.538 raeburn 7877: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7878: if (caller == 'link') {
7879: propagateState(targetform,'rpicknum');
7880: }
7881: } else {
7882: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7883: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7884: }
1.478 raeburn 7885: } else {
7886: if (caller == 'check') {
1.537 raeburn 7887: if (index == 'all') {
7888: picknumtext.innerHTML = '';
7889: if (caller == 'link') {
7890: propagateState(targetform,'rpicknum');
7891: }
7892: } else {
7893: pickitem.checked=false;
1.538 raeburn 7894: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7895: }
1.478 raeburn 7896: }
7897: return;
7898: }
7899: }
7900: } else {
1.537 raeburn 7901: picknumitem.value = '';
7902: picknumtext.innerHTML = '';
7903: if (index == 'all') {
7904: if (caller == 'link') {
7905: propagateState(targetform,'rpicknum');
7906: }
7907: } else {
1.538 raeburn 7908: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7909: }
7910: }
7911: }
7912:
7913: function propagateState(form,param) {
7914: if (document.getElementById(param+'all')) {
7915: var setcheck = 0;
7916: var rpick = 0;
7917: if (param == 'rpicknum') {
7918: if (document.getElementById('randompickall')) {
7919: if (document.getElementById('randompickall').checked) {
7920: if (document.getElementById('rpicknumall')) {
7921: rpick = document.getElementById('rpicknumall').value;
7922: }
7923: }
7924: }
7925: } else {
7926: if (document.getElementById(param+'all').checked) {
7927: setcheck = 1;
7928: }
7929: }
1.538 raeburn 7930: var allidxlist;
7931: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7932: if (document.getElementById('all'+param+'idx')) {
7933: allidxlist = document.getElementById('all'+param+'idx').value;
7934: }
7935: var actions = new Array ('remove','cut','copy');
7936: for (var i=0; i<actions.length; i++) {
7937: if (actions[i] != param) {
7938: if (document.getElementById(actions[i]+'all')) {
7939: document.getElementById(actions[i]+'all').checked = false;
7940: }
7941: }
7942: }
7943: }
1.537 raeburn 7944: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7945: allidxlist = form.allidx.value;
7946: }
7947: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7948: allidxlist = form.allmapidx.value;
7949: }
7950: if ((allidxlist != '') && (allidxlist != null)) {
7951: var allidxs = allidxlist.split(',');
7952: if (allidxs.length > 1) {
7953: for (var i=0; i<allidxs.length; i++) {
7954: if (document.getElementById(param+'_'+allidxs[i])) {
7955: if (param == 'rpicknum') {
7956: if (document.getElementById('randompick_'+allidxs[i])) {
7957: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7958: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7959: if (rpick > 0) {
7960: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7961: } else {
7962: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7963: }
7964: }
7965: }
7966: } else {
1.537 raeburn 7967: if (setcheck == 1) {
7968: document.getElementById(param+'_'+allidxs[i]).checked = true;
7969: } else {
7970: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7971: if (param == 'randompick') {
7972: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7973: }
1.537 raeburn 7974: }
7975: }
7976: }
7977: }
1.538 raeburn 7978: if (setcheck == 1) {
7979: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7980: var actions = new Array('copy','cut','remove');
7981: for (var i=0; i<actions.length; i++) {
7982: var otheractions;
7983: var otheridxs;
7984: if (actions[i] === param) {
7985: continue;
7986: } else {
7987: if (document.getElementById('all'+actions[i]+'idx')) {
7988: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7989: otheridxs = otheractions.split(',');
7990: if (otheridxs.length > 1) {
7991: for (var j=0; j<otheridxs.length; j++) {
7992: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7993: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7994: }
1.537 raeburn 7995: }
7996: }
7997: }
1.538 raeburn 7998: }
7999: }
8000: }
8001: }
8002: }
8003: }
8004: }
8005: return;
8006: }
8007:
1.603 raeburn 8008: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 8009: var canedit = '$canedit';
8010: if (canedit == '') {
8011: alert("$js_lt{'edri'}");
8012: return;
8013: }
1.539 raeburn 8014: var dosettings;
8015: var doaction;
1.538 raeburn 8016: var control = document.togglemultsettings;
8017: if (context == 'actions') {
8018: control = document.togglemultactions;
1.539 raeburn 8019: doaction = 1;
8020: } else {
8021: dosettings = 1;
1.538 raeburn 8022: }
1.539 raeburn 8023: if (control) {
8024: if (control.showmultpick.length) {
8025: for (var i=0; i<control.showmultpick.length; i++) {
8026: if (control.showmultpick[i].checked) {
8027: if (control.showmultpick[i].value == 1) {
8028: if (context == 'settings') {
8029: dosettings = 0;
8030: } else {
8031: doaction = 0;
1.538 raeburn 8032: }
8033: }
8034: }
1.537 raeburn 8035: }
8036: }
1.539 raeburn 8037: }
8038: if (context == 'settings') {
8039: if (dosettings == 1) {
1.538 raeburn 8040: targetform.changeparms.value=param;
8041: targetform.submit();
8042: }
1.537 raeburn 8043: }
1.539 raeburn 8044: if (context == 'actions') {
8045: if (doaction == 1) {
8046: targetform.cmd.value=param+'_'+index;
8047: targetform.folderpath.value=folderpath;
8048: targetform.markcopy.value=idx+':'+param;
8049: targetform.copyfolder.value=folder+'.'+container;
8050: if (param == 'remove') {
1.603 raeburn 8051: var doremove = 0;
8052: if (skip_confirm) {
8053: if (confirm_removal) {
8054: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8055: doremove = 1;
8056: }
8057: } else {
8058: doremove = 1;
8059: }
8060: } else {
8061: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8062: doremove = 1;
8063: }
8064: }
8065: if (doremove) {
1.539 raeburn 8066: targetform.markcopy.value='';
8067: targetform.copyfolder.value='';
8068: targetform.submit();
8069: }
8070: }
8071: if (param == 'cut') {
1.594 damieng 8072: 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 8073: targetform.submit();
8074: return;
8075: }
8076: }
8077: if (param == 'copy') {
8078: targetform.submit();
8079: return;
8080: }
8081: targetform.markcopy.value='';
8082: targetform.copyfolder.value='';
8083: targetform.cmd.value='';
8084: targetform.folderpath.value='';
8085: return;
8086: } else {
8087: if (document.getElementById(param+'_'+idx)) {
8088: item = document.getElementById(param+'_'+idx);
8089: if (item.type == 'checkbox') {
8090: if (item.checked) {
8091: item.checked = false;
8092: } else {
8093: item.checked = true;
8094: singleCheck(item,idx,param);
8095: }
8096: }
8097: }
8098: }
8099: }
1.537 raeburn 8100: return;
8101: }
8102:
1.538 raeburn 8103: function singleCheck(caller,idx,action) {
8104: actions = new Array('cut','copy','remove');
8105: if (caller.checked) {
8106: for (var i=0; i<actions.length; i++) {
8107: if (actions[i] != action) {
8108: if (document.getElementById(actions[i]+'_'+idx)) {
8109: if (document.getElementById(actions[i]+'_'+idx).checked) {
8110: document.getElementById(actions[i]+'_'+idx).checked = false;
8111: }
1.537 raeburn 8112: }
8113: }
8114: }
1.478 raeburn 8115: }
1.537 raeburn 8116: return;
1.478 raeburn 8117: }
8118:
1.334 muellerd 8119: function unselectInactive(nav) {
1.335 ehlerst 8120: currentNav = document.getElementById(nav);
8121: currentLis = currentNav.getElementsByTagName('LI');
8122: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8123: if (currentLis[i].className == 'goback') {
8124: currentLis[i].className = 'goback';
8125: } else {
8126: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8127: currentLis[i].className = 'right';
1.472 raeburn 8128: } else {
1.374 tempelho 8129: currentLis[i].className = 'i';
1.472 raeburn 8130: }
8131: }
1.335 ehlerst 8132: }
1.332 tempelho 8133: }
8134:
1.334 muellerd 8135: function hideAll(current, nav, data) {
1.335 ehlerst 8136: unselectInactive(nav);
1.570 raeburn 8137: if (current) {
8138: if (current.className == 'right'){
8139: current.className = 'right active'
8140: } else {
8141: current.className = 'active';
8142: }
1.374 tempelho 8143: }
1.335 ehlerst 8144: currentData = document.getElementById(data);
8145: currentDivs = currentData.getElementsByTagName('DIV');
8146: for (i = 0; i < currentDivs.length; i++) {
8147: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8148: currentDivs[i].style.display = 'none';
1.330 tempelho 8149: }
8150: }
1.335 ehlerst 8151: }
1.330 tempelho 8152:
1.374 tempelho 8153: function openTabs(pageId) {
8154: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8155: if(tabnav.length > 2 ){
1.389 tempelho 8156: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8157: currentLis = currentNav.getElementsByTagName('LI');
8158: for(i = 0; i< currentLis.length; i++){
8159: if(currentLis[i].className == 'active') {
1.375 tempelho 8160: funcString = currentLis[i].onclick.toString();
8161: tab = funcString.split('"');
1.420 onken 8162: if(tab.length < 2) {
8163: tab = funcString.split("'");
8164: }
1.375 tempelho 8165: currentData = document.getElementById(tab[1]);
8166: currentData.style.display = 'block';
1.374 tempelho 8167: }
8168: }
8169: }
8170: }
8171:
1.334 muellerd 8172: function showPage(current, pageId, nav, data) {
1.570 raeburn 8173: currstate = current.className;
1.334 muellerd 8174: hideAll(current, nav, data);
1.375 tempelho 8175: openTabs(pageId);
1.334 muellerd 8176: unselectInactive(nav);
1.570 raeburn 8177: if ((currstate == 'active') || (currstate == 'right active')) {
8178: if (currstate == 'active') {
8179: current.className = '';
8180: } else {
8181: current.className = 'right';
8182: }
8183: activeTab = '';
1.656 raeburn 8184: toggleExternal();
1.570 raeburn 8185: toggleUpload();
8186: toggleMap();
1.606 raeburn 8187: toggleCrsRes();
8188: toggleImportCrsres();
1.570 raeburn 8189: resize_scrollbox('contentscroll','1','0');
8190: return;
8191: } else {
8192: current.className = 'active';
8193: }
1.330 tempelho 8194: currentData = document.getElementById(pageId);
8195: currentData.style.display = 'block';
1.458 raeburn 8196: activeTab = pageId;
1.656 raeburn 8197: toggleExternal();
1.501 raeburn 8198: toggleUpload();
1.503 raeburn 8199: toggleMap();
1.606 raeburn 8200: toggleCrsRes();
8201: toggleImportCrsres();
1.433 raeburn 8202: if (nav == 'mainnav') {
8203: var storedpath = "$docs_folderpath";
1.434 raeburn 8204: var storedpage = "$main_container_page";
1.433 raeburn 8205: var reg = new RegExp("^supplemental");
8206: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8207: if (storedpage == 1) {
8208: document.simpleedit.folderpath.value = '';
8209: document.uploaddocument.folderpath.value = '';
8210: } else {
8211: if (reg.test(storedpath)) {
8212: document.simpleedit.folderpath.value = '$toplevelmain';
8213: document.uploaddocument.folderpath.value = '$toplevelmain';
8214: document.newext.folderpath.value = '$toplevelmain';
8215: } else {
8216: document.simpleedit.folderpath.value = storedpath;
8217: document.uploaddocument.folderpath.value = storedpath;
8218: document.newext.folderpath.value = storedpath;
8219: }
1.433 raeburn 8220: }
8221: } else {
1.434 raeburn 8222: if (reg.test(storedpath)) {
8223: document.simpleedit.folderpath.value = storedpath;
8224: document.supuploaddocument.folderpath.value = storedpath;
8225: document.supnewext.folderpath.value = storedpath;
8226: } else {
1.433 raeburn 8227: document.simpleedit.folderpath.value = '$toplevelsupp';
8228: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8229: document.supnewext.folderpath.value = '$toplevelsupp';
8230: }
8231: }
8232: }
1.485 raeburn 8233: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8234: return false;
8235: }
1.329 droeschl 8236:
1.472 raeburn 8237: function toContents(jumpto) {
8238: var newurl = '$backtourl';
1.525 raeburn 8239: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8240: newurl = newurl+'?postdata='+jumpto;
8241: }
8242: location.href=newurl;
8243: }
8244:
1.538 raeburn 8245: function togglePick(caller,value) {
8246: var disp = 'none';
8247: if (document.getElementById('multi'+caller)) {
8248: var curr = document.getElementById('multi'+caller).style.display;
8249: if (value == 1) {
8250: disp='block';
8251: }
8252: if (curr == disp) {
8253: return;
8254: }
8255: document.getElementById('multi'+caller).style.display=disp;
8256: if (value == 1) {
1.594 damieng 8257: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8258: } else {
8259: document.getElementById('more'+caller).innerHTML = '';
8260: }
8261: if (caller == 'actions') {
8262: setClass(value);
8263: setBoxes(value);
8264: }
8265: }
8266: var showButton = multiSettings();
8267: if (showButton != 1) {
8268: showButton = multiActions();
8269: }
8270: if (document.getElementById('multisave')) {
8271: if (showButton == 1) {
8272: document.getElementById('multisave').style.display='block';
8273: } else {
8274: document.getElementById('multisave').style.display='none';
8275: }
8276: }
8277: resize_scrollbox('contentscroll','1','1');
8278: return;
8279: }
8280:
8281: function toggleCheckUncheck(caller,more) {
8282: if (more == 1) {
1.594 damieng 8283: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8284: document.getElementById('allfields'+caller).style.display='block';
8285: } else {
1.594 damieng 8286: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8287: document.getElementById('allfields'+caller).style.display='none';
8288: }
8289: resize_scrollbox('contentscroll','1','1');
8290: }
8291:
8292: function multiSettings() {
8293: var inuse = 0;
8294: var settingsform = document.togglemultsettings;
8295: if (settingsform.showmultpick.length > 1) {
8296: for (var i=0; i<settingsform.showmultpick.length; i++) {
8297: if (settingsform.showmultpick[i].checked) {
8298: if (settingsform.showmultpick[i].value == 1) {
8299: inuse = 1;
8300: }
8301: }
8302: }
8303: }
8304: return inuse;
8305: }
8306:
8307: function multiActions() {
8308: var inuse = 0;
8309: var actionsform = document.togglemultactions;
8310: if (actionsform.showmultpick.length > 1) {
8311: for (var i=0; i<actionsform.showmultpick.length; i++) {
8312: if (actionsform.showmultpick[i].checked) {
8313: if (actionsform.showmultpick[i].value == 1) {
8314: inuse = 1;
8315: }
8316: }
8317: }
8318: }
8319: return inuse;
8320: }
8321:
8322: function checkSubmits() {
8323: var numchanges = 0;
8324: var form = document.saveactions;
8325: var doactions = multiActions();
1.542 raeburn 8326: var cutwarnings = 0;
8327: var remwarnings = 0;
1.603 raeburn 8328: var removalinfo = 0;
1.538 raeburn 8329: if (doactions == 1) {
8330: var remidxlist = document.cumulativeactions.allremoveidx.value;
8331: if ((remidxlist != '') && (remidxlist != null)) {
8332: var remidxs = remidxlist.split(',');
8333: for (var i=0; i<remidxs.length; i++) {
8334: if (document.getElementById('remove_'+remidxs[i])) {
8335: if (document.getElementById('remove_'+remidxs[i]).checked) {
8336: form.multiremove.value += remidxs[i]+',';
8337: numchanges ++;
1.542 raeburn 8338: if (document.getElementById('skip_remove_'+remidxs[i])) {
8339: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8340: remwarnings ++;
8341: }
8342: }
1.603 raeburn 8343: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8344: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8345: removalinfo ++;
8346: }
8347: }
1.537 raeburn 8348: }
8349: }
1.538 raeburn 8350: }
8351: }
8352: var cutidxlist = document.cumulativeactions.allcutidx.value;
8353: if ((cutidxlist != '') && (cutidxlist != null)) {
8354: var cutidxs = cutidxlist.split(',');
8355: for (var i=0; i<cutidxs.length; i++) {
8356: if (document.getElementById('cut_'+cutidxs[i])) {
8357: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8358: form.multicut.value += cutidxs[i]+',';
8359: numchanges ++;
1.542 raeburn 8360: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8361: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8362: cutwarnings ++;
8363: }
8364: }
1.537 raeburn 8365: }
8366: }
8367: }
8368: }
1.538 raeburn 8369: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8370: if ((copyidxlist != '') && (copyidxlist != null)) {
8371: var copyidxs = copyidxlist.split(',');
8372: for (var i=0; i<copyidxs.length; i++) {
8373: if (document.getElementById('copy_'+copyidxs[i])) {
8374: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8375: form.multicopy.value += copyidxs[i]+',';
8376: numchanges ++;
8377: }
8378: }
8379: }
8380: }
8381: if (numchanges > 0) {
8382: form.multichange.value = numchanges;
8383: }
1.537 raeburn 8384: }
1.538 raeburn 8385: var dosettings = multiSettings();
1.543 raeburn 8386: var haschanges = 0;
1.538 raeburn 8387: if (dosettings == 1) {
8388: form.allencrypturl.value = '';
8389: form.allhiddenresource.value = '';
1.543 raeburn 8390: form.changeparms.value = 'all';
8391: var patt=new RegExp(",\$");
1.538 raeburn 8392: var allidxlist = document.cumulativesettings.allidx.value;
8393: if ((allidxlist != '') && (allidxlist != null)) {
8394: var allidxs = allidxlist.split(',');
8395: if (allidxs.length > 1) {
8396: for (var i=0; i<allidxs.length; i++) {
8397: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8398: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8399: form.allhiddenresource.value += allidxs[i]+',';
8400: }
8401: }
8402: if (document.getElementById('encrypturl_'+allidxs[i])) {
8403: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8404: form.allencrypturl.value += allidxs[i]+',';
8405: }
8406: }
8407: }
1.543 raeburn 8408: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8409: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8410: }
1.538 raeburn 8411: }
8412: form.allrandompick.value = '';
8413: form.allrandomorder.value = '';
8414: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8415: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8416: var allmapidxs = allmapidxlist.split(',');
8417: for (var i=0; i<allmapidxs.length; i++) {
8418: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8419: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8420: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8421: if ((randompick.checked) && (rpicknum.value != '')) {
8422: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8423: }
8424: if (randorder.checked) {
8425: form.allrandomorder.value += allmapidxs[i]+',';
8426: }
1.537 raeburn 8427: }
1.543 raeburn 8428: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8429: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8430: }
8431: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8432: haschanges = 1;
8433: }
8434: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8435: haschanges = 1;
8436: }
8437: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8438: haschanges = 1;
8439: }
8440: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8441: haschanges = 1;
1.537 raeburn 8442: }
8443: }
1.543 raeburn 8444: if (doactions == 1) {
1.542 raeburn 8445: if (numchanges > 0) {
1.603 raeburn 8446: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8447: if (remwarnings > 0) {
1.594 damieng 8448: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8449: return false;
8450: }
8451: }
1.603 raeburn 8452: if (removalinfo > 0) {
8453: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8454: return false;
8455: }
8456: }
1.542 raeburn 8457: if (cutwarnings > 0) {
1.594 damieng 8458: 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 8459: return false;
8460: }
8461: }
8462: }
8463: form.submit();
8464: return true;
1.543 raeburn 8465: }
8466: }
8467: if (dosettings == 1) {
8468: if (haschanges == 1) {
1.542 raeburn 8469: form.submit();
8470: return true;
8471: }
1.543 raeburn 8472: }
8473: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8474: alert("$js_lt{'noor'}");
1.543 raeburn 8475: } else {
8476: if (dosettings == 1) {
1.594 damieng 8477: alert("$js_lt{'noch'}");
1.543 raeburn 8478: } else {
1.594 damieng 8479: alert("$js_lt{'noac'}");
1.543 raeburn 8480: }
8481: }
1.538 raeburn 8482: return false;
8483: }
8484:
8485: function setClass(value) {
8486: var cutclass = 'LC_docs_cut';
8487: var copyclass = 'LC_docs_copy';
8488: var removeclass = 'LC_docs_remove';
8489: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8490: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8491: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8492: var links = document.getElementsByTagName('a');
8493: for (var i=0; i<links.length; i++) {
8494: var classes = links[i].className;
8495: if (cutreg.test(classes)) {
8496: links[i].className = cutclass;
8497: if (value == 1) {
8498: links[i].className += " LC_menubuttons_link";
8499: }
8500: } else {
8501: if (copyreg.test(classes)) {
8502: links[i].className = copyclass;
8503: if (value == 1) {
8504: links[i].className += " LC_menubuttons_link";
8505: }
8506: } else {
8507: if (removereg.test(classes)) {
8508: links[i].className = removeclass;
8509: if (value == 1) {
8510: links[i].className += " LC_menubuttons_link";
8511: }
8512: }
8513: }
8514: }
8515: }
8516: return;
1.537 raeburn 8517: }
8518:
1.538 raeburn 8519: function setBoxes(value) {
8520: var remidxlist = document.cumulativeactions.allremoveidx.value;
8521: if ((remidxlist != '') && (remidxlist != null)) {
8522: var remidxs = remidxlist.split(',');
8523: for (var i=0; i<remidxs.length; i++) {
8524: if (document.getElementById('remove_'+remidxs[i])) {
8525: var item = document.getElementById('remove_'+remidxs[i]);
8526: if (value == 1) {
8527: item.className = 'LC_docs_remove';
8528: } else {
8529: item.className = 'LC_hidden';
8530: }
8531: }
8532: }
8533: }
8534: var cutidxlist = document.cumulativeactions.allcutidx.value;
8535: if ((cutidxlist != '') && (cutidxlist != null)) {
8536: var cutidxs = cutidxlist.split(',');
8537: for (var i=0; i<cutidxs.length; i++) {
8538: if (document.getElementById('cut_'+cutidxs[i])) {
8539: var item = document.getElementById('cut_'+cutidxs[i]);
8540: if (value == 1) {
8541: item.className = 'LC_docs_cut';
8542: } else {
8543: item.className = 'LC_hidden';
8544: }
8545: }
1.537 raeburn 8546: }
8547: }
1.538 raeburn 8548: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8549: if ((copyidxlist != '') && (copyidxlist != null)) {
8550: var copyidxs = copyidxlist.split(',');
8551: for (var i=0; i<copyidxs.length; i++) {
8552: if (document.getElementById('copy_'+copyidxs[i])) {
8553: var item = document.getElementById('copy_'+copyidxs[i]);
8554: if (value == 1) {
8555: item.className = 'LC_docs_copy';
8556: } else {
8557: item.className = 'LC_hidden';
8558: }
8559: }
1.537 raeburn 8560: }
8561: }
8562: return;
8563: }
8564:
1.606 raeburn 8565: function validImportCrsRes() {
8566: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8567: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8568: if ((fname == '') || (fname == null)) {
8569: alert("$js_lt{'nofi'}");
8570: return false;
8571: }
8572: var url = '/res/$coursedom/$coursenum/';
8573: if (path && path != '/') {
8574: url += path+'/';
8575: }
8576: if (fname != '') {
8577: url += fname;
8578: }
8579: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 8580: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 8581: return true;
8582: }
8583:
8584: function validateNewRes(caller) {
8585: if (caller == 'single') {
8586: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8587: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8588: var resname = document.courseresform.newresourcename.value;
8589: }
8590: }
8591:
1.611 raeburn 8592: ENDSCRIPT
1.329 droeschl 8593: }
1.457 raeburn 8594:
1.483 raeburn 8595: sub history_tab_js {
8596: return <<"ENDHIST";
8597: function toggleHistoryDisp(choice) {
8598: document.docslogform.docslog.value = choice;
8599: document.docslogform.submit();
8600: return;
8601: }
8602:
8603: ENDHIST
8604: }
8605:
1.484 raeburn 8606: sub inject_data_js {
8607: return <<ENDINJECT;
8608:
8609: function injectData(current, hiddenField, name, value) {
8610: currentElement = document.getElementById(hiddenField);
8611: currentElement.name = name;
8612: currentElement.value = value;
8613: current.submit();
8614: }
8615:
8616: ENDINJECT
8617: }
8618:
8619: sub dump_switchserver_js {
8620: my @hosts = @_;
1.594 damieng 8621: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8622: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8623: swit => 'Switch server?',
1.594 damieng 8624: );
8625: my %html_js_lt = &Apache::lonlocal::texthash(
8626: swit => 'Switch server?',
1.568 raeburn 8627: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8628: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8629: chos => 'Choose server',
8630: );
1.594 damieng 8631: &js_escape(\%js_lt);
8632: &html_escape(\%html_js_lt);
8633: &js_escape(\%html_js_lt);
1.484 raeburn 8634: my $role = $env{'request.role'};
8635: my $js = <<"ENDSWJS";
8636: <script type="text/javascript">
8637: function write_switchserver() {
8638: var server;
8639: if (document.setserver.posshosts.length > 0) {
8640: for (var i=0; i<document.setserver.posshosts.length; i++) {
8641: if (document.setserver.posshosts[i].checked) {
8642: server = document.setserver.posshosts[i].value;
8643: }
8644: }
8645: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8646: }
8647: window.close();
8648: }
8649: </script>
8650:
8651: ENDSWJS
8652:
8653: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8654: {'only_body' => 1,
8655: 'js_ready' => 1,});
8656: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8657:
8658: my $hostpicker;
8659: my $count = 0;
8660: foreach my $host (sort(@hosts)) {
8661: my $checked;
8662: if ($count == 0) {
8663: $checked = ' checked="checked"';
8664: }
8665: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8666: $host.'"'.$checked.' />'.$host.'</label> ';
8667: $count++;
8668: }
8669:
8670: return <<"ENDSWITCHJS";
8671:
8672: function dump_needs_switchserver(url) {
8673: if (url!='' && url!= null) {
1.594 damieng 8674: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8675: go(url);
8676: }
8677: }
8678: return;
8679: }
8680:
8681: function choose_switchserver_window() {
8682: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8683: newWindow.document.open();
8684: newWindow.document.writeln('$startpage');
1.594 damieng 8685: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8686: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8687: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8688: '<form name="setserver" method="post" action="" \\/>\\n'+
8689: '$hostpicker\\n'+
8690: '<br \\/><br \\/>\\n'+
1.594 damieng 8691: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8692: 'onclick="write_switchserver();" \\/>\\n'+
8693: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8694: newWindow.document.writeln('$endpage');
8695: newWindow.document.close();
8696: newWindow.focus();
8697: }
8698:
8699: ENDSWITCHJS
8700: }
8701:
8702: sub makedocslogform {
8703: my ($formelems,$docslog) = @_;
8704: return <<"LOGSFORM";
8705: <form action="/adm/coursedocs" method="post" name="docslogform">
8706: <input type="hidden" name="docslog" value="$docslog" />
8707: $formelems
8708: </form>
8709: LOGSFORM
8710: }
8711:
8712: sub makesimpleeditform {
8713: my ($formelems) = @_;
8714: return <<"SIMPFORM";
8715: <form name="simpleedit" method="post" action="/adm/coursedocs">
8716: <input type="hidden" name="importdetail" value="" />
8717: $formelems
8718: </form>
8719: SIMPFORM
8720: }
8721:
1.606 raeburn 8722: sub makenewproblem {
8723: my ($r,$coursedom,$coursenum) = @_;
8724: # Creating a new problem
8725: my ($redirect,$error);
8726: if ($env{'form.authorrole'}) {
8727: my ($newsubdir,$filename);
8728: if ($env{'form.newsubdir'}) {
8729: if ($env{'form.newsubdirname'} ne '') {
8730: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 8731: }
1.606 raeburn 8732: }
8733: if ($env{'form.newresourcename'}) {
8734: $filename = $env{'form.newresourcename'};
8735: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8736: $filename =~ s/`//g;
8737: $filename =~ s{/\.\./}{_}g;
8738: $filename =~ s/\.+/./g;
8739: $filename =~ s{/+}{_}g;
8740: if ($filename ne '') {
8741: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8742: if (($ext) && ($ext ne '.problem')) {
8743: $filename = $name.'.problem';
8744: } elsif ($ext eq '') {
8745: $filename .= '.problem';
8746: }
8747: my $docroot = $r->dir_config('lonDocRoot');
8748: my @ids=&Apache::lonnet::current_machine_ids();
8749: if ($env{'form.authorrole'} eq 'author') {
8750: if ($env{'user.author'}) {
8751: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8752: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8753: my $path = $docroot.$url;
8754: my $subdir = $env{'form.authorpath'};
8755: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8756: }
8757: }
8758: } elsif ($env{'form.authorrole'} eq 'course') {
8759: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8760: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8761: my $url = "/priv/$coursedom/$coursenum";
8762: my $path=$docroot.$url;
8763: my $subdir = $env{'form.authorpath'};
8764: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8765: if ($redirect) {
8766: my $rightsfile = 'default.rights';
8767: my $sourcerights = "$path/$rightsfile";
8768: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8769: my $now = time;
8770: if (!-e $sourcerights) {
8771: my $cid = $coursedom.'_'.$coursenum;
8772: if (open(my $fh,">$sourcerights")) {
8773: print $fh <<END;
8774: <accessrule effect="deny" realm="" type="course" role="" />
8775: <accessrule effect="allow" realm="$cid" type="course" role="" />
8776: END
8777: close($fh);
8778: }
8779: }
8780: if (!-e "$sourcerights.meta") {
8781: if (open(my $fh,">$sourcerights.meta")) {
8782: my $author=$env{'environment.firstname'}.' '.
8783: $env{'environment.middlename'}.' '.
8784: $env{'environment.lastname'}.' '.
8785: $env{'environment.generation'};
8786: $author =~ s/\s+$//;
8787: print $fh <<"END";
8788:
8789: <abstract></abstract>
8790: <author>$author</author>
8791: <authorspace>$coursenum:$coursedom</authorspace>
8792: <copyright>private</copyright>
8793: <creationdate>$now</creationdate>
8794: <customdistributionfile></customdistributionfile>
8795: <dependencies></dependencies>
8796: <domain>$coursedom</domain>
8797: <highestgradelevel>0</highestgradelevel>
8798: <keywords></keywords>
8799: <language>notset </language>
8800: <lastrevisiondate>$now</lastrevisiondate>
8801: <lowestgradelevel>0</lowestgradelevel>
8802: <mime>rights</mime>
8803: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8804: <notes></notes>
8805: <obsolete></obsolete>
8806: <obsoletereplacement></obsoletereplacement>
8807: <owner>$coursenum:$coursedom</owner>
8808: <rule>deny:::course,allow:$cid::course</rule>
8809: <sourceavail></sourceavail>
8810: <standards></standards>
8811: <subject></subject>
8812: <title></title>
8813: END
1.654 raeburn 8814: close($fh);
8815: }
8816: }
8817: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8818: if (!-e "$docroot/res/$coursedom") {
8819: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 8820: }
1.654 raeburn 8821: if (!-e "$docroot/res/$coursedom/$coursenum") {
8822: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8823: }
8824: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8825: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8826: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 8827: }
8828: }
1.654 raeburn 8829: my $source = $docroot.$redirect;
8830: if (!-e "$source.meta") {
8831: my $cid = $coursedom.'_'.$coursenum;
8832: my $now = time;
8833: if (open(my $fh,">$source.meta")) {
8834: my $author=$env{'environment.firstname'}.' '.
8835: $env{'environment.middlename'}.' '.
8836: $env{'environment.lastname'}.' '.
8837: $env{'environment.generation'};
8838: $author =~ s/\s+$//;
8839: my $title = $env{'form.newresourcetitle'};
8840: $title =~ s/^\s+|\s+$//g;
8841: print $fh <<END;
1.606 raeburn 8842:
8843: <abstract></abstract>
8844: <author>$author</author>
8845: <authorspace>$coursenum:$coursedom</authorspace>
8846: <copyright>custom</copyright>
8847: <creationdate>$now</creationdate>
8848: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8849: <dependencies></dependencies>
8850: <domain>$coursedom</domain>
8851: <highestgradelevel>0</highestgradelevel>
8852: <keywords></keywords>
8853: <language>notset </language>
8854: <lastrevisiondate>$now</lastrevisiondate>
8855: <lowestgradelevel>0</lowestgradelevel>
8856: <mime>problem</mime>
8857: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8858: <notes></notes>
8859: <obsolete></obsolete>
8860: <obsoletereplacement></obsoletereplacement>
8861: <owner>$coursenum:$coursedom</owner>
8862: <sourceavail></sourceavail>
8863: <standards></standards>
8864: <subject></subject>
8865: <title>$title</title>
8866: END
1.654 raeburn 8867: close($fh);
1.606 raeburn 8868: }
8869: }
8870: }
8871: }
8872: } else {
8873: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8874: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8875: if (grep(/^\Q$rolehome\E$/,@ids)) {
8876: my $now = time;
8877: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8878: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8879: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8880: my $url = "/priv/$audom/$auname";
8881: my $path = $r->dir_config('lonDocRoot').$url;
8882: my $subdir = $env{'form.authorpath'};
8883: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8884: }
8885: }
8886: }
8887: }
8888: }
8889: }
8890: }
8891: return ($redirect,$error);
8892: }
8893:
8894: sub finishnewprob {
1.654 raeburn 8895: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 8896: unless (-d $path) {
8897: unless (mkdir($path,02770)) {
8898: return;
8899: }
8900: }
1.606 raeburn 8901: my $redirect;
8902: if ($subdir ne '/') {
8903: $subdir = &cleandir($subdir);
8904: if (($subdir ne '') && (-d "$path/$subdir")) {
8905: $path .= "/$subdir";
8906: $url .= "/$subdir";
8907: }
8908: }
8909: my $dest;
8910: if ($newsubdir ne '') {
8911: $newsubdir = &cleandir($newsubdir);
8912: }
8913: if ($newsubdir ne '') {
8914: if (-d "$path/$newsubdir") {
8915: $dest = "$path/$newsubdir/$filename";
8916: } else {
8917: my $dirok;
8918: unless (-e "$path/$newsubdir") {
8919: if (mkdir("$path/$newsubdir",02770)) {
8920: if (chmod(02770,"$path/$newsubdir")) {
8921: $dirok = 1;
8922: }
8923: }
8924: }
8925: if ($dirok) {
8926: $dest = "$path/$newsubdir/$filename";
8927: }
8928: }
8929: if (($dest ne '') && (!-e $dest)) {
8930: $redirect = "$url/$newsubdir/$filename";
8931: }
8932: } else {
8933: $dest = "$path/$filename";
8934: if (($dest ne '') && (!-e $dest)) {
8935: $redirect = "$url/$filename";
8936: }
8937: }
1.654 raeburn 8938: if ((!-e $dest) && ($context ne 'upload')) {
8939: my $template = $env{'form.template'};
8940: my $copyfrom;
8941: if ($template ne '') {
8942: my %templates;
8943: my @files = &Apache::lonhomework::get_template_list('problem');
8944: foreach my $poss (@files) {
8945: if (ref($poss) eq 'ARRAY') {
8946: if ($template eq $poss->[0]) {
8947: $templates{$template} = 1;
8948: last;
8949: }
8950: }
8951: }
8952: if ($templates{$template}) {
8953: $copyfrom = $template;
8954: }
8955: }
8956: if ($filename =~ /\.problem$/) {
8957: unless ($copyfrom) {
8958: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
8959: }
8960: &File::Copy::copy($copyfrom,$dest);
8961: }
8962: }
1.606 raeburn 8963: return $redirect;
8964: }
8965:
8966: sub cleandir {
8967: my ($dir) = @_;
8968: $dir =~ s/^\s+//;
8969: $dir =~ s/\s+$//;
8970: $dir =~ s/\.+//g;
8971: $dir =~ s/[\#\?&%\":]//g;
8972: return $dir;
8973: }
8974:
1.329 droeschl 8975: 1;
8976: __END__
8977:
8978:
8979: =head1 NAME
8980:
8981: Apache::londocs.pm
8982:
8983: =head1 SYNOPSIS
8984:
8985: This is part of the LearningOnline Network with CAPA project
8986: described at http://www.lon-capa.org.
8987:
8988: =head1 SUBROUTINES
8989:
8990: =over
8991:
8992: =item %help=()
8993:
8994: Available help topics
8995:
8996: =item mapread()
8997:
1.344 bisitz 8998: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8999: @order and @resources, determines status
9000: sets @order - pointer to resources in right order
9001: sets @resources - array with the resources with correct idx
9002:
9003: =item authorhosts()
9004:
9005: Return hash with valid author names
9006:
9007: =item clean()
9008:
9009: =item dumpcourse()
9010:
9011: Actually dump course
9012:
9013: =item group_import()
9014:
9015: Imports the given (name, url) resources into the course
9016: coursenum, coursedom, and folder must precede the list
9017:
9018: =item breadcrumbs()
9019:
9020: =item log_docs()
9021:
9022: =item docs_change_log()
9023:
9024: =item update_paste_buffer()
9025:
9026: =item print_paste_buffer()
9027:
9028: =item do_paste_from_buffer()
9029:
1.538 raeburn 9030: =item do_buffer_empty()
9031:
9032: =item clear_from_buffer()
9033:
1.492 raeburn 9034: =item get_newmap_url()
9035:
9036: =item dbcopy()
9037:
9038: =item uniqueness_check()
9039:
9040: =item contained_map_check()
9041:
9042: =item url_paste_fixups()
9043:
9044: =item apply_fixups()
9045:
9046: =item copy_dependencies()
9047:
1.329 droeschl 9048: =item update_parameter()
9049:
9050: =item handle_edit_cmd()
9051:
9052: =item editor()
9053:
9054: =item process_file_upload()
9055:
9056: =item process_secondary_uploads()
9057:
9058: =item is_supplemental_title()
9059:
9060: =item entryline()
9061:
9062: =item tiehash()
9063:
9064: =item untiehash()
9065:
9066: =item checkonthis()
9067:
9068: check on this
9069:
9070: =item verifycontent()
9071:
9072: Verify Content
9073:
1.636 raeburn 9074: =item devalidateversioncache()
9075:
9076: =item checkversions()
1.329 droeschl 9077:
9078: Check Versions
9079:
9080: =item mark_hash_old()
9081:
9082: =item is_hash_old()
9083:
9084: =item changewarning()
9085:
9086: =item init_breadcrumbs()
9087:
9088: Breadcrumbs for special functions
9089:
1.484 raeburn 9090: =item create_list_elements()
9091:
9092: =item create_form_ul()
9093:
9094: =item startContentScreen()
9095:
9096: =item endContentScreen()
9097:
9098: =item supplemental_base()
9099:
9100: =item embedded_form_elems()
9101:
9102: =item embedded_destination()
9103:
9104: =item return_to_editor()
9105:
9106: =item decompression_info()
9107:
9108: =item decompression_phase_one()
9109:
9110: =item decompression_phase_two()
9111:
9112: =item remove_archive()
9113:
9114: =item generate_admin_menu()
9115:
9116: =item generate_edit_table()
9117:
9118: =item editing_js()
9119:
9120: =item history_tab_js()
9121:
9122: =item inject_data_js()
9123:
9124: =item dump_switchserver_js()
9125:
1.485 raeburn 9126: =item resize_scrollbox_js()
1.484 raeburn 9127:
9128: =item makedocslogform()
9129:
1.485 raeburn 9130: =item makesimpleeditform()
9131:
1.329 droeschl 9132: =back
9133:
9134: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>