Annotation of loncom/interface/londocs.pm, revision 1.718
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.718 ! raeburn 4: # $Id: londocs.pm,v 1.717 2025/01/04 01:34:57 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.713 raeburn 51: use HTML::LCParser;
1.329 droeschl 52: use GDBM_File;
1.578 raeburn 53: use File::MMagic;
1.606 raeburn 54: use File::Copy;
1.329 droeschl 55: use Apache::lonlocal;
56: use Cwd;
1.643 raeburn 57: use UUID::Tiny ':std';
1.329 droeschl 58: use LONCAPA qw(:DEFAULT :match);
59:
60: my $iconpath;
61:
62: my %hash;
63:
64: my $hashtied;
65: my %alreadyseen=();
66:
67: my $hadchanges;
1.557 raeburn 68: my $suppchanges;
1.329 droeschl 69:
70:
71: my %help=();
72:
73:
74: sub mapread {
75: my ($coursenum,$coursedom,$map)=@_;
76: return
77: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
78: $map);
79: }
80:
81: sub storemap {
1.492 raeburn 82: my ($coursenum,$coursedom,$map,$contentchg)=@_;
83: my $report;
84: if (($contentchg) && ($map =~ /^default/)) {
85: $report = 1;
86: }
1.329 droeschl 87: my ($outtext,$errtext)=
88: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 89: $map,1,$report);
1.329 droeschl 90: if ($errtext) { return ($errtext,2); }
1.364 bisitz 91:
1.557 raeburn 92: if ($map =~ /^default/) {
93: $hadchanges=1;
1.682 raeburn 94: } elsif ($contentchg) {
1.557 raeburn 95: $suppchanges=1;
96: }
1.329 droeschl 97: return ($errtext,0);
98: }
99:
100:
101:
102: sub authorhosts {
103: my %outhash=();
104: my $home=0;
105: my $other=0;
1.709 raeburn 106: my @ids=&Apache::lonnet::current_machine_ids();
1.329 droeschl 107: foreach my $key (keys(%env)) {
108: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
109: my $role=$1;
110: my $realm=$2;
111: my ($start,$end)=split(/\./,$env{$key});
112: if (($start) && ($start>time)) { next; }
113: if (($end) && (time>$end)) { next; }
114: my ($ca,$cd);
115: if ($1 eq 'au') {
116: $ca=$env{'user.name'};
117: $cd=$env{'user.domain'};
118: } else {
119: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
120: }
121: my $allowed=0;
122: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
1.484 raeburn 123: foreach my $id (@ids) {
124: if ($id eq $myhome) {
125: $allowed=1;
126: last;
127: }
128: }
1.329 droeschl 129: if ($allowed) {
130: $home++;
1.484 raeburn 131: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 132: } else {
1.484 raeburn 133: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 134: $other++;
135: }
136: }
137: }
138: return ($home,$other,%outhash);
139: }
140:
141:
142: sub clean {
143: my ($title)=@_;
144: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 145: return $title;
1.329 droeschl 146: }
147:
1.617 raeburn 148: sub default_folderpath {
149: my ($coursenum,$coursedom,$navmapref) = @_;
150: return unless ($coursenum && $coursedom && ref($navmapref));
151: # Check if entire course is hidden and/or encrypted
152: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
153: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
154: unless (ref($$navmapref)) {
155: $$navmapref = Apache::lonnavmaps::navmap->new();
156: }
157: if (ref($$navmapref)) {
158: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
159: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
160: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
161: unless (@resources) {
162: $hiddenmap = 1;
163: unless ($env{'request.role.adv'}) {
164: $hiddentop = 1;
165: if ($env{'form.folder'}) {
166: undef($env{'form.folder'});
167: }
168: }
169: }
170: }
171: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
172: $encryptmap = 1;
173: }
174: }
175: unless ($hiddentop) {
176: $folderpath='default&'.&escape(&mt('Main Content')).
177: '::'.$hiddenmap.':'.$encryptmap.'::';
178: }
179: if (wantarray) {
180: return ($folderpath,$hiddentop);
181: } else {
182: return $folderpath;
183: }
184: }
1.329 droeschl 185:
1.685 raeburn 186: sub validate_supppath {
187: my ($coursenum,$coursedom) = @_;
188: my $backto;
1.677 raeburn 189: if ($env{'form.supppath'} ne '') {
190: my @items = split(/\&/,$env{'form.supppath'});
1.685 raeburn 191: my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
1.677 raeburn 192: for (my $i=0; $i<@items; $i++) {
193: my $odd = $i%2;
194: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
195: $badpath = 1;
1.685 raeburn 196: last;
197: } elsif ($odd) {
198: my $suffix;
199: my $idx = $i-1;
200: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
201: $backto .= '&'.$1;
202: } elsif ($items[$idx] eq 'supplemental') {
203: $backto .= '&'.$items[$i];
204: } else {
205: $backto .= '&'.$items[$i];
206: my $is_hidden;
207: unless ($got_supp) {
1.688 raeburn 208: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 209: if (ref($supplemental) eq 'HASH') {
210: if (ref($supplemental->{'hidden'}) eq 'HASH') {
211: %supphidden = %{$supplemental->{'hidden'}};
212: }
213: if (ref($supplemental->{'ids'}) eq 'HASH') {
214: %suppids = %{$supplemental->{'ids'}};
215: }
216: }
217: $got_supp = 1;
218: }
219: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
220: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
221: if ($supphidden{$mapid}) {
222: $is_hidden = 1;
223: }
224: }
225: $suffix = '::'.$is_hidden.':::';
226: }
227: $supppath .= '&'.$items[$i].$suffix;
228: } else {
229: $supppath .= '&'.$items[$i];
230: $backto .= '&'.$items[$i];
1.677 raeburn 231: }
232: }
233: if ($badpath) {
234: delete($env{'form.supppath'});
1.685 raeburn 235: } else {
236: $supppath =~ s/^\&//;
237: $backto =~ s/^\&//;
238: $env{'form.supppath'} = $supppath;
1.677 raeburn 239: }
240: }
1.685 raeburn 241: return $backto;
1.677 raeburn 242: }
243:
1.329 droeschl 244: sub dumpcourse {
245: my ($r) = @_;
1.408 raeburn 246: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 247: my ($starthash,$js);
248: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
249: $js = <<"ENDJS";
250: <script type="text/javascript">
251: // <![CDATA[
252:
253: function hide_searching() {
254: if (document.getElementById('searching')) {
255: document.getElementById('searching').style.display = 'none';
256: }
257: return;
258: }
259:
260: // ]]>
261: </script>
262: ENDJS
263: $starthash = {
264: add_entries => {'onload' => "hide_searching();"},
265: };
266: }
1.709 raeburn 267: $r->print(&Apache::loncommon::start_page('Copy uploaded content to Authoring Space',$js,$starthash)."\n".
268: &Apache::lonhtmlcommon::breadcrumbs('Copy uploaded content to Authoring Space')."\n");
1.484 raeburn 269: $r->print(&startContentScreen('tools'));
1.329 droeschl 270: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 271: unless ($home) {
1.712 raeburn 272: $r->print('<p class="LC_info">'.&mt('No author or co-author roles on this server.').'</p>');
1.484 raeburn 273: $r->print(&endContentScreen());
274: return '';
275: }
1.329 droeschl 276: my $origcrsid=$env{'request.course.id'};
277: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
278: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
279: # Do the dumping
1.484 raeburn 280: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
1.712 raeburn 281: $r->print('<p class="LC_info">'.&mt('Selected Authoring Space is not on this server.').'</p>'.
282: &endContentScreen());
1.484 raeburn 283: return '';
284: }
1.531 raeburn 285: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 286: $r->print('<h3>'.&mt('Copying Files').'</h3>');
287: my $title=$env{'form.authorfolder'};
288: $title=&clean($title);
1.567 raeburn 289: my ($navmap,$errormsg) =
290: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
291: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
292: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
293: my (%maps,%resources,%titles);
294: if (!ref($navmap)) {
295: $r->print($errormsg.
296: &endContentScreen());
297: return '';
298: } else {
299: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
300: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 301: }
1.567 raeburn 302: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
303: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
304: %newcontent,%has_simpleprobs);
305: foreach my $item (sort {$a <=> $b} (@todump)) {
306: my $name = $env{'form.namefor_'.$item};
307: if ($resources{$item}) {
308: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
309: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
310: $tocopy{$1} = $name;
311: $display{$item} = $1;
312: $lookup{$1} = $item;
313: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
314: $simpleproblems{$item} = {
315: symb => $resources{$item},
316: name => $name,
317: };
318: $display{$item} = 'simpleproblem_'.$name;
319: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
320: $has_simpleprobs{$1}{$id} = $item;
321: }
322: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
323: my $marker = $1;
324: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
325: $simplepages{$item} = {
326: res => $res,
327: title => $titles{$item},
328: db => $db_name,
329: marker => $marker,
330: symb => $resources{$item},
331: name => $name,
332: };
333: $display{$item} = '/'.$res;
334: }
335: } elsif ($maps{$item}) {
336: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
337: $tocopy{$1} = $name;
338: $display{$item} = $1;
339: $lookup{$1} = $item;
340: }
341: } else {
342: next;
343: }
344: }
1.329 droeschl 345: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
346: $crs=~s/\_/\//g;
1.567 raeburn 347: my $mm = new File::MMagic;
348: my $prefix = "/uploaded/$cdom/$cnum/";
349: %replacehash = %tocopy;
350: foreach my $item (sort(keys(%simpleproblems))) {
351: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
352: $newcontent{$display{$item}} = $content;
353: }
354: my $gateway = Apache::lonhtmlgateway->new('web');
355: foreach my $item (sort(keys(%simplepages))) {
356: if (ref($simplepages{$item}) eq 'HASH') {
357: my $pagetitle = $simplepages{$item}{'title'};
358: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
359: my %contents;
360: foreach my $field (keys(%fields)) {
361: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
362: my $name = $1;
363: my $msg = $fields{$field};
364: if ($name eq 'webreferences') {
365: if ($msg =~ m{^https?://}) {
366: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
367: }
368: } else {
369: $msg = &Encode::decode('utf8',$msg);
370: $msg = $gateway->process_outgoing_html($msg,1);
371: $contents{$name} = $msg;
372: }
373: } elsif ($field eq 'uploaded.photourl') {
374: my $marker = $simplepages{$item}{marker};
375: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
376: my $filepath = $1;
377: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
378: if ($fname ne '') {
379: $fname=~s/\.(\w+)$//;
380: my $ext=$1;
381: $fname = &clean($fname);
382: $fname.='.'.$ext;
383: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
384: $replacehash{$filepath} = $relpath.$fname;
385: $deps{$item}{$filepath} = 1;
386: }
387: }
388: }
389: }
390: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
391: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
392: my $content = '
393: <html>
394: <head>
395: <title>'.$pagetitle.'</title>
396: </head>
397: <body bgcolor="#ffffff">';
398: if ($contents{title}) {
399: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
400: }
401: if ($contents{image}) {
402: $content .= "\n".$contents{image};
403: }
404: if ($contents{content}) {
405: $content .= '
406: <div class="LC_Box">
1.577 bisitz 407: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 408: $contents{content}.'
409: </div>';
410: }
411: if ($contents{webreferences}) {
412: $content .= '
413: <div class="LC_Box">
1.577 bisitz 414: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 415: $contents{webreferences}.'
416: </div>';
417: }
418: $content .= '
419: </body>
420: </html>
421: ';
422: $newcontent{'/'.$simplepages{$item}{res}} = $content;
423: }
424: }
425: foreach my $item (keys(%tocopy)) {
426: unless ($item=~/\.(sequence|page)$/) {
427: my $currurlpath = $prefix.$item;
428: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
429: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
430: }
431: }
432: foreach my $num (sort {$a <=> $b} (@todump)) {
433: my $src = $display{$num};
434: next if ($src eq '');
435: my @needcopy = ();
436: if ($replacehash{$src}) {
437: push(@needcopy,$src);
438: if (ref($deps{$num}) eq 'HASH') {
439: foreach my $dep (sort(keys(%{$deps{$num}}))) {
440: if ($replacehash{$dep}) {
441: push(@needcopy,$dep);
442: }
443: }
444: }
445: } elsif ($src =~ /^simpleproblem_/) {
446: push(@needcopy,$src);
447: }
448: next if (@needcopy == 0);
449: my ($result,$depresult);
450: for (my $i=0; $i<@needcopy; $i++) {
451: my $item = $needcopy[$i];
452: my $newfilename;
453: if ($simpleproblems{$num}) {
454: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
455: } else {
456: $newfilename=$title.'/'.$replacehash{$item};
457: }
458: $newfilename=~s/\.(\w+)$//;
459: my $ext=$1;
460: $newfilename=&clean($newfilename);
461: $newfilename.='.'.$ext;
462: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
463: if ($newrelpath ne $replacehash{$item}) {
464: $replacehash{$item} = $newrelpath;
465: }
466: my @dirs=split(/\//,$newfilename);
467: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
468: my $makepath=$path;
469: my $fail;
470: my $origin;
471: for (my $i=0;$i<$#dirs;$i++) {
472: $makepath.='/'.$dirs[$i];
473: unless (-e $makepath) {
474: unless(mkdir($makepath,0755)) {
475: $fail = &mt('Directory creation failed.');
476: }
477: }
478: }
479: if ($i == 0) {
480: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
481: } else {
482: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
483: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
484: &mt('(dependency)').'</span>: ';
485: }
486: if (-e $path.'/'.$newfilename) {
487: $fail = &mt('Destination already exists -- not overwriting.');
488: } else {
489: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
490: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
491: ($item =~ /^simpleproblem_/)) {
492: print $fh $newcontent{$item};
493: } else {
494: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
495: if (-e $fileloc) {
496: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
497: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
498: (ref($has_simpleprobs{$item}) eq 'HASH')) {
499: my %changes = %{$has_simpleprobs{$item}};
500: my $content = &Apache::lonclonecourse::rewritefile(
501: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
502: (%replacehash,$crs => '')
503: );
504: my $updatedcontent = '';
505: my $parser = HTML::TokeParser->new(\$content);
506: $parser->attr_encoded(1);
507: while (my $token = $parser->get_token) {
508: if ($token->[0] eq 'S') {
509: if (($token->[1] eq 'resource') &&
510: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
511: ($changes{$token->[2]->{'id'}})) {
512: my $id = $token->[2]->{'id'};
513: $updatedcontent .= '<'.$token->[1];
514: foreach my $attrib (@{$token->[3]}) {
515: next unless ($attrib =~ /^(src|type|title|id)$/);
516: if ($attrib eq 'src') {
517: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
518: if ($file) {
519: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
520: } else {
521: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
522: }
523: } else {
524: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
525: }
526: }
527: $updatedcontent .= ' />'."\n";
528: } else {
529: $updatedcontent .= $token->[4]."\n";
530: }
531: } else {
532: $updatedcontent .= $token->[2];
533: }
534: }
535: print $fh $updatedcontent;
536: } else {
537: print $fh &Apache::lonclonecourse::rewritefile(
538: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
539: (%replacehash,$crs => '')
540: );
541: }
542: } else {
543: print $fh
544: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
545: }
546: } else {
547: $fail = &mt('Source does not exist.');
548: }
549: }
550: $fh->close();
551: } else {
552: $fail = &mt('Could not write to destination.');
553: }
554: }
555: my $text;
556: if ($fail) {
557: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
558: } else {
559: $text = '<span class="LC_success">'.&mt('ok').'</span>';
560: }
561: if ($i == 0) {
562: $result .= $text;
563: } else {
564: $depresult .= $text.'</li>';
565: }
566: }
567: $r->print($result);
568: if ($depresult) {
569: $r->print('<ul>'.$depresult.'</ul>');
570: }
571: }
572: } else {
573: my ($navmap,$errormsg) =
574: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
575: if (!ref($navmap)) {
576: $r->print($errormsg);
577: } else {
578: my $title=$origcrsdata{'description'};
579: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 580: $title=&clean($title);
1.712 raeburn 581: my $formname = 'dumpdoc';
1.715 raeburn 582: my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash).
583: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
1.712 raeburn 584: my %uploadedfiles;
1.567 raeburn 585: &tiehash();
586: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
587: my ($ext)=($file=~/\.(\w+)$/);
588: # FIXME Check supplemental here
589: my $title=$hash{'title_'.$hash{
590: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
591: if (!$title) {
592: $title=$file;
593: } else {
594: $title=~s|/|_|g;
595: }
596: $title=~s/\.(\w+)$//;
597: $title=&clean($title);
598: $title.='.'.$ext;
599: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
600: $uploadedfiles{$file} = $title;
601: }
602: &untiehash();
603: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
604: undef,undef,$preamble,$home,\%uploadedfiles));
605: }
1.329 droeschl 606: }
1.484 raeburn 607: $r->print(&endContentScreen());
1.329 droeschl 608: }
609:
1.712 raeburn 610: sub authorspace_selector {
611: my ($r,$formname,$home,$title,%outhash) = @_;
612: $r->print('<div id="searching">'.&mt('Searching ...').'</div>'."\n");
613: $r->rflush();
614: my $preamble;
615: unless ($home==1) {
616: $preamble = '<div class="LC_left_float">'.
617: '<fieldset><legend>'.
618: &mt('Select the Authoring Space').
619: '</legend><select name="authorspace">';
620: }
621: my @orderspaces = ();
622: foreach my $key (sort(keys(%outhash))) {
623: if ($key=~/^home_(.+)$/) {
624: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
625: unshift(@orderspaces,$1);
626: } else {
627: push(@orderspaces,$1);
628: }
629: }
630: }
631: if ($home>1) {
632: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
633: }
634: foreach my $user (@orderspaces) {
635: if ($home==1) {
636: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
637: } else {
638: $preamble .= '<option value="'.$user.'">'.$user.' - '.
639: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
640: }
641: }
642: unless ($home==1) {
643: $preamble .= '</select></fieldset></div>'."\n";
644: }
645: $preamble .= '<div class="LC_left_float">'.
646: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
1.715 raeburn 647: '<input type="text" size="30" name="authorfolder" value="'.$title.'" />'."\n".
648: '</fieldset></div>'."\n";
1.712 raeburn 649: return $preamble;
650: }
651:
1.567 raeburn 652: sub recurse_html {
653: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
654: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
655: my (%allfiles,%codebase);
656: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
657: if (keys(%allfiles)) {
658: foreach my $dependency (keys(%allfiles)) {
659: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
660: my ($depurl,$relfile,$newcontainer);
661: if ($dependency =~ m{^/}) {
662: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
663: $relfile = $1;
664: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
665: $newcontainer = $1;
666: next if ($replacehash->{$newcontainer});
667: }
668: $depurl = $dependency;
669: } else {
670: next;
671: }
672: } else {
673: $relfile = $dependency;
674: $depurl = $currurlpath;
1.630 raeburn 675: $depurl =~ s{[^/]+$}{};
1.567 raeburn 676: $depurl .= $dependency;
1.630 raeburn 677: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 678: }
679: next if ($relfile eq '');
680: my $newname = $replacehash->{$container};
681: $newname =~ s{[^/]+$}{};
682: $replacehash->{$newcontainer} = $newname.$relfile;
683: $deps->{$item}{$newcontainer} = 1;
684: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
685: my $depfile = &Apache::lonnet::filelocation('',$depurl);
686: my $type = $mm->checktype_filename($depfile);
687: if ($type eq 'text/html') {
688: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
689: }
690: }
691: }
692: }
693: return;
694: }
695:
1.712 raeburn 696: sub copycrsauthored {
697: my ($r,$coursenum,$coursedom,$coursehome,$readonly) = @_;
1.715 raeburn 698: my ($starthash,$js,$title,$formname);
699: my %origcrsdata=&Apache::lonnet::coursedescription($env{'request.course.id'});
700: $title=$origcrsdata{'description'};
701: $title=~s/[\/\s]+/\_/gs;
702: $title=&clean($title);
703: my ($home,$other,%outhash)=&authorhosts();
1.712 raeburn 704: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
1.715 raeburn 705: my %js_lt;
706: $formname = 'copycrsauthored';
707: if ($home) {
708: %js_lt =
709: &Apache::lonlocal::texthash(
710: yomu => 'You must select an Authoring Space',
711: whco => 'When Copyright set to "custom", URL of a published rights file is needed.',
712: );
713: &js_escape(\%js_lt);
714: }
715: if ($home > 1) {
716: $js = <<"ENDJS";
717: <script type="text/javascript">
718: // <![CDATA[
719:
720: function validCrsCopy() {
721: var dest = document.$formname.authorspace.options[document.$formname.authorspace.selectedIndex].value;
722: if (dest == '') {
723: alert("$js_lt{'yomu'}");
724: return false;
725: }
726: var dist = document.$formname.copyright.options[document.$formname.copyright.selectedIndex].value;
727: if (dist == 'custom') {
728: if (document.$formname.customrights.value == '') {
729: alert("$js_lt{'whco'}");
730: return false;
731: }
1.716 raeburn 732: }
1.715 raeburn 733: return true;
734: }
735:
736: function init_copycrs_form() {
737: document.$formname.authorspace.selectedIndex = "0";
738: document.$formname.authorfolder.value = '$title';
739: document.$formname.copyright.selectedIndex = "0";
740: }
741:
742: // ]]>
743: </script>
744:
745: ENDJS
746: } elsif ($home) {
747: $js = <<"ENDJS";
748: <script type="text/javascript">
749: // <![CDATA[
750:
751: function init_copycrs_form() {
752: document.$formname.authorfolder.value = '$title';
753: document.$formname.copyright.selectedIndex = "0";
754: }
755:
756: // ]]>
757: </script>
758:
759: ENDJS
760: }
761: $js .= <<"ENDJS";
1.712 raeburn 762: <script type="text/javascript">
763: // <![CDATA[
764:
765: function hide_searching() {
766: if (document.getElementById('searching')) {
767: document.getElementById('searching').style.display = 'none';
768: }
769: return;
770: }
771:
1.715 raeburn 772: function showHideCustom(caller,divid) {
773: if (document.getElementById(divid)) {
774: if (caller.options[caller.selectedIndex].value == 'custom') {
775: document.getElementById(divid).style.display="inline-block";
776: } else {
777: document.getElementById(divid).style.display="none";
778: }
779: }
780: return;
781: }
782:
1.712 raeburn 783: // ]]>
784: </script>
785: ENDJS
1.715 raeburn 786:
787: $js .= "\n".&Apache::lonhtmlcommon::scripttag(&Apache::loncommon::browser_and_searcher_javascript())."\n";
1.712 raeburn 788: $starthash = {
1.715 raeburn 789: add_entries => {'onload' => "hide_searching(); init_copycrs_form();"},
1.712 raeburn 790: };
791: }
792: $r->print(&Apache::loncommon::start_page('Copy from Course Authoring to User Authoring',$js,$starthash)."\n".
793: &Apache::lonhtmlcommon::breadcrumbs('Copy from Course Authoring Space')."\n");
794: $r->print(&startContentScreen('tools'));
795: unless ($home) {
796: $r->print('<p class="LC_info">'.&mt('No author or co-author roles on this server.').'</p>');
797: $r->print(&endContentScreen());
798: return '';
799: }
1.715 raeburn 800: my $docroot = $r->dir_config('lonDocRoot');
1.714 raeburn 801: my $is_course_home;
802: my @ids=&Apache::lonnet::current_machine_ids();
803: if (($coursehome ne '') && (grep(/^\Q$coursehome\E$/,@ids))) {
804: $is_course_home = 1;
805: }
1.712 raeburn 806: my $exclude = &Apache::lonnet::priv_exclude();
807: my $srcurl = "/priv/$coursedom/$coursenum";
1.715 raeburn 808: my $srctop = $docroot.$srcurl;
809: my $resurl = "/res/$coursedom/$coursenum";
810: my $res_exclude = &Apache::lonnet::res_exclude();
1.712 raeburn 811: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
812: $r->print('<h3>'.&mt('Copying Files and/or Sub-directories').'</h3>');
813: if ($readonly) {
814: $r->print('<p class="LC_info">'.
815: &mt('You do not have permission to copy files and/or directories from Course Authoring Space.').
816: '</p>'.
817: &endContentScreen());
818: return '';
819: }
820: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
821: $r->print('<p class="LC_info">'.&mt('Selected Authoring Space is not on this server.').'</p>'.
822: &endContentScreen());
823: return '';
824: }
825: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
826: my $desturl = "/priv/$cd/$ca";
1.715 raeburn 827: my $destresurl = "/res/$cd/$ca";
828: my $desttop = $docroot.$desturl;
1.712 raeburn 829: my $subdir = &clean($env{'form.authorfolder'});
830: $subdir = &cleandir($subdir);
831: if ($subdir eq '') {
832: $r->print('<p class="LC_info">'.&mt('After removal of disallowed characters target sub-directory name was blank.').'</p>'.
833: &endContentScreen());
834: return '';
835: } elsif ($subdir =~/^_+$/) {
836: $r->print('<p class="LC_info">'.&mt('After replacement of non-alphanumeric characters with _ in target sub-directory name, nothing but underscores was left.').'</p>'.
837: &endContentScreen());
838: return '';
839: }
840: my (%tocopy,%dirs_to_make,%files_to_copy);
841: map { $tocopy{&unescape($_)} = 1; } &Apache::loncommon::get_env_multiple('form.copytouser');
842: if (keys(%tocopy)) {
843: my (%subdirs,%files);
1.714 raeburn 844: &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files);
1.712 raeburn 845: foreach my $possible (sort(keys(%tocopy))) {
846: if ($possible =~ m{/$}) {
847: my $possdir = $possible;
848: $possdir =~ s{^/+|/+$}{}g;
849: if (exists($subdirs{$possdir})) {
850: $dirs_to_make{$possdir} = 1;
851: } else {
852: delete($tocopy{$possible});
853: }
854: } else {
855: my ($path,$fname) = ($possible =~ m{(.*/)([^/]+)$});
856: my $found = 0;
857: if ($path eq '/') {
858: if (ref($files{$path}) eq 'HASH') {
859: if (exists($files{$path}{$fname})) {
860: $found = 1;
861: $files_to_copy{$fname} = 1;
862: }
863: }
864: } else {
865: $path =~ s{^/+|/+$}{}g;
866: if (ref($files{$path}) eq 'HASH') {
867: if (exists($files{$path}{$fname})) {
868: $dirs_to_make{$path} = 1;
869: $files_to_copy{"$path/$fname"} = 1;
870: $found = 1;
871: }
872: }
873: }
874: unless ($found) {
875: delete($tocopy{$possible});
876: }
877: }
878: }
879: } else {
880: $r->print('<p>'.&mt('No files or directories selected for copying').'</p>');
881: $r->print(&endContentScreen());
882: return '';
883: }
884: if (keys(%tocopy)) {
1.714 raeburn 885: my (%resdirs,%resfiles);
886: &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
1.713 raeburn 887: my ($notopdir,%newdir,%newfile,%checkdeps);
1.712 raeburn 888: $r->print('<p>'.&mt('Copy to: [_1]',
889: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
890: '</p>'."\n");
891: if (keys(%dirs_to_make)) {
1.714 raeburn 892: unless (-e $desttop.'/'.$subdir) {
893: mkdir($desttop.'/'.$subdir,0755);
894: }
895: if (-e $desttop.'/'.$subdir) {
896: foreach my $dir (sort(keys(%dirs_to_make))) {
897: my @dirs=split(/\//,$dir);
898: my $path="$desttop/$subdir";
899: my $makepath=$path;
900: my $fail;
901: for (my $i=0;$i<@dirs;$i++) {
902: $makepath.='/'.$dirs[$i];
903: unless (-e $makepath) {
904: unless (mkdir($makepath,0755)) {
905: $fail = 1;
906: last;
907: }
908: if (($i == scalar(@dirs)-1) && (!$fail)) {
909: $newdir{$dir} = 1;
1.712 raeburn 910: }
911: }
912: }
1.714 raeburn 913: if ($fail) {
914: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
915: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$dir.'</span>').
916: '</p>'."\n");
917: }
1.712 raeburn 918: }
1.714 raeburn 919: } else {
920: $notopdir = 1;
1.712 raeburn 921: }
922: }
923: if (keys(%files_to_copy)) {
1.714 raeburn 924: unless (-e $desttop.'/'.$subdir) {
925: mkdir($desttop.'/'.$subdir,0755);
926: }
927: if (-e $desttop.'/'.$subdir) {
928: my $num = 0;
1.715 raeburn 929: my ($copyright,$customdistfile);
930: if ($env{'form.copyright'} eq 'default' || $env{'form.copyright'} eq 'domain' || $env{'form.copyright'} eq 'public') {
931: $copyright = $env{'form.copyright'};
932: } elsif ($env{'form.copyright'} eq 'custom') {
933: if ($env{'form.customrights'} =~ m{^/res/$match_domain/$match_username/.+\.rights$}) {
934: my ($rightsdom,$rightsuname) = ($1,$2);
935: my $rightshome = &Apache::lonnet::homeserver($rightsdom,$rightsuname);
936: if (($rightshome eq 'no_host') || ($rightshome eq '')) {
937: $copyright = 'default';
938: } elsif (grep(/^\Q$rightshome\E$/,@ids)) {
939: if (-e $docroot.$env{'form.customrights'}) {
940: $copyright = 'custom';
941: $customdistfile = $env{'form.customrights'};
942: } else {
943: $copyright = 'default';
944: }
945: } else {
946: my $rightsfile = &Apache::lonnet::filelocation('',$env{'form.customrights'});
947: unless (&Apache::lonnet::getfile($rightsfile) eq '-1') {
948: $customdistfile = $env{'form.customrights'};
949: }
950: }
951: }
952: }
953: my $sourceavail;
954: if ($env{'form.sourceavail'} =~ /^(open|closed)$/) {
955: $sourceavail = $env{'form.sourceavail'};
956: }
957: my $respublish;
958: if ($env{'form.respublish'}) {
959: $respublish = 1;
960: }
961: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
1.714 raeburn 962: foreach my $file (keys(%files_to_copy)) {
963: my ($fail,$dup,$dir_is_file,$src,$dest,$path,$fname);
964: if ($file =~ m{/}) {
965: ($path,$fname) = ($file =~ m{^(.+)/([^/]+)$});
966: if (-d "$desttop/$subdir/$path") {
967: if (-e "$desttop/$subdir/$path/$fname") {
968: $dup = 1;
1.712 raeburn 969: } else {
1.714 raeburn 970: $src = "$srctop/$path/$fname";
971: $dest = "$desttop/$subdir/$path/$fname";
1.712 raeburn 972: }
1.714 raeburn 973: } elsif (-f "$desttop/$subdir/$path") {
974: $dir_is_file = 1;
1.712 raeburn 975: } else {
1.714 raeburn 976: $fail = 1;
977: }
978: } elsif (-e "$desttop/$subdir/$file") {
979: $dup = 1;
980: } else {
981: $src = "$srctop/$file";
982: $dest = "$desttop/$subdir/$file";
983: $fname = $file;
984: }
985: if ($fail) {
986: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
987: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$path.'</span>').
988: '</p>'."\n");
989: } elsif ($dup) {
990: $r->print('<p class="LC_warning">'.&mt('Target file: [_1] already exists -- not overwriting.',
991: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
992: '</p>'."\n");
993: } elsif ($dir_is_file) {
994: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] name is already in a use for a file -- not overwriting.',
995: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
996: '</p>'."\n");
997: } elsif (($src ne '') && ($dest ne '')) {
1.717 raeburn 998: my $ressrc = $docroot.$resurl.'/'.$file;
999: my $ressrcmeta = $ressrc.'.meta';
1000: my ($ext) = ($file =~ /\.(\w+)$/);
1001: my $embstyle=&Apache::loncommon::fileembstyle($ext);
1002: my ($getres,$getresmeta);
1003: if ($respublish) {
1004: if ($path eq '') {
1005: if ((ref($resfiles{'/'}) eq 'HASH') &&
1006: (exists($resfiles{'/'}{$fname}))) {
1007: $getres = 1;
1008: $getresmeta = 1;
1009: }
1010: } elsif ((ref($resfiles{$path}) eq 'HASH') &&
1011: (exists($resfiles{$path}{$fname}))) {
1012: $getres = 1;
1013: $getresmeta = 1;
1.714 raeburn 1014: }
1015: }
1.717 raeburn 1016: if ($is_course_home) {
1017: my ($needpriv,$needprivmeta);
1018: if ($respublish) {
1019: if ($getres) {
1020: if (&Apache::londiff::are_different_files($src,$ressrc)) {
1021: $needpriv = 1;
1022: if (&File::Copy::copy($ressrc,$dest)) {
1023: if ($embstyle eq 'ssi') {
1024: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd);
1025: }
1026: }
1027: } else {
1028: if (&File::Copy::copy($src,$dest)) {
1029: $newfile{$file} = 1;
1030: if ($embstyle eq 'ssi') {
1031: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
1032: }
1033: }
1.714 raeburn 1034: }
1.717 raeburn 1035: } else {
1036: $needpriv = 1;
1.714 raeburn 1037: }
1.717 raeburn 1038: if ($getresmeta) {
1039: if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
1040: if (&Apache::londiff::are_different_files($src.'.meta',$ressrc.'.meta')) {
1041: if (&File::Copy::copy($ressrc.'.meta',$dest.'.meta')) {
1042: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
1043: $customdistfile,$sourceavail,\%checkdeps);
1.715 raeburn 1044: }
1.717 raeburn 1045: $needprivmeta = 1;
1046: } else {
1047: if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
1048: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
1049: $customdistfile,$sourceavail,\%checkdeps);
1.713 raeburn 1050: }
1051: }
1.712 raeburn 1052: }
1.717 raeburn 1053: }
1054: if ($getres) {
1055: my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file;
1056: if (-e $dest) {
1057: my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
1.714 raeburn 1058: }
1.712 raeburn 1059: }
1.717 raeburn 1060: } else {
1061: $needpriv = 1;
1062: if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
1063: $needprivmeta = 1;
1064: }
1065: }
1066: if ($needpriv) {
1067: if (&File::Copy::copy($src,$dest)) {
1068: $newfile{$file} = 1;
1069: if ($embstyle eq 'ssi') {
1070: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
1071: }
1072: }
1073: }
1074: if ($needprivmeta) {
1075: if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
1076: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
1077: $customdistfile,$sourceavail,\%checkdeps);
1078: }
1.714 raeburn 1079: }
1.717 raeburn 1080: } else {
1081: my ($needpriv,$needprivmeta);
1082: if ($respublish) {
1083: if ($getres) {
1084: &Apache::lonnet::repcopy($docroot.$resurl.'/'.$file);
1085: }
1086: if ($getresmeta) {
1087: &Apache::lonnet::repcopy($docroot.$resurl.'/'.$file.'.meta');
1088: }
1089: if (-e $docroot.$resurl.'/'.$file) {
1090: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
1091: if (&Apache::londiff::are_different_files($docroot.$resurl.'/'.$file,$dest)) {
1092: $needpriv = 1;
1093: if (&File::Copy::copy($docroot.$resurl.'/'.$file,$dest)) {
1094: if ($embstyle eq 'ssi') {
1095: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd);
1.713 raeburn 1096: }
1.714 raeburn 1097: }
1.717 raeburn 1098: } else {
1099: if ($embstyle eq 'ssi') {
1100: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
1.714 raeburn 1101: }
1.717 raeburn 1102: $newfile{$file} = 1;
1103: }
1104: }
1105: } else {
1106: $needpriv = 1;
1107: }
1108: if (-e $docroot.$resurl.'/'.$file.'.meta') {
1109: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
1110: if (&Apache::londiff::are_different_files($docroot.$resurl.'/'.$file.'.meta',$dest.'.meta')) {
1111: $needprivmeta = 1;
1112: if (&File::Copy::copy($docroot.$resurl.'/'.$file.'.meta',$dest.'.meta')) {
1113: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
1114: $customdistfile,$sourceavail,\%checkdeps);
1.713 raeburn 1115: }
1.714 raeburn 1116: } else {
1.717 raeburn 1117: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
1118: $customdistfile,$sourceavail,\%checkdeps);
1.713 raeburn 1119: }
1120: }
1.717 raeburn 1121: } else {
1122: if (!-e $dest.'.meta') {
1123: $needprivmeta = 1;
1124: }
1.714 raeburn 1125: }
1.717 raeburn 1126: if ($getres) {
1127: my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file;
1128: if (-e $dest) {
1129: my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
1.713 raeburn 1130: }
1.712 raeburn 1131: }
1.717 raeburn 1132: } else {
1133: $needpriv = 1;
1134: if (!-e $dest.'.meta') {
1135: $needprivmeta = 1;
1136: }
1.712 raeburn 1137: }
1.717 raeburn 1138: if ($needpriv) {
1139: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
1140: if ($embstyle eq 'ssi') {
1141: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
1.715 raeburn 1142: }
1.717 raeburn 1143: $newfile{$file} = 1;
1144: }
1145: }
1146: if ($needprivmeta) {
1147: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
1148: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
1149: $customdistfile,$sourceavail,\%checkdeps);
1.715 raeburn 1150: }
1151: }
1.712 raeburn 1152: }
1153: }
1154: }
1.714 raeburn 1155: } else {
1156: $notopdir = 1;
1.712 raeburn 1157: }
1158: }
1159: if ($notopdir) {
1160: $r->print('<p><span class="LC_info">'.&mt('No files or sub-directories copied').'</span><br />'."\n".
1161: '<span class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
1162: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1163: '</span></p>'."\n");
1164: }
1165: if (keys(%newdir)) {
1166: $r->print('<p>'.&mt('Created the following directories in [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1167: '</p>'."\n".
1168: '<ul><li>'.join('</li><li>',sort(keys(%newdir))).'</li></ul></p>'."\n");
1169: }
1170: if (keys(%newfile)) {
1171: $r->print('<p>'.&mt('Copied the following files to [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1172: '</p>'."\n".
1173: '<ul><li>'.join('</li><li>',sort(keys(%newfile))).'</li></ul></p>'."\n");
1174: }
1.713 raeburn 1175: if (keys(%checkdeps)) {
1176: my %missingdep;
1177: foreach my $depfile (sort(keys(%checkdeps))) {
1178: unless (-e "$desttop/$depfile") {
1179: $missingdep{$depfile} = 1;
1180: }
1181: }
1182: if (keys(%missingdep)) {
1183: $r->print('<p>'.&mt('You may also need to copy the following missing dependencies for files copied to [_1]:',
1184: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1185: '</p>'."\n".
1186: '<ul><li>'.join('</li><li>',sort(keys(%missingdep))).'</li></ul></p>'."\n");
1187: }
1188: }
1.712 raeburn 1189: } else {
1190: $r->print('<p>'.&mt('No currently existing files or directories in Course Authoring Space selected for copying').'</p>');
1191: $r->print(&endContentScreen());
1192: return '';
1193: }
1194: } else {
1195: my $chkname = 'copytouser';
1196: my $context = 'crsauthored';
1197: my (%subdirs,%files,@dirs_by_depth,@files_by_depth,%parent,%children,%hierarchy,@checked_maps);
1.714 raeburn 1198: &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files,1);
1.712 raeburn 1199: foreach my $key (keys(%subdirs)) {
1200: next if (($key eq '/') || ($key eq ''));
1201: my @items = split(/\//,$key);
1202: my $dir = pop(@items);
1203: my $depth = scalar(@items);
1204: my $path;
1205: if (!$depth) {
1206: $path = '/';
1207: } else {
1208: $path = join('/',@items);
1209: }
1210: $dirs_by_depth[$depth]{$path}{$dir} = 1;
1211: }
1212: foreach my $path (keys(%files)) {
1213: next if ($path eq '');
1214: my $depth;
1215: if ($path eq '/') {
1216: $depth = 0;
1217: } else {
1218: $depth = scalar(split(/\//,$path));
1219: }
1220: if (ref($files{$path}) eq 'HASH') {
1221: foreach my $file (keys(%{$files{$path}})) {
1.714 raeburn 1222: $files_by_depth[$depth]{$path}{$file} = $files{$path}{$file};
1.712 raeburn 1223: }
1224: }
1225: }
1226: my ($info,$display,$onsubmit,$togglebuttons,$disabled);
1.714 raeburn 1227: my (%resdirs,%resfiles);
1.715 raeburn 1228: &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
1229: my $numpub = 0;
1230: if (keys(%resfiles)) {
1231: foreach my $dir (keys(%resfiles)) {
1232: if (ref($resfiles{$dir}) eq 'HASH') {
1233: foreach my $file (keys(%{$resfiles{$dir}})) {
1234: if (exists($files{$dir}{$file})) {
1235: $numpub ++;
1236: }
1237: }
1238: }
1239: }
1240: }
1.712 raeburn 1241: if ($readonly) {
1242: $disabled = ' disabled="disabled"';
1243: }
1244: if ($disabled) {
1245: $togglebuttons = '<br />';
1246: } else {
1247: $togglebuttons = '<input type="button" value="'.&mt('check all').'" '.
1248: 'onclick="javascript:checkAll(document.'.$formname.'.'.$chkname.')" />'.
1249: ' <input type="button" value="'.&mt('uncheck all').'"'.
1250: ' onclick="javascript:uncheckAll(document.'.$formname.'.'.$chkname.')" />';
1251: }
1.715 raeburn 1252: my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash).
1253: &courseresource_options($formname,$numpub).
1254: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
1255: my $display = '<form name="'.$formname.'" action="" method="post" onsubmit="return validCrsCopy();">'."\n".
1.712 raeburn 1256: $preamble."\n".
1257: '<div class="LC_float_left">'."\n".
1258: '<fieldset>'."\n".
1259: '<legend>'.&mt('Content to copy').(' 'x4).$togglebuttons.'</legend>'."\n".
1260: '<span class="LC_fontsize_medium">'.
1261: &mt('Choose the files and/or folders to copy from Course Authoring to User Authoring').
1262: '</span><br /><br />'."\n";
1263: my $count = 0;
1264: my $startcount = 4 + $home;
1265: my $lastcontainer = $startcount;
1266: $display .= &Apache::loncommon::start_data_table()."\n".
1267: &Apache::loncommon::start_data_table_header_row().
1268: '<th>'.&mt('Copy?').'</th>'.
1.714 raeburn 1269: '<th>'.&mt('Name').'</th>'.
1270: '<th>'.&mt('Last modified').'</th>'.
1271: '<th>'.&mt('Published?').'</th>'.
1.712 raeburn 1272: &Apache::loncommon::end_data_table_header_row()."\n";
1273: $count = &recurse_crsauthored(0,\@dirs_by_depth,\@files_by_depth,'/',$startcount,
1274: $count,\$display,\%parent,\%children,$readonly,
1.714 raeburn 1275: $formname,$chkname,\$lastcontainer,\%resfiles);
1.712 raeburn 1276: $display .= &Apache::loncommon::end_data_table().'</fieldset>';
1277: unless ($readonly) {
1278: $display .= '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
1279: '<div>'.
1280: '<input type="submit" name="copyauthored" value="'.&mt("Copy Selected Content").'" />'.
1281: '</div>';
1282: }
1283: $display .= &Apache::loncourserespicker::respicker_javascript($startcount,$count,$context,$formname,\%children,
1284: \%hierarchy,\@checked_maps,$home,$chkname);
1285: $r->print($display);
1286: }
1287: $r->print(&endContentScreen());
1288: }
1289:
1290: sub recurse_crsauthored {
1291: my ($currdepth,$dirs_by_depth,$files_by_depth,$currpath,$startcount,$count,$displayref,
1.714 raeburn 1292: $parent,$children,$readonly,$formname,$chkname,$lastcontainerref,$resfilesref) = @_;
1293: return $count unless ((ref($dirs_by_depth) eq 'ARRAY') && (ref($files_by_depth) eq 'ARRAY') &&
1294: (ref($resfilesref) eq 'HASH'));
1.712 raeburn 1295: my ($disabled,$hasdirs,$hasfiles,%unique,%dirs,%files);
1296: if ((ref($dirs_by_depth->[$currdepth]) eq 'HASH') &&
1297: (ref($dirs_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1298: $hasdirs = 1;
1299: %dirs = %{$dirs_by_depth->[$currdepth]{$currpath}};
1300: map { $unique{$_} = 1; } keys(%dirs);
1301: }
1302: if ((ref($files_by_depth->[$currdepth]) eq 'HASH') &&
1303: (ref($files_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1304: $hasfiles = 1;
1305: %files = %{$files_by_depth->[$currdepth]{$currpath}};
1306: map { $unique{$_} = 1; } keys(%files);
1307: }
1308: if ($readonly) {
1309: $disabled = ' disabled="disabled"';
1310: }
1311: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
1312: my $whitespace =
1313: '<img src="'.$location.'/whitespace_21.gif" class="LC_docs_spacer" alt="" />';
1314: $parent->{$currdepth} = $$lastcontainerref;
1315: foreach my $item (sort { lc($a) cmp lc($b) } (keys(%unique))) {
1316: next if ($item eq '');
1317: my $currelem;
1318: if ($hasdirs && exists($dirs{$item})) {
1319: $count ++;
1320: my $deeper = $currdepth+1;
1321: my ($newpath,$showpath);
1322: if ($currpath eq '/') {
1323: $newpath = $item;
1324: $showpath = $currpath.$item.'/';
1325: } else {
1326: $newpath = $currpath.'/'.$item;
1327: $showpath = '/'.$currpath.'/'.$item.'/';
1328: }
1329: $currelem = $count+$startcount;
1330: $$lastcontainerref = $currelem;
1331: $children->{$parent->{$currdepth}} .= $currelem.':';
1332: my $icon = 'src="'.$location.'/navmap.folder.open.gif" alt="'.&mt('Folder').'"';
1333: $$displayref .= &Apache::loncommon::start_data_table_row().
1334: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath).'" '.
1335: 'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" '.
1336: $disabled.' /></td><td>';
1337: for (my $i=0; $i<$currdepth; $i++) {
1338: $$displayref .= "$whitespace\n";
1339: }
1.714 raeburn 1340: $$displayref .= '<img '.$icon.' /> '.$item.'</td><td> </td><td> </td>'.
1.712 raeburn 1341: &Apache::loncommon::end_data_table_row()."\n";
1342: $count = &recurse_crsauthored($deeper,$dirs_by_depth,$files_by_depth,$newpath,
1343: $startcount,$count,$displayref,$parent,$children,
1.714 raeburn 1344: $readonly,$formname,$chkname,$lastcontainerref,$resfilesref);
1.712 raeburn 1345: }
1346: if ($hasfiles && exists($files{$item})) {
1347: $count ++;
1348: $currelem = $count+$startcount;
1349: $children->{$parent->{$currdepth}} .= $currelem.':';
1350: my $icon = 'src="'.&Apache::loncommon::icon($item).'"';
1351: my ($ext) = ($item =~ /\.([^.]+)$/);
1352: my $alttext;
1353: if (lc($ext) eq 'problem') {
1354: $alttext = ' alt="'.&mt('Problem Icon').'"';
1355: } elsif ($ext =~ /^x?html?$/i) {
1356: $alttext = ' alt="'.&mt('Web Page Icon').'"';
1357: } elsif ($ext =~ /^(jpg|gif|png|svg|jpeg)$/) {
1358: $alttext = ' alt="'.&mt('Image Icon').'"';
1359: } else {
1360: $alttext = ' alt="'.&mt('Resource Icon').'"';
1361: }
1362: my $showpath;
1363: if ($currpath eq '/') {
1364: $showpath = $currpath;
1365: } else {
1366: $showpath = "/$currpath/";
1367: }
1.714 raeburn 1368: my ($published,$lastmod);
1369: if ((ref($resfilesref->{$currpath})) && (exists($resfilesref->{$currpath}{$item}))) {
1370: $published = '<img src="'.$location.'/navmap.correct.gif" alt="'.&mt('yes').'" />';
1371: } else {
1372: $published = '<img src="'.$location.'/navmap.wrong.gif" alt="'.&mt('no').'" />';
1373: }
1.712 raeburn 1374: $$displayref .= &Apache::loncommon::start_data_table_row().
1375: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath.$item).'" '.
1376: 'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" '.
1377: $disabled.' /></td><td>';
1378: for (my $i=0; $i<$currdepth; $i++) {
1379: $$displayref .= "$whitespace\n";
1380: }
1381: $$displayref .= '<img '.$icon.$alttext.' /> '.$item.'</td>'.
1.714 raeburn 1382: '<td>'.&Apache::lonlocal::locallocaltime($files{$item}).'</td>'.
1383: '<td style="text-align: center;">'.$published.'</td>'.
1.712 raeburn 1384: &Apache::loncommon::end_data_table_row()."\n";
1385: }
1386: }
1387: $$lastcontainerref = $parent->{$currdepth};
1388: return $count;
1389: }
1390:
1.715 raeburn 1391: sub courseresource_options {
1392: my ($formname,$numpub) = @_;
1393: my %lt = &Apache::lonlocal::texthash(
1394: 'default' => 'System wide - can be used for any courses system wide',
1395: 'domain' => 'Domain only - use limited to courses in the domain',
1396: 'custom' => 'Customized right of use ...',
1397: 'public' => 'Public - no authentication or authorization required for use',
1398: 'closed' => 'Closed - XML source is closed to everyone',
1399: 'open' => 'Open - XML source is open to people who want to use it',
1400: 'sel' => 'Select',
1401: );
1402: my $output;
1403: if ($numpub) {
1404: $output .= '<div class="LC_left_float">'.
1405: '<fieldset><legend>'.&mt('Published Resources').'</legend>'.
1406: &mt('[quant,_1,file] in Course Authoring Space also exist in Resource Space.',
1407: $numpub).'</br />'.
1408: &mt('Publish copied files in selected Authoring Space?').': '."\n".
1409: '<label><input type="radio" name="respublish" checked="checked" value="1" />'.
1410: &mt('Yes').'</label>'."\n".
1411: '<label><input type="radio" name="respublish" value="0" />'.
1412: &mt('No').'</label>'."\n".
1413: '</fieldset></div>'."\n";
1414: }
1415: $output .= '<div class="LC_left_float">'.
1416: '<fieldset><legend>'.&mt('Distribution to set in metadata').'</legend>'.
1417: &mt('Copyright').': '.
1418: '<select name="copyright" onchange="showHideCustom(this,'."'LC_customfile'".');">'."\n".
1419: '<option value="default" selected="selected">'.$lt{'default'}.'</option>'."\n".
1420: '<option value="domain">'.$lt{'domain'}.'</option>'."\n".
1421: '<option value="public">'.$lt{'public'}.'</option>'."\n".
1422: '<option value="custom">'.$lt{'custom'}.'</option>'."\n".
1423: '</select><div id="LC_customfile" style="padding:0;clear:both;margin:0;border:0;display:none">'."\n".
1424: '<input type="text" name="customrights" size="60" value="" />'.
1425: '<a href="javascript:openbrowser('."'$formname','customrights','rights'".');">'.
1426: $lt{'sel'}.'</a></div><br />'."\n".
1427: &mt('Source').' :'.
1428: '<select name="sourceavail">'."\n".
1429: '<option value="closed" selected="selected">'.$lt{'closed'}.'</option>'."\n".
1430: '<option value="open">'.$lt{'open'}.'</option>'."\n".
1431: '</select><br />'."\n".
1432: '</fieldset></div>'."\n";
1433: return $output;
1434: }
1435:
1.717 raeburn 1436: sub crsres_fixup_meta {
1437: my ($dest,$coursenum,$coursedom,$ca,$cd,$copyright,$customdistfile,$sourceavail,$checkdeps) = @_;
1438: return unless (ref($checkdeps) eq 'HASH');
1439: if (open(my $fh,'<',$dest.'.meta')) {
1440: my ($output,$now,$setsourceavail);
1441: $now = time;
1442: if (($dest =~ /\.(xml|html|htm|xhtml|xhtm)$/i) || ($dest =~ /$LONCAPA::assess_re/)) {
1443: $setsourceavail = 1;
1444: }
1445: while (my $line=<$fh>) {
1446: chomp($line);
1447: if ($line eq "<authorspace>$coursenum:$coursedom</authorspace>") {
1448: $output .= "<authorspace>$ca:$cd</authorspace>\n";
1449: } elsif ($line eq '<copyright>custom</copyright>') {
1450: $output .= "<copyright>$copyright</copyright>\n";
1451: } elsif ($line =~ m{^<creationdate>\d+</creationdate>$}) {
1452: $output .= "<creationdate>$now</creationdate>\n";
1453: } elsif ($line eq "<customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>") {
1454: $output .= "<customdistributionfile>$customdistfile</customdistributionfile>\n";
1455: } elsif ($line =~ m{^<sourceavail>(open|closed)</sourceavail>$}) {
1456: if ($setsourceavail) {
1457: $output .= "<sourceavail>$sourceavail</sourceavail>\n";
1458: }
1459: } elsif ($line eq "<domain>$coursedom</domain>") {
1460: $output .= "<domain>$cd</domain>\n";
1461: } elsif ($line =~ m{^<lastrevisiondate>\d+</lastrevisiondate>$}) {
1462: $output .= "<lastrevisiondate>$now</lastrevisiondate>\n";
1463: } elsif ($line =~ m{^<modifyinguser>$match_username:$match_domain</modifyinguser>$}) {
1464: $output .= "<modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>\n";
1465: } elsif ($line eq "<owner>$coursenum:$coursedom</owner>") {
1466: $output .= "<owner>$ca:$cd</owner>\n";
1467: } elsif ($line =~ m{^<dependencies>(.+)</dependencies>$}) {
1468: my @deps = split(/\s*,\s*/,$1);
1469: my @newdeps;
1470: my $changed = 0;
1471: foreach my $dep (@deps) {
1472: if ($dep =~ m{^/res/$coursedom/$coursenum/(.+)$}) {
1473: my $rest = $1;
1474: push(@newdeps,"/res/$cd/$ca/$rest");
1475: $checkdeps->{$rest} = 1;
1476: $changed ++;
1477: } else {
1478: push(@newdeps,$dep);
1479: }
1480: }
1481: if ($changed) {
1482: $output .= '<dependencies>'.join(',',@newdeps).'</dependencies>'."\n";
1483: }
1484: } else {
1485: $output .= "$line\n";
1486: }
1487: }
1488: close($fh);
1489: if (open(my $fh,'>',$dest.'.meta')) {
1490: print $fh $output;
1491: close($fh);
1492: }
1493: }
1494: }
1495:
1496: sub crsres_fixup {
1497: my ($dest,$coursenum,$coursedom,$ca,$cd,$subdir) = @_;
1498: my $outstring='';
1499: my $changes = 0;
1500: my @parser;
1501: $parser[0]=HTML::LCParser->new($dest);
1502: $parser[-1]->xml_mode(1);
1503: my $token;
1504: while (@parser) {
1505: while ($token=$parser[-1]->get_token) {
1506: if ($token->[0] eq 'S') {
1507: my $tag=$token->[1];
1508: my $lctag=lc($tag);
1509: my %parms=%{$token->[2]};
1510: foreach my $type ('src','href','background','bgimg') {
1511: foreach my $key (keys(%parms)) {
1512: if ($key =~ /^$type$/i) {
1513: next if (($lctag eq 'img') && ($type eq 'src') &&
1514: ($parms{$key} =~ m{^data\:image/gif;base64,}));
1515: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1516: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
1517: $changes ++;
1518: }
1519: }
1520: }
1521: }
1522: # probably a <randomlabel> image type <label>
1523: # or a <image> tag inside <imageresponse> or <drawimage>
1524: if (($lctag eq 'label' && defined($parms{'description'}))
1525: || ($lctag eq 'image') || ($lctag eq 'import')) {
1526: my $next_token=$parser[-1]->get_token();
1527: if ($next_token->[0] eq 'T') {
1528: $next_token->[1] =~ s/[\n\r\f]+//g;
1529: if ($next_token->[1] =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1530: $next_token->[1] =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
1531: $changes ++;
1532: }
1533: }
1534: $parser[-1]->unget_token($next_token);
1535: }
1536: if ($lctag eq 'applet') {
1537: my $havecodebase=0;
1538: foreach my $key (keys(%parms)) {
1539: if (lc($key) eq 'codebase') {
1540: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1541: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
1542: $changes ++;
1543: }
1544: $havecodebase = 1;
1545: }
1546: }
1547: unless ($havecodebase) {
1548: foreach my $key (keys(%parms)) {
1549: if ($key =~ /(archive|code|object)/i) {
1550: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1551: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/si};
1552: $changes ++;
1553: }
1554: }
1555: }
1556: }
1557: }
1558: my $newparmstring='';
1559: my $endtag='';
1560: foreach my $parkey (keys(%parms)) {
1561: if ($parkey eq '/') {
1562: $endtag=' /';
1563: } else {
1564: my $quote=($parms{$parkey}=~/\"/?"'":'"');
1565: $newparmstring.=' '.$parkey.'='.$quote.$parms{$parkey}.$quote;
1566: }
1567: }
1568: if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
1569: $outstring.='<'.$tag.$newparmstring.$endtag.'>';
1570: if ($lctag eq 'm' || $lctag eq 'answer' || $lctag eq 'display' ||
1571: $lctag eq 'tex') {
1572: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
1573: } elsif ($lctag eq 'script') {
1574: if ($parms{'type'} eq 'loncapa/perl') {
1575: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
1576: } else {
1577: my $needsupdate;
1578: my $script = &Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
1579: if ($script =~ m{\.addMediaSrc\((["'])((?!\1).+)\1\);}) {
1580: my $src = $2;
1581: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1582: $needsupdate = 1;
1583: }
1584: }
1585: if ($script =~ /\(document,\s*(['"])script\1,\s*\[([^\]]+)\]\);/s) {
1586: my $scriptslist = $2;
1587: my @srcs = split(/\s*,\s*/,$scriptslist);
1588: foreach my $src (@srcs) {
1589: if ($src =~ /(["'])(?:(?!\1).)+\.js\1/) {
1590: my $quote = $1;
1591: my ($url) = ($src =~ m/\Q$quote\E([^$quote]+)\Q$quote\E/);
1592: if ($url =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1593: $needsupdate = 1;
1594: }
1595: }
1596: }
1597: }
1598: if ($script =~ m{loadScript\(\s*(['"])((?:(?!\1).)+\.js)\1,\s*function}is) {
1599: my $src = $2;
1600: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1601: $needsupdate = 1;
1602: }
1603: }
1604: if ($needsupdate) {
1605: $script =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/gsi};
1606: $changes ++;
1607: }
1608: $outstring .= $script;
1609: }
1610: }
1611: } elsif ($token->[0] eq 'E') {
1612: if ($token->[2]) {
1613: unless ($token->[1] eq 'allow') {
1614: $outstring.='</'.$token->[1].'>';
1615: }
1616: }
1617: } else {
1618: $outstring.=$token->[1];
1619: }
1620: }
1621: pop(@parser);
1622: }
1623: if ($changes) {
1624: if (open(my $fh,'>',$dest)) {
1625: print $fh $outstring;
1626: close($fh);
1627: }
1628: }
1629: }
1630:
1.329 droeschl 1631: sub group_import {
1.598 raeburn 1632: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 1633: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
1634: %removeparam,$importuploaded,$fixuperrors);
1635: $allmaps = {};
1.329 droeschl 1636: while (@files) {
1637: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 1638: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 1639: && ($caller eq 'londocs')
1640: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 1641:
1.329 droeschl 1642: my $errtext = '';
1643: my $fatal = 0;
1644: my $newmapstr = '<map>'."\n".
1645: '<resource id="1" src="" type="start"></resource>'."\n".
1646: '<link from="1" to="2" index="1"></link>'."\n".
1647: '<resource id="2" src="" type="finish"></resource>'."\n".
1648: '</map>';
1649: $env{'form.output'}=$newmapstr;
1650: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1651: 'output',$1.$2);
1.534 raeburn 1652: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 1653: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
1654: $fatal = 2;
1655: }
1656: if ($fatal) {
1657: return ($errtext,$fatal);
1658: }
1659: }
1660: if ($url) {
1.626 raeburn 1661: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 1662: $url = $1;
1663: my $marker = $2;
1664: my $info = $3;
1.699 raeburn 1665: my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.642 raeburn 1666: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 1667: my @toolinfo = split(/:/,$info);
1668: if ($residx) {
1.604 raeburn 1669: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 1670: $toolid = $toolsettings{'id'};
1671: } else {
1.604 raeburn 1672: $toolid = shift(@toolinfo);
1.598 raeburn 1673: }
1.699 raeburn 1674: if ($toolid =~ /^c/) {
1675: $tooltype = 'crs';
1676: $toolprefix = 'c';
1677: } else {
1678: $tooltype = 'dom';
1679: }
1.598 raeburn 1680: $toolid =~ s/\D//g;
1.604 raeburn 1681: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 1682: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
1683: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 1684: foreach my $item (@extras) {
1685: $toolhash{$item} = &unescape($toolhash{$item});
1686: }
1.645 raeburn 1687: if ($folder =~ /^supplemental/) {
1.648 raeburn 1688: delete($toolhash{'gradable'});
1689: } else {
1690: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 1691: }
1.598 raeburn 1692: if (ref($ltitoolsref) eq 'HASH') {
1.699 raeburn 1693: if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
1694: if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
1695: my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
1696: my @deleted;
1697: $toolhash{'id'} = $toolprefix.$toolid;
1698: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
1699: ($toolhash{'target'} eq 'window')) {
1700: if ($toolhash{'target'} eq 'window') {
1701: foreach my $item ('width','height') {
1702: $toolhash{$item} =~ s/^\s+//;
1703: $toolhash{$item} =~ s/\s+$//;
1704: if ($toolhash{$item} =~ /\D/) {
1705: delete($toolhash{$item});
1706: if ($residx) {
1707: if ($toolsettings{$item}) {
1708: push(@deleted,$item);
1709: }
1.624 raeburn 1710: }
1711: }
1712: }
1.604 raeburn 1713: }
1.699 raeburn 1714: } elsif ($residx) {
1715: $toolhash{'target'} = $toolsettings{'target'};
1716: if ($toolhash{'target'} eq 'window') {
1717: foreach my $item ('width','height') {
1718: $toolhash{$item} = $toolsettings{$item};
1719: }
1720: }
1721: } elsif (ref($tools{'display'}) eq 'HASH') {
1722: $toolhash{'target'} = $tools{'display'}{'target'};
1723: if ($toolhash{'target'} eq 'window') {
1724: $toolhash{'width'} = $tools{'display'}{'width'};
1725: $toolhash{'height'} = $tools{'display'}{'height'};
1.624 raeburn 1726: }
1.604 raeburn 1727: }
1.699 raeburn 1728: if ($toolhash{'target'} eq 'iframe') {
1729: foreach my $item ('width','height','linktext','explanation') {
1730: delete($toolhash{$item});
1731: if ($residx) {
1732: if ($toolsettings{$item}) {
1733: push(@deleted,$item);
1734: }
1.624 raeburn 1735: }
1.604 raeburn 1736: }
1.699 raeburn 1737: } elsif ($toolhash{'target'} eq 'tab') {
1738: foreach my $item ('width','height') {
1739: delete($toolhash{$item});
1740: if ($residx) {
1741: if ($toolsettings{$item}) {
1742: push(@deleted,$item);
1743: }
1.628 raeburn 1744: }
1745: }
1746: }
1.699 raeburn 1747: if (ref($tools{'crsconf'}) eq 'HASH') {
1748: foreach my $item ('label','title','linktext','explanation') {
1749: my $crsitem;
1750: if (($item eq 'label') || ($item eq 'title')) {
1751: $crsitem = 'crs'.$item;
1752: } else {
1753: $crsitem = $item;
1754: }
1755: if ($tools{'crsconf'}{$item}) {
1756: $toolhash{$crsitem} =~ s/^\s+//;
1757: $toolhash{$crsitem} =~ s/\s+$//;
1758: if ($toolhash{$crsitem} eq '') {
1759: delete($toolhash{$crsitem});
1760: }
1761: } else {
1.624 raeburn 1762: delete($toolhash{$crsitem});
1.604 raeburn 1763: }
1.699 raeburn 1764: if (($residx) && (exists($toolsettings{$crsitem}))) {
1765: unless (exists($toolhash{$crsitem})) {
1766: push(@deleted,$crsitem);
1767: }
1768: }
1.604 raeburn 1769: }
1.699 raeburn 1770: }
1771: if ($toolhash{'passback'}) {
1772: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1773: $toolhash{'gradesecret'} = $gradesecret;
1774: $toolhash{'gradesecretdate'} = time;
1775: }
1776: if ($toolhash{'roster'}) {
1777: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1778: $toolhash{'rostersecret'} = $rostersecret;
1779: $toolhash{'rostersecretdate'} = time;
1780: }
1781: my $changegradable;
1782: if (($residx) && ($folder =~ /^default/)) {
1783: if ($toolsettings{'gradable'}) {
1784: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1785: push(@deleted,'gradable');
1786: $changegradable = 1;
1.604 raeburn 1787: }
1.699 raeburn 1788: } elsif ($toolhash{'gradable'}) {
1789: $changegradable = 1;
1.604 raeburn 1790: }
1.699 raeburn 1791: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 1792: $changegradable = 1;
1.699 raeburn 1793: if ($toolsettings{'gradable'}) {
1794: $toolhash{'gradable'} = 1;
1795: }
1.645 raeburn 1796: }
1.648 raeburn 1797: }
1.699 raeburn 1798: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1799: if ($putres eq 'ok') {
1800: if (@deleted) {
1801: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648 raeburn 1802: }
1.699 raeburn 1803: if (($changegradable) && ($folder =~ /^default/)) {
1804: my $val;
1805: if ($toolhash{'gradable'}) {
1806: $val = 'yes';
1807: } else {
1808: $val = 'no';
1809: }
1810: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
1811: 'string_yesno');
1812: &remember_parms($residx,'gradable','set',$val);
1.645 raeburn 1813: }
1.699 raeburn 1814: } else {
1815: return (&mt('Failed to save update to external tool.'),1);
1.645 raeburn 1816: }
1.604 raeburn 1817: }
1.598 raeburn 1818: }
1819: }
1820: }
1.529 raeburn 1821: if (($caller eq 'londocs') &&
1822: ($folder =~ /^default/)) {
1.534 raeburn 1823: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 1824: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
1825: my $cid = $coursedom.'_'.$coursenum;
1826: $allmaps =
1827: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1828: $chome,$cid);
1829: $donechk = 1;
1830: }
1831: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 1832: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1833: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 1834: $importuploaded = 1;
1835: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
1836: next if ($allmaps->{$url});
1837: }
1838: }
1.344 bisitz 1839: if (!$residx
1.329 droeschl 1840: || defined($LONCAPA::map::zombies[$residx])) {
1841: $residx = &LONCAPA::map::getresidx($url,$residx);
1842: push(@LONCAPA::map::order, $residx);
1843: }
1844: my $ext = 'false';
1845: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 1846: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
1847: my $filepath = $1;
1.675 raeburn 1848: my $fname;
1849: if ($name eq '') {
1850: $name = &mt('Web Page');
1.534 raeburn 1851: $fname = 'web';
1852: } else {
1.675 raeburn 1853: $fname = $name;
1854: $fname=&Apache::lonnet::clean_filename($fname);
1855: if ($fname eq '') {
1856: $fname = 'web';
1857: } elsif (length($fname) > 15) {
1858: $fname = substr($fname,0,14);
1859: }
1.534 raeburn 1860: }
1.675 raeburn 1861: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 1862: my $initialtext = &mt('Replace with your own content.');
1863: my $newhtml = <<END;
1.545 raeburn 1864: <html>
1.534 raeburn 1865: <head>
1.675 raeburn 1866: <title>$title</title>
1.534 raeburn 1867: </head>
1868: <body bgcolor="#ffffff">
1869: $initialtext
1870: </body>
1871: </html>
1872: END
1873: $env{'form.output'}=$newhtml;
1.630 raeburn 1874: my $result =
1.534 raeburn 1875: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1876: 'output',
1877: "$filepath/$residx/$fname.html");
1878: if ($result =~ m{^/uploaded/}) {
1879: $url = $result;
1880: if ($filepath =~ /^supplemental/) {
1881: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1882: $env{'user.domain'}.'___&&&___'.$name;
1883: }
1884: } else {
1885: return (&mt('Failed to save new web page.'),1);
1886: }
1887: }
1.675 raeburn 1888: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 1889: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 1890: $LONCAPA::map::resources[$residx] =
1.329 droeschl 1891: join(':', ($name, $url, $ext, 'normal', 'res'));
1892: }
1893: }
1.529 raeburn 1894: if ($importuploaded) {
1895: my %import_errors;
1896: my %updated = (
1897: removefrommap => \%removefrommap,
1898: removeparam => \%removeparam,
1899: );
1.533 raeburn 1900: my ($result,$msgsarray,$lockerror) =
1901: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 1902: if (keys(%import_errors) > 0) {
1.530 raeburn 1903: $fixuperrors =
1.529 raeburn 1904: '<p span class="LC_warning">'."\n".
1905: &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".
1906: '<ul>'."\n";
1907: foreach my $key (sort(keys(%import_errors))) {
1908: $fixuperrors .= '<li>'.$key.'</li>'."\n";
1909: }
1910: $fixuperrors .= '</ul></p>'."\n";
1911: }
1.533 raeburn 1912: if (ref($msgsarray) eq 'ARRAY') {
1913: if (@{$msgsarray} > 0) {
1914: $fixuperrors .= '<p class="LC_info">'.
1915: join('<br />',@{$msgsarray}).
1916: '</p>';
1917: }
1918: }
1919: if ($lockerror) {
1920: $fixuperrors .= '<p class="LC_error">'.
1921: $lockerror.
1922: '</p>';
1923: }
1.529 raeburn 1924: }
1925: my ($errtext,$fatal) =
1926: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 1927: unless ($fatal) {
1928: if ($folder =~ /^supplemental/) {
1.561 raeburn 1929: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1930: $folder.'.'.$container);
1.557 raeburn 1931: }
1932: }
1.529 raeburn 1933: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 1934: }
1935:
1936: sub log_docs {
1.494 raeburn 1937: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 1938: }
1939:
1940: {
1941: my @oldresources=();
1942: my @oldorder=();
1943: my $parmidx;
1944: my %parmaction=();
1945: my %parmvalue=();
1946: my $changedflag;
1947:
1948: sub snapshotbefore {
1949: @oldresources=@LONCAPA::map::resources;
1950: @oldorder=@LONCAPA::map::order;
1951: $parmidx=undef;
1952: %parmaction=();
1953: %parmvalue=();
1954: $changedflag=0;
1955: }
1956:
1957: sub remember_parms {
1958: my ($idx,$parameter,$action,$value)=@_;
1959: $parmidx=$idx;
1960: $parmaction{$parameter}=$action;
1961: $parmvalue{$parameter}=$value;
1962: $changedflag=1;
1963: }
1964:
1965: sub log_differences {
1966: my ($plain)=@_;
1967: my %storehash=('folder' => $plain,
1968: 'currentfolder' => $env{'form.folder'});
1969: if ($parmidx) {
1970: $storehash{'parameter_res'}=$oldresources[$parmidx];
1971: foreach my $parm (keys(%parmaction)) {
1972: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1973: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1974: }
1975: }
1976: my $maxidx=$#oldresources;
1977: if ($#LONCAPA::map::resources>$#oldresources) {
1978: $maxidx=$#LONCAPA::map::resources;
1979: }
1980: for (my $idx=0; $idx<=$maxidx; $idx++) {
1981: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1982: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1983: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1984: $changedflag=1;
1985: }
1986: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1987: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1988: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1989: $changedflag=1;
1990: }
1991: }
1992: $storehash{'maxidx'}=$maxidx;
1993: if ($changedflag) { &log_docs(\%storehash); }
1994: }
1995: }
1996:
1997: sub docs_change_log {
1.611 raeburn 1998: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 1999: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 2000: my $navmap;
1.483 raeburn 2001: my $js = '<script type="text/javascript">'."\n".
2002: '// <![CDATA['."\n".
2003: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 2004: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 2005: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 2006: &history_tab_js()."\n".
1.484 raeburn 2007: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 2008: '// ]]>'."\n".
2009: '</script>'."\n";
1.484 raeburn 2010: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
2011: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 2012: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 2013: my %orderhash;
2014: my $container='sequence';
2015: my $pathitem;
1.519 raeburn 2016: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 2017: $container='page';
2018: }
1.519 raeburn 2019: my $folderpath=$env{'form.folderpath'};
2020: if ($folderpath eq '') {
1.617 raeburn 2021: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 2022: }
1.617 raeburn 2023: undef($navmap);
1.519 raeburn 2024: $pathitem = '<input type="hidden" name="folderpath" value="'.
2025: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 2026: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
2027: my $jumpto = $readfile;
2028: $jumpto =~ s{^/}{};
2029: my $tid = 1;
1.489 raeburn 2030: if ($supplementalflag) {
2031: $tid = 2;
2032: }
1.630 raeburn 2033: my ($breadcrumbtrail) =
1.509 raeburn 2034: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 2035: $r->print($breadcrumbtrail.
2036: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
2037: $readfile));
1.329 droeschl 2038: my %docslog=&Apache::lonnet::dump('nohist_docslog',
2039: $env{'course.'.$env{'request.course.id'}.'.domain'},
2040: $env{'course.'.$env{'request.course.id'}.'.num'});
2041:
2042: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
2043:
2044: my %saveable_parameters = ('show' => 'scalar',);
2045: &Apache::loncommon::store_course_settings('docs_log',
2046: \%saveable_parameters);
2047: &Apache::loncommon::restore_course_settings('docs_log',
2048: \%saveable_parameters);
2049: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 2050: # FIXME: internationalization seems wrong here
1.329 droeschl 2051: my %lt=('hiddenresource' => 'Resources hidden',
2052: 'encrypturl' => 'URL hidden',
2053: 'randompick' => 'Randomly pick',
2054: 'randomorder' => 'Randomly ordered',
1.645 raeburn 2055: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 2056: 'set' => 'set to',
2057: 'del' => 'deleted');
1.484 raeburn 2058: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
2059: $pathitem."\n".
2060: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
2061: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
2062: $r->print('<div class="LC_left_float">'.
2063: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
2064: &makedocslogform($filter,1).
2065: '</fieldset></div><br clear="all" />');
1.329 droeschl 2066: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
2067: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
2068: &mt('After').'</th>'.
2069: &Apache::loncommon::end_data_table_header_row());
2070: my $shown=0;
2071: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
2072: if ($env{'form.displayfilter'} eq 'currentfolder') {
2073: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
2074: }
2075: my @changes=keys(%{$docslog{$id}{'logentry'}});
2076: if ($env{'form.displayfilter'} eq 'containing') {
2077: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
2078: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
2079: foreach my $key (@changes) {
2080: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
2081: }
1.344 bisitz 2082: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 2083: }
2084: my $count = 0;
2085: my $time =
2086: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
2087: my $plainname =
2088: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
2089: $docslog{$id}{'exe_udom'});
2090: my $about_me_link =
2091: &Apache::loncommon::aboutmewrapper($plainname,
2092: $docslog{$id}{'exe_uname'},
2093: $docslog{$id}{'exe_udom'});
2094: my $send_msg_link='';
2095: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
2096: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
2097: $send_msg_link ='<br />'.
2098: &Apache::loncommon::messagewrapper(&mt('Send message'),
2099: $docslog{$id}{'exe_uname'},
2100: $docslog{$id}{'exe_udom'});
2101: }
2102: $r->print(&Apache::loncommon::start_data_table_row());
2103: $r->print('<td>'.$time.'</td>
2104: <td>'.$about_me_link.
2105: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
2106: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
2107: $send_msg_link.'</td><td>'.
2108: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 2109: my $is_supp = 0;
2110: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
2111: $is_supp = 1;
2112: }
1.329 droeschl 2113: # Before
2114: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2115: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
2116: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
2117: if ($oldname ne $newname) {
1.488 raeburn 2118: my $shown = &LONCAPA::map::qtescape($oldname);
2119: if ($is_supp) {
2120: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2121: }
2122: $r->print($shown);
1.329 droeschl 2123: }
2124: }
2125: $r->print('<ul>');
2126: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2127: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 2128: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
2129: if ($is_supp) {
2130: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2131: }
2132: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 2133: }
2134: }
2135: $r->print('</ul>');
2136: # After
2137: $r->print('</td><td>');
2138:
2139: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2140: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
2141: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
2142: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 2143: my $shown = &LONCAPA::map::qtescape($newname);
2144: if ($is_supp) {
2145: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
2146: }
2147: $r->print($shown);
1.329 droeschl 2148: }
1.364 bisitz 2149: }
1.329 droeschl 2150: $r->print('<ul>');
2151: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2152: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 2153: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
2154: if ($is_supp) {
2155: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2156: }
2157: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 2158: }
2159: }
2160: $r->print('</ul>');
2161: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 2162: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
2163: if ($title eq '') {
2164: ($title) = ($url =~ m{/([^/]+)$});
1.695 raeburn 2165: } elsif ($is_supp) {
2166: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 2167: }
2168: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 2169: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 2170: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 2171: # FIXME: internationalization seems wrong here
1.329 droeschl 2172: $r->print('<li>'.
2173: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
2174: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
2175: .'</li>');
2176: }
2177: }
2178: $r->print('</ul>');
2179: }
2180: # End
2181: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
2182: $shown++;
2183: if (!($env{'form.show'} eq &mt('all')
2184: || $shown<=$env{'form.show'})) { last; }
2185: }
1.484 raeburn 2186: $r->print(&Apache::loncommon::end_data_table()."\n".
2187: &makesimpleeditform($pathitem)."\n".
2188: '</div></div>');
2189: $r->print(&endContentScreen());
1.329 droeschl 2190: }
2191:
2192: sub update_paste_buffer {
1.492 raeburn 2193: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 2194: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 2195: if ($env{'form.multiremove'}) {
2196: $env{'form.multiremove'} =~ s/,$//;
2197: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
2198: }
2199: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
2200: if ($env{'form.multicut'}) {
2201: $env{'form.multicut'} =~ s/,$//;
2202: foreach my $item (split(/,/,$env{'form.multicut'})) {
2203: unless ($removals{$item}) {
2204: $cuts{$item} = 1;
2205: push(@possibles,$item.':cut');
2206: }
2207: }
2208: }
2209: if ($env{'form.multicopy'}) {
2210: $env{'form.multicopy'} =~ s/,$//;
2211: foreach my $item (split(/,/,$env{'form.multicopy'})) {
2212: unless ($removals{$item} || $cuts{$item}) {
2213: push(@possibles,$item.':copy');
2214: }
2215: }
2216: }
2217: } elsif ($env{'form.markcopy'}) {
2218: @possibles = split(/,/,$env{'form.markcopy'});
2219: }
1.329 droeschl 2220:
1.538 raeburn 2221: return if (@possibles == 0);
1.329 droeschl 2222: return if (!defined($env{'form.copyfolder'}));
2223:
2224: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2225: $env{'form.copyfolder'});
1.538 raeburn 2226: return if ($fatal);
2227:
2228: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 2229:
1.538 raeburn 2230: # Retrieve current paste buffer suffixes.
2231: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2232: my (%pasteurls,@newpaste);
2233:
2234: # Construct identifiers for current contents of user's paste buffer
2235: if (@currpaste) {
2236: foreach my $suffix (@currpaste) {
1.667 raeburn 2237: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
2238: my $url = $env{'docs.markedcopy_url_'.$suffix};
2239: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
2240: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
2241: ($url ne '')) {
2242: if ($url eq '/res/lib/templates/simpleproblem.problem') {
2243: $pasteurls{$cid.'_'.$mapidx} = 1;
2244: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
2245: $pasteurls{$url} = 1;
2246: } else {
1.669 raeburn 2247: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 2248: }
2249: }
1.538 raeburn 2250: }
2251: }
2252:
2253: # Mark items for copying (skip any items already in user's paste buffer)
2254: my %addtoenv;
1.597 raeburn 2255:
2256: my @pathitems = split(/\&/,$env{'form.folderpath'});
2257: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 2258: my $ispage = $folderconf[5];
1.597 raeburn 2259:
1.538 raeburn 2260: foreach my $item (@possibles) {
2261: my ($orderidx,$cmd) = split(/:/,$item);
2262: next if ($orderidx =~ /\D/);
2263: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 2264: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 2265: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
2266: my %denied = &action_restrictions($coursenum,$coursedom,
2267: &LONCAPA::map::qtescape($url),
2268: $env{'form.folderpath'},\%curr_groups);
2269: next if ($denied{'copy'});
2270: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 2271: if ($url eq '/res/lib/templates/simpleproblem.problem') {
2272: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
2273: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
2274: next if (exists($pasteurls{$url}));
2275: } else {
2276: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
2277: }
1.538 raeburn 2278: my ($suffix,$errortxt,$locknotfreed) =
2279: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 2280: if ($suffix ne '') {
2281: push(@newpaste,$suffix);
2282: } else {
2283: if ($locknotfreed) {
2284: return $locknotfreed;
2285: }
1.538 raeburn 2286: }
2287: if (&is_supplemental_title($title)) {
2288: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
2289: ($title) = &Apache::loncommon::parse_supplemental_title($title);
2290: }
1.329 droeschl 2291:
1.538 raeburn 2292: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
2293: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
2294: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
2295: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 2296: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 2297: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
2298: my $prefix = $1;
2299: my $subdir =$2;
2300: if ($subdir eq '') {
2301: $subdir = $prefix;
1.492 raeburn 2302: }
1.538 raeburn 2303: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 2304: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
2305: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 2306: if (ref($hierarchy{$url}) eq 'HASH') {
2307: my ($nested,$nestednames);
2308: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
2309: $nested =~ s/\&$//;
2310: $nestednames =~ s/\Q___&&&___\E$//;
2311: if ($nested ne '') {
2312: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
2313: }
2314: if ($nestednames ne '') {
2315: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
2316: }
1.492 raeburn 2317: }
2318: }
1.591 raeburn 2319: if ($locknotfreed) {
2320: $output = $locknotfreed;
2321: last;
2322: }
1.492 raeburn 2323: }
1.538 raeburn 2324: if (@newpaste) {
2325: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
2326: }
1.492 raeburn 2327: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 2328: delete($env{'form.markcopy'});
1.591 raeburn 2329: return $output;
1.329 droeschl 2330: }
2331:
1.492 raeburn 2332: sub recurse_uploaded_maps {
2333: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
2334: if (ref($hierarchy->{$url}) eq 'HASH') {
2335: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
2336: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
2337: my (@uploaded,@names,%shorter);
2338: for (my $i=0; $i<@maps; $i++) {
2339: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
2340: if ($inner ne '') {
2341: push(@uploaded,$inner);
2342: push(@names,&escape($titles[$i]));
2343: $shorter{$maps[$i]} = $inner;
2344: }
2345: }
2346: $$nestref .= "$dir:".join(',',@uploaded).'&';
2347: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
2348: foreach my $map (@maps) {
2349: if ($shorter{$map} ne '') {
2350: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
2351: }
2352: }
2353: }
2354: return;
2355: }
2356:
1.329 droeschl 2357: sub print_paste_buffer {
1.492 raeburn 2358: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 2359: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 2360:
1.538 raeburn 2361: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
2362: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 2363: }
2364:
1.538 raeburn 2365: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1.704 raeburn 2366: my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
1.575 raeburn 2367: my $clipboardcount = 0;
1.488 raeburn 2368:
1.538 raeburn 2369: # Construct identifiers for current contents of user's paste buffer
2370: foreach my $suffix (@currpaste) {
2371: next if ($suffix =~ /\D/);
2372: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
2373: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 2374: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 2375: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
2376: ($url ne '')) {
1.575 raeburn 2377: $clipboardcount ++;
1.538 raeburn 2378: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.704 raeburn 2379: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
2380: $toolcnum,$marker);
1.538 raeburn 2381: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
2382: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
2383: $is_external = 1;
1.704 raeburn 2384: } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2385: ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1.598 raeburn 2386: $is_exttool = 1;
1.538 raeburn 2387: }
2388: if ($folder =~ /^supplemental/) {
2389: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
2390: unless ($canpaste) {
2391: $nopaste = &mt('Paste into Supplemental Content unavailable.');
2392: }
2393: } else {
2394: $canpaste = 1;
2395: }
2396: if ($canpaste) {
2397: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2398: my $srcdom = $1;
2399: my $srcnum = $2;
2400: my $rem = $3;
2401: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
2402: $othercourse = 1;
2403: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 2404: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 2405: } else {
2406: $canpaste = 0;
2407: $nopaste = &mt('Paste from another course unavailable.');
2408: }
2409: }
2410: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
2411: my $prefix = $1;
2412: $parent = $2;
2413: if ($folder !~ /^\Q$prefix\E/) {
2414: $areachange = 1;
2415: }
2416: $is_uploaded_map = 1;
1.492 raeburn 2417: }
1.597 raeburn 2418: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 2419: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 2420: if ($cid ne $env{'request.course.id'}) {
2421: my ($srcdom,$srcnum) = split(/_/,$cid);
2422: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.704 raeburn 2423: if ($is_exttool) {
2424: if ($toolcdom ne $coursedom) {
2425: $canpaste = 0;
2426: $nopaste = &mt('Paste from another domain unavailable.');
2427: } elsif ($toolcnum ne $coursenum) {
2428: my %toolsettings =
2429: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2430: my %tooltypes = &Apache::loncommon::usable_exttools();
2431: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2432: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2433: $canpaste = 0;
2434: $nopaste = &mt('Paste from another course unavailable.');
2435: } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
2436: unless ($checkedsameinst) {
2437: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2438: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2439: if ($intdom ne '') {
2440: my $internet_names =
2441: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2442: if (ref($internet_names) eq 'ARRAY') {
2443: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2444: $same_institution = 1;
2445: }
2446: }
2447: }
2448: $checkedsameinst = 1;
2449: }
2450: if ($same_institution) {
2451: $othercrs = '<br />'.&mt('(from another course)');
2452: } else {
2453: $nopaste = &mt('Paste from another course unavailable.');
2454: }
2455: } else {
2456: $othercrs = '<br />'.&mt('(from another course)');
2457: }
2458: }
1.627 raeburn 2459: }
1.596 raeburn 2460: } else {
2461: $canpaste = 0;
2462: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 2463: }
1.596 raeburn 2464: }
1.703 raeburn 2465: } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
2466: my ($audom,$auname) = ($1,$2);
2467: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2468: if (&Apache::lonnet::is_course($audom,$auname)) {
2469: $canpaste = 0;
2470: $nopaste = &mt('Paste from another course unavailable.');
2471: }
2472: }
1.492 raeburn 2473: }
1.596 raeburn 2474: if ($canpaste) {
2475: push(@pasteable,$suffix);
1.629 raeburn 2476: }
1.538 raeburn 2477: }
2478: my $buffer;
1.627 raeburn 2479: if ($is_external) {
1.538 raeburn 2480: $buffer = &mt('External Resource').': '.
2481: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
2482: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 2483: } elsif ($is_exttool) {
2484: $buffer = &mt('External Tool').': '.
2485: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 2486: } else {
2487: my $icon = &Apache::loncommon::icon($extension);
2488: if ($extension eq 'sequence' &&
2489: $url =~ m{/default_\d+\.sequence$}x) {
2490: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
2491: $icon .= '/navmap.folder.closed.gif';
2492: }
1.589 raeburn 2493: my $title = $env{'docs.markedcopy_title_'.$suffix};
2494: if ($title eq '') {
2495: ($title) = ($url =~ m{/([^/]+)$});
2496: }
1.538 raeburn 2497: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
2498: ': '.
2499: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 2500: &LONCAPA::map::qtescape($title));
1.538 raeburn 2501: }
2502: $pasteitems .= '<div class="LC_left_float">';
2503: my ($options,$onclick);
2504: if (($canpaste) && (!$areachange) && (!$othercourse) &&
2505: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
2506: if (($is_uploaded_map) ||
2507: ($url =~ /(bulletinboard|smppg)$/) ||
2508: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
2509: $options = &paste_options($suffix,$is_uploaded_map,$parent);
2510: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
2511: }
2512: }
2513: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
2514: if ($nopaste) {
1.681 raeburn 2515: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 2516: } else {
2517: if ($othercrs) {
2518: $pasteitems .= $othercrs;
2519: }
2520: if ($options) {
2521: $pasteitems .= $options;
1.492 raeburn 2522: }
2523: }
1.538 raeburn 2524: $pasteitems .= '</div>';
2525: }
2526: }
2527: if ($pasteitems eq '') {
2528: &Apache::lonnet::delenv('docs.markedcopies');
2529: }
2530: my ($pasteform,$form_start,$buttons,$form_end);
2531: if ($pasteitems) {
2532: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 2533: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 2534: if (@pasteable) {
1.575 raeburn 2535: my $value = &mt('Paste to current folder');
2536: if ($container eq 'page') {
2537: $value = &mt('Paste to current page');
2538: }
2539: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
2540: }
2541: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
2542: if ($clipboardcount > 1) {
2543: $buttons .=
2544: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
2545: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
2546: (' 'x2).
2547: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
2548: (' 'x2);
1.492 raeburn 2549: }
1.575 raeburn 2550: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
2551: '</form>';
1.538 raeburn 2552: } else {
2553: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 2554: }
1.538 raeburn 2555: $r->print($form_start
2556: .'<fieldset>'
2557: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
2558: .$pasteitems
2559: .'</fieldset>'
2560: .$form_end);
2561: }
2562:
2563: sub paste_options {
2564: my ($suffix,$is_uploaded_map,$parent) = @_;
2565: my ($copytext,$movetext);
2566: if ($is_uploaded_map) {
2567: $copytext = &mt('Copy to new folder');
2568: $movetext = &mt('Move old');
2569: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
2570: $copytext = &mt('Copy to new board');
2571: $movetext = &mt('Move (not posts)');
2572: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
2573: $copytext = &mt('Copy to new page');
2574: $movetext = &mt('Move');
1.533 raeburn 2575: } else {
1.538 raeburn 2576: $copytext = &mt('Copy to new file');
2577: $movetext = &mt('Move');
2578: }
2579: my $output = '<br />'.
2580: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
2581: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
2582: '<label>'.
2583: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
2584: $copytext.'</label></span>'.(' 'x2).' '.
2585: '<span class="LC_nobreak"><label>'.
2586: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
2587: $movetext.'</label></span>';
2588: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
2589: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
2590: '</legend><table border="0">';
2591: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2592: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
2593: my $lastdir = $parent;
2594: my %depths = (
2595: $lastdir => 0,
2596: );
2597: my (%display,%deps);
2598: for (my $i=0; $i<@pastemaps; $i++) {
2599: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
2600: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
2601: my @subfolders = split(/,/,$subfolderstr);
2602: $deps{$lastdir} = \@subfolders;
2603: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
2604: my $depth = $depths{$lastdir} + 1;
2605: my $offset = int($depth * 4);
2606: my $indent = (' ' x $offset);
2607: for (my $j=0; $j<@subfolders; $j++) {
2608: $depths{$subfolders[$j]} = $depth;
2609: $display{$subfolders[$j]} =
2610: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
2611: '<td><label>'.
2612: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
2613: '<label>'.
2614: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
2615: &mt('Move old').'</label>'.
2616: '</td></tr>';
2617: }
1.492 raeburn 2618: }
1.538 raeburn 2619: &recurse_print(\$output,$parent,\%deps,\%display);
2620: $output .= '</table></fieldset>';
1.329 droeschl 2621: }
1.538 raeburn 2622: $output .= '</div>';
2623: return $output;
1.488 raeburn 2624: }
2625:
1.492 raeburn 2626: sub recurse_print {
1.538 raeburn 2627: my ($outputref,$dir,$deps,$display) = @_;
2628: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 2629: if (ref($deps->{$dir}) eq 'ARRAY') {
2630: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 2631: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 2632: }
2633: }
2634: }
2635:
1.488 raeburn 2636: sub supp_pasteable {
2637: my ($url) = @_;
2638: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
2639: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
2640: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
2641: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 2642: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 2643: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 2644: return 1;
2645: }
2646: return;
1.329 droeschl 2647: }
2648:
1.492 raeburn 2649: sub paste_popup_js {
1.594 damieng 2650: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 2651: show => 'Show Options',
2652: hide => 'Hide Options',
1.594 damieng 2653: );
2654: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 2655: none => 'No items selected from clipboard.',
1.492 raeburn 2656: );
1.594 damieng 2657: &html_escape(\%html_js_lt);
2658: &js_escape(\%html_js_lt);
2659: &js_escape(\%js_lt);
1.492 raeburn 2660: return <<"END";
2661:
1.538 raeburn 2662: function showPasteOptions(suffix) {
2663: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 2664: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 2665: return;
2666: }
2667:
1.538 raeburn 2668: function hidePasteOptions(suffix) {
2669: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 2670: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2671: return;
2672: }
2673:
2674: function showOptions(caller,suffix) {
2675: if (document.getElementById('pasteoptionstext_'+suffix)) {
2676: if (caller.checked) {
1.594 damieng 2677: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2678: } else {
2679: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
2680: }
2681: if (document.getElementById('pasteoptions_'+suffix)) {
2682: document.getElementById('pasteoptions_'+suffix).style.display='none';
2683: }
2684: }
1.492 raeburn 2685: return;
2686: }
2687:
1.541 raeburn 2688: function validateClipboard() {
2689: var numchk = 0;
2690: if (document.pasteform.pasting.length > 1) {
2691: for (var i=0; i<document.pasteform.pasting.length; i++) {
2692: if (document.pasteform.pasting[i].checked) {
2693: numchk ++;
2694: }
2695: }
2696: } else {
2697: if (document.pasteform.pasting.type == 'checkbox') {
2698: if (document.pasteform.pasting.checked) {
2699: numchk ++;
2700: }
2701: }
2702: }
2703: if (numchk > 0) {
2704: return true;
2705: } else {
1.594 damieng 2706: alert("$js_lt{'none'}");
1.541 raeburn 2707: return false;
2708: }
2709: }
2710:
1.575 raeburn 2711: function checkClipboard() {
2712: if (document.pasteform.pasting.length > 1) {
2713: for (var i=0; i<document.pasteform.pasting.length; i++) {
2714: document.pasteform.pasting[i].checked = true;
2715: }
2716: }
2717: return;
2718: }
2719:
2720: function uncheckClipboard() {
2721: if (document.pasteform.pasting.length >1) {
2722: for (var i=0; i<document.pasteform.pasting.length; i++) {
2723: document.pasteform.pasting[i].checked = false;
2724: }
2725: }
2726: return;
2727: }
2728:
1.492 raeburn 2729: END
2730:
2731: }
2732:
1.329 droeschl 2733: sub do_paste_from_buffer {
1.492 raeburn 2734: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 2735:
1.538 raeburn 2736: # Array of items in paste buffer
2737: my (@currpaste,%pastebuffer,%allerrors);
2738: @currpaste = split(/,/,$env{'docs.markedcopies'});
2739:
1.492 raeburn 2740: # Early out if paste buffer is empty
1.538 raeburn 2741: if (@currpaste == 0) {
1.492 raeburn 2742: return ();
1.538 raeburn 2743: }
2744: map { $pastebuffer{$_} = 1; } @currpaste;
2745:
2746: # Array of items selected items to paste
2747: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
2748:
2749: # Early out if nothing selected to paste
2750: if (@reqpaste == 0) {
2751: return();
2752: }
2753: my @topaste;
2754: foreach my $suffix (@reqpaste) {
2755: next if ($suffix =~ /\D/);
2756: next unless (exists($pastebuffer{$suffix}));
2757: push(@topaste,$suffix);
2758: }
2759:
2760: # Early out if nothing available to paste
2761: if (@topaste == 0) {
2762: return();
1.329 droeschl 2763: }
2764:
1.704 raeburn 2765: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
2766: %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
2767: %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
2768: %currltititles,$currltimax,$gotcrsltitools);
2769: $currltimax = 0;
2770: $gotcrsltitools = 0;
1.538 raeburn 2771: foreach my $suffix (@topaste) {
2772: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 2773: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 2774: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 2775: # Supplemental content may only include certain types of content
2776: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 2777: if ($folder =~ /^supplemental/) {
2778: unless (&supp_pasteable($url)) {
2779: $notinsupp{$suffix} = 1;
2780: next;
2781: }
1.492 raeburn 2782: }
1.538 raeburn 2783: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
2784: my $srcd = $1;
2785: my $srcn = $2;
1.492 raeburn 2786: # When paste buffer was populated using an active role in a different course
1.538 raeburn 2787: # check for mdc privilege in the course from which the resource was pasted
2788: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2789: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2790: $notincrs{$suffix} = 1;
2791: next;
2792: }
1.491 raeburn 2793: }
1.538 raeburn 2794: $srcdom{$suffix} = $srcd;
2795: $srcnum{$suffix} = $srcn;
1.597 raeburn 2796: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 2797: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
2798: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 2799: my ($srcd,$srcn) = split(/_/,$cid);
2800: # When paste buffer was populated using an active role in a different course
2801: # check for mdc privilege in the course from which the resource was pasted
2802: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2803: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2804: $notincrs{$suffix} = 1;
2805: next;
2806: }
2807: }
1.632 raeburn 2808: # When buffer was populated using an active role in a different course
1.704 raeburn 2809: # disallow pasting of External Tool if course is in a different domain,
2810: # or if External Tool use is not permitted in this course.
2811: if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2812: my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
2813: if ($toolcdom ne $coursedom) {
2814: $notindom{$suffix} = 1;
2815: next;
2816: } elsif ($toolcnum ne $coursenum) {
2817: my %toolsettings =
2818: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2819: my %tooltypes = &Apache::loncommon::usable_exttools();
2820: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2821: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2822: $othcrstool{$suffix} = 1;
2823: next;
2824: }
2825: if ($toolsettings{'id'} =~ /^c\d+$/) {
2826: unless ($gotcrsltitools) {
2827: %currcrsltitools =
2828: &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
2829: foreach my $item (sort(keys(%currcrsltitools))) {
2830: if (ref($currcrsltitools{$item}) eq 'HASH') {
2831: $currltimax ++;
2832: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
2833: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
2834: } else {
2835: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
2836: }
2837: }
2838: }
2839: $gotcrsltitools = 1;
2840: }
2841: }
2842: }
1.627 raeburn 2843: }
1.596 raeburn 2844: $srcdom{$suffix} = $srcd;
2845: $srcnum{$suffix} = $srcn;
1.703 raeburn 2846: } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
2847: my ($audom,$auname) = ($1,$2);
2848: # When buffer was populated using an active role in a different course
2849: # disallow pasting of published resources from Course Authoring Space
2850: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2851: if (&Apache::lonnet::is_course($audom,$auname)) {
2852: $othcrsres{$suffix} = 1;
2853: next;
2854: }
2855: }
1.491 raeburn 2856: }
1.597 raeburn 2857: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 2858: push(@dopaste,$suffix);
2859: if ($url=~/\.(page|sequence)$/) {
2860: $is_map{$suffix} = 1;
2861: }
2862: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
2863: my $oldprefix = $1;
1.492 raeburn 2864: # When pasting content from Main Content to Supplemental Content and vice versa
2865: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 2866: # a folder/page or a document).
1.538 raeburn 2867: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
2868: $prefixchg{$suffix} = 'docstosupp';
2869: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
2870: $prefixchg{$suffix} = 'supptodocs';
2871: }
1.491 raeburn 2872:
1.492 raeburn 2873: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 2874: if ($env{'docs.markedcopy_nested_'.$suffix}) {
2875: my @nested;
2876: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
2877: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2878: my @deps = map { /\d+:([\d,]+$)/ } @items;
2879: foreach my $dep (@deps) {
2880: if ($dep =~ /,/) {
2881: push(@nested,split(/,/,$dep));
2882: } else {
2883: push(@nested,$dep);
2884: }
1.492 raeburn 2885: }
1.538 raeburn 2886: foreach my $item (@nested) {
2887: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
2888: push(@{$marktomove{$suffix}},$type.'_'.$item);
2889: }
1.492 raeburn 2890: }
2891: }
1.488 raeburn 2892: }
2893: }
2894:
1.538 raeburn 2895: # Early out if nothing available to paste
2896: if (@dopaste == 0) {
2897: return ();
2898: }
2899:
2900: # Populate message hash and hashes used for main content <=> supplemental content
2901: # changes
2902:
2903: %msgs = &Apache::lonlocal::texthash (
2904: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
2905: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 2906: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.704 raeburn 2907: othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.703 raeburn 2908: othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538 raeburn 2909: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
2910: );
2911:
2912: %before = (
2913: docstosupp => {
2914: map => 'default',
2915: doc => 'docs',
2916: },
2917: supptodocs => {
2918: map => 'supplemental',
2919: doc => 'supplemental',
2920: },
2921: );
2922:
2923: %after = (
2924: docstosupp => {
2925: map => 'supplemental',
2926: doc => 'supplemental'
2927: },
2928: supptodocs => {
2929: map => 'default',
2930: doc => 'docs',
2931: },
2932: );
2933:
2934: # Retrieve information about all course maps in main content area
2935:
2936: my $allmaps = {};
1.704 raeburn 2937: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
2938: @updatetoolsenc,$updatetoolscache,$checkedsameinst,
2939: $same_institution);
1.538 raeburn 2940:
2941: # Loop over the items to paste
2942: foreach my $suffix (@dopaste) {
1.329 droeschl 2943: # Maps need to be copied first
1.538 raeburn 2944: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
2945: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 2946: %newurls,%tomove,%resdatacopy);
1.538 raeburn 2947: if (ref($marktomove{$suffix}) eq 'ARRAY') {
2948: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
2949: }
2950: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
2951: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 2952: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 2953: my $oldurl = $url;
2954: if ($is_map{$suffix}) {
1.491 raeburn 2955: # If pasting a map, check if map contains other maps
1.538 raeburn 2956: my (%hierarchy,%titles);
1.660 raeburn 2957: if (($folder =~ /^default/) && (!$donechk)) {
2958: $allmaps =
2959: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
2960: $env{"course.$env{'request.course.id'}.home"},
2961: $env{'request.course.id'});
2962: $donechk = 1;
2963: }
1.627 raeburn 2964: &contained_map_check($url,$folder,$coursenum,$coursedom,
2965: \%removefrommap,\%removeparam,\%addedmaps,
2966: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 2967: if ($url=~ m{^/uploaded/}) {
2968: my $newurl;
2969: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2970: ($newurl,my $error) =
2971: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
2972: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2973: \$title,$allmaps,\%newurls);
2974: if ($error) {
2975: $allerrors{$suffix} = $error;
2976: next;
2977: }
2978: if ($newurl ne '') {
2979: if ($newurl ne $url) {
2980: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
2981: $newsubdir{$url} = $1;
2982: }
2983: $mapchanges{$url} = 1;
1.492 raeburn 2984: }
1.538 raeburn 2985: }
2986: }
2987: if (($srcdom{$suffix} ne $coursedom) ||
2988: ($srcnum{$suffix} ne $coursenum) ||
2989: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
2990: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
2991: $coursedom,$coursenum,$srcdom{$suffix},
2992: $srcnum{$suffix},$allmaps,\%rewrites,
2993: \%retitles,\%copies,\%dbcopies,
2994: \%zombies,\%params,\%mapmoves,
2995: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 2996: \%newurls,\%resdatacopy)) {
1.538 raeburn 2997: $mapmoves{$url} = 1;
2998: }
2999: $url = $newurl;
3000: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
3001: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
3002: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
3003: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
3004: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 3005: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 3006: }
3007: } elsif ($url=~m {^/res/}) {
1.597 raeburn 3008: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 3009: push(@toclear,$suffix);
3010: # if pasting published map (main content area only) check map not already in course
3011: if ($folder =~ /^default/) {
3012: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
3013: $duplicate{$suffix} = 1;
3014: next;
1.492 raeburn 3015: }
1.491 raeburn 3016: }
3017: }
1.538 raeburn 3018: }
1.627 raeburn 3019: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 3020: my $prefix = $1;
1.648 raeburn 3021: my $fromothercrs;
1.538 raeburn 3022: #need to copy the db contents to a new one, unless this is a move.
3023: my %info = (
3024: src => $url,
3025: cdom => $coursedom,
3026: cnum => $coursenum,
1.596 raeburn 3027: );
1.649 raeburn 3028: if ($prefix eq 'ext.tool') {
1.655 raeburn 3029: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 3030: $info{'delgradable'} = 1;
3031: }
3032: }
1.596 raeburn 3033: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
3034: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
3035: $fromothercrs = 1;
3036: $info{'cdom'} = $srcdom{$suffix};
3037: $info{'cnum'} = $srcnum{$suffix};
1.704 raeburn 3038: unless ($checkedsameinst) {
3039: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
3040: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3041: if ($intdom ne '') {
3042: my $internet_names =
3043: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
3044: if (ref($internet_names) eq 'ARRAY') {
3045: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
3046: $same_institution = 1;
3047: }
3048: }
3049: }
3050: $checkedsameinst = 1;
3051: }
1.596 raeburn 3052: }
3053: }
3054: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 3055: my (%lockerr,$msg);
1.538 raeburn 3056: my ($newurl,$result,$errtext) =
1.704 raeburn 3057: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
3058: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.538 raeburn 3059: if ($result eq 'ok') {
3060: $url = $newurl;
3061: $title=&mt('Copy of').' '.$title;
3062: } else {
3063: if ($prefix eq 'smppg') {
3064: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
3065: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 3066: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 3067: } elsif ($prefix eq 'ext.tool') {
3068: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 3069: }
3070: $results{$suffix} = $result;
3071: $msgerrs{$suffix} = $msg;
3072: $lockerrs{$suffix} = $lockerr{$prefix};
3073: next;
3074: }
3075: if ($lockerr{$prefix}) {
3076: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 3077: }
1.489 raeburn 3078: }
3079: }
1.538 raeburn 3080: $title = &LONCAPA::map::qtunescape($title);
3081: my $ext='false';
3082: if ($url=~m{^http(|s)://}) { $ext='true'; }
3083: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
3084: if ($folder !~ /^supplemental/) {
3085: (undef,undef,$title) =
3086: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
3087: }
3088: } else {
3089: if ($folder=~/^supplemental/) {
3090: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3091: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 3092: }
1.533 raeburn 3093: }
1.491 raeburn 3094:
3095: # For uploaded files (excluding pages/sequences) path in copied file is changed
3096: # if paste is from Main to Supplemental (or vice versa), or if pasting between
3097: # courses.
3098:
1.538 raeburn 3099: unless ($is_map{$suffix}) {
3100: my $newidx;
1.492 raeburn 3101: # Now insert the URL at the bottom
1.538 raeburn 3102: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
3103: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
3104: my $relpath = $1;
3105: if ($relpath ne '') {
3106: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
3107: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
3108: my $newprefix = $newloc;
3109: if ($newloc eq 'default') {
3110: $newprefix = 'docs';
3111: }
3112: if ($newdocsdir eq '') {
3113: $newdocsdir = 'default';
3114: }
1.630 raeburn 3115: if (($prefixchg{$suffix}) ||
3116: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 3117: ($srcnum{$suffix} ne $coursenum) ||
3118: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
3119: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
3120: $url =
3121: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
3122: &Apache::lonnet::getfile($oldurl));
3123: if ($url eq '/adm/notfound.html') {
3124: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
3125: next;
3126: } else {
3127: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
3128: $newsubpath =~ s{/+$}{/};
3129: $docmoves{$oldurl} = $newsubpath;
3130: }
1.491 raeburn 3131: }
3132: }
1.597 raeburn 3133: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
3134: my $template = $1;
3135: if ($newidx) {
3136: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
3137: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
3138: }
1.649 raeburn 3139: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 3140: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 3141: my $marker = (split(m{/},$url))[4];
3142: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
3143: my $val = 'no';
3144: if ($toolsettings{'gradable'}) {
3145: $val = 'yes';
3146: }
3147: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
3148: 'string_yesno');
3149: &remember_parms($newidx,'gradable','set',$val);
3150: }
1.491 raeburn 3151: }
1.538 raeburn 3152: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
3153: ':'.$ext.':normal:res';
3154: push(@LONCAPA::map::order,$newidx);
3155: # Store the result
3156: my ($errtext,$fatal) =
3157: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3158: if ($fatal) {
3159: $save_err .= $errtext;
3160: $allresult = 'fail';
3161: }
1.488 raeburn 3162: }
1.538 raeburn 3163:
1.597 raeburn 3164: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
3165: # resourcedata for simpleproblems copied from another course
1.538 raeburn 3166: unless ($allresult eq 'fail') {
3167: my %updated = (
3168: rewrites => \%rewrites,
3169: zombies => \%zombies,
3170: removefrommap => \%removefrommap,
3171: removeparam => \%removeparam,
3172: dbcopies => \%dbcopies,
1.597 raeburn 3173: resdatacopy => \%resdatacopy,
1.538 raeburn 3174: retitles => \%retitles,
3175: );
3176: my %info = (
3177: newsubdir => \%newsubdir,
3178: params => \%params,
3179: );
3180: if ($prefixchg{$suffix}) {
3181: $info{'before'} = $before{$prefixchg{$suffix}};
3182: $info{'after'} = $after{$prefixchg{$suffix}};
3183: }
3184: my %moves = (
3185: copies => \%copies,
3186: docmoves => \%docmoves,
3187: mapmoves => \%mapmoves,
3188: );
3189: (my $result,$msgs{$suffix},my $lockerror) =
3190: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
3191: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
3192: $url,'paste');
3193: $lockerrors .= $lockerror;
3194: if ($result eq 'ok') {
3195: if ($is_map{$suffix}) {
3196: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3197: $folder.'.'.$container);
3198: if ($fatal) {
3199: $allresult = 'failread';
3200: } else {
3201: if ($#LONCAPA::map::order<1) {
3202: my $idx=&LONCAPA::map::getresidx();
3203: if ($idx<=0) { $idx=1; }
3204: $LONCAPA::map::order[0]=$idx;
3205: $LONCAPA::map::resources[$idx]='';
3206: }
3207: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
3208: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
3209: ':'.$ext.':normal:res';
3210: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 3211:
3212: # Store the result
1.538 raeburn 3213: my ($errtext,$fatal) =
3214: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3215: if ($fatal) {
3216: $save_err .= $errtext;
3217: $allresult = 'failstore';
3218: }
3219: }
3220: }
3221: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
3222: push(@toclear,$suffix);
3223: }
3224: }
1.492 raeburn 3225: }
3226: }
1.704 raeburn 3227: if (($updatetoolscache) || (@updatetoolsenc)) {
3228: &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
3229: \@updatetoolsenc);
3230: }
1.538 raeburn 3231: &clear_from_buffer(\@toclear,\@currpaste);
3232: my $msgsarray;
3233: foreach my $suffix (keys(%msgs)) {
3234: if (ref($msgs{$suffix}) eq 'ARRAY') {
3235: $msgsarray .= join(',',@{$msgs{$suffix}});
3236: }
3237: }
3238: return ($allresult,$save_err,$msgsarray,$lockerrors);
3239: }
1.533 raeburn 3240:
1.538 raeburn 3241: sub do_buffer_empty {
3242: my @currpaste = split(/,/,$env{'docs.markedcopies'});
3243: if (@currpaste == 0) {
3244: return &mt('Clipboard is already empty');
3245: }
3246: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
3247: if (@toclear == 0) {
3248: return &mt('Nothing selected to clear from clipboard');
3249: }
3250: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
3251: if ($numdel) {
3252: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
3253: } else {
3254: return &mt('Clipboard unchanged');
1.492 raeburn 3255: }
1.538 raeburn 3256: return;
3257: }
3258:
3259: sub clear_from_buffer {
3260: my ($toclear,$currpaste) = @_;
3261: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
3262: my %pastebuffer;
3263: map { $pastebuffer{$_} = 1; } @{$currpaste};
3264: my $numdel = 0;
3265: foreach my $suffix (@{$toclear}) {
3266: next if ($suffix =~ /\D/);
3267: next unless (exists($pastebuffer{$suffix}));
3268: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
3269: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
3270: delete($pastebuffer{$suffix});
3271: $numdel ++;
3272: }
3273: }
3274: my $newbuffer = join(',',sort(keys(%pastebuffer)));
3275: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
3276: return $numdel;
1.492 raeburn 3277: }
3278:
1.704 raeburn 3279: sub update_ltitools_caches {
3280: my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
3281: my $hashid=$coursedom.'_'.$coursenum;
3282: if ($updatetoolscache) {
3283: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3284: }
3285: if ((ref($updatetoolsenc) eq 'ARRAY') &&
3286: (@{$updatetoolsenc})) {
3287: my @ids=&Apache::lonnet::current_machine_ids();
3288: my $updatedone;
3289: foreach my $lonhost (@{$updatetoolsenc}) {
3290: if (grep(/^\Q$lonhost\E$/,@ids)) {
3291: unless ($updatedone) {
3292: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
3293: }
3294: $updatedone = 1;
3295: } else {
3296: &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
3297: }
3298: }
3299: }
3300: return;
3301: }
3302:
1.492 raeburn 3303: sub get_newmap_url {
3304: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
3305: $titleref,$allmaps,$newurls) = @_;
3306: my $newurl;
3307: if ($url=~ m{^/uploaded/}) {
3308: $$titleref=&mt('Copy of').' '.$$titleref;
3309: }
3310: my $now = time;
3311: my $suffix=$$.int(rand(100)).$now;
3312: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
3313: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
3314: my $path = $1;
3315: my $prefix = $2;
3316: my $ancestor = $3;
3317: if (length($ancestor) > 10) {
3318: $ancestor = substr($ancestor,-10,10);
3319: }
3320: my $newid;
3321: if ($prefixchg) {
3322: if ($folder =~ /^supplemental/) {
3323: $prefix =~ s/^default/supplemental/;
3324: } else {
3325: $prefix =~ s/^supplemental/default/;
3326: }
3327: }
3328: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3329: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3330: } else {
3331: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
3332: }
3333: my $counter = 0;
3334: my $is_unique = &uniqueness_check($newurl);
3335: if ($folder =~ /^default/) {
3336: if ($allmaps->{$newurl}) {
3337: $is_unique = 0;
3338: }
3339: }
3340: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
3341: $counter ++;
3342: $suffix ++;
3343: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3344: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3345: } else {
3346: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
3347: }
3348: $is_unique = &uniqueness_check($newurl);
3349: }
3350: if ($is_unique) {
3351: $newurls->{$newurl} = 1;
3352: } else {
3353: if ($url=~/\.page$/) {
3354: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
3355: } else {
3356: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
3357: }
3358: }
1.329 droeschl 3359: }
1.492 raeburn 3360: return ($newurl);
1.329 droeschl 3361: }
3362:
1.488 raeburn 3363: sub dbcopy {
1.704 raeburn 3364: my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
3365: $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.533 raeburn 3366: my ($url,$result,$errtext);
3367: if (ref($dbref) eq 'HASH') {
1.596 raeburn 3368: $url = $dbref->{'src'};
1.627 raeburn 3369: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 3370: my $prefix = $1;
1.627 raeburn 3371: if ($prefix eq 'ext.tool') {
3372: $prefix = 'exttool';
3373: }
1.533 raeburn 3374: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3375: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3376: my $db_name;
3377: my $marker = (split(m{/},$url))[4];
3378: $marker=~s/\D//g;
3379: if ($dbref->{'src'} =~ m{/smppg$}) {
3380: $db_name =
3381: &Apache::lonsimplepage::get_db_name($url,$marker,
3382: $dbref->{'cdom'},
3383: $dbref->{'cnum'});
1.627 raeburn 3384: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
3385: $db_name = 'exttool_'.$marker;
1.533 raeburn 3386: } else {
3387: $db_name = 'bulletinpage_'.$marker;
3388: }
3389: my ($suffix,$freedlock,$error) =
3390: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
3391: $coursedom,$coursenum,
3392: 'concat');
3393: if (!$suffix) {
3394: if ($prefix eq 'smppg') {
3395: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 3396: } elsif ($prefix eq 'exttool') {
3397: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 3398: } else {
1.565 bisitz 3399: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 3400: }
3401: if ($error) {
3402: $errtext .= '<br />'.$error;
3403: }
3404: } else {
3405: #need to copy the db contents to a new one.
3406: my %contents=&Apache::lonnet::dump($db_name,
3407: $dbref->{'cdom'},
3408: $dbref->{'cnum'});
1.704 raeburn 3409: my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
3410: if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
3411: if ($contents{'id'} =~ /^(|c)(\d+)$/) {
3412: $oldtoolid = $2;
3413: if ($1 eq 'c') {
3414: $defincrs = 1;
3415: %toolinfo =
3416: &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
3417: } else {
3418: %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
3419: }
3420: if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
3421: if ($toolinfo{$oldtoolid}{'passback'}) {
3422: $toolpassback = 1;
3423: }
3424: if ($toolinfo{$oldtoolid}{'roster'}) {
3425: $toolroster = 1;
3426: }
3427: } else {
3428: $toolcopyerror = 1;
3429: $errtext = &mt('Could not retrieve original settings for pasted external tool.');
3430: }
3431: }
3432: unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
3433: $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
3434: if ($contents{'crstitle'} ne '') {
3435: $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
3436: }
3437: if (($defincrs) && (!$toolcopyerror)) {
3438: my %newtool;
3439: my $oldcdom = $dbref->{'cdom'};
3440: my $oldcnum = $dbref->{'cnum'};
3441: my $title = $toolinfo{$oldtoolid}{'title'};
3442: if (ref($currltititles) eq 'HASH') {
3443: if (exists($currltititles->{$title})) {
3444: $title .= ' (copied from another course)';
3445: }
3446: }
3447: my ($newid,$iderror) =
3448: &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
3449: if ($newid =~ /^\d+$/) {
3450: %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
3451: $newtool{$newid}{'title'} = $title;
3452: if (ref($currltimax)) {
3453: $newtool{$newid}{'order'} = $$currltimax;
3454: }
3455: if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
3456: my $fname = $1;
3457: my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
3458: if ($content eq '-1') {
3459: delete($newtool{$newid}{'image'});
3460: } else {
3461: $env{'form.'.$suffix.'.image'} = $content;
3462: my $newlogo =
3463: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
3464: delete($env{'form.'.$suffix.'.image'});
3465: if ($newlogo =~ m{^/uploaded/}) {
3466: $newtool{$newid}{'image'} = $newlogo;
3467: } else {
3468: delete($newtool{$newid}{'image'});
3469: }
3470: }
3471: }
3472: my $newusable;
3473: if ($same_institution) {
3474: my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
3475: if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
3476: my %newtoolsenc;
3477: %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
3478: my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
3479: if ($putres eq 'ok') {
3480: if (ref($updatetoolsenc) eq 'ARRAY') {
3481: my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
3482: unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
3483: push(@{$updatetoolsenc},$newhome);
3484: }
3485: }
3486: $newusable = 1;
3487: }
3488: }
3489: }
3490: if ($newtool{$newid}{'usable'}) {
3491: unless ($newusable) {
3492: delete($newtool{$newid}{'usable'});
3493: }
3494: }
3495: my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
3496: if ($putres eq 'ok') {
3497: $contents{'id'} = "c$newid";
3498: if (ref($updatetoolscache)) {
3499: $$updatetoolscache ++;
3500: }
3501: if (ref($currltititles->{$title}) eq 'ARRAY') {
3502: push(@{$currltititles->{$title}},$newid);
3503: } else {
3504: $currltititles->{$title} = [$newid];
3505: }
3506: if (ref($currltimax)) {
3507: $$currltimax ++;
3508: }
3509: } else {
3510: $toolcopyerror = 1;
3511: $errtext = &mt('Unable to save external tool definition in Course Settings.');
3512: }
3513: } else {
3514: $toolcopyerror = 1;
3515: $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
3516: }
3517: }
3518: }
3519: }
1.533 raeburn 3520: if (exists($contents{'uploaded.photourl'})) {
3521: my $photo = $contents{'uploaded.photourl'};
3522: my ($subdir,$fname) =
3523: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 3524: my $newphoto;
1.533 raeburn 3525: if ($fname ne '') {
3526: my $content = &Apache::lonnet::getfile($photo);
3527: unless ($content eq '-1') {
3528: $env{'form.'.$suffix.'.photourl'} = $content;
3529: $newphoto =
3530: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
3531: delete($env{'form.'.$suffix.'.photourl'});
3532: }
3533: }
3534: if ($newphoto =~ m{^/uploaded/}) {
3535: $contents{'uploaded.photourl'} = $newphoto;
3536: }
3537: }
3538: $db_name =~ s{_\d*$ }{_$suffix}x;
1.704 raeburn 3539: if ($prefix eq 'exttool') {
3540: unless ($toolcopyerror) {
3541: foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
3542: if (exists($contents{$key})) {
3543: delete($contents{$key});
3544: }
3545: }
3546: if ($dbref->{'delgradable'}) {
3547: if (exists($contents{'gradable'})) {
3548: delete($contents{'gradable'});
3549: }
3550: }
3551: if ($toolpassback) {
3552: if ($contents{'gradable'}) {
3553: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3554: $contents{'gradesecret'} = $gradesecret;
3555: $contents{'gradesecretdate'} = time;
3556: }
3557: }
3558: if ($toolroster) {
3559: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3560: $contents{'rostersecret'} = $rostersecret;
3561: $contents{'rostersecretdate'} = time;
3562: }
3563: }
1.649 raeburn 3564: }
1.704 raeburn 3565: if (($prefix eq 'exttool') && ($toolcopyerror)) {
3566: $result = 'error';
3567: } else {
3568: $result=&Apache::lonnet::put($db_name,\%contents,
3569: $coursedom,$coursenum);
3570: if ($result eq 'ok') {
3571: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
3572: }
1.533 raeburn 3573: }
3574: }
3575: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 3576: $lockerrorsref->{$prefix} =
1.533 raeburn 3577: '<div class="LC_error">'.
3578: &mt('There was a problem removing a lockfile.');
3579: if ($prefix eq 'smppg') {
1.560 raeburn 3580: $lockerrorsref->{$prefix} .=
1.559 raeburn 3581: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 3582: } elsif ($prefix eq 'exttool') {
3583: $lockerrorsref->{$prefix} .=
3584: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 3585: } else {
1.565 bisitz 3586: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 3587: }
1.560 raeburn 3588: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
3589: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
3590: '</div>';
1.533 raeburn 3591: }
3592: }
3593: } elsif ($url =~ m{/syllabus$}) {
3594: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3595: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3596: if (($dbref->{'cdom'} ne $coursedom) ||
3597: ($dbref->{'cnum'} ne $coursenum)) {
3598: my %contents=&Apache::lonnet::dump('syllabus',
3599: $dbref->{'cdom'},
3600: $dbref->{'cnum'});
3601: $result=&Apache::lonnet::put('syllabus',\%contents,
3602: $coursedom,$coursenum);
3603: }
3604: }
1.488 raeburn 3605: }
3606: }
1.533 raeburn 3607: return ($url,$result,$errtext);
1.488 raeburn 3608: }
3609:
1.597 raeburn 3610: sub copy_templated_files {
3611: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
3612: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
3613: my $srccontainer = 'sequence';
3614: if ($srcwaspage) {
3615: $srccontainer = 'page';
3616: }
3617: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
3618: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
3619: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
3620: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
3621: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
3622: $template.'.problem';
3623: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
3624: if ($template eq 'simpleproblem') {
3625: $srcprefix .= '.0.';
3626: my $weightprefix = $newprefix;
3627: $newprefix .= '.0.';
3628: my @simpleprobqtypes = qw(radio option string essay numerical);
3629: my $qtype=$srcparms{$srcprefix.'questiontype'};
3630: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 3631: my %newdata = (
3632: $newprefix.'questiontype' => $qtype,
3633: );
1.597 raeburn 3634: foreach my $type (@simpleprobqtypes) {
3635: if ($type eq $qtype) {
3636: $newdata{"$weightprefix.$type.weight"}=1;
3637: } else {
3638: $newdata{"$weightprefix.$type.weight"}=0;
3639: }
3640: }
3641: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
3642: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
3643: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
3644: if ($qtype eq 'numerical') {
3645: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
3646: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
3647: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
3648: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
3649: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3650: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3651: unless (defined($maxfoils)) { $maxfoils=10; }
3652: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3653: if ($maxfoils<=0) { $maxfoils=10; }
3654: my $randomize=$srcparms{$srcprefix.'randomize'};
3655: unless (defined($randomize)) { $randomize='yes'; }
3656: unless ($randomize eq 'no') { $randomize='yes'; }
3657: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3658: $newdata{$newprefix.'randomize'} = $randomize;
3659: if ($qtype eq 'option') {
3660: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3661: }
3662: for (my $i=1; $i<=10; $i++) {
3663: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3664: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3665: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3666: }
3667:
3668: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3669: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3670: unless (defined($maxfoils)) { $maxfoils=10; }
3671: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3672: if ($maxfoils<=0) { $maxfoils=10; }
3673: my $randomize=$srcparms{$srcprefix.'randomize'};
3674: unless (defined($randomize)) { $randomize='yes'; }
3675: unless ($randomize eq 'no') { $randomize='yes'; }
3676: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3677: $newdata{$newprefix.'randomize'} = $randomize;
3678: if ($qtype eq 'option') {
3679: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3680: }
3681: for (my $i=1; $i<=10; $i++) {
3682: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3683: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3684: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3685: }
3686: } elsif ($qtype eq 'string') {
3687: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
3688: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
3689: }
3690: if (keys(%newdata)) {
3691: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
3692: $coursenum);
3693: if ($putres eq 'ok') {
3694: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
3695: }
3696: }
3697: }
3698: }
3699: }
3700:
1.329 droeschl 3701: sub uniqueness_check {
3702: my ($newurl) = @_;
3703: my $unique = 1;
3704: foreach my $res (@LONCAPA::map::order) {
3705: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3706: $url=&LONCAPA::map::qtescape($url);
3707: if ($newurl eq $url) {
3708: $unique = 0;
1.344 bisitz 3709: last;
1.329 droeschl 3710: }
3711: }
3712: return $unique;
3713: }
3714:
1.488 raeburn 3715: sub contained_map_check {
1.627 raeburn 3716: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
3717: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 3718: my $content = &Apache::lonnet::getfile($url);
3719: unless ($content eq '-1') {
3720: my $parser = HTML::TokeParser->new(\$content);
3721: $parser->attr_encoded(1);
3722: while (my $token = $parser->get_token) {
3723: next if ($token->[0] ne 'S');
3724: if ($token->[1] eq 'resource') {
3725: next if ($token->[2]->{'type'} eq 'zombie');
3726: my $ressrc = $token->[2]->{'src'};
1.704 raeburn 3727: if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
3728: my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
1.627 raeburn 3729: unless ($srcdom eq $coursedom) {
3730: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3731: next;
3732: }
1.704 raeburn 3733: unless ($srcnum eq $coursenum) {
3734: my %toolsettings =
3735: &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
3736: my %tooltypes = &Apache::loncommon::usable_exttools();
3737: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
3738: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
3739: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3740: next;
3741: }
3742: }
1.627 raeburn 3743: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 3744: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 3745: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 3746: next;
3747: }
3748: }
1.703 raeburn 3749: if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
3750: my ($srcdom,$srcnum) = ($1,$2);
3751: unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
3752: if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
3753: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3754: next;
3755: }
3756: }
3757: }
1.492 raeburn 3758: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
3759: if ($1 eq 'uploaded') {
3760: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
3761: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 3762: } else {
1.492 raeburn 3763: if ($allmaps->{$ressrc}) {
1.529 raeburn 3764: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 3765: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
3766: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3767: } else {
3768: $addedmaps->{$ressrc} = [$url];
3769: }
1.488 raeburn 3770: }
1.627 raeburn 3771: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
3772: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 3773: }
1.492 raeburn 3774: } elsif ($token->[1] eq 'param') {
1.488 raeburn 3775: if ($folder =~ /^supplemental/) {
1.492 raeburn 3776: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
3777: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
3778: } else {
3779: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
3780: }
1.488 raeburn 3781: }
3782: }
3783: }
3784: }
3785: return;
3786: }
3787:
3788: sub url_paste_fixups {
1.533 raeburn 3789: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
3790: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 3791: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 3792: my $checktitle;
3793: if (($prefixchg) &&
1.492 raeburn 3794: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 3795: $checktitle = 1;
3796: }
1.492 raeburn 3797: my $skip;
3798: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
3799: my $mapid = $1.$2;
3800: if ($tomove->{$mapid}) {
3801: $skip = 1;
3802: }
3803: }
1.491 raeburn 3804: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 3805: return if ($file eq '-1');
3806: my $parser = HTML::TokeParser->new(\$file);
3807: $parser->attr_encoded(1);
1.491 raeburn 3808: my $changed = 0;
1.488 raeburn 3809: while (my $token = $parser->get_token) {
3810: next if ($token->[0] ne 'S');
3811: if ($token->[1] eq 'resource') {
3812: my $ressrc = $token->[2]->{'src'};
3813: next if ($ressrc eq '');
1.491 raeburn 3814: my $id = $token->[2]->{'id'};
1.492 raeburn 3815: my $title = $token->[2]->{'title'};
1.491 raeburn 3816: if ($checktitle) {
3817: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 3818: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3819: }
3820: }
1.488 raeburn 3821: next if ($token->[2]->{'type'} eq 'external');
3822: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 3823: next if ($skip);
1.532 raeburn 3824: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3825: $changed = 1;
3826: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3827: my $srcdom = $1;
3828: my $srcnum = $2;
1.488 raeburn 3829: my $rem = $3;
1.492 raeburn 3830: my $newurl;
3831: my $mapname;
3832: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
3833: my $prefix = $1;
3834: $mapname = $prefix.$2;
3835: if ($tomove->{$mapname}) {
1.533 raeburn 3836: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
3837: $srcdom,$srcnum,$allmaps,$rewrites,
3838: $retitles,$copies,$dbcopies,$zombies,
3839: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 3840: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 3841: next;
3842: } else {
3843: ($newurl,my $error) =
3844: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
3845: $srcdom,$srcnum,\$title,$allmaps,$newurls);
3846: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
3847: $newsubdir->{$ressrc} = $1;
3848: }
3849: if ($error) {
3850: next;
3851: }
3852: }
3853: }
3854: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
3855: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
3856:
1.488 raeburn 3857: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 3858: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3859: $mapchanges->{$ressrc} = 1;
1.533 raeburn 3860: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
3861: $cnum,$srcdom,$srcnum,$allmaps,
3862: $rewrites,$retitles,$copies,$dbcopies,
3863: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 3864: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 3865: $mapmoves->{$ressrc} = 1;
3866: }
3867: $changed = 1;
1.488 raeburn 3868: } else {
1.532 raeburn 3869: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 3870: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 3871: $changed = 1;
1.488 raeburn 3872: }
3873: }
1.649 raeburn 3874: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 3875: next if ($skip);
1.492 raeburn 3876: my $srcdom = $1;
3877: my $srcnum = $2;
1.649 raeburn 3878: my $rem = $3;
3879: my ($is_exttool,$exttoolchg);
3880: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 3881: $is_exttool = 1;
1.649 raeburn 3882: }
1.492 raeburn 3883: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 3884: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 3885: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3886: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3887: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3888: $changed = 1;
1.649 raeburn 3889: if ($is_exttool) {
3890: $exttoolchg = 1;
3891: }
1.700 raeburn 3892: } elsif (($is_exttool) &&
1.649 raeburn 3893: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3894: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3895: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3896: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3897: $changed = 1;
3898: $exttoolchg = 1;
3899: }
3900: if (($is_exttool) && ($prefixchg)) {
3901: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
3902: if ($exttoolchg) {
3903: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
3904: }
3905: }
1.533 raeburn 3906: }
3907: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
3908: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
3909: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3910: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3911: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
3912: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 3913: $changed = 1;
1.488 raeburn 3914: }
1.597 raeburn 3915: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
3916: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
3917: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
3918: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
3919: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
3920: }
1.488 raeburn 3921: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3922: next if ($skip);
3923: my $srcdom = $1;
3924: my $srcnum = $2;
3925: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 3926: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3927: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3928: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 3929: $changed = 1;
1.488 raeburn 3930: }
3931: }
3932: } elsif ($token->[1] eq 'param') {
1.492 raeburn 3933: next if ($skip);
1.488 raeburn 3934: my $to = $token->[2]->{'to'};
3935: if ($to ne '') {
3936: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 3937: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 3938: } else {
3939: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
3940: }
3941: }
3942: }
3943: }
1.491 raeburn 3944: return $changed;
1.488 raeburn 3945: }
3946:
3947: sub apply_fixups {
1.529 raeburn 3948: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
3949: $oldurl,$url,$caller) = @_;
3950: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 3951: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.704 raeburn 3952: %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
3953: %currltititles,$currltimax);
3954: $currltimax = 0;
1.529 raeburn 3955: if (ref($updated) eq 'HASH') {
3956: if (ref($updated->{'rewrites'}) eq 'HASH') {
3957: %rewrites = %{$updated->{'rewrites'}};
3958: }
3959: if (ref($updated->{'zombies'}) eq 'HASH') {
3960: %zombies = %{$updated->{'zombies'}};
3961: }
3962: if (ref($updated->{'removefrommap'}) eq 'HASH') {
3963: %removefrommap = %{$updated->{'removefrommap'}};
3964: }
3965: if (ref($updated->{'removeparam'}) eq 'HASH') {
3966: %removeparam = %{$updated->{'removeparam'}};
3967: }
3968: if (ref($updated->{'dbcopies'}) eq 'HASH') {
3969: %dbcopies = %{$updated->{'dbcopies'}};
3970: }
3971: if (ref($updated->{'retitles'}) eq 'HASH') {
3972: %retitles = %{$updated->{'retitles'}};
3973: }
1.597 raeburn 3974: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
3975: %resdatacopy = %{$updated->{'resdatacopy'}};
3976: }
1.529 raeburn 3977: }
3978: if (ref($info) eq 'HASH') {
3979: if (ref($info->{'newsubdir'}) eq 'HASH') {
3980: %newsubdir = %{$info->{'newsubdir'}};
3981: }
3982: if (ref($info->{'params'}) eq 'HASH') {
3983: %params = %{$info->{'params'}};
3984: }
3985: if (ref($info->{'before'}) eq 'HASH') {
3986: %before = %{$info->{'before'}};
3987: }
3988: if (ref($info->{'after'}) eq 'HASH') {
3989: %after = %{$info->{'after'}};
3990: }
3991: }
3992: if (ref($moves) eq 'HASH') {
3993: if (ref($moves->{'copies'}) eq 'HASH') {
3994: %copies = %{$moves->{'copies'}};
3995: }
3996: if (ref($moves->{'docmoves'}) eq 'HASH') {
3997: %docmoves = %{$moves->{'docmoves'}};
3998: }
3999: if (ref($moves->{'mapmoves'}) eq 'HASH') {
4000: %mapmoves = %{$moves->{'mapmoves'}};
4001: }
4002: }
4003: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 4004: my @allcopies;
1.529 raeburn 4005: if (exists($copies{$key})) {
4006: if (ref($copies{$key}) eq 'HASH') {
4007: my %added;
4008: foreach my $innerkey (keys(%{$copies{$key}})) {
4009: if (($innerkey ne '') && (!$added{$innerkey})) {
4010: push(@allcopies,$innerkey);
4011: $added{$innerkey} = 1;
4012: }
1.491 raeburn 4013: }
1.529 raeburn 4014: undef(%added);
1.491 raeburn 4015: }
4016: }
4017: if ($key eq $oldurl) {
1.529 raeburn 4018: if ((exists($docmoves{$key}))) {
1.532 raeburn 4019: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 4020: push(@allcopies,$oldurl);
4021: }
4022: }
4023: }
4024: if (@allcopies > 0) {
4025: foreach my $item (@allcopies) {
1.492 raeburn 4026: my ($relpath,$oldsubdir,$fname) =
4027: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 4028: if ($fname ne '') {
4029: my $content = &Apache::lonnet::getfile($item);
4030: unless ($content eq '-1') {
4031: my $storefn;
1.529 raeburn 4032: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
4033: $storefn = $docmoves{$key};
1.491 raeburn 4034: } else {
4035: $storefn = $relpath;
4036: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4037: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
4038: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 4039: }
1.529 raeburn 4040: if ($newsubdir{$key}) {
1.532 raeburn 4041: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 4042: }
4043: }
4044: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
4045: my $copyurl =
4046: &Apache::lonclonecourse::writefile($env{'request.course.id'},
4047: $storefn.$fname,$content);
4048: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 4049: if (exists($docmoves{$oldurl})) {
1.491 raeburn 4050: return &mt('Paste failed: an error occurred copying the file.');
4051: } elsif (ref($errors) eq 'HASH') {
4052: $errors->{$item} = 1;
1.489 raeburn 4053: }
4054: }
1.488 raeburn 4055: }
4056: }
1.491 raeburn 4057: }
4058: }
4059: }
1.529 raeburn 4060: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 4061: my $storefn=$key;
4062: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4063: if ($prefixchg && $before{'map'} && $after{'map'}) {
4064: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 4065: }
1.529 raeburn 4066: if ($newsubdir{$key}) {
4067: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 4068: }
1.491 raeburn 4069: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 4070: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
4071: ($after{'map'} eq 'default') &&
4072: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
4073: $mapcontent = '<map>'."\n".
4074: '<resource id="1" src="" type="start" />'."\n".
4075: '<link from="1" to="2" index="1" />'."\n".
4076: '<resource id="2" src="" type="finish" />'."\n".
4077: '</map>';
4078: }
1.491 raeburn 4079: if ($mapcontent eq '-1') {
4080: if (ref($errors) eq 'HASH') {
4081: $errors->{$key} = 1;
4082: }
4083: } else {
4084: my $newmap =
4085: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
4086: $mapcontent);
4087: if ($newmap eq '/adm/notfound.html') {
4088: if (ref($errors) eq 'HASH') {
4089: $errors->{$key} = 1;
1.489 raeburn 4090: }
1.488 raeburn 4091: }
4092: }
4093: }
1.491 raeburn 4094: my %updates;
4095: if ($is_map) {
1.529 raeburn 4096: if (ref($updated) eq 'HASH') {
4097: foreach my $type (keys(%{$updated})) {
4098: if (ref($updated->{$type}) eq 'HASH') {
4099: foreach my $key (keys(%{$updated->{$type}})) {
4100: $updates{$key} = 1;
4101: }
4102: }
4103: }
1.491 raeburn 4104: }
1.704 raeburn 4105: my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.491 raeburn 4106: foreach my $key (keys(%updates)) {
1.492 raeburn 4107: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 4108: if (ref($rewrites{$key}) eq 'HASH') {
4109: %torewrite = %{$rewrites{$key}};
1.491 raeburn 4110: }
1.529 raeburn 4111: if (ref($retitles{$key}) eq 'HASH') {
4112: %toretitle = %{$retitles{$key}};
1.491 raeburn 4113: }
1.529 raeburn 4114: if (ref($removefrommap{$key}) eq 'HASH') {
4115: %toremove = %{$removefrommap{$key}};
1.491 raeburn 4116: }
1.529 raeburn 4117: if (ref($removeparam{$key}) eq 'HASH') {
4118: %remparam = %{$removeparam{$key}};
1.492 raeburn 4119: }
1.529 raeburn 4120: if (ref($zombies{$key}) eq 'HASH') {
4121: %zombie = %{$zombies{$key}};
1.491 raeburn 4122: }
1.529 raeburn 4123: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 4124: foreach my $idx (keys(%{$dbcopies{$key}})) {
4125: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.704 raeburn 4126: my $oldurl = $dbcopies{$key}{$idx}{'src'};
4127: my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
4128: my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
4129: my $oldmarker;
4130: if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
4131: $oldmarker = $1;
4132: unless (($gotcrsltitools) ||
4133: (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
4134: my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
4135: if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
4136: unless ($gotcrsltitools) {
4137: %currcrsltitools =
4138: &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
4139: foreach my $item (sort(keys(%currcrsltitools))) {
4140: if (ref($currcrsltitools{$item}) eq 'HASH') {
4141: $currltimax ++;
4142: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
4143: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
4144: } else {
4145: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
4146: }
4147: }
4148: }
4149: $gotcrsltitools = 1;
4150: }
4151: unless ($checkedsameinst) {
4152: my $primary_id = &Apache::lonnet::domain($cdom,'primary');
4153: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4154: if ($intdom ne '') {
4155: my $internet_names =
4156: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4157: if (ref($internet_names) eq 'ARRAY') {
4158: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4159: $same_institution = 1;
4160: }
4161: }
4162: }
4163: $checkedsameinst = 1;
4164: }
4165: }
4166: }
4167: }
1.533 raeburn 4168: my ($newurl,$result,$errtext) =
1.704 raeburn 4169: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
4170: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.533 raeburn 4171: if ($result eq 'ok') {
4172: $newdb{$idx} = $newurl;
1.704 raeburn 4173: if ($newurl =~ /ext\.tool$/) {
4174: if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
4175: if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
4176: my $newmarker = $1;
4177: unless ($oldmarker eq $newmarker) {
4178: $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
4179: }
4180: }
4181: }
4182: }
1.533 raeburn 4183: } elsif (ref($errors) eq 'HASH') {
4184: $errors->{$key} = 1;
4185: }
4186: push(@msgs,$errtext);
4187: }
1.491 raeburn 4188: }
4189: }
1.597 raeburn 4190: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 4191: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 4192: foreach my $idx (keys(%{$resdatacopy{$key}})) {
4193: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
4194: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
4195: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
4196: my $template = $1;
4197: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
4198: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
4199: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
4200: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 4201: unless ($gotnewmapname) {
4202: ($newmapname) = ($key =~ m{/([^/]+)$});
4203: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
4204: if ($newsubdir{$key}) {
4205: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
4206: }
4207: $gotnewmapname = 1;
4208: }
1.597 raeburn 4209: my $srcmapinfo = $srcfolder.':'.$idx;
4210: if ($srccontainer eq 'page') {
4211: $srcmapinfo .= ':1';
4212: }
4213: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
4214: $cnum,$template,$idx,$newmapname);
4215: }
4216: }
4217: }
4218: }
4219: }
1.529 raeburn 4220: if (ref($params{$key}) eq 'HASH') {
4221: %currparam = %{$params{$key}};
1.492 raeburn 4222: }
4223: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
4224: if ($fatal) {
1.533 raeburn 4225: return ($errtext);
1.492 raeburn 4226: }
4227: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
4228: if (defined($LONCAPA::map::zombies[$i])) {
4229: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 4230: if ($zombie{$i} eq $src) {
1.492 raeburn 4231: undef($LONCAPA::map::zombies[$i]);
4232: }
4233: }
4234: }
1.646 raeburn 4235: my $total = scalar(@LONCAPA::map::order) - 1;
4236: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 4237: my $idx = $LONCAPA::map::order[$i];
4238: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 4239: my $changed;
1.529 raeburn 4240: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 4241: if ((exists($toremove{$idx})) &&
4242: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 4243: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 4244: if (ref($currparam{$idx}) eq 'ARRAY') {
4245: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 4246: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 4247: }
4248: }
4249: next;
4250: }
4251: my $origsrc = $src;
1.532 raeburn 4252: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 4253: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
4254: $changed = 1;
1.491 raeburn 4255: }
1.492 raeburn 4256: }
1.532 raeburn 4257: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 4258: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
4259: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 4260: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 4261: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 4262: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 4263: } else {
1.529 raeburn 4264: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 4265: }
1.491 raeburn 4266: }
1.532 raeburn 4267: if ($origsrc =~ /\.(page|sequence)$/) {
4268: if ($newsubdir{$origsrc}) {
1.529 raeburn 4269: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 4270: }
1.532 raeburn 4271: } elsif ($newsubdir{$key}) {
4272: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 4273: }
4274: }
1.492 raeburn 4275: $changed = 1;
1.533 raeburn 4276: } elsif ($newdb{$idx} ne '') {
4277: $src = $newdb{$idx};
1.492 raeburn 4278: $changed = 1;
4279: }
4280: if ($changed) {
1.538 raeburn 4281: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 4282: }
4283: }
4284: }
4285: foreach my $idx (keys(%remparam)) {
4286: if (ref($remparam{$idx}) eq 'ARRAY') {
4287: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 4288: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 4289: }
4290: }
4291: }
1.533 raeburn 4292: if (values(%lockerrors) > 0) {
4293: $lockmsg = join('<br />',values(%lockerrors));
4294: }
1.491 raeburn 4295: my $storefn;
4296: if ($key eq $oldurl) {
4297: $storefn = $url;
4298: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
4299: } else {
4300: $storefn = $key;
4301: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4302: if ($prefixchg && $before{'map'} && $after{'map'}) {
4303: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 4304: }
1.529 raeburn 4305: if ($newsubdir{$key}) {
4306: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 4307: }
1.491 raeburn 4308: }
1.492 raeburn 4309: my $report;
4310: if ($folder !~ /^supplemental/) {
4311: $report = 1;
4312: }
1.527 raeburn 4313: (my $outtext,$errtext) =
1.492 raeburn 4314: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
4315: if ($errtext) {
1.529 raeburn 4316: if ($caller eq 'paste') {
1.533 raeburn 4317: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 4318: }
1.491 raeburn 4319: }
4320: }
1.704 raeburn 4321: if (($updatetoolscache) || (@updatetoolsenc)) {
4322: &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
4323: \@updatetoolsenc);
4324: }
1.491 raeburn 4325: }
1.533 raeburn 4326: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 4327: }
4328:
4329: sub copy_dependencies {
4330: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
4331: my $content;
4332: if (ref($contentref)) {
4333: $content = $$contentref;
4334: } else {
4335: $content = &Apache::lonnet::getfile($item);
4336: }
4337: unless ($content eq '-1') {
4338: my $mm = new File::MMagic;
4339: my $mimetype = $mm->checktype_contents($content);
4340: if ($mimetype eq 'text/html') {
4341: my (%allfiles,%codebase,$state);
4342: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
4343: if ($res eq 'ok') {
4344: my ($numexisting,$numpathchanges,$existing);
4345: (undef,$numexisting,$numpathchanges,$existing) =
4346: &Apache::loncommon::ask_for_embedded_content(
4347: '/adm/coursedocs',$state,\%allfiles,\%codebase,
4348: {'error_on_invalid_names' => 1,
4349: 'ignore_remote_references' => 1,
4350: 'docs_url' => $item,
4351: 'context' => 'paste'});
4352: if ($numexisting > 0) {
4353: if (ref($existing) eq 'HASH') {
4354: foreach my $dep (keys(%{$existing})) {
4355: my $depfile = $dep;
4356: unless ($depfile =~ m{^\Q$relpath\E}) {
4357: $depfile = $relpath.$dep;
4358: }
4359: my $depcontent = &Apache::lonnet::getfile($depfile);
4360: unless ($depcontent eq '-1') {
4361: my $storedep = $dep;
4362: $storedep =~ s{^\Q$relpath\E}{};
4363: my $dep_url =
4364: &Apache::lonclonecourse::writefile(
4365: $env{'request.course.id'},
4366: $storefn.$storedep,$depcontent);
4367: if ($dep_url eq '/adm/notfound.html') {
4368: if (ref($errors) eq 'HASH') {
4369: $errors->{$depfile} = 1;
4370: }
4371: } else {
4372: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
4373: }
4374: }
4375: }
1.488 raeburn 4376: }
4377: }
4378: }
4379: }
4380: }
4381: return;
4382: }
4383:
1.329 droeschl 4384: my %parameter_type = ( 'randompick' => 'int_pos',
4385: 'hiddenresource' => 'string_yesno',
4386: 'encrypturl' => 'string_yesno',
4387: 'randomorder' => 'string_yesno',);
4388: my $valid_parameters_re = join('|',keys(%parameter_type));
4389: # set parameters
4390: sub update_parameter {
1.537 raeburn 4391: if ($env{'form.changeparms'} eq 'all') {
4392: my (@allidx,@allmapidx,%allchecked,%currchecked);
4393: %allchecked = (
4394: 'hiddenresource' => {},
4395: 'encrypturl' => {},
4396: 'randompick' => {},
4397: 'randomorder' => {},
4398: );
4399: foreach my $which (keys(%allchecked)) {
1.630 raeburn 4400: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 4401: if ($which eq 'randompick') {
4402: foreach my $item (split(/,/,$env{'form.all'.$which})) {
4403: my ($res,$value) = split(/:/,$item);
4404: if ($value =~ /^\d+$/) {
4405: $allchecked{$which}{$res} = $value;
4406: }
4407: }
4408: } else {
1.539 raeburn 4409: if ($env{'form.all'.$which}) {
4410: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
4411: }
1.537 raeburn 4412: }
4413: }
4414: my $haschanges = 0;
4415: foreach my $res (@LONCAPA::map::order) {
4416: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4417: $name=&LONCAPA::map::qtescape($name);
4418: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 4419: next unless $url;
1.537 raeburn 4420: my $is_map;
4421: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4422: $is_map = 1;
4423: }
4424: foreach my $which (keys(%allchecked)) {
4425: if (($which eq 'randompick' || $which eq 'randomorder')) {
4426: next if (!$is_map);
4427: }
4428: my $oldvalue = 0;
4429: my $newvalue = 0;
4430: if ($allchecked{$which}{$res}) {
4431: $newvalue = $allchecked{$which}{$res};
4432: }
4433: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
4434: if ($which eq 'randompick') {
4435: if ($current =~ /^(\d+)$/) {
4436: $oldvalue = $1;
4437: }
4438: } else {
4439: if ($current =~ /^yes$/i) {
4440: $oldvalue = 1;
4441: }
4442: }
4443: if ($oldvalue ne $newvalue) {
4444: $haschanges = 1;
4445: if ($newvalue) {
4446: my $storeval = 'yes';
4447: if ($which eq 'randompick') {
4448: $storeval = $newvalue;
4449: }
4450: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
4451: $storeval,
4452: $parameter_type{$which});
4453: &remember_parms($res,$which,'set',$storeval);
4454: } elsif ($oldvalue) {
4455: &LONCAPA::map::delparameter($res,'parameter_'.$which);
4456: &remember_parms($res,$which,'del');
4457: }
4458: }
4459: }
4460: }
4461: return $haschanges;
4462: } else {
1.588 raeburn 4463: my $haschanges = 0;
4464: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 4465:
1.537 raeburn 4466: my $which = $env{'form.changeparms'};
4467: my $idx = $env{'form.setparms'};
1.588 raeburn 4468: my $oldvalue = 0;
4469: my $newvalue = 0;
4470: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
4471: if ($which eq 'randompick') {
4472: if ($current =~ /^(\d+)$/) {
4473: $oldvalue = $1;
4474: }
4475: } elsif ($current =~ /^yes$/i) {
4476: $oldvalue = 1;
4477: }
1.537 raeburn 4478: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 4479: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
4480: : 1;
4481: }
4482: if ($oldvalue ne $newvalue) {
4483: $haschanges = 1;
4484: if ($newvalue) {
4485: my $storeval = 'yes';
4486: if ($which eq 'randompick') {
4487: $storeval = $newvalue;
4488: }
4489: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
4490: $parameter_type{$which});
4491: &remember_parms($idx,$which,'set',$storeval);
4492: } else {
4493: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
4494: &remember_parms($idx,$which,'del');
4495: }
1.537 raeburn 4496: }
1.588 raeburn 4497: return $haschanges;
1.329 droeschl 4498: }
4499: }
4500:
4501: sub handle_edit_cmd {
4502: my ($coursenum,$coursedom) =@_;
1.633 raeburn 4503: my $haschanges = 0;
1.543 raeburn 4504: if ($env{'form.cmd'} eq '') {
1.633 raeburn 4505: return $haschanges;
1.543 raeburn 4506: }
1.329 droeschl 4507: my ($cmd,$idx)=split('_',$env{'form.cmd'});
4508:
4509: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
4510: my ($title, $url, @rrest) = split(':', $ratstr);
4511:
1.538 raeburn 4512: if ($cmd eq 'remove') {
1.329 droeschl 4513: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 4514: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 4515: &Apache::lonnet::removeuploadedurl($url);
4516: } else {
4517: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4518: }
4519: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4520: $haschanges = 1;
1.329 droeschl 4521: } elsif ($cmd eq 'cut') {
4522: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4523: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4524: $haschanges = 1;
1.344 bisitz 4525: } elsif ($cmd eq 'up'
1.329 droeschl 4526: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
4527: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 4528: $haschanges = 1;
1.329 droeschl 4529: } elsif ($cmd eq 'down'
4530: && defined($LONCAPA::map::order[$idx+1])) {
4531: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 4532: $haschanges = 1;
1.329 droeschl 4533: } elsif ($cmd eq 'rename') {
4534: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
4535: if ($comment=~/\S/) {
4536: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
4537: $comment.':'.join(':', $url, @rrest);
4538: }
4539: # Devalidate title cache
4540: my $renamed_url=&LONCAPA::map::qtescape($url);
4541: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 4542: $haschanges = 1;
4543: } elsif ($cmd eq 'setalias') {
4544: my $newvalue = $env{'form.alias'};
4545: if ($newvalue ne '') {
4546: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
4547: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
4548: 'string');
4549: &remember_parms($idx,'mapalias','set',$newvalue);
4550: $haschanges = 1;
4551: }
4552: }
4553: } elsif ($cmd eq 'delalias') {
4554: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
4555: if ($current ne '') {
4556: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
4557: &remember_parms($idx,'mapalias','del');
4558: $haschanges = 1;
4559: }
1.329 droeschl 4560: }
1.633 raeburn 4561: return $haschanges;
1.329 droeschl 4562: }
4563:
4564: sub editor {
1.458 raeburn 4565: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 4566: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 4567: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 4568: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 4569: if ($allowed) {
1.519 raeburn 4570: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
4571: $is_random_order,$container) =
1.510 raeburn 4572: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
4573: $r->print($breadcrumbtrail);
1.519 raeburn 4574: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
4575: $container = 'page';
4576: } else {
4577: $container = 'sequence';
1.510 raeburn 4578: }
1.484 raeburn 4579:
1.525 raeburn 4580: my $jumpto;
4581:
4582: unless ($supplementalflag) {
1.546 raeburn 4583: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 4584: }
1.484 raeburn 4585:
4586: unless ($allowed) {
4587: $randompick = -1;
4588: }
4589:
1.615 raeburn 4590: my ($errtext,$fatal);
4591: if (($folder eq '') && (!$supplementalflag)) {
4592: if (@LONCAPA::map::order) {
4593: undef(@LONCAPA::map::order);
4594: undef(@LONCAPA::map::resources);
4595: undef(@LONCAPA::map::resparms);
4596: undef(@LONCAPA::map::zombies);
4597: }
4598: $folder = 'default';
4599: $container = 'sequence';
4600: } else {
4601: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
4602: $folder.'.'.$container);
4603: return $errtext if ($fatal);
4604: }
1.329 droeschl 4605:
4606: if ($#LONCAPA::map::order<1) {
4607: my $idx=&LONCAPA::map::getresidx();
4608: if ($idx<=0) { $idx=1; }
4609: $LONCAPA::map::order[0]=$idx;
4610: $LONCAPA::map::resources[$idx]='';
4611: }
1.364 bisitz 4612:
1.329 droeschl 4613: # ------------------------------------------------------------ Process commands
4614:
4615: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 4616: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 4617: # set parameters and change order
4618: &snapshotbefore();
4619:
4620: if (&update_parameter()) {
1.588 raeburn 4621: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 4622: return $errtext if ($fatal);
4623: }
4624:
4625: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
4626: # change order
4627: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
4628: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
4629:
4630: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
4631: return $errtext if ($fatal);
4632: }
1.364 bisitz 4633:
1.329 droeschl 4634: if ($env{'form.pastemarked'}) {
1.491 raeburn 4635: my %paste_errors;
1.533 raeburn 4636: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 4637: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
4638: \%paste_errors);
1.541 raeburn 4639: if (ref($pastemsgarray) eq 'ARRAY') {
4640: if (@{$pastemsgarray} > 0) {
4641: $r->print('<p class="LC_info">'.
4642: join('<br />',@{$pastemsgarray}).
1.533 raeburn 4643: '</p>');
4644: }
1.541 raeburn 4645: }
4646: if ($lockerror) {
4647: $r->print('<p class="LC_error">'.
4648: $lockerror.
4649: '</p>');
4650: }
4651: if ($save_error ne '') {
4652: return $save_error;
4653: }
4654: if ($paste_res) {
4655: my %errortext = &Apache::lonlocal::texthash (
4656: fail => 'Storage of folder contents failed',
4657: failread => 'Reading folder contents failed',
4658: failstore => 'Storage of folder contents failed',
4659: );
4660: if ($errortext{$paste_res}) {
4661: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 4662: }
1.329 droeschl 4663: }
1.491 raeburn 4664: if (keys(%paste_errors) > 0) {
1.538 raeburn 4665: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 4666: &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".
4667: '<ul>'."\n");
4668: foreach my $key (sort(keys(%paste_errors))) {
4669: $r->print('<li>'.$key.'</li>'."\n");
4670: }
4671: $r->print('</ul></p>'."\n");
4672: }
1.538 raeburn 4673: } elsif ($env{'form.clearmarked'}) {
4674: my $output = &do_buffer_empty();
4675: if ($output) {
4676: $r->print('<p class="LC_info">'.$output.'</p>');
4677: }
4678: }
1.329 droeschl 4679:
4680: $r->print($upload_output);
4681:
1.538 raeburn 4682: # Rename, cut, copy or remove a single resource
1.602 raeburn 4683: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 4684: my $contentchg;
1.633 raeburn 4685: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 4686: $contentchg = 1;
4687: }
4688: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 4689: return $errtext if ($fatal);
4690: }
1.538 raeburn 4691:
4692: # Cut, copy and/or remove multiple resources
4693: if ($env{'form.multichange'}) {
4694: my %allchecked = (
4695: cut => {},
4696: remove => {},
4697: );
4698: my $needsupdate;
4699: foreach my $which (keys(%allchecked)) {
4700: $env{'form.multi'.$which} =~ s/,$//;
4701: if ($env{'form.multi'.$which}) {
4702: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
4703: if (ref($allchecked{$which}) eq 'HASH') {
4704: $needsupdate += scalar(keys(%{$allchecked{$which}}));
4705: }
4706: }
4707: }
4708: if ($needsupdate) {
4709: my $haschanges = 0;
4710: my %curr_groups = &Apache::longroup::coursegroups();
4711: my $total = scalar(@LONCAPA::map::order) - 1;
4712: for (my $i=$total; $i>=0; $i--) {
4713: my $res = $LONCAPA::map::order[$i];
4714: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4715: $name=&LONCAPA::map::qtescape($name);
4716: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 4717: next unless $url;
1.538 raeburn 4718: my %denied =
4719: &action_restrictions($coursenum,$coursedom,$url,
4720: $env{'form.folderpath'},\%curr_groups);
4721: foreach my $which (keys(%allchecked)) {
4722: next if ($denied{$which});
4723: next unless ($allchecked{$which}{$res});
4724: if ($which eq 'remove') {
4725: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4726: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4727: &Apache::lonnet::removeuploadedurl($url);
4728: } else {
4729: &LONCAPA::map::makezombie($res);
4730: }
4731: splice(@LONCAPA::map::order,$i,1);
4732: $haschanges ++;
4733: } elsif ($which eq 'cut') {
4734: &LONCAPA::map::makezombie($res);
4735: splice(@LONCAPA::map::order,$i,1);
4736: $haschanges ++;
4737: }
4738: }
4739: }
4740: if ($haschanges) {
4741: ($errtext,$fatal) =
4742: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
4743: return $errtext if ($fatal);
4744: }
4745: }
4746: }
4747:
1.329 droeschl 4748: # Group import/search
4749: if ($env{'form.importdetail'}) {
4750: my @imports;
4751: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
4752: if (defined($item)) {
4753: my ($name,$url,$residx)=
1.533 raeburn 4754: map { &unescape($_); } split(/\=/,$item);
4755: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
4756: my ($suffix,$errortxt,$locknotfreed) =
4757: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 4758: if ($locknotfreed) {
4759: $r->print($locknotfreed);
4760: }
4761: if ($suffix) {
4762: $url =~ s/_new\./_$suffix./;
4763: } else {
4764: return $errortxt;
4765: }
1.533 raeburn 4766: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
4767: my $type = $1;
4768: my ($suffix,$errortxt,$locknotfreed) =
4769: &new_timebased_suffix($coursedom,$coursenum,$type);
4770: if ($locknotfreed) {
4771: $r->print($locknotfreed);
4772: }
4773: if ($suffix) {
4774: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
4775: } else {
4776: return $errortxt;
4777: }
1.626 raeburn 4778: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 4779: my ($suffix,$errortxt,$locknotfreed) =
4780: &new_timebased_suffix($coursedom,$coursenum,'exttool');
4781: if ($locknotfreed) {
4782: $r->print($locknotfreed);
4783: }
4784: if ($suffix) {
4785: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
4786: } else {
4787: return $errortxt;
4788: }
1.534 raeburn 4789: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
4790: if ($supplementalflag) {
4791: next unless ($1 eq 'supplemental');
4792: if ($folder eq 'supplemental') {
4793: next unless ($2 eq 'default');
4794: } else {
4795: next unless ($folder eq 'supplemental_'.$2);
4796: }
4797: } else {
4798: next unless ($1 eq 'docs');
4799: if ($folder eq 'default') {
4800: next unless ($2 eq 'default');
4801: } else {
4802: next unless ($folder eq 'default_'.$2);
4803: }
4804: }
1.504 raeburn 4805: }
1.329 droeschl 4806: push(@imports, [$name, $url, $residx]);
4807: }
4808: }
1.530 raeburn 4809: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 4810: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 4811: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 4812: return $errtext if ($fatal);
1.529 raeburn 4813: if ($fixuperrors) {
4814: $r->print($fixuperrors);
4815: }
1.329 droeschl 4816: }
4817: # Loading a complete map
4818: if ($env{'form.loadmap'}) {
4819: if ($env{'form.importmap'}=~/\w/) {
4820: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
4821: my ($title,$url,$ext,$type)=split(/\:/,$res);
4822: my $idx=&LONCAPA::map::getresidx($url);
4823: $LONCAPA::map::resources[$idx]=$res;
4824: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
4825: }
4826: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 4827: $folder.'.'.$container,1);
1.329 droeschl 4828: return $errtext if ($fatal);
4829: } else {
4830: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 4831:
1.329 droeschl 4832: }
4833: }
4834: &log_differences($plain);
4835: }
4836: # ---------------------------------------------------------------- End commands
4837: # ---------------------------------------------------------------- Print screen
4838: my $idx=0;
4839: my $shown=0;
4840: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 4841: $r->print('<div class="LC_Box">'.
1.432 raeburn 4842: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
4843: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
4844: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
4845: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
4846: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 4847: '</ol>');
1.381 bisitz 4848: if ($randompick>=0) {
4849: $r->print('<p class="LC_warning">'
4850: .&mt('Caution: this folder is set to randomly pick a subset'
4851: .' of resources. Adding or removing resources from this'
4852: .' folder will change the set of resources that the'
4853: .' students see, resulting in spurious or missing credit'
4854: .' for completed problems, not limited to ones you'
4855: .' modify. Do not modify the contents of this folder if'
4856: .' it is in active student use.')
4857: .'</p>'
4858: );
4859: }
4860: if ($is_random_order) {
4861: $r->print('<p class="LC_warning">'
4862: .&mt('Caution: this folder is set to randomly order its'
4863: .' contents. Adding or removing resources from this folder'
4864: .' will change the order of resources shown.')
4865: .'</p>'
4866: );
4867: }
4868: $r->print('</div>');
1.364 bisitz 4869: }
1.381 bisitz 4870:
1.685 raeburn 4871: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 4872: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 4873: if (ref($supplemental) eq 'HASH') {
4874: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
4875: (ref($supplemental->{'ids'}) eq 'HASH')) {
4876: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
4877: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
4878: if ($supplemental->{'hidden'}->{$mapnum}) {
4879: $ishidden = 1;
4880: }
4881: }
4882: }
4883: }
4884: }
4885:
1.538 raeburn 4886: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
4887: %filters = (
1.543 raeburn 4888: canremove => [],
4889: cancut => [],
4890: cancopy => [],
4891: hiddenresource => [],
4892: encrypturl => [],
4893: randomorder => [],
4894: randompick => [],
1.538 raeburn 4895: );
4896: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 4897: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 4898: foreach my $res (@LONCAPA::map::order) {
4899: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4900: $name=&LONCAPA::map::qtescape($name);
4901: $url=&LONCAPA::map::qtescape($url);
4902: unless ($name) { $name=(split(/\//,$url))[-1]; }
4903: unless ($name) { $idx++; next; }
1.537 raeburn 4904: push(@allidx,$res);
4905: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4906: push(@allmapidx,$res);
4907: }
1.617 raeburn 4908:
1.682 raeburn 4909: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 4910: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
4911: $idx++;
4912: next;
4913: }
1.682 raeburn 4914: }
1.381 bisitz 4915: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 4916: $coursenum,$coursedom,$crstype,
1.538 raeburn 4917: $pathitem,$supplementalflag,$container,
1.620 raeburn 4918: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 4919: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 4920: $idx++;
4921: $shown++;
1.329 droeschl 4922: }
1.424 onken 4923: &Apache::loncommon::end_data_table_count();
1.510 raeburn 4924:
1.538 raeburn 4925: my $need_save;
1.611 raeburn 4926: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 4927: my $toolslink;
1.682 raeburn 4928: if ($allowed || $canedit) {
4929: my $helpitem = 'Navigation_Screen';
4930: if (!$allowed) {
4931: $helpitem = 'Supplemental_Navigation';
4932: }
1.544 raeburn 4933: $toolslink = '<table><tr><td>'
1.520 raeburn 4934: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 4935: $helpitem,undef,'RAT')
1.520 raeburn 4936: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
4937: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 4938: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 4939: .'id="LC_content_toolbar_edittoplevel" '
4940: .'class="LC_toolbarItem" '
4941: .'title="'.&mt('Supplemental Content Editor').'">'
4942: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 4943: }
1.510 raeburn 4944: if ($shown) {
4945: if ($allowed) {
4946: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
4947: .&Apache::loncommon::start_data_table(undef,'contentlist')
4948: .&Apache::loncommon::start_data_table_header_row()
4949: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 4950: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 4951: .'<th>'.&mt('Document').'</th>'
4952: .'<th colspan="2">'.&mt('Settings').'</th>'
4953: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 4954: if ($folder !~ /^supplemental/) {
1.538 raeburn 4955: $lists{'canhide'} = join(',',@allidx);
4956: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 4957: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
4958: 'randomorder','randompick');
4959: foreach my $item (@possfilters) {
1.538 raeburn 4960: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 4961: if (@{$filters{$item}} > 0) {
4962: $lists{$item} = join(',',@{$filters{$item}});
4963: }
1.538 raeburn 4964: }
4965: }
1.537 raeburn 4966: if (@allidx > 0) {
4967: my $path;
4968: if ($env{'form.folderpath'}) {
1.630 raeburn 4969: $path =
1.537 raeburn 4970: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4971: }
1.538 raeburn 4972: if (@allidx > 1) {
1.630 raeburn 4973: $to_show .=
1.538 raeburn 4974: &Apache::loncommon::continue_data_table_row().
4975: '<td colspan="2"> </td>'.
4976: '<td>'.
1.611 raeburn 4977: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 4978: '</td>'.
1.633 raeburn 4979: '<td colspan="3"> </td>'.
4980: '<td colspan="2">'.
1.611 raeburn 4981: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 4982: '</td>'.
4983: &Apache::loncommon::end_data_table_row();
4984: $need_save = 1;
4985: }
1.537 raeburn 4986: }
4987: }
4988: $to_show .= $output.' '
1.510 raeburn 4989: .&Apache::loncommon::end_data_table()
4990: .'<br style="line-height:2px;" />'
4991: .&Apache::loncommon::end_scrollbox();
4992: } else {
1.520 raeburn 4993: $to_show .= $toolslink
1.510 raeburn 4994: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4995: .$output.' '
4996: .&Apache::loncommon::end_data_table();
1.393 raeburn 4997: }
1.510 raeburn 4998: } else {
1.520 raeburn 4999: if (!$allowed) {
5000: $to_show .= $toolslink;
5001: }
1.615 raeburn 5002: my $noresmsg;
5003: if ($allowed && $hiddentop && !$supplementalflag) {
5004: $noresmsg = &mt('Main Content Hidden');
5005: } else {
5006: $noresmsg = &mt('Currently empty');
5007: }
1.510 raeburn 5008: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
5009: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 5010: .$noresmsg
1.510 raeburn 5011: .'</div>'
5012: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 5013: }
5014: } else {
1.510 raeburn 5015: if ($shown) {
5016: $to_show = '<div>'
5017: .&Apache::loncommon::start_data_table('LC_tableOfContent')
5018: .$output
5019: .&Apache::loncommon::end_data_table()
5020: .'</div>';
5021: } else {
5022: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 5023: .&mt('Currently empty')
1.510 raeburn 5024: .'</div>'
5025: }
1.458 raeburn 5026: }
5027: my $tid = 1;
5028: if ($supplementalflag) {
5029: $tid = 2;
1.329 droeschl 5030: }
5031: if ($allowed) {
1.484 raeburn 5032: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 5033: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 5034: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
5035: if ($canedit) {
5036: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
5037: }
1.460 raeburn 5038: } else {
5039: $r->print($to_show);
1.329 droeschl 5040: }
5041: return;
5042: }
5043:
1.538 raeburn 5044: sub multiple_check_form {
1.611 raeburn 5045: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 5046: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 5047: my $disabled;
5048: unless ($canedit) {
1.700 raeburn 5049: $disabled = ' disabled="disabled"';
1.611 raeburn 5050: }
1.538 raeburn 5051: my $output =
5052: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
5053: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
5054: '<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>'.
5055: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
5056: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
5057: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
5058: if ($caller eq 'settings') {
5059: $output .=
5060: '<table><tr>'.
5061: '<td class="LC_docs_entry_parameter">'.
5062: '<span class="LC_nobreak"><label>'.
1.611 raeburn 5063: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 5064: '</label></span></td>'.
5065: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 5066: '<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 5067: '</span></td>'.
5068: '</tr>'."\n".
5069: '<tr>'.
5070: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 5071: '<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 5072: '</label></span>'.
5073: '</td></tr></table>'."\n";
5074: } else {
5075: $output .=
5076: '<table><tr>'.
5077: '<td class="LC_docs_entry_parameter">'.
5078: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 5079: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 5080: '</label></span></td>'.
5081: '<td class="LC_docs_entry_parameter">'.
5082: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 5083: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 5084: '</label></span></td>'."\n".
5085: '<td class="LC_docs_entry_parameter">'.
5086: '<span class="LC_nobreak LC_docs_copy">'.
1.700 raeburn 5087: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538 raeburn 5088: '</label></span></td>'.
5089: '</tr></table>'."\n";
5090: }
5091: $output .=
5092: '</fieldset>'.
5093: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
5094: if ($caller eq 'settings') {
5095: $output .=
1.543 raeburn 5096: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
5097: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
5098: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
5099: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
5100: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 5101: } elsif ($caller eq 'actions') {
5102: $output .=
5103: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
5104: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
5105: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
5106: }
5107: $output .=
5108: '</form>'.
5109: '</div>';
5110: return $output;
5111: }
5112:
1.329 droeschl 5113: sub process_file_upload {
1.552 raeburn 5114: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 5115: # upload a file, if present
1.552 raeburn 5116: my $filesize = length($env{'form.uploaddoc'});
5117: if (!$filesize) {
5118: $$upload_output = '<div class="LC_error">'.
5119: &mt('Unable to upload [_1]. (size = [_2] bytes)',
5120: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
5121: $filesize).'<br />'.
5122: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
5123: '</div>';
5124: return;
5125: }
5126: my $quotatype = 'unofficial';
5127: if ($crstype eq 'Community') {
1.601 raeburn 5128: $quotatype = 'community';
5129: } elsif ($crstype eq 'Placement') {
5130: $quotatype = 'placement';
1.580 raeburn 5131: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 5132: $quotatype = 'official';
1.573 raeburn 5133: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5134: $quotatype = 'textbook';
1.552 raeburn 5135: }
5136: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
5137: $filesize = int($filesize/1000); #expressed in kb
5138: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 5139: $env{'form.uploaddoc.filename'},$filesize,
5140: 'upload',$quotatype);
1.552 raeburn 5141: return if ($$upload_output);
5142: }
1.440 raeburn 5143: my ($parseaction,$showupload,$nextphase,$mimetype);
5144: if ($env{'form.parserflag'}) {
1.329 droeschl 5145: $parseaction = 'parse';
5146: }
5147: my $folder=$env{'form.folder'};
5148: if ($folder eq '') {
5149: $folder='default';
5150: }
5151: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
5152: my $errtext='';
5153: my $fatal=0;
5154: my $container='sequence';
1.519 raeburn 5155: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 5156: $container='page';
5157: }
5158: ($errtext,$fatal)=
1.534 raeburn 5159: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 5160: if ($#LONCAPA::map::order<1) {
5161: $LONCAPA::map::order[0]=1;
5162: $LONCAPA::map::resources[1]='';
5163: }
5164: my $destination = 'docs/';
5165: if ($folder =~ /^supplemental/) {
5166: $destination = 'supplemental/';
5167: }
5168: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5169: $destination .= 'default/';
5170: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5171: $destination .= $2.'/';
5172: }
1.534 raeburn 5173: if ($fatal) {
5174: $$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>';
5175: return;
5176: }
1.440 raeburn 5177: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 5178: my $newidx=&LONCAPA::map::getresidx();
5179: $destination .= $newidx;
1.439 raeburn 5180: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 5181: $parseaction,$allfiles,
1.440 raeburn 5182: $codebase,undef,undef,undef,undef,
5183: undef,undef,\$mimetype);
5184: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
5185: my $stored = $1;
5186: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
5187: $stored.'</span>').'</p>';
5188: } else {
5189: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
5190:
1.457 raeburn 5191: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 5192: return;
5193: }
1.329 droeschl 5194: my $ext='false';
5195: if ($url=~m{^http://}) { $ext='true'; }
5196: $url = &LONCAPA::map::qtunescape($url);
5197: my $comment=$env{'form.comment'};
5198: $comment = &LONCAPA::map::qtunescape($comment);
5199: if ($folder=~/^supplemental/) {
5200: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
5201: $env{'user.domain'}.'___&&&___'.$comment;
5202: }
5203:
5204: $LONCAPA::map::resources[$newidx]=
5205: $comment.':'.$url.':'.$ext.':normal:res';
5206: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
5207: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 5208: $folder.'.'.$container,1);
1.329 droeschl 5209: if ($fatal) {
1.457 raeburn 5210: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 5211: return;
1.329 droeschl 5212: } else {
1.440 raeburn 5213: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
5214: $$upload_output = $showupload;
1.384 raeburn 5215: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 5216: if ($total_embedded > 0) {
1.440 raeburn 5217: my $uploadphase = 'upload_embedded';
5218: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
5219: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 5220: my ($embedded,$num) =
1.440 raeburn 5221: &Apache::loncommon::ask_for_embedded_content(
5222: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
5223: if ($embedded) {
5224: if ($num) {
5225: $$upload_output .=
5226: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
5227: $nextphase = $uploadphase;
5228: } else {
5229: $$upload_output .= $embedded;
5230: }
5231: } else {
5232: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
5233: }
1.329 droeschl 5234: } else {
1.440 raeburn 5235: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 5236: }
1.457 raeburn 5237: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 5238: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
5239: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 5240: $nextphase = 'decompress_uploaded';
5241: my $position = scalar(@LONCAPA::map::order)-1;
5242: my $noextract = &return_to_editor();
5243: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
5244: my %archiveitems = (
5245: folderpath => $env{'form.folderpath'},
5246: cmd => $nextphase,
5247: newidx => $newidx,
5248: position => $position,
5249: phase => $nextphase,
1.477 raeburn 5250: comment => $comment,
1.480 raeburn 5251: );
5252: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
5253: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 5254: $$upload_output = $showupload.
5255: &Apache::loncommon::decompress_form($mimetype,
5256: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 5257: \%archiveitems,\@current);
1.329 droeschl 5258: }
5259: }
5260: }
1.440 raeburn 5261: return $nextphase;
1.329 droeschl 5262: }
5263:
1.480 raeburn 5264: sub get_dir_list {
5265: my ($url,$coursenum,$coursedom,$newidx) = @_;
5266: my ($destination,$dir_root) = &embedded_destination();
5267: my ($dirlistref,$listerror) =
5268: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
5269: my @dir_lines;
5270: my $dirptr=16384;
5271: if (ref($dirlistref) eq 'ARRAY') {
5272: foreach my $dir_line (sort
5273: {
5274: my ($afile)=split('&',$a,2);
5275: my ($bfile)=split('&',$b,2);
5276: return (lc($afile) cmp lc($bfile));
5277: } (@{$dirlistref})) {
5278: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
5279: $filename =~ s/\s+$//;
5280: next if ($filename =~ /^\.\.?$/);
5281: my $isdir = 0;
5282: if ($dirptr&$testdir) {
5283: $isdir = 1;
5284: }
5285: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
5286: }
5287: }
5288: return @dir_lines;
5289: }
5290:
1.329 droeschl 5291: sub is_supplemental_title {
5292: my ($title) = @_;
5293: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
5294: }
5295:
5296: # --------------------------------------------------------------- An entry line
5297:
5298: sub entryline {
1.501 raeburn 5299: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 5300: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 5301: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 5302: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 5303: if (&is_supplemental_title($title)) {
1.488 raeburn 5304: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 5305: $encodedtitle=$title;
1.329 droeschl 5306: } else {
5307: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 5308: $encodedtitle=$title;
1.329 droeschl 5309: $renametitle=$title;
5310: $foldertitle=$title;
5311: }
5312:
1.611 raeburn 5313: my ($disabled,$readonly,$js_lt);
5314: unless ($canedit) {
5315: $disabled = 'disabled="disabled"';
5316: $readonly = 1;
5317: }
5318:
1.329 droeschl 5319: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 5320:
1.329 droeschl 5321: $renametitle=~s/\\/\\\\/g;
5322: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 5323: $renametitle=~s/"/%22/g;
1.581 raeburn 5324: $renametitle=~s/ /%20/g;
5325: $oldtitle = $renametitle;
1.576 raeburn 5326: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 5327: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 5328: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 5329: # Edit commands
1.679 raeburn 5330: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 5331: if ($env{'form.folderpath'}) {
5332: $esc_path=&escape($env{'form.folderpath'});
5333: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5334: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
5335: }
1.505 raeburn 5336: my $isexternal;
1.510 raeburn 5337: if ($residx) {
1.501 raeburn 5338: my $currurl = $url;
5339: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 5340: if ($currurl =~ m{^/adm/wrapper/ext/}) {
5341: $isexternal = 1;
5342: }
1.510 raeburn 5343: if (!$supplementalflag) {
5344: my $path = 'uploaded/'.
5345: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
5346: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
5347: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
5348: $residx,
5349: &Apache::lonnet::declutter($currurl));
5350: }
1.501 raeburn 5351: }
1.538 raeburn 5352: my ($renamelink,%lt,$ishash);
5353: if (ref($filtersref) eq 'HASH') {
5354: $ishash = 1;
5355: }
5356:
1.329 droeschl 5357: if ($allowed) {
1.538 raeburn 5358: $form_start = '
5359: <form action="/adm/coursedocs" method="post">
5360: ';
5361: $form_common=(<<END);
5362: <input type="hidden" name="folderpath" value="$path" />
5363: <input type="hidden" name="symb" value="$symb" />
5364: END
5365: $form_param=(<<END);
5366: <input type="hidden" name="setparms" value="$orderidx" />
5367: <input type="hidden" name="changeparms" value="0" />
5368: END
5369: $form_end = '</form>';
5370:
1.329 droeschl 5371: my $incindex=$index+1;
5372: my $selectbox='';
1.471 raeburn 5373: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 5374: ((split(/\:/,
1.344 bisitz 5375: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
5376: ne '') &&
1.329 droeschl 5377: ((split(/\:/,
1.344 bisitz 5378: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 5379: ne '')) {
5380: $selectbox=
5381: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 5382: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 5383: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
5384: if ($i==$incindex) {
1.358 bisitz 5385: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 5386: } else {
5387: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
5388: }
5389: }
5390: $selectbox.='</select>';
5391: }
1.501 raeburn 5392: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 5393: 'up' => 'Move Up',
5394: 'dw' => 'Move Down',
5395: 'rm' => 'Remove',
5396: 'ct' => 'Cut',
5397: 'rn' => 'Rename',
1.501 raeburn 5398: 'cp' => 'Copy',
1.633 raeburn 5399: 'da' => 'Unset alias',
5400: 'sa' => 'Set alias',
1.501 raeburn 5401: 'ex' => 'External Resource',
1.598 raeburn 5402: 'et' => 'External Tool',
1.501 raeburn 5403: 'ed' => 'Edit',
5404: 'pr' => 'Preview',
5405: 'sv' => 'Save',
5406: 'ul' => 'URL',
1.611 raeburn 5407: 'ti' => 'Title',
1.618 raeburn 5408: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 5409: );
1.538 raeburn 5410: my %denied = &action_restrictions($coursenum,$coursedom,$url,
5411: $env{'form.folderpath'},
5412: $currgroups);
1.517 raeburn 5413: my ($copylink,$cutlink,$removelink);
1.329 droeschl 5414: my $skip_confirm = 0;
1.603 raeburn 5415: my $confirm_removal = 0;
1.329 droeschl 5416: if ( $folder =~ /^supplemental/
5417: || ($url =~ m{( /smppg$
5418: |/syllabus$
5419: |/aboutme$
5420: |/navmaps$
5421: |/bulletinboard$
1.626 raeburn 5422: |/ext\.tool$
1.505 raeburn 5423: |\.html$)}x)
5424: || $isexternal) {
1.329 droeschl 5425: $skip_confirm = 1;
5426: }
1.603 raeburn 5427: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
5428: ($url!~/$LONCAPA::assess_page_seq_re/)) {
5429: $confirm_removal = 1;
5430: }
1.633 raeburn 5431: if ($url =~ /$LONCAPA::assess_re/) {
5432: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
5433: }
1.329 droeschl 5434:
1.538 raeburn 5435: if ($denied{'copy'}) {
1.543 raeburn 5436: $copylink=(<<ENDCOPY)
1.507 raeburn 5437: <span style="visibility: hidden;">$lt{'cp'}</span>
5438: ENDCOPY
5439: } else {
1.538 raeburn 5440: my $formname = 'edit_copy_'.$orderidx;
5441: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5442: $copylink=(<<ENDCOPY);
1.538 raeburn 5443: <form name="$formname" method="post" action="/adm/coursedocs">
5444: $form_common
1.611 raeburn 5445: <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 5446: $form_end
1.329 droeschl 5447: ENDCOPY
1.538 raeburn 5448: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
5449: push(@{$filtersref->{'cancopy'}},$orderidx);
5450: }
1.329 droeschl 5451: }
1.538 raeburn 5452: if ($denied{'cut'}) {
1.507 raeburn 5453: $cutlink=(<<ENDCUT);
5454: <span style="visibility: hidden;">$lt{'ct'}</span>
5455: ENDCUT
5456: } else {
1.538 raeburn 5457: my $formname = 'edit_cut_'.$orderidx;
5458: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5459: $cutlink=(<<ENDCUT);
1.538 raeburn 5460: <form name="$formname" method="post" action="/adm/coursedocs">
5461: $form_common
1.542 raeburn 5462: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 5463: <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 5464: $form_end
1.329 droeschl 5465: ENDCUT
1.538 raeburn 5466: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
5467: push(@{$filtersref->{'cancut'}},$orderidx);
5468: }
1.329 droeschl 5469: }
1.538 raeburn 5470: if ($denied{'remove'}) {
1.507 raeburn 5471: $removelink=(<<ENDREM);
5472: <span style="visibility: hidden;">$lt{'rm'}</a>
5473: ENDREM
5474: } else {
1.538 raeburn 5475: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 5476: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 5477: $removelink=(<<ENDREM);
1.538 raeburn 5478: <form name="$formname" method="post" action="/adm/coursedocs">
5479: $form_common
1.542 raeburn 5480: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 5481: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 5482: <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 5483: $form_end
1.497 raeburn 5484: ENDREM
1.538 raeburn 5485: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
5486: push(@{$filtersref->{'canremove'}},$orderidx);
5487: }
1.497 raeburn 5488: }
1.551 raeburn 5489: $renamelink=(<<ENDREN);
1.581 raeburn 5490: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 5491: ENDREN
1.611 raeburn 5492: my ($uplink,$downlink);
5493: if ($canedit) {
5494: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
5495: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
5496: } else {
5497: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
5498: $downlink = $uplink;
5499: }
1.329 droeschl 5500: $line.=(<<END);
5501: <td>
1.379 bisitz 5502: <div class="LC_docs_entry_move">
1.611 raeburn 5503: <a href="$uplink">
1.501 raeburn 5504: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 5505: </a>
5506: </div>
5507: <div class="LC_docs_entry_move">
1.611 raeburn 5508: <a href="$downlink">
1.501 raeburn 5509: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 5510: </a>
5511: </div>
1.329 droeschl 5512: </td>
5513: <td>
5514: $form_start
1.538 raeburn 5515: $form_param
1.478 raeburn 5516: $form_common
1.329 droeschl 5517: $selectbox
5518: $form_end
5519: </td>
1.540 raeburn 5520: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 5521: $removelink
1.329 droeschl 5522: $cutlink
5523: $copylink
5524: </td>
5525: END
5526: }
5527: # Figure out what kind of a resource this is
5528: my ($extension)=($url=~/\.(\w+)$/);
5529: my $uploaded=($url=~/^\/*uploaded\//);
5530: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 5531: my $isfolder;
5532: my $ispage;
5533: my $containerarg;
1.615 raeburn 5534: my $folderurl;
1.685 raeburn 5535: my $plainurl;
1.329 droeschl 5536: if ($uploaded) {
1.472 raeburn 5537: if (($extension eq 'sequence') || ($extension eq 'page')) {
5538: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 5539: $containerarg = $1;
1.472 raeburn 5540: if ($extension eq 'sequence') {
5541: $icon=$iconpath.'navmap.folder.closed.gif';
5542: $isfolder=1;
5543: } else {
5544: $icon=$iconpath.'page.gif';
5545: $ispage=1;
5546: }
1.615 raeburn 5547: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 5548: if ($allowed) {
5549: $url='/adm/coursedocs?';
5550: } else {
5551: $url='/adm/supplemental?';
5552: }
1.329 droeschl 5553: } else {
1.685 raeburn 5554: $plainurl = $url;
1.329 droeschl 5555: }
5556: }
1.364 bisitz 5557:
1.621 raeburn 5558: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 5559: my $orig_url = $url;
1.340 raeburn 5560: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 5561: if ($container eq 'page') {
5562: $url=~s{^http(|s)(:|:)//}{/ext/};
5563: } else {
5564: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
5565: }
1.501 raeburn 5566: if (!$supplementalflag && $residx && $symb) {
5567: if ((!$isfolder) && (!$ispage)) {
5568: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 5569: if (($url =~ m{^ext/}) && ($container eq 'page')) {
5570: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
5571: } else {
5572: $url=&Apache::lonnet::clutter($url);
5573: }
1.501 raeburn 5574: if ($url=~/^\/*uploaded\//) {
5575: $url=~/\.(\w+)$/;
5576: my $embstyle=&Apache::loncommon::fileembstyle($1);
5577: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
5578: $url='/adm/wrapper'.$url;
5579: } elsif ($embstyle eq 'ssi') {
5580: #do nothing with these
5581: } elsif ($url!~/\.(sequence|page)$/) {
5582: $url='/adm/coursedocs/showdoc'.$url;
5583: }
1.623 raeburn 5584: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
5585: my $wrapped = $1;
5586: my $exturl = $2;
1.668 raeburn 5587: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 5588: $url='/adm/wrapper'.$url;
5589: }
5590: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
5591: $nomodal = 1;
5592: }
1.626 raeburn 5593: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5594: $url='/adm/wrapper'.$url;
1.621 raeburn 5595: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
5596: if (($ENV{'SERVER_PORT'} == 443) &&
5597: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5598: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5599: $url .= '?usehttp=1';
5600: }
1.621 raeburn 5601: $nomodal = 1;
5602: }
1.598 raeburn 5603: }
1.696 raeburn 5604: my $checkencrypt;
1.680 raeburn 5605: if (!$env{'request.role.adv'}) {
1.615 raeburn 5606: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 5607: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 5608: $checkencrypt = 1;
1.620 raeburn 5609: } elsif (ref($navmapref)) {
1.615 raeburn 5610: unless (ref($$navmapref)) {
5611: $$navmapref = Apache::lonnavmaps::navmap->new();
5612: }
5613: if (ref($$navmapref)) {
5614: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 5615: $checkencrypt = 1;
1.615 raeburn 5616: }
5617: }
5618: }
1.680 raeburn 5619: }
5620: if ($checkencrypt) {
5621: my $currenc = $env{'request.enc'};
5622: $env{'request.enc'} = 1;
5623: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 5624: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 5625: if (&Apache::lonnet::symbverify($symb,$url)) {
5626: $url = $shownurl;
5627: } else {
5628: $url = '';
5629: }
5630: $env{'request.enc'} = $currenc;
5631: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
5632: $shownsymb = $symb;
5633: if ($isexternal) {
5634: $url =~ s/\#[^#]+$//;
5635: if ($container eq 'page') {
5636: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 5637: }
1.612 raeburn 5638: }
1.696 raeburn 5639: } else {
5640: $url = '';
1.680 raeburn 5641: }
5642: unless ($env{'request.role.adv'}) {
5643: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5644: $url = '';
5645: }
5646: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
5647: $url = '';
5648: $hiddenres = 1;
5649: }
5650: }
1.696 raeburn 5651: if (($url ne '') && ($shownsymb ne '')) {
5652: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 5653: }
1.329 droeschl 5654: }
1.621 raeburn 5655: } elsif ($supplementalflag) {
1.610 raeburn 5656: if ($isexternal) {
5657: if ($url =~ /^([^#]+)#([^#]+)$/) {
5658: $url = $1;
5659: $anchor = $2;
1.623 raeburn 5660: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 5661: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5662: if ($hostname ne '') {
5663: $url = 'http://'.$hostname.$url;
5664: }
5665: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 5666: }
5667: $nomodal = 1;
5668: }
1.610 raeburn 5669: }
1.621 raeburn 5670: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
5671: if (($ENV{'SERVER_PORT'} == 443) &&
5672: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5673: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5674: if ($hostname ne '') {
5675: $url = 'http://'.$hostname.$url;
5676: }
5677: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 5678: }
1.621 raeburn 5679: $nomodal = 1;
5680: }
1.705 raeburn 5681: } elsif (($uploaded) && ($url ne '/adm/supplemental?') && ($url ne '/adm/coursedocs?')) {
1.686 raeburn 5682: my $embstyle=&Apache::loncommon::fileembstyle($extension);
5683: unless ($embstyle eq 'ssi') {
5684: if (($embstyle eq 'img')
5685: || ($embstyle eq 'emb')
5686: || ($embstyle eq 'wrp')) {
5687: $url='/adm/wrapper'.$url;
5688: } elsif ($url !~ /\.(sequence|page)$/) {
5689: $url='/adm/coursedocs/showdoc'.$url;
5690: }
5691: }
1.610 raeburn 5692: }
1.685 raeburn 5693: unless ($allowed && $env{'request.role.adv'}) {
5694: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5695: $hiddenres = 1;
5696: }
5697: }
1.329 droeschl 5698: }
1.615 raeburn 5699: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 5700: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 5701: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 5702: my $foldername=&escape($foldertitle);
5703: my $folderpath=$env{'form.folderpath'};
5704: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 5705: if (!$allowed && $supplementalflag) {
1.519 raeburn 5706: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 5707: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 5708: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5709: $hiddenfolder = 1;
1.682 raeburn 5710: }
1.510 raeburn 5711: } else {
1.617 raeburn 5712: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
5713: 'parameter_randompick'))[0];
5714: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
5715: 'parameter_randomorder'))[0]=~/^yes$/i);
5716: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
5717: 'parameter_hiddenresource'))[0]=~/^yes$/i);
5718: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
5719: 'parameter_encrypturl'))[0]=~/^yes$/i);
5720: unless ($hiddenmap) {
1.620 raeburn 5721: if (ref($navmapref)) {
5722: unless (ref($$navmapref)) {
5723: $$navmapref = Apache::lonnavmaps::navmap->new();
5724: }
5725: if (ref($$navmapref)) {
5726: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5727: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
5728: unless (@resources) {
5729: $hiddenmap = 1;
5730: unless ($env{'request.role.adv'}) {
5731: $url = '';
5732: $hiddenfolder = 1;
5733: }
1.617 raeburn 5734: }
1.615 raeburn 5735: }
5736: }
5737: }
5738: }
1.617 raeburn 5739: unless ($encryptmap) {
1.620 raeburn 5740: if ((ref($navmapref)) && (ref($$navmapref))) {
5741: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
5742: $encryptmap = 1;
5743: }
1.617 raeburn 5744: }
5745: }
1.630 raeburn 5746:
1.617 raeburn 5747: # Append randompick number, hidden, and encrypted with ":" to foldername,
5748: # so it gets transferred between levels
5749: $folderpath.=$containerarg.'&'.$foldername.
5750: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 5751: unless ($url eq '') {
1.612 raeburn 5752: $url.='folderpath='.&escape($folderpath);
5753: }
1.510 raeburn 5754: my $rpckchk;
5755: if ($rpicknum) {
5756: $rpckchk = ' checked="checked"';
1.543 raeburn 5757: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
5758: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
5759: }
1.510 raeburn 5760: }
1.537 raeburn 5761: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 5762: $rand_pick_text =
1.478 raeburn 5763: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5764: $form_param."\n".
1.478 raeburn 5765: $form_common."\n".
1.611 raeburn 5766: '<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 5767: if ($rpicknum ne '') {
5768: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
5769: }
1.537 raeburn 5770: $rand_pick_text .= '</span></span>'.
5771: $form_end;
1.543 raeburn 5772: my $ro_set;
1.617 raeburn 5773: if ($randorder) {
1.543 raeburn 5774: $ro_set = 'checked="checked"';
5775: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
5776: push(@{$filtersref->{'randomorder'}},$orderidx);
5777: }
5778: }
1.564 raeburn 5779: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 5780: $rand_order_text =
1.537 raeburn 5781: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5782: $form_param."\n".
1.537 raeburn 5783: $form_common."\n".
1.611 raeburn 5784: '<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 5785: $form_end;
1.510 raeburn 5786: }
1.705 raeburn 5787: } elsif ($supplementalflag) {
1.598 raeburn 5788: my $isexttool;
1.626 raeburn 5789: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5790: $url='/adm/wrapper'.$url;
5791: $isexttool = 1;
5792: }
1.510 raeburn 5793: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 5794: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 5795: if ($title) {
1.687 raeburn 5796: $url .= '&title='.$encodedtitle;
1.510 raeburn 5797: }
1.598 raeburn 5798: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 5799: $url .= '&idx='.$orderidx;
5800: }
1.610 raeburn 5801: if ($anchor ne '') {
5802: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5803: }
1.329 droeschl 5804: }
1.519 raeburn 5805: my ($tdalign,$tdwidth);
1.501 raeburn 5806: if ($allowed) {
1.630 raeburn 5807: my $fileloc =
1.501 raeburn 5808: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 5809: if ($isexternal) {
1.630 raeburn 5810: ($editlink,$extresform) =
1.611 raeburn 5811: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5812: undef,undef,undef,undef,undef,undef,
5813: undef,$disabled);
1.626 raeburn 5814: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5815: ($editlink,$extresform) =
5816: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5817: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 5818: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 5819: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 5820: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
5821: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 5822: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 5823: my $suppanchor;
5824: if ($supplementalflag) {
5825: $suppanchor = $anchor;
5826: }
1.630 raeburn 5827: my $jscall =
1.501 raeburn 5828: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
5829: $switchserver,
1.503 raeburn 5830: $forceedit,
1.679 raeburn 5831: undef,$symb,$shownsymb,
1.511 raeburn 5832: &escape($env{'form.folderpath'}),
1.622 raeburn 5833: $renametitle,$hostname,
5834: '','',1,$suppanchor);
1.501 raeburn 5835: if ($jscall) {
1.518 raeburn 5836: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
5837: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 5838: }
5839: }
5840: }
1.519 raeburn 5841: $tdalign = ' align="right" valign="top"';
5842: $tdwidth = ' width="80%"';
1.329 droeschl 5843: }
1.408 raeburn 5844: my $reinit;
5845: if ($crstype eq 'Community') {
5846: $reinit = &mt('(re-initialize community to access)');
5847: } else {
5848: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 5849: }
1.702 raeburn 5850: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
1.650 raeburn 5851: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 5852: $line.= '<br />';
5853: if ($curralias ne '') {
5854: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5855: $lt{'da'}.'</a></span>';
5856: } else {
5857: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5858: $lt{'sa'}.'</a></span>';
5859: }
5860: }
1.701 raeburn 5861: $line.='</td><td><span class="LC_nobreak">';
1.685 raeburn 5862: my ($link,$nolink);
1.472 raeburn 5863: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5864: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
5865: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5866: $nolink = 1;
5867: }
5868: }
5869: if ($nolink) {
5870: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5871: } else {
5872: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5873: }
1.469 www 5874: } elsif ($url) {
1.610 raeburn 5875: if ($anchor ne '') {
5876: if ($supplementalflag) {
5877: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5878: } else {
5879: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
5880: }
5881: }
1.705 raeburn 5882: if (($nomodal) && ($hostname ne '')) {
1.622 raeburn 5883: $link = 'http://'.$hostname.$url;
5884: } else {
5885: $link = $url;
5886: }
1.705 raeburn 5887: my $inhibitmenu;
5888: if ((($supplementalflag) && ($allowed) && ($url =~ m{^/adm/wrapper/})) ||
5889: (($allowed) && (($url =~ m{^/adm/(viewclasslist|$match_domain/$match_username/aboutme)(\?|$)}) ||
5890: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus(\?|$)})))) {
5891: $inhibitmenu = 'only_body=1';
5892: } else {
5893: $inhibitmenu = 'inhibitmenu=yes';
5894: }
5895: $link = &js_escape($link.(($url=~/\?/)?'&':'?').$inhibitmenu.$anchor);
1.685 raeburn 5896: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
5897: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5898: $nolink = 1;
5899: }
5900: }
5901: if ($nolink) {
5902: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5903: } elsif ($nomodal) {
1.621 raeburn 5904: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5905: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
5906: } else {
5907: $line.=&Apache::loncommon::modal_link($link,
5908: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
5909: }
1.469 www 5910: } else {
5911: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5912: }
1.519 raeburn 5913: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 5914: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5915: if ($nolink) {
5916: $line.=$title;
5917: } else {
5918: $line.='<a href="'.$url.'">'.$title.'</a>';
5919: }
1.682 raeburn 5920: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
5921: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
5922: my $editurl = $url;
5923: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
5924: $line .= ' '.'<a href="'.$editurl.'">'.
5925: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
5926: '</a>';
5927: }
5928: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
5929: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
5930: }
1.469 www 5931: } elsif ($url) {
1.685 raeburn 5932: if ($nolink) {
5933: $line.=$title;
5934: } elsif ($nomodal) {
1.621 raeburn 5935: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5936: $title.'</a>';
5937: } else {
5938: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
5939: }
1.617 raeburn 5940: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 5941: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 5942: } else {
5943: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
5944: }
1.633 raeburn 5945: if (($allowed) && ($curralias ne '')) {
5946: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
5947: } else {
5948: $line .= $extresform;
5949: }
5950: $line .= '</td>';
1.478 raeburn 5951: $rand_pick_text = ' ' if ($rand_pick_text eq '');
5952: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 5953: if ($uploaded && $url && !$isfolder && !$ispage) {
5954: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
5955: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
5956: }
5957: }
1.682 raeburn 5958: if ($allowed) {
5959: my %lt=&Apache::lonlocal::texthash(
5960: 'hd' => 'Hidden',
5961: 'ec' => 'URL hidden');
5962: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 5963: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5964: $hidtext = ' checked="checked"';
1.694 raeburn 5965: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 5966: push(@{$filtersref->{'hiddenresource'}},$orderidx);
5967: }
5968: }
1.682 raeburn 5969: $formhidden = 'edit_hiddenresource_'.$orderidx;
5970: $line.=(<<ENDPARMS);
1.329 droeschl 5971: <td class="LC_docs_entry_parameter">
1.537 raeburn 5972: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 5973: $form_param
1.478 raeburn 5974: $form_common
1.611 raeburn 5975: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 5976: $form_end
1.682 raeburn 5977: ENDPARMS
5978: if ($folder =~/^supplemental/) {
5979: $line.= "\n <td>";
5980: } else {
5981: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
5982: $enctext = ' checked="checked"';
5983: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
5984: push(@{$filtersref->{'encrypturl'}},$orderidx);
5985: }
5986: }
5987: $formurlhidden = 'edit_encrypturl_'.$orderidx;
5988: $line.=(<<ENDPARMS);
1.458 raeburn 5989: <br />
1.537 raeburn 5990: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 5991: $form_param
1.478 raeburn 5992: $form_common
1.611 raeburn 5993: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 5994: $form_end
5995: </td>
1.478 raeburn 5996: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
5997: $rand_order_text</td>
1.329 droeschl 5998: ENDPARMS
1.682 raeburn 5999: }
1.329 droeschl 6000: }
1.379 bisitz 6001: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 6002: return $line;
6003: }
6004:
1.538 raeburn 6005: sub action_restrictions {
6006: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
6007: my %denied = (
6008: cut => 0,
6009: copy => 0,
6010: remove => 0,
6011: );
6012: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
6013: # no copy for published maps
6014: $denied{'copy'} = 1;
1.597 raeburn 6015: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
6016: unless ($1 eq 'simpleproblem') {
6017: $denied{'copy'} = 1;
6018: }
6019: $denied{'cut'} = 1;
1.538 raeburn 6020: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
6021: if ($folderpath =~ /^default&[^\&]+$/) {
6022: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
6023: $denied{'remove'} = 1;
6024: }
6025: $denied{'cut'} = 1;
6026: $denied{'copy'} = 1;
6027: }
6028: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
6029: my $group = $1;
6030: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
6031: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
6032: $denied{'remove'} = 1;
6033: }
6034: }
6035: $denied{'cut'} = 1;
6036: $denied{'copy'} = 1;
6037: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
6038: my $group = $1;
6039: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
6040: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
6041: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
6042: if (keys(%groupsettings) > 0) {
6043: $denied{'remove'} = 1;
6044: }
6045: $denied{'cut'} = 1;
6046: $denied{'copy'} = 1;
6047: }
6048: }
6049: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
6050: my $group = $1;
6051: if ($url =~ /group_boards_\Q$group\E/) {
6052: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
6053: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
6054: if (keys(%groupsettings) > 0) {
6055: if (ref($groupsettings{'functions'}) eq 'HASH') {
6056: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
6057: $denied{'remove'} = 1;
6058: }
6059: }
6060: }
6061: $denied{'cut'} = 1;
6062: $denied{'copy'} = 1;
6063: }
6064: }
6065: }
6066: return %denied;
6067: }
6068:
1.533 raeburn 6069: sub new_timebased_suffix {
1.538 raeburn 6070: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 6071: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 6072: if ($type eq 'paste') {
6073: $prefix = $type;
6074: $namespace = 'courseeditor';
1.587 raeburn 6075: $idtype = 'addcode';
1.538 raeburn 6076: } elsif ($type eq 'map') {
1.533 raeburn 6077: $prefix = 'docs';
6078: if ($area eq 'supplemental') {
6079: $prefix = 'supp';
6080: }
6081: $prefix .= $container;
6082: $namespace = 'uploadedmaps';
6083: } else {
6084: $prefix = $type;
6085: $namespace = 'templated';
1.504 raeburn 6086: }
6087: my ($suffix,$freedlock,$error) =
1.587 raeburn 6088: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 6089: if (!$suffix) {
1.538 raeburn 6090: if ($type eq 'paste') {
6091: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
6092: } elsif ($type eq 'map') {
1.533 raeburn 6093: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
6094: } elsif ($type eq 'smppg') {
6095: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 6096: } elsif ($type eq 'exttool') {
6097: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 6098: } else {
1.565 bisitz 6099: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 6100: }
1.504 raeburn 6101: if ($error) {
6102: $errtext .= '<br />'.$error;
6103: }
6104: }
6105: if ($freedlock ne 'ok') {
1.630 raeburn 6106: $locknotfreed =
1.533 raeburn 6107: '<div class="LC_error">'.
6108: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 6109: if ($type eq 'paste') {
1.591 raeburn 6110: if ($freedlock eq 'nolock') {
6111: $locknotfreed =
6112: '<div class="LC_error">'.
6113: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
6114:
1.593 droeschl 6115: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 6116: } else {
6117: $locknotfreed .=
6118: &mt('This will prevent addition of items to the clipboard until your next log-in.');
6119: }
1.538 raeburn 6120: } elsif ($type eq 'map') {
1.591 raeburn 6121: $locknotfreed .=
6122: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 6123: } elsif ($type eq 'smppg') {
6124: $locknotfreed .=
6125: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 6126: } elsif ($type eq 'exttool') {
6127: $locknotfreed .=
6128: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 6129: } else {
6130: $locknotfreed .=
1.565 bisitz 6131: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 6132: }
1.538 raeburn 6133: unless ($type eq 'paste') {
6134: $locknotfreed .=
1.560 raeburn 6135: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
6136: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 6137: }
6138: $locknotfreed .= '</div>';
1.504 raeburn 6139: }
6140: return ($suffix,$errtext,$locknotfreed);
6141: }
6142:
1.329 droeschl 6143: =pod
6144:
6145: =item tiehash()
6146:
6147: tie the hash
6148:
6149: =cut
6150:
6151: sub tiehash {
6152: my ($mode)=@_;
6153: $hashtied=0;
6154: if ($env{'request.course.fn'}) {
6155: if ($mode eq 'write') {
6156: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
6157: &GDBM_WRCREAT(),0640)) {
6158: $hashtied=2;
6159: }
6160: } else {
6161: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
6162: &GDBM_READER(),0640)) {
6163: $hashtied=1;
6164: }
6165: }
1.364 bisitz 6166: }
1.329 droeschl 6167: }
6168:
6169: sub untiehash {
6170: if ($hashtied) { untie %hash; }
6171: $hashtied=0;
6172: return OK;
6173: }
6174:
6175:
6176:
6177:
6178: sub checkonthis {
1.637 raeburn 6179: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 6180: $url=&unescape($url);
6181: $alreadyseen{$url}=1;
6182: $r->rflush();
6183: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
6184: $r->print("\n<br />");
6185: if ($level==0) {
6186: $r->print("<br />");
6187: }
6188: for (my $i=0;$i<=$level*5;$i++) {
6189: $r->print(' ');
6190: }
6191: $r->print('<a href="'.$url.'" target="cat">'.
6192: ($title?$title:$url).'</a> ');
6193: if ($url=~/^\/res\//) {
1.637 raeburn 6194: my $updated;
6195: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
6196: ($url !~ /\.\d+\.\w+$/)) {
6197: $updated = &Apache::lonnet::remove_stale_resfile($url);
6198: }
1.329 droeschl 6199: my $result=&Apache::lonnet::repcopy(
6200: &Apache::lonnet::filelocation('',$url));
6201: if ($result eq 'ok') {
6202: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 6203: if ($updated) {
6204: $r->print('<br />');
6205: for (my $i=0;$i<=$level*5;$i++) {
6206: $r->print(' ');
6207: }
6208: $r->print('- '.&mt('Outdated copy removed'));
6209: }
1.329 droeschl 6210: $r->rflush();
6211: &Apache::lonnet::countacc($url);
6212: $url=~/\.(\w+)$/;
6213: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
6214: $r->print('<br />');
6215: $r->rflush();
6216: for (my $i=0;$i<=$level*5;$i++) {
6217: $r->print(' ');
6218: }
6219: $r->print('- '.&mt('Rendering:').' ');
6220: my ($errorcount,$warningcount)=split(/:/,
6221: &Apache::lonnet::ssi_body($url,
6222: ('grade_target'=>'web',
6223: 'return_only_error_and_warning_counts' => 1)));
6224: if (($errorcount) ||
6225: ($warningcount)) {
6226: if ($errorcount) {
1.369 bisitz 6227: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 6228: &mt('[quant,_1,error]',$errorcount).'</span>');
6229: }
6230: if ($warningcount) {
6231: $r->print('<span class="LC_warning">'.
6232: &mt('[quant,_1,warning]',$warningcount).'</span>');
6233: }
6234: } else {
6235: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
6236: }
6237: $r->rflush();
6238: }
6239: my $dependencies=
6240: &Apache::lonnet::metadata($url,'dependencies');
6241: foreach my $dep (split(/\,/,$dependencies)) {
6242: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 6243: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 6244: }
6245: }
6246: } elsif ($result eq 'unavailable') {
6247: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
6248: } elsif ($result eq 'not_found') {
6249: unless ($url=~/\$/) {
1.521 bisitz 6250: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 6251: } else {
1.366 bisitz 6252: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 6253: }
6254: } else {
6255: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
6256: }
1.637 raeburn 6257: if (($updated) && ($result ne 'ok')) {
6258: $r->print('<br />'.&mt('Outdated copy removed'));
6259: }
1.329 droeschl 6260: }
6261: }
6262: }
6263:
6264:
6265:
6266: =pod
6267:
6268: =item list_symbs()
6269:
1.485 raeburn 6270: List Content Identifiers
1.329 droeschl 6271:
6272: =cut
6273:
6274: sub list_symbs {
6275: my ($r) = @_;
6276:
1.408 raeburn 6277: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 6278: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
6279: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
6280: $r->print(&startContentScreen('tools'));
1.329 droeschl 6281: my $navmap = Apache::lonnavmaps::navmap->new();
6282: if (!defined($navmap)) {
6283: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
6284: '<div class="LC_error">'.
6285: &mt('Unable to retrieve information about course contents').
6286: '</div>');
1.408 raeburn 6287: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 6288: } else {
1.484 raeburn 6289: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
6290: &Apache::loncommon::start_data_table().
6291: &Apache::loncommon::start_data_table_header_row().
6292: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
6293: &Apache::loncommon::end_data_table_header_row()."\n");
6294: my $count;
1.329 droeschl 6295: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 6296: $r->print(&Apache::loncommon::start_data_table_row().
6297: '<td>'.$res->compTitle().'</td>'.
6298: '<td>'.$res->symb().'</td>'.
1.521 bisitz 6299: &Apache::loncommon::end_data_table_row());
1.484 raeburn 6300: $count ++;
6301: }
6302: if (!$count) {
6303: $r->print(&Apache::loncommon::start_data_table_row().
6304: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
6305: &Apache::loncommon::end_data_table_row());
1.329 droeschl 6306: }
1.484 raeburn 6307: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 6308: }
1.521 bisitz 6309: $r->print(&endContentScreen());
1.329 droeschl 6310: }
6311:
1.651 raeburn 6312: sub short_urls {
6313: my ($r,$canedit) = @_;
6314: my $crstype = &Apache::loncommon::course_type();
6315: my $formname = 'shortenurl';
6316: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
6317: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
6318: $r->print(&startContentScreen('tools'));
6319: my ($navmap,$errormsg) =
6320: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
6321: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6322: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6323: my (%maps,%resources,%titles);
6324: if (!ref($navmap)) {
6325: $r->print($errormsg.
6326: &endContentScreen());
6327: return '';
6328: } else {
1.652 raeburn 6329: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 6330: $r->rflush();
6331: my $readonly;
6332: if ($canedit) {
1.671 raeburn 6333: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 6334: if ($numnew) {
6335: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
6336: }
6337: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
6338: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
6339: foreach my $error (@{$errors}) {
6340: $r->print('<li>'.$error.'</li>');
6341: }
6342: $r->print('</ul><br />');
6343: }
6344: } else {
6345: $readonly = 1;
6346: }
6347: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
6348: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
1.711 raeburn 6349: undef,undef,undef,undef,undef,\%currtiny,undef,$readonly));
1.651 raeburn 6350: }
6351: $r->print(&endContentScreen());
6352: }
6353:
1.637 raeburn 6354: sub contentverifyform {
6355: my ($r) = @_;
6356: my $crstype = &Apache::loncommon::course_type();
6357: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6358: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
6359: $r->print(&startContentScreen('tools'));
6360: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
6361: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
6362: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
6363: ' <span class="LC_nobreak">'.
6364: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
6365: &mt('No').'</label>'.(' 'x2).
6366: '<label><input type="radio" name="checkstale" value="1" />'.
6367: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 6368: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 6369: '<input type="hidden" value="1" name="tools" />'.
6370: '<input type="hidden" value="1" name="verify" /></p></form>');
6371: $r->print(&endContentScreen());
6372: return;
6373: }
1.329 droeschl 6374:
6375: sub verifycontent {
1.637 raeburn 6376: my ($r,$checkstale) = @_;
1.408 raeburn 6377: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 6378: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6379: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 6380: $r->print(&startContentScreen('tools'));
6381: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 6382: $hashtied=0;
6383: undef %alreadyseen;
6384: %alreadyseen=();
6385: &tiehash();
1.484 raeburn 6386:
1.329 droeschl 6387: foreach my $key (keys(%hash)) {
6388: if ($hash{$key}=~/\.(page|sequence)$/) {
6389: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
6390: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 6391: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 6392: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 6393: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 6394: }
6395: }
6396: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 6397: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 6398: }
6399: }
6400: &untiehash();
1.442 www 6401: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 6402: $r->print(&endContentScreen());
1.329 droeschl 6403: }
6404:
6405: sub devalidateversioncache {
6406: my $src=shift;
6407: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
6408: &Apache::lonnet::clutter($src));
6409: }
6410:
6411: sub checkversions {
1.611 raeburn 6412: my ($r,$canedit) = @_;
1.408 raeburn 6413: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 6414: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
6415: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 6416: $r->print(&startContentScreen('tools'));
1.442 www 6417:
1.329 droeschl 6418: my $header='';
6419: my $startsel='';
6420: my $monthsel='';
6421: my $weeksel='';
6422: my $daysel='';
6423: my $allsel='';
6424: my %changes=();
6425: my $starttime=0;
6426: my $haschanged=0;
6427: my %setversions=&Apache::lonnet::dump('resourceversions',
6428: $env{'course.'.$env{'request.course.id'}.'.domain'},
6429: $env{'course.'.$env{'request.course.id'}.'.num'});
6430:
6431: $hashtied=0;
6432: &tiehash();
1.611 raeburn 6433: if ($canedit) {
6434: my %newsetversions=();
6435: if ($env{'form.setmostrecent'}) {
6436: $haschanged=1;
6437: foreach my $key (keys(%hash)) {
6438: if ($key=~/^ids\_(\/res\/.+)$/) {
6439: $newsetversions{$1}='mostrecent';
6440: &devalidateversioncache($1);
6441: }
6442: }
6443: } elsif ($env{'form.setcurrent'}) {
6444: $haschanged=1;
6445: foreach my $key (keys(%hash)) {
6446: if ($key=~/^ids\_(\/res\/.+)$/) {
6447: my $getvers=&Apache::lonnet::getversion($1);
6448: if ($getvers>0) {
6449: $newsetversions{$1}=$getvers;
6450: &devalidateversioncache($1);
6451: }
6452: }
1.329 droeschl 6453: }
1.611 raeburn 6454: } elsif ($env{'form.setversions'}) {
6455: $haschanged=1;
6456: foreach my $key (keys(%env)) {
6457: if ($key=~/^form\.set_version_(.+)$/) {
6458: my $src=$1;
6459: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
6460: $newsetversions{$src}=$env{$key};
6461: &devalidateversioncache($src);
6462: }
6463: }
1.329 droeschl 6464: }
1.611 raeburn 6465: }
6466: if ($haschanged) {
6467: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
6468: $env{'course.'.$env{'request.course.id'}.'.domain'},
6469: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
6470: $r->print(&Apache::loncommon::confirmwrapper(
6471: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
6472: } else {
6473: $r->print(&Apache::loncommon::confirmwrapper(
6474: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 6475: }
1.611 raeburn 6476: &mark_hash_old();
6477: }
6478: &changewarning($r,'');
1.329 droeschl 6479: }
6480: if ($env{'form.timerange'} eq 'all') {
6481: # show all documents
1.549 raeburn 6482: $header=&mt('All content in '.$crstype);
1.521 bisitz 6483: $allsel=' selected="selected"';
1.329 droeschl 6484: foreach my $key (keys(%hash)) {
6485: if ($key=~/^ids\_(\/res\/.+)$/) {
6486: my $src=$1;
6487: $changes{$src}=1;
6488: }
6489: }
6490: } else {
6491: # show documents which changed
6492: %changes=&Apache::lonnet::dump
6493: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
6494: $env{'course.'.$env{'request.course.id'}.'.num'});
6495: my $firstkey=(keys(%changes))[0];
6496: unless ($firstkey=~/^error\:/) {
6497: unless ($env{'form.timerange'}) {
6498: $env{'form.timerange'}=604800;
6499: }
6500: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
6501: .&mt('seconds');
6502: if ($env{'form.timerange'}==-1) {
6503: $seltext='since start of course';
1.521 bisitz 6504: $startsel=' selected="selected"';
1.329 droeschl 6505: $env{'form.timerange'}=time;
6506: }
6507: $starttime=time-$env{'form.timerange'};
6508: if ($env{'form.timerange'}==2592000) {
6509: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6510: $monthsel=' selected="selected"';
1.329 droeschl 6511: } elsif ($env{'form.timerange'}==604800) {
6512: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6513: $weeksel=' selected="selected"';
1.329 droeschl 6514: } elsif ($env{'form.timerange'}==86400) {
6515: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6516: $daysel=' selected="selected"';
1.329 droeschl 6517: }
6518: $header=&mt('Content changed').' '.$seltext;
6519: } else {
6520: $header=&mt('No content modifications yet.');
6521: }
6522: }
6523: %setversions=&Apache::lonnet::dump('resourceversions',
6524: $env{'course.'.$env{'request.course.id'}.'.domain'},
6525: $env{'course.'.$env{'request.course.id'}.'.num'});
6526: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 6527: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 6528: 'lm' => 'Version changes since last Month',
6529: 'lw' => 'Version changes since last Week',
6530: 'sy' => 'Version changes since Yesterday',
6531: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 6532: 'cd' => 'Change display',
1.329 droeschl 6533: 'sd' => 'Display',
6534: 'fi' => 'File',
6535: 'md' => 'Modification Date',
6536: 'mr' => 'Most recently published Version',
1.408 raeburn 6537: 've' => 'Version used in '.$crstype,
6538: 'vu' => 'Set Version to be used in '.$crstype,
6539: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 6540: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
6541: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 6542: 'di' => 'Differences',
1.484 raeburn 6543: 'save' => 'Save changes',
6544: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 6545: 'act' => 'Actions');
1.611 raeburn 6546: my ($disabled,$readonly);
6547: unless ($canedit) {
6548: $disabled = 'disabled="disabled"';
6549: $readonly = 1;
6550: }
1.329 droeschl 6551: $r->print(<<ENDHEADERS);
1.484 raeburn 6552: <h4 class="LC_info">$header</h4>
1.329 droeschl 6553: <form action="/adm/coursedocs" method="post">
6554: <input type="hidden" name="versions" value="1" />
1.484 raeburn 6555: <div class="LC_left_float">
1.479 golterma 6556: <fieldset>
1.484 raeburn 6557: <legend>$lt{'cd'}</legend>
1.329 droeschl 6558: <select name="timerange">
1.521 bisitz 6559: <option value='all'$allsel>$lt{'al'}</option>
6560: <option value="-1"$startsel>$lt{'st'}</option>
6561: <option value="2592000"$monthsel>$lt{'lm'}</option>
6562: <option value="604800"$weeksel>$lt{'lw'}</option>
6563: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 6564: </select>
6565: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 6566: </fieldset>
6567: </div>
6568: <div class="LC_left_float">
6569: <fieldset>
6570: <legend>$lt{'act'}</legend>
1.611 raeburn 6571: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
6572: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 6573: </fieldset>
6574: </div>
6575: <br clear="all" />
6576: <hr />
6577: <h4>$lt{'vers'}</h4>
1.329 droeschl 6578: ENDHEADERS
1.479 golterma 6579: #number of columns for version history
1.571 raeburn 6580: my %changedbytime;
6581: foreach my $key (keys(%changes)) {
6582: #excludes not versionable problems from resource version history:
6583: next if ($key =~ /^\/res\/lib\/templates/);
6584: my $chg;
6585: if ($env{'form.timerange'} eq 'all') {
6586: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6587: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
6588: } else {
6589: $chg = $changes{$key};
6590: next if ($chg < $starttime);
6591: }
6592: push(@{$changedbytime{$chg}},$key);
6593: }
6594: if (keys(%changedbytime) == 0) {
6595: &untiehash();
6596: $r->print(&mt('No content changes in imported content in specified time frame').
6597: &endContentScreen());
6598: return;
6599: }
1.479 golterma 6600: $r->print(
1.611 raeburn 6601: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6602: &Apache::loncommon::start_data_table().
6603: &Apache::loncommon::start_data_table_header_row().
6604: '<th>'.&mt('Resources').'</th>'.
6605: "<th>$lt{'mr'}</th>".
6606: "<th>$lt{'ve'}</th>".
6607: "<th>$lt{'vu'}</th>".
6608: '<th>'.&mt('History').'</th>'.
6609: &Apache::loncommon::end_data_table_header_row()
6610: );
1.571 raeburn 6611: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
6612: foreach my $key (sort(@{$changedbytime{$chg}})) {
6613: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6614: my $currentversion=&Apache::lonnet::getversion($key);
6615: if ($currentversion<0) {
6616: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
6617: }
6618: my $linkurl=&Apache::lonnet::clutter($key);
6619: $r->print(
6620: &Apache::loncommon::start_data_table_row().
6621: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
6622: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
6623: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
6624: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
6625: '<td align="right">'
6626: );
6627: # Used in course
6628: my $usedversion=$hash{'version_'.$linkurl};
6629: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 6630: if ($usedversion != $currentversion) {
1.479 golterma 6631: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 6632: } else {
1.479 golterma 6633: $r->print($usedversion);
6634: }
1.329 droeschl 6635: } else {
1.521 bisitz 6636: $r->print($currentversion);
1.329 droeschl 6637: }
1.571 raeburn 6638: $r->print('</td><td title="'.$lt{'vu'}.'">');
6639: # Set version
6640: $r->print(&Apache::loncommon::select_form(
6641: $setversions{$linkurl},
6642: 'set_version_'.$linkurl,
6643: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
6644: '' => '',
6645: 'mostrecent' => &mt('most recent'),
1.611 raeburn 6646: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 6647: my $lastold=1;
6648: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
6649: my $url=$root.'.'.$prevvers.'.'.$extension;
6650: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
6651: $lastold=$prevvers;
6652: }
6653: }
6654: $r->print('</td>');
6655: # List all available versions
6656: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
6657: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
6658: my $url=$root.'.'.$prevvers.'.'.$extension;
6659: $r->print(
6660: '<span class="LC_nobreak">'
6661: .'<a href="'.&Apache::lonnet::clutter($url).'">'
6662: .&mt('Version [_1]',$prevvers).'</a>'
6663: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 6664: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 6665: .')');
6666: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
6667: $r->print(
6668: ' <a href="/adm/diff?filename='.
6669: &Apache::lonnet::clutter($root.'.'.$extension).
6670: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
6671: '" target="diffs">'.&mt('Diffs').'</a>');
6672: }
6673: $r->print('</span><br />');
1.329 droeschl 6674: }
1.571 raeburn 6675: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 6676: }
1.329 droeschl 6677: }
1.521 bisitz 6678: $r->print(
6679: &Apache::loncommon::end_data_table().
1.611 raeburn 6680: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6681: '</form>'
6682: );
1.329 droeschl 6683:
6684: &untiehash();
1.521 bisitz 6685: $r->print(&endContentScreen());
1.571 raeburn 6686: return;
1.329 droeschl 6687: }
6688:
6689: sub mark_hash_old {
6690: my $retie_hash=0;
6691: if ($hashtied) {
6692: $retie_hash=1;
6693: &untiehash();
6694: }
6695: &tiehash('write');
6696: $hash{'old'}=1;
6697: &untiehash();
6698: if ($retie_hash) { &tiehash(); }
6699: }
6700:
6701: sub is_hash_old {
6702: my $untie_hash=0;
6703: if (!$hashtied) {
6704: $untie_hash=1;
6705: &tiehash();
6706: }
6707: my $return=$hash{'old'};
6708: if ($untie_hash) { &untiehash(); }
6709: return $return;
6710: }
6711:
6712: sub changewarning {
6713: my ($r,$postexec,$message,$url)=@_;
6714: if (!&is_hash_old()) { return; }
6715: my $pathvar='folderpath';
6716: my $path=&escape($env{'form.folderpath'});
6717: if (!defined($url)) {
6718: $url='/adm/coursedocs?'.$pathvar.'='.$path;
6719: }
6720: my $course_type = &Apache::loncommon::course_type();
6721: if (!defined($message)) {
6722: $message='Changes will become active for your current session after [_1], or the next time you log in.';
6723: }
1.653 raeburn 6724: my $windowname = 'loncapaclient';
6725: if ($env{'request.lti.login'}) {
6726: $windowname .= 'lti';
6727: }
1.329 droeschl 6728: $r->print("\n\n".
1.372 bisitz 6729: '<script type="text/javascript">'."\n".
6730: '// <![CDATA['."\n".
6731: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
6732: '// ]]>'."\n".
1.369 bisitz 6733: '</script>'."\n".
1.653 raeburn 6734: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 6735: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 6736: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 6737: &mt($message,' <input type="hidden" name="'.
6738: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 6739: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 6740: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 6741: }
6742:
6743:
6744: sub init_breadcrumbs {
1.571 raeburn 6745: my ($form,$text,$help)=@_;
1.329 droeschl 6746: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 6747: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 6748: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 6749: faq=>273,
6750: bug=>'Instructor Interface',
1.571 raeburn 6751: help => $help});
1.329 droeschl 6752: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
6753: text=>$text,
6754: faq=>273,
6755: bug=>'Instructor Interface'});
6756: }
6757:
1.441 www 6758: # subroutine to list form elements
6759: sub create_list_elements {
6760: my @formarr = @_;
6761: my $list = '';
1.501 raeburn 6762: foreach my $button (@formarr){
6763: foreach my $picture (keys(%{$button})) {
6764: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 6765: }
6766: }
6767: return $list;
6768: }
1.329 droeschl 6769:
1.441 www 6770: # subroutine to create ul from list elements
6771: sub create_form_ul {
6772: my $list = shift;
6773: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
6774: return $ul;
6775: }
1.329 droeschl 6776:
1.442 www 6777: #
6778: # Start tabs
6779: #
6780:
6781: sub startContentScreen {
1.484 raeburn 6782: my ($mode) = @_;
6783: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 6784: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 6785: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
6786: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
6787: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
6788: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
6789: } else {
1.549 raeburn 6790: $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 6791: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
6792: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
6793: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
6794: }
6795: $output .= "\n".'</ul>'."\n";
6796: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
6797: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
6798: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
6799: return $output;
1.442 www 6800: }
6801:
6802: #
6803: # End tabs
6804: #
6805:
6806: sub endContentScreen {
1.484 raeburn 6807: return '</div></div></div>';
1.442 www 6808: }
1.329 droeschl 6809:
1.446 www 6810: sub supplemental_base {
1.548 raeburn 6811: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 6812: }
6813:
1.329 droeschl 6814: sub handler {
6815: my $r = shift;
6816: &Apache::loncommon::content_type($r,'text/html');
6817: $r->send_http_header;
6818: return OK if $r->header_only;
1.484 raeburn 6819:
6820: # get course data
1.408 raeburn 6821: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 6822: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
6823: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.712 raeburn 6824: my $coursehome=$env{'course.'.$env{'request.course.id'}.'.home'};
1.484 raeburn 6825:
1.606 raeburn 6826: # get docroot
6827: my $londocroot = $r->dir_config('lonDocRoot');
6828:
1.484 raeburn 6829: # graphics settings
6830: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 6831:
1.443 www 6832: #
1.329 droeschl 6833: # --------------------------------------------- Initialize help topics for this
6834: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 6835: 'Adding_External_Resource','Adding_External_Tool',
6836: 'Navigate_Content','Adding_Folders','Docs_Overview',
6837: 'Load_Map','Supplemental','Score_Upload_Form',
6838: 'Adding_Pages','Importing_LON-CAPA_Resource',
6839: 'Importing_IMS_Course','Uploading_From_Harddrive',
1.706 raeburn 6840: 'Course_Roster','Web_Page','Dropbox','Simple_Problem',
6841: 'Standard_Problem','Course_Resources',
6842: 'Search_LON-CAPA_Resource','Import_Stored_Links') {
1.329 droeschl 6843: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
6844: }
6845: # Composite help files
6846: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
6847: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
6848: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
6849: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
6850: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
6851: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 6852: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 6853: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 6854: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 6855: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 6856:
1.611 raeburn 6857: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 6858: # does this user have privileges to modify content.
6859: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 6860: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 6861: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6862: $allowed = 1;
1.682 raeburn 6863: }
6864: $canedit = 1;
6865: $canview = 1;
6866: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
6867: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
6868: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6869: $allowed = 1;
6870: }
1.682 raeburn 6871: $canview = 1;
1.611 raeburn 6872: }
6873: unless ($canedit) {
6874: $disabled = ' disabled="disabled"';
1.472 raeburn 6875: }
1.582 raeburn 6876: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 6877: if ($env{'form.inhibitmenu'}) {
6878: unless ($env{'form.inhibitmenu'} eq 'yes') {
6879: delete($env{'form.inhibitmenu'});
6880: }
6881: }
6882:
1.582 raeburn 6883: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 6884: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 6885: if (!$canedit) {
6886: &verifycontent($r);
6887: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
6888: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
6889: text=>'Results',
6890: faq=>273,
6891: bug=>'Instructor Interface'});
6892: &verifycontent($r,$env{'form.checkstale'});
6893: } else {
6894: &contentverifyform($r);
6895: }
1.329 droeschl 6896: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 6897: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 6898: &list_symbs($r);
1.651 raeburn 6899: } elsif ($allowed && $env{'form.shorturls'}) {
6900: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
6901: &short_urls($r,$canedit);
1.329 droeschl 6902: } elsif ($allowed && $env{'form.docslog'}) {
6903: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 6904: my $folder = $env{'form.folder'};
6905: if ($folder eq '') {
6906: $folder='default';
6907: }
1.611 raeburn 6908: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 6909: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 6910: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 6911: &checkversions($r,$canedit);
6912: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.709 raeburn 6913: &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
1.329 droeschl 6914: &dumpcourse($r);
1.712 raeburn 6915: } elsif (($canedit || $canview) && ($env{'form.copyauthored'})) {
6916: &init_breadcrumbs('copyauthored','Copy from Course Authoring to User Authoring');
6917: my $readonly;
6918: if (!$canedit) {
6919: $readonly = 1;
6920: }
6921: ©crsauthored($r,$coursenum,$coursedom,$coursehome,$readonly);
1.611 raeburn 6922: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 6923: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 6924: &Apache::imsexport::exportcourse($r);
1.329 droeschl 6925: } else {
1.611 raeburn 6926: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 6927: $noendpage = 1;
6928: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
6929: if ($redirect) {
6930: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
6931: my $container = 'sequence';
6932: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
6933: $is_random_order,$container) =
6934: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
6935: my (@folders)=split('&',$env{'form.folderpath'});
6936: $env{'form.foldername'}=&unescape(pop(@folders));
6937: my $folder=pop(@folders);
6938: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
6939: $folder.'.'.$container);
6940: my $warning;
6941: if ($fatal) {
6942: if ($container eq 'page') {
6943: $warning = &mt('An error occurred retrieving the contents of the current page.');
6944: } else {
6945: $warning = &mt('An error occurred retrieving the contents of the current folder.');
6946: }
6947: } else {
6948: my $url = $redirect;
6949: my $srcfile = $londocroot.$url;
6950: $url =~ s{^/priv/}{/res/};
6951: my $targetfile = $londocroot.$url;
6952: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
6953: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
6954: $env{'form.folder'} = $folder;
6955: &snapshotbefore();
6956: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
6957: my $ext = 'false';
6958: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
6959: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
6960: ':'.$ext.':normal:res';
6961: push(@LONCAPA::map::order,$newidx);
6962: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
6963: 'string_yesno');
6964: &remember_parms($newidx,'hiddenresource','set','yes');
6965: ($errtext,$fatal) =
6966: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
6967: &log_differences($plain);
6968: &mark_hash_old();
6969: $r->internal_redirect($redirect);
6970: return OK;
6971: }
1.654 raeburn 6972: } else {
6973: $r->internal_redirect($redirect);
1.606 raeburn 6974: }
6975: }
6976: }
1.445 www 6977: #
6978: # Done catching special calls
1.484 raeburn 6979: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 6980: # Get the parameters that may be needed
6981: #
6982: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 6983: ['folderpath','title',
1.519 raeburn 6984: 'forcesupplement','forcestandard',
1.510 raeburn 6985: 'tools','symb','command','supppath']);
1.445 www 6986:
1.635 raeburn 6987: foreach my $item ('forcesupplement','forcestandard','tools') {
6988: next if ($env{'form.'.$item} eq '');
6989: unless ($env{'form.'.$item} eq '1') {
6990: delete($env{'form.'.$item});
6991: }
6992: }
6993:
6994: if ($env{'form.command'}) {
6995: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
6996: delete($env{'form.command'});
6997: }
6998: }
6999:
7000: if ($env{'form.symb'}) {
7001: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
7002: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
7003: delete($env{'form.symb'});
7004: }
7005: }
7006:
1.445 www 7007: # standard=1: this is a "new-style" course with an uploaded map as top level
7008: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 7009:
7010: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 7011:
1.484 raeburn 7012: # Decide whether this should display supplemental or main content or utilities
1.445 www 7013: # supplementalflag=1: show supplemental documents
7014: # supplementalflag=0: show standard documents
1.484 raeburn 7015: # toolsflag=1: show utilities
1.445 www 7016:
1.561 raeburn 7017: my $unesc_folderpath = &unescape($env{'form.folderpath'});
7018: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
7019: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 7020: $supplementalflag=0;
7021: }
7022: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
7023: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
1.705 raeburn 7024: unless (($supplementalflag) ||
7025: ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
7026: unless ($allowed) { $supplementalflag=1; }
7027: unless ($standard) { $supplementalflag=1; }
7028: }
1.484 raeburn 7029: my $toolsflag=0;
7030: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 7031:
1.635 raeburn 7032: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 7033: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 7034: }
7035:
1.685 raeburn 7036: my $backto_supppath;
1.635 raeburn 7037: if ($env{'form.supppath'} ne '') {
1.685 raeburn 7038: if ($supplementalflag && $allowed) {
7039: $backto_supppath = &validate_supppath($coursenum,$coursedom);
7040: }
1.635 raeburn 7041: }
7042:
1.329 droeschl 7043: my $script='';
7044: my $showdoc=0;
1.457 raeburn 7045: my $addentries = {};
1.475 raeburn 7046: my $container;
1.329 droeschl 7047: my $containertag;
1.508 raeburn 7048: my $pathitem;
1.598 raeburn 7049: my %ltitools;
1.699 raeburn 7050: my $posslti;
1.617 raeburn 7051: my $hiddentop;
1.615 raeburn 7052: my $navmap;
1.617 raeburn 7053: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 7054:
1.464 www 7055: # Do we directly jump somewhere?
1.525 raeburn 7056: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 7057: if ($env{'form.symb'} ne '') {
1.522 raeburn 7058: $env{'form.folderpath'}=
1.617 raeburn 7059: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 7060: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 7061: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 7062: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 7063: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 7064: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 7065: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 7066: }
1.472 raeburn 7067: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 7068: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 7069: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 7070: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 7071: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 7072: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
7073: } elsif ($env{'form.command'} eq 'contents') {
7074: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
7075: } elsif ($env{'form.command'} eq 'home') {
7076: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 7077: }
7078:
1.525 raeburn 7079:
1.445 www 7080: # Where do we store these for when we come back?
7081: my $stored_folderpath='docs_folderpath';
7082: if ($supplementalflag) {
7083: $stored_folderpath='docs_sup_folderpath';
7084: }
1.464 www 7085:
1.519 raeburn 7086: # No folderpath, and in edit mode, see if we have something stored
7087: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 7088: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 7089: {'folderpath' => 'scalar'});
1.615 raeburn 7090:
7091: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
7092: if ($supplementalflag) {
7093: undef($env{'form.folderpath'}) if ($1 eq 'default');
7094: } else {
7095: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
7096: }
7097: } else {
1.523 raeburn 7098: undef($env{'form.folderpath'});
7099: }
1.677 raeburn 7100: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 7101: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 7102: }
1.329 droeschl 7103: }
1.706 raeburn 7104:
7105: # Set folderpath if we are not allowed to make changes and this is supplemental content
1.705 raeburn 7106: if ((!$allowed) && ($supplementalflag)) {
1.446 www 7107: unless ($env{'form.folderpath'} =~ /^supplemental/) {
7108: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 7109: }
7110: }
1.446 www 7111: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 7112: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 7113: $env{'form.folderpath'} = &supplemental_base()
7114: .'&'.
1.329 droeschl 7115: $env{'form.folderpath'};
7116: }
1.685 raeburn 7117: # If allowed and user's role is not advanced check folderpath is not hidden
7118: my $hidden_and_empty;
1.687 raeburn 7119: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 7120: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 7121: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 7122: my $folder = $pathitems[-2];
7123: if ($folder eq '') {
7124: undef($env{'form.folderpath'});
7125: } else {
7126: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 7127: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 7128: $folderurl .= '.page';
7129: } else {
7130: $folderurl .= '.sequence';
7131: }
1.685 raeburn 7132: if ($supplementalflag) {
7133: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
7134: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 7135: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 7136: if (ref($supplemental) eq 'HASH') {
7137: my ($suppmap,$suppmapnum);
7138: if ($folder eq 'supplemental') {
7139: $suppmap = 'default';
7140: $suppmapnum = 0;
7141: } elsif ($folder =~ /^supplemental_(\d+)$/) {
7142: $suppmap = $1;
7143: $suppmapnum = $suppmap;
7144: }
7145: if ($hiddenfolder) {
7146: my $hascontent;
7147: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
7148: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
7149: $hascontent = 1;
7150: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
7151: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
7152: if ($id =~ /^$suppmapnum\:/) {
7153: $hascontent = 1;
7154: last;
7155: }
7156: }
7157: }
7158: last if ($hascontent);
7159: }
7160: unless ($hascontent) {
7161: if ($foldername ne '') {
7162: $hidden_and_empty = $foldername;
7163: } else {
7164: $hidden_and_empty = $folder;
7165: }
7166: }
7167: }
7168: }
7169: } else {
7170: unless (ref($navmap)) {
7171: $navmap = Apache::lonnavmaps::navmap->new();
7172: }
7173: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
7174: $foldername = &HTML::Entities::decode(&unescape($foldername));
7175: if (ref($navmap)) {
7176: if ($hiddenfolder ||
7177: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
7178: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
7179: unless (@resources) {
7180: if ($foldername ne '') {
7181: $hidden_and_empty = $foldername;
7182: } else {
7183: $hidden_and_empty = $folder;
7184: }
7185: }
7186: }
7187: }
1.617 raeburn 7188: }
1.685 raeburn 7189: if ($hidden_and_empty ne '') {
7190: splice(@pathitems,-2);
7191: if (@pathitems) {
7192: $env{'form.folderpath'} = join('&',@pathitems);
7193: } else {
7194: undef($env{'form.folderpath'});
1.615 raeburn 7195: }
7196: }
7197: }
7198: }
7199:
1.446 www 7200: # If after all of this, we still don't have any paths, make them
1.519 raeburn 7201: unless ($env{'form.folderpath'}) {
1.446 www 7202: if ($supplementalflag) {
7203: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 7204: } elsif ($allowed) {
7205: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 7206: }
1.472 raeburn 7207: }
1.446 www 7208:
1.445 www 7209: # Store this
1.484 raeburn 7210: unless ($toolsflag) {
1.615 raeburn 7211: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 7212: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 7213: {'folderpath' => 'scalar'});
1.510 raeburn 7214: }
1.519 raeburn 7215: my $folderpath;
1.484 raeburn 7216: if ($env{'form.folderpath'}) {
1.519 raeburn 7217: $folderpath = $env{'form.folderpath'};
7218: my (@folders)=split('&',$env{'form.folderpath'});
7219: $env{'form.foldername'}=&unescape(pop(@folders));
7220: if ($env{'form.foldername'} =~ /\:1$/) {
7221: $container = 'page';
7222: } else {
7223: $container = 'sequence';
7224: }
7225: $env{'form.folder'}=pop(@folders);
1.484 raeburn 7226: } else {
1.519 raeburn 7227: if ($env{'form.folder'} eq '' ||
7228: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 7229: if ($env{'form.folder'} eq 'supplemental') {
7230: $folderpath=&supplemental_base();
7231: } elsif (!$hiddentop) {
7232: $folderpath='default&'.
7233: &escape(&mt('Main Content').':::::');
7234: }
1.484 raeburn 7235: }
7236: }
1.519 raeburn 7237: $containertag = '<input type="hidden" name="folderpath" value="" />';
7238: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 7239: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
7240: $showdoc='/'.$1;
7241: }
7242: if ($showdoc) { # got called in sequence from course
7243: $allowed=0;
7244: } else {
1.611 raeburn 7245: if ($canedit) {
1.484 raeburn 7246: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
7247: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 7248: }
7249: }
1.329 droeschl 7250: }
7251:
1.344 bisitz 7252: # get personal data
1.329 droeschl 7253: my $uname=$env{'user.name'};
7254: my $udom=$env{'user.domain'};
7255: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
7256:
7257: if ($allowed) {
1.484 raeburn 7258: if ($toolsflag) {
7259: $script .= &inject_data_js();
7260: my ($home,$other,%outhash)=&authorhosts();
7261: if (!$home && $other) {
7262: my @hosts;
7263: foreach my $aurole (keys(%outhash)) {
7264: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7265: push(@hosts,$outhash{$aurole});
7266: }
7267: }
7268: $script .= &dump_switchserver_js(@hosts);
7269: }
1.458 raeburn 7270: } else {
1.570 raeburn 7271: my $tid = 1;
1.484 raeburn 7272: my @tabids;
7273: if ($supplementalflag) {
1.655 raeburn 7274: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 7275: $tid = 2;
1.484 raeburn 7276: } else {
7277: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 7278: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 7279: unshift(@tabids,'001');
7280: push(@tabids,('dd1','ee1'));
7281: }
1.458 raeburn 7282: }
1.484 raeburn 7283: my $tabidstr = join("','",@tabids);
1.699 raeburn 7284: my (%domtools,%crstools);
7285: my %tooltypes = &Apache::loncommon::usable_exttools();
7286: if ($tooltypes{'dom'}) {
7287: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
7288: }
7289: if ($tooltypes{'crs'}) {
7290: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
7291: }
7292: %ltitools = (
7293: dom => \%domtools,
7294: crs => \%crstools,
7295: );
7296: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622 raeburn 7297: my $hostname = $r->hostname();
1.606 raeburn 7298: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 7299: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 7300: &history_tab_js().
7301: &inject_data_js().
1.570 raeburn 7302: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 7303: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 7304: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
7305: if ($hidden_and_empty ne '') {
7306: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
7307: $hidden_and_empty);
7308: $onload .= "javascript:alert('".&js_escape($alert)."');";
7309: }
1.484 raeburn 7310: $addentries = {
1.685 raeburn 7311: onload => $onload,
1.484 raeburn 7312: };
1.458 raeburn 7313: }
1.538 raeburn 7314: $script .= &paste_popup_js();
1.501 raeburn 7315: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
7316: &mt('Switch server?');
7317:
7318:
1.329 droeschl 7319: }
7320: # -------------------------------------------------------------------- Body tag
1.369 bisitz 7321: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 7322: .'// <![CDATA['."\n"
7323: .$script."\n"
7324: .'// ]]>'."\n"
1.595 musolffc 7325: .'</script>'."\n"
7326: .'<script type="text/javascript"
7327: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 7328:
7329: # Breadcrumbs
7330: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 7331:
7332: if ($showdoc) {
1.682 raeburn 7333: my $args;
7334: if ($supplementalflag) {
1.687 raeburn 7335: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
7336: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.705 raeburn 7337: $args = {'bread_crumbs' => $brcrum,
7338: 'bread_crumbs_nomenu' => 1};
1.682 raeburn 7339: } else {
7340: $args = {'force_register' => $showdoc};
7341: }
7342: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 7343: } elsif ($toolsflag) {
1.611 raeburn 7344: my ($breadtext,$breadtitle);
1.617 raeburn 7345: $breadtext = "$crstype Editor";
1.611 raeburn 7346: if ($canedit) {
7347: $breadtitle = 'Editing '.$crstype.' Contents';
7348: } else {
7349: $breadtext .= ' (View-only mode)';
7350: $breadtitle = 'Viewing '.$crstype.' Contents';
7351: }
1.571 raeburn 7352: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7353: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 7354: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
7355: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7356: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7357: $breadtitle)
1.571 raeburn 7358: );
1.510 raeburn 7359: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 7360: unless ($env{'request.role.adv'}) {
7361: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
7362: $r->internal_redirect('/adm/navmaps');
7363: return OK;
7364: }
7365: }
1.510 raeburn 7366: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
1.705 raeburn 7367: my $args = {'bread_crumbs' => $brcrum};
7368: unless (($env{'form.folderpath'} eq '') ||
7369: ($env{'form.folder'} eq 'supplemental')) {
7370: $args->{'bread_crumbs_nomenu'} = 1;
7371: }
1.510 raeburn 7372: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
1.705 raeburn 7373: $args));
1.510 raeburn 7374: } else {
1.611 raeburn 7375: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 7376: $breadtext = "$crstype Editor";
1.611 raeburn 7377: if ($canedit) {
7378: $breadtitle = 'Editing '.$crstype.' Contents';
7379: $helpitem = 'Docs_Adding_Course_Doc';
7380: } else {
7381: $breadtext .= ' (View-only mode)';
7382: $breadtitle = 'Viewing '.$crstype.' Contents';
7383: $helpitem = 'Docs_Viewing_Course_Doc';
7384: }
1.392 raeburn 7385: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7386: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 7387: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 7388: {'add_entries' => $addentries}
7389: )
1.392 raeburn 7390: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7391: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7392: $breadtitle,
7393: $helpitem)
1.392 raeburn 7394: );
7395: }
1.364 bisitz 7396:
1.329 droeschl 7397: my %allfiles = ();
7398: my %codebase = ();
1.440 raeburn 7399: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 7400: if ($canedit) {
1.684 raeburn 7401: undef($suppchanges);
1.329 droeschl 7402: if (($env{'form.uploaddoc.filename'}) &&
7403: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 7404: my $context = $1;
7405: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 7406: undef($hadchanges);
1.440 raeburn 7407: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 7408: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 7409: undef($navmap);
1.329 droeschl 7410: if ($hadchanges) {
7411: &mark_hash_old();
7412: }
1.684 raeburn 7413: if ($suppchanges) {
7414: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
7415: undef($suppchanges);
7416: }
1.440 raeburn 7417: $r->print($upload_output);
7418: } elsif ($env{'form.phase'} eq 'upload_embedded') {
7419: # Process file upload - phase two - upload embedded objects
7420: $uploadphase = 'check_embedded';
7421: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
7422: my $state = &embedded_form_elems($uploadphase,$primaryurl,
7423: $env{'form.newidx'});
7424: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7425: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7426: my ($destination,$dir_root) = &embedded_destination();
7427: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
7428: my $actionurl = '/adm/coursedocs';
1.630 raeburn 7429: my ($result,$flag) =
1.440 raeburn 7430: &Apache::loncommon::upload_embedded('coursedoc',$destination,
7431: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
7432: $actionurl);
7433: $r->print($result.&return_to_editor());
7434: } elsif ($env{'form.phase'} eq 'check_embedded') {
7435: # Process file upload - phase three - modify references in HTML file
7436: $uploadphase = 'modified_orightml';
7437: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7438: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7439: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 7440: my $result =
1.482 raeburn 7441: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
7442: $docuname,$docudom,undef,
7443: $dir_root);
1.630 raeburn 7444: $r->print($result.&return_to_editor());
1.476 raeburn 7445: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
7446: $uploadphase = 'decompress_phase_one';
7447: $r->print(&decompression_phase_one().
7448: &return_to_editor());
7449: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
7450: $uploadphase = 'decompress_phase_two';
7451: $r->print(&decompression_phase_two().
7452: &return_to_editor());
1.329 droeschl 7453: }
7454: }
7455:
1.484 raeburn 7456: if ($allowed && $toolsflag) {
7457: $r->print(&startContentScreen('tools'));
1.708 raeburn 7458: $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom));
1.484 raeburn 7459: $r->print(&endContentScreen());
7460: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 7461: # -----------------------------------------------------------------------------
7462: my %lt=&Apache::lonlocal::texthash(
7463: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 7464: 'upfi' => 'Upload File',
1.553 raeburn 7465: 'upld' => 'Upload Content',
1.706 raeburn 7466: 'srch' => 'Search Repository',
7467: 'impo' => 'Import from Repository',
1.487 raeburn 7468: 'lnks' => 'Import from Stored Links',
1.502 raeburn 7469: 'impm' => 'Import from Assembled Map',
1.630 raeburn 7470: 'imcr' => 'Import from Course Resources',
1.598 raeburn 7471: 'extr' => 'External Resource',
7472: 'extt' => 'External Tool',
1.329 droeschl 7473: 'selm' => 'Select Map',
7474: 'load' => 'Load Map',
7475: 'newf' => 'New Folder',
7476: 'newp' => 'New Composite Page',
7477: 'syll' => 'Syllabus',
1.425 raeburn 7478: 'navc' => 'Table of Contents',
1.343 biermanm 7479: 'sipa' => 'Simple Course Page',
1.329 droeschl 7480: 'sipr' => 'Simple Problem',
1.630 raeburn 7481: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 7482: 'stpr' => 'Standard Problem',
7483: 'news' => 'New sub-directory',
7484: 'crpr' => 'Create Problem',
1.689 raeburn 7485: 'swit' => 'Switch Server',
1.329 droeschl 7486: 'drbx' => 'Drop Box',
1.451 www 7487: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 7488: 'bull' => 'Discussion Board',
1.347 weissno 7489: 'mypi' => 'My Personal Information Page',
1.353 weissno 7490: 'grpo' => 'Group Portfolio',
1.329 droeschl 7491: 'rost' => 'Course Roster',
1.528 raeburn 7492: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 7493: 'imsf' => 'IMS Upload',
7494: 'imsl' => 'Upload IMS package',
1.501 raeburn 7495: 'cms' => 'Origin of IMS package',
7496: 'se' => 'Select',
1.329 droeschl 7497: 'file' => 'File',
7498: 'title' => 'Title',
1.606 raeburn 7499: 'addp' => 'Add Placeholder to course?',
7500: 'uste' => 'Use Template?',
7501: 'fnam' => 'File Name:',
7502: 'loca' => 'Location:',
7503: 'dire' => 'Directory:',
7504: 'cate' => 'Category:',
7505: 'tmpl' => 'Template:',
1.698 raeburn 7506: 'empd' => 'No resources found',
1.329 droeschl 7507: 'comment' => 'Comment',
1.403 raeburn 7508: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 7509: 'bb5' => 'Blackboard 5',
7510: 'bb6' => 'Blackboard 6',
7511: 'angel5' => 'ANGEL 5.5',
7512: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 7513: 'yes' => 'Yes',
7514: 'no' => 'No',
1.618 raeburn 7515: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 7516: );
1.329 droeschl 7517: # -----------------------------------------------------------------------------
1.595 musolffc 7518:
7519: # Calculate free quota space for a user or course. A javascript function checks
7520: # file size to determine if upload should be allowed.
7521: my $quotatype = 'unofficial';
7522: if ($crstype eq 'Community') {
1.601 raeburn 7523: $quotatype = 'community';
7524: } elsif ($crstype eq 'Placement') {
7525: $quotatype = 'placement';
1.595 musolffc 7526: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
7527: $quotatype = 'official';
7528: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
7529: $quotatype = 'textbook';
7530: }
7531: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
7532: 'course',$quotatype); # expressed in MB
7533: my $current_disk_usage = 0;
7534: foreach my $subdir ('docs','supplemental') {
7535: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
7536: "userfiles/$subdir",1); # expressed in kB
7537: }
7538: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 7539: my $usage = $current_disk_usage/1024; # in MB
7540: my $quota = $disk_quota;
7541: my $percent;
7542: if ($disk_quota == 0) {
7543: $percent = 100.0;
7544: } else {
1.619 raeburn 7545: $percent = 100*($usage/$disk_quota);
1.605 raeburn 7546: }
7547: $usage = sprintf("%.2f",$usage);
7548: $quota = sprintf("%.2f",$quota);
7549: $percent = sprintf("%.0f",$percent);
7550: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
7551: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 7552:
1.329 droeschl 7553: my $fileupload=(<<FIUP);
1.605 raeburn 7554: $quotainfo
1.329 droeschl 7555: $lt{'file'}:<br />
7556: FIUP
7557: my $checkbox=(<<CHBO);
7558: <!-- <label>$lt{'parse'}?
7559: <input type="checkbox" name="parserflag" />
7560: </label> -->
7561: <label>
1.611 raeburn 7562: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 7563: </label>
7564: CHBO
1.501 raeburn 7565: my $imsfolder = $env{'form.folder'};
7566: if ($imsfolder eq '') {
7567: $imsfolder = 'default';
7568: }
7569: my $imspform=(<<IMSFORM);
7570: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
7571: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
7572: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 7573: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 7574: <legend>$lt{'imsf'}</legend>
7575: $fileupload
1.702 raeburn 7576: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
7577: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501 raeburn 7578: <br />
7579: <p>
7580: $lt{'cms'}:
1.611 raeburn 7581: <select name="source" $disabled>
1.501 raeburn 7582: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 7583: <option value="bb5">$lt{'bb5'}</option>
7584: <option value="bb6">$lt{'bb6'}</option>
7585: <option value="angel5">$lt{'angel5'}</option>
7586: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 7587: </select>
7588: <input type="hidden" name="folder" value="$imsfolder" />
7589: </p>
7590: <input type="hidden" name="phase" value="one" />
1.611 raeburn 7591: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 7592: </fieldset>
7593: </form>
7594: IMSFORM
1.329 droeschl 7595:
7596: my $fileuploadform=(<<FUFORM);
1.501 raeburn 7597: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
7598: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
7599: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 7600: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 7601: <legend>$lt{'upfi'}</legend>
1.371 tempelho 7602: <input type="hidden" name="active" value="aa" />
1.595 musolffc 7603: $fileupload
1.702 raeburn 7604: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
7605: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 7606: <br />
7607: $lt{'title'}:<br />
1.611 raeburn 7608: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 7609: $pathitem
1.329 droeschl 7610: <input type="hidden" name="cmd" value="upload_default" />
7611: <br />
1.458 raeburn 7612: <span class="LC_nobreak" style="float:left">
1.329 droeschl 7613: $checkbox
7614: </span>
1.501 raeburn 7615: <br clear="all" />
1.611 raeburn 7616: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 7617: </fieldset>
7618: </form>
1.383 tempelho 7619: FUFORM
1.329 droeschl 7620:
1.611 raeburn 7621: my $mapimportjs;
7622: if ($canedit) {
7623: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
7624: } else {
7625: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
7626: }
1.502 raeburn 7627: my $importpubform=(<<SEDFFORM);
1.514 raeburn 7628: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 7629: $lt{'impm'}</a>$help{'Load_Map'}
7630: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 7631: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 7632: <legend>$lt{'impm'}</legend>
1.371 tempelho 7633: <input type="hidden" name="active" value="bb" />
1.502 raeburn 7634: $lt{'copm'}<br />
7635: <span class="LC_nobreak">
7636: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 7637: onfocus="this.blur();$mapimportjs" $disabled />
7638: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
7639: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 7640: </fieldset>
7641: </form>
7642:
1.383 tempelho 7643: SEDFFORM
1.706 raeburn 7644: my ($importcrsresform,$checkcrsres);
7645: if ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'}) {
7646: $checkcrsres = 1;
7647: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'} ne '0') {
7648: my %domdefs=&Apache::lonnet::get_domain_defaults($coursedom);
1.710 raeburn 7649: my $type = lc($env{'course.'.$env{'request.course.id'}.'.type'});
7650: unless (($type eq 'community') || ($type eq 'placement')) {
7651: $type = 'unofficial';
7652: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'} ne '') {
7653: $type = 'official';
7654: } elsif ($env{'course.'.$env{'request.course.id'}.'internal.textbook'} ne '') {
7655: $type = 'textbook';
7656: } else {
7657: $type = 'unofficial';
7658: }
7659: }
7660: if ($domdefs{$type.'crsauthor'}) {
1.706 raeburn 7661: $checkcrsres = 1;
7662: }
7663: }
7664: if ($checkcrsres) {
7665: my ($numdirs,$pickfile) =
7666: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
7667: "resize_scrollbox('contentscroll','1','0');",
7668: undef,'res');
7669: if ($pickfile) {
7670: $importcrsresform=(<<CRSFORM);
1.690 raeburn 7671: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 7672: $lt{'imcr'}</a>$help{'Course_Resources'}
7673: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
7674: <fieldset id="importcrsresform" style="display: none;">
7675: <legend>$lt{'imcr'}</legend>
1.698 raeburn 7676: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 7677: <input type="hidden" name="active" value="bb" />
7678: $pickfile
7679: <p>
1.699 raeburn 7680: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606 raeburn 7681: </p>
7682: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 7683: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 raeburn 7684: </div>
7685: <div id="importcrsresempty" style="display: none;">
7686: <p>
7687: $lt{'empd'}
7688: </p>
7689: </div>
1.606 raeburn 7690: </fieldset>
7691: </form>
7692: CRSFORM
1.706 raeburn 7693: }
1.606 raeburn 7694: }
7695:
1.611 raeburn 7696: my $fromstoredjs;
7697: if ($canedit) {
7698: $fromstoredjs = 'open_StoredLinks_Import()';
7699: } else {
7700: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
7701: }
7702:
1.502 raeburn 7703: my @importpubforma = (
1.706 raeburn 7704: { '<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>$help{'Search_LON-CAPA_Resource'}" },
1.423 onken 7705: { '<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.706 raeburn 7706: { '<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>'.$help{'Import_Stored_Links'} },
1.606 raeburn 7707: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
7708: );
1.706 raeburn 7709: if ($importcrsresform) {
7710: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/impcrsau.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\');" />' => $importcrsresform});
1.606 raeburn 7711: }
1.502 raeburn 7712: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 7713: my $extresourcesform =
7714: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 7715: $help{'Adding_External_Resource'},
7716: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 7717: my $exttoolform =
7718: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
7719: $help{'Adding_External_Tool'},undef,
7720: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 7721: \%ltitools,$disabled);
1.329 droeschl 7722: if ($allowed) {
1.492 raeburn 7723: my $folder = $env{'form.folder'};
7724: if ($folder eq '') {
7725: $folder='default';
7726: }
1.615 raeburn 7727: if ($canedit) {
7728: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
7729: if ($output) {
7730: $r->print($output);
7731: }
1.538 raeburn 7732: }
1.337 ehlerst 7733: $r->print(<<HIDDENFORM);
7734: <form name="renameform" method="post" action="/adm/coursedocs">
7735: <input type="hidden" name="title" />
7736: <input type="hidden" name="cmd" />
7737: <input type="hidden" name="markcopy" />
7738: <input type="hidden" name="copyfolder" />
7739: $containertag
7740: </form>
1.633 raeburn 7741: <form name="aliasform" method="post" action="/adm/coursedocs">
7742: <input type="hidden" name="alias" />
7743: <input type="hidden" name="cmd" />
7744: $containertag
7745: </form>
1.484 raeburn 7746:
1.337 ehlerst 7747: HIDDENFORM
1.508 raeburn 7748: $r->print(&makesimpleeditform($pathitem)."\n".
7749: &makedocslogform($pathitem."\n".
1.484 raeburn 7750: '<input type="hidden" name="folder" value="'.
7751: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 7752: }
1.442 www 7753:
7754: # Generate the tabs
1.510 raeburn 7755: my ($mode,$needs_end);
1.472 raeburn 7756: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 7757: my @folders = split('&',$env{'form.folderpath'});
7758: unless (@folders > 2) {
7759: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
7760: $needs_end = 1;
7761: }
1.472 raeburn 7762: } else {
1.484 raeburn 7763: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 7764: $needs_end = 1;
1.472 raeburn 7765: }
1.443 www 7766:
1.442 www 7767: #
1.622 raeburn 7768: my $hostname = $r->hostname();
1.442 www 7769: my $savefolderpath;
7770:
1.395 raeburn 7771: if ($allowed) {
1.329 droeschl 7772: my $folder=$env{'form.folder'};
1.615 raeburn 7773: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 7774: $folder='default';
1.356 tempelho 7775: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 7776: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 7777: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 7778: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
7779: }
7780: my $postexec='';
7781: if ($folder eq 'default') {
1.653 raeburn 7782: my $windowname = 'loncapaclient';
7783: if ($env{'request.lti.login'}) {
7784: $windowname .= 'lti';
7785: }
1.372 bisitz 7786: $r->print('<script type="text/javascript">'."\n"
7787: .'// <![CDATA['."\n"
1.653 raeburn 7788: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 7789: .'// ]]>'."\n"
7790: .'</script>'."\n"
1.369 bisitz 7791: );
1.329 droeschl 7792: } else {
7793: #$postexec='self.close();';
7794: }
1.504 raeburn 7795: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
7796: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 7797: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
7798:
7799: my $newnavform=(<<NNFORM);
7800: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 7801: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7802: $pathitem
1.329 droeschl 7803: <input type="hidden" name="importdetail"
7804: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 7805: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 7806: $help{'Navigate_Content'}
7807: </form>
7808: NNFORM
7809: my $newsmppageform=(<<NSPFORM);
7810: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 7811: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7812: $pathitem
1.329 droeschl 7813: <input type="hidden" name="importdetail" value="" />
1.423 onken 7814: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 7815: $help{'Simple Page'}
1.329 droeschl 7816: </form>
7817: NSPFORM
7818:
7819: my $newsmpproblemform=(<<NSPROBFORM);
7820: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 7821: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7822: $pathitem
1.329 droeschl 7823: <input type="hidden" name="importdetail" value="" />
1.423 onken 7824: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 7825: $help{'Simple_Problem'}
1.329 droeschl 7826: </form>
7827:
7828: NSPROBFORM
7829:
7830: my $newdropboxform=(<<NDBFORM);
7831: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 7832: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7833: $pathitem
1.329 droeschl 7834: <input type="hidden" name="importdetail" value="" />
1.423 onken 7835: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 7836: $help{'Dropbox'}
1.344 bisitz 7837: </form>
1.329 droeschl 7838: NDBFORM
7839:
7840: my $newexuploadform=(<<NEXUFORM);
7841: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 7842: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7843: $pathitem
1.329 droeschl 7844: <input type="hidden" name="importdetail" value="" />
1.423 onken 7845: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 7846: $help{'Score_Upload_Form'}
7847: </form>
7848: NEXUFORM
7849:
7850: my $newbulform=(<<NBFORM);
7851: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 7852: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7853: $pathitem
1.329 droeschl 7854: <input type="hidden" name="importdetail" value="" />
1.423 onken 7855: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 7856: $help{'Bulletin Board'}
7857: </form>
7858: NBFORM
7859:
7860: my $newaboutmeform=(<<NAMFORM);
7861: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 7862: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7863: $pathitem
1.329 droeschl 7864: <input type="hidden" name="importdetail"
7865: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7866: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 7867: $help{'My Personal Information Page'}
1.329 droeschl 7868: </form>
7869: NAMFORM
7870:
7871: my $newaboutsomeoneform=(<<NASOFORM);
7872: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 7873: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7874: $pathitem
1.329 droeschl 7875: <input type="hidden" name="importdetail" value="" />
1.423 onken 7876: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 7877: </form>
7878: NASOFORM
7879:
7880: my $newrosterform=(<<NROSTFORM);
7881: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 7882: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7883: $pathitem
1.329 droeschl 7884: <input type="hidden" name="importdetail"
7885: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 7886: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 7887: $help{'Course_Roster'}
1.329 droeschl 7888: </form>
7889: NROSTFORM
7890:
1.534 raeburn 7891: my $newwebpage;
7892: if ($folder =~ /^default_?(\d*)$/) {
7893: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
7894: if ($1) {
7895: $newwebpage .= $1;
7896: } else {
7897: $newwebpage .= 'default';
7898: }
7899: $newwebpage .= '/new.html';
7900: }
7901: my $newwebpageform =(<<NWEBFORM);
7902: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 7903: <input type="hidden" name="active" value="ff" />
1.534 raeburn 7904: $pathitem
7905: <input type="hidden" name="importdetail" value="$newwebpage" />
7906: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 7907: $help{'Web_Page'}
1.534 raeburn 7908: </form>
7909: NWEBFORM
1.701 raeburn 7910: my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606 raeburn 7911: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 7912: my $machines_str = "'".join("','",@ids)."'";
7913: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 7914: if ($env{'user.author'}) {
7915: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 7916: $is_home{'author'} = 1;
1.606 raeburn 7917: }
1.691 raeburn 7918: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 7919: }
7920: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
7921: ['active'],['ca','aa']);
1.691 raeburn 7922: my %by_roletype;
1.606 raeburn 7923: if (keys(%roleshash)) {
7924: foreach my $entry (keys(%roleshash)) {
7925: my ($auname,$audom,$roletype) = split(/:/,$entry);
7926: my $key = $entry;
7927: $key =~ s/:/___/g;
1.691 raeburn 7928: my $author = $auname.'___'.$audom;
7929: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 7930: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 7931: $toppath{$author} = "/priv/$audom/$auname";
7932: if (grep(/^\Q$rolehome\E$/,@ids)) {
7933: $is_home{$author} = 1;
1.606 raeburn 7934: }
1.691 raeburn 7935: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
7936: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 7937: }
1.691 raeburn 7938: }
7939: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
7940: if (grep(/^\Q$crshome\E$/,@ids)) {
7941: $is_home{'course'} = 1;
7942: }
7943: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
7944: my $pickdir = $lt{'loca'}.
7945: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
7946: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
7947: if ($env{'user.author'}) {
7948: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
7949: }
7950: if (keys(%by_roletype)) {
7951: foreach my $possrole ('ca','aa') {
7952: if (ref($by_roletype{$possrole}) eq 'HASH') {
7953: my $roletitle = &Apache::lonnet::plaintext($possrole);
7954: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
7955: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
7956: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
7957: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 7958: }
7959: }
7960: }
7961: }
1.706 raeburn 7962: if ($checkcrsres) {
7963: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n";
7964: }
7965: $pickdir .= '</select><br />'."\n".
1.691 raeburn 7966: $lt{'dire'}.
7967: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
7968: '<option value=""></option>'.
7969: '</select><br />'."\n";
1.606 raeburn 7970: my %seltemplate_menus;
7971: my @files = &Apache::lonhomework::get_template_list('problem');
7972: my @noexamplelink = ('blank.problem','blank.library','script.library');
7973: my $currentcategory = '';
7974: my @ordered = ('');
7975: my %templatehelp;
7976: my $defcategory = '';
7977: my @catorder = ($defcategory);
7978: $seltemplate_menus{$defcategory}->{'order'} = [''];
7979: $seltemplate_menus{$defcategory}->{'text'} = '';
7980: foreach my $file (@files) {
7981: if (ref($file) eq 'ARRAY') {
7982: my ($path,$title,$category,$help) = @{$file};
7983: next if ($title !~ /\S/);
7984: if (&js_escape($category) ne $currentcategory) {
7985: $currentcategory = &js_escape($category);
7986: push(@catorder,&js_escape($currentcategory));
7987: $seltemplate_menus{$currentcategory}->{'text'} = $category;
7988: $seltemplate_menus{$currentcategory}->{'default'} = '';
7989: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
7990: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
7991: }
7992: if ($path) {
7993: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
7994: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
7995: if ($help) {
7996: $templatehelp{$path} = $help;
7997: }
7998: }
7999: }
8000: }
8001:
8002: my $templates = $lt{'cate'}.' '.
8003: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
8004: $defcategory,'tempcategory','template',
8005: \%seltemplate_menus,\@catorder,
8006: "resize_scrollbox('contentscroll','1','0');",
8007: "toggleExampleText();",'template').'<br />';
8008: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
1.701 raeburn 8009: '<span id="newresexample">'.&mt('Example').'</span></a>';
1.706 raeburn 8010: my $crsresform;
8011: if (($env{'user.author'}) || ($checkcrsres)) {
8012: $crsresform=(<<RESFORM);
1.691 raeburn 8013: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.706 raeburn 8014: $lt{'stpr'}</a>$help{'Standard_Problem'}
1.606 raeburn 8015: <form action="/adm/coursedocs" method="post" name="courseresform">
8016: <fieldset id="crsresform" style="display:none;">
8017: <legend>$lt{'stpr'}</legend>
1.655 raeburn 8018: <input type="hidden" name="active" value="bb" />
1.606 raeburn 8019: <p>
8020: $pickdir
1.701 raeburn 8021: </p>
1.691 raeburn 8022: <div id="newstdproblem" style="display:none;">
1.701 raeburn 8023: <p>
1.606 raeburn 8024: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 8025: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 8026:
1.611 raeburn 8027: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 8028: </span><span id="newsubdir"></span>
8029: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701 raeburn 8030: </p>
1.699 raeburn 8031: </div>
1.606 raeburn 8032: $lt{'fnam'}
1.611 raeburn 8033: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.701 raeburn 8034: <div id="newresource" style="display:none">
1.606 raeburn 8035: <p>
8036: $lt{'addp'}
1.611 raeburn 8037: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 8038: $lt{'no'}</label>
1.611 raeburn 8039: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 8040: $lt{'yes'}</label>
8041: <span id="newrestitle"></span>
1.611 raeburn 8042: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701 raeburn 8043: </p>
1.606 raeburn 8044: </div>
8045: <p>
8046: $lt{'uste'}
1.611 raeburn 8047: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 8048: $lt{'no'}</label>
1.611 raeburn 8049: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 8050: $lt{'yes'}</label>
1.701 raeburn 8051: </p>
1.606 raeburn 8052: <div id="newrestemplate" style="display:none">
8053: $templates
8054: $templatepreview
8055: </div>
8056: <span class="LC_nobreak">
1.701 raeburn 8057: <input type="hidden" name="folderpath" value="$showpath" />
1.611 raeburn 8058: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 8059: </span>
1.691 raeburn 8060: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 8061: $rolehomes
8062: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
8063: </div>
1.606 raeburn 8064: </fieldset>
8065: </form>
8066:
8067: RESFORM
1.706 raeburn 8068: }
1.534 raeburn 8069:
1.342 ehlerst 8070: my $specialdocumentsform;
1.383 tempelho 8071: my @specialdocumentsforma;
1.451 www 8072: my $gradingform;
8073: my @gradingforma;
8074: my $communityform;
8075: my @communityforma;
1.351 ehlerst 8076: my $newfolderform;
1.390 tempelho 8077: my $newfolderb;
1.342 ehlerst 8078:
1.451 www 8079: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 8080:
1.329 droeschl 8081: my $newpageform=(<<NPFORM);
8082: <form action="/adm/coursedocs" method="post" name="newpage">
8083: <input type="hidden" name="folderpath" value="$path" />
8084: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 8085: <input type="hidden" name="active" value="ee" />
1.423 onken 8086: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 8087: $help{'Adding_Pages'}
1.329 droeschl 8088: </form>
8089: NPFORM
1.390 tempelho 8090:
8091:
1.351 ehlerst 8092: $newfolderform=(<<NFFORM);
1.329 droeschl 8093: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 8094: $pathitem
1.329 droeschl 8095: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 8096: <input type="hidden" name="active" value="" />
1.422 onken 8097: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 8098: </form>
8099: NFFORM
8100:
8101: my $newsylform=(<<NSYLFORM);
8102: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 8103: <input type="hidden" name="active" value="ee" />
1.508 raeburn 8104: $pathitem
1.329 droeschl 8105: <input type="hidden" name="importdetail"
8106: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 8107: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 8108: $help{'Syllabus'}
1.383 tempelho 8109:
1.329 droeschl 8110: </form>
8111: NSYLFORM
1.364 bisitz 8112:
1.329 droeschl 8113: my $newgroupfileform=(<<NGFFORM);
8114: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 8115: <input type="hidden" name="active" value="ee" />
1.508 raeburn 8116: $pathitem
1.329 droeschl 8117: <input type="hidden" name="importdetail"
8118: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 8119: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 8120: $help{'Group Portfolio'}
1.329 droeschl 8121: </form>
8122: NGFFORM
1.672 raeburn 8123: if ($container eq 'page') {
8124: @specialdocumentsforma=(
8125: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
8126: );
8127: } else {
8128: @specialdocumentsforma=(
1.421 onken 8129: {'<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 8130: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 8131: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 8132: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 8133: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 8134: );
8135: }
1.451 www 8136: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
8137:
1.655 raeburn 8138: my @external = (
8139: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 8140: );
1.699 raeburn 8141: if ($posslti) {
1.655 raeburn 8142: push(@external,
8143: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
8144: );
1.598 raeburn 8145: }
1.655 raeburn 8146: my $externalform = &create_form_ul(&create_list_elements(@external));
8147:
8148: my @importdoc = ();
1.519 raeburn 8149: unless ($container eq 'page') {
8150: push(@importdoc,
8151: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
8152: );
8153: }
8154: push(@importdoc,
1.558 raeburn 8155: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 8156: );
1.501 raeburn 8157: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 8158:
1.451 www 8159: @gradingforma=(
8160: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
8161: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
1.706 raeburn 8162: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
1.451 www 8163: );
1.706 raeburn 8164: if ($crsresform) {
8165: push(@gradingforma,
8166: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform}
8167: );
8168: }
1.451 www 8169: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
8170:
8171: @communityforma=(
8172: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
8173: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
8174: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 8175: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
8176: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 8177: );
8178: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 8179:
1.330 tempelho 8180: my %orderhash = (
1.553 raeburn 8181: 'aa' => ['Upload',$fileuploadform],
1.707 raeburn 8182: 'bb' => ['External',$externalform],
8183: 'cc' => ['Import',$importpubform],
1.701 raeburn 8184: 'dd' => ['Assessment',$gradingform],
1.673 raeburn 8185: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 8186: );
1.519 raeburn 8187: unless ($container eq 'page') {
1.434 raeburn 8188: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 8189: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 8190: }
8191:
1.341 ehlerst 8192: $hadchanges=0;
1.484 raeburn 8193: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 8194: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 8195: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 8196: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 8197: undef($navmap);
1.443 www 8198: if ($error) {
8199: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
8200: }
1.639 raeburn 8201: if ($hadchanges) {
8202: unless (&is_hash_old()) {
1.638 raeburn 8203: &mark_hash_old();
8204: }
8205: }
1.341 ehlerst 8206:
1.443 www 8207: &changewarning($r,'');
8208: }
1.458 raeburn 8209: }
1.442 www 8210:
1.443 www 8211: # Supplemental documents start here
8212:
1.329 droeschl 8213: my $folder=$env{'form.folder'};
1.443 www 8214: unless ($supplementalflag) {
1.329 droeschl 8215: $folder='supplemental';
8216: }
1.685 raeburn 8217: if (($folder eq 'supplemental') &&
1.329 droeschl 8218: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 8219: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 8220: } elsif ($allowed) {
1.356 tempelho 8221: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 8222: }
1.508 raeburn 8223: $pathitem = '<input type="hidden" name="folderpath" value="'.
8224: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 8225: if ($allowed) {
8226: my $folderseq=
1.504 raeburn 8227: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 8228:
8229: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 8230: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
8231: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 8232: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 8233: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 8234: <legend>$lt{'upfi'}</legend>
1.630 raeburn 8235: <input type="hidden" name="active" value="ee" />
1.329 droeschl 8236: $fileupload
1.702 raeburn 8237: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
8238: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 8239: <br />
8240: <br />
8241: <span class="LC_nobreak">
8242: $checkbox
8243: </span>
8244: <br /><br />
8245: $lt{'comment'}:<br />
1.383 tempelho 8246: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 8247: <br />
1.508 raeburn 8248: $pathitem
1.329 droeschl 8249: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 8250: <input type='submit' value="$lt{'upld'}" />
1.700 raeburn 8251: </fieldset>
1.501 raeburn 8252: </form>
1.329 droeschl 8253: SUPDOCFORM
8254:
8255: my $supnewfolderform=(<<SNFFORM);
8256: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 8257: <input type="hidden" name="active" value="" />
1.508 raeburn 8258: $pathitem
1.329 droeschl 8259: <input type="hidden" name="importdetail" value="" />
1.423 onken 8260: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 8261: $help{'Adding_Folders'}
1.329 droeschl 8262: </form>
8263: SNFFORM
1.383 tempelho 8264:
1.510 raeburn 8265: my $supextform =
8266: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 8267: $help{'Adding_External_Resource'},
8268: undef,undef,undef,undef,undef,undef,
8269: $disabled);
1.329 droeschl 8270:
1.598 raeburn 8271: my $supexttoolform =
8272: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
8273: $help{'Adding_External_Tool'},
8274: undef,undef,'tool',$coursedom,
1.611 raeburn 8275: $coursenum,\%ltitools,$disabled);
1.598 raeburn 8276:
1.329 droeschl 8277: my $supnewsylform=(<<SNSFORM);
8278: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 8279: <input type="hidden" name="active" value="ff" />
1.508 raeburn 8280: $pathitem
1.329 droeschl 8281: <input type="hidden" name="importdetail"
8282: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 8283: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 8284: $help{'Syllabus'}
8285: </form>
8286: SNSFORM
8287:
8288: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 8289: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 8290: <input type="hidden" name="active" value="ff" />
1.508 raeburn 8291: $pathitem
1.329 droeschl 8292: <input type="hidden" name="importdetail"
8293: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 8294: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 8295: $help{'My Personal Information Page'}
1.329 droeschl 8296: </form>
8297: SNAMFORM
8298:
1.534 raeburn 8299: my $supwebpage;
8300: if ($folder =~ /^supplemental_?(\d*)$/) {
8301: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
8302: if ($1) {
8303: $supwebpage .= $1;
8304: } else {
8305: $supwebpage .= 'default';
8306: }
8307: $supwebpage .= '/new.html';
8308: }
8309: my $supwebpageform =(<<SWEBFORM);
8310: <form action="/adm/coursedocs" method="post" name="supwebpage">
8311: <input type="hidden" name="active" value="cc" />
8312: $pathitem
8313: <input type="hidden" name="importdetail" value="$supwebpage" />
8314: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 8315: $help{'Web_Page'}
1.534 raeburn 8316: </form>
8317: SWEBFORM
8318:
1.333 muellerd 8319:
1.383 tempelho 8320: my @specialdocs = (
1.618 raeburn 8321: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 8322: =>$supnewsylform},
1.611 raeburn 8323: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 8324: =>$supnewaboutmeform},
1.534 raeburn 8325: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
8326:
1.383 tempelho 8327: );
1.655 raeburn 8328: my @supexternal = (
8329: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
8330: =>$supextform});
1.699 raeburn 8331: if ($posslti) {
1.655 raeburn 8332: push(@supexternal,
8333: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 8334: =>$supexttoolform});
8335: }
1.655 raeburn 8336: my @supimportdoc = (
1.598 raeburn 8337: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 8338: =>$supupdocform},
1.598 raeburn 8339: );
1.501 raeburn 8340:
8341: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 8342: my %suporderhash = (
1.390 tempelho 8343: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 8344: 'dd' => ['Upload',$supupdocform],
8345: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 8346: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 8347: );
1.443 www 8348: if ($supplementalflag) {
1.682 raeburn 8349: $suppchanges = 0;
8350: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
8351: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
8352: \%ltitools,$canedit,$hostname);
8353: if ($error) {
8354: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
8355: }
8356: if ($suppchanges) {
1.684 raeburn 8357: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 8358: undef($suppchanges);
8359: }
1.393 raeburn 8360: }
1.443 www 8361: } elsif ($supplementalflag) {
1.458 raeburn 8362: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 8363: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
8364: $hostname);
1.393 raeburn 8365: if ($error) {
8366: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 8367: }
1.393 raeburn 8368: }
1.389 tempelho 8369:
1.510 raeburn 8370: if ($needs_end) {
8371: $r->print(&endContentScreen());
8372: }
1.383 tempelho 8373:
1.329 droeschl 8374: if ($allowed) {
8375: $r->print('
8376: <form method="post" name="extimport" action="/adm/coursedocs">
8377: <input type="hidden" name="title" />
8378: <input type="hidden" name="url" />
8379: <input type="hidden" name="useform" />
8380: <input type="hidden" name="residx" />
8381: </form>');
8382: }
1.484 raeburn 8383: } elsif ($showdoc) {
1.329 droeschl 8384: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 8385: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 8386: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 8387: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 8388: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 8389: }
8390: }
1.630 raeburn 8391: unless ($noendpage) {
1.606 raeburn 8392: $r->print(&Apache::loncommon::end_page());
8393: }
1.329 droeschl 8394: return OK;
1.364 bisitz 8395: }
1.329 droeschl 8396:
1.440 raeburn 8397: sub embedded_form_elems {
8398: my ($phase,$primaryurl,$newidx) = @_;
8399: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 8400: $newidx =~s /\D+//g;
1.440 raeburn 8401: return <<STATE;
8402: <input type="hidden" name="folderpath" value="$folderpath" />
8403: <input type="hidden" name="cmd" value="upload_embedded" />
8404: <input type="hidden" name="newidx" value="$newidx" />
8405: <input type="hidden" name="phase" value="$phase" />
8406: <input type="hidden" name="primaryurl" value="$primaryurl" />
8407: STATE
8408: }
8409:
8410: sub embedded_destination {
8411: my $folder=$env{'form.folder'};
8412: my $destination = 'docs/';
8413: if ($folder =~ /^supplemental/) {
8414: $destination = 'supplemental/';
8415: }
8416: if (($folder eq 'default') || ($folder eq 'supplemental')) {
8417: $destination .= 'default/';
8418: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
8419: $destination .= $2.'/';
8420: }
1.634 raeburn 8421: my $newidx = $env{'form.newidx'};
8422: $newidx =~s /\D+//g;
8423: if ($newidx) {
8424: $destination .= $newidx;
8425: }
1.440 raeburn 8426: my $dir_root = '/userfiles';
8427: return ($destination,$dir_root);
8428: }
8429:
8430: sub return_to_editor {
8431: my $actionurl = '/adm/coursedocs';
8432: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
8433: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
8434: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
8435: '</a></p>';
8436: }
8437:
1.476 raeburn 8438: sub decompression_info {
8439: my ($destination,$dir_root) = &embedded_destination();
8440: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
8441: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8442: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
8443: my $container='sequence';
1.480 raeburn 8444: my ($pathitem,$hiddenelem);
1.583 raeburn 8445: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 8446: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 8447: $container='page';
8448: }
1.480 raeburn 8449: unshift(@hiddens,$pathitem);
8450: foreach my $item (@hiddens) {
1.634 raeburn 8451: if ($item eq 'newidx') {
8452: next if ($env{'form.'.$item} =~ /\D/);
8453: }
1.480 raeburn 8454: if ($env{'form.'.$item}) {
8455: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 8456: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 8457: }
1.477 raeburn 8458: }
1.476 raeburn 8459: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
8460: $hiddenelem);
8461: }
8462:
8463: sub decompression_phase_one {
8464: my ($dir,$file,$warning,$error,$output);
8465: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8466: &decompression_info();
1.490 raeburn 8467: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 8468: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
8469: } else {
8470: my $file = $1;
1.630 raeburn 8471: $output =
1.481 raeburn 8472: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
8473: $destination,$dir_root,
8474: $hiddenelem);
8475: if ($env{'form.autoextract_camtasia'}) {
8476: $output .= &remove_archive($docudom,$docuname,$container);
8477: }
1.476 raeburn 8478: }
8479: if ($error) {
8480: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
8481: $error.'</p>'."\n";
8482: }
8483: if ($warning) {
8484: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
8485: }
8486: return $output;
8487: }
8488:
8489: sub decompression_phase_two {
8490: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8491: &decompression_info();
1.481 raeburn 8492: my $output;
1.480 raeburn 8493: if ($env{'form.archivedelete'}) {
1.481 raeburn 8494: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 8495: }
8496: $output .=
1.481 raeburn 8497: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 8498: $destination,$dir_root,$hiddenelem);
8499: return $output;
8500: }
8501:
1.480 raeburn 8502: sub remove_archive {
8503: my ($docudom,$docuname,$container) = @_;
8504: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 8505: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 8506: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
8507: if ($fatal) {
8508: if ($container eq 'page') {
8509: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
8510: } else {
8511: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
8512: }
1.583 raeburn 8513: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8514: } else {
8515: my $currcmd = $env{'form.cmd'};
8516: my $position = $env{'form.position'};
1.583 raeburn 8517: my $archiveidx = $position;
1.563 raeburn 8518: if ($position > 0) {
1.583 raeburn 8519: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
8520: $archiveidx = $position-1;
8521: }
8522: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 8523: my ($title,$url,@rrest) =
1.583 raeburn 8524: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
8525: if ($url eq $env{'form.archiveurl'}) {
8526: if (&handle_edit_cmd($docuname,$docudom)) {
8527: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 8528: if ($suppchanges) {
8529: &Apache::lonnet::update_supp_caches($docudom,$docuname);
8530: undef($suppchanges);
8531: }
1.583 raeburn 8532: if ($fatal) {
8533: if ($container eq 'page') {
8534: $delwarning = &mt('An error occurred updating the contents of the current page.');
8535: } else {
8536: $delwarning = &mt('An error occurred updating the contents of the current folder.');
8537: }
1.480 raeburn 8538: } else {
1.583 raeburn 8539: $delresult = &mt('Archive file removed.');
1.480 raeburn 8540: }
8541: }
1.583 raeburn 8542: } else {
8543: $delwarning .= &mt('Archive file had unexpected item number in folder.').
8544: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8545: }
8546: }
8547: $env{'form.cmd'} = $currcmd;
8548: }
8549: if ($delwarning) {
8550: $output = '<p class="LC_warning">'.
8551: $delwarning.
8552: '</p>';
8553: }
8554: if ($delresult) {
8555: $output .= '<p class="LC_info">'.
8556: $delresult.
8557: '</p>';
8558: }
1.481 raeburn 8559: return $output;
1.480 raeburn 8560: }
8561:
1.484 raeburn 8562: sub generate_admin_menu {
1.708 raeburn 8563: my ($crstype,$canedit,$coursenum,$coursedom) = @_;
1.484 raeburn 8564: my $lc_crstype = lc($crstype);
8565: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 8566: my %lt= ( # do not translate here
1.484 raeburn 8567: 'vc' => 'Verify Content',
8568: 'cv' => 'Check/Set Resource Versions',
8569: 'ls' => 'List Resource Identifiers',
1.651 raeburn 8570: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.708 raeburn 8571: 'ca' => "Enter $crstype Authoring Space",
1.484 raeburn 8572: 'imse' => 'Export contents to IMS Archive',
1.712 raeburn 8573: 'dcd' => 'Copy uploaded content to Authoring Space',
8574: 'cpc' => 'Copy from Course Authoring to User Authoring',
1.562 bisitz 8575: );
1.712 raeburn 8576: my ($candump,$dumpurl,$exportcrsurl);
1.484 raeburn 8577: if ($home + $other > 0) {
8578: $candump = 'F';
8579: if ($home) {
8580: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
1.712 raeburn 8581: $exportcrsurl = "javascript:injectData(document.courseverify,'dummy','copyauthored','$lt{'cpc'}')";
1.484 raeburn 8582: } else {
8583: my @hosts;
8584: foreach my $aurole (keys(%outhash)) {
8585: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
8586: push(@hosts,$outhash{$aurole});
1.538 raeburn 8587: }
1.484 raeburn 8588: }
8589: if (@hosts == 1) {
8590: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
8591: '&role='.
8592: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
8593: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
8594: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
1.712 raeburn 8595: $exportcrsurl = $dumpurl;
1.484 raeburn 8596: } else {
8597: $dumpurl = "javascript:choose_switchserver_window()";
1.712 raeburn 8598: $exportcrsurl = $dumpurl;
1.484 raeburn 8599: }
8600: }
8601: }
8602: my @menu=
8603: ({ categorytitle=>'Administration',
8604: items =>[
8605: { linktext => $lt{'vc'},
8606: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
8607: permission => 'F',
1.571 raeburn 8608: help => 'Docs_Verify_Content',
1.484 raeburn 8609: icon => 'verify.png',
8610: linktitle => 'Verify contents can be retrieved/rendered',
8611: },
8612: { linktext => $lt{'cv'},
8613: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
8614: permission => 'F',
1.571 raeburn 8615: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 8616: icon => 'resversion.png',
8617: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
8618: },
8619: { linktext => $lt{'ls'},
8620: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
8621: permission => 'F',
8622: #help => '',
8623: icon => 'symbs.png',
8624: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
8625: },
1.651 raeburn 8626: { linktext => $lt{'ct'},
8627: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
8628: permission => 'F',
8629: help => 'Docs_Short_URLs',
8630: icon => 'shorturls.png',
8631: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
8632: },
1.484 raeburn 8633: ]
1.611 raeburn 8634: });
8635: if ($canedit) {
1.708 raeburn 8636: my ($crsauname,$crsaudom,$crshome);
8637: if (($coursenum ne '') && ($coursedom ne '')) {
8638: my $crsauthorurl = "/priv/$coursedom/$coursenum/";
8639: ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl);
8640: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8641: my @ids=&Apache::lonnet::current_machine_ids();
8642: my $linkurl;
8643: if (grep(/^\Q$crshome\E$/,@ids)) {
8644: $linkurl = $crsauthorurl;
8645: } else {
8646: $linkurl =
8647: &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1);
8648: }
8649: if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY')) {
8650: push(@{$menu[0]->{items}},
8651: { linktext => $lt{'ca'},
8652: url => $linkurl,
8653: permission => 'F',
8654: help => 'Docs_Course_Authorspace',
8655: icon => 'impcrsau.png',
8656: linktitle => $lt{'ca'},
8657: });
8658: }
8659: }
8660: }
1.611 raeburn 8661: push(@menu,
1.484 raeburn 8662: { categorytitle=>'Export',
8663: items =>[
8664: { linktext => $lt{'imse'},
8665: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
8666: permission => 'F',
8667: help => 'Docs_Export_Course_Docs',
8668: icon => 'imsexport.png',
8669: linktitle => $lt{'imse'},
8670: },
8671: { linktext => $lt{'dcd'},
8672: url => $dumpurl,
8673: permission => $candump,
1.571 raeburn 8674: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 8675: icon => 'dump.png',
8676: linktitle => $lt{'dcd'},
8677: },
8678: ]
8679: });
1.712 raeburn 8680: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8681: if ((ref($menu[1]) eq 'HASH') && (ref($menu[1]->{'items'}) eq 'ARRAY')) {
8682: push(@{$menu[1]->{items}},
8683: { linktext => $lt{'cpc'},
8684: url => $exportcrsurl,
8685: permission => 'F',
8686: help => 'Docs_Export_Course_Author',
8687: icon => 'res.png',
8688: linktitle => $lt{'cpc'},
8689: });
8690: }
8691: }
1.611 raeburn 8692: }
1.484 raeburn 8693: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
8694: '<input type="hidden" id="dummy" />'."\n".
8695: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
8696: '</form>';
1.329 droeschl 8697: }
8698:
8699: sub generate_edit_table {
1.538 raeburn 8700: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 8701: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 8702: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 8703: my %orderhash = %{$orderhash_ref};
1.611 raeburn 8704: my ($form, $activetab, $active, $disabled);
1.570 raeburn 8705: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 8706: $activetab = $env{'form.active'};
8707: }
1.611 raeburn 8708: unless ($canedit) {
8709: $disabled = ' disabled="disabled"';
8710: }
1.472 raeburn 8711: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 8712: my $backtext = &mt('Exit Editor');
1.458 raeburn 8713: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 8714: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
8715: '<li class="goback">'.
1.546 raeburn 8716: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 8717: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
8718: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
8719: '<li>'.
8720: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
8721: &mt('Undo Delete').'</a></li>'."\n";
8722: if ($env{'form.docslog'}) {
8723: $form .= '<li class="active">';
8724: } else {
8725: $form .= '<li>';
8726: }
8727: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
8728: &mt('History').'</a></li>'."\n";
8729: if ($env{'form.docslog'}) {
8730: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
8731: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 8732: }
1.458 raeburn 8733: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 8734: if($name ne '00'){
1.371 tempelho 8735: if($activetab eq '' || $activetab ne $name){
8736: $active = '';
8737: }elsif($activetab eq $name){
8738: $active = 'class="active"';
8739: }
1.458 raeburn 8740: $form .= '<li style="float:right" '.$active
1.484 raeburn 8741: .' 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 8742: } else {
1.570 raeburn 8743: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 8744:
8745: }
1.329 droeschl 8746: }
1.484 raeburn 8747: $form .= '</ul>'."\n";
8748: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 8749:
8750: if ($to_show ne '') {
1.538 raeburn 8751: my $saveform;
8752: if ($need_save) {
8753: my $button = &mt('Make changes');
8754: my $path;
8755: if ($env{'form.folderpath'}) {
8756: $path =
8757: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
8758: }
8759: $saveform = <<"END";
8760: <div id="multisave" style="display:none; clear:both;" >
8761: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
8762: <input type="hidden" name="folderpath" value="$path" />
8763: <input type="hidden" name="symb" value="$env{'form.symb'}" />
8764: <input type="hidden" name="allhiddenresource" value="" />
8765: <input type="hidden" name="allencrypturl" value="" />
8766: <input type="hidden" name="allrandompick" value="" />
8767: <input type="hidden" name="allrandomorder" value="" />
8768: <input type="hidden" name="changeparms" value="" />
8769: <input type="hidden" name="multiremove" value="" />
8770: <input type="hidden" name="multicut" value="" />
8771: <input type="hidden" name="multicopy" value="" />
8772: <input type="hidden" name="multichange" value="" />
8773: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 8774: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 8775: </form>
8776: </div>
8777: END
8778: }
8779: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 8780: }
1.363 ehlerst 8781: foreach my $field (keys(%orderhash)){
1.390 tempelho 8782: if($field ne '00'){
1.422 onken 8783: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 8784: $active = 'style="display: none;float:left"';
1.422 onken 8785: }elsif($activetab eq $field){
1.458 raeburn 8786: $active = 'style="display:block;float:left"';
1.422 onken 8787: }
8788: $form .= '<div id="'.$field.$tid.'"'
8789: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 8790: .'</div>'."\n";
1.363 ehlerst 8791: }
8792: }
1.484 raeburn 8793: unless ($env{'form.docslog'}) {
8794: $form .= '</div></div>'."\n";
8795: }
1.329 droeschl 8796: return $form;
8797: }
8798:
8799: sub editing_js {
1.622 raeburn 8800: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
8801: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 8802: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 8803: p_mnf => 'Name of New Folder',
8804: t_mnf => 'New Folder',
8805: p_mnp => 'Name of New Page',
8806: t_mnp => 'New Page',
1.451 www 8807: p_mxu => 'Title for the External Score',
1.349 biermanm 8808: p_msp => 'Name of Simple Course Page',
1.329 droeschl 8809: p_msb => 'Title for the Problem',
8810: p_mdb => 'Title for the Drop Box',
1.336 schafran 8811: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 8812: p_mwp => 'Title for Web Page',
1.606 raeburn 8813: p_mnr => 'Title for the Resource',
1.348 weissno 8814: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 8815: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 8816: p_mab_alrt1 => 'Not a valid user:domain',
8817: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
8818: p_chn => 'New Title',
8819: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 8820: p_rmr2a => 'Remove',
8821: p_rmr2b => '?',
8822: p_rmr3a => 'Remove those',
8823: p_rmr3b => 'items?',
8824: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
8825: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 8826: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
8827: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 8828: p_ctr2a => 'Cut',
8829: p_ctr2b => '?',
8830: p_ctr3a => 'Cut those',
8831: p_ctr3b => 'items?',
1.633 raeburn 8832: setal => 'Enter a (unique) alias',
8833: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 8834: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 8835: imsfile => 'You must choose an IMS package for import',
8836: imscms => 'You must select which Course Management System was the source of the IMS package',
8837: invurl => 'Invalid URL',
8838: titbl => 'Title is blank',
1.538 raeburn 8839: more => '(More ...)',
8840: less => '(Less ...)',
1.543 raeburn 8841: noor => 'No actions selected or changes to settings specified.',
8842: noch => 'No changes to settings specified.',
8843: noac => 'No actions selected.',
1.606 raeburn 8844: nofi => 'No file selected',
8845: tinc => 'Title in course',
8846: sunm => 'Sub-directory name',
1.618 raeburn 8847: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 8848: sele => 'Select',
8849: swit => 'Switch server required',
1.329 droeschl 8850: );
1.594 damieng 8851: &js_escape(\%js_lt);
1.433 raeburn 8852: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 8853: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
8854: my $main_container_page;
1.519 raeburn 8855: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
8856: $main_container_page = 1;
1.434 raeburn 8857: }
1.617 raeburn 8858: my $backtourl;
8859: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 8860: my $toplevelsupp = &supplemental_base();
1.690 raeburn 8861: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 8862: my @ids=&Apache::lonnet::current_machine_ids();
8863: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 8864: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
8865: my $caller = $1;
1.525 raeburn 8866: if ($caller =~ /^supplemental/) {
8867: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
8868: } else {
8869: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
8870: $res = &Apache::lonnet::clutter($res);
8871: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 8872: my ($url,$anchor);
8873: if ($res =~ /^([^#]+)#([^#]+)$/) {
8874: $url = $1;
8875: $anchor = $2;
8876: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
8877: $caller = $1.&escape('#').$anchor;
8878: }
1.614 raeburn 8879: } else {
8880: $url = $res;
1.609 raeburn 8881: }
1.640 raeburn 8882: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
8883: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
8884: $backtourl .= '?navmap=1';
8885: } else {
8886: $backtourl .= '?symb='.
8887: &HTML::Entities::encode($caller,'<>&"');
8888: }
1.622 raeburn 8889: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
8890: if (($ENV{'SERVER_PORT'} == 443) &&
8891: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 8892: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 8893: if ($hostname ne '') {
8894: $backtourl = 'http://'.$hostname.$backtourl;
8895: }
8896: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 8897: }
8898: }
1.623 raeburn 8899: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
8900: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 8901: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 8902: if ($hostname ne '') {
8903: $backtourl = 'http://'.$hostname.$backtourl;
8904: }
8905: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 8906: }
1.623 raeburn 8907: }
1.622 raeburn 8908: }
1.609 raeburn 8909: if ($anchor ne '') {
8910: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
8911: }
1.590 raeburn 8912: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 8913: } else {
8914: $backtourl = '/adm/navmaps';
1.525 raeburn 8915: }
8916: }
8917: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
8918: $backtourl = '/adm/menu';
8919: } elsif ($supplementalflag) {
1.682 raeburn 8920: if (($env{'request.role.adv'}) ||
8921: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
8922: $backtourl = '/adm/supplemental';
8923: } else {
8924: $backtourl = '/adm/navmaps';
8925: }
1.525 raeburn 8926: } else {
8927: $backtourl = '/adm/navmaps';
1.472 raeburn 8928: }
8929:
1.655 raeburn 8930: my $fieldsets = "'doc'";
1.519 raeburn 8931: unless ($main_container_page) {
8932: $fieldsets .=",'ims'";
8933: }
1.655 raeburn 8934: my $extfieldsets = "'ext'";
8935: if ($posslti) {
8936: $extfieldsets .= ",'tool'";
8937: }
1.501 raeburn 8938: if ($supplementalflag) {
1.655 raeburn 8939: $fieldsets = "'suppdoc'";
8940: $extfieldsets = "'suppext'";
1.600 raeburn 8941: if ($posslti) {
1.655 raeburn 8942: $extfieldsets .= ",'supptool'";
1.600 raeburn 8943: }
1.501 raeburn 8944: }
1.655 raeburn 8945:
1.611 raeburn 8946: my $jsmakefunctions;
8947: if ($canedit) {
8948: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 8949: function makenewfolder(targetform,folderseq) {
1.594 damieng 8950: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 8951: if (foldername) {
1.676 raeburn 8952: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 8953: targetform.submit();
8954: }
8955: }
8956:
8957: function makenewpage(targetform,folderseq) {
1.594 damieng 8958: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 8959: if (pagename) {
1.676 raeburn 8960: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 8961: targetform.submit();
8962: }
8963: }
8964:
8965: function makeexamupload() {
1.594 damieng 8966: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 8967: if (title) {
1.329 droeschl 8968: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 8969: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 8970: this.document.forms.newexamupload.submit();
8971: }
8972: }
8973:
8974: function makesmppage() {
1.594 damieng 8975: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 8976: if (title) {
1.329 droeschl 8977: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 8978: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 8979: this.document.forms.newsmppg.submit();
8980: }
8981: }
8982:
1.534 raeburn 8983: function makewebpage(type) {
1.594 damieng 8984: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 8985: var formname;
8986: if (type == 'supp') {
8987: formname = this.document.forms.supwebpage;
8988: } else {
8989: formname = this.document.forms.newwebpage;
8990: }
8991: if (title) {
8992: var webpage = formname.importdetail.value;
1.675 raeburn 8993: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 8994: formname.submit();
8995: }
8996: }
8997:
1.329 droeschl 8998: function makesmpproblem() {
1.594 damieng 8999: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 9000: if (title) {
1.329 droeschl 9001: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 9002: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 9003: this.document.forms.newsmpproblem.submit();
9004: }
9005: }
9006:
9007: function makedropbox() {
1.594 damieng 9008: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 9009: if (title) {
1.329 droeschl 9010: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 9011: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 9012: this.document.forms.newdropbox.submit();
9013: }
9014: }
9015:
9016: function makebulboard() {
1.594 damieng 9017: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 9018: if (title) {
9019: this.document.forms.newbul.importdetail.value=
1.676 raeburn 9020: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 9021: this.document.forms.newbul.submit();
9022: }
9023: }
9024:
9025: function makeabout() {
1.594 damieng 9026: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 9027: if (user) {
9028: var comp=new Array();
9029: comp=user.split(':');
9030: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
9031: if ((comp[0]) && (comp[1])) {
9032: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 9033: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 9034: this.document.forms.newaboutsomeone.submit();
9035: } else {
9036: alert("$js_lt{'p_mab_alrt1'}");
9037: }
9038: } else {
9039: alert("$js_lt{'p_mab_alrt2'}");
9040: }
9041: }
9042: }
9043:
9044: function makenew(targetform) {
9045: targetform.submit();
9046: }
9047:
9048: function changename(folderpath,index,oldtitle) {
9049: var title=prompt('$js_lt{"p_chn"}',oldtitle);
9050: if (title) {
9051: this.document.forms.renameform.markcopy.value='';
9052: this.document.forms.renameform.title.value=title;
9053: this.document.forms.renameform.cmd.value='rename_'+index;
9054: this.document.forms.renameform.folderpath.value=folderpath;
9055: this.document.forms.renameform.submit();
9056: }
9057: }
9058:
1.633 raeburn 9059: function setalias(folderpath,index) {
9060: var alias = prompt('$js_lt{"setal"}');
9061: if ((alias != null) && (alias != '')) {
9062: this.document.forms.aliasform.alias.value=alias;
9063: this.document.forms.aliasform.cmd.value='setalias_'+index;
9064: this.document.forms.aliasform.folderpath.value=folderpath;
9065: this.document.forms.aliasform.submit();
9066: }
9067: }
9068:
9069: function delalias(folderpath,index) {
9070: if (confirm('$js_lt{"delal"}')) {
9071: this.document.forms.aliasform.cmd.value='delalias_'+index;
9072: this.document.forms.aliasform.folderpath.value=folderpath;
9073: this.document.forms.aliasform.submit();
9074: }
9075: }
9076:
1.611 raeburn 9077: ENDNEWSCRIPT
9078: } else {
9079: $jsmakefunctions = <<ENDNEWSCRIPT;
9080:
9081: function makenewfolder() {
9082: alert("$js_lt{'edri'}");
9083: }
9084:
9085: function makenewpage() {
9086: alert("$js_lt{'edri'}");
9087: }
9088:
9089: function makeexamupload() {
9090: alert("$js_lt{'edri'}");
9091: }
9092:
9093: function makesmppage() {
9094: alert("$js_lt{'edri'}");
9095: }
9096:
9097: function makewebpage(type) {
9098: alert("$js_lt{'edri'}");
9099: }
9100:
9101: function makesmpproblem() {
9102: alert("$js_lt{'edri'}");
9103: }
9104:
9105: function makedropbox() {
9106: alert("$js_lt{'edri'}");
9107: }
9108:
9109: function makebulboard() {
9110: alert("$js_lt{'edri'}");
9111: }
9112:
9113: function makeabout() {
9114: alert("$js_lt{'edri'}");
9115: }
9116:
9117: function changename() {
9118: alert("$js_lt{'edri'}");
9119: }
9120:
1.633 raeburn 9121: function setalias() {
9122: alert("$js_lt{'edri'}");
9123: }
9124:
9125: function delalias() {
9126: alert("$js_lt{'edri'}");
9127: }
9128:
1.611 raeburn 9129: function makenew() {
9130: alert("$js_lt{'edri'}");
9131: }
9132:
9133: function groupimport() {
9134: alert("$js_lt{'edri'}");
1.335 ehlerst 9135: }
1.611 raeburn 9136:
9137: function groupsearch() {
9138: alert("$js_lt{'edri'}");
1.335 ehlerst 9139: }
1.611 raeburn 9140:
9141: function groupopen(url,recover) {
9142: var options="scrollbars=1,resizable=1,menubar=0";
9143: idxflag=1;
9144: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
9145: idx.focus();
1.329 droeschl 9146: }
9147:
1.611 raeburn 9148: ENDNEWSCRIPT
9149:
9150: }
9151: return <<ENDSCRIPT;
9152:
9153: $jsmakefunctions
9154:
1.501 raeburn 9155: function toggleUpload(caller) {
9156: var blocks = Array($fieldsets);
9157: for (var i=0; i<blocks.length; i++) {
9158: var disp = 'none';
9159: if (caller == blocks[i]) {
9160: var curr = document.getElementById('upload'+caller+'form').style.display;
9161: if (curr == 'none') {
9162: disp='block';
9163: }
9164: }
9165: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 9166: }
9167: resize_scrollbox('contentscroll','1','1');
9168: return;
9169: }
9170:
9171: function toggleExternal(caller) {
9172: var blocks = Array($extfieldsets);
9173: for (var i=0; i<blocks.length; i++) {
9174: var disp = 'none';
9175: if (caller == blocks[i]) {
9176: var curr = document.getElementById('external'+caller+'form').style.display;
9177: if (curr == 'none') {
9178: disp='block';
9179: }
9180: }
9181: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 9182: if ((caller == 'tool') || (caller == 'supptool')) {
9183: if (disp == 'block') {
1.655 raeburn 9184: if (document.getElementById('LC_exttoolid')) {
9185: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 9186: var suppflag = 0;
9187: if (caller == 'supptool') {
9188: suppflag = 1;
9189: }
9190: currForm = document.getElementById('new'+caller);
1.655 raeburn 9191: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 9192: }
9193: }
9194: }
1.501 raeburn 9195: }
1.502 raeburn 9196: resize_scrollbox('contentscroll','1','1');
9197: return;
9198: }
9199:
1.514 raeburn 9200: function toggleMap(caller) {
1.502 raeburn 9201: var disp = 'none';
1.510 raeburn 9202: if (document.getElementById('importmapform')) {
1.514 raeburn 9203: if (caller == 'map') {
9204: var curr = document.getElementById('importmapform').style.display;
9205: if (curr == 'none') {
9206: disp='block';
9207: }
1.510 raeburn 9208: }
9209: document.getElementById('importmapform').style.display=disp;
1.706 raeburn 9210: if (disp == 'block') {
9211: if (document.getElementById('importcrsresform')) {
9212: if (document.getElementById('importcrsresform').style.display == 'block') {
9213: document.getElementById('importcrsresform').style.display = 'none';
9214: }
9215: }
9216: }
1.510 raeburn 9217: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 9218: }
1.501 raeburn 9219: return;
1.329 droeschl 9220: }
9221:
1.691 raeburn 9222: function toggleCrsRes(caller) {
1.606 raeburn 9223: var disp = 'none';
9224: if (document.getElementById('crsresform')) {
9225: if (caller == 'res') {
1.691 raeburn 9226: var form = document.getElementById('crsresform');
9227: var curr = form.style.display;
1.606 raeburn 9228: if (curr == 'none') {
9229: disp='block';
1.691 raeburn 9230: document.courseresform.authorrole.selectedIndex = 0;
9231: document.courseresform.authorpath.selectedIndex = 0;
9232: document.courseresform.newresourceadd.selectedIndex = 0;
9233: populateDirSelects(form,'authorrole','authorpath',1,0,0);
9234: toggleNewInCourse(document.courseresform);
9235: if (document.getElementById('newresource')) {
9236: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 9237: }
9238: if (document.courseresform.newresusetemp.length) {
9239: document.courseresform.newresusetemp[0].checked = true;
9240: toggleWithTemplate(document.courseresform);
9241: }
9242: document.courseresform.newresourcename.value = '';
9243: }
9244: }
9245: if (document.courseresform.newsubdir.length) {
9246: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
9247: if (document.courseresform.newsubdir[j].value == 0) {
9248: document.courseresform.newsubdir[j].checked = true;
9249: }
9250: break;
9251: }
9252: if (document.getElementById('newsubdirname')) {
9253: document.getElementById('newsubdirname').type = "hidden";
9254: document.getElementById('newsubdirname').value = "";
9255: }
9256: if (document.getElementById('newsubdir')) {
9257: document.getElementById('newsubdir').innerHTML = "";
9258: }
9259: }
9260: document.getElementById('crsresform').style.display=disp;
9261: resize_scrollbox('contentscroll','1','0');
9262: }
9263: return;
9264: }
9265:
9266: function toggleNewsubdir(form) {
9267: if (form.newsubdir.length) {
9268: for (var j=0; j<form.newsubdir.length; j++) {
9269: if (form.newsubdir[j].checked) {
9270: if (document.getElementById('newsubdirname')) {
9271: if (form.newsubdir[j].value == '1') {
9272: document.getElementById('newsubdirname').type = "text";
9273: if (document.getElementById('newsubdir')) {
9274: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
9275: }
9276: } else {
9277: document.getElementById('newsubdirname').type = "hidden";
9278: document.getElementById('newsubdirname').value = "";
9279: document.getElementById('newsubdir').innerHTML = "";
9280: }
9281: }
9282: break;
9283: }
9284: }
9285: }
9286: }
9287:
9288: function toggleCrsResTitle() {
9289: if (document.getElementById('newresource')) {
1.691 raeburn 9290: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9291: if (selloc == 'course') {
1.606 raeburn 9292: document.getElementById('newresource').style.display = 'inline';
9293: document.courseresform.newresourceadd[0].checked = true;
9294: toggleNewInCourse(document.courseresform);
9295: } else {
9296: document.getElementById('newresource').style.display = 'none';
9297: }
1.689 raeburn 9298: }
9299: if (document.getElementById('newstdproblem')) {
9300: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
9301: document.getElementById('newstdproblem').style.display = 'none';
9302: if (document.getElementById('stdprobswitch')) {
9303: document.getElementById('stdprobswitch').style.display = 'block';
9304: }
9305: } else {
9306: document.getElementById('newstdproblem').style.display = 'block';
9307: if (document.getElementById('stdprobswitch')) {
9308: document.getElementById('stdprobswitch').style.display = 'none';
9309: }
9310: }
9311: }
1.606 raeburn 9312: }
9313:
9314: function toggleNewInCourse(form) {
9315: if (form.newresourceadd.length) {
9316: for (var i=0; i<form.newresourceadd.length; i++) {
9317: if (form.newresourceadd[i].checked) {
9318: if (document.getElementById('newresourcetitle')) {
9319: if (form.newresourceadd[i].value == '1') {
9320: document.getElementById('newresourcetitle').type = 'text';
9321: if (document.getElementById('newrestitle')) {
9322: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
9323: }
9324: } else {
9325: document.getElementById('newresourcetitle').type = 'hidden';
9326: document.getElementById('newresourcetitle').value = '';
9327: if (document.getElementById('newrestitle')) {
9328: document.getElementById('newrestitle').innerHTML = '';
9329: }
9330: }
9331: }
9332: break;
9333: }
9334: }
9335: }
9336: }
9337:
9338: function toggleWithTemplate(form) {
9339: if (form.newresusetemp.length) {
9340: for (var i=0; i<form.newresusetemp.length; i++) {
9341: if (form.newresusetemp[i].checked) {
9342: if (document.getElementById('newrestemplate')) {
9343: if (form.newresusetemp[i].value == '1') {
9344: document.getElementById('newrestemplate').style.display = 'inline';
9345: toggleExampleText();
9346: } else {
9347: form.tempcategory.selectedIndex = 0;
9348: select1template_changed();
9349: document.getElementById('newrestemplate').style.display = 'none';
9350: }
9351: }
9352: }
9353: }
9354: }
9355: }
9356:
9357: function toggleExampleText() {
9358: if (document.getElementById('newresexample')) {
9359: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9360: if (url == '') {
9361: document.getElementById('newresexample').style.fontWeight = 'normal';
9362: } else {
9363: document.getElementById('newresexample').style.fontWeight = 'bold';
9364: }
9365: }
9366: }
9367:
9368: function getExample(width,height,scrolling,transparency) {
9369: var url;
9370: if (document.courseresform.newresusetemp.length) {
9371: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
9372: if (document.courseresform.newresusetemp[i].checked) {
9373: if (document.courseresform.newresusetemp[i].value == '1') {
9374: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9375: if (url == '') {
9376: alert('Pick a category and template');
9377: } else {
9378: url = url.replace("$londocroot","");
9379: url += '?inhibitmenu=yes';
9380: }
9381: }
9382: break;
9383: }
9384: }
9385: }
9386: if (url != '') {
9387: openMyModal(url,width,height,scrolling,transparency,'');
9388: }
9389: }
9390:
1.690 raeburn 9391: function toggleImportCrsres(caller) {
1.606 raeburn 9392: var disp = 'none';
9393: if (document.getElementById('importcrsresform')) {
9394: if (caller == 'res') {
9395: var curr = document.getElementById('importcrsresform').style.display;
9396: if (curr == 'none') {
9397: disp='block';
1.698 raeburn 9398: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
9399: if ((document.getElementById('importcrsrescontent')) &&
9400: (document.getElementById('importcrsresempty'))) {
9401: var selelem = document.crsresimportform.elements['coursepath'];
9402: var numdirs = 0;
9403: if (selelem.options.length) {
9404: numdirs = selelem.options.length - 1;
9405: }
9406: if (numdirs) {
9407: document.getElementById('importcrsrescontent').style.display='block';
9408: document.getElementById('importcrsresempty').style.display='none';
9409: } else {
9410: document.getElementById('importcrsrescontent').style.display='none';
9411: document.getElementById('importcrsresempty').style.display='block';
9412: }
9413: }
1.606 raeburn 9414: }
9415: }
9416: document.getElementById('importcrsresform').style.display=disp;
1.706 raeburn 9417: if (disp == 'block') {
9418: if (document.getElementById('importmapform')) {
9419: if (document.getElementById('importmapform').style.display == 'block') {
9420: document.getElementById('importmapform').style.display = 'none';
9421: }
9422: }
9423: }
1.606 raeburn 9424: resize_scrollbox('contentscroll','1','0');
9425: }
9426: return;
9427: }
9428:
1.690 raeburn 9429: $showfile_js
9430:
1.691 raeburn 9431: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
9432: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
9433: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
9434: var selelem = form.elements[dirsel];
9435: var i, numfiles = selelem.options.length -1;
9436: if (numfiles >=0) {
9437: for (i = numfiles; i >= 0; i--) {
9438: selelem.remove(i);
9439: }
9440: }
9441: if ((location == '') || (location == null) || (location == 'undefined')) {
9442: if (selelem.options.length == 0) {
9443: selelem.options[selelem.options.length] = new Option('','');
9444: selelem.selectedIndex = 0;
9445: }
9446: if (document.getElementById('newstdproblem')) {
9447: document.getElementById('newstdproblem').style.display = 'none';
9448: }
9449: return;
9450: }
9451: var machineIds = new Array($machines_str);
9452: var athome = 0;
9453: var role = location;
9454: if ((location == 'author') || (location == 'course')) {
9455: if (document.getElementById('rolehome_'+location)) {
9456: var currhome = document.getElementById('rolehome_'+location).value;
9457: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9458: if (machineIds.includes(currhome)) {
9459: athome = 1;
9460: }
9461: }
9462: }
9463: } else {
9464: const roleinfo = location.split('___');
9465: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
9466: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
9467: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
9468: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9469: if (machineIds.includes(currhome)) {
9470: athome = 1;
9471: }
9472: }
9473: }
9474: }
1.706 raeburn 9475: var templateradio = document.courseresform.elements['newresusetemp'];
1.691 raeburn 9476: if (athome) {
9477: if (document.getElementById('stdprobswitch')) {
9478: document.getElementById('stdprobswitch').style.display = 'none';
9479: }
9480: if (document.getElementById('newstdproblem')) {
9481: document.getElementById('newstdproblem').style.display = 'none';
9482: }
1.706 raeburn 9483: var canedit = '$canedit';
9484: if (canedit) {
9485: if (templateradio.length > 1) {
9486: for (var i=0; i<templateradio.length; i++) {
9487: templateradio[i].disabled = false;
9488: }
9489: }
9490: document.courseresform.newresourcename.disabled = false;
9491: document.courseresform.newcrs.disabled = false;
9492: }
1.691 raeburn 9493: var http = new XMLHttpRequest();
9494: var url = "/adm/courseauthor";
1.698 raeburn 9495: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 9496: http.open("POST", url, true);
9497: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
9498: http.onreadystatechange = function() {
9499: if (http.readyState == 4 && http.status == 200) {
9500: var data = JSON.parse(http.responseText);
9501: if (Array.isArray(data.dirs)) {
9502: var len = data.dirs.length;
9503: if (len) {
9504: if (len > 1) {
9505: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
9506: }
9507: }
9508: if (len) {
9509: var j;
9510: for (j = 0; j < len; j++) {
9511: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
9512: }
9513: selelem.selectedIndex = 0;
1.697 raeburn 9514: if (len == 1) {
9515: toggleCrsResTitle();
9516: }
1.691 raeburn 9517: }
9518: }
9519: }
9520: }
9521: http.send(params);
9522: } else {
9523: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
9524: selelem.selectedIndex = 0;
9525: if (document.getElementById('stdprobswitch')) {
9526: document.getElementById('stdprobswitch').style.display = 'block';
9527: }
9528: if (document.getElementById('newstdproblem')) {
9529: document.getElementById('newstdproblem').style.display = 'none';
9530: }
1.706 raeburn 9531: if (templateradio.length > 1) {
9532: for (var i=0; i<templateradio.length; i++) {
9533: templateradio[i].disabled = true;
9534: }
9535: }
9536: document.courseresform.newresourcename.disabled = true;
9537: document.courseresform.newcrs.disabled = true;
1.691 raeburn 9538: }
9539: }
9540: return;
9541: }
9542:
1.689 raeburn 9543: function switchForProb() {
9544: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
9545: var url = '/adm/switchserver?otherserver=';
9546: var newhostid = '';
9547: var role = '';
9548: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9549: if (selloc == 'author') {
9550: newhostid = document.courseresform.rolehome_author.value;
9551: role = "au./&js_escape($env{'user.domain'})/";
9552: } else if (selloc == 'course') {
9553: newhostid = document.courseresform.rolehome_course.value;
9554: role = "&js_escape($env{'request.role'})";
9555: } else {
9556: var items = new Array();
9557: items = selloc.split('___');
9558: var len = document.courseresform.rolehome_coauthor.length;
9559: if (null == len) {
9560: var currval = document.courseresform.rolehome_coauthor.value;
9561: if (null != currval) {
9562: var info = new Array();
9563: info = currval.split('=');
9564: newhostid = info[2];
9565: role = info[0]+'./'+info[1];
9566: }
9567: } else {
9568: for (var i=0; i<len; i++) {
9569: var currval = document.courseresform.rolehome_coauthor[i].value;
9570: if (null != currval) {
9571: var info = new Array();
9572: info = currval.split('=');
9573: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
9574: newhostid = info[2];
9575: role = info[0]+'./'+info[1];
9576: break;
9577: }
9578: }
9579: }
9580: }
9581: }
9582: if (newhostid != '') {
9583: url += newhostid;
9584: if (role != '') {
9585: url += '&role='+role;
9586: }
9587: document.location.href = url;
9588: }
9589: }
9590: return;
9591: }
9592:
1.501 raeburn 9593: function makeims(imsform) {
9594: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 9595: alert("$js_lt{'imsfile'}");
1.501 raeburn 9596: return;
9597: }
9598: if (imsform.source.selectedIndex == 0) {
1.594 damieng 9599: alert("$js_lt{'imscms'}");
1.501 raeburn 9600: return;
9601: }
9602: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
9603: imsform.submit();
9604: }
9605:
1.478 raeburn 9606: function updatePick(targetform,index,caller) {
1.537 raeburn 9607: var pickitem;
9608: var picknumitem;
9609: var picknumtext;
9610: if (index == 'all') {
9611: pickitem = document.getElementById('randompickall');
9612: picknumitem = document.getElementById('rpicknumall');
9613: picknumtext = document.getElementById('rpicktextall');
9614: } else {
9615: pickitem = document.getElementById('randompick_'+index);
9616: picknumitem = document.getElementById('rpicknum_'+index);
9617: picknumtext = document.getElementById('randompicknum_'+index);
9618: }
1.478 raeburn 9619: if (pickitem.checked) {
1.594 damieng 9620: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 9621: if (picknum == '' || picknum == null) {
9622: if (caller == 'check') {
9623: pickitem.checked=false;
1.537 raeburn 9624: if (index == 'all') {
9625: picknumtext.innerHTML = '';
9626: if (caller == 'link') {
9627: propagateState(targetform,'rpicknum');
9628: }
9629: } else {
1.538 raeburn 9630: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9631: }
1.478 raeburn 9632: }
9633: } else {
9634: picknum.toString();
9635: var regexdigit=/^\\d+\$/;
9636: if (regexdigit.test(picknum)) {
9637: picknumitem.value = picknum;
1.537 raeburn 9638: if (index == 'all') {
1.538 raeburn 9639: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 9640: if (caller == 'link') {
9641: propagateState(targetform,'rpicknum');
9642: }
9643: } else {
9644: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 9645: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9646: }
1.478 raeburn 9647: } else {
9648: if (caller == 'check') {
1.537 raeburn 9649: if (index == 'all') {
9650: picknumtext.innerHTML = '';
9651: if (caller == 'link') {
9652: propagateState(targetform,'rpicknum');
9653: }
9654: } else {
9655: pickitem.checked=false;
1.538 raeburn 9656: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9657: }
1.478 raeburn 9658: }
9659: return;
9660: }
9661: }
9662: } else {
1.537 raeburn 9663: picknumitem.value = '';
9664: picknumtext.innerHTML = '';
9665: if (index == 'all') {
9666: if (caller == 'link') {
9667: propagateState(targetform,'rpicknum');
9668: }
9669: } else {
1.538 raeburn 9670: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9671: }
9672: }
9673: }
9674:
9675: function propagateState(form,param) {
9676: if (document.getElementById(param+'all')) {
9677: var setcheck = 0;
9678: var rpick = 0;
9679: if (param == 'rpicknum') {
9680: if (document.getElementById('randompickall')) {
9681: if (document.getElementById('randompickall').checked) {
9682: if (document.getElementById('rpicknumall')) {
9683: rpick = document.getElementById('rpicknumall').value;
9684: }
9685: }
9686: }
9687: } else {
9688: if (document.getElementById(param+'all').checked) {
9689: setcheck = 1;
9690: }
9691: }
1.538 raeburn 9692: var allidxlist;
9693: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9694: if (document.getElementById('all'+param+'idx')) {
9695: allidxlist = document.getElementById('all'+param+'idx').value;
9696: }
9697: var actions = new Array ('remove','cut','copy');
9698: for (var i=0; i<actions.length; i++) {
9699: if (actions[i] != param) {
9700: if (document.getElementById(actions[i]+'all')) {
9701: document.getElementById(actions[i]+'all').checked = false;
9702: }
9703: }
9704: }
9705: }
1.537 raeburn 9706: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 9707: allidxlist = form.allidx.value;
9708: }
9709: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
9710: allidxlist = form.allmapidx.value;
9711: }
9712: if ((allidxlist != '') && (allidxlist != null)) {
9713: var allidxs = allidxlist.split(',');
9714: if (allidxs.length > 1) {
9715: for (var i=0; i<allidxs.length; i++) {
9716: if (document.getElementById(param+'_'+allidxs[i])) {
9717: if (param == 'rpicknum') {
9718: if (document.getElementById('randompick_'+allidxs[i])) {
9719: if (document.getElementById('randompick_'+allidxs[i]).checked) {
9720: document.getElementById(param+'_'+allidxs[i]).value = rpick;
9721: if (rpick > 0) {
9722: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
9723: } else {
9724: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9725: }
9726: }
9727: }
9728: } else {
1.537 raeburn 9729: if (setcheck == 1) {
9730: document.getElementById(param+'_'+allidxs[i]).checked = true;
9731: } else {
9732: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 9733: if (param == 'randompick') {
9734: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9735: }
1.537 raeburn 9736: }
9737: }
9738: }
9739: }
1.538 raeburn 9740: if (setcheck == 1) {
9741: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9742: var actions = new Array('copy','cut','remove');
9743: for (var i=0; i<actions.length; i++) {
9744: var otheractions;
9745: var otheridxs;
9746: if (actions[i] === param) {
9747: continue;
9748: } else {
9749: if (document.getElementById('all'+actions[i]+'idx')) {
9750: otheractions = document.getElementById('all'+actions[i]+'idx').value;
9751: otheridxs = otheractions.split(',');
9752: if (otheridxs.length > 1) {
9753: for (var j=0; j<otheridxs.length; j++) {
9754: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
9755: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
9756: }
1.537 raeburn 9757: }
9758: }
9759: }
1.538 raeburn 9760: }
9761: }
9762: }
9763: }
9764: }
9765: }
9766: }
9767: return;
9768: }
9769:
1.603 raeburn 9770: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 9771: var canedit = '$canedit';
9772: if (canedit == '') {
9773: alert("$js_lt{'edri'}");
9774: return;
9775: }
1.539 raeburn 9776: var dosettings;
9777: var doaction;
1.538 raeburn 9778: var control = document.togglemultsettings;
9779: if (context == 'actions') {
9780: control = document.togglemultactions;
1.539 raeburn 9781: doaction = 1;
9782: } else {
9783: dosettings = 1;
1.538 raeburn 9784: }
1.539 raeburn 9785: if (control) {
9786: if (control.showmultpick.length) {
9787: for (var i=0; i<control.showmultpick.length; i++) {
9788: if (control.showmultpick[i].checked) {
9789: if (control.showmultpick[i].value == 1) {
9790: if (context == 'settings') {
9791: dosettings = 0;
9792: } else {
9793: doaction = 0;
1.538 raeburn 9794: }
9795: }
9796: }
1.537 raeburn 9797: }
9798: }
1.539 raeburn 9799: }
9800: if (context == 'settings') {
9801: if (dosettings == 1) {
1.538 raeburn 9802: targetform.changeparms.value=param;
9803: targetform.submit();
9804: }
1.537 raeburn 9805: }
1.539 raeburn 9806: if (context == 'actions') {
9807: if (doaction == 1) {
9808: targetform.cmd.value=param+'_'+index;
9809: targetform.folderpath.value=folderpath;
9810: targetform.markcopy.value=idx+':'+param;
9811: targetform.copyfolder.value=folder+'.'+container;
9812: if (param == 'remove') {
1.603 raeburn 9813: var doremove = 0;
9814: if (skip_confirm) {
9815: if (confirm_removal) {
9816: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
9817: doremove = 1;
9818: }
9819: } else {
9820: doremove = 1;
9821: }
9822: } else {
9823: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
9824: doremove = 1;
9825: }
9826: }
9827: if (doremove) {
1.539 raeburn 9828: targetform.markcopy.value='';
9829: targetform.copyfolder.value='';
9830: targetform.submit();
9831: }
9832: }
9833: if (param == 'cut') {
1.594 damieng 9834: 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 9835: targetform.submit();
9836: return;
9837: }
9838: }
9839: if (param == 'copy') {
9840: targetform.submit();
9841: return;
9842: }
9843: targetform.markcopy.value='';
9844: targetform.copyfolder.value='';
9845: targetform.cmd.value='';
9846: targetform.folderpath.value='';
9847: return;
9848: } else {
9849: if (document.getElementById(param+'_'+idx)) {
9850: item = document.getElementById(param+'_'+idx);
9851: if (item.type == 'checkbox') {
9852: if (item.checked) {
9853: item.checked = false;
9854: } else {
9855: item.checked = true;
9856: singleCheck(item,idx,param);
9857: }
9858: }
9859: }
9860: }
9861: }
1.537 raeburn 9862: return;
9863: }
9864:
1.538 raeburn 9865: function singleCheck(caller,idx,action) {
9866: actions = new Array('cut','copy','remove');
9867: if (caller.checked) {
9868: for (var i=0; i<actions.length; i++) {
9869: if (actions[i] != action) {
9870: if (document.getElementById(actions[i]+'_'+idx)) {
9871: if (document.getElementById(actions[i]+'_'+idx).checked) {
9872: document.getElementById(actions[i]+'_'+idx).checked = false;
9873: }
1.537 raeburn 9874: }
9875: }
9876: }
1.478 raeburn 9877: }
1.537 raeburn 9878: return;
1.478 raeburn 9879: }
9880:
1.334 muellerd 9881: function unselectInactive(nav) {
1.335 ehlerst 9882: currentNav = document.getElementById(nav);
9883: currentLis = currentNav.getElementsByTagName('LI');
9884: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 9885: if (currentLis[i].className == 'goback') {
9886: currentLis[i].className = 'goback';
9887: } else {
9888: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 9889: currentLis[i].className = 'right';
1.472 raeburn 9890: } else {
1.374 tempelho 9891: currentLis[i].className = 'i';
1.472 raeburn 9892: }
9893: }
1.335 ehlerst 9894: }
1.332 tempelho 9895: }
9896:
1.334 muellerd 9897: function hideAll(current, nav, data) {
1.335 ehlerst 9898: unselectInactive(nav);
1.570 raeburn 9899: if (current) {
9900: if (current.className == 'right'){
9901: current.className = 'right active'
9902: } else {
9903: current.className = 'active';
9904: }
1.374 tempelho 9905: }
1.335 ehlerst 9906: currentData = document.getElementById(data);
9907: currentDivs = currentData.getElementsByTagName('DIV');
9908: for (i = 0; i < currentDivs.length; i++) {
9909: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 9910: currentDivs[i].style.display = 'none';
1.330 tempelho 9911: }
9912: }
1.335 ehlerst 9913: }
1.330 tempelho 9914:
1.374 tempelho 9915: function openTabs(pageId) {
9916: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 9917: if(tabnav.length > 2 ){
1.389 tempelho 9918: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 9919: currentLis = currentNav.getElementsByTagName('LI');
9920: for(i = 0; i< currentLis.length; i++){
9921: if(currentLis[i].className == 'active') {
1.375 tempelho 9922: funcString = currentLis[i].onclick.toString();
9923: tab = funcString.split('"');
1.420 onken 9924: if(tab.length < 2) {
9925: tab = funcString.split("'");
9926: }
1.375 tempelho 9927: currentData = document.getElementById(tab[1]);
9928: currentData.style.display = 'block';
1.374 tempelho 9929: }
9930: }
9931: }
9932: }
9933:
1.334 muellerd 9934: function showPage(current, pageId, nav, data) {
1.570 raeburn 9935: currstate = current.className;
1.334 muellerd 9936: hideAll(current, nav, data);
1.375 tempelho 9937: openTabs(pageId);
1.334 muellerd 9938: unselectInactive(nav);
1.570 raeburn 9939: if ((currstate == 'active') || (currstate == 'right active')) {
9940: if (currstate == 'active') {
9941: current.className = '';
9942: } else {
9943: current.className = 'right';
9944: }
9945: activeTab = '';
1.656 raeburn 9946: toggleExternal();
1.570 raeburn 9947: toggleUpload();
9948: toggleMap();
1.606 raeburn 9949: toggleCrsRes();
9950: toggleImportCrsres();
1.570 raeburn 9951: resize_scrollbox('contentscroll','1','0');
9952: return;
9953: } else {
9954: current.className = 'active';
9955: }
1.330 tempelho 9956: currentData = document.getElementById(pageId);
9957: currentData.style.display = 'block';
1.458 raeburn 9958: activeTab = pageId;
1.656 raeburn 9959: toggleExternal();
1.501 raeburn 9960: toggleUpload();
1.503 raeburn 9961: toggleMap();
1.606 raeburn 9962: toggleCrsRes();
9963: toggleImportCrsres();
1.433 raeburn 9964: if (nav == 'mainnav') {
9965: var storedpath = "$docs_folderpath";
1.434 raeburn 9966: var storedpage = "$main_container_page";
1.433 raeburn 9967: var reg = new RegExp("^supplemental");
9968: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 9969: if (storedpage == 1) {
9970: document.simpleedit.folderpath.value = '';
9971: document.uploaddocument.folderpath.value = '';
9972: } else {
9973: if (reg.test(storedpath)) {
9974: document.simpleedit.folderpath.value = '$toplevelmain';
9975: document.uploaddocument.folderpath.value = '$toplevelmain';
9976: document.newext.folderpath.value = '$toplevelmain';
9977: } else {
9978: document.simpleedit.folderpath.value = storedpath;
9979: document.uploaddocument.folderpath.value = storedpath;
9980: document.newext.folderpath.value = storedpath;
9981: }
1.433 raeburn 9982: }
9983: } else {
1.434 raeburn 9984: if (reg.test(storedpath)) {
9985: document.simpleedit.folderpath.value = storedpath;
9986: document.supuploaddocument.folderpath.value = storedpath;
9987: document.supnewext.folderpath.value = storedpath;
9988: } else {
1.433 raeburn 9989: document.simpleedit.folderpath.value = '$toplevelsupp';
9990: document.supuploaddocument.folderpath.value = '$toplevelsupp';
9991: document.supnewext.folderpath.value = '$toplevelsupp';
9992: }
9993: }
9994: }
1.485 raeburn 9995: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 9996: return false;
9997: }
1.329 droeschl 9998:
1.472 raeburn 9999: function toContents(jumpto) {
10000: var newurl = '$backtourl';
1.525 raeburn 10001: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 10002: newurl = newurl+'?postdata='+jumpto;
10003: }
10004: location.href=newurl;
10005: }
10006:
1.538 raeburn 10007: function togglePick(caller,value) {
10008: var disp = 'none';
10009: if (document.getElementById('multi'+caller)) {
10010: var curr = document.getElementById('multi'+caller).style.display;
10011: if (value == 1) {
10012: disp='block';
10013: }
10014: if (curr == disp) {
10015: return;
10016: }
10017: document.getElementById('multi'+caller).style.display=disp;
10018: if (value == 1) {
1.594 damieng 10019: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 10020: } else {
10021: document.getElementById('more'+caller).innerHTML = '';
10022: }
10023: if (caller == 'actions') {
10024: setClass(value);
10025: setBoxes(value);
10026: }
10027: }
10028: var showButton = multiSettings();
10029: if (showButton != 1) {
10030: showButton = multiActions();
10031: }
10032: if (document.getElementById('multisave')) {
10033: if (showButton == 1) {
10034: document.getElementById('multisave').style.display='block';
10035: } else {
10036: document.getElementById('multisave').style.display='none';
10037: }
10038: }
10039: resize_scrollbox('contentscroll','1','1');
10040: return;
10041: }
10042:
10043: function toggleCheckUncheck(caller,more) {
10044: if (more == 1) {
1.594 damieng 10045: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 10046: document.getElementById('allfields'+caller).style.display='block';
10047: } else {
1.594 damieng 10048: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 10049: document.getElementById('allfields'+caller).style.display='none';
10050: }
10051: resize_scrollbox('contentscroll','1','1');
10052: }
10053:
10054: function multiSettings() {
10055: var inuse = 0;
10056: var settingsform = document.togglemultsettings;
10057: if (settingsform.showmultpick.length > 1) {
10058: for (var i=0; i<settingsform.showmultpick.length; i++) {
10059: if (settingsform.showmultpick[i].checked) {
10060: if (settingsform.showmultpick[i].value == 1) {
10061: inuse = 1;
10062: }
10063: }
10064: }
10065: }
10066: return inuse;
10067: }
10068:
10069: function multiActions() {
10070: var inuse = 0;
10071: var actionsform = document.togglemultactions;
10072: if (actionsform.showmultpick.length > 1) {
10073: for (var i=0; i<actionsform.showmultpick.length; i++) {
10074: if (actionsform.showmultpick[i].checked) {
10075: if (actionsform.showmultpick[i].value == 1) {
10076: inuse = 1;
10077: }
10078: }
10079: }
10080: }
10081: return inuse;
10082: }
10083:
10084: function checkSubmits() {
10085: var numchanges = 0;
10086: var form = document.saveactions;
10087: var doactions = multiActions();
1.542 raeburn 10088: var cutwarnings = 0;
10089: var remwarnings = 0;
1.603 raeburn 10090: var removalinfo = 0;
1.538 raeburn 10091: if (doactions == 1) {
10092: var remidxlist = document.cumulativeactions.allremoveidx.value;
10093: if ((remidxlist != '') && (remidxlist != null)) {
10094: var remidxs = remidxlist.split(',');
10095: for (var i=0; i<remidxs.length; i++) {
10096: if (document.getElementById('remove_'+remidxs[i])) {
10097: if (document.getElementById('remove_'+remidxs[i]).checked) {
10098: form.multiremove.value += remidxs[i]+',';
10099: numchanges ++;
1.542 raeburn 10100: if (document.getElementById('skip_remove_'+remidxs[i])) {
10101: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
10102: remwarnings ++;
10103: }
10104: }
1.603 raeburn 10105: if (document.getElementById('confirm_removal_'+remidxs[i])) {
10106: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
10107: removalinfo ++;
10108: }
10109: }
1.537 raeburn 10110: }
10111: }
1.538 raeburn 10112: }
10113: }
10114: var cutidxlist = document.cumulativeactions.allcutidx.value;
10115: if ((cutidxlist != '') && (cutidxlist != null)) {
10116: var cutidxs = cutidxlist.split(',');
10117: for (var i=0; i<cutidxs.length; i++) {
10118: if (document.getElementById('cut_'+cutidxs[i])) {
10119: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
10120: form.multicut.value += cutidxs[i]+',';
10121: numchanges ++;
1.542 raeburn 10122: if (document.getElementById('skip_cut_'+cutidxs[i])) {
10123: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
10124: cutwarnings ++;
10125: }
10126: }
1.537 raeburn 10127: }
10128: }
10129: }
10130: }
1.538 raeburn 10131: var copyidxlist = document.cumulativeactions.allcopyidx.value;
10132: if ((copyidxlist != '') && (copyidxlist != null)) {
10133: var copyidxs = copyidxlist.split(',');
10134: for (var i=0; i<copyidxs.length; i++) {
10135: if (document.getElementById('copy_'+copyidxs[i])) {
10136: if (document.getElementById('copy_'+copyidxs[i]).checked) {
10137: form.multicopy.value += copyidxs[i]+',';
10138: numchanges ++;
10139: }
10140: }
10141: }
10142: }
10143: if (numchanges > 0) {
10144: form.multichange.value = numchanges;
10145: }
1.537 raeburn 10146: }
1.538 raeburn 10147: var dosettings = multiSettings();
1.543 raeburn 10148: var haschanges = 0;
1.538 raeburn 10149: if (dosettings == 1) {
10150: form.allencrypturl.value = '';
10151: form.allhiddenresource.value = '';
1.543 raeburn 10152: form.changeparms.value = 'all';
10153: var patt=new RegExp(",\$");
1.538 raeburn 10154: var allidxlist = document.cumulativesettings.allidx.value;
10155: if ((allidxlist != '') && (allidxlist != null)) {
10156: var allidxs = allidxlist.split(',');
10157: if (allidxs.length > 1) {
10158: for (var i=0; i<allidxs.length; i++) {
10159: if (document.getElementById('hiddenresource_'+allidxs[i])) {
10160: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
10161: form.allhiddenresource.value += allidxs[i]+',';
10162: }
10163: }
10164: if (document.getElementById('encrypturl_'+allidxs[i])) {
10165: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
10166: form.allencrypturl.value += allidxs[i]+',';
10167: }
10168: }
10169: }
1.543 raeburn 10170: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
10171: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 10172: }
1.538 raeburn 10173: }
10174: form.allrandompick.value = '';
10175: form.allrandomorder.value = '';
10176: var allmapidxlist = document.cumulativesettings.allmapidx.value;
10177: if ((allmapidxlist != '') && (allmapidxlist != null)) {
10178: var allmapidxs = allmapidxlist.split(',');
10179: for (var i=0; i<allmapidxs.length; i++) {
10180: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
10181: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
10182: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
10183: if ((randompick.checked) && (rpicknum.value != '')) {
10184: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
10185: }
10186: if (randorder.checked) {
10187: form.allrandomorder.value += allmapidxs[i]+',';
10188: }
1.537 raeburn 10189: }
1.543 raeburn 10190: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
10191: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
10192: }
10193: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
10194: haschanges = 1;
10195: }
10196: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
10197: haschanges = 1;
10198: }
10199: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
10200: haschanges = 1;
10201: }
10202: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
10203: haschanges = 1;
1.537 raeburn 10204: }
10205: }
1.543 raeburn 10206: if (doactions == 1) {
1.542 raeburn 10207: if (numchanges > 0) {
1.603 raeburn 10208: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 10209: if (remwarnings > 0) {
1.594 damieng 10210: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 10211: return false;
10212: }
10213: }
1.603 raeburn 10214: if (removalinfo > 0) {
10215: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
10216: return false;
10217: }
10218: }
1.542 raeburn 10219: if (cutwarnings > 0) {
1.594 damieng 10220: 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 10221: return false;
10222: }
10223: }
10224: }
10225: form.submit();
10226: return true;
1.543 raeburn 10227: }
10228: }
10229: if (dosettings == 1) {
10230: if (haschanges == 1) {
1.542 raeburn 10231: form.submit();
10232: return true;
10233: }
1.543 raeburn 10234: }
10235: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 10236: alert("$js_lt{'noor'}");
1.543 raeburn 10237: } else {
10238: if (dosettings == 1) {
1.594 damieng 10239: alert("$js_lt{'noch'}");
1.543 raeburn 10240: } else {
1.594 damieng 10241: alert("$js_lt{'noac'}");
1.543 raeburn 10242: }
10243: }
1.538 raeburn 10244: return false;
10245: }
10246:
10247: function setClass(value) {
10248: var cutclass = 'LC_docs_cut';
10249: var copyclass = 'LC_docs_copy';
10250: var removeclass = 'LC_docs_remove';
10251: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
10252: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
10253: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
10254: var links = document.getElementsByTagName('a');
10255: for (var i=0; i<links.length; i++) {
10256: var classes = links[i].className;
10257: if (cutreg.test(classes)) {
10258: links[i].className = cutclass;
10259: if (value == 1) {
10260: links[i].className += " LC_menubuttons_link";
10261: }
10262: } else {
10263: if (copyreg.test(classes)) {
10264: links[i].className = copyclass;
10265: if (value == 1) {
10266: links[i].className += " LC_menubuttons_link";
10267: }
10268: } else {
10269: if (removereg.test(classes)) {
10270: links[i].className = removeclass;
10271: if (value == 1) {
10272: links[i].className += " LC_menubuttons_link";
10273: }
10274: }
10275: }
10276: }
10277: }
10278: return;
1.537 raeburn 10279: }
10280:
1.538 raeburn 10281: function setBoxes(value) {
10282: var remidxlist = document.cumulativeactions.allremoveidx.value;
10283: if ((remidxlist != '') && (remidxlist != null)) {
10284: var remidxs = remidxlist.split(',');
10285: for (var i=0; i<remidxs.length; i++) {
10286: if (document.getElementById('remove_'+remidxs[i])) {
10287: var item = document.getElementById('remove_'+remidxs[i]);
10288: if (value == 1) {
10289: item.className = 'LC_docs_remove';
10290: } else {
10291: item.className = 'LC_hidden';
10292: }
10293: }
10294: }
10295: }
10296: var cutidxlist = document.cumulativeactions.allcutidx.value;
10297: if ((cutidxlist != '') && (cutidxlist != null)) {
10298: var cutidxs = cutidxlist.split(',');
10299: for (var i=0; i<cutidxs.length; i++) {
10300: if (document.getElementById('cut_'+cutidxs[i])) {
10301: var item = document.getElementById('cut_'+cutidxs[i]);
10302: if (value == 1) {
10303: item.className = 'LC_docs_cut';
10304: } else {
10305: item.className = 'LC_hidden';
10306: }
10307: }
1.537 raeburn 10308: }
10309: }
1.538 raeburn 10310: var copyidxlist = document.cumulativeactions.allcopyidx.value;
10311: if ((copyidxlist != '') && (copyidxlist != null)) {
10312: var copyidxs = copyidxlist.split(',');
10313: for (var i=0; i<copyidxs.length; i++) {
10314: if (document.getElementById('copy_'+copyidxs[i])) {
10315: var item = document.getElementById('copy_'+copyidxs[i]);
10316: if (value == 1) {
10317: item.className = 'LC_docs_copy';
10318: } else {
10319: item.className = 'LC_hidden';
10320: }
10321: }
1.537 raeburn 10322: }
10323: }
10324: return;
10325: }
10326:
1.606 raeburn 10327: function validImportCrsRes() {
10328: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
10329: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
10330: if ((fname == '') || (fname == null)) {
10331: alert("$js_lt{'nofi'}");
10332: return false;
10333: }
10334: var url = '/res/$coursedom/$coursenum/';
10335: if (path && path != '/') {
10336: url += path+'/';
10337: }
10338: if (fname != '') {
10339: url += fname;
10340: }
10341: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 10342: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 10343: return true;
10344: }
10345:
10346: function validateNewRes(caller) {
10347: if (caller == 'single') {
10348: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
10349: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
10350: var resname = document.courseresform.newresourcename.value;
10351: }
10352: }
10353:
1.611 raeburn 10354: ENDSCRIPT
1.329 droeschl 10355: }
1.457 raeburn 10356:
1.483 raeburn 10357: sub history_tab_js {
10358: return <<"ENDHIST";
10359: function toggleHistoryDisp(choice) {
10360: document.docslogform.docslog.value = choice;
10361: document.docslogform.submit();
10362: return;
10363: }
10364:
10365: ENDHIST
10366: }
10367:
1.484 raeburn 10368: sub inject_data_js {
10369: return <<ENDINJECT;
10370:
10371: function injectData(current, hiddenField, name, value) {
10372: currentElement = document.getElementById(hiddenField);
10373: currentElement.name = name;
10374: currentElement.value = value;
10375: current.submit();
10376: }
10377:
10378: ENDINJECT
10379: }
10380:
10381: sub dump_switchserver_js {
10382: my @hosts = @_;
1.594 damieng 10383: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 10384: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 10385: swit => 'Switch server?',
1.594 damieng 10386: );
10387: my %html_js_lt = &Apache::lonlocal::texthash(
10388: swit => 'Switch server?',
1.709 raeburn 10389: duco => 'Copying uploaded content to Authoring Space',
1.484 raeburn 10390: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
10391: chos => 'Choose server',
10392: );
1.594 damieng 10393: &js_escape(\%js_lt);
10394: &html_escape(\%html_js_lt);
10395: &js_escape(\%html_js_lt);
1.484 raeburn 10396: my $role = $env{'request.role'};
10397: my $js = <<"ENDSWJS";
10398: <script type="text/javascript">
10399: function write_switchserver() {
10400: var server;
10401: if (document.setserver.posshosts.length > 0) {
10402: for (var i=0; i<document.setserver.posshosts.length; i++) {
10403: if (document.setserver.posshosts[i].checked) {
10404: server = document.setserver.posshosts[i].value;
10405: }
10406: }
10407: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
10408: }
10409: window.close();
10410: }
10411: </script>
10412:
10413: ENDSWJS
10414:
10415: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
10416: {'only_body' => 1,
10417: 'js_ready' => 1,});
10418: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
10419:
10420: my $hostpicker;
10421: my $count = 0;
10422: foreach my $host (sort(@hosts)) {
10423: my $checked;
10424: if ($count == 0) {
10425: $checked = ' checked="checked"';
10426: }
10427: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
10428: $host.'"'.$checked.' />'.$host.'</label> ';
10429: $count++;
10430: }
10431:
10432: return <<"ENDSWITCHJS";
10433:
10434: function dump_needs_switchserver(url) {
10435: if (url!='' && url!= null) {
1.594 damieng 10436: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 10437: go(url);
10438: }
10439: }
10440: return;
10441: }
10442:
10443: function choose_switchserver_window() {
10444: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
10445: newWindow.document.open();
10446: newWindow.document.writeln('$startpage');
1.594 damieng 10447: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
10448: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
10449: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 10450: '<form name="setserver" method="post" action="" \\/>\\n'+
10451: '$hostpicker\\n'+
10452: '<br \\/><br \\/>\\n'+
1.594 damieng 10453: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 10454: 'onclick="write_switchserver();" \\/>\\n'+
10455: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
10456: newWindow.document.writeln('$endpage');
10457: newWindow.document.close();
10458: newWindow.focus();
10459: }
10460:
10461: ENDSWITCHJS
10462: }
10463:
10464: sub makedocslogform {
10465: my ($formelems,$docslog) = @_;
10466: return <<"LOGSFORM";
10467: <form action="/adm/coursedocs" method="post" name="docslogform">
10468: <input type="hidden" name="docslog" value="$docslog" />
10469: $formelems
10470: </form>
10471: LOGSFORM
10472: }
10473:
10474: sub makesimpleeditform {
10475: my ($formelems) = @_;
10476: return <<"SIMPFORM";
10477: <form name="simpleedit" method="post" action="/adm/coursedocs">
10478: <input type="hidden" name="importdetail" value="" />
10479: $formelems
10480: </form>
10481: SIMPFORM
10482: }
10483:
1.606 raeburn 10484: sub makenewproblem {
10485: my ($r,$coursedom,$coursenum) = @_;
10486: # Creating a new problem
10487: my ($redirect,$error);
10488: if ($env{'form.authorrole'}) {
10489: my ($newsubdir,$filename);
10490: if ($env{'form.newsubdir'}) {
10491: if ($env{'form.newsubdirname'} ne '') {
10492: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 10493: }
1.606 raeburn 10494: }
10495: if ($env{'form.newresourcename'}) {
10496: $filename = $env{'form.newresourcename'};
10497: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
10498: $filename =~ s/`//g;
10499: $filename =~ s{/\.\./}{_}g;
10500: $filename =~ s/\.+/./g;
10501: $filename =~ s{/+}{_}g;
10502: if ($filename ne '') {
10503: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
10504: if (($ext) && ($ext ne '.problem')) {
10505: $filename = $name.'.problem';
10506: } elsif ($ext eq '') {
10507: $filename .= '.problem';
10508: }
10509: my $docroot = $r->dir_config('lonDocRoot');
10510: my @ids=&Apache::lonnet::current_machine_ids();
10511: if ($env{'form.authorrole'} eq 'author') {
10512: if ($env{'user.author'}) {
10513: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
10514: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
10515: my $path = $docroot.$url;
10516: my $subdir = $env{'form.authorpath'};
10517: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10518: }
10519: }
10520: } elsif ($env{'form.authorrole'} eq 'course') {
10521: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
10522: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
10523: my $url = "/priv/$coursedom/$coursenum";
10524: my $path=$docroot.$url;
10525: my $subdir = $env{'form.authorpath'};
10526: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10527: if ($redirect) {
10528: my $rightsfile = 'default.rights';
10529: my $sourcerights = "$path/$rightsfile";
1.709 raeburn 10530: &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom);
1.606 raeburn 10531: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
1.654 raeburn 10532: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
10533: if (!-e "$docroot/res/$coursedom") {
10534: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 10535: }
1.654 raeburn 10536: if (!-e "$docroot/res/$coursedom/$coursenum") {
10537: mkdir("$docroot/res/$coursedom/$coursenum",0755);
10538: }
10539: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
10540: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
10541: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 10542: }
10543: }
1.654 raeburn 10544: my $source = $docroot.$redirect;
10545: if (!-e "$source.meta") {
10546: my $cid = $coursedom.'_'.$coursenum;
10547: my $now = time;
10548: if (open(my $fh,">$source.meta")) {
10549: my $author=$env{'environment.firstname'}.' '.
10550: $env{'environment.middlename'}.' '.
10551: $env{'environment.lastname'}.' '.
10552: $env{'environment.generation'};
10553: $author =~ s/\s+$//;
10554: my $title = $env{'form.newresourcetitle'};
10555: $title =~ s/^\s+|\s+$//g;
10556: print $fh <<END;
1.606 raeburn 10557:
10558: <abstract></abstract>
10559: <author>$author</author>
10560: <authorspace>$coursenum:$coursedom</authorspace>
10561: <copyright>custom</copyright>
10562: <creationdate>$now</creationdate>
10563: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
10564: <dependencies></dependencies>
10565: <domain>$coursedom</domain>
10566: <highestgradelevel>0</highestgradelevel>
10567: <keywords></keywords>
10568: <language>notset </language>
10569: <lastrevisiondate>$now</lastrevisiondate>
10570: <lowestgradelevel>0</lowestgradelevel>
10571: <mime>problem</mime>
10572: <modifyinguser>$coursenum:$coursedom</modifyinguser>
10573: <notes></notes>
10574: <obsolete></obsolete>
10575: <obsoletereplacement></obsoletereplacement>
10576: <owner>$coursenum:$coursedom</owner>
10577: <sourceavail></sourceavail>
10578: <standards></standards>
10579: <subject></subject>
10580: <title>$title</title>
10581: END
1.654 raeburn 10582: close($fh);
1.606 raeburn 10583: }
10584: }
10585: }
10586: }
10587: } else {
10588: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
10589: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
10590: if (grep(/^\Q$rolehome\E$/,@ids)) {
10591: my $now = time;
10592: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
10593: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
10594: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
10595: my $url = "/priv/$audom/$auname";
10596: my $path = $r->dir_config('lonDocRoot').$url;
10597: my $subdir = $env{'form.authorpath'};
10598: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10599: }
10600: }
10601: }
10602: }
10603: }
10604: }
10605: }
10606: return ($redirect,$error);
10607: }
10608:
10609: sub finishnewprob {
1.654 raeburn 10610: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 10611: unless (-d $path) {
10612: unless (mkdir($path,02770)) {
10613: return;
10614: }
10615: }
1.606 raeburn 10616: my $redirect;
10617: if ($subdir ne '/') {
10618: $subdir = &cleandir($subdir);
10619: if (($subdir ne '') && (-d "$path/$subdir")) {
10620: $path .= "/$subdir";
10621: $url .= "/$subdir";
10622: }
10623: }
10624: my $dest;
10625: if ($newsubdir ne '') {
10626: $newsubdir = &cleandir($newsubdir);
10627: }
10628: if ($newsubdir ne '') {
10629: if (-d "$path/$newsubdir") {
10630: $dest = "$path/$newsubdir/$filename";
10631: } else {
10632: my $dirok;
10633: unless (-e "$path/$newsubdir") {
10634: if (mkdir("$path/$newsubdir",02770)) {
10635: if (chmod(02770,"$path/$newsubdir")) {
10636: $dirok = 1;
10637: }
10638: }
10639: }
10640: if ($dirok) {
10641: $dest = "$path/$newsubdir/$filename";
10642: }
10643: }
10644: if (($dest ne '') && (!-e $dest)) {
10645: $redirect = "$url/$newsubdir/$filename";
10646: }
10647: } else {
10648: $dest = "$path/$filename";
10649: if (($dest ne '') && (!-e $dest)) {
10650: $redirect = "$url/$filename";
10651: }
10652: }
1.654 raeburn 10653: if ((!-e $dest) && ($context ne 'upload')) {
10654: my $template = $env{'form.template'};
10655: my $copyfrom;
10656: if ($template ne '') {
10657: my %templates;
10658: my @files = &Apache::lonhomework::get_template_list('problem');
10659: foreach my $poss (@files) {
10660: if (ref($poss) eq 'ARRAY') {
10661: if ($template eq $poss->[0]) {
10662: $templates{$template} = 1;
10663: last;
10664: }
10665: }
10666: }
10667: if ($templates{$template}) {
10668: $copyfrom = $template;
10669: }
10670: }
10671: if ($filename =~ /\.problem$/) {
10672: unless ($copyfrom) {
10673: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
10674: }
10675: &File::Copy::copy($copyfrom,$dest);
10676: }
10677: }
1.606 raeburn 10678: return $redirect;
10679: }
10680:
10681: sub cleandir {
10682: my ($dir) = @_;
10683: $dir =~ s/^\s+//;
10684: $dir =~ s/\s+$//;
10685: $dir =~ s/\.+//g;
10686: $dir =~ s/[\#\?&%\":]//g;
10687: return $dir;
10688: }
10689:
1.329 droeschl 10690: 1;
10691: __END__
10692:
10693:
10694: =head1 NAME
10695:
10696: Apache::londocs.pm
10697:
10698: =head1 SYNOPSIS
10699:
10700: This is part of the LearningOnline Network with CAPA project
10701: described at http://www.lon-capa.org.
10702:
10703: =head1 SUBROUTINES
10704:
10705: =over
10706:
10707: =item %help=()
10708:
10709: Available help topics
10710:
10711: =item mapread()
10712:
1.344 bisitz 10713: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 10714: @order and @resources, determines status
10715: sets @order - pointer to resources in right order
10716: sets @resources - array with the resources with correct idx
10717:
10718: =item authorhosts()
10719:
10720: Return hash with valid author names
10721:
10722: =item clean()
10723:
10724: =item dumpcourse()
10725:
10726: Actually dump course
10727:
10728: =item group_import()
10729:
10730: Imports the given (name, url) resources into the course
10731: coursenum, coursedom, and folder must precede the list
10732:
10733: =item breadcrumbs()
10734:
10735: =item log_docs()
10736:
10737: =item docs_change_log()
10738:
10739: =item update_paste_buffer()
10740:
10741: =item print_paste_buffer()
10742:
10743: =item do_paste_from_buffer()
10744:
1.538 raeburn 10745: =item do_buffer_empty()
10746:
10747: =item clear_from_buffer()
10748:
1.492 raeburn 10749: =item get_newmap_url()
10750:
10751: =item dbcopy()
10752:
10753: =item uniqueness_check()
10754:
10755: =item contained_map_check()
10756:
10757: =item url_paste_fixups()
10758:
10759: =item apply_fixups()
10760:
10761: =item copy_dependencies()
10762:
1.329 droeschl 10763: =item update_parameter()
10764:
10765: =item handle_edit_cmd()
10766:
10767: =item editor()
10768:
10769: =item process_file_upload()
10770:
10771: =item process_secondary_uploads()
10772:
10773: =item is_supplemental_title()
10774:
10775: =item entryline()
10776:
10777: =item tiehash()
10778:
10779: =item untiehash()
10780:
10781: =item checkonthis()
10782:
10783: check on this
10784:
10785: =item verifycontent()
10786:
10787: Verify Content
10788:
1.636 raeburn 10789: =item devalidateversioncache()
10790:
10791: =item checkversions()
1.329 droeschl 10792:
10793: Check Versions
10794:
10795: =item mark_hash_old()
10796:
10797: =item is_hash_old()
10798:
10799: =item changewarning()
10800:
10801: =item init_breadcrumbs()
10802:
10803: Breadcrumbs for special functions
10804:
1.484 raeburn 10805: =item create_list_elements()
10806:
10807: =item create_form_ul()
10808:
10809: =item startContentScreen()
10810:
10811: =item endContentScreen()
10812:
10813: =item supplemental_base()
10814:
10815: =item embedded_form_elems()
10816:
10817: =item embedded_destination()
10818:
10819: =item return_to_editor()
10820:
10821: =item decompression_info()
10822:
10823: =item decompression_phase_one()
10824:
10825: =item decompression_phase_two()
10826:
10827: =item remove_archive()
10828:
10829: =item generate_admin_menu()
10830:
10831: =item generate_edit_table()
10832:
10833: =item editing_js()
10834:
10835: =item history_tab_js()
10836:
10837: =item inject_data_js()
10838:
10839: =item dump_switchserver_js()
10840:
1.485 raeburn 10841: =item resize_scrollbox_js()
1.484 raeburn 10842:
10843: =item makedocslogform()
10844:
1.485 raeburn 10845: =item makesimpleeditform()
10846:
1.329 droeschl 10847: =back
10848:
10849: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>