Annotation of loncom/interface/londocs.pm, revision 1.705
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.705 ! raeburn 4: # $Id: londocs.pm,v 1.704 2023/07/20 22:12:39 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'});
1.704 raeburn 1422: my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
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.704 raeburn 1435: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
1436: $toolcnum,$marker);
1.538 raeburn 1437: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1438: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1439: $is_external = 1;
1.704 raeburn 1440: } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
1441: ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1.598 raeburn 1442: $is_exttool = 1;
1.538 raeburn 1443: }
1444: if ($folder =~ /^supplemental/) {
1445: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1446: unless ($canpaste) {
1447: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1448: }
1449: } else {
1450: $canpaste = 1;
1451: }
1452: if ($canpaste) {
1453: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1454: my $srcdom = $1;
1455: my $srcnum = $2;
1456: my $rem = $3;
1457: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1458: $othercourse = 1;
1459: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1460: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1461: } else {
1462: $canpaste = 0;
1463: $nopaste = &mt('Paste from another course unavailable.');
1464: }
1465: }
1466: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1467: my $prefix = $1;
1468: $parent = $2;
1469: if ($folder !~ /^\Q$prefix\E/) {
1470: $areachange = 1;
1471: }
1472: $is_uploaded_map = 1;
1.492 raeburn 1473: }
1.597 raeburn 1474: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1475: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1476: if ($cid ne $env{'request.course.id'}) {
1477: my ($srcdom,$srcnum) = split(/_/,$cid);
1478: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.704 raeburn 1479: if ($is_exttool) {
1480: if ($toolcdom ne $coursedom) {
1481: $canpaste = 0;
1482: $nopaste = &mt('Paste from another domain unavailable.');
1483: } elsif ($toolcnum ne $coursenum) {
1484: my %toolsettings =
1485: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
1486: my %tooltypes = &Apache::loncommon::usable_exttools();
1487: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
1488: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
1489: $canpaste = 0;
1490: $nopaste = &mt('Paste from another course unavailable.');
1491: } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
1492: unless ($checkedsameinst) {
1493: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
1494: my $intdom = &Apache::lonnet::internet_dom($primary_id);
1495: if ($intdom ne '') {
1496: my $internet_names =
1497: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
1498: if (ref($internet_names) eq 'ARRAY') {
1499: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
1500: $same_institution = 1;
1501: }
1502: }
1503: }
1504: $checkedsameinst = 1;
1505: }
1506: if ($same_institution) {
1507: $othercrs = '<br />'.&mt('(from another course)');
1508: } else {
1509: $nopaste = &mt('Paste from another course unavailable.');
1510: }
1511: } else {
1512: $othercrs = '<br />'.&mt('(from another course)');
1513: }
1514: }
1.627 raeburn 1515: }
1.596 raeburn 1516: } else {
1517: $canpaste = 0;
1518: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1519: }
1.596 raeburn 1520: }
1.703 raeburn 1521: } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
1522: my ($audom,$auname) = ($1,$2);
1523: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
1524: if (&Apache::lonnet::is_course($audom,$auname)) {
1525: $canpaste = 0;
1526: $nopaste = &mt('Paste from another course unavailable.');
1527: }
1528: }
1.492 raeburn 1529: }
1.596 raeburn 1530: if ($canpaste) {
1531: push(@pasteable,$suffix);
1.629 raeburn 1532: }
1.538 raeburn 1533: }
1534: my $buffer;
1.627 raeburn 1535: if ($is_external) {
1.538 raeburn 1536: $buffer = &mt('External Resource').': '.
1537: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1538: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1539: } elsif ($is_exttool) {
1540: $buffer = &mt('External Tool').': '.
1541: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1542: } else {
1543: my $icon = &Apache::loncommon::icon($extension);
1544: if ($extension eq 'sequence' &&
1545: $url =~ m{/default_\d+\.sequence$}x) {
1546: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1547: $icon .= '/navmap.folder.closed.gif';
1548: }
1.589 raeburn 1549: my $title = $env{'docs.markedcopy_title_'.$suffix};
1550: if ($title eq '') {
1551: ($title) = ($url =~ m{/([^/]+)$});
1552: }
1.538 raeburn 1553: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1554: ': '.
1555: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1556: &LONCAPA::map::qtescape($title));
1.538 raeburn 1557: }
1558: $pasteitems .= '<div class="LC_left_float">';
1559: my ($options,$onclick);
1560: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1561: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1562: if (($is_uploaded_map) ||
1563: ($url =~ /(bulletinboard|smppg)$/) ||
1564: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1565: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1566: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1567: }
1568: }
1569: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1570: if ($nopaste) {
1.681 raeburn 1571: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 1572: } else {
1573: if ($othercrs) {
1574: $pasteitems .= $othercrs;
1575: }
1576: if ($options) {
1577: $pasteitems .= $options;
1.492 raeburn 1578: }
1579: }
1.538 raeburn 1580: $pasteitems .= '</div>';
1581: }
1582: }
1583: if ($pasteitems eq '') {
1584: &Apache::lonnet::delenv('docs.markedcopies');
1585: }
1586: my ($pasteform,$form_start,$buttons,$form_end);
1587: if ($pasteitems) {
1588: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1589: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1590: if (@pasteable) {
1.575 raeburn 1591: my $value = &mt('Paste to current folder');
1592: if ($container eq 'page') {
1593: $value = &mt('Paste to current page');
1594: }
1595: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1596: }
1597: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1598: if ($clipboardcount > 1) {
1599: $buttons .=
1600: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1601: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1602: (' 'x2).
1603: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1604: (' 'x2);
1.492 raeburn 1605: }
1.575 raeburn 1606: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1607: '</form>';
1.538 raeburn 1608: } else {
1609: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1610: }
1.538 raeburn 1611: $r->print($form_start
1612: .'<fieldset>'
1613: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1614: .$pasteitems
1615: .'</fieldset>'
1616: .$form_end);
1617: }
1618:
1619: sub paste_options {
1620: my ($suffix,$is_uploaded_map,$parent) = @_;
1621: my ($copytext,$movetext);
1622: if ($is_uploaded_map) {
1623: $copytext = &mt('Copy to new folder');
1624: $movetext = &mt('Move old');
1625: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1626: $copytext = &mt('Copy to new board');
1627: $movetext = &mt('Move (not posts)');
1628: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1629: $copytext = &mt('Copy to new page');
1630: $movetext = &mt('Move');
1.533 raeburn 1631: } else {
1.538 raeburn 1632: $copytext = &mt('Copy to new file');
1633: $movetext = &mt('Move');
1634: }
1635: my $output = '<br />'.
1636: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1637: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1638: '<label>'.
1639: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1640: $copytext.'</label></span>'.(' 'x2).' '.
1641: '<span class="LC_nobreak"><label>'.
1642: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1643: $movetext.'</label></span>';
1644: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1645: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1646: '</legend><table border="0">';
1647: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1648: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1649: my $lastdir = $parent;
1650: my %depths = (
1651: $lastdir => 0,
1652: );
1653: my (%display,%deps);
1654: for (my $i=0; $i<@pastemaps; $i++) {
1655: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1656: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1657: my @subfolders = split(/,/,$subfolderstr);
1658: $deps{$lastdir} = \@subfolders;
1659: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1660: my $depth = $depths{$lastdir} + 1;
1661: my $offset = int($depth * 4);
1662: my $indent = (' ' x $offset);
1663: for (my $j=0; $j<@subfolders; $j++) {
1664: $depths{$subfolders[$j]} = $depth;
1665: $display{$subfolders[$j]} =
1666: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1667: '<td><label>'.
1668: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1669: '<label>'.
1670: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1671: &mt('Move old').'</label>'.
1672: '</td></tr>';
1673: }
1.492 raeburn 1674: }
1.538 raeburn 1675: &recurse_print(\$output,$parent,\%deps,\%display);
1676: $output .= '</table></fieldset>';
1.329 droeschl 1677: }
1.538 raeburn 1678: $output .= '</div>';
1679: return $output;
1.488 raeburn 1680: }
1681:
1.492 raeburn 1682: sub recurse_print {
1.538 raeburn 1683: my ($outputref,$dir,$deps,$display) = @_;
1684: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1685: if (ref($deps->{$dir}) eq 'ARRAY') {
1686: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1687: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1688: }
1689: }
1690: }
1691:
1.488 raeburn 1692: sub supp_pasteable {
1693: my ($url) = @_;
1694: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1695: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1696: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1697: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1698: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1699: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1700: return 1;
1701: }
1702: return;
1.329 droeschl 1703: }
1704:
1.492 raeburn 1705: sub paste_popup_js {
1.594 damieng 1706: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1707: show => 'Show Options',
1708: hide => 'Hide Options',
1.594 damieng 1709: );
1710: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1711: none => 'No items selected from clipboard.',
1.492 raeburn 1712: );
1.594 damieng 1713: &html_escape(\%html_js_lt);
1714: &js_escape(\%html_js_lt);
1715: &js_escape(\%js_lt);
1.492 raeburn 1716: return <<"END";
1717:
1.538 raeburn 1718: function showPasteOptions(suffix) {
1719: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1720: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1721: return;
1722: }
1723:
1.538 raeburn 1724: function hidePasteOptions(suffix) {
1725: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1726: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1727: return;
1728: }
1729:
1730: function showOptions(caller,suffix) {
1731: if (document.getElementById('pasteoptionstext_'+suffix)) {
1732: if (caller.checked) {
1.594 damieng 1733: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1734: } else {
1735: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1736: }
1737: if (document.getElementById('pasteoptions_'+suffix)) {
1738: document.getElementById('pasteoptions_'+suffix).style.display='none';
1739: }
1740: }
1.492 raeburn 1741: return;
1742: }
1743:
1.541 raeburn 1744: function validateClipboard() {
1745: var numchk = 0;
1746: if (document.pasteform.pasting.length > 1) {
1747: for (var i=0; i<document.pasteform.pasting.length; i++) {
1748: if (document.pasteform.pasting[i].checked) {
1749: numchk ++;
1750: }
1751: }
1752: } else {
1753: if (document.pasteform.pasting.type == 'checkbox') {
1754: if (document.pasteform.pasting.checked) {
1755: numchk ++;
1756: }
1757: }
1758: }
1759: if (numchk > 0) {
1760: return true;
1761: } else {
1.594 damieng 1762: alert("$js_lt{'none'}");
1.541 raeburn 1763: return false;
1764: }
1765: }
1766:
1.575 raeburn 1767: function checkClipboard() {
1768: if (document.pasteform.pasting.length > 1) {
1769: for (var i=0; i<document.pasteform.pasting.length; i++) {
1770: document.pasteform.pasting[i].checked = true;
1771: }
1772: }
1773: return;
1774: }
1775:
1776: function uncheckClipboard() {
1777: if (document.pasteform.pasting.length >1) {
1778: for (var i=0; i<document.pasteform.pasting.length; i++) {
1779: document.pasteform.pasting[i].checked = false;
1780: }
1781: }
1782: return;
1783: }
1784:
1.492 raeburn 1785: END
1786:
1787: }
1788:
1.329 droeschl 1789: sub do_paste_from_buffer {
1.492 raeburn 1790: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1791:
1.538 raeburn 1792: # Array of items in paste buffer
1793: my (@currpaste,%pastebuffer,%allerrors);
1794: @currpaste = split(/,/,$env{'docs.markedcopies'});
1795:
1.492 raeburn 1796: # Early out if paste buffer is empty
1.538 raeburn 1797: if (@currpaste == 0) {
1.492 raeburn 1798: return ();
1.538 raeburn 1799: }
1800: map { $pastebuffer{$_} = 1; } @currpaste;
1801:
1802: # Array of items selected items to paste
1803: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1804:
1805: # Early out if nothing selected to paste
1806: if (@reqpaste == 0) {
1807: return();
1808: }
1809: my @topaste;
1810: foreach my $suffix (@reqpaste) {
1811: next if ($suffix =~ /\D/);
1812: next unless (exists($pastebuffer{$suffix}));
1813: push(@topaste,$suffix);
1814: }
1815:
1816: # Early out if nothing available to paste
1817: if (@topaste == 0) {
1818: return();
1.329 droeschl 1819: }
1820:
1.704 raeburn 1821: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
1822: %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
1823: %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
1824: %currltititles,$currltimax,$gotcrsltitools);
1825: $currltimax = 0;
1826: $gotcrsltitools = 0;
1.538 raeburn 1827: foreach my $suffix (@topaste) {
1828: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1829: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1830: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1831: # Supplemental content may only include certain types of content
1832: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1833: if ($folder =~ /^supplemental/) {
1834: unless (&supp_pasteable($url)) {
1835: $notinsupp{$suffix} = 1;
1836: next;
1837: }
1.492 raeburn 1838: }
1.538 raeburn 1839: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1840: my $srcd = $1;
1841: my $srcn = $2;
1.492 raeburn 1842: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1843: # check for mdc privilege in the course from which the resource was pasted
1844: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1845: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1846: $notincrs{$suffix} = 1;
1847: next;
1848: }
1.491 raeburn 1849: }
1.538 raeburn 1850: $srcdom{$suffix} = $srcd;
1851: $srcnum{$suffix} = $srcn;
1.597 raeburn 1852: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1853: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1854: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1855: my ($srcd,$srcn) = split(/_/,$cid);
1856: # When paste buffer was populated using an active role in a different course
1857: # check for mdc privilege in the course from which the resource was pasted
1858: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1859: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1860: $notincrs{$suffix} = 1;
1861: next;
1862: }
1863: }
1.632 raeburn 1864: # When buffer was populated using an active role in a different course
1.704 raeburn 1865: # disallow pasting of External Tool if course is in a different domain,
1866: # or if External Tool use is not permitted in this course.
1867: if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
1868: my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1869: if ($toolcdom ne $coursedom) {
1870: $notindom{$suffix} = 1;
1871: next;
1872: } elsif ($toolcnum ne $coursenum) {
1873: my %toolsettings =
1874: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
1875: my %tooltypes = &Apache::loncommon::usable_exttools();
1876: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
1877: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
1878: $othcrstool{$suffix} = 1;
1879: next;
1880: }
1881: if ($toolsettings{'id'} =~ /^c\d+$/) {
1882: unless ($gotcrsltitools) {
1883: %currcrsltitools =
1884: &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
1885: foreach my $item (sort(keys(%currcrsltitools))) {
1886: if (ref($currcrsltitools{$item}) eq 'HASH') {
1887: $currltimax ++;
1888: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
1889: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
1890: } else {
1891: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
1892: }
1893: }
1894: }
1895: $gotcrsltitools = 1;
1896: }
1897: }
1898: }
1.627 raeburn 1899: }
1.596 raeburn 1900: $srcdom{$suffix} = $srcd;
1901: $srcnum{$suffix} = $srcn;
1.703 raeburn 1902: } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
1903: my ($audom,$auname) = ($1,$2);
1904: # When buffer was populated using an active role in a different course
1905: # disallow pasting of published resources from Course Authoring Space
1906: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
1907: if (&Apache::lonnet::is_course($audom,$auname)) {
1908: $othcrsres{$suffix} = 1;
1909: next;
1910: }
1911: }
1.491 raeburn 1912: }
1.597 raeburn 1913: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1914: push(@dopaste,$suffix);
1915: if ($url=~/\.(page|sequence)$/) {
1916: $is_map{$suffix} = 1;
1917: }
1918: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1919: my $oldprefix = $1;
1.492 raeburn 1920: # When pasting content from Main Content to Supplemental Content and vice versa
1921: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1922: # a folder/page or a document).
1.538 raeburn 1923: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1924: $prefixchg{$suffix} = 'docstosupp';
1925: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1926: $prefixchg{$suffix} = 'supptodocs';
1927: }
1.491 raeburn 1928:
1.492 raeburn 1929: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1930: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1931: my @nested;
1932: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1933: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1934: my @deps = map { /\d+:([\d,]+$)/ } @items;
1935: foreach my $dep (@deps) {
1936: if ($dep =~ /,/) {
1937: push(@nested,split(/,/,$dep));
1938: } else {
1939: push(@nested,$dep);
1940: }
1.492 raeburn 1941: }
1.538 raeburn 1942: foreach my $item (@nested) {
1943: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1944: push(@{$marktomove{$suffix}},$type.'_'.$item);
1945: }
1.492 raeburn 1946: }
1947: }
1.488 raeburn 1948: }
1949: }
1950:
1.538 raeburn 1951: # Early out if nothing available to paste
1952: if (@dopaste == 0) {
1953: return ();
1954: }
1955:
1956: # Populate message hash and hashes used for main content <=> supplemental content
1957: # changes
1958:
1959: %msgs = &Apache::lonlocal::texthash (
1960: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1961: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 1962: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.704 raeburn 1963: othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.703 raeburn 1964: othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538 raeburn 1965: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1966: );
1967:
1968: %before = (
1969: docstosupp => {
1970: map => 'default',
1971: doc => 'docs',
1972: },
1973: supptodocs => {
1974: map => 'supplemental',
1975: doc => 'supplemental',
1976: },
1977: );
1978:
1979: %after = (
1980: docstosupp => {
1981: map => 'supplemental',
1982: doc => 'supplemental'
1983: },
1984: supptodocs => {
1985: map => 'default',
1986: doc => 'docs',
1987: },
1988: );
1989:
1990: # Retrieve information about all course maps in main content area
1991:
1992: my $allmaps = {};
1.704 raeburn 1993: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
1994: @updatetoolsenc,$updatetoolscache,$checkedsameinst,
1995: $same_institution);
1.538 raeburn 1996:
1997: # Loop over the items to paste
1998: foreach my $suffix (@dopaste) {
1.329 droeschl 1999: # Maps need to be copied first
1.538 raeburn 2000: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
2001: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 2002: %newurls,%tomove,%resdatacopy);
1.538 raeburn 2003: if (ref($marktomove{$suffix}) eq 'ARRAY') {
2004: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
2005: }
2006: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
2007: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 2008: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 2009: my $oldurl = $url;
2010: if ($is_map{$suffix}) {
1.491 raeburn 2011: # If pasting a map, check if map contains other maps
1.538 raeburn 2012: my (%hierarchy,%titles);
1.660 raeburn 2013: if (($folder =~ /^default/) && (!$donechk)) {
2014: $allmaps =
2015: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
2016: $env{"course.$env{'request.course.id'}.home"},
2017: $env{'request.course.id'});
2018: $donechk = 1;
2019: }
1.627 raeburn 2020: &contained_map_check($url,$folder,$coursenum,$coursedom,
2021: \%removefrommap,\%removeparam,\%addedmaps,
2022: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 2023: if ($url=~ m{^/uploaded/}) {
2024: my $newurl;
2025: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2026: ($newurl,my $error) =
2027: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
2028: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2029: \$title,$allmaps,\%newurls);
2030: if ($error) {
2031: $allerrors{$suffix} = $error;
2032: next;
2033: }
2034: if ($newurl ne '') {
2035: if ($newurl ne $url) {
2036: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
2037: $newsubdir{$url} = $1;
2038: }
2039: $mapchanges{$url} = 1;
1.492 raeburn 2040: }
1.538 raeburn 2041: }
2042: }
2043: if (($srcdom{$suffix} ne $coursedom) ||
2044: ($srcnum{$suffix} ne $coursenum) ||
2045: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
2046: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
2047: $coursedom,$coursenum,$srcdom{$suffix},
2048: $srcnum{$suffix},$allmaps,\%rewrites,
2049: \%retitles,\%copies,\%dbcopies,
2050: \%zombies,\%params,\%mapmoves,
2051: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 2052: \%newurls,\%resdatacopy)) {
1.538 raeburn 2053: $mapmoves{$url} = 1;
2054: }
2055: $url = $newurl;
2056: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
2057: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
2058: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2059: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
2060: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 2061: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 2062: }
2063: } elsif ($url=~m {^/res/}) {
1.597 raeburn 2064: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 2065: push(@toclear,$suffix);
2066: # if pasting published map (main content area only) check map not already in course
2067: if ($folder =~ /^default/) {
2068: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
2069: $duplicate{$suffix} = 1;
2070: next;
1.492 raeburn 2071: }
1.491 raeburn 2072: }
2073: }
1.538 raeburn 2074: }
1.627 raeburn 2075: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 2076: my $prefix = $1;
1.648 raeburn 2077: my $fromothercrs;
1.538 raeburn 2078: #need to copy the db contents to a new one, unless this is a move.
2079: my %info = (
2080: src => $url,
2081: cdom => $coursedom,
2082: cnum => $coursenum,
1.596 raeburn 2083: );
1.649 raeburn 2084: if ($prefix eq 'ext.tool') {
1.655 raeburn 2085: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 2086: $info{'delgradable'} = 1;
2087: }
2088: }
1.596 raeburn 2089: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
2090: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
2091: $fromothercrs = 1;
2092: $info{'cdom'} = $srcdom{$suffix};
2093: $info{'cnum'} = $srcnum{$suffix};
1.704 raeburn 2094: unless ($checkedsameinst) {
2095: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2096: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2097: if ($intdom ne '') {
2098: my $internet_names =
2099: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2100: if (ref($internet_names) eq 'ARRAY') {
2101: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2102: $same_institution = 1;
2103: }
2104: }
2105: }
2106: $checkedsameinst = 1;
2107: }
1.596 raeburn 2108: }
2109: }
2110: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 2111: my (%lockerr,$msg);
1.538 raeburn 2112: my ($newurl,$result,$errtext) =
1.704 raeburn 2113: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
2114: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.538 raeburn 2115: if ($result eq 'ok') {
2116: $url = $newurl;
2117: $title=&mt('Copy of').' '.$title;
2118: } else {
2119: if ($prefix eq 'smppg') {
2120: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2121: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 2122: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 2123: } elsif ($prefix eq 'ext.tool') {
2124: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 2125: }
2126: $results{$suffix} = $result;
2127: $msgerrs{$suffix} = $msg;
2128: $lockerrs{$suffix} = $lockerr{$prefix};
2129: next;
2130: }
2131: if ($lockerr{$prefix}) {
2132: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 2133: }
1.489 raeburn 2134: }
2135: }
1.538 raeburn 2136: $title = &LONCAPA::map::qtunescape($title);
2137: my $ext='false';
2138: if ($url=~m{^http(|s)://}) { $ext='true'; }
2139: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2140: if ($folder !~ /^supplemental/) {
2141: (undef,undef,$title) =
2142: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2143: }
2144: } else {
2145: if ($folder=~/^supplemental/) {
2146: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2147: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2148: }
1.533 raeburn 2149: }
1.491 raeburn 2150:
2151: # For uploaded files (excluding pages/sequences) path in copied file is changed
2152: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2153: # courses.
2154:
1.538 raeburn 2155: unless ($is_map{$suffix}) {
2156: my $newidx;
1.492 raeburn 2157: # Now insert the URL at the bottom
1.538 raeburn 2158: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2159: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2160: my $relpath = $1;
2161: if ($relpath ne '') {
2162: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2163: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2164: my $newprefix = $newloc;
2165: if ($newloc eq 'default') {
2166: $newprefix = 'docs';
2167: }
2168: if ($newdocsdir eq '') {
2169: $newdocsdir = 'default';
2170: }
1.630 raeburn 2171: if (($prefixchg{$suffix}) ||
2172: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2173: ($srcnum{$suffix} ne $coursenum) ||
2174: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2175: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2176: $url =
2177: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2178: &Apache::lonnet::getfile($oldurl));
2179: if ($url eq '/adm/notfound.html') {
2180: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2181: next;
2182: } else {
2183: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2184: $newsubpath =~ s{/+$}{/};
2185: $docmoves{$oldurl} = $newsubpath;
2186: }
1.491 raeburn 2187: }
2188: }
1.597 raeburn 2189: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2190: my $template = $1;
2191: if ($newidx) {
2192: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2193: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2194: }
1.649 raeburn 2195: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2196: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2197: my $marker = (split(m{/},$url))[4];
2198: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2199: my $val = 'no';
2200: if ($toolsettings{'gradable'}) {
2201: $val = 'yes';
2202: }
2203: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2204: 'string_yesno');
2205: &remember_parms($newidx,'gradable','set',$val);
2206: }
1.491 raeburn 2207: }
1.538 raeburn 2208: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2209: ':'.$ext.':normal:res';
2210: push(@LONCAPA::map::order,$newidx);
2211: # Store the result
2212: my ($errtext,$fatal) =
2213: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2214: if ($fatal) {
2215: $save_err .= $errtext;
2216: $allresult = 'fail';
2217: }
1.488 raeburn 2218: }
1.538 raeburn 2219:
1.597 raeburn 2220: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2221: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2222: unless ($allresult eq 'fail') {
2223: my %updated = (
2224: rewrites => \%rewrites,
2225: zombies => \%zombies,
2226: removefrommap => \%removefrommap,
2227: removeparam => \%removeparam,
2228: dbcopies => \%dbcopies,
1.597 raeburn 2229: resdatacopy => \%resdatacopy,
1.538 raeburn 2230: retitles => \%retitles,
2231: );
2232: my %info = (
2233: newsubdir => \%newsubdir,
2234: params => \%params,
2235: );
2236: if ($prefixchg{$suffix}) {
2237: $info{'before'} = $before{$prefixchg{$suffix}};
2238: $info{'after'} = $after{$prefixchg{$suffix}};
2239: }
2240: my %moves = (
2241: copies => \%copies,
2242: docmoves => \%docmoves,
2243: mapmoves => \%mapmoves,
2244: );
2245: (my $result,$msgs{$suffix},my $lockerror) =
2246: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2247: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2248: $url,'paste');
2249: $lockerrors .= $lockerror;
2250: if ($result eq 'ok') {
2251: if ($is_map{$suffix}) {
2252: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2253: $folder.'.'.$container);
2254: if ($fatal) {
2255: $allresult = 'failread';
2256: } else {
2257: if ($#LONCAPA::map::order<1) {
2258: my $idx=&LONCAPA::map::getresidx();
2259: if ($idx<=0) { $idx=1; }
2260: $LONCAPA::map::order[0]=$idx;
2261: $LONCAPA::map::resources[$idx]='';
2262: }
2263: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2264: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2265: ':'.$ext.':normal:res';
2266: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2267:
2268: # Store the result
1.538 raeburn 2269: my ($errtext,$fatal) =
2270: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2271: if ($fatal) {
2272: $save_err .= $errtext;
2273: $allresult = 'failstore';
2274: }
2275: }
2276: }
2277: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2278: push(@toclear,$suffix);
2279: }
2280: }
1.492 raeburn 2281: }
2282: }
1.704 raeburn 2283: if (($updatetoolscache) || (@updatetoolsenc)) {
2284: &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
2285: \@updatetoolsenc);
2286: }
1.538 raeburn 2287: &clear_from_buffer(\@toclear,\@currpaste);
2288: my $msgsarray;
2289: foreach my $suffix (keys(%msgs)) {
2290: if (ref($msgs{$suffix}) eq 'ARRAY') {
2291: $msgsarray .= join(',',@{$msgs{$suffix}});
2292: }
2293: }
2294: return ($allresult,$save_err,$msgsarray,$lockerrors);
2295: }
1.533 raeburn 2296:
1.538 raeburn 2297: sub do_buffer_empty {
2298: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2299: if (@currpaste == 0) {
2300: return &mt('Clipboard is already empty');
2301: }
2302: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2303: if (@toclear == 0) {
2304: return &mt('Nothing selected to clear from clipboard');
2305: }
2306: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2307: if ($numdel) {
2308: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2309: } else {
2310: return &mt('Clipboard unchanged');
1.492 raeburn 2311: }
1.538 raeburn 2312: return;
2313: }
2314:
2315: sub clear_from_buffer {
2316: my ($toclear,$currpaste) = @_;
2317: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2318: my %pastebuffer;
2319: map { $pastebuffer{$_} = 1; } @{$currpaste};
2320: my $numdel = 0;
2321: foreach my $suffix (@{$toclear}) {
2322: next if ($suffix =~ /\D/);
2323: next unless (exists($pastebuffer{$suffix}));
2324: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2325: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2326: delete($pastebuffer{$suffix});
2327: $numdel ++;
2328: }
2329: }
2330: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2331: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2332: return $numdel;
1.492 raeburn 2333: }
2334:
1.704 raeburn 2335: sub update_ltitools_caches {
2336: my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
2337: my $hashid=$coursedom.'_'.$coursenum;
2338: if ($updatetoolscache) {
2339: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
2340: }
2341: if ((ref($updatetoolsenc) eq 'ARRAY') &&
2342: (@{$updatetoolsenc})) {
2343: my @ids=&Apache::lonnet::current_machine_ids();
2344: my $updatedone;
2345: foreach my $lonhost (@{$updatetoolsenc}) {
2346: if (grep(/^\Q$lonhost\E$/,@ids)) {
2347: unless ($updatedone) {
2348: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
2349: }
2350: $updatedone = 1;
2351: } else {
2352: &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
2353: }
2354: }
2355: }
2356: return;
2357: }
2358:
1.492 raeburn 2359: sub get_newmap_url {
2360: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2361: $titleref,$allmaps,$newurls) = @_;
2362: my $newurl;
2363: if ($url=~ m{^/uploaded/}) {
2364: $$titleref=&mt('Copy of').' '.$$titleref;
2365: }
2366: my $now = time;
2367: my $suffix=$$.int(rand(100)).$now;
2368: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2369: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2370: my $path = $1;
2371: my $prefix = $2;
2372: my $ancestor = $3;
2373: if (length($ancestor) > 10) {
2374: $ancestor = substr($ancestor,-10,10);
2375: }
2376: my $newid;
2377: if ($prefixchg) {
2378: if ($folder =~ /^supplemental/) {
2379: $prefix =~ s/^default/supplemental/;
2380: } else {
2381: $prefix =~ s/^supplemental/default/;
2382: }
2383: }
2384: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2385: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2386: } else {
2387: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2388: }
2389: my $counter = 0;
2390: my $is_unique = &uniqueness_check($newurl);
2391: if ($folder =~ /^default/) {
2392: if ($allmaps->{$newurl}) {
2393: $is_unique = 0;
2394: }
2395: }
2396: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2397: $counter ++;
2398: $suffix ++;
2399: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2400: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2401: } else {
2402: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2403: }
2404: $is_unique = &uniqueness_check($newurl);
2405: }
2406: if ($is_unique) {
2407: $newurls->{$newurl} = 1;
2408: } else {
2409: if ($url=~/\.page$/) {
2410: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2411: } else {
2412: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2413: }
2414: }
1.329 droeschl 2415: }
1.492 raeburn 2416: return ($newurl);
1.329 droeschl 2417: }
2418:
1.488 raeburn 2419: sub dbcopy {
1.704 raeburn 2420: my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
2421: $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.533 raeburn 2422: my ($url,$result,$errtext);
2423: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2424: $url = $dbref->{'src'};
1.627 raeburn 2425: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2426: my $prefix = $1;
1.627 raeburn 2427: if ($prefix eq 'ext.tool') {
2428: $prefix = 'exttool';
2429: }
1.533 raeburn 2430: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2431: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2432: my $db_name;
2433: my $marker = (split(m{/},$url))[4];
2434: $marker=~s/\D//g;
2435: if ($dbref->{'src'} =~ m{/smppg$}) {
2436: $db_name =
2437: &Apache::lonsimplepage::get_db_name($url,$marker,
2438: $dbref->{'cdom'},
2439: $dbref->{'cnum'});
1.627 raeburn 2440: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2441: $db_name = 'exttool_'.$marker;
1.533 raeburn 2442: } else {
2443: $db_name = 'bulletinpage_'.$marker;
2444: }
2445: my ($suffix,$freedlock,$error) =
2446: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2447: $coursedom,$coursenum,
2448: 'concat');
2449: if (!$suffix) {
2450: if ($prefix eq 'smppg') {
2451: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2452: } elsif ($prefix eq 'exttool') {
2453: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2454: } else {
1.565 bisitz 2455: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2456: }
2457: if ($error) {
2458: $errtext .= '<br />'.$error;
2459: }
2460: } else {
2461: #need to copy the db contents to a new one.
2462: my %contents=&Apache::lonnet::dump($db_name,
2463: $dbref->{'cdom'},
2464: $dbref->{'cnum'});
1.704 raeburn 2465: my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
2466: if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
2467: if ($contents{'id'} =~ /^(|c)(\d+)$/) {
2468: $oldtoolid = $2;
2469: if ($1 eq 'c') {
2470: $defincrs = 1;
2471: %toolinfo =
2472: &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
2473: } else {
2474: %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
2475: }
2476: if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
2477: if ($toolinfo{$oldtoolid}{'passback'}) {
2478: $toolpassback = 1;
2479: }
2480: if ($toolinfo{$oldtoolid}{'roster'}) {
2481: $toolroster = 1;
2482: }
2483: } else {
2484: $toolcopyerror = 1;
2485: $errtext = &mt('Could not retrieve original settings for pasted external tool.');
2486: }
2487: }
2488: unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
2489: $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
2490: if ($contents{'crstitle'} ne '') {
2491: $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
2492: }
2493: if (($defincrs) && (!$toolcopyerror)) {
2494: my %newtool;
2495: my $oldcdom = $dbref->{'cdom'};
2496: my $oldcnum = $dbref->{'cnum'};
2497: my $title = $toolinfo{$oldtoolid}{'title'};
2498: if (ref($currltititles) eq 'HASH') {
2499: if (exists($currltititles->{$title})) {
2500: $title .= ' (copied from another course)';
2501: }
2502: }
2503: my ($newid,$iderror) =
2504: &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
2505: if ($newid =~ /^\d+$/) {
2506: %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
2507: $newtool{$newid}{'title'} = $title;
2508: if (ref($currltimax)) {
2509: $newtool{$newid}{'order'} = $$currltimax;
2510: }
2511: if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
2512: my $fname = $1;
2513: my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
2514: if ($content eq '-1') {
2515: delete($newtool{$newid}{'image'});
2516: } else {
2517: $env{'form.'.$suffix.'.image'} = $content;
2518: my $newlogo =
2519: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
2520: delete($env{'form.'.$suffix.'.image'});
2521: if ($newlogo =~ m{^/uploaded/}) {
2522: $newtool{$newid}{'image'} = $newlogo;
2523: } else {
2524: delete($newtool{$newid}{'image'});
2525: }
2526: }
2527: }
2528: my $newusable;
2529: if ($same_institution) {
2530: my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
2531: if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
2532: my %newtoolsenc;
2533: %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
2534: my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
2535: if ($putres eq 'ok') {
2536: if (ref($updatetoolsenc) eq 'ARRAY') {
2537: my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
2538: unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
2539: push(@{$updatetoolsenc},$newhome);
2540: }
2541: }
2542: $newusable = 1;
2543: }
2544: }
2545: }
2546: if ($newtool{$newid}{'usable'}) {
2547: unless ($newusable) {
2548: delete($newtool{$newid}{'usable'});
2549: }
2550: }
2551: my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
2552: if ($putres eq 'ok') {
2553: $contents{'id'} = "c$newid";
2554: if (ref($updatetoolscache)) {
2555: $$updatetoolscache ++;
2556: }
2557: if (ref($currltititles->{$title}) eq 'ARRAY') {
2558: push(@{$currltititles->{$title}},$newid);
2559: } else {
2560: $currltititles->{$title} = [$newid];
2561: }
2562: if (ref($currltimax)) {
2563: $$currltimax ++;
2564: }
2565: } else {
2566: $toolcopyerror = 1;
2567: $errtext = &mt('Unable to save external tool definition in Course Settings.');
2568: }
2569: } else {
2570: $toolcopyerror = 1;
2571: $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
2572: }
2573: }
2574: }
2575: }
1.533 raeburn 2576: if (exists($contents{'uploaded.photourl'})) {
2577: my $photo = $contents{'uploaded.photourl'};
2578: my ($subdir,$fname) =
2579: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2580: my $newphoto;
1.533 raeburn 2581: if ($fname ne '') {
2582: my $content = &Apache::lonnet::getfile($photo);
2583: unless ($content eq '-1') {
2584: $env{'form.'.$suffix.'.photourl'} = $content;
2585: $newphoto =
2586: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2587: delete($env{'form.'.$suffix.'.photourl'});
2588: }
2589: }
2590: if ($newphoto =~ m{^/uploaded/}) {
2591: $contents{'uploaded.photourl'} = $newphoto;
2592: }
2593: }
2594: $db_name =~ s{_\d*$ }{_$suffix}x;
1.704 raeburn 2595: if ($prefix eq 'exttool') {
2596: unless ($toolcopyerror) {
2597: foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
2598: if (exists($contents{$key})) {
2599: delete($contents{$key});
2600: }
2601: }
2602: if ($dbref->{'delgradable'}) {
2603: if (exists($contents{'gradable'})) {
2604: delete($contents{'gradable'});
2605: }
2606: }
2607: if ($toolpassback) {
2608: if ($contents{'gradable'}) {
2609: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
2610: $contents{'gradesecret'} = $gradesecret;
2611: $contents{'gradesecretdate'} = time;
2612: }
2613: }
2614: if ($toolroster) {
2615: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
2616: $contents{'rostersecret'} = $rostersecret;
2617: $contents{'rostersecretdate'} = time;
2618: }
2619: }
1.649 raeburn 2620: }
1.704 raeburn 2621: if (($prefix eq 'exttool') && ($toolcopyerror)) {
2622: $result = 'error';
2623: } else {
2624: $result=&Apache::lonnet::put($db_name,\%contents,
2625: $coursedom,$coursenum);
2626: if ($result eq 'ok') {
2627: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
2628: }
1.533 raeburn 2629: }
2630: }
2631: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2632: $lockerrorsref->{$prefix} =
1.533 raeburn 2633: '<div class="LC_error">'.
2634: &mt('There was a problem removing a lockfile.');
2635: if ($prefix eq 'smppg') {
1.560 raeburn 2636: $lockerrorsref->{$prefix} .=
1.559 raeburn 2637: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2638: } elsif ($prefix eq 'exttool') {
2639: $lockerrorsref->{$prefix} .=
2640: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2641: } else {
1.565 bisitz 2642: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2643: }
1.560 raeburn 2644: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2645: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2646: '</div>';
1.533 raeburn 2647: }
2648: }
2649: } elsif ($url =~ m{/syllabus$}) {
2650: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2651: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2652: if (($dbref->{'cdom'} ne $coursedom) ||
2653: ($dbref->{'cnum'} ne $coursenum)) {
2654: my %contents=&Apache::lonnet::dump('syllabus',
2655: $dbref->{'cdom'},
2656: $dbref->{'cnum'});
2657: $result=&Apache::lonnet::put('syllabus',\%contents,
2658: $coursedom,$coursenum);
2659: }
2660: }
1.488 raeburn 2661: }
2662: }
1.533 raeburn 2663: return ($url,$result,$errtext);
1.488 raeburn 2664: }
2665:
1.597 raeburn 2666: sub copy_templated_files {
2667: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2668: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2669: my $srccontainer = 'sequence';
2670: if ($srcwaspage) {
2671: $srccontainer = 'page';
2672: }
2673: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2674: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2675: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2676: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2677: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2678: $template.'.problem';
2679: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2680: if ($template eq 'simpleproblem') {
2681: $srcprefix .= '.0.';
2682: my $weightprefix = $newprefix;
2683: $newprefix .= '.0.';
2684: my @simpleprobqtypes = qw(radio option string essay numerical);
2685: my $qtype=$srcparms{$srcprefix.'questiontype'};
2686: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 2687: my %newdata = (
2688: $newprefix.'questiontype' => $qtype,
2689: );
1.597 raeburn 2690: foreach my $type (@simpleprobqtypes) {
2691: if ($type eq $qtype) {
2692: $newdata{"$weightprefix.$type.weight"}=1;
2693: } else {
2694: $newdata{"$weightprefix.$type.weight"}=0;
2695: }
2696: }
2697: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2698: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2699: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2700: if ($qtype eq 'numerical') {
2701: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2702: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2703: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2704: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2705: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2706: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2707: unless (defined($maxfoils)) { $maxfoils=10; }
2708: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2709: if ($maxfoils<=0) { $maxfoils=10; }
2710: my $randomize=$srcparms{$srcprefix.'randomize'};
2711: unless (defined($randomize)) { $randomize='yes'; }
2712: unless ($randomize eq 'no') { $randomize='yes'; }
2713: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2714: $newdata{$newprefix.'randomize'} = $randomize;
2715: if ($qtype eq 'option') {
2716: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2717: }
2718: for (my $i=1; $i<=10; $i++) {
2719: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2720: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2721: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2722: }
2723:
2724: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2725: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2726: unless (defined($maxfoils)) { $maxfoils=10; }
2727: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2728: if ($maxfoils<=0) { $maxfoils=10; }
2729: my $randomize=$srcparms{$srcprefix.'randomize'};
2730: unless (defined($randomize)) { $randomize='yes'; }
2731: unless ($randomize eq 'no') { $randomize='yes'; }
2732: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2733: $newdata{$newprefix.'randomize'} = $randomize;
2734: if ($qtype eq 'option') {
2735: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2736: }
2737: for (my $i=1; $i<=10; $i++) {
2738: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2739: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2740: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2741: }
2742: } elsif ($qtype eq 'string') {
2743: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2744: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2745: }
2746: if (keys(%newdata)) {
2747: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2748: $coursenum);
2749: if ($putres eq 'ok') {
2750: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2751: }
2752: }
2753: }
2754: }
2755: }
2756:
1.329 droeschl 2757: sub uniqueness_check {
2758: my ($newurl) = @_;
2759: my $unique = 1;
2760: foreach my $res (@LONCAPA::map::order) {
2761: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2762: $url=&LONCAPA::map::qtescape($url);
2763: if ($newurl eq $url) {
2764: $unique = 0;
1.344 bisitz 2765: last;
1.329 droeschl 2766: }
2767: }
2768: return $unique;
2769: }
2770:
1.488 raeburn 2771: sub contained_map_check {
1.627 raeburn 2772: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2773: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2774: my $content = &Apache::lonnet::getfile($url);
2775: unless ($content eq '-1') {
2776: my $parser = HTML::TokeParser->new(\$content);
2777: $parser->attr_encoded(1);
2778: while (my $token = $parser->get_token) {
2779: next if ($token->[0] ne 'S');
2780: if ($token->[1] eq 'resource') {
2781: next if ($token->[2]->{'type'} eq 'zombie');
2782: my $ressrc = $token->[2]->{'src'};
1.704 raeburn 2783: if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2784: my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
1.627 raeburn 2785: unless ($srcdom eq $coursedom) {
2786: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2787: next;
2788: }
1.704 raeburn 2789: unless ($srcnum eq $coursenum) {
2790: my %toolsettings =
2791: &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
2792: my %tooltypes = &Apache::loncommon::usable_exttools();
2793: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2794: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2795: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2796: next;
2797: }
2798: }
1.627 raeburn 2799: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2800: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2801: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2802: next;
2803: }
2804: }
1.703 raeburn 2805: if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
2806: my ($srcdom,$srcnum) = ($1,$2);
2807: unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
2808: if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
2809: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2810: next;
2811: }
2812: }
2813: }
1.492 raeburn 2814: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2815: if ($1 eq 'uploaded') {
2816: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2817: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2818: } else {
1.492 raeburn 2819: if ($allmaps->{$ressrc}) {
1.529 raeburn 2820: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2821: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2822: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2823: } else {
2824: $addedmaps->{$ressrc} = [$url];
2825: }
1.488 raeburn 2826: }
1.627 raeburn 2827: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2828: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2829: }
1.492 raeburn 2830: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2831: if ($folder =~ /^supplemental/) {
1.492 raeburn 2832: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2833: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2834: } else {
2835: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2836: }
1.488 raeburn 2837: }
2838: }
2839: }
2840: }
2841: return;
2842: }
2843:
2844: sub url_paste_fixups {
1.533 raeburn 2845: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2846: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2847: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2848: my $checktitle;
2849: if (($prefixchg) &&
1.492 raeburn 2850: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2851: $checktitle = 1;
2852: }
1.492 raeburn 2853: my $skip;
2854: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2855: my $mapid = $1.$2;
2856: if ($tomove->{$mapid}) {
2857: $skip = 1;
2858: }
2859: }
1.491 raeburn 2860: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2861: return if ($file eq '-1');
2862: my $parser = HTML::TokeParser->new(\$file);
2863: $parser->attr_encoded(1);
1.491 raeburn 2864: my $changed = 0;
1.488 raeburn 2865: while (my $token = $parser->get_token) {
2866: next if ($token->[0] ne 'S');
2867: if ($token->[1] eq 'resource') {
2868: my $ressrc = $token->[2]->{'src'};
2869: next if ($ressrc eq '');
1.491 raeburn 2870: my $id = $token->[2]->{'id'};
1.492 raeburn 2871: my $title = $token->[2]->{'title'};
1.491 raeburn 2872: if ($checktitle) {
2873: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2874: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2875: }
2876: }
1.488 raeburn 2877: next if ($token->[2]->{'type'} eq 'external');
2878: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2879: next if ($skip);
1.532 raeburn 2880: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2881: $changed = 1;
2882: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2883: my $srcdom = $1;
2884: my $srcnum = $2;
1.488 raeburn 2885: my $rem = $3;
1.492 raeburn 2886: my $newurl;
2887: my $mapname;
2888: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2889: my $prefix = $1;
2890: $mapname = $prefix.$2;
2891: if ($tomove->{$mapname}) {
1.533 raeburn 2892: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2893: $srcdom,$srcnum,$allmaps,$rewrites,
2894: $retitles,$copies,$dbcopies,$zombies,
2895: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2896: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2897: next;
2898: } else {
2899: ($newurl,my $error) =
2900: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2901: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2902: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2903: $newsubdir->{$ressrc} = $1;
2904: }
2905: if ($error) {
2906: next;
2907: }
2908: }
2909: }
2910: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2911: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2912:
1.488 raeburn 2913: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2914: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2915: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2916: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2917: $cnum,$srcdom,$srcnum,$allmaps,
2918: $rewrites,$retitles,$copies,$dbcopies,
2919: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2920: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2921: $mapmoves->{$ressrc} = 1;
2922: }
2923: $changed = 1;
1.488 raeburn 2924: } else {
1.532 raeburn 2925: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2926: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2927: $changed = 1;
1.488 raeburn 2928: }
2929: }
1.649 raeburn 2930: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 2931: next if ($skip);
1.492 raeburn 2932: my $srcdom = $1;
2933: my $srcnum = $2;
1.649 raeburn 2934: my $rem = $3;
2935: my ($is_exttool,$exttoolchg);
2936: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 2937: $is_exttool = 1;
1.649 raeburn 2938: }
1.492 raeburn 2939: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2940: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2941: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2942: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2943: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2944: $changed = 1;
1.649 raeburn 2945: if ($is_exttool) {
2946: $exttoolchg = 1;
2947: }
1.700 raeburn 2948: } elsif (($is_exttool) &&
1.649 raeburn 2949: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2950: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2951: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2952: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2953: $changed = 1;
2954: $exttoolchg = 1;
2955: }
2956: if (($is_exttool) && ($prefixchg)) {
2957: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2958: if ($exttoolchg) {
2959: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2960: }
2961: }
1.533 raeburn 2962: }
2963: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2964: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2965: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2966: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2967: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2968: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2969: $changed = 1;
1.488 raeburn 2970: }
1.597 raeburn 2971: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2972: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2973: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2974: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2975: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2976: }
1.488 raeburn 2977: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2978: next if ($skip);
2979: my $srcdom = $1;
2980: my $srcnum = $2;
2981: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2982: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2983: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2984: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2985: $changed = 1;
1.488 raeburn 2986: }
2987: }
2988: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2989: next if ($skip);
1.488 raeburn 2990: my $to = $token->[2]->{'to'};
2991: if ($to ne '') {
2992: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2993: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2994: } else {
2995: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2996: }
2997: }
2998: }
2999: }
1.491 raeburn 3000: return $changed;
1.488 raeburn 3001: }
3002:
3003: sub apply_fixups {
1.529 raeburn 3004: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
3005: $oldurl,$url,$caller) = @_;
3006: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 3007: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.704 raeburn 3008: %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
3009: %currltititles,$currltimax);
3010: $currltimax = 0;
1.529 raeburn 3011: if (ref($updated) eq 'HASH') {
3012: if (ref($updated->{'rewrites'}) eq 'HASH') {
3013: %rewrites = %{$updated->{'rewrites'}};
3014: }
3015: if (ref($updated->{'zombies'}) eq 'HASH') {
3016: %zombies = %{$updated->{'zombies'}};
3017: }
3018: if (ref($updated->{'removefrommap'}) eq 'HASH') {
3019: %removefrommap = %{$updated->{'removefrommap'}};
3020: }
3021: if (ref($updated->{'removeparam'}) eq 'HASH') {
3022: %removeparam = %{$updated->{'removeparam'}};
3023: }
3024: if (ref($updated->{'dbcopies'}) eq 'HASH') {
3025: %dbcopies = %{$updated->{'dbcopies'}};
3026: }
3027: if (ref($updated->{'retitles'}) eq 'HASH') {
3028: %retitles = %{$updated->{'retitles'}};
3029: }
1.597 raeburn 3030: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
3031: %resdatacopy = %{$updated->{'resdatacopy'}};
3032: }
1.529 raeburn 3033: }
3034: if (ref($info) eq 'HASH') {
3035: if (ref($info->{'newsubdir'}) eq 'HASH') {
3036: %newsubdir = %{$info->{'newsubdir'}};
3037: }
3038: if (ref($info->{'params'}) eq 'HASH') {
3039: %params = %{$info->{'params'}};
3040: }
3041: if (ref($info->{'before'}) eq 'HASH') {
3042: %before = %{$info->{'before'}};
3043: }
3044: if (ref($info->{'after'}) eq 'HASH') {
3045: %after = %{$info->{'after'}};
3046: }
3047: }
3048: if (ref($moves) eq 'HASH') {
3049: if (ref($moves->{'copies'}) eq 'HASH') {
3050: %copies = %{$moves->{'copies'}};
3051: }
3052: if (ref($moves->{'docmoves'}) eq 'HASH') {
3053: %docmoves = %{$moves->{'docmoves'}};
3054: }
3055: if (ref($moves->{'mapmoves'}) eq 'HASH') {
3056: %mapmoves = %{$moves->{'mapmoves'}};
3057: }
3058: }
3059: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 3060: my @allcopies;
1.529 raeburn 3061: if (exists($copies{$key})) {
3062: if (ref($copies{$key}) eq 'HASH') {
3063: my %added;
3064: foreach my $innerkey (keys(%{$copies{$key}})) {
3065: if (($innerkey ne '') && (!$added{$innerkey})) {
3066: push(@allcopies,$innerkey);
3067: $added{$innerkey} = 1;
3068: }
1.491 raeburn 3069: }
1.529 raeburn 3070: undef(%added);
1.491 raeburn 3071: }
3072: }
3073: if ($key eq $oldurl) {
1.529 raeburn 3074: if ((exists($docmoves{$key}))) {
1.532 raeburn 3075: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 3076: push(@allcopies,$oldurl);
3077: }
3078: }
3079: }
3080: if (@allcopies > 0) {
3081: foreach my $item (@allcopies) {
1.492 raeburn 3082: my ($relpath,$oldsubdir,$fname) =
3083: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 3084: if ($fname ne '') {
3085: my $content = &Apache::lonnet::getfile($item);
3086: unless ($content eq '-1') {
3087: my $storefn;
1.529 raeburn 3088: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
3089: $storefn = $docmoves{$key};
1.491 raeburn 3090: } else {
3091: $storefn = $relpath;
3092: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3093: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
3094: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 3095: }
1.529 raeburn 3096: if ($newsubdir{$key}) {
1.532 raeburn 3097: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 3098: }
3099: }
3100: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
3101: my $copyurl =
3102: &Apache::lonclonecourse::writefile($env{'request.course.id'},
3103: $storefn.$fname,$content);
3104: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 3105: if (exists($docmoves{$oldurl})) {
1.491 raeburn 3106: return &mt('Paste failed: an error occurred copying the file.');
3107: } elsif (ref($errors) eq 'HASH') {
3108: $errors->{$item} = 1;
1.489 raeburn 3109: }
3110: }
1.488 raeburn 3111: }
3112: }
1.491 raeburn 3113: }
3114: }
3115: }
1.529 raeburn 3116: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 3117: my $storefn=$key;
3118: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3119: if ($prefixchg && $before{'map'} && $after{'map'}) {
3120: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3121: }
1.529 raeburn 3122: if ($newsubdir{$key}) {
3123: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3124: }
1.491 raeburn 3125: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 3126: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
3127: ($after{'map'} eq 'default') &&
3128: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
3129: $mapcontent = '<map>'."\n".
3130: '<resource id="1" src="" type="start" />'."\n".
3131: '<link from="1" to="2" index="1" />'."\n".
3132: '<resource id="2" src="" type="finish" />'."\n".
3133: '</map>';
3134: }
1.491 raeburn 3135: if ($mapcontent eq '-1') {
3136: if (ref($errors) eq 'HASH') {
3137: $errors->{$key} = 1;
3138: }
3139: } else {
3140: my $newmap =
3141: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
3142: $mapcontent);
3143: if ($newmap eq '/adm/notfound.html') {
3144: if (ref($errors) eq 'HASH') {
3145: $errors->{$key} = 1;
1.489 raeburn 3146: }
1.488 raeburn 3147: }
3148: }
3149: }
1.491 raeburn 3150: my %updates;
3151: if ($is_map) {
1.529 raeburn 3152: if (ref($updated) eq 'HASH') {
3153: foreach my $type (keys(%{$updated})) {
3154: if (ref($updated->{$type}) eq 'HASH') {
3155: foreach my $key (keys(%{$updated->{$type}})) {
3156: $updates{$key} = 1;
3157: }
3158: }
3159: }
1.491 raeburn 3160: }
1.704 raeburn 3161: my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.491 raeburn 3162: foreach my $key (keys(%updates)) {
1.492 raeburn 3163: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 3164: if (ref($rewrites{$key}) eq 'HASH') {
3165: %torewrite = %{$rewrites{$key}};
1.491 raeburn 3166: }
1.529 raeburn 3167: if (ref($retitles{$key}) eq 'HASH') {
3168: %toretitle = %{$retitles{$key}};
1.491 raeburn 3169: }
1.529 raeburn 3170: if (ref($removefrommap{$key}) eq 'HASH') {
3171: %toremove = %{$removefrommap{$key}};
1.491 raeburn 3172: }
1.529 raeburn 3173: if (ref($removeparam{$key}) eq 'HASH') {
3174: %remparam = %{$removeparam{$key}};
1.492 raeburn 3175: }
1.529 raeburn 3176: if (ref($zombies{$key}) eq 'HASH') {
3177: %zombie = %{$zombies{$key}};
1.491 raeburn 3178: }
1.529 raeburn 3179: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 3180: foreach my $idx (keys(%{$dbcopies{$key}})) {
3181: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.704 raeburn 3182: my $oldurl = $dbcopies{$key}{$idx}{'src'};
3183: my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
3184: my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
3185: my $oldmarker;
3186: if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
3187: $oldmarker = $1;
3188: unless (($gotcrsltitools) ||
3189: (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
3190: my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
3191: if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
3192: unless ($gotcrsltitools) {
3193: %currcrsltitools =
3194: &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
3195: foreach my $item (sort(keys(%currcrsltitools))) {
3196: if (ref($currcrsltitools{$item}) eq 'HASH') {
3197: $currltimax ++;
3198: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
3199: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
3200: } else {
3201: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
3202: }
3203: }
3204: }
3205: $gotcrsltitools = 1;
3206: }
3207: unless ($checkedsameinst) {
3208: my $primary_id = &Apache::lonnet::domain($cdom,'primary');
3209: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3210: if ($intdom ne '') {
3211: my $internet_names =
3212: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
3213: if (ref($internet_names) eq 'ARRAY') {
3214: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
3215: $same_institution = 1;
3216: }
3217: }
3218: }
3219: $checkedsameinst = 1;
3220: }
3221: }
3222: }
3223: }
1.533 raeburn 3224: my ($newurl,$result,$errtext) =
1.704 raeburn 3225: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
3226: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.533 raeburn 3227: if ($result eq 'ok') {
3228: $newdb{$idx} = $newurl;
1.704 raeburn 3229: if ($newurl =~ /ext\.tool$/) {
3230: if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
3231: if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
3232: my $newmarker = $1;
3233: unless ($oldmarker eq $newmarker) {
3234: $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
3235: }
3236: }
3237: }
3238: }
1.533 raeburn 3239: } elsif (ref($errors) eq 'HASH') {
3240: $errors->{$key} = 1;
3241: }
3242: push(@msgs,$errtext);
3243: }
1.491 raeburn 3244: }
3245: }
1.597 raeburn 3246: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 3247: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 3248: foreach my $idx (keys(%{$resdatacopy{$key}})) {
3249: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
3250: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
3251: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
3252: my $template = $1;
3253: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
3254: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
3255: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
3256: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 3257: unless ($gotnewmapname) {
3258: ($newmapname) = ($key =~ m{/([^/]+)$});
3259: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
3260: if ($newsubdir{$key}) {
3261: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
3262: }
3263: $gotnewmapname = 1;
3264: }
1.597 raeburn 3265: my $srcmapinfo = $srcfolder.':'.$idx;
3266: if ($srccontainer eq 'page') {
3267: $srcmapinfo .= ':1';
3268: }
3269: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
3270: $cnum,$template,$idx,$newmapname);
3271: }
3272: }
3273: }
3274: }
3275: }
1.529 raeburn 3276: if (ref($params{$key}) eq 'HASH') {
3277: %currparam = %{$params{$key}};
1.492 raeburn 3278: }
3279: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
3280: if ($fatal) {
1.533 raeburn 3281: return ($errtext);
1.492 raeburn 3282: }
3283: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
3284: if (defined($LONCAPA::map::zombies[$i])) {
3285: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 3286: if ($zombie{$i} eq $src) {
1.492 raeburn 3287: undef($LONCAPA::map::zombies[$i]);
3288: }
3289: }
3290: }
1.646 raeburn 3291: my $total = scalar(@LONCAPA::map::order) - 1;
3292: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 3293: my $idx = $LONCAPA::map::order[$i];
3294: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 3295: my $changed;
1.529 raeburn 3296: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 3297: if ((exists($toremove{$idx})) &&
3298: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 3299: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 3300: if (ref($currparam{$idx}) eq 'ARRAY') {
3301: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 3302: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 3303: }
3304: }
3305: next;
3306: }
3307: my $origsrc = $src;
1.532 raeburn 3308: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 3309: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
3310: $changed = 1;
1.491 raeburn 3311: }
1.492 raeburn 3312: }
1.532 raeburn 3313: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 3314: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
3315: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 3316: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 3317: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 3318: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 3319: } else {
1.529 raeburn 3320: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 3321: }
1.491 raeburn 3322: }
1.532 raeburn 3323: if ($origsrc =~ /\.(page|sequence)$/) {
3324: if ($newsubdir{$origsrc}) {
1.529 raeburn 3325: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 3326: }
1.532 raeburn 3327: } elsif ($newsubdir{$key}) {
3328: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 3329: }
3330: }
1.492 raeburn 3331: $changed = 1;
1.533 raeburn 3332: } elsif ($newdb{$idx} ne '') {
3333: $src = $newdb{$idx};
1.492 raeburn 3334: $changed = 1;
3335: }
3336: if ($changed) {
1.538 raeburn 3337: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 3338: }
3339: }
3340: }
3341: foreach my $idx (keys(%remparam)) {
3342: if (ref($remparam{$idx}) eq 'ARRAY') {
3343: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 3344: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 3345: }
3346: }
3347: }
1.533 raeburn 3348: if (values(%lockerrors) > 0) {
3349: $lockmsg = join('<br />',values(%lockerrors));
3350: }
1.491 raeburn 3351: my $storefn;
3352: if ($key eq $oldurl) {
3353: $storefn = $url;
3354: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3355: } else {
3356: $storefn = $key;
3357: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3358: if ($prefixchg && $before{'map'} && $after{'map'}) {
3359: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3360: }
1.529 raeburn 3361: if ($newsubdir{$key}) {
3362: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3363: }
1.491 raeburn 3364: }
1.492 raeburn 3365: my $report;
3366: if ($folder !~ /^supplemental/) {
3367: $report = 1;
3368: }
1.527 raeburn 3369: (my $outtext,$errtext) =
1.492 raeburn 3370: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3371: if ($errtext) {
1.529 raeburn 3372: if ($caller eq 'paste') {
1.533 raeburn 3373: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 3374: }
1.491 raeburn 3375: }
3376: }
1.704 raeburn 3377: if (($updatetoolscache) || (@updatetoolsenc)) {
3378: &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
3379: \@updatetoolsenc);
3380: }
1.491 raeburn 3381: }
1.533 raeburn 3382: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 3383: }
3384:
3385: sub copy_dependencies {
3386: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3387: my $content;
3388: if (ref($contentref)) {
3389: $content = $$contentref;
3390: } else {
3391: $content = &Apache::lonnet::getfile($item);
3392: }
3393: unless ($content eq '-1') {
3394: my $mm = new File::MMagic;
3395: my $mimetype = $mm->checktype_contents($content);
3396: if ($mimetype eq 'text/html') {
3397: my (%allfiles,%codebase,$state);
3398: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3399: if ($res eq 'ok') {
3400: my ($numexisting,$numpathchanges,$existing);
3401: (undef,$numexisting,$numpathchanges,$existing) =
3402: &Apache::loncommon::ask_for_embedded_content(
3403: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3404: {'error_on_invalid_names' => 1,
3405: 'ignore_remote_references' => 1,
3406: 'docs_url' => $item,
3407: 'context' => 'paste'});
3408: if ($numexisting > 0) {
3409: if (ref($existing) eq 'HASH') {
3410: foreach my $dep (keys(%{$existing})) {
3411: my $depfile = $dep;
3412: unless ($depfile =~ m{^\Q$relpath\E}) {
3413: $depfile = $relpath.$dep;
3414: }
3415: my $depcontent = &Apache::lonnet::getfile($depfile);
3416: unless ($depcontent eq '-1') {
3417: my $storedep = $dep;
3418: $storedep =~ s{^\Q$relpath\E}{};
3419: my $dep_url =
3420: &Apache::lonclonecourse::writefile(
3421: $env{'request.course.id'},
3422: $storefn.$storedep,$depcontent);
3423: if ($dep_url eq '/adm/notfound.html') {
3424: if (ref($errors) eq 'HASH') {
3425: $errors->{$depfile} = 1;
3426: }
3427: } else {
3428: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3429: }
3430: }
3431: }
1.488 raeburn 3432: }
3433: }
3434: }
3435: }
3436: }
3437: return;
3438: }
3439:
1.329 droeschl 3440: my %parameter_type = ( 'randompick' => 'int_pos',
3441: 'hiddenresource' => 'string_yesno',
3442: 'encrypturl' => 'string_yesno',
3443: 'randomorder' => 'string_yesno',);
3444: my $valid_parameters_re = join('|',keys(%parameter_type));
3445: # set parameters
3446: sub update_parameter {
1.537 raeburn 3447: if ($env{'form.changeparms'} eq 'all') {
3448: my (@allidx,@allmapidx,%allchecked,%currchecked);
3449: %allchecked = (
3450: 'hiddenresource' => {},
3451: 'encrypturl' => {},
3452: 'randompick' => {},
3453: 'randomorder' => {},
3454: );
3455: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3456: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3457: if ($which eq 'randompick') {
3458: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3459: my ($res,$value) = split(/:/,$item);
3460: if ($value =~ /^\d+$/) {
3461: $allchecked{$which}{$res} = $value;
3462: }
3463: }
3464: } else {
1.539 raeburn 3465: if ($env{'form.all'.$which}) {
3466: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3467: }
1.537 raeburn 3468: }
3469: }
3470: my $haschanges = 0;
3471: foreach my $res (@LONCAPA::map::order) {
3472: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3473: $name=&LONCAPA::map::qtescape($name);
3474: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 3475: next unless $url;
1.537 raeburn 3476: my $is_map;
3477: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3478: $is_map = 1;
3479: }
3480: foreach my $which (keys(%allchecked)) {
3481: if (($which eq 'randompick' || $which eq 'randomorder')) {
3482: next if (!$is_map);
3483: }
3484: my $oldvalue = 0;
3485: my $newvalue = 0;
3486: if ($allchecked{$which}{$res}) {
3487: $newvalue = $allchecked{$which}{$res};
3488: }
3489: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3490: if ($which eq 'randompick') {
3491: if ($current =~ /^(\d+)$/) {
3492: $oldvalue = $1;
3493: }
3494: } else {
3495: if ($current =~ /^yes$/i) {
3496: $oldvalue = 1;
3497: }
3498: }
3499: if ($oldvalue ne $newvalue) {
3500: $haschanges = 1;
3501: if ($newvalue) {
3502: my $storeval = 'yes';
3503: if ($which eq 'randompick') {
3504: $storeval = $newvalue;
3505: }
3506: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3507: $storeval,
3508: $parameter_type{$which});
3509: &remember_parms($res,$which,'set',$storeval);
3510: } elsif ($oldvalue) {
3511: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3512: &remember_parms($res,$which,'del');
3513: }
3514: }
3515: }
3516: }
3517: return $haschanges;
3518: } else {
1.588 raeburn 3519: my $haschanges = 0;
3520: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3521:
1.537 raeburn 3522: my $which = $env{'form.changeparms'};
3523: my $idx = $env{'form.setparms'};
1.588 raeburn 3524: my $oldvalue = 0;
3525: my $newvalue = 0;
3526: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3527: if ($which eq 'randompick') {
3528: if ($current =~ /^(\d+)$/) {
3529: $oldvalue = $1;
3530: }
3531: } elsif ($current =~ /^yes$/i) {
3532: $oldvalue = 1;
3533: }
1.537 raeburn 3534: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3535: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3536: : 1;
3537: }
3538: if ($oldvalue ne $newvalue) {
3539: $haschanges = 1;
3540: if ($newvalue) {
3541: my $storeval = 'yes';
3542: if ($which eq 'randompick') {
3543: $storeval = $newvalue;
3544: }
3545: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3546: $parameter_type{$which});
3547: &remember_parms($idx,$which,'set',$storeval);
3548: } else {
3549: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3550: &remember_parms($idx,$which,'del');
3551: }
1.537 raeburn 3552: }
1.588 raeburn 3553: return $haschanges;
1.329 droeschl 3554: }
3555: }
3556:
3557: sub handle_edit_cmd {
3558: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3559: my $haschanges = 0;
1.543 raeburn 3560: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3561: return $haschanges;
1.543 raeburn 3562: }
1.329 droeschl 3563: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3564:
3565: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3566: my ($title, $url, @rrest) = split(':', $ratstr);
3567:
1.538 raeburn 3568: if ($cmd eq 'remove') {
1.329 droeschl 3569: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3570: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3571: &Apache::lonnet::removeuploadedurl($url);
3572: } else {
3573: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3574: }
3575: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3576: $haschanges = 1;
1.329 droeschl 3577: } elsif ($cmd eq 'cut') {
3578: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3579: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3580: $haschanges = 1;
1.344 bisitz 3581: } elsif ($cmd eq 'up'
1.329 droeschl 3582: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3583: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3584: $haschanges = 1;
1.329 droeschl 3585: } elsif ($cmd eq 'down'
3586: && defined($LONCAPA::map::order[$idx+1])) {
3587: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3588: $haschanges = 1;
1.329 droeschl 3589: } elsif ($cmd eq 'rename') {
3590: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3591: if ($comment=~/\S/) {
3592: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3593: $comment.':'.join(':', $url, @rrest);
3594: }
3595: # Devalidate title cache
3596: my $renamed_url=&LONCAPA::map::qtescape($url);
3597: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3598: $haschanges = 1;
3599: } elsif ($cmd eq 'setalias') {
3600: my $newvalue = $env{'form.alias'};
3601: if ($newvalue ne '') {
3602: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3603: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3604: 'string');
3605: &remember_parms($idx,'mapalias','set',$newvalue);
3606: $haschanges = 1;
3607: }
3608: }
3609: } elsif ($cmd eq 'delalias') {
3610: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3611: if ($current ne '') {
3612: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3613: &remember_parms($idx,'mapalias','del');
3614: $haschanges = 1;
3615: }
1.329 droeschl 3616: }
1.633 raeburn 3617: return $haschanges;
1.329 droeschl 3618: }
3619:
3620: sub editor {
1.458 raeburn 3621: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3622: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3623: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3624: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3625: if ($allowed) {
1.519 raeburn 3626: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3627: $is_random_order,$container) =
1.510 raeburn 3628: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3629: $r->print($breadcrumbtrail);
1.519 raeburn 3630: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3631: $container = 'page';
3632: } else {
3633: $container = 'sequence';
1.510 raeburn 3634: }
1.484 raeburn 3635:
1.525 raeburn 3636: my $jumpto;
3637:
3638: unless ($supplementalflag) {
1.546 raeburn 3639: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3640: }
1.484 raeburn 3641:
3642: unless ($allowed) {
3643: $randompick = -1;
3644: }
3645:
1.615 raeburn 3646: my ($errtext,$fatal);
3647: if (($folder eq '') && (!$supplementalflag)) {
3648: if (@LONCAPA::map::order) {
3649: undef(@LONCAPA::map::order);
3650: undef(@LONCAPA::map::resources);
3651: undef(@LONCAPA::map::resparms);
3652: undef(@LONCAPA::map::zombies);
3653: }
3654: $folder = 'default';
3655: $container = 'sequence';
3656: } else {
3657: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3658: $folder.'.'.$container);
3659: return $errtext if ($fatal);
3660: }
1.329 droeschl 3661:
3662: if ($#LONCAPA::map::order<1) {
3663: my $idx=&LONCAPA::map::getresidx();
3664: if ($idx<=0) { $idx=1; }
3665: $LONCAPA::map::order[0]=$idx;
3666: $LONCAPA::map::resources[$idx]='';
3667: }
1.364 bisitz 3668:
1.329 droeschl 3669: # ------------------------------------------------------------ Process commands
3670:
3671: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3672: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3673: # set parameters and change order
3674: &snapshotbefore();
3675:
3676: if (&update_parameter()) {
1.588 raeburn 3677: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3678: return $errtext if ($fatal);
3679: }
3680:
3681: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3682: # change order
3683: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3684: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3685:
3686: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3687: return $errtext if ($fatal);
3688: }
1.364 bisitz 3689:
1.329 droeschl 3690: if ($env{'form.pastemarked'}) {
1.491 raeburn 3691: my %paste_errors;
1.533 raeburn 3692: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3693: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3694: \%paste_errors);
1.541 raeburn 3695: if (ref($pastemsgarray) eq 'ARRAY') {
3696: if (@{$pastemsgarray} > 0) {
3697: $r->print('<p class="LC_info">'.
3698: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3699: '</p>');
3700: }
1.541 raeburn 3701: }
3702: if ($lockerror) {
3703: $r->print('<p class="LC_error">'.
3704: $lockerror.
3705: '</p>');
3706: }
3707: if ($save_error ne '') {
3708: return $save_error;
3709: }
3710: if ($paste_res) {
3711: my %errortext = &Apache::lonlocal::texthash (
3712: fail => 'Storage of folder contents failed',
3713: failread => 'Reading folder contents failed',
3714: failstore => 'Storage of folder contents failed',
3715: );
3716: if ($errortext{$paste_res}) {
3717: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3718: }
1.329 droeschl 3719: }
1.491 raeburn 3720: if (keys(%paste_errors) > 0) {
1.538 raeburn 3721: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3722: &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".
3723: '<ul>'."\n");
3724: foreach my $key (sort(keys(%paste_errors))) {
3725: $r->print('<li>'.$key.'</li>'."\n");
3726: }
3727: $r->print('</ul></p>'."\n");
3728: }
1.538 raeburn 3729: } elsif ($env{'form.clearmarked'}) {
3730: my $output = &do_buffer_empty();
3731: if ($output) {
3732: $r->print('<p class="LC_info">'.$output.'</p>');
3733: }
3734: }
1.329 droeschl 3735:
3736: $r->print($upload_output);
3737:
1.538 raeburn 3738: # Rename, cut, copy or remove a single resource
1.602 raeburn 3739: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3740: my $contentchg;
1.633 raeburn 3741: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3742: $contentchg = 1;
3743: }
3744: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3745: return $errtext if ($fatal);
3746: }
1.538 raeburn 3747:
3748: # Cut, copy and/or remove multiple resources
3749: if ($env{'form.multichange'}) {
3750: my %allchecked = (
3751: cut => {},
3752: remove => {},
3753: );
3754: my $needsupdate;
3755: foreach my $which (keys(%allchecked)) {
3756: $env{'form.multi'.$which} =~ s/,$//;
3757: if ($env{'form.multi'.$which}) {
3758: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3759: if (ref($allchecked{$which}) eq 'HASH') {
3760: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3761: }
3762: }
3763: }
3764: if ($needsupdate) {
3765: my $haschanges = 0;
3766: my %curr_groups = &Apache::longroup::coursegroups();
3767: my $total = scalar(@LONCAPA::map::order) - 1;
3768: for (my $i=$total; $i>=0; $i--) {
3769: my $res = $LONCAPA::map::order[$i];
3770: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3771: $name=&LONCAPA::map::qtescape($name);
3772: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3773: next unless $url;
1.538 raeburn 3774: my %denied =
3775: &action_restrictions($coursenum,$coursedom,$url,
3776: $env{'form.folderpath'},\%curr_groups);
3777: foreach my $which (keys(%allchecked)) {
3778: next if ($denied{$which});
3779: next unless ($allchecked{$which}{$res});
3780: if ($which eq 'remove') {
3781: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3782: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3783: &Apache::lonnet::removeuploadedurl($url);
3784: } else {
3785: &LONCAPA::map::makezombie($res);
3786: }
3787: splice(@LONCAPA::map::order,$i,1);
3788: $haschanges ++;
3789: } elsif ($which eq 'cut') {
3790: &LONCAPA::map::makezombie($res);
3791: splice(@LONCAPA::map::order,$i,1);
3792: $haschanges ++;
3793: }
3794: }
3795: }
3796: if ($haschanges) {
3797: ($errtext,$fatal) =
3798: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3799: return $errtext if ($fatal);
3800: }
3801: }
3802: }
3803:
1.329 droeschl 3804: # Group import/search
3805: if ($env{'form.importdetail'}) {
3806: my @imports;
3807: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3808: if (defined($item)) {
3809: my ($name,$url,$residx)=
1.533 raeburn 3810: map { &unescape($_); } split(/\=/,$item);
3811: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3812: my ($suffix,$errortxt,$locknotfreed) =
3813: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3814: if ($locknotfreed) {
3815: $r->print($locknotfreed);
3816: }
3817: if ($suffix) {
3818: $url =~ s/_new\./_$suffix./;
3819: } else {
3820: return $errortxt;
3821: }
1.533 raeburn 3822: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3823: my $type = $1;
3824: my ($suffix,$errortxt,$locknotfreed) =
3825: &new_timebased_suffix($coursedom,$coursenum,$type);
3826: if ($locknotfreed) {
3827: $r->print($locknotfreed);
3828: }
3829: if ($suffix) {
3830: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3831: } else {
3832: return $errortxt;
3833: }
1.626 raeburn 3834: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3835: my ($suffix,$errortxt,$locknotfreed) =
3836: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3837: if ($locknotfreed) {
3838: $r->print($locknotfreed);
3839: }
3840: if ($suffix) {
3841: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3842: } else {
3843: return $errortxt;
3844: }
1.534 raeburn 3845: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3846: if ($supplementalflag) {
3847: next unless ($1 eq 'supplemental');
3848: if ($folder eq 'supplemental') {
3849: next unless ($2 eq 'default');
3850: } else {
3851: next unless ($folder eq 'supplemental_'.$2);
3852: }
3853: } else {
3854: next unless ($1 eq 'docs');
3855: if ($folder eq 'default') {
3856: next unless ($2 eq 'default');
3857: } else {
3858: next unless ($folder eq 'default_'.$2);
3859: }
3860: }
1.504 raeburn 3861: }
1.329 droeschl 3862: push(@imports, [$name, $url, $residx]);
3863: }
3864: }
1.530 raeburn 3865: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3866: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3867: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3868: return $errtext if ($fatal);
1.529 raeburn 3869: if ($fixuperrors) {
3870: $r->print($fixuperrors);
3871: }
1.329 droeschl 3872: }
3873: # Loading a complete map
3874: if ($env{'form.loadmap'}) {
3875: if ($env{'form.importmap'}=~/\w/) {
3876: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3877: my ($title,$url,$ext,$type)=split(/\:/,$res);
3878: my $idx=&LONCAPA::map::getresidx($url);
3879: $LONCAPA::map::resources[$idx]=$res;
3880: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3881: }
3882: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3883: $folder.'.'.$container,1);
1.329 droeschl 3884: return $errtext if ($fatal);
3885: } else {
3886: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3887:
1.329 droeschl 3888: }
3889: }
3890: &log_differences($plain);
3891: }
3892: # ---------------------------------------------------------------- End commands
3893: # ---------------------------------------------------------------- Print screen
3894: my $idx=0;
3895: my $shown=0;
3896: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3897: $r->print('<div class="LC_Box">'.
1.432 raeburn 3898: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3899: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3900: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3901: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3902: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3903: '</ol>');
1.381 bisitz 3904: if ($randompick>=0) {
3905: $r->print('<p class="LC_warning">'
3906: .&mt('Caution: this folder is set to randomly pick a subset'
3907: .' of resources. Adding or removing resources from this'
3908: .' folder will change the set of resources that the'
3909: .' students see, resulting in spurious or missing credit'
3910: .' for completed problems, not limited to ones you'
3911: .' modify. Do not modify the contents of this folder if'
3912: .' it is in active student use.')
3913: .'</p>'
3914: );
3915: }
3916: if ($is_random_order) {
3917: $r->print('<p class="LC_warning">'
3918: .&mt('Caution: this folder is set to randomly order its'
3919: .' contents. Adding or removing resources from this folder'
3920: .' will change the order of resources shown.')
3921: .'</p>'
3922: );
3923: }
3924: $r->print('</div>');
1.364 bisitz 3925: }
1.381 bisitz 3926:
1.685 raeburn 3927: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 3928: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 3929: if (ref($supplemental) eq 'HASH') {
3930: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
3931: (ref($supplemental->{'ids'}) eq 'HASH')) {
3932: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
3933: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
3934: if ($supplemental->{'hidden'}->{$mapnum}) {
3935: $ishidden = 1;
3936: }
3937: }
3938: }
3939: }
3940: }
3941:
1.538 raeburn 3942: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3943: %filters = (
1.543 raeburn 3944: canremove => [],
3945: cancut => [],
3946: cancopy => [],
3947: hiddenresource => [],
3948: encrypturl => [],
3949: randomorder => [],
3950: randompick => [],
1.538 raeburn 3951: );
3952: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3953: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3954: foreach my $res (@LONCAPA::map::order) {
3955: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3956: $name=&LONCAPA::map::qtescape($name);
3957: $url=&LONCAPA::map::qtescape($url);
3958: unless ($name) { $name=(split(/\//,$url))[-1]; }
3959: unless ($name) { $idx++; next; }
1.537 raeburn 3960: push(@allidx,$res);
3961: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3962: push(@allmapidx,$res);
3963: }
1.617 raeburn 3964:
1.682 raeburn 3965: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 3966: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
3967: $idx++;
3968: next;
3969: }
1.682 raeburn 3970: }
1.381 bisitz 3971: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3972: $coursenum,$coursedom,$crstype,
1.538 raeburn 3973: $pathitem,$supplementalflag,$container,
1.620 raeburn 3974: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 3975: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 3976: $idx++;
3977: $shown++;
1.329 droeschl 3978: }
1.424 onken 3979: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3980:
1.538 raeburn 3981: my $need_save;
1.611 raeburn 3982: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3983: my $toolslink;
1.682 raeburn 3984: if ($allowed || $canedit) {
3985: my $helpitem = 'Navigation_Screen';
3986: if (!$allowed) {
3987: $helpitem = 'Supplemental_Navigation';
3988: }
1.544 raeburn 3989: $toolslink = '<table><tr><td>'
1.520 raeburn 3990: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 3991: $helpitem,undef,'RAT')
1.520 raeburn 3992: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3993: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3994: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3995: .'id="LC_content_toolbar_edittoplevel" '
3996: .'class="LC_toolbarItem" '
3997: .'title="'.&mt('Supplemental Content Editor').'">'
3998: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3999: }
1.510 raeburn 4000: if ($shown) {
4001: if ($allowed) {
4002: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
4003: .&Apache::loncommon::start_data_table(undef,'contentlist')
4004: .&Apache::loncommon::start_data_table_header_row()
4005: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 4006: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 4007: .'<th>'.&mt('Document').'</th>'
4008: .'<th colspan="2">'.&mt('Settings').'</th>'
4009: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 4010: if ($folder !~ /^supplemental/) {
1.538 raeburn 4011: $lists{'canhide'} = join(',',@allidx);
4012: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 4013: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
4014: 'randomorder','randompick');
4015: foreach my $item (@possfilters) {
1.538 raeburn 4016: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 4017: if (@{$filters{$item}} > 0) {
4018: $lists{$item} = join(',',@{$filters{$item}});
4019: }
1.538 raeburn 4020: }
4021: }
1.537 raeburn 4022: if (@allidx > 0) {
4023: my $path;
4024: if ($env{'form.folderpath'}) {
1.630 raeburn 4025: $path =
1.537 raeburn 4026: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4027: }
1.538 raeburn 4028: if (@allidx > 1) {
1.630 raeburn 4029: $to_show .=
1.538 raeburn 4030: &Apache::loncommon::continue_data_table_row().
4031: '<td colspan="2"> </td>'.
4032: '<td>'.
1.611 raeburn 4033: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 4034: '</td>'.
1.633 raeburn 4035: '<td colspan="3"> </td>'.
4036: '<td colspan="2">'.
1.611 raeburn 4037: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 4038: '</td>'.
4039: &Apache::loncommon::end_data_table_row();
4040: $need_save = 1;
4041: }
1.537 raeburn 4042: }
4043: }
4044: $to_show .= $output.' '
1.510 raeburn 4045: .&Apache::loncommon::end_data_table()
4046: .'<br style="line-height:2px;" />'
4047: .&Apache::loncommon::end_scrollbox();
4048: } else {
1.520 raeburn 4049: $to_show .= $toolslink
1.510 raeburn 4050: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4051: .$output.' '
4052: .&Apache::loncommon::end_data_table();
1.393 raeburn 4053: }
1.510 raeburn 4054: } else {
1.520 raeburn 4055: if (!$allowed) {
4056: $to_show .= $toolslink;
4057: }
1.615 raeburn 4058: my $noresmsg;
4059: if ($allowed && $hiddentop && !$supplementalflag) {
4060: $noresmsg = &mt('Main Content Hidden');
4061: } else {
4062: $noresmsg = &mt('Currently empty');
4063: }
1.510 raeburn 4064: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
4065: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 4066: .$noresmsg
1.510 raeburn 4067: .'</div>'
4068: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 4069: }
4070: } else {
1.510 raeburn 4071: if ($shown) {
4072: $to_show = '<div>'
4073: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4074: .$output
4075: .&Apache::loncommon::end_data_table()
4076: .'</div>';
4077: } else {
4078: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 4079: .&mt('Currently empty')
1.510 raeburn 4080: .'</div>'
4081: }
1.458 raeburn 4082: }
4083: my $tid = 1;
4084: if ($supplementalflag) {
4085: $tid = 2;
1.329 droeschl 4086: }
4087: if ($allowed) {
1.484 raeburn 4088: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 4089: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 4090: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
4091: if ($canedit) {
4092: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
4093: }
1.460 raeburn 4094: } else {
4095: $r->print($to_show);
1.329 droeschl 4096: }
4097: return;
4098: }
4099:
1.538 raeburn 4100: sub multiple_check_form {
1.611 raeburn 4101: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 4102: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 4103: my $disabled;
4104: unless ($canedit) {
1.700 raeburn 4105: $disabled = ' disabled="disabled"';
1.611 raeburn 4106: }
1.538 raeburn 4107: my $output =
4108: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
4109: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
4110: '<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>'.
4111: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
4112: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
4113: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
4114: if ($caller eq 'settings') {
4115: $output .=
4116: '<table><tr>'.
4117: '<td class="LC_docs_entry_parameter">'.
4118: '<span class="LC_nobreak"><label>'.
1.611 raeburn 4119: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 4120: '</label></span></td>'.
4121: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 4122: '<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 4123: '</span></td>'.
4124: '</tr>'."\n".
4125: '<tr>'.
4126: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 4127: '<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 4128: '</label></span>'.
4129: '</td></tr></table>'."\n";
4130: } else {
4131: $output .=
4132: '<table><tr>'.
4133: '<td class="LC_docs_entry_parameter">'.
4134: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 4135: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 4136: '</label></span></td>'.
4137: '<td class="LC_docs_entry_parameter">'.
4138: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 4139: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 4140: '</label></span></td>'."\n".
4141: '<td class="LC_docs_entry_parameter">'.
4142: '<span class="LC_nobreak LC_docs_copy">'.
1.700 raeburn 4143: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538 raeburn 4144: '</label></span></td>'.
4145: '</tr></table>'."\n";
4146: }
4147: $output .=
4148: '</fieldset>'.
4149: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
4150: if ($caller eq 'settings') {
4151: $output .=
1.543 raeburn 4152: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
4153: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
4154: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
4155: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
4156: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 4157: } elsif ($caller eq 'actions') {
4158: $output .=
4159: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
4160: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
4161: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
4162: }
4163: $output .=
4164: '</form>'.
4165: '</div>';
4166: return $output;
4167: }
4168:
1.329 droeschl 4169: sub process_file_upload {
1.552 raeburn 4170: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 4171: # upload a file, if present
1.552 raeburn 4172: my $filesize = length($env{'form.uploaddoc'});
4173: if (!$filesize) {
4174: $$upload_output = '<div class="LC_error">'.
4175: &mt('Unable to upload [_1]. (size = [_2] bytes)',
4176: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
4177: $filesize).'<br />'.
4178: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
4179: '</div>';
4180: return;
4181: }
4182: my $quotatype = 'unofficial';
4183: if ($crstype eq 'Community') {
1.601 raeburn 4184: $quotatype = 'community';
4185: } elsif ($crstype eq 'Placement') {
4186: $quotatype = 'placement';
1.580 raeburn 4187: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 4188: $quotatype = 'official';
1.573 raeburn 4189: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
4190: $quotatype = 'textbook';
1.552 raeburn 4191: }
4192: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
4193: $filesize = int($filesize/1000); #expressed in kb
4194: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 4195: $env{'form.uploaddoc.filename'},$filesize,
4196: 'upload',$quotatype);
1.552 raeburn 4197: return if ($$upload_output);
4198: }
1.440 raeburn 4199: my ($parseaction,$showupload,$nextphase,$mimetype);
4200: if ($env{'form.parserflag'}) {
1.329 droeschl 4201: $parseaction = 'parse';
4202: }
4203: my $folder=$env{'form.folder'};
4204: if ($folder eq '') {
4205: $folder='default';
4206: }
4207: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
4208: my $errtext='';
4209: my $fatal=0;
4210: my $container='sequence';
1.519 raeburn 4211: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 4212: $container='page';
4213: }
4214: ($errtext,$fatal)=
1.534 raeburn 4215: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 4216: if ($#LONCAPA::map::order<1) {
4217: $LONCAPA::map::order[0]=1;
4218: $LONCAPA::map::resources[1]='';
4219: }
4220: my $destination = 'docs/';
4221: if ($folder =~ /^supplemental/) {
4222: $destination = 'supplemental/';
4223: }
4224: if (($folder eq 'default') || ($folder eq 'supplemental')) {
4225: $destination .= 'default/';
4226: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
4227: $destination .= $2.'/';
4228: }
1.534 raeburn 4229: if ($fatal) {
4230: $$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>';
4231: return;
4232: }
1.440 raeburn 4233: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 4234: my $newidx=&LONCAPA::map::getresidx();
4235: $destination .= $newidx;
1.439 raeburn 4236: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 4237: $parseaction,$allfiles,
1.440 raeburn 4238: $codebase,undef,undef,undef,undef,
4239: undef,undef,\$mimetype);
4240: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
4241: my $stored = $1;
4242: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
4243: $stored.'</span>').'</p>';
4244: } else {
4245: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
4246:
1.457 raeburn 4247: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 4248: return;
4249: }
1.329 droeschl 4250: my $ext='false';
4251: if ($url=~m{^http://}) { $ext='true'; }
4252: $url = &LONCAPA::map::qtunescape($url);
4253: my $comment=$env{'form.comment'};
4254: $comment = &LONCAPA::map::qtunescape($comment);
4255: if ($folder=~/^supplemental/) {
4256: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
4257: $env{'user.domain'}.'___&&&___'.$comment;
4258: }
4259:
4260: $LONCAPA::map::resources[$newidx]=
4261: $comment.':'.$url.':'.$ext.':normal:res';
4262: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
4263: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 4264: $folder.'.'.$container,1);
1.329 droeschl 4265: if ($fatal) {
1.457 raeburn 4266: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 4267: return;
1.329 droeschl 4268: } else {
1.440 raeburn 4269: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
4270: $$upload_output = $showupload;
1.384 raeburn 4271: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 4272: if ($total_embedded > 0) {
1.440 raeburn 4273: my $uploadphase = 'upload_embedded';
4274: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
4275: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 4276: my ($embedded,$num) =
1.440 raeburn 4277: &Apache::loncommon::ask_for_embedded_content(
4278: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
4279: if ($embedded) {
4280: if ($num) {
4281: $$upload_output .=
4282: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
4283: $nextphase = $uploadphase;
4284: } else {
4285: $$upload_output .= $embedded;
4286: }
4287: } else {
4288: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
4289: }
1.329 droeschl 4290: } else {
1.440 raeburn 4291: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 4292: }
1.457 raeburn 4293: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 4294: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
4295: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 4296: $nextphase = 'decompress_uploaded';
4297: my $position = scalar(@LONCAPA::map::order)-1;
4298: my $noextract = &return_to_editor();
4299: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
4300: my %archiveitems = (
4301: folderpath => $env{'form.folderpath'},
4302: cmd => $nextphase,
4303: newidx => $newidx,
4304: position => $position,
4305: phase => $nextphase,
1.477 raeburn 4306: comment => $comment,
1.480 raeburn 4307: );
4308: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
4309: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 4310: $$upload_output = $showupload.
4311: &Apache::loncommon::decompress_form($mimetype,
4312: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 4313: \%archiveitems,\@current);
1.329 droeschl 4314: }
4315: }
4316: }
1.440 raeburn 4317: return $nextphase;
1.329 droeschl 4318: }
4319:
1.480 raeburn 4320: sub get_dir_list {
4321: my ($url,$coursenum,$coursedom,$newidx) = @_;
4322: my ($destination,$dir_root) = &embedded_destination();
4323: my ($dirlistref,$listerror) =
4324: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
4325: my @dir_lines;
4326: my $dirptr=16384;
4327: if (ref($dirlistref) eq 'ARRAY') {
4328: foreach my $dir_line (sort
4329: {
4330: my ($afile)=split('&',$a,2);
4331: my ($bfile)=split('&',$b,2);
4332: return (lc($afile) cmp lc($bfile));
4333: } (@{$dirlistref})) {
4334: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
4335: $filename =~ s/\s+$//;
4336: next if ($filename =~ /^\.\.?$/);
4337: my $isdir = 0;
4338: if ($dirptr&$testdir) {
4339: $isdir = 1;
4340: }
4341: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
4342: }
4343: }
4344: return @dir_lines;
4345: }
4346:
1.329 droeschl 4347: sub is_supplemental_title {
4348: my ($title) = @_;
4349: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
4350: }
4351:
4352: # --------------------------------------------------------------- An entry line
4353:
4354: sub entryline {
1.501 raeburn 4355: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 4356: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 4357: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 4358: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 4359: if (&is_supplemental_title($title)) {
1.488 raeburn 4360: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 4361: $encodedtitle=$title;
1.329 droeschl 4362: } else {
4363: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 4364: $encodedtitle=$title;
1.329 droeschl 4365: $renametitle=$title;
4366: $foldertitle=$title;
4367: }
4368:
1.611 raeburn 4369: my ($disabled,$readonly,$js_lt);
4370: unless ($canedit) {
4371: $disabled = 'disabled="disabled"';
4372: $readonly = 1;
4373: }
4374:
1.329 droeschl 4375: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 4376:
1.329 droeschl 4377: $renametitle=~s/\\/\\\\/g;
4378: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 4379: $renametitle=~s/"/%22/g;
1.581 raeburn 4380: $renametitle=~s/ /%20/g;
4381: $oldtitle = $renametitle;
1.576 raeburn 4382: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 4383: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 4384: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 4385: # Edit commands
1.679 raeburn 4386: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 4387: if ($env{'form.folderpath'}) {
4388: $esc_path=&escape($env{'form.folderpath'});
4389: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4390: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4391: }
1.505 raeburn 4392: my $isexternal;
1.510 raeburn 4393: if ($residx) {
1.501 raeburn 4394: my $currurl = $url;
4395: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 4396: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4397: $isexternal = 1;
4398: }
1.510 raeburn 4399: if (!$supplementalflag) {
4400: my $path = 'uploaded/'.
4401: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4402: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4403: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4404: $residx,
4405: &Apache::lonnet::declutter($currurl));
4406: }
1.501 raeburn 4407: }
1.538 raeburn 4408: my ($renamelink,%lt,$ishash);
4409: if (ref($filtersref) eq 'HASH') {
4410: $ishash = 1;
4411: }
4412:
1.329 droeschl 4413: if ($allowed) {
1.538 raeburn 4414: $form_start = '
4415: <form action="/adm/coursedocs" method="post">
4416: ';
4417: $form_common=(<<END);
4418: <input type="hidden" name="folderpath" value="$path" />
4419: <input type="hidden" name="symb" value="$symb" />
4420: END
4421: $form_param=(<<END);
4422: <input type="hidden" name="setparms" value="$orderidx" />
4423: <input type="hidden" name="changeparms" value="0" />
4424: END
4425: $form_end = '</form>';
4426:
1.329 droeschl 4427: my $incindex=$index+1;
4428: my $selectbox='';
1.471 raeburn 4429: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 4430: ((split(/\:/,
1.344 bisitz 4431: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4432: ne '') &&
1.329 droeschl 4433: ((split(/\:/,
1.344 bisitz 4434: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 4435: ne '')) {
4436: $selectbox=
4437: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 4438: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 4439: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4440: if ($i==$incindex) {
1.358 bisitz 4441: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 4442: } else {
4443: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4444: }
4445: }
4446: $selectbox.='</select>';
4447: }
1.501 raeburn 4448: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 4449: 'up' => 'Move Up',
4450: 'dw' => 'Move Down',
4451: 'rm' => 'Remove',
4452: 'ct' => 'Cut',
4453: 'rn' => 'Rename',
1.501 raeburn 4454: 'cp' => 'Copy',
1.633 raeburn 4455: 'da' => 'Unset alias',
4456: 'sa' => 'Set alias',
1.501 raeburn 4457: 'ex' => 'External Resource',
1.598 raeburn 4458: 'et' => 'External Tool',
1.501 raeburn 4459: 'ed' => 'Edit',
4460: 'pr' => 'Preview',
4461: 'sv' => 'Save',
4462: 'ul' => 'URL',
1.611 raeburn 4463: 'ti' => 'Title',
1.618 raeburn 4464: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 4465: );
1.538 raeburn 4466: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4467: $env{'form.folderpath'},
4468: $currgroups);
1.517 raeburn 4469: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4470: my $skip_confirm = 0;
1.603 raeburn 4471: my $confirm_removal = 0;
1.329 droeschl 4472: if ( $folder =~ /^supplemental/
4473: || ($url =~ m{( /smppg$
4474: |/syllabus$
4475: |/aboutme$
4476: |/navmaps$
4477: |/bulletinboard$
1.626 raeburn 4478: |/ext\.tool$
1.505 raeburn 4479: |\.html$)}x)
4480: || $isexternal) {
1.329 droeschl 4481: $skip_confirm = 1;
4482: }
1.603 raeburn 4483: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4484: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4485: $confirm_removal = 1;
4486: }
1.633 raeburn 4487: if ($url =~ /$LONCAPA::assess_re/) {
4488: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4489: }
1.329 droeschl 4490:
1.538 raeburn 4491: if ($denied{'copy'}) {
1.543 raeburn 4492: $copylink=(<<ENDCOPY)
1.507 raeburn 4493: <span style="visibility: hidden;">$lt{'cp'}</span>
4494: ENDCOPY
4495: } else {
1.538 raeburn 4496: my $formname = 'edit_copy_'.$orderidx;
4497: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4498: $copylink=(<<ENDCOPY);
1.538 raeburn 4499: <form name="$formname" method="post" action="/adm/coursedocs">
4500: $form_common
1.611 raeburn 4501: <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 4502: $form_end
1.329 droeschl 4503: ENDCOPY
1.538 raeburn 4504: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4505: push(@{$filtersref->{'cancopy'}},$orderidx);
4506: }
1.329 droeschl 4507: }
1.538 raeburn 4508: if ($denied{'cut'}) {
1.507 raeburn 4509: $cutlink=(<<ENDCUT);
4510: <span style="visibility: hidden;">$lt{'ct'}</span>
4511: ENDCUT
4512: } else {
1.538 raeburn 4513: my $formname = 'edit_cut_'.$orderidx;
4514: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4515: $cutlink=(<<ENDCUT);
1.538 raeburn 4516: <form name="$formname" method="post" action="/adm/coursedocs">
4517: $form_common
1.542 raeburn 4518: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4519: <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 4520: $form_end
1.329 droeschl 4521: ENDCUT
1.538 raeburn 4522: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4523: push(@{$filtersref->{'cancut'}},$orderidx);
4524: }
1.329 droeschl 4525: }
1.538 raeburn 4526: if ($denied{'remove'}) {
1.507 raeburn 4527: $removelink=(<<ENDREM);
4528: <span style="visibility: hidden;">$lt{'rm'}</a>
4529: ENDREM
4530: } else {
1.538 raeburn 4531: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4532: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4533: $removelink=(<<ENDREM);
1.538 raeburn 4534: <form name="$formname" method="post" action="/adm/coursedocs">
4535: $form_common
1.542 raeburn 4536: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4537: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4538: <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 4539: $form_end
1.497 raeburn 4540: ENDREM
1.538 raeburn 4541: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4542: push(@{$filtersref->{'canremove'}},$orderidx);
4543: }
1.497 raeburn 4544: }
1.551 raeburn 4545: $renamelink=(<<ENDREN);
1.581 raeburn 4546: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4547: ENDREN
1.611 raeburn 4548: my ($uplink,$downlink);
4549: if ($canedit) {
4550: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4551: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4552: } else {
4553: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4554: $downlink = $uplink;
4555: }
1.329 droeschl 4556: $line.=(<<END);
4557: <td>
1.379 bisitz 4558: <div class="LC_docs_entry_move">
1.611 raeburn 4559: <a href="$uplink">
1.501 raeburn 4560: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4561: </a>
4562: </div>
4563: <div class="LC_docs_entry_move">
1.611 raeburn 4564: <a href="$downlink">
1.501 raeburn 4565: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4566: </a>
4567: </div>
1.329 droeschl 4568: </td>
4569: <td>
4570: $form_start
1.538 raeburn 4571: $form_param
1.478 raeburn 4572: $form_common
1.329 droeschl 4573: $selectbox
4574: $form_end
4575: </td>
1.540 raeburn 4576: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4577: $removelink
1.329 droeschl 4578: $cutlink
4579: $copylink
4580: </td>
4581: END
4582: }
4583: # Figure out what kind of a resource this is
4584: my ($extension)=($url=~/\.(\w+)$/);
4585: my $uploaded=($url=~/^\/*uploaded\//);
4586: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4587: my $isfolder;
4588: my $ispage;
4589: my $containerarg;
1.615 raeburn 4590: my $folderurl;
1.685 raeburn 4591: my $plainurl;
1.329 droeschl 4592: if ($uploaded) {
1.472 raeburn 4593: if (($extension eq 'sequence') || ($extension eq 'page')) {
4594: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4595: $containerarg = $1;
1.472 raeburn 4596: if ($extension eq 'sequence') {
4597: $icon=$iconpath.'navmap.folder.closed.gif';
4598: $isfolder=1;
4599: } else {
4600: $icon=$iconpath.'page.gif';
4601: $ispage=1;
4602: }
1.615 raeburn 4603: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4604: if ($allowed) {
4605: $url='/adm/coursedocs?';
4606: } else {
4607: $url='/adm/supplemental?';
4608: }
1.329 droeschl 4609: } else {
1.685 raeburn 4610: $plainurl = $url;
1.329 droeschl 4611: }
4612: }
1.364 bisitz 4613:
1.621 raeburn 4614: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4615: my $orig_url = $url;
1.340 raeburn 4616: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 4617: if ($container eq 'page') {
4618: $url=~s{^http(|s)(:|:)//}{/ext/};
4619: } else {
4620: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4621: }
1.501 raeburn 4622: if (!$supplementalflag && $residx && $symb) {
4623: if ((!$isfolder) && (!$ispage)) {
4624: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 4625: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4626: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4627: } else {
4628: $url=&Apache::lonnet::clutter($url);
4629: }
1.501 raeburn 4630: if ($url=~/^\/*uploaded\//) {
4631: $url=~/\.(\w+)$/;
4632: my $embstyle=&Apache::loncommon::fileembstyle($1);
4633: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4634: $url='/adm/wrapper'.$url;
4635: } elsif ($embstyle eq 'ssi') {
4636: #do nothing with these
4637: } elsif ($url!~/\.(sequence|page)$/) {
4638: $url='/adm/coursedocs/showdoc'.$url;
4639: }
1.623 raeburn 4640: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4641: my $wrapped = $1;
4642: my $exturl = $2;
1.668 raeburn 4643: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 4644: $url='/adm/wrapper'.$url;
4645: }
4646: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4647: $nomodal = 1;
4648: }
1.626 raeburn 4649: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4650: $url='/adm/wrapper'.$url;
1.621 raeburn 4651: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4652: if (($ENV{'SERVER_PORT'} == 443) &&
4653: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4654: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4655: $url .= '?usehttp=1';
4656: }
1.621 raeburn 4657: $nomodal = 1;
4658: }
1.598 raeburn 4659: }
1.696 raeburn 4660: my $checkencrypt;
1.680 raeburn 4661: if (!$env{'request.role.adv'}) {
1.615 raeburn 4662: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 4663: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 4664: $checkencrypt = 1;
1.620 raeburn 4665: } elsif (ref($navmapref)) {
1.615 raeburn 4666: unless (ref($$navmapref)) {
4667: $$navmapref = Apache::lonnavmaps::navmap->new();
4668: }
4669: if (ref($$navmapref)) {
4670: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 4671: $checkencrypt = 1;
1.615 raeburn 4672: }
4673: }
4674: }
1.680 raeburn 4675: }
4676: if ($checkencrypt) {
4677: my $currenc = $env{'request.enc'};
4678: $env{'request.enc'} = 1;
4679: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 4680: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 4681: if (&Apache::lonnet::symbverify($symb,$url)) {
4682: $url = $shownurl;
4683: } else {
4684: $url = '';
4685: }
4686: $env{'request.enc'} = $currenc;
4687: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4688: $shownsymb = $symb;
4689: if ($isexternal) {
4690: $url =~ s/\#[^#]+$//;
4691: if ($container eq 'page') {
4692: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 4693: }
1.612 raeburn 4694: }
1.696 raeburn 4695: } else {
4696: $url = '';
1.680 raeburn 4697: }
4698: unless ($env{'request.role.adv'}) {
4699: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4700: $url = '';
4701: }
4702: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4703: $url = '';
4704: $hiddenres = 1;
4705: }
4706: }
1.696 raeburn 4707: if (($url ne '') && ($shownsymb ne '')) {
4708: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 4709: }
1.329 droeschl 4710: }
1.621 raeburn 4711: } elsif ($supplementalflag) {
1.610 raeburn 4712: if ($isexternal) {
4713: if ($url =~ /^([^#]+)#([^#]+)$/) {
4714: $url = $1;
4715: $anchor = $2;
1.623 raeburn 4716: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 4717: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4718: if ($hostname ne '') {
4719: $url = 'http://'.$hostname.$url;
4720: }
4721: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 4722: }
4723: $nomodal = 1;
4724: }
1.610 raeburn 4725: }
1.621 raeburn 4726: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4727: if (($ENV{'SERVER_PORT'} == 443) &&
4728: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4729: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4730: if ($hostname ne '') {
4731: $url = 'http://'.$hostname.$url;
4732: }
4733: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 4734: }
1.621 raeburn 4735: $nomodal = 1;
4736: }
1.705 ! raeburn 4737: } elsif (($uploaded) && ($url ne '/adm/supplemental?') && ($url ne '/adm/coursedocs?')) {
1.686 raeburn 4738: my $embstyle=&Apache::loncommon::fileembstyle($extension);
4739: unless ($embstyle eq 'ssi') {
4740: if (($embstyle eq 'img')
4741: || ($embstyle eq 'emb')
4742: || ($embstyle eq 'wrp')) {
4743: $url='/adm/wrapper'.$url;
4744: } elsif ($url !~ /\.(sequence|page)$/) {
4745: $url='/adm/coursedocs/showdoc'.$url;
4746: }
4747: }
1.610 raeburn 4748: }
1.685 raeburn 4749: unless ($allowed && $env{'request.role.adv'}) {
4750: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4751: $hiddenres = 1;
4752: }
4753: }
1.329 droeschl 4754: }
1.615 raeburn 4755: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4756: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4757: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4758: my $foldername=&escape($foldertitle);
4759: my $folderpath=$env{'form.folderpath'};
4760: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4761: if (!$allowed && $supplementalflag) {
1.519 raeburn 4762: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4763: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 4764: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4765: $hiddenfolder = 1;
1.682 raeburn 4766: }
1.510 raeburn 4767: } else {
1.617 raeburn 4768: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4769: 'parameter_randompick'))[0];
4770: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4771: 'parameter_randomorder'))[0]=~/^yes$/i);
4772: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4773: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4774: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4775: 'parameter_encrypturl'))[0]=~/^yes$/i);
4776: unless ($hiddenmap) {
1.620 raeburn 4777: if (ref($navmapref)) {
4778: unless (ref($$navmapref)) {
4779: $$navmapref = Apache::lonnavmaps::navmap->new();
4780: }
4781: if (ref($$navmapref)) {
4782: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4783: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4784: unless (@resources) {
4785: $hiddenmap = 1;
4786: unless ($env{'request.role.adv'}) {
4787: $url = '';
4788: $hiddenfolder = 1;
4789: }
1.617 raeburn 4790: }
1.615 raeburn 4791: }
4792: }
4793: }
4794: }
1.617 raeburn 4795: unless ($encryptmap) {
1.620 raeburn 4796: if ((ref($navmapref)) && (ref($$navmapref))) {
4797: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4798: $encryptmap = 1;
4799: }
1.617 raeburn 4800: }
4801: }
1.630 raeburn 4802:
1.617 raeburn 4803: # Append randompick number, hidden, and encrypted with ":" to foldername,
4804: # so it gets transferred between levels
4805: $folderpath.=$containerarg.'&'.$foldername.
4806: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4807: unless ($url eq '') {
1.612 raeburn 4808: $url.='folderpath='.&escape($folderpath);
4809: }
1.510 raeburn 4810: my $rpckchk;
4811: if ($rpicknum) {
4812: $rpckchk = ' checked="checked"';
1.543 raeburn 4813: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4814: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4815: }
1.510 raeburn 4816: }
1.537 raeburn 4817: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4818: $rand_pick_text =
1.478 raeburn 4819: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4820: $form_param."\n".
1.478 raeburn 4821: $form_common."\n".
1.611 raeburn 4822: '<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 4823: if ($rpicknum ne '') {
4824: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4825: }
1.537 raeburn 4826: $rand_pick_text .= '</span></span>'.
4827: $form_end;
1.543 raeburn 4828: my $ro_set;
1.617 raeburn 4829: if ($randorder) {
1.543 raeburn 4830: $ro_set = 'checked="checked"';
4831: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4832: push(@{$filtersref->{'randomorder'}},$orderidx);
4833: }
4834: }
1.564 raeburn 4835: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4836: $rand_order_text =
1.537 raeburn 4837: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4838: $form_param."\n".
1.537 raeburn 4839: $form_common."\n".
1.611 raeburn 4840: '<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 4841: $form_end;
1.510 raeburn 4842: }
1.705 ! raeburn 4843: } elsif ($supplementalflag) {
1.598 raeburn 4844: my $isexttool;
1.626 raeburn 4845: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4846: $url='/adm/wrapper'.$url;
4847: $isexttool = 1;
4848: }
1.510 raeburn 4849: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4850: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4851: if ($title) {
1.687 raeburn 4852: $url .= '&title='.$encodedtitle;
1.510 raeburn 4853: }
1.598 raeburn 4854: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4855: $url .= '&idx='.$orderidx;
4856: }
1.610 raeburn 4857: if ($anchor ne '') {
4858: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4859: }
1.329 droeschl 4860: }
1.519 raeburn 4861: my ($tdalign,$tdwidth);
1.501 raeburn 4862: if ($allowed) {
1.630 raeburn 4863: my $fileloc =
1.501 raeburn 4864: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4865: if ($isexternal) {
1.630 raeburn 4866: ($editlink,$extresform) =
1.611 raeburn 4867: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4868: undef,undef,undef,undef,undef,undef,
4869: undef,$disabled);
1.626 raeburn 4870: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4871: ($editlink,$extresform) =
4872: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4873: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4874: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4875: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4876: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4877: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4878: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4879: my $suppanchor;
4880: if ($supplementalflag) {
4881: $suppanchor = $anchor;
4882: }
1.630 raeburn 4883: my $jscall =
1.501 raeburn 4884: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4885: $switchserver,
1.503 raeburn 4886: $forceedit,
1.679 raeburn 4887: undef,$symb,$shownsymb,
1.511 raeburn 4888: &escape($env{'form.folderpath'}),
1.622 raeburn 4889: $renametitle,$hostname,
4890: '','',1,$suppanchor);
1.501 raeburn 4891: if ($jscall) {
1.518 raeburn 4892: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4893: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4894: }
4895: }
4896: }
1.519 raeburn 4897: $tdalign = ' align="right" valign="top"';
4898: $tdwidth = ' width="80%"';
1.329 droeschl 4899: }
1.408 raeburn 4900: my $reinit;
4901: if ($crstype eq 'Community') {
4902: $reinit = &mt('(re-initialize community to access)');
4903: } else {
4904: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4905: }
1.702 raeburn 4906: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
1.650 raeburn 4907: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 4908: $line.= '<br />';
4909: if ($curralias ne '') {
4910: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4911: $lt{'da'}.'</a></span>';
4912: } else {
4913: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4914: $lt{'sa'}.'</a></span>';
4915: }
4916: }
1.701 raeburn 4917: $line.='</td><td><span class="LC_nobreak">';
1.685 raeburn 4918: my ($link,$nolink);
1.472 raeburn 4919: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4920: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
4921: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4922: $nolink = 1;
4923: }
4924: }
4925: if ($nolink) {
4926: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4927: } else {
4928: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4929: }
1.469 www 4930: } elsif ($url) {
1.610 raeburn 4931: if ($anchor ne '') {
4932: if ($supplementalflag) {
4933: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4934: } else {
4935: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4936: }
4937: }
1.705 ! raeburn 4938: if (($nomodal) && ($hostname ne '')) {
1.622 raeburn 4939: $link = 'http://'.$hostname.$url;
4940: } else {
4941: $link = $url;
4942: }
1.705 ! raeburn 4943: my $inhibitmenu;
! 4944: if ((($supplementalflag) && ($allowed) && ($url =~ m{^/adm/wrapper/})) ||
! 4945: (($allowed) && (($url =~ m{^/adm/(viewclasslist|$match_domain/$match_username/aboutme)(\?|$)}) ||
! 4946: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus(\?|$)})))) {
! 4947: $inhibitmenu = 'only_body=1';
! 4948: } else {
! 4949: $inhibitmenu = 'inhibitmenu=yes';
! 4950: }
! 4951: $link = &js_escape($link.(($url=~/\?/)?'&':'?').$inhibitmenu.$anchor);
1.685 raeburn 4952: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
4953: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4954: $nolink = 1;
4955: }
4956: }
4957: if ($nolink) {
4958: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4959: } elsif ($nomodal) {
1.621 raeburn 4960: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4961: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4962: } else {
4963: $line.=&Apache::loncommon::modal_link($link,
4964: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4965: }
1.469 www 4966: } else {
4967: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4968: }
1.519 raeburn 4969: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4970: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4971: if ($nolink) {
4972: $line.=$title;
4973: } else {
4974: $line.='<a href="'.$url.'">'.$title.'</a>';
4975: }
1.682 raeburn 4976: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4977: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4978: my $editurl = $url;
4979: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4980: $line .= ' '.'<a href="'.$editurl.'">'.
4981: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4982: '</a>';
4983: }
4984: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4985: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4986: }
1.469 www 4987: } elsif ($url) {
1.685 raeburn 4988: if ($nolink) {
4989: $line.=$title;
4990: } elsif ($nomodal) {
1.621 raeburn 4991: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4992: $title.'</a>';
4993: } else {
4994: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4995: }
1.617 raeburn 4996: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4997: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4998: } else {
4999: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
5000: }
1.633 raeburn 5001: if (($allowed) && ($curralias ne '')) {
5002: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
5003: } else {
5004: $line .= $extresform;
5005: }
5006: $line .= '</td>';
1.478 raeburn 5007: $rand_pick_text = ' ' if ($rand_pick_text eq '');
5008: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 5009: if ($uploaded && $url && !$isfolder && !$ispage) {
5010: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
5011: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
5012: }
5013: }
1.682 raeburn 5014: if ($allowed) {
5015: my %lt=&Apache::lonlocal::texthash(
5016: 'hd' => 'Hidden',
5017: 'ec' => 'URL hidden');
5018: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 5019: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5020: $hidtext = ' checked="checked"';
1.694 raeburn 5021: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 5022: push(@{$filtersref->{'hiddenresource'}},$orderidx);
5023: }
5024: }
1.682 raeburn 5025: $formhidden = 'edit_hiddenresource_'.$orderidx;
5026: $line.=(<<ENDPARMS);
1.329 droeschl 5027: <td class="LC_docs_entry_parameter">
1.537 raeburn 5028: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 5029: $form_param
1.478 raeburn 5030: $form_common
1.611 raeburn 5031: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 5032: $form_end
1.682 raeburn 5033: ENDPARMS
5034: if ($folder =~/^supplemental/) {
5035: $line.= "\n <td>";
5036: } else {
5037: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
5038: $enctext = ' checked="checked"';
5039: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
5040: push(@{$filtersref->{'encrypturl'}},$orderidx);
5041: }
5042: }
5043: $formurlhidden = 'edit_encrypturl_'.$orderidx;
5044: $line.=(<<ENDPARMS);
1.458 raeburn 5045: <br />
1.537 raeburn 5046: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 5047: $form_param
1.478 raeburn 5048: $form_common
1.611 raeburn 5049: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 5050: $form_end
5051: </td>
1.478 raeburn 5052: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
5053: $rand_order_text</td>
1.329 droeschl 5054: ENDPARMS
1.682 raeburn 5055: }
1.329 droeschl 5056: }
1.379 bisitz 5057: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 5058: return $line;
5059: }
5060:
1.538 raeburn 5061: sub action_restrictions {
5062: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
5063: my %denied = (
5064: cut => 0,
5065: copy => 0,
5066: remove => 0,
5067: );
5068: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
5069: # no copy for published maps
5070: $denied{'copy'} = 1;
1.597 raeburn 5071: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
5072: unless ($1 eq 'simpleproblem') {
5073: $denied{'copy'} = 1;
5074: }
5075: $denied{'cut'} = 1;
1.538 raeburn 5076: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
5077: if ($folderpath =~ /^default&[^\&]+$/) {
5078: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
5079: $denied{'remove'} = 1;
5080: }
5081: $denied{'cut'} = 1;
5082: $denied{'copy'} = 1;
5083: }
5084: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
5085: my $group = $1;
5086: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
5087: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5088: $denied{'remove'} = 1;
5089: }
5090: }
5091: $denied{'cut'} = 1;
5092: $denied{'copy'} = 1;
5093: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
5094: my $group = $1;
5095: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
5096: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5097: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5098: if (keys(%groupsettings) > 0) {
5099: $denied{'remove'} = 1;
5100: }
5101: $denied{'cut'} = 1;
5102: $denied{'copy'} = 1;
5103: }
5104: }
5105: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
5106: my $group = $1;
5107: if ($url =~ /group_boards_\Q$group\E/) {
5108: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5109: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5110: if (keys(%groupsettings) > 0) {
5111: if (ref($groupsettings{'functions'}) eq 'HASH') {
5112: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
5113: $denied{'remove'} = 1;
5114: }
5115: }
5116: }
5117: $denied{'cut'} = 1;
5118: $denied{'copy'} = 1;
5119: }
5120: }
5121: }
5122: return %denied;
5123: }
5124:
1.533 raeburn 5125: sub new_timebased_suffix {
1.538 raeburn 5126: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 5127: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 5128: if ($type eq 'paste') {
5129: $prefix = $type;
5130: $namespace = 'courseeditor';
1.587 raeburn 5131: $idtype = 'addcode';
1.538 raeburn 5132: } elsif ($type eq 'map') {
1.533 raeburn 5133: $prefix = 'docs';
5134: if ($area eq 'supplemental') {
5135: $prefix = 'supp';
5136: }
5137: $prefix .= $container;
5138: $namespace = 'uploadedmaps';
5139: } else {
5140: $prefix = $type;
5141: $namespace = 'templated';
1.504 raeburn 5142: }
5143: my ($suffix,$freedlock,$error) =
1.587 raeburn 5144: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 5145: if (!$suffix) {
1.538 raeburn 5146: if ($type eq 'paste') {
5147: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
5148: } elsif ($type eq 'map') {
1.533 raeburn 5149: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
5150: } elsif ($type eq 'smppg') {
5151: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 5152: } elsif ($type eq 'exttool') {
5153: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 5154: } else {
1.565 bisitz 5155: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 5156: }
1.504 raeburn 5157: if ($error) {
5158: $errtext .= '<br />'.$error;
5159: }
5160: }
5161: if ($freedlock ne 'ok') {
1.630 raeburn 5162: $locknotfreed =
1.533 raeburn 5163: '<div class="LC_error">'.
5164: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 5165: if ($type eq 'paste') {
1.591 raeburn 5166: if ($freedlock eq 'nolock') {
5167: $locknotfreed =
5168: '<div class="LC_error">'.
5169: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
5170:
1.593 droeschl 5171: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 5172: } else {
5173: $locknotfreed .=
5174: &mt('This will prevent addition of items to the clipboard until your next log-in.');
5175: }
1.538 raeburn 5176: } elsif ($type eq 'map') {
1.591 raeburn 5177: $locknotfreed .=
5178: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 5179: } elsif ($type eq 'smppg') {
5180: $locknotfreed .=
5181: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 5182: } elsif ($type eq 'exttool') {
5183: $locknotfreed .=
5184: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 5185: } else {
5186: $locknotfreed .=
1.565 bisitz 5187: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 5188: }
1.538 raeburn 5189: unless ($type eq 'paste') {
5190: $locknotfreed .=
1.560 raeburn 5191: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
5192: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 5193: }
5194: $locknotfreed .= '</div>';
1.504 raeburn 5195: }
5196: return ($suffix,$errtext,$locknotfreed);
5197: }
5198:
1.329 droeschl 5199: =pod
5200:
5201: =item tiehash()
5202:
5203: tie the hash
5204:
5205: =cut
5206:
5207: sub tiehash {
5208: my ($mode)=@_;
5209: $hashtied=0;
5210: if ($env{'request.course.fn'}) {
5211: if ($mode eq 'write') {
5212: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5213: &GDBM_WRCREAT(),0640)) {
5214: $hashtied=2;
5215: }
5216: } else {
5217: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5218: &GDBM_READER(),0640)) {
5219: $hashtied=1;
5220: }
5221: }
1.364 bisitz 5222: }
1.329 droeschl 5223: }
5224:
5225: sub untiehash {
5226: if ($hashtied) { untie %hash; }
5227: $hashtied=0;
5228: return OK;
5229: }
5230:
5231:
5232:
5233:
5234: sub checkonthis {
1.637 raeburn 5235: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 5236: $url=&unescape($url);
5237: $alreadyseen{$url}=1;
5238: $r->rflush();
5239: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
5240: $r->print("\n<br />");
5241: if ($level==0) {
5242: $r->print("<br />");
5243: }
5244: for (my $i=0;$i<=$level*5;$i++) {
5245: $r->print(' ');
5246: }
5247: $r->print('<a href="'.$url.'" target="cat">'.
5248: ($title?$title:$url).'</a> ');
5249: if ($url=~/^\/res\//) {
1.637 raeburn 5250: my $updated;
5251: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
5252: ($url !~ /\.\d+\.\w+$/)) {
5253: $updated = &Apache::lonnet::remove_stale_resfile($url);
5254: }
1.329 droeschl 5255: my $result=&Apache::lonnet::repcopy(
5256: &Apache::lonnet::filelocation('',$url));
5257: if ($result eq 'ok') {
5258: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 5259: if ($updated) {
5260: $r->print('<br />');
5261: for (my $i=0;$i<=$level*5;$i++) {
5262: $r->print(' ');
5263: }
5264: $r->print('- '.&mt('Outdated copy removed'));
5265: }
1.329 droeschl 5266: $r->rflush();
5267: &Apache::lonnet::countacc($url);
5268: $url=~/\.(\w+)$/;
5269: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
5270: $r->print('<br />');
5271: $r->rflush();
5272: for (my $i=0;$i<=$level*5;$i++) {
5273: $r->print(' ');
5274: }
5275: $r->print('- '.&mt('Rendering:').' ');
5276: my ($errorcount,$warningcount)=split(/:/,
5277: &Apache::lonnet::ssi_body($url,
5278: ('grade_target'=>'web',
5279: 'return_only_error_and_warning_counts' => 1)));
5280: if (($errorcount) ||
5281: ($warningcount)) {
5282: if ($errorcount) {
1.369 bisitz 5283: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 5284: &mt('[quant,_1,error]',$errorcount).'</span>');
5285: }
5286: if ($warningcount) {
5287: $r->print('<span class="LC_warning">'.
5288: &mt('[quant,_1,warning]',$warningcount).'</span>');
5289: }
5290: } else {
5291: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
5292: }
5293: $r->rflush();
5294: }
5295: my $dependencies=
5296: &Apache::lonnet::metadata($url,'dependencies');
5297: foreach my $dep (split(/\,/,$dependencies)) {
5298: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 5299: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 5300: }
5301: }
5302: } elsif ($result eq 'unavailable') {
5303: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
5304: } elsif ($result eq 'not_found') {
5305: unless ($url=~/\$/) {
1.521 bisitz 5306: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 5307: } else {
1.366 bisitz 5308: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 5309: }
5310: } else {
5311: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
5312: }
1.637 raeburn 5313: if (($updated) && ($result ne 'ok')) {
5314: $r->print('<br />'.&mt('Outdated copy removed'));
5315: }
1.329 droeschl 5316: }
5317: }
5318: }
5319:
5320:
5321:
5322: =pod
5323:
5324: =item list_symbs()
5325:
1.485 raeburn 5326: List Content Identifiers
1.329 droeschl 5327:
5328: =cut
5329:
5330: sub list_symbs {
5331: my ($r) = @_;
5332:
1.408 raeburn 5333: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5334: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
5335: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
5336: $r->print(&startContentScreen('tools'));
1.329 droeschl 5337: my $navmap = Apache::lonnavmaps::navmap->new();
5338: if (!defined($navmap)) {
5339: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
5340: '<div class="LC_error">'.
5341: &mt('Unable to retrieve information about course contents').
5342: '</div>');
1.408 raeburn 5343: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 5344: } else {
1.484 raeburn 5345: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
5346: &Apache::loncommon::start_data_table().
5347: &Apache::loncommon::start_data_table_header_row().
5348: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
5349: &Apache::loncommon::end_data_table_header_row()."\n");
5350: my $count;
1.329 droeschl 5351: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 5352: $r->print(&Apache::loncommon::start_data_table_row().
5353: '<td>'.$res->compTitle().'</td>'.
5354: '<td>'.$res->symb().'</td>'.
1.521 bisitz 5355: &Apache::loncommon::end_data_table_row());
1.484 raeburn 5356: $count ++;
5357: }
5358: if (!$count) {
5359: $r->print(&Apache::loncommon::start_data_table_row().
5360: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
5361: &Apache::loncommon::end_data_table_row());
1.329 droeschl 5362: }
1.484 raeburn 5363: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 5364: }
1.521 bisitz 5365: $r->print(&endContentScreen());
1.329 droeschl 5366: }
5367:
1.651 raeburn 5368: sub short_urls {
5369: my ($r,$canedit) = @_;
5370: my $crstype = &Apache::loncommon::course_type();
5371: my $formname = 'shortenurl';
5372: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5373: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5374: $r->print(&startContentScreen('tools'));
5375: my ($navmap,$errormsg) =
5376: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5377: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5378: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5379: my (%maps,%resources,%titles);
5380: if (!ref($navmap)) {
5381: $r->print($errormsg.
5382: &endContentScreen());
5383: return '';
5384: } else {
1.652 raeburn 5385: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 5386: $r->rflush();
5387: my $readonly;
5388: if ($canedit) {
1.671 raeburn 5389: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 5390: if ($numnew) {
5391: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
5392: }
5393: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
5394: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
5395: foreach my $error (@{$errors}) {
5396: $r->print('<li>'.$error.'</li>');
5397: }
5398: $r->print('</ul><br />');
5399: }
5400: } else {
5401: $readonly = 1;
5402: }
5403: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
5404: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
5405: undef,undef,undef,undef,undef,\%currtiny,$readonly));
5406: }
5407: $r->print(&endContentScreen());
5408: }
5409:
1.637 raeburn 5410: sub contentverifyform {
5411: my ($r) = @_;
5412: my $crstype = &Apache::loncommon::course_type();
5413: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5414: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5415: $r->print(&startContentScreen('tools'));
5416: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5417: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
5418: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
5419: ' <span class="LC_nobreak">'.
5420: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
5421: &mt('No').'</label>'.(' 'x2).
5422: '<label><input type="radio" name="checkstale" value="1" />'.
5423: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 5424: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 5425: '<input type="hidden" value="1" name="tools" />'.
5426: '<input type="hidden" value="1" name="verify" /></p></form>');
5427: $r->print(&endContentScreen());
5428: return;
5429: }
1.329 droeschl 5430:
5431: sub verifycontent {
1.637 raeburn 5432: my ($r,$checkstale) = @_;
1.408 raeburn 5433: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 5434: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5435: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 5436: $r->print(&startContentScreen('tools'));
5437: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 5438: $hashtied=0;
5439: undef %alreadyseen;
5440: %alreadyseen=();
5441: &tiehash();
1.484 raeburn 5442:
1.329 droeschl 5443: foreach my $key (keys(%hash)) {
5444: if ($hash{$key}=~/\.(page|sequence)$/) {
5445: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5446: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 5447: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 5448: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 5449: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 5450: }
5451: }
5452: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 5453: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 5454: }
5455: }
5456: &untiehash();
1.442 www 5457: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 5458: $r->print(&endContentScreen());
1.329 droeschl 5459: }
5460:
5461: sub devalidateversioncache {
5462: my $src=shift;
5463: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5464: &Apache::lonnet::clutter($src));
5465: }
5466:
5467: sub checkversions {
1.611 raeburn 5468: my ($r,$canedit) = @_;
1.408 raeburn 5469: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 5470: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5471: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 5472: $r->print(&startContentScreen('tools'));
1.442 www 5473:
1.329 droeschl 5474: my $header='';
5475: my $startsel='';
5476: my $monthsel='';
5477: my $weeksel='';
5478: my $daysel='';
5479: my $allsel='';
5480: my %changes=();
5481: my $starttime=0;
5482: my $haschanged=0;
5483: my %setversions=&Apache::lonnet::dump('resourceversions',
5484: $env{'course.'.$env{'request.course.id'}.'.domain'},
5485: $env{'course.'.$env{'request.course.id'}.'.num'});
5486:
5487: $hashtied=0;
5488: &tiehash();
1.611 raeburn 5489: if ($canedit) {
5490: my %newsetversions=();
5491: if ($env{'form.setmostrecent'}) {
5492: $haschanged=1;
5493: foreach my $key (keys(%hash)) {
5494: if ($key=~/^ids\_(\/res\/.+)$/) {
5495: $newsetversions{$1}='mostrecent';
5496: &devalidateversioncache($1);
5497: }
5498: }
5499: } elsif ($env{'form.setcurrent'}) {
5500: $haschanged=1;
5501: foreach my $key (keys(%hash)) {
5502: if ($key=~/^ids\_(\/res\/.+)$/) {
5503: my $getvers=&Apache::lonnet::getversion($1);
5504: if ($getvers>0) {
5505: $newsetversions{$1}=$getvers;
5506: &devalidateversioncache($1);
5507: }
5508: }
1.329 droeschl 5509: }
1.611 raeburn 5510: } elsif ($env{'form.setversions'}) {
5511: $haschanged=1;
5512: foreach my $key (keys(%env)) {
5513: if ($key=~/^form\.set_version_(.+)$/) {
5514: my $src=$1;
5515: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5516: $newsetversions{$src}=$env{$key};
5517: &devalidateversioncache($src);
5518: }
5519: }
1.329 droeschl 5520: }
1.611 raeburn 5521: }
5522: if ($haschanged) {
5523: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5524: $env{'course.'.$env{'request.course.id'}.'.domain'},
5525: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5526: $r->print(&Apache::loncommon::confirmwrapper(
5527: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5528: } else {
5529: $r->print(&Apache::loncommon::confirmwrapper(
5530: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 5531: }
1.611 raeburn 5532: &mark_hash_old();
5533: }
5534: &changewarning($r,'');
1.329 droeschl 5535: }
5536: if ($env{'form.timerange'} eq 'all') {
5537: # show all documents
1.549 raeburn 5538: $header=&mt('All content in '.$crstype);
1.521 bisitz 5539: $allsel=' selected="selected"';
1.329 droeschl 5540: foreach my $key (keys(%hash)) {
5541: if ($key=~/^ids\_(\/res\/.+)$/) {
5542: my $src=$1;
5543: $changes{$src}=1;
5544: }
5545: }
5546: } else {
5547: # show documents which changed
5548: %changes=&Apache::lonnet::dump
5549: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5550: $env{'course.'.$env{'request.course.id'}.'.num'});
5551: my $firstkey=(keys(%changes))[0];
5552: unless ($firstkey=~/^error\:/) {
5553: unless ($env{'form.timerange'}) {
5554: $env{'form.timerange'}=604800;
5555: }
5556: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5557: .&mt('seconds');
5558: if ($env{'form.timerange'}==-1) {
5559: $seltext='since start of course';
1.521 bisitz 5560: $startsel=' selected="selected"';
1.329 droeschl 5561: $env{'form.timerange'}=time;
5562: }
5563: $starttime=time-$env{'form.timerange'};
5564: if ($env{'form.timerange'}==2592000) {
5565: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5566: $monthsel=' selected="selected"';
1.329 droeschl 5567: } elsif ($env{'form.timerange'}==604800) {
5568: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5569: $weeksel=' selected="selected"';
1.329 droeschl 5570: } elsif ($env{'form.timerange'}==86400) {
5571: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5572: $daysel=' selected="selected"';
1.329 droeschl 5573: }
5574: $header=&mt('Content changed').' '.$seltext;
5575: } else {
5576: $header=&mt('No content modifications yet.');
5577: }
5578: }
5579: %setversions=&Apache::lonnet::dump('resourceversions',
5580: $env{'course.'.$env{'request.course.id'}.'.domain'},
5581: $env{'course.'.$env{'request.course.id'}.'.num'});
5582: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5583: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5584: 'lm' => 'Version changes since last Month',
5585: 'lw' => 'Version changes since last Week',
5586: 'sy' => 'Version changes since Yesterday',
5587: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5588: 'cd' => 'Change display',
1.329 droeschl 5589: 'sd' => 'Display',
5590: 'fi' => 'File',
5591: 'md' => 'Modification Date',
5592: 'mr' => 'Most recently published Version',
1.408 raeburn 5593: 've' => 'Version used in '.$crstype,
5594: 'vu' => 'Set Version to be used in '.$crstype,
5595: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5596: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5597: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5598: 'di' => 'Differences',
1.484 raeburn 5599: 'save' => 'Save changes',
5600: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5601: 'act' => 'Actions');
1.611 raeburn 5602: my ($disabled,$readonly);
5603: unless ($canedit) {
5604: $disabled = 'disabled="disabled"';
5605: $readonly = 1;
5606: }
1.329 droeschl 5607: $r->print(<<ENDHEADERS);
1.484 raeburn 5608: <h4 class="LC_info">$header</h4>
1.329 droeschl 5609: <form action="/adm/coursedocs" method="post">
5610: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5611: <div class="LC_left_float">
1.479 golterma 5612: <fieldset>
1.484 raeburn 5613: <legend>$lt{'cd'}</legend>
1.329 droeschl 5614: <select name="timerange">
1.521 bisitz 5615: <option value='all'$allsel>$lt{'al'}</option>
5616: <option value="-1"$startsel>$lt{'st'}</option>
5617: <option value="2592000"$monthsel>$lt{'lm'}</option>
5618: <option value="604800"$weeksel>$lt{'lw'}</option>
5619: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5620: </select>
5621: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5622: </fieldset>
5623: </div>
5624: <div class="LC_left_float">
5625: <fieldset>
5626: <legend>$lt{'act'}</legend>
1.611 raeburn 5627: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5628: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5629: </fieldset>
5630: </div>
5631: <br clear="all" />
5632: <hr />
5633: <h4>$lt{'vers'}</h4>
1.329 droeschl 5634: ENDHEADERS
1.479 golterma 5635: #number of columns for version history
1.571 raeburn 5636: my %changedbytime;
5637: foreach my $key (keys(%changes)) {
5638: #excludes not versionable problems from resource version history:
5639: next if ($key =~ /^\/res\/lib\/templates/);
5640: my $chg;
5641: if ($env{'form.timerange'} eq 'all') {
5642: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5643: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5644: } else {
5645: $chg = $changes{$key};
5646: next if ($chg < $starttime);
5647: }
5648: push(@{$changedbytime{$chg}},$key);
5649: }
5650: if (keys(%changedbytime) == 0) {
5651: &untiehash();
5652: $r->print(&mt('No content changes in imported content in specified time frame').
5653: &endContentScreen());
5654: return;
5655: }
1.479 golterma 5656: $r->print(
1.611 raeburn 5657: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5658: &Apache::loncommon::start_data_table().
5659: &Apache::loncommon::start_data_table_header_row().
5660: '<th>'.&mt('Resources').'</th>'.
5661: "<th>$lt{'mr'}</th>".
5662: "<th>$lt{'ve'}</th>".
5663: "<th>$lt{'vu'}</th>".
5664: '<th>'.&mt('History').'</th>'.
5665: &Apache::loncommon::end_data_table_header_row()
5666: );
1.571 raeburn 5667: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5668: foreach my $key (sort(@{$changedbytime{$chg}})) {
5669: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5670: my $currentversion=&Apache::lonnet::getversion($key);
5671: if ($currentversion<0) {
5672: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5673: }
5674: my $linkurl=&Apache::lonnet::clutter($key);
5675: $r->print(
5676: &Apache::loncommon::start_data_table_row().
5677: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5678: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5679: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5680: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5681: '<td align="right">'
5682: );
5683: # Used in course
5684: my $usedversion=$hash{'version_'.$linkurl};
5685: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5686: if ($usedversion != $currentversion) {
1.479 golterma 5687: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5688: } else {
1.479 golterma 5689: $r->print($usedversion);
5690: }
1.329 droeschl 5691: } else {
1.521 bisitz 5692: $r->print($currentversion);
1.329 droeschl 5693: }
1.571 raeburn 5694: $r->print('</td><td title="'.$lt{'vu'}.'">');
5695: # Set version
5696: $r->print(&Apache::loncommon::select_form(
5697: $setversions{$linkurl},
5698: 'set_version_'.$linkurl,
5699: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5700: '' => '',
5701: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5702: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5703: my $lastold=1;
5704: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5705: my $url=$root.'.'.$prevvers.'.'.$extension;
5706: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5707: $lastold=$prevvers;
5708: }
5709: }
5710: $r->print('</td>');
5711: # List all available versions
5712: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5713: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5714: my $url=$root.'.'.$prevvers.'.'.$extension;
5715: $r->print(
5716: '<span class="LC_nobreak">'
5717: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5718: .&mt('Version [_1]',$prevvers).'</a>'
5719: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5720: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5721: .')');
5722: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5723: $r->print(
5724: ' <a href="/adm/diff?filename='.
5725: &Apache::lonnet::clutter($root.'.'.$extension).
5726: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5727: '" target="diffs">'.&mt('Diffs').'</a>');
5728: }
5729: $r->print('</span><br />');
1.329 droeschl 5730: }
1.571 raeburn 5731: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5732: }
1.329 droeschl 5733: }
1.521 bisitz 5734: $r->print(
5735: &Apache::loncommon::end_data_table().
1.611 raeburn 5736: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5737: '</form>'
5738: );
1.329 droeschl 5739:
5740: &untiehash();
1.521 bisitz 5741: $r->print(&endContentScreen());
1.571 raeburn 5742: return;
1.329 droeschl 5743: }
5744:
5745: sub mark_hash_old {
5746: my $retie_hash=0;
5747: if ($hashtied) {
5748: $retie_hash=1;
5749: &untiehash();
5750: }
5751: &tiehash('write');
5752: $hash{'old'}=1;
5753: &untiehash();
5754: if ($retie_hash) { &tiehash(); }
5755: }
5756:
5757: sub is_hash_old {
5758: my $untie_hash=0;
5759: if (!$hashtied) {
5760: $untie_hash=1;
5761: &tiehash();
5762: }
5763: my $return=$hash{'old'};
5764: if ($untie_hash) { &untiehash(); }
5765: return $return;
5766: }
5767:
5768: sub changewarning {
5769: my ($r,$postexec,$message,$url)=@_;
5770: if (!&is_hash_old()) { return; }
5771: my $pathvar='folderpath';
5772: my $path=&escape($env{'form.folderpath'});
5773: if (!defined($url)) {
5774: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5775: }
5776: my $course_type = &Apache::loncommon::course_type();
5777: if (!defined($message)) {
5778: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5779: }
1.653 raeburn 5780: my $windowname = 'loncapaclient';
5781: if ($env{'request.lti.login'}) {
5782: $windowname .= 'lti';
5783: }
1.329 droeschl 5784: $r->print("\n\n".
1.372 bisitz 5785: '<script type="text/javascript">'."\n".
5786: '// <![CDATA['."\n".
5787: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5788: '// ]]>'."\n".
1.369 bisitz 5789: '</script>'."\n".
1.653 raeburn 5790: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5791: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5792: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5793: &mt($message,' <input type="hidden" name="'.
5794: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5795: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5796: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5797: }
5798:
5799:
5800: sub init_breadcrumbs {
1.571 raeburn 5801: my ($form,$text,$help)=@_;
1.329 droeschl 5802: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5803: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5804: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5805: faq=>273,
5806: bug=>'Instructor Interface',
1.571 raeburn 5807: help => $help});
1.329 droeschl 5808: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5809: text=>$text,
5810: faq=>273,
5811: bug=>'Instructor Interface'});
5812: }
5813:
1.441 www 5814: # subroutine to list form elements
5815: sub create_list_elements {
5816: my @formarr = @_;
5817: my $list = '';
1.501 raeburn 5818: foreach my $button (@formarr){
5819: foreach my $picture (keys(%{$button})) {
5820: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5821: }
5822: }
5823: return $list;
5824: }
1.329 droeschl 5825:
1.441 www 5826: # subroutine to create ul from list elements
5827: sub create_form_ul {
5828: my $list = shift;
5829: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5830: return $ul;
5831: }
1.329 droeschl 5832:
1.442 www 5833: #
5834: # Start tabs
5835: #
5836:
5837: sub startContentScreen {
1.484 raeburn 5838: my ($mode) = @_;
5839: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5840: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5841: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5842: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5843: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5844: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5845: } else {
1.549 raeburn 5846: $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 5847: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5848: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5849: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5850: }
5851: $output .= "\n".'</ul>'."\n";
5852: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5853: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5854: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5855: return $output;
1.442 www 5856: }
5857:
5858: #
5859: # End tabs
5860: #
5861:
5862: sub endContentScreen {
1.484 raeburn 5863: return '</div></div></div>';
1.442 www 5864: }
1.329 droeschl 5865:
1.446 www 5866: sub supplemental_base {
1.548 raeburn 5867: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5868: }
5869:
1.329 droeschl 5870: sub handler {
5871: my $r = shift;
5872: &Apache::loncommon::content_type($r,'text/html');
5873: $r->send_http_header;
5874: return OK if $r->header_only;
1.484 raeburn 5875:
5876: # get course data
1.408 raeburn 5877: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5878: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5879: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5880:
1.606 raeburn 5881: # get docroot
5882: my $londocroot = $r->dir_config('lonDocRoot');
5883:
1.484 raeburn 5884: # graphics settings
5885: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5886:
1.443 www 5887: #
1.329 droeschl 5888: # --------------------------------------------- Initialize help topics for this
5889: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5890: 'Adding_External_Resource','Adding_External_Tool',
5891: 'Navigate_Content','Adding_Folders','Docs_Overview',
5892: 'Load_Map','Supplemental','Score_Upload_Form',
5893: 'Adding_Pages','Importing_LON-CAPA_Resource',
5894: 'Importing_IMS_Course','Uploading_From_Harddrive',
5895: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5896: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5897: }
5898: # Composite help files
5899: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5900: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5901: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5902: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5903: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5904: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5905: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5906: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5907: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5908: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5909:
1.611 raeburn 5910: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 5911: # does this user have privileges to modify content.
5912: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 5913: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 5914: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5915: $allowed = 1;
1.682 raeburn 5916: }
5917: $canedit = 1;
5918: $canview = 1;
5919: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5920: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5921: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5922: $allowed = 1;
5923: }
1.682 raeburn 5924: $canview = 1;
1.611 raeburn 5925: }
5926: unless ($canedit) {
5927: $disabled = ' disabled="disabled"';
1.472 raeburn 5928: }
1.582 raeburn 5929: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5930: if ($env{'form.inhibitmenu'}) {
5931: unless ($env{'form.inhibitmenu'} eq 'yes') {
5932: delete($env{'form.inhibitmenu'});
5933: }
5934: }
5935:
1.582 raeburn 5936: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5937: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5938: if (!$canedit) {
5939: &verifycontent($r);
5940: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5941: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5942: text=>'Results',
5943: faq=>273,
5944: bug=>'Instructor Interface'});
5945: &verifycontent($r,$env{'form.checkstale'});
5946: } else {
5947: &contentverifyform($r);
5948: }
1.329 droeschl 5949: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5950: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5951: &list_symbs($r);
1.651 raeburn 5952: } elsif ($allowed && $env{'form.shorturls'}) {
5953: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5954: &short_urls($r,$canedit);
1.329 droeschl 5955: } elsif ($allowed && $env{'form.docslog'}) {
5956: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5957: my $folder = $env{'form.folder'};
5958: if ($folder eq '') {
5959: $folder='default';
5960: }
1.611 raeburn 5961: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5962: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5963: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5964: &checkversions($r,$canedit);
5965: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5966: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5967: &dumpcourse($r);
1.611 raeburn 5968: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5969: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5970: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5971: } else {
1.611 raeburn 5972: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5973: $noendpage = 1;
5974: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5975: if ($redirect) {
5976: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5977: my $container = 'sequence';
5978: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5979: $is_random_order,$container) =
5980: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5981: my (@folders)=split('&',$env{'form.folderpath'});
5982: $env{'form.foldername'}=&unescape(pop(@folders));
5983: my $folder=pop(@folders);
5984: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5985: $folder.'.'.$container);
5986: my $warning;
5987: if ($fatal) {
5988: if ($container eq 'page') {
5989: $warning = &mt('An error occurred retrieving the contents of the current page.');
5990: } else {
5991: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5992: }
5993: } else {
5994: my $url = $redirect;
5995: my $srcfile = $londocroot.$url;
5996: $url =~ s{^/priv/}{/res/};
5997: my $targetfile = $londocroot.$url;
5998: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5999: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
6000: $env{'form.folder'} = $folder;
6001: &snapshotbefore();
6002: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
6003: my $ext = 'false';
6004: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
6005: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
6006: ':'.$ext.':normal:res';
6007: push(@LONCAPA::map::order,$newidx);
6008: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
6009: 'string_yesno');
6010: &remember_parms($newidx,'hiddenresource','set','yes');
6011: ($errtext,$fatal) =
6012: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
6013: &log_differences($plain);
6014: &mark_hash_old();
6015: $r->internal_redirect($redirect);
6016: return OK;
6017: }
1.654 raeburn 6018: } else {
6019: $r->internal_redirect($redirect);
1.606 raeburn 6020: }
6021: }
6022: }
1.445 www 6023: #
6024: # Done catching special calls
1.484 raeburn 6025: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 6026: # Get the parameters that may be needed
6027: #
6028: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 6029: ['folderpath','title',
1.519 raeburn 6030: 'forcesupplement','forcestandard',
1.510 raeburn 6031: 'tools','symb','command','supppath']);
1.445 www 6032:
1.635 raeburn 6033: foreach my $item ('forcesupplement','forcestandard','tools') {
6034: next if ($env{'form.'.$item} eq '');
6035: unless ($env{'form.'.$item} eq '1') {
6036: delete($env{'form.'.$item});
6037: }
6038: }
6039:
6040: if ($env{'form.command'}) {
6041: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
6042: delete($env{'form.command'});
6043: }
6044: }
6045:
6046: if ($env{'form.symb'}) {
6047: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
6048: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
6049: delete($env{'form.symb'});
6050: }
6051: }
6052:
1.445 www 6053: # standard=1: this is a "new-style" course with an uploaded map as top level
6054: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 6055:
6056: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 6057:
1.484 raeburn 6058: # Decide whether this should display supplemental or main content or utilities
1.445 www 6059: # supplementalflag=1: show supplemental documents
6060: # supplementalflag=0: show standard documents
1.484 raeburn 6061: # toolsflag=1: show utilities
1.445 www 6062:
1.561 raeburn 6063: my $unesc_folderpath = &unescape($env{'form.folderpath'});
6064: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
6065: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 6066: $supplementalflag=0;
6067: }
6068: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
6069: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
1.705 ! raeburn 6070: unless (($supplementalflag) ||
! 6071: ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
! 6072: unless ($allowed) { $supplementalflag=1; }
! 6073: unless ($standard) { $supplementalflag=1; }
! 6074: }
1.484 raeburn 6075: my $toolsflag=0;
6076: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 6077:
1.635 raeburn 6078: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 6079: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 6080: }
6081:
1.685 raeburn 6082: my $backto_supppath;
1.635 raeburn 6083: if ($env{'form.supppath'} ne '') {
1.685 raeburn 6084: if ($supplementalflag && $allowed) {
6085: $backto_supppath = &validate_supppath($coursenum,$coursedom);
6086: }
1.635 raeburn 6087: }
6088:
1.329 droeschl 6089: my $script='';
6090: my $showdoc=0;
1.457 raeburn 6091: my $addentries = {};
1.475 raeburn 6092: my $container;
1.329 droeschl 6093: my $containertag;
1.508 raeburn 6094: my $pathitem;
1.598 raeburn 6095: my %ltitools;
1.699 raeburn 6096: my $posslti;
1.617 raeburn 6097: my $hiddentop;
1.615 raeburn 6098: my $navmap;
1.617 raeburn 6099: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 6100:
1.464 www 6101: # Do we directly jump somewhere?
1.525 raeburn 6102: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 6103: if ($env{'form.symb'} ne '') {
1.522 raeburn 6104: $env{'form.folderpath'}=
1.617 raeburn 6105: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 6106: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 6107: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 6108: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 6109: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 6110: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 6111: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 6112: }
1.472 raeburn 6113: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 6114: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 6115: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 6116: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 6117: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 6118: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
6119: } elsif ($env{'form.command'} eq 'contents') {
6120: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
6121: } elsif ($env{'form.command'} eq 'home') {
6122: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 6123: }
6124:
1.525 raeburn 6125:
1.445 www 6126: # Where do we store these for when we come back?
6127: my $stored_folderpath='docs_folderpath';
6128: if ($supplementalflag) {
6129: $stored_folderpath='docs_sup_folderpath';
6130: }
1.464 www 6131:
1.519 raeburn 6132: # No folderpath, and in edit mode, see if we have something stored
6133: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 6134: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 6135: {'folderpath' => 'scalar'});
1.615 raeburn 6136:
6137: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
6138: if ($supplementalflag) {
6139: undef($env{'form.folderpath'}) if ($1 eq 'default');
6140: } else {
6141: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
6142: }
6143: } else {
1.523 raeburn 6144: undef($env{'form.folderpath'});
6145: }
1.677 raeburn 6146: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 6147: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 6148: }
1.329 droeschl 6149: }
1.705 ! raeburn 6150:
! 6151: # If we are not allowed to make changes and this is supplemental content set folderpath
! 6152: if ((!$allowed) && ($supplementalflag)) {
1.446 www 6153: unless ($env{'form.folderpath'} =~ /^supplemental/) {
6154: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 6155: }
6156: }
1.446 www 6157: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 6158: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 6159: $env{'form.folderpath'} = &supplemental_base()
6160: .'&'.
1.329 droeschl 6161: $env{'form.folderpath'};
6162: }
1.685 raeburn 6163: # If allowed and user's role is not advanced check folderpath is not hidden
6164: my $hidden_and_empty;
1.687 raeburn 6165: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 6166: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 6167: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 6168: my $folder = $pathitems[-2];
6169: if ($folder eq '') {
6170: undef($env{'form.folderpath'});
6171: } else {
6172: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 6173: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 6174: $folderurl .= '.page';
6175: } else {
6176: $folderurl .= '.sequence';
6177: }
1.685 raeburn 6178: if ($supplementalflag) {
6179: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
6180: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 6181: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 6182: if (ref($supplemental) eq 'HASH') {
6183: my ($suppmap,$suppmapnum);
6184: if ($folder eq 'supplemental') {
6185: $suppmap = 'default';
6186: $suppmapnum = 0;
6187: } elsif ($folder =~ /^supplemental_(\d+)$/) {
6188: $suppmap = $1;
6189: $suppmapnum = $suppmap;
6190: }
6191: if ($hiddenfolder) {
6192: my $hascontent;
6193: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
6194: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
6195: $hascontent = 1;
6196: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
6197: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
6198: if ($id =~ /^$suppmapnum\:/) {
6199: $hascontent = 1;
6200: last;
6201: }
6202: }
6203: }
6204: last if ($hascontent);
6205: }
6206: unless ($hascontent) {
6207: if ($foldername ne '') {
6208: $hidden_and_empty = $foldername;
6209: } else {
6210: $hidden_and_empty = $folder;
6211: }
6212: }
6213: }
6214: }
6215: } else {
6216: unless (ref($navmap)) {
6217: $navmap = Apache::lonnavmaps::navmap->new();
6218: }
6219: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
6220: $foldername = &HTML::Entities::decode(&unescape($foldername));
6221: if (ref($navmap)) {
6222: if ($hiddenfolder ||
6223: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
6224: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
6225: unless (@resources) {
6226: if ($foldername ne '') {
6227: $hidden_and_empty = $foldername;
6228: } else {
6229: $hidden_and_empty = $folder;
6230: }
6231: }
6232: }
6233: }
1.617 raeburn 6234: }
1.685 raeburn 6235: if ($hidden_and_empty ne '') {
6236: splice(@pathitems,-2);
6237: if (@pathitems) {
6238: $env{'form.folderpath'} = join('&',@pathitems);
6239: } else {
6240: undef($env{'form.folderpath'});
1.615 raeburn 6241: }
6242: }
6243: }
6244: }
6245:
1.446 www 6246: # If after all of this, we still don't have any paths, make them
1.519 raeburn 6247: unless ($env{'form.folderpath'}) {
1.446 www 6248: if ($supplementalflag) {
6249: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 6250: } elsif ($allowed) {
6251: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 6252: }
1.472 raeburn 6253: }
1.446 www 6254:
1.445 www 6255: # Store this
1.484 raeburn 6256: unless ($toolsflag) {
1.615 raeburn 6257: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 6258: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 6259: {'folderpath' => 'scalar'});
1.510 raeburn 6260: }
1.519 raeburn 6261: my $folderpath;
1.484 raeburn 6262: if ($env{'form.folderpath'}) {
1.519 raeburn 6263: $folderpath = $env{'form.folderpath'};
6264: my (@folders)=split('&',$env{'form.folderpath'});
6265: $env{'form.foldername'}=&unescape(pop(@folders));
6266: if ($env{'form.foldername'} =~ /\:1$/) {
6267: $container = 'page';
6268: } else {
6269: $container = 'sequence';
6270: }
6271: $env{'form.folder'}=pop(@folders);
1.484 raeburn 6272: } else {
1.519 raeburn 6273: if ($env{'form.folder'} eq '' ||
6274: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 6275: if ($env{'form.folder'} eq 'supplemental') {
6276: $folderpath=&supplemental_base();
6277: } elsif (!$hiddentop) {
6278: $folderpath='default&'.
6279: &escape(&mt('Main Content').':::::');
6280: }
1.484 raeburn 6281: }
6282: }
1.519 raeburn 6283: $containertag = '<input type="hidden" name="folderpath" value="" />';
6284: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 6285: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
6286: $showdoc='/'.$1;
6287: }
6288: if ($showdoc) { # got called in sequence from course
6289: $allowed=0;
6290: } else {
1.611 raeburn 6291: if ($canedit) {
1.484 raeburn 6292: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
6293: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 6294: }
6295: }
1.329 droeschl 6296: }
6297:
1.344 bisitz 6298: # get personal data
1.329 droeschl 6299: my $uname=$env{'user.name'};
6300: my $udom=$env{'user.domain'};
6301: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
6302:
6303: if ($allowed) {
1.484 raeburn 6304: if ($toolsflag) {
6305: $script .= &inject_data_js();
6306: my ($home,$other,%outhash)=&authorhosts();
6307: if (!$home && $other) {
6308: my @hosts;
6309: foreach my $aurole (keys(%outhash)) {
6310: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6311: push(@hosts,$outhash{$aurole});
6312: }
6313: }
6314: $script .= &dump_switchserver_js(@hosts);
6315: }
1.458 raeburn 6316: } else {
1.570 raeburn 6317: my $tid = 1;
1.484 raeburn 6318: my @tabids;
6319: if ($supplementalflag) {
1.655 raeburn 6320: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 6321: $tid = 2;
1.484 raeburn 6322: } else {
6323: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 6324: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 6325: unshift(@tabids,'001');
6326: push(@tabids,('dd1','ee1'));
6327: }
1.458 raeburn 6328: }
1.484 raeburn 6329: my $tabidstr = join("','",@tabids);
1.699 raeburn 6330: my (%domtools,%crstools);
6331: my %tooltypes = &Apache::loncommon::usable_exttools();
6332: if ($tooltypes{'dom'}) {
6333: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
6334: }
6335: if ($tooltypes{'crs'}) {
6336: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
6337: }
6338: %ltitools = (
6339: dom => \%domtools,
6340: crs => \%crstools,
6341: );
6342: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622 raeburn 6343: my $hostname = $r->hostname();
1.606 raeburn 6344: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 6345: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 6346: &history_tab_js().
6347: &inject_data_js().
1.570 raeburn 6348: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 6349: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 6350: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
6351: if ($hidden_and_empty ne '') {
6352: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
6353: $hidden_and_empty);
6354: $onload .= "javascript:alert('".&js_escape($alert)."');";
6355: }
1.484 raeburn 6356: $addentries = {
1.685 raeburn 6357: onload => $onload,
1.484 raeburn 6358: };
1.458 raeburn 6359: }
1.538 raeburn 6360: $script .= &paste_popup_js();
1.501 raeburn 6361: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
6362: &mt('Switch server?');
6363:
6364:
1.329 droeschl 6365: }
6366: # -------------------------------------------------------------------- Body tag
1.369 bisitz 6367: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 6368: .'// <![CDATA['."\n"
6369: .$script."\n"
6370: .'// ]]>'."\n"
1.595 musolffc 6371: .'</script>'."\n"
6372: .'<script type="text/javascript"
6373: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 6374:
6375: # Breadcrumbs
6376: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 6377:
6378: if ($showdoc) {
1.682 raeburn 6379: my $args;
6380: if ($supplementalflag) {
1.687 raeburn 6381: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
6382: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.705 ! raeburn 6383: $args = {'bread_crumbs' => $brcrum,
! 6384: 'bread_crumbs_nomenu' => 1};
1.682 raeburn 6385: } else {
6386: $args = {'force_register' => $showdoc};
6387: }
6388: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 6389: } elsif ($toolsflag) {
1.611 raeburn 6390: my ($breadtext,$breadtitle);
1.617 raeburn 6391: $breadtext = "$crstype Editor";
1.611 raeburn 6392: if ($canedit) {
6393: $breadtitle = 'Editing '.$crstype.' Contents';
6394: } else {
6395: $breadtext .= ' (View-only mode)';
6396: $breadtitle = 'Viewing '.$crstype.' Contents';
6397: }
1.571 raeburn 6398: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6399: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 6400: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
6401: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6402: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6403: $breadtitle)
1.571 raeburn 6404: );
1.510 raeburn 6405: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 6406: unless ($env{'request.role.adv'}) {
6407: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
6408: $r->internal_redirect('/adm/navmaps');
6409: return OK;
6410: }
6411: }
1.510 raeburn 6412: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
1.705 ! raeburn 6413: my $args = {'bread_crumbs' => $brcrum};
! 6414: unless (($env{'form.folderpath'} eq '') ||
! 6415: ($env{'form.folder'} eq 'supplemental')) {
! 6416: $args->{'bread_crumbs_nomenu'} = 1;
! 6417: }
1.510 raeburn 6418: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
1.705 ! raeburn 6419: $args));
1.510 raeburn 6420: } else {
1.611 raeburn 6421: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 6422: $breadtext = "$crstype Editor";
1.611 raeburn 6423: if ($canedit) {
6424: $breadtitle = 'Editing '.$crstype.' Contents';
6425: $helpitem = 'Docs_Adding_Course_Doc';
6426: } else {
6427: $breadtext .= ' (View-only mode)';
6428: $breadtitle = 'Viewing '.$crstype.' Contents';
6429: $helpitem = 'Docs_Viewing_Course_Doc';
6430: }
1.392 raeburn 6431: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6432: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 6433: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 6434: {'add_entries' => $addentries}
6435: )
1.392 raeburn 6436: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6437: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6438: $breadtitle,
6439: $helpitem)
1.392 raeburn 6440: );
6441: }
1.364 bisitz 6442:
1.329 droeschl 6443: my %allfiles = ();
6444: my %codebase = ();
1.440 raeburn 6445: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 6446: if ($canedit) {
1.684 raeburn 6447: undef($suppchanges);
1.329 droeschl 6448: if (($env{'form.uploaddoc.filename'}) &&
6449: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 6450: my $context = $1;
6451: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 6452: undef($hadchanges);
1.440 raeburn 6453: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 6454: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 6455: undef($navmap);
1.329 droeschl 6456: if ($hadchanges) {
6457: &mark_hash_old();
6458: }
1.684 raeburn 6459: if ($suppchanges) {
6460: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6461: undef($suppchanges);
6462: }
1.440 raeburn 6463: $r->print($upload_output);
6464: } elsif ($env{'form.phase'} eq 'upload_embedded') {
6465: # Process file upload - phase two - upload embedded objects
6466: $uploadphase = 'check_embedded';
6467: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
6468: my $state = &embedded_form_elems($uploadphase,$primaryurl,
6469: $env{'form.newidx'});
6470: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6471: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6472: my ($destination,$dir_root) = &embedded_destination();
6473: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
6474: my $actionurl = '/adm/coursedocs';
1.630 raeburn 6475: my ($result,$flag) =
1.440 raeburn 6476: &Apache::loncommon::upload_embedded('coursedoc',$destination,
6477: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
6478: $actionurl);
6479: $r->print($result.&return_to_editor());
6480: } elsif ($env{'form.phase'} eq 'check_embedded') {
6481: # Process file upload - phase three - modify references in HTML file
6482: $uploadphase = 'modified_orightml';
6483: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6484: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6485: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 6486: my $result =
1.482 raeburn 6487: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
6488: $docuname,$docudom,undef,
6489: $dir_root);
1.630 raeburn 6490: $r->print($result.&return_to_editor());
1.476 raeburn 6491: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
6492: $uploadphase = 'decompress_phase_one';
6493: $r->print(&decompression_phase_one().
6494: &return_to_editor());
6495: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
6496: $uploadphase = 'decompress_phase_two';
6497: $r->print(&decompression_phase_two().
6498: &return_to_editor());
1.329 droeschl 6499: }
6500: }
6501:
1.484 raeburn 6502: if ($allowed && $toolsflag) {
6503: $r->print(&startContentScreen('tools'));
1.611 raeburn 6504: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 6505: $r->print(&endContentScreen());
6506: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 6507: # -----------------------------------------------------------------------------
6508: my %lt=&Apache::lonlocal::texthash(
6509: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 6510: 'upfi' => 'Upload File',
1.553 raeburn 6511: 'upld' => 'Upload Content',
1.329 droeschl 6512: 'srch' => 'Search',
6513: 'impo' => 'Import',
1.487 raeburn 6514: 'lnks' => 'Import from Stored Links',
1.502 raeburn 6515: 'impm' => 'Import from Assembled Map',
1.630 raeburn 6516: 'imcr' => 'Import from Course Resources',
1.598 raeburn 6517: 'extr' => 'External Resource',
6518: 'extt' => 'External Tool',
1.329 droeschl 6519: 'selm' => 'Select Map',
6520: 'load' => 'Load Map',
6521: 'newf' => 'New Folder',
6522: 'newp' => 'New Composite Page',
6523: 'syll' => 'Syllabus',
1.425 raeburn 6524: 'navc' => 'Table of Contents',
1.343 biermanm 6525: 'sipa' => 'Simple Course Page',
1.329 droeschl 6526: 'sipr' => 'Simple Problem',
1.630 raeburn 6527: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 6528: 'stpr' => 'Standard Problem',
6529: 'news' => 'New sub-directory',
6530: 'crpr' => 'Create Problem',
1.689 raeburn 6531: 'swit' => 'Switch Server',
1.329 droeschl 6532: 'drbx' => 'Drop Box',
1.451 www 6533: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 6534: 'bull' => 'Discussion Board',
1.347 weissno 6535: 'mypi' => 'My Personal Information Page',
1.353 weissno 6536: 'grpo' => 'Group Portfolio',
1.329 droeschl 6537: 'rost' => 'Course Roster',
1.528 raeburn 6538: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 6539: 'imsf' => 'IMS Upload',
6540: 'imsl' => 'Upload IMS package',
1.501 raeburn 6541: 'cms' => 'Origin of IMS package',
6542: 'se' => 'Select',
1.329 droeschl 6543: 'file' => 'File',
6544: 'title' => 'Title',
1.606 raeburn 6545: 'addp' => 'Add Placeholder to course?',
6546: 'uste' => 'Use Template?',
6547: 'fnam' => 'File Name:',
6548: 'loca' => 'Location:',
6549: 'dire' => 'Directory:',
6550: 'cate' => 'Category:',
6551: 'tmpl' => 'Template:',
1.698 raeburn 6552: 'empd' => 'No resources found',
1.329 droeschl 6553: 'comment' => 'Comment',
1.403 raeburn 6554: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 6555: 'bb5' => 'Blackboard 5',
6556: 'bb6' => 'Blackboard 6',
6557: 'angel5' => 'ANGEL 5.5',
6558: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 6559: 'yes' => 'Yes',
6560: 'no' => 'No',
1.618 raeburn 6561: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 6562: );
1.329 droeschl 6563: # -----------------------------------------------------------------------------
1.595 musolffc 6564:
6565: # Calculate free quota space for a user or course. A javascript function checks
6566: # file size to determine if upload should be allowed.
6567: my $quotatype = 'unofficial';
6568: if ($crstype eq 'Community') {
1.601 raeburn 6569: $quotatype = 'community';
6570: } elsif ($crstype eq 'Placement') {
6571: $quotatype = 'placement';
1.595 musolffc 6572: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6573: $quotatype = 'official';
6574: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6575: $quotatype = 'textbook';
6576: }
6577: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6578: 'course',$quotatype); # expressed in MB
6579: my $current_disk_usage = 0;
6580: foreach my $subdir ('docs','supplemental') {
6581: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6582: "userfiles/$subdir",1); # expressed in kB
6583: }
6584: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 6585: my $usage = $current_disk_usage/1024; # in MB
6586: my $quota = $disk_quota;
6587: my $percent;
6588: if ($disk_quota == 0) {
6589: $percent = 100.0;
6590: } else {
1.619 raeburn 6591: $percent = 100*($usage/$disk_quota);
1.605 raeburn 6592: }
6593: $usage = sprintf("%.2f",$usage);
6594: $quota = sprintf("%.2f",$quota);
6595: $percent = sprintf("%.0f",$percent);
6596: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6597: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 6598:
1.329 droeschl 6599: my $fileupload=(<<FIUP);
1.605 raeburn 6600: $quotainfo
1.329 droeschl 6601: $lt{'file'}:<br />
6602: FIUP
6603: my $checkbox=(<<CHBO);
6604: <!-- <label>$lt{'parse'}?
6605: <input type="checkbox" name="parserflag" />
6606: </label> -->
6607: <label>
1.611 raeburn 6608: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6609: </label>
6610: CHBO
1.501 raeburn 6611: my $imsfolder = $env{'form.folder'};
6612: if ($imsfolder eq '') {
6613: $imsfolder = 'default';
6614: }
6615: my $imspform=(<<IMSFORM);
6616: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6617: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6618: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 6619: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 6620: <legend>$lt{'imsf'}</legend>
6621: $fileupload
1.702 raeburn 6622: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
6623: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501 raeburn 6624: <br />
6625: <p>
6626: $lt{'cms'}:
1.611 raeburn 6627: <select name="source" $disabled>
1.501 raeburn 6628: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 6629: <option value="bb5">$lt{'bb5'}</option>
6630: <option value="bb6">$lt{'bb6'}</option>
6631: <option value="angel5">$lt{'angel5'}</option>
6632: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 6633: </select>
6634: <input type="hidden" name="folder" value="$imsfolder" />
6635: </p>
6636: <input type="hidden" name="phase" value="one" />
1.611 raeburn 6637: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 6638: </fieldset>
6639: </form>
6640: IMSFORM
1.329 droeschl 6641:
6642: my $fileuploadform=(<<FUFORM);
1.501 raeburn 6643: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6644: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6645: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 6646: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 6647: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6648: <input type="hidden" name="active" value="aa" />
1.595 musolffc 6649: $fileupload
1.702 raeburn 6650: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
6651: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 6652: <br />
6653: $lt{'title'}:<br />
1.611 raeburn 6654: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 6655: $pathitem
1.329 droeschl 6656: <input type="hidden" name="cmd" value="upload_default" />
6657: <br />
1.458 raeburn 6658: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6659: $checkbox
6660: </span>
1.501 raeburn 6661: <br clear="all" />
1.611 raeburn 6662: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 6663: </fieldset>
6664: </form>
1.383 tempelho 6665: FUFORM
1.329 droeschl 6666:
1.611 raeburn 6667: my $mapimportjs;
6668: if ($canedit) {
6669: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6670: } else {
6671: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6672: }
1.502 raeburn 6673: my $importpubform=(<<SEDFFORM);
1.514 raeburn 6674: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 6675: $lt{'impm'}</a>$help{'Load_Map'}
6676: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 6677: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 6678: <legend>$lt{'impm'}</legend>
1.371 tempelho 6679: <input type="hidden" name="active" value="bb" />
1.502 raeburn 6680: $lt{'copm'}<br />
6681: <span class="LC_nobreak">
6682: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 6683: onfocus="this.blur();$mapimportjs" $disabled />
6684: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6685: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 6686: </fieldset>
6687: </form>
6688:
1.383 tempelho 6689: SEDFFORM
1.606 raeburn 6690: my $importcrsresform;
1.608 raeburn 6691: my ($numdirs,$pickfile) =
1.690 raeburn 6692: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
1.608 raeburn 6693: "resize_scrollbox('contentscroll','1','0');",
6694: undef,'res');
1.606 raeburn 6695: if ($pickfile) {
6696: $importcrsresform=(<<CRSFORM);
1.690 raeburn 6697: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 6698: $lt{'imcr'}</a>$help{'Course_Resources'}
6699: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6700: <fieldset id="importcrsresform" style="display: none;">
6701: <legend>$lt{'imcr'}</legend>
1.698 raeburn 6702: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 6703: <input type="hidden" name="active" value="bb" />
6704: $pickfile
6705: <p>
1.699 raeburn 6706: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606 raeburn 6707: </p>
6708: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 6709: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 raeburn 6710: </div>
6711: <div id="importcrsresempty" style="display: none;">
6712: <p>
6713: $lt{'empd'}
6714: </p>
6715: </div>
1.606 raeburn 6716: </fieldset>
6717: </form>
6718: CRSFORM
6719: }
6720:
1.611 raeburn 6721: my $fromstoredjs;
6722: if ($canedit) {
6723: $fromstoredjs = 'open_StoredLinks_Import()';
6724: } else {
6725: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6726: }
6727:
1.502 raeburn 6728: my @importpubforma = (
1.508 raeburn 6729: { '<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 6730: { '<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 6731: { '<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 6732: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6733: );
6734: if ($pickfile) {
1.690 raeburn 6735: 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 6736: }
1.502 raeburn 6737: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 6738: my $extresourcesform =
6739: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6740: $help{'Adding_External_Resource'},
6741: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6742: my $exttoolform =
6743: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6744: $help{'Adding_External_Tool'},undef,
6745: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6746: \%ltitools,$disabled);
1.329 droeschl 6747: if ($allowed) {
1.492 raeburn 6748: my $folder = $env{'form.folder'};
6749: if ($folder eq '') {
6750: $folder='default';
6751: }
1.615 raeburn 6752: if ($canedit) {
6753: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6754: if ($output) {
6755: $r->print($output);
6756: }
1.538 raeburn 6757: }
1.337 ehlerst 6758: $r->print(<<HIDDENFORM);
6759: <form name="renameform" method="post" action="/adm/coursedocs">
6760: <input type="hidden" name="title" />
6761: <input type="hidden" name="cmd" />
6762: <input type="hidden" name="markcopy" />
6763: <input type="hidden" name="copyfolder" />
6764: $containertag
6765: </form>
1.633 raeburn 6766: <form name="aliasform" method="post" action="/adm/coursedocs">
6767: <input type="hidden" name="alias" />
6768: <input type="hidden" name="cmd" />
6769: $containertag
6770: </form>
1.484 raeburn 6771:
1.337 ehlerst 6772: HIDDENFORM
1.508 raeburn 6773: $r->print(&makesimpleeditform($pathitem)."\n".
6774: &makedocslogform($pathitem."\n".
1.484 raeburn 6775: '<input type="hidden" name="folder" value="'.
6776: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6777: }
1.442 www 6778:
6779: # Generate the tabs
1.510 raeburn 6780: my ($mode,$needs_end);
1.472 raeburn 6781: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6782: my @folders = split('&',$env{'form.folderpath'});
6783: unless (@folders > 2) {
6784: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6785: $needs_end = 1;
6786: }
1.472 raeburn 6787: } else {
1.484 raeburn 6788: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6789: $needs_end = 1;
1.472 raeburn 6790: }
1.443 www 6791:
1.442 www 6792: #
1.622 raeburn 6793: my $hostname = $r->hostname();
1.442 www 6794: my $savefolderpath;
6795:
1.395 raeburn 6796: if ($allowed) {
1.329 droeschl 6797: my $folder=$env{'form.folder'};
1.615 raeburn 6798: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6799: $folder='default';
1.356 tempelho 6800: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6801: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6802: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6803: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6804: }
6805: my $postexec='';
6806: if ($folder eq 'default') {
1.653 raeburn 6807: my $windowname = 'loncapaclient';
6808: if ($env{'request.lti.login'}) {
6809: $windowname .= 'lti';
6810: }
1.372 bisitz 6811: $r->print('<script type="text/javascript">'."\n"
6812: .'// <![CDATA['."\n"
1.653 raeburn 6813: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 6814: .'// ]]>'."\n"
6815: .'</script>'."\n"
1.369 bisitz 6816: );
1.329 droeschl 6817: } else {
6818: #$postexec='self.close();';
6819: }
1.504 raeburn 6820: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6821: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6822: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6823:
6824: my $newnavform=(<<NNFORM);
6825: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 6826: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6827: $pathitem
1.329 droeschl 6828: <input type="hidden" name="importdetail"
6829: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6830: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6831: $help{'Navigate_Content'}
6832: </form>
6833: NNFORM
6834: my $newsmppageform=(<<NSPFORM);
6835: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 6836: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6837: $pathitem
1.329 droeschl 6838: <input type="hidden" name="importdetail" value="" />
1.423 onken 6839: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6840: $help{'Simple Page'}
1.329 droeschl 6841: </form>
6842: NSPFORM
6843:
6844: my $newsmpproblemform=(<<NSPROBFORM);
6845: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 6846: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6847: $pathitem
1.329 droeschl 6848: <input type="hidden" name="importdetail" value="" />
1.423 onken 6849: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6850: $help{'Simple_Problem'}
1.329 droeschl 6851: </form>
6852:
6853: NSPROBFORM
6854:
6855: my $newdropboxform=(<<NDBFORM);
6856: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 6857: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6858: $pathitem
1.329 droeschl 6859: <input type="hidden" name="importdetail" value="" />
1.423 onken 6860: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6861: $help{'Dropbox'}
1.344 bisitz 6862: </form>
1.329 droeschl 6863: NDBFORM
6864:
6865: my $newexuploadform=(<<NEXUFORM);
6866: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 6867: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6868: $pathitem
1.329 droeschl 6869: <input type="hidden" name="importdetail" value="" />
1.423 onken 6870: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6871: $help{'Score_Upload_Form'}
6872: </form>
6873: NEXUFORM
6874:
6875: my $newbulform=(<<NBFORM);
6876: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 6877: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6878: $pathitem
1.329 droeschl 6879: <input type="hidden" name="importdetail" value="" />
1.423 onken 6880: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6881: $help{'Bulletin Board'}
6882: </form>
6883: NBFORM
6884:
6885: my $newaboutmeform=(<<NAMFORM);
6886: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 6887: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6888: $pathitem
1.329 droeschl 6889: <input type="hidden" name="importdetail"
6890: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6891: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6892: $help{'My Personal Information Page'}
1.329 droeschl 6893: </form>
6894: NAMFORM
6895:
6896: my $newaboutsomeoneform=(<<NASOFORM);
6897: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 6898: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6899: $pathitem
1.329 droeschl 6900: <input type="hidden" name="importdetail" value="" />
1.423 onken 6901: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6902: </form>
6903: NASOFORM
6904:
6905: my $newrosterform=(<<NROSTFORM);
6906: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 6907: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6908: $pathitem
1.329 droeschl 6909: <input type="hidden" name="importdetail"
6910: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6911: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6912: $help{'Course_Roster'}
1.329 droeschl 6913: </form>
6914: NROSTFORM
6915:
1.534 raeburn 6916: my $newwebpage;
6917: if ($folder =~ /^default_?(\d*)$/) {
6918: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6919: if ($1) {
6920: $newwebpage .= $1;
6921: } else {
6922: $newwebpage .= 'default';
6923: }
6924: $newwebpage .= '/new.html';
6925: }
6926: my $newwebpageform =(<<NWEBFORM);
6927: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 6928: <input type="hidden" name="active" value="ff" />
1.534 raeburn 6929: $pathitem
6930: <input type="hidden" name="importdetail" value="$newwebpage" />
6931: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6932: $help{'Web_Page'}
1.534 raeburn 6933: </form>
6934: NWEBFORM
1.701 raeburn 6935: my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606 raeburn 6936: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 6937: my $machines_str = "'".join("','",@ids)."'";
6938: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 6939: if ($env{'user.author'}) {
6940: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 6941: $is_home{'author'} = 1;
1.606 raeburn 6942: }
1.691 raeburn 6943: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 6944: }
6945: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6946: ['active'],['ca','aa']);
1.691 raeburn 6947: my %by_roletype;
1.606 raeburn 6948: if (keys(%roleshash)) {
6949: foreach my $entry (keys(%roleshash)) {
6950: my ($auname,$audom,$roletype) = split(/:/,$entry);
6951: my $key = $entry;
6952: $key =~ s/:/___/g;
1.691 raeburn 6953: my $author = $auname.'___'.$audom;
6954: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 6955: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 6956: $toppath{$author} = "/priv/$audom/$auname";
6957: if (grep(/^\Q$rolehome\E$/,@ids)) {
6958: $is_home{$author} = 1;
1.606 raeburn 6959: }
1.691 raeburn 6960: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
6961: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 6962: }
1.691 raeburn 6963: }
6964: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6965: if (grep(/^\Q$crshome\E$/,@ids)) {
6966: $is_home{'course'} = 1;
6967: }
6968: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
6969: my $pickdir = $lt{'loca'}.
6970: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
6971: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
6972: if ($env{'user.author'}) {
6973: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
6974: }
6975: if (keys(%by_roletype)) {
6976: foreach my $possrole ('ca','aa') {
6977: if (ref($by_roletype{$possrole}) eq 'HASH') {
6978: my $roletitle = &Apache::lonnet::plaintext($possrole);
6979: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6980: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
6981: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
6982: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 6983: }
6984: }
6985: }
6986: }
1.691 raeburn 6987: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n".
6988: '</select><br />'."\n".
6989: $lt{'dire'}.
6990: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
6991: '<option value=""></option>'.
6992: '</select><br />'."\n";
1.606 raeburn 6993:
6994: my %seltemplate_menus;
6995: my @files = &Apache::lonhomework::get_template_list('problem');
6996: my @noexamplelink = ('blank.problem','blank.library','script.library');
6997: my $currentcategory = '';
6998: my @ordered = ('');
6999: my %templatehelp;
7000: my $defcategory = '';
7001: my @catorder = ($defcategory);
7002: $seltemplate_menus{$defcategory}->{'order'} = [''];
7003: $seltemplate_menus{$defcategory}->{'text'} = '';
7004: foreach my $file (@files) {
7005: if (ref($file) eq 'ARRAY') {
7006: my ($path,$title,$category,$help) = @{$file};
7007: next if ($title !~ /\S/);
7008: if (&js_escape($category) ne $currentcategory) {
7009: $currentcategory = &js_escape($category);
7010: push(@catorder,&js_escape($currentcategory));
7011: $seltemplate_menus{$currentcategory}->{'text'} = $category;
7012: $seltemplate_menus{$currentcategory}->{'default'} = '';
7013: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
7014: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
7015: }
7016: if ($path) {
7017: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
7018: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
7019: if ($help) {
7020: $templatehelp{$path} = $help;
7021: }
7022: }
7023: }
7024: }
7025:
7026: my $templates = $lt{'cate'}.' '.
7027: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
7028: $defcategory,'tempcategory','template',
7029: \%seltemplate_menus,\@catorder,
7030: "resize_scrollbox('contentscroll','1','0');",
7031: "toggleExampleText();",'template').'<br />';
7032: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
1.701 raeburn 7033: '<span id="newresexample">'.&mt('Example').'</span></a>';
1.606 raeburn 7034: my $crsresform=(<<RESFORM);
1.691 raeburn 7035: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.606 raeburn 7036: $lt{'stpr'}</a>$help{'Course_Resource'}
7037: <form action="/adm/coursedocs" method="post" name="courseresform">
7038: <fieldset id="crsresform" style="display:none;">
7039: <legend>$lt{'stpr'}</legend>
1.655 raeburn 7040: <input type="hidden" name="active" value="bb" />
1.606 raeburn 7041: <p>
7042: $pickdir
1.701 raeburn 7043: </p>
1.691 raeburn 7044: <div id="newstdproblem" style="display:none;">
1.701 raeburn 7045: <p>
1.606 raeburn 7046: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 7047: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 7048:
1.611 raeburn 7049: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 7050: </span><span id="newsubdir"></span>
7051: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701 raeburn 7052: </p>
1.699 raeburn 7053: </div>
1.606 raeburn 7054: $lt{'fnam'}
1.611 raeburn 7055: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.701 raeburn 7056: <div id="newresource" style="display:none">
1.606 raeburn 7057: <p>
7058: $lt{'addp'}
1.611 raeburn 7059: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 7060: $lt{'no'}</label>
1.611 raeburn 7061: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 7062: $lt{'yes'}</label>
7063: <span id="newrestitle"></span>
1.611 raeburn 7064: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701 raeburn 7065: </p>
1.606 raeburn 7066: </div>
7067: <p>
7068: $lt{'uste'}
1.611 raeburn 7069: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 7070: $lt{'no'}</label>
1.611 raeburn 7071: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 7072: $lt{'yes'}</label>
1.701 raeburn 7073: </p>
1.606 raeburn 7074: <div id="newrestemplate" style="display:none">
7075: $templates
7076: $templatepreview
7077: </div>
7078: <span class="LC_nobreak">
1.701 raeburn 7079: <input type="hidden" name="folderpath" value="$showpath" />
1.611 raeburn 7080: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 7081: </span>
1.691 raeburn 7082: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 7083: $rolehomes
7084: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
7085: </div>
1.606 raeburn 7086: </fieldset>
7087: </form>
7088:
7089: RESFORM
1.534 raeburn 7090:
1.342 ehlerst 7091: my $specialdocumentsform;
1.383 tempelho 7092: my @specialdocumentsforma;
1.451 www 7093: my $gradingform;
7094: my @gradingforma;
7095: my $communityform;
7096: my @communityforma;
1.351 ehlerst 7097: my $newfolderform;
1.390 tempelho 7098: my $newfolderb;
1.342 ehlerst 7099:
1.451 www 7100: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 7101:
1.329 droeschl 7102: my $newpageform=(<<NPFORM);
7103: <form action="/adm/coursedocs" method="post" name="newpage">
7104: <input type="hidden" name="folderpath" value="$path" />
7105: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 7106: <input type="hidden" name="active" value="ee" />
1.423 onken 7107: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 7108: $help{'Adding_Pages'}
1.329 droeschl 7109: </form>
7110: NPFORM
1.390 tempelho 7111:
7112:
1.351 ehlerst 7113: $newfolderform=(<<NFFORM);
1.329 droeschl 7114: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 7115: $pathitem
1.329 droeschl 7116: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 7117: <input type="hidden" name="active" value="" />
1.422 onken 7118: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 7119: </form>
7120: NFFORM
7121:
7122: my $newsylform=(<<NSYLFORM);
7123: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 7124: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7125: $pathitem
1.329 droeschl 7126: <input type="hidden" name="importdetail"
7127: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 7128: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 7129: $help{'Syllabus'}
1.383 tempelho 7130:
1.329 droeschl 7131: </form>
7132: NSYLFORM
1.364 bisitz 7133:
1.329 droeschl 7134: my $newgroupfileform=(<<NGFFORM);
7135: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 7136: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7137: $pathitem
1.329 droeschl 7138: <input type="hidden" name="importdetail"
7139: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 7140: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 7141: $help{'Group Portfolio'}
1.329 droeschl 7142: </form>
7143: NGFFORM
1.672 raeburn 7144: if ($container eq 'page') {
7145: @specialdocumentsforma=(
7146: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
7147: );
7148: } else {
7149: @specialdocumentsforma=(
1.421 onken 7150: {'<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 7151: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 7152: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 7153: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 7154: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 7155: );
7156: }
1.451 www 7157: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
7158:
1.655 raeburn 7159: my @external = (
7160: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 7161: );
1.699 raeburn 7162: if ($posslti) {
1.655 raeburn 7163: push(@external,
7164: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
7165: );
1.598 raeburn 7166: }
1.655 raeburn 7167: my $externalform = &create_form_ul(&create_list_elements(@external));
7168:
7169: my @importdoc = ();
1.519 raeburn 7170: unless ($container eq 'page') {
7171: push(@importdoc,
7172: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
7173: );
7174: }
7175: push(@importdoc,
1.558 raeburn 7176: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 7177: );
1.501 raeburn 7178: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 7179:
1.451 www 7180: @gradingforma=(
7181: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
7182: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
7183: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.691 raeburn 7184: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform},
1.451 www 7185: );
7186: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
7187:
7188: @communityforma=(
7189: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
7190: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
7191: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 7192: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
7193: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 7194: );
7195: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 7196:
1.330 tempelho 7197: my %orderhash = (
1.553 raeburn 7198: 'aa' => ['Upload',$fileuploadform],
7199: 'bb' => ['Import',$importpubform],
1.655 raeburn 7200: 'cc' => ['External',$externalform],
1.701 raeburn 7201: 'dd' => ['Assessment',$gradingform],
1.673 raeburn 7202: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 7203: );
1.519 raeburn 7204: unless ($container eq 'page') {
1.434 raeburn 7205: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 7206: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 7207: }
7208:
1.341 ehlerst 7209: $hadchanges=0;
1.484 raeburn 7210: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 7211: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 7212: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 7213: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 7214: undef($navmap);
1.443 www 7215: if ($error) {
7216: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7217: }
1.639 raeburn 7218: if ($hadchanges) {
7219: unless (&is_hash_old()) {
1.638 raeburn 7220: &mark_hash_old();
7221: }
7222: }
1.341 ehlerst 7223:
1.443 www 7224: &changewarning($r,'');
7225: }
1.458 raeburn 7226: }
1.442 www 7227:
1.443 www 7228: # Supplemental documents start here
7229:
1.329 droeschl 7230: my $folder=$env{'form.folder'};
1.443 www 7231: unless ($supplementalflag) {
1.329 droeschl 7232: $folder='supplemental';
7233: }
1.685 raeburn 7234: if (($folder eq 'supplemental') &&
1.329 droeschl 7235: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 7236: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 7237: } elsif ($allowed) {
1.356 tempelho 7238: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 7239: }
1.508 raeburn 7240: $pathitem = '<input type="hidden" name="folderpath" value="'.
7241: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 7242: if ($allowed) {
7243: my $folderseq=
1.504 raeburn 7244: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 7245:
7246: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 7247: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
7248: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 7249: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 7250: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 7251: <legend>$lt{'upfi'}</legend>
1.630 raeburn 7252: <input type="hidden" name="active" value="ee" />
1.329 droeschl 7253: $fileupload
1.702 raeburn 7254: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
7255: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 7256: <br />
7257: <br />
7258: <span class="LC_nobreak">
7259: $checkbox
7260: </span>
7261: <br /><br />
7262: $lt{'comment'}:<br />
1.383 tempelho 7263: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 7264: <br />
1.508 raeburn 7265: $pathitem
1.329 droeschl 7266: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 7267: <input type='submit' value="$lt{'upld'}" />
1.700 raeburn 7268: </fieldset>
1.501 raeburn 7269: </form>
1.329 droeschl 7270: SUPDOCFORM
7271:
7272: my $supnewfolderform=(<<SNFFORM);
7273: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 7274: <input type="hidden" name="active" value="" />
1.508 raeburn 7275: $pathitem
1.329 droeschl 7276: <input type="hidden" name="importdetail" value="" />
1.423 onken 7277: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 7278: $help{'Adding_Folders'}
1.329 droeschl 7279: </form>
7280: SNFFORM
1.383 tempelho 7281:
1.510 raeburn 7282: my $supextform =
7283: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 7284: $help{'Adding_External_Resource'},
7285: undef,undef,undef,undef,undef,undef,
7286: $disabled);
1.329 droeschl 7287:
1.598 raeburn 7288: my $supexttoolform =
7289: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
7290: $help{'Adding_External_Tool'},
7291: undef,undef,'tool',$coursedom,
1.611 raeburn 7292: $coursenum,\%ltitools,$disabled);
1.598 raeburn 7293:
1.329 droeschl 7294: my $supnewsylform=(<<SNSFORM);
7295: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 7296: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7297: $pathitem
1.329 droeschl 7298: <input type="hidden" name="importdetail"
7299: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 7300: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 7301: $help{'Syllabus'}
7302: </form>
7303: SNSFORM
7304:
7305: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 7306: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 7307: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7308: $pathitem
1.329 droeschl 7309: <input type="hidden" name="importdetail"
7310: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7311: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 7312: $help{'My Personal Information Page'}
1.329 droeschl 7313: </form>
7314: SNAMFORM
7315:
1.534 raeburn 7316: my $supwebpage;
7317: if ($folder =~ /^supplemental_?(\d*)$/) {
7318: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
7319: if ($1) {
7320: $supwebpage .= $1;
7321: } else {
7322: $supwebpage .= 'default';
7323: }
7324: $supwebpage .= '/new.html';
7325: }
7326: my $supwebpageform =(<<SWEBFORM);
7327: <form action="/adm/coursedocs" method="post" name="supwebpage">
7328: <input type="hidden" name="active" value="cc" />
7329: $pathitem
7330: <input type="hidden" name="importdetail" value="$supwebpage" />
7331: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 7332: $help{'Web_Page'}
1.534 raeburn 7333: </form>
7334: SWEBFORM
7335:
1.333 muellerd 7336:
1.383 tempelho 7337: my @specialdocs = (
1.618 raeburn 7338: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 7339: =>$supnewsylform},
1.611 raeburn 7340: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 7341: =>$supnewaboutmeform},
1.534 raeburn 7342: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
7343:
1.383 tempelho 7344: );
1.655 raeburn 7345: my @supexternal = (
7346: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
7347: =>$supextform});
1.699 raeburn 7348: if ($posslti) {
1.655 raeburn 7349: push(@supexternal,
7350: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 7351: =>$supexttoolform});
7352: }
1.655 raeburn 7353: my @supimportdoc = (
1.598 raeburn 7354: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 7355: =>$supupdocform},
1.598 raeburn 7356: );
1.501 raeburn 7357:
7358: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 7359: my %suporderhash = (
1.390 tempelho 7360: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 7361: 'dd' => ['Upload',$supupdocform],
7362: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 7363: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 7364: );
1.443 www 7365: if ($supplementalflag) {
1.682 raeburn 7366: $suppchanges = 0;
7367: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
7368: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
7369: \%ltitools,$canedit,$hostname);
7370: if ($error) {
7371: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7372: }
7373: if ($suppchanges) {
1.684 raeburn 7374: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 7375: undef($suppchanges);
7376: }
1.393 raeburn 7377: }
1.443 www 7378: } elsif ($supplementalflag) {
1.458 raeburn 7379: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 7380: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
7381: $hostname);
1.393 raeburn 7382: if ($error) {
7383: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 7384: }
1.393 raeburn 7385: }
1.389 tempelho 7386:
1.510 raeburn 7387: if ($needs_end) {
7388: $r->print(&endContentScreen());
7389: }
1.383 tempelho 7390:
1.329 droeschl 7391: if ($allowed) {
7392: $r->print('
7393: <form method="post" name="extimport" action="/adm/coursedocs">
7394: <input type="hidden" name="title" />
7395: <input type="hidden" name="url" />
7396: <input type="hidden" name="useform" />
7397: <input type="hidden" name="residx" />
7398: </form>');
7399: }
1.484 raeburn 7400: } elsif ($showdoc) {
1.329 droeschl 7401: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 7402: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 7403: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 7404: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 7405: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 7406: }
7407: }
1.630 raeburn 7408: unless ($noendpage) {
1.606 raeburn 7409: $r->print(&Apache::loncommon::end_page());
7410: }
1.329 droeschl 7411: return OK;
1.364 bisitz 7412: }
1.329 droeschl 7413:
1.440 raeburn 7414: sub embedded_form_elems {
7415: my ($phase,$primaryurl,$newidx) = @_;
7416: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 7417: $newidx =~s /\D+//g;
1.440 raeburn 7418: return <<STATE;
7419: <input type="hidden" name="folderpath" value="$folderpath" />
7420: <input type="hidden" name="cmd" value="upload_embedded" />
7421: <input type="hidden" name="newidx" value="$newidx" />
7422: <input type="hidden" name="phase" value="$phase" />
7423: <input type="hidden" name="primaryurl" value="$primaryurl" />
7424: STATE
7425: }
7426:
7427: sub embedded_destination {
7428: my $folder=$env{'form.folder'};
7429: my $destination = 'docs/';
7430: if ($folder =~ /^supplemental/) {
7431: $destination = 'supplemental/';
7432: }
7433: if (($folder eq 'default') || ($folder eq 'supplemental')) {
7434: $destination .= 'default/';
7435: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
7436: $destination .= $2.'/';
7437: }
1.634 raeburn 7438: my $newidx = $env{'form.newidx'};
7439: $newidx =~s /\D+//g;
7440: if ($newidx) {
7441: $destination .= $newidx;
7442: }
1.440 raeburn 7443: my $dir_root = '/userfiles';
7444: return ($destination,$dir_root);
7445: }
7446:
7447: sub return_to_editor {
7448: my $actionurl = '/adm/coursedocs';
7449: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7450: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7451: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7452: '</a></p>';
7453: }
7454:
1.476 raeburn 7455: sub decompression_info {
7456: my ($destination,$dir_root) = &embedded_destination();
7457: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7458: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7459: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7460: my $container='sequence';
1.480 raeburn 7461: my ($pathitem,$hiddenelem);
1.583 raeburn 7462: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 7463: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 7464: $container='page';
7465: }
1.480 raeburn 7466: unshift(@hiddens,$pathitem);
7467: foreach my $item (@hiddens) {
1.634 raeburn 7468: if ($item eq 'newidx') {
7469: next if ($env{'form.'.$item} =~ /\D/);
7470: }
1.480 raeburn 7471: if ($env{'form.'.$item}) {
7472: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 7473: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 7474: }
1.477 raeburn 7475: }
1.476 raeburn 7476: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7477: $hiddenelem);
7478: }
7479:
7480: sub decompression_phase_one {
7481: my ($dir,$file,$warning,$error,$output);
7482: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7483: &decompression_info();
1.490 raeburn 7484: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 7485: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7486: } else {
7487: my $file = $1;
1.630 raeburn 7488: $output =
1.481 raeburn 7489: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7490: $destination,$dir_root,
7491: $hiddenelem);
7492: if ($env{'form.autoextract_camtasia'}) {
7493: $output .= &remove_archive($docudom,$docuname,$container);
7494: }
1.476 raeburn 7495: }
7496: if ($error) {
7497: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7498: $error.'</p>'."\n";
7499: }
7500: if ($warning) {
7501: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7502: }
7503: return $output;
7504: }
7505:
7506: sub decompression_phase_two {
7507: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7508: &decompression_info();
1.481 raeburn 7509: my $output;
1.480 raeburn 7510: if ($env{'form.archivedelete'}) {
1.481 raeburn 7511: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 7512: }
7513: $output .=
1.481 raeburn 7514: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 7515: $destination,$dir_root,$hiddenelem);
7516: return $output;
7517: }
7518:
1.480 raeburn 7519: sub remove_archive {
7520: my ($docudom,$docuname,$container) = @_;
7521: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 7522: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 7523: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7524: if ($fatal) {
7525: if ($container eq 'page') {
7526: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7527: } else {
7528: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7529: }
1.583 raeburn 7530: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7531: } else {
7532: my $currcmd = $env{'form.cmd'};
7533: my $position = $env{'form.position'};
1.583 raeburn 7534: my $archiveidx = $position;
1.563 raeburn 7535: if ($position > 0) {
1.583 raeburn 7536: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7537: $archiveidx = $position-1;
7538: }
7539: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 7540: my ($title,$url,@rrest) =
1.583 raeburn 7541: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7542: if ($url eq $env{'form.archiveurl'}) {
7543: if (&handle_edit_cmd($docuname,$docudom)) {
7544: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 7545: if ($suppchanges) {
7546: &Apache::lonnet::update_supp_caches($docudom,$docuname);
7547: undef($suppchanges);
7548: }
1.583 raeburn 7549: if ($fatal) {
7550: if ($container eq 'page') {
7551: $delwarning = &mt('An error occurred updating the contents of the current page.');
7552: } else {
7553: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7554: }
1.480 raeburn 7555: } else {
1.583 raeburn 7556: $delresult = &mt('Archive file removed.');
1.480 raeburn 7557: }
7558: }
1.583 raeburn 7559: } else {
7560: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7561: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7562: }
7563: }
7564: $env{'form.cmd'} = $currcmd;
7565: }
7566: if ($delwarning) {
7567: $output = '<p class="LC_warning">'.
7568: $delwarning.
7569: '</p>';
7570: }
7571: if ($delresult) {
7572: $output .= '<p class="LC_info">'.
7573: $delresult.
7574: '</p>';
7575: }
1.481 raeburn 7576: return $output;
1.480 raeburn 7577: }
7578:
1.484 raeburn 7579: sub generate_admin_menu {
1.611 raeburn 7580: my ($crstype,$canedit) = @_;
1.484 raeburn 7581: my $lc_crstype = lc($crstype);
7582: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 7583: my %lt= ( # do not translate here
1.484 raeburn 7584: 'vc' => 'Verify Content',
7585: 'cv' => 'Check/Set Resource Versions',
7586: 'ls' => 'List Resource Identifiers',
1.651 raeburn 7587: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 7588: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 7589: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 7590: );
1.484 raeburn 7591: my ($candump,$dumpurl);
7592: if ($home + $other > 0) {
7593: $candump = 'F';
7594: if ($home) {
7595: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7596: } else {
7597: my @hosts;
7598: foreach my $aurole (keys(%outhash)) {
7599: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7600: push(@hosts,$outhash{$aurole});
1.538 raeburn 7601: }
1.484 raeburn 7602: }
7603: if (@hosts == 1) {
7604: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7605: '&role='.
7606: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7607: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7608: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7609: } else {
7610: $dumpurl = "javascript:choose_switchserver_window()";
7611: }
7612: }
7613: }
7614: my @menu=
7615: ({ categorytitle=>'Administration',
7616: items =>[
7617: { linktext => $lt{'vc'},
7618: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7619: permission => 'F',
1.571 raeburn 7620: help => 'Docs_Verify_Content',
1.484 raeburn 7621: icon => 'verify.png',
7622: linktitle => 'Verify contents can be retrieved/rendered',
7623: },
7624: { linktext => $lt{'cv'},
7625: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7626: permission => 'F',
1.571 raeburn 7627: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7628: icon => 'resversion.png',
7629: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7630: },
7631: { linktext => $lt{'ls'},
7632: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7633: permission => 'F',
7634: #help => '',
7635: icon => 'symbs.png',
7636: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7637: },
1.651 raeburn 7638: { linktext => $lt{'ct'},
7639: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7640: permission => 'F',
7641: help => 'Docs_Short_URLs',
7642: icon => 'shorturls.png',
7643: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7644: },
1.484 raeburn 7645: ]
1.611 raeburn 7646: });
7647: if ($canedit) {
7648: push(@menu,
1.484 raeburn 7649: { categorytitle=>'Export',
7650: items =>[
7651: { linktext => $lt{'imse'},
7652: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7653: permission => 'F',
7654: help => 'Docs_Export_Course_Docs',
7655: icon => 'imsexport.png',
7656: linktitle => $lt{'imse'},
7657: },
7658: { linktext => $lt{'dcd'},
7659: url => $dumpurl,
7660: permission => $candump,
1.571 raeburn 7661: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7662: icon => 'dump.png',
7663: linktitle => $lt{'dcd'},
7664: },
7665: ]
7666: });
1.611 raeburn 7667: }
1.484 raeburn 7668: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7669: '<input type="hidden" id="dummy" />'."\n".
7670: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7671: '</form>';
1.329 droeschl 7672: }
7673:
7674: sub generate_edit_table {
1.538 raeburn 7675: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 7676: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7677: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7678: my %orderhash = %{$orderhash_ref};
1.611 raeburn 7679: my ($form, $activetab, $active, $disabled);
1.570 raeburn 7680: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7681: $activetab = $env{'form.active'};
7682: }
1.611 raeburn 7683: unless ($canedit) {
7684: $disabled = ' disabled="disabled"';
7685: }
1.472 raeburn 7686: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 7687: my $backtext = &mt('Exit Editor');
1.458 raeburn 7688: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 7689: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7690: '<li class="goback">'.
1.546 raeburn 7691: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 7692: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7693: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7694: '<li>'.
7695: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7696: &mt('Undo Delete').'</a></li>'."\n";
7697: if ($env{'form.docslog'}) {
7698: $form .= '<li class="active">';
7699: } else {
7700: $form .= '<li>';
7701: }
7702: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7703: &mt('History').'</a></li>'."\n";
7704: if ($env{'form.docslog'}) {
7705: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7706: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7707: }
1.458 raeburn 7708: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7709: if($name ne '00'){
1.371 tempelho 7710: if($activetab eq '' || $activetab ne $name){
7711: $active = '';
7712: }elsif($activetab eq $name){
7713: $active = 'class="active"';
7714: }
1.458 raeburn 7715: $form .= '<li style="float:right" '.$active
1.484 raeburn 7716: .' 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 7717: } else {
1.570 raeburn 7718: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7719:
7720: }
1.329 droeschl 7721: }
1.484 raeburn 7722: $form .= '</ul>'."\n";
7723: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7724:
7725: if ($to_show ne '') {
1.538 raeburn 7726: my $saveform;
7727: if ($need_save) {
7728: my $button = &mt('Make changes');
7729: my $path;
7730: if ($env{'form.folderpath'}) {
7731: $path =
7732: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7733: }
7734: $saveform = <<"END";
7735: <div id="multisave" style="display:none; clear:both;" >
7736: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7737: <input type="hidden" name="folderpath" value="$path" />
7738: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7739: <input type="hidden" name="allhiddenresource" value="" />
7740: <input type="hidden" name="allencrypturl" value="" />
7741: <input type="hidden" name="allrandompick" value="" />
7742: <input type="hidden" name="allrandomorder" value="" />
7743: <input type="hidden" name="changeparms" value="" />
7744: <input type="hidden" name="multiremove" value="" />
7745: <input type="hidden" name="multicut" value="" />
7746: <input type="hidden" name="multicopy" value="" />
7747: <input type="hidden" name="multichange" value="" />
7748: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7749: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7750: </form>
7751: </div>
7752: END
7753: }
7754: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7755: }
1.363 ehlerst 7756: foreach my $field (keys(%orderhash)){
1.390 tempelho 7757: if($field ne '00'){
1.422 onken 7758: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7759: $active = 'style="display: none;float:left"';
1.422 onken 7760: }elsif($activetab eq $field){
1.458 raeburn 7761: $active = 'style="display:block;float:left"';
1.422 onken 7762: }
7763: $form .= '<div id="'.$field.$tid.'"'
7764: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7765: .'</div>'."\n";
1.363 ehlerst 7766: }
7767: }
1.484 raeburn 7768: unless ($env{'form.docslog'}) {
7769: $form .= '</div></div>'."\n";
7770: }
1.329 droeschl 7771: return $form;
7772: }
7773:
7774: sub editing_js {
1.622 raeburn 7775: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7776: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7777: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7778: p_mnf => 'Name of New Folder',
7779: t_mnf => 'New Folder',
7780: p_mnp => 'Name of New Page',
7781: t_mnp => 'New Page',
1.451 www 7782: p_mxu => 'Title for the External Score',
1.349 biermanm 7783: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7784: p_msb => 'Title for the Problem',
7785: p_mdb => 'Title for the Drop Box',
1.336 schafran 7786: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7787: p_mwp => 'Title for Web Page',
1.606 raeburn 7788: p_mnr => 'Title for the Resource',
1.348 weissno 7789: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7790: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7791: p_mab_alrt1 => 'Not a valid user:domain',
7792: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7793: p_chn => 'New Title',
7794: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7795: p_rmr2a => 'Remove',
7796: p_rmr2b => '?',
7797: p_rmr3a => 'Remove those',
7798: p_rmr3b => 'items?',
7799: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7800: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7801: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7802: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7803: p_ctr2a => 'Cut',
7804: p_ctr2b => '?',
7805: p_ctr3a => 'Cut those',
7806: p_ctr3b => 'items?',
1.633 raeburn 7807: setal => 'Enter a (unique) alias',
7808: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7809: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7810: imsfile => 'You must choose an IMS package for import',
7811: imscms => 'You must select which Course Management System was the source of the IMS package',
7812: invurl => 'Invalid URL',
7813: titbl => 'Title is blank',
1.538 raeburn 7814: more => '(More ...)',
7815: less => '(Less ...)',
1.543 raeburn 7816: noor => 'No actions selected or changes to settings specified.',
7817: noch => 'No changes to settings specified.',
7818: noac => 'No actions selected.',
1.606 raeburn 7819: nofi => 'No file selected',
7820: tinc => 'Title in course',
7821: sunm => 'Sub-directory name',
1.618 raeburn 7822: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 7823: sele => 'Select',
7824: swit => 'Switch server required',
1.329 droeschl 7825: );
1.594 damieng 7826: &js_escape(\%js_lt);
1.433 raeburn 7827: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7828: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7829: my $main_container_page;
1.519 raeburn 7830: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7831: $main_container_page = 1;
1.434 raeburn 7832: }
1.617 raeburn 7833: my $backtourl;
7834: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7835: my $toplevelsupp = &supplemental_base();
1.690 raeburn 7836: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 7837: my @ids=&Apache::lonnet::current_machine_ids();
7838: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 7839: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7840: my $caller = $1;
1.525 raeburn 7841: if ($caller =~ /^supplemental/) {
7842: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7843: } else {
7844: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7845: $res = &Apache::lonnet::clutter($res);
7846: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7847: my ($url,$anchor);
7848: if ($res =~ /^([^#]+)#([^#]+)$/) {
7849: $url = $1;
7850: $anchor = $2;
7851: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7852: $caller = $1.&escape('#').$anchor;
7853: }
1.614 raeburn 7854: } else {
7855: $url = $res;
1.609 raeburn 7856: }
1.640 raeburn 7857: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7858: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7859: $backtourl .= '?navmap=1';
7860: } else {
7861: $backtourl .= '?symb='.
7862: &HTML::Entities::encode($caller,'<>&"');
7863: }
1.622 raeburn 7864: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7865: if (($ENV{'SERVER_PORT'} == 443) &&
7866: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 7867: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 7868: if ($hostname ne '') {
7869: $backtourl = 'http://'.$hostname.$backtourl;
7870: }
7871: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7872: }
7873: }
1.623 raeburn 7874: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7875: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 7876: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 7877: if ($hostname ne '') {
7878: $backtourl = 'http://'.$hostname.$backtourl;
7879: }
7880: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 7881: }
1.623 raeburn 7882: }
1.622 raeburn 7883: }
1.609 raeburn 7884: if ($anchor ne '') {
7885: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7886: }
1.590 raeburn 7887: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7888: } else {
7889: $backtourl = '/adm/navmaps';
1.525 raeburn 7890: }
7891: }
7892: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7893: $backtourl = '/adm/menu';
7894: } elsif ($supplementalflag) {
1.682 raeburn 7895: if (($env{'request.role.adv'}) ||
7896: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7897: $backtourl = '/adm/supplemental';
7898: } else {
7899: $backtourl = '/adm/navmaps';
7900: }
1.525 raeburn 7901: } else {
7902: $backtourl = '/adm/navmaps';
1.472 raeburn 7903: }
7904:
1.655 raeburn 7905: my $fieldsets = "'doc'";
1.519 raeburn 7906: unless ($main_container_page) {
7907: $fieldsets .=",'ims'";
7908: }
1.655 raeburn 7909: my $extfieldsets = "'ext'";
7910: if ($posslti) {
7911: $extfieldsets .= ",'tool'";
7912: }
1.501 raeburn 7913: if ($supplementalflag) {
1.655 raeburn 7914: $fieldsets = "'suppdoc'";
7915: $extfieldsets = "'suppext'";
1.600 raeburn 7916: if ($posslti) {
1.655 raeburn 7917: $extfieldsets .= ",'supptool'";
1.600 raeburn 7918: }
1.501 raeburn 7919: }
1.655 raeburn 7920:
1.611 raeburn 7921: my $jsmakefunctions;
7922: if ($canedit) {
7923: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7924: function makenewfolder(targetform,folderseq) {
1.594 damieng 7925: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7926: if (foldername) {
1.676 raeburn 7927: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 7928: targetform.submit();
7929: }
7930: }
7931:
7932: function makenewpage(targetform,folderseq) {
1.594 damieng 7933: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7934: if (pagename) {
1.676 raeburn 7935: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 7936: targetform.submit();
7937: }
7938: }
7939:
7940: function makeexamupload() {
1.594 damieng 7941: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7942: if (title) {
1.329 droeschl 7943: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 7944: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 7945: this.document.forms.newexamupload.submit();
7946: }
7947: }
7948:
7949: function makesmppage() {
1.594 damieng 7950: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7951: if (title) {
1.329 droeschl 7952: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 7953: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7954: this.document.forms.newsmppg.submit();
7955: }
7956: }
7957:
1.534 raeburn 7958: function makewebpage(type) {
1.594 damieng 7959: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7960: var formname;
7961: if (type == 'supp') {
7962: formname = this.document.forms.supwebpage;
7963: } else {
7964: formname = this.document.forms.newwebpage;
7965: }
7966: if (title) {
7967: var webpage = formname.importdetail.value;
1.675 raeburn 7968: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 7969: formname.submit();
7970: }
7971: }
7972:
1.329 droeschl 7973: function makesmpproblem() {
1.594 damieng 7974: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7975: if (title) {
1.329 droeschl 7976: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 7977: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 7978: this.document.forms.newsmpproblem.submit();
7979: }
7980: }
7981:
7982: function makedropbox() {
1.594 damieng 7983: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7984: if (title) {
1.329 droeschl 7985: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 7986: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 7987: this.document.forms.newdropbox.submit();
7988: }
7989: }
7990:
7991: function makebulboard() {
1.594 damieng 7992: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7993: if (title) {
7994: this.document.forms.newbul.importdetail.value=
1.676 raeburn 7995: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7996: this.document.forms.newbul.submit();
7997: }
7998: }
7999:
8000: function makeabout() {
1.594 damieng 8001: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 8002: if (user) {
8003: var comp=new Array();
8004: comp=user.split(':');
8005: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
8006: if ((comp[0]) && (comp[1])) {
8007: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 8008: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 8009: this.document.forms.newaboutsomeone.submit();
8010: } else {
8011: alert("$js_lt{'p_mab_alrt1'}");
8012: }
8013: } else {
8014: alert("$js_lt{'p_mab_alrt2'}");
8015: }
8016: }
8017: }
8018:
8019: function makenew(targetform) {
8020: targetform.submit();
8021: }
8022:
8023: function changename(folderpath,index,oldtitle) {
8024: var title=prompt('$js_lt{"p_chn"}',oldtitle);
8025: if (title) {
8026: this.document.forms.renameform.markcopy.value='';
8027: this.document.forms.renameform.title.value=title;
8028: this.document.forms.renameform.cmd.value='rename_'+index;
8029: this.document.forms.renameform.folderpath.value=folderpath;
8030: this.document.forms.renameform.submit();
8031: }
8032: }
8033:
1.633 raeburn 8034: function setalias(folderpath,index) {
8035: var alias = prompt('$js_lt{"setal"}');
8036: if ((alias != null) && (alias != '')) {
8037: this.document.forms.aliasform.alias.value=alias;
8038: this.document.forms.aliasform.cmd.value='setalias_'+index;
8039: this.document.forms.aliasform.folderpath.value=folderpath;
8040: this.document.forms.aliasform.submit();
8041: }
8042: }
8043:
8044: function delalias(folderpath,index) {
8045: if (confirm('$js_lt{"delal"}')) {
8046: this.document.forms.aliasform.cmd.value='delalias_'+index;
8047: this.document.forms.aliasform.folderpath.value=folderpath;
8048: this.document.forms.aliasform.submit();
8049: }
8050: }
8051:
1.611 raeburn 8052: ENDNEWSCRIPT
8053: } else {
8054: $jsmakefunctions = <<ENDNEWSCRIPT;
8055:
8056: function makenewfolder() {
8057: alert("$js_lt{'edri'}");
8058: }
8059:
8060: function makenewpage() {
8061: alert("$js_lt{'edri'}");
8062: }
8063:
8064: function makeexamupload() {
8065: alert("$js_lt{'edri'}");
8066: }
8067:
8068: function makesmppage() {
8069: alert("$js_lt{'edri'}");
8070: }
8071:
8072: function makewebpage(type) {
8073: alert("$js_lt{'edri'}");
8074: }
8075:
8076: function makesmpproblem() {
8077: alert("$js_lt{'edri'}");
8078: }
8079:
8080: function makedropbox() {
8081: alert("$js_lt{'edri'}");
8082: }
8083:
8084: function makebulboard() {
8085: alert("$js_lt{'edri'}");
8086: }
8087:
8088: function makeabout() {
8089: alert("$js_lt{'edri'}");
8090: }
8091:
8092: function changename() {
8093: alert("$js_lt{'edri'}");
8094: }
8095:
1.633 raeburn 8096: function setalias() {
8097: alert("$js_lt{'edri'}");
8098: }
8099:
8100: function delalias() {
8101: alert("$js_lt{'edri'}");
8102: }
8103:
1.611 raeburn 8104: function makenew() {
8105: alert("$js_lt{'edri'}");
8106: }
8107:
8108: function groupimport() {
8109: alert("$js_lt{'edri'}");
1.335 ehlerst 8110: }
1.611 raeburn 8111:
8112: function groupsearch() {
8113: alert("$js_lt{'edri'}");
1.335 ehlerst 8114: }
1.611 raeburn 8115:
8116: function groupopen(url,recover) {
8117: var options="scrollbars=1,resizable=1,menubar=0";
8118: idxflag=1;
8119: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
8120: idx.focus();
1.329 droeschl 8121: }
8122:
1.611 raeburn 8123: ENDNEWSCRIPT
8124:
8125: }
8126: return <<ENDSCRIPT;
8127:
8128: $jsmakefunctions
8129:
1.501 raeburn 8130: function toggleUpload(caller) {
8131: var blocks = Array($fieldsets);
8132: for (var i=0; i<blocks.length; i++) {
8133: var disp = 'none';
8134: if (caller == blocks[i]) {
8135: var curr = document.getElementById('upload'+caller+'form').style.display;
8136: if (curr == 'none') {
8137: disp='block';
8138: }
8139: }
8140: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 8141: }
8142: resize_scrollbox('contentscroll','1','1');
8143: return;
8144: }
8145:
8146: function toggleExternal(caller) {
8147: var blocks = Array($extfieldsets);
8148: for (var i=0; i<blocks.length; i++) {
8149: var disp = 'none';
8150: if (caller == blocks[i]) {
8151: var curr = document.getElementById('external'+caller+'form').style.display;
8152: if (curr == 'none') {
8153: disp='block';
8154: }
8155: }
8156: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 8157: if ((caller == 'tool') || (caller == 'supptool')) {
8158: if (disp == 'block') {
1.655 raeburn 8159: if (document.getElementById('LC_exttoolid')) {
8160: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 8161: var suppflag = 0;
8162: if (caller == 'supptool') {
8163: suppflag = 1;
8164: }
8165: currForm = document.getElementById('new'+caller);
1.655 raeburn 8166: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 8167: }
8168: }
8169: }
1.501 raeburn 8170: }
1.502 raeburn 8171: resize_scrollbox('contentscroll','1','1');
8172: return;
8173: }
8174:
1.514 raeburn 8175: function toggleMap(caller) {
1.502 raeburn 8176: var disp = 'none';
1.510 raeburn 8177: if (document.getElementById('importmapform')) {
1.514 raeburn 8178: if (caller == 'map') {
8179: var curr = document.getElementById('importmapform').style.display;
8180: if (curr == 'none') {
8181: disp='block';
8182: }
1.510 raeburn 8183: }
8184: document.getElementById('importmapform').style.display=disp;
8185: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 8186: }
1.501 raeburn 8187: return;
1.329 droeschl 8188: }
8189:
1.691 raeburn 8190: function toggleCrsRes(caller) {
1.606 raeburn 8191: var disp = 'none';
8192: if (document.getElementById('crsresform')) {
8193: if (caller == 'res') {
1.691 raeburn 8194: var form = document.getElementById('crsresform');
8195: var curr = form.style.display;
1.606 raeburn 8196: if (curr == 'none') {
8197: disp='block';
1.691 raeburn 8198: document.courseresform.authorrole.selectedIndex = 0;
8199: document.courseresform.authorpath.selectedIndex = 0;
8200: document.courseresform.newresourceadd.selectedIndex = 0;
8201: populateDirSelects(form,'authorrole','authorpath',1,0,0);
8202: toggleNewInCourse(document.courseresform);
8203: if (document.getElementById('newresource')) {
8204: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 8205: }
8206: if (document.courseresform.newresusetemp.length) {
8207: document.courseresform.newresusetemp[0].checked = true;
8208: toggleWithTemplate(document.courseresform);
8209: }
8210: document.courseresform.newresourcename.value = '';
8211: }
8212: }
8213: if (document.courseresform.newsubdir.length) {
8214: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
8215: if (document.courseresform.newsubdir[j].value == 0) {
8216: document.courseresform.newsubdir[j].checked = true;
8217: }
8218: break;
8219: }
8220: if (document.getElementById('newsubdirname')) {
8221: document.getElementById('newsubdirname').type = "hidden";
8222: document.getElementById('newsubdirname').value = "";
8223: }
8224: if (document.getElementById('newsubdir')) {
8225: document.getElementById('newsubdir').innerHTML = "";
8226: }
8227: }
8228: document.getElementById('crsresform').style.display=disp;
8229: resize_scrollbox('contentscroll','1','0');
8230: }
8231: return;
8232: }
8233:
8234: function toggleNewsubdir(form) {
8235: if (form.newsubdir.length) {
8236: for (var j=0; j<form.newsubdir.length; j++) {
8237: if (form.newsubdir[j].checked) {
8238: if (document.getElementById('newsubdirname')) {
8239: if (form.newsubdir[j].value == '1') {
8240: document.getElementById('newsubdirname').type = "text";
8241: if (document.getElementById('newsubdir')) {
8242: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
8243: }
8244: } else {
8245: document.getElementById('newsubdirname').type = "hidden";
8246: document.getElementById('newsubdirname').value = "";
8247: document.getElementById('newsubdir').innerHTML = "";
8248: }
8249: }
8250: break;
8251: }
8252: }
8253: }
8254: }
8255:
8256: function toggleCrsResTitle() {
8257: if (document.getElementById('newresource')) {
1.691 raeburn 8258: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8259: if (selloc == 'course') {
1.606 raeburn 8260: document.getElementById('newresource').style.display = 'inline';
8261: document.courseresform.newresourceadd[0].checked = true;
8262: toggleNewInCourse(document.courseresform);
8263: } else {
8264: document.getElementById('newresource').style.display = 'none';
8265: }
1.689 raeburn 8266: }
8267: if (document.getElementById('newstdproblem')) {
8268: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8269: document.getElementById('newstdproblem').style.display = 'none';
8270: if (document.getElementById('stdprobswitch')) {
8271: document.getElementById('stdprobswitch').style.display = 'block';
8272: }
8273: } else {
8274: document.getElementById('newstdproblem').style.display = 'block';
8275: if (document.getElementById('stdprobswitch')) {
8276: document.getElementById('stdprobswitch').style.display = 'none';
8277: }
8278: }
8279: }
1.606 raeburn 8280: }
8281:
8282: function toggleNewInCourse(form) {
8283: if (form.newresourceadd.length) {
8284: for (var i=0; i<form.newresourceadd.length; i++) {
8285: if (form.newresourceadd[i].checked) {
8286: if (document.getElementById('newresourcetitle')) {
8287: if (form.newresourceadd[i].value == '1') {
8288: document.getElementById('newresourcetitle').type = 'text';
8289: if (document.getElementById('newrestitle')) {
8290: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
8291: }
8292: } else {
8293: document.getElementById('newresourcetitle').type = 'hidden';
8294: document.getElementById('newresourcetitle').value = '';
8295: if (document.getElementById('newrestitle')) {
8296: document.getElementById('newrestitle').innerHTML = '';
8297: }
8298: }
8299: }
8300: break;
8301: }
8302: }
8303: }
8304: }
8305:
8306: function toggleWithTemplate(form) {
8307: if (form.newresusetemp.length) {
8308: for (var i=0; i<form.newresusetemp.length; i++) {
8309: if (form.newresusetemp[i].checked) {
8310: if (document.getElementById('newrestemplate')) {
8311: if (form.newresusetemp[i].value == '1') {
8312: document.getElementById('newrestemplate').style.display = 'inline';
8313: toggleExampleText();
8314: } else {
8315: form.tempcategory.selectedIndex = 0;
8316: select1template_changed();
8317: document.getElementById('newrestemplate').style.display = 'none';
8318: }
8319: }
8320: }
8321: }
8322: }
8323: }
8324:
8325: function toggleExampleText() {
8326: if (document.getElementById('newresexample')) {
8327: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
8328: if (url == '') {
8329: document.getElementById('newresexample').style.fontWeight = 'normal';
8330: } else {
8331: document.getElementById('newresexample').style.fontWeight = 'bold';
8332: }
8333: }
8334: }
8335:
8336: function getExample(width,height,scrolling,transparency) {
8337: var url;
8338: if (document.courseresform.newresusetemp.length) {
8339: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
8340: if (document.courseresform.newresusetemp[i].checked) {
8341: if (document.courseresform.newresusetemp[i].value == '1') {
8342: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
8343: if (url == '') {
8344: alert('Pick a category and template');
8345: } else {
8346: url = url.replace("$londocroot","");
8347: url += '?inhibitmenu=yes';
8348: }
8349: }
8350: break;
8351: }
8352: }
8353: }
8354: if (url != '') {
8355: openMyModal(url,width,height,scrolling,transparency,'');
8356: }
8357: }
8358:
1.690 raeburn 8359: function toggleImportCrsres(caller) {
1.606 raeburn 8360: var disp = 'none';
8361: if (document.getElementById('importcrsresform')) {
8362: if (caller == 'res') {
8363: var curr = document.getElementById('importcrsresform').style.display;
8364: if (curr == 'none') {
8365: disp='block';
1.698 raeburn 8366: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
8367: if ((document.getElementById('importcrsrescontent')) &&
8368: (document.getElementById('importcrsresempty'))) {
8369: var selelem = document.crsresimportform.elements['coursepath'];
8370: var numdirs = 0;
8371: if (selelem.options.length) {
8372: numdirs = selelem.options.length - 1;
8373: }
8374: if (numdirs) {
8375: document.getElementById('importcrsrescontent').style.display='block';
8376: document.getElementById('importcrsresempty').style.display='none';
8377: } else {
8378: document.getElementById('importcrsrescontent').style.display='none';
8379: document.getElementById('importcrsresempty').style.display='block';
8380: }
8381: }
1.606 raeburn 8382: }
8383: }
8384: document.getElementById('importcrsresform').style.display=disp;
8385: resize_scrollbox('contentscroll','1','0');
8386: }
8387: return;
8388: }
8389:
1.690 raeburn 8390: $showfile_js
8391:
1.691 raeburn 8392: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
8393: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
8394: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
8395: var selelem = form.elements[dirsel];
8396: var i, numfiles = selelem.options.length -1;
8397: if (numfiles >=0) {
8398: for (i = numfiles; i >= 0; i--) {
8399: selelem.remove(i);
8400: }
8401: }
8402: if ((location == '') || (location == null) || (location == 'undefined')) {
8403: if (selelem.options.length == 0) {
8404: selelem.options[selelem.options.length] = new Option('','');
8405: selelem.selectedIndex = 0;
8406: }
8407: if (document.getElementById('newstdproblem')) {
8408: document.getElementById('newstdproblem').style.display = 'none';
8409: }
8410: return;
8411: }
8412: var machineIds = new Array($machines_str);
8413: var athome = 0;
8414: var role = location;
8415: if ((location == 'author') || (location == 'course')) {
8416: if (document.getElementById('rolehome_'+location)) {
8417: var currhome = document.getElementById('rolehome_'+location).value;
8418: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8419: if (machineIds.includes(currhome)) {
8420: athome = 1;
8421: }
8422: }
8423: }
8424: } else {
8425: const roleinfo = location.split('___');
8426: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
8427: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
8428: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
8429: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8430: if (machineIds.includes(currhome)) {
8431: athome = 1;
8432: }
8433: }
8434: }
8435: }
8436: if (athome) {
8437: if (document.getElementById('stdprobswitch')) {
8438: document.getElementById('stdprobswitch').style.display = 'none';
8439: }
8440: if (document.getElementById('newstdproblem')) {
8441: document.getElementById('newstdproblem').style.display = 'none';
8442: }
8443: var http = new XMLHttpRequest();
8444: var url = "/adm/courseauthor";
1.698 raeburn 8445: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 8446: http.open("POST", url, true);
8447: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
8448: http.onreadystatechange = function() {
8449: if (http.readyState == 4 && http.status == 200) {
8450: var data = JSON.parse(http.responseText);
8451: if (Array.isArray(data.dirs)) {
8452: var len = data.dirs.length;
8453: if (len) {
8454: if (len > 1) {
8455: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
8456: }
8457: }
8458: if (len) {
8459: var j;
8460: for (j = 0; j < len; j++) {
8461: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
8462: }
8463: selelem.selectedIndex = 0;
1.697 raeburn 8464: if (len == 1) {
8465: toggleCrsResTitle();
8466: }
1.691 raeburn 8467: }
8468: }
8469: }
8470: }
8471: http.send(params);
8472: } else {
8473: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
8474: selelem.selectedIndex = 0;
8475: if (document.getElementById('stdprobswitch')) {
8476: document.getElementById('stdprobswitch').style.display = 'block';
8477: }
8478: if (document.getElementById('newstdproblem')) {
8479: document.getElementById('newstdproblem').style.display = 'none';
8480: }
8481: }
8482: }
8483: return;
8484: }
8485:
1.689 raeburn 8486: function switchForProb() {
8487: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8488: var url = '/adm/switchserver?otherserver=';
8489: var newhostid = '';
8490: var role = '';
8491: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8492: if (selloc == 'author') {
8493: newhostid = document.courseresform.rolehome_author.value;
8494: role = "au./&js_escape($env{'user.domain'})/";
8495: } else if (selloc == 'course') {
8496: newhostid = document.courseresform.rolehome_course.value;
8497: role = "&js_escape($env{'request.role'})";
8498: } else {
8499: var items = new Array();
8500: items = selloc.split('___');
8501: var len = document.courseresform.rolehome_coauthor.length;
8502: if (null == len) {
8503: var currval = document.courseresform.rolehome_coauthor.value;
8504: if (null != currval) {
8505: var info = new Array();
8506: info = currval.split('=');
8507: newhostid = info[2];
8508: role = info[0]+'./'+info[1];
8509: }
8510: } else {
8511: for (var i=0; i<len; i++) {
8512: var currval = document.courseresform.rolehome_coauthor[i].value;
8513: if (null != currval) {
8514: var info = new Array();
8515: info = currval.split('=');
8516: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
8517: newhostid = info[2];
8518: role = info[0]+'./'+info[1];
8519: break;
8520: }
8521: }
8522: }
8523: }
8524: }
8525: if (newhostid != '') {
8526: url += newhostid;
8527: if (role != '') {
8528: url += '&role='+role;
8529: }
8530: document.location.href = url;
8531: }
8532: }
8533: return;
8534: }
8535:
1.501 raeburn 8536: function makeims(imsform) {
8537: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 8538: alert("$js_lt{'imsfile'}");
1.501 raeburn 8539: return;
8540: }
8541: if (imsform.source.selectedIndex == 0) {
1.594 damieng 8542: alert("$js_lt{'imscms'}");
1.501 raeburn 8543: return;
8544: }
8545: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
8546: imsform.submit();
8547: }
8548:
1.478 raeburn 8549: function updatePick(targetform,index,caller) {
1.537 raeburn 8550: var pickitem;
8551: var picknumitem;
8552: var picknumtext;
8553: if (index == 'all') {
8554: pickitem = document.getElementById('randompickall');
8555: picknumitem = document.getElementById('rpicknumall');
8556: picknumtext = document.getElementById('rpicktextall');
8557: } else {
8558: pickitem = document.getElementById('randompick_'+index);
8559: picknumitem = document.getElementById('rpicknum_'+index);
8560: picknumtext = document.getElementById('randompicknum_'+index);
8561: }
1.478 raeburn 8562: if (pickitem.checked) {
1.594 damieng 8563: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 8564: if (picknum == '' || picknum == null) {
8565: if (caller == 'check') {
8566: pickitem.checked=false;
1.537 raeburn 8567: if (index == 'all') {
8568: picknumtext.innerHTML = '';
8569: if (caller == 'link') {
8570: propagateState(targetform,'rpicknum');
8571: }
8572: } else {
1.538 raeburn 8573: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8574: }
1.478 raeburn 8575: }
8576: } else {
8577: picknum.toString();
8578: var regexdigit=/^\\d+\$/;
8579: if (regexdigit.test(picknum)) {
8580: picknumitem.value = picknum;
1.537 raeburn 8581: if (index == 'all') {
1.538 raeburn 8582: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 8583: if (caller == 'link') {
8584: propagateState(targetform,'rpicknum');
8585: }
8586: } else {
8587: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 8588: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8589: }
1.478 raeburn 8590: } else {
8591: if (caller == 'check') {
1.537 raeburn 8592: if (index == 'all') {
8593: picknumtext.innerHTML = '';
8594: if (caller == 'link') {
8595: propagateState(targetform,'rpicknum');
8596: }
8597: } else {
8598: pickitem.checked=false;
1.538 raeburn 8599: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8600: }
1.478 raeburn 8601: }
8602: return;
8603: }
8604: }
8605: } else {
1.537 raeburn 8606: picknumitem.value = '';
8607: picknumtext.innerHTML = '';
8608: if (index == 'all') {
8609: if (caller == 'link') {
8610: propagateState(targetform,'rpicknum');
8611: }
8612: } else {
1.538 raeburn 8613: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8614: }
8615: }
8616: }
8617:
8618: function propagateState(form,param) {
8619: if (document.getElementById(param+'all')) {
8620: var setcheck = 0;
8621: var rpick = 0;
8622: if (param == 'rpicknum') {
8623: if (document.getElementById('randompickall')) {
8624: if (document.getElementById('randompickall').checked) {
8625: if (document.getElementById('rpicknumall')) {
8626: rpick = document.getElementById('rpicknumall').value;
8627: }
8628: }
8629: }
8630: } else {
8631: if (document.getElementById(param+'all').checked) {
8632: setcheck = 1;
8633: }
8634: }
1.538 raeburn 8635: var allidxlist;
8636: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8637: if (document.getElementById('all'+param+'idx')) {
8638: allidxlist = document.getElementById('all'+param+'idx').value;
8639: }
8640: var actions = new Array ('remove','cut','copy');
8641: for (var i=0; i<actions.length; i++) {
8642: if (actions[i] != param) {
8643: if (document.getElementById(actions[i]+'all')) {
8644: document.getElementById(actions[i]+'all').checked = false;
8645: }
8646: }
8647: }
8648: }
1.537 raeburn 8649: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 8650: allidxlist = form.allidx.value;
8651: }
8652: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
8653: allidxlist = form.allmapidx.value;
8654: }
8655: if ((allidxlist != '') && (allidxlist != null)) {
8656: var allidxs = allidxlist.split(',');
8657: if (allidxs.length > 1) {
8658: for (var i=0; i<allidxs.length; i++) {
8659: if (document.getElementById(param+'_'+allidxs[i])) {
8660: if (param == 'rpicknum') {
8661: if (document.getElementById('randompick_'+allidxs[i])) {
8662: if (document.getElementById('randompick_'+allidxs[i]).checked) {
8663: document.getElementById(param+'_'+allidxs[i]).value = rpick;
8664: if (rpick > 0) {
8665: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
8666: } else {
8667: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8668: }
8669: }
8670: }
8671: } else {
1.537 raeburn 8672: if (setcheck == 1) {
8673: document.getElementById(param+'_'+allidxs[i]).checked = true;
8674: } else {
8675: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 8676: if (param == 'randompick') {
8677: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8678: }
1.537 raeburn 8679: }
8680: }
8681: }
8682: }
1.538 raeburn 8683: if (setcheck == 1) {
8684: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8685: var actions = new Array('copy','cut','remove');
8686: for (var i=0; i<actions.length; i++) {
8687: var otheractions;
8688: var otheridxs;
8689: if (actions[i] === param) {
8690: continue;
8691: } else {
8692: if (document.getElementById('all'+actions[i]+'idx')) {
8693: otheractions = document.getElementById('all'+actions[i]+'idx').value;
8694: otheridxs = otheractions.split(',');
8695: if (otheridxs.length > 1) {
8696: for (var j=0; j<otheridxs.length; j++) {
8697: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
8698: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
8699: }
1.537 raeburn 8700: }
8701: }
8702: }
1.538 raeburn 8703: }
8704: }
8705: }
8706: }
8707: }
8708: }
8709: }
8710: return;
8711: }
8712:
1.603 raeburn 8713: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 8714: var canedit = '$canedit';
8715: if (canedit == '') {
8716: alert("$js_lt{'edri'}");
8717: return;
8718: }
1.539 raeburn 8719: var dosettings;
8720: var doaction;
1.538 raeburn 8721: var control = document.togglemultsettings;
8722: if (context == 'actions') {
8723: control = document.togglemultactions;
1.539 raeburn 8724: doaction = 1;
8725: } else {
8726: dosettings = 1;
1.538 raeburn 8727: }
1.539 raeburn 8728: if (control) {
8729: if (control.showmultpick.length) {
8730: for (var i=0; i<control.showmultpick.length; i++) {
8731: if (control.showmultpick[i].checked) {
8732: if (control.showmultpick[i].value == 1) {
8733: if (context == 'settings') {
8734: dosettings = 0;
8735: } else {
8736: doaction = 0;
1.538 raeburn 8737: }
8738: }
8739: }
1.537 raeburn 8740: }
8741: }
1.539 raeburn 8742: }
8743: if (context == 'settings') {
8744: if (dosettings == 1) {
1.538 raeburn 8745: targetform.changeparms.value=param;
8746: targetform.submit();
8747: }
1.537 raeburn 8748: }
1.539 raeburn 8749: if (context == 'actions') {
8750: if (doaction == 1) {
8751: targetform.cmd.value=param+'_'+index;
8752: targetform.folderpath.value=folderpath;
8753: targetform.markcopy.value=idx+':'+param;
8754: targetform.copyfolder.value=folder+'.'+container;
8755: if (param == 'remove') {
1.603 raeburn 8756: var doremove = 0;
8757: if (skip_confirm) {
8758: if (confirm_removal) {
8759: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8760: doremove = 1;
8761: }
8762: } else {
8763: doremove = 1;
8764: }
8765: } else {
8766: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8767: doremove = 1;
8768: }
8769: }
8770: if (doremove) {
1.539 raeburn 8771: targetform.markcopy.value='';
8772: targetform.copyfolder.value='';
8773: targetform.submit();
8774: }
8775: }
8776: if (param == 'cut') {
1.594 damieng 8777: 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 8778: targetform.submit();
8779: return;
8780: }
8781: }
8782: if (param == 'copy') {
8783: targetform.submit();
8784: return;
8785: }
8786: targetform.markcopy.value='';
8787: targetform.copyfolder.value='';
8788: targetform.cmd.value='';
8789: targetform.folderpath.value='';
8790: return;
8791: } else {
8792: if (document.getElementById(param+'_'+idx)) {
8793: item = document.getElementById(param+'_'+idx);
8794: if (item.type == 'checkbox') {
8795: if (item.checked) {
8796: item.checked = false;
8797: } else {
8798: item.checked = true;
8799: singleCheck(item,idx,param);
8800: }
8801: }
8802: }
8803: }
8804: }
1.537 raeburn 8805: return;
8806: }
8807:
1.538 raeburn 8808: function singleCheck(caller,idx,action) {
8809: actions = new Array('cut','copy','remove');
8810: if (caller.checked) {
8811: for (var i=0; i<actions.length; i++) {
8812: if (actions[i] != action) {
8813: if (document.getElementById(actions[i]+'_'+idx)) {
8814: if (document.getElementById(actions[i]+'_'+idx).checked) {
8815: document.getElementById(actions[i]+'_'+idx).checked = false;
8816: }
1.537 raeburn 8817: }
8818: }
8819: }
1.478 raeburn 8820: }
1.537 raeburn 8821: return;
1.478 raeburn 8822: }
8823:
1.334 muellerd 8824: function unselectInactive(nav) {
1.335 ehlerst 8825: currentNav = document.getElementById(nav);
8826: currentLis = currentNav.getElementsByTagName('LI');
8827: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8828: if (currentLis[i].className == 'goback') {
8829: currentLis[i].className = 'goback';
8830: } else {
8831: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8832: currentLis[i].className = 'right';
1.472 raeburn 8833: } else {
1.374 tempelho 8834: currentLis[i].className = 'i';
1.472 raeburn 8835: }
8836: }
1.335 ehlerst 8837: }
1.332 tempelho 8838: }
8839:
1.334 muellerd 8840: function hideAll(current, nav, data) {
1.335 ehlerst 8841: unselectInactive(nav);
1.570 raeburn 8842: if (current) {
8843: if (current.className == 'right'){
8844: current.className = 'right active'
8845: } else {
8846: current.className = 'active';
8847: }
1.374 tempelho 8848: }
1.335 ehlerst 8849: currentData = document.getElementById(data);
8850: currentDivs = currentData.getElementsByTagName('DIV');
8851: for (i = 0; i < currentDivs.length; i++) {
8852: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8853: currentDivs[i].style.display = 'none';
1.330 tempelho 8854: }
8855: }
1.335 ehlerst 8856: }
1.330 tempelho 8857:
1.374 tempelho 8858: function openTabs(pageId) {
8859: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8860: if(tabnav.length > 2 ){
1.389 tempelho 8861: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8862: currentLis = currentNav.getElementsByTagName('LI');
8863: for(i = 0; i< currentLis.length; i++){
8864: if(currentLis[i].className == 'active') {
1.375 tempelho 8865: funcString = currentLis[i].onclick.toString();
8866: tab = funcString.split('"');
1.420 onken 8867: if(tab.length < 2) {
8868: tab = funcString.split("'");
8869: }
1.375 tempelho 8870: currentData = document.getElementById(tab[1]);
8871: currentData.style.display = 'block';
1.374 tempelho 8872: }
8873: }
8874: }
8875: }
8876:
1.334 muellerd 8877: function showPage(current, pageId, nav, data) {
1.570 raeburn 8878: currstate = current.className;
1.334 muellerd 8879: hideAll(current, nav, data);
1.375 tempelho 8880: openTabs(pageId);
1.334 muellerd 8881: unselectInactive(nav);
1.570 raeburn 8882: if ((currstate == 'active') || (currstate == 'right active')) {
8883: if (currstate == 'active') {
8884: current.className = '';
8885: } else {
8886: current.className = 'right';
8887: }
8888: activeTab = '';
1.656 raeburn 8889: toggleExternal();
1.570 raeburn 8890: toggleUpload();
8891: toggleMap();
1.606 raeburn 8892: toggleCrsRes();
8893: toggleImportCrsres();
1.570 raeburn 8894: resize_scrollbox('contentscroll','1','0');
8895: return;
8896: } else {
8897: current.className = 'active';
8898: }
1.330 tempelho 8899: currentData = document.getElementById(pageId);
8900: currentData.style.display = 'block';
1.458 raeburn 8901: activeTab = pageId;
1.656 raeburn 8902: toggleExternal();
1.501 raeburn 8903: toggleUpload();
1.503 raeburn 8904: toggleMap();
1.606 raeburn 8905: toggleCrsRes();
8906: toggleImportCrsres();
1.433 raeburn 8907: if (nav == 'mainnav') {
8908: var storedpath = "$docs_folderpath";
1.434 raeburn 8909: var storedpage = "$main_container_page";
1.433 raeburn 8910: var reg = new RegExp("^supplemental");
8911: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8912: if (storedpage == 1) {
8913: document.simpleedit.folderpath.value = '';
8914: document.uploaddocument.folderpath.value = '';
8915: } else {
8916: if (reg.test(storedpath)) {
8917: document.simpleedit.folderpath.value = '$toplevelmain';
8918: document.uploaddocument.folderpath.value = '$toplevelmain';
8919: document.newext.folderpath.value = '$toplevelmain';
8920: } else {
8921: document.simpleedit.folderpath.value = storedpath;
8922: document.uploaddocument.folderpath.value = storedpath;
8923: document.newext.folderpath.value = storedpath;
8924: }
1.433 raeburn 8925: }
8926: } else {
1.434 raeburn 8927: if (reg.test(storedpath)) {
8928: document.simpleedit.folderpath.value = storedpath;
8929: document.supuploaddocument.folderpath.value = storedpath;
8930: document.supnewext.folderpath.value = storedpath;
8931: } else {
1.433 raeburn 8932: document.simpleedit.folderpath.value = '$toplevelsupp';
8933: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8934: document.supnewext.folderpath.value = '$toplevelsupp';
8935: }
8936: }
8937: }
1.485 raeburn 8938: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8939: return false;
8940: }
1.329 droeschl 8941:
1.472 raeburn 8942: function toContents(jumpto) {
8943: var newurl = '$backtourl';
1.525 raeburn 8944: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8945: newurl = newurl+'?postdata='+jumpto;
8946: }
8947: location.href=newurl;
8948: }
8949:
1.538 raeburn 8950: function togglePick(caller,value) {
8951: var disp = 'none';
8952: if (document.getElementById('multi'+caller)) {
8953: var curr = document.getElementById('multi'+caller).style.display;
8954: if (value == 1) {
8955: disp='block';
8956: }
8957: if (curr == disp) {
8958: return;
8959: }
8960: document.getElementById('multi'+caller).style.display=disp;
8961: if (value == 1) {
1.594 damieng 8962: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8963: } else {
8964: document.getElementById('more'+caller).innerHTML = '';
8965: }
8966: if (caller == 'actions') {
8967: setClass(value);
8968: setBoxes(value);
8969: }
8970: }
8971: var showButton = multiSettings();
8972: if (showButton != 1) {
8973: showButton = multiActions();
8974: }
8975: if (document.getElementById('multisave')) {
8976: if (showButton == 1) {
8977: document.getElementById('multisave').style.display='block';
8978: } else {
8979: document.getElementById('multisave').style.display='none';
8980: }
8981: }
8982: resize_scrollbox('contentscroll','1','1');
8983: return;
8984: }
8985:
8986: function toggleCheckUncheck(caller,more) {
8987: if (more == 1) {
1.594 damieng 8988: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8989: document.getElementById('allfields'+caller).style.display='block';
8990: } else {
1.594 damieng 8991: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8992: document.getElementById('allfields'+caller).style.display='none';
8993: }
8994: resize_scrollbox('contentscroll','1','1');
8995: }
8996:
8997: function multiSettings() {
8998: var inuse = 0;
8999: var settingsform = document.togglemultsettings;
9000: if (settingsform.showmultpick.length > 1) {
9001: for (var i=0; i<settingsform.showmultpick.length; i++) {
9002: if (settingsform.showmultpick[i].checked) {
9003: if (settingsform.showmultpick[i].value == 1) {
9004: inuse = 1;
9005: }
9006: }
9007: }
9008: }
9009: return inuse;
9010: }
9011:
9012: function multiActions() {
9013: var inuse = 0;
9014: var actionsform = document.togglemultactions;
9015: if (actionsform.showmultpick.length > 1) {
9016: for (var i=0; i<actionsform.showmultpick.length; i++) {
9017: if (actionsform.showmultpick[i].checked) {
9018: if (actionsform.showmultpick[i].value == 1) {
9019: inuse = 1;
9020: }
9021: }
9022: }
9023: }
9024: return inuse;
9025: }
9026:
9027: function checkSubmits() {
9028: var numchanges = 0;
9029: var form = document.saveactions;
9030: var doactions = multiActions();
1.542 raeburn 9031: var cutwarnings = 0;
9032: var remwarnings = 0;
1.603 raeburn 9033: var removalinfo = 0;
1.538 raeburn 9034: if (doactions == 1) {
9035: var remidxlist = document.cumulativeactions.allremoveidx.value;
9036: if ((remidxlist != '') && (remidxlist != null)) {
9037: var remidxs = remidxlist.split(',');
9038: for (var i=0; i<remidxs.length; i++) {
9039: if (document.getElementById('remove_'+remidxs[i])) {
9040: if (document.getElementById('remove_'+remidxs[i]).checked) {
9041: form.multiremove.value += remidxs[i]+',';
9042: numchanges ++;
1.542 raeburn 9043: if (document.getElementById('skip_remove_'+remidxs[i])) {
9044: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
9045: remwarnings ++;
9046: }
9047: }
1.603 raeburn 9048: if (document.getElementById('confirm_removal_'+remidxs[i])) {
9049: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
9050: removalinfo ++;
9051: }
9052: }
1.537 raeburn 9053: }
9054: }
1.538 raeburn 9055: }
9056: }
9057: var cutidxlist = document.cumulativeactions.allcutidx.value;
9058: if ((cutidxlist != '') && (cutidxlist != null)) {
9059: var cutidxs = cutidxlist.split(',');
9060: for (var i=0; i<cutidxs.length; i++) {
9061: if (document.getElementById('cut_'+cutidxs[i])) {
9062: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
9063: form.multicut.value += cutidxs[i]+',';
9064: numchanges ++;
1.542 raeburn 9065: if (document.getElementById('skip_cut_'+cutidxs[i])) {
9066: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
9067: cutwarnings ++;
9068: }
9069: }
1.537 raeburn 9070: }
9071: }
9072: }
9073: }
1.538 raeburn 9074: var copyidxlist = document.cumulativeactions.allcopyidx.value;
9075: if ((copyidxlist != '') && (copyidxlist != null)) {
9076: var copyidxs = copyidxlist.split(',');
9077: for (var i=0; i<copyidxs.length; i++) {
9078: if (document.getElementById('copy_'+copyidxs[i])) {
9079: if (document.getElementById('copy_'+copyidxs[i]).checked) {
9080: form.multicopy.value += copyidxs[i]+',';
9081: numchanges ++;
9082: }
9083: }
9084: }
9085: }
9086: if (numchanges > 0) {
9087: form.multichange.value = numchanges;
9088: }
1.537 raeburn 9089: }
1.538 raeburn 9090: var dosettings = multiSettings();
1.543 raeburn 9091: var haschanges = 0;
1.538 raeburn 9092: if (dosettings == 1) {
9093: form.allencrypturl.value = '';
9094: form.allhiddenresource.value = '';
1.543 raeburn 9095: form.changeparms.value = 'all';
9096: var patt=new RegExp(",\$");
1.538 raeburn 9097: var allidxlist = document.cumulativesettings.allidx.value;
9098: if ((allidxlist != '') && (allidxlist != null)) {
9099: var allidxs = allidxlist.split(',');
9100: if (allidxs.length > 1) {
9101: for (var i=0; i<allidxs.length; i++) {
9102: if (document.getElementById('hiddenresource_'+allidxs[i])) {
9103: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
9104: form.allhiddenresource.value += allidxs[i]+',';
9105: }
9106: }
9107: if (document.getElementById('encrypturl_'+allidxs[i])) {
9108: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
9109: form.allencrypturl.value += allidxs[i]+',';
9110: }
9111: }
9112: }
1.543 raeburn 9113: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
9114: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 9115: }
1.538 raeburn 9116: }
9117: form.allrandompick.value = '';
9118: form.allrandomorder.value = '';
9119: var allmapidxlist = document.cumulativesettings.allmapidx.value;
9120: if ((allmapidxlist != '') && (allmapidxlist != null)) {
9121: var allmapidxs = allmapidxlist.split(',');
9122: for (var i=0; i<allmapidxs.length; i++) {
9123: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
9124: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
9125: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
9126: if ((randompick.checked) && (rpicknum.value != '')) {
9127: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
9128: }
9129: if (randorder.checked) {
9130: form.allrandomorder.value += allmapidxs[i]+',';
9131: }
1.537 raeburn 9132: }
1.543 raeburn 9133: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
9134: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
9135: }
9136: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
9137: haschanges = 1;
9138: }
9139: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
9140: haschanges = 1;
9141: }
9142: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
9143: haschanges = 1;
9144: }
9145: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
9146: haschanges = 1;
1.537 raeburn 9147: }
9148: }
1.543 raeburn 9149: if (doactions == 1) {
1.542 raeburn 9150: if (numchanges > 0) {
1.603 raeburn 9151: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 9152: if (remwarnings > 0) {
1.594 damieng 9153: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 9154: return false;
9155: }
9156: }
1.603 raeburn 9157: if (removalinfo > 0) {
9158: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
9159: return false;
9160: }
9161: }
1.542 raeburn 9162: if (cutwarnings > 0) {
1.594 damieng 9163: 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 9164: return false;
9165: }
9166: }
9167: }
9168: form.submit();
9169: return true;
1.543 raeburn 9170: }
9171: }
9172: if (dosettings == 1) {
9173: if (haschanges == 1) {
1.542 raeburn 9174: form.submit();
9175: return true;
9176: }
1.543 raeburn 9177: }
9178: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 9179: alert("$js_lt{'noor'}");
1.543 raeburn 9180: } else {
9181: if (dosettings == 1) {
1.594 damieng 9182: alert("$js_lt{'noch'}");
1.543 raeburn 9183: } else {
1.594 damieng 9184: alert("$js_lt{'noac'}");
1.543 raeburn 9185: }
9186: }
1.538 raeburn 9187: return false;
9188: }
9189:
9190: function setClass(value) {
9191: var cutclass = 'LC_docs_cut';
9192: var copyclass = 'LC_docs_copy';
9193: var removeclass = 'LC_docs_remove';
9194: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
9195: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
9196: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
9197: var links = document.getElementsByTagName('a');
9198: for (var i=0; i<links.length; i++) {
9199: var classes = links[i].className;
9200: if (cutreg.test(classes)) {
9201: links[i].className = cutclass;
9202: if (value == 1) {
9203: links[i].className += " LC_menubuttons_link";
9204: }
9205: } else {
9206: if (copyreg.test(classes)) {
9207: links[i].className = copyclass;
9208: if (value == 1) {
9209: links[i].className += " LC_menubuttons_link";
9210: }
9211: } else {
9212: if (removereg.test(classes)) {
9213: links[i].className = removeclass;
9214: if (value == 1) {
9215: links[i].className += " LC_menubuttons_link";
9216: }
9217: }
9218: }
9219: }
9220: }
9221: return;
1.537 raeburn 9222: }
9223:
1.538 raeburn 9224: function setBoxes(value) {
9225: var remidxlist = document.cumulativeactions.allremoveidx.value;
9226: if ((remidxlist != '') && (remidxlist != null)) {
9227: var remidxs = remidxlist.split(',');
9228: for (var i=0; i<remidxs.length; i++) {
9229: if (document.getElementById('remove_'+remidxs[i])) {
9230: var item = document.getElementById('remove_'+remidxs[i]);
9231: if (value == 1) {
9232: item.className = 'LC_docs_remove';
9233: } else {
9234: item.className = 'LC_hidden';
9235: }
9236: }
9237: }
9238: }
9239: var cutidxlist = document.cumulativeactions.allcutidx.value;
9240: if ((cutidxlist != '') && (cutidxlist != null)) {
9241: var cutidxs = cutidxlist.split(',');
9242: for (var i=0; i<cutidxs.length; i++) {
9243: if (document.getElementById('cut_'+cutidxs[i])) {
9244: var item = document.getElementById('cut_'+cutidxs[i]);
9245: if (value == 1) {
9246: item.className = 'LC_docs_cut';
9247: } else {
9248: item.className = 'LC_hidden';
9249: }
9250: }
1.537 raeburn 9251: }
9252: }
1.538 raeburn 9253: var copyidxlist = document.cumulativeactions.allcopyidx.value;
9254: if ((copyidxlist != '') && (copyidxlist != null)) {
9255: var copyidxs = copyidxlist.split(',');
9256: for (var i=0; i<copyidxs.length; i++) {
9257: if (document.getElementById('copy_'+copyidxs[i])) {
9258: var item = document.getElementById('copy_'+copyidxs[i]);
9259: if (value == 1) {
9260: item.className = 'LC_docs_copy';
9261: } else {
9262: item.className = 'LC_hidden';
9263: }
9264: }
1.537 raeburn 9265: }
9266: }
9267: return;
9268: }
9269:
1.606 raeburn 9270: function validImportCrsRes() {
9271: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
9272: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
9273: if ((fname == '') || (fname == null)) {
9274: alert("$js_lt{'nofi'}");
9275: return false;
9276: }
9277: var url = '/res/$coursedom/$coursenum/';
9278: if (path && path != '/') {
9279: url += path+'/';
9280: }
9281: if (fname != '') {
9282: url += fname;
9283: }
9284: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 9285: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 9286: return true;
9287: }
9288:
9289: function validateNewRes(caller) {
9290: if (caller == 'single') {
9291: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9292: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
9293: var resname = document.courseresform.newresourcename.value;
9294: }
9295: }
9296:
1.611 raeburn 9297: ENDSCRIPT
1.329 droeschl 9298: }
1.457 raeburn 9299:
1.483 raeburn 9300: sub history_tab_js {
9301: return <<"ENDHIST";
9302: function toggleHistoryDisp(choice) {
9303: document.docslogform.docslog.value = choice;
9304: document.docslogform.submit();
9305: return;
9306: }
9307:
9308: ENDHIST
9309: }
9310:
1.484 raeburn 9311: sub inject_data_js {
9312: return <<ENDINJECT;
9313:
9314: function injectData(current, hiddenField, name, value) {
9315: currentElement = document.getElementById(hiddenField);
9316: currentElement.name = name;
9317: currentElement.value = value;
9318: current.submit();
9319: }
9320:
9321: ENDINJECT
9322: }
9323:
9324: sub dump_switchserver_js {
9325: my @hosts = @_;
1.594 damieng 9326: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 9327: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 9328: swit => 'Switch server?',
1.594 damieng 9329: );
9330: my %html_js_lt = &Apache::lonlocal::texthash(
9331: swit => 'Switch server?',
1.568 raeburn 9332: duco => 'Copying Content to Authoring Space',
1.484 raeburn 9333: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
9334: chos => 'Choose server',
9335: );
1.594 damieng 9336: &js_escape(\%js_lt);
9337: &html_escape(\%html_js_lt);
9338: &js_escape(\%html_js_lt);
1.484 raeburn 9339: my $role = $env{'request.role'};
9340: my $js = <<"ENDSWJS";
9341: <script type="text/javascript">
9342: function write_switchserver() {
9343: var server;
9344: if (document.setserver.posshosts.length > 0) {
9345: for (var i=0; i<document.setserver.posshosts.length; i++) {
9346: if (document.setserver.posshosts[i].checked) {
9347: server = document.setserver.posshosts[i].value;
9348: }
9349: }
9350: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
9351: }
9352: window.close();
9353: }
9354: </script>
9355:
9356: ENDSWJS
9357:
9358: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
9359: {'only_body' => 1,
9360: 'js_ready' => 1,});
9361: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
9362:
9363: my $hostpicker;
9364: my $count = 0;
9365: foreach my $host (sort(@hosts)) {
9366: my $checked;
9367: if ($count == 0) {
9368: $checked = ' checked="checked"';
9369: }
9370: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
9371: $host.'"'.$checked.' />'.$host.'</label> ';
9372: $count++;
9373: }
9374:
9375: return <<"ENDSWITCHJS";
9376:
9377: function dump_needs_switchserver(url) {
9378: if (url!='' && url!= null) {
1.594 damieng 9379: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 9380: go(url);
9381: }
9382: }
9383: return;
9384: }
9385:
9386: function choose_switchserver_window() {
9387: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
9388: newWindow.document.open();
9389: newWindow.document.writeln('$startpage');
1.594 damieng 9390: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
9391: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
9392: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 9393: '<form name="setserver" method="post" action="" \\/>\\n'+
9394: '$hostpicker\\n'+
9395: '<br \\/><br \\/>\\n'+
1.594 damieng 9396: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 9397: 'onclick="write_switchserver();" \\/>\\n'+
9398: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
9399: newWindow.document.writeln('$endpage');
9400: newWindow.document.close();
9401: newWindow.focus();
9402: }
9403:
9404: ENDSWITCHJS
9405: }
9406:
9407: sub makedocslogform {
9408: my ($formelems,$docslog) = @_;
9409: return <<"LOGSFORM";
9410: <form action="/adm/coursedocs" method="post" name="docslogform">
9411: <input type="hidden" name="docslog" value="$docslog" />
9412: $formelems
9413: </form>
9414: LOGSFORM
9415: }
9416:
9417: sub makesimpleeditform {
9418: my ($formelems) = @_;
9419: return <<"SIMPFORM";
9420: <form name="simpleedit" method="post" action="/adm/coursedocs">
9421: <input type="hidden" name="importdetail" value="" />
9422: $formelems
9423: </form>
9424: SIMPFORM
9425: }
9426:
1.606 raeburn 9427: sub makenewproblem {
9428: my ($r,$coursedom,$coursenum) = @_;
9429: # Creating a new problem
9430: my ($redirect,$error);
9431: if ($env{'form.authorrole'}) {
9432: my ($newsubdir,$filename);
9433: if ($env{'form.newsubdir'}) {
9434: if ($env{'form.newsubdirname'} ne '') {
9435: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 9436: }
1.606 raeburn 9437: }
9438: if ($env{'form.newresourcename'}) {
9439: $filename = $env{'form.newresourcename'};
9440: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
9441: $filename =~ s/`//g;
9442: $filename =~ s{/\.\./}{_}g;
9443: $filename =~ s/\.+/./g;
9444: $filename =~ s{/+}{_}g;
9445: if ($filename ne '') {
9446: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
9447: if (($ext) && ($ext ne '.problem')) {
9448: $filename = $name.'.problem';
9449: } elsif ($ext eq '') {
9450: $filename .= '.problem';
9451: }
9452: my $docroot = $r->dir_config('lonDocRoot');
9453: my @ids=&Apache::lonnet::current_machine_ids();
9454: if ($env{'form.authorrole'} eq 'author') {
9455: if ($env{'user.author'}) {
9456: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
9457: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
9458: my $path = $docroot.$url;
9459: my $subdir = $env{'form.authorpath'};
9460: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9461: }
9462: }
9463: } elsif ($env{'form.authorrole'} eq 'course') {
9464: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
9465: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
9466: my $url = "/priv/$coursedom/$coursenum";
9467: my $path=$docroot.$url;
9468: my $subdir = $env{'form.authorpath'};
9469: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9470: if ($redirect) {
9471: my $rightsfile = 'default.rights';
9472: my $sourcerights = "$path/$rightsfile";
9473: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
9474: my $now = time;
9475: if (!-e $sourcerights) {
9476: my $cid = $coursedom.'_'.$coursenum;
9477: if (open(my $fh,">$sourcerights")) {
9478: print $fh <<END;
9479: <accessrule effect="deny" realm="" type="course" role="" />
9480: <accessrule effect="allow" realm="$cid" type="course" role="" />
9481: END
9482: close($fh);
9483: }
9484: }
9485: if (!-e "$sourcerights.meta") {
9486: if (open(my $fh,">$sourcerights.meta")) {
9487: my $author=$env{'environment.firstname'}.' '.
9488: $env{'environment.middlename'}.' '.
9489: $env{'environment.lastname'}.' '.
9490: $env{'environment.generation'};
9491: $author =~ s/\s+$//;
9492: print $fh <<"END";
9493:
9494: <abstract></abstract>
9495: <author>$author</author>
9496: <authorspace>$coursenum:$coursedom</authorspace>
9497: <copyright>private</copyright>
9498: <creationdate>$now</creationdate>
9499: <customdistributionfile></customdistributionfile>
9500: <dependencies></dependencies>
9501: <domain>$coursedom</domain>
9502: <highestgradelevel>0</highestgradelevel>
9503: <keywords></keywords>
9504: <language>notset </language>
9505: <lastrevisiondate>$now</lastrevisiondate>
9506: <lowestgradelevel>0</lowestgradelevel>
9507: <mime>rights</mime>
9508: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
9509: <notes></notes>
9510: <obsolete></obsolete>
9511: <obsoletereplacement></obsoletereplacement>
9512: <owner>$coursenum:$coursedom</owner>
9513: <rule>deny:::course,allow:$cid::course</rule>
9514: <sourceavail></sourceavail>
9515: <standards></standards>
9516: <subject></subject>
1.703 raeburn 9517: <title>Course Authoring Rights</title>
1.606 raeburn 9518: END
1.654 raeburn 9519: close($fh);
9520: }
9521: }
9522: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
9523: if (!-e "$docroot/res/$coursedom") {
9524: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 9525: }
1.654 raeburn 9526: if (!-e "$docroot/res/$coursedom/$coursenum") {
9527: mkdir("$docroot/res/$coursedom/$coursenum",0755);
9528: }
9529: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
9530: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
9531: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 9532: }
9533: }
1.654 raeburn 9534: my $source = $docroot.$redirect;
9535: if (!-e "$source.meta") {
9536: my $cid = $coursedom.'_'.$coursenum;
9537: my $now = time;
9538: if (open(my $fh,">$source.meta")) {
9539: my $author=$env{'environment.firstname'}.' '.
9540: $env{'environment.middlename'}.' '.
9541: $env{'environment.lastname'}.' '.
9542: $env{'environment.generation'};
9543: $author =~ s/\s+$//;
9544: my $title = $env{'form.newresourcetitle'};
9545: $title =~ s/^\s+|\s+$//g;
9546: print $fh <<END;
1.606 raeburn 9547:
9548: <abstract></abstract>
9549: <author>$author</author>
9550: <authorspace>$coursenum:$coursedom</authorspace>
9551: <copyright>custom</copyright>
9552: <creationdate>$now</creationdate>
9553: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
9554: <dependencies></dependencies>
9555: <domain>$coursedom</domain>
9556: <highestgradelevel>0</highestgradelevel>
9557: <keywords></keywords>
9558: <language>notset </language>
9559: <lastrevisiondate>$now</lastrevisiondate>
9560: <lowestgradelevel>0</lowestgradelevel>
9561: <mime>problem</mime>
9562: <modifyinguser>$coursenum:$coursedom</modifyinguser>
9563: <notes></notes>
9564: <obsolete></obsolete>
9565: <obsoletereplacement></obsoletereplacement>
9566: <owner>$coursenum:$coursedom</owner>
9567: <sourceavail></sourceavail>
9568: <standards></standards>
9569: <subject></subject>
9570: <title>$title</title>
9571: END
1.654 raeburn 9572: close($fh);
1.606 raeburn 9573: }
9574: }
9575: }
9576: }
9577: } else {
9578: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
9579: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
9580: if (grep(/^\Q$rolehome\E$/,@ids)) {
9581: my $now = time;
9582: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
9583: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
9584: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
9585: my $url = "/priv/$audom/$auname";
9586: my $path = $r->dir_config('lonDocRoot').$url;
9587: my $subdir = $env{'form.authorpath'};
9588: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9589: }
9590: }
9591: }
9592: }
9593: }
9594: }
9595: }
9596: return ($redirect,$error);
9597: }
9598:
9599: sub finishnewprob {
1.654 raeburn 9600: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 9601: unless (-d $path) {
9602: unless (mkdir($path,02770)) {
9603: return;
9604: }
9605: }
1.606 raeburn 9606: my $redirect;
9607: if ($subdir ne '/') {
9608: $subdir = &cleandir($subdir);
9609: if (($subdir ne '') && (-d "$path/$subdir")) {
9610: $path .= "/$subdir";
9611: $url .= "/$subdir";
9612: }
9613: }
9614: my $dest;
9615: if ($newsubdir ne '') {
9616: $newsubdir = &cleandir($newsubdir);
9617: }
9618: if ($newsubdir ne '') {
9619: if (-d "$path/$newsubdir") {
9620: $dest = "$path/$newsubdir/$filename";
9621: } else {
9622: my $dirok;
9623: unless (-e "$path/$newsubdir") {
9624: if (mkdir("$path/$newsubdir",02770)) {
9625: if (chmod(02770,"$path/$newsubdir")) {
9626: $dirok = 1;
9627: }
9628: }
9629: }
9630: if ($dirok) {
9631: $dest = "$path/$newsubdir/$filename";
9632: }
9633: }
9634: if (($dest ne '') && (!-e $dest)) {
9635: $redirect = "$url/$newsubdir/$filename";
9636: }
9637: } else {
9638: $dest = "$path/$filename";
9639: if (($dest ne '') && (!-e $dest)) {
9640: $redirect = "$url/$filename";
9641: }
9642: }
1.654 raeburn 9643: if ((!-e $dest) && ($context ne 'upload')) {
9644: my $template = $env{'form.template'};
9645: my $copyfrom;
9646: if ($template ne '') {
9647: my %templates;
9648: my @files = &Apache::lonhomework::get_template_list('problem');
9649: foreach my $poss (@files) {
9650: if (ref($poss) eq 'ARRAY') {
9651: if ($template eq $poss->[0]) {
9652: $templates{$template} = 1;
9653: last;
9654: }
9655: }
9656: }
9657: if ($templates{$template}) {
9658: $copyfrom = $template;
9659: }
9660: }
9661: if ($filename =~ /\.problem$/) {
9662: unless ($copyfrom) {
9663: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
9664: }
9665: &File::Copy::copy($copyfrom,$dest);
9666: }
9667: }
1.606 raeburn 9668: return $redirect;
9669: }
9670:
9671: sub cleandir {
9672: my ($dir) = @_;
9673: $dir =~ s/^\s+//;
9674: $dir =~ s/\s+$//;
9675: $dir =~ s/\.+//g;
9676: $dir =~ s/[\#\?&%\":]//g;
9677: return $dir;
9678: }
9679:
1.329 droeschl 9680: 1;
9681: __END__
9682:
9683:
9684: =head1 NAME
9685:
9686: Apache::londocs.pm
9687:
9688: =head1 SYNOPSIS
9689:
9690: This is part of the LearningOnline Network with CAPA project
9691: described at http://www.lon-capa.org.
9692:
9693: =head1 SUBROUTINES
9694:
9695: =over
9696:
9697: =item %help=()
9698:
9699: Available help topics
9700:
9701: =item mapread()
9702:
1.344 bisitz 9703: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 9704: @order and @resources, determines status
9705: sets @order - pointer to resources in right order
9706: sets @resources - array with the resources with correct idx
9707:
9708: =item authorhosts()
9709:
9710: Return hash with valid author names
9711:
9712: =item clean()
9713:
9714: =item dumpcourse()
9715:
9716: Actually dump course
9717:
9718: =item group_import()
9719:
9720: Imports the given (name, url) resources into the course
9721: coursenum, coursedom, and folder must precede the list
9722:
9723: =item breadcrumbs()
9724:
9725: =item log_docs()
9726:
9727: =item docs_change_log()
9728:
9729: =item update_paste_buffer()
9730:
9731: =item print_paste_buffer()
9732:
9733: =item do_paste_from_buffer()
9734:
1.538 raeburn 9735: =item do_buffer_empty()
9736:
9737: =item clear_from_buffer()
9738:
1.492 raeburn 9739: =item get_newmap_url()
9740:
9741: =item dbcopy()
9742:
9743: =item uniqueness_check()
9744:
9745: =item contained_map_check()
9746:
9747: =item url_paste_fixups()
9748:
9749: =item apply_fixups()
9750:
9751: =item copy_dependencies()
9752:
1.329 droeschl 9753: =item update_parameter()
9754:
9755: =item handle_edit_cmd()
9756:
9757: =item editor()
9758:
9759: =item process_file_upload()
9760:
9761: =item process_secondary_uploads()
9762:
9763: =item is_supplemental_title()
9764:
9765: =item entryline()
9766:
9767: =item tiehash()
9768:
9769: =item untiehash()
9770:
9771: =item checkonthis()
9772:
9773: check on this
9774:
9775: =item verifycontent()
9776:
9777: Verify Content
9778:
1.636 raeburn 9779: =item devalidateversioncache()
9780:
9781: =item checkversions()
1.329 droeschl 9782:
9783: Check Versions
9784:
9785: =item mark_hash_old()
9786:
9787: =item is_hash_old()
9788:
9789: =item changewarning()
9790:
9791: =item init_breadcrumbs()
9792:
9793: Breadcrumbs for special functions
9794:
1.484 raeburn 9795: =item create_list_elements()
9796:
9797: =item create_form_ul()
9798:
9799: =item startContentScreen()
9800:
9801: =item endContentScreen()
9802:
9803: =item supplemental_base()
9804:
9805: =item embedded_form_elems()
9806:
9807: =item embedded_destination()
9808:
9809: =item return_to_editor()
9810:
9811: =item decompression_info()
9812:
9813: =item decompression_phase_one()
9814:
9815: =item decompression_phase_two()
9816:
9817: =item remove_archive()
9818:
9819: =item generate_admin_menu()
9820:
9821: =item generate_edit_table()
9822:
9823: =item editing_js()
9824:
9825: =item history_tab_js()
9826:
9827: =item inject_data_js()
9828:
9829: =item dump_switchserver_js()
9830:
1.485 raeburn 9831: =item resize_scrollbox_js()
1.484 raeburn 9832:
9833: =item makedocslogform()
9834:
1.485 raeburn 9835: =item makesimpleeditform()
9836:
1.329 droeschl 9837: =back
9838:
9839: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>