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