Annotation of loncom/interface/londocs.pm, revision 1.702
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.702 ! raeburn 4: # $Id: londocs.pm,v 1.701 2023/07/11 19:33:02 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.606 raeburn 46: use Apache::lonhomework();
47: use Apache::lonpublisher();
1.651 raeburn 48: use Apache::loncourserespicker();
1.329 droeschl 49: use HTML::Entities;
1.488 raeburn 50: use HTML::TokeParser;
1.329 droeschl 51: use GDBM_File;
1.578 raeburn 52: use File::MMagic;
1.606 raeburn 53: use File::Copy;
1.329 droeschl 54: use Apache::lonlocal;
55: use Cwd;
1.643 raeburn 56: use UUID::Tiny ':std';
1.329 droeschl 57: use LONCAPA qw(:DEFAULT :match);
58:
59: my $iconpath;
60:
61: my %hash;
62:
63: my $hashtied;
64: my %alreadyseen=();
65:
66: my $hadchanges;
1.557 raeburn 67: my $suppchanges;
1.329 droeschl 68:
69:
70: my %help=();
71:
72:
73: sub mapread {
74: my ($coursenum,$coursedom,$map)=@_;
75: return
76: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
77: $map);
78: }
79:
80: sub storemap {
1.492 raeburn 81: my ($coursenum,$coursedom,$map,$contentchg)=@_;
82: my $report;
83: if (($contentchg) && ($map =~ /^default/)) {
84: $report = 1;
85: }
1.329 droeschl 86: my ($outtext,$errtext)=
87: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 88: $map,1,$report);
1.329 droeschl 89: if ($errtext) { return ($errtext,2); }
1.364 bisitz 90:
1.557 raeburn 91: if ($map =~ /^default/) {
92: $hadchanges=1;
1.682 raeburn 93: } elsif ($contentchg) {
1.557 raeburn 94: $suppchanges=1;
95: }
1.329 droeschl 96: return ($errtext,0);
97: }
98:
99:
100:
101: sub authorhosts {
102: my %outhash=();
103: my $home=0;
104: my $other=0;
105: foreach my $key (keys(%env)) {
106: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
107: my $role=$1;
108: my $realm=$2;
109: my ($start,$end)=split(/\./,$env{$key});
110: if (($start) && ($start>time)) { next; }
111: if (($end) && (time>$end)) { next; }
112: my ($ca,$cd);
113: if ($1 eq 'au') {
114: $ca=$env{'user.name'};
115: $cd=$env{'user.domain'};
116: } else {
117: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
118: }
119: my $allowed=0;
120: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
121: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 122: foreach my $id (@ids) {
123: if ($id eq $myhome) {
124: $allowed=1;
125: last;
126: }
127: }
1.329 droeschl 128: if ($allowed) {
129: $home++;
1.484 raeburn 130: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 131: } else {
1.484 raeburn 132: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 133: $other++;
134: }
135: }
136: }
137: return ($home,$other,%outhash);
138: }
139:
140:
141: sub clean {
142: my ($title)=@_;
143: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 144: return $title;
1.329 droeschl 145: }
146:
1.617 raeburn 147: sub default_folderpath {
148: my ($coursenum,$coursedom,$navmapref) = @_;
149: return unless ($coursenum && $coursedom && ref($navmapref));
150: # Check if entire course is hidden and/or encrypted
151: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
152: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
153: unless (ref($$navmapref)) {
154: $$navmapref = Apache::lonnavmaps::navmap->new();
155: }
156: if (ref($$navmapref)) {
157: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
158: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
159: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
160: unless (@resources) {
161: $hiddenmap = 1;
162: unless ($env{'request.role.adv'}) {
163: $hiddentop = 1;
164: if ($env{'form.folder'}) {
165: undef($env{'form.folder'});
166: }
167: }
168: }
169: }
170: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
171: $encryptmap = 1;
172: }
173: }
174: unless ($hiddentop) {
175: $folderpath='default&'.&escape(&mt('Main Content')).
176: '::'.$hiddenmap.':'.$encryptmap.'::';
177: }
178: if (wantarray) {
179: return ($folderpath,$hiddentop);
180: } else {
181: return $folderpath;
182: }
183: }
1.329 droeschl 184:
1.685 raeburn 185: sub validate_supppath {
186: my ($coursenum,$coursedom) = @_;
187: my $backto;
1.677 raeburn 188: if ($env{'form.supppath'} ne '') {
189: my @items = split(/\&/,$env{'form.supppath'});
1.685 raeburn 190: my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
1.677 raeburn 191: for (my $i=0; $i<@items; $i++) {
192: my $odd = $i%2;
193: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
194: $badpath = 1;
1.685 raeburn 195: last;
196: } elsif ($odd) {
197: my $suffix;
198: my $idx = $i-1;
199: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
200: $backto .= '&'.$1;
201: } elsif ($items[$idx] eq 'supplemental') {
202: $backto .= '&'.$items[$i];
203: } else {
204: $backto .= '&'.$items[$i];
205: my $is_hidden;
206: unless ($got_supp) {
1.688 raeburn 207: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 208: if (ref($supplemental) eq 'HASH') {
209: if (ref($supplemental->{'hidden'}) eq 'HASH') {
210: %supphidden = %{$supplemental->{'hidden'}};
211: }
212: if (ref($supplemental->{'ids'}) eq 'HASH') {
213: %suppids = %{$supplemental->{'ids'}};
214: }
215: }
216: $got_supp = 1;
217: }
218: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
219: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
220: if ($supphidden{$mapid}) {
221: $is_hidden = 1;
222: }
223: }
224: $suffix = '::'.$is_hidden.':::';
225: }
226: $supppath .= '&'.$items[$i].$suffix;
227: } else {
228: $supppath .= '&'.$items[$i];
229: $backto .= '&'.$items[$i];
1.677 raeburn 230: }
231: }
232: if ($badpath) {
233: delete($env{'form.supppath'});
1.685 raeburn 234: } else {
235: $supppath =~ s/^\&//;
236: $backto =~ s/^\&//;
237: $env{'form.supppath'} = $supppath;
1.677 raeburn 238: }
239: }
1.685 raeburn 240: return $backto;
1.677 raeburn 241: }
242:
1.329 droeschl 243: sub dumpcourse {
244: my ($r) = @_;
1.408 raeburn 245: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 246: my ($starthash,$js);
247: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
248: $js = <<"ENDJS";
249: <script type="text/javascript">
250: // <![CDATA[
251:
252: function hide_searching() {
253: if (document.getElementById('searching')) {
254: document.getElementById('searching').style.display = 'none';
255: }
256: return;
257: }
258:
259: // ]]>
260: </script>
261: ENDJS
262: $starthash = {
263: add_entries => {'onload' => "hide_searching();"},
264: };
265: }
1.568 raeburn 266: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
267: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 268: $r->print(&startContentScreen('tools'));
1.329 droeschl 269: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 270: unless ($home) {
271: $r->print(&endContentScreen());
272: return '';
273: }
1.329 droeschl 274: my $origcrsid=$env{'request.course.id'};
275: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
276: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
277: # Do the dumping
1.484 raeburn 278: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
279: $r->print(&endContentScreen());
280: return '';
281: }
1.531 raeburn 282: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 283: $r->print('<h3>'.&mt('Copying Files').'</h3>');
284: my $title=$env{'form.authorfolder'};
285: $title=&clean($title);
1.567 raeburn 286: my ($navmap,$errormsg) =
287: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
288: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
289: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
290: my (%maps,%resources,%titles);
291: if (!ref($navmap)) {
292: $r->print($errormsg.
293: &endContentScreen());
294: return '';
295: } else {
296: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
297: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 298: }
1.567 raeburn 299: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
300: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
301: %newcontent,%has_simpleprobs);
302: foreach my $item (sort {$a <=> $b} (@todump)) {
303: my $name = $env{'form.namefor_'.$item};
304: if ($resources{$item}) {
305: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
306: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
307: $tocopy{$1} = $name;
308: $display{$item} = $1;
309: $lookup{$1} = $item;
310: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
311: $simpleproblems{$item} = {
312: symb => $resources{$item},
313: name => $name,
314: };
315: $display{$item} = 'simpleproblem_'.$name;
316: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
317: $has_simpleprobs{$1}{$id} = $item;
318: }
319: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
320: my $marker = $1;
321: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
322: $simplepages{$item} = {
323: res => $res,
324: title => $titles{$item},
325: db => $db_name,
326: marker => $marker,
327: symb => $resources{$item},
328: name => $name,
329: };
330: $display{$item} = '/'.$res;
331: }
332: } elsif ($maps{$item}) {
333: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
334: $tocopy{$1} = $name;
335: $display{$item} = $1;
336: $lookup{$1} = $item;
337: }
338: } else {
339: next;
340: }
341: }
1.329 droeschl 342: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
343: $crs=~s/\_/\//g;
1.567 raeburn 344: my $mm = new File::MMagic;
345: my $prefix = "/uploaded/$cdom/$cnum/";
346: %replacehash = %tocopy;
347: foreach my $item (sort(keys(%simpleproblems))) {
348: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
349: $newcontent{$display{$item}} = $content;
350: }
351: my $gateway = Apache::lonhtmlgateway->new('web');
352: foreach my $item (sort(keys(%simplepages))) {
353: if (ref($simplepages{$item}) eq 'HASH') {
354: my $pagetitle = $simplepages{$item}{'title'};
355: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
356: my %contents;
357: foreach my $field (keys(%fields)) {
358: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
359: my $name = $1;
360: my $msg = $fields{$field};
361: if ($name eq 'webreferences') {
362: if ($msg =~ m{^https?://}) {
363: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
364: }
365: } else {
366: $msg = &Encode::decode('utf8',$msg);
367: $msg = $gateway->process_outgoing_html($msg,1);
368: $contents{$name} = $msg;
369: }
370: } elsif ($field eq 'uploaded.photourl') {
371: my $marker = $simplepages{$item}{marker};
372: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
373: my $filepath = $1;
374: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
375: if ($fname ne '') {
376: $fname=~s/\.(\w+)$//;
377: my $ext=$1;
378: $fname = &clean($fname);
379: $fname.='.'.$ext;
380: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
381: $replacehash{$filepath} = $relpath.$fname;
382: $deps{$item}{$filepath} = 1;
383: }
384: }
385: }
386: }
387: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
388: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
389: my $content = '
390: <html>
391: <head>
392: <title>'.$pagetitle.'</title>
393: </head>
394: <body bgcolor="#ffffff">';
395: if ($contents{title}) {
396: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
397: }
398: if ($contents{image}) {
399: $content .= "\n".$contents{image};
400: }
401: if ($contents{content}) {
402: $content .= '
403: <div class="LC_Box">
1.577 bisitz 404: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 405: $contents{content}.'
406: </div>';
407: }
408: if ($contents{webreferences}) {
409: $content .= '
410: <div class="LC_Box">
1.577 bisitz 411: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 412: $contents{webreferences}.'
413: </div>';
414: }
415: $content .= '
416: </body>
417: </html>
418: ';
419: $newcontent{'/'.$simplepages{$item}{res}} = $content;
420: }
421: }
422: foreach my $item (keys(%tocopy)) {
423: unless ($item=~/\.(sequence|page)$/) {
424: my $currurlpath = $prefix.$item;
425: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
426: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
427: }
428: }
429: foreach my $num (sort {$a <=> $b} (@todump)) {
430: my $src = $display{$num};
431: next if ($src eq '');
432: my @needcopy = ();
433: if ($replacehash{$src}) {
434: push(@needcopy,$src);
435: if (ref($deps{$num}) eq 'HASH') {
436: foreach my $dep (sort(keys(%{$deps{$num}}))) {
437: if ($replacehash{$dep}) {
438: push(@needcopy,$dep);
439: }
440: }
441: }
442: } elsif ($src =~ /^simpleproblem_/) {
443: push(@needcopy,$src);
444: }
445: next if (@needcopy == 0);
446: my ($result,$depresult);
447: for (my $i=0; $i<@needcopy; $i++) {
448: my $item = $needcopy[$i];
449: my $newfilename;
450: if ($simpleproblems{$num}) {
451: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
452: } else {
453: $newfilename=$title.'/'.$replacehash{$item};
454: }
455: $newfilename=~s/\.(\w+)$//;
456: my $ext=$1;
457: $newfilename=&clean($newfilename);
458: $newfilename.='.'.$ext;
459: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
460: if ($newrelpath ne $replacehash{$item}) {
461: $replacehash{$item} = $newrelpath;
462: }
463: my @dirs=split(/\//,$newfilename);
464: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
465: my $makepath=$path;
466: my $fail;
467: my $origin;
468: for (my $i=0;$i<$#dirs;$i++) {
469: $makepath.='/'.$dirs[$i];
470: unless (-e $makepath) {
471: unless(mkdir($makepath,0755)) {
472: $fail = &mt('Directory creation failed.');
473: }
474: }
475: }
476: if ($i == 0) {
477: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
478: } else {
479: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
480: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
481: &mt('(dependency)').'</span>: ';
482: }
483: if (-e $path.'/'.$newfilename) {
484: $fail = &mt('Destination already exists -- not overwriting.');
485: } else {
486: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
487: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
488: ($item =~ /^simpleproblem_/)) {
489: print $fh $newcontent{$item};
490: } else {
491: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
492: if (-e $fileloc) {
493: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
494: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
495: (ref($has_simpleprobs{$item}) eq 'HASH')) {
496: my %changes = %{$has_simpleprobs{$item}};
497: my $content = &Apache::lonclonecourse::rewritefile(
498: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
499: (%replacehash,$crs => '')
500: );
501: my $updatedcontent = '';
502: my $parser = HTML::TokeParser->new(\$content);
503: $parser->attr_encoded(1);
504: while (my $token = $parser->get_token) {
505: if ($token->[0] eq 'S') {
506: if (($token->[1] eq 'resource') &&
507: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
508: ($changes{$token->[2]->{'id'}})) {
509: my $id = $token->[2]->{'id'};
510: $updatedcontent .= '<'.$token->[1];
511: foreach my $attrib (@{$token->[3]}) {
512: next unless ($attrib =~ /^(src|type|title|id)$/);
513: if ($attrib eq 'src') {
514: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
515: if ($file) {
516: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
517: } else {
518: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
519: }
520: } else {
521: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
522: }
523: }
524: $updatedcontent .= ' />'."\n";
525: } else {
526: $updatedcontent .= $token->[4]."\n";
527: }
528: } else {
529: $updatedcontent .= $token->[2];
530: }
531: }
532: print $fh $updatedcontent;
533: } else {
534: print $fh &Apache::lonclonecourse::rewritefile(
535: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
536: (%replacehash,$crs => '')
537: );
538: }
539: } else {
540: print $fh
541: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
542: }
543: } else {
544: $fail = &mt('Source does not exist.');
545: }
546: }
547: $fh->close();
548: } else {
549: $fail = &mt('Could not write to destination.');
550: }
551: }
552: my $text;
553: if ($fail) {
554: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
555: } else {
556: $text = '<span class="LC_success">'.&mt('ok').'</span>';
557: }
558: if ($i == 0) {
559: $result .= $text;
560: } else {
561: $depresult .= $text.'</li>';
562: }
563: }
564: $r->print($result);
565: if ($depresult) {
566: $r->print('<ul>'.$depresult.'</ul>');
567: }
568: }
569: } else {
570: my ($navmap,$errormsg) =
571: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
572: if (!ref($navmap)) {
573: $r->print($errormsg);
574: } else {
575: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
576: $r->rflush();
577: my ($preamble,$formname);
578: $formname = 'dumpdoc';
579: unless ($home==1) {
580: $preamble = '<div class="LC_left_float">'.
581: '<fieldset><legend>'.
582: &mt('Select the Authoring Space').
583: '</legend><select name="authorspace">';
1.329 droeschl 584: }
1.567 raeburn 585: my @orderspaces = ();
586: foreach my $key (sort(keys(%outhash))) {
587: if ($key=~/^home_(.+)$/) {
588: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
589: unshift(@orderspaces,$1);
590: } else {
591: push(@orderspaces,$1);
592: }
593: }
594: }
1.569 raeburn 595: if ($home>1) {
596: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
597: }
1.567 raeburn 598: foreach my $user (@orderspaces) {
1.329 droeschl 599: if ($home==1) {
1.567 raeburn 600: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 601: } else {
1.567 raeburn 602: $preamble .= '<option value="'.$user.'">'.$user.' - '.
603: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
604: }
1.329 droeschl 605: }
1.567 raeburn 606: unless ($home==1) {
607: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 608: }
1.567 raeburn 609: my $title=$origcrsdata{'description'};
610: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 611: $title=&clean($title);
1.567 raeburn 612: $preamble .= '<div class="LC_left_float">'.
613: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
614: '<input type="text" size="50" name="authorfolder" value="'.
615: $title.'" />'.
616: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
617: my %uploadedfiles;
618: &tiehash();
619: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
620: my ($ext)=($file=~/\.(\w+)$/);
621: # FIXME Check supplemental here
622: my $title=$hash{'title_'.$hash{
623: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
624: if (!$title) {
625: $title=$file;
626: } else {
627: $title=~s|/|_|g;
628: }
629: $title=~s/\.(\w+)$//;
630: $title=&clean($title);
631: $title.='.'.$ext;
632: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
633: $uploadedfiles{$file} = $title;
634: }
635: &untiehash();
636: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
637: undef,undef,$preamble,$home,\%uploadedfiles));
638: }
1.329 droeschl 639: }
1.484 raeburn 640: $r->print(&endContentScreen());
1.329 droeschl 641: }
642:
1.567 raeburn 643: sub recurse_html {
644: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
645: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
646: my (%allfiles,%codebase);
647: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
648: if (keys(%allfiles)) {
649: foreach my $dependency (keys(%allfiles)) {
650: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
651: my ($depurl,$relfile,$newcontainer);
652: if ($dependency =~ m{^/}) {
653: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
654: $relfile = $1;
655: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
656: $newcontainer = $1;
657: next if ($replacehash->{$newcontainer});
658: }
659: $depurl = $dependency;
660: } else {
661: next;
662: }
663: } else {
664: $relfile = $dependency;
665: $depurl = $currurlpath;
1.630 raeburn 666: $depurl =~ s{[^/]+$}{};
1.567 raeburn 667: $depurl .= $dependency;
1.630 raeburn 668: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 669: }
670: next if ($relfile eq '');
671: my $newname = $replacehash->{$container};
672: $newname =~ s{[^/]+$}{};
673: $replacehash->{$newcontainer} = $newname.$relfile;
674: $deps->{$item}{$newcontainer} = 1;
675: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
676: my $depfile = &Apache::lonnet::filelocation('',$depurl);
677: my $type = $mm->checktype_filename($depfile);
678: if ($type eq 'text/html') {
679: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
680: }
681: }
682: }
683: }
684: return;
685: }
686:
1.329 droeschl 687: sub group_import {
1.598 raeburn 688: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 689: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
690: %removeparam,$importuploaded,$fixuperrors);
691: $allmaps = {};
1.329 droeschl 692: while (@files) {
693: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 694: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 695: && ($caller eq 'londocs')
696: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 697:
1.329 droeschl 698: my $errtext = '';
699: my $fatal = 0;
700: my $newmapstr = '<map>'."\n".
701: '<resource id="1" src="" type="start"></resource>'."\n".
702: '<link from="1" to="2" index="1"></link>'."\n".
703: '<resource id="2" src="" type="finish"></resource>'."\n".
704: '</map>';
705: $env{'form.output'}=$newmapstr;
706: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
707: 'output',$1.$2);
1.534 raeburn 708: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 709: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
710: $fatal = 2;
711: }
712: if ($fatal) {
713: return ($errtext,$fatal);
714: }
715: }
716: if ($url) {
1.626 raeburn 717: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 718: $url = $1;
719: my $marker = $2;
720: my $info = $3;
1.699 raeburn 721: my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.642 raeburn 722: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 723: my @toolinfo = split(/:/,$info);
724: if ($residx) {
1.604 raeburn 725: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 726: $toolid = $toolsettings{'id'};
727: } else {
1.604 raeburn 728: $toolid = shift(@toolinfo);
1.598 raeburn 729: }
1.699 raeburn 730: if ($toolid =~ /^c/) {
731: $tooltype = 'crs';
732: $toolprefix = 'c';
733: } else {
734: $tooltype = 'dom';
735: }
1.598 raeburn 736: $toolid =~ s/\D//g;
1.604 raeburn 737: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 738: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
739: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 740: foreach my $item (@extras) {
741: $toolhash{$item} = &unescape($toolhash{$item});
742: }
1.645 raeburn 743: if ($folder =~ /^supplemental/) {
1.648 raeburn 744: delete($toolhash{'gradable'});
745: } else {
746: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 747: }
1.598 raeburn 748: if (ref($ltitoolsref) eq 'HASH') {
1.699 raeburn 749: if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
750: if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
751: my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
752: my @deleted;
753: $toolhash{'id'} = $toolprefix.$toolid;
754: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
755: ($toolhash{'target'} eq 'window')) {
756: if ($toolhash{'target'} eq 'window') {
757: foreach my $item ('width','height') {
758: $toolhash{$item} =~ s/^\s+//;
759: $toolhash{$item} =~ s/\s+$//;
760: if ($toolhash{$item} =~ /\D/) {
761: delete($toolhash{$item});
762: if ($residx) {
763: if ($toolsettings{$item}) {
764: push(@deleted,$item);
765: }
1.624 raeburn 766: }
767: }
768: }
1.604 raeburn 769: }
1.699 raeburn 770: } elsif ($residx) {
771: $toolhash{'target'} = $toolsettings{'target'};
772: if ($toolhash{'target'} eq 'window') {
773: foreach my $item ('width','height') {
774: $toolhash{$item} = $toolsettings{$item};
775: }
776: }
777: } elsif (ref($tools{'display'}) eq 'HASH') {
778: $toolhash{'target'} = $tools{'display'}{'target'};
779: if ($toolhash{'target'} eq 'window') {
780: $toolhash{'width'} = $tools{'display'}{'width'};
781: $toolhash{'height'} = $tools{'display'}{'height'};
1.624 raeburn 782: }
1.604 raeburn 783: }
1.699 raeburn 784: if ($toolhash{'target'} eq 'iframe') {
785: foreach my $item ('width','height','linktext','explanation') {
786: delete($toolhash{$item});
787: if ($residx) {
788: if ($toolsettings{$item}) {
789: push(@deleted,$item);
790: }
1.624 raeburn 791: }
1.604 raeburn 792: }
1.699 raeburn 793: } elsif ($toolhash{'target'} eq 'tab') {
794: foreach my $item ('width','height') {
795: delete($toolhash{$item});
796: if ($residx) {
797: if ($toolsettings{$item}) {
798: push(@deleted,$item);
799: }
1.628 raeburn 800: }
801: }
802: }
1.699 raeburn 803: if (ref($tools{'crsconf'}) eq 'HASH') {
804: foreach my $item ('label','title','linktext','explanation') {
805: my $crsitem;
806: if (($item eq 'label') || ($item eq 'title')) {
807: $crsitem = 'crs'.$item;
808: } else {
809: $crsitem = $item;
810: }
811: if ($tools{'crsconf'}{$item}) {
812: $toolhash{$crsitem} =~ s/^\s+//;
813: $toolhash{$crsitem} =~ s/\s+$//;
814: if ($toolhash{$crsitem} eq '') {
815: delete($toolhash{$crsitem});
816: }
817: } else {
1.624 raeburn 818: delete($toolhash{$crsitem});
1.604 raeburn 819: }
1.699 raeburn 820: if (($residx) && (exists($toolsettings{$crsitem}))) {
821: unless (exists($toolhash{$crsitem})) {
822: push(@deleted,$crsitem);
823: }
824: }
1.604 raeburn 825: }
1.699 raeburn 826: }
827: if ($toolhash{'passback'}) {
828: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
829: $toolhash{'gradesecret'} = $gradesecret;
830: $toolhash{'gradesecretdate'} = time;
831: }
832: if ($toolhash{'roster'}) {
833: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
834: $toolhash{'rostersecret'} = $rostersecret;
835: $toolhash{'rostersecretdate'} = time;
836: }
837: my $changegradable;
838: if (($residx) && ($folder =~ /^default/)) {
839: if ($toolsettings{'gradable'}) {
840: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
841: push(@deleted,'gradable');
842: $changegradable = 1;
1.604 raeburn 843: }
1.699 raeburn 844: } elsif ($toolhash{'gradable'}) {
845: $changegradable = 1;
1.604 raeburn 846: }
1.699 raeburn 847: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 848: $changegradable = 1;
1.699 raeburn 849: if ($toolsettings{'gradable'}) {
850: $toolhash{'gradable'} = 1;
851: }
1.645 raeburn 852: }
1.648 raeburn 853: }
1.699 raeburn 854: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
855: if ($putres eq 'ok') {
856: if (@deleted) {
857: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648 raeburn 858: }
1.699 raeburn 859: if (($changegradable) && ($folder =~ /^default/)) {
860: my $val;
861: if ($toolhash{'gradable'}) {
862: $val = 'yes';
863: } else {
864: $val = 'no';
865: }
866: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
867: 'string_yesno');
868: &remember_parms($residx,'gradable','set',$val);
1.645 raeburn 869: }
1.699 raeburn 870: } else {
871: return (&mt('Failed to save update to external tool.'),1);
1.645 raeburn 872: }
1.604 raeburn 873: }
1.598 raeburn 874: }
875: }
876: }
1.529 raeburn 877: if (($caller eq 'londocs') &&
878: ($folder =~ /^default/)) {
1.534 raeburn 879: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 880: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
881: my $cid = $coursedom.'_'.$coursenum;
882: $allmaps =
883: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
884: $chome,$cid);
885: $donechk = 1;
886: }
887: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 888: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
889: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 890: $importuploaded = 1;
891: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
892: next if ($allmaps->{$url});
893: }
894: }
1.344 bisitz 895: if (!$residx
1.329 droeschl 896: || defined($LONCAPA::map::zombies[$residx])) {
897: $residx = &LONCAPA::map::getresidx($url,$residx);
898: push(@LONCAPA::map::order, $residx);
899: }
900: my $ext = 'false';
901: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 902: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
903: my $filepath = $1;
1.675 raeburn 904: my $fname;
905: if ($name eq '') {
906: $name = &mt('Web Page');
1.534 raeburn 907: $fname = 'web';
908: } else {
1.675 raeburn 909: $fname = $name;
910: $fname=&Apache::lonnet::clean_filename($fname);
911: if ($fname eq '') {
912: $fname = 'web';
913: } elsif (length($fname) > 15) {
914: $fname = substr($fname,0,14);
915: }
1.534 raeburn 916: }
1.675 raeburn 917: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 918: my $initialtext = &mt('Replace with your own content.');
919: my $newhtml = <<END;
1.545 raeburn 920: <html>
1.534 raeburn 921: <head>
1.675 raeburn 922: <title>$title</title>
1.534 raeburn 923: </head>
924: <body bgcolor="#ffffff">
925: $initialtext
926: </body>
927: </html>
928: END
929: $env{'form.output'}=$newhtml;
1.630 raeburn 930: my $result =
1.534 raeburn 931: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
932: 'output',
933: "$filepath/$residx/$fname.html");
934: if ($result =~ m{^/uploaded/}) {
935: $url = $result;
936: if ($filepath =~ /^supplemental/) {
937: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
938: $env{'user.domain'}.'___&&&___'.$name;
939: }
940: } else {
941: return (&mt('Failed to save new web page.'),1);
942: }
943: }
1.675 raeburn 944: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 945: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 946: $LONCAPA::map::resources[$residx] =
1.329 droeschl 947: join(':', ($name, $url, $ext, 'normal', 'res'));
948: }
949: }
1.529 raeburn 950: if ($importuploaded) {
951: my %import_errors;
952: my %updated = (
953: removefrommap => \%removefrommap,
954: removeparam => \%removeparam,
955: );
1.533 raeburn 956: my ($result,$msgsarray,$lockerror) =
957: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 958: if (keys(%import_errors) > 0) {
1.530 raeburn 959: $fixuperrors =
1.529 raeburn 960: '<p span class="LC_warning">'."\n".
961: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
962: '<ul>'."\n";
963: foreach my $key (sort(keys(%import_errors))) {
964: $fixuperrors .= '<li>'.$key.'</li>'."\n";
965: }
966: $fixuperrors .= '</ul></p>'."\n";
967: }
1.533 raeburn 968: if (ref($msgsarray) eq 'ARRAY') {
969: if (@{$msgsarray} > 0) {
970: $fixuperrors .= '<p class="LC_info">'.
971: join('<br />',@{$msgsarray}).
972: '</p>';
973: }
974: }
975: if ($lockerror) {
976: $fixuperrors .= '<p class="LC_error">'.
977: $lockerror.
978: '</p>';
979: }
1.529 raeburn 980: }
981: my ($errtext,$fatal) =
982: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 983: unless ($fatal) {
984: if ($folder =~ /^supplemental/) {
1.561 raeburn 985: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
986: $folder.'.'.$container);
1.557 raeburn 987: }
988: }
1.529 raeburn 989: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 990: }
991:
992: sub log_docs {
1.494 raeburn 993: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 994: }
995:
996: {
997: my @oldresources=();
998: my @oldorder=();
999: my $parmidx;
1000: my %parmaction=();
1001: my %parmvalue=();
1002: my $changedflag;
1003:
1004: sub snapshotbefore {
1005: @oldresources=@LONCAPA::map::resources;
1006: @oldorder=@LONCAPA::map::order;
1007: $parmidx=undef;
1008: %parmaction=();
1009: %parmvalue=();
1010: $changedflag=0;
1011: }
1012:
1013: sub remember_parms {
1014: my ($idx,$parameter,$action,$value)=@_;
1015: $parmidx=$idx;
1016: $parmaction{$parameter}=$action;
1017: $parmvalue{$parameter}=$value;
1018: $changedflag=1;
1019: }
1020:
1021: sub log_differences {
1022: my ($plain)=@_;
1023: my %storehash=('folder' => $plain,
1024: 'currentfolder' => $env{'form.folder'});
1025: if ($parmidx) {
1026: $storehash{'parameter_res'}=$oldresources[$parmidx];
1027: foreach my $parm (keys(%parmaction)) {
1028: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1029: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1030: }
1031: }
1032: my $maxidx=$#oldresources;
1033: if ($#LONCAPA::map::resources>$#oldresources) {
1034: $maxidx=$#LONCAPA::map::resources;
1035: }
1036: for (my $idx=0; $idx<=$maxidx; $idx++) {
1037: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1038: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1039: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1040: $changedflag=1;
1041: }
1042: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1043: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1044: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1045: $changedflag=1;
1046: }
1047: }
1048: $storehash{'maxidx'}=$maxidx;
1049: if ($changedflag) { &log_docs(\%storehash); }
1050: }
1051: }
1052:
1053: sub docs_change_log {
1.611 raeburn 1054: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 1055: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 1056: my $navmap;
1.483 raeburn 1057: my $js = '<script type="text/javascript">'."\n".
1058: '// <![CDATA['."\n".
1059: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 1060: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 1061: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 1062: &history_tab_js()."\n".
1.484 raeburn 1063: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 1064: '// ]]>'."\n".
1065: '</script>'."\n";
1.484 raeburn 1066: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1067: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1068: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1069: my %orderhash;
1070: my $container='sequence';
1071: my $pathitem;
1.519 raeburn 1072: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1073: $container='page';
1074: }
1.519 raeburn 1075: my $folderpath=$env{'form.folderpath'};
1076: if ($folderpath eq '') {
1.617 raeburn 1077: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1078: }
1.617 raeburn 1079: undef($navmap);
1.519 raeburn 1080: $pathitem = '<input type="hidden" name="folderpath" value="'.
1081: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1082: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1083: my $jumpto = $readfile;
1084: $jumpto =~ s{^/}{};
1085: my $tid = 1;
1.489 raeburn 1086: if ($supplementalflag) {
1087: $tid = 2;
1088: }
1.630 raeburn 1089: my ($breadcrumbtrail) =
1.509 raeburn 1090: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1091: $r->print($breadcrumbtrail.
1092: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1093: $readfile));
1.329 droeschl 1094: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1095: $env{'course.'.$env{'request.course.id'}.'.domain'},
1096: $env{'course.'.$env{'request.course.id'}.'.num'});
1097:
1098: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1099:
1100: my %saveable_parameters = ('show' => 'scalar',);
1101: &Apache::loncommon::store_course_settings('docs_log',
1102: \%saveable_parameters);
1103: &Apache::loncommon::restore_course_settings('docs_log',
1104: \%saveable_parameters);
1105: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1106: # FIXME: internationalization seems wrong here
1.329 droeschl 1107: my %lt=('hiddenresource' => 'Resources hidden',
1108: 'encrypturl' => 'URL hidden',
1109: 'randompick' => 'Randomly pick',
1110: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1111: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1112: 'set' => 'set to',
1113: 'del' => 'deleted');
1.484 raeburn 1114: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1115: $pathitem."\n".
1116: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1117: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1118: $r->print('<div class="LC_left_float">'.
1119: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1120: &makedocslogform($filter,1).
1121: '</fieldset></div><br clear="all" />');
1.329 droeschl 1122: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1123: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1124: &mt('After').'</th>'.
1125: &Apache::loncommon::end_data_table_header_row());
1126: my $shown=0;
1127: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1128: if ($env{'form.displayfilter'} eq 'currentfolder') {
1129: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1130: }
1131: my @changes=keys(%{$docslog{$id}{'logentry'}});
1132: if ($env{'form.displayfilter'} eq 'containing') {
1133: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1134: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1135: foreach my $key (@changes) {
1136: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1137: }
1.344 bisitz 1138: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1139: }
1140: my $count = 0;
1141: my $time =
1142: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1143: my $plainname =
1144: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1145: $docslog{$id}{'exe_udom'});
1146: my $about_me_link =
1147: &Apache::loncommon::aboutmewrapper($plainname,
1148: $docslog{$id}{'exe_uname'},
1149: $docslog{$id}{'exe_udom'});
1150: my $send_msg_link='';
1151: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1152: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1153: $send_msg_link ='<br />'.
1154: &Apache::loncommon::messagewrapper(&mt('Send message'),
1155: $docslog{$id}{'exe_uname'},
1156: $docslog{$id}{'exe_udom'});
1157: }
1158: $r->print(&Apache::loncommon::start_data_table_row());
1159: $r->print('<td>'.$time.'</td>
1160: <td>'.$about_me_link.
1161: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1162: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1163: $send_msg_link.'</td><td>'.
1164: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1165: my $is_supp = 0;
1166: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1167: $is_supp = 1;
1168: }
1.329 droeschl 1169: # Before
1170: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1171: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1172: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1173: if ($oldname ne $newname) {
1.488 raeburn 1174: my $shown = &LONCAPA::map::qtescape($oldname);
1175: if ($is_supp) {
1176: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1177: }
1178: $r->print($shown);
1.329 droeschl 1179: }
1180: }
1181: $r->print('<ul>');
1182: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1183: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1184: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1185: if ($is_supp) {
1186: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1187: }
1188: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1189: }
1190: }
1191: $r->print('</ul>');
1192: # After
1193: $r->print('</td><td>');
1194:
1195: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1196: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1197: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1198: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1199: my $shown = &LONCAPA::map::qtescape($newname);
1200: if ($is_supp) {
1201: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1202: }
1203: $r->print($shown);
1.329 droeschl 1204: }
1.364 bisitz 1205: }
1.329 droeschl 1206: $r->print('<ul>');
1207: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1208: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1209: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1210: if ($is_supp) {
1211: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1212: }
1213: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1214: }
1215: }
1216: $r->print('</ul>');
1217: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 1218: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1219: if ($title eq '') {
1220: ($title) = ($url =~ m{/([^/]+)$});
1.695 raeburn 1221: } elsif ($is_supp) {
1222: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 1223: }
1224: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 1225: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1226: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1227: # FIXME: internationalization seems wrong here
1.329 droeschl 1228: $r->print('<li>'.
1229: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1230: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1231: .'</li>');
1232: }
1233: }
1234: $r->print('</ul>');
1235: }
1236: # End
1237: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1238: $shown++;
1239: if (!($env{'form.show'} eq &mt('all')
1240: || $shown<=$env{'form.show'})) { last; }
1241: }
1.484 raeburn 1242: $r->print(&Apache::loncommon::end_data_table()."\n".
1243: &makesimpleeditform($pathitem)."\n".
1244: '</div></div>');
1245: $r->print(&endContentScreen());
1.329 droeschl 1246: }
1247:
1248: sub update_paste_buffer {
1.492 raeburn 1249: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1250: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1251: if ($env{'form.multiremove'}) {
1252: $env{'form.multiremove'} =~ s/,$//;
1253: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1254: }
1255: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1256: if ($env{'form.multicut'}) {
1257: $env{'form.multicut'} =~ s/,$//;
1258: foreach my $item (split(/,/,$env{'form.multicut'})) {
1259: unless ($removals{$item}) {
1260: $cuts{$item} = 1;
1261: push(@possibles,$item.':cut');
1262: }
1263: }
1264: }
1265: if ($env{'form.multicopy'}) {
1266: $env{'form.multicopy'} =~ s/,$//;
1267: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1268: unless ($removals{$item} || $cuts{$item}) {
1269: push(@possibles,$item.':copy');
1270: }
1271: }
1272: }
1273: } elsif ($env{'form.markcopy'}) {
1274: @possibles = split(/,/,$env{'form.markcopy'});
1275: }
1.329 droeschl 1276:
1.538 raeburn 1277: return if (@possibles == 0);
1.329 droeschl 1278: return if (!defined($env{'form.copyfolder'}));
1279:
1280: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1281: $env{'form.copyfolder'});
1.538 raeburn 1282: return if ($fatal);
1283:
1284: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1285:
1.538 raeburn 1286: # Retrieve current paste buffer suffixes.
1287: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1288: my (%pasteurls,@newpaste);
1289:
1290: # Construct identifiers for current contents of user's paste buffer
1291: if (@currpaste) {
1292: foreach my $suffix (@currpaste) {
1.667 raeburn 1293: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1294: my $url = $env{'docs.markedcopy_url_'.$suffix};
1295: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1296: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1297: ($url ne '')) {
1298: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1299: $pasteurls{$cid.'_'.$mapidx} = 1;
1300: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1301: $pasteurls{$url} = 1;
1302: } else {
1.669 raeburn 1303: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 1304: }
1305: }
1.538 raeburn 1306: }
1307: }
1308:
1309: # Mark items for copying (skip any items already in user's paste buffer)
1310: my %addtoenv;
1.597 raeburn 1311:
1312: my @pathitems = split(/\&/,$env{'form.folderpath'});
1313: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 1314: my $ispage = $folderconf[5];
1.597 raeburn 1315:
1.538 raeburn 1316: foreach my $item (@possibles) {
1317: my ($orderidx,$cmd) = split(/:/,$item);
1318: next if ($orderidx =~ /\D/);
1319: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1320: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1321: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1322: my %denied = &action_restrictions($coursenum,$coursedom,
1323: &LONCAPA::map::qtescape($url),
1324: $env{'form.folderpath'},\%curr_groups);
1325: next if ($denied{'copy'});
1326: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 1327: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1328: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1329: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1330: next if (exists($pasteurls{$url}));
1331: } else {
1332: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1333: }
1.538 raeburn 1334: my ($suffix,$errortxt,$locknotfreed) =
1335: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1336: if ($suffix ne '') {
1337: push(@newpaste,$suffix);
1338: } else {
1339: if ($locknotfreed) {
1340: return $locknotfreed;
1341: }
1.538 raeburn 1342: }
1343: if (&is_supplemental_title($title)) {
1344: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1345: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1346: }
1.329 droeschl 1347:
1.538 raeburn 1348: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1349: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1350: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1351: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1352: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1353: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1354: my $prefix = $1;
1355: my $subdir =$2;
1356: if ($subdir eq '') {
1357: $subdir = $prefix;
1.492 raeburn 1358: }
1.538 raeburn 1359: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1360: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1361: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1362: if (ref($hierarchy{$url}) eq 'HASH') {
1363: my ($nested,$nestednames);
1364: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1365: $nested =~ s/\&$//;
1366: $nestednames =~ s/\Q___&&&___\E$//;
1367: if ($nested ne '') {
1368: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1369: }
1370: if ($nestednames ne '') {
1371: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1372: }
1.492 raeburn 1373: }
1374: }
1.591 raeburn 1375: if ($locknotfreed) {
1376: $output = $locknotfreed;
1377: last;
1378: }
1.492 raeburn 1379: }
1.538 raeburn 1380: if (@newpaste) {
1381: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1382: }
1.492 raeburn 1383: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1384: delete($env{'form.markcopy'});
1.591 raeburn 1385: return $output;
1.329 droeschl 1386: }
1387:
1.492 raeburn 1388: sub recurse_uploaded_maps {
1389: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1390: if (ref($hierarchy->{$url}) eq 'HASH') {
1391: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1392: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1393: my (@uploaded,@names,%shorter);
1394: for (my $i=0; $i<@maps; $i++) {
1395: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1396: if ($inner ne '') {
1397: push(@uploaded,$inner);
1398: push(@names,&escape($titles[$i]));
1399: $shorter{$maps[$i]} = $inner;
1400: }
1401: }
1402: $$nestref .= "$dir:".join(',',@uploaded).'&';
1403: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1404: foreach my $map (@maps) {
1405: if ($shorter{$map} ne '') {
1406: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1407: }
1408: }
1409: }
1410: return;
1411: }
1412:
1.329 droeschl 1413: sub print_paste_buffer {
1.492 raeburn 1414: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1415: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1416:
1.538 raeburn 1417: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1418: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1419: }
1420:
1.538 raeburn 1421: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1422: my ($pasteitems,@pasteable);
1.575 raeburn 1423: my $clipboardcount = 0;
1.488 raeburn 1424:
1.538 raeburn 1425: # Construct identifiers for current contents of user's paste buffer
1426: foreach my $suffix (@currpaste) {
1427: next if ($suffix =~ /\D/);
1428: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1429: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1430: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1431: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1432: ($url ne '')) {
1.575 raeburn 1433: $clipboardcount ++;
1.538 raeburn 1434: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1435: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1436: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1437: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1438: $is_external = 1;
1.626 raeburn 1439: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1440: $is_exttool = 1;
1.538 raeburn 1441: }
1442: if ($folder =~ /^supplemental/) {
1443: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1444: unless ($canpaste) {
1445: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1446: }
1447: } else {
1448: $canpaste = 1;
1449: }
1450: if ($canpaste) {
1451: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1452: my $srcdom = $1;
1453: my $srcnum = $2;
1454: my $rem = $3;
1455: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1456: $othercourse = 1;
1457: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1458: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1459: } else {
1460: $canpaste = 0;
1461: $nopaste = &mt('Paste from another course unavailable.');
1462: }
1463: }
1464: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1465: my $prefix = $1;
1466: $parent = $2;
1467: if ($folder !~ /^\Q$prefix\E/) {
1468: $areachange = 1;
1469: }
1470: $is_uploaded_map = 1;
1.492 raeburn 1471: }
1.597 raeburn 1472: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1473: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1474: if ($cid ne $env{'request.course.id'}) {
1475: my ($srcdom,$srcnum) = split(/_/,$cid);
1476: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1477: if (($is_exttool) && ($srcdom ne $coursedom)) {
1478: $canpaste = 0;
1479: $nopaste = &mt('Paste from another domain unavailable.');
1480: } else {
1481: $othercrs = '<br />'.&mt('(from another course)');
1482: }
1.596 raeburn 1483: } else {
1484: $canpaste = 0;
1485: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1486: }
1.596 raeburn 1487: }
1.492 raeburn 1488: }
1.596 raeburn 1489: if ($canpaste) {
1490: push(@pasteable,$suffix);
1.629 raeburn 1491: }
1.538 raeburn 1492: }
1493: my $buffer;
1.627 raeburn 1494: if ($is_external) {
1.538 raeburn 1495: $buffer = &mt('External Resource').': '.
1496: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1497: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1498: } elsif ($is_exttool) {
1499: $buffer = &mt('External Tool').': '.
1500: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1501: } else {
1502: my $icon = &Apache::loncommon::icon($extension);
1503: if ($extension eq 'sequence' &&
1504: $url =~ m{/default_\d+\.sequence$}x) {
1505: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1506: $icon .= '/navmap.folder.closed.gif';
1507: }
1.589 raeburn 1508: my $title = $env{'docs.markedcopy_title_'.$suffix};
1509: if ($title eq '') {
1510: ($title) = ($url =~ m{/([^/]+)$});
1511: }
1.538 raeburn 1512: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1513: ': '.
1514: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1515: &LONCAPA::map::qtescape($title));
1.538 raeburn 1516: }
1517: $pasteitems .= '<div class="LC_left_float">';
1518: my ($options,$onclick);
1519: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1520: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1521: if (($is_uploaded_map) ||
1522: ($url =~ /(bulletinboard|smppg)$/) ||
1523: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1524: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1525: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1526: }
1527: }
1528: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1529: if ($nopaste) {
1.681 raeburn 1530: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 1531: } else {
1532: if ($othercrs) {
1533: $pasteitems .= $othercrs;
1534: }
1535: if ($options) {
1536: $pasteitems .= $options;
1.492 raeburn 1537: }
1538: }
1.538 raeburn 1539: $pasteitems .= '</div>';
1540: }
1541: }
1542: if ($pasteitems eq '') {
1543: &Apache::lonnet::delenv('docs.markedcopies');
1544: }
1545: my ($pasteform,$form_start,$buttons,$form_end);
1546: if ($pasteitems) {
1547: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1548: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1549: if (@pasteable) {
1.575 raeburn 1550: my $value = &mt('Paste to current folder');
1551: if ($container eq 'page') {
1552: $value = &mt('Paste to current page');
1553: }
1554: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1555: }
1556: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1557: if ($clipboardcount > 1) {
1558: $buttons .=
1559: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1560: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1561: (' 'x2).
1562: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1563: (' 'x2);
1.492 raeburn 1564: }
1.575 raeburn 1565: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1566: '</form>';
1.538 raeburn 1567: } else {
1568: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1569: }
1.538 raeburn 1570: $r->print($form_start
1571: .'<fieldset>'
1572: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1573: .$pasteitems
1574: .'</fieldset>'
1575: .$form_end);
1576: }
1577:
1578: sub paste_options {
1579: my ($suffix,$is_uploaded_map,$parent) = @_;
1580: my ($copytext,$movetext);
1581: if ($is_uploaded_map) {
1582: $copytext = &mt('Copy to new folder');
1583: $movetext = &mt('Move old');
1584: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1585: $copytext = &mt('Copy to new board');
1586: $movetext = &mt('Move (not posts)');
1587: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1588: $copytext = &mt('Copy to new page');
1589: $movetext = &mt('Move');
1.533 raeburn 1590: } else {
1.538 raeburn 1591: $copytext = &mt('Copy to new file');
1592: $movetext = &mt('Move');
1593: }
1594: my $output = '<br />'.
1595: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1596: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1597: '<label>'.
1598: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1599: $copytext.'</label></span>'.(' 'x2).' '.
1600: '<span class="LC_nobreak"><label>'.
1601: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1602: $movetext.'</label></span>';
1603: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1604: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1605: '</legend><table border="0">';
1606: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1607: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1608: my $lastdir = $parent;
1609: my %depths = (
1610: $lastdir => 0,
1611: );
1612: my (%display,%deps);
1613: for (my $i=0; $i<@pastemaps; $i++) {
1614: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1615: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1616: my @subfolders = split(/,/,$subfolderstr);
1617: $deps{$lastdir} = \@subfolders;
1618: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1619: my $depth = $depths{$lastdir} + 1;
1620: my $offset = int($depth * 4);
1621: my $indent = (' ' x $offset);
1622: for (my $j=0; $j<@subfolders; $j++) {
1623: $depths{$subfolders[$j]} = $depth;
1624: $display{$subfolders[$j]} =
1625: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1626: '<td><label>'.
1627: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1628: '<label>'.
1629: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1630: &mt('Move old').'</label>'.
1631: '</td></tr>';
1632: }
1.492 raeburn 1633: }
1.538 raeburn 1634: &recurse_print(\$output,$parent,\%deps,\%display);
1635: $output .= '</table></fieldset>';
1.329 droeschl 1636: }
1.538 raeburn 1637: $output .= '</div>';
1638: return $output;
1.488 raeburn 1639: }
1640:
1.492 raeburn 1641: sub recurse_print {
1.538 raeburn 1642: my ($outputref,$dir,$deps,$display) = @_;
1643: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1644: if (ref($deps->{$dir}) eq 'ARRAY') {
1645: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1646: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1647: }
1648: }
1649: }
1650:
1.488 raeburn 1651: sub supp_pasteable {
1652: my ($url) = @_;
1653: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1654: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1655: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1656: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1657: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1658: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1659: return 1;
1660: }
1661: return;
1.329 droeschl 1662: }
1663:
1.492 raeburn 1664: sub paste_popup_js {
1.594 damieng 1665: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1666: show => 'Show Options',
1667: hide => 'Hide Options',
1.594 damieng 1668: );
1669: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1670: none => 'No items selected from clipboard.',
1.492 raeburn 1671: );
1.594 damieng 1672: &html_escape(\%html_js_lt);
1673: &js_escape(\%html_js_lt);
1674: &js_escape(\%js_lt);
1.492 raeburn 1675: return <<"END";
1676:
1.538 raeburn 1677: function showPasteOptions(suffix) {
1678: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1679: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1680: return;
1681: }
1682:
1.538 raeburn 1683: function hidePasteOptions(suffix) {
1684: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1685: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1686: return;
1687: }
1688:
1689: function showOptions(caller,suffix) {
1690: if (document.getElementById('pasteoptionstext_'+suffix)) {
1691: if (caller.checked) {
1.594 damieng 1692: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1693: } else {
1694: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1695: }
1696: if (document.getElementById('pasteoptions_'+suffix)) {
1697: document.getElementById('pasteoptions_'+suffix).style.display='none';
1698: }
1699: }
1.492 raeburn 1700: return;
1701: }
1702:
1.541 raeburn 1703: function validateClipboard() {
1704: var numchk = 0;
1705: if (document.pasteform.pasting.length > 1) {
1706: for (var i=0; i<document.pasteform.pasting.length; i++) {
1707: if (document.pasteform.pasting[i].checked) {
1708: numchk ++;
1709: }
1710: }
1711: } else {
1712: if (document.pasteform.pasting.type == 'checkbox') {
1713: if (document.pasteform.pasting.checked) {
1714: numchk ++;
1715: }
1716: }
1717: }
1718: if (numchk > 0) {
1719: return true;
1720: } else {
1.594 damieng 1721: alert("$js_lt{'none'}");
1.541 raeburn 1722: return false;
1723: }
1724: }
1725:
1.575 raeburn 1726: function checkClipboard() {
1727: if (document.pasteform.pasting.length > 1) {
1728: for (var i=0; i<document.pasteform.pasting.length; i++) {
1729: document.pasteform.pasting[i].checked = true;
1730: }
1731: }
1732: return;
1733: }
1734:
1735: function uncheckClipboard() {
1736: if (document.pasteform.pasting.length >1) {
1737: for (var i=0; i<document.pasteform.pasting.length; i++) {
1738: document.pasteform.pasting[i].checked = false;
1739: }
1740: }
1741: return;
1742: }
1743:
1.492 raeburn 1744: END
1745:
1746: }
1747:
1.329 droeschl 1748: sub do_paste_from_buffer {
1.492 raeburn 1749: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1750:
1.538 raeburn 1751: # Array of items in paste buffer
1752: my (@currpaste,%pastebuffer,%allerrors);
1753: @currpaste = split(/,/,$env{'docs.markedcopies'});
1754:
1.492 raeburn 1755: # Early out if paste buffer is empty
1.538 raeburn 1756: if (@currpaste == 0) {
1.492 raeburn 1757: return ();
1.538 raeburn 1758: }
1759: map { $pastebuffer{$_} = 1; } @currpaste;
1760:
1761: # Array of items selected items to paste
1762: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1763:
1764: # Early out if nothing selected to paste
1765: if (@reqpaste == 0) {
1766: return();
1767: }
1768: my @topaste;
1769: foreach my $suffix (@reqpaste) {
1770: next if ($suffix =~ /\D/);
1771: next unless (exists($pastebuffer{$suffix}));
1772: push(@topaste,$suffix);
1773: }
1774:
1775: # Early out if nothing available to paste
1776: if (@topaste == 0) {
1777: return();
1.329 droeschl 1778: }
1779:
1.627 raeburn 1780: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1781: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1782:
1783: foreach my $suffix (@topaste) {
1784: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1785: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1786: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1787: # Supplemental content may only include certain types of content
1788: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1789: if ($folder =~ /^supplemental/) {
1790: unless (&supp_pasteable($url)) {
1791: $notinsupp{$suffix} = 1;
1792: next;
1793: }
1.492 raeburn 1794: }
1.538 raeburn 1795: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1796: my $srcd = $1;
1797: my $srcn = $2;
1.492 raeburn 1798: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1799: # check for mdc privilege in the course from which the resource was pasted
1800: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1801: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1802: $notincrs{$suffix} = 1;
1803: next;
1804: }
1.491 raeburn 1805: }
1.538 raeburn 1806: $srcdom{$suffix} = $srcd;
1807: $srcnum{$suffix} = $srcn;
1.597 raeburn 1808: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1809: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1810: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1811: my ($srcd,$srcn) = split(/_/,$cid);
1812: # When paste buffer was populated using an active role in a different course
1813: # check for mdc privilege in the course from which the resource was pasted
1814: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1815: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1816: $notincrs{$suffix} = 1;
1817: next;
1818: }
1819: }
1.632 raeburn 1820: # When buffer was populated using an active role in a different course
1821: # disallow pasting of External Tool if course is in a different domain.
1822: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1823: $notindom{$suffix} = 1;
1824: next;
1825: }
1.596 raeburn 1826: $srcdom{$suffix} = $srcd;
1827: $srcnum{$suffix} = $srcn;
1.491 raeburn 1828: }
1.597 raeburn 1829: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1830: push(@dopaste,$suffix);
1831: if ($url=~/\.(page|sequence)$/) {
1832: $is_map{$suffix} = 1;
1833: }
1834: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1835: my $oldprefix = $1;
1.492 raeburn 1836: # When pasting content from Main Content to Supplemental Content and vice versa
1837: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1838: # a folder/page or a document).
1.538 raeburn 1839: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1840: $prefixchg{$suffix} = 'docstosupp';
1841: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1842: $prefixchg{$suffix} = 'supptodocs';
1843: }
1.491 raeburn 1844:
1.492 raeburn 1845: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1846: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1847: my @nested;
1848: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1849: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1850: my @deps = map { /\d+:([\d,]+$)/ } @items;
1851: foreach my $dep (@deps) {
1852: if ($dep =~ /,/) {
1853: push(@nested,split(/,/,$dep));
1854: } else {
1855: push(@nested,$dep);
1856: }
1.492 raeburn 1857: }
1.538 raeburn 1858: foreach my $item (@nested) {
1859: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1860: push(@{$marktomove{$suffix}},$type.'_'.$item);
1861: }
1.492 raeburn 1862: }
1863: }
1.488 raeburn 1864: }
1865: }
1866:
1.538 raeburn 1867: # Early out if nothing available to paste
1868: if (@dopaste == 0) {
1869: return ();
1870: }
1871:
1872: # Populate message hash and hashes used for main content <=> supplemental content
1873: # changes
1874:
1875: %msgs = &Apache::lonlocal::texthash (
1876: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1877: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 1878: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.538 raeburn 1879: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1880: );
1881:
1882: %before = (
1883: docstosupp => {
1884: map => 'default',
1885: doc => 'docs',
1886: },
1887: supptodocs => {
1888: map => 'supplemental',
1889: doc => 'supplemental',
1890: },
1891: );
1892:
1893: %after = (
1894: docstosupp => {
1895: map => 'supplemental',
1896: doc => 'supplemental'
1897: },
1898: supptodocs => {
1899: map => 'default',
1900: doc => 'docs',
1901: },
1902: );
1903:
1904: # Retrieve information about all course maps in main content area
1905:
1906: my $allmaps = {};
1.660 raeburn 1907: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.538 raeburn 1908:
1909: # Loop over the items to paste
1910: foreach my $suffix (@dopaste) {
1.329 droeschl 1911: # Maps need to be copied first
1.538 raeburn 1912: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1913: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1914: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1915: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1916: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1917: }
1918: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1919: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1920: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1921: my $oldurl = $url;
1922: if ($is_map{$suffix}) {
1.491 raeburn 1923: # If pasting a map, check if map contains other maps
1.538 raeburn 1924: my (%hierarchy,%titles);
1.660 raeburn 1925: if (($folder =~ /^default/) && (!$donechk)) {
1926: $allmaps =
1927: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1928: $env{"course.$env{'request.course.id'}.home"},
1929: $env{'request.course.id'});
1930: $donechk = 1;
1931: }
1.627 raeburn 1932: &contained_map_check($url,$folder,$coursenum,$coursedom,
1933: \%removefrommap,\%removeparam,\%addedmaps,
1934: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1935: if ($url=~ m{^/uploaded/}) {
1936: my $newurl;
1937: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1938: ($newurl,my $error) =
1939: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1940: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1941: \$title,$allmaps,\%newurls);
1942: if ($error) {
1943: $allerrors{$suffix} = $error;
1944: next;
1945: }
1946: if ($newurl ne '') {
1947: if ($newurl ne $url) {
1948: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1949: $newsubdir{$url} = $1;
1950: }
1951: $mapchanges{$url} = 1;
1.492 raeburn 1952: }
1.538 raeburn 1953: }
1954: }
1955: if (($srcdom{$suffix} ne $coursedom) ||
1956: ($srcnum{$suffix} ne $coursenum) ||
1957: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1958: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1959: $coursedom,$coursenum,$srcdom{$suffix},
1960: $srcnum{$suffix},$allmaps,\%rewrites,
1961: \%retitles,\%copies,\%dbcopies,
1962: \%zombies,\%params,\%mapmoves,
1963: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1964: \%newurls,\%resdatacopy)) {
1.538 raeburn 1965: $mapmoves{$url} = 1;
1966: }
1967: $url = $newurl;
1968: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1969: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1970: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1971: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1972: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1973: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1974: }
1975: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1976: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1977: push(@toclear,$suffix);
1978: # if pasting published map (main content area only) check map not already in course
1979: if ($folder =~ /^default/) {
1980: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1981: $duplicate{$suffix} = 1;
1982: next;
1.492 raeburn 1983: }
1.491 raeburn 1984: }
1985: }
1.538 raeburn 1986: }
1.627 raeburn 1987: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1988: my $prefix = $1;
1.648 raeburn 1989: my $fromothercrs;
1.538 raeburn 1990: #need to copy the db contents to a new one, unless this is a move.
1991: my %info = (
1992: src => $url,
1993: cdom => $coursedom,
1994: cnum => $coursenum,
1.596 raeburn 1995: );
1.649 raeburn 1996: if ($prefix eq 'ext.tool') {
1.655 raeburn 1997: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 1998: $info{'delgradable'} = 1;
1999: }
2000: }
1.596 raeburn 2001: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
2002: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
2003: $fromothercrs = 1;
2004: $info{'cdom'} = $srcdom{$suffix};
2005: $info{'cnum'} = $srcnum{$suffix};
2006: }
2007: }
2008: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 2009: my (%lockerr,$msg);
1.538 raeburn 2010: my ($newurl,$result,$errtext) =
2011: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
2012: if ($result eq 'ok') {
2013: $url = $newurl;
2014: $title=&mt('Copy of').' '.$title;
2015: } else {
2016: if ($prefix eq 'smppg') {
2017: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2018: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 2019: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 2020: } elsif ($prefix eq 'ext.tool') {
2021: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 2022: }
2023: $results{$suffix} = $result;
2024: $msgerrs{$suffix} = $msg;
2025: $lockerrs{$suffix} = $lockerr{$prefix};
2026: next;
2027: }
2028: if ($lockerr{$prefix}) {
2029: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 2030: }
1.489 raeburn 2031: }
2032: }
1.538 raeburn 2033: $title = &LONCAPA::map::qtunescape($title);
2034: my $ext='false';
2035: if ($url=~m{^http(|s)://}) { $ext='true'; }
2036: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2037: if ($folder !~ /^supplemental/) {
2038: (undef,undef,$title) =
2039: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2040: }
2041: } else {
2042: if ($folder=~/^supplemental/) {
2043: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2044: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2045: }
1.533 raeburn 2046: }
1.491 raeburn 2047:
2048: # For uploaded files (excluding pages/sequences) path in copied file is changed
2049: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2050: # courses.
2051:
1.538 raeburn 2052: unless ($is_map{$suffix}) {
2053: my $newidx;
1.492 raeburn 2054: # Now insert the URL at the bottom
1.538 raeburn 2055: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2056: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2057: my $relpath = $1;
2058: if ($relpath ne '') {
2059: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2060: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2061: my $newprefix = $newloc;
2062: if ($newloc eq 'default') {
2063: $newprefix = 'docs';
2064: }
2065: if ($newdocsdir eq '') {
2066: $newdocsdir = 'default';
2067: }
1.630 raeburn 2068: if (($prefixchg{$suffix}) ||
2069: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2070: ($srcnum{$suffix} ne $coursenum) ||
2071: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2072: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2073: $url =
2074: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2075: &Apache::lonnet::getfile($oldurl));
2076: if ($url eq '/adm/notfound.html') {
2077: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2078: next;
2079: } else {
2080: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2081: $newsubpath =~ s{/+$}{/};
2082: $docmoves{$oldurl} = $newsubpath;
2083: }
1.491 raeburn 2084: }
2085: }
1.597 raeburn 2086: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2087: my $template = $1;
2088: if ($newidx) {
2089: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2090: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2091: }
1.649 raeburn 2092: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2093: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2094: my $marker = (split(m{/},$url))[4];
2095: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2096: my $val = 'no';
2097: if ($toolsettings{'gradable'}) {
2098: $val = 'yes';
2099: }
2100: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2101: 'string_yesno');
2102: &remember_parms($newidx,'gradable','set',$val);
2103: }
1.491 raeburn 2104: }
1.538 raeburn 2105: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2106: ':'.$ext.':normal:res';
2107: push(@LONCAPA::map::order,$newidx);
2108: # Store the result
2109: my ($errtext,$fatal) =
2110: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2111: if ($fatal) {
2112: $save_err .= $errtext;
2113: $allresult = 'fail';
2114: }
1.488 raeburn 2115: }
1.538 raeburn 2116:
1.597 raeburn 2117: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2118: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2119: unless ($allresult eq 'fail') {
2120: my %updated = (
2121: rewrites => \%rewrites,
2122: zombies => \%zombies,
2123: removefrommap => \%removefrommap,
2124: removeparam => \%removeparam,
2125: dbcopies => \%dbcopies,
1.597 raeburn 2126: resdatacopy => \%resdatacopy,
1.538 raeburn 2127: retitles => \%retitles,
2128: );
2129: my %info = (
2130: newsubdir => \%newsubdir,
2131: params => \%params,
2132: );
2133: if ($prefixchg{$suffix}) {
2134: $info{'before'} = $before{$prefixchg{$suffix}};
2135: $info{'after'} = $after{$prefixchg{$suffix}};
2136: }
2137: my %moves = (
2138: copies => \%copies,
2139: docmoves => \%docmoves,
2140: mapmoves => \%mapmoves,
2141: );
2142: (my $result,$msgs{$suffix},my $lockerror) =
2143: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2144: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2145: $url,'paste');
2146: $lockerrors .= $lockerror;
2147: if ($result eq 'ok') {
2148: if ($is_map{$suffix}) {
2149: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2150: $folder.'.'.$container);
2151: if ($fatal) {
2152: $allresult = 'failread';
2153: } else {
2154: if ($#LONCAPA::map::order<1) {
2155: my $idx=&LONCAPA::map::getresidx();
2156: if ($idx<=0) { $idx=1; }
2157: $LONCAPA::map::order[0]=$idx;
2158: $LONCAPA::map::resources[$idx]='';
2159: }
2160: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2161: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2162: ':'.$ext.':normal:res';
2163: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2164:
2165: # Store the result
1.538 raeburn 2166: my ($errtext,$fatal) =
2167: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2168: if ($fatal) {
2169: $save_err .= $errtext;
2170: $allresult = 'failstore';
2171: }
2172: }
2173: }
2174: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2175: push(@toclear,$suffix);
2176: }
2177: }
1.492 raeburn 2178: }
2179: }
1.538 raeburn 2180: &clear_from_buffer(\@toclear,\@currpaste);
2181: my $msgsarray;
2182: foreach my $suffix (keys(%msgs)) {
2183: if (ref($msgs{$suffix}) eq 'ARRAY') {
2184: $msgsarray .= join(',',@{$msgs{$suffix}});
2185: }
2186: }
2187: return ($allresult,$save_err,$msgsarray,$lockerrors);
2188: }
1.533 raeburn 2189:
1.538 raeburn 2190: sub do_buffer_empty {
2191: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2192: if (@currpaste == 0) {
2193: return &mt('Clipboard is already empty');
2194: }
2195: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2196: if (@toclear == 0) {
2197: return &mt('Nothing selected to clear from clipboard');
2198: }
2199: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2200: if ($numdel) {
2201: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2202: } else {
2203: return &mt('Clipboard unchanged');
1.492 raeburn 2204: }
1.538 raeburn 2205: return;
2206: }
2207:
2208: sub clear_from_buffer {
2209: my ($toclear,$currpaste) = @_;
2210: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2211: my %pastebuffer;
2212: map { $pastebuffer{$_} = 1; } @{$currpaste};
2213: my $numdel = 0;
2214: foreach my $suffix (@{$toclear}) {
2215: next if ($suffix =~ /\D/);
2216: next unless (exists($pastebuffer{$suffix}));
2217: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2218: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2219: delete($pastebuffer{$suffix});
2220: $numdel ++;
2221: }
2222: }
2223: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2224: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2225: return $numdel;
1.492 raeburn 2226: }
2227:
2228: sub get_newmap_url {
2229: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2230: $titleref,$allmaps,$newurls) = @_;
2231: my $newurl;
2232: if ($url=~ m{^/uploaded/}) {
2233: $$titleref=&mt('Copy of').' '.$$titleref;
2234: }
2235: my $now = time;
2236: my $suffix=$$.int(rand(100)).$now;
2237: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2238: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2239: my $path = $1;
2240: my $prefix = $2;
2241: my $ancestor = $3;
2242: if (length($ancestor) > 10) {
2243: $ancestor = substr($ancestor,-10,10);
2244: }
2245: my $newid;
2246: if ($prefixchg) {
2247: if ($folder =~ /^supplemental/) {
2248: $prefix =~ s/^default/supplemental/;
2249: } else {
2250: $prefix =~ s/^supplemental/default/;
2251: }
2252: }
2253: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2254: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2255: } else {
2256: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2257: }
2258: my $counter = 0;
2259: my $is_unique = &uniqueness_check($newurl);
2260: if ($folder =~ /^default/) {
2261: if ($allmaps->{$newurl}) {
2262: $is_unique = 0;
2263: }
2264: }
2265: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2266: $counter ++;
2267: $suffix ++;
2268: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2269: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2270: } else {
2271: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2272: }
2273: $is_unique = &uniqueness_check($newurl);
2274: }
2275: if ($is_unique) {
2276: $newurls->{$newurl} = 1;
2277: } else {
2278: if ($url=~/\.page$/) {
2279: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2280: } else {
2281: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2282: }
2283: }
1.329 droeschl 2284: }
1.492 raeburn 2285: return ($newurl);
1.329 droeschl 2286: }
2287:
1.488 raeburn 2288: sub dbcopy {
1.533 raeburn 2289: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2290: my ($url,$result,$errtext);
2291: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2292: $url = $dbref->{'src'};
1.627 raeburn 2293: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2294: my $prefix = $1;
1.627 raeburn 2295: if ($prefix eq 'ext.tool') {
2296: $prefix = 'exttool';
2297: }
1.533 raeburn 2298: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2299: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2300: my $db_name;
2301: my $marker = (split(m{/},$url))[4];
2302: $marker=~s/\D//g;
2303: if ($dbref->{'src'} =~ m{/smppg$}) {
2304: $db_name =
2305: &Apache::lonsimplepage::get_db_name($url,$marker,
2306: $dbref->{'cdom'},
2307: $dbref->{'cnum'});
1.627 raeburn 2308: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2309: $db_name = 'exttool_'.$marker;
1.533 raeburn 2310: } else {
2311: $db_name = 'bulletinpage_'.$marker;
2312: }
2313: my ($suffix,$freedlock,$error) =
2314: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2315: $coursedom,$coursenum,
2316: 'concat');
2317: if (!$suffix) {
2318: if ($prefix eq 'smppg') {
2319: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2320: } elsif ($prefix eq 'exttool') {
2321: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2322: } else {
1.565 bisitz 2323: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2324: }
2325: if ($error) {
2326: $errtext .= '<br />'.$error;
2327: }
2328: } else {
2329: #need to copy the db contents to a new one.
2330: my %contents=&Apache::lonnet::dump($db_name,
2331: $dbref->{'cdom'},
2332: $dbref->{'cnum'});
2333: if (exists($contents{'uploaded.photourl'})) {
2334: my $photo = $contents{'uploaded.photourl'};
2335: my ($subdir,$fname) =
2336: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2337: my $newphoto;
1.533 raeburn 2338: if ($fname ne '') {
2339: my $content = &Apache::lonnet::getfile($photo);
2340: unless ($content eq '-1') {
2341: $env{'form.'.$suffix.'.photourl'} = $content;
2342: $newphoto =
2343: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2344: delete($env{'form.'.$suffix.'.photourl'});
2345: }
2346: }
2347: if ($newphoto =~ m{^/uploaded/}) {
2348: $contents{'uploaded.photourl'} = $newphoto;
2349: }
2350: }
2351: $db_name =~ s{_\d*$ }{_$suffix}x;
1.649 raeburn 2352: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2353: delete($contents{'gradable'});
2354: }
1.533 raeburn 2355: $result=&Apache::lonnet::put($db_name,\%contents,
2356: $coursedom,$coursenum);
2357: if ($result eq 'ok') {
1.627 raeburn 2358: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2359: }
2360: }
2361: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2362: $lockerrorsref->{$prefix} =
1.533 raeburn 2363: '<div class="LC_error">'.
2364: &mt('There was a problem removing a lockfile.');
2365: if ($prefix eq 'smppg') {
1.560 raeburn 2366: $lockerrorsref->{$prefix} .=
1.559 raeburn 2367: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2368: } elsif ($prefix eq 'exttool') {
2369: $lockerrorsref->{$prefix} .=
2370: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2371: } else {
1.565 bisitz 2372: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2373: }
1.560 raeburn 2374: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2375: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2376: '</div>';
1.533 raeburn 2377: }
2378: }
2379: } elsif ($url =~ m{/syllabus$}) {
2380: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2381: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2382: if (($dbref->{'cdom'} ne $coursedom) ||
2383: ($dbref->{'cnum'} ne $coursenum)) {
2384: my %contents=&Apache::lonnet::dump('syllabus',
2385: $dbref->{'cdom'},
2386: $dbref->{'cnum'});
2387: $result=&Apache::lonnet::put('syllabus',\%contents,
2388: $coursedom,$coursenum);
2389: }
2390: }
1.488 raeburn 2391: }
2392: }
1.533 raeburn 2393: return ($url,$result,$errtext);
1.488 raeburn 2394: }
2395:
1.597 raeburn 2396: sub copy_templated_files {
2397: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2398: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2399: my $srccontainer = 'sequence';
2400: if ($srcwaspage) {
2401: $srccontainer = 'page';
2402: }
2403: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2404: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2405: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2406: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2407: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2408: $template.'.problem';
2409: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2410: if ($template eq 'simpleproblem') {
2411: $srcprefix .= '.0.';
2412: my $weightprefix = $newprefix;
2413: $newprefix .= '.0.';
2414: my @simpleprobqtypes = qw(radio option string essay numerical);
2415: my $qtype=$srcparms{$srcprefix.'questiontype'};
2416: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 2417: my %newdata = (
2418: $newprefix.'questiontype' => $qtype,
2419: );
1.597 raeburn 2420: foreach my $type (@simpleprobqtypes) {
2421: if ($type eq $qtype) {
2422: $newdata{"$weightprefix.$type.weight"}=1;
2423: } else {
2424: $newdata{"$weightprefix.$type.weight"}=0;
2425: }
2426: }
2427: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2428: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2429: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2430: if ($qtype eq 'numerical') {
2431: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2432: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2433: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2434: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2435: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2436: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2437: unless (defined($maxfoils)) { $maxfoils=10; }
2438: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2439: if ($maxfoils<=0) { $maxfoils=10; }
2440: my $randomize=$srcparms{$srcprefix.'randomize'};
2441: unless (defined($randomize)) { $randomize='yes'; }
2442: unless ($randomize eq 'no') { $randomize='yes'; }
2443: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2444: $newdata{$newprefix.'randomize'} = $randomize;
2445: if ($qtype eq 'option') {
2446: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2447: }
2448: for (my $i=1; $i<=10; $i++) {
2449: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2450: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2451: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2452: }
2453:
2454: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2455: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2456: unless (defined($maxfoils)) { $maxfoils=10; }
2457: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2458: if ($maxfoils<=0) { $maxfoils=10; }
2459: my $randomize=$srcparms{$srcprefix.'randomize'};
2460: unless (defined($randomize)) { $randomize='yes'; }
2461: unless ($randomize eq 'no') { $randomize='yes'; }
2462: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2463: $newdata{$newprefix.'randomize'} = $randomize;
2464: if ($qtype eq 'option') {
2465: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2466: }
2467: for (my $i=1; $i<=10; $i++) {
2468: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2469: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2470: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2471: }
2472: } elsif ($qtype eq 'string') {
2473: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2474: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2475: }
2476: if (keys(%newdata)) {
2477: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2478: $coursenum);
2479: if ($putres eq 'ok') {
2480: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2481: }
2482: }
2483: }
2484: }
2485: }
2486:
1.329 droeschl 2487: sub uniqueness_check {
2488: my ($newurl) = @_;
2489: my $unique = 1;
2490: foreach my $res (@LONCAPA::map::order) {
2491: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2492: $url=&LONCAPA::map::qtescape($url);
2493: if ($newurl eq $url) {
2494: $unique = 0;
1.344 bisitz 2495: last;
1.329 droeschl 2496: }
2497: }
2498: return $unique;
2499: }
2500:
1.488 raeburn 2501: sub contained_map_check {
1.627 raeburn 2502: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2503: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2504: my $content = &Apache::lonnet::getfile($url);
2505: unless ($content eq '-1') {
2506: my $parser = HTML::TokeParser->new(\$content);
2507: $parser->attr_encoded(1);
2508: while (my $token = $parser->get_token) {
2509: next if ($token->[0] ne 'S');
2510: if ($token->[1] eq 'resource') {
2511: next if ($token->[2]->{'type'} eq 'zombie');
2512: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2513: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2514: my $srcdom = $1;
2515: unless ($srcdom eq $coursedom) {
2516: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2517: next;
2518: }
2519: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2520: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2521: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2522: next;
2523: }
2524: }
1.492 raeburn 2525: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2526: if ($1 eq 'uploaded') {
2527: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2528: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2529: } else {
1.492 raeburn 2530: if ($allmaps->{$ressrc}) {
1.529 raeburn 2531: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2532: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2533: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2534: } else {
2535: $addedmaps->{$ressrc} = [$url];
2536: }
1.488 raeburn 2537: }
1.627 raeburn 2538: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2539: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2540: }
1.492 raeburn 2541: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2542: if ($folder =~ /^supplemental/) {
1.492 raeburn 2543: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2544: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2545: } else {
2546: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2547: }
1.488 raeburn 2548: }
2549: }
2550: }
2551: }
2552: return;
2553: }
2554:
2555: sub url_paste_fixups {
1.533 raeburn 2556: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2557: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2558: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2559: my $checktitle;
2560: if (($prefixchg) &&
1.492 raeburn 2561: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2562: $checktitle = 1;
2563: }
1.492 raeburn 2564: my $skip;
2565: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2566: my $mapid = $1.$2;
2567: if ($tomove->{$mapid}) {
2568: $skip = 1;
2569: }
2570: }
1.491 raeburn 2571: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2572: return if ($file eq '-1');
2573: my $parser = HTML::TokeParser->new(\$file);
2574: $parser->attr_encoded(1);
1.491 raeburn 2575: my $changed = 0;
1.488 raeburn 2576: while (my $token = $parser->get_token) {
2577: next if ($token->[0] ne 'S');
2578: if ($token->[1] eq 'resource') {
2579: my $ressrc = $token->[2]->{'src'};
2580: next if ($ressrc eq '');
1.491 raeburn 2581: my $id = $token->[2]->{'id'};
1.492 raeburn 2582: my $title = $token->[2]->{'title'};
1.491 raeburn 2583: if ($checktitle) {
2584: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2585: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2586: }
2587: }
1.488 raeburn 2588: next if ($token->[2]->{'type'} eq 'external');
2589: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2590: next if ($skip);
1.532 raeburn 2591: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2592: $changed = 1;
2593: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2594: my $srcdom = $1;
2595: my $srcnum = $2;
1.488 raeburn 2596: my $rem = $3;
1.492 raeburn 2597: my $newurl;
2598: my $mapname;
2599: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2600: my $prefix = $1;
2601: $mapname = $prefix.$2;
2602: if ($tomove->{$mapname}) {
1.533 raeburn 2603: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2604: $srcdom,$srcnum,$allmaps,$rewrites,
2605: $retitles,$copies,$dbcopies,$zombies,
2606: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2607: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2608: next;
2609: } else {
2610: ($newurl,my $error) =
2611: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2612: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2613: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2614: $newsubdir->{$ressrc} = $1;
2615: }
2616: if ($error) {
2617: next;
2618: }
2619: }
2620: }
2621: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2622: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2623:
1.488 raeburn 2624: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2625: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2626: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2627: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2628: $cnum,$srcdom,$srcnum,$allmaps,
2629: $rewrites,$retitles,$copies,$dbcopies,
2630: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2631: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2632: $mapmoves->{$ressrc} = 1;
2633: }
2634: $changed = 1;
1.488 raeburn 2635: } else {
1.532 raeburn 2636: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2637: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2638: $changed = 1;
1.488 raeburn 2639: }
2640: }
1.649 raeburn 2641: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 2642: next if ($skip);
1.492 raeburn 2643: my $srcdom = $1;
2644: my $srcnum = $2;
1.649 raeburn 2645: my $rem = $3;
2646: my ($is_exttool,$exttoolchg);
2647: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 2648: $is_exttool = 1;
1.649 raeburn 2649: }
1.492 raeburn 2650: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2651: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2652: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2653: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2654: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2655: $changed = 1;
1.649 raeburn 2656: if ($is_exttool) {
2657: $exttoolchg = 1;
2658: }
1.700 raeburn 2659: } elsif (($is_exttool) &&
1.649 raeburn 2660: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2661: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2662: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2663: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2664: $changed = 1;
2665: $exttoolchg = 1;
2666: }
2667: if (($is_exttool) && ($prefixchg)) {
2668: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2669: if ($exttoolchg) {
2670: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2671: }
2672: }
1.533 raeburn 2673: }
2674: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2675: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2676: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2677: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2678: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2679: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2680: $changed = 1;
1.488 raeburn 2681: }
1.597 raeburn 2682: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2683: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2684: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2685: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2686: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2687: }
1.488 raeburn 2688: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2689: next if ($skip);
2690: my $srcdom = $1;
2691: my $srcnum = $2;
2692: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2693: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2694: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2695: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2696: $changed = 1;
1.488 raeburn 2697: }
2698: }
2699: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2700: next if ($skip);
1.488 raeburn 2701: my $to = $token->[2]->{'to'};
2702: if ($to ne '') {
2703: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2704: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2705: } else {
2706: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2707: }
2708: }
2709: }
2710: }
1.491 raeburn 2711: return $changed;
1.488 raeburn 2712: }
2713:
2714: sub apply_fixups {
1.529 raeburn 2715: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2716: $oldurl,$url,$caller) = @_;
2717: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2718: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2719: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2720: if (ref($updated) eq 'HASH') {
2721: if (ref($updated->{'rewrites'}) eq 'HASH') {
2722: %rewrites = %{$updated->{'rewrites'}};
2723: }
2724: if (ref($updated->{'zombies'}) eq 'HASH') {
2725: %zombies = %{$updated->{'zombies'}};
2726: }
2727: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2728: %removefrommap = %{$updated->{'removefrommap'}};
2729: }
2730: if (ref($updated->{'removeparam'}) eq 'HASH') {
2731: %removeparam = %{$updated->{'removeparam'}};
2732: }
2733: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2734: %dbcopies = %{$updated->{'dbcopies'}};
2735: }
2736: if (ref($updated->{'retitles'}) eq 'HASH') {
2737: %retitles = %{$updated->{'retitles'}};
2738: }
1.597 raeburn 2739: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2740: %resdatacopy = %{$updated->{'resdatacopy'}};
2741: }
1.529 raeburn 2742: }
2743: if (ref($info) eq 'HASH') {
2744: if (ref($info->{'newsubdir'}) eq 'HASH') {
2745: %newsubdir = %{$info->{'newsubdir'}};
2746: }
2747: if (ref($info->{'params'}) eq 'HASH') {
2748: %params = %{$info->{'params'}};
2749: }
2750: if (ref($info->{'before'}) eq 'HASH') {
2751: %before = %{$info->{'before'}};
2752: }
2753: if (ref($info->{'after'}) eq 'HASH') {
2754: %after = %{$info->{'after'}};
2755: }
2756: }
2757: if (ref($moves) eq 'HASH') {
2758: if (ref($moves->{'copies'}) eq 'HASH') {
2759: %copies = %{$moves->{'copies'}};
2760: }
2761: if (ref($moves->{'docmoves'}) eq 'HASH') {
2762: %docmoves = %{$moves->{'docmoves'}};
2763: }
2764: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2765: %mapmoves = %{$moves->{'mapmoves'}};
2766: }
2767: }
2768: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2769: my @allcopies;
1.529 raeburn 2770: if (exists($copies{$key})) {
2771: if (ref($copies{$key}) eq 'HASH') {
2772: my %added;
2773: foreach my $innerkey (keys(%{$copies{$key}})) {
2774: if (($innerkey ne '') && (!$added{$innerkey})) {
2775: push(@allcopies,$innerkey);
2776: $added{$innerkey} = 1;
2777: }
1.491 raeburn 2778: }
1.529 raeburn 2779: undef(%added);
1.491 raeburn 2780: }
2781: }
2782: if ($key eq $oldurl) {
1.529 raeburn 2783: if ((exists($docmoves{$key}))) {
1.532 raeburn 2784: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2785: push(@allcopies,$oldurl);
2786: }
2787: }
2788: }
2789: if (@allcopies > 0) {
2790: foreach my $item (@allcopies) {
1.492 raeburn 2791: my ($relpath,$oldsubdir,$fname) =
2792: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2793: if ($fname ne '') {
2794: my $content = &Apache::lonnet::getfile($item);
2795: unless ($content eq '-1') {
2796: my $storefn;
1.529 raeburn 2797: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2798: $storefn = $docmoves{$key};
1.491 raeburn 2799: } else {
2800: $storefn = $relpath;
2801: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2802: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2803: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2804: }
1.529 raeburn 2805: if ($newsubdir{$key}) {
1.532 raeburn 2806: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2807: }
2808: }
2809: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2810: my $copyurl =
2811: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2812: $storefn.$fname,$content);
2813: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2814: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2815: return &mt('Paste failed: an error occurred copying the file.');
2816: } elsif (ref($errors) eq 'HASH') {
2817: $errors->{$item} = 1;
1.489 raeburn 2818: }
2819: }
1.488 raeburn 2820: }
2821: }
1.491 raeburn 2822: }
2823: }
2824: }
1.529 raeburn 2825: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2826: my $storefn=$key;
2827: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2828: if ($prefixchg && $before{'map'} && $after{'map'}) {
2829: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2830: }
1.529 raeburn 2831: if ($newsubdir{$key}) {
2832: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2833: }
1.491 raeburn 2834: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 2835: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
2836: ($after{'map'} eq 'default') &&
2837: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
2838: $mapcontent = '<map>'."\n".
2839: '<resource id="1" src="" type="start" />'."\n".
2840: '<link from="1" to="2" index="1" />'."\n".
2841: '<resource id="2" src="" type="finish" />'."\n".
2842: '</map>';
2843: }
1.491 raeburn 2844: if ($mapcontent eq '-1') {
2845: if (ref($errors) eq 'HASH') {
2846: $errors->{$key} = 1;
2847: }
2848: } else {
2849: my $newmap =
2850: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2851: $mapcontent);
2852: if ($newmap eq '/adm/notfound.html') {
2853: if (ref($errors) eq 'HASH') {
2854: $errors->{$key} = 1;
1.489 raeburn 2855: }
1.488 raeburn 2856: }
2857: }
2858: }
1.491 raeburn 2859: my %updates;
2860: if ($is_map) {
1.529 raeburn 2861: if (ref($updated) eq 'HASH') {
2862: foreach my $type (keys(%{$updated})) {
2863: if (ref($updated->{$type}) eq 'HASH') {
2864: foreach my $key (keys(%{$updated->{$type}})) {
2865: $updates{$key} = 1;
2866: }
2867: }
2868: }
1.491 raeburn 2869: }
2870: foreach my $key (keys(%updates)) {
1.492 raeburn 2871: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2872: if (ref($rewrites{$key}) eq 'HASH') {
2873: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2874: }
1.529 raeburn 2875: if (ref($retitles{$key}) eq 'HASH') {
2876: %toretitle = %{$retitles{$key}};
1.491 raeburn 2877: }
1.529 raeburn 2878: if (ref($removefrommap{$key}) eq 'HASH') {
2879: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2880: }
1.529 raeburn 2881: if (ref($removeparam{$key}) eq 'HASH') {
2882: %remparam = %{$removeparam{$key}};
1.492 raeburn 2883: }
1.529 raeburn 2884: if (ref($zombies{$key}) eq 'HASH') {
2885: %zombie = %{$zombies{$key}};
1.491 raeburn 2886: }
1.529 raeburn 2887: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2888: foreach my $idx (keys(%{$dbcopies{$key}})) {
2889: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2890: my ($newurl,$result,$errtext) =
2891: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2892: if ($result eq 'ok') {
2893: $newdb{$idx} = $newurl;
2894: } elsif (ref($errors) eq 'HASH') {
2895: $errors->{$key} = 1;
2896: }
2897: push(@msgs,$errtext);
2898: }
1.491 raeburn 2899: }
2900: }
1.597 raeburn 2901: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 2902: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 2903: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2904: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2905: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2906: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2907: my $template = $1;
2908: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2909: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2910: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2911: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 2912: unless ($gotnewmapname) {
2913: ($newmapname) = ($key =~ m{/([^/]+)$});
2914: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2915: if ($newsubdir{$key}) {
2916: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2917: }
2918: $gotnewmapname = 1;
2919: }
1.597 raeburn 2920: my $srcmapinfo = $srcfolder.':'.$idx;
2921: if ($srccontainer eq 'page') {
2922: $srcmapinfo .= ':1';
2923: }
2924: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2925: $cnum,$template,$idx,$newmapname);
2926: }
2927: }
2928: }
2929: }
2930: }
1.529 raeburn 2931: if (ref($params{$key}) eq 'HASH') {
2932: %currparam = %{$params{$key}};
1.492 raeburn 2933: }
2934: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2935: if ($fatal) {
1.533 raeburn 2936: return ($errtext);
1.492 raeburn 2937: }
2938: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2939: if (defined($LONCAPA::map::zombies[$i])) {
2940: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2941: if ($zombie{$i} eq $src) {
1.492 raeburn 2942: undef($LONCAPA::map::zombies[$i]);
2943: }
2944: }
2945: }
1.646 raeburn 2946: my $total = scalar(@LONCAPA::map::order) - 1;
2947: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 2948: my $idx = $LONCAPA::map::order[$i];
2949: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2950: my $changed;
1.529 raeburn 2951: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2952: if ((exists($toremove{$idx})) &&
2953: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2954: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2955: if (ref($currparam{$idx}) eq 'ARRAY') {
2956: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 2957: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 2958: }
2959: }
2960: next;
2961: }
2962: my $origsrc = $src;
1.532 raeburn 2963: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2964: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2965: $changed = 1;
1.491 raeburn 2966: }
1.492 raeburn 2967: }
1.532 raeburn 2968: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2969: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2970: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2971: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2972: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2973: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2974: } else {
1.529 raeburn 2975: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2976: }
1.491 raeburn 2977: }
1.532 raeburn 2978: if ($origsrc =~ /\.(page|sequence)$/) {
2979: if ($newsubdir{$origsrc}) {
1.529 raeburn 2980: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2981: }
1.532 raeburn 2982: } elsif ($newsubdir{$key}) {
2983: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2984: }
2985: }
1.492 raeburn 2986: $changed = 1;
1.533 raeburn 2987: } elsif ($newdb{$idx} ne '') {
2988: $src = $newdb{$idx};
1.492 raeburn 2989: $changed = 1;
2990: }
2991: if ($changed) {
1.538 raeburn 2992: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2993: }
2994: }
2995: }
2996: foreach my $idx (keys(%remparam)) {
2997: if (ref($remparam{$idx}) eq 'ARRAY') {
2998: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 2999: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 3000: }
3001: }
3002: }
1.533 raeburn 3003: if (values(%lockerrors) > 0) {
3004: $lockmsg = join('<br />',values(%lockerrors));
3005: }
1.491 raeburn 3006: my $storefn;
3007: if ($key eq $oldurl) {
3008: $storefn = $url;
3009: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3010: } else {
3011: $storefn = $key;
3012: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3013: if ($prefixchg && $before{'map'} && $after{'map'}) {
3014: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3015: }
1.529 raeburn 3016: if ($newsubdir{$key}) {
3017: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3018: }
1.491 raeburn 3019: }
1.492 raeburn 3020: my $report;
3021: if ($folder !~ /^supplemental/) {
3022: $report = 1;
3023: }
1.527 raeburn 3024: (my $outtext,$errtext) =
1.492 raeburn 3025: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3026: if ($errtext) {
1.529 raeburn 3027: if ($caller eq 'paste') {
1.533 raeburn 3028: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 3029: }
1.491 raeburn 3030: }
3031: }
3032: }
1.533 raeburn 3033: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 3034: }
3035:
3036: sub copy_dependencies {
3037: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3038: my $content;
3039: if (ref($contentref)) {
3040: $content = $$contentref;
3041: } else {
3042: $content = &Apache::lonnet::getfile($item);
3043: }
3044: unless ($content eq '-1') {
3045: my $mm = new File::MMagic;
3046: my $mimetype = $mm->checktype_contents($content);
3047: if ($mimetype eq 'text/html') {
3048: my (%allfiles,%codebase,$state);
3049: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3050: if ($res eq 'ok') {
3051: my ($numexisting,$numpathchanges,$existing);
3052: (undef,$numexisting,$numpathchanges,$existing) =
3053: &Apache::loncommon::ask_for_embedded_content(
3054: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3055: {'error_on_invalid_names' => 1,
3056: 'ignore_remote_references' => 1,
3057: 'docs_url' => $item,
3058: 'context' => 'paste'});
3059: if ($numexisting > 0) {
3060: if (ref($existing) eq 'HASH') {
3061: foreach my $dep (keys(%{$existing})) {
3062: my $depfile = $dep;
3063: unless ($depfile =~ m{^\Q$relpath\E}) {
3064: $depfile = $relpath.$dep;
3065: }
3066: my $depcontent = &Apache::lonnet::getfile($depfile);
3067: unless ($depcontent eq '-1') {
3068: my $storedep = $dep;
3069: $storedep =~ s{^\Q$relpath\E}{};
3070: my $dep_url =
3071: &Apache::lonclonecourse::writefile(
3072: $env{'request.course.id'},
3073: $storefn.$storedep,$depcontent);
3074: if ($dep_url eq '/adm/notfound.html') {
3075: if (ref($errors) eq 'HASH') {
3076: $errors->{$depfile} = 1;
3077: }
3078: } else {
3079: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3080: }
3081: }
3082: }
1.488 raeburn 3083: }
3084: }
3085: }
3086: }
3087: }
3088: return;
3089: }
3090:
1.329 droeschl 3091: my %parameter_type = ( 'randompick' => 'int_pos',
3092: 'hiddenresource' => 'string_yesno',
3093: 'encrypturl' => 'string_yesno',
3094: 'randomorder' => 'string_yesno',);
3095: my $valid_parameters_re = join('|',keys(%parameter_type));
3096: # set parameters
3097: sub update_parameter {
1.537 raeburn 3098: if ($env{'form.changeparms'} eq 'all') {
3099: my (@allidx,@allmapidx,%allchecked,%currchecked);
3100: %allchecked = (
3101: 'hiddenresource' => {},
3102: 'encrypturl' => {},
3103: 'randompick' => {},
3104: 'randomorder' => {},
3105: );
3106: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3107: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3108: if ($which eq 'randompick') {
3109: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3110: my ($res,$value) = split(/:/,$item);
3111: if ($value =~ /^\d+$/) {
3112: $allchecked{$which}{$res} = $value;
3113: }
3114: }
3115: } else {
1.539 raeburn 3116: if ($env{'form.all'.$which}) {
3117: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3118: }
1.537 raeburn 3119: }
3120: }
3121: my $haschanges = 0;
3122: foreach my $res (@LONCAPA::map::order) {
3123: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3124: $name=&LONCAPA::map::qtescape($name);
3125: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 3126: next unless $url;
1.537 raeburn 3127: my $is_map;
3128: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3129: $is_map = 1;
3130: }
3131: foreach my $which (keys(%allchecked)) {
3132: if (($which eq 'randompick' || $which eq 'randomorder')) {
3133: next if (!$is_map);
3134: }
3135: my $oldvalue = 0;
3136: my $newvalue = 0;
3137: if ($allchecked{$which}{$res}) {
3138: $newvalue = $allchecked{$which}{$res};
3139: }
3140: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3141: if ($which eq 'randompick') {
3142: if ($current =~ /^(\d+)$/) {
3143: $oldvalue = $1;
3144: }
3145: } else {
3146: if ($current =~ /^yes$/i) {
3147: $oldvalue = 1;
3148: }
3149: }
3150: if ($oldvalue ne $newvalue) {
3151: $haschanges = 1;
3152: if ($newvalue) {
3153: my $storeval = 'yes';
3154: if ($which eq 'randompick') {
3155: $storeval = $newvalue;
3156: }
3157: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3158: $storeval,
3159: $parameter_type{$which});
3160: &remember_parms($res,$which,'set',$storeval);
3161: } elsif ($oldvalue) {
3162: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3163: &remember_parms($res,$which,'del');
3164: }
3165: }
3166: }
3167: }
3168: return $haschanges;
3169: } else {
1.588 raeburn 3170: my $haschanges = 0;
3171: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3172:
1.537 raeburn 3173: my $which = $env{'form.changeparms'};
3174: my $idx = $env{'form.setparms'};
1.588 raeburn 3175: my $oldvalue = 0;
3176: my $newvalue = 0;
3177: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3178: if ($which eq 'randompick') {
3179: if ($current =~ /^(\d+)$/) {
3180: $oldvalue = $1;
3181: }
3182: } elsif ($current =~ /^yes$/i) {
3183: $oldvalue = 1;
3184: }
1.537 raeburn 3185: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3186: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3187: : 1;
3188: }
3189: if ($oldvalue ne $newvalue) {
3190: $haschanges = 1;
3191: if ($newvalue) {
3192: my $storeval = 'yes';
3193: if ($which eq 'randompick') {
3194: $storeval = $newvalue;
3195: }
3196: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3197: $parameter_type{$which});
3198: &remember_parms($idx,$which,'set',$storeval);
3199: } else {
3200: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3201: &remember_parms($idx,$which,'del');
3202: }
1.537 raeburn 3203: }
1.588 raeburn 3204: return $haschanges;
1.329 droeschl 3205: }
3206: }
3207:
3208: sub handle_edit_cmd {
3209: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3210: my $haschanges = 0;
1.543 raeburn 3211: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3212: return $haschanges;
1.543 raeburn 3213: }
1.329 droeschl 3214: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3215:
3216: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3217: my ($title, $url, @rrest) = split(':', $ratstr);
3218:
1.538 raeburn 3219: if ($cmd eq 'remove') {
1.329 droeschl 3220: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3221: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3222: &Apache::lonnet::removeuploadedurl($url);
3223: } else {
3224: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3225: }
3226: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3227: $haschanges = 1;
1.329 droeschl 3228: } elsif ($cmd eq 'cut') {
3229: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3230: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3231: $haschanges = 1;
1.344 bisitz 3232: } elsif ($cmd eq 'up'
1.329 droeschl 3233: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3234: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3235: $haschanges = 1;
1.329 droeschl 3236: } elsif ($cmd eq 'down'
3237: && defined($LONCAPA::map::order[$idx+1])) {
3238: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3239: $haschanges = 1;
1.329 droeschl 3240: } elsif ($cmd eq 'rename') {
3241: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3242: if ($comment=~/\S/) {
3243: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3244: $comment.':'.join(':', $url, @rrest);
3245: }
3246: # Devalidate title cache
3247: my $renamed_url=&LONCAPA::map::qtescape($url);
3248: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3249: $haschanges = 1;
3250: } elsif ($cmd eq 'setalias') {
3251: my $newvalue = $env{'form.alias'};
3252: if ($newvalue ne '') {
3253: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3254: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3255: 'string');
3256: &remember_parms($idx,'mapalias','set',$newvalue);
3257: $haschanges = 1;
3258: }
3259: }
3260: } elsif ($cmd eq 'delalias') {
3261: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3262: if ($current ne '') {
3263: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3264: &remember_parms($idx,'mapalias','del');
3265: $haschanges = 1;
3266: }
1.329 droeschl 3267: }
1.633 raeburn 3268: return $haschanges;
1.329 droeschl 3269: }
3270:
3271: sub editor {
1.458 raeburn 3272: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3273: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3274: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3275: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3276: if ($allowed) {
1.519 raeburn 3277: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3278: $is_random_order,$container) =
1.510 raeburn 3279: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3280: $r->print($breadcrumbtrail);
1.519 raeburn 3281: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3282: $container = 'page';
3283: } else {
3284: $container = 'sequence';
1.510 raeburn 3285: }
1.484 raeburn 3286:
1.525 raeburn 3287: my $jumpto;
3288:
3289: unless ($supplementalflag) {
1.546 raeburn 3290: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3291: }
1.484 raeburn 3292:
3293: unless ($allowed) {
3294: $randompick = -1;
3295: }
3296:
1.615 raeburn 3297: my ($errtext,$fatal);
3298: if (($folder eq '') && (!$supplementalflag)) {
3299: if (@LONCAPA::map::order) {
3300: undef(@LONCAPA::map::order);
3301: undef(@LONCAPA::map::resources);
3302: undef(@LONCAPA::map::resparms);
3303: undef(@LONCAPA::map::zombies);
3304: }
3305: $folder = 'default';
3306: $container = 'sequence';
3307: } else {
3308: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3309: $folder.'.'.$container);
3310: return $errtext if ($fatal);
3311: }
1.329 droeschl 3312:
3313: if ($#LONCAPA::map::order<1) {
3314: my $idx=&LONCAPA::map::getresidx();
3315: if ($idx<=0) { $idx=1; }
3316: $LONCAPA::map::order[0]=$idx;
3317: $LONCAPA::map::resources[$idx]='';
3318: }
1.364 bisitz 3319:
1.329 droeschl 3320: # ------------------------------------------------------------ Process commands
3321:
3322: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3323: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3324: # set parameters and change order
3325: &snapshotbefore();
3326:
3327: if (&update_parameter()) {
1.588 raeburn 3328: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3329: return $errtext if ($fatal);
3330: }
3331:
3332: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3333: # change order
3334: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3335: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3336:
3337: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3338: return $errtext if ($fatal);
3339: }
1.364 bisitz 3340:
1.329 droeschl 3341: if ($env{'form.pastemarked'}) {
1.491 raeburn 3342: my %paste_errors;
1.533 raeburn 3343: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3344: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3345: \%paste_errors);
1.541 raeburn 3346: if (ref($pastemsgarray) eq 'ARRAY') {
3347: if (@{$pastemsgarray} > 0) {
3348: $r->print('<p class="LC_info">'.
3349: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3350: '</p>');
3351: }
1.541 raeburn 3352: }
3353: if ($lockerror) {
3354: $r->print('<p class="LC_error">'.
3355: $lockerror.
3356: '</p>');
3357: }
3358: if ($save_error ne '') {
3359: return $save_error;
3360: }
3361: if ($paste_res) {
3362: my %errortext = &Apache::lonlocal::texthash (
3363: fail => 'Storage of folder contents failed',
3364: failread => 'Reading folder contents failed',
3365: failstore => 'Storage of folder contents failed',
3366: );
3367: if ($errortext{$paste_res}) {
3368: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3369: }
1.329 droeschl 3370: }
1.491 raeburn 3371: if (keys(%paste_errors) > 0) {
1.538 raeburn 3372: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3373: &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".
3374: '<ul>'."\n");
3375: foreach my $key (sort(keys(%paste_errors))) {
3376: $r->print('<li>'.$key.'</li>'."\n");
3377: }
3378: $r->print('</ul></p>'."\n");
3379: }
1.538 raeburn 3380: } elsif ($env{'form.clearmarked'}) {
3381: my $output = &do_buffer_empty();
3382: if ($output) {
3383: $r->print('<p class="LC_info">'.$output.'</p>');
3384: }
3385: }
1.329 droeschl 3386:
3387: $r->print($upload_output);
3388:
1.538 raeburn 3389: # Rename, cut, copy or remove a single resource
1.602 raeburn 3390: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3391: my $contentchg;
1.633 raeburn 3392: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3393: $contentchg = 1;
3394: }
3395: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3396: return $errtext if ($fatal);
3397: }
1.538 raeburn 3398:
3399: # Cut, copy and/or remove multiple resources
3400: if ($env{'form.multichange'}) {
3401: my %allchecked = (
3402: cut => {},
3403: remove => {},
3404: );
3405: my $needsupdate;
3406: foreach my $which (keys(%allchecked)) {
3407: $env{'form.multi'.$which} =~ s/,$//;
3408: if ($env{'form.multi'.$which}) {
3409: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3410: if (ref($allchecked{$which}) eq 'HASH') {
3411: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3412: }
3413: }
3414: }
3415: if ($needsupdate) {
3416: my $haschanges = 0;
3417: my %curr_groups = &Apache::longroup::coursegroups();
3418: my $total = scalar(@LONCAPA::map::order) - 1;
3419: for (my $i=$total; $i>=0; $i--) {
3420: my $res = $LONCAPA::map::order[$i];
3421: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3422: $name=&LONCAPA::map::qtescape($name);
3423: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3424: next unless $url;
1.538 raeburn 3425: my %denied =
3426: &action_restrictions($coursenum,$coursedom,$url,
3427: $env{'form.folderpath'},\%curr_groups);
3428: foreach my $which (keys(%allchecked)) {
3429: next if ($denied{$which});
3430: next unless ($allchecked{$which}{$res});
3431: if ($which eq 'remove') {
3432: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3433: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3434: &Apache::lonnet::removeuploadedurl($url);
3435: } else {
3436: &LONCAPA::map::makezombie($res);
3437: }
3438: splice(@LONCAPA::map::order,$i,1);
3439: $haschanges ++;
3440: } elsif ($which eq 'cut') {
3441: &LONCAPA::map::makezombie($res);
3442: splice(@LONCAPA::map::order,$i,1);
3443: $haschanges ++;
3444: }
3445: }
3446: }
3447: if ($haschanges) {
3448: ($errtext,$fatal) =
3449: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3450: return $errtext if ($fatal);
3451: }
3452: }
3453: }
3454:
1.329 droeschl 3455: # Group import/search
3456: if ($env{'form.importdetail'}) {
3457: my @imports;
3458: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3459: if (defined($item)) {
3460: my ($name,$url,$residx)=
1.533 raeburn 3461: map { &unescape($_); } split(/\=/,$item);
3462: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3463: my ($suffix,$errortxt,$locknotfreed) =
3464: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3465: if ($locknotfreed) {
3466: $r->print($locknotfreed);
3467: }
3468: if ($suffix) {
3469: $url =~ s/_new\./_$suffix./;
3470: } else {
3471: return $errortxt;
3472: }
1.533 raeburn 3473: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3474: my $type = $1;
3475: my ($suffix,$errortxt,$locknotfreed) =
3476: &new_timebased_suffix($coursedom,$coursenum,$type);
3477: if ($locknotfreed) {
3478: $r->print($locknotfreed);
3479: }
3480: if ($suffix) {
3481: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3482: } else {
3483: return $errortxt;
3484: }
1.626 raeburn 3485: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3486: my ($suffix,$errortxt,$locknotfreed) =
3487: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3488: if ($locknotfreed) {
3489: $r->print($locknotfreed);
3490: }
3491: if ($suffix) {
3492: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3493: } else {
3494: return $errortxt;
3495: }
1.534 raeburn 3496: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3497: if ($supplementalflag) {
3498: next unless ($1 eq 'supplemental');
3499: if ($folder eq 'supplemental') {
3500: next unless ($2 eq 'default');
3501: } else {
3502: next unless ($folder eq 'supplemental_'.$2);
3503: }
3504: } else {
3505: next unless ($1 eq 'docs');
3506: if ($folder eq 'default') {
3507: next unless ($2 eq 'default');
3508: } else {
3509: next unless ($folder eq 'default_'.$2);
3510: }
3511: }
1.504 raeburn 3512: }
1.329 droeschl 3513: push(@imports, [$name, $url, $residx]);
3514: }
3515: }
1.530 raeburn 3516: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3517: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3518: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3519: return $errtext if ($fatal);
1.529 raeburn 3520: if ($fixuperrors) {
3521: $r->print($fixuperrors);
3522: }
1.329 droeschl 3523: }
3524: # Loading a complete map
3525: if ($env{'form.loadmap'}) {
3526: if ($env{'form.importmap'}=~/\w/) {
3527: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3528: my ($title,$url,$ext,$type)=split(/\:/,$res);
3529: my $idx=&LONCAPA::map::getresidx($url);
3530: $LONCAPA::map::resources[$idx]=$res;
3531: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3532: }
3533: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3534: $folder.'.'.$container,1);
1.329 droeschl 3535: return $errtext if ($fatal);
3536: } else {
3537: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3538:
1.329 droeschl 3539: }
3540: }
3541: &log_differences($plain);
3542: }
3543: # ---------------------------------------------------------------- End commands
3544: # ---------------------------------------------------------------- Print screen
3545: my $idx=0;
3546: my $shown=0;
3547: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3548: $r->print('<div class="LC_Box">'.
1.432 raeburn 3549: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3550: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3551: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3552: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3553: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3554: '</ol>');
1.381 bisitz 3555: if ($randompick>=0) {
3556: $r->print('<p class="LC_warning">'
3557: .&mt('Caution: this folder is set to randomly pick a subset'
3558: .' of resources. Adding or removing resources from this'
3559: .' folder will change the set of resources that the'
3560: .' students see, resulting in spurious or missing credit'
3561: .' for completed problems, not limited to ones you'
3562: .' modify. Do not modify the contents of this folder if'
3563: .' it is in active student use.')
3564: .'</p>'
3565: );
3566: }
3567: if ($is_random_order) {
3568: $r->print('<p class="LC_warning">'
3569: .&mt('Caution: this folder is set to randomly order its'
3570: .' contents. Adding or removing resources from this folder'
3571: .' will change the order of resources shown.')
3572: .'</p>'
3573: );
3574: }
3575: $r->print('</div>');
1.364 bisitz 3576: }
1.381 bisitz 3577:
1.685 raeburn 3578: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 3579: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 3580: if (ref($supplemental) eq 'HASH') {
3581: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
3582: (ref($supplemental->{'ids'}) eq 'HASH')) {
3583: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
3584: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
3585: if ($supplemental->{'hidden'}->{$mapnum}) {
3586: $ishidden = 1;
3587: }
3588: }
3589: }
3590: }
3591: }
3592:
1.538 raeburn 3593: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3594: %filters = (
1.543 raeburn 3595: canremove => [],
3596: cancut => [],
3597: cancopy => [],
3598: hiddenresource => [],
3599: encrypturl => [],
3600: randomorder => [],
3601: randompick => [],
1.538 raeburn 3602: );
3603: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3604: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3605: foreach my $res (@LONCAPA::map::order) {
3606: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3607: $name=&LONCAPA::map::qtescape($name);
3608: $url=&LONCAPA::map::qtescape($url);
3609: unless ($name) { $name=(split(/\//,$url))[-1]; }
3610: unless ($name) { $idx++; next; }
1.537 raeburn 3611: push(@allidx,$res);
3612: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3613: push(@allmapidx,$res);
3614: }
1.617 raeburn 3615:
1.682 raeburn 3616: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 3617: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
3618: $idx++;
3619: next;
3620: }
1.682 raeburn 3621: }
1.381 bisitz 3622: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3623: $coursenum,$coursedom,$crstype,
1.538 raeburn 3624: $pathitem,$supplementalflag,$container,
1.620 raeburn 3625: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 3626: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 3627: $idx++;
3628: $shown++;
1.329 droeschl 3629: }
1.424 onken 3630: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3631:
1.538 raeburn 3632: my $need_save;
1.611 raeburn 3633: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3634: my $toolslink;
1.682 raeburn 3635: if ($allowed || $canedit) {
3636: my $helpitem = 'Navigation_Screen';
3637: if (!$allowed) {
3638: $helpitem = 'Supplemental_Navigation';
3639: }
1.544 raeburn 3640: $toolslink = '<table><tr><td>'
1.520 raeburn 3641: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 3642: $helpitem,undef,'RAT')
1.520 raeburn 3643: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3644: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3645: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3646: .'id="LC_content_toolbar_edittoplevel" '
3647: .'class="LC_toolbarItem" '
3648: .'title="'.&mt('Supplemental Content Editor').'">'
3649: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3650: }
1.510 raeburn 3651: if ($shown) {
3652: if ($allowed) {
3653: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3654: .&Apache::loncommon::start_data_table(undef,'contentlist')
3655: .&Apache::loncommon::start_data_table_header_row()
3656: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3657: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 3658: .'<th>'.&mt('Document').'</th>'
3659: .'<th colspan="2">'.&mt('Settings').'</th>'
3660: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 3661: if ($folder !~ /^supplemental/) {
1.538 raeburn 3662: $lists{'canhide'} = join(',',@allidx);
3663: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3664: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3665: 'randomorder','randompick');
3666: foreach my $item (@possfilters) {
1.538 raeburn 3667: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3668: if (@{$filters{$item}} > 0) {
3669: $lists{$item} = join(',',@{$filters{$item}});
3670: }
1.538 raeburn 3671: }
3672: }
1.537 raeburn 3673: if (@allidx > 0) {
3674: my $path;
3675: if ($env{'form.folderpath'}) {
1.630 raeburn 3676: $path =
1.537 raeburn 3677: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3678: }
1.538 raeburn 3679: if (@allidx > 1) {
1.630 raeburn 3680: $to_show .=
1.538 raeburn 3681: &Apache::loncommon::continue_data_table_row().
3682: '<td colspan="2"> </td>'.
3683: '<td>'.
1.611 raeburn 3684: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3685: '</td>'.
1.633 raeburn 3686: '<td colspan="3"> </td>'.
3687: '<td colspan="2">'.
1.611 raeburn 3688: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3689: '</td>'.
3690: &Apache::loncommon::end_data_table_row();
3691: $need_save = 1;
3692: }
1.537 raeburn 3693: }
3694: }
3695: $to_show .= $output.' '
1.510 raeburn 3696: .&Apache::loncommon::end_data_table()
3697: .'<br style="line-height:2px;" />'
3698: .&Apache::loncommon::end_scrollbox();
3699: } else {
1.520 raeburn 3700: $to_show .= $toolslink
1.510 raeburn 3701: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3702: .$output.' '
3703: .&Apache::loncommon::end_data_table();
1.393 raeburn 3704: }
1.510 raeburn 3705: } else {
1.520 raeburn 3706: if (!$allowed) {
3707: $to_show .= $toolslink;
3708: }
1.615 raeburn 3709: my $noresmsg;
3710: if ($allowed && $hiddentop && !$supplementalflag) {
3711: $noresmsg = &mt('Main Content Hidden');
3712: } else {
3713: $noresmsg = &mt('Currently empty');
3714: }
1.510 raeburn 3715: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3716: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3717: .$noresmsg
1.510 raeburn 3718: .'</div>'
3719: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3720: }
3721: } else {
1.510 raeburn 3722: if ($shown) {
3723: $to_show = '<div>'
3724: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3725: .$output
3726: .&Apache::loncommon::end_data_table()
3727: .'</div>';
3728: } else {
3729: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3730: .&mt('Currently empty')
1.510 raeburn 3731: .'</div>'
3732: }
1.458 raeburn 3733: }
3734: my $tid = 1;
3735: if ($supplementalflag) {
3736: $tid = 2;
1.329 droeschl 3737: }
3738: if ($allowed) {
1.484 raeburn 3739: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3740: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3741: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3742: if ($canedit) {
3743: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3744: }
1.460 raeburn 3745: } else {
3746: $r->print($to_show);
1.329 droeschl 3747: }
3748: return;
3749: }
3750:
1.538 raeburn 3751: sub multiple_check_form {
1.611 raeburn 3752: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3753: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3754: my $disabled;
3755: unless ($canedit) {
1.700 raeburn 3756: $disabled = ' disabled="disabled"';
1.611 raeburn 3757: }
1.538 raeburn 3758: my $output =
3759: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3760: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3761: '<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>'.
3762: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3763: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3764: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3765: if ($caller eq 'settings') {
3766: $output .=
3767: '<table><tr>'.
3768: '<td class="LC_docs_entry_parameter">'.
3769: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3770: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3771: '</label></span></td>'.
3772: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3773: '<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 3774: '</span></td>'.
3775: '</tr>'."\n".
3776: '<tr>'.
3777: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3778: '<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 3779: '</label></span>'.
3780: '</td></tr></table>'."\n";
3781: } else {
3782: $output .=
3783: '<table><tr>'.
3784: '<td class="LC_docs_entry_parameter">'.
3785: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3786: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3787: '</label></span></td>'.
3788: '<td class="LC_docs_entry_parameter">'.
3789: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3790: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3791: '</label></span></td>'."\n".
3792: '<td class="LC_docs_entry_parameter">'.
3793: '<span class="LC_nobreak LC_docs_copy">'.
1.700 raeburn 3794: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538 raeburn 3795: '</label></span></td>'.
3796: '</tr></table>'."\n";
3797: }
3798: $output .=
3799: '</fieldset>'.
3800: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3801: if ($caller eq 'settings') {
3802: $output .=
1.543 raeburn 3803: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3804: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3805: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3806: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3807: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3808: } elsif ($caller eq 'actions') {
3809: $output .=
3810: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3811: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3812: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3813: }
3814: $output .=
3815: '</form>'.
3816: '</div>';
3817: return $output;
3818: }
3819:
1.329 droeschl 3820: sub process_file_upload {
1.552 raeburn 3821: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3822: # upload a file, if present
1.552 raeburn 3823: my $filesize = length($env{'form.uploaddoc'});
3824: if (!$filesize) {
3825: $$upload_output = '<div class="LC_error">'.
3826: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3827: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3828: $filesize).'<br />'.
3829: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3830: '</div>';
3831: return;
3832: }
3833: my $quotatype = 'unofficial';
3834: if ($crstype eq 'Community') {
1.601 raeburn 3835: $quotatype = 'community';
3836: } elsif ($crstype eq 'Placement') {
3837: $quotatype = 'placement';
1.580 raeburn 3838: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3839: $quotatype = 'official';
1.573 raeburn 3840: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3841: $quotatype = 'textbook';
1.552 raeburn 3842: }
3843: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3844: $filesize = int($filesize/1000); #expressed in kb
3845: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3846: $env{'form.uploaddoc.filename'},$filesize,
3847: 'upload',$quotatype);
1.552 raeburn 3848: return if ($$upload_output);
3849: }
1.440 raeburn 3850: my ($parseaction,$showupload,$nextphase,$mimetype);
3851: if ($env{'form.parserflag'}) {
1.329 droeschl 3852: $parseaction = 'parse';
3853: }
3854: my $folder=$env{'form.folder'};
3855: if ($folder eq '') {
3856: $folder='default';
3857: }
3858: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3859: my $errtext='';
3860: my $fatal=0;
3861: my $container='sequence';
1.519 raeburn 3862: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3863: $container='page';
3864: }
3865: ($errtext,$fatal)=
1.534 raeburn 3866: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3867: if ($#LONCAPA::map::order<1) {
3868: $LONCAPA::map::order[0]=1;
3869: $LONCAPA::map::resources[1]='';
3870: }
3871: my $destination = 'docs/';
3872: if ($folder =~ /^supplemental/) {
3873: $destination = 'supplemental/';
3874: }
3875: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3876: $destination .= 'default/';
3877: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3878: $destination .= $2.'/';
3879: }
1.534 raeburn 3880: if ($fatal) {
3881: $$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>';
3882: return;
3883: }
1.440 raeburn 3884: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3885: my $newidx=&LONCAPA::map::getresidx();
3886: $destination .= $newidx;
1.439 raeburn 3887: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3888: $parseaction,$allfiles,
1.440 raeburn 3889: $codebase,undef,undef,undef,undef,
3890: undef,undef,\$mimetype);
3891: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3892: my $stored = $1;
3893: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3894: $stored.'</span>').'</p>';
3895: } else {
3896: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3897:
1.457 raeburn 3898: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3899: return;
3900: }
1.329 droeschl 3901: my $ext='false';
3902: if ($url=~m{^http://}) { $ext='true'; }
3903: $url = &LONCAPA::map::qtunescape($url);
3904: my $comment=$env{'form.comment'};
3905: $comment = &LONCAPA::map::qtunescape($comment);
3906: if ($folder=~/^supplemental/) {
3907: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3908: $env{'user.domain'}.'___&&&___'.$comment;
3909: }
3910:
3911: $LONCAPA::map::resources[$newidx]=
3912: $comment.':'.$url.':'.$ext.':normal:res';
3913: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3914: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3915: $folder.'.'.$container,1);
1.329 droeschl 3916: if ($fatal) {
1.457 raeburn 3917: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3918: return;
1.329 droeschl 3919: } else {
1.440 raeburn 3920: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3921: $$upload_output = $showupload;
1.384 raeburn 3922: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3923: if ($total_embedded > 0) {
1.440 raeburn 3924: my $uploadphase = 'upload_embedded';
3925: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3926: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3927: my ($embedded,$num) =
1.440 raeburn 3928: &Apache::loncommon::ask_for_embedded_content(
3929: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3930: if ($embedded) {
3931: if ($num) {
3932: $$upload_output .=
3933: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3934: $nextphase = $uploadphase;
3935: } else {
3936: $$upload_output .= $embedded;
3937: }
3938: } else {
3939: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3940: }
1.329 droeschl 3941: } else {
1.440 raeburn 3942: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3943: }
1.457 raeburn 3944: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3945: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3946: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3947: $nextphase = 'decompress_uploaded';
3948: my $position = scalar(@LONCAPA::map::order)-1;
3949: my $noextract = &return_to_editor();
3950: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3951: my %archiveitems = (
3952: folderpath => $env{'form.folderpath'},
3953: cmd => $nextphase,
3954: newidx => $newidx,
3955: position => $position,
3956: phase => $nextphase,
1.477 raeburn 3957: comment => $comment,
1.480 raeburn 3958: );
3959: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3960: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3961: $$upload_output = $showupload.
3962: &Apache::loncommon::decompress_form($mimetype,
3963: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3964: \%archiveitems,\@current);
1.329 droeschl 3965: }
3966: }
3967: }
1.440 raeburn 3968: return $nextphase;
1.329 droeschl 3969: }
3970:
1.480 raeburn 3971: sub get_dir_list {
3972: my ($url,$coursenum,$coursedom,$newidx) = @_;
3973: my ($destination,$dir_root) = &embedded_destination();
3974: my ($dirlistref,$listerror) =
3975: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3976: my @dir_lines;
3977: my $dirptr=16384;
3978: if (ref($dirlistref) eq 'ARRAY') {
3979: foreach my $dir_line (sort
3980: {
3981: my ($afile)=split('&',$a,2);
3982: my ($bfile)=split('&',$b,2);
3983: return (lc($afile) cmp lc($bfile));
3984: } (@{$dirlistref})) {
3985: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3986: $filename =~ s/\s+$//;
3987: next if ($filename =~ /^\.\.?$/);
3988: my $isdir = 0;
3989: if ($dirptr&$testdir) {
3990: $isdir = 1;
3991: }
3992: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3993: }
3994: }
3995: return @dir_lines;
3996: }
3997:
1.329 droeschl 3998: sub is_supplemental_title {
3999: my ($title) = @_;
4000: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
4001: }
4002:
4003: # --------------------------------------------------------------- An entry line
4004:
4005: sub entryline {
1.501 raeburn 4006: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 4007: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 4008: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 4009: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 4010: if (&is_supplemental_title($title)) {
1.488 raeburn 4011: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 4012: $encodedtitle=$title;
1.329 droeschl 4013: } else {
4014: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 4015: $encodedtitle=$title;
1.329 droeschl 4016: $renametitle=$title;
4017: $foldertitle=$title;
4018: }
4019:
1.611 raeburn 4020: my ($disabled,$readonly,$js_lt);
4021: unless ($canedit) {
4022: $disabled = 'disabled="disabled"';
4023: $readonly = 1;
4024: }
4025:
1.329 droeschl 4026: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 4027:
1.329 droeschl 4028: $renametitle=~s/\\/\\\\/g;
4029: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 4030: $renametitle=~s/"/%22/g;
1.581 raeburn 4031: $renametitle=~s/ /%20/g;
4032: $oldtitle = $renametitle;
1.576 raeburn 4033: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 4034: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 4035: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 4036: # Edit commands
1.679 raeburn 4037: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 4038: if ($env{'form.folderpath'}) {
4039: $esc_path=&escape($env{'form.folderpath'});
4040: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4041: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4042: }
1.505 raeburn 4043: my $isexternal;
1.510 raeburn 4044: if ($residx) {
1.501 raeburn 4045: my $currurl = $url;
4046: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 4047: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4048: $isexternal = 1;
4049: }
1.510 raeburn 4050: if (!$supplementalflag) {
4051: my $path = 'uploaded/'.
4052: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4053: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4054: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4055: $residx,
4056: &Apache::lonnet::declutter($currurl));
4057: }
1.501 raeburn 4058: }
1.538 raeburn 4059: my ($renamelink,%lt,$ishash);
4060: if (ref($filtersref) eq 'HASH') {
4061: $ishash = 1;
4062: }
4063:
1.329 droeschl 4064: if ($allowed) {
1.538 raeburn 4065: $form_start = '
4066: <form action="/adm/coursedocs" method="post">
4067: ';
4068: $form_common=(<<END);
4069: <input type="hidden" name="folderpath" value="$path" />
4070: <input type="hidden" name="symb" value="$symb" />
4071: END
4072: $form_param=(<<END);
4073: <input type="hidden" name="setparms" value="$orderidx" />
4074: <input type="hidden" name="changeparms" value="0" />
4075: END
4076: $form_end = '</form>';
4077:
1.329 droeschl 4078: my $incindex=$index+1;
4079: my $selectbox='';
1.471 raeburn 4080: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 4081: ((split(/\:/,
1.344 bisitz 4082: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4083: ne '') &&
1.329 droeschl 4084: ((split(/\:/,
1.344 bisitz 4085: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 4086: ne '')) {
4087: $selectbox=
4088: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 4089: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 4090: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4091: if ($i==$incindex) {
1.358 bisitz 4092: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 4093: } else {
4094: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4095: }
4096: }
4097: $selectbox.='</select>';
4098: }
1.501 raeburn 4099: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 4100: 'up' => 'Move Up',
4101: 'dw' => 'Move Down',
4102: 'rm' => 'Remove',
4103: 'ct' => 'Cut',
4104: 'rn' => 'Rename',
1.501 raeburn 4105: 'cp' => 'Copy',
1.633 raeburn 4106: 'da' => 'Unset alias',
4107: 'sa' => 'Set alias',
1.501 raeburn 4108: 'ex' => 'External Resource',
1.598 raeburn 4109: 'et' => 'External Tool',
1.501 raeburn 4110: 'ed' => 'Edit',
4111: 'pr' => 'Preview',
4112: 'sv' => 'Save',
4113: 'ul' => 'URL',
1.611 raeburn 4114: 'ti' => 'Title',
1.618 raeburn 4115: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 4116: );
1.538 raeburn 4117: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4118: $env{'form.folderpath'},
4119: $currgroups);
1.517 raeburn 4120: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4121: my $skip_confirm = 0;
1.603 raeburn 4122: my $confirm_removal = 0;
1.329 droeschl 4123: if ( $folder =~ /^supplemental/
4124: || ($url =~ m{( /smppg$
4125: |/syllabus$
4126: |/aboutme$
4127: |/navmaps$
4128: |/bulletinboard$
1.626 raeburn 4129: |/ext\.tool$
1.505 raeburn 4130: |\.html$)}x)
4131: || $isexternal) {
1.329 droeschl 4132: $skip_confirm = 1;
4133: }
1.603 raeburn 4134: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4135: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4136: $confirm_removal = 1;
4137: }
1.633 raeburn 4138: if ($url =~ /$LONCAPA::assess_re/) {
4139: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4140: }
1.329 droeschl 4141:
1.538 raeburn 4142: if ($denied{'copy'}) {
1.543 raeburn 4143: $copylink=(<<ENDCOPY)
1.507 raeburn 4144: <span style="visibility: hidden;">$lt{'cp'}</span>
4145: ENDCOPY
4146: } else {
1.538 raeburn 4147: my $formname = 'edit_copy_'.$orderidx;
4148: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4149: $copylink=(<<ENDCOPY);
1.538 raeburn 4150: <form name="$formname" method="post" action="/adm/coursedocs">
4151: $form_common
1.611 raeburn 4152: <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 4153: $form_end
1.329 droeschl 4154: ENDCOPY
1.538 raeburn 4155: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4156: push(@{$filtersref->{'cancopy'}},$orderidx);
4157: }
1.329 droeschl 4158: }
1.538 raeburn 4159: if ($denied{'cut'}) {
1.507 raeburn 4160: $cutlink=(<<ENDCUT);
4161: <span style="visibility: hidden;">$lt{'ct'}</span>
4162: ENDCUT
4163: } else {
1.538 raeburn 4164: my $formname = 'edit_cut_'.$orderidx;
4165: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4166: $cutlink=(<<ENDCUT);
1.538 raeburn 4167: <form name="$formname" method="post" action="/adm/coursedocs">
4168: $form_common
1.542 raeburn 4169: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4170: <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 4171: $form_end
1.329 droeschl 4172: ENDCUT
1.538 raeburn 4173: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4174: push(@{$filtersref->{'cancut'}},$orderidx);
4175: }
1.329 droeschl 4176: }
1.538 raeburn 4177: if ($denied{'remove'}) {
1.507 raeburn 4178: $removelink=(<<ENDREM);
4179: <span style="visibility: hidden;">$lt{'rm'}</a>
4180: ENDREM
4181: } else {
1.538 raeburn 4182: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4183: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4184: $removelink=(<<ENDREM);
1.538 raeburn 4185: <form name="$formname" method="post" action="/adm/coursedocs">
4186: $form_common
1.542 raeburn 4187: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4188: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4189: <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 4190: $form_end
1.497 raeburn 4191: ENDREM
1.538 raeburn 4192: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4193: push(@{$filtersref->{'canremove'}},$orderidx);
4194: }
1.497 raeburn 4195: }
1.551 raeburn 4196: $renamelink=(<<ENDREN);
1.581 raeburn 4197: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4198: ENDREN
1.611 raeburn 4199: my ($uplink,$downlink);
4200: if ($canedit) {
4201: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4202: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4203: } else {
4204: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4205: $downlink = $uplink;
4206: }
1.329 droeschl 4207: $line.=(<<END);
4208: <td>
1.379 bisitz 4209: <div class="LC_docs_entry_move">
1.611 raeburn 4210: <a href="$uplink">
1.501 raeburn 4211: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4212: </a>
4213: </div>
4214: <div class="LC_docs_entry_move">
1.611 raeburn 4215: <a href="$downlink">
1.501 raeburn 4216: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4217: </a>
4218: </div>
1.329 droeschl 4219: </td>
4220: <td>
4221: $form_start
1.538 raeburn 4222: $form_param
1.478 raeburn 4223: $form_common
1.329 droeschl 4224: $selectbox
4225: $form_end
4226: </td>
1.540 raeburn 4227: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4228: $removelink
1.329 droeschl 4229: $cutlink
4230: $copylink
4231: </td>
4232: END
4233: }
4234: # Figure out what kind of a resource this is
4235: my ($extension)=($url=~/\.(\w+)$/);
4236: my $uploaded=($url=~/^\/*uploaded\//);
4237: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4238: my $isfolder;
4239: my $ispage;
4240: my $containerarg;
1.615 raeburn 4241: my $folderurl;
1.685 raeburn 4242: my $plainurl;
1.329 droeschl 4243: if ($uploaded) {
1.472 raeburn 4244: if (($extension eq 'sequence') || ($extension eq 'page')) {
4245: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4246: $containerarg = $1;
1.472 raeburn 4247: if ($extension eq 'sequence') {
4248: $icon=$iconpath.'navmap.folder.closed.gif';
4249: $isfolder=1;
4250: } else {
4251: $icon=$iconpath.'page.gif';
4252: $ispage=1;
4253: }
1.615 raeburn 4254: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4255: if ($allowed) {
4256: $url='/adm/coursedocs?';
4257: } else {
4258: $url='/adm/supplemental?';
4259: }
1.329 droeschl 4260: } else {
1.685 raeburn 4261: $plainurl = $url;
1.329 droeschl 4262: }
4263: }
1.364 bisitz 4264:
1.621 raeburn 4265: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4266: my $orig_url = $url;
1.340 raeburn 4267: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 4268: if ($container eq 'page') {
4269: $url=~s{^http(|s)(:|:)//}{/ext/};
4270: } else {
4271: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4272: }
1.501 raeburn 4273: if (!$supplementalflag && $residx && $symb) {
4274: if ((!$isfolder) && (!$ispage)) {
4275: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 4276: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4277: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4278: } else {
4279: $url=&Apache::lonnet::clutter($url);
4280: }
1.501 raeburn 4281: if ($url=~/^\/*uploaded\//) {
4282: $url=~/\.(\w+)$/;
4283: my $embstyle=&Apache::loncommon::fileembstyle($1);
4284: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4285: $url='/adm/wrapper'.$url;
4286: } elsif ($embstyle eq 'ssi') {
4287: #do nothing with these
4288: } elsif ($url!~/\.(sequence|page)$/) {
4289: $url='/adm/coursedocs/showdoc'.$url;
4290: }
1.623 raeburn 4291: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4292: my $wrapped = $1;
4293: my $exturl = $2;
1.668 raeburn 4294: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 4295: $url='/adm/wrapper'.$url;
4296: }
4297: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4298: $nomodal = 1;
4299: }
1.626 raeburn 4300: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4301: $url='/adm/wrapper'.$url;
1.621 raeburn 4302: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4303: if (($ENV{'SERVER_PORT'} == 443) &&
4304: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4305: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4306: $url .= '?usehttp=1';
4307: }
1.621 raeburn 4308: $nomodal = 1;
4309: }
1.598 raeburn 4310: }
1.696 raeburn 4311: my $checkencrypt;
1.680 raeburn 4312: if (!$env{'request.role.adv'}) {
1.615 raeburn 4313: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 4314: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 4315: $checkencrypt = 1;
1.620 raeburn 4316: } elsif (ref($navmapref)) {
1.615 raeburn 4317: unless (ref($$navmapref)) {
4318: $$navmapref = Apache::lonnavmaps::navmap->new();
4319: }
4320: if (ref($$navmapref)) {
4321: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 4322: $checkencrypt = 1;
1.615 raeburn 4323: }
4324: }
4325: }
1.680 raeburn 4326: }
4327: if ($checkencrypt) {
4328: my $currenc = $env{'request.enc'};
4329: $env{'request.enc'} = 1;
4330: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 4331: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 4332: if (&Apache::lonnet::symbverify($symb,$url)) {
4333: $url = $shownurl;
4334: } else {
4335: $url = '';
4336: }
4337: $env{'request.enc'} = $currenc;
4338: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4339: $shownsymb = $symb;
4340: if ($isexternal) {
4341: $url =~ s/\#[^#]+$//;
4342: if ($container eq 'page') {
4343: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 4344: }
1.612 raeburn 4345: }
1.696 raeburn 4346: } else {
4347: $url = '';
1.680 raeburn 4348: }
4349: unless ($env{'request.role.adv'}) {
4350: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4351: $url = '';
4352: }
4353: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4354: $url = '';
4355: $hiddenres = 1;
4356: }
4357: }
1.696 raeburn 4358: if (($url ne '') && ($shownsymb ne '')) {
4359: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 4360: }
1.329 droeschl 4361: }
1.621 raeburn 4362: } elsif ($supplementalflag) {
1.610 raeburn 4363: if ($isexternal) {
4364: if ($url =~ /^([^#]+)#([^#]+)$/) {
4365: $url = $1;
4366: $anchor = $2;
1.623 raeburn 4367: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 4368: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4369: if ($hostname ne '') {
4370: $url = 'http://'.$hostname.$url;
4371: }
4372: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 4373: }
4374: $nomodal = 1;
4375: }
1.610 raeburn 4376: }
1.621 raeburn 4377: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4378: if (($ENV{'SERVER_PORT'} == 443) &&
4379: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4380: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4381: if ($hostname ne '') {
4382: $url = 'http://'.$hostname.$url;
4383: }
4384: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 4385: }
1.621 raeburn 4386: $nomodal = 1;
4387: }
1.686 raeburn 4388: } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
4389: my $embstyle=&Apache::loncommon::fileembstyle($extension);
4390: unless ($embstyle eq 'ssi') {
4391: if (($embstyle eq 'img')
4392: || ($embstyle eq 'emb')
4393: || ($embstyle eq 'wrp')) {
4394: $url='/adm/wrapper'.$url;
4395: } elsif ($url !~ /\.(sequence|page)$/) {
4396: $url='/adm/coursedocs/showdoc'.$url;
4397: }
4398: }
1.610 raeburn 4399: }
1.685 raeburn 4400: unless ($allowed && $env{'request.role.adv'}) {
4401: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4402: $hiddenres = 1;
4403: }
4404: }
1.329 droeschl 4405: }
1.615 raeburn 4406: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4407: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4408: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4409: my $foldername=&escape($foldertitle);
4410: my $folderpath=$env{'form.folderpath'};
4411: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4412: if (!$allowed && $supplementalflag) {
1.519 raeburn 4413: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4414: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 4415: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4416: $hiddenfolder = 1;
1.682 raeburn 4417: }
1.510 raeburn 4418: } else {
1.617 raeburn 4419: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4420: 'parameter_randompick'))[0];
4421: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4422: 'parameter_randomorder'))[0]=~/^yes$/i);
4423: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4424: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4425: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4426: 'parameter_encrypturl'))[0]=~/^yes$/i);
4427: unless ($hiddenmap) {
1.620 raeburn 4428: if (ref($navmapref)) {
4429: unless (ref($$navmapref)) {
4430: $$navmapref = Apache::lonnavmaps::navmap->new();
4431: }
4432: if (ref($$navmapref)) {
4433: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4434: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4435: unless (@resources) {
4436: $hiddenmap = 1;
4437: unless ($env{'request.role.adv'}) {
4438: $url = '';
4439: $hiddenfolder = 1;
4440: }
1.617 raeburn 4441: }
1.615 raeburn 4442: }
4443: }
4444: }
4445: }
1.617 raeburn 4446: unless ($encryptmap) {
1.620 raeburn 4447: if ((ref($navmapref)) && (ref($$navmapref))) {
4448: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4449: $encryptmap = 1;
4450: }
1.617 raeburn 4451: }
4452: }
1.630 raeburn 4453:
1.617 raeburn 4454: # Append randompick number, hidden, and encrypted with ":" to foldername,
4455: # so it gets transferred between levels
4456: $folderpath.=$containerarg.'&'.$foldername.
4457: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4458: unless ($url eq '') {
1.612 raeburn 4459: $url.='folderpath='.&escape($folderpath);
4460: }
1.510 raeburn 4461: my $rpckchk;
4462: if ($rpicknum) {
4463: $rpckchk = ' checked="checked"';
1.543 raeburn 4464: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4465: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4466: }
1.510 raeburn 4467: }
1.537 raeburn 4468: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4469: $rand_pick_text =
1.478 raeburn 4470: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4471: $form_param."\n".
1.478 raeburn 4472: $form_common."\n".
1.611 raeburn 4473: '<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 4474: if ($rpicknum ne '') {
4475: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4476: }
1.537 raeburn 4477: $rand_pick_text .= '</span></span>'.
4478: $form_end;
1.543 raeburn 4479: my $ro_set;
1.617 raeburn 4480: if ($randorder) {
1.543 raeburn 4481: $ro_set = 'checked="checked"';
4482: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4483: push(@{$filtersref->{'randomorder'}},$orderidx);
4484: }
4485: }
1.564 raeburn 4486: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4487: $rand_order_text =
1.537 raeburn 4488: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4489: $form_param."\n".
1.537 raeburn 4490: $form_common."\n".
1.611 raeburn 4491: '<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 4492: $form_end;
1.510 raeburn 4493: }
1.509 raeburn 4494: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4495: my $isexttool;
1.626 raeburn 4496: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4497: $url='/adm/wrapper'.$url;
4498: $isexttool = 1;
4499: }
1.510 raeburn 4500: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4501: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4502: if ($title) {
1.687 raeburn 4503: $url .= '&title='.$encodedtitle;
1.510 raeburn 4504: }
1.598 raeburn 4505: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4506: $url .= '&idx='.$orderidx;
4507: }
1.610 raeburn 4508: if ($anchor ne '') {
4509: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4510: }
1.329 droeschl 4511: }
1.519 raeburn 4512: my ($tdalign,$tdwidth);
1.501 raeburn 4513: if ($allowed) {
1.630 raeburn 4514: my $fileloc =
1.501 raeburn 4515: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4516: if ($isexternal) {
1.630 raeburn 4517: ($editlink,$extresform) =
1.611 raeburn 4518: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4519: undef,undef,undef,undef,undef,undef,
4520: undef,$disabled);
1.626 raeburn 4521: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4522: ($editlink,$extresform) =
4523: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4524: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4525: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4526: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4527: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4528: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4529: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4530: my $suppanchor;
4531: if ($supplementalflag) {
4532: $suppanchor = $anchor;
4533: }
1.630 raeburn 4534: my $jscall =
1.501 raeburn 4535: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4536: $switchserver,
1.503 raeburn 4537: $forceedit,
1.679 raeburn 4538: undef,$symb,$shownsymb,
1.511 raeburn 4539: &escape($env{'form.folderpath'}),
1.622 raeburn 4540: $renametitle,$hostname,
4541: '','',1,$suppanchor);
1.501 raeburn 4542: if ($jscall) {
1.518 raeburn 4543: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4544: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4545: }
4546: }
4547: }
1.519 raeburn 4548: $tdalign = ' align="right" valign="top"';
4549: $tdwidth = ' width="80%"';
1.329 droeschl 4550: }
1.408 raeburn 4551: my $reinit;
4552: if ($crstype eq 'Community') {
4553: $reinit = &mt('(re-initialize community to access)');
4554: } else {
4555: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4556: }
1.702 ! raeburn 4557: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
1.650 raeburn 4558: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 4559: $line.= '<br />';
4560: if ($curralias ne '') {
4561: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4562: $lt{'da'}.'</a></span>';
4563: } else {
4564: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4565: $lt{'sa'}.'</a></span>';
4566: }
4567: }
1.701 raeburn 4568: $line.='</td><td><span class="LC_nobreak">';
1.685 raeburn 4569: my ($link,$nolink);
1.472 raeburn 4570: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4571: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
4572: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4573: $nolink = 1;
4574: }
4575: }
4576: if ($nolink) {
4577: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4578: } else {
4579: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4580: }
1.469 www 4581: } elsif ($url) {
1.610 raeburn 4582: if ($anchor ne '') {
4583: if ($supplementalflag) {
4584: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4585: } else {
4586: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4587: }
4588: }
1.622 raeburn 4589: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4590: $link = 'http://'.$hostname.$url;
4591: } else {
4592: $link = $url;
4593: }
1.659 raeburn 4594: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.685 raeburn 4595: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
4596: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4597: $nolink = 1;
4598: }
4599: }
4600: if ($nolink) {
4601: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4602: } elsif ($nomodal) {
1.621 raeburn 4603: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4604: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4605: } else {
4606: $line.=&Apache::loncommon::modal_link($link,
4607: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4608: }
1.469 www 4609: } else {
4610: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4611: }
1.519 raeburn 4612: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4613: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4614: if ($nolink) {
4615: $line.=$title;
4616: } else {
4617: $line.='<a href="'.$url.'">'.$title.'</a>';
4618: }
1.682 raeburn 4619: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4620: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4621: my $editurl = $url;
4622: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4623: $line .= ' '.'<a href="'.$editurl.'">'.
4624: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4625: '</a>';
4626: }
4627: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4628: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4629: }
1.469 www 4630: } elsif ($url) {
1.685 raeburn 4631: if ($nolink) {
4632: $line.=$title;
4633: } elsif ($nomodal) {
1.621 raeburn 4634: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4635: $title.'</a>';
4636: } else {
4637: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4638: }
1.617 raeburn 4639: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4640: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4641: } else {
4642: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4643: }
1.633 raeburn 4644: if (($allowed) && ($curralias ne '')) {
4645: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4646: } else {
4647: $line .= $extresform;
4648: }
4649: $line .= '</td>';
1.478 raeburn 4650: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4651: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 4652: if ($uploaded && $url && !$isfolder && !$ispage) {
4653: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
4654: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
4655: }
4656: }
1.682 raeburn 4657: if ($allowed) {
4658: my %lt=&Apache::lonlocal::texthash(
4659: 'hd' => 'Hidden',
4660: 'ec' => 'URL hidden');
4661: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 4662: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4663: $hidtext = ' checked="checked"';
1.694 raeburn 4664: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 4665: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4666: }
4667: }
1.682 raeburn 4668: $formhidden = 'edit_hiddenresource_'.$orderidx;
4669: $line.=(<<ENDPARMS);
1.329 droeschl 4670: <td class="LC_docs_entry_parameter">
1.537 raeburn 4671: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4672: $form_param
1.478 raeburn 4673: $form_common
1.611 raeburn 4674: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4675: $form_end
1.682 raeburn 4676: ENDPARMS
4677: if ($folder =~/^supplemental/) {
4678: $line.= "\n <td>";
4679: } else {
4680: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4681: $enctext = ' checked="checked"';
4682: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4683: push(@{$filtersref->{'encrypturl'}},$orderidx);
4684: }
4685: }
4686: $formurlhidden = 'edit_encrypturl_'.$orderidx;
4687: $line.=(<<ENDPARMS);
1.458 raeburn 4688: <br />
1.537 raeburn 4689: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4690: $form_param
1.478 raeburn 4691: $form_common
1.611 raeburn 4692: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4693: $form_end
4694: </td>
1.478 raeburn 4695: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4696: $rand_order_text</td>
1.329 droeschl 4697: ENDPARMS
1.682 raeburn 4698: }
1.329 droeschl 4699: }
1.379 bisitz 4700: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4701: return $line;
4702: }
4703:
1.538 raeburn 4704: sub action_restrictions {
4705: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4706: my %denied = (
4707: cut => 0,
4708: copy => 0,
4709: remove => 0,
4710: );
4711: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4712: # no copy for published maps
4713: $denied{'copy'} = 1;
1.597 raeburn 4714: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4715: unless ($1 eq 'simpleproblem') {
4716: $denied{'copy'} = 1;
4717: }
4718: $denied{'cut'} = 1;
1.538 raeburn 4719: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4720: if ($folderpath =~ /^default&[^\&]+$/) {
4721: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4722: $denied{'remove'} = 1;
4723: }
4724: $denied{'cut'} = 1;
4725: $denied{'copy'} = 1;
4726: }
4727: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4728: my $group = $1;
4729: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4730: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4731: $denied{'remove'} = 1;
4732: }
4733: }
4734: $denied{'cut'} = 1;
4735: $denied{'copy'} = 1;
4736: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4737: my $group = $1;
4738: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4739: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4740: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4741: if (keys(%groupsettings) > 0) {
4742: $denied{'remove'} = 1;
4743: }
4744: $denied{'cut'} = 1;
4745: $denied{'copy'} = 1;
4746: }
4747: }
4748: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4749: my $group = $1;
4750: if ($url =~ /group_boards_\Q$group\E/) {
4751: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4752: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4753: if (keys(%groupsettings) > 0) {
4754: if (ref($groupsettings{'functions'}) eq 'HASH') {
4755: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4756: $denied{'remove'} = 1;
4757: }
4758: }
4759: }
4760: $denied{'cut'} = 1;
4761: $denied{'copy'} = 1;
4762: }
4763: }
4764: }
4765: return %denied;
4766: }
4767:
1.533 raeburn 4768: sub new_timebased_suffix {
1.538 raeburn 4769: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4770: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4771: if ($type eq 'paste') {
4772: $prefix = $type;
4773: $namespace = 'courseeditor';
1.587 raeburn 4774: $idtype = 'addcode';
1.538 raeburn 4775: } elsif ($type eq 'map') {
1.533 raeburn 4776: $prefix = 'docs';
4777: if ($area eq 'supplemental') {
4778: $prefix = 'supp';
4779: }
4780: $prefix .= $container;
4781: $namespace = 'uploadedmaps';
4782: } else {
4783: $prefix = $type;
4784: $namespace = 'templated';
1.504 raeburn 4785: }
4786: my ($suffix,$freedlock,$error) =
1.587 raeburn 4787: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4788: if (!$suffix) {
1.538 raeburn 4789: if ($type eq 'paste') {
4790: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4791: } elsif ($type eq 'map') {
1.533 raeburn 4792: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4793: } elsif ($type eq 'smppg') {
4794: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4795: } elsif ($type eq 'exttool') {
4796: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4797: } else {
1.565 bisitz 4798: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4799: }
1.504 raeburn 4800: if ($error) {
4801: $errtext .= '<br />'.$error;
4802: }
4803: }
4804: if ($freedlock ne 'ok') {
1.630 raeburn 4805: $locknotfreed =
1.533 raeburn 4806: '<div class="LC_error">'.
4807: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4808: if ($type eq 'paste') {
1.591 raeburn 4809: if ($freedlock eq 'nolock') {
4810: $locknotfreed =
4811: '<div class="LC_error">'.
4812: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4813:
1.593 droeschl 4814: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4815: } else {
4816: $locknotfreed .=
4817: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4818: }
1.538 raeburn 4819: } elsif ($type eq 'map') {
1.591 raeburn 4820: $locknotfreed .=
4821: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4822: } elsif ($type eq 'smppg') {
4823: $locknotfreed .=
4824: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4825: } elsif ($type eq 'exttool') {
4826: $locknotfreed .=
4827: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4828: } else {
4829: $locknotfreed .=
1.565 bisitz 4830: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4831: }
1.538 raeburn 4832: unless ($type eq 'paste') {
4833: $locknotfreed .=
1.560 raeburn 4834: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4835: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4836: }
4837: $locknotfreed .= '</div>';
1.504 raeburn 4838: }
4839: return ($suffix,$errtext,$locknotfreed);
4840: }
4841:
1.329 droeschl 4842: =pod
4843:
4844: =item tiehash()
4845:
4846: tie the hash
4847:
4848: =cut
4849:
4850: sub tiehash {
4851: my ($mode)=@_;
4852: $hashtied=0;
4853: if ($env{'request.course.fn'}) {
4854: if ($mode eq 'write') {
4855: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4856: &GDBM_WRCREAT(),0640)) {
4857: $hashtied=2;
4858: }
4859: } else {
4860: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4861: &GDBM_READER(),0640)) {
4862: $hashtied=1;
4863: }
4864: }
1.364 bisitz 4865: }
1.329 droeschl 4866: }
4867:
4868: sub untiehash {
4869: if ($hashtied) { untie %hash; }
4870: $hashtied=0;
4871: return OK;
4872: }
4873:
4874:
4875:
4876:
4877: sub checkonthis {
1.637 raeburn 4878: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4879: $url=&unescape($url);
4880: $alreadyseen{$url}=1;
4881: $r->rflush();
4882: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4883: $r->print("\n<br />");
4884: if ($level==0) {
4885: $r->print("<br />");
4886: }
4887: for (my $i=0;$i<=$level*5;$i++) {
4888: $r->print(' ');
4889: }
4890: $r->print('<a href="'.$url.'" target="cat">'.
4891: ($title?$title:$url).'</a> ');
4892: if ($url=~/^\/res\//) {
1.637 raeburn 4893: my $updated;
4894: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4895: ($url !~ /\.\d+\.\w+$/)) {
4896: $updated = &Apache::lonnet::remove_stale_resfile($url);
4897: }
1.329 droeschl 4898: my $result=&Apache::lonnet::repcopy(
4899: &Apache::lonnet::filelocation('',$url));
4900: if ($result eq 'ok') {
4901: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4902: if ($updated) {
4903: $r->print('<br />');
4904: for (my $i=0;$i<=$level*5;$i++) {
4905: $r->print(' ');
4906: }
4907: $r->print('- '.&mt('Outdated copy removed'));
4908: }
1.329 droeschl 4909: $r->rflush();
4910: &Apache::lonnet::countacc($url);
4911: $url=~/\.(\w+)$/;
4912: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4913: $r->print('<br />');
4914: $r->rflush();
4915: for (my $i=0;$i<=$level*5;$i++) {
4916: $r->print(' ');
4917: }
4918: $r->print('- '.&mt('Rendering:').' ');
4919: my ($errorcount,$warningcount)=split(/:/,
4920: &Apache::lonnet::ssi_body($url,
4921: ('grade_target'=>'web',
4922: 'return_only_error_and_warning_counts' => 1)));
4923: if (($errorcount) ||
4924: ($warningcount)) {
4925: if ($errorcount) {
1.369 bisitz 4926: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4927: &mt('[quant,_1,error]',$errorcount).'</span>');
4928: }
4929: if ($warningcount) {
4930: $r->print('<span class="LC_warning">'.
4931: &mt('[quant,_1,warning]',$warningcount).'</span>');
4932: }
4933: } else {
4934: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4935: }
4936: $r->rflush();
4937: }
4938: my $dependencies=
4939: &Apache::lonnet::metadata($url,'dependencies');
4940: foreach my $dep (split(/\,/,$dependencies)) {
4941: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4942: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4943: }
4944: }
4945: } elsif ($result eq 'unavailable') {
4946: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4947: } elsif ($result eq 'not_found') {
4948: unless ($url=~/\$/) {
1.521 bisitz 4949: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4950: } else {
1.366 bisitz 4951: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4952: }
4953: } else {
4954: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4955: }
1.637 raeburn 4956: if (($updated) && ($result ne 'ok')) {
4957: $r->print('<br />'.&mt('Outdated copy removed'));
4958: }
1.329 droeschl 4959: }
4960: }
4961: }
4962:
4963:
4964:
4965: =pod
4966:
4967: =item list_symbs()
4968:
1.485 raeburn 4969: List Content Identifiers
1.329 droeschl 4970:
4971: =cut
4972:
4973: sub list_symbs {
4974: my ($r) = @_;
4975:
1.408 raeburn 4976: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4977: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4978: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4979: $r->print(&startContentScreen('tools'));
1.329 droeschl 4980: my $navmap = Apache::lonnavmaps::navmap->new();
4981: if (!defined($navmap)) {
4982: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4983: '<div class="LC_error">'.
4984: &mt('Unable to retrieve information about course contents').
4985: '</div>');
1.408 raeburn 4986: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4987: } else {
1.484 raeburn 4988: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4989: &Apache::loncommon::start_data_table().
4990: &Apache::loncommon::start_data_table_header_row().
4991: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4992: &Apache::loncommon::end_data_table_header_row()."\n");
4993: my $count;
1.329 droeschl 4994: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4995: $r->print(&Apache::loncommon::start_data_table_row().
4996: '<td>'.$res->compTitle().'</td>'.
4997: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4998: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4999: $count ++;
5000: }
5001: if (!$count) {
5002: $r->print(&Apache::loncommon::start_data_table_row().
5003: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
5004: &Apache::loncommon::end_data_table_row());
1.329 droeschl 5005: }
1.484 raeburn 5006: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 5007: }
1.521 bisitz 5008: $r->print(&endContentScreen());
1.329 droeschl 5009: }
5010:
1.651 raeburn 5011: sub short_urls {
5012: my ($r,$canedit) = @_;
5013: my $crstype = &Apache::loncommon::course_type();
5014: my $formname = 'shortenurl';
5015: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5016: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5017: $r->print(&startContentScreen('tools'));
5018: my ($navmap,$errormsg) =
5019: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5020: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5021: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5022: my (%maps,%resources,%titles);
5023: if (!ref($navmap)) {
5024: $r->print($errormsg.
5025: &endContentScreen());
5026: return '';
5027: } else {
1.652 raeburn 5028: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 5029: $r->rflush();
5030: my $readonly;
5031: if ($canedit) {
1.671 raeburn 5032: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 5033: if ($numnew) {
5034: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
5035: }
5036: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
5037: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
5038: foreach my $error (@{$errors}) {
5039: $r->print('<li>'.$error.'</li>');
5040: }
5041: $r->print('</ul><br />');
5042: }
5043: } else {
5044: $readonly = 1;
5045: }
5046: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
5047: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
5048: undef,undef,undef,undef,undef,\%currtiny,$readonly));
5049: }
5050: $r->print(&endContentScreen());
5051: }
5052:
1.637 raeburn 5053: sub contentverifyform {
5054: my ($r) = @_;
5055: my $crstype = &Apache::loncommon::course_type();
5056: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5057: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5058: $r->print(&startContentScreen('tools'));
5059: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5060: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
5061: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
5062: ' <span class="LC_nobreak">'.
5063: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
5064: &mt('No').'</label>'.(' 'x2).
5065: '<label><input type="radio" name="checkstale" value="1" />'.
5066: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 5067: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 5068: '<input type="hidden" value="1" name="tools" />'.
5069: '<input type="hidden" value="1" name="verify" /></p></form>');
5070: $r->print(&endContentScreen());
5071: return;
5072: }
1.329 droeschl 5073:
5074: sub verifycontent {
1.637 raeburn 5075: my ($r,$checkstale) = @_;
1.408 raeburn 5076: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 5077: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5078: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 5079: $r->print(&startContentScreen('tools'));
5080: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 5081: $hashtied=0;
5082: undef %alreadyseen;
5083: %alreadyseen=();
5084: &tiehash();
1.484 raeburn 5085:
1.329 droeschl 5086: foreach my $key (keys(%hash)) {
5087: if ($hash{$key}=~/\.(page|sequence)$/) {
5088: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5089: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 5090: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 5091: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 5092: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 5093: }
5094: }
5095: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 5096: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 5097: }
5098: }
5099: &untiehash();
1.442 www 5100: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 5101: $r->print(&endContentScreen());
1.329 droeschl 5102: }
5103:
5104: sub devalidateversioncache {
5105: my $src=shift;
5106: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5107: &Apache::lonnet::clutter($src));
5108: }
5109:
5110: sub checkversions {
1.611 raeburn 5111: my ($r,$canedit) = @_;
1.408 raeburn 5112: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 5113: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5114: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 5115: $r->print(&startContentScreen('tools'));
1.442 www 5116:
1.329 droeschl 5117: my $header='';
5118: my $startsel='';
5119: my $monthsel='';
5120: my $weeksel='';
5121: my $daysel='';
5122: my $allsel='';
5123: my %changes=();
5124: my $starttime=0;
5125: my $haschanged=0;
5126: my %setversions=&Apache::lonnet::dump('resourceversions',
5127: $env{'course.'.$env{'request.course.id'}.'.domain'},
5128: $env{'course.'.$env{'request.course.id'}.'.num'});
5129:
5130: $hashtied=0;
5131: &tiehash();
1.611 raeburn 5132: if ($canedit) {
5133: my %newsetversions=();
5134: if ($env{'form.setmostrecent'}) {
5135: $haschanged=1;
5136: foreach my $key (keys(%hash)) {
5137: if ($key=~/^ids\_(\/res\/.+)$/) {
5138: $newsetversions{$1}='mostrecent';
5139: &devalidateversioncache($1);
5140: }
5141: }
5142: } elsif ($env{'form.setcurrent'}) {
5143: $haschanged=1;
5144: foreach my $key (keys(%hash)) {
5145: if ($key=~/^ids\_(\/res\/.+)$/) {
5146: my $getvers=&Apache::lonnet::getversion($1);
5147: if ($getvers>0) {
5148: $newsetversions{$1}=$getvers;
5149: &devalidateversioncache($1);
5150: }
5151: }
1.329 droeschl 5152: }
1.611 raeburn 5153: } elsif ($env{'form.setversions'}) {
5154: $haschanged=1;
5155: foreach my $key (keys(%env)) {
5156: if ($key=~/^form\.set_version_(.+)$/) {
5157: my $src=$1;
5158: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5159: $newsetversions{$src}=$env{$key};
5160: &devalidateversioncache($src);
5161: }
5162: }
1.329 droeschl 5163: }
1.611 raeburn 5164: }
5165: if ($haschanged) {
5166: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5167: $env{'course.'.$env{'request.course.id'}.'.domain'},
5168: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5169: $r->print(&Apache::loncommon::confirmwrapper(
5170: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5171: } else {
5172: $r->print(&Apache::loncommon::confirmwrapper(
5173: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 5174: }
1.611 raeburn 5175: &mark_hash_old();
5176: }
5177: &changewarning($r,'');
1.329 droeschl 5178: }
5179: if ($env{'form.timerange'} eq 'all') {
5180: # show all documents
1.549 raeburn 5181: $header=&mt('All content in '.$crstype);
1.521 bisitz 5182: $allsel=' selected="selected"';
1.329 droeschl 5183: foreach my $key (keys(%hash)) {
5184: if ($key=~/^ids\_(\/res\/.+)$/) {
5185: my $src=$1;
5186: $changes{$src}=1;
5187: }
5188: }
5189: } else {
5190: # show documents which changed
5191: %changes=&Apache::lonnet::dump
5192: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5193: $env{'course.'.$env{'request.course.id'}.'.num'});
5194: my $firstkey=(keys(%changes))[0];
5195: unless ($firstkey=~/^error\:/) {
5196: unless ($env{'form.timerange'}) {
5197: $env{'form.timerange'}=604800;
5198: }
5199: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5200: .&mt('seconds');
5201: if ($env{'form.timerange'}==-1) {
5202: $seltext='since start of course';
1.521 bisitz 5203: $startsel=' selected="selected"';
1.329 droeschl 5204: $env{'form.timerange'}=time;
5205: }
5206: $starttime=time-$env{'form.timerange'};
5207: if ($env{'form.timerange'}==2592000) {
5208: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5209: $monthsel=' selected="selected"';
1.329 droeschl 5210: } elsif ($env{'form.timerange'}==604800) {
5211: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5212: $weeksel=' selected="selected"';
1.329 droeschl 5213: } elsif ($env{'form.timerange'}==86400) {
5214: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5215: $daysel=' selected="selected"';
1.329 droeschl 5216: }
5217: $header=&mt('Content changed').' '.$seltext;
5218: } else {
5219: $header=&mt('No content modifications yet.');
5220: }
5221: }
5222: %setversions=&Apache::lonnet::dump('resourceversions',
5223: $env{'course.'.$env{'request.course.id'}.'.domain'},
5224: $env{'course.'.$env{'request.course.id'}.'.num'});
5225: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5226: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5227: 'lm' => 'Version changes since last Month',
5228: 'lw' => 'Version changes since last Week',
5229: 'sy' => 'Version changes since Yesterday',
5230: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5231: 'cd' => 'Change display',
1.329 droeschl 5232: 'sd' => 'Display',
5233: 'fi' => 'File',
5234: 'md' => 'Modification Date',
5235: 'mr' => 'Most recently published Version',
1.408 raeburn 5236: 've' => 'Version used in '.$crstype,
5237: 'vu' => 'Set Version to be used in '.$crstype,
5238: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5239: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5240: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5241: 'di' => 'Differences',
1.484 raeburn 5242: 'save' => 'Save changes',
5243: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5244: 'act' => 'Actions');
1.611 raeburn 5245: my ($disabled,$readonly);
5246: unless ($canedit) {
5247: $disabled = 'disabled="disabled"';
5248: $readonly = 1;
5249: }
1.329 droeschl 5250: $r->print(<<ENDHEADERS);
1.484 raeburn 5251: <h4 class="LC_info">$header</h4>
1.329 droeschl 5252: <form action="/adm/coursedocs" method="post">
5253: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5254: <div class="LC_left_float">
1.479 golterma 5255: <fieldset>
1.484 raeburn 5256: <legend>$lt{'cd'}</legend>
1.329 droeschl 5257: <select name="timerange">
1.521 bisitz 5258: <option value='all'$allsel>$lt{'al'}</option>
5259: <option value="-1"$startsel>$lt{'st'}</option>
5260: <option value="2592000"$monthsel>$lt{'lm'}</option>
5261: <option value="604800"$weeksel>$lt{'lw'}</option>
5262: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5263: </select>
5264: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5265: </fieldset>
5266: </div>
5267: <div class="LC_left_float">
5268: <fieldset>
5269: <legend>$lt{'act'}</legend>
1.611 raeburn 5270: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5271: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5272: </fieldset>
5273: </div>
5274: <br clear="all" />
5275: <hr />
5276: <h4>$lt{'vers'}</h4>
1.329 droeschl 5277: ENDHEADERS
1.479 golterma 5278: #number of columns for version history
1.571 raeburn 5279: my %changedbytime;
5280: foreach my $key (keys(%changes)) {
5281: #excludes not versionable problems from resource version history:
5282: next if ($key =~ /^\/res\/lib\/templates/);
5283: my $chg;
5284: if ($env{'form.timerange'} eq 'all') {
5285: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5286: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5287: } else {
5288: $chg = $changes{$key};
5289: next if ($chg < $starttime);
5290: }
5291: push(@{$changedbytime{$chg}},$key);
5292: }
5293: if (keys(%changedbytime) == 0) {
5294: &untiehash();
5295: $r->print(&mt('No content changes in imported content in specified time frame').
5296: &endContentScreen());
5297: return;
5298: }
1.479 golterma 5299: $r->print(
1.611 raeburn 5300: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5301: &Apache::loncommon::start_data_table().
5302: &Apache::loncommon::start_data_table_header_row().
5303: '<th>'.&mt('Resources').'</th>'.
5304: "<th>$lt{'mr'}</th>".
5305: "<th>$lt{'ve'}</th>".
5306: "<th>$lt{'vu'}</th>".
5307: '<th>'.&mt('History').'</th>'.
5308: &Apache::loncommon::end_data_table_header_row()
5309: );
1.571 raeburn 5310: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5311: foreach my $key (sort(@{$changedbytime{$chg}})) {
5312: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5313: my $currentversion=&Apache::lonnet::getversion($key);
5314: if ($currentversion<0) {
5315: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5316: }
5317: my $linkurl=&Apache::lonnet::clutter($key);
5318: $r->print(
5319: &Apache::loncommon::start_data_table_row().
5320: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5321: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5322: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5323: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5324: '<td align="right">'
5325: );
5326: # Used in course
5327: my $usedversion=$hash{'version_'.$linkurl};
5328: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5329: if ($usedversion != $currentversion) {
1.479 golterma 5330: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5331: } else {
1.479 golterma 5332: $r->print($usedversion);
5333: }
1.329 droeschl 5334: } else {
1.521 bisitz 5335: $r->print($currentversion);
1.329 droeschl 5336: }
1.571 raeburn 5337: $r->print('</td><td title="'.$lt{'vu'}.'">');
5338: # Set version
5339: $r->print(&Apache::loncommon::select_form(
5340: $setversions{$linkurl},
5341: 'set_version_'.$linkurl,
5342: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5343: '' => '',
5344: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5345: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5346: my $lastold=1;
5347: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5348: my $url=$root.'.'.$prevvers.'.'.$extension;
5349: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5350: $lastold=$prevvers;
5351: }
5352: }
5353: $r->print('</td>');
5354: # List all available versions
5355: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5356: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5357: my $url=$root.'.'.$prevvers.'.'.$extension;
5358: $r->print(
5359: '<span class="LC_nobreak">'
5360: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5361: .&mt('Version [_1]',$prevvers).'</a>'
5362: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5363: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5364: .')');
5365: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5366: $r->print(
5367: ' <a href="/adm/diff?filename='.
5368: &Apache::lonnet::clutter($root.'.'.$extension).
5369: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5370: '" target="diffs">'.&mt('Diffs').'</a>');
5371: }
5372: $r->print('</span><br />');
1.329 droeschl 5373: }
1.571 raeburn 5374: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5375: }
1.329 droeschl 5376: }
1.521 bisitz 5377: $r->print(
5378: &Apache::loncommon::end_data_table().
1.611 raeburn 5379: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5380: '</form>'
5381: );
1.329 droeschl 5382:
5383: &untiehash();
1.521 bisitz 5384: $r->print(&endContentScreen());
1.571 raeburn 5385: return;
1.329 droeschl 5386: }
5387:
5388: sub mark_hash_old {
5389: my $retie_hash=0;
5390: if ($hashtied) {
5391: $retie_hash=1;
5392: &untiehash();
5393: }
5394: &tiehash('write');
5395: $hash{'old'}=1;
5396: &untiehash();
5397: if ($retie_hash) { &tiehash(); }
5398: }
5399:
5400: sub is_hash_old {
5401: my $untie_hash=0;
5402: if (!$hashtied) {
5403: $untie_hash=1;
5404: &tiehash();
5405: }
5406: my $return=$hash{'old'};
5407: if ($untie_hash) { &untiehash(); }
5408: return $return;
5409: }
5410:
5411: sub changewarning {
5412: my ($r,$postexec,$message,$url)=@_;
5413: if (!&is_hash_old()) { return; }
5414: my $pathvar='folderpath';
5415: my $path=&escape($env{'form.folderpath'});
5416: if (!defined($url)) {
5417: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5418: }
5419: my $course_type = &Apache::loncommon::course_type();
5420: if (!defined($message)) {
5421: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5422: }
1.653 raeburn 5423: my $windowname = 'loncapaclient';
5424: if ($env{'request.lti.login'}) {
5425: $windowname .= 'lti';
5426: }
1.329 droeschl 5427: $r->print("\n\n".
1.372 bisitz 5428: '<script type="text/javascript">'."\n".
5429: '// <![CDATA['."\n".
5430: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5431: '// ]]>'."\n".
1.369 bisitz 5432: '</script>'."\n".
1.653 raeburn 5433: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5434: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5435: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5436: &mt($message,' <input type="hidden" name="'.
5437: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5438: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5439: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5440: }
5441:
5442:
5443: sub init_breadcrumbs {
1.571 raeburn 5444: my ($form,$text,$help)=@_;
1.329 droeschl 5445: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5446: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5447: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5448: faq=>273,
5449: bug=>'Instructor Interface',
1.571 raeburn 5450: help => $help});
1.329 droeschl 5451: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5452: text=>$text,
5453: faq=>273,
5454: bug=>'Instructor Interface'});
5455: }
5456:
1.441 www 5457: # subroutine to list form elements
5458: sub create_list_elements {
5459: my @formarr = @_;
5460: my $list = '';
1.501 raeburn 5461: foreach my $button (@formarr){
5462: foreach my $picture (keys(%{$button})) {
5463: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5464: }
5465: }
5466: return $list;
5467: }
1.329 droeschl 5468:
1.441 www 5469: # subroutine to create ul from list elements
5470: sub create_form_ul {
5471: my $list = shift;
5472: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5473: return $ul;
5474: }
1.329 droeschl 5475:
1.442 www 5476: #
5477: # Start tabs
5478: #
5479:
5480: sub startContentScreen {
1.484 raeburn 5481: my ($mode) = @_;
5482: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5483: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5484: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5485: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5486: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5487: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5488: } else {
1.549 raeburn 5489: $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 5490: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5491: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5492: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5493: }
5494: $output .= "\n".'</ul>'."\n";
5495: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5496: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5497: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5498: return $output;
1.442 www 5499: }
5500:
5501: #
5502: # End tabs
5503: #
5504:
5505: sub endContentScreen {
1.484 raeburn 5506: return '</div></div></div>';
1.442 www 5507: }
1.329 droeschl 5508:
1.446 www 5509: sub supplemental_base {
1.548 raeburn 5510: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5511: }
5512:
1.329 droeschl 5513: sub handler {
5514: my $r = shift;
5515: &Apache::loncommon::content_type($r,'text/html');
5516: $r->send_http_header;
5517: return OK if $r->header_only;
1.484 raeburn 5518:
5519: # get course data
1.408 raeburn 5520: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5521: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5522: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5523:
1.606 raeburn 5524: # get docroot
5525: my $londocroot = $r->dir_config('lonDocRoot');
5526:
1.484 raeburn 5527: # graphics settings
5528: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5529:
1.443 www 5530: #
1.329 droeschl 5531: # --------------------------------------------- Initialize help topics for this
5532: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5533: 'Adding_External_Resource','Adding_External_Tool',
5534: 'Navigate_Content','Adding_Folders','Docs_Overview',
5535: 'Load_Map','Supplemental','Score_Upload_Form',
5536: 'Adding_Pages','Importing_LON-CAPA_Resource',
5537: 'Importing_IMS_Course','Uploading_From_Harddrive',
5538: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5539: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5540: }
5541: # Composite help files
5542: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5543: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5544: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5545: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5546: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5547: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5548: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5549: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5550: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5551: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5552:
1.611 raeburn 5553: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 5554: # does this user have privileges to modify content.
5555: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 5556: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 5557: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5558: $allowed = 1;
1.682 raeburn 5559: }
5560: $canedit = 1;
5561: $canview = 1;
5562: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5563: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5564: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5565: $allowed = 1;
5566: }
1.682 raeburn 5567: $canview = 1;
1.611 raeburn 5568: }
5569: unless ($canedit) {
5570: $disabled = ' disabled="disabled"';
1.472 raeburn 5571: }
1.582 raeburn 5572: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5573: if ($env{'form.inhibitmenu'}) {
5574: unless ($env{'form.inhibitmenu'} eq 'yes') {
5575: delete($env{'form.inhibitmenu'});
5576: }
5577: }
5578:
1.582 raeburn 5579: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5580: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5581: if (!$canedit) {
5582: &verifycontent($r);
5583: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5584: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5585: text=>'Results',
5586: faq=>273,
5587: bug=>'Instructor Interface'});
5588: &verifycontent($r,$env{'form.checkstale'});
5589: } else {
5590: &contentverifyform($r);
5591: }
1.329 droeschl 5592: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5593: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5594: &list_symbs($r);
1.651 raeburn 5595: } elsif ($allowed && $env{'form.shorturls'}) {
5596: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5597: &short_urls($r,$canedit);
1.329 droeschl 5598: } elsif ($allowed && $env{'form.docslog'}) {
5599: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5600: my $folder = $env{'form.folder'};
5601: if ($folder eq '') {
5602: $folder='default';
5603: }
1.611 raeburn 5604: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5605: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5606: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5607: &checkversions($r,$canedit);
5608: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5609: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5610: &dumpcourse($r);
1.611 raeburn 5611: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5612: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5613: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5614: } else {
1.611 raeburn 5615: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5616: $noendpage = 1;
5617: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5618: if ($redirect) {
5619: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5620: my $container = 'sequence';
5621: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5622: $is_random_order,$container) =
5623: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5624: my (@folders)=split('&',$env{'form.folderpath'});
5625: $env{'form.foldername'}=&unescape(pop(@folders));
5626: my $folder=pop(@folders);
5627: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5628: $folder.'.'.$container);
5629: my $warning;
5630: if ($fatal) {
5631: if ($container eq 'page') {
5632: $warning = &mt('An error occurred retrieving the contents of the current page.');
5633: } else {
5634: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5635: }
5636: } else {
5637: my $url = $redirect;
5638: my $srcfile = $londocroot.$url;
5639: $url =~ s{^/priv/}{/res/};
5640: my $targetfile = $londocroot.$url;
5641: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5642: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5643: $env{'form.folder'} = $folder;
5644: &snapshotbefore();
5645: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5646: my $ext = 'false';
5647: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5648: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5649: ':'.$ext.':normal:res';
5650: push(@LONCAPA::map::order,$newidx);
5651: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5652: 'string_yesno');
5653: &remember_parms($newidx,'hiddenresource','set','yes');
5654: ($errtext,$fatal) =
5655: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5656: &log_differences($plain);
5657: &mark_hash_old();
5658: $r->internal_redirect($redirect);
5659: return OK;
5660: }
1.654 raeburn 5661: } else {
5662: $r->internal_redirect($redirect);
1.606 raeburn 5663: }
5664: }
5665: }
1.445 www 5666: #
5667: # Done catching special calls
1.484 raeburn 5668: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5669: # Get the parameters that may be needed
5670: #
5671: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 5672: ['folderpath','title',
1.519 raeburn 5673: 'forcesupplement','forcestandard',
1.510 raeburn 5674: 'tools','symb','command','supppath']);
1.445 www 5675:
1.635 raeburn 5676: foreach my $item ('forcesupplement','forcestandard','tools') {
5677: next if ($env{'form.'.$item} eq '');
5678: unless ($env{'form.'.$item} eq '1') {
5679: delete($env{'form.'.$item});
5680: }
5681: }
5682:
5683: if ($env{'form.command'}) {
5684: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5685: delete($env{'form.command'});
5686: }
5687: }
5688:
5689: if ($env{'form.symb'}) {
5690: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5691: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5692: delete($env{'form.symb'});
5693: }
5694: }
5695:
1.445 www 5696: # standard=1: this is a "new-style" course with an uploaded map as top level
5697: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5698:
5699: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5700:
1.484 raeburn 5701: # Decide whether this should display supplemental or main content or utilities
1.445 www 5702: # supplementalflag=1: show supplemental documents
5703: # supplementalflag=0: show standard documents
1.484 raeburn 5704: # toolsflag=1: show utilities
1.445 www 5705:
1.561 raeburn 5706: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5707: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5708: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5709: $supplementalflag=0;
5710: }
5711: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5712: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5713: unless ($allowed) { $supplementalflag=1; }
5714: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5715: my $toolsflag=0;
5716: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5717:
1.635 raeburn 5718: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5719: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 5720: }
5721:
1.685 raeburn 5722: my $backto_supppath;
1.635 raeburn 5723: if ($env{'form.supppath'} ne '') {
1.685 raeburn 5724: if ($supplementalflag && $allowed) {
5725: $backto_supppath = &validate_supppath($coursenum,$coursedom);
5726: }
1.635 raeburn 5727: }
5728:
1.329 droeschl 5729: my $script='';
5730: my $showdoc=0;
1.457 raeburn 5731: my $addentries = {};
1.475 raeburn 5732: my $container;
1.329 droeschl 5733: my $containertag;
1.508 raeburn 5734: my $pathitem;
1.598 raeburn 5735: my %ltitools;
1.699 raeburn 5736: my $posslti;
1.617 raeburn 5737: my $hiddentop;
1.615 raeburn 5738: my $navmap;
1.617 raeburn 5739: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5740:
1.464 www 5741: # Do we directly jump somewhere?
1.525 raeburn 5742: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5743: if ($env{'form.symb'} ne '') {
1.522 raeburn 5744: $env{'form.folderpath'}=
1.617 raeburn 5745: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5746: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5747: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 5748: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 5749: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5750: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 5751: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 5752: }
1.472 raeburn 5753: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5754: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5755: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5756: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5757: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5758: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5759: } elsif ($env{'form.command'} eq 'contents') {
5760: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5761: } elsif ($env{'form.command'} eq 'home') {
5762: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5763: }
5764:
1.525 raeburn 5765:
1.445 www 5766: # Where do we store these for when we come back?
5767: my $stored_folderpath='docs_folderpath';
5768: if ($supplementalflag) {
5769: $stored_folderpath='docs_sup_folderpath';
5770: }
1.464 www 5771:
1.519 raeburn 5772: # No folderpath, and in edit mode, see if we have something stored
5773: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5774: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5775: {'folderpath' => 'scalar'});
1.615 raeburn 5776:
5777: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5778: if ($supplementalflag) {
5779: undef($env{'form.folderpath'}) if ($1 eq 'default');
5780: } else {
5781: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5782: }
5783: } else {
1.523 raeburn 5784: undef($env{'form.folderpath'});
5785: }
1.677 raeburn 5786: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5787: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 5788: }
1.329 droeschl 5789: }
1.446 www 5790:
5791: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5792: if (!$allowed) {
1.446 www 5793: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5794: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5795: }
5796: }
1.446 www 5797: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5798: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5799: $env{'form.folderpath'} = &supplemental_base()
5800: .'&'.
1.329 droeschl 5801: $env{'form.folderpath'};
5802: }
1.685 raeburn 5803: # If allowed and user's role is not advanced check folderpath is not hidden
5804: my $hidden_and_empty;
1.687 raeburn 5805: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 5806: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 5807: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5808: my $folder = $pathitems[-2];
5809: if ($folder eq '') {
5810: undef($env{'form.folderpath'});
5811: } else {
5812: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 5813: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 5814: $folderurl .= '.page';
5815: } else {
5816: $folderurl .= '.sequence';
5817: }
1.685 raeburn 5818: if ($supplementalflag) {
5819: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
5820: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 5821: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 5822: if (ref($supplemental) eq 'HASH') {
5823: my ($suppmap,$suppmapnum);
5824: if ($folder eq 'supplemental') {
5825: $suppmap = 'default';
5826: $suppmapnum = 0;
5827: } elsif ($folder =~ /^supplemental_(\d+)$/) {
5828: $suppmap = $1;
5829: $suppmapnum = $suppmap;
5830: }
5831: if ($hiddenfolder) {
5832: my $hascontent;
5833: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
5834: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
5835: $hascontent = 1;
5836: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
5837: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
5838: if ($id =~ /^$suppmapnum\:/) {
5839: $hascontent = 1;
5840: last;
5841: }
5842: }
5843: }
5844: last if ($hascontent);
5845: }
5846: unless ($hascontent) {
5847: if ($foldername ne '') {
5848: $hidden_and_empty = $foldername;
5849: } else {
5850: $hidden_and_empty = $folder;
5851: }
5852: }
5853: }
5854: }
5855: } else {
5856: unless (ref($navmap)) {
5857: $navmap = Apache::lonnavmaps::navmap->new();
5858: }
5859: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
5860: $foldername = &HTML::Entities::decode(&unescape($foldername));
5861: if (ref($navmap)) {
5862: if ($hiddenfolder ||
5863: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
5864: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5865: unless (@resources) {
5866: if ($foldername ne '') {
5867: $hidden_and_empty = $foldername;
5868: } else {
5869: $hidden_and_empty = $folder;
5870: }
5871: }
5872: }
5873: }
1.617 raeburn 5874: }
1.685 raeburn 5875: if ($hidden_and_empty ne '') {
5876: splice(@pathitems,-2);
5877: if (@pathitems) {
5878: $env{'form.folderpath'} = join('&',@pathitems);
5879: } else {
5880: undef($env{'form.folderpath'});
1.615 raeburn 5881: }
5882: }
5883: }
5884: }
5885:
1.446 www 5886: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5887: unless ($env{'form.folderpath'}) {
1.446 www 5888: if ($supplementalflag) {
5889: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5890: } elsif ($allowed) {
5891: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5892: }
1.472 raeburn 5893: }
1.446 www 5894:
1.445 www 5895: # Store this
1.484 raeburn 5896: unless ($toolsflag) {
1.615 raeburn 5897: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5898: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5899: {'folderpath' => 'scalar'});
1.510 raeburn 5900: }
1.519 raeburn 5901: my $folderpath;
1.484 raeburn 5902: if ($env{'form.folderpath'}) {
1.519 raeburn 5903: $folderpath = $env{'form.folderpath'};
5904: my (@folders)=split('&',$env{'form.folderpath'});
5905: $env{'form.foldername'}=&unescape(pop(@folders));
5906: if ($env{'form.foldername'} =~ /\:1$/) {
5907: $container = 'page';
5908: } else {
5909: $container = 'sequence';
5910: }
5911: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5912: } else {
1.519 raeburn 5913: if ($env{'form.folder'} eq '' ||
5914: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5915: if ($env{'form.folder'} eq 'supplemental') {
5916: $folderpath=&supplemental_base();
5917: } elsif (!$hiddentop) {
5918: $folderpath='default&'.
5919: &escape(&mt('Main Content').':::::');
5920: }
1.484 raeburn 5921: }
5922: }
1.519 raeburn 5923: $containertag = '<input type="hidden" name="folderpath" value="" />';
5924: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5925: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5926: $showdoc='/'.$1;
5927: }
5928: if ($showdoc) { # got called in sequence from course
5929: $allowed=0;
5930: } else {
1.611 raeburn 5931: if ($canedit) {
1.484 raeburn 5932: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5933: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5934: }
5935: }
1.329 droeschl 5936: }
5937:
1.344 bisitz 5938: # get personal data
1.329 droeschl 5939: my $uname=$env{'user.name'};
5940: my $udom=$env{'user.domain'};
5941: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5942:
5943: if ($allowed) {
1.484 raeburn 5944: if ($toolsflag) {
5945: $script .= &inject_data_js();
5946: my ($home,$other,%outhash)=&authorhosts();
5947: if (!$home && $other) {
5948: my @hosts;
5949: foreach my $aurole (keys(%outhash)) {
5950: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5951: push(@hosts,$outhash{$aurole});
5952: }
5953: }
5954: $script .= &dump_switchserver_js(@hosts);
5955: }
1.458 raeburn 5956: } else {
1.570 raeburn 5957: my $tid = 1;
1.484 raeburn 5958: my @tabids;
5959: if ($supplementalflag) {
1.655 raeburn 5960: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 5961: $tid = 2;
1.484 raeburn 5962: } else {
5963: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5964: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5965: unshift(@tabids,'001');
5966: push(@tabids,('dd1','ee1'));
5967: }
1.458 raeburn 5968: }
1.484 raeburn 5969: my $tabidstr = join("','",@tabids);
1.699 raeburn 5970: my (%domtools,%crstools);
5971: my %tooltypes = &Apache::loncommon::usable_exttools();
5972: if ($tooltypes{'dom'}) {
5973: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
5974: }
5975: if ($tooltypes{'crs'}) {
5976: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
5977: }
5978: %ltitools = (
5979: dom => \%domtools,
5980: crs => \%crstools,
5981: );
5982: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622 raeburn 5983: my $hostname = $r->hostname();
1.606 raeburn 5984: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5985: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5986: &history_tab_js().
5987: &inject_data_js().
1.570 raeburn 5988: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5989: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 5990: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
5991: if ($hidden_and_empty ne '') {
5992: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
5993: $hidden_and_empty);
5994: $onload .= "javascript:alert('".&js_escape($alert)."');";
5995: }
1.484 raeburn 5996: $addentries = {
1.685 raeburn 5997: onload => $onload,
1.484 raeburn 5998: };
1.458 raeburn 5999: }
1.538 raeburn 6000: $script .= &paste_popup_js();
1.501 raeburn 6001: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
6002: &mt('Switch server?');
6003:
6004:
1.329 droeschl 6005: }
6006: # -------------------------------------------------------------------- Body tag
1.369 bisitz 6007: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 6008: .'// <![CDATA['."\n"
6009: .$script."\n"
6010: .'// ]]>'."\n"
1.595 musolffc 6011: .'</script>'."\n"
6012: .'<script type="text/javascript"
6013: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 6014:
6015: # Breadcrumbs
6016: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 6017:
6018: if ($showdoc) {
1.682 raeburn 6019: my $args;
6020: if ($supplementalflag) {
1.687 raeburn 6021: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
6022: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.682 raeburn 6023: $args = {'bread_crumbs' => $brcrum};
6024: } else {
6025: $args = {'force_register' => $showdoc};
6026: }
6027: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 6028: } elsif ($toolsflag) {
1.611 raeburn 6029: my ($breadtext,$breadtitle);
1.617 raeburn 6030: $breadtext = "$crstype Editor";
1.611 raeburn 6031: if ($canedit) {
6032: $breadtitle = 'Editing '.$crstype.' Contents';
6033: } else {
6034: $breadtext .= ' (View-only mode)';
6035: $breadtitle = 'Viewing '.$crstype.' Contents';
6036: }
1.571 raeburn 6037: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6038: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 6039: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
6040: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6041: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6042: $breadtitle)
1.571 raeburn 6043: );
1.510 raeburn 6044: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 6045: unless ($env{'request.role.adv'}) {
6046: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
6047: $r->internal_redirect('/adm/navmaps');
6048: return OK;
6049: }
6050: }
1.510 raeburn 6051: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
6052: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
6053: {'bread_crumbs' => $brcrum,}));
6054: } else {
1.611 raeburn 6055: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 6056: $breadtext = "$crstype Editor";
1.611 raeburn 6057: if ($canedit) {
6058: $breadtitle = 'Editing '.$crstype.' Contents';
6059: $helpitem = 'Docs_Adding_Course_Doc';
6060: } else {
6061: $breadtext .= ' (View-only mode)';
6062: $breadtitle = 'Viewing '.$crstype.' Contents';
6063: $helpitem = 'Docs_Viewing_Course_Doc';
6064: }
1.392 raeburn 6065: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6066: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 6067: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 6068: {'add_entries' => $addentries}
6069: )
1.392 raeburn 6070: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6071: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6072: $breadtitle,
6073: $helpitem)
1.392 raeburn 6074: );
6075: }
1.364 bisitz 6076:
1.329 droeschl 6077: my %allfiles = ();
6078: my %codebase = ();
1.440 raeburn 6079: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 6080: if ($canedit) {
1.684 raeburn 6081: undef($suppchanges);
1.329 droeschl 6082: if (($env{'form.uploaddoc.filename'}) &&
6083: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 6084: my $context = $1;
6085: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 6086: undef($hadchanges);
1.440 raeburn 6087: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 6088: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 6089: undef($navmap);
1.329 droeschl 6090: if ($hadchanges) {
6091: &mark_hash_old();
6092: }
1.684 raeburn 6093: if ($suppchanges) {
6094: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6095: undef($suppchanges);
6096: }
1.440 raeburn 6097: $r->print($upload_output);
6098: } elsif ($env{'form.phase'} eq 'upload_embedded') {
6099: # Process file upload - phase two - upload embedded objects
6100: $uploadphase = 'check_embedded';
6101: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
6102: my $state = &embedded_form_elems($uploadphase,$primaryurl,
6103: $env{'form.newidx'});
6104: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6105: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6106: my ($destination,$dir_root) = &embedded_destination();
6107: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
6108: my $actionurl = '/adm/coursedocs';
1.630 raeburn 6109: my ($result,$flag) =
1.440 raeburn 6110: &Apache::loncommon::upload_embedded('coursedoc',$destination,
6111: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
6112: $actionurl);
6113: $r->print($result.&return_to_editor());
6114: } elsif ($env{'form.phase'} eq 'check_embedded') {
6115: # Process file upload - phase three - modify references in HTML file
6116: $uploadphase = 'modified_orightml';
6117: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6118: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6119: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 6120: my $result =
1.482 raeburn 6121: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
6122: $docuname,$docudom,undef,
6123: $dir_root);
1.630 raeburn 6124: $r->print($result.&return_to_editor());
1.476 raeburn 6125: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
6126: $uploadphase = 'decompress_phase_one';
6127: $r->print(&decompression_phase_one().
6128: &return_to_editor());
6129: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
6130: $uploadphase = 'decompress_phase_two';
6131: $r->print(&decompression_phase_two().
6132: &return_to_editor());
1.329 droeschl 6133: }
6134: }
6135:
1.484 raeburn 6136: if ($allowed && $toolsflag) {
6137: $r->print(&startContentScreen('tools'));
1.611 raeburn 6138: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 6139: $r->print(&endContentScreen());
6140: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 6141: # -----------------------------------------------------------------------------
6142: my %lt=&Apache::lonlocal::texthash(
6143: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 6144: 'upfi' => 'Upload File',
1.553 raeburn 6145: 'upld' => 'Upload Content',
1.329 droeschl 6146: 'srch' => 'Search',
6147: 'impo' => 'Import',
1.487 raeburn 6148: 'lnks' => 'Import from Stored Links',
1.502 raeburn 6149: 'impm' => 'Import from Assembled Map',
1.630 raeburn 6150: 'imcr' => 'Import from Course Resources',
1.598 raeburn 6151: 'extr' => 'External Resource',
6152: 'extt' => 'External Tool',
1.329 droeschl 6153: 'selm' => 'Select Map',
6154: 'load' => 'Load Map',
6155: 'newf' => 'New Folder',
6156: 'newp' => 'New Composite Page',
6157: 'syll' => 'Syllabus',
1.425 raeburn 6158: 'navc' => 'Table of Contents',
1.343 biermanm 6159: 'sipa' => 'Simple Course Page',
1.329 droeschl 6160: 'sipr' => 'Simple Problem',
1.630 raeburn 6161: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 6162: 'stpr' => 'Standard Problem',
6163: 'news' => 'New sub-directory',
6164: 'crpr' => 'Create Problem',
1.689 raeburn 6165: 'swit' => 'Switch Server',
1.329 droeschl 6166: 'drbx' => 'Drop Box',
1.451 www 6167: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 6168: 'bull' => 'Discussion Board',
1.347 weissno 6169: 'mypi' => 'My Personal Information Page',
1.353 weissno 6170: 'grpo' => 'Group Portfolio',
1.329 droeschl 6171: 'rost' => 'Course Roster',
1.528 raeburn 6172: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 6173: 'imsf' => 'IMS Upload',
6174: 'imsl' => 'Upload IMS package',
1.501 raeburn 6175: 'cms' => 'Origin of IMS package',
6176: 'se' => 'Select',
1.329 droeschl 6177: 'file' => 'File',
6178: 'title' => 'Title',
1.606 raeburn 6179: 'addp' => 'Add Placeholder to course?',
6180: 'uste' => 'Use Template?',
6181: 'fnam' => 'File Name:',
6182: 'loca' => 'Location:',
6183: 'dire' => 'Directory:',
6184: 'cate' => 'Category:',
6185: 'tmpl' => 'Template:',
1.698 raeburn 6186: 'empd' => 'No resources found',
1.329 droeschl 6187: 'comment' => 'Comment',
1.403 raeburn 6188: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 6189: 'bb5' => 'Blackboard 5',
6190: 'bb6' => 'Blackboard 6',
6191: 'angel5' => 'ANGEL 5.5',
6192: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 6193: 'yes' => 'Yes',
6194: 'no' => 'No',
1.618 raeburn 6195: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 6196: );
1.329 droeschl 6197: # -----------------------------------------------------------------------------
1.595 musolffc 6198:
6199: # Calculate free quota space for a user or course. A javascript function checks
6200: # file size to determine if upload should be allowed.
6201: my $quotatype = 'unofficial';
6202: if ($crstype eq 'Community') {
1.601 raeburn 6203: $quotatype = 'community';
6204: } elsif ($crstype eq 'Placement') {
6205: $quotatype = 'placement';
1.595 musolffc 6206: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6207: $quotatype = 'official';
6208: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6209: $quotatype = 'textbook';
6210: }
6211: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6212: 'course',$quotatype); # expressed in MB
6213: my $current_disk_usage = 0;
6214: foreach my $subdir ('docs','supplemental') {
6215: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6216: "userfiles/$subdir",1); # expressed in kB
6217: }
6218: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 6219: my $usage = $current_disk_usage/1024; # in MB
6220: my $quota = $disk_quota;
6221: my $percent;
6222: if ($disk_quota == 0) {
6223: $percent = 100.0;
6224: } else {
1.619 raeburn 6225: $percent = 100*($usage/$disk_quota);
1.605 raeburn 6226: }
6227: $usage = sprintf("%.2f",$usage);
6228: $quota = sprintf("%.2f",$quota);
6229: $percent = sprintf("%.0f",$percent);
6230: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6231: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 6232:
1.329 droeschl 6233: my $fileupload=(<<FIUP);
1.605 raeburn 6234: $quotainfo
1.329 droeschl 6235: $lt{'file'}:<br />
6236: FIUP
6237: my $checkbox=(<<CHBO);
6238: <!-- <label>$lt{'parse'}?
6239: <input type="checkbox" name="parserflag" />
6240: </label> -->
6241: <label>
1.611 raeburn 6242: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6243: </label>
6244: CHBO
1.501 raeburn 6245: my $imsfolder = $env{'form.folder'};
6246: if ($imsfolder eq '') {
6247: $imsfolder = 'default';
6248: }
6249: my $imspform=(<<IMSFORM);
6250: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6251: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6252: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 6253: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 6254: <legend>$lt{'imsf'}</legend>
6255: $fileupload
1.702 ! raeburn 6256: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
! 6257: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501 raeburn 6258: <br />
6259: <p>
6260: $lt{'cms'}:
1.611 raeburn 6261: <select name="source" $disabled>
1.501 raeburn 6262: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 6263: <option value="bb5">$lt{'bb5'}</option>
6264: <option value="bb6">$lt{'bb6'}</option>
6265: <option value="angel5">$lt{'angel5'}</option>
6266: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 6267: </select>
6268: <input type="hidden" name="folder" value="$imsfolder" />
6269: </p>
6270: <input type="hidden" name="phase" value="one" />
1.611 raeburn 6271: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 6272: </fieldset>
6273: </form>
6274: IMSFORM
1.329 droeschl 6275:
6276: my $fileuploadform=(<<FUFORM);
1.501 raeburn 6277: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6278: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6279: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 6280: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 6281: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6282: <input type="hidden" name="active" value="aa" />
1.595 musolffc 6283: $fileupload
1.702 ! raeburn 6284: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
! 6285: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 6286: <br />
6287: $lt{'title'}:<br />
1.611 raeburn 6288: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 6289: $pathitem
1.329 droeschl 6290: <input type="hidden" name="cmd" value="upload_default" />
6291: <br />
1.458 raeburn 6292: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6293: $checkbox
6294: </span>
1.501 raeburn 6295: <br clear="all" />
1.611 raeburn 6296: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 6297: </fieldset>
6298: </form>
1.383 tempelho 6299: FUFORM
1.329 droeschl 6300:
1.611 raeburn 6301: my $mapimportjs;
6302: if ($canedit) {
6303: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6304: } else {
6305: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6306: }
1.502 raeburn 6307: my $importpubform=(<<SEDFFORM);
1.514 raeburn 6308: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 6309: $lt{'impm'}</a>$help{'Load_Map'}
6310: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 6311: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 6312: <legend>$lt{'impm'}</legend>
1.371 tempelho 6313: <input type="hidden" name="active" value="bb" />
1.502 raeburn 6314: $lt{'copm'}<br />
6315: <span class="LC_nobreak">
6316: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 6317: onfocus="this.blur();$mapimportjs" $disabled />
6318: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6319: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 6320: </fieldset>
6321: </form>
6322:
1.383 tempelho 6323: SEDFFORM
1.606 raeburn 6324: my $importcrsresform;
1.608 raeburn 6325: my ($numdirs,$pickfile) =
1.690 raeburn 6326: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
1.608 raeburn 6327: "resize_scrollbox('contentscroll','1','0');",
6328: undef,'res');
1.606 raeburn 6329: if ($pickfile) {
6330: $importcrsresform=(<<CRSFORM);
1.690 raeburn 6331: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 6332: $lt{'imcr'}</a>$help{'Course_Resources'}
6333: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6334: <fieldset id="importcrsresform" style="display: none;">
6335: <legend>$lt{'imcr'}</legend>
1.698 raeburn 6336: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 6337: <input type="hidden" name="active" value="bb" />
6338: $pickfile
6339: <p>
1.699 raeburn 6340: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606 raeburn 6341: </p>
6342: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 6343: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 raeburn 6344: </div>
6345: <div id="importcrsresempty" style="display: none;">
6346: <p>
6347: $lt{'empd'}
6348: </p>
6349: </div>
1.606 raeburn 6350: </fieldset>
6351: </form>
6352: CRSFORM
6353: }
6354:
1.611 raeburn 6355: my $fromstoredjs;
6356: if ($canedit) {
6357: $fromstoredjs = 'open_StoredLinks_Import()';
6358: } else {
6359: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6360: }
6361:
1.502 raeburn 6362: my @importpubforma = (
1.508 raeburn 6363: { '<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 6364: { '<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 6365: { '<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 6366: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6367: );
6368: if ($pickfile) {
1.690 raeburn 6369: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\');" />' => $importcrsresform});
1.606 raeburn 6370: }
1.502 raeburn 6371: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 6372: my $extresourcesform =
6373: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6374: $help{'Adding_External_Resource'},
6375: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6376: my $exttoolform =
6377: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6378: $help{'Adding_External_Tool'},undef,
6379: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6380: \%ltitools,$disabled);
1.329 droeschl 6381: if ($allowed) {
1.492 raeburn 6382: my $folder = $env{'form.folder'};
6383: if ($folder eq '') {
6384: $folder='default';
6385: }
1.615 raeburn 6386: if ($canedit) {
6387: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6388: if ($output) {
6389: $r->print($output);
6390: }
1.538 raeburn 6391: }
1.337 ehlerst 6392: $r->print(<<HIDDENFORM);
6393: <form name="renameform" method="post" action="/adm/coursedocs">
6394: <input type="hidden" name="title" />
6395: <input type="hidden" name="cmd" />
6396: <input type="hidden" name="markcopy" />
6397: <input type="hidden" name="copyfolder" />
6398: $containertag
6399: </form>
1.633 raeburn 6400: <form name="aliasform" method="post" action="/adm/coursedocs">
6401: <input type="hidden" name="alias" />
6402: <input type="hidden" name="cmd" />
6403: $containertag
6404: </form>
1.484 raeburn 6405:
1.337 ehlerst 6406: HIDDENFORM
1.508 raeburn 6407: $r->print(&makesimpleeditform($pathitem)."\n".
6408: &makedocslogform($pathitem."\n".
1.484 raeburn 6409: '<input type="hidden" name="folder" value="'.
6410: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6411: }
1.442 www 6412:
6413: # Generate the tabs
1.510 raeburn 6414: my ($mode,$needs_end);
1.472 raeburn 6415: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6416: my @folders = split('&',$env{'form.folderpath'});
6417: unless (@folders > 2) {
6418: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6419: $needs_end = 1;
6420: }
1.472 raeburn 6421: } else {
1.484 raeburn 6422: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6423: $needs_end = 1;
1.472 raeburn 6424: }
1.443 www 6425:
1.442 www 6426: #
1.622 raeburn 6427: my $hostname = $r->hostname();
1.442 www 6428: my $savefolderpath;
6429:
1.395 raeburn 6430: if ($allowed) {
1.329 droeschl 6431: my $folder=$env{'form.folder'};
1.615 raeburn 6432: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6433: $folder='default';
1.356 tempelho 6434: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6435: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6436: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6437: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6438: }
6439: my $postexec='';
6440: if ($folder eq 'default') {
1.653 raeburn 6441: my $windowname = 'loncapaclient';
6442: if ($env{'request.lti.login'}) {
6443: $windowname .= 'lti';
6444: }
1.372 bisitz 6445: $r->print('<script type="text/javascript">'."\n"
6446: .'// <![CDATA['."\n"
1.653 raeburn 6447: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 6448: .'// ]]>'."\n"
6449: .'</script>'."\n"
1.369 bisitz 6450: );
1.329 droeschl 6451: } else {
6452: #$postexec='self.close();';
6453: }
1.504 raeburn 6454: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6455: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6456: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6457:
6458: my $newnavform=(<<NNFORM);
6459: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 6460: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6461: $pathitem
1.329 droeschl 6462: <input type="hidden" name="importdetail"
6463: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6464: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6465: $help{'Navigate_Content'}
6466: </form>
6467: NNFORM
6468: my $newsmppageform=(<<NSPFORM);
6469: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 6470: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6471: $pathitem
1.329 droeschl 6472: <input type="hidden" name="importdetail" value="" />
1.423 onken 6473: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6474: $help{'Simple Page'}
1.329 droeschl 6475: </form>
6476: NSPFORM
6477:
6478: my $newsmpproblemform=(<<NSPROBFORM);
6479: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 6480: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6481: $pathitem
1.329 droeschl 6482: <input type="hidden" name="importdetail" value="" />
1.423 onken 6483: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6484: $help{'Simple_Problem'}
1.329 droeschl 6485: </form>
6486:
6487: NSPROBFORM
6488:
6489: my $newdropboxform=(<<NDBFORM);
6490: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 6491: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6492: $pathitem
1.329 droeschl 6493: <input type="hidden" name="importdetail" value="" />
1.423 onken 6494: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6495: $help{'Dropbox'}
1.344 bisitz 6496: </form>
1.329 droeschl 6497: NDBFORM
6498:
6499: my $newexuploadform=(<<NEXUFORM);
6500: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 6501: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6502: $pathitem
1.329 droeschl 6503: <input type="hidden" name="importdetail" value="" />
1.423 onken 6504: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6505: $help{'Score_Upload_Form'}
6506: </form>
6507: NEXUFORM
6508:
6509: my $newbulform=(<<NBFORM);
6510: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 6511: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6512: $pathitem
1.329 droeschl 6513: <input type="hidden" name="importdetail" value="" />
1.423 onken 6514: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6515: $help{'Bulletin Board'}
6516: </form>
6517: NBFORM
6518:
6519: my $newaboutmeform=(<<NAMFORM);
6520: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 6521: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6522: $pathitem
1.329 droeschl 6523: <input type="hidden" name="importdetail"
6524: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6525: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6526: $help{'My Personal Information Page'}
1.329 droeschl 6527: </form>
6528: NAMFORM
6529:
6530: my $newaboutsomeoneform=(<<NASOFORM);
6531: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 6532: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6533: $pathitem
1.329 droeschl 6534: <input type="hidden" name="importdetail" value="" />
1.423 onken 6535: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6536: </form>
6537: NASOFORM
6538:
6539: my $newrosterform=(<<NROSTFORM);
6540: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 6541: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6542: $pathitem
1.329 droeschl 6543: <input type="hidden" name="importdetail"
6544: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6545: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6546: $help{'Course_Roster'}
1.329 droeschl 6547: </form>
6548: NROSTFORM
6549:
1.534 raeburn 6550: my $newwebpage;
6551: if ($folder =~ /^default_?(\d*)$/) {
6552: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6553: if ($1) {
6554: $newwebpage .= $1;
6555: } else {
6556: $newwebpage .= 'default';
6557: }
6558: $newwebpage .= '/new.html';
6559: }
6560: my $newwebpageform =(<<NWEBFORM);
6561: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 6562: <input type="hidden" name="active" value="ff" />
1.534 raeburn 6563: $pathitem
6564: <input type="hidden" name="importdetail" value="$newwebpage" />
6565: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6566: $help{'Web_Page'}
1.534 raeburn 6567: </form>
6568: NWEBFORM
1.701 raeburn 6569: my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606 raeburn 6570: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 6571: my $machines_str = "'".join("','",@ids)."'";
6572: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 6573: if ($env{'user.author'}) {
6574: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 6575: $is_home{'author'} = 1;
1.606 raeburn 6576: }
1.691 raeburn 6577: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 6578: }
6579: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6580: ['active'],['ca','aa']);
1.691 raeburn 6581: my %by_roletype;
1.606 raeburn 6582: if (keys(%roleshash)) {
6583: foreach my $entry (keys(%roleshash)) {
6584: my ($auname,$audom,$roletype) = split(/:/,$entry);
6585: my $key = $entry;
6586: $key =~ s/:/___/g;
1.691 raeburn 6587: my $author = $auname.'___'.$audom;
6588: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 6589: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 6590: $toppath{$author} = "/priv/$audom/$auname";
6591: if (grep(/^\Q$rolehome\E$/,@ids)) {
6592: $is_home{$author} = 1;
1.606 raeburn 6593: }
1.691 raeburn 6594: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
6595: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 6596: }
1.691 raeburn 6597: }
6598: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6599: if (grep(/^\Q$crshome\E$/,@ids)) {
6600: $is_home{'course'} = 1;
6601: }
6602: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
6603: my $pickdir = $lt{'loca'}.
6604: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
6605: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
6606: if ($env{'user.author'}) {
6607: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
6608: }
6609: if (keys(%by_roletype)) {
6610: foreach my $possrole ('ca','aa') {
6611: if (ref($by_roletype{$possrole}) eq 'HASH') {
6612: my $roletitle = &Apache::lonnet::plaintext($possrole);
6613: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6614: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
6615: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
6616: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 6617: }
6618: }
6619: }
6620: }
1.691 raeburn 6621: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n".
6622: '</select><br />'."\n".
6623: $lt{'dire'}.
6624: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
6625: '<option value=""></option>'.
6626: '</select><br />'."\n";
1.606 raeburn 6627:
6628: my %seltemplate_menus;
6629: my @files = &Apache::lonhomework::get_template_list('problem');
6630: my @noexamplelink = ('blank.problem','blank.library','script.library');
6631: my $currentcategory = '';
6632: my @ordered = ('');
6633: my %templatehelp;
6634: my $defcategory = '';
6635: my @catorder = ($defcategory);
6636: $seltemplate_menus{$defcategory}->{'order'} = [''];
6637: $seltemplate_menus{$defcategory}->{'text'} = '';
6638: foreach my $file (@files) {
6639: if (ref($file) eq 'ARRAY') {
6640: my ($path,$title,$category,$help) = @{$file};
6641: next if ($title !~ /\S/);
6642: if (&js_escape($category) ne $currentcategory) {
6643: $currentcategory = &js_escape($category);
6644: push(@catorder,&js_escape($currentcategory));
6645: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6646: $seltemplate_menus{$currentcategory}->{'default'} = '';
6647: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6648: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6649: }
6650: if ($path) {
6651: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6652: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6653: if ($help) {
6654: $templatehelp{$path} = $help;
6655: }
6656: }
6657: }
6658: }
6659:
6660: my $templates = $lt{'cate'}.' '.
6661: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6662: $defcategory,'tempcategory','template',
6663: \%seltemplate_menus,\@catorder,
6664: "resize_scrollbox('contentscroll','1','0');",
6665: "toggleExampleText();",'template').'<br />';
6666: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
1.701 raeburn 6667: '<span id="newresexample">'.&mt('Example').'</span></a>';
1.606 raeburn 6668: my $crsresform=(<<RESFORM);
1.691 raeburn 6669: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.606 raeburn 6670: $lt{'stpr'}</a>$help{'Course_Resource'}
6671: <form action="/adm/coursedocs" method="post" name="courseresform">
6672: <fieldset id="crsresform" style="display:none;">
6673: <legend>$lt{'stpr'}</legend>
1.655 raeburn 6674: <input type="hidden" name="active" value="bb" />
1.606 raeburn 6675: <p>
6676: $pickdir
1.701 raeburn 6677: </p>
1.691 raeburn 6678: <div id="newstdproblem" style="display:none;">
1.701 raeburn 6679: <p>
1.606 raeburn 6680: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6681: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6682:
1.611 raeburn 6683: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6684: </span><span id="newsubdir"></span>
6685: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701 raeburn 6686: </p>
1.699 raeburn 6687: </div>
1.606 raeburn 6688: $lt{'fnam'}
1.611 raeburn 6689: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.701 raeburn 6690: <div id="newresource" style="display:none">
1.606 raeburn 6691: <p>
6692: $lt{'addp'}
1.611 raeburn 6693: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6694: $lt{'no'}</label>
1.611 raeburn 6695: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6696: $lt{'yes'}</label>
6697: <span id="newrestitle"></span>
1.611 raeburn 6698: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701 raeburn 6699: </p>
1.606 raeburn 6700: </div>
6701: <p>
6702: $lt{'uste'}
1.611 raeburn 6703: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6704: $lt{'no'}</label>
1.611 raeburn 6705: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6706: $lt{'yes'}</label>
1.701 raeburn 6707: </p>
1.606 raeburn 6708: <div id="newrestemplate" style="display:none">
6709: $templates
6710: $templatepreview
6711: </div>
6712: <span class="LC_nobreak">
1.701 raeburn 6713: <input type="hidden" name="folderpath" value="$showpath" />
1.611 raeburn 6714: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6715: </span>
1.691 raeburn 6716: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 6717: $rolehomes
6718: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
6719: </div>
1.606 raeburn 6720: </fieldset>
6721: </form>
6722:
6723: RESFORM
1.534 raeburn 6724:
1.342 ehlerst 6725: my $specialdocumentsform;
1.383 tempelho 6726: my @specialdocumentsforma;
1.451 www 6727: my $gradingform;
6728: my @gradingforma;
6729: my $communityform;
6730: my @communityforma;
1.351 ehlerst 6731: my $newfolderform;
1.390 tempelho 6732: my $newfolderb;
1.342 ehlerst 6733:
1.451 www 6734: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6735:
1.329 droeschl 6736: my $newpageform=(<<NPFORM);
6737: <form action="/adm/coursedocs" method="post" name="newpage">
6738: <input type="hidden" name="folderpath" value="$path" />
6739: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6740: <input type="hidden" name="active" value="ee" />
1.423 onken 6741: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6742: $help{'Adding_Pages'}
1.329 droeschl 6743: </form>
6744: NPFORM
1.390 tempelho 6745:
6746:
1.351 ehlerst 6747: $newfolderform=(<<NFFORM);
1.329 droeschl 6748: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6749: $pathitem
1.329 droeschl 6750: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6751: <input type="hidden" name="active" value="" />
1.422 onken 6752: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6753: </form>
6754: NFFORM
6755:
6756: my $newsylform=(<<NSYLFORM);
6757: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6758: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6759: $pathitem
1.329 droeschl 6760: <input type="hidden" name="importdetail"
6761: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6762: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6763: $help{'Syllabus'}
1.383 tempelho 6764:
1.329 droeschl 6765: </form>
6766: NSYLFORM
1.364 bisitz 6767:
1.329 droeschl 6768: my $newgroupfileform=(<<NGFFORM);
6769: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 6770: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6771: $pathitem
1.329 droeschl 6772: <input type="hidden" name="importdetail"
6773: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6774: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6775: $help{'Group Portfolio'}
1.329 droeschl 6776: </form>
6777: NGFFORM
1.672 raeburn 6778: if ($container eq 'page') {
6779: @specialdocumentsforma=(
6780: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6781: );
6782: } else {
6783: @specialdocumentsforma=(
1.421 onken 6784: {'<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 6785: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6786: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6787: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6788: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 6789: );
6790: }
1.451 www 6791: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6792:
1.655 raeburn 6793: my @external = (
6794: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 6795: );
1.699 raeburn 6796: if ($posslti) {
1.655 raeburn 6797: push(@external,
6798: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6799: );
1.598 raeburn 6800: }
1.655 raeburn 6801: my $externalform = &create_form_ul(&create_list_elements(@external));
6802:
6803: my @importdoc = ();
1.519 raeburn 6804: unless ($container eq 'page') {
6805: push(@importdoc,
6806: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6807: );
6808: }
6809: push(@importdoc,
1.558 raeburn 6810: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6811: );
1.501 raeburn 6812: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6813:
1.451 www 6814: @gradingforma=(
6815: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6816: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6817: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.691 raeburn 6818: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform},
1.451 www 6819: );
6820: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6821:
6822: @communityforma=(
6823: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6824: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6825: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6826: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6827: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6828: );
6829: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6830:
1.330 tempelho 6831: my %orderhash = (
1.553 raeburn 6832: 'aa' => ['Upload',$fileuploadform],
6833: 'bb' => ['Import',$importpubform],
1.655 raeburn 6834: 'cc' => ['External',$externalform],
1.701 raeburn 6835: 'dd' => ['Assessment',$gradingform],
1.673 raeburn 6836: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 6837: );
1.519 raeburn 6838: unless ($container eq 'page') {
1.434 raeburn 6839: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 6840: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 6841: }
6842:
1.341 ehlerst 6843: $hadchanges=0;
1.484 raeburn 6844: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6845: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6846: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6847: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6848: undef($navmap);
1.443 www 6849: if ($error) {
6850: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6851: }
1.639 raeburn 6852: if ($hadchanges) {
6853: unless (&is_hash_old()) {
1.638 raeburn 6854: &mark_hash_old();
6855: }
6856: }
1.341 ehlerst 6857:
1.443 www 6858: &changewarning($r,'');
6859: }
1.458 raeburn 6860: }
1.442 www 6861:
1.443 www 6862: # Supplemental documents start here
6863:
1.329 droeschl 6864: my $folder=$env{'form.folder'};
1.443 www 6865: unless ($supplementalflag) {
1.329 droeschl 6866: $folder='supplemental';
6867: }
1.685 raeburn 6868: if (($folder eq 'supplemental') &&
1.329 droeschl 6869: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6870: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6871: } elsif ($allowed) {
1.356 tempelho 6872: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6873: }
1.508 raeburn 6874: $pathitem = '<input type="hidden" name="folderpath" value="'.
6875: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6876: if ($allowed) {
6877: my $folderseq=
1.504 raeburn 6878: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6879:
6880: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6881: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6882: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6883: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6884: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6885: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6886: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6887: $fileupload
1.702 ! raeburn 6888: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
! 6889: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 6890: <br />
6891: <br />
6892: <span class="LC_nobreak">
6893: $checkbox
6894: </span>
6895: <br /><br />
6896: $lt{'comment'}:<br />
1.383 tempelho 6897: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6898: <br />
1.508 raeburn 6899: $pathitem
1.329 droeschl 6900: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6901: <input type='submit' value="$lt{'upld'}" />
1.700 raeburn 6902: </fieldset>
1.501 raeburn 6903: </form>
1.329 droeschl 6904: SUPDOCFORM
6905:
6906: my $supnewfolderform=(<<SNFFORM);
6907: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6908: <input type="hidden" name="active" value="" />
1.508 raeburn 6909: $pathitem
1.329 droeschl 6910: <input type="hidden" name="importdetail" value="" />
1.423 onken 6911: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6912: $help{'Adding_Folders'}
1.329 droeschl 6913: </form>
6914: SNFFORM
1.383 tempelho 6915:
1.510 raeburn 6916: my $supextform =
6917: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6918: $help{'Adding_External_Resource'},
6919: undef,undef,undef,undef,undef,undef,
6920: $disabled);
1.329 droeschl 6921:
1.598 raeburn 6922: my $supexttoolform =
6923: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6924: $help{'Adding_External_Tool'},
6925: undef,undef,'tool',$coursedom,
1.611 raeburn 6926: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6927:
1.329 droeschl 6928: my $supnewsylform=(<<SNSFORM);
6929: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6930: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6931: $pathitem
1.329 droeschl 6932: <input type="hidden" name="importdetail"
6933: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6934: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6935: $help{'Syllabus'}
6936: </form>
6937: SNSFORM
6938:
6939: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6940: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6941: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6942: $pathitem
1.329 droeschl 6943: <input type="hidden" name="importdetail"
6944: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6945: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6946: $help{'My Personal Information Page'}
1.329 droeschl 6947: </form>
6948: SNAMFORM
6949:
1.534 raeburn 6950: my $supwebpage;
6951: if ($folder =~ /^supplemental_?(\d*)$/) {
6952: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6953: if ($1) {
6954: $supwebpage .= $1;
6955: } else {
6956: $supwebpage .= 'default';
6957: }
6958: $supwebpage .= '/new.html';
6959: }
6960: my $supwebpageform =(<<SWEBFORM);
6961: <form action="/adm/coursedocs" method="post" name="supwebpage">
6962: <input type="hidden" name="active" value="cc" />
6963: $pathitem
6964: <input type="hidden" name="importdetail" value="$supwebpage" />
6965: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6966: $help{'Web_Page'}
1.534 raeburn 6967: </form>
6968: SWEBFORM
6969:
1.333 muellerd 6970:
1.383 tempelho 6971: my @specialdocs = (
1.618 raeburn 6972: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6973: =>$supnewsylform},
1.611 raeburn 6974: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6975: =>$supnewaboutmeform},
1.534 raeburn 6976: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6977:
1.383 tempelho 6978: );
1.655 raeburn 6979: my @supexternal = (
6980: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
6981: =>$supextform});
1.699 raeburn 6982: if ($posslti) {
1.655 raeburn 6983: push(@supexternal,
6984: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 6985: =>$supexttoolform});
6986: }
1.655 raeburn 6987: my @supimportdoc = (
1.598 raeburn 6988: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6989: =>$supupdocform},
1.598 raeburn 6990: );
1.501 raeburn 6991:
6992: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6993: my %suporderhash = (
1.390 tempelho 6994: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 6995: 'dd' => ['Upload',$supupdocform],
6996: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 6997: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6998: );
1.443 www 6999: if ($supplementalflag) {
1.682 raeburn 7000: $suppchanges = 0;
7001: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
7002: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
7003: \%ltitools,$canedit,$hostname);
7004: if ($error) {
7005: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7006: }
7007: if ($suppchanges) {
1.684 raeburn 7008: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 7009: undef($suppchanges);
7010: }
1.393 raeburn 7011: }
1.443 www 7012: } elsif ($supplementalflag) {
1.458 raeburn 7013: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 7014: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
7015: $hostname);
1.393 raeburn 7016: if ($error) {
7017: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 7018: }
1.393 raeburn 7019: }
1.389 tempelho 7020:
1.510 raeburn 7021: if ($needs_end) {
7022: $r->print(&endContentScreen());
7023: }
1.383 tempelho 7024:
1.329 droeschl 7025: if ($allowed) {
7026: $r->print('
7027: <form method="post" name="extimport" action="/adm/coursedocs">
7028: <input type="hidden" name="title" />
7029: <input type="hidden" name="url" />
7030: <input type="hidden" name="useform" />
7031: <input type="hidden" name="residx" />
7032: </form>');
7033: }
1.484 raeburn 7034: } elsif ($showdoc) {
1.329 droeschl 7035: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 7036: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 7037: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 7038: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 7039: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 7040: }
7041: }
1.630 raeburn 7042: unless ($noendpage) {
1.606 raeburn 7043: $r->print(&Apache::loncommon::end_page());
7044: }
1.329 droeschl 7045: return OK;
1.364 bisitz 7046: }
1.329 droeschl 7047:
1.440 raeburn 7048: sub embedded_form_elems {
7049: my ($phase,$primaryurl,$newidx) = @_;
7050: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 7051: $newidx =~s /\D+//g;
1.440 raeburn 7052: return <<STATE;
7053: <input type="hidden" name="folderpath" value="$folderpath" />
7054: <input type="hidden" name="cmd" value="upload_embedded" />
7055: <input type="hidden" name="newidx" value="$newidx" />
7056: <input type="hidden" name="phase" value="$phase" />
7057: <input type="hidden" name="primaryurl" value="$primaryurl" />
7058: STATE
7059: }
7060:
7061: sub embedded_destination {
7062: my $folder=$env{'form.folder'};
7063: my $destination = 'docs/';
7064: if ($folder =~ /^supplemental/) {
7065: $destination = 'supplemental/';
7066: }
7067: if (($folder eq 'default') || ($folder eq 'supplemental')) {
7068: $destination .= 'default/';
7069: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
7070: $destination .= $2.'/';
7071: }
1.634 raeburn 7072: my $newidx = $env{'form.newidx'};
7073: $newidx =~s /\D+//g;
7074: if ($newidx) {
7075: $destination .= $newidx;
7076: }
1.440 raeburn 7077: my $dir_root = '/userfiles';
7078: return ($destination,$dir_root);
7079: }
7080:
7081: sub return_to_editor {
7082: my $actionurl = '/adm/coursedocs';
7083: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7084: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7085: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7086: '</a></p>';
7087: }
7088:
1.476 raeburn 7089: sub decompression_info {
7090: my ($destination,$dir_root) = &embedded_destination();
7091: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7092: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7093: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7094: my $container='sequence';
1.480 raeburn 7095: my ($pathitem,$hiddenelem);
1.583 raeburn 7096: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 7097: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 7098: $container='page';
7099: }
1.480 raeburn 7100: unshift(@hiddens,$pathitem);
7101: foreach my $item (@hiddens) {
1.634 raeburn 7102: if ($item eq 'newidx') {
7103: next if ($env{'form.'.$item} =~ /\D/);
7104: }
1.480 raeburn 7105: if ($env{'form.'.$item}) {
7106: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 7107: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 7108: }
1.477 raeburn 7109: }
1.476 raeburn 7110: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7111: $hiddenelem);
7112: }
7113:
7114: sub decompression_phase_one {
7115: my ($dir,$file,$warning,$error,$output);
7116: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7117: &decompression_info();
1.490 raeburn 7118: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 7119: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7120: } else {
7121: my $file = $1;
1.630 raeburn 7122: $output =
1.481 raeburn 7123: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7124: $destination,$dir_root,
7125: $hiddenelem);
7126: if ($env{'form.autoextract_camtasia'}) {
7127: $output .= &remove_archive($docudom,$docuname,$container);
7128: }
1.476 raeburn 7129: }
7130: if ($error) {
7131: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7132: $error.'</p>'."\n";
7133: }
7134: if ($warning) {
7135: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7136: }
7137: return $output;
7138: }
7139:
7140: sub decompression_phase_two {
7141: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7142: &decompression_info();
1.481 raeburn 7143: my $output;
1.480 raeburn 7144: if ($env{'form.archivedelete'}) {
1.481 raeburn 7145: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 7146: }
7147: $output .=
1.481 raeburn 7148: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 7149: $destination,$dir_root,$hiddenelem);
7150: return $output;
7151: }
7152:
1.480 raeburn 7153: sub remove_archive {
7154: my ($docudom,$docuname,$container) = @_;
7155: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 7156: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 7157: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7158: if ($fatal) {
7159: if ($container eq 'page') {
7160: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7161: } else {
7162: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7163: }
1.583 raeburn 7164: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7165: } else {
7166: my $currcmd = $env{'form.cmd'};
7167: my $position = $env{'form.position'};
1.583 raeburn 7168: my $archiveidx = $position;
1.563 raeburn 7169: if ($position > 0) {
1.583 raeburn 7170: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7171: $archiveidx = $position-1;
7172: }
7173: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 7174: my ($title,$url,@rrest) =
1.583 raeburn 7175: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7176: if ($url eq $env{'form.archiveurl'}) {
7177: if (&handle_edit_cmd($docuname,$docudom)) {
7178: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 7179: if ($suppchanges) {
7180: &Apache::lonnet::update_supp_caches($docudom,$docuname);
7181: undef($suppchanges);
7182: }
1.583 raeburn 7183: if ($fatal) {
7184: if ($container eq 'page') {
7185: $delwarning = &mt('An error occurred updating the contents of the current page.');
7186: } else {
7187: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7188: }
1.480 raeburn 7189: } else {
1.583 raeburn 7190: $delresult = &mt('Archive file removed.');
1.480 raeburn 7191: }
7192: }
1.583 raeburn 7193: } else {
7194: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7195: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7196: }
7197: }
7198: $env{'form.cmd'} = $currcmd;
7199: }
7200: if ($delwarning) {
7201: $output = '<p class="LC_warning">'.
7202: $delwarning.
7203: '</p>';
7204: }
7205: if ($delresult) {
7206: $output .= '<p class="LC_info">'.
7207: $delresult.
7208: '</p>';
7209: }
1.481 raeburn 7210: return $output;
1.480 raeburn 7211: }
7212:
1.484 raeburn 7213: sub generate_admin_menu {
1.611 raeburn 7214: my ($crstype,$canedit) = @_;
1.484 raeburn 7215: my $lc_crstype = lc($crstype);
7216: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 7217: my %lt= ( # do not translate here
1.484 raeburn 7218: 'vc' => 'Verify Content',
7219: 'cv' => 'Check/Set Resource Versions',
7220: 'ls' => 'List Resource Identifiers',
1.651 raeburn 7221: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 7222: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 7223: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 7224: );
1.484 raeburn 7225: my ($candump,$dumpurl);
7226: if ($home + $other > 0) {
7227: $candump = 'F';
7228: if ($home) {
7229: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7230: } else {
7231: my @hosts;
7232: foreach my $aurole (keys(%outhash)) {
7233: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7234: push(@hosts,$outhash{$aurole});
1.538 raeburn 7235: }
1.484 raeburn 7236: }
7237: if (@hosts == 1) {
7238: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7239: '&role='.
7240: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7241: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7242: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7243: } else {
7244: $dumpurl = "javascript:choose_switchserver_window()";
7245: }
7246: }
7247: }
7248: my @menu=
7249: ({ categorytitle=>'Administration',
7250: items =>[
7251: { linktext => $lt{'vc'},
7252: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7253: permission => 'F',
1.571 raeburn 7254: help => 'Docs_Verify_Content',
1.484 raeburn 7255: icon => 'verify.png',
7256: linktitle => 'Verify contents can be retrieved/rendered',
7257: },
7258: { linktext => $lt{'cv'},
7259: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7260: permission => 'F',
1.571 raeburn 7261: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7262: icon => 'resversion.png',
7263: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7264: },
7265: { linktext => $lt{'ls'},
7266: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7267: permission => 'F',
7268: #help => '',
7269: icon => 'symbs.png',
7270: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7271: },
1.651 raeburn 7272: { linktext => $lt{'ct'},
7273: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7274: permission => 'F',
7275: help => 'Docs_Short_URLs',
7276: icon => 'shorturls.png',
7277: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7278: },
1.484 raeburn 7279: ]
1.611 raeburn 7280: });
7281: if ($canedit) {
7282: push(@menu,
1.484 raeburn 7283: { categorytitle=>'Export',
7284: items =>[
7285: { linktext => $lt{'imse'},
7286: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7287: permission => 'F',
7288: help => 'Docs_Export_Course_Docs',
7289: icon => 'imsexport.png',
7290: linktitle => $lt{'imse'},
7291: },
7292: { linktext => $lt{'dcd'},
7293: url => $dumpurl,
7294: permission => $candump,
1.571 raeburn 7295: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7296: icon => 'dump.png',
7297: linktitle => $lt{'dcd'},
7298: },
7299: ]
7300: });
1.611 raeburn 7301: }
1.484 raeburn 7302: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7303: '<input type="hidden" id="dummy" />'."\n".
7304: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7305: '</form>';
1.329 droeschl 7306: }
7307:
7308: sub generate_edit_table {
1.538 raeburn 7309: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 7310: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7311: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7312: my %orderhash = %{$orderhash_ref};
1.611 raeburn 7313: my ($form, $activetab, $active, $disabled);
1.570 raeburn 7314: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7315: $activetab = $env{'form.active'};
7316: }
1.611 raeburn 7317: unless ($canedit) {
7318: $disabled = ' disabled="disabled"';
7319: }
1.472 raeburn 7320: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 7321: my $backtext = &mt('Exit Editor');
1.458 raeburn 7322: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 7323: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7324: '<li class="goback">'.
1.546 raeburn 7325: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 7326: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7327: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7328: '<li>'.
7329: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7330: &mt('Undo Delete').'</a></li>'."\n";
7331: if ($env{'form.docslog'}) {
7332: $form .= '<li class="active">';
7333: } else {
7334: $form .= '<li>';
7335: }
7336: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7337: &mt('History').'</a></li>'."\n";
7338: if ($env{'form.docslog'}) {
7339: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7340: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7341: }
1.458 raeburn 7342: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7343: if($name ne '00'){
1.371 tempelho 7344: if($activetab eq '' || $activetab ne $name){
7345: $active = '';
7346: }elsif($activetab eq $name){
7347: $active = 'class="active"';
7348: }
1.458 raeburn 7349: $form .= '<li style="float:right" '.$active
1.484 raeburn 7350: .' 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 7351: } else {
1.570 raeburn 7352: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7353:
7354: }
1.329 droeschl 7355: }
1.484 raeburn 7356: $form .= '</ul>'."\n";
7357: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7358:
7359: if ($to_show ne '') {
1.538 raeburn 7360: my $saveform;
7361: if ($need_save) {
7362: my $button = &mt('Make changes');
7363: my $path;
7364: if ($env{'form.folderpath'}) {
7365: $path =
7366: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7367: }
7368: $saveform = <<"END";
7369: <div id="multisave" style="display:none; clear:both;" >
7370: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7371: <input type="hidden" name="folderpath" value="$path" />
7372: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7373: <input type="hidden" name="allhiddenresource" value="" />
7374: <input type="hidden" name="allencrypturl" value="" />
7375: <input type="hidden" name="allrandompick" value="" />
7376: <input type="hidden" name="allrandomorder" value="" />
7377: <input type="hidden" name="changeparms" value="" />
7378: <input type="hidden" name="multiremove" value="" />
7379: <input type="hidden" name="multicut" value="" />
7380: <input type="hidden" name="multicopy" value="" />
7381: <input type="hidden" name="multichange" value="" />
7382: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7383: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7384: </form>
7385: </div>
7386: END
7387: }
7388: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7389: }
1.363 ehlerst 7390: foreach my $field (keys(%orderhash)){
1.390 tempelho 7391: if($field ne '00'){
1.422 onken 7392: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7393: $active = 'style="display: none;float:left"';
1.422 onken 7394: }elsif($activetab eq $field){
1.458 raeburn 7395: $active = 'style="display:block;float:left"';
1.422 onken 7396: }
7397: $form .= '<div id="'.$field.$tid.'"'
7398: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7399: .'</div>'."\n";
1.363 ehlerst 7400: }
7401: }
1.484 raeburn 7402: unless ($env{'form.docslog'}) {
7403: $form .= '</div></div>'."\n";
7404: }
1.329 droeschl 7405: return $form;
7406: }
7407:
7408: sub editing_js {
1.622 raeburn 7409: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7410: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7411: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7412: p_mnf => 'Name of New Folder',
7413: t_mnf => 'New Folder',
7414: p_mnp => 'Name of New Page',
7415: t_mnp => 'New Page',
1.451 www 7416: p_mxu => 'Title for the External Score',
1.349 biermanm 7417: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7418: p_msb => 'Title for the Problem',
7419: p_mdb => 'Title for the Drop Box',
1.336 schafran 7420: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7421: p_mwp => 'Title for Web Page',
1.606 raeburn 7422: p_mnr => 'Title for the Resource',
1.348 weissno 7423: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7424: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7425: p_mab_alrt1 => 'Not a valid user:domain',
7426: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7427: p_chn => 'New Title',
7428: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7429: p_rmr2a => 'Remove',
7430: p_rmr2b => '?',
7431: p_rmr3a => 'Remove those',
7432: p_rmr3b => 'items?',
7433: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7434: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7435: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7436: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7437: p_ctr2a => 'Cut',
7438: p_ctr2b => '?',
7439: p_ctr3a => 'Cut those',
7440: p_ctr3b => 'items?',
1.633 raeburn 7441: setal => 'Enter a (unique) alias',
7442: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7443: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7444: imsfile => 'You must choose an IMS package for import',
7445: imscms => 'You must select which Course Management System was the source of the IMS package',
7446: invurl => 'Invalid URL',
7447: titbl => 'Title is blank',
1.538 raeburn 7448: more => '(More ...)',
7449: less => '(Less ...)',
1.543 raeburn 7450: noor => 'No actions selected or changes to settings specified.',
7451: noch => 'No changes to settings specified.',
7452: noac => 'No actions selected.',
1.606 raeburn 7453: nofi => 'No file selected',
7454: tinc => 'Title in course',
7455: sunm => 'Sub-directory name',
1.618 raeburn 7456: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 7457: sele => 'Select',
7458: swit => 'Switch server required',
1.329 droeschl 7459: );
1.594 damieng 7460: &js_escape(\%js_lt);
1.433 raeburn 7461: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7462: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7463: my $main_container_page;
1.519 raeburn 7464: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7465: $main_container_page = 1;
1.434 raeburn 7466: }
1.617 raeburn 7467: my $backtourl;
7468: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7469: my $toplevelsupp = &supplemental_base();
1.690 raeburn 7470: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 7471: my @ids=&Apache::lonnet::current_machine_ids();
7472: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 7473: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7474: my $caller = $1;
1.525 raeburn 7475: if ($caller =~ /^supplemental/) {
7476: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7477: } else {
7478: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7479: $res = &Apache::lonnet::clutter($res);
7480: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7481: my ($url,$anchor);
7482: if ($res =~ /^([^#]+)#([^#]+)$/) {
7483: $url = $1;
7484: $anchor = $2;
7485: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7486: $caller = $1.&escape('#').$anchor;
7487: }
1.614 raeburn 7488: } else {
7489: $url = $res;
1.609 raeburn 7490: }
1.640 raeburn 7491: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7492: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7493: $backtourl .= '?navmap=1';
7494: } else {
7495: $backtourl .= '?symb='.
7496: &HTML::Entities::encode($caller,'<>&"');
7497: }
1.622 raeburn 7498: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7499: if (($ENV{'SERVER_PORT'} == 443) &&
7500: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 7501: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 7502: if ($hostname ne '') {
7503: $backtourl = 'http://'.$hostname.$backtourl;
7504: }
7505: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7506: }
7507: }
1.623 raeburn 7508: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7509: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 7510: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 7511: if ($hostname ne '') {
7512: $backtourl = 'http://'.$hostname.$backtourl;
7513: }
7514: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 7515: }
1.623 raeburn 7516: }
1.622 raeburn 7517: }
1.609 raeburn 7518: if ($anchor ne '') {
7519: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7520: }
1.590 raeburn 7521: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7522: } else {
7523: $backtourl = '/adm/navmaps';
1.525 raeburn 7524: }
7525: }
7526: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7527: $backtourl = '/adm/menu';
7528: } elsif ($supplementalflag) {
1.682 raeburn 7529: if (($env{'request.role.adv'}) ||
7530: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7531: $backtourl = '/adm/supplemental';
7532: } else {
7533: $backtourl = '/adm/navmaps';
7534: }
1.525 raeburn 7535: } else {
7536: $backtourl = '/adm/navmaps';
1.472 raeburn 7537: }
7538:
1.655 raeburn 7539: my $fieldsets = "'doc'";
1.519 raeburn 7540: unless ($main_container_page) {
7541: $fieldsets .=",'ims'";
7542: }
1.655 raeburn 7543: my $extfieldsets = "'ext'";
7544: if ($posslti) {
7545: $extfieldsets .= ",'tool'";
7546: }
1.501 raeburn 7547: if ($supplementalflag) {
1.655 raeburn 7548: $fieldsets = "'suppdoc'";
7549: $extfieldsets = "'suppext'";
1.600 raeburn 7550: if ($posslti) {
1.655 raeburn 7551: $extfieldsets .= ",'supptool'";
1.600 raeburn 7552: }
1.501 raeburn 7553: }
1.655 raeburn 7554:
1.611 raeburn 7555: my $jsmakefunctions;
7556: if ($canedit) {
7557: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7558: function makenewfolder(targetform,folderseq) {
1.594 damieng 7559: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7560: if (foldername) {
1.676 raeburn 7561: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 7562: targetform.submit();
7563: }
7564: }
7565:
7566: function makenewpage(targetform,folderseq) {
1.594 damieng 7567: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7568: if (pagename) {
1.676 raeburn 7569: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 7570: targetform.submit();
7571: }
7572: }
7573:
7574: function makeexamupload() {
1.594 damieng 7575: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7576: if (title) {
1.329 droeschl 7577: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 7578: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 7579: this.document.forms.newexamupload.submit();
7580: }
7581: }
7582:
7583: function makesmppage() {
1.594 damieng 7584: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7585: if (title) {
1.329 droeschl 7586: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 7587: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7588: this.document.forms.newsmppg.submit();
7589: }
7590: }
7591:
1.534 raeburn 7592: function makewebpage(type) {
1.594 damieng 7593: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7594: var formname;
7595: if (type == 'supp') {
7596: formname = this.document.forms.supwebpage;
7597: } else {
7598: formname = this.document.forms.newwebpage;
7599: }
7600: if (title) {
7601: var webpage = formname.importdetail.value;
1.675 raeburn 7602: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 7603: formname.submit();
7604: }
7605: }
7606:
1.329 droeschl 7607: function makesmpproblem() {
1.594 damieng 7608: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7609: if (title) {
1.329 droeschl 7610: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 7611: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 7612: this.document.forms.newsmpproblem.submit();
7613: }
7614: }
7615:
7616: function makedropbox() {
1.594 damieng 7617: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7618: if (title) {
1.329 droeschl 7619: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 7620: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 7621: this.document.forms.newdropbox.submit();
7622: }
7623: }
7624:
7625: function makebulboard() {
1.594 damieng 7626: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7627: if (title) {
7628: this.document.forms.newbul.importdetail.value=
1.676 raeburn 7629: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7630: this.document.forms.newbul.submit();
7631: }
7632: }
7633:
7634: function makeabout() {
1.594 damieng 7635: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7636: if (user) {
7637: var comp=new Array();
7638: comp=user.split(':');
7639: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7640: if ((comp[0]) && (comp[1])) {
7641: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7642: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7643: this.document.forms.newaboutsomeone.submit();
7644: } else {
7645: alert("$js_lt{'p_mab_alrt1'}");
7646: }
7647: } else {
7648: alert("$js_lt{'p_mab_alrt2'}");
7649: }
7650: }
7651: }
7652:
7653: function makenew(targetform) {
7654: targetform.submit();
7655: }
7656:
7657: function changename(folderpath,index,oldtitle) {
7658: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7659: if (title) {
7660: this.document.forms.renameform.markcopy.value='';
7661: this.document.forms.renameform.title.value=title;
7662: this.document.forms.renameform.cmd.value='rename_'+index;
7663: this.document.forms.renameform.folderpath.value=folderpath;
7664: this.document.forms.renameform.submit();
7665: }
7666: }
7667:
1.633 raeburn 7668: function setalias(folderpath,index) {
7669: var alias = prompt('$js_lt{"setal"}');
7670: if ((alias != null) && (alias != '')) {
7671: this.document.forms.aliasform.alias.value=alias;
7672: this.document.forms.aliasform.cmd.value='setalias_'+index;
7673: this.document.forms.aliasform.folderpath.value=folderpath;
7674: this.document.forms.aliasform.submit();
7675: }
7676: }
7677:
7678: function delalias(folderpath,index) {
7679: if (confirm('$js_lt{"delal"}')) {
7680: this.document.forms.aliasform.cmd.value='delalias_'+index;
7681: this.document.forms.aliasform.folderpath.value=folderpath;
7682: this.document.forms.aliasform.submit();
7683: }
7684: }
7685:
1.611 raeburn 7686: ENDNEWSCRIPT
7687: } else {
7688: $jsmakefunctions = <<ENDNEWSCRIPT;
7689:
7690: function makenewfolder() {
7691: alert("$js_lt{'edri'}");
7692: }
7693:
7694: function makenewpage() {
7695: alert("$js_lt{'edri'}");
7696: }
7697:
7698: function makeexamupload() {
7699: alert("$js_lt{'edri'}");
7700: }
7701:
7702: function makesmppage() {
7703: alert("$js_lt{'edri'}");
7704: }
7705:
7706: function makewebpage(type) {
7707: alert("$js_lt{'edri'}");
7708: }
7709:
7710: function makesmpproblem() {
7711: alert("$js_lt{'edri'}");
7712: }
7713:
7714: function makedropbox() {
7715: alert("$js_lt{'edri'}");
7716: }
7717:
7718: function makebulboard() {
7719: alert("$js_lt{'edri'}");
7720: }
7721:
7722: function makeabout() {
7723: alert("$js_lt{'edri'}");
7724: }
7725:
7726: function changename() {
7727: alert("$js_lt{'edri'}");
7728: }
7729:
1.633 raeburn 7730: function setalias() {
7731: alert("$js_lt{'edri'}");
7732: }
7733:
7734: function delalias() {
7735: alert("$js_lt{'edri'}");
7736: }
7737:
1.611 raeburn 7738: function makenew() {
7739: alert("$js_lt{'edri'}");
7740: }
7741:
7742: function groupimport() {
7743: alert("$js_lt{'edri'}");
1.335 ehlerst 7744: }
1.611 raeburn 7745:
7746: function groupsearch() {
7747: alert("$js_lt{'edri'}");
1.335 ehlerst 7748: }
1.611 raeburn 7749:
7750: function groupopen(url,recover) {
7751: var options="scrollbars=1,resizable=1,menubar=0";
7752: idxflag=1;
7753: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7754: idx.focus();
1.329 droeschl 7755: }
7756:
1.611 raeburn 7757: ENDNEWSCRIPT
7758:
7759: }
7760: return <<ENDSCRIPT;
7761:
7762: $jsmakefunctions
7763:
1.501 raeburn 7764: function toggleUpload(caller) {
7765: var blocks = Array($fieldsets);
7766: for (var i=0; i<blocks.length; i++) {
7767: var disp = 'none';
7768: if (caller == blocks[i]) {
7769: var curr = document.getElementById('upload'+caller+'form').style.display;
7770: if (curr == 'none') {
7771: disp='block';
7772: }
7773: }
7774: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 7775: }
7776: resize_scrollbox('contentscroll','1','1');
7777: return;
7778: }
7779:
7780: function toggleExternal(caller) {
7781: var blocks = Array($extfieldsets);
7782: for (var i=0; i<blocks.length; i++) {
7783: var disp = 'none';
7784: if (caller == blocks[i]) {
7785: var curr = document.getElementById('external'+caller+'form').style.display;
7786: if (curr == 'none') {
7787: disp='block';
7788: }
7789: }
7790: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7791: if ((caller == 'tool') || (caller == 'supptool')) {
7792: if (disp == 'block') {
1.655 raeburn 7793: if (document.getElementById('LC_exttoolid')) {
7794: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 7795: var suppflag = 0;
7796: if (caller == 'supptool') {
7797: suppflag = 1;
7798: }
7799: currForm = document.getElementById('new'+caller);
1.655 raeburn 7800: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 7801: }
7802: }
7803: }
1.501 raeburn 7804: }
1.502 raeburn 7805: resize_scrollbox('contentscroll','1','1');
7806: return;
7807: }
7808:
1.514 raeburn 7809: function toggleMap(caller) {
1.502 raeburn 7810: var disp = 'none';
1.510 raeburn 7811: if (document.getElementById('importmapform')) {
1.514 raeburn 7812: if (caller == 'map') {
7813: var curr = document.getElementById('importmapform').style.display;
7814: if (curr == 'none') {
7815: disp='block';
7816: }
1.510 raeburn 7817: }
7818: document.getElementById('importmapform').style.display=disp;
7819: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7820: }
1.501 raeburn 7821: return;
1.329 droeschl 7822: }
7823:
1.691 raeburn 7824: function toggleCrsRes(caller) {
1.606 raeburn 7825: var disp = 'none';
7826: if (document.getElementById('crsresform')) {
7827: if (caller == 'res') {
1.691 raeburn 7828: var form = document.getElementById('crsresform');
7829: var curr = form.style.display;
1.606 raeburn 7830: if (curr == 'none') {
7831: disp='block';
1.691 raeburn 7832: document.courseresform.authorrole.selectedIndex = 0;
7833: document.courseresform.authorpath.selectedIndex = 0;
7834: document.courseresform.newresourceadd.selectedIndex = 0;
7835: populateDirSelects(form,'authorrole','authorpath',1,0,0);
7836: toggleNewInCourse(document.courseresform);
7837: if (document.getElementById('newresource')) {
7838: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 7839: }
7840: if (document.courseresform.newresusetemp.length) {
7841: document.courseresform.newresusetemp[0].checked = true;
7842: toggleWithTemplate(document.courseresform);
7843: }
7844: document.courseresform.newresourcename.value = '';
7845: }
7846: }
7847: if (document.courseresform.newsubdir.length) {
7848: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7849: if (document.courseresform.newsubdir[j].value == 0) {
7850: document.courseresform.newsubdir[j].checked = true;
7851: }
7852: break;
7853: }
7854: if (document.getElementById('newsubdirname')) {
7855: document.getElementById('newsubdirname').type = "hidden";
7856: document.getElementById('newsubdirname').value = "";
7857: }
7858: if (document.getElementById('newsubdir')) {
7859: document.getElementById('newsubdir').innerHTML = "";
7860: }
7861: }
7862: document.getElementById('crsresform').style.display=disp;
7863: resize_scrollbox('contentscroll','1','0');
7864: }
7865: return;
7866: }
7867:
7868: function toggleNewsubdir(form) {
7869: if (form.newsubdir.length) {
7870: for (var j=0; j<form.newsubdir.length; j++) {
7871: if (form.newsubdir[j].checked) {
7872: if (document.getElementById('newsubdirname')) {
7873: if (form.newsubdir[j].value == '1') {
7874: document.getElementById('newsubdirname').type = "text";
7875: if (document.getElementById('newsubdir')) {
7876: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7877: }
7878: } else {
7879: document.getElementById('newsubdirname').type = "hidden";
7880: document.getElementById('newsubdirname').value = "";
7881: document.getElementById('newsubdir').innerHTML = "";
7882: }
7883: }
7884: break;
7885: }
7886: }
7887: }
7888: }
7889:
7890: function toggleCrsResTitle() {
7891: if (document.getElementById('newresource')) {
1.691 raeburn 7892: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
7893: if (selloc == 'course') {
1.606 raeburn 7894: document.getElementById('newresource').style.display = 'inline';
7895: document.courseresform.newresourceadd[0].checked = true;
7896: toggleNewInCourse(document.courseresform);
7897: } else {
7898: document.getElementById('newresource').style.display = 'none';
7899: }
1.689 raeburn 7900: }
7901: if (document.getElementById('newstdproblem')) {
7902: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
7903: document.getElementById('newstdproblem').style.display = 'none';
7904: if (document.getElementById('stdprobswitch')) {
7905: document.getElementById('stdprobswitch').style.display = 'block';
7906: }
7907: } else {
7908: document.getElementById('newstdproblem').style.display = 'block';
7909: if (document.getElementById('stdprobswitch')) {
7910: document.getElementById('stdprobswitch').style.display = 'none';
7911: }
7912: }
7913: }
1.606 raeburn 7914: }
7915:
7916: function toggleNewInCourse(form) {
7917: if (form.newresourceadd.length) {
7918: for (var i=0; i<form.newresourceadd.length; i++) {
7919: if (form.newresourceadd[i].checked) {
7920: if (document.getElementById('newresourcetitle')) {
7921: if (form.newresourceadd[i].value == '1') {
7922: document.getElementById('newresourcetitle').type = 'text';
7923: if (document.getElementById('newrestitle')) {
7924: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7925: }
7926: } else {
7927: document.getElementById('newresourcetitle').type = 'hidden';
7928: document.getElementById('newresourcetitle').value = '';
7929: if (document.getElementById('newrestitle')) {
7930: document.getElementById('newrestitle').innerHTML = '';
7931: }
7932: }
7933: }
7934: break;
7935: }
7936: }
7937: }
7938: }
7939:
7940: function toggleWithTemplate(form) {
7941: if (form.newresusetemp.length) {
7942: for (var i=0; i<form.newresusetemp.length; i++) {
7943: if (form.newresusetemp[i].checked) {
7944: if (document.getElementById('newrestemplate')) {
7945: if (form.newresusetemp[i].value == '1') {
7946: document.getElementById('newrestemplate').style.display = 'inline';
7947: toggleExampleText();
7948: } else {
7949: form.tempcategory.selectedIndex = 0;
7950: select1template_changed();
7951: document.getElementById('newrestemplate').style.display = 'none';
7952: }
7953: }
7954: }
7955: }
7956: }
7957: }
7958:
7959: function toggleExampleText() {
7960: if (document.getElementById('newresexample')) {
7961: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7962: if (url == '') {
7963: document.getElementById('newresexample').style.fontWeight = 'normal';
7964: } else {
7965: document.getElementById('newresexample').style.fontWeight = 'bold';
7966: }
7967: }
7968: }
7969:
7970: function getExample(width,height,scrolling,transparency) {
7971: var url;
7972: if (document.courseresform.newresusetemp.length) {
7973: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7974: if (document.courseresform.newresusetemp[i].checked) {
7975: if (document.courseresform.newresusetemp[i].value == '1') {
7976: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7977: if (url == '') {
7978: alert('Pick a category and template');
7979: } else {
7980: url = url.replace("$londocroot","");
7981: url += '?inhibitmenu=yes';
7982: }
7983: }
7984: break;
7985: }
7986: }
7987: }
7988: if (url != '') {
7989: openMyModal(url,width,height,scrolling,transparency,'');
7990: }
7991: }
7992:
1.690 raeburn 7993: function toggleImportCrsres(caller) {
1.606 raeburn 7994: var disp = 'none';
7995: if (document.getElementById('importcrsresform')) {
7996: if (caller == 'res') {
7997: var curr = document.getElementById('importcrsresform').style.display;
7998: if (curr == 'none') {
7999: disp='block';
1.698 raeburn 8000: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
8001: if ((document.getElementById('importcrsrescontent')) &&
8002: (document.getElementById('importcrsresempty'))) {
8003: var selelem = document.crsresimportform.elements['coursepath'];
8004: var numdirs = 0;
8005: if (selelem.options.length) {
8006: numdirs = selelem.options.length - 1;
8007: }
8008: if (numdirs) {
8009: document.getElementById('importcrsrescontent').style.display='block';
8010: document.getElementById('importcrsresempty').style.display='none';
8011: } else {
8012: document.getElementById('importcrsrescontent').style.display='none';
8013: document.getElementById('importcrsresempty').style.display='block';
8014: }
8015: }
1.606 raeburn 8016: }
8017: }
8018: document.getElementById('importcrsresform').style.display=disp;
8019: resize_scrollbox('contentscroll','1','0');
8020: }
8021: return;
8022: }
8023:
1.690 raeburn 8024: $showfile_js
8025:
1.691 raeburn 8026: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
8027: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
8028: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
8029: var selelem = form.elements[dirsel];
8030: var i, numfiles = selelem.options.length -1;
8031: if (numfiles >=0) {
8032: for (i = numfiles; i >= 0; i--) {
8033: selelem.remove(i);
8034: }
8035: }
8036: if ((location == '') || (location == null) || (location == 'undefined')) {
8037: if (selelem.options.length == 0) {
8038: selelem.options[selelem.options.length] = new Option('','');
8039: selelem.selectedIndex = 0;
8040: }
8041: if (document.getElementById('newstdproblem')) {
8042: document.getElementById('newstdproblem').style.display = 'none';
8043: }
8044: return;
8045: }
8046: var machineIds = new Array($machines_str);
8047: var athome = 0;
8048: var role = location;
8049: if ((location == 'author') || (location == 'course')) {
8050: if (document.getElementById('rolehome_'+location)) {
8051: var currhome = document.getElementById('rolehome_'+location).value;
8052: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8053: if (machineIds.includes(currhome)) {
8054: athome = 1;
8055: }
8056: }
8057: }
8058: } else {
8059: const roleinfo = location.split('___');
8060: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
8061: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
8062: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
8063: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8064: if (machineIds.includes(currhome)) {
8065: athome = 1;
8066: }
8067: }
8068: }
8069: }
8070: if (athome) {
8071: if (document.getElementById('stdprobswitch')) {
8072: document.getElementById('stdprobswitch').style.display = 'none';
8073: }
8074: if (document.getElementById('newstdproblem')) {
8075: document.getElementById('newstdproblem').style.display = 'none';
8076: }
8077: var http = new XMLHttpRequest();
8078: var url = "/adm/courseauthor";
1.698 raeburn 8079: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 8080: http.open("POST", url, true);
8081: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
8082: http.onreadystatechange = function() {
8083: if (http.readyState == 4 && http.status == 200) {
8084: var data = JSON.parse(http.responseText);
8085: if (Array.isArray(data.dirs)) {
8086: var len = data.dirs.length;
8087: if (len) {
8088: if (len > 1) {
8089: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
8090: }
8091: }
8092: if (len) {
8093: var j;
8094: for (j = 0; j < len; j++) {
8095: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
8096: }
8097: selelem.selectedIndex = 0;
1.697 raeburn 8098: if (len == 1) {
8099: toggleCrsResTitle();
8100: }
1.691 raeburn 8101: }
8102: }
8103: }
8104: }
8105: http.send(params);
8106: } else {
8107: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
8108: selelem.selectedIndex = 0;
8109: if (document.getElementById('stdprobswitch')) {
8110: document.getElementById('stdprobswitch').style.display = 'block';
8111: }
8112: if (document.getElementById('newstdproblem')) {
8113: document.getElementById('newstdproblem').style.display = 'none';
8114: }
8115: }
8116: }
8117: return;
8118: }
8119:
1.689 raeburn 8120: function switchForProb() {
8121: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8122: var url = '/adm/switchserver?otherserver=';
8123: var newhostid = '';
8124: var role = '';
8125: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8126: if (selloc == 'author') {
8127: newhostid = document.courseresform.rolehome_author.value;
8128: role = "au./&js_escape($env{'user.domain'})/";
8129: } else if (selloc == 'course') {
8130: newhostid = document.courseresform.rolehome_course.value;
8131: role = "&js_escape($env{'request.role'})";
8132: } else {
8133: var items = new Array();
8134: items = selloc.split('___');
8135: var len = document.courseresform.rolehome_coauthor.length;
8136: if (null == len) {
8137: var currval = document.courseresform.rolehome_coauthor.value;
8138: if (null != currval) {
8139: var info = new Array();
8140: info = currval.split('=');
8141: newhostid = info[2];
8142: role = info[0]+'./'+info[1];
8143: }
8144: } else {
8145: for (var i=0; i<len; i++) {
8146: var currval = document.courseresform.rolehome_coauthor[i].value;
8147: if (null != currval) {
8148: var info = new Array();
8149: info = currval.split('=');
8150: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
8151: newhostid = info[2];
8152: role = info[0]+'./'+info[1];
8153: break;
8154: }
8155: }
8156: }
8157: }
8158: }
8159: if (newhostid != '') {
8160: url += newhostid;
8161: if (role != '') {
8162: url += '&role='+role;
8163: }
8164: document.location.href = url;
8165: }
8166: }
8167: return;
8168: }
8169:
1.501 raeburn 8170: function makeims(imsform) {
8171: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 8172: alert("$js_lt{'imsfile'}");
1.501 raeburn 8173: return;
8174: }
8175: if (imsform.source.selectedIndex == 0) {
1.594 damieng 8176: alert("$js_lt{'imscms'}");
1.501 raeburn 8177: return;
8178: }
8179: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
8180: imsform.submit();
8181: }
8182:
1.478 raeburn 8183: function updatePick(targetform,index,caller) {
1.537 raeburn 8184: var pickitem;
8185: var picknumitem;
8186: var picknumtext;
8187: if (index == 'all') {
8188: pickitem = document.getElementById('randompickall');
8189: picknumitem = document.getElementById('rpicknumall');
8190: picknumtext = document.getElementById('rpicktextall');
8191: } else {
8192: pickitem = document.getElementById('randompick_'+index);
8193: picknumitem = document.getElementById('rpicknum_'+index);
8194: picknumtext = document.getElementById('randompicknum_'+index);
8195: }
1.478 raeburn 8196: if (pickitem.checked) {
1.594 damieng 8197: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 8198: if (picknum == '' || picknum == null) {
8199: if (caller == 'check') {
8200: pickitem.checked=false;
1.537 raeburn 8201: if (index == 'all') {
8202: picknumtext.innerHTML = '';
8203: if (caller == 'link') {
8204: propagateState(targetform,'rpicknum');
8205: }
8206: } else {
1.538 raeburn 8207: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8208: }
1.478 raeburn 8209: }
8210: } else {
8211: picknum.toString();
8212: var regexdigit=/^\\d+\$/;
8213: if (regexdigit.test(picknum)) {
8214: picknumitem.value = picknum;
1.537 raeburn 8215: if (index == 'all') {
1.538 raeburn 8216: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 8217: if (caller == 'link') {
8218: propagateState(targetform,'rpicknum');
8219: }
8220: } else {
8221: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 8222: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8223: }
1.478 raeburn 8224: } else {
8225: if (caller == 'check') {
1.537 raeburn 8226: if (index == 'all') {
8227: picknumtext.innerHTML = '';
8228: if (caller == 'link') {
8229: propagateState(targetform,'rpicknum');
8230: }
8231: } else {
8232: pickitem.checked=false;
1.538 raeburn 8233: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8234: }
1.478 raeburn 8235: }
8236: return;
8237: }
8238: }
8239: } else {
1.537 raeburn 8240: picknumitem.value = '';
8241: picknumtext.innerHTML = '';
8242: if (index == 'all') {
8243: if (caller == 'link') {
8244: propagateState(targetform,'rpicknum');
8245: }
8246: } else {
1.538 raeburn 8247: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8248: }
8249: }
8250: }
8251:
8252: function propagateState(form,param) {
8253: if (document.getElementById(param+'all')) {
8254: var setcheck = 0;
8255: var rpick = 0;
8256: if (param == 'rpicknum') {
8257: if (document.getElementById('randompickall')) {
8258: if (document.getElementById('randompickall').checked) {
8259: if (document.getElementById('rpicknumall')) {
8260: rpick = document.getElementById('rpicknumall').value;
8261: }
8262: }
8263: }
8264: } else {
8265: if (document.getElementById(param+'all').checked) {
8266: setcheck = 1;
8267: }
8268: }
1.538 raeburn 8269: var allidxlist;
8270: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8271: if (document.getElementById('all'+param+'idx')) {
8272: allidxlist = document.getElementById('all'+param+'idx').value;
8273: }
8274: var actions = new Array ('remove','cut','copy');
8275: for (var i=0; i<actions.length; i++) {
8276: if (actions[i] != param) {
8277: if (document.getElementById(actions[i]+'all')) {
8278: document.getElementById(actions[i]+'all').checked = false;
8279: }
8280: }
8281: }
8282: }
1.537 raeburn 8283: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 8284: allidxlist = form.allidx.value;
8285: }
8286: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
8287: allidxlist = form.allmapidx.value;
8288: }
8289: if ((allidxlist != '') && (allidxlist != null)) {
8290: var allidxs = allidxlist.split(',');
8291: if (allidxs.length > 1) {
8292: for (var i=0; i<allidxs.length; i++) {
8293: if (document.getElementById(param+'_'+allidxs[i])) {
8294: if (param == 'rpicknum') {
8295: if (document.getElementById('randompick_'+allidxs[i])) {
8296: if (document.getElementById('randompick_'+allidxs[i]).checked) {
8297: document.getElementById(param+'_'+allidxs[i]).value = rpick;
8298: if (rpick > 0) {
8299: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
8300: } else {
8301: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8302: }
8303: }
8304: }
8305: } else {
1.537 raeburn 8306: if (setcheck == 1) {
8307: document.getElementById(param+'_'+allidxs[i]).checked = true;
8308: } else {
8309: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 8310: if (param == 'randompick') {
8311: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8312: }
1.537 raeburn 8313: }
8314: }
8315: }
8316: }
1.538 raeburn 8317: if (setcheck == 1) {
8318: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8319: var actions = new Array('copy','cut','remove');
8320: for (var i=0; i<actions.length; i++) {
8321: var otheractions;
8322: var otheridxs;
8323: if (actions[i] === param) {
8324: continue;
8325: } else {
8326: if (document.getElementById('all'+actions[i]+'idx')) {
8327: otheractions = document.getElementById('all'+actions[i]+'idx').value;
8328: otheridxs = otheractions.split(',');
8329: if (otheridxs.length > 1) {
8330: for (var j=0; j<otheridxs.length; j++) {
8331: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
8332: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
8333: }
1.537 raeburn 8334: }
8335: }
8336: }
1.538 raeburn 8337: }
8338: }
8339: }
8340: }
8341: }
8342: }
8343: }
8344: return;
8345: }
8346:
1.603 raeburn 8347: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 8348: var canedit = '$canedit';
8349: if (canedit == '') {
8350: alert("$js_lt{'edri'}");
8351: return;
8352: }
1.539 raeburn 8353: var dosettings;
8354: var doaction;
1.538 raeburn 8355: var control = document.togglemultsettings;
8356: if (context == 'actions') {
8357: control = document.togglemultactions;
1.539 raeburn 8358: doaction = 1;
8359: } else {
8360: dosettings = 1;
1.538 raeburn 8361: }
1.539 raeburn 8362: if (control) {
8363: if (control.showmultpick.length) {
8364: for (var i=0; i<control.showmultpick.length; i++) {
8365: if (control.showmultpick[i].checked) {
8366: if (control.showmultpick[i].value == 1) {
8367: if (context == 'settings') {
8368: dosettings = 0;
8369: } else {
8370: doaction = 0;
1.538 raeburn 8371: }
8372: }
8373: }
1.537 raeburn 8374: }
8375: }
1.539 raeburn 8376: }
8377: if (context == 'settings') {
8378: if (dosettings == 1) {
1.538 raeburn 8379: targetform.changeparms.value=param;
8380: targetform.submit();
8381: }
1.537 raeburn 8382: }
1.539 raeburn 8383: if (context == 'actions') {
8384: if (doaction == 1) {
8385: targetform.cmd.value=param+'_'+index;
8386: targetform.folderpath.value=folderpath;
8387: targetform.markcopy.value=idx+':'+param;
8388: targetform.copyfolder.value=folder+'.'+container;
8389: if (param == 'remove') {
1.603 raeburn 8390: var doremove = 0;
8391: if (skip_confirm) {
8392: if (confirm_removal) {
8393: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8394: doremove = 1;
8395: }
8396: } else {
8397: doremove = 1;
8398: }
8399: } else {
8400: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8401: doremove = 1;
8402: }
8403: }
8404: if (doremove) {
1.539 raeburn 8405: targetform.markcopy.value='';
8406: targetform.copyfolder.value='';
8407: targetform.submit();
8408: }
8409: }
8410: if (param == 'cut') {
1.594 damieng 8411: 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 8412: targetform.submit();
8413: return;
8414: }
8415: }
8416: if (param == 'copy') {
8417: targetform.submit();
8418: return;
8419: }
8420: targetform.markcopy.value='';
8421: targetform.copyfolder.value='';
8422: targetform.cmd.value='';
8423: targetform.folderpath.value='';
8424: return;
8425: } else {
8426: if (document.getElementById(param+'_'+idx)) {
8427: item = document.getElementById(param+'_'+idx);
8428: if (item.type == 'checkbox') {
8429: if (item.checked) {
8430: item.checked = false;
8431: } else {
8432: item.checked = true;
8433: singleCheck(item,idx,param);
8434: }
8435: }
8436: }
8437: }
8438: }
1.537 raeburn 8439: return;
8440: }
8441:
1.538 raeburn 8442: function singleCheck(caller,idx,action) {
8443: actions = new Array('cut','copy','remove');
8444: if (caller.checked) {
8445: for (var i=0; i<actions.length; i++) {
8446: if (actions[i] != action) {
8447: if (document.getElementById(actions[i]+'_'+idx)) {
8448: if (document.getElementById(actions[i]+'_'+idx).checked) {
8449: document.getElementById(actions[i]+'_'+idx).checked = false;
8450: }
1.537 raeburn 8451: }
8452: }
8453: }
1.478 raeburn 8454: }
1.537 raeburn 8455: return;
1.478 raeburn 8456: }
8457:
1.334 muellerd 8458: function unselectInactive(nav) {
1.335 ehlerst 8459: currentNav = document.getElementById(nav);
8460: currentLis = currentNav.getElementsByTagName('LI');
8461: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8462: if (currentLis[i].className == 'goback') {
8463: currentLis[i].className = 'goback';
8464: } else {
8465: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8466: currentLis[i].className = 'right';
1.472 raeburn 8467: } else {
1.374 tempelho 8468: currentLis[i].className = 'i';
1.472 raeburn 8469: }
8470: }
1.335 ehlerst 8471: }
1.332 tempelho 8472: }
8473:
1.334 muellerd 8474: function hideAll(current, nav, data) {
1.335 ehlerst 8475: unselectInactive(nav);
1.570 raeburn 8476: if (current) {
8477: if (current.className == 'right'){
8478: current.className = 'right active'
8479: } else {
8480: current.className = 'active';
8481: }
1.374 tempelho 8482: }
1.335 ehlerst 8483: currentData = document.getElementById(data);
8484: currentDivs = currentData.getElementsByTagName('DIV');
8485: for (i = 0; i < currentDivs.length; i++) {
8486: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8487: currentDivs[i].style.display = 'none';
1.330 tempelho 8488: }
8489: }
1.335 ehlerst 8490: }
1.330 tempelho 8491:
1.374 tempelho 8492: function openTabs(pageId) {
8493: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8494: if(tabnav.length > 2 ){
1.389 tempelho 8495: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8496: currentLis = currentNav.getElementsByTagName('LI');
8497: for(i = 0; i< currentLis.length; i++){
8498: if(currentLis[i].className == 'active') {
1.375 tempelho 8499: funcString = currentLis[i].onclick.toString();
8500: tab = funcString.split('"');
1.420 onken 8501: if(tab.length < 2) {
8502: tab = funcString.split("'");
8503: }
1.375 tempelho 8504: currentData = document.getElementById(tab[1]);
8505: currentData.style.display = 'block';
1.374 tempelho 8506: }
8507: }
8508: }
8509: }
8510:
1.334 muellerd 8511: function showPage(current, pageId, nav, data) {
1.570 raeburn 8512: currstate = current.className;
1.334 muellerd 8513: hideAll(current, nav, data);
1.375 tempelho 8514: openTabs(pageId);
1.334 muellerd 8515: unselectInactive(nav);
1.570 raeburn 8516: if ((currstate == 'active') || (currstate == 'right active')) {
8517: if (currstate == 'active') {
8518: current.className = '';
8519: } else {
8520: current.className = 'right';
8521: }
8522: activeTab = '';
1.656 raeburn 8523: toggleExternal();
1.570 raeburn 8524: toggleUpload();
8525: toggleMap();
1.606 raeburn 8526: toggleCrsRes();
8527: toggleImportCrsres();
1.570 raeburn 8528: resize_scrollbox('contentscroll','1','0');
8529: return;
8530: } else {
8531: current.className = 'active';
8532: }
1.330 tempelho 8533: currentData = document.getElementById(pageId);
8534: currentData.style.display = 'block';
1.458 raeburn 8535: activeTab = pageId;
1.656 raeburn 8536: toggleExternal();
1.501 raeburn 8537: toggleUpload();
1.503 raeburn 8538: toggleMap();
1.606 raeburn 8539: toggleCrsRes();
8540: toggleImportCrsres();
1.433 raeburn 8541: if (nav == 'mainnav') {
8542: var storedpath = "$docs_folderpath";
1.434 raeburn 8543: var storedpage = "$main_container_page";
1.433 raeburn 8544: var reg = new RegExp("^supplemental");
8545: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8546: if (storedpage == 1) {
8547: document.simpleedit.folderpath.value = '';
8548: document.uploaddocument.folderpath.value = '';
8549: } else {
8550: if (reg.test(storedpath)) {
8551: document.simpleedit.folderpath.value = '$toplevelmain';
8552: document.uploaddocument.folderpath.value = '$toplevelmain';
8553: document.newext.folderpath.value = '$toplevelmain';
8554: } else {
8555: document.simpleedit.folderpath.value = storedpath;
8556: document.uploaddocument.folderpath.value = storedpath;
8557: document.newext.folderpath.value = storedpath;
8558: }
1.433 raeburn 8559: }
8560: } else {
1.434 raeburn 8561: if (reg.test(storedpath)) {
8562: document.simpleedit.folderpath.value = storedpath;
8563: document.supuploaddocument.folderpath.value = storedpath;
8564: document.supnewext.folderpath.value = storedpath;
8565: } else {
1.433 raeburn 8566: document.simpleedit.folderpath.value = '$toplevelsupp';
8567: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8568: document.supnewext.folderpath.value = '$toplevelsupp';
8569: }
8570: }
8571: }
1.485 raeburn 8572: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8573: return false;
8574: }
1.329 droeschl 8575:
1.472 raeburn 8576: function toContents(jumpto) {
8577: var newurl = '$backtourl';
1.525 raeburn 8578: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8579: newurl = newurl+'?postdata='+jumpto;
8580: }
8581: location.href=newurl;
8582: }
8583:
1.538 raeburn 8584: function togglePick(caller,value) {
8585: var disp = 'none';
8586: if (document.getElementById('multi'+caller)) {
8587: var curr = document.getElementById('multi'+caller).style.display;
8588: if (value == 1) {
8589: disp='block';
8590: }
8591: if (curr == disp) {
8592: return;
8593: }
8594: document.getElementById('multi'+caller).style.display=disp;
8595: if (value == 1) {
1.594 damieng 8596: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8597: } else {
8598: document.getElementById('more'+caller).innerHTML = '';
8599: }
8600: if (caller == 'actions') {
8601: setClass(value);
8602: setBoxes(value);
8603: }
8604: }
8605: var showButton = multiSettings();
8606: if (showButton != 1) {
8607: showButton = multiActions();
8608: }
8609: if (document.getElementById('multisave')) {
8610: if (showButton == 1) {
8611: document.getElementById('multisave').style.display='block';
8612: } else {
8613: document.getElementById('multisave').style.display='none';
8614: }
8615: }
8616: resize_scrollbox('contentscroll','1','1');
8617: return;
8618: }
8619:
8620: function toggleCheckUncheck(caller,more) {
8621: if (more == 1) {
1.594 damieng 8622: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8623: document.getElementById('allfields'+caller).style.display='block';
8624: } else {
1.594 damieng 8625: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8626: document.getElementById('allfields'+caller).style.display='none';
8627: }
8628: resize_scrollbox('contentscroll','1','1');
8629: }
8630:
8631: function multiSettings() {
8632: var inuse = 0;
8633: var settingsform = document.togglemultsettings;
8634: if (settingsform.showmultpick.length > 1) {
8635: for (var i=0; i<settingsform.showmultpick.length; i++) {
8636: if (settingsform.showmultpick[i].checked) {
8637: if (settingsform.showmultpick[i].value == 1) {
8638: inuse = 1;
8639: }
8640: }
8641: }
8642: }
8643: return inuse;
8644: }
8645:
8646: function multiActions() {
8647: var inuse = 0;
8648: var actionsform = document.togglemultactions;
8649: if (actionsform.showmultpick.length > 1) {
8650: for (var i=0; i<actionsform.showmultpick.length; i++) {
8651: if (actionsform.showmultpick[i].checked) {
8652: if (actionsform.showmultpick[i].value == 1) {
8653: inuse = 1;
8654: }
8655: }
8656: }
8657: }
8658: return inuse;
8659: }
8660:
8661: function checkSubmits() {
8662: var numchanges = 0;
8663: var form = document.saveactions;
8664: var doactions = multiActions();
1.542 raeburn 8665: var cutwarnings = 0;
8666: var remwarnings = 0;
1.603 raeburn 8667: var removalinfo = 0;
1.538 raeburn 8668: if (doactions == 1) {
8669: var remidxlist = document.cumulativeactions.allremoveidx.value;
8670: if ((remidxlist != '') && (remidxlist != null)) {
8671: var remidxs = remidxlist.split(',');
8672: for (var i=0; i<remidxs.length; i++) {
8673: if (document.getElementById('remove_'+remidxs[i])) {
8674: if (document.getElementById('remove_'+remidxs[i]).checked) {
8675: form.multiremove.value += remidxs[i]+',';
8676: numchanges ++;
1.542 raeburn 8677: if (document.getElementById('skip_remove_'+remidxs[i])) {
8678: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8679: remwarnings ++;
8680: }
8681: }
1.603 raeburn 8682: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8683: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8684: removalinfo ++;
8685: }
8686: }
1.537 raeburn 8687: }
8688: }
1.538 raeburn 8689: }
8690: }
8691: var cutidxlist = document.cumulativeactions.allcutidx.value;
8692: if ((cutidxlist != '') && (cutidxlist != null)) {
8693: var cutidxs = cutidxlist.split(',');
8694: for (var i=0; i<cutidxs.length; i++) {
8695: if (document.getElementById('cut_'+cutidxs[i])) {
8696: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8697: form.multicut.value += cutidxs[i]+',';
8698: numchanges ++;
1.542 raeburn 8699: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8700: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8701: cutwarnings ++;
8702: }
8703: }
1.537 raeburn 8704: }
8705: }
8706: }
8707: }
1.538 raeburn 8708: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8709: if ((copyidxlist != '') && (copyidxlist != null)) {
8710: var copyidxs = copyidxlist.split(',');
8711: for (var i=0; i<copyidxs.length; i++) {
8712: if (document.getElementById('copy_'+copyidxs[i])) {
8713: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8714: form.multicopy.value += copyidxs[i]+',';
8715: numchanges ++;
8716: }
8717: }
8718: }
8719: }
8720: if (numchanges > 0) {
8721: form.multichange.value = numchanges;
8722: }
1.537 raeburn 8723: }
1.538 raeburn 8724: var dosettings = multiSettings();
1.543 raeburn 8725: var haschanges = 0;
1.538 raeburn 8726: if (dosettings == 1) {
8727: form.allencrypturl.value = '';
8728: form.allhiddenresource.value = '';
1.543 raeburn 8729: form.changeparms.value = 'all';
8730: var patt=new RegExp(",\$");
1.538 raeburn 8731: var allidxlist = document.cumulativesettings.allidx.value;
8732: if ((allidxlist != '') && (allidxlist != null)) {
8733: var allidxs = allidxlist.split(',');
8734: if (allidxs.length > 1) {
8735: for (var i=0; i<allidxs.length; i++) {
8736: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8737: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8738: form.allhiddenresource.value += allidxs[i]+',';
8739: }
8740: }
8741: if (document.getElementById('encrypturl_'+allidxs[i])) {
8742: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8743: form.allencrypturl.value += allidxs[i]+',';
8744: }
8745: }
8746: }
1.543 raeburn 8747: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8748: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8749: }
1.538 raeburn 8750: }
8751: form.allrandompick.value = '';
8752: form.allrandomorder.value = '';
8753: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8754: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8755: var allmapidxs = allmapidxlist.split(',');
8756: for (var i=0; i<allmapidxs.length; i++) {
8757: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8758: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8759: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8760: if ((randompick.checked) && (rpicknum.value != '')) {
8761: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8762: }
8763: if (randorder.checked) {
8764: form.allrandomorder.value += allmapidxs[i]+',';
8765: }
1.537 raeburn 8766: }
1.543 raeburn 8767: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8768: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8769: }
8770: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8771: haschanges = 1;
8772: }
8773: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8774: haschanges = 1;
8775: }
8776: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8777: haschanges = 1;
8778: }
8779: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8780: haschanges = 1;
1.537 raeburn 8781: }
8782: }
1.543 raeburn 8783: if (doactions == 1) {
1.542 raeburn 8784: if (numchanges > 0) {
1.603 raeburn 8785: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8786: if (remwarnings > 0) {
1.594 damieng 8787: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8788: return false;
8789: }
8790: }
1.603 raeburn 8791: if (removalinfo > 0) {
8792: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8793: return false;
8794: }
8795: }
1.542 raeburn 8796: if (cutwarnings > 0) {
1.594 damieng 8797: 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 8798: return false;
8799: }
8800: }
8801: }
8802: form.submit();
8803: return true;
1.543 raeburn 8804: }
8805: }
8806: if (dosettings == 1) {
8807: if (haschanges == 1) {
1.542 raeburn 8808: form.submit();
8809: return true;
8810: }
1.543 raeburn 8811: }
8812: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8813: alert("$js_lt{'noor'}");
1.543 raeburn 8814: } else {
8815: if (dosettings == 1) {
1.594 damieng 8816: alert("$js_lt{'noch'}");
1.543 raeburn 8817: } else {
1.594 damieng 8818: alert("$js_lt{'noac'}");
1.543 raeburn 8819: }
8820: }
1.538 raeburn 8821: return false;
8822: }
8823:
8824: function setClass(value) {
8825: var cutclass = 'LC_docs_cut';
8826: var copyclass = 'LC_docs_copy';
8827: var removeclass = 'LC_docs_remove';
8828: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8829: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8830: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8831: var links = document.getElementsByTagName('a');
8832: for (var i=0; i<links.length; i++) {
8833: var classes = links[i].className;
8834: if (cutreg.test(classes)) {
8835: links[i].className = cutclass;
8836: if (value == 1) {
8837: links[i].className += " LC_menubuttons_link";
8838: }
8839: } else {
8840: if (copyreg.test(classes)) {
8841: links[i].className = copyclass;
8842: if (value == 1) {
8843: links[i].className += " LC_menubuttons_link";
8844: }
8845: } else {
8846: if (removereg.test(classes)) {
8847: links[i].className = removeclass;
8848: if (value == 1) {
8849: links[i].className += " LC_menubuttons_link";
8850: }
8851: }
8852: }
8853: }
8854: }
8855: return;
1.537 raeburn 8856: }
8857:
1.538 raeburn 8858: function setBoxes(value) {
8859: var remidxlist = document.cumulativeactions.allremoveidx.value;
8860: if ((remidxlist != '') && (remidxlist != null)) {
8861: var remidxs = remidxlist.split(',');
8862: for (var i=0; i<remidxs.length; i++) {
8863: if (document.getElementById('remove_'+remidxs[i])) {
8864: var item = document.getElementById('remove_'+remidxs[i]);
8865: if (value == 1) {
8866: item.className = 'LC_docs_remove';
8867: } else {
8868: item.className = 'LC_hidden';
8869: }
8870: }
8871: }
8872: }
8873: var cutidxlist = document.cumulativeactions.allcutidx.value;
8874: if ((cutidxlist != '') && (cutidxlist != null)) {
8875: var cutidxs = cutidxlist.split(',');
8876: for (var i=0; i<cutidxs.length; i++) {
8877: if (document.getElementById('cut_'+cutidxs[i])) {
8878: var item = document.getElementById('cut_'+cutidxs[i]);
8879: if (value == 1) {
8880: item.className = 'LC_docs_cut';
8881: } else {
8882: item.className = 'LC_hidden';
8883: }
8884: }
1.537 raeburn 8885: }
8886: }
1.538 raeburn 8887: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8888: if ((copyidxlist != '') && (copyidxlist != null)) {
8889: var copyidxs = copyidxlist.split(',');
8890: for (var i=0; i<copyidxs.length; i++) {
8891: if (document.getElementById('copy_'+copyidxs[i])) {
8892: var item = document.getElementById('copy_'+copyidxs[i]);
8893: if (value == 1) {
8894: item.className = 'LC_docs_copy';
8895: } else {
8896: item.className = 'LC_hidden';
8897: }
8898: }
1.537 raeburn 8899: }
8900: }
8901: return;
8902: }
8903:
1.606 raeburn 8904: function validImportCrsRes() {
8905: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8906: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8907: if ((fname == '') || (fname == null)) {
8908: alert("$js_lt{'nofi'}");
8909: return false;
8910: }
8911: var url = '/res/$coursedom/$coursenum/';
8912: if (path && path != '/') {
8913: url += path+'/';
8914: }
8915: if (fname != '') {
8916: url += fname;
8917: }
8918: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 8919: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 8920: return true;
8921: }
8922:
8923: function validateNewRes(caller) {
8924: if (caller == 'single') {
8925: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8926: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8927: var resname = document.courseresform.newresourcename.value;
8928: }
8929: }
8930:
1.611 raeburn 8931: ENDSCRIPT
1.329 droeschl 8932: }
1.457 raeburn 8933:
1.483 raeburn 8934: sub history_tab_js {
8935: return <<"ENDHIST";
8936: function toggleHistoryDisp(choice) {
8937: document.docslogform.docslog.value = choice;
8938: document.docslogform.submit();
8939: return;
8940: }
8941:
8942: ENDHIST
8943: }
8944:
1.484 raeburn 8945: sub inject_data_js {
8946: return <<ENDINJECT;
8947:
8948: function injectData(current, hiddenField, name, value) {
8949: currentElement = document.getElementById(hiddenField);
8950: currentElement.name = name;
8951: currentElement.value = value;
8952: current.submit();
8953: }
8954:
8955: ENDINJECT
8956: }
8957:
8958: sub dump_switchserver_js {
8959: my @hosts = @_;
1.594 damieng 8960: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8961: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8962: swit => 'Switch server?',
1.594 damieng 8963: );
8964: my %html_js_lt = &Apache::lonlocal::texthash(
8965: swit => 'Switch server?',
1.568 raeburn 8966: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8967: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8968: chos => 'Choose server',
8969: );
1.594 damieng 8970: &js_escape(\%js_lt);
8971: &html_escape(\%html_js_lt);
8972: &js_escape(\%html_js_lt);
1.484 raeburn 8973: my $role = $env{'request.role'};
8974: my $js = <<"ENDSWJS";
8975: <script type="text/javascript">
8976: function write_switchserver() {
8977: var server;
8978: if (document.setserver.posshosts.length > 0) {
8979: for (var i=0; i<document.setserver.posshosts.length; i++) {
8980: if (document.setserver.posshosts[i].checked) {
8981: server = document.setserver.posshosts[i].value;
8982: }
8983: }
8984: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8985: }
8986: window.close();
8987: }
8988: </script>
8989:
8990: ENDSWJS
8991:
8992: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8993: {'only_body' => 1,
8994: 'js_ready' => 1,});
8995: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8996:
8997: my $hostpicker;
8998: my $count = 0;
8999: foreach my $host (sort(@hosts)) {
9000: my $checked;
9001: if ($count == 0) {
9002: $checked = ' checked="checked"';
9003: }
9004: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
9005: $host.'"'.$checked.' />'.$host.'</label> ';
9006: $count++;
9007: }
9008:
9009: return <<"ENDSWITCHJS";
9010:
9011: function dump_needs_switchserver(url) {
9012: if (url!='' && url!= null) {
1.594 damieng 9013: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 9014: go(url);
9015: }
9016: }
9017: return;
9018: }
9019:
9020: function choose_switchserver_window() {
9021: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
9022: newWindow.document.open();
9023: newWindow.document.writeln('$startpage');
1.594 damieng 9024: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
9025: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
9026: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 9027: '<form name="setserver" method="post" action="" \\/>\\n'+
9028: '$hostpicker\\n'+
9029: '<br \\/><br \\/>\\n'+
1.594 damieng 9030: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 9031: 'onclick="write_switchserver();" \\/>\\n'+
9032: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
9033: newWindow.document.writeln('$endpage');
9034: newWindow.document.close();
9035: newWindow.focus();
9036: }
9037:
9038: ENDSWITCHJS
9039: }
9040:
9041: sub makedocslogform {
9042: my ($formelems,$docslog) = @_;
9043: return <<"LOGSFORM";
9044: <form action="/adm/coursedocs" method="post" name="docslogform">
9045: <input type="hidden" name="docslog" value="$docslog" />
9046: $formelems
9047: </form>
9048: LOGSFORM
9049: }
9050:
9051: sub makesimpleeditform {
9052: my ($formelems) = @_;
9053: return <<"SIMPFORM";
9054: <form name="simpleedit" method="post" action="/adm/coursedocs">
9055: <input type="hidden" name="importdetail" value="" />
9056: $formelems
9057: </form>
9058: SIMPFORM
9059: }
9060:
1.606 raeburn 9061: sub makenewproblem {
9062: my ($r,$coursedom,$coursenum) = @_;
9063: # Creating a new problem
9064: my ($redirect,$error);
9065: if ($env{'form.authorrole'}) {
9066: my ($newsubdir,$filename);
9067: if ($env{'form.newsubdir'}) {
9068: if ($env{'form.newsubdirname'} ne '') {
9069: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 9070: }
1.606 raeburn 9071: }
9072: if ($env{'form.newresourcename'}) {
9073: $filename = $env{'form.newresourcename'};
9074: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
9075: $filename =~ s/`//g;
9076: $filename =~ s{/\.\./}{_}g;
9077: $filename =~ s/\.+/./g;
9078: $filename =~ s{/+}{_}g;
9079: if ($filename ne '') {
9080: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
9081: if (($ext) && ($ext ne '.problem')) {
9082: $filename = $name.'.problem';
9083: } elsif ($ext eq '') {
9084: $filename .= '.problem';
9085: }
9086: my $docroot = $r->dir_config('lonDocRoot');
9087: my @ids=&Apache::lonnet::current_machine_ids();
9088: if ($env{'form.authorrole'} eq 'author') {
9089: if ($env{'user.author'}) {
9090: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
9091: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
9092: my $path = $docroot.$url;
9093: my $subdir = $env{'form.authorpath'};
9094: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9095: }
9096: }
9097: } elsif ($env{'form.authorrole'} eq 'course') {
9098: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
9099: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
9100: my $url = "/priv/$coursedom/$coursenum";
9101: my $path=$docroot.$url;
9102: my $subdir = $env{'form.authorpath'};
9103: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9104: if ($redirect) {
9105: my $rightsfile = 'default.rights';
9106: my $sourcerights = "$path/$rightsfile";
9107: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
9108: my $now = time;
9109: if (!-e $sourcerights) {
9110: my $cid = $coursedom.'_'.$coursenum;
9111: if (open(my $fh,">$sourcerights")) {
9112: print $fh <<END;
9113: <accessrule effect="deny" realm="" type="course" role="" />
9114: <accessrule effect="allow" realm="$cid" type="course" role="" />
9115: END
9116: close($fh);
9117: }
9118: }
9119: if (!-e "$sourcerights.meta") {
9120: if (open(my $fh,">$sourcerights.meta")) {
9121: my $author=$env{'environment.firstname'}.' '.
9122: $env{'environment.middlename'}.' '.
9123: $env{'environment.lastname'}.' '.
9124: $env{'environment.generation'};
9125: $author =~ s/\s+$//;
9126: print $fh <<"END";
9127:
9128: <abstract></abstract>
9129: <author>$author</author>
9130: <authorspace>$coursenum:$coursedom</authorspace>
9131: <copyright>private</copyright>
9132: <creationdate>$now</creationdate>
9133: <customdistributionfile></customdistributionfile>
9134: <dependencies></dependencies>
9135: <domain>$coursedom</domain>
9136: <highestgradelevel>0</highestgradelevel>
9137: <keywords></keywords>
9138: <language>notset </language>
9139: <lastrevisiondate>$now</lastrevisiondate>
9140: <lowestgradelevel>0</lowestgradelevel>
9141: <mime>rights</mime>
9142: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
9143: <notes></notes>
9144: <obsolete></obsolete>
9145: <obsoletereplacement></obsoletereplacement>
9146: <owner>$coursenum:$coursedom</owner>
9147: <rule>deny:::course,allow:$cid::course</rule>
9148: <sourceavail></sourceavail>
9149: <standards></standards>
9150: <subject></subject>
9151: <title></title>
9152: END
1.654 raeburn 9153: close($fh);
9154: }
9155: }
9156: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
9157: if (!-e "$docroot/res/$coursedom") {
9158: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 9159: }
1.654 raeburn 9160: if (!-e "$docroot/res/$coursedom/$coursenum") {
9161: mkdir("$docroot/res/$coursedom/$coursenum",0755);
9162: }
9163: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
9164: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
9165: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 9166: }
9167: }
1.654 raeburn 9168: my $source = $docroot.$redirect;
9169: if (!-e "$source.meta") {
9170: my $cid = $coursedom.'_'.$coursenum;
9171: my $now = time;
9172: if (open(my $fh,">$source.meta")) {
9173: my $author=$env{'environment.firstname'}.' '.
9174: $env{'environment.middlename'}.' '.
9175: $env{'environment.lastname'}.' '.
9176: $env{'environment.generation'};
9177: $author =~ s/\s+$//;
9178: my $title = $env{'form.newresourcetitle'};
9179: $title =~ s/^\s+|\s+$//g;
9180: print $fh <<END;
1.606 raeburn 9181:
9182: <abstract></abstract>
9183: <author>$author</author>
9184: <authorspace>$coursenum:$coursedom</authorspace>
9185: <copyright>custom</copyright>
9186: <creationdate>$now</creationdate>
9187: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
9188: <dependencies></dependencies>
9189: <domain>$coursedom</domain>
9190: <highestgradelevel>0</highestgradelevel>
9191: <keywords></keywords>
9192: <language>notset </language>
9193: <lastrevisiondate>$now</lastrevisiondate>
9194: <lowestgradelevel>0</lowestgradelevel>
9195: <mime>problem</mime>
9196: <modifyinguser>$coursenum:$coursedom</modifyinguser>
9197: <notes></notes>
9198: <obsolete></obsolete>
9199: <obsoletereplacement></obsoletereplacement>
9200: <owner>$coursenum:$coursedom</owner>
9201: <sourceavail></sourceavail>
9202: <standards></standards>
9203: <subject></subject>
9204: <title>$title</title>
9205: END
1.654 raeburn 9206: close($fh);
1.606 raeburn 9207: }
9208: }
9209: }
9210: }
9211: } else {
9212: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
9213: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
9214: if (grep(/^\Q$rolehome\E$/,@ids)) {
9215: my $now = time;
9216: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
9217: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
9218: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
9219: my $url = "/priv/$audom/$auname";
9220: my $path = $r->dir_config('lonDocRoot').$url;
9221: my $subdir = $env{'form.authorpath'};
9222: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9223: }
9224: }
9225: }
9226: }
9227: }
9228: }
9229: }
9230: return ($redirect,$error);
9231: }
9232:
9233: sub finishnewprob {
1.654 raeburn 9234: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 9235: unless (-d $path) {
9236: unless (mkdir($path,02770)) {
9237: return;
9238: }
9239: }
1.606 raeburn 9240: my $redirect;
9241: if ($subdir ne '/') {
9242: $subdir = &cleandir($subdir);
9243: if (($subdir ne '') && (-d "$path/$subdir")) {
9244: $path .= "/$subdir";
9245: $url .= "/$subdir";
9246: }
9247: }
9248: my $dest;
9249: if ($newsubdir ne '') {
9250: $newsubdir = &cleandir($newsubdir);
9251: }
9252: if ($newsubdir ne '') {
9253: if (-d "$path/$newsubdir") {
9254: $dest = "$path/$newsubdir/$filename";
9255: } else {
9256: my $dirok;
9257: unless (-e "$path/$newsubdir") {
9258: if (mkdir("$path/$newsubdir",02770)) {
9259: if (chmod(02770,"$path/$newsubdir")) {
9260: $dirok = 1;
9261: }
9262: }
9263: }
9264: if ($dirok) {
9265: $dest = "$path/$newsubdir/$filename";
9266: }
9267: }
9268: if (($dest ne '') && (!-e $dest)) {
9269: $redirect = "$url/$newsubdir/$filename";
9270: }
9271: } else {
9272: $dest = "$path/$filename";
9273: if (($dest ne '') && (!-e $dest)) {
9274: $redirect = "$url/$filename";
9275: }
9276: }
1.654 raeburn 9277: if ((!-e $dest) && ($context ne 'upload')) {
9278: my $template = $env{'form.template'};
9279: my $copyfrom;
9280: if ($template ne '') {
9281: my %templates;
9282: my @files = &Apache::lonhomework::get_template_list('problem');
9283: foreach my $poss (@files) {
9284: if (ref($poss) eq 'ARRAY') {
9285: if ($template eq $poss->[0]) {
9286: $templates{$template} = 1;
9287: last;
9288: }
9289: }
9290: }
9291: if ($templates{$template}) {
9292: $copyfrom = $template;
9293: }
9294: }
9295: if ($filename =~ /\.problem$/) {
9296: unless ($copyfrom) {
9297: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
9298: }
9299: &File::Copy::copy($copyfrom,$dest);
9300: }
9301: }
1.606 raeburn 9302: return $redirect;
9303: }
9304:
9305: sub cleandir {
9306: my ($dir) = @_;
9307: $dir =~ s/^\s+//;
9308: $dir =~ s/\s+$//;
9309: $dir =~ s/\.+//g;
9310: $dir =~ s/[\#\?&%\":]//g;
9311: return $dir;
9312: }
9313:
1.329 droeschl 9314: 1;
9315: __END__
9316:
9317:
9318: =head1 NAME
9319:
9320: Apache::londocs.pm
9321:
9322: =head1 SYNOPSIS
9323:
9324: This is part of the LearningOnline Network with CAPA project
9325: described at http://www.lon-capa.org.
9326:
9327: =head1 SUBROUTINES
9328:
9329: =over
9330:
9331: =item %help=()
9332:
9333: Available help topics
9334:
9335: =item mapread()
9336:
1.344 bisitz 9337: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 9338: @order and @resources, determines status
9339: sets @order - pointer to resources in right order
9340: sets @resources - array with the resources with correct idx
9341:
9342: =item authorhosts()
9343:
9344: Return hash with valid author names
9345:
9346: =item clean()
9347:
9348: =item dumpcourse()
9349:
9350: Actually dump course
9351:
9352: =item group_import()
9353:
9354: Imports the given (name, url) resources into the course
9355: coursenum, coursedom, and folder must precede the list
9356:
9357: =item breadcrumbs()
9358:
9359: =item log_docs()
9360:
9361: =item docs_change_log()
9362:
9363: =item update_paste_buffer()
9364:
9365: =item print_paste_buffer()
9366:
9367: =item do_paste_from_buffer()
9368:
1.538 raeburn 9369: =item do_buffer_empty()
9370:
9371: =item clear_from_buffer()
9372:
1.492 raeburn 9373: =item get_newmap_url()
9374:
9375: =item dbcopy()
9376:
9377: =item uniqueness_check()
9378:
9379: =item contained_map_check()
9380:
9381: =item url_paste_fixups()
9382:
9383: =item apply_fixups()
9384:
9385: =item copy_dependencies()
9386:
1.329 droeschl 9387: =item update_parameter()
9388:
9389: =item handle_edit_cmd()
9390:
9391: =item editor()
9392:
9393: =item process_file_upload()
9394:
9395: =item process_secondary_uploads()
9396:
9397: =item is_supplemental_title()
9398:
9399: =item entryline()
9400:
9401: =item tiehash()
9402:
9403: =item untiehash()
9404:
9405: =item checkonthis()
9406:
9407: check on this
9408:
9409: =item verifycontent()
9410:
9411: Verify Content
9412:
1.636 raeburn 9413: =item devalidateversioncache()
9414:
9415: =item checkversions()
1.329 droeschl 9416:
9417: Check Versions
9418:
9419: =item mark_hash_old()
9420:
9421: =item is_hash_old()
9422:
9423: =item changewarning()
9424:
9425: =item init_breadcrumbs()
9426:
9427: Breadcrumbs for special functions
9428:
1.484 raeburn 9429: =item create_list_elements()
9430:
9431: =item create_form_ul()
9432:
9433: =item startContentScreen()
9434:
9435: =item endContentScreen()
9436:
9437: =item supplemental_base()
9438:
9439: =item embedded_form_elems()
9440:
9441: =item embedded_destination()
9442:
9443: =item return_to_editor()
9444:
9445: =item decompression_info()
9446:
9447: =item decompression_phase_one()
9448:
9449: =item decompression_phase_two()
9450:
9451: =item remove_archive()
9452:
9453: =item generate_admin_menu()
9454:
9455: =item generate_edit_table()
9456:
9457: =item editing_js()
9458:
9459: =item history_tab_js()
9460:
9461: =item inject_data_js()
9462:
9463: =item dump_switchserver_js()
9464:
1.485 raeburn 9465: =item resize_scrollbox_js()
1.484 raeburn 9466:
9467: =item makedocslogform()
9468:
1.485 raeburn 9469: =item makesimpleeditform()
9470:
1.329 droeschl 9471: =back
9472:
9473: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>