Annotation of loncom/interface/londocs.pm, revision 1.680
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.680 ! raeburn 4: # $Id: londocs.pm,v 1.679 2022/09/13 12:22:14 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) {
1498: $pasteitems .= $nopaste;
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);
2803: if ($mapcontent eq '-1') {
2804: if (ref($errors) eq 'HASH') {
2805: $errors->{$key} = 1;
2806: }
2807: } else {
2808: my $newmap =
2809: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2810: $mapcontent);
2811: if ($newmap eq '/adm/notfound.html') {
2812: if (ref($errors) eq 'HASH') {
2813: $errors->{$key} = 1;
1.489 raeburn 2814: }
1.488 raeburn 2815: }
2816: }
2817: }
1.491 raeburn 2818: my %updates;
2819: if ($is_map) {
1.529 raeburn 2820: if (ref($updated) eq 'HASH') {
2821: foreach my $type (keys(%{$updated})) {
2822: if (ref($updated->{$type}) eq 'HASH') {
2823: foreach my $key (keys(%{$updated->{$type}})) {
2824: $updates{$key} = 1;
2825: }
2826: }
2827: }
1.491 raeburn 2828: }
2829: foreach my $key (keys(%updates)) {
1.492 raeburn 2830: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2831: if (ref($rewrites{$key}) eq 'HASH') {
2832: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2833: }
1.529 raeburn 2834: if (ref($retitles{$key}) eq 'HASH') {
2835: %toretitle = %{$retitles{$key}};
1.491 raeburn 2836: }
1.529 raeburn 2837: if (ref($removefrommap{$key}) eq 'HASH') {
2838: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2839: }
1.529 raeburn 2840: if (ref($removeparam{$key}) eq 'HASH') {
2841: %remparam = %{$removeparam{$key}};
1.492 raeburn 2842: }
1.529 raeburn 2843: if (ref($zombies{$key}) eq 'HASH') {
2844: %zombie = %{$zombies{$key}};
1.491 raeburn 2845: }
1.529 raeburn 2846: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2847: foreach my $idx (keys(%{$dbcopies{$key}})) {
2848: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2849: my ($newurl,$result,$errtext) =
2850: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2851: if ($result eq 'ok') {
2852: $newdb{$idx} = $newurl;
2853: } elsif (ref($errors) eq 'HASH') {
2854: $errors->{$key} = 1;
2855: }
2856: push(@msgs,$errtext);
2857: }
1.491 raeburn 2858: }
2859: }
1.597 raeburn 2860: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 2861: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 2862: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2863: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2864: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2865: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2866: my $template = $1;
2867: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2868: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2869: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2870: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 2871: unless ($gotnewmapname) {
2872: ($newmapname) = ($key =~ m{/([^/]+)$});
2873: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2874: if ($newsubdir{$key}) {
2875: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2876: }
2877: $gotnewmapname = 1;
2878: }
1.597 raeburn 2879: my $srcmapinfo = $srcfolder.':'.$idx;
2880: if ($srccontainer eq 'page') {
2881: $srcmapinfo .= ':1';
2882: }
2883: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2884: $cnum,$template,$idx,$newmapname);
2885: }
2886: }
2887: }
2888: }
2889: }
1.529 raeburn 2890: if (ref($params{$key}) eq 'HASH') {
2891: %currparam = %{$params{$key}};
1.492 raeburn 2892: }
2893: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2894: if ($fatal) {
1.533 raeburn 2895: return ($errtext);
1.492 raeburn 2896: }
2897: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2898: if (defined($LONCAPA::map::zombies[$i])) {
2899: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2900: if ($zombie{$i} eq $src) {
1.492 raeburn 2901: undef($LONCAPA::map::zombies[$i]);
2902: }
2903: }
2904: }
1.646 raeburn 2905: my $total = scalar(@LONCAPA::map::order) - 1;
2906: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 2907: my $idx = $LONCAPA::map::order[$i];
2908: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2909: my $changed;
1.529 raeburn 2910: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2911: if ((exists($toremove{$idx})) &&
2912: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2913: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2914: if (ref($currparam{$idx}) eq 'ARRAY') {
2915: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 2916: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 2917: }
2918: }
2919: next;
2920: }
2921: my $origsrc = $src;
1.532 raeburn 2922: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2923: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2924: $changed = 1;
1.491 raeburn 2925: }
1.492 raeburn 2926: }
1.532 raeburn 2927: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2928: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2929: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2930: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2931: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2932: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2933: } else {
1.529 raeburn 2934: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2935: }
1.491 raeburn 2936: }
1.532 raeburn 2937: if ($origsrc =~ /\.(page|sequence)$/) {
2938: if ($newsubdir{$origsrc}) {
1.529 raeburn 2939: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2940: }
1.532 raeburn 2941: } elsif ($newsubdir{$key}) {
2942: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2943: }
2944: }
1.492 raeburn 2945: $changed = 1;
1.533 raeburn 2946: } elsif ($newdb{$idx} ne '') {
2947: $src = $newdb{$idx};
1.492 raeburn 2948: $changed = 1;
2949: }
2950: if ($changed) {
1.538 raeburn 2951: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2952: }
2953: }
2954: }
2955: foreach my $idx (keys(%remparam)) {
2956: if (ref($remparam{$idx}) eq 'ARRAY') {
2957: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 2958: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 2959: }
2960: }
2961: }
1.533 raeburn 2962: if (values(%lockerrors) > 0) {
2963: $lockmsg = join('<br />',values(%lockerrors));
2964: }
1.491 raeburn 2965: my $storefn;
2966: if ($key eq $oldurl) {
2967: $storefn = $url;
2968: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2969: } else {
2970: $storefn = $key;
2971: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2972: if ($prefixchg && $before{'map'} && $after{'map'}) {
2973: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2974: }
1.529 raeburn 2975: if ($newsubdir{$key}) {
2976: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2977: }
1.491 raeburn 2978: }
1.492 raeburn 2979: my $report;
2980: if ($folder !~ /^supplemental/) {
2981: $report = 1;
2982: }
1.527 raeburn 2983: (my $outtext,$errtext) =
1.492 raeburn 2984: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2985: if ($errtext) {
1.529 raeburn 2986: if ($caller eq 'paste') {
1.533 raeburn 2987: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2988: }
1.491 raeburn 2989: }
2990: }
2991: }
1.533 raeburn 2992: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2993: }
2994:
2995: sub copy_dependencies {
2996: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2997: my $content;
2998: if (ref($contentref)) {
2999: $content = $$contentref;
3000: } else {
3001: $content = &Apache::lonnet::getfile($item);
3002: }
3003: unless ($content eq '-1') {
3004: my $mm = new File::MMagic;
3005: my $mimetype = $mm->checktype_contents($content);
3006: if ($mimetype eq 'text/html') {
3007: my (%allfiles,%codebase,$state);
3008: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3009: if ($res eq 'ok') {
3010: my ($numexisting,$numpathchanges,$existing);
3011: (undef,$numexisting,$numpathchanges,$existing) =
3012: &Apache::loncommon::ask_for_embedded_content(
3013: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3014: {'error_on_invalid_names' => 1,
3015: 'ignore_remote_references' => 1,
3016: 'docs_url' => $item,
3017: 'context' => 'paste'});
3018: if ($numexisting > 0) {
3019: if (ref($existing) eq 'HASH') {
3020: foreach my $dep (keys(%{$existing})) {
3021: my $depfile = $dep;
3022: unless ($depfile =~ m{^\Q$relpath\E}) {
3023: $depfile = $relpath.$dep;
3024: }
3025: my $depcontent = &Apache::lonnet::getfile($depfile);
3026: unless ($depcontent eq '-1') {
3027: my $storedep = $dep;
3028: $storedep =~ s{^\Q$relpath\E}{};
3029: my $dep_url =
3030: &Apache::lonclonecourse::writefile(
3031: $env{'request.course.id'},
3032: $storefn.$storedep,$depcontent);
3033: if ($dep_url eq '/adm/notfound.html') {
3034: if (ref($errors) eq 'HASH') {
3035: $errors->{$depfile} = 1;
3036: }
3037: } else {
3038: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3039: }
3040: }
3041: }
1.488 raeburn 3042: }
3043: }
3044: }
3045: }
3046: }
3047: return;
3048: }
3049:
1.329 droeschl 3050: my %parameter_type = ( 'randompick' => 'int_pos',
3051: 'hiddenresource' => 'string_yesno',
3052: 'encrypturl' => 'string_yesno',
3053: 'randomorder' => 'string_yesno',);
3054: my $valid_parameters_re = join('|',keys(%parameter_type));
3055: # set parameters
3056: sub update_parameter {
1.537 raeburn 3057: if ($env{'form.changeparms'} eq 'all') {
3058: my (@allidx,@allmapidx,%allchecked,%currchecked);
3059: %allchecked = (
3060: 'hiddenresource' => {},
3061: 'encrypturl' => {},
3062: 'randompick' => {},
3063: 'randomorder' => {},
3064: );
3065: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3066: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3067: if ($which eq 'randompick') {
3068: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3069: my ($res,$value) = split(/:/,$item);
3070: if ($value =~ /^\d+$/) {
3071: $allchecked{$which}{$res} = $value;
3072: }
3073: }
3074: } else {
1.539 raeburn 3075: if ($env{'form.all'.$which}) {
3076: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3077: }
1.537 raeburn 3078: }
3079: }
3080: my $haschanges = 0;
3081: foreach my $res (@LONCAPA::map::order) {
3082: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3083: $name=&LONCAPA::map::qtescape($name);
3084: $url=&LONCAPA::map::qtescape($url);
3085: next unless ($name && $url);
3086: my $is_map;
3087: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3088: $is_map = 1;
3089: }
3090: foreach my $which (keys(%allchecked)) {
3091: if (($which eq 'randompick' || $which eq 'randomorder')) {
3092: next if (!$is_map);
3093: }
3094: my $oldvalue = 0;
3095: my $newvalue = 0;
3096: if ($allchecked{$which}{$res}) {
3097: $newvalue = $allchecked{$which}{$res};
3098: }
3099: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3100: if ($which eq 'randompick') {
3101: if ($current =~ /^(\d+)$/) {
3102: $oldvalue = $1;
3103: }
3104: } else {
3105: if ($current =~ /^yes$/i) {
3106: $oldvalue = 1;
3107: }
3108: }
3109: if ($oldvalue ne $newvalue) {
3110: $haschanges = 1;
3111: if ($newvalue) {
3112: my $storeval = 'yes';
3113: if ($which eq 'randompick') {
3114: $storeval = $newvalue;
3115: }
3116: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3117: $storeval,
3118: $parameter_type{$which});
3119: &remember_parms($res,$which,'set',$storeval);
3120: } elsif ($oldvalue) {
3121: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3122: &remember_parms($res,$which,'del');
3123: }
3124: }
3125: }
3126: }
3127: return $haschanges;
3128: } else {
1.588 raeburn 3129: my $haschanges = 0;
3130: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3131:
1.537 raeburn 3132: my $which = $env{'form.changeparms'};
3133: my $idx = $env{'form.setparms'};
1.588 raeburn 3134: my $oldvalue = 0;
3135: my $newvalue = 0;
3136: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3137: if ($which eq 'randompick') {
3138: if ($current =~ /^(\d+)$/) {
3139: $oldvalue = $1;
3140: }
3141: } elsif ($current =~ /^yes$/i) {
3142: $oldvalue = 1;
3143: }
1.537 raeburn 3144: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3145: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3146: : 1;
3147: }
3148: if ($oldvalue ne $newvalue) {
3149: $haschanges = 1;
3150: if ($newvalue) {
3151: my $storeval = 'yes';
3152: if ($which eq 'randompick') {
3153: $storeval = $newvalue;
3154: }
3155: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3156: $parameter_type{$which});
3157: &remember_parms($idx,$which,'set',$storeval);
3158: } else {
3159: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3160: &remember_parms($idx,$which,'del');
3161: }
1.537 raeburn 3162: }
1.588 raeburn 3163: return $haschanges;
1.329 droeschl 3164: }
3165: }
3166:
3167: sub handle_edit_cmd {
3168: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3169: my $haschanges = 0;
1.543 raeburn 3170: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3171: return $haschanges;
1.543 raeburn 3172: }
1.329 droeschl 3173: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3174:
3175: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3176: my ($title, $url, @rrest) = split(':', $ratstr);
3177:
1.538 raeburn 3178: if ($cmd eq 'remove') {
1.329 droeschl 3179: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3180: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3181: &Apache::lonnet::removeuploadedurl($url);
3182: } else {
3183: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3184: }
3185: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3186: $haschanges = 1;
1.329 droeschl 3187: } elsif ($cmd eq 'cut') {
3188: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3189: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3190: $haschanges = 1;
1.344 bisitz 3191: } elsif ($cmd eq 'up'
1.329 droeschl 3192: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3193: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3194: $haschanges = 1;
1.329 droeschl 3195: } elsif ($cmd eq 'down'
3196: && defined($LONCAPA::map::order[$idx+1])) {
3197: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3198: $haschanges = 1;
1.329 droeschl 3199: } elsif ($cmd eq 'rename') {
3200: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3201: if ($comment=~/\S/) {
3202: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3203: $comment.':'.join(':', $url, @rrest);
3204: }
3205: # Devalidate title cache
3206: my $renamed_url=&LONCAPA::map::qtescape($url);
3207: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3208: $haschanges = 1;
3209: } elsif ($cmd eq 'setalias') {
3210: my $newvalue = $env{'form.alias'};
3211: if ($newvalue ne '') {
3212: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3213: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3214: 'string');
3215: &remember_parms($idx,'mapalias','set',$newvalue);
3216: $haschanges = 1;
3217: }
3218: }
3219: } elsif ($cmd eq 'delalias') {
3220: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3221: if ($current ne '') {
3222: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3223: &remember_parms($idx,'mapalias','del');
3224: $haschanges = 1;
3225: }
1.329 droeschl 3226: }
1.633 raeburn 3227: return $haschanges;
1.329 droeschl 3228: }
3229:
3230: sub editor {
1.458 raeburn 3231: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3232: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3233: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3234: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3235: if ($allowed) {
1.519 raeburn 3236: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3237: $is_random_order,$container) =
1.510 raeburn 3238: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3239: $r->print($breadcrumbtrail);
1.519 raeburn 3240: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3241: $container = 'page';
3242: } else {
3243: $container = 'sequence';
1.510 raeburn 3244: }
1.484 raeburn 3245:
1.525 raeburn 3246: my $jumpto;
3247:
3248: unless ($supplementalflag) {
1.546 raeburn 3249: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3250: }
1.484 raeburn 3251:
3252: unless ($allowed) {
3253: $randompick = -1;
3254: }
3255:
1.615 raeburn 3256: my ($errtext,$fatal);
3257: if (($folder eq '') && (!$supplementalflag)) {
3258: if (@LONCAPA::map::order) {
3259: undef(@LONCAPA::map::order);
3260: undef(@LONCAPA::map::resources);
3261: undef(@LONCAPA::map::resparms);
3262: undef(@LONCAPA::map::zombies);
3263: }
3264: $folder = 'default';
3265: $container = 'sequence';
3266: } else {
3267: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3268: $folder.'.'.$container);
3269: return $errtext if ($fatal);
3270: }
1.329 droeschl 3271:
3272: if ($#LONCAPA::map::order<1) {
3273: my $idx=&LONCAPA::map::getresidx();
3274: if ($idx<=0) { $idx=1; }
3275: $LONCAPA::map::order[0]=$idx;
3276: $LONCAPA::map::resources[$idx]='';
3277: }
1.364 bisitz 3278:
1.329 droeschl 3279: # ------------------------------------------------------------ Process commands
3280:
3281: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3282: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3283: # set parameters and change order
3284: &snapshotbefore();
3285:
3286: if (&update_parameter()) {
1.588 raeburn 3287: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3288: return $errtext if ($fatal);
3289: }
3290:
3291: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3292: # change order
3293: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3294: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3295:
3296: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3297: return $errtext if ($fatal);
3298: }
1.364 bisitz 3299:
1.329 droeschl 3300: if ($env{'form.pastemarked'}) {
1.491 raeburn 3301: my %paste_errors;
1.533 raeburn 3302: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3303: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3304: \%paste_errors);
1.541 raeburn 3305: if (ref($pastemsgarray) eq 'ARRAY') {
3306: if (@{$pastemsgarray} > 0) {
3307: $r->print('<p class="LC_info">'.
3308: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3309: '</p>');
3310: }
1.541 raeburn 3311: }
3312: if ($lockerror) {
3313: $r->print('<p class="LC_error">'.
3314: $lockerror.
3315: '</p>');
3316: }
3317: if ($save_error ne '') {
3318: return $save_error;
3319: }
3320: if ($paste_res) {
3321: my %errortext = &Apache::lonlocal::texthash (
3322: fail => 'Storage of folder contents failed',
3323: failread => 'Reading folder contents failed',
3324: failstore => 'Storage of folder contents failed',
3325: );
3326: if ($errortext{$paste_res}) {
3327: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3328: }
1.329 droeschl 3329: }
1.491 raeburn 3330: if (keys(%paste_errors) > 0) {
1.538 raeburn 3331: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3332: &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".
3333: '<ul>'."\n");
3334: foreach my $key (sort(keys(%paste_errors))) {
3335: $r->print('<li>'.$key.'</li>'."\n");
3336: }
3337: $r->print('</ul></p>'."\n");
3338: }
1.538 raeburn 3339: } elsif ($env{'form.clearmarked'}) {
3340: my $output = &do_buffer_empty();
3341: if ($output) {
3342: $r->print('<p class="LC_info">'.$output.'</p>');
3343: }
3344: }
1.329 droeschl 3345:
3346: $r->print($upload_output);
3347:
1.538 raeburn 3348: # Rename, cut, copy or remove a single resource
1.602 raeburn 3349: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3350: my $contentchg;
1.633 raeburn 3351: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3352: $contentchg = 1;
3353: }
3354: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3355: return $errtext if ($fatal);
3356: }
1.538 raeburn 3357:
3358: # Cut, copy and/or remove multiple resources
3359: if ($env{'form.multichange'}) {
3360: my %allchecked = (
3361: cut => {},
3362: remove => {},
3363: );
3364: my $needsupdate;
3365: foreach my $which (keys(%allchecked)) {
3366: $env{'form.multi'.$which} =~ s/,$//;
3367: if ($env{'form.multi'.$which}) {
3368: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3369: if (ref($allchecked{$which}) eq 'HASH') {
3370: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3371: }
3372: }
3373: }
3374: if ($needsupdate) {
3375: my $haschanges = 0;
3376: my %curr_groups = &Apache::longroup::coursegroups();
3377: my $total = scalar(@LONCAPA::map::order) - 1;
3378: for (my $i=$total; $i>=0; $i--) {
3379: my $res = $LONCAPA::map::order[$i];
3380: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3381: $name=&LONCAPA::map::qtescape($name);
3382: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3383: next unless $url;
1.538 raeburn 3384: my %denied =
3385: &action_restrictions($coursenum,$coursedom,$url,
3386: $env{'form.folderpath'},\%curr_groups);
3387: foreach my $which (keys(%allchecked)) {
3388: next if ($denied{$which});
3389: next unless ($allchecked{$which}{$res});
3390: if ($which eq 'remove') {
3391: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3392: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3393: &Apache::lonnet::removeuploadedurl($url);
3394: } else {
3395: &LONCAPA::map::makezombie($res);
3396: }
3397: splice(@LONCAPA::map::order,$i,1);
3398: $haschanges ++;
3399: } elsif ($which eq 'cut') {
3400: &LONCAPA::map::makezombie($res);
3401: splice(@LONCAPA::map::order,$i,1);
3402: $haschanges ++;
3403: }
3404: }
3405: }
3406: if ($haschanges) {
3407: ($errtext,$fatal) =
3408: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3409: return $errtext if ($fatal);
3410: }
3411: }
3412: }
3413:
1.329 droeschl 3414: # Group import/search
3415: if ($env{'form.importdetail'}) {
3416: my @imports;
3417: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3418: if (defined($item)) {
3419: my ($name,$url,$residx)=
1.533 raeburn 3420: map { &unescape($_); } split(/\=/,$item);
3421: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3422: my ($suffix,$errortxt,$locknotfreed) =
3423: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3424: if ($locknotfreed) {
3425: $r->print($locknotfreed);
3426: }
3427: if ($suffix) {
3428: $url =~ s/_new\./_$suffix./;
3429: } else {
3430: return $errortxt;
3431: }
1.533 raeburn 3432: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3433: my $type = $1;
3434: my ($suffix,$errortxt,$locknotfreed) =
3435: &new_timebased_suffix($coursedom,$coursenum,$type);
3436: if ($locknotfreed) {
3437: $r->print($locknotfreed);
3438: }
3439: if ($suffix) {
3440: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3441: } else {
3442: return $errortxt;
3443: }
1.626 raeburn 3444: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3445: my ($suffix,$errortxt,$locknotfreed) =
3446: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3447: if ($locknotfreed) {
3448: $r->print($locknotfreed);
3449: }
3450: if ($suffix) {
3451: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3452: } else {
3453: return $errortxt;
3454: }
1.534 raeburn 3455: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3456: if ($supplementalflag) {
3457: next unless ($1 eq 'supplemental');
3458: if ($folder eq 'supplemental') {
3459: next unless ($2 eq 'default');
3460: } else {
3461: next unless ($folder eq 'supplemental_'.$2);
3462: }
3463: } else {
3464: next unless ($1 eq 'docs');
3465: if ($folder eq 'default') {
3466: next unless ($2 eq 'default');
3467: } else {
3468: next unless ($folder eq 'default_'.$2);
3469: }
3470: }
1.504 raeburn 3471: }
1.329 droeschl 3472: push(@imports, [$name, $url, $residx]);
3473: }
3474: }
1.530 raeburn 3475: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3476: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3477: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3478: return $errtext if ($fatal);
1.529 raeburn 3479: if ($fixuperrors) {
3480: $r->print($fixuperrors);
3481: }
1.329 droeschl 3482: }
3483: # Loading a complete map
3484: if ($env{'form.loadmap'}) {
3485: if ($env{'form.importmap'}=~/\w/) {
3486: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3487: my ($title,$url,$ext,$type)=split(/\:/,$res);
3488: my $idx=&LONCAPA::map::getresidx($url);
3489: $LONCAPA::map::resources[$idx]=$res;
3490: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3491: }
3492: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3493: $folder.'.'.$container,1);
1.329 droeschl 3494: return $errtext if ($fatal);
3495: } else {
3496: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3497:
1.329 droeschl 3498: }
3499: }
3500: &log_differences($plain);
3501: }
3502: # ---------------------------------------------------------------- End commands
3503: # ---------------------------------------------------------------- Print screen
3504: my $idx=0;
3505: my $shown=0;
3506: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3507: $r->print('<div class="LC_Box">'.
1.432 raeburn 3508: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3509: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3510: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3511: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3512: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3513: '</ol>');
1.381 bisitz 3514: if ($randompick>=0) {
3515: $r->print('<p class="LC_warning">'
3516: .&mt('Caution: this folder is set to randomly pick a subset'
3517: .' of resources. Adding or removing resources from this'
3518: .' folder will change the set of resources that the'
3519: .' students see, resulting in spurious or missing credit'
3520: .' for completed problems, not limited to ones you'
3521: .' modify. Do not modify the contents of this folder if'
3522: .' it is in active student use.')
3523: .'</p>'
3524: );
3525: }
3526: if ($is_random_order) {
3527: $r->print('<p class="LC_warning">'
3528: .&mt('Caution: this folder is set to randomly order its'
3529: .' contents. Adding or removing resources from this folder'
3530: .' will change the order of resources shown.')
3531: .'</p>'
3532: );
3533: }
3534: $r->print('</div>');
1.364 bisitz 3535: }
1.381 bisitz 3536:
1.538 raeburn 3537: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3538: %filters = (
1.543 raeburn 3539: canremove => [],
3540: cancut => [],
3541: cancopy => [],
3542: hiddenresource => [],
3543: encrypturl => [],
3544: randomorder => [],
3545: randompick => [],
1.538 raeburn 3546: );
3547: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3548: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3549: foreach my $res (@LONCAPA::map::order) {
3550: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3551: $name=&LONCAPA::map::qtescape($name);
3552: $url=&LONCAPA::map::qtescape($url);
3553: unless ($name) { $name=(split(/\//,$url))[-1]; }
3554: unless ($name) { $idx++; next; }
1.537 raeburn 3555: push(@allidx,$res);
3556: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3557: push(@allmapidx,$res);
3558: }
1.617 raeburn 3559:
1.381 bisitz 3560: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3561: $coursenum,$coursedom,$crstype,
1.538 raeburn 3562: $pathitem,$supplementalflag,$container,
1.620 raeburn 3563: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622 raeburn 3564: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3565: $idx++;
3566: $shown++;
1.329 droeschl 3567: }
1.424 onken 3568: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3569:
1.538 raeburn 3570: my $need_save;
1.611 raeburn 3571: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3572: my $toolslink;
1.611 raeburn 3573: if ($allowed) {
1.544 raeburn 3574: $toolslink = '<table><tr><td>'
1.520 raeburn 3575: .&Apache::loncommon::help_open_menu('Navigation Screen',
3576: 'Navigation_Screen',undef,'RAT')
3577: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3578: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3579: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3580: .'id="LC_content_toolbar_edittoplevel" '
3581: .'class="LC_toolbarItem" '
3582: .'title="'.&mt('Supplemental Content Editor').'">'
3583: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3584: }
1.510 raeburn 3585: if ($shown) {
3586: if ($allowed) {
3587: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3588: .&Apache::loncommon::start_data_table(undef,'contentlist')
3589: .&Apache::loncommon::start_data_table_header_row()
3590: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3591: .'<th colspan="3">'.&mt('Actions').'</th>'
1.538 raeburn 3592: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3593: if ($folder !~ /^supplemental/) {
1.633 raeburn 3594: $to_show .= '<th colspan="2">'.&mt('Settings').'</th>';
1.510 raeburn 3595: }
1.537 raeburn 3596: $to_show .= &Apache::loncommon::end_data_table_header_row();
3597: if ($folder !~ /^supplemental/) {
1.538 raeburn 3598: $lists{'canhide'} = join(',',@allidx);
3599: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3600: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3601: 'randomorder','randompick');
3602: foreach my $item (@possfilters) {
1.538 raeburn 3603: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3604: if (@{$filters{$item}} > 0) {
3605: $lists{$item} = join(',',@{$filters{$item}});
3606: }
1.538 raeburn 3607: }
3608: }
1.537 raeburn 3609: if (@allidx > 0) {
3610: my $path;
3611: if ($env{'form.folderpath'}) {
1.630 raeburn 3612: $path =
1.537 raeburn 3613: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3614: }
1.538 raeburn 3615: if (@allidx > 1) {
1.630 raeburn 3616: $to_show .=
1.538 raeburn 3617: &Apache::loncommon::continue_data_table_row().
3618: '<td colspan="2"> </td>'.
3619: '<td>'.
1.611 raeburn 3620: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3621: '</td>'.
1.633 raeburn 3622: '<td colspan="3"> </td>'.
3623: '<td colspan="2">'.
1.611 raeburn 3624: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3625: '</td>'.
3626: &Apache::loncommon::end_data_table_row();
3627: $need_save = 1;
3628: }
1.537 raeburn 3629: }
3630: }
3631: $to_show .= $output.' '
1.510 raeburn 3632: .&Apache::loncommon::end_data_table()
3633: .'<br style="line-height:2px;" />'
3634: .&Apache::loncommon::end_scrollbox();
3635: } else {
1.520 raeburn 3636: $to_show .= $toolslink
1.510 raeburn 3637: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3638: .$output.' '
3639: .&Apache::loncommon::end_data_table();
1.393 raeburn 3640: }
1.510 raeburn 3641: } else {
1.520 raeburn 3642: if (!$allowed) {
3643: $to_show .= $toolslink;
3644: }
1.615 raeburn 3645: my $noresmsg;
3646: if ($allowed && $hiddentop && !$supplementalflag) {
3647: $noresmsg = &mt('Main Content Hidden');
3648: } else {
3649: $noresmsg = &mt('Currently empty');
3650: }
1.510 raeburn 3651: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3652: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3653: .$noresmsg
1.510 raeburn 3654: .'</div>'
3655: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3656: }
3657: } else {
1.510 raeburn 3658: if ($shown) {
3659: $to_show = '<div>'
3660: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3661: .$output
3662: .&Apache::loncommon::end_data_table()
3663: .'</div>';
3664: } else {
3665: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3666: .&mt('Currently empty')
1.510 raeburn 3667: .'</div>'
3668: }
1.458 raeburn 3669: }
3670: my $tid = 1;
3671: if ($supplementalflag) {
3672: $tid = 2;
1.329 droeschl 3673: }
3674: if ($allowed) {
1.484 raeburn 3675: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3676: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3677: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3678: if ($canedit) {
3679: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3680: }
1.460 raeburn 3681: } else {
3682: $r->print($to_show);
1.329 droeschl 3683: }
3684: return;
3685: }
3686:
1.538 raeburn 3687: sub multiple_check_form {
1.611 raeburn 3688: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3689: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3690: my $disabled;
3691: unless ($canedit) {
3692: $disabled = 'disabled="disabled"';
3693: }
1.538 raeburn 3694: my $output =
3695: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3696: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3697: '<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>'.
3698: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3699: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3700: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3701: if ($caller eq 'settings') {
3702: $output .=
3703: '<table><tr>'.
3704: '<td class="LC_docs_entry_parameter">'.
3705: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3706: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3707: '</label></span></td>'.
3708: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3709: '<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 3710: '</span></td>'.
3711: '</tr>'."\n".
3712: '<tr>'.
3713: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3714: '<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 3715: '</label></span>'.
3716: '</td></tr></table>'."\n";
3717: } else {
3718: $output .=
3719: '<table><tr>'.
3720: '<td class="LC_docs_entry_parameter">'.
3721: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3722: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3723: '</label></span></td>'.
3724: '<td class="LC_docs_entry_parameter">'.
3725: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3726: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3727: '</label></span></td>'."\n".
3728: '<td class="LC_docs_entry_parameter">'.
3729: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3730: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3731: '</label></span></td>'.
3732: '</tr></table>'."\n";
3733: }
3734: $output .=
3735: '</fieldset>'.
3736: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3737: if ($caller eq 'settings') {
3738: $output .=
1.543 raeburn 3739: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3740: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3741: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3742: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3743: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3744: } elsif ($caller eq 'actions') {
3745: $output .=
3746: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3747: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3748: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3749: }
3750: $output .=
3751: '</form>'.
3752: '</div>';
3753: return $output;
3754: }
3755:
1.329 droeschl 3756: sub process_file_upload {
1.552 raeburn 3757: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3758: # upload a file, if present
1.552 raeburn 3759: my $filesize = length($env{'form.uploaddoc'});
3760: if (!$filesize) {
3761: $$upload_output = '<div class="LC_error">'.
3762: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3763: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3764: $filesize).'<br />'.
3765: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3766: '</div>';
3767: return;
3768: }
3769: my $quotatype = 'unofficial';
3770: if ($crstype eq 'Community') {
1.601 raeburn 3771: $quotatype = 'community';
3772: } elsif ($crstype eq 'Placement') {
3773: $quotatype = 'placement';
1.580 raeburn 3774: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3775: $quotatype = 'official';
1.573 raeburn 3776: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3777: $quotatype = 'textbook';
1.552 raeburn 3778: }
3779: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3780: $filesize = int($filesize/1000); #expressed in kb
3781: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3782: $env{'form.uploaddoc.filename'},$filesize,
3783: 'upload',$quotatype);
1.552 raeburn 3784: return if ($$upload_output);
3785: }
1.440 raeburn 3786: my ($parseaction,$showupload,$nextphase,$mimetype);
3787: if ($env{'form.parserflag'}) {
1.329 droeschl 3788: $parseaction = 'parse';
3789: }
3790: my $folder=$env{'form.folder'};
3791: if ($folder eq '') {
3792: $folder='default';
3793: }
3794: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3795: my $errtext='';
3796: my $fatal=0;
3797: my $container='sequence';
1.519 raeburn 3798: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3799: $container='page';
3800: }
3801: ($errtext,$fatal)=
1.534 raeburn 3802: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3803: if ($#LONCAPA::map::order<1) {
3804: $LONCAPA::map::order[0]=1;
3805: $LONCAPA::map::resources[1]='';
3806: }
3807: my $destination = 'docs/';
3808: if ($folder =~ /^supplemental/) {
3809: $destination = 'supplemental/';
3810: }
3811: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3812: $destination .= 'default/';
3813: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3814: $destination .= $2.'/';
3815: }
1.534 raeburn 3816: if ($fatal) {
3817: $$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>';
3818: return;
3819: }
1.440 raeburn 3820: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3821: my $newidx=&LONCAPA::map::getresidx();
3822: $destination .= $newidx;
1.439 raeburn 3823: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3824: $parseaction,$allfiles,
1.440 raeburn 3825: $codebase,undef,undef,undef,undef,
3826: undef,undef,\$mimetype);
3827: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3828: my $stored = $1;
3829: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3830: $stored.'</span>').'</p>';
3831: } else {
3832: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3833:
1.457 raeburn 3834: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3835: return;
3836: }
1.329 droeschl 3837: my $ext='false';
3838: if ($url=~m{^http://}) { $ext='true'; }
3839: $url = &LONCAPA::map::qtunescape($url);
3840: my $comment=$env{'form.comment'};
3841: $comment = &LONCAPA::map::qtunescape($comment);
3842: if ($folder=~/^supplemental/) {
3843: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3844: $env{'user.domain'}.'___&&&___'.$comment;
3845: }
3846:
3847: $LONCAPA::map::resources[$newidx]=
3848: $comment.':'.$url.':'.$ext.':normal:res';
3849: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3850: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3851: $folder.'.'.$container,1);
1.329 droeschl 3852: if ($fatal) {
1.457 raeburn 3853: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3854: return;
1.329 droeschl 3855: } else {
1.440 raeburn 3856: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3857: $$upload_output = $showupload;
1.384 raeburn 3858: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3859: if ($total_embedded > 0) {
1.440 raeburn 3860: my $uploadphase = 'upload_embedded';
3861: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3862: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3863: my ($embedded,$num) =
1.440 raeburn 3864: &Apache::loncommon::ask_for_embedded_content(
3865: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3866: if ($embedded) {
3867: if ($num) {
3868: $$upload_output .=
3869: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3870: $nextphase = $uploadphase;
3871: } else {
3872: $$upload_output .= $embedded;
3873: }
3874: } else {
3875: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3876: }
1.329 droeschl 3877: } else {
1.440 raeburn 3878: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3879: }
1.457 raeburn 3880: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3881: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3882: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3883: $nextphase = 'decompress_uploaded';
3884: my $position = scalar(@LONCAPA::map::order)-1;
3885: my $noextract = &return_to_editor();
3886: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3887: my %archiveitems = (
3888: folderpath => $env{'form.folderpath'},
3889: cmd => $nextphase,
3890: newidx => $newidx,
3891: position => $position,
3892: phase => $nextphase,
1.477 raeburn 3893: comment => $comment,
1.480 raeburn 3894: );
3895: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3896: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3897: $$upload_output = $showupload.
3898: &Apache::loncommon::decompress_form($mimetype,
3899: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3900: \%archiveitems,\@current);
1.329 droeschl 3901: }
3902: }
3903: }
1.440 raeburn 3904: return $nextphase;
1.329 droeschl 3905: }
3906:
1.480 raeburn 3907: sub get_dir_list {
3908: my ($url,$coursenum,$coursedom,$newidx) = @_;
3909: my ($destination,$dir_root) = &embedded_destination();
3910: my ($dirlistref,$listerror) =
3911: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3912: my @dir_lines;
3913: my $dirptr=16384;
3914: if (ref($dirlistref) eq 'ARRAY') {
3915: foreach my $dir_line (sort
3916: {
3917: my ($afile)=split('&',$a,2);
3918: my ($bfile)=split('&',$b,2);
3919: return (lc($afile) cmp lc($bfile));
3920: } (@{$dirlistref})) {
3921: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3922: $filename =~ s/\s+$//;
3923: next if ($filename =~ /^\.\.?$/);
3924: my $isdir = 0;
3925: if ($dirptr&$testdir) {
3926: $isdir = 1;
3927: }
3928: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3929: }
3930: }
3931: return @dir_lines;
3932: }
3933:
1.329 droeschl 3934: sub is_supplemental_title {
3935: my ($title) = @_;
3936: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3937: }
3938:
3939: # --------------------------------------------------------------- An entry line
3940:
3941: sub entryline {
1.501 raeburn 3942: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3943: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622 raeburn 3944: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581 raeburn 3945: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3946: if (&is_supplemental_title($title)) {
1.488 raeburn 3947: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3948: } else {
3949: $title=&HTML::Entities::encode($title,'"<>&\'');
3950: $renametitle=$title;
3951: $foldertitle=$title;
3952: }
3953:
1.611 raeburn 3954: my ($disabled,$readonly,$js_lt);
3955: unless ($canedit) {
3956: $disabled = 'disabled="disabled"';
3957: $readonly = 1;
3958: }
3959:
1.329 droeschl 3960: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3961:
1.329 droeschl 3962: $renametitle=~s/\\/\\\\/g;
3963: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3964: $renametitle=~s/"/%22/g;
1.581 raeburn 3965: $renametitle=~s/ /%20/g;
3966: $oldtitle = $renametitle;
1.576 raeburn 3967: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3968: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3969: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3970: # Edit commands
1.679 raeburn 3971: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 3972: if ($env{'form.folderpath'}) {
3973: $esc_path=&escape($env{'form.folderpath'});
3974: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3975: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3976: }
1.505 raeburn 3977: my $isexternal;
1.510 raeburn 3978: if ($residx) {
1.501 raeburn 3979: my $currurl = $url;
3980: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3981: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3982: $isexternal = 1;
3983: }
1.510 raeburn 3984: if (!$supplementalflag) {
3985: my $path = 'uploaded/'.
3986: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3987: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3988: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3989: $residx,
3990: &Apache::lonnet::declutter($currurl));
3991: }
1.501 raeburn 3992: }
1.538 raeburn 3993: my ($renamelink,%lt,$ishash);
3994: if (ref($filtersref) eq 'HASH') {
3995: $ishash = 1;
3996: }
3997:
1.329 droeschl 3998: if ($allowed) {
1.538 raeburn 3999: $form_start = '
4000: <form action="/adm/coursedocs" method="post">
4001: ';
4002: $form_common=(<<END);
4003: <input type="hidden" name="folderpath" value="$path" />
4004: <input type="hidden" name="symb" value="$symb" />
4005: END
4006: $form_param=(<<END);
4007: <input type="hidden" name="setparms" value="$orderidx" />
4008: <input type="hidden" name="changeparms" value="0" />
4009: END
4010: $form_end = '</form>';
4011:
1.329 droeschl 4012: my $incindex=$index+1;
4013: my $selectbox='';
1.471 raeburn 4014: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 4015: ((split(/\:/,
1.344 bisitz 4016: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4017: ne '') &&
1.329 droeschl 4018: ((split(/\:/,
1.344 bisitz 4019: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 4020: ne '')) {
4021: $selectbox=
4022: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 4023: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 4024: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4025: if ($i==$incindex) {
1.358 bisitz 4026: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 4027: } else {
4028: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4029: }
4030: }
4031: $selectbox.='</select>';
4032: }
1.501 raeburn 4033: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 4034: 'up' => 'Move Up',
4035: 'dw' => 'Move Down',
4036: 'rm' => 'Remove',
4037: 'ct' => 'Cut',
4038: 'rn' => 'Rename',
1.501 raeburn 4039: 'cp' => 'Copy',
1.633 raeburn 4040: 'da' => 'Unset alias',
4041: 'sa' => 'Set alias',
1.501 raeburn 4042: 'ex' => 'External Resource',
1.598 raeburn 4043: 'et' => 'External Tool',
1.501 raeburn 4044: 'ed' => 'Edit',
4045: 'pr' => 'Preview',
4046: 'sv' => 'Save',
4047: 'ul' => 'URL',
1.611 raeburn 4048: 'ti' => 'Title',
1.618 raeburn 4049: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 4050: );
1.538 raeburn 4051: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4052: $env{'form.folderpath'},
4053: $currgroups);
1.517 raeburn 4054: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4055: my $skip_confirm = 0;
1.603 raeburn 4056: my $confirm_removal = 0;
1.329 droeschl 4057: if ( $folder =~ /^supplemental/
4058: || ($url =~ m{( /smppg$
4059: |/syllabus$
4060: |/aboutme$
4061: |/navmaps$
4062: |/bulletinboard$
1.626 raeburn 4063: |/ext\.tool$
1.505 raeburn 4064: |\.html$)}x)
4065: || $isexternal) {
1.329 droeschl 4066: $skip_confirm = 1;
4067: }
1.603 raeburn 4068: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4069: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4070: $confirm_removal = 1;
4071: }
1.633 raeburn 4072: if ($url =~ /$LONCAPA::assess_re/) {
4073: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4074: }
1.329 droeschl 4075:
1.538 raeburn 4076: if ($denied{'copy'}) {
1.543 raeburn 4077: $copylink=(<<ENDCOPY)
1.507 raeburn 4078: <span style="visibility: hidden;">$lt{'cp'}</span>
4079: ENDCOPY
4080: } else {
1.538 raeburn 4081: my $formname = 'edit_copy_'.$orderidx;
4082: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4083: $copylink=(<<ENDCOPY);
1.538 raeburn 4084: <form name="$formname" method="post" action="/adm/coursedocs">
4085: $form_common
1.611 raeburn 4086: <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 4087: $form_end
1.329 droeschl 4088: ENDCOPY
1.538 raeburn 4089: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4090: push(@{$filtersref->{'cancopy'}},$orderidx);
4091: }
1.329 droeschl 4092: }
1.538 raeburn 4093: if ($denied{'cut'}) {
1.507 raeburn 4094: $cutlink=(<<ENDCUT);
4095: <span style="visibility: hidden;">$lt{'ct'}</span>
4096: ENDCUT
4097: } else {
1.538 raeburn 4098: my $formname = 'edit_cut_'.$orderidx;
4099: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4100: $cutlink=(<<ENDCUT);
1.538 raeburn 4101: <form name="$formname" method="post" action="/adm/coursedocs">
4102: $form_common
1.542 raeburn 4103: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4104: <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 4105: $form_end
1.329 droeschl 4106: ENDCUT
1.538 raeburn 4107: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4108: push(@{$filtersref->{'cancut'}},$orderidx);
4109: }
1.329 droeschl 4110: }
1.538 raeburn 4111: if ($denied{'remove'}) {
1.507 raeburn 4112: $removelink=(<<ENDREM);
4113: <span style="visibility: hidden;">$lt{'rm'}</a>
4114: ENDREM
4115: } else {
1.538 raeburn 4116: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4117: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4118: $removelink=(<<ENDREM);
1.538 raeburn 4119: <form name="$formname" method="post" action="/adm/coursedocs">
4120: $form_common
1.542 raeburn 4121: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4122: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4123: <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 4124: $form_end
1.497 raeburn 4125: ENDREM
1.538 raeburn 4126: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4127: push(@{$filtersref->{'canremove'}},$orderidx);
4128: }
1.497 raeburn 4129: }
1.551 raeburn 4130: $renamelink=(<<ENDREN);
1.581 raeburn 4131: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4132: ENDREN
1.611 raeburn 4133: my ($uplink,$downlink);
4134: if ($canedit) {
4135: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4136: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4137: } else {
4138: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4139: $downlink = $uplink;
4140: }
1.329 droeschl 4141: $line.=(<<END);
4142: <td>
1.379 bisitz 4143: <div class="LC_docs_entry_move">
1.611 raeburn 4144: <a href="$uplink">
1.501 raeburn 4145: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4146: </a>
4147: </div>
4148: <div class="LC_docs_entry_move">
1.611 raeburn 4149: <a href="$downlink">
1.501 raeburn 4150: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4151: </a>
4152: </div>
1.329 droeschl 4153: </td>
4154: <td>
4155: $form_start
1.538 raeburn 4156: $form_param
1.478 raeburn 4157: $form_common
1.329 droeschl 4158: $selectbox
4159: $form_end
4160: </td>
1.540 raeburn 4161: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4162: $removelink
1.329 droeschl 4163: $cutlink
4164: $copylink
4165: </td>
4166: END
4167: }
4168: # Figure out what kind of a resource this is
4169: my ($extension)=($url=~/\.(\w+)$/);
4170: my $uploaded=($url=~/^\/*uploaded\//);
4171: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4172: my $isfolder;
4173: my $ispage;
4174: my $containerarg;
1.615 raeburn 4175: my $folderurl;
1.329 droeschl 4176: if ($uploaded) {
1.472 raeburn 4177: if (($extension eq 'sequence') || ($extension eq 'page')) {
4178: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4179: $containerarg = $1;
1.472 raeburn 4180: if ($extension eq 'sequence') {
4181: $icon=$iconpath.'navmap.folder.closed.gif';
4182: $isfolder=1;
4183: } else {
4184: $icon=$iconpath.'page.gif';
4185: $ispage=1;
4186: }
1.615 raeburn 4187: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4188: if ($allowed) {
4189: $url='/adm/coursedocs?';
4190: } else {
4191: $url='/adm/supplemental?';
4192: }
1.329 droeschl 4193: } else {
4194: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4195: }
4196: }
1.364 bisitz 4197:
1.621 raeburn 4198: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4199: my $orig_url = $url;
1.340 raeburn 4200: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 4201: if ($container eq 'page') {
4202: $url=~s{^http(|s)(:|:)//}{/ext/};
4203: } else {
4204: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4205: }
1.501 raeburn 4206: if (!$supplementalflag && $residx && $symb) {
4207: if ((!$isfolder) && (!$ispage)) {
4208: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 4209: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4210: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4211: } else {
4212: $url=&Apache::lonnet::clutter($url);
4213: }
1.501 raeburn 4214: if ($url=~/^\/*uploaded\//) {
4215: $url=~/\.(\w+)$/;
4216: my $embstyle=&Apache::loncommon::fileembstyle($1);
4217: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4218: $url='/adm/wrapper'.$url;
4219: } elsif ($embstyle eq 'ssi') {
4220: #do nothing with these
4221: } elsif ($url!~/\.(sequence|page)$/) {
4222: $url='/adm/coursedocs/showdoc'.$url;
4223: }
1.623 raeburn 4224: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4225: my $wrapped = $1;
4226: my $exturl = $2;
1.668 raeburn 4227: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 4228: $url='/adm/wrapper'.$url;
4229: }
4230: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4231: $nomodal = 1;
4232: }
1.626 raeburn 4233: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4234: $url='/adm/wrapper'.$url;
1.621 raeburn 4235: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4236: if (($ENV{'SERVER_PORT'} == 443) &&
4237: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4238: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4239: $url .= '?usehttp=1';
4240: }
1.621 raeburn 4241: $nomodal = 1;
4242: }
1.598 raeburn 4243: }
1.680 ! raeburn 4244: my ($checkencrypt,$shownurl);
! 4245: if (!$env{'request.role.adv'}) {
1.615 raeburn 4246: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 ! raeburn 4247: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 4248: $checkencrypt = 1;
1.620 raeburn 4249: } elsif (ref($navmapref)) {
1.615 raeburn 4250: unless (ref($$navmapref)) {
4251: $$navmapref = Apache::lonnavmaps::navmap->new();
4252: }
4253: if (ref($$navmapref)) {
4254: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 ! raeburn 4255: $checkencrypt = 1;
1.615 raeburn 4256: }
4257: }
4258: }
1.680 ! raeburn 4259: }
! 4260: if ($checkencrypt) {
! 4261: my $currenc = $env{'request.enc'};
! 4262: $env{'request.enc'} = 1;
! 4263: $shownsymb = &Apache::lonenc::encrypted($symb);
! 4264: $shownurl = &Apache::lonenc::encrypted($url);
! 4265: if (&Apache::lonnet::symbverify($symb,$url)) {
! 4266: $url = $shownurl;
! 4267: } else {
! 4268: $url = '';
! 4269: }
! 4270: $env{'request.enc'} = $currenc;
! 4271: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
! 4272: $shownsymb = $symb;
! 4273: if ($isexternal) {
! 4274: $url =~ s/\#[^#]+$//;
! 4275: if ($container eq 'page') {
! 4276: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 4277: }
1.612 raeburn 4278: }
1.680 ! raeburn 4279: $shownurl = $url;
! 4280: }
! 4281: unless ($env{'request.role.adv'}) {
! 4282: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
! 4283: $url = '';
! 4284: }
! 4285: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
! 4286: $url = '';
! 4287: $hiddenres = 1;
! 4288: }
! 4289: }
! 4290: if ($url ne '') {
! 4291: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 4292: }
1.329 droeschl 4293: }
1.621 raeburn 4294: } elsif ($supplementalflag) {
1.610 raeburn 4295: if ($isexternal) {
4296: if ($url =~ /^([^#]+)#([^#]+)$/) {
4297: $url = $1;
4298: $anchor = $2;
1.623 raeburn 4299: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 4300: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4301: if ($hostname ne '') {
4302: $url = 'http://'.$hostname.$url;
4303: }
4304: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 4305: }
4306: $nomodal = 1;
4307: }
1.610 raeburn 4308: }
1.621 raeburn 4309: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4310: if (($ENV{'SERVER_PORT'} == 443) &&
4311: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4312: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4313: if ($hostname ne '') {
4314: $url = 'http://'.$hostname.$url;
4315: }
4316: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 4317: }
1.621 raeburn 4318: $nomodal = 1;
4319: }
1.610 raeburn 4320: }
1.329 droeschl 4321: }
1.615 raeburn 4322: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4323: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4324: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4325: my $foldername=&escape($foldertitle);
4326: my $folderpath=$env{'form.folderpath'};
4327: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4328: if (!$allowed && $supplementalflag) {
1.519 raeburn 4329: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4330: $url.='folderpath='.&escape($folderpath);
4331: } else {
1.617 raeburn 4332: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4333: 'parameter_randompick'))[0];
4334: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4335: 'parameter_randomorder'))[0]=~/^yes$/i);
4336: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4337: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4338: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4339: 'parameter_encrypturl'))[0]=~/^yes$/i);
4340: unless ($hiddenmap) {
1.620 raeburn 4341: if (ref($navmapref)) {
4342: unless (ref($$navmapref)) {
4343: $$navmapref = Apache::lonnavmaps::navmap->new();
4344: }
4345: if (ref($$navmapref)) {
4346: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4347: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4348: unless (@resources) {
4349: $hiddenmap = 1;
4350: unless ($env{'request.role.adv'}) {
4351: $url = '';
4352: $hiddenfolder = 1;
4353: }
1.617 raeburn 4354: }
1.615 raeburn 4355: }
4356: }
4357: }
4358: }
1.617 raeburn 4359: unless ($encryptmap) {
1.620 raeburn 4360: if ((ref($navmapref)) && (ref($$navmapref))) {
4361: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4362: $encryptmap = 1;
4363: }
1.617 raeburn 4364: }
4365: }
1.630 raeburn 4366:
1.617 raeburn 4367: # Append randompick number, hidden, and encrypted with ":" to foldername,
4368: # so it gets transferred between levels
4369: $folderpath.=$containerarg.'&'.$foldername.
4370: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4371: unless ($url eq '') {
1.612 raeburn 4372: $url.='folderpath='.&escape($folderpath);
4373: }
1.510 raeburn 4374: my $rpckchk;
4375: if ($rpicknum) {
4376: $rpckchk = ' checked="checked"';
1.543 raeburn 4377: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4378: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4379: }
1.510 raeburn 4380: }
1.537 raeburn 4381: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4382: $rand_pick_text =
1.478 raeburn 4383: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4384: $form_param."\n".
1.478 raeburn 4385: $form_common."\n".
1.611 raeburn 4386: '<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 4387: if ($rpicknum ne '') {
4388: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4389: }
1.537 raeburn 4390: $rand_pick_text .= '</span></span>'.
4391: $form_end;
1.543 raeburn 4392: my $ro_set;
1.617 raeburn 4393: if ($randorder) {
1.543 raeburn 4394: $ro_set = 'checked="checked"';
4395: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4396: push(@{$filtersref->{'randomorder'}},$orderidx);
4397: }
4398: }
1.564 raeburn 4399: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4400: $rand_order_text =
1.537 raeburn 4401: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4402: $form_param."\n".
1.537 raeburn 4403: $form_common."\n".
1.611 raeburn 4404: '<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 4405: $form_end;
1.510 raeburn 4406: }
1.509 raeburn 4407: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4408: my $isexttool;
1.626 raeburn 4409: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4410: $url='/adm/wrapper'.$url;
4411: $isexttool = 1;
4412: }
1.510 raeburn 4413: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4414: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4415: if ($title) {
4416: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4417: }
1.598 raeburn 4418: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4419: $url .= '&idx='.$orderidx;
4420: }
1.610 raeburn 4421: if ($anchor ne '') {
4422: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4423: }
1.329 droeschl 4424: }
1.519 raeburn 4425: my ($tdalign,$tdwidth);
1.501 raeburn 4426: if ($allowed) {
1.630 raeburn 4427: my $fileloc =
1.501 raeburn 4428: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4429: if ($isexternal) {
1.630 raeburn 4430: ($editlink,$extresform) =
1.611 raeburn 4431: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4432: undef,undef,undef,undef,undef,undef,
4433: undef,$disabled);
1.626 raeburn 4434: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4435: ($editlink,$extresform) =
4436: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4437: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4438: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4439: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4440: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4441: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4442: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4443: my $suppanchor;
4444: if ($supplementalflag) {
4445: $suppanchor = $anchor;
4446: }
1.630 raeburn 4447: my $jscall =
1.501 raeburn 4448: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4449: $switchserver,
1.503 raeburn 4450: $forceedit,
1.679 raeburn 4451: undef,$symb,$shownsymb,
1.511 raeburn 4452: &escape($env{'form.folderpath'}),
1.622 raeburn 4453: $renametitle,$hostname,
4454: '','',1,$suppanchor);
1.501 raeburn 4455: if ($jscall) {
1.518 raeburn 4456: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4457: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4458: }
4459: }
4460: }
1.519 raeburn 4461: $tdalign = ' align="right" valign="top"';
4462: $tdwidth = ' width="80%"';
1.329 droeschl 4463: }
1.408 raeburn 4464: my $reinit;
4465: if ($crstype eq 'Community') {
4466: $reinit = &mt('(re-initialize community to access)');
4467: } else {
4468: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4469: }
4470: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.650 raeburn 4471: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 4472: $line.= '<br />';
4473: if ($curralias ne '') {
4474: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4475: $lt{'da'}.'</a></span>';
4476: } else {
4477: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4478: $lt{'sa'}.'</a></span>';
4479: }
4480: }
4481: $line.='</td><td>';
1.621 raeburn 4482: my $link;
1.472 raeburn 4483: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4484: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4485: } elsif ($url) {
1.610 raeburn 4486: if ($anchor ne '') {
4487: if ($supplementalflag) {
4488: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4489: } else {
4490: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4491: }
4492: }
1.622 raeburn 4493: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4494: $link = 'http://'.$hostname.$url;
4495: } else {
4496: $link = $url;
4497: }
1.659 raeburn 4498: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.621 raeburn 4499: if ($nomodal) {
4500: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4501: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4502: } else {
4503: $line.=&Apache::loncommon::modal_link($link,
4504: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4505: }
1.469 www 4506: } else {
4507: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4508: }
1.519 raeburn 4509: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4510: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4511: $line.='<a href="'.$url.'">'.$title.'</a>';
4512: } elsif ($url) {
1.621 raeburn 4513: if ($nomodal) {
4514: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4515: $title.'</a>';
4516: } else {
4517: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4518: }
1.617 raeburn 4519: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4520: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4521: } else {
4522: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4523: }
1.633 raeburn 4524: if (($allowed) && ($curralias ne '')) {
4525: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4526: } else {
4527: $line .= $extresform;
4528: }
4529: $line .= '</td>';
1.478 raeburn 4530: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4531: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4532: if (($allowed) && ($folder!~/^supplemental/)) {
4533: my %lt=&Apache::lonlocal::texthash(
4534: 'hd' => 'Hidden',
4535: 'ec' => 'URL hidden');
1.543 raeburn 4536: my ($enctext,$hidtext);
4537: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4538: $enctext = ' checked="checked"';
4539: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4540: push(@{$filtersref->{'encrypturl'}},$orderidx);
4541: }
4542: }
4543: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4544: $hidtext = ' checked="checked"';
4545: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4546: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4547: }
4548: }
1.537 raeburn 4549: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4550: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4551: $line.=(<<ENDPARMS);
4552: <td class="LC_docs_entry_parameter">
1.537 raeburn 4553: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4554: $form_param
1.478 raeburn 4555: $form_common
1.611 raeburn 4556: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4557: $form_end
1.458 raeburn 4558: <br />
1.537 raeburn 4559: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4560: $form_param
1.478 raeburn 4561: $form_common
1.611 raeburn 4562: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4563: $form_end
4564: </td>
1.478 raeburn 4565: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4566: $rand_order_text</td>
1.329 droeschl 4567: ENDPARMS
4568: }
1.379 bisitz 4569: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4570: return $line;
4571: }
4572:
1.538 raeburn 4573: sub action_restrictions {
4574: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4575: my %denied = (
4576: cut => 0,
4577: copy => 0,
4578: remove => 0,
4579: );
4580: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4581: # no copy for published maps
4582: $denied{'copy'} = 1;
1.597 raeburn 4583: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4584: unless ($1 eq 'simpleproblem') {
4585: $denied{'copy'} = 1;
4586: }
4587: $denied{'cut'} = 1;
1.538 raeburn 4588: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4589: if ($folderpath =~ /^default&[^\&]+$/) {
4590: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4591: $denied{'remove'} = 1;
4592: }
4593: $denied{'cut'} = 1;
4594: $denied{'copy'} = 1;
4595: }
4596: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4597: my $group = $1;
4598: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4599: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4600: $denied{'remove'} = 1;
4601: }
4602: }
4603: $denied{'cut'} = 1;
4604: $denied{'copy'} = 1;
4605: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4606: my $group = $1;
4607: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4608: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4609: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4610: if (keys(%groupsettings) > 0) {
4611: $denied{'remove'} = 1;
4612: }
4613: $denied{'cut'} = 1;
4614: $denied{'copy'} = 1;
4615: }
4616: }
4617: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4618: my $group = $1;
4619: if ($url =~ /group_boards_\Q$group\E/) {
4620: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4621: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4622: if (keys(%groupsettings) > 0) {
4623: if (ref($groupsettings{'functions'}) eq 'HASH') {
4624: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4625: $denied{'remove'} = 1;
4626: }
4627: }
4628: }
4629: $denied{'cut'} = 1;
4630: $denied{'copy'} = 1;
4631: }
4632: }
4633: }
4634: return %denied;
4635: }
4636:
1.533 raeburn 4637: sub new_timebased_suffix {
1.538 raeburn 4638: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4639: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4640: if ($type eq 'paste') {
4641: $prefix = $type;
4642: $namespace = 'courseeditor';
1.587 raeburn 4643: $idtype = 'addcode';
1.538 raeburn 4644: } elsif ($type eq 'map') {
1.533 raeburn 4645: $prefix = 'docs';
4646: if ($area eq 'supplemental') {
4647: $prefix = 'supp';
4648: }
4649: $prefix .= $container;
4650: $namespace = 'uploadedmaps';
4651: } else {
4652: $prefix = $type;
4653: $namespace = 'templated';
1.504 raeburn 4654: }
4655: my ($suffix,$freedlock,$error) =
1.587 raeburn 4656: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4657: if (!$suffix) {
1.538 raeburn 4658: if ($type eq 'paste') {
4659: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4660: } elsif ($type eq 'map') {
1.533 raeburn 4661: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4662: } elsif ($type eq 'smppg') {
4663: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4664: } elsif ($type eq 'exttool') {
4665: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4666: } else {
1.565 bisitz 4667: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4668: }
1.504 raeburn 4669: if ($error) {
4670: $errtext .= '<br />'.$error;
4671: }
4672: }
4673: if ($freedlock ne 'ok') {
1.630 raeburn 4674: $locknotfreed =
1.533 raeburn 4675: '<div class="LC_error">'.
4676: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4677: if ($type eq 'paste') {
1.591 raeburn 4678: if ($freedlock eq 'nolock') {
4679: $locknotfreed =
4680: '<div class="LC_error">'.
4681: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4682:
1.593 droeschl 4683: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4684: } else {
4685: $locknotfreed .=
4686: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4687: }
1.538 raeburn 4688: } elsif ($type eq 'map') {
1.591 raeburn 4689: $locknotfreed .=
4690: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4691: } elsif ($type eq 'smppg') {
4692: $locknotfreed .=
4693: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4694: } elsif ($type eq 'exttool') {
4695: $locknotfreed .=
4696: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4697: } else {
4698: $locknotfreed .=
1.565 bisitz 4699: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4700: }
1.538 raeburn 4701: unless ($type eq 'paste') {
4702: $locknotfreed .=
1.560 raeburn 4703: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4704: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4705: }
4706: $locknotfreed .= '</div>';
1.504 raeburn 4707: }
4708: return ($suffix,$errtext,$locknotfreed);
4709: }
4710:
1.329 droeschl 4711: =pod
4712:
4713: =item tiehash()
4714:
4715: tie the hash
4716:
4717: =cut
4718:
4719: sub tiehash {
4720: my ($mode)=@_;
4721: $hashtied=0;
4722: if ($env{'request.course.fn'}) {
4723: if ($mode eq 'write') {
4724: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4725: &GDBM_WRCREAT(),0640)) {
4726: $hashtied=2;
4727: }
4728: } else {
4729: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4730: &GDBM_READER(),0640)) {
4731: $hashtied=1;
4732: }
4733: }
1.364 bisitz 4734: }
1.329 droeschl 4735: }
4736:
4737: sub untiehash {
4738: if ($hashtied) { untie %hash; }
4739: $hashtied=0;
4740: return OK;
4741: }
4742:
4743:
4744:
4745:
4746: sub checkonthis {
1.637 raeburn 4747: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4748: $url=&unescape($url);
4749: $alreadyseen{$url}=1;
4750: $r->rflush();
4751: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4752: $r->print("\n<br />");
4753: if ($level==0) {
4754: $r->print("<br />");
4755: }
4756: for (my $i=0;$i<=$level*5;$i++) {
4757: $r->print(' ');
4758: }
4759: $r->print('<a href="'.$url.'" target="cat">'.
4760: ($title?$title:$url).'</a> ');
4761: if ($url=~/^\/res\//) {
1.637 raeburn 4762: my $updated;
4763: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4764: ($url !~ /\.\d+\.\w+$/)) {
4765: $updated = &Apache::lonnet::remove_stale_resfile($url);
4766: }
1.329 droeschl 4767: my $result=&Apache::lonnet::repcopy(
4768: &Apache::lonnet::filelocation('',$url));
4769: if ($result eq 'ok') {
4770: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4771: if ($updated) {
4772: $r->print('<br />');
4773: for (my $i=0;$i<=$level*5;$i++) {
4774: $r->print(' ');
4775: }
4776: $r->print('- '.&mt('Outdated copy removed'));
4777: }
1.329 droeschl 4778: $r->rflush();
4779: &Apache::lonnet::countacc($url);
4780: $url=~/\.(\w+)$/;
4781: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4782: $r->print('<br />');
4783: $r->rflush();
4784: for (my $i=0;$i<=$level*5;$i++) {
4785: $r->print(' ');
4786: }
4787: $r->print('- '.&mt('Rendering:').' ');
4788: my ($errorcount,$warningcount)=split(/:/,
4789: &Apache::lonnet::ssi_body($url,
4790: ('grade_target'=>'web',
4791: 'return_only_error_and_warning_counts' => 1)));
4792: if (($errorcount) ||
4793: ($warningcount)) {
4794: if ($errorcount) {
1.369 bisitz 4795: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4796: &mt('[quant,_1,error]',$errorcount).'</span>');
4797: }
4798: if ($warningcount) {
4799: $r->print('<span class="LC_warning">'.
4800: &mt('[quant,_1,warning]',$warningcount).'</span>');
4801: }
4802: } else {
4803: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4804: }
4805: $r->rflush();
4806: }
4807: my $dependencies=
4808: &Apache::lonnet::metadata($url,'dependencies');
4809: foreach my $dep (split(/\,/,$dependencies)) {
4810: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4811: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4812: }
4813: }
4814: } elsif ($result eq 'unavailable') {
4815: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4816: } elsif ($result eq 'not_found') {
4817: unless ($url=~/\$/) {
1.521 bisitz 4818: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4819: } else {
1.366 bisitz 4820: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4821: }
4822: } else {
4823: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4824: }
1.637 raeburn 4825: if (($updated) && ($result ne 'ok')) {
4826: $r->print('<br />'.&mt('Outdated copy removed'));
4827: }
1.329 droeschl 4828: }
4829: }
4830: }
4831:
4832:
4833:
4834: =pod
4835:
4836: =item list_symbs()
4837:
1.485 raeburn 4838: List Content Identifiers
1.329 droeschl 4839:
4840: =cut
4841:
4842: sub list_symbs {
4843: my ($r) = @_;
4844:
1.408 raeburn 4845: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4846: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4847: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4848: $r->print(&startContentScreen('tools'));
1.329 droeschl 4849: my $navmap = Apache::lonnavmaps::navmap->new();
4850: if (!defined($navmap)) {
4851: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4852: '<div class="LC_error">'.
4853: &mt('Unable to retrieve information about course contents').
4854: '</div>');
1.408 raeburn 4855: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4856: } else {
1.484 raeburn 4857: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4858: &Apache::loncommon::start_data_table().
4859: &Apache::loncommon::start_data_table_header_row().
4860: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4861: &Apache::loncommon::end_data_table_header_row()."\n");
4862: my $count;
1.329 droeschl 4863: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4864: $r->print(&Apache::loncommon::start_data_table_row().
4865: '<td>'.$res->compTitle().'</td>'.
4866: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4867: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4868: $count ++;
4869: }
4870: if (!$count) {
4871: $r->print(&Apache::loncommon::start_data_table_row().
4872: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4873: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4874: }
1.484 raeburn 4875: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4876: }
1.521 bisitz 4877: $r->print(&endContentScreen());
1.329 droeschl 4878: }
4879:
1.651 raeburn 4880: sub short_urls {
4881: my ($r,$canedit) = @_;
4882: my $crstype = &Apache::loncommon::course_type();
4883: my $formname = 'shortenurl';
4884: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4885: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4886: $r->print(&startContentScreen('tools'));
4887: my ($navmap,$errormsg) =
4888: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4889: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4890: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4891: my (%maps,%resources,%titles);
4892: if (!ref($navmap)) {
4893: $r->print($errormsg.
4894: &endContentScreen());
4895: return '';
4896: } else {
1.652 raeburn 4897: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 4898: $r->rflush();
4899: my $readonly;
4900: if ($canedit) {
1.671 raeburn 4901: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 4902: if ($numnew) {
4903: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4904: }
4905: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4906: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4907: foreach my $error (@{$errors}) {
4908: $r->print('<li>'.$error.'</li>');
4909: }
4910: $r->print('</ul><br />');
4911: }
4912: } else {
4913: $readonly = 1;
4914: }
4915: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4916: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4917: undef,undef,undef,undef,undef,\%currtiny,$readonly));
4918: }
4919: $r->print(&endContentScreen());
4920: }
4921:
1.637 raeburn 4922: sub contentverifyform {
4923: my ($r) = @_;
4924: my $crstype = &Apache::loncommon::course_type();
4925: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4926: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4927: $r->print(&startContentScreen('tools'));
4928: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4929: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4930: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4931: ' <span class="LC_nobreak">'.
4932: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4933: &mt('No').'</label>'.(' 'x2).
4934: '<label><input type="radio" name="checkstale" value="1" />'.
4935: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 4936: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 4937: '<input type="hidden" value="1" name="tools" />'.
4938: '<input type="hidden" value="1" name="verify" /></p></form>');
4939: $r->print(&endContentScreen());
4940: return;
4941: }
1.329 droeschl 4942:
4943: sub verifycontent {
1.637 raeburn 4944: my ($r,$checkstale) = @_;
1.408 raeburn 4945: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4946: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4947: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4948: $r->print(&startContentScreen('tools'));
4949: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4950: $hashtied=0;
4951: undef %alreadyseen;
4952: %alreadyseen=();
4953: &tiehash();
1.484 raeburn 4954:
1.329 droeschl 4955: foreach my $key (keys(%hash)) {
4956: if ($hash{$key}=~/\.(page|sequence)$/) {
4957: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4958: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4959: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4960: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4961: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4962: }
4963: }
4964: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 4965: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4966: }
4967: }
4968: &untiehash();
1.442 www 4969: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4970: $r->print(&endContentScreen());
1.329 droeschl 4971: }
4972:
4973: sub devalidateversioncache {
4974: my $src=shift;
4975: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4976: &Apache::lonnet::clutter($src));
4977: }
4978:
4979: sub checkversions {
1.611 raeburn 4980: my ($r,$canedit) = @_;
1.408 raeburn 4981: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4982: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4983: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4984: $r->print(&startContentScreen('tools'));
1.442 www 4985:
1.329 droeschl 4986: my $header='';
4987: my $startsel='';
4988: my $monthsel='';
4989: my $weeksel='';
4990: my $daysel='';
4991: my $allsel='';
4992: my %changes=();
4993: my $starttime=0;
4994: my $haschanged=0;
4995: my %setversions=&Apache::lonnet::dump('resourceversions',
4996: $env{'course.'.$env{'request.course.id'}.'.domain'},
4997: $env{'course.'.$env{'request.course.id'}.'.num'});
4998:
4999: $hashtied=0;
5000: &tiehash();
1.611 raeburn 5001: if ($canedit) {
5002: my %newsetversions=();
5003: if ($env{'form.setmostrecent'}) {
5004: $haschanged=1;
5005: foreach my $key (keys(%hash)) {
5006: if ($key=~/^ids\_(\/res\/.+)$/) {
5007: $newsetversions{$1}='mostrecent';
5008: &devalidateversioncache($1);
5009: }
5010: }
5011: } elsif ($env{'form.setcurrent'}) {
5012: $haschanged=1;
5013: foreach my $key (keys(%hash)) {
5014: if ($key=~/^ids\_(\/res\/.+)$/) {
5015: my $getvers=&Apache::lonnet::getversion($1);
5016: if ($getvers>0) {
5017: $newsetversions{$1}=$getvers;
5018: &devalidateversioncache($1);
5019: }
5020: }
1.329 droeschl 5021: }
1.611 raeburn 5022: } elsif ($env{'form.setversions'}) {
5023: $haschanged=1;
5024: foreach my $key (keys(%env)) {
5025: if ($key=~/^form\.set_version_(.+)$/) {
5026: my $src=$1;
5027: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5028: $newsetversions{$src}=$env{$key};
5029: &devalidateversioncache($src);
5030: }
5031: }
1.329 droeschl 5032: }
1.611 raeburn 5033: }
5034: if ($haschanged) {
5035: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5036: $env{'course.'.$env{'request.course.id'}.'.domain'},
5037: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5038: $r->print(&Apache::loncommon::confirmwrapper(
5039: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5040: } else {
5041: $r->print(&Apache::loncommon::confirmwrapper(
5042: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 5043: }
1.611 raeburn 5044: &mark_hash_old();
5045: }
5046: &changewarning($r,'');
1.329 droeschl 5047: }
5048: if ($env{'form.timerange'} eq 'all') {
5049: # show all documents
1.549 raeburn 5050: $header=&mt('All content in '.$crstype);
1.521 bisitz 5051: $allsel=' selected="selected"';
1.329 droeschl 5052: foreach my $key (keys(%hash)) {
5053: if ($key=~/^ids\_(\/res\/.+)$/) {
5054: my $src=$1;
5055: $changes{$src}=1;
5056: }
5057: }
5058: } else {
5059: # show documents which changed
5060: %changes=&Apache::lonnet::dump
5061: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5062: $env{'course.'.$env{'request.course.id'}.'.num'});
5063: my $firstkey=(keys(%changes))[0];
5064: unless ($firstkey=~/^error\:/) {
5065: unless ($env{'form.timerange'}) {
5066: $env{'form.timerange'}=604800;
5067: }
5068: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5069: .&mt('seconds');
5070: if ($env{'form.timerange'}==-1) {
5071: $seltext='since start of course';
1.521 bisitz 5072: $startsel=' selected="selected"';
1.329 droeschl 5073: $env{'form.timerange'}=time;
5074: }
5075: $starttime=time-$env{'form.timerange'};
5076: if ($env{'form.timerange'}==2592000) {
5077: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5078: $monthsel=' selected="selected"';
1.329 droeschl 5079: } elsif ($env{'form.timerange'}==604800) {
5080: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5081: $weeksel=' selected="selected"';
1.329 droeschl 5082: } elsif ($env{'form.timerange'}==86400) {
5083: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5084: $daysel=' selected="selected"';
1.329 droeschl 5085: }
5086: $header=&mt('Content changed').' '.$seltext;
5087: } else {
5088: $header=&mt('No content modifications yet.');
5089: }
5090: }
5091: %setversions=&Apache::lonnet::dump('resourceversions',
5092: $env{'course.'.$env{'request.course.id'}.'.domain'},
5093: $env{'course.'.$env{'request.course.id'}.'.num'});
5094: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5095: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5096: 'lm' => 'Version changes since last Month',
5097: 'lw' => 'Version changes since last Week',
5098: 'sy' => 'Version changes since Yesterday',
5099: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5100: 'cd' => 'Change display',
1.329 droeschl 5101: 'sd' => 'Display',
5102: 'fi' => 'File',
5103: 'md' => 'Modification Date',
5104: 'mr' => 'Most recently published Version',
1.408 raeburn 5105: 've' => 'Version used in '.$crstype,
5106: 'vu' => 'Set Version to be used in '.$crstype,
5107: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5108: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5109: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5110: 'di' => 'Differences',
1.484 raeburn 5111: 'save' => 'Save changes',
5112: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5113: 'act' => 'Actions');
1.611 raeburn 5114: my ($disabled,$readonly);
5115: unless ($canedit) {
5116: $disabled = 'disabled="disabled"';
5117: $readonly = 1;
5118: }
1.329 droeschl 5119: $r->print(<<ENDHEADERS);
1.484 raeburn 5120: <h4 class="LC_info">$header</h4>
1.329 droeschl 5121: <form action="/adm/coursedocs" method="post">
5122: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5123: <div class="LC_left_float">
1.479 golterma 5124: <fieldset>
1.484 raeburn 5125: <legend>$lt{'cd'}</legend>
1.329 droeschl 5126: <select name="timerange">
1.521 bisitz 5127: <option value='all'$allsel>$lt{'al'}</option>
5128: <option value="-1"$startsel>$lt{'st'}</option>
5129: <option value="2592000"$monthsel>$lt{'lm'}</option>
5130: <option value="604800"$weeksel>$lt{'lw'}</option>
5131: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5132: </select>
5133: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5134: </fieldset>
5135: </div>
5136: <div class="LC_left_float">
5137: <fieldset>
5138: <legend>$lt{'act'}</legend>
1.611 raeburn 5139: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5140: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5141: </fieldset>
5142: </div>
5143: <br clear="all" />
5144: <hr />
5145: <h4>$lt{'vers'}</h4>
1.329 droeschl 5146: ENDHEADERS
1.479 golterma 5147: #number of columns for version history
1.571 raeburn 5148: my %changedbytime;
5149: foreach my $key (keys(%changes)) {
5150: #excludes not versionable problems from resource version history:
5151: next if ($key =~ /^\/res\/lib\/templates/);
5152: my $chg;
5153: if ($env{'form.timerange'} eq 'all') {
5154: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5155: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5156: } else {
5157: $chg = $changes{$key};
5158: next if ($chg < $starttime);
5159: }
5160: push(@{$changedbytime{$chg}},$key);
5161: }
5162: if (keys(%changedbytime) == 0) {
5163: &untiehash();
5164: $r->print(&mt('No content changes in imported content in specified time frame').
5165: &endContentScreen());
5166: return;
5167: }
1.479 golterma 5168: $r->print(
1.611 raeburn 5169: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5170: &Apache::loncommon::start_data_table().
5171: &Apache::loncommon::start_data_table_header_row().
5172: '<th>'.&mt('Resources').'</th>'.
5173: "<th>$lt{'mr'}</th>".
5174: "<th>$lt{'ve'}</th>".
5175: "<th>$lt{'vu'}</th>".
5176: '<th>'.&mt('History').'</th>'.
5177: &Apache::loncommon::end_data_table_header_row()
5178: );
1.571 raeburn 5179: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5180: foreach my $key (sort(@{$changedbytime{$chg}})) {
5181: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5182: my $currentversion=&Apache::lonnet::getversion($key);
5183: if ($currentversion<0) {
5184: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5185: }
5186: my $linkurl=&Apache::lonnet::clutter($key);
5187: $r->print(
5188: &Apache::loncommon::start_data_table_row().
5189: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5190: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5191: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5192: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5193: '<td align="right">'
5194: );
5195: # Used in course
5196: my $usedversion=$hash{'version_'.$linkurl};
5197: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5198: if ($usedversion != $currentversion) {
1.479 golterma 5199: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5200: } else {
1.479 golterma 5201: $r->print($usedversion);
5202: }
1.329 droeschl 5203: } else {
1.521 bisitz 5204: $r->print($currentversion);
1.329 droeschl 5205: }
1.571 raeburn 5206: $r->print('</td><td title="'.$lt{'vu'}.'">');
5207: # Set version
5208: $r->print(&Apache::loncommon::select_form(
5209: $setversions{$linkurl},
5210: 'set_version_'.$linkurl,
5211: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5212: '' => '',
5213: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5214: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5215: my $lastold=1;
5216: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5217: my $url=$root.'.'.$prevvers.'.'.$extension;
5218: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5219: $lastold=$prevvers;
5220: }
5221: }
5222: $r->print('</td>');
5223: # List all available versions
5224: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5225: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5226: my $url=$root.'.'.$prevvers.'.'.$extension;
5227: $r->print(
5228: '<span class="LC_nobreak">'
5229: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5230: .&mt('Version [_1]',$prevvers).'</a>'
5231: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5232: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5233: .')');
5234: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5235: $r->print(
5236: ' <a href="/adm/diff?filename='.
5237: &Apache::lonnet::clutter($root.'.'.$extension).
5238: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5239: '" target="diffs">'.&mt('Diffs').'</a>');
5240: }
5241: $r->print('</span><br />');
1.329 droeschl 5242: }
1.571 raeburn 5243: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5244: }
1.329 droeschl 5245: }
1.521 bisitz 5246: $r->print(
5247: &Apache::loncommon::end_data_table().
1.611 raeburn 5248: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5249: '</form>'
5250: );
1.329 droeschl 5251:
5252: &untiehash();
1.521 bisitz 5253: $r->print(&endContentScreen());
1.571 raeburn 5254: return;
1.329 droeschl 5255: }
5256:
5257: sub mark_hash_old {
5258: my $retie_hash=0;
5259: if ($hashtied) {
5260: $retie_hash=1;
5261: &untiehash();
5262: }
5263: &tiehash('write');
5264: $hash{'old'}=1;
5265: &untiehash();
5266: if ($retie_hash) { &tiehash(); }
5267: }
5268:
5269: sub is_hash_old {
5270: my $untie_hash=0;
5271: if (!$hashtied) {
5272: $untie_hash=1;
5273: &tiehash();
5274: }
5275: my $return=$hash{'old'};
5276: if ($untie_hash) { &untiehash(); }
5277: return $return;
5278: }
5279:
5280: sub changewarning {
5281: my ($r,$postexec,$message,$url)=@_;
5282: if (!&is_hash_old()) { return; }
5283: my $pathvar='folderpath';
5284: my $path=&escape($env{'form.folderpath'});
5285: if (!defined($url)) {
5286: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5287: }
5288: my $course_type = &Apache::loncommon::course_type();
5289: if (!defined($message)) {
5290: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5291: }
1.653 raeburn 5292: my $windowname = 'loncapaclient';
5293: if ($env{'request.lti.login'}) {
5294: $windowname .= 'lti';
5295: }
1.329 droeschl 5296: $r->print("\n\n".
1.372 bisitz 5297: '<script type="text/javascript">'."\n".
5298: '// <![CDATA['."\n".
5299: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5300: '// ]]>'."\n".
1.369 bisitz 5301: '</script>'."\n".
1.653 raeburn 5302: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5303: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5304: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5305: &mt($message,' <input type="hidden" name="'.
5306: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5307: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5308: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5309: }
5310:
5311:
5312: sub init_breadcrumbs {
1.571 raeburn 5313: my ($form,$text,$help)=@_;
1.329 droeschl 5314: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5315: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5316: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5317: faq=>273,
5318: bug=>'Instructor Interface',
1.571 raeburn 5319: help => $help});
1.329 droeschl 5320: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5321: text=>$text,
5322: faq=>273,
5323: bug=>'Instructor Interface'});
5324: }
5325:
1.441 www 5326: # subroutine to list form elements
5327: sub create_list_elements {
5328: my @formarr = @_;
5329: my $list = '';
1.501 raeburn 5330: foreach my $button (@formarr){
5331: foreach my $picture (keys(%{$button})) {
5332: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5333: }
5334: }
5335: return $list;
5336: }
1.329 droeschl 5337:
1.441 www 5338: # subroutine to create ul from list elements
5339: sub create_form_ul {
5340: my $list = shift;
5341: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5342: return $ul;
5343: }
1.329 droeschl 5344:
1.442 www 5345: #
5346: # Start tabs
5347: #
5348:
5349: sub startContentScreen {
1.484 raeburn 5350: my ($mode) = @_;
5351: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5352: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5353: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5354: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5355: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5356: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5357: } else {
1.549 raeburn 5358: $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 5359: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5360: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5361: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5362: }
5363: $output .= "\n".'</ul>'."\n";
5364: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5365: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5366: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5367: return $output;
1.442 www 5368: }
5369:
5370: #
5371: # End tabs
5372: #
5373:
5374: sub endContentScreen {
1.484 raeburn 5375: return '</div></div></div>';
1.442 www 5376: }
1.329 droeschl 5377:
1.446 www 5378: sub supplemental_base {
1.548 raeburn 5379: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5380: }
5381:
1.329 droeschl 5382: sub handler {
5383: my $r = shift;
5384: &Apache::loncommon::content_type($r,'text/html');
5385: $r->send_http_header;
5386: return OK if $r->header_only;
1.484 raeburn 5387:
5388: # get course data
1.408 raeburn 5389: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5390: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5391: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5392:
1.606 raeburn 5393: # get docroot
5394: my $londocroot = $r->dir_config('lonDocRoot');
5395:
1.484 raeburn 5396: # graphics settings
5397: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5398:
1.443 www 5399: #
1.329 droeschl 5400: # --------------------------------------------- Initialize help topics for this
5401: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5402: 'Adding_External_Resource','Adding_External_Tool',
5403: 'Navigate_Content','Adding_Folders','Docs_Overview',
5404: 'Load_Map','Supplemental','Score_Upload_Form',
5405: 'Adding_Pages','Importing_LON-CAPA_Resource',
5406: 'Importing_IMS_Course','Uploading_From_Harddrive',
5407: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5408: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5409: }
5410: # Composite help files
5411: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5412: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5413: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5414: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5415: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5416: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5417: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5418: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5419: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5420: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5421:
1.611 raeburn 5422: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5423: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5424: unless ($r->uri eq '/adm/supplemental') {
5425: # does this user have privileges to modify content.
1.611 raeburn 5426: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5427: $allowed = 1;
5428: $canedit = 1;
5429: $canview = 1;
5430: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5431: $allowed = 1;
5432: $canview = 1;
5433: }
5434: }
5435: unless ($canedit) {
5436: $disabled = ' disabled="disabled"';
1.472 raeburn 5437: }
1.582 raeburn 5438: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5439: if ($env{'form.inhibitmenu'}) {
5440: unless ($env{'form.inhibitmenu'} eq 'yes') {
5441: delete($env{'form.inhibitmenu'});
5442: }
5443: }
5444:
1.582 raeburn 5445: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5446: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5447: if (!$canedit) {
5448: &verifycontent($r);
5449: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5450: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5451: text=>'Results',
5452: faq=>273,
5453: bug=>'Instructor Interface'});
5454: &verifycontent($r,$env{'form.checkstale'});
5455: } else {
5456: &contentverifyform($r);
5457: }
1.329 droeschl 5458: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5459: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5460: &list_symbs($r);
1.651 raeburn 5461: } elsif ($allowed && $env{'form.shorturls'}) {
5462: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5463: &short_urls($r,$canedit);
1.329 droeschl 5464: } elsif ($allowed && $env{'form.docslog'}) {
5465: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5466: my $folder = $env{'form.folder'};
5467: if ($folder eq '') {
5468: $folder='default';
5469: }
1.611 raeburn 5470: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5471: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5472: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5473: &checkversions($r,$canedit);
5474: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5475: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5476: &dumpcourse($r);
1.611 raeburn 5477: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5478: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5479: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5480: } else {
1.611 raeburn 5481: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5482: $noendpage = 1;
5483: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5484: if ($redirect) {
5485: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5486: my $container = 'sequence';
5487: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5488: $is_random_order,$container) =
5489: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5490: my (@folders)=split('&',$env{'form.folderpath'});
5491: $env{'form.foldername'}=&unescape(pop(@folders));
5492: my $folder=pop(@folders);
5493: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5494: $folder.'.'.$container);
5495: my $warning;
5496: if ($fatal) {
5497: if ($container eq 'page') {
5498: $warning = &mt('An error occurred retrieving the contents of the current page.');
5499: } else {
5500: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5501: }
5502: } else {
5503: my $url = $redirect;
5504: my $srcfile = $londocroot.$url;
5505: $url =~ s{^/priv/}{/res/};
5506: my $targetfile = $londocroot.$url;
5507: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5508: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5509: $env{'form.folder'} = $folder;
5510: &snapshotbefore();
5511: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5512: my $ext = 'false';
5513: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5514: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5515: ':'.$ext.':normal:res';
5516: push(@LONCAPA::map::order,$newidx);
5517: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5518: 'string_yesno');
5519: &remember_parms($newidx,'hiddenresource','set','yes');
5520: ($errtext,$fatal) =
5521: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5522: &log_differences($plain);
5523: &mark_hash_old();
5524: $r->internal_redirect($redirect);
5525: return OK;
5526: }
1.654 raeburn 5527: } else {
5528: $r->internal_redirect($redirect);
1.606 raeburn 5529: }
5530: }
5531: }
1.445 www 5532: #
5533: # Done catching special calls
1.484 raeburn 5534: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5535: # Get the parameters that may be needed
5536: #
5537: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5538: ['folderpath',
5539: 'forcesupplement','forcestandard',
1.510 raeburn 5540: 'tools','symb','command','supppath']);
1.445 www 5541:
1.635 raeburn 5542: foreach my $item ('forcesupplement','forcestandard','tools') {
5543: next if ($env{'form.'.$item} eq '');
5544: unless ($env{'form.'.$item} eq '1') {
5545: delete($env{'form.'.$item});
5546: }
5547: }
5548:
5549: if ($env{'form.command'}) {
5550: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5551: delete($env{'form.command'});
5552: }
5553: }
5554:
5555: if ($env{'form.symb'}) {
5556: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5557: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5558: delete($env{'form.symb'});
5559: }
5560: }
5561:
1.445 www 5562: # standard=1: this is a "new-style" course with an uploaded map as top level
5563: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5564:
5565: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5566:
1.484 raeburn 5567: # Decide whether this should display supplemental or main content or utilities
1.445 www 5568: # supplementalflag=1: show supplemental documents
5569: # supplementalflag=0: show standard documents
1.484 raeburn 5570: # toolsflag=1: show utilities
1.445 www 5571:
1.561 raeburn 5572: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5573: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5574: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5575: $supplementalflag=0;
5576: }
5577: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5578: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5579: unless ($allowed) { $supplementalflag=1; }
5580: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5581: my $toolsflag=0;
5582: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5583:
1.635 raeburn 5584: if ($env{'form.folderpath'} ne '') {
1.677 raeburn 5585: &validate_folderpath($supplementalflag);
1.635 raeburn 5586: }
5587:
5588: if ($env{'form.supppath'} ne '') {
1.677 raeburn 5589: &validate_suppath();
1.635 raeburn 5590: }
5591:
1.329 droeschl 5592: my $script='';
5593: my $showdoc=0;
1.457 raeburn 5594: my $addentries = {};
1.475 raeburn 5595: my $container;
1.329 droeschl 5596: my $containertag;
1.508 raeburn 5597: my $pathitem;
1.598 raeburn 5598: my %ltitools;
1.617 raeburn 5599: my $hiddentop;
1.615 raeburn 5600: my $navmap;
1.617 raeburn 5601: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5602:
1.464 www 5603: # Do we directly jump somewhere?
1.525 raeburn 5604: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5605: if ($env{'form.symb'} ne '') {
1.522 raeburn 5606: $env{'form.folderpath'}=
1.617 raeburn 5607: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5608: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5609: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5610: } elsif ($env{'form.supppath'} ne '') {
5611: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5612: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5613: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5614: }
1.472 raeburn 5615: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5616: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5617: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5618: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5619: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5620: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5621: } elsif ($env{'form.command'} eq 'contents') {
5622: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5623: } elsif ($env{'form.command'} eq 'home') {
5624: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5625: }
5626:
1.525 raeburn 5627:
1.445 www 5628: # Where do we store these for when we come back?
5629: my $stored_folderpath='docs_folderpath';
5630: if ($supplementalflag) {
5631: $stored_folderpath='docs_sup_folderpath';
5632: }
1.464 www 5633:
1.519 raeburn 5634: # No folderpath, and in edit mode, see if we have something stored
5635: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5636: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5637: {'folderpath' => 'scalar'});
1.615 raeburn 5638:
5639: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5640: if ($supplementalflag) {
5641: undef($env{'form.folderpath'}) if ($1 eq 'default');
5642: } else {
5643: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5644: }
5645: } else {
1.523 raeburn 5646: undef($env{'form.folderpath'});
5647: }
1.677 raeburn 5648: if ($env{'form.folderpath'} ne '') {
5649: &validate_folderpath($supplementalflag);
5650: }
1.329 droeschl 5651: }
1.446 www 5652:
5653: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5654: if (!$allowed) {
1.446 www 5655: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5656: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5657: }
5658: }
1.446 www 5659: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5660: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5661: $env{'form.folderpath'} = &supplemental_base()
5662: .'&'.
1.329 droeschl 5663: $env{'form.folderpath'};
5664: }
1.615 raeburn 5665: # If allowed and user's role is not advanced check folderpath is not hidden
5666: if (($allowed) && (!$env{'request.role.adv'}) &&
5667: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5668: my $folderurl;
5669: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5670: my $folder = $pathitems[-2];
5671: if ($folder eq '') {
5672: undef($env{'form.folderpath'});
5673: } else {
5674: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 5675: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 5676: $folderurl .= '.page';
5677: } else {
5678: $folderurl .= '.sequence';
5679: }
1.617 raeburn 5680: unless (ref($navmap)) {
5681: $navmap = Apache::lonnavmaps::navmap->new();
5682: }
1.615 raeburn 5683: if (ref($navmap)) {
5684: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5685: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5686: unless (@resources) {
5687: undef($env{'form.folderpath'});
5688: }
1.615 raeburn 5689: }
5690: }
5691: }
5692: }
5693:
5694:
1.446 www 5695: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5696: unless ($env{'form.folderpath'}) {
1.446 www 5697: if ($supplementalflag) {
5698: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5699: } elsif ($allowed) {
5700: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5701: }
1.472 raeburn 5702: }
1.446 www 5703:
1.445 www 5704: # Store this
1.484 raeburn 5705: unless ($toolsflag) {
1.615 raeburn 5706: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5707: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5708: {'folderpath' => 'scalar'});
1.510 raeburn 5709: }
1.519 raeburn 5710: my $folderpath;
1.484 raeburn 5711: if ($env{'form.folderpath'}) {
1.519 raeburn 5712: $folderpath = $env{'form.folderpath'};
5713: my (@folders)=split('&',$env{'form.folderpath'});
5714: $env{'form.foldername'}=&unescape(pop(@folders));
5715: if ($env{'form.foldername'} =~ /\:1$/) {
5716: $container = 'page';
5717: } else {
5718: $container = 'sequence';
5719: }
5720: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5721: } else {
1.519 raeburn 5722: if ($env{'form.folder'} eq '' ||
5723: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5724: if ($env{'form.folder'} eq 'supplemental') {
5725: $folderpath=&supplemental_base();
5726: } elsif (!$hiddentop) {
5727: $folderpath='default&'.
5728: &escape(&mt('Main Content').':::::');
5729: }
1.484 raeburn 5730: }
5731: }
1.519 raeburn 5732: $containertag = '<input type="hidden" name="folderpath" value="" />';
5733: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5734: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5735: $showdoc='/'.$1;
5736: }
5737: if ($showdoc) { # got called in sequence from course
5738: $allowed=0;
5739: } else {
1.611 raeburn 5740: if ($canedit) {
1.484 raeburn 5741: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5742: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5743: }
5744: }
1.329 droeschl 5745: }
5746:
1.344 bisitz 5747: # get personal data
1.329 droeschl 5748: my $uname=$env{'user.name'};
5749: my $udom=$env{'user.domain'};
5750: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5751:
5752: if ($allowed) {
1.484 raeburn 5753: if ($toolsflag) {
5754: $script .= &inject_data_js();
5755: my ($home,$other,%outhash)=&authorhosts();
5756: if (!$home && $other) {
5757: my @hosts;
5758: foreach my $aurole (keys(%outhash)) {
5759: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5760: push(@hosts,$outhash{$aurole});
5761: }
5762: }
5763: $script .= &dump_switchserver_js(@hosts);
5764: }
1.458 raeburn 5765: } else {
1.570 raeburn 5766: my $tid = 1;
1.484 raeburn 5767: my @tabids;
5768: if ($supplementalflag) {
1.655 raeburn 5769: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 5770: $tid = 2;
1.484 raeburn 5771: } else {
5772: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5773: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5774: unshift(@tabids,'001');
5775: push(@tabids,('dd1','ee1'));
5776: }
1.458 raeburn 5777: }
1.484 raeburn 5778: my $tabidstr = join("','",@tabids);
1.644 raeburn 5779: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
1.600 raeburn 5780: my $posslti = keys(%ltitools);
1.622 raeburn 5781: my $hostname = $r->hostname();
1.606 raeburn 5782: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5783: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5784: &history_tab_js().
5785: &inject_data_js().
1.570 raeburn 5786: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5787: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5788: $addentries = {
1.485 raeburn 5789: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5790: };
1.458 raeburn 5791: }
1.538 raeburn 5792: $script .= &paste_popup_js();
1.501 raeburn 5793: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5794: &mt('Switch server?');
5795:
5796:
1.329 droeschl 5797: }
5798: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5799: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5800: .'// <![CDATA['."\n"
5801: .$script."\n"
5802: .'// ]]>'."\n"
1.595 musolffc 5803: .'</script>'."\n"
5804: .'<script type="text/javascript"
5805: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5806:
5807: # Breadcrumbs
5808: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5809:
5810: if ($showdoc) {
5811: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5812: {'force_register' => $showdoc,}));
1.571 raeburn 5813: } elsif ($toolsflag) {
1.611 raeburn 5814: my ($breadtext,$breadtitle);
1.617 raeburn 5815: $breadtext = "$crstype Editor";
1.611 raeburn 5816: if ($canedit) {
5817: $breadtitle = 'Editing '.$crstype.' Contents';
5818: } else {
5819: $breadtext .= ' (View-only mode)';
5820: $breadtitle = 'Viewing '.$crstype.' Contents';
5821: }
1.571 raeburn 5822: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5823: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5824: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5825: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5826: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5827: $breadtitle)
1.571 raeburn 5828: );
1.510 raeburn 5829: } elsif ($r->uri eq '/adm/supplemental') {
5830: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5831: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5832: {'bread_crumbs' => $brcrum,}));
5833: } else {
1.611 raeburn 5834: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5835: $breadtext = "$crstype Editor";
1.611 raeburn 5836: if ($canedit) {
5837: $breadtitle = 'Editing '.$crstype.' Contents';
5838: $helpitem = 'Docs_Adding_Course_Doc';
5839: } else {
5840: $breadtext .= ' (View-only mode)';
5841: $breadtitle = 'Viewing '.$crstype.' Contents';
5842: $helpitem = 'Docs_Viewing_Course_Doc';
5843: }
1.392 raeburn 5844: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5845: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5846: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5847: {'add_entries' => $addentries}
5848: )
1.392 raeburn 5849: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5850: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5851: $breadtitle,
5852: $helpitem)
1.392 raeburn 5853: );
5854: }
1.364 bisitz 5855:
1.329 droeschl 5856: my %allfiles = ();
5857: my %codebase = ();
1.440 raeburn 5858: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5859: if ($canedit) {
1.329 droeschl 5860: if (($env{'form.uploaddoc.filename'}) &&
5861: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5862: my $context = $1;
5863: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5864: undef($hadchanges);
1.440 raeburn 5865: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5866: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 5867: undef($navmap);
1.329 droeschl 5868: if ($hadchanges) {
5869: &mark_hash_old();
5870: }
1.440 raeburn 5871: $r->print($upload_output);
5872: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5873: # Process file upload - phase two - upload embedded objects
5874: $uploadphase = 'check_embedded';
5875: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5876: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5877: $env{'form.newidx'});
5878: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5879: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5880: my ($destination,$dir_root) = &embedded_destination();
5881: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5882: my $actionurl = '/adm/coursedocs';
1.630 raeburn 5883: my ($result,$flag) =
1.440 raeburn 5884: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5885: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5886: $actionurl);
5887: $r->print($result.&return_to_editor());
5888: } elsif ($env{'form.phase'} eq 'check_embedded') {
5889: # Process file upload - phase three - modify references in HTML file
5890: $uploadphase = 'modified_orightml';
5891: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5892: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5893: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 5894: my $result =
1.482 raeburn 5895: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5896: $docuname,$docudom,undef,
5897: $dir_root);
1.630 raeburn 5898: $r->print($result.&return_to_editor());
1.476 raeburn 5899: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5900: $uploadphase = 'decompress_phase_one';
5901: $r->print(&decompression_phase_one().
5902: &return_to_editor());
5903: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5904: $uploadphase = 'decompress_phase_two';
5905: $r->print(&decompression_phase_two().
5906: &return_to_editor());
1.329 droeschl 5907: }
5908: }
5909:
1.484 raeburn 5910: if ($allowed && $toolsflag) {
5911: $r->print(&startContentScreen('tools'));
1.611 raeburn 5912: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5913: $r->print(&endContentScreen());
5914: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5915: # -----------------------------------------------------------------------------
5916: my %lt=&Apache::lonlocal::texthash(
5917: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5918: 'upfi' => 'Upload File',
1.553 raeburn 5919: 'upld' => 'Upload Content',
1.329 droeschl 5920: 'srch' => 'Search',
5921: 'impo' => 'Import',
1.487 raeburn 5922: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5923: 'impm' => 'Import from Assembled Map',
1.630 raeburn 5924: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5925: 'extr' => 'External Resource',
5926: 'extt' => 'External Tool',
1.329 droeschl 5927: 'selm' => 'Select Map',
5928: 'load' => 'Load Map',
5929: 'newf' => 'New Folder',
5930: 'newp' => 'New Composite Page',
5931: 'syll' => 'Syllabus',
1.425 raeburn 5932: 'navc' => 'Table of Contents',
1.343 biermanm 5933: 'sipa' => 'Simple Course Page',
1.329 droeschl 5934: 'sipr' => 'Simple Problem',
1.630 raeburn 5935: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5936: 'stpr' => 'Standard Problem',
5937: 'news' => 'New sub-directory',
5938: 'crpr' => 'Create Problem',
1.329 droeschl 5939: 'drbx' => 'Drop Box',
1.451 www 5940: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5941: 'bull' => 'Discussion Board',
1.347 weissno 5942: 'mypi' => 'My Personal Information Page',
1.353 weissno 5943: 'grpo' => 'Group Portfolio',
1.329 droeschl 5944: 'rost' => 'Course Roster',
1.528 raeburn 5945: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5946: 'imsf' => 'IMS Upload',
5947: 'imsl' => 'Upload IMS package',
1.501 raeburn 5948: 'cms' => 'Origin of IMS package',
5949: 'se' => 'Select',
1.329 droeschl 5950: 'file' => 'File',
5951: 'title' => 'Title',
1.606 raeburn 5952: 'addp' => 'Add Placeholder to course?',
5953: 'uste' => 'Use Template?',
5954: 'fnam' => 'File Name:',
5955: 'loca' => 'Location:',
5956: 'dire' => 'Directory:',
5957: 'cate' => 'Category:',
5958: 'tmpl' => 'Template:',
1.329 droeschl 5959: 'comment' => 'Comment',
1.403 raeburn 5960: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5961: 'bb5' => 'Blackboard 5',
5962: 'bb6' => 'Blackboard 6',
5963: 'angel5' => 'ANGEL 5.5',
5964: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5965: 'yes' => 'Yes',
5966: 'no' => 'No',
1.618 raeburn 5967: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5968: );
1.329 droeschl 5969: # -----------------------------------------------------------------------------
1.595 musolffc 5970:
5971: # Calculate free quota space for a user or course. A javascript function checks
5972: # file size to determine if upload should be allowed.
5973: my $quotatype = 'unofficial';
5974: if ($crstype eq 'Community') {
1.601 raeburn 5975: $quotatype = 'community';
5976: } elsif ($crstype eq 'Placement') {
5977: $quotatype = 'placement';
1.595 musolffc 5978: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5979: $quotatype = 'official';
5980: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5981: $quotatype = 'textbook';
5982: }
5983: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5984: 'course',$quotatype); # expressed in MB
5985: my $current_disk_usage = 0;
5986: foreach my $subdir ('docs','supplemental') {
5987: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5988: "userfiles/$subdir",1); # expressed in kB
5989: }
5990: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5991: my $usage = $current_disk_usage/1024; # in MB
5992: my $quota = $disk_quota;
5993: my $percent;
5994: if ($disk_quota == 0) {
5995: $percent = 100.0;
5996: } else {
1.619 raeburn 5997: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5998: }
5999: $usage = sprintf("%.2f",$usage);
6000: $quota = sprintf("%.2f",$quota);
6001: $percent = sprintf("%.0f",$percent);
6002: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6003: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 6004:
1.329 droeschl 6005: my $fileupload=(<<FIUP);
1.605 raeburn 6006: $quotainfo
1.329 droeschl 6007: $lt{'file'}:<br />
1.662 raeburn 6008: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
1.663 raeburn 6009: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 6010: FIUP
6011:
6012: my $checkbox=(<<CHBO);
6013: <!-- <label>$lt{'parse'}?
6014: <input type="checkbox" name="parserflag" />
6015: </label> -->
6016: <label>
1.611 raeburn 6017: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6018: </label>
6019: CHBO
1.501 raeburn 6020: my $imsfolder = $env{'form.folder'};
6021: if ($imsfolder eq '') {
6022: $imsfolder = 'default';
6023: }
6024: my $imspform=(<<IMSFORM);
6025: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6026: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6027: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 6028: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 6029: <legend>$lt{'imsf'}</legend>
6030: $fileupload
6031: <br />
6032: <p>
6033: $lt{'cms'}:
1.611 raeburn 6034: <select name="source" $disabled>
1.501 raeburn 6035: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 6036: <option value="bb5">$lt{'bb5'}</option>
6037: <option value="bb6">$lt{'bb6'}</option>
6038: <option value="angel5">$lt{'angel5'}</option>
6039: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 6040: </select>
6041: <input type="hidden" name="folder" value="$imsfolder" />
6042: </p>
6043: <input type="hidden" name="phase" value="one" />
1.611 raeburn 6044: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 6045: </fieldset>
6046: </form>
6047: IMSFORM
1.329 droeschl 6048:
6049: my $fileuploadform=(<<FUFORM);
1.501 raeburn 6050: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6051: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6052: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 6053: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 6054: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6055: <input type="hidden" name="active" value="aa" />
1.595 musolffc 6056: $fileupload
1.329 droeschl 6057: <br />
6058: $lt{'title'}:<br />
1.611 raeburn 6059: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 6060: $pathitem
1.329 droeschl 6061: <input type="hidden" name="cmd" value="upload_default" />
6062: <br />
1.458 raeburn 6063: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6064: $checkbox
6065: </span>
1.501 raeburn 6066: <br clear="all" />
1.611 raeburn 6067: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 6068: </fieldset>
6069: </form>
1.383 tempelho 6070: FUFORM
1.329 droeschl 6071:
1.611 raeburn 6072: my $mapimportjs;
6073: if ($canedit) {
6074: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6075: } else {
6076: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6077: }
1.502 raeburn 6078: my $importpubform=(<<SEDFFORM);
1.514 raeburn 6079: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 6080: $lt{'impm'}</a>$help{'Load_Map'}
6081: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 6082: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 6083: <legend>$lt{'impm'}</legend>
1.371 tempelho 6084: <input type="hidden" name="active" value="bb" />
1.502 raeburn 6085: $lt{'copm'}<br />
6086: <span class="LC_nobreak">
6087: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 6088: onfocus="this.blur();$mapimportjs" $disabled />
6089: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6090: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 6091: </fieldset>
6092: </form>
6093:
1.383 tempelho 6094: SEDFFORM
1.606 raeburn 6095: my $importcrsresform;
1.608 raeburn 6096: my ($numdirs,$pickfile) =
6097: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
6098: "resize_scrollbox('contentscroll','1','0');",
6099: undef,'res');
1.606 raeburn 6100: if ($pickfile) {
6101: $importcrsresform=(<<CRSFORM);
6102: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
6103: $lt{'imcr'}</a>$help{'Course_Resources'}
6104: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6105: <fieldset id="importcrsresform" style="display: none;">
6106: <legend>$lt{'imcr'}</legend>
6107: <input type="hidden" name="active" value="bb" />
6108: $pickfile
6109: <p>
1.611 raeburn 6110: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 6111: </p>
6112: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 6113: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 6114: </fieldset>
6115: </form>
6116: CRSFORM
6117: }
6118:
1.611 raeburn 6119: my $fromstoredjs;
6120: if ($canedit) {
6121: $fromstoredjs = 'open_StoredLinks_Import()';
6122: } else {
6123: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6124: }
6125:
1.502 raeburn 6126: my @importpubforma = (
1.508 raeburn 6127: { '<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 6128: { '<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 6129: { '<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 6130: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6131: );
6132: if ($pickfile) {
6133: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
6134: }
1.502 raeburn 6135: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 6136: my $extresourcesform =
6137: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6138: $help{'Adding_External_Resource'},
6139: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6140: my $exttoolform =
6141: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6142: $help{'Adding_External_Tool'},undef,
6143: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6144: \%ltitools,$disabled);
1.329 droeschl 6145: if ($allowed) {
1.492 raeburn 6146: my $folder = $env{'form.folder'};
6147: if ($folder eq '') {
6148: $folder='default';
6149: }
1.615 raeburn 6150: if ($canedit) {
6151: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6152: if ($output) {
6153: $r->print($output);
6154: }
1.538 raeburn 6155: }
1.337 ehlerst 6156: $r->print(<<HIDDENFORM);
6157: <form name="renameform" method="post" action="/adm/coursedocs">
6158: <input type="hidden" name="title" />
6159: <input type="hidden" name="cmd" />
6160: <input type="hidden" name="markcopy" />
6161: <input type="hidden" name="copyfolder" />
6162: $containertag
6163: </form>
1.633 raeburn 6164: <form name="aliasform" method="post" action="/adm/coursedocs">
6165: <input type="hidden" name="alias" />
6166: <input type="hidden" name="cmd" />
6167: $containertag
6168: </form>
1.484 raeburn 6169:
1.337 ehlerst 6170: HIDDENFORM
1.508 raeburn 6171: $r->print(&makesimpleeditform($pathitem)."\n".
6172: &makedocslogform($pathitem."\n".
1.484 raeburn 6173: '<input type="hidden" name="folder" value="'.
6174: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6175: }
1.442 www 6176:
6177: # Generate the tabs
1.510 raeburn 6178: my ($mode,$needs_end);
1.472 raeburn 6179: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6180: my @folders = split('&',$env{'form.folderpath'});
6181: unless (@folders > 2) {
6182: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6183: $needs_end = 1;
6184: }
1.472 raeburn 6185: } else {
1.484 raeburn 6186: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6187: $needs_end = 1;
1.472 raeburn 6188: }
1.443 www 6189:
1.442 www 6190: #
1.622 raeburn 6191: my $hostname = $r->hostname();
1.442 www 6192: my $savefolderpath;
6193:
1.395 raeburn 6194: if ($allowed) {
1.329 droeschl 6195: my $folder=$env{'form.folder'};
1.615 raeburn 6196: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6197: $folder='default';
1.356 tempelho 6198: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6199: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6200: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6201: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6202: }
6203: my $postexec='';
6204: if ($folder eq 'default') {
1.653 raeburn 6205: my $windowname = 'loncapaclient';
6206: if ($env{'request.lti.login'}) {
6207: $windowname .= 'lti';
6208: }
1.372 bisitz 6209: $r->print('<script type="text/javascript">'."\n"
6210: .'// <![CDATA['."\n"
1.653 raeburn 6211: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 6212: .'// ]]>'."\n"
6213: .'</script>'."\n"
1.369 bisitz 6214: );
1.329 droeschl 6215: } else {
6216: #$postexec='self.close();';
6217: }
1.504 raeburn 6218: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6219: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6220: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6221:
6222: my $newnavform=(<<NNFORM);
6223: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 6224: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6225: $pathitem
1.329 droeschl 6226: <input type="hidden" name="importdetail"
6227: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6228: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6229: $help{'Navigate_Content'}
6230: </form>
6231: NNFORM
6232: my $newsmppageform=(<<NSPFORM);
6233: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 6234: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6235: $pathitem
1.329 droeschl 6236: <input type="hidden" name="importdetail" value="" />
1.423 onken 6237: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6238: $help{'Simple Page'}
1.329 droeschl 6239: </form>
6240: NSPFORM
6241:
6242: my $newsmpproblemform=(<<NSPROBFORM);
6243: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 6244: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6245: $pathitem
1.329 droeschl 6246: <input type="hidden" name="importdetail" value="" />
1.423 onken 6247: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6248: $help{'Simple_Problem'}
1.329 droeschl 6249: </form>
6250:
6251: NSPROBFORM
6252:
6253: my $newdropboxform=(<<NDBFORM);
6254: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 6255: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6256: $pathitem
1.329 droeschl 6257: <input type="hidden" name="importdetail" value="" />
1.423 onken 6258: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6259: $help{'Dropbox'}
1.344 bisitz 6260: </form>
1.329 droeschl 6261: NDBFORM
6262:
6263: my $newexuploadform=(<<NEXUFORM);
6264: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 6265: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6266: $pathitem
1.329 droeschl 6267: <input type="hidden" name="importdetail" value="" />
1.423 onken 6268: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6269: $help{'Score_Upload_Form'}
6270: </form>
6271: NEXUFORM
6272:
6273: my $newbulform=(<<NBFORM);
6274: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 6275: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6276: $pathitem
1.329 droeschl 6277: <input type="hidden" name="importdetail" value="" />
1.423 onken 6278: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6279: $help{'Bulletin Board'}
6280: </form>
6281: NBFORM
6282:
6283: my $newaboutmeform=(<<NAMFORM);
6284: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 6285: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6286: $pathitem
1.329 droeschl 6287: <input type="hidden" name="importdetail"
6288: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6289: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6290: $help{'My Personal Information Page'}
1.329 droeschl 6291: </form>
6292: NAMFORM
6293:
6294: my $newaboutsomeoneform=(<<NASOFORM);
6295: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 6296: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6297: $pathitem
1.329 droeschl 6298: <input type="hidden" name="importdetail" value="" />
1.423 onken 6299: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6300: </form>
6301: NASOFORM
6302:
6303: my $newrosterform=(<<NROSTFORM);
6304: <form action="/adm/coursedocs" method="post" name="newroster">
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"
6308: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6309: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6310: $help{'Course_Roster'}
1.329 droeschl 6311: </form>
6312: NROSTFORM
6313:
1.534 raeburn 6314: my $newwebpage;
6315: if ($folder =~ /^default_?(\d*)$/) {
6316: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6317: if ($1) {
6318: $newwebpage .= $1;
6319: } else {
6320: $newwebpage .= 'default';
6321: }
6322: $newwebpage .= '/new.html';
6323: }
6324: my $newwebpageform =(<<NWEBFORM);
6325: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 6326: <input type="hidden" name="active" value="ff" />
1.534 raeburn 6327: $pathitem
6328: <input type="hidden" name="importdetail" value="$newwebpage" />
6329: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6330: $help{'Web_Page'}
1.534 raeburn 6331: </form>
6332: NWEBFORM
1.604 raeburn 6333:
1.606 raeburn 6334: my @ids=&Apache::lonnet::current_machine_ids();
6335: my %select_menus;
6336: my $numauthor = 0;
6337: my $numcrsdirs = 0;
6338: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
6339: if ($env{'user.author'}) {
6340: $numauthor ++;
6341: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6342: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6343: my $is_home = 1;
6344: my %subdirs;
1.608 raeburn 6345: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6346: $select_menus{'author'}->{'default'} = '/';
6347: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6348: my @ordered = ('/');
6349: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6350: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6351: push(@ordered,$relpath);
6352: }
6353: $select_menus{'author'}->{'order'} = \@ordered;
6354: } else {
6355: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6356: $select_menus{'author'}->{'default'} = 'switch';
6357: $select_menus{'author'}->{'order'} = ['switch'];
6358: }
6359: }
6360: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6361: ['active'],['ca','aa']);
6362: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6363: my %by_roletype;
6364: if (keys(%roleshash)) {
6365: foreach my $entry (keys(%roleshash)) {
6366: my ($auname,$audom,$roletype) = split(/:/,$entry);
6367: my $key = $entry;
6368: $key =~ s/:/___/g;
6369: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6370: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6371: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6372: if (grep(/^\Q$rolehome\E$/,@ids)) {
6373: my $is_home = 1;
6374: my (%subdirs,@ordered);
6375: my $toppath="/priv/$audom/$auname";
1.608 raeburn 6376: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6377: $select_menus{$key}->{'default'} = '/';
6378: $select_menus{$key}->{'select2'}->{'/'} = '/';
6379: my @ordered = ('/');
6380: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6381: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6382: push(@ordered,$relpath);
6383: }
6384: $select_menus{$key}->{'order'} = \@ordered;
6385: } else {
6386: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6387: $select_menus{$key}->{'default'} = 'switch';
6388: $select_menus{$key}->{'order'} = ['switch'];
6389: }
6390: $numauthor ++;
6391: }
6392: }
1.631 raeburn 6393: my ($pickdir,$showtitle);
1.606 raeburn 6394: if ($numauthor) {
6395: my @order;
6396: my $defrole;
6397: if ($env{'user.author'}) {
6398: push(@order,'author');
6399: $defrole = 'author';
6400: }
6401: if (keys(%by_roletype)) {
6402: foreach my $possrole ('ca','aa') {
6403: if (ref($by_roletype{$possrole}) eq 'HASH') {
6404: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6405: unless ($defrole) {
6406: $defrole = $author;
6407: }
6408: push(@order,$author.'___'.$possrole);
6409: }
6410: }
6411: }
6412: }
6413: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6414: if (grep(/^\Q$crshome\E$/,@ids)) {
6415: my $is_home = 1;
6416: my %subdirs;
6417: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6418: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6419: $numcrsdirs = keys(%subdirs);
6420: $select_menus{'course'}->{'default'} = '/';
6421: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6422: my @ordered = ('/');
6423: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6424: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6425: push(@ordered,$relpath);
6426: }
6427: $select_menus{'course'}->{'order'} = \@ordered;
6428: } else {
6429: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6430: $select_menus{'course'}->{'default'} = 'switch';
6431: $select_menus{'course'}->{'order'} = ['switch'];
6432: }
6433: push(@order,'course');
6434: $pickdir = $lt{'loca'}.
6435: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6436: $defrole,'authorrole','authorpath',
6437: \%select_menus,\@order,'toggleCrsResTitle();',
6438: '','priv').'<br />';
6439: $showtitle = 'none';
6440: } else {
6441: my $is_home;
6442: $showtitle = 'inline';
6443: if (grep(/^\Q$crshome\E$/,@ids)) {
6444: $is_home = 1;
6445: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6446: my $toppath="/priv/$coursedom/$coursenum'}";
6447: my %subdirs;
1.608 raeburn 6448: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6449: $numcrsdirs = keys(%subdirs);
6450: if ($numcrsdirs) {
6451: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6452: '<option value="/">/</option>'."\n";
6453: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6454: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6455: }
6456: $pickdir .= '</select>';
6457: } else {
6458: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6459: }
6460: }
6461: }
6462:
6463: my %seltemplate_menus;
6464: my @files = &Apache::lonhomework::get_template_list('problem');
6465: my @noexamplelink = ('blank.problem','blank.library','script.library');
6466: my $currentcategory = '';
6467: my @ordered = ('');
6468: my %templatehelp;
6469: my $defcategory = '';
6470: my @catorder = ($defcategory);
6471: $seltemplate_menus{$defcategory}->{'order'} = [''];
6472: $seltemplate_menus{$defcategory}->{'text'} = '';
6473: foreach my $file (@files) {
6474: if (ref($file) eq 'ARRAY') {
6475: my ($path,$title,$category,$help) = @{$file};
6476: next if ($title !~ /\S/);
6477: if (&js_escape($category) ne $currentcategory) {
6478: $currentcategory = &js_escape($category);
6479: push(@catorder,&js_escape($currentcategory));
6480: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6481: $seltemplate_menus{$currentcategory}->{'default'} = '';
6482: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6483: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6484: }
6485: if ($path) {
6486: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6487: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6488: if ($help) {
6489: $templatehelp{$path} = $help;
6490: }
6491: }
6492: }
6493: }
6494:
6495: my $templates = $lt{'cate'}.' '.
6496: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6497: $defcategory,'tempcategory','template',
6498: \%seltemplate_menus,\@catorder,
6499: "resize_scrollbox('contentscroll','1','0');",
6500: "toggleExampleText();",'template').'<br />';
6501: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6502: '<span id="newresexample">'.&mt('Example').'<span></a>';
6503: my $crsresform=(<<RESFORM);
6504: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6505: $lt{'stpr'}</a>$help{'Course_Resource'}
6506: <form action="/adm/coursedocs" method="post" name="courseresform">
6507: <fieldset id="crsresform" style="display:none;">
6508: <legend>$lt{'stpr'}</legend>
1.655 raeburn 6509: <input type="hidden" name="active" value="bb" />
1.606 raeburn 6510: <p>
6511: $pickdir
6512: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6513: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6514:
1.611 raeburn 6515: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6516: </span><span id="newsubdir"></span>
6517: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6518: </p>
6519: $lt{'fnam'}
1.611 raeburn 6520: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6521: <p>
6522: <div id="newresource" style="display:$showtitle">
6523: $lt{'addp'}
1.611 raeburn 6524: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6525: $lt{'no'}</label>
1.611 raeburn 6526: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6527: $lt{'yes'}</label>
6528: <span id="newrestitle"></span>
1.611 raeburn 6529: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6530: </div>
6531: </p>
6532: <p>
6533: $lt{'uste'}
1.611 raeburn 6534: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6535: $lt{'no'}</label>
1.611 raeburn 6536: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6537: $lt{'yes'}</label>
6538: <div id="newrestemplate" style="display:none">
6539: $templates
6540: $templatepreview
6541: </div>
6542: </p>
6543: <span class="LC_nobreak">
6544: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6545: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6546: </span>
6547: </fieldset>
6548: </form>
6549:
6550: RESFORM
1.534 raeburn 6551:
1.342 ehlerst 6552: my $specialdocumentsform;
1.383 tempelho 6553: my @specialdocumentsforma;
1.451 www 6554: my $gradingform;
6555: my @gradingforma;
6556: my $communityform;
6557: my @communityforma;
1.351 ehlerst 6558: my $newfolderform;
1.390 tempelho 6559: my $newfolderb;
1.342 ehlerst 6560:
1.451 www 6561: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6562:
1.329 droeschl 6563: my $newpageform=(<<NPFORM);
6564: <form action="/adm/coursedocs" method="post" name="newpage">
6565: <input type="hidden" name="folderpath" value="$path" />
6566: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6567: <input type="hidden" name="active" value="ee" />
1.423 onken 6568: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6569: $help{'Adding_Pages'}
1.329 droeschl 6570: </form>
6571: NPFORM
1.390 tempelho 6572:
6573:
1.351 ehlerst 6574: $newfolderform=(<<NFFORM);
1.329 droeschl 6575: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6576: $pathitem
1.329 droeschl 6577: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6578: <input type="hidden" name="active" value="" />
1.422 onken 6579: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6580: </form>
6581: NFFORM
6582:
6583: my $newsylform=(<<NSYLFORM);
6584: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6585: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6586: $pathitem
1.329 droeschl 6587: <input type="hidden" name="importdetail"
6588: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6589: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6590: $help{'Syllabus'}
1.383 tempelho 6591:
1.329 droeschl 6592: </form>
6593: NSYLFORM
1.364 bisitz 6594:
1.329 droeschl 6595: my $newgroupfileform=(<<NGFFORM);
6596: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 6597: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6598: $pathitem
1.329 droeschl 6599: <input type="hidden" name="importdetail"
6600: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6601: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6602: $help{'Group Portfolio'}
1.329 droeschl 6603: </form>
6604: NGFFORM
1.672 raeburn 6605: if ($container eq 'page') {
6606: @specialdocumentsforma=(
6607: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6608: );
6609: } else {
6610: @specialdocumentsforma=(
1.421 onken 6611: {'<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 6612: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6613: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6614: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6615: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 6616: );
6617: }
1.451 www 6618: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6619:
1.655 raeburn 6620: my @external = (
6621: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 6622: );
1.598 raeburn 6623: if (keys(%ltitools)) {
1.655 raeburn 6624: push(@external,
6625: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6626: );
1.598 raeburn 6627: }
1.655 raeburn 6628: my $externalform = &create_form_ul(&create_list_elements(@external));
6629:
6630: my @importdoc = ();
1.519 raeburn 6631: unless ($container eq 'page') {
6632: push(@importdoc,
6633: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6634: );
6635: }
6636: push(@importdoc,
1.558 raeburn 6637: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6638: );
1.501 raeburn 6639: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6640:
1.451 www 6641: @gradingforma=(
6642: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6643: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6644: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6645: {'<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 6646: );
6647: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6648:
6649: @communityforma=(
6650: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6651: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6652: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6653: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6654: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6655: );
6656: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6657:
1.330 tempelho 6658: my %orderhash = (
1.553 raeburn 6659: 'aa' => ['Upload',$fileuploadform],
6660: 'bb' => ['Import',$importpubform],
1.655 raeburn 6661: 'cc' => ['External',$externalform],
6662: 'dd' => ['Grading',$gradingform],
1.673 raeburn 6663: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 6664: );
1.519 raeburn 6665: unless ($container eq 'page') {
1.434 raeburn 6666: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 6667: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 6668: }
6669:
1.341 ehlerst 6670: $hadchanges=0;
1.484 raeburn 6671: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6672: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6673: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6674: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6675: undef($navmap);
1.443 www 6676: if ($error) {
6677: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6678: }
1.639 raeburn 6679: if ($hadchanges) {
6680: unless (&is_hash_old()) {
1.638 raeburn 6681: &mark_hash_old();
6682: }
6683: }
1.341 ehlerst 6684:
1.443 www 6685: &changewarning($r,'');
6686: }
1.458 raeburn 6687: }
1.442 www 6688:
1.443 www 6689: # Supplemental documents start here
6690:
1.329 droeschl 6691: my $folder=$env{'form.folder'};
1.443 www 6692: unless ($supplementalflag) {
1.329 droeschl 6693: $folder='supplemental';
6694: }
6695: if ($folder =~ /^supplemental$/ &&
6696: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6697: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6698: } elsif ($allowed) {
1.356 tempelho 6699: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6700: }
1.508 raeburn 6701: $pathitem = '<input type="hidden" name="folderpath" value="'.
6702: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6703: if ($allowed) {
6704: my $folderseq=
1.504 raeburn 6705: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6706:
6707: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6708: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6709: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6710: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6711: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6712: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6713: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6714: $fileupload
6715: <br />
6716: <br />
6717: <span class="LC_nobreak">
6718: $checkbox
6719: </span>
6720: <br /><br />
6721: $lt{'comment'}:<br />
1.383 tempelho 6722: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6723: <br />
1.508 raeburn 6724: $pathitem
1.329 droeschl 6725: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6726: <input type='submit' value="$lt{'upld'}" />
6727: </form>
1.329 droeschl 6728: SUPDOCFORM
6729:
6730: my $supnewfolderform=(<<SNFFORM);
6731: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6732: <input type="hidden" name="active" value="" />
1.508 raeburn 6733: $pathitem
1.329 droeschl 6734: <input type="hidden" name="importdetail" value="" />
1.423 onken 6735: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6736: $help{'Adding_Folders'}
1.329 droeschl 6737: </form>
6738: SNFFORM
1.383 tempelho 6739:
1.510 raeburn 6740: my $supextform =
6741: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6742: $help{'Adding_External_Resource'},
6743: undef,undef,undef,undef,undef,undef,
6744: $disabled);
1.329 droeschl 6745:
1.598 raeburn 6746: my $supexttoolform =
6747: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6748: $help{'Adding_External_Tool'},
6749: undef,undef,'tool',$coursedom,
1.611 raeburn 6750: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6751:
1.329 droeschl 6752: my $supnewsylform=(<<SNSFORM);
6753: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6754: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6755: $pathitem
1.329 droeschl 6756: <input type="hidden" name="importdetail"
6757: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6758: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6759: $help{'Syllabus'}
6760: </form>
6761: SNSFORM
6762:
6763: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6764: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6765: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6766: $pathitem
1.329 droeschl 6767: <input type="hidden" name="importdetail"
6768: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6769: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6770: $help{'My Personal Information Page'}
1.329 droeschl 6771: </form>
6772: SNAMFORM
6773:
1.534 raeburn 6774: my $supwebpage;
6775: if ($folder =~ /^supplemental_?(\d*)$/) {
6776: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6777: if ($1) {
6778: $supwebpage .= $1;
6779: } else {
6780: $supwebpage .= 'default';
6781: }
6782: $supwebpage .= '/new.html';
6783: }
6784: my $supwebpageform =(<<SWEBFORM);
6785: <form action="/adm/coursedocs" method="post" name="supwebpage">
6786: <input type="hidden" name="active" value="cc" />
6787: $pathitem
6788: <input type="hidden" name="importdetail" value="$supwebpage" />
6789: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6790: $help{'Web_Page'}
1.534 raeburn 6791: </form>
6792: SWEBFORM
6793:
1.333 muellerd 6794:
1.383 tempelho 6795: my @specialdocs = (
1.618 raeburn 6796: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6797: =>$supnewsylform},
1.611 raeburn 6798: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6799: =>$supnewaboutmeform},
1.534 raeburn 6800: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6801:
1.383 tempelho 6802: );
1.655 raeburn 6803: my @supexternal = (
6804: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
6805: =>$supextform});
1.598 raeburn 6806: if (keys(%ltitools)) {
1.655 raeburn 6807: push(@supexternal,
6808: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 6809: =>$supexttoolform});
6810: }
1.655 raeburn 6811: my @supimportdoc = (
1.598 raeburn 6812: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6813: =>$supupdocform},
1.598 raeburn 6814: );
1.501 raeburn 6815:
6816: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6817: my %suporderhash = (
1.390 tempelho 6818: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 6819: 'dd' => ['Upload',$supupdocform],
6820: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 6821: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6822: );
1.443 www 6823: if ($supplementalflag) {
1.458 raeburn 6824: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6825: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 raeburn 6826: \%ltitools,$canedit,$hostname);
1.443 www 6827: if ($error) {
6828: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6829: } else {
6830: if ($suppchanges) {
6831: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6832: my @ids=&Apache::lonnet::current_machine_ids();
6833: foreach my $server (keys(%servers)) {
6834: next if (grep(/^\Q$server\E$/,@ids));
6835: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6836: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6837: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6838: }
6839: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6840: undef($suppchanges);
1.630 raeburn 6841: }
6842: }
1.393 raeburn 6843: }
1.443 www 6844: } elsif ($supplementalflag) {
1.458 raeburn 6845: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 raeburn 6846: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6847: if ($error) {
6848: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6849: }
1.393 raeburn 6850: }
1.389 tempelho 6851:
1.510 raeburn 6852: if ($needs_end) {
6853: $r->print(&endContentScreen());
6854: }
1.383 tempelho 6855:
1.329 droeschl 6856: if ($allowed) {
6857: $r->print('
6858: <form method="post" name="extimport" action="/adm/coursedocs">
6859: <input type="hidden" name="title" />
6860: <input type="hidden" name="url" />
6861: <input type="hidden" name="useform" />
6862: <input type="hidden" name="residx" />
6863: </form>');
6864: }
1.484 raeburn 6865: } elsif ($showdoc) {
1.329 droeschl 6866: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6867: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6868: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6869: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6870: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6871: }
6872: }
1.630 raeburn 6873: unless ($noendpage) {
1.606 raeburn 6874: $r->print(&Apache::loncommon::end_page());
6875: }
1.329 droeschl 6876: return OK;
1.364 bisitz 6877: }
1.329 droeschl 6878:
1.440 raeburn 6879: sub embedded_form_elems {
6880: my ($phase,$primaryurl,$newidx) = @_;
6881: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 6882: $newidx =~s /\D+//g;
1.440 raeburn 6883: return <<STATE;
6884: <input type="hidden" name="folderpath" value="$folderpath" />
6885: <input type="hidden" name="cmd" value="upload_embedded" />
6886: <input type="hidden" name="newidx" value="$newidx" />
6887: <input type="hidden" name="phase" value="$phase" />
6888: <input type="hidden" name="primaryurl" value="$primaryurl" />
6889: STATE
6890: }
6891:
6892: sub embedded_destination {
6893: my $folder=$env{'form.folder'};
6894: my $destination = 'docs/';
6895: if ($folder =~ /^supplemental/) {
6896: $destination = 'supplemental/';
6897: }
6898: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6899: $destination .= 'default/';
6900: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6901: $destination .= $2.'/';
6902: }
1.634 raeburn 6903: my $newidx = $env{'form.newidx'};
6904: $newidx =~s /\D+//g;
6905: if ($newidx) {
6906: $destination .= $newidx;
6907: }
1.440 raeburn 6908: my $dir_root = '/userfiles';
6909: return ($destination,$dir_root);
6910: }
6911:
6912: sub return_to_editor {
6913: my $actionurl = '/adm/coursedocs';
6914: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6915: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6916: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6917: '</a></p>';
6918: }
6919:
1.476 raeburn 6920: sub decompression_info {
6921: my ($destination,$dir_root) = &embedded_destination();
6922: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6923: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6924: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6925: my $container='sequence';
1.480 raeburn 6926: my ($pathitem,$hiddenelem);
1.583 raeburn 6927: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6928: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6929: $container='page';
6930: }
1.480 raeburn 6931: unshift(@hiddens,$pathitem);
6932: foreach my $item (@hiddens) {
1.634 raeburn 6933: if ($item eq 'newidx') {
6934: next if ($env{'form.'.$item} =~ /\D/);
6935: }
1.480 raeburn 6936: if ($env{'form.'.$item}) {
6937: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6938: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6939: }
1.477 raeburn 6940: }
1.476 raeburn 6941: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6942: $hiddenelem);
6943: }
6944:
6945: sub decompression_phase_one {
6946: my ($dir,$file,$warning,$error,$output);
6947: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6948: &decompression_info();
1.490 raeburn 6949: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6950: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6951: } else {
6952: my $file = $1;
1.630 raeburn 6953: $output =
1.481 raeburn 6954: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6955: $destination,$dir_root,
6956: $hiddenelem);
6957: if ($env{'form.autoextract_camtasia'}) {
6958: $output .= &remove_archive($docudom,$docuname,$container);
6959: }
1.476 raeburn 6960: }
6961: if ($error) {
6962: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6963: $error.'</p>'."\n";
6964: }
6965: if ($warning) {
6966: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6967: }
6968: return $output;
6969: }
6970:
6971: sub decompression_phase_two {
6972: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6973: &decompression_info();
1.481 raeburn 6974: my $output;
1.480 raeburn 6975: if ($env{'form.archivedelete'}) {
1.481 raeburn 6976: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6977: }
6978: $output .=
1.481 raeburn 6979: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6980: $destination,$dir_root,$hiddenelem);
6981: return $output;
6982: }
6983:
1.480 raeburn 6984: sub remove_archive {
6985: my ($docudom,$docuname,$container) = @_;
6986: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6987: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6988: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6989: if ($fatal) {
6990: if ($container eq 'page') {
6991: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6992: } else {
6993: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6994: }
1.583 raeburn 6995: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6996: } else {
6997: my $currcmd = $env{'form.cmd'};
6998: my $position = $env{'form.position'};
1.583 raeburn 6999: my $archiveidx = $position;
1.563 raeburn 7000: if ($position > 0) {
1.583 raeburn 7001: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7002: $archiveidx = $position-1;
7003: }
7004: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 7005: my ($title,$url,@rrest) =
1.583 raeburn 7006: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7007: if ($url eq $env{'form.archiveurl'}) {
7008: if (&handle_edit_cmd($docuname,$docudom)) {
7009: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
7010: if ($fatal) {
7011: if ($container eq 'page') {
7012: $delwarning = &mt('An error occurred updating the contents of the current page.');
7013: } else {
7014: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7015: }
1.480 raeburn 7016: } else {
1.583 raeburn 7017: $delresult = &mt('Archive file removed.');
1.480 raeburn 7018: }
7019: }
1.583 raeburn 7020: } else {
7021: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7022: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7023: }
7024: }
7025: $env{'form.cmd'} = $currcmd;
7026: }
7027: if ($delwarning) {
7028: $output = '<p class="LC_warning">'.
7029: $delwarning.
7030: '</p>';
7031: }
7032: if ($delresult) {
7033: $output .= '<p class="LC_info">'.
7034: $delresult.
7035: '</p>';
7036: }
1.481 raeburn 7037: return $output;
1.480 raeburn 7038: }
7039:
1.484 raeburn 7040: sub generate_admin_menu {
1.611 raeburn 7041: my ($crstype,$canedit) = @_;
1.484 raeburn 7042: my $lc_crstype = lc($crstype);
7043: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 7044: my %lt= ( # do not translate here
1.484 raeburn 7045: 'vc' => 'Verify Content',
7046: 'cv' => 'Check/Set Resource Versions',
7047: 'ls' => 'List Resource Identifiers',
1.651 raeburn 7048: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 7049: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 7050: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 7051: );
1.484 raeburn 7052: my ($candump,$dumpurl);
7053: if ($home + $other > 0) {
7054: $candump = 'F';
7055: if ($home) {
7056: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7057: } else {
7058: my @hosts;
7059: foreach my $aurole (keys(%outhash)) {
7060: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7061: push(@hosts,$outhash{$aurole});
1.538 raeburn 7062: }
1.484 raeburn 7063: }
7064: if (@hosts == 1) {
7065: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7066: '&role='.
7067: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7068: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7069: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7070: } else {
7071: $dumpurl = "javascript:choose_switchserver_window()";
7072: }
7073: }
7074: }
7075: my @menu=
7076: ({ categorytitle=>'Administration',
7077: items =>[
7078: { linktext => $lt{'vc'},
7079: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7080: permission => 'F',
1.571 raeburn 7081: help => 'Docs_Verify_Content',
1.484 raeburn 7082: icon => 'verify.png',
7083: linktitle => 'Verify contents can be retrieved/rendered',
7084: },
7085: { linktext => $lt{'cv'},
7086: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7087: permission => 'F',
1.571 raeburn 7088: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7089: icon => 'resversion.png',
7090: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7091: },
7092: { linktext => $lt{'ls'},
7093: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7094: permission => 'F',
7095: #help => '',
7096: icon => 'symbs.png',
7097: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7098: },
1.651 raeburn 7099: { linktext => $lt{'ct'},
7100: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7101: permission => 'F',
7102: help => 'Docs_Short_URLs',
7103: icon => 'shorturls.png',
7104: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7105: },
1.484 raeburn 7106: ]
1.611 raeburn 7107: });
7108: if ($canedit) {
7109: push(@menu,
1.484 raeburn 7110: { categorytitle=>'Export',
7111: items =>[
7112: { linktext => $lt{'imse'},
7113: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7114: permission => 'F',
7115: help => 'Docs_Export_Course_Docs',
7116: icon => 'imsexport.png',
7117: linktitle => $lt{'imse'},
7118: },
7119: { linktext => $lt{'dcd'},
7120: url => $dumpurl,
7121: permission => $candump,
1.571 raeburn 7122: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7123: icon => 'dump.png',
7124: linktitle => $lt{'dcd'},
7125: },
7126: ]
7127: });
1.611 raeburn 7128: }
1.484 raeburn 7129: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7130: '<input type="hidden" id="dummy" />'."\n".
7131: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7132: '</form>';
1.329 droeschl 7133: }
7134:
7135: sub generate_edit_table {
1.538 raeburn 7136: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 7137: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7138: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7139: my %orderhash = %{$orderhash_ref};
1.611 raeburn 7140: my ($form, $activetab, $active, $disabled);
1.570 raeburn 7141: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7142: $activetab = $env{'form.active'};
7143: }
1.611 raeburn 7144: unless ($canedit) {
7145: $disabled = ' disabled="disabled"';
7146: }
1.472 raeburn 7147: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 7148: my $backtext = &mt('Exit Editor');
1.458 raeburn 7149: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 7150: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7151: '<li class="goback">'.
1.546 raeburn 7152: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 7153: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7154: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7155: '<li>'.
7156: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7157: &mt('Undo Delete').'</a></li>'."\n";
7158: if ($env{'form.docslog'}) {
7159: $form .= '<li class="active">';
7160: } else {
7161: $form .= '<li>';
7162: }
7163: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7164: &mt('History').'</a></li>'."\n";
7165: if ($env{'form.docslog'}) {
7166: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7167: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7168: }
1.458 raeburn 7169: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7170: if($name ne '00'){
1.371 tempelho 7171: if($activetab eq '' || $activetab ne $name){
7172: $active = '';
7173: }elsif($activetab eq $name){
7174: $active = 'class="active"';
7175: }
1.458 raeburn 7176: $form .= '<li style="float:right" '.$active
1.484 raeburn 7177: .' 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 7178: } else {
1.570 raeburn 7179: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7180:
7181: }
1.329 droeschl 7182: }
1.484 raeburn 7183: $form .= '</ul>'."\n";
7184: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7185:
7186: if ($to_show ne '') {
1.538 raeburn 7187: my $saveform;
7188: if ($need_save) {
7189: my $button = &mt('Make changes');
7190: my $path;
7191: if ($env{'form.folderpath'}) {
7192: $path =
7193: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7194: }
7195: $saveform = <<"END";
7196: <div id="multisave" style="display:none; clear:both;" >
7197: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7198: <input type="hidden" name="folderpath" value="$path" />
7199: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7200: <input type="hidden" name="allhiddenresource" value="" />
7201: <input type="hidden" name="allencrypturl" value="" />
7202: <input type="hidden" name="allrandompick" value="" />
7203: <input type="hidden" name="allrandomorder" value="" />
7204: <input type="hidden" name="changeparms" value="" />
7205: <input type="hidden" name="multiremove" value="" />
7206: <input type="hidden" name="multicut" value="" />
7207: <input type="hidden" name="multicopy" value="" />
7208: <input type="hidden" name="multichange" value="" />
7209: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7210: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7211: </form>
7212: </div>
7213: END
7214: }
7215: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7216: }
1.363 ehlerst 7217: foreach my $field (keys(%orderhash)){
1.390 tempelho 7218: if($field ne '00'){
1.422 onken 7219: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7220: $active = 'style="display: none;float:left"';
1.422 onken 7221: }elsif($activetab eq $field){
1.458 raeburn 7222: $active = 'style="display:block;float:left"';
1.422 onken 7223: }
7224: $form .= '<div id="'.$field.$tid.'"'
7225: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7226: .'</div>'."\n";
1.363 ehlerst 7227: }
7228: }
1.484 raeburn 7229: unless ($env{'form.docslog'}) {
7230: $form .= '</div></div>'."\n";
7231: }
1.329 droeschl 7232: return $form;
7233: }
7234:
7235: sub editing_js {
1.622 raeburn 7236: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7237: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7238: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7239: p_mnf => 'Name of New Folder',
7240: t_mnf => 'New Folder',
7241: p_mnp => 'Name of New Page',
7242: t_mnp => 'New Page',
1.451 www 7243: p_mxu => 'Title for the External Score',
1.349 biermanm 7244: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7245: p_msb => 'Title for the Problem',
7246: p_mdb => 'Title for the Drop Box',
1.336 schafran 7247: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7248: p_mwp => 'Title for Web Page',
1.606 raeburn 7249: p_mnr => 'Title for the Resource',
1.348 weissno 7250: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7251: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7252: p_mab_alrt1 => 'Not a valid user:domain',
7253: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7254: p_chn => 'New Title',
7255: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7256: p_rmr2a => 'Remove',
7257: p_rmr2b => '?',
7258: p_rmr3a => 'Remove those',
7259: p_rmr3b => 'items?',
7260: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7261: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7262: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7263: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7264: p_ctr2a => 'Cut',
7265: p_ctr2b => '?',
7266: p_ctr3a => 'Cut those',
7267: p_ctr3b => 'items?',
1.633 raeburn 7268: setal => 'Enter a (unique) alias',
7269: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7270: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7271: imsfile => 'You must choose an IMS package for import',
7272: imscms => 'You must select which Course Management System was the source of the IMS package',
7273: invurl => 'Invalid URL',
7274: titbl => 'Title is blank',
1.538 raeburn 7275: more => '(More ...)',
7276: less => '(Less ...)',
1.543 raeburn 7277: noor => 'No actions selected or changes to settings specified.',
7278: noch => 'No changes to settings specified.',
7279: noac => 'No actions selected.',
1.606 raeburn 7280: nofi => 'No file selected',
7281: tinc => 'Title in course',
7282: sunm => 'Sub-directory name',
1.618 raeburn 7283: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 7284: );
1.594 damieng 7285: &js_escape(\%js_lt);
1.433 raeburn 7286: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7287: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7288: my $main_container_page;
1.519 raeburn 7289: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7290: $main_container_page = 1;
1.434 raeburn 7291: }
1.617 raeburn 7292: my $backtourl;
7293: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7294: my $toplevelsupp = &supplemental_base();
1.433 raeburn 7295:
1.530 raeburn 7296: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7297: my $caller = $1;
1.525 raeburn 7298: if ($caller =~ /^supplemental/) {
7299: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7300: } else {
7301: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7302: $res = &Apache::lonnet::clutter($res);
7303: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7304: my ($url,$anchor);
7305: if ($res =~ /^([^#]+)#([^#]+)$/) {
7306: $url = $1;
7307: $anchor = $2;
7308: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7309: $caller = $1.&escape('#').$anchor;
7310: }
1.614 raeburn 7311: } else {
7312: $url = $res;
1.609 raeburn 7313: }
1.640 raeburn 7314: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7315: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7316: $backtourl .= '?navmap=1';
7317: } else {
7318: $backtourl .= '?symb='.
7319: &HTML::Entities::encode($caller,'<>&"');
7320: }
1.622 raeburn 7321: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7322: if (($ENV{'SERVER_PORT'} == 443) &&
7323: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 7324: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 7325: if ($hostname ne '') {
7326: $backtourl = 'http://'.$hostname.$backtourl;
7327: }
7328: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7329: }
7330: }
1.623 raeburn 7331: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7332: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 7333: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 7334: if ($hostname ne '') {
7335: $backtourl = 'http://'.$hostname.$backtourl;
7336: }
7337: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 7338: }
1.623 raeburn 7339: }
1.622 raeburn 7340: }
1.609 raeburn 7341: if ($anchor ne '') {
7342: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7343: }
1.590 raeburn 7344: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7345: } else {
7346: $backtourl = '/adm/navmaps';
1.525 raeburn 7347: }
7348: }
7349: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7350: $backtourl = '/adm/menu';
7351: } elsif ($supplementalflag) {
1.472 raeburn 7352: $backtourl = '/adm/supplemental';
1.525 raeburn 7353: } else {
7354: $backtourl = '/adm/navmaps';
1.472 raeburn 7355: }
7356:
1.655 raeburn 7357: my $fieldsets = "'doc'";
1.519 raeburn 7358: unless ($main_container_page) {
7359: $fieldsets .=",'ims'";
7360: }
1.655 raeburn 7361: my $extfieldsets = "'ext'";
7362: if ($posslti) {
7363: $extfieldsets .= ",'tool'";
7364: }
1.501 raeburn 7365: if ($supplementalflag) {
1.655 raeburn 7366: $fieldsets = "'suppdoc'";
7367: $extfieldsets = "'suppext'";
1.600 raeburn 7368: if ($posslti) {
1.655 raeburn 7369: $extfieldsets .= ",'supptool'";
1.600 raeburn 7370: }
1.501 raeburn 7371: }
1.655 raeburn 7372:
1.611 raeburn 7373: my $jsmakefunctions;
7374: if ($canedit) {
7375: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7376: function makenewfolder(targetform,folderseq) {
1.594 damieng 7377: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7378: if (foldername) {
1.676 raeburn 7379: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 7380: targetform.submit();
7381: }
7382: }
7383:
7384: function makenewpage(targetform,folderseq) {
1.594 damieng 7385: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7386: if (pagename) {
1.676 raeburn 7387: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 7388: targetform.submit();
7389: }
7390: }
7391:
7392: function makeexamupload() {
1.594 damieng 7393: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7394: if (title) {
1.329 droeschl 7395: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 7396: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 7397: this.document.forms.newexamupload.submit();
7398: }
7399: }
7400:
7401: function makesmppage() {
1.594 damieng 7402: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7403: if (title) {
1.329 droeschl 7404: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 7405: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7406: this.document.forms.newsmppg.submit();
7407: }
7408: }
7409:
1.534 raeburn 7410: function makewebpage(type) {
1.594 damieng 7411: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7412: var formname;
7413: if (type == 'supp') {
7414: formname = this.document.forms.supwebpage;
7415: } else {
7416: formname = this.document.forms.newwebpage;
7417: }
7418: if (title) {
7419: var webpage = formname.importdetail.value;
1.675 raeburn 7420: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 7421: formname.submit();
7422: }
7423: }
7424:
1.329 droeschl 7425: function makesmpproblem() {
1.594 damieng 7426: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7427: if (title) {
1.329 droeschl 7428: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 7429: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 7430: this.document.forms.newsmpproblem.submit();
7431: }
7432: }
7433:
7434: function makedropbox() {
1.594 damieng 7435: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7436: if (title) {
1.329 droeschl 7437: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 7438: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 7439: this.document.forms.newdropbox.submit();
7440: }
7441: }
7442:
7443: function makebulboard() {
1.594 damieng 7444: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7445: if (title) {
7446: this.document.forms.newbul.importdetail.value=
1.676 raeburn 7447: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7448: this.document.forms.newbul.submit();
7449: }
7450: }
7451:
7452: function makeabout() {
1.594 damieng 7453: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7454: if (user) {
7455: var comp=new Array();
7456: comp=user.split(':');
7457: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7458: if ((comp[0]) && (comp[1])) {
7459: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7460: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7461: this.document.forms.newaboutsomeone.submit();
7462: } else {
7463: alert("$js_lt{'p_mab_alrt1'}");
7464: }
7465: } else {
7466: alert("$js_lt{'p_mab_alrt2'}");
7467: }
7468: }
7469: }
7470:
7471: function makenew(targetform) {
7472: targetform.submit();
7473: }
7474:
7475: function changename(folderpath,index,oldtitle) {
7476: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7477: if (title) {
7478: this.document.forms.renameform.markcopy.value='';
7479: this.document.forms.renameform.title.value=title;
7480: this.document.forms.renameform.cmd.value='rename_'+index;
7481: this.document.forms.renameform.folderpath.value=folderpath;
7482: this.document.forms.renameform.submit();
7483: }
7484: }
7485:
1.633 raeburn 7486: function setalias(folderpath,index) {
7487: var alias = prompt('$js_lt{"setal"}');
7488: if ((alias != null) && (alias != '')) {
7489: this.document.forms.aliasform.alias.value=alias;
7490: this.document.forms.aliasform.cmd.value='setalias_'+index;
7491: this.document.forms.aliasform.folderpath.value=folderpath;
7492: this.document.forms.aliasform.submit();
7493: }
7494: }
7495:
7496: function delalias(folderpath,index) {
7497: if (confirm('$js_lt{"delal"}')) {
7498: this.document.forms.aliasform.cmd.value='delalias_'+index;
7499: this.document.forms.aliasform.folderpath.value=folderpath;
7500: this.document.forms.aliasform.submit();
7501: }
7502: }
7503:
1.611 raeburn 7504: ENDNEWSCRIPT
7505: } else {
7506: $jsmakefunctions = <<ENDNEWSCRIPT;
7507:
7508: function makenewfolder() {
7509: alert("$js_lt{'edri'}");
7510: }
7511:
7512: function makenewpage() {
7513: alert("$js_lt{'edri'}");
7514: }
7515:
7516: function makeexamupload() {
7517: alert("$js_lt{'edri'}");
7518: }
7519:
7520: function makesmppage() {
7521: alert("$js_lt{'edri'}");
7522: }
7523:
7524: function makewebpage(type) {
7525: alert("$js_lt{'edri'}");
7526: }
7527:
7528: function makesmpproblem() {
7529: alert("$js_lt{'edri'}");
7530: }
7531:
7532: function makedropbox() {
7533: alert("$js_lt{'edri'}");
7534: }
7535:
7536: function makebulboard() {
7537: alert("$js_lt{'edri'}");
7538: }
7539:
7540: function makeabout() {
7541: alert("$js_lt{'edri'}");
7542: }
7543:
7544: function changename() {
7545: alert("$js_lt{'edri'}");
7546: }
7547:
1.633 raeburn 7548: function setalias() {
7549: alert("$js_lt{'edri'}");
7550: }
7551:
7552: function delalias() {
7553: alert("$js_lt{'edri'}");
7554: }
7555:
1.611 raeburn 7556: function makenew() {
7557: alert("$js_lt{'edri'}");
7558: }
7559:
7560: function groupimport() {
7561: alert("$js_lt{'edri'}");
1.335 ehlerst 7562: }
1.611 raeburn 7563:
7564: function groupsearch() {
7565: alert("$js_lt{'edri'}");
1.335 ehlerst 7566: }
1.611 raeburn 7567:
7568: function groupopen(url,recover) {
7569: var options="scrollbars=1,resizable=1,menubar=0";
7570: idxflag=1;
7571: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7572: idx.focus();
1.329 droeschl 7573: }
7574:
1.611 raeburn 7575: ENDNEWSCRIPT
7576:
7577: }
7578: return <<ENDSCRIPT;
7579:
7580: $jsmakefunctions
7581:
1.501 raeburn 7582: function toggleUpload(caller) {
7583: var blocks = Array($fieldsets);
7584: for (var i=0; i<blocks.length; i++) {
7585: var disp = 'none';
7586: if (caller == blocks[i]) {
7587: var curr = document.getElementById('upload'+caller+'form').style.display;
7588: if (curr == 'none') {
7589: disp='block';
7590: }
7591: }
7592: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 7593: }
7594: resize_scrollbox('contentscroll','1','1');
7595: return;
7596: }
7597:
7598: function toggleExternal(caller) {
7599: var blocks = Array($extfieldsets);
7600: for (var i=0; i<blocks.length; i++) {
7601: var disp = 'none';
7602: if (caller == blocks[i]) {
7603: var curr = document.getElementById('external'+caller+'form').style.display;
7604: if (curr == 'none') {
7605: disp='block';
7606: }
7607: }
7608: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7609: if ((caller == 'tool') || (caller == 'supptool')) {
7610: if (disp == 'block') {
1.655 raeburn 7611: if (document.getElementById('LC_exttoolid')) {
7612: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 7613: var suppflag = 0;
7614: if (caller == 'supptool') {
7615: suppflag = 1;
7616: }
7617: currForm = document.getElementById('new'+caller);
1.655 raeburn 7618: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 7619: }
7620: }
7621: }
1.501 raeburn 7622: }
1.502 raeburn 7623: resize_scrollbox('contentscroll','1','1');
7624: return;
7625: }
7626:
1.514 raeburn 7627: function toggleMap(caller) {
1.502 raeburn 7628: var disp = 'none';
1.510 raeburn 7629: if (document.getElementById('importmapform')) {
1.514 raeburn 7630: if (caller == 'map') {
7631: var curr = document.getElementById('importmapform').style.display;
7632: if (curr == 'none') {
7633: disp='block';
7634: }
1.510 raeburn 7635: }
7636: document.getElementById('importmapform').style.display=disp;
7637: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7638: }
1.501 raeburn 7639: return;
1.329 droeschl 7640: }
7641:
1.606 raeburn 7642: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7643: var disp = 'none';
7644: if (document.getElementById('crsresform')) {
7645: if (caller == 'res') {
7646: var curr = document.getElementById('crsresform').style.display;
7647: if (curr == 'none') {
7648: disp='block';
7649: numauthor = parseInt(numauthorrole);
7650: if (numauthor > 0) {
7651: document.courseresform.authorrole.selectedIndex = 0;
7652: select1priv_changed();
7653: document.courseresform.authorpath.selectedIndex = 0;
7654: document.courseresform.newresourceadd.selectedIndex = 0;
7655: toggleNewInCourse(document.courseresform);
7656: if (document.getElementById('newresource')) {
7657: document.getElementById('newresource').style.display = 'none';
7658: }
7659: } else {
7660: if (numcrsdirs) {
7661: document.courseresform.authorpath.selectedIndex = 0;
7662: }
7663: }
7664: if (document.courseresform.newresusetemp.length) {
7665: document.courseresform.newresusetemp[0].checked = true;
7666: toggleWithTemplate(document.courseresform);
7667: }
7668: document.courseresform.newresourcename.value = '';
7669: }
7670: }
7671: if (document.courseresform.newsubdir.length) {
7672: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7673: if (document.courseresform.newsubdir[j].value == 0) {
7674: document.courseresform.newsubdir[j].checked = true;
7675: }
7676: break;
7677: }
7678: if (document.getElementById('newsubdirname')) {
7679: document.getElementById('newsubdirname').type = "hidden";
7680: document.getElementById('newsubdirname').value = "";
7681: }
7682: if (document.getElementById('newsubdir')) {
7683: document.getElementById('newsubdir').innerHTML = "";
7684: }
7685: }
7686: document.getElementById('crsresform').style.display=disp;
7687: resize_scrollbox('contentscroll','1','0');
7688: }
7689: return;
7690: }
7691:
7692: function toggleNewsubdir(form) {
7693: if (form.newsubdir.length) {
7694: for (var j=0; j<form.newsubdir.length; j++) {
7695: if (form.newsubdir[j].checked) {
7696: if (document.getElementById('newsubdirname')) {
7697: if (form.newsubdir[j].value == '1') {
7698: document.getElementById('newsubdirname').type = "text";
7699: if (document.getElementById('newsubdir')) {
7700: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7701: }
7702: } else {
7703: document.getElementById('newsubdirname').type = "hidden";
7704: document.getElementById('newsubdirname').value = "";
7705: document.getElementById('newsubdir').innerHTML = "";
7706: }
7707: }
7708: break;
7709: }
7710: }
7711: }
7712: }
7713:
7714: function toggleCrsResTitle() {
7715: if (document.getElementById('newresource')) {
7716: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7717: document.getElementById('newresource').style.display = 'inline';
7718: document.courseresform.newresourceadd[0].checked = true;
7719: toggleNewInCourse(document.courseresform);
7720: } else {
7721: document.getElementById('newresource').style.display = 'none';
7722: }
7723: }
7724: }
7725:
7726: function toggleNewInCourse(form) {
7727: if (form.newresourceadd.length) {
7728: for (var i=0; i<form.newresourceadd.length; i++) {
7729: if (form.newresourceadd[i].checked) {
7730: if (document.getElementById('newresourcetitle')) {
7731: if (form.newresourceadd[i].value == '1') {
7732: document.getElementById('newresourcetitle').type = 'text';
7733: if (document.getElementById('newrestitle')) {
7734: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7735: }
7736: } else {
7737: document.getElementById('newresourcetitle').type = 'hidden';
7738: document.getElementById('newresourcetitle').value = '';
7739: if (document.getElementById('newrestitle')) {
7740: document.getElementById('newrestitle').innerHTML = '';
7741: }
7742: }
7743: }
7744: break;
7745: }
7746: }
7747: }
7748: }
7749:
7750: function toggleWithTemplate(form) {
7751: if (form.newresusetemp.length) {
7752: for (var i=0; i<form.newresusetemp.length; i++) {
7753: if (form.newresusetemp[i].checked) {
7754: if (document.getElementById('newrestemplate')) {
7755: if (form.newresusetemp[i].value == '1') {
7756: document.getElementById('newrestemplate').style.display = 'inline';
7757: toggleExampleText();
7758: } else {
7759: form.tempcategory.selectedIndex = 0;
7760: select1template_changed();
7761: document.getElementById('newrestemplate').style.display = 'none';
7762: }
7763: }
7764: }
7765: }
7766: }
7767: }
7768:
7769: function toggleExampleText() {
7770: if (document.getElementById('newresexample')) {
7771: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7772: if (url == '') {
7773: document.getElementById('newresexample').style.fontWeight = 'normal';
7774: } else {
7775: document.getElementById('newresexample').style.fontWeight = 'bold';
7776: }
7777: }
7778: }
7779:
7780: function getExample(width,height,scrolling,transparency) {
7781: var url;
7782: if (document.courseresform.newresusetemp.length) {
7783: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7784: if (document.courseresform.newresusetemp[i].checked) {
7785: if (document.courseresform.newresusetemp[i].value == '1') {
7786: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7787: if (url == '') {
7788: alert('Pick a category and template');
7789: } else {
7790: url = url.replace("$londocroot","");
7791: url += '?inhibitmenu=yes';
7792: }
7793: }
7794: break;
7795: }
7796: }
7797: }
7798: if (url != '') {
7799: openMyModal(url,width,height,scrolling,transparency,'');
7800: }
7801: }
7802:
7803: function toggleImportCrsres(caller,dircount) {
7804: var disp = 'none';
7805: if (document.getElementById('importcrsresform')) {
7806: if (caller == 'res') {
7807: var numdirs = parseInt(dircount);
7808: var curr = document.getElementById('importcrsresform').style.display;
7809: if (curr == 'none') {
7810: disp='block';
7811: if (numdirs > 1) {
7812: select1res_changed();
7813: }
7814: }
7815: }
7816: document.getElementById('importcrsresform').style.display=disp;
7817: resize_scrollbox('contentscroll','1','0');
7818: }
7819: return;
7820: }
7821:
1.501 raeburn 7822: function makeims(imsform) {
7823: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7824: alert("$js_lt{'imsfile'}");
1.501 raeburn 7825: return;
7826: }
7827: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7828: alert("$js_lt{'imscms'}");
1.501 raeburn 7829: return;
7830: }
7831: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7832: imsform.submit();
7833: }
7834:
1.478 raeburn 7835: function updatePick(targetform,index,caller) {
1.537 raeburn 7836: var pickitem;
7837: var picknumitem;
7838: var picknumtext;
7839: if (index == 'all') {
7840: pickitem = document.getElementById('randompickall');
7841: picknumitem = document.getElementById('rpicknumall');
7842: picknumtext = document.getElementById('rpicktextall');
7843: } else {
7844: pickitem = document.getElementById('randompick_'+index);
7845: picknumitem = document.getElementById('rpicknum_'+index);
7846: picknumtext = document.getElementById('randompicknum_'+index);
7847: }
1.478 raeburn 7848: if (pickitem.checked) {
1.594 damieng 7849: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7850: if (picknum == '' || picknum == null) {
7851: if (caller == 'check') {
7852: pickitem.checked=false;
1.537 raeburn 7853: if (index == 'all') {
7854: picknumtext.innerHTML = '';
7855: if (caller == 'link') {
7856: propagateState(targetform,'rpicknum');
7857: }
7858: } else {
1.538 raeburn 7859: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7860: }
1.478 raeburn 7861: }
7862: } else {
7863: picknum.toString();
7864: var regexdigit=/^\\d+\$/;
7865: if (regexdigit.test(picknum)) {
7866: picknumitem.value = picknum;
1.537 raeburn 7867: if (index == 'all') {
1.538 raeburn 7868: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7869: if (caller == 'link') {
7870: propagateState(targetform,'rpicknum');
7871: }
7872: } else {
7873: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7874: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7875: }
1.478 raeburn 7876: } else {
7877: if (caller == 'check') {
1.537 raeburn 7878: if (index == 'all') {
7879: picknumtext.innerHTML = '';
7880: if (caller == 'link') {
7881: propagateState(targetform,'rpicknum');
7882: }
7883: } else {
7884: pickitem.checked=false;
1.538 raeburn 7885: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7886: }
1.478 raeburn 7887: }
7888: return;
7889: }
7890: }
7891: } else {
1.537 raeburn 7892: picknumitem.value = '';
7893: picknumtext.innerHTML = '';
7894: if (index == 'all') {
7895: if (caller == 'link') {
7896: propagateState(targetform,'rpicknum');
7897: }
7898: } else {
1.538 raeburn 7899: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7900: }
7901: }
7902: }
7903:
7904: function propagateState(form,param) {
7905: if (document.getElementById(param+'all')) {
7906: var setcheck = 0;
7907: var rpick = 0;
7908: if (param == 'rpicknum') {
7909: if (document.getElementById('randompickall')) {
7910: if (document.getElementById('randompickall').checked) {
7911: if (document.getElementById('rpicknumall')) {
7912: rpick = document.getElementById('rpicknumall').value;
7913: }
7914: }
7915: }
7916: } else {
7917: if (document.getElementById(param+'all').checked) {
7918: setcheck = 1;
7919: }
7920: }
1.538 raeburn 7921: var allidxlist;
7922: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7923: if (document.getElementById('all'+param+'idx')) {
7924: allidxlist = document.getElementById('all'+param+'idx').value;
7925: }
7926: var actions = new Array ('remove','cut','copy');
7927: for (var i=0; i<actions.length; i++) {
7928: if (actions[i] != param) {
7929: if (document.getElementById(actions[i]+'all')) {
7930: document.getElementById(actions[i]+'all').checked = false;
7931: }
7932: }
7933: }
7934: }
1.537 raeburn 7935: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7936: allidxlist = form.allidx.value;
7937: }
7938: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7939: allidxlist = form.allmapidx.value;
7940: }
7941: if ((allidxlist != '') && (allidxlist != null)) {
7942: var allidxs = allidxlist.split(',');
7943: if (allidxs.length > 1) {
7944: for (var i=0; i<allidxs.length; i++) {
7945: if (document.getElementById(param+'_'+allidxs[i])) {
7946: if (param == 'rpicknum') {
7947: if (document.getElementById('randompick_'+allidxs[i])) {
7948: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7949: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7950: if (rpick > 0) {
7951: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7952: } else {
7953: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7954: }
7955: }
7956: }
7957: } else {
1.537 raeburn 7958: if (setcheck == 1) {
7959: document.getElementById(param+'_'+allidxs[i]).checked = true;
7960: } else {
7961: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7962: if (param == 'randompick') {
7963: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7964: }
1.537 raeburn 7965: }
7966: }
7967: }
7968: }
1.538 raeburn 7969: if (setcheck == 1) {
7970: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7971: var actions = new Array('copy','cut','remove');
7972: for (var i=0; i<actions.length; i++) {
7973: var otheractions;
7974: var otheridxs;
7975: if (actions[i] === param) {
7976: continue;
7977: } else {
7978: if (document.getElementById('all'+actions[i]+'idx')) {
7979: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7980: otheridxs = otheractions.split(',');
7981: if (otheridxs.length > 1) {
7982: for (var j=0; j<otheridxs.length; j++) {
7983: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7984: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7985: }
1.537 raeburn 7986: }
7987: }
7988: }
1.538 raeburn 7989: }
7990: }
7991: }
7992: }
7993: }
7994: }
7995: }
7996: return;
7997: }
7998:
1.603 raeburn 7999: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 8000: var canedit = '$canedit';
8001: if (canedit == '') {
8002: alert("$js_lt{'edri'}");
8003: return;
8004: }
1.539 raeburn 8005: var dosettings;
8006: var doaction;
1.538 raeburn 8007: var control = document.togglemultsettings;
8008: if (context == 'actions') {
8009: control = document.togglemultactions;
1.539 raeburn 8010: doaction = 1;
8011: } else {
8012: dosettings = 1;
1.538 raeburn 8013: }
1.539 raeburn 8014: if (control) {
8015: if (control.showmultpick.length) {
8016: for (var i=0; i<control.showmultpick.length; i++) {
8017: if (control.showmultpick[i].checked) {
8018: if (control.showmultpick[i].value == 1) {
8019: if (context == 'settings') {
8020: dosettings = 0;
8021: } else {
8022: doaction = 0;
1.538 raeburn 8023: }
8024: }
8025: }
1.537 raeburn 8026: }
8027: }
1.539 raeburn 8028: }
8029: if (context == 'settings') {
8030: if (dosettings == 1) {
1.538 raeburn 8031: targetform.changeparms.value=param;
8032: targetform.submit();
8033: }
1.537 raeburn 8034: }
1.539 raeburn 8035: if (context == 'actions') {
8036: if (doaction == 1) {
8037: targetform.cmd.value=param+'_'+index;
8038: targetform.folderpath.value=folderpath;
8039: targetform.markcopy.value=idx+':'+param;
8040: targetform.copyfolder.value=folder+'.'+container;
8041: if (param == 'remove') {
1.603 raeburn 8042: var doremove = 0;
8043: if (skip_confirm) {
8044: if (confirm_removal) {
8045: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8046: doremove = 1;
8047: }
8048: } else {
8049: doremove = 1;
8050: }
8051: } else {
8052: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8053: doremove = 1;
8054: }
8055: }
8056: if (doremove) {
1.539 raeburn 8057: targetform.markcopy.value='';
8058: targetform.copyfolder.value='';
8059: targetform.submit();
8060: }
8061: }
8062: if (param == 'cut') {
1.594 damieng 8063: 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 8064: targetform.submit();
8065: return;
8066: }
8067: }
8068: if (param == 'copy') {
8069: targetform.submit();
8070: return;
8071: }
8072: targetform.markcopy.value='';
8073: targetform.copyfolder.value='';
8074: targetform.cmd.value='';
8075: targetform.folderpath.value='';
8076: return;
8077: } else {
8078: if (document.getElementById(param+'_'+idx)) {
8079: item = document.getElementById(param+'_'+idx);
8080: if (item.type == 'checkbox') {
8081: if (item.checked) {
8082: item.checked = false;
8083: } else {
8084: item.checked = true;
8085: singleCheck(item,idx,param);
8086: }
8087: }
8088: }
8089: }
8090: }
1.537 raeburn 8091: return;
8092: }
8093:
1.538 raeburn 8094: function singleCheck(caller,idx,action) {
8095: actions = new Array('cut','copy','remove');
8096: if (caller.checked) {
8097: for (var i=0; i<actions.length; i++) {
8098: if (actions[i] != action) {
8099: if (document.getElementById(actions[i]+'_'+idx)) {
8100: if (document.getElementById(actions[i]+'_'+idx).checked) {
8101: document.getElementById(actions[i]+'_'+idx).checked = false;
8102: }
1.537 raeburn 8103: }
8104: }
8105: }
1.478 raeburn 8106: }
1.537 raeburn 8107: return;
1.478 raeburn 8108: }
8109:
1.334 muellerd 8110: function unselectInactive(nav) {
1.335 ehlerst 8111: currentNav = document.getElementById(nav);
8112: currentLis = currentNav.getElementsByTagName('LI');
8113: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8114: if (currentLis[i].className == 'goback') {
8115: currentLis[i].className = 'goback';
8116: } else {
8117: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8118: currentLis[i].className = 'right';
1.472 raeburn 8119: } else {
1.374 tempelho 8120: currentLis[i].className = 'i';
1.472 raeburn 8121: }
8122: }
1.335 ehlerst 8123: }
1.332 tempelho 8124: }
8125:
1.334 muellerd 8126: function hideAll(current, nav, data) {
1.335 ehlerst 8127: unselectInactive(nav);
1.570 raeburn 8128: if (current) {
8129: if (current.className == 'right'){
8130: current.className = 'right active'
8131: } else {
8132: current.className = 'active';
8133: }
1.374 tempelho 8134: }
1.335 ehlerst 8135: currentData = document.getElementById(data);
8136: currentDivs = currentData.getElementsByTagName('DIV');
8137: for (i = 0; i < currentDivs.length; i++) {
8138: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8139: currentDivs[i].style.display = 'none';
1.330 tempelho 8140: }
8141: }
1.335 ehlerst 8142: }
1.330 tempelho 8143:
1.374 tempelho 8144: function openTabs(pageId) {
8145: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8146: if(tabnav.length > 2 ){
1.389 tempelho 8147: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8148: currentLis = currentNav.getElementsByTagName('LI');
8149: for(i = 0; i< currentLis.length; i++){
8150: if(currentLis[i].className == 'active') {
1.375 tempelho 8151: funcString = currentLis[i].onclick.toString();
8152: tab = funcString.split('"');
1.420 onken 8153: if(tab.length < 2) {
8154: tab = funcString.split("'");
8155: }
1.375 tempelho 8156: currentData = document.getElementById(tab[1]);
8157: currentData.style.display = 'block';
1.374 tempelho 8158: }
8159: }
8160: }
8161: }
8162:
1.334 muellerd 8163: function showPage(current, pageId, nav, data) {
1.570 raeburn 8164: currstate = current.className;
1.334 muellerd 8165: hideAll(current, nav, data);
1.375 tempelho 8166: openTabs(pageId);
1.334 muellerd 8167: unselectInactive(nav);
1.570 raeburn 8168: if ((currstate == 'active') || (currstate == 'right active')) {
8169: if (currstate == 'active') {
8170: current.className = '';
8171: } else {
8172: current.className = 'right';
8173: }
8174: activeTab = '';
1.656 raeburn 8175: toggleExternal();
1.570 raeburn 8176: toggleUpload();
8177: toggleMap();
1.606 raeburn 8178: toggleCrsRes();
8179: toggleImportCrsres();
1.570 raeburn 8180: resize_scrollbox('contentscroll','1','0');
8181: return;
8182: } else {
8183: current.className = 'active';
8184: }
1.330 tempelho 8185: currentData = document.getElementById(pageId);
8186: currentData.style.display = 'block';
1.458 raeburn 8187: activeTab = pageId;
1.656 raeburn 8188: toggleExternal();
1.501 raeburn 8189: toggleUpload();
1.503 raeburn 8190: toggleMap();
1.606 raeburn 8191: toggleCrsRes();
8192: toggleImportCrsres();
1.433 raeburn 8193: if (nav == 'mainnav') {
8194: var storedpath = "$docs_folderpath";
1.434 raeburn 8195: var storedpage = "$main_container_page";
1.433 raeburn 8196: var reg = new RegExp("^supplemental");
8197: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8198: if (storedpage == 1) {
8199: document.simpleedit.folderpath.value = '';
8200: document.uploaddocument.folderpath.value = '';
8201: } else {
8202: if (reg.test(storedpath)) {
8203: document.simpleedit.folderpath.value = '$toplevelmain';
8204: document.uploaddocument.folderpath.value = '$toplevelmain';
8205: document.newext.folderpath.value = '$toplevelmain';
8206: } else {
8207: document.simpleedit.folderpath.value = storedpath;
8208: document.uploaddocument.folderpath.value = storedpath;
8209: document.newext.folderpath.value = storedpath;
8210: }
1.433 raeburn 8211: }
8212: } else {
1.434 raeburn 8213: if (reg.test(storedpath)) {
8214: document.simpleedit.folderpath.value = storedpath;
8215: document.supuploaddocument.folderpath.value = storedpath;
8216: document.supnewext.folderpath.value = storedpath;
8217: } else {
1.433 raeburn 8218: document.simpleedit.folderpath.value = '$toplevelsupp';
8219: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8220: document.supnewext.folderpath.value = '$toplevelsupp';
8221: }
8222: }
8223: }
1.485 raeburn 8224: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8225: return false;
8226: }
1.329 droeschl 8227:
1.472 raeburn 8228: function toContents(jumpto) {
8229: var newurl = '$backtourl';
1.525 raeburn 8230: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8231: newurl = newurl+'?postdata='+jumpto;
8232: }
8233: location.href=newurl;
8234: }
8235:
1.538 raeburn 8236: function togglePick(caller,value) {
8237: var disp = 'none';
8238: if (document.getElementById('multi'+caller)) {
8239: var curr = document.getElementById('multi'+caller).style.display;
8240: if (value == 1) {
8241: disp='block';
8242: }
8243: if (curr == disp) {
8244: return;
8245: }
8246: document.getElementById('multi'+caller).style.display=disp;
8247: if (value == 1) {
1.594 damieng 8248: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8249: } else {
8250: document.getElementById('more'+caller).innerHTML = '';
8251: }
8252: if (caller == 'actions') {
8253: setClass(value);
8254: setBoxes(value);
8255: }
8256: }
8257: var showButton = multiSettings();
8258: if (showButton != 1) {
8259: showButton = multiActions();
8260: }
8261: if (document.getElementById('multisave')) {
8262: if (showButton == 1) {
8263: document.getElementById('multisave').style.display='block';
8264: } else {
8265: document.getElementById('multisave').style.display='none';
8266: }
8267: }
8268: resize_scrollbox('contentscroll','1','1');
8269: return;
8270: }
8271:
8272: function toggleCheckUncheck(caller,more) {
8273: if (more == 1) {
1.594 damieng 8274: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8275: document.getElementById('allfields'+caller).style.display='block';
8276: } else {
1.594 damieng 8277: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8278: document.getElementById('allfields'+caller).style.display='none';
8279: }
8280: resize_scrollbox('contentscroll','1','1');
8281: }
8282:
8283: function multiSettings() {
8284: var inuse = 0;
8285: var settingsform = document.togglemultsettings;
8286: if (settingsform.showmultpick.length > 1) {
8287: for (var i=0; i<settingsform.showmultpick.length; i++) {
8288: if (settingsform.showmultpick[i].checked) {
8289: if (settingsform.showmultpick[i].value == 1) {
8290: inuse = 1;
8291: }
8292: }
8293: }
8294: }
8295: return inuse;
8296: }
8297:
8298: function multiActions() {
8299: var inuse = 0;
8300: var actionsform = document.togglemultactions;
8301: if (actionsform.showmultpick.length > 1) {
8302: for (var i=0; i<actionsform.showmultpick.length; i++) {
8303: if (actionsform.showmultpick[i].checked) {
8304: if (actionsform.showmultpick[i].value == 1) {
8305: inuse = 1;
8306: }
8307: }
8308: }
8309: }
8310: return inuse;
8311: }
8312:
8313: function checkSubmits() {
8314: var numchanges = 0;
8315: var form = document.saveactions;
8316: var doactions = multiActions();
1.542 raeburn 8317: var cutwarnings = 0;
8318: var remwarnings = 0;
1.603 raeburn 8319: var removalinfo = 0;
1.538 raeburn 8320: if (doactions == 1) {
8321: var remidxlist = document.cumulativeactions.allremoveidx.value;
8322: if ((remidxlist != '') && (remidxlist != null)) {
8323: var remidxs = remidxlist.split(',');
8324: for (var i=0; i<remidxs.length; i++) {
8325: if (document.getElementById('remove_'+remidxs[i])) {
8326: if (document.getElementById('remove_'+remidxs[i]).checked) {
8327: form.multiremove.value += remidxs[i]+',';
8328: numchanges ++;
1.542 raeburn 8329: if (document.getElementById('skip_remove_'+remidxs[i])) {
8330: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8331: remwarnings ++;
8332: }
8333: }
1.603 raeburn 8334: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8335: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8336: removalinfo ++;
8337: }
8338: }
1.537 raeburn 8339: }
8340: }
1.538 raeburn 8341: }
8342: }
8343: var cutidxlist = document.cumulativeactions.allcutidx.value;
8344: if ((cutidxlist != '') && (cutidxlist != null)) {
8345: var cutidxs = cutidxlist.split(',');
8346: for (var i=0; i<cutidxs.length; i++) {
8347: if (document.getElementById('cut_'+cutidxs[i])) {
8348: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8349: form.multicut.value += cutidxs[i]+',';
8350: numchanges ++;
1.542 raeburn 8351: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8352: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8353: cutwarnings ++;
8354: }
8355: }
1.537 raeburn 8356: }
8357: }
8358: }
8359: }
1.538 raeburn 8360: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8361: if ((copyidxlist != '') && (copyidxlist != null)) {
8362: var copyidxs = copyidxlist.split(',');
8363: for (var i=0; i<copyidxs.length; i++) {
8364: if (document.getElementById('copy_'+copyidxs[i])) {
8365: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8366: form.multicopy.value += copyidxs[i]+',';
8367: numchanges ++;
8368: }
8369: }
8370: }
8371: }
8372: if (numchanges > 0) {
8373: form.multichange.value = numchanges;
8374: }
1.537 raeburn 8375: }
1.538 raeburn 8376: var dosettings = multiSettings();
1.543 raeburn 8377: var haschanges = 0;
1.538 raeburn 8378: if (dosettings == 1) {
8379: form.allencrypturl.value = '';
8380: form.allhiddenresource.value = '';
1.543 raeburn 8381: form.changeparms.value = 'all';
8382: var patt=new RegExp(",\$");
1.538 raeburn 8383: var allidxlist = document.cumulativesettings.allidx.value;
8384: if ((allidxlist != '') && (allidxlist != null)) {
8385: var allidxs = allidxlist.split(',');
8386: if (allidxs.length > 1) {
8387: for (var i=0; i<allidxs.length; i++) {
8388: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8389: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8390: form.allhiddenresource.value += allidxs[i]+',';
8391: }
8392: }
8393: if (document.getElementById('encrypturl_'+allidxs[i])) {
8394: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8395: form.allencrypturl.value += allidxs[i]+',';
8396: }
8397: }
8398: }
1.543 raeburn 8399: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8400: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8401: }
1.538 raeburn 8402: }
8403: form.allrandompick.value = '';
8404: form.allrandomorder.value = '';
8405: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8406: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8407: var allmapidxs = allmapidxlist.split(',');
8408: for (var i=0; i<allmapidxs.length; i++) {
8409: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8410: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8411: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8412: if ((randompick.checked) && (rpicknum.value != '')) {
8413: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8414: }
8415: if (randorder.checked) {
8416: form.allrandomorder.value += allmapidxs[i]+',';
8417: }
1.537 raeburn 8418: }
1.543 raeburn 8419: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8420: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8421: }
8422: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8423: haschanges = 1;
8424: }
8425: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8426: haschanges = 1;
8427: }
8428: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8429: haschanges = 1;
8430: }
8431: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8432: haschanges = 1;
1.537 raeburn 8433: }
8434: }
1.543 raeburn 8435: if (doactions == 1) {
1.542 raeburn 8436: if (numchanges > 0) {
1.603 raeburn 8437: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8438: if (remwarnings > 0) {
1.594 damieng 8439: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8440: return false;
8441: }
8442: }
1.603 raeburn 8443: if (removalinfo > 0) {
8444: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8445: return false;
8446: }
8447: }
1.542 raeburn 8448: if (cutwarnings > 0) {
1.594 damieng 8449: 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 8450: return false;
8451: }
8452: }
8453: }
8454: form.submit();
8455: return true;
1.543 raeburn 8456: }
8457: }
8458: if (dosettings == 1) {
8459: if (haschanges == 1) {
1.542 raeburn 8460: form.submit();
8461: return true;
8462: }
1.543 raeburn 8463: }
8464: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8465: alert("$js_lt{'noor'}");
1.543 raeburn 8466: } else {
8467: if (dosettings == 1) {
1.594 damieng 8468: alert("$js_lt{'noch'}");
1.543 raeburn 8469: } else {
1.594 damieng 8470: alert("$js_lt{'noac'}");
1.543 raeburn 8471: }
8472: }
1.538 raeburn 8473: return false;
8474: }
8475:
8476: function setClass(value) {
8477: var cutclass = 'LC_docs_cut';
8478: var copyclass = 'LC_docs_copy';
8479: var removeclass = 'LC_docs_remove';
8480: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8481: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8482: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8483: var links = document.getElementsByTagName('a');
8484: for (var i=0; i<links.length; i++) {
8485: var classes = links[i].className;
8486: if (cutreg.test(classes)) {
8487: links[i].className = cutclass;
8488: if (value == 1) {
8489: links[i].className += " LC_menubuttons_link";
8490: }
8491: } else {
8492: if (copyreg.test(classes)) {
8493: links[i].className = copyclass;
8494: if (value == 1) {
8495: links[i].className += " LC_menubuttons_link";
8496: }
8497: } else {
8498: if (removereg.test(classes)) {
8499: links[i].className = removeclass;
8500: if (value == 1) {
8501: links[i].className += " LC_menubuttons_link";
8502: }
8503: }
8504: }
8505: }
8506: }
8507: return;
1.537 raeburn 8508: }
8509:
1.538 raeburn 8510: function setBoxes(value) {
8511: var remidxlist = document.cumulativeactions.allremoveidx.value;
8512: if ((remidxlist != '') && (remidxlist != null)) {
8513: var remidxs = remidxlist.split(',');
8514: for (var i=0; i<remidxs.length; i++) {
8515: if (document.getElementById('remove_'+remidxs[i])) {
8516: var item = document.getElementById('remove_'+remidxs[i]);
8517: if (value == 1) {
8518: item.className = 'LC_docs_remove';
8519: } else {
8520: item.className = 'LC_hidden';
8521: }
8522: }
8523: }
8524: }
8525: var cutidxlist = document.cumulativeactions.allcutidx.value;
8526: if ((cutidxlist != '') && (cutidxlist != null)) {
8527: var cutidxs = cutidxlist.split(',');
8528: for (var i=0; i<cutidxs.length; i++) {
8529: if (document.getElementById('cut_'+cutidxs[i])) {
8530: var item = document.getElementById('cut_'+cutidxs[i]);
8531: if (value == 1) {
8532: item.className = 'LC_docs_cut';
8533: } else {
8534: item.className = 'LC_hidden';
8535: }
8536: }
1.537 raeburn 8537: }
8538: }
1.538 raeburn 8539: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8540: if ((copyidxlist != '') && (copyidxlist != null)) {
8541: var copyidxs = copyidxlist.split(',');
8542: for (var i=0; i<copyidxs.length; i++) {
8543: if (document.getElementById('copy_'+copyidxs[i])) {
8544: var item = document.getElementById('copy_'+copyidxs[i]);
8545: if (value == 1) {
8546: item.className = 'LC_docs_copy';
8547: } else {
8548: item.className = 'LC_hidden';
8549: }
8550: }
1.537 raeburn 8551: }
8552: }
8553: return;
8554: }
8555:
1.606 raeburn 8556: function validImportCrsRes() {
8557: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8558: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8559: if ((fname == '') || (fname == null)) {
8560: alert("$js_lt{'nofi'}");
8561: return false;
8562: }
8563: var url = '/res/$coursedom/$coursenum/';
8564: if (path && path != '/') {
8565: url += path+'/';
8566: }
8567: if (fname != '') {
8568: url += fname;
8569: }
8570: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 8571: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 8572: return true;
8573: }
8574:
8575: function validateNewRes(caller) {
8576: if (caller == 'single') {
8577: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8578: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8579: var resname = document.courseresform.newresourcename.value;
8580: }
8581: }
8582:
1.611 raeburn 8583: ENDSCRIPT
1.329 droeschl 8584: }
1.457 raeburn 8585:
1.483 raeburn 8586: sub history_tab_js {
8587: return <<"ENDHIST";
8588: function toggleHistoryDisp(choice) {
8589: document.docslogform.docslog.value = choice;
8590: document.docslogform.submit();
8591: return;
8592: }
8593:
8594: ENDHIST
8595: }
8596:
1.484 raeburn 8597: sub inject_data_js {
8598: return <<ENDINJECT;
8599:
8600: function injectData(current, hiddenField, name, value) {
8601: currentElement = document.getElementById(hiddenField);
8602: currentElement.name = name;
8603: currentElement.value = value;
8604: current.submit();
8605: }
8606:
8607: ENDINJECT
8608: }
8609:
8610: sub dump_switchserver_js {
8611: my @hosts = @_;
1.594 damieng 8612: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8613: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8614: swit => 'Switch server?',
1.594 damieng 8615: );
8616: my %html_js_lt = &Apache::lonlocal::texthash(
8617: swit => 'Switch server?',
1.568 raeburn 8618: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8619: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8620: chos => 'Choose server',
8621: );
1.594 damieng 8622: &js_escape(\%js_lt);
8623: &html_escape(\%html_js_lt);
8624: &js_escape(\%html_js_lt);
1.484 raeburn 8625: my $role = $env{'request.role'};
8626: my $js = <<"ENDSWJS";
8627: <script type="text/javascript">
8628: function write_switchserver() {
8629: var server;
8630: if (document.setserver.posshosts.length > 0) {
8631: for (var i=0; i<document.setserver.posshosts.length; i++) {
8632: if (document.setserver.posshosts[i].checked) {
8633: server = document.setserver.posshosts[i].value;
8634: }
8635: }
8636: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8637: }
8638: window.close();
8639: }
8640: </script>
8641:
8642: ENDSWJS
8643:
8644: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8645: {'only_body' => 1,
8646: 'js_ready' => 1,});
8647: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8648:
8649: my $hostpicker;
8650: my $count = 0;
8651: foreach my $host (sort(@hosts)) {
8652: my $checked;
8653: if ($count == 0) {
8654: $checked = ' checked="checked"';
8655: }
8656: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8657: $host.'"'.$checked.' />'.$host.'</label> ';
8658: $count++;
8659: }
8660:
8661: return <<"ENDSWITCHJS";
8662:
8663: function dump_needs_switchserver(url) {
8664: if (url!='' && url!= null) {
1.594 damieng 8665: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8666: go(url);
8667: }
8668: }
8669: return;
8670: }
8671:
8672: function choose_switchserver_window() {
8673: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8674: newWindow.document.open();
8675: newWindow.document.writeln('$startpage');
1.594 damieng 8676: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8677: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8678: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8679: '<form name="setserver" method="post" action="" \\/>\\n'+
8680: '$hostpicker\\n'+
8681: '<br \\/><br \\/>\\n'+
1.594 damieng 8682: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8683: 'onclick="write_switchserver();" \\/>\\n'+
8684: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8685: newWindow.document.writeln('$endpage');
8686: newWindow.document.close();
8687: newWindow.focus();
8688: }
8689:
8690: ENDSWITCHJS
8691: }
8692:
8693: sub makedocslogform {
8694: my ($formelems,$docslog) = @_;
8695: return <<"LOGSFORM";
8696: <form action="/adm/coursedocs" method="post" name="docslogform">
8697: <input type="hidden" name="docslog" value="$docslog" />
8698: $formelems
8699: </form>
8700: LOGSFORM
8701: }
8702:
8703: sub makesimpleeditform {
8704: my ($formelems) = @_;
8705: return <<"SIMPFORM";
8706: <form name="simpleedit" method="post" action="/adm/coursedocs">
8707: <input type="hidden" name="importdetail" value="" />
8708: $formelems
8709: </form>
8710: SIMPFORM
8711: }
8712:
1.606 raeburn 8713: sub makenewproblem {
8714: my ($r,$coursedom,$coursenum) = @_;
8715: # Creating a new problem
8716: my ($redirect,$error);
8717: if ($env{'form.authorrole'}) {
8718: my ($newsubdir,$filename);
8719: if ($env{'form.newsubdir'}) {
8720: if ($env{'form.newsubdirname'} ne '') {
8721: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 8722: }
1.606 raeburn 8723: }
8724: if ($env{'form.newresourcename'}) {
8725: $filename = $env{'form.newresourcename'};
8726: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8727: $filename =~ s/`//g;
8728: $filename =~ s{/\.\./}{_}g;
8729: $filename =~ s/\.+/./g;
8730: $filename =~ s{/+}{_}g;
8731: if ($filename ne '') {
8732: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8733: if (($ext) && ($ext ne '.problem')) {
8734: $filename = $name.'.problem';
8735: } elsif ($ext eq '') {
8736: $filename .= '.problem';
8737: }
8738: my $docroot = $r->dir_config('lonDocRoot');
8739: my @ids=&Apache::lonnet::current_machine_ids();
8740: if ($env{'form.authorrole'} eq 'author') {
8741: if ($env{'user.author'}) {
8742: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8743: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8744: my $path = $docroot.$url;
8745: my $subdir = $env{'form.authorpath'};
8746: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8747: }
8748: }
8749: } elsif ($env{'form.authorrole'} eq 'course') {
8750: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8751: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8752: my $url = "/priv/$coursedom/$coursenum";
8753: my $path=$docroot.$url;
8754: my $subdir = $env{'form.authorpath'};
8755: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8756: if ($redirect) {
8757: my $rightsfile = 'default.rights';
8758: my $sourcerights = "$path/$rightsfile";
8759: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8760: my $now = time;
8761: if (!-e $sourcerights) {
8762: my $cid = $coursedom.'_'.$coursenum;
8763: if (open(my $fh,">$sourcerights")) {
8764: print $fh <<END;
8765: <accessrule effect="deny" realm="" type="course" role="" />
8766: <accessrule effect="allow" realm="$cid" type="course" role="" />
8767: END
8768: close($fh);
8769: }
8770: }
8771: if (!-e "$sourcerights.meta") {
8772: if (open(my $fh,">$sourcerights.meta")) {
8773: my $author=$env{'environment.firstname'}.' '.
8774: $env{'environment.middlename'}.' '.
8775: $env{'environment.lastname'}.' '.
8776: $env{'environment.generation'};
8777: $author =~ s/\s+$//;
8778: print $fh <<"END";
8779:
8780: <abstract></abstract>
8781: <author>$author</author>
8782: <authorspace>$coursenum:$coursedom</authorspace>
8783: <copyright>private</copyright>
8784: <creationdate>$now</creationdate>
8785: <customdistributionfile></customdistributionfile>
8786: <dependencies></dependencies>
8787: <domain>$coursedom</domain>
8788: <highestgradelevel>0</highestgradelevel>
8789: <keywords></keywords>
8790: <language>notset </language>
8791: <lastrevisiondate>$now</lastrevisiondate>
8792: <lowestgradelevel>0</lowestgradelevel>
8793: <mime>rights</mime>
8794: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8795: <notes></notes>
8796: <obsolete></obsolete>
8797: <obsoletereplacement></obsoletereplacement>
8798: <owner>$coursenum:$coursedom</owner>
8799: <rule>deny:::course,allow:$cid::course</rule>
8800: <sourceavail></sourceavail>
8801: <standards></standards>
8802: <subject></subject>
8803: <title></title>
8804: END
1.654 raeburn 8805: close($fh);
8806: }
8807: }
8808: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8809: if (!-e "$docroot/res/$coursedom") {
8810: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 8811: }
1.654 raeburn 8812: if (!-e "$docroot/res/$coursedom/$coursenum") {
8813: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8814: }
8815: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8816: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8817: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 8818: }
8819: }
1.654 raeburn 8820: my $source = $docroot.$redirect;
8821: if (!-e "$source.meta") {
8822: my $cid = $coursedom.'_'.$coursenum;
8823: my $now = time;
8824: if (open(my $fh,">$source.meta")) {
8825: my $author=$env{'environment.firstname'}.' '.
8826: $env{'environment.middlename'}.' '.
8827: $env{'environment.lastname'}.' '.
8828: $env{'environment.generation'};
8829: $author =~ s/\s+$//;
8830: my $title = $env{'form.newresourcetitle'};
8831: $title =~ s/^\s+|\s+$//g;
8832: print $fh <<END;
1.606 raeburn 8833:
8834: <abstract></abstract>
8835: <author>$author</author>
8836: <authorspace>$coursenum:$coursedom</authorspace>
8837: <copyright>custom</copyright>
8838: <creationdate>$now</creationdate>
8839: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8840: <dependencies></dependencies>
8841: <domain>$coursedom</domain>
8842: <highestgradelevel>0</highestgradelevel>
8843: <keywords></keywords>
8844: <language>notset </language>
8845: <lastrevisiondate>$now</lastrevisiondate>
8846: <lowestgradelevel>0</lowestgradelevel>
8847: <mime>problem</mime>
8848: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8849: <notes></notes>
8850: <obsolete></obsolete>
8851: <obsoletereplacement></obsoletereplacement>
8852: <owner>$coursenum:$coursedom</owner>
8853: <sourceavail></sourceavail>
8854: <standards></standards>
8855: <subject></subject>
8856: <title>$title</title>
8857: END
1.654 raeburn 8858: close($fh);
1.606 raeburn 8859: }
8860: }
8861: }
8862: }
8863: } else {
8864: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8865: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8866: if (grep(/^\Q$rolehome\E$/,@ids)) {
8867: my $now = time;
8868: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8869: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8870: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8871: my $url = "/priv/$audom/$auname";
8872: my $path = $r->dir_config('lonDocRoot').$url;
8873: my $subdir = $env{'form.authorpath'};
8874: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8875: }
8876: }
8877: }
8878: }
8879: }
8880: }
8881: }
8882: return ($redirect,$error);
8883: }
8884:
8885: sub finishnewprob {
1.654 raeburn 8886: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 8887: unless (-d $path) {
8888: unless (mkdir($path,02770)) {
8889: return;
8890: }
8891: }
1.606 raeburn 8892: my $redirect;
8893: if ($subdir ne '/') {
8894: $subdir = &cleandir($subdir);
8895: if (($subdir ne '') && (-d "$path/$subdir")) {
8896: $path .= "/$subdir";
8897: $url .= "/$subdir";
8898: }
8899: }
8900: my $dest;
8901: if ($newsubdir ne '') {
8902: $newsubdir = &cleandir($newsubdir);
8903: }
8904: if ($newsubdir ne '') {
8905: if (-d "$path/$newsubdir") {
8906: $dest = "$path/$newsubdir/$filename";
8907: } else {
8908: my $dirok;
8909: unless (-e "$path/$newsubdir") {
8910: if (mkdir("$path/$newsubdir",02770)) {
8911: if (chmod(02770,"$path/$newsubdir")) {
8912: $dirok = 1;
8913: }
8914: }
8915: }
8916: if ($dirok) {
8917: $dest = "$path/$newsubdir/$filename";
8918: }
8919: }
8920: if (($dest ne '') && (!-e $dest)) {
8921: $redirect = "$url/$newsubdir/$filename";
8922: }
8923: } else {
8924: $dest = "$path/$filename";
8925: if (($dest ne '') && (!-e $dest)) {
8926: $redirect = "$url/$filename";
8927: }
8928: }
1.654 raeburn 8929: if ((!-e $dest) && ($context ne 'upload')) {
8930: my $template = $env{'form.template'};
8931: my $copyfrom;
8932: if ($template ne '') {
8933: my %templates;
8934: my @files = &Apache::lonhomework::get_template_list('problem');
8935: foreach my $poss (@files) {
8936: if (ref($poss) eq 'ARRAY') {
8937: if ($template eq $poss->[0]) {
8938: $templates{$template} = 1;
8939: last;
8940: }
8941: }
8942: }
8943: if ($templates{$template}) {
8944: $copyfrom = $template;
8945: }
8946: }
8947: if ($filename =~ /\.problem$/) {
8948: unless ($copyfrom) {
8949: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
8950: }
8951: &File::Copy::copy($copyfrom,$dest);
8952: }
8953: }
1.606 raeburn 8954: return $redirect;
8955: }
8956:
8957: sub cleandir {
8958: my ($dir) = @_;
8959: $dir =~ s/^\s+//;
8960: $dir =~ s/\s+$//;
8961: $dir =~ s/\.+//g;
8962: $dir =~ s/[\#\?&%\":]//g;
8963: return $dir;
8964: }
8965:
1.329 droeschl 8966: 1;
8967: __END__
8968:
8969:
8970: =head1 NAME
8971:
8972: Apache::londocs.pm
8973:
8974: =head1 SYNOPSIS
8975:
8976: This is part of the LearningOnline Network with CAPA project
8977: described at http://www.lon-capa.org.
8978:
8979: =head1 SUBROUTINES
8980:
8981: =over
8982:
8983: =item %help=()
8984:
8985: Available help topics
8986:
8987: =item mapread()
8988:
1.344 bisitz 8989: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8990: @order and @resources, determines status
8991: sets @order - pointer to resources in right order
8992: sets @resources - array with the resources with correct idx
8993:
8994: =item authorhosts()
8995:
8996: Return hash with valid author names
8997:
8998: =item clean()
8999:
9000: =item dumpcourse()
9001:
9002: Actually dump course
9003:
9004: =item group_import()
9005:
9006: Imports the given (name, url) resources into the course
9007: coursenum, coursedom, and folder must precede the list
9008:
9009: =item breadcrumbs()
9010:
9011: =item log_docs()
9012:
9013: =item docs_change_log()
9014:
9015: =item update_paste_buffer()
9016:
9017: =item print_paste_buffer()
9018:
9019: =item do_paste_from_buffer()
9020:
1.538 raeburn 9021: =item do_buffer_empty()
9022:
9023: =item clear_from_buffer()
9024:
1.492 raeburn 9025: =item get_newmap_url()
9026:
9027: =item dbcopy()
9028:
9029: =item uniqueness_check()
9030:
9031: =item contained_map_check()
9032:
9033: =item url_paste_fixups()
9034:
9035: =item apply_fixups()
9036:
9037: =item copy_dependencies()
9038:
1.329 droeschl 9039: =item update_parameter()
9040:
9041: =item handle_edit_cmd()
9042:
9043: =item editor()
9044:
9045: =item process_file_upload()
9046:
9047: =item process_secondary_uploads()
9048:
9049: =item is_supplemental_title()
9050:
9051: =item entryline()
9052:
9053: =item tiehash()
9054:
9055: =item untiehash()
9056:
9057: =item checkonthis()
9058:
9059: check on this
9060:
9061: =item verifycontent()
9062:
9063: Verify Content
9064:
1.636 raeburn 9065: =item devalidateversioncache()
9066:
9067: =item checkversions()
1.329 droeschl 9068:
9069: Check Versions
9070:
9071: =item mark_hash_old()
9072:
9073: =item is_hash_old()
9074:
9075: =item changewarning()
9076:
9077: =item init_breadcrumbs()
9078:
9079: Breadcrumbs for special functions
9080:
1.484 raeburn 9081: =item create_list_elements()
9082:
9083: =item create_form_ul()
9084:
9085: =item startContentScreen()
9086:
9087: =item endContentScreen()
9088:
9089: =item supplemental_base()
9090:
9091: =item embedded_form_elems()
9092:
9093: =item embedded_destination()
9094:
9095: =item return_to_editor()
9096:
9097: =item decompression_info()
9098:
9099: =item decompression_phase_one()
9100:
9101: =item decompression_phase_two()
9102:
9103: =item remove_archive()
9104:
9105: =item generate_admin_menu()
9106:
9107: =item generate_edit_table()
9108:
9109: =item editing_js()
9110:
9111: =item history_tab_js()
9112:
9113: =item inject_data_js()
9114:
9115: =item dump_switchserver_js()
9116:
1.485 raeburn 9117: =item resize_scrollbox_js()
1.484 raeburn 9118:
9119: =item makedocslogform()
9120:
1.485 raeburn 9121: =item makesimpleeditform()
9122:
1.329 droeschl 9123: =back
9124:
9125: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>