Annotation of loncom/interface/londocs.pm, revision 1.720
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.720 ! raeburn 4: # $Id: londocs.pm,v 1.719 2025/01/07 01:25: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.719 raeburn 887: my ($notopdir,%newdir,%newfile,%checkdeps,%newresfile);
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)) {
1.719 raeburn 1029: $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
1.717 raeburn 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.719 raeburn 1058: if (-e $destresfile) {
1059: $newresfile{$file} = $destresurl.'/'.$subdir.'/'.$file;
1060: }
1.714 raeburn 1061: }
1.712 raeburn 1062: }
1.717 raeburn 1063: } else {
1064: $needpriv = 1;
1065: if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
1066: $needprivmeta = 1;
1067: }
1068: }
1069: if ($needpriv) {
1070: if (&File::Copy::copy($src,$dest)) {
1.719 raeburn 1071: $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
1.717 raeburn 1072: if ($embstyle eq 'ssi') {
1073: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
1074: }
1075: }
1076: }
1077: if ($needprivmeta) {
1078: if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
1079: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
1080: $customdistfile,$sourceavail,\%checkdeps);
1081: }
1.714 raeburn 1082: }
1.717 raeburn 1083: } else {
1084: my ($needpriv,$needprivmeta);
1085: if ($respublish) {
1086: if ($getres) {
1087: &Apache::lonnet::repcopy($docroot.$resurl.'/'.$file);
1088: }
1089: if ($getresmeta) {
1090: &Apache::lonnet::repcopy($docroot.$resurl.'/'.$file.'.meta');
1091: }
1092: if (-e $docroot.$resurl.'/'.$file) {
1093: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
1094: if (&Apache::londiff::are_different_files($docroot.$resurl.'/'.$file,$dest)) {
1095: $needpriv = 1;
1096: if (&File::Copy::copy($docroot.$resurl.'/'.$file,$dest)) {
1097: if ($embstyle eq 'ssi') {
1098: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd);
1.713 raeburn 1099: }
1.714 raeburn 1100: }
1.717 raeburn 1101: } else {
1102: if ($embstyle eq 'ssi') {
1103: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
1.714 raeburn 1104: }
1.719 raeburn 1105: $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
1.717 raeburn 1106: }
1107: }
1108: } else {
1109: $needpriv = 1;
1110: }
1111: if (-e $docroot.$resurl.'/'.$file.'.meta') {
1112: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
1113: if (&Apache::londiff::are_different_files($docroot.$resurl.'/'.$file.'.meta',$dest.'.meta')) {
1114: $needprivmeta = 1;
1115: if (&File::Copy::copy($docroot.$resurl.'/'.$file.'.meta',$dest.'.meta')) {
1116: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
1117: $customdistfile,$sourceavail,\%checkdeps);
1.713 raeburn 1118: }
1.714 raeburn 1119: } else {
1.717 raeburn 1120: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
1121: $customdistfile,$sourceavail,\%checkdeps);
1.713 raeburn 1122: }
1123: }
1.717 raeburn 1124: } else {
1125: if (!-e $dest.'.meta') {
1126: $needprivmeta = 1;
1127: }
1.714 raeburn 1128: }
1.717 raeburn 1129: if ($getres) {
1130: my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file;
1131: if (-e $dest) {
1132: my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
1.719 raeburn 1133: if (-e $destresfile) {
1134: $newresfile{$file} = $destresurl.'/'.$subdir.'/'.$file;
1135: }
1.713 raeburn 1136: }
1.712 raeburn 1137: }
1.717 raeburn 1138: } else {
1139: $needpriv = 1;
1140: if (!-e $dest.'.meta') {
1141: $needprivmeta = 1;
1142: }
1.712 raeburn 1143: }
1.717 raeburn 1144: if ($needpriv) {
1145: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
1146: if ($embstyle eq 'ssi') {
1147: &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
1.715 raeburn 1148: }
1.719 raeburn 1149: $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
1.717 raeburn 1150: }
1151: }
1152: if ($needprivmeta) {
1153: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
1154: &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
1155: $customdistfile,$sourceavail,\%checkdeps);
1.715 raeburn 1156: }
1157: }
1.712 raeburn 1158: }
1159: }
1160: }
1.714 raeburn 1161: } else {
1162: $notopdir = 1;
1.712 raeburn 1163: }
1164: }
1165: if ($notopdir) {
1166: $r->print('<p><span class="LC_info">'.&mt('No files or sub-directories copied').'</span><br />'."\n".
1167: '<span class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
1168: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1169: '</span></p>'."\n");
1170: }
1171: if (keys(%newdir)) {
1172: $r->print('<p>'.&mt('Created the following directories in [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1173: '</p>'."\n".
1174: '<ul><li>'.join('</li><li>',sort(keys(%newdir))).'</li></ul></p>'."\n");
1175: }
1176: if (keys(%newfile)) {
1177: $r->print('<p>'.&mt('Copied the following files to [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1178: '</p>'."\n".
1179: '<ul><li>'.join('</li><li>',sort(keys(%newfile))).'</li></ul></p>'."\n");
1.719 raeburn 1180: foreach my $key (keys(%newfile)) {
1181: my %storehash = (
1182: 'priv' => $newfile{$key},
1183: 'who' => $env{'user.name'}.':'.$env{'user.domain'},
1184: );
1185: if (exists($newresfile{$file})) {
1186: $storehash{'res'} = 1;
1187: }
1188: &Apache::lonnet::store_userdata(\%storehash,$file,'copycourseauthor',$coursedom,$coursenum);
1189: }
1.712 raeburn 1190: }
1.713 raeburn 1191: if (keys(%checkdeps)) {
1192: my %missingdep;
1193: foreach my $depfile (sort(keys(%checkdeps))) {
1194: unless (-e "$desttop/$depfile") {
1195: $missingdep{$depfile} = 1;
1196: }
1197: }
1198: if (keys(%missingdep)) {
1199: $r->print('<p>'.&mt('You may also need to copy the following missing dependencies for files copied to [_1]:',
1200: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1201: '</p>'."\n".
1202: '<ul><li>'.join('</li><li>',sort(keys(%missingdep))).'</li></ul></p>'."\n");
1203: }
1204: }
1.712 raeburn 1205: } else {
1206: $r->print('<p>'.&mt('No currently existing files or directories in Course Authoring Space selected for copying').'</p>');
1207: $r->print(&endContentScreen());
1208: return '';
1209: }
1210: } else {
1211: my $chkname = 'copytouser';
1212: my $context = 'crsauthored';
1213: my (%subdirs,%files,@dirs_by_depth,@files_by_depth,%parent,%children,%hierarchy,@checked_maps);
1.714 raeburn 1214: &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files,1);
1.712 raeburn 1215: foreach my $key (keys(%subdirs)) {
1216: next if (($key eq '/') || ($key eq ''));
1217: my @items = split(/\//,$key);
1218: my $dir = pop(@items);
1219: my $depth = scalar(@items);
1220: my $path;
1221: if (!$depth) {
1222: $path = '/';
1223: } else {
1224: $path = join('/',@items);
1225: }
1226: $dirs_by_depth[$depth]{$path}{$dir} = 1;
1227: }
1228: foreach my $path (keys(%files)) {
1229: next if ($path eq '');
1230: my $depth;
1231: if ($path eq '/') {
1232: $depth = 0;
1233: } else {
1234: $depth = scalar(split(/\//,$path));
1235: }
1236: if (ref($files{$path}) eq 'HASH') {
1237: foreach my $file (keys(%{$files{$path}})) {
1.714 raeburn 1238: $files_by_depth[$depth]{$path}{$file} = $files{$path}{$file};
1.712 raeburn 1239: }
1240: }
1241: }
1242: my ($info,$display,$onsubmit,$togglebuttons,$disabled);
1.714 raeburn 1243: my (%resdirs,%resfiles);
1.715 raeburn 1244: &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
1245: my $numpub = 0;
1246: if (keys(%resfiles)) {
1247: foreach my $dir (keys(%resfiles)) {
1248: if (ref($resfiles{$dir}) eq 'HASH') {
1249: foreach my $file (keys(%{$resfiles{$dir}})) {
1250: if (exists($files{$dir}{$file})) {
1251: $numpub ++;
1252: }
1253: }
1254: }
1255: }
1256: }
1.712 raeburn 1257: if ($readonly) {
1258: $disabled = ' disabled="disabled"';
1259: }
1260: if ($disabled) {
1261: $togglebuttons = '<br />';
1262: } else {
1263: $togglebuttons = '<input type="button" value="'.&mt('check all').'" '.
1264: 'onclick="javascript:checkAll(document.'.$formname.'.'.$chkname.')" />'.
1265: ' <input type="button" value="'.&mt('uncheck all').'"'.
1266: ' onclick="javascript:uncheckAll(document.'.$formname.'.'.$chkname.')" />';
1267: }
1.715 raeburn 1268: my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash).
1269: &courseresource_options($formname,$numpub).
1270: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
1271: my $display = '<form name="'.$formname.'" action="" method="post" onsubmit="return validCrsCopy();">'."\n".
1.712 raeburn 1272: $preamble."\n".
1273: '<div class="LC_float_left">'."\n".
1274: '<fieldset>'."\n".
1275: '<legend>'.&mt('Content to copy').(' 'x4).$togglebuttons.'</legend>'."\n".
1276: '<span class="LC_fontsize_medium">'.
1277: &mt('Choose the files and/or folders to copy from Course Authoring to User Authoring').
1278: '</span><br /><br />'."\n";
1279: my $count = 0;
1280: my $startcount = 4 + $home;
1281: my $lastcontainer = $startcount;
1282: $display .= &Apache::loncommon::start_data_table()."\n".
1283: &Apache::loncommon::start_data_table_header_row().
1284: '<th>'.&mt('Copy?').'</th>'.
1.714 raeburn 1285: '<th>'.&mt('Name').'</th>'.
1286: '<th>'.&mt('Last modified').'</th>'.
1287: '<th>'.&mt('Published?').'</th>'.
1.712 raeburn 1288: &Apache::loncommon::end_data_table_header_row()."\n";
1289: $count = &recurse_crsauthored(0,\@dirs_by_depth,\@files_by_depth,'/',$startcount,
1290: $count,\$display,\%parent,\%children,$readonly,
1.714 raeburn 1291: $formname,$chkname,\$lastcontainer,\%resfiles);
1.712 raeburn 1292: $display .= &Apache::loncommon::end_data_table().'</fieldset>';
1293: unless ($readonly) {
1294: $display .= '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
1295: '<div>'.
1296: '<input type="submit" name="copyauthored" value="'.&mt("Copy Selected Content").'" />'.
1297: '</div>';
1298: }
1299: $display .= &Apache::loncourserespicker::respicker_javascript($startcount,$count,$context,$formname,\%children,
1300: \%hierarchy,\@checked_maps,$home,$chkname);
1301: $r->print($display);
1302: }
1303: $r->print(&endContentScreen());
1304: }
1305:
1306: sub recurse_crsauthored {
1307: my ($currdepth,$dirs_by_depth,$files_by_depth,$currpath,$startcount,$count,$displayref,
1.714 raeburn 1308: $parent,$children,$readonly,$formname,$chkname,$lastcontainerref,$resfilesref) = @_;
1309: return $count unless ((ref($dirs_by_depth) eq 'ARRAY') && (ref($files_by_depth) eq 'ARRAY') &&
1310: (ref($resfilesref) eq 'HASH'));
1.712 raeburn 1311: my ($disabled,$hasdirs,$hasfiles,%unique,%dirs,%files);
1312: if ((ref($dirs_by_depth->[$currdepth]) eq 'HASH') &&
1313: (ref($dirs_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1314: $hasdirs = 1;
1315: %dirs = %{$dirs_by_depth->[$currdepth]{$currpath}};
1316: map { $unique{$_} = 1; } keys(%dirs);
1317: }
1318: if ((ref($files_by_depth->[$currdepth]) eq 'HASH') &&
1319: (ref($files_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1320: $hasfiles = 1;
1321: %files = %{$files_by_depth->[$currdepth]{$currpath}};
1322: map { $unique{$_} = 1; } keys(%files);
1323: }
1324: if ($readonly) {
1325: $disabled = ' disabled="disabled"';
1326: }
1327: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
1328: my $whitespace =
1329: '<img src="'.$location.'/whitespace_21.gif" class="LC_docs_spacer" alt="" />';
1330: $parent->{$currdepth} = $$lastcontainerref;
1331: foreach my $item (sort { lc($a) cmp lc($b) } (keys(%unique))) {
1332: next if ($item eq '');
1333: my $currelem;
1334: if ($hasdirs && exists($dirs{$item})) {
1335: $count ++;
1336: my $deeper = $currdepth+1;
1337: my ($newpath,$showpath);
1338: if ($currpath eq '/') {
1339: $newpath = $item;
1340: $showpath = $currpath.$item.'/';
1341: } else {
1342: $newpath = $currpath.'/'.$item;
1343: $showpath = '/'.$currpath.'/'.$item.'/';
1344: }
1345: $currelem = $count+$startcount;
1346: $$lastcontainerref = $currelem;
1347: $children->{$parent->{$currdepth}} .= $currelem.':';
1348: my $icon = 'src="'.$location.'/navmap.folder.open.gif" alt="'.&mt('Folder').'"';
1349: $$displayref .= &Apache::loncommon::start_data_table_row().
1350: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath).'" '.
1351: 'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" '.
1352: $disabled.' /></td><td>';
1353: for (my $i=0; $i<$currdepth; $i++) {
1354: $$displayref .= "$whitespace\n";
1355: }
1.714 raeburn 1356: $$displayref .= '<img '.$icon.' /> '.$item.'</td><td> </td><td> </td>'.
1.712 raeburn 1357: &Apache::loncommon::end_data_table_row()."\n";
1358: $count = &recurse_crsauthored($deeper,$dirs_by_depth,$files_by_depth,$newpath,
1359: $startcount,$count,$displayref,$parent,$children,
1.714 raeburn 1360: $readonly,$formname,$chkname,$lastcontainerref,$resfilesref);
1.712 raeburn 1361: }
1362: if ($hasfiles && exists($files{$item})) {
1363: $count ++;
1364: $currelem = $count+$startcount;
1365: $children->{$parent->{$currdepth}} .= $currelem.':';
1366: my $icon = 'src="'.&Apache::loncommon::icon($item).'"';
1367: my ($ext) = ($item =~ /\.([^.]+)$/);
1368: my $alttext;
1369: if (lc($ext) eq 'problem') {
1370: $alttext = ' alt="'.&mt('Problem Icon').'"';
1371: } elsif ($ext =~ /^x?html?$/i) {
1372: $alttext = ' alt="'.&mt('Web Page Icon').'"';
1373: } elsif ($ext =~ /^(jpg|gif|png|svg|jpeg)$/) {
1374: $alttext = ' alt="'.&mt('Image Icon').'"';
1375: } else {
1376: $alttext = ' alt="'.&mt('Resource Icon').'"';
1377: }
1378: my $showpath;
1379: if ($currpath eq '/') {
1380: $showpath = $currpath;
1381: } else {
1382: $showpath = "/$currpath/";
1383: }
1.714 raeburn 1384: my ($published,$lastmod);
1385: if ((ref($resfilesref->{$currpath})) && (exists($resfilesref->{$currpath}{$item}))) {
1386: $published = '<img src="'.$location.'/navmap.correct.gif" alt="'.&mt('yes').'" />';
1387: } else {
1388: $published = '<img src="'.$location.'/navmap.wrong.gif" alt="'.&mt('no').'" />';
1389: }
1.712 raeburn 1390: $$displayref .= &Apache::loncommon::start_data_table_row().
1391: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath.$item).'" '.
1392: 'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" '.
1393: $disabled.' /></td><td>';
1394: for (my $i=0; $i<$currdepth; $i++) {
1395: $$displayref .= "$whitespace\n";
1396: }
1397: $$displayref .= '<img '.$icon.$alttext.' /> '.$item.'</td>'.
1.714 raeburn 1398: '<td>'.&Apache::lonlocal::locallocaltime($files{$item}).'</td>'.
1399: '<td style="text-align: center;">'.$published.'</td>'.
1.712 raeburn 1400: &Apache::loncommon::end_data_table_row()."\n";
1401: }
1402: }
1403: $$lastcontainerref = $parent->{$currdepth};
1404: return $count;
1405: }
1406:
1.715 raeburn 1407: sub courseresource_options {
1408: my ($formname,$numpub) = @_;
1409: my %lt = &Apache::lonlocal::texthash(
1410: 'default' => 'System wide - can be used for any courses system wide',
1411: 'domain' => 'Domain only - use limited to courses in the domain',
1412: 'custom' => 'Customized right of use ...',
1413: 'public' => 'Public - no authentication or authorization required for use',
1414: 'closed' => 'Closed - XML source is closed to everyone',
1415: 'open' => 'Open - XML source is open to people who want to use it',
1416: 'sel' => 'Select',
1417: );
1418: my $output;
1419: if ($numpub) {
1420: $output .= '<div class="LC_left_float">'.
1421: '<fieldset><legend>'.&mt('Published Resources').'</legend>'.
1422: &mt('[quant,_1,file] in Course Authoring Space also exist in Resource Space.',
1423: $numpub).'</br />'.
1424: &mt('Publish copied files in selected Authoring Space?').': '."\n".
1425: '<label><input type="radio" name="respublish" checked="checked" value="1" />'.
1426: &mt('Yes').'</label>'."\n".
1427: '<label><input type="radio" name="respublish" value="0" />'.
1428: &mt('No').'</label>'."\n".
1429: '</fieldset></div>'."\n";
1430: }
1431: $output .= '<div class="LC_left_float">'.
1432: '<fieldset><legend>'.&mt('Distribution to set in metadata').'</legend>'.
1433: &mt('Copyright').': '.
1434: '<select name="copyright" onchange="showHideCustom(this,'."'LC_customfile'".');">'."\n".
1435: '<option value="default" selected="selected">'.$lt{'default'}.'</option>'."\n".
1436: '<option value="domain">'.$lt{'domain'}.'</option>'."\n".
1437: '<option value="public">'.$lt{'public'}.'</option>'."\n".
1438: '<option value="custom">'.$lt{'custom'}.'</option>'."\n".
1439: '</select><div id="LC_customfile" style="padding:0;clear:both;margin:0;border:0;display:none">'."\n".
1440: '<input type="text" name="customrights" size="60" value="" />'.
1441: '<a href="javascript:openbrowser('."'$formname','customrights','rights'".');">'.
1442: $lt{'sel'}.'</a></div><br />'."\n".
1443: &mt('Source').' :'.
1444: '<select name="sourceavail">'."\n".
1445: '<option value="closed" selected="selected">'.$lt{'closed'}.'</option>'."\n".
1446: '<option value="open">'.$lt{'open'}.'</option>'."\n".
1447: '</select><br />'."\n".
1448: '</fieldset></div>'."\n";
1449: return $output;
1450: }
1451:
1.717 raeburn 1452: sub crsres_fixup_meta {
1453: my ($dest,$coursenum,$coursedom,$ca,$cd,$copyright,$customdistfile,$sourceavail,$checkdeps) = @_;
1454: return unless (ref($checkdeps) eq 'HASH');
1455: if (open(my $fh,'<',$dest.'.meta')) {
1456: my ($output,$now,$setsourceavail);
1457: $now = time;
1458: if (($dest =~ /\.(xml|html|htm|xhtml|xhtm)$/i) || ($dest =~ /$LONCAPA::assess_re/)) {
1459: $setsourceavail = 1;
1460: }
1461: while (my $line=<$fh>) {
1462: chomp($line);
1463: if ($line eq "<authorspace>$coursenum:$coursedom</authorspace>") {
1464: $output .= "<authorspace>$ca:$cd</authorspace>\n";
1465: } elsif ($line eq '<copyright>custom</copyright>') {
1466: $output .= "<copyright>$copyright</copyright>\n";
1467: } elsif ($line =~ m{^<creationdate>\d+</creationdate>$}) {
1468: $output .= "<creationdate>$now</creationdate>\n";
1469: } elsif ($line eq "<customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>") {
1470: $output .= "<customdistributionfile>$customdistfile</customdistributionfile>\n";
1471: } elsif ($line =~ m{^<sourceavail>(open|closed)</sourceavail>$}) {
1472: if ($setsourceavail) {
1473: $output .= "<sourceavail>$sourceavail</sourceavail>\n";
1474: }
1475: } elsif ($line eq "<domain>$coursedom</domain>") {
1476: $output .= "<domain>$cd</domain>\n";
1477: } elsif ($line =~ m{^<lastrevisiondate>\d+</lastrevisiondate>$}) {
1478: $output .= "<lastrevisiondate>$now</lastrevisiondate>\n";
1479: } elsif ($line =~ m{^<modifyinguser>$match_username:$match_domain</modifyinguser>$}) {
1480: $output .= "<modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>\n";
1481: } elsif ($line eq "<owner>$coursenum:$coursedom</owner>") {
1482: $output .= "<owner>$ca:$cd</owner>\n";
1483: } elsif ($line =~ m{^<dependencies>(.+)</dependencies>$}) {
1484: my @deps = split(/\s*,\s*/,$1);
1485: my @newdeps;
1486: my $changed = 0;
1487: foreach my $dep (@deps) {
1488: if ($dep =~ m{^/res/$coursedom/$coursenum/(.+)$}) {
1489: my $rest = $1;
1490: push(@newdeps,"/res/$cd/$ca/$rest");
1491: $checkdeps->{$rest} = 1;
1492: $changed ++;
1493: } else {
1494: push(@newdeps,$dep);
1495: }
1496: }
1497: if ($changed) {
1498: $output .= '<dependencies>'.join(',',@newdeps).'</dependencies>'."\n";
1499: }
1500: } else {
1501: $output .= "$line\n";
1502: }
1503: }
1504: close($fh);
1505: if (open(my $fh,'>',$dest.'.meta')) {
1506: print $fh $output;
1507: close($fh);
1508: }
1509: }
1510: }
1511:
1512: sub crsres_fixup {
1513: my ($dest,$coursenum,$coursedom,$ca,$cd,$subdir) = @_;
1514: my $outstring='';
1515: my $changes = 0;
1516: my @parser;
1517: $parser[0]=HTML::LCParser->new($dest);
1518: $parser[-1]->xml_mode(1);
1519: my $token;
1520: while (@parser) {
1521: while ($token=$parser[-1]->get_token) {
1522: if ($token->[0] eq 'S') {
1523: my $tag=$token->[1];
1524: my $lctag=lc($tag);
1525: my %parms=%{$token->[2]};
1526: foreach my $type ('src','href','background','bgimg') {
1527: foreach my $key (keys(%parms)) {
1528: if ($key =~ /^$type$/i) {
1529: next if (($lctag eq 'img') && ($type eq 'src') &&
1530: ($parms{$key} =~ m{^data\:image/gif;base64,}));
1531: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1532: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
1533: $changes ++;
1534: }
1535: }
1536: }
1537: }
1538: # probably a <randomlabel> image type <label>
1539: # or a <image> tag inside <imageresponse> or <drawimage>
1540: if (($lctag eq 'label' && defined($parms{'description'}))
1541: || ($lctag eq 'image') || ($lctag eq 'import')) {
1542: my $next_token=$parser[-1]->get_token();
1543: if ($next_token->[0] eq 'T') {
1544: $next_token->[1] =~ s/[\n\r\f]+//g;
1545: if ($next_token->[1] =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1546: $next_token->[1] =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
1547: $changes ++;
1548: }
1549: }
1550: $parser[-1]->unget_token($next_token);
1551: }
1552: if ($lctag eq 'applet') {
1553: my $havecodebase=0;
1554: foreach my $key (keys(%parms)) {
1555: if (lc($key) eq 'codebase') {
1556: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1557: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
1558: $changes ++;
1559: }
1560: $havecodebase = 1;
1561: }
1562: }
1563: unless ($havecodebase) {
1564: foreach my $key (keys(%parms)) {
1565: if ($key =~ /(archive|code|object)/i) {
1566: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1567: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/si};
1568: $changes ++;
1569: }
1570: }
1571: }
1572: }
1573: }
1574: my $newparmstring='';
1575: my $endtag='';
1576: foreach my $parkey (keys(%parms)) {
1577: if ($parkey eq '/') {
1578: $endtag=' /';
1579: } else {
1580: my $quote=($parms{$parkey}=~/\"/?"'":'"');
1581: $newparmstring.=' '.$parkey.'='.$quote.$parms{$parkey}.$quote;
1582: }
1583: }
1584: if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
1585: $outstring.='<'.$tag.$newparmstring.$endtag.'>';
1586: if ($lctag eq 'm' || $lctag eq 'answer' || $lctag eq 'display' ||
1587: $lctag eq 'tex') {
1588: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
1589: } elsif ($lctag eq 'script') {
1590: if ($parms{'type'} eq 'loncapa/perl') {
1591: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
1592: } else {
1593: my $needsupdate;
1594: my $script = &Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
1595: if ($script =~ m{\.addMediaSrc\((["'])((?!\1).+)\1\);}) {
1596: my $src = $2;
1597: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1598: $needsupdate = 1;
1599: }
1600: }
1601: if ($script =~ /\(document,\s*(['"])script\1,\s*\[([^\]]+)\]\);/s) {
1602: my $scriptslist = $2;
1603: my @srcs = split(/\s*,\s*/,$scriptslist);
1604: foreach my $src (@srcs) {
1605: if ($src =~ /(["'])(?:(?!\1).)+\.js\1/) {
1606: my $quote = $1;
1607: my ($url) = ($src =~ m/\Q$quote\E([^$quote]+)\Q$quote\E/);
1608: if ($url =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1609: $needsupdate = 1;
1610: }
1611: }
1612: }
1613: }
1614: if ($script =~ m{loadScript\(\s*(['"])((?:(?!\1).)+\.js)\1,\s*function}is) {
1615: my $src = $2;
1616: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1617: $needsupdate = 1;
1618: }
1619: }
1620: if ($needsupdate) {
1621: $script =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/gsi};
1622: $changes ++;
1623: }
1624: $outstring .= $script;
1625: }
1626: }
1627: } elsif ($token->[0] eq 'E') {
1628: if ($token->[2]) {
1629: unless ($token->[1] eq 'allow') {
1630: $outstring.='</'.$token->[1].'>';
1631: }
1632: }
1633: } else {
1634: $outstring.=$token->[1];
1635: }
1636: }
1637: pop(@parser);
1638: }
1639: if ($changes) {
1640: if (open(my $fh,'>',$dest)) {
1641: print $fh $outstring;
1642: close($fh);
1643: }
1644: }
1645: }
1646:
1.329 droeschl 1647: sub group_import {
1.598 raeburn 1648: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 1649: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
1650: %removeparam,$importuploaded,$fixuperrors);
1651: $allmaps = {};
1.329 droeschl 1652: while (@files) {
1653: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 1654: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 1655: && ($caller eq 'londocs')
1656: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 1657:
1.329 droeschl 1658: my $errtext = '';
1659: my $fatal = 0;
1660: my $newmapstr = '<map>'."\n".
1661: '<resource id="1" src="" type="start"></resource>'."\n".
1662: '<link from="1" to="2" index="1"></link>'."\n".
1663: '<resource id="2" src="" type="finish"></resource>'."\n".
1664: '</map>';
1665: $env{'form.output'}=$newmapstr;
1666: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1667: 'output',$1.$2);
1.534 raeburn 1668: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 1669: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
1670: $fatal = 2;
1671: }
1672: if ($fatal) {
1673: return ($errtext,$fatal);
1674: }
1675: }
1676: if ($url) {
1.626 raeburn 1677: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 1678: $url = $1;
1679: my $marker = $2;
1680: my $info = $3;
1.699 raeburn 1681: my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.642 raeburn 1682: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 1683: my @toolinfo = split(/:/,$info);
1684: if ($residx) {
1.604 raeburn 1685: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 1686: $toolid = $toolsettings{'id'};
1687: } else {
1.604 raeburn 1688: $toolid = shift(@toolinfo);
1.598 raeburn 1689: }
1.699 raeburn 1690: if ($toolid =~ /^c/) {
1691: $tooltype = 'crs';
1692: $toolprefix = 'c';
1693: } else {
1694: $tooltype = 'dom';
1695: }
1.598 raeburn 1696: $toolid =~ s/\D//g;
1.604 raeburn 1697: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 1698: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
1699: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 1700: foreach my $item (@extras) {
1701: $toolhash{$item} = &unescape($toolhash{$item});
1702: }
1.645 raeburn 1703: if ($folder =~ /^supplemental/) {
1.648 raeburn 1704: delete($toolhash{'gradable'});
1705: } else {
1706: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 1707: }
1.598 raeburn 1708: if (ref($ltitoolsref) eq 'HASH') {
1.699 raeburn 1709: if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
1710: if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
1711: my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
1712: my @deleted;
1713: $toolhash{'id'} = $toolprefix.$toolid;
1714: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
1715: ($toolhash{'target'} eq 'window')) {
1716: if ($toolhash{'target'} eq 'window') {
1717: foreach my $item ('width','height') {
1718: $toolhash{$item} =~ s/^\s+//;
1719: $toolhash{$item} =~ s/\s+$//;
1720: if ($toolhash{$item} =~ /\D/) {
1721: delete($toolhash{$item});
1722: if ($residx) {
1723: if ($toolsettings{$item}) {
1724: push(@deleted,$item);
1725: }
1.624 raeburn 1726: }
1727: }
1728: }
1.604 raeburn 1729: }
1.699 raeburn 1730: } elsif ($residx) {
1731: $toolhash{'target'} = $toolsettings{'target'};
1732: if ($toolhash{'target'} eq 'window') {
1733: foreach my $item ('width','height') {
1734: $toolhash{$item} = $toolsettings{$item};
1735: }
1736: }
1737: } elsif (ref($tools{'display'}) eq 'HASH') {
1738: $toolhash{'target'} = $tools{'display'}{'target'};
1739: if ($toolhash{'target'} eq 'window') {
1740: $toolhash{'width'} = $tools{'display'}{'width'};
1741: $toolhash{'height'} = $tools{'display'}{'height'};
1.624 raeburn 1742: }
1.604 raeburn 1743: }
1.699 raeburn 1744: if ($toolhash{'target'} eq 'iframe') {
1745: foreach my $item ('width','height','linktext','explanation') {
1746: delete($toolhash{$item});
1747: if ($residx) {
1748: if ($toolsettings{$item}) {
1749: push(@deleted,$item);
1750: }
1.624 raeburn 1751: }
1.604 raeburn 1752: }
1.699 raeburn 1753: } elsif ($toolhash{'target'} eq 'tab') {
1754: foreach my $item ('width','height') {
1755: delete($toolhash{$item});
1756: if ($residx) {
1757: if ($toolsettings{$item}) {
1758: push(@deleted,$item);
1759: }
1.628 raeburn 1760: }
1761: }
1762: }
1.699 raeburn 1763: if (ref($tools{'crsconf'}) eq 'HASH') {
1764: foreach my $item ('label','title','linktext','explanation') {
1765: my $crsitem;
1766: if (($item eq 'label') || ($item eq 'title')) {
1767: $crsitem = 'crs'.$item;
1768: } else {
1769: $crsitem = $item;
1770: }
1771: if ($tools{'crsconf'}{$item}) {
1772: $toolhash{$crsitem} =~ s/^\s+//;
1773: $toolhash{$crsitem} =~ s/\s+$//;
1774: if ($toolhash{$crsitem} eq '') {
1775: delete($toolhash{$crsitem});
1776: }
1777: } else {
1.624 raeburn 1778: delete($toolhash{$crsitem});
1.604 raeburn 1779: }
1.699 raeburn 1780: if (($residx) && (exists($toolsettings{$crsitem}))) {
1781: unless (exists($toolhash{$crsitem})) {
1782: push(@deleted,$crsitem);
1783: }
1784: }
1.604 raeburn 1785: }
1.699 raeburn 1786: }
1787: if ($toolhash{'passback'}) {
1788: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1789: $toolhash{'gradesecret'} = $gradesecret;
1790: $toolhash{'gradesecretdate'} = time;
1791: }
1792: if ($toolhash{'roster'}) {
1793: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1794: $toolhash{'rostersecret'} = $rostersecret;
1795: $toolhash{'rostersecretdate'} = time;
1796: }
1797: my $changegradable;
1798: if (($residx) && ($folder =~ /^default/)) {
1799: if ($toolsettings{'gradable'}) {
1800: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1801: push(@deleted,'gradable');
1802: $changegradable = 1;
1.604 raeburn 1803: }
1.699 raeburn 1804: } elsif ($toolhash{'gradable'}) {
1805: $changegradable = 1;
1.604 raeburn 1806: }
1.699 raeburn 1807: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 1808: $changegradable = 1;
1.699 raeburn 1809: if ($toolsettings{'gradable'}) {
1810: $toolhash{'gradable'} = 1;
1811: }
1.645 raeburn 1812: }
1.648 raeburn 1813: }
1.699 raeburn 1814: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1815: if ($putres eq 'ok') {
1816: if (@deleted) {
1817: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648 raeburn 1818: }
1.699 raeburn 1819: if (($changegradable) && ($folder =~ /^default/)) {
1820: my $val;
1821: if ($toolhash{'gradable'}) {
1822: $val = 'yes';
1823: } else {
1824: $val = 'no';
1825: }
1826: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
1827: 'string_yesno');
1828: &remember_parms($residx,'gradable','set',$val);
1.645 raeburn 1829: }
1.699 raeburn 1830: } else {
1831: return (&mt('Failed to save update to external tool.'),1);
1.645 raeburn 1832: }
1.604 raeburn 1833: }
1.598 raeburn 1834: }
1835: }
1836: }
1.529 raeburn 1837: if (($caller eq 'londocs') &&
1838: ($folder =~ /^default/)) {
1.534 raeburn 1839: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 1840: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
1841: my $cid = $coursedom.'_'.$coursenum;
1842: $allmaps =
1843: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1844: $chome,$cid);
1845: $donechk = 1;
1846: }
1847: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 1848: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1849: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 1850: $importuploaded = 1;
1851: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
1852: next if ($allmaps->{$url});
1853: }
1854: }
1.344 bisitz 1855: if (!$residx
1.329 droeschl 1856: || defined($LONCAPA::map::zombies[$residx])) {
1857: $residx = &LONCAPA::map::getresidx($url,$residx);
1858: push(@LONCAPA::map::order, $residx);
1859: }
1860: my $ext = 'false';
1861: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 1862: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
1863: my $filepath = $1;
1.675 raeburn 1864: my $fname;
1865: if ($name eq '') {
1866: $name = &mt('Web Page');
1.534 raeburn 1867: $fname = 'web';
1868: } else {
1.675 raeburn 1869: $fname = $name;
1870: $fname=&Apache::lonnet::clean_filename($fname);
1871: if ($fname eq '') {
1872: $fname = 'web';
1873: } elsif (length($fname) > 15) {
1874: $fname = substr($fname,0,14);
1875: }
1.534 raeburn 1876: }
1.675 raeburn 1877: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 1878: my $initialtext = &mt('Replace with your own content.');
1879: my $newhtml = <<END;
1.545 raeburn 1880: <html>
1.534 raeburn 1881: <head>
1.675 raeburn 1882: <title>$title</title>
1.534 raeburn 1883: </head>
1884: <body bgcolor="#ffffff">
1885: $initialtext
1886: </body>
1887: </html>
1888: END
1889: $env{'form.output'}=$newhtml;
1.630 raeburn 1890: my $result =
1.534 raeburn 1891: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1892: 'output',
1893: "$filepath/$residx/$fname.html");
1894: if ($result =~ m{^/uploaded/}) {
1895: $url = $result;
1896: if ($filepath =~ /^supplemental/) {
1897: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1898: $env{'user.domain'}.'___&&&___'.$name;
1899: }
1900: } else {
1901: return (&mt('Failed to save new web page.'),1);
1902: }
1903: }
1.675 raeburn 1904: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 1905: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 1906: $LONCAPA::map::resources[$residx] =
1.329 droeschl 1907: join(':', ($name, $url, $ext, 'normal', 'res'));
1908: }
1909: }
1.529 raeburn 1910: if ($importuploaded) {
1911: my %import_errors;
1912: my %updated = (
1913: removefrommap => \%removefrommap,
1914: removeparam => \%removeparam,
1915: );
1.533 raeburn 1916: my ($result,$msgsarray,$lockerror) =
1917: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 1918: if (keys(%import_errors) > 0) {
1.530 raeburn 1919: $fixuperrors =
1.529 raeburn 1920: '<p span class="LC_warning">'."\n".
1921: &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".
1922: '<ul>'."\n";
1923: foreach my $key (sort(keys(%import_errors))) {
1924: $fixuperrors .= '<li>'.$key.'</li>'."\n";
1925: }
1926: $fixuperrors .= '</ul></p>'."\n";
1927: }
1.533 raeburn 1928: if (ref($msgsarray) eq 'ARRAY') {
1929: if (@{$msgsarray} > 0) {
1930: $fixuperrors .= '<p class="LC_info">'.
1931: join('<br />',@{$msgsarray}).
1932: '</p>';
1933: }
1934: }
1935: if ($lockerror) {
1936: $fixuperrors .= '<p class="LC_error">'.
1937: $lockerror.
1938: '</p>';
1939: }
1.529 raeburn 1940: }
1941: my ($errtext,$fatal) =
1942: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 1943: unless ($fatal) {
1944: if ($folder =~ /^supplemental/) {
1.561 raeburn 1945: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1946: $folder.'.'.$container);
1.557 raeburn 1947: }
1948: }
1.529 raeburn 1949: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 1950: }
1951:
1952: sub log_docs {
1.494 raeburn 1953: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 1954: }
1955:
1956: {
1957: my @oldresources=();
1958: my @oldorder=();
1959: my $parmidx;
1960: my %parmaction=();
1961: my %parmvalue=();
1962: my $changedflag;
1963:
1964: sub snapshotbefore {
1965: @oldresources=@LONCAPA::map::resources;
1966: @oldorder=@LONCAPA::map::order;
1967: $parmidx=undef;
1968: %parmaction=();
1969: %parmvalue=();
1970: $changedflag=0;
1971: }
1972:
1973: sub remember_parms {
1974: my ($idx,$parameter,$action,$value)=@_;
1975: $parmidx=$idx;
1976: $parmaction{$parameter}=$action;
1977: $parmvalue{$parameter}=$value;
1978: $changedflag=1;
1979: }
1980:
1981: sub log_differences {
1982: my ($plain)=@_;
1983: my %storehash=('folder' => $plain,
1984: 'currentfolder' => $env{'form.folder'});
1985: if ($parmidx) {
1986: $storehash{'parameter_res'}=$oldresources[$parmidx];
1987: foreach my $parm (keys(%parmaction)) {
1988: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1989: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1990: }
1991: }
1992: my $maxidx=$#oldresources;
1993: if ($#LONCAPA::map::resources>$#oldresources) {
1994: $maxidx=$#LONCAPA::map::resources;
1995: }
1996: for (my $idx=0; $idx<=$maxidx; $idx++) {
1997: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1998: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1999: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
2000: $changedflag=1;
2001: }
2002: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
2003: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
2004: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2005: $changedflag=1;
2006: }
2007: }
2008: $storehash{'maxidx'}=$maxidx;
2009: if ($changedflag) { &log_docs(\%storehash); }
2010: }
2011: }
2012:
2013: sub docs_change_log {
1.611 raeburn 2014: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 2015: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 2016: my $navmap;
1.483 raeburn 2017: my $js = '<script type="text/javascript">'."\n".
2018: '// <![CDATA['."\n".
2019: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 2020: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 2021: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 2022: &history_tab_js()."\n".
1.484 raeburn 2023: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 2024: '// ]]>'."\n".
2025: '</script>'."\n";
1.484 raeburn 2026: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
2027: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 2028: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 2029: my %orderhash;
2030: my $container='sequence';
2031: my $pathitem;
1.519 raeburn 2032: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 2033: $container='page';
2034: }
1.519 raeburn 2035: my $folderpath=$env{'form.folderpath'};
2036: if ($folderpath eq '') {
1.617 raeburn 2037: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 2038: }
1.617 raeburn 2039: undef($navmap);
1.519 raeburn 2040: $pathitem = '<input type="hidden" name="folderpath" value="'.
2041: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 2042: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
2043: my $jumpto = $readfile;
2044: $jumpto =~ s{^/}{};
2045: my $tid = 1;
1.489 raeburn 2046: if ($supplementalflag) {
2047: $tid = 2;
2048: }
1.630 raeburn 2049: my ($breadcrumbtrail) =
1.509 raeburn 2050: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 2051: $r->print($breadcrumbtrail.
2052: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
2053: $readfile));
1.329 droeschl 2054: my %docslog=&Apache::lonnet::dump('nohist_docslog',
2055: $env{'course.'.$env{'request.course.id'}.'.domain'},
2056: $env{'course.'.$env{'request.course.id'}.'.num'});
2057:
2058: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
2059:
2060: my %saveable_parameters = ('show' => 'scalar',);
2061: &Apache::loncommon::store_course_settings('docs_log',
2062: \%saveable_parameters);
2063: &Apache::loncommon::restore_course_settings('docs_log',
2064: \%saveable_parameters);
2065: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 2066: # FIXME: internationalization seems wrong here
1.329 droeschl 2067: my %lt=('hiddenresource' => 'Resources hidden',
2068: 'encrypturl' => 'URL hidden',
2069: 'randompick' => 'Randomly pick',
2070: 'randomorder' => 'Randomly ordered',
1.645 raeburn 2071: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 2072: 'set' => 'set to',
2073: 'del' => 'deleted');
1.484 raeburn 2074: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
2075: $pathitem."\n".
2076: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
2077: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
2078: $r->print('<div class="LC_left_float">'.
2079: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
2080: &makedocslogform($filter,1).
2081: '</fieldset></div><br clear="all" />');
1.329 droeschl 2082: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
2083: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
2084: &mt('After').'</th>'.
2085: &Apache::loncommon::end_data_table_header_row());
2086: my $shown=0;
2087: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
2088: if ($env{'form.displayfilter'} eq 'currentfolder') {
2089: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
2090: }
2091: my @changes=keys(%{$docslog{$id}{'logentry'}});
2092: if ($env{'form.displayfilter'} eq 'containing') {
2093: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
2094: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
2095: foreach my $key (@changes) {
2096: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
2097: }
1.344 bisitz 2098: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 2099: }
2100: my $count = 0;
2101: my $time =
2102: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
2103: my $plainname =
2104: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
2105: $docslog{$id}{'exe_udom'});
2106: my $about_me_link =
2107: &Apache::loncommon::aboutmewrapper($plainname,
2108: $docslog{$id}{'exe_uname'},
2109: $docslog{$id}{'exe_udom'});
2110: my $send_msg_link='';
2111: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
2112: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
2113: $send_msg_link ='<br />'.
2114: &Apache::loncommon::messagewrapper(&mt('Send message'),
2115: $docslog{$id}{'exe_uname'},
2116: $docslog{$id}{'exe_udom'});
2117: }
2118: $r->print(&Apache::loncommon::start_data_table_row());
2119: $r->print('<td>'.$time.'</td>
2120: <td>'.$about_me_link.
2121: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
2122: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
2123: $send_msg_link.'</td><td>'.
2124: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 2125: my $is_supp = 0;
2126: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
2127: $is_supp = 1;
2128: }
1.329 droeschl 2129: # Before
2130: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2131: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
2132: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
2133: if ($oldname ne $newname) {
1.488 raeburn 2134: my $shown = &LONCAPA::map::qtescape($oldname);
2135: if ($is_supp) {
2136: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2137: }
2138: $r->print($shown);
1.329 droeschl 2139: }
2140: }
2141: $r->print('<ul>');
2142: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2143: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 2144: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
2145: if ($is_supp) {
2146: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2147: }
2148: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 2149: }
2150: }
2151: $r->print('</ul>');
2152: # After
2153: $r->print('</td><td>');
2154:
2155: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2156: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
2157: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
2158: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 2159: my $shown = &LONCAPA::map::qtescape($newname);
2160: if ($is_supp) {
2161: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
2162: }
2163: $r->print($shown);
1.329 droeschl 2164: }
1.364 bisitz 2165: }
1.329 droeschl 2166: $r->print('<ul>');
2167: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2168: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 2169: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
2170: if ($is_supp) {
2171: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2172: }
2173: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 2174: }
2175: }
2176: $r->print('</ul>');
2177: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 2178: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
2179: if ($title eq '') {
2180: ($title) = ($url =~ m{/([^/]+)$});
1.695 raeburn 2181: } elsif ($is_supp) {
2182: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 2183: }
2184: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 2185: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 2186: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 2187: # FIXME: internationalization seems wrong here
1.329 droeschl 2188: $r->print('<li>'.
2189: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
2190: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
2191: .'</li>');
2192: }
2193: }
2194: $r->print('</ul>');
2195: }
2196: # End
2197: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
2198: $shown++;
2199: if (!($env{'form.show'} eq &mt('all')
2200: || $shown<=$env{'form.show'})) { last; }
2201: }
1.484 raeburn 2202: $r->print(&Apache::loncommon::end_data_table()."\n".
2203: &makesimpleeditform($pathitem)."\n".
2204: '</div></div>');
2205: $r->print(&endContentScreen());
1.329 droeschl 2206: }
2207:
2208: sub update_paste_buffer {
1.492 raeburn 2209: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 2210: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 2211: if ($env{'form.multiremove'}) {
2212: $env{'form.multiremove'} =~ s/,$//;
2213: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
2214: }
2215: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
2216: if ($env{'form.multicut'}) {
2217: $env{'form.multicut'} =~ s/,$//;
2218: foreach my $item (split(/,/,$env{'form.multicut'})) {
2219: unless ($removals{$item}) {
2220: $cuts{$item} = 1;
2221: push(@possibles,$item.':cut');
2222: }
2223: }
2224: }
2225: if ($env{'form.multicopy'}) {
2226: $env{'form.multicopy'} =~ s/,$//;
2227: foreach my $item (split(/,/,$env{'form.multicopy'})) {
2228: unless ($removals{$item} || $cuts{$item}) {
2229: push(@possibles,$item.':copy');
2230: }
2231: }
2232: }
2233: } elsif ($env{'form.markcopy'}) {
2234: @possibles = split(/,/,$env{'form.markcopy'});
2235: }
1.329 droeschl 2236:
1.538 raeburn 2237: return if (@possibles == 0);
1.329 droeschl 2238: return if (!defined($env{'form.copyfolder'}));
2239:
2240: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2241: $env{'form.copyfolder'});
1.538 raeburn 2242: return if ($fatal);
2243:
2244: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 2245:
1.538 raeburn 2246: # Retrieve current paste buffer suffixes.
2247: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2248: my (%pasteurls,@newpaste);
2249:
2250: # Construct identifiers for current contents of user's paste buffer
2251: if (@currpaste) {
2252: foreach my $suffix (@currpaste) {
1.667 raeburn 2253: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
2254: my $url = $env{'docs.markedcopy_url_'.$suffix};
2255: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
2256: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
2257: ($url ne '')) {
2258: if ($url eq '/res/lib/templates/simpleproblem.problem') {
2259: $pasteurls{$cid.'_'.$mapidx} = 1;
2260: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
2261: $pasteurls{$url} = 1;
2262: } else {
1.669 raeburn 2263: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 2264: }
2265: }
1.538 raeburn 2266: }
2267: }
2268:
2269: # Mark items for copying (skip any items already in user's paste buffer)
2270: my %addtoenv;
1.597 raeburn 2271:
2272: my @pathitems = split(/\&/,$env{'form.folderpath'});
2273: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 2274: my $ispage = $folderconf[5];
1.597 raeburn 2275:
1.538 raeburn 2276: foreach my $item (@possibles) {
2277: my ($orderidx,$cmd) = split(/:/,$item);
2278: next if ($orderidx =~ /\D/);
2279: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 2280: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 2281: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
2282: my %denied = &action_restrictions($coursenum,$coursedom,
2283: &LONCAPA::map::qtescape($url),
2284: $env{'form.folderpath'},\%curr_groups);
2285: next if ($denied{'copy'});
2286: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 2287: if ($url eq '/res/lib/templates/simpleproblem.problem') {
2288: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
2289: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
2290: next if (exists($pasteurls{$url}));
2291: } else {
2292: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
2293: }
1.538 raeburn 2294: my ($suffix,$errortxt,$locknotfreed) =
2295: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 2296: if ($suffix ne '') {
2297: push(@newpaste,$suffix);
2298: } else {
2299: if ($locknotfreed) {
2300: return $locknotfreed;
2301: }
1.538 raeburn 2302: }
2303: if (&is_supplemental_title($title)) {
2304: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
2305: ($title) = &Apache::loncommon::parse_supplemental_title($title);
2306: }
1.329 droeschl 2307:
1.538 raeburn 2308: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
2309: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
2310: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
2311: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 2312: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 2313: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
2314: my $prefix = $1;
2315: my $subdir =$2;
2316: if ($subdir eq '') {
2317: $subdir = $prefix;
1.492 raeburn 2318: }
1.538 raeburn 2319: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 2320: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
2321: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 2322: if (ref($hierarchy{$url}) eq 'HASH') {
2323: my ($nested,$nestednames);
2324: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
2325: $nested =~ s/\&$//;
2326: $nestednames =~ s/\Q___&&&___\E$//;
2327: if ($nested ne '') {
2328: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
2329: }
2330: if ($nestednames ne '') {
2331: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
2332: }
1.492 raeburn 2333: }
2334: }
1.591 raeburn 2335: if ($locknotfreed) {
2336: $output = $locknotfreed;
2337: last;
2338: }
1.492 raeburn 2339: }
1.538 raeburn 2340: if (@newpaste) {
2341: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
2342: }
1.492 raeburn 2343: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 2344: delete($env{'form.markcopy'});
1.591 raeburn 2345: return $output;
1.329 droeschl 2346: }
2347:
1.492 raeburn 2348: sub recurse_uploaded_maps {
2349: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
2350: if (ref($hierarchy->{$url}) eq 'HASH') {
2351: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
2352: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
2353: my (@uploaded,@names,%shorter);
2354: for (my $i=0; $i<@maps; $i++) {
2355: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
2356: if ($inner ne '') {
2357: push(@uploaded,$inner);
2358: push(@names,&escape($titles[$i]));
2359: $shorter{$maps[$i]} = $inner;
2360: }
2361: }
2362: $$nestref .= "$dir:".join(',',@uploaded).'&';
2363: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
2364: foreach my $map (@maps) {
2365: if ($shorter{$map} ne '') {
2366: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
2367: }
2368: }
2369: }
2370: return;
2371: }
2372:
1.329 droeschl 2373: sub print_paste_buffer {
1.492 raeburn 2374: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 2375: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 2376:
1.538 raeburn 2377: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
2378: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 2379: }
2380:
1.538 raeburn 2381: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1.704 raeburn 2382: my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
1.575 raeburn 2383: my $clipboardcount = 0;
1.488 raeburn 2384:
1.538 raeburn 2385: # Construct identifiers for current contents of user's paste buffer
2386: foreach my $suffix (@currpaste) {
2387: next if ($suffix =~ /\D/);
2388: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
2389: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 2390: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 2391: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
2392: ($url ne '')) {
1.575 raeburn 2393: $clipboardcount ++;
1.538 raeburn 2394: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.704 raeburn 2395: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
2396: $toolcnum,$marker);
1.538 raeburn 2397: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
2398: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
2399: $is_external = 1;
1.704 raeburn 2400: } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2401: ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1.598 raeburn 2402: $is_exttool = 1;
1.538 raeburn 2403: }
2404: if ($folder =~ /^supplemental/) {
2405: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
2406: unless ($canpaste) {
2407: $nopaste = &mt('Paste into Supplemental Content unavailable.');
2408: }
2409: } else {
2410: $canpaste = 1;
2411: }
2412: if ($canpaste) {
2413: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2414: my $srcdom = $1;
2415: my $srcnum = $2;
2416: my $rem = $3;
2417: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
2418: $othercourse = 1;
2419: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 2420: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 2421: } else {
2422: $canpaste = 0;
2423: $nopaste = &mt('Paste from another course unavailable.');
2424: }
2425: }
2426: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
2427: my $prefix = $1;
2428: $parent = $2;
2429: if ($folder !~ /^\Q$prefix\E/) {
2430: $areachange = 1;
2431: }
2432: $is_uploaded_map = 1;
1.492 raeburn 2433: }
1.597 raeburn 2434: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 2435: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 2436: if ($cid ne $env{'request.course.id'}) {
2437: my ($srcdom,$srcnum) = split(/_/,$cid);
2438: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.704 raeburn 2439: if ($is_exttool) {
2440: if ($toolcdom ne $coursedom) {
2441: $canpaste = 0;
2442: $nopaste = &mt('Paste from another domain unavailable.');
2443: } elsif ($toolcnum ne $coursenum) {
2444: my %toolsettings =
2445: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2446: my %tooltypes = &Apache::loncommon::usable_exttools();
2447: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2448: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2449: $canpaste = 0;
2450: $nopaste = &mt('Paste from another course unavailable.');
2451: } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
2452: unless ($checkedsameinst) {
2453: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2454: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2455: if ($intdom ne '') {
2456: my $internet_names =
2457: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2458: if (ref($internet_names) eq 'ARRAY') {
2459: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2460: $same_institution = 1;
2461: }
2462: }
2463: }
2464: $checkedsameinst = 1;
2465: }
2466: if ($same_institution) {
2467: $othercrs = '<br />'.&mt('(from another course)');
2468: } else {
2469: $nopaste = &mt('Paste from another course unavailable.');
2470: }
2471: } else {
2472: $othercrs = '<br />'.&mt('(from another course)');
2473: }
2474: }
1.627 raeburn 2475: }
1.596 raeburn 2476: } else {
2477: $canpaste = 0;
2478: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 2479: }
1.596 raeburn 2480: }
1.703 raeburn 2481: } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
2482: my ($audom,$auname) = ($1,$2);
2483: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2484: if (&Apache::lonnet::is_course($audom,$auname)) {
2485: $canpaste = 0;
2486: $nopaste = &mt('Paste from another course unavailable.');
2487: }
2488: }
1.492 raeburn 2489: }
1.596 raeburn 2490: if ($canpaste) {
2491: push(@pasteable,$suffix);
1.629 raeburn 2492: }
1.538 raeburn 2493: }
2494: my $buffer;
1.627 raeburn 2495: if ($is_external) {
1.538 raeburn 2496: $buffer = &mt('External Resource').': '.
2497: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
2498: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 2499: } elsif ($is_exttool) {
2500: $buffer = &mt('External Tool').': '.
2501: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 2502: } else {
2503: my $icon = &Apache::loncommon::icon($extension);
2504: if ($extension eq 'sequence' &&
2505: $url =~ m{/default_\d+\.sequence$}x) {
2506: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
2507: $icon .= '/navmap.folder.closed.gif';
2508: }
1.589 raeburn 2509: my $title = $env{'docs.markedcopy_title_'.$suffix};
2510: if ($title eq '') {
2511: ($title) = ($url =~ m{/([^/]+)$});
2512: }
1.538 raeburn 2513: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
2514: ': '.
2515: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 2516: &LONCAPA::map::qtescape($title));
1.538 raeburn 2517: }
2518: $pasteitems .= '<div class="LC_left_float">';
2519: my ($options,$onclick);
2520: if (($canpaste) && (!$areachange) && (!$othercourse) &&
2521: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
2522: if (($is_uploaded_map) ||
2523: ($url =~ /(bulletinboard|smppg)$/) ||
2524: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
2525: $options = &paste_options($suffix,$is_uploaded_map,$parent);
2526: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
2527: }
2528: }
2529: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
2530: if ($nopaste) {
1.681 raeburn 2531: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 2532: } else {
2533: if ($othercrs) {
2534: $pasteitems .= $othercrs;
2535: }
2536: if ($options) {
2537: $pasteitems .= $options;
1.492 raeburn 2538: }
2539: }
1.538 raeburn 2540: $pasteitems .= '</div>';
2541: }
2542: }
2543: if ($pasteitems eq '') {
2544: &Apache::lonnet::delenv('docs.markedcopies');
2545: }
2546: my ($pasteform,$form_start,$buttons,$form_end);
2547: if ($pasteitems) {
2548: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 2549: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 2550: if (@pasteable) {
1.575 raeburn 2551: my $value = &mt('Paste to current folder');
2552: if ($container eq 'page') {
2553: $value = &mt('Paste to current page');
2554: }
2555: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
2556: }
2557: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
2558: if ($clipboardcount > 1) {
2559: $buttons .=
2560: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
2561: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
2562: (' 'x2).
2563: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
2564: (' 'x2);
1.492 raeburn 2565: }
1.575 raeburn 2566: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
2567: '</form>';
1.538 raeburn 2568: } else {
2569: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 2570: }
1.538 raeburn 2571: $r->print($form_start
2572: .'<fieldset>'
2573: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
2574: .$pasteitems
2575: .'</fieldset>'
2576: .$form_end);
2577: }
2578:
2579: sub paste_options {
2580: my ($suffix,$is_uploaded_map,$parent) = @_;
2581: my ($copytext,$movetext);
2582: if ($is_uploaded_map) {
2583: $copytext = &mt('Copy to new folder');
2584: $movetext = &mt('Move old');
2585: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
2586: $copytext = &mt('Copy to new board');
2587: $movetext = &mt('Move (not posts)');
2588: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
2589: $copytext = &mt('Copy to new page');
2590: $movetext = &mt('Move');
1.533 raeburn 2591: } else {
1.538 raeburn 2592: $copytext = &mt('Copy to new file');
2593: $movetext = &mt('Move');
2594: }
2595: my $output = '<br />'.
2596: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
2597: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
2598: '<label>'.
2599: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
2600: $copytext.'</label></span>'.(' 'x2).' '.
2601: '<span class="LC_nobreak"><label>'.
2602: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
2603: $movetext.'</label></span>';
2604: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
2605: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
2606: '</legend><table border="0">';
2607: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2608: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
2609: my $lastdir = $parent;
2610: my %depths = (
2611: $lastdir => 0,
2612: );
2613: my (%display,%deps);
2614: for (my $i=0; $i<@pastemaps; $i++) {
2615: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
2616: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
2617: my @subfolders = split(/,/,$subfolderstr);
2618: $deps{$lastdir} = \@subfolders;
2619: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
2620: my $depth = $depths{$lastdir} + 1;
2621: my $offset = int($depth * 4);
2622: my $indent = (' ' x $offset);
2623: for (my $j=0; $j<@subfolders; $j++) {
2624: $depths{$subfolders[$j]} = $depth;
2625: $display{$subfolders[$j]} =
2626: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
2627: '<td><label>'.
2628: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
2629: '<label>'.
2630: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
2631: &mt('Move old').'</label>'.
2632: '</td></tr>';
2633: }
1.492 raeburn 2634: }
1.538 raeburn 2635: &recurse_print(\$output,$parent,\%deps,\%display);
2636: $output .= '</table></fieldset>';
1.329 droeschl 2637: }
1.538 raeburn 2638: $output .= '</div>';
2639: return $output;
1.488 raeburn 2640: }
2641:
1.492 raeburn 2642: sub recurse_print {
1.538 raeburn 2643: my ($outputref,$dir,$deps,$display) = @_;
2644: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 2645: if (ref($deps->{$dir}) eq 'ARRAY') {
2646: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 2647: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 2648: }
2649: }
2650: }
2651:
1.488 raeburn 2652: sub supp_pasteable {
2653: my ($url) = @_;
2654: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
2655: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
2656: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
2657: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 2658: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 2659: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 2660: return 1;
2661: }
2662: return;
1.329 droeschl 2663: }
2664:
1.492 raeburn 2665: sub paste_popup_js {
1.594 damieng 2666: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 2667: show => 'Show Options',
2668: hide => 'Hide Options',
1.594 damieng 2669: );
2670: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 2671: none => 'No items selected from clipboard.',
1.492 raeburn 2672: );
1.594 damieng 2673: &html_escape(\%html_js_lt);
2674: &js_escape(\%html_js_lt);
2675: &js_escape(\%js_lt);
1.492 raeburn 2676: return <<"END";
2677:
1.538 raeburn 2678: function showPasteOptions(suffix) {
2679: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 2680: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 2681: return;
2682: }
2683:
1.538 raeburn 2684: function hidePasteOptions(suffix) {
2685: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 2686: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2687: return;
2688: }
2689:
2690: function showOptions(caller,suffix) {
2691: if (document.getElementById('pasteoptionstext_'+suffix)) {
2692: if (caller.checked) {
1.594 damieng 2693: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2694: } else {
2695: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
2696: }
2697: if (document.getElementById('pasteoptions_'+suffix)) {
2698: document.getElementById('pasteoptions_'+suffix).style.display='none';
2699: }
2700: }
1.492 raeburn 2701: return;
2702: }
2703:
1.541 raeburn 2704: function validateClipboard() {
2705: var numchk = 0;
2706: if (document.pasteform.pasting.length > 1) {
2707: for (var i=0; i<document.pasteform.pasting.length; i++) {
2708: if (document.pasteform.pasting[i].checked) {
2709: numchk ++;
2710: }
2711: }
2712: } else {
2713: if (document.pasteform.pasting.type == 'checkbox') {
2714: if (document.pasteform.pasting.checked) {
2715: numchk ++;
2716: }
2717: }
2718: }
2719: if (numchk > 0) {
2720: return true;
2721: } else {
1.594 damieng 2722: alert("$js_lt{'none'}");
1.541 raeburn 2723: return false;
2724: }
2725: }
2726:
1.575 raeburn 2727: function checkClipboard() {
2728: if (document.pasteform.pasting.length > 1) {
2729: for (var i=0; i<document.pasteform.pasting.length; i++) {
2730: document.pasteform.pasting[i].checked = true;
2731: }
2732: }
2733: return;
2734: }
2735:
2736: function uncheckClipboard() {
2737: if (document.pasteform.pasting.length >1) {
2738: for (var i=0; i<document.pasteform.pasting.length; i++) {
2739: document.pasteform.pasting[i].checked = false;
2740: }
2741: }
2742: return;
2743: }
2744:
1.492 raeburn 2745: END
2746:
2747: }
2748:
1.329 droeschl 2749: sub do_paste_from_buffer {
1.492 raeburn 2750: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 2751:
1.538 raeburn 2752: # Array of items in paste buffer
2753: my (@currpaste,%pastebuffer,%allerrors);
2754: @currpaste = split(/,/,$env{'docs.markedcopies'});
2755:
1.492 raeburn 2756: # Early out if paste buffer is empty
1.538 raeburn 2757: if (@currpaste == 0) {
1.492 raeburn 2758: return ();
1.538 raeburn 2759: }
2760: map { $pastebuffer{$_} = 1; } @currpaste;
2761:
2762: # Array of items selected items to paste
2763: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
2764:
2765: # Early out if nothing selected to paste
2766: if (@reqpaste == 0) {
2767: return();
2768: }
2769: my @topaste;
2770: foreach my $suffix (@reqpaste) {
2771: next if ($suffix =~ /\D/);
2772: next unless (exists($pastebuffer{$suffix}));
2773: push(@topaste,$suffix);
2774: }
2775:
2776: # Early out if nothing available to paste
2777: if (@topaste == 0) {
2778: return();
1.329 droeschl 2779: }
2780:
1.704 raeburn 2781: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
2782: %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
2783: %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
2784: %currltititles,$currltimax,$gotcrsltitools);
2785: $currltimax = 0;
2786: $gotcrsltitools = 0;
1.538 raeburn 2787: foreach my $suffix (@topaste) {
2788: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 2789: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 2790: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 2791: # Supplemental content may only include certain types of content
2792: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 2793: if ($folder =~ /^supplemental/) {
2794: unless (&supp_pasteable($url)) {
2795: $notinsupp{$suffix} = 1;
2796: next;
2797: }
1.492 raeburn 2798: }
1.538 raeburn 2799: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
2800: my $srcd = $1;
2801: my $srcn = $2;
1.492 raeburn 2802: # When paste buffer was populated using an active role in a different course
1.538 raeburn 2803: # check for mdc privilege in the course from which the resource was pasted
2804: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2805: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2806: $notincrs{$suffix} = 1;
2807: next;
2808: }
1.491 raeburn 2809: }
1.538 raeburn 2810: $srcdom{$suffix} = $srcd;
2811: $srcnum{$suffix} = $srcn;
1.597 raeburn 2812: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 2813: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
2814: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 2815: my ($srcd,$srcn) = split(/_/,$cid);
2816: # When paste buffer was populated using an active role in a different course
2817: # check for mdc privilege in the course from which the resource was pasted
2818: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2819: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2820: $notincrs{$suffix} = 1;
2821: next;
2822: }
2823: }
1.632 raeburn 2824: # When buffer was populated using an active role in a different course
1.704 raeburn 2825: # disallow pasting of External Tool if course is in a different domain,
2826: # or if External Tool use is not permitted in this course.
2827: if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2828: my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
2829: if ($toolcdom ne $coursedom) {
2830: $notindom{$suffix} = 1;
2831: next;
2832: } elsif ($toolcnum ne $coursenum) {
2833: my %toolsettings =
2834: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2835: my %tooltypes = &Apache::loncommon::usable_exttools();
2836: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2837: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2838: $othcrstool{$suffix} = 1;
2839: next;
2840: }
2841: if ($toolsettings{'id'} =~ /^c\d+$/) {
2842: unless ($gotcrsltitools) {
2843: %currcrsltitools =
2844: &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
2845: foreach my $item (sort(keys(%currcrsltitools))) {
2846: if (ref($currcrsltitools{$item}) eq 'HASH') {
2847: $currltimax ++;
2848: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
2849: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
2850: } else {
2851: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
2852: }
2853: }
2854: }
2855: $gotcrsltitools = 1;
2856: }
2857: }
2858: }
1.627 raeburn 2859: }
1.596 raeburn 2860: $srcdom{$suffix} = $srcd;
2861: $srcnum{$suffix} = $srcn;
1.703 raeburn 2862: } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
2863: my ($audom,$auname) = ($1,$2);
2864: # When buffer was populated using an active role in a different course
2865: # disallow pasting of published resources from Course Authoring Space
2866: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2867: if (&Apache::lonnet::is_course($audom,$auname)) {
2868: $othcrsres{$suffix} = 1;
2869: next;
2870: }
2871: }
1.491 raeburn 2872: }
1.597 raeburn 2873: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 2874: push(@dopaste,$suffix);
2875: if ($url=~/\.(page|sequence)$/) {
2876: $is_map{$suffix} = 1;
2877: }
2878: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
2879: my $oldprefix = $1;
1.492 raeburn 2880: # When pasting content from Main Content to Supplemental Content and vice versa
2881: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 2882: # a folder/page or a document).
1.538 raeburn 2883: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
2884: $prefixchg{$suffix} = 'docstosupp';
2885: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
2886: $prefixchg{$suffix} = 'supptodocs';
2887: }
1.491 raeburn 2888:
1.492 raeburn 2889: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 2890: if ($env{'docs.markedcopy_nested_'.$suffix}) {
2891: my @nested;
2892: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
2893: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2894: my @deps = map { /\d+:([\d,]+$)/ } @items;
2895: foreach my $dep (@deps) {
2896: if ($dep =~ /,/) {
2897: push(@nested,split(/,/,$dep));
2898: } else {
2899: push(@nested,$dep);
2900: }
1.492 raeburn 2901: }
1.538 raeburn 2902: foreach my $item (@nested) {
2903: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
2904: push(@{$marktomove{$suffix}},$type.'_'.$item);
2905: }
1.492 raeburn 2906: }
2907: }
1.488 raeburn 2908: }
2909: }
2910:
1.538 raeburn 2911: # Early out if nothing available to paste
2912: if (@dopaste == 0) {
2913: return ();
2914: }
2915:
2916: # Populate message hash and hashes used for main content <=> supplemental content
2917: # changes
2918:
2919: %msgs = &Apache::lonlocal::texthash (
2920: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
2921: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 2922: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.704 raeburn 2923: othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.703 raeburn 2924: othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538 raeburn 2925: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
2926: );
2927:
2928: %before = (
2929: docstosupp => {
2930: map => 'default',
2931: doc => 'docs',
2932: },
2933: supptodocs => {
2934: map => 'supplemental',
2935: doc => 'supplemental',
2936: },
2937: );
2938:
2939: %after = (
2940: docstosupp => {
2941: map => 'supplemental',
2942: doc => 'supplemental'
2943: },
2944: supptodocs => {
2945: map => 'default',
2946: doc => 'docs',
2947: },
2948: );
2949:
2950: # Retrieve information about all course maps in main content area
2951:
2952: my $allmaps = {};
1.704 raeburn 2953: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
2954: @updatetoolsenc,$updatetoolscache,$checkedsameinst,
2955: $same_institution);
1.538 raeburn 2956:
2957: # Loop over the items to paste
2958: foreach my $suffix (@dopaste) {
1.329 droeschl 2959: # Maps need to be copied first
1.538 raeburn 2960: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
2961: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 2962: %newurls,%tomove,%resdatacopy);
1.538 raeburn 2963: if (ref($marktomove{$suffix}) eq 'ARRAY') {
2964: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
2965: }
2966: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
2967: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 2968: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 2969: my $oldurl = $url;
2970: if ($is_map{$suffix}) {
1.491 raeburn 2971: # If pasting a map, check if map contains other maps
1.538 raeburn 2972: my (%hierarchy,%titles);
1.660 raeburn 2973: if (($folder =~ /^default/) && (!$donechk)) {
2974: $allmaps =
2975: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
2976: $env{"course.$env{'request.course.id'}.home"},
2977: $env{'request.course.id'});
2978: $donechk = 1;
2979: }
1.627 raeburn 2980: &contained_map_check($url,$folder,$coursenum,$coursedom,
2981: \%removefrommap,\%removeparam,\%addedmaps,
2982: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 2983: if ($url=~ m{^/uploaded/}) {
2984: my $newurl;
2985: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2986: ($newurl,my $error) =
2987: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
2988: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2989: \$title,$allmaps,\%newurls);
2990: if ($error) {
2991: $allerrors{$suffix} = $error;
2992: next;
2993: }
2994: if ($newurl ne '') {
2995: if ($newurl ne $url) {
2996: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
2997: $newsubdir{$url} = $1;
2998: }
2999: $mapchanges{$url} = 1;
1.492 raeburn 3000: }
1.538 raeburn 3001: }
3002: }
3003: if (($srcdom{$suffix} ne $coursedom) ||
3004: ($srcnum{$suffix} ne $coursenum) ||
3005: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
3006: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
3007: $coursedom,$coursenum,$srcdom{$suffix},
3008: $srcnum{$suffix},$allmaps,\%rewrites,
3009: \%retitles,\%copies,\%dbcopies,
3010: \%zombies,\%params,\%mapmoves,
3011: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 3012: \%newurls,\%resdatacopy)) {
1.538 raeburn 3013: $mapmoves{$url} = 1;
3014: }
3015: $url = $newurl;
3016: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
3017: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
3018: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
3019: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
3020: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 3021: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 3022: }
3023: } elsif ($url=~m {^/res/}) {
1.597 raeburn 3024: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 3025: push(@toclear,$suffix);
3026: # if pasting published map (main content area only) check map not already in course
3027: if ($folder =~ /^default/) {
3028: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
3029: $duplicate{$suffix} = 1;
3030: next;
1.492 raeburn 3031: }
1.491 raeburn 3032: }
3033: }
1.538 raeburn 3034: }
1.627 raeburn 3035: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 3036: my $prefix = $1;
1.648 raeburn 3037: my $fromothercrs;
1.538 raeburn 3038: #need to copy the db contents to a new one, unless this is a move.
3039: my %info = (
3040: src => $url,
3041: cdom => $coursedom,
3042: cnum => $coursenum,
1.596 raeburn 3043: );
1.649 raeburn 3044: if ($prefix eq 'ext.tool') {
1.655 raeburn 3045: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 3046: $info{'delgradable'} = 1;
3047: }
3048: }
1.596 raeburn 3049: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
3050: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
3051: $fromothercrs = 1;
3052: $info{'cdom'} = $srcdom{$suffix};
3053: $info{'cnum'} = $srcnum{$suffix};
1.704 raeburn 3054: unless ($checkedsameinst) {
3055: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
3056: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3057: if ($intdom ne '') {
3058: my $internet_names =
3059: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
3060: if (ref($internet_names) eq 'ARRAY') {
3061: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
3062: $same_institution = 1;
3063: }
3064: }
3065: }
3066: $checkedsameinst = 1;
3067: }
1.596 raeburn 3068: }
3069: }
3070: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 3071: my (%lockerr,$msg);
1.538 raeburn 3072: my ($newurl,$result,$errtext) =
1.704 raeburn 3073: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
3074: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.538 raeburn 3075: if ($result eq 'ok') {
3076: $url = $newurl;
3077: $title=&mt('Copy of').' '.$title;
3078: } else {
3079: if ($prefix eq 'smppg') {
3080: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
3081: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 3082: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 3083: } elsif ($prefix eq 'ext.tool') {
3084: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 3085: }
3086: $results{$suffix} = $result;
3087: $msgerrs{$suffix} = $msg;
3088: $lockerrs{$suffix} = $lockerr{$prefix};
3089: next;
3090: }
3091: if ($lockerr{$prefix}) {
3092: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 3093: }
1.489 raeburn 3094: }
3095: }
1.538 raeburn 3096: $title = &LONCAPA::map::qtunescape($title);
3097: my $ext='false';
3098: if ($url=~m{^http(|s)://}) { $ext='true'; }
3099: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
3100: if ($folder !~ /^supplemental/) {
3101: (undef,undef,$title) =
3102: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
3103: }
3104: } else {
3105: if ($folder=~/^supplemental/) {
3106: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3107: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 3108: }
1.533 raeburn 3109: }
1.491 raeburn 3110:
3111: # For uploaded files (excluding pages/sequences) path in copied file is changed
3112: # if paste is from Main to Supplemental (or vice versa), or if pasting between
3113: # courses.
3114:
1.538 raeburn 3115: unless ($is_map{$suffix}) {
3116: my $newidx;
1.492 raeburn 3117: # Now insert the URL at the bottom
1.538 raeburn 3118: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
3119: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
3120: my $relpath = $1;
3121: if ($relpath ne '') {
3122: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
3123: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
3124: my $newprefix = $newloc;
3125: if ($newloc eq 'default') {
3126: $newprefix = 'docs';
3127: }
3128: if ($newdocsdir eq '') {
3129: $newdocsdir = 'default';
3130: }
1.630 raeburn 3131: if (($prefixchg{$suffix}) ||
3132: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 3133: ($srcnum{$suffix} ne $coursenum) ||
3134: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
3135: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
3136: $url =
3137: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
3138: &Apache::lonnet::getfile($oldurl));
3139: if ($url eq '/adm/notfound.html') {
3140: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
3141: next;
3142: } else {
3143: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
3144: $newsubpath =~ s{/+$}{/};
3145: $docmoves{$oldurl} = $newsubpath;
3146: }
1.491 raeburn 3147: }
3148: }
1.597 raeburn 3149: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
3150: my $template = $1;
3151: if ($newidx) {
3152: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
3153: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
3154: }
1.649 raeburn 3155: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 3156: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 3157: my $marker = (split(m{/},$url))[4];
3158: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
3159: my $val = 'no';
3160: if ($toolsettings{'gradable'}) {
3161: $val = 'yes';
3162: }
3163: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
3164: 'string_yesno');
3165: &remember_parms($newidx,'gradable','set',$val);
3166: }
1.491 raeburn 3167: }
1.538 raeburn 3168: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
3169: ':'.$ext.':normal:res';
3170: push(@LONCAPA::map::order,$newidx);
3171: # Store the result
3172: my ($errtext,$fatal) =
3173: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3174: if ($fatal) {
3175: $save_err .= $errtext;
3176: $allresult = 'fail';
3177: }
1.488 raeburn 3178: }
1.538 raeburn 3179:
1.597 raeburn 3180: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
3181: # resourcedata for simpleproblems copied from another course
1.538 raeburn 3182: unless ($allresult eq 'fail') {
3183: my %updated = (
3184: rewrites => \%rewrites,
3185: zombies => \%zombies,
3186: removefrommap => \%removefrommap,
3187: removeparam => \%removeparam,
3188: dbcopies => \%dbcopies,
1.597 raeburn 3189: resdatacopy => \%resdatacopy,
1.538 raeburn 3190: retitles => \%retitles,
3191: );
3192: my %info = (
3193: newsubdir => \%newsubdir,
3194: params => \%params,
3195: );
3196: if ($prefixchg{$suffix}) {
3197: $info{'before'} = $before{$prefixchg{$suffix}};
3198: $info{'after'} = $after{$prefixchg{$suffix}};
3199: }
3200: my %moves = (
3201: copies => \%copies,
3202: docmoves => \%docmoves,
3203: mapmoves => \%mapmoves,
3204: );
3205: (my $result,$msgs{$suffix},my $lockerror) =
3206: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
3207: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
3208: $url,'paste');
3209: $lockerrors .= $lockerror;
3210: if ($result eq 'ok') {
3211: if ($is_map{$suffix}) {
3212: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3213: $folder.'.'.$container);
3214: if ($fatal) {
3215: $allresult = 'failread';
3216: } else {
3217: if ($#LONCAPA::map::order<1) {
3218: my $idx=&LONCAPA::map::getresidx();
3219: if ($idx<=0) { $idx=1; }
3220: $LONCAPA::map::order[0]=$idx;
3221: $LONCAPA::map::resources[$idx]='';
3222: }
3223: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
3224: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
3225: ':'.$ext.':normal:res';
3226: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 3227:
3228: # Store the result
1.538 raeburn 3229: my ($errtext,$fatal) =
3230: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3231: if ($fatal) {
3232: $save_err .= $errtext;
3233: $allresult = 'failstore';
3234: }
3235: }
3236: }
3237: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
3238: push(@toclear,$suffix);
3239: }
3240: }
1.492 raeburn 3241: }
3242: }
1.704 raeburn 3243: if (($updatetoolscache) || (@updatetoolsenc)) {
3244: &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
3245: \@updatetoolsenc);
3246: }
1.538 raeburn 3247: &clear_from_buffer(\@toclear,\@currpaste);
3248: my $msgsarray;
3249: foreach my $suffix (keys(%msgs)) {
3250: if (ref($msgs{$suffix}) eq 'ARRAY') {
3251: $msgsarray .= join(',',@{$msgs{$suffix}});
3252: }
3253: }
3254: return ($allresult,$save_err,$msgsarray,$lockerrors);
3255: }
1.533 raeburn 3256:
1.538 raeburn 3257: sub do_buffer_empty {
3258: my @currpaste = split(/,/,$env{'docs.markedcopies'});
3259: if (@currpaste == 0) {
3260: return &mt('Clipboard is already empty');
3261: }
3262: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
3263: if (@toclear == 0) {
3264: return &mt('Nothing selected to clear from clipboard');
3265: }
3266: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
3267: if ($numdel) {
3268: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
3269: } else {
3270: return &mt('Clipboard unchanged');
1.492 raeburn 3271: }
1.538 raeburn 3272: return;
3273: }
3274:
3275: sub clear_from_buffer {
3276: my ($toclear,$currpaste) = @_;
3277: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
3278: my %pastebuffer;
3279: map { $pastebuffer{$_} = 1; } @{$currpaste};
3280: my $numdel = 0;
3281: foreach my $suffix (@{$toclear}) {
3282: next if ($suffix =~ /\D/);
3283: next unless (exists($pastebuffer{$suffix}));
3284: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
3285: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
3286: delete($pastebuffer{$suffix});
3287: $numdel ++;
3288: }
3289: }
3290: my $newbuffer = join(',',sort(keys(%pastebuffer)));
3291: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
3292: return $numdel;
1.492 raeburn 3293: }
3294:
1.704 raeburn 3295: sub update_ltitools_caches {
3296: my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
3297: my $hashid=$coursedom.'_'.$coursenum;
3298: if ($updatetoolscache) {
3299: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3300: }
3301: if ((ref($updatetoolsenc) eq 'ARRAY') &&
3302: (@{$updatetoolsenc})) {
3303: my @ids=&Apache::lonnet::current_machine_ids();
3304: my $updatedone;
3305: foreach my $lonhost (@{$updatetoolsenc}) {
3306: if (grep(/^\Q$lonhost\E$/,@ids)) {
3307: unless ($updatedone) {
3308: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
3309: }
3310: $updatedone = 1;
3311: } else {
3312: &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
3313: }
3314: }
3315: }
3316: return;
3317: }
3318:
1.492 raeburn 3319: sub get_newmap_url {
3320: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
3321: $titleref,$allmaps,$newurls) = @_;
3322: my $newurl;
3323: if ($url=~ m{^/uploaded/}) {
3324: $$titleref=&mt('Copy of').' '.$$titleref;
3325: }
3326: my $now = time;
3327: my $suffix=$$.int(rand(100)).$now;
3328: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
3329: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
3330: my $path = $1;
3331: my $prefix = $2;
3332: my $ancestor = $3;
3333: if (length($ancestor) > 10) {
3334: $ancestor = substr($ancestor,-10,10);
3335: }
3336: my $newid;
3337: if ($prefixchg) {
3338: if ($folder =~ /^supplemental/) {
3339: $prefix =~ s/^default/supplemental/;
3340: } else {
3341: $prefix =~ s/^supplemental/default/;
3342: }
3343: }
3344: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3345: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3346: } else {
3347: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
3348: }
3349: my $counter = 0;
3350: my $is_unique = &uniqueness_check($newurl);
3351: if ($folder =~ /^default/) {
3352: if ($allmaps->{$newurl}) {
3353: $is_unique = 0;
3354: }
3355: }
3356: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
3357: $counter ++;
3358: $suffix ++;
3359: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3360: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3361: } else {
3362: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
3363: }
3364: $is_unique = &uniqueness_check($newurl);
3365: }
3366: if ($is_unique) {
3367: $newurls->{$newurl} = 1;
3368: } else {
3369: if ($url=~/\.page$/) {
3370: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
3371: } else {
3372: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
3373: }
3374: }
1.329 droeschl 3375: }
1.492 raeburn 3376: return ($newurl);
1.329 droeschl 3377: }
3378:
1.488 raeburn 3379: sub dbcopy {
1.704 raeburn 3380: my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
3381: $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.533 raeburn 3382: my ($url,$result,$errtext);
3383: if (ref($dbref) eq 'HASH') {
1.596 raeburn 3384: $url = $dbref->{'src'};
1.627 raeburn 3385: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 3386: my $prefix = $1;
1.627 raeburn 3387: if ($prefix eq 'ext.tool') {
3388: $prefix = 'exttool';
3389: }
1.533 raeburn 3390: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3391: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3392: my $db_name;
3393: my $marker = (split(m{/},$url))[4];
3394: $marker=~s/\D//g;
3395: if ($dbref->{'src'} =~ m{/smppg$}) {
3396: $db_name =
3397: &Apache::lonsimplepage::get_db_name($url,$marker,
3398: $dbref->{'cdom'},
3399: $dbref->{'cnum'});
1.627 raeburn 3400: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
3401: $db_name = 'exttool_'.$marker;
1.533 raeburn 3402: } else {
3403: $db_name = 'bulletinpage_'.$marker;
3404: }
3405: my ($suffix,$freedlock,$error) =
3406: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
3407: $coursedom,$coursenum,
3408: 'concat');
3409: if (!$suffix) {
3410: if ($prefix eq 'smppg') {
3411: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 3412: } elsif ($prefix eq 'exttool') {
3413: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 3414: } else {
1.565 bisitz 3415: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 3416: }
3417: if ($error) {
3418: $errtext .= '<br />'.$error;
3419: }
3420: } else {
3421: #need to copy the db contents to a new one.
3422: my %contents=&Apache::lonnet::dump($db_name,
3423: $dbref->{'cdom'},
3424: $dbref->{'cnum'});
1.704 raeburn 3425: my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
3426: if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
3427: if ($contents{'id'} =~ /^(|c)(\d+)$/) {
3428: $oldtoolid = $2;
3429: if ($1 eq 'c') {
3430: $defincrs = 1;
3431: %toolinfo =
3432: &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
3433: } else {
3434: %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
3435: }
3436: if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
3437: if ($toolinfo{$oldtoolid}{'passback'}) {
3438: $toolpassback = 1;
3439: }
3440: if ($toolinfo{$oldtoolid}{'roster'}) {
3441: $toolroster = 1;
3442: }
3443: } else {
3444: $toolcopyerror = 1;
3445: $errtext = &mt('Could not retrieve original settings for pasted external tool.');
3446: }
3447: }
3448: unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
3449: $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
3450: if ($contents{'crstitle'} ne '') {
3451: $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
3452: }
3453: if (($defincrs) && (!$toolcopyerror)) {
3454: my %newtool;
3455: my $oldcdom = $dbref->{'cdom'};
3456: my $oldcnum = $dbref->{'cnum'};
3457: my $title = $toolinfo{$oldtoolid}{'title'};
3458: if (ref($currltititles) eq 'HASH') {
3459: if (exists($currltititles->{$title})) {
3460: $title .= ' (copied from another course)';
3461: }
3462: }
3463: my ($newid,$iderror) =
3464: &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
3465: if ($newid =~ /^\d+$/) {
3466: %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
3467: $newtool{$newid}{'title'} = $title;
3468: if (ref($currltimax)) {
3469: $newtool{$newid}{'order'} = $$currltimax;
3470: }
3471: if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
3472: my $fname = $1;
3473: my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
3474: if ($content eq '-1') {
3475: delete($newtool{$newid}{'image'});
3476: } else {
3477: $env{'form.'.$suffix.'.image'} = $content;
3478: my $newlogo =
3479: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
3480: delete($env{'form.'.$suffix.'.image'});
3481: if ($newlogo =~ m{^/uploaded/}) {
3482: $newtool{$newid}{'image'} = $newlogo;
3483: } else {
3484: delete($newtool{$newid}{'image'});
3485: }
3486: }
3487: }
3488: my $newusable;
3489: if ($same_institution) {
3490: my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
3491: if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
3492: my %newtoolsenc;
3493: %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
3494: my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
3495: if ($putres eq 'ok') {
3496: if (ref($updatetoolsenc) eq 'ARRAY') {
3497: my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
3498: unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
3499: push(@{$updatetoolsenc},$newhome);
3500: }
3501: }
3502: $newusable = 1;
3503: }
3504: }
3505: }
3506: if ($newtool{$newid}{'usable'}) {
3507: unless ($newusable) {
3508: delete($newtool{$newid}{'usable'});
3509: }
3510: }
3511: my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
3512: if ($putres eq 'ok') {
3513: $contents{'id'} = "c$newid";
3514: if (ref($updatetoolscache)) {
3515: $$updatetoolscache ++;
3516: }
3517: if (ref($currltititles->{$title}) eq 'ARRAY') {
3518: push(@{$currltititles->{$title}},$newid);
3519: } else {
3520: $currltititles->{$title} = [$newid];
3521: }
3522: if (ref($currltimax)) {
3523: $$currltimax ++;
3524: }
3525: } else {
3526: $toolcopyerror = 1;
3527: $errtext = &mt('Unable to save external tool definition in Course Settings.');
3528: }
3529: } else {
3530: $toolcopyerror = 1;
3531: $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
3532: }
3533: }
3534: }
3535: }
1.533 raeburn 3536: if (exists($contents{'uploaded.photourl'})) {
3537: my $photo = $contents{'uploaded.photourl'};
3538: my ($subdir,$fname) =
3539: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 3540: my $newphoto;
1.533 raeburn 3541: if ($fname ne '') {
3542: my $content = &Apache::lonnet::getfile($photo);
3543: unless ($content eq '-1') {
3544: $env{'form.'.$suffix.'.photourl'} = $content;
3545: $newphoto =
3546: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
3547: delete($env{'form.'.$suffix.'.photourl'});
3548: }
3549: }
3550: if ($newphoto =~ m{^/uploaded/}) {
3551: $contents{'uploaded.photourl'} = $newphoto;
3552: }
3553: }
3554: $db_name =~ s{_\d*$ }{_$suffix}x;
1.704 raeburn 3555: if ($prefix eq 'exttool') {
3556: unless ($toolcopyerror) {
3557: foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
3558: if (exists($contents{$key})) {
3559: delete($contents{$key});
3560: }
3561: }
3562: if ($dbref->{'delgradable'}) {
3563: if (exists($contents{'gradable'})) {
3564: delete($contents{'gradable'});
3565: }
3566: }
3567: if ($toolpassback) {
3568: if ($contents{'gradable'}) {
3569: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3570: $contents{'gradesecret'} = $gradesecret;
3571: $contents{'gradesecretdate'} = time;
3572: }
3573: }
3574: if ($toolroster) {
3575: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3576: $contents{'rostersecret'} = $rostersecret;
3577: $contents{'rostersecretdate'} = time;
3578: }
3579: }
1.649 raeburn 3580: }
1.704 raeburn 3581: if (($prefix eq 'exttool') && ($toolcopyerror)) {
3582: $result = 'error';
3583: } else {
3584: $result=&Apache::lonnet::put($db_name,\%contents,
3585: $coursedom,$coursenum);
3586: if ($result eq 'ok') {
3587: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
3588: }
1.533 raeburn 3589: }
3590: }
3591: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 3592: $lockerrorsref->{$prefix} =
1.533 raeburn 3593: '<div class="LC_error">'.
3594: &mt('There was a problem removing a lockfile.');
3595: if ($prefix eq 'smppg') {
1.560 raeburn 3596: $lockerrorsref->{$prefix} .=
1.559 raeburn 3597: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 3598: } elsif ($prefix eq 'exttool') {
3599: $lockerrorsref->{$prefix} .=
3600: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 3601: } else {
1.565 bisitz 3602: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 3603: }
1.560 raeburn 3604: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
3605: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
3606: '</div>';
1.533 raeburn 3607: }
3608: }
3609: } elsif ($url =~ m{/syllabus$}) {
3610: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3611: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3612: if (($dbref->{'cdom'} ne $coursedom) ||
3613: ($dbref->{'cnum'} ne $coursenum)) {
3614: my %contents=&Apache::lonnet::dump('syllabus',
3615: $dbref->{'cdom'},
3616: $dbref->{'cnum'});
3617: $result=&Apache::lonnet::put('syllabus',\%contents,
3618: $coursedom,$coursenum);
3619: }
3620: }
1.488 raeburn 3621: }
3622: }
1.533 raeburn 3623: return ($url,$result,$errtext);
1.488 raeburn 3624: }
3625:
1.597 raeburn 3626: sub copy_templated_files {
3627: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
3628: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
3629: my $srccontainer = 'sequence';
3630: if ($srcwaspage) {
3631: $srccontainer = 'page';
3632: }
3633: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
3634: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
3635: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
3636: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
3637: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
3638: $template.'.problem';
3639: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
3640: if ($template eq 'simpleproblem') {
3641: $srcprefix .= '.0.';
3642: my $weightprefix = $newprefix;
3643: $newprefix .= '.0.';
3644: my @simpleprobqtypes = qw(radio option string essay numerical);
3645: my $qtype=$srcparms{$srcprefix.'questiontype'};
3646: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 3647: my %newdata = (
3648: $newprefix.'questiontype' => $qtype,
3649: );
1.597 raeburn 3650: foreach my $type (@simpleprobqtypes) {
3651: if ($type eq $qtype) {
3652: $newdata{"$weightprefix.$type.weight"}=1;
3653: } else {
3654: $newdata{"$weightprefix.$type.weight"}=0;
3655: }
3656: }
3657: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
3658: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
3659: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
3660: if ($qtype eq 'numerical') {
3661: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
3662: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
3663: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
3664: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
3665: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3666: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3667: unless (defined($maxfoils)) { $maxfoils=10; }
3668: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3669: if ($maxfoils<=0) { $maxfoils=10; }
3670: my $randomize=$srcparms{$srcprefix.'randomize'};
3671: unless (defined($randomize)) { $randomize='yes'; }
3672: unless ($randomize eq 'no') { $randomize='yes'; }
3673: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3674: $newdata{$newprefix.'randomize'} = $randomize;
3675: if ($qtype eq 'option') {
3676: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3677: }
3678: for (my $i=1; $i<=10; $i++) {
3679: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3680: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3681: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3682: }
3683:
3684: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3685: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3686: unless (defined($maxfoils)) { $maxfoils=10; }
3687: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3688: if ($maxfoils<=0) { $maxfoils=10; }
3689: my $randomize=$srcparms{$srcprefix.'randomize'};
3690: unless (defined($randomize)) { $randomize='yes'; }
3691: unless ($randomize eq 'no') { $randomize='yes'; }
3692: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3693: $newdata{$newprefix.'randomize'} = $randomize;
3694: if ($qtype eq 'option') {
3695: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3696: }
3697: for (my $i=1; $i<=10; $i++) {
3698: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3699: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3700: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3701: }
3702: } elsif ($qtype eq 'string') {
3703: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
3704: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
3705: }
3706: if (keys(%newdata)) {
3707: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
3708: $coursenum);
3709: if ($putres eq 'ok') {
3710: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
3711: }
3712: }
3713: }
3714: }
3715: }
3716:
1.329 droeschl 3717: sub uniqueness_check {
3718: my ($newurl) = @_;
3719: my $unique = 1;
3720: foreach my $res (@LONCAPA::map::order) {
3721: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3722: $url=&LONCAPA::map::qtescape($url);
3723: if ($newurl eq $url) {
3724: $unique = 0;
1.344 bisitz 3725: last;
1.329 droeschl 3726: }
3727: }
3728: return $unique;
3729: }
3730:
1.488 raeburn 3731: sub contained_map_check {
1.627 raeburn 3732: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
3733: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 3734: my $content = &Apache::lonnet::getfile($url);
3735: unless ($content eq '-1') {
3736: my $parser = HTML::TokeParser->new(\$content);
3737: $parser->attr_encoded(1);
3738: while (my $token = $parser->get_token) {
3739: next if ($token->[0] ne 'S');
3740: if ($token->[1] eq 'resource') {
3741: next if ($token->[2]->{'type'} eq 'zombie');
3742: my $ressrc = $token->[2]->{'src'};
1.704 raeburn 3743: if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
3744: my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
1.627 raeburn 3745: unless ($srcdom eq $coursedom) {
3746: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3747: next;
3748: }
1.704 raeburn 3749: unless ($srcnum eq $coursenum) {
3750: my %toolsettings =
3751: &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
3752: my %tooltypes = &Apache::loncommon::usable_exttools();
3753: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
3754: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
3755: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3756: next;
3757: }
3758: }
1.627 raeburn 3759: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 3760: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 3761: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 3762: next;
3763: }
3764: }
1.703 raeburn 3765: if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
3766: my ($srcdom,$srcnum) = ($1,$2);
3767: unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
3768: if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
3769: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3770: next;
3771: }
3772: }
3773: }
1.492 raeburn 3774: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
3775: if ($1 eq 'uploaded') {
3776: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
3777: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 3778: } else {
1.492 raeburn 3779: if ($allmaps->{$ressrc}) {
1.529 raeburn 3780: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 3781: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
3782: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3783: } else {
3784: $addedmaps->{$ressrc} = [$url];
3785: }
1.488 raeburn 3786: }
1.627 raeburn 3787: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
3788: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 3789: }
1.492 raeburn 3790: } elsif ($token->[1] eq 'param') {
1.488 raeburn 3791: if ($folder =~ /^supplemental/) {
1.492 raeburn 3792: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
3793: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
3794: } else {
3795: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
3796: }
1.488 raeburn 3797: }
3798: }
3799: }
3800: }
3801: return;
3802: }
3803:
3804: sub url_paste_fixups {
1.533 raeburn 3805: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
3806: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 3807: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 3808: my $checktitle;
3809: if (($prefixchg) &&
1.492 raeburn 3810: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 3811: $checktitle = 1;
3812: }
1.492 raeburn 3813: my $skip;
3814: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
3815: my $mapid = $1.$2;
3816: if ($tomove->{$mapid}) {
3817: $skip = 1;
3818: }
3819: }
1.491 raeburn 3820: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 3821: return if ($file eq '-1');
3822: my $parser = HTML::TokeParser->new(\$file);
3823: $parser->attr_encoded(1);
1.491 raeburn 3824: my $changed = 0;
1.488 raeburn 3825: while (my $token = $parser->get_token) {
3826: next if ($token->[0] ne 'S');
3827: if ($token->[1] eq 'resource') {
3828: my $ressrc = $token->[2]->{'src'};
3829: next if ($ressrc eq '');
1.491 raeburn 3830: my $id = $token->[2]->{'id'};
1.492 raeburn 3831: my $title = $token->[2]->{'title'};
1.491 raeburn 3832: if ($checktitle) {
3833: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 3834: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3835: }
3836: }
1.488 raeburn 3837: next if ($token->[2]->{'type'} eq 'external');
3838: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 3839: next if ($skip);
1.532 raeburn 3840: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3841: $changed = 1;
3842: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3843: my $srcdom = $1;
3844: my $srcnum = $2;
1.488 raeburn 3845: my $rem = $3;
1.492 raeburn 3846: my $newurl;
3847: my $mapname;
3848: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
3849: my $prefix = $1;
3850: $mapname = $prefix.$2;
3851: if ($tomove->{$mapname}) {
1.533 raeburn 3852: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
3853: $srcdom,$srcnum,$allmaps,$rewrites,
3854: $retitles,$copies,$dbcopies,$zombies,
3855: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 3856: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 3857: next;
3858: } else {
3859: ($newurl,my $error) =
3860: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
3861: $srcdom,$srcnum,\$title,$allmaps,$newurls);
3862: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
3863: $newsubdir->{$ressrc} = $1;
3864: }
3865: if ($error) {
3866: next;
3867: }
3868: }
3869: }
3870: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
3871: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
3872:
1.488 raeburn 3873: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 3874: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3875: $mapchanges->{$ressrc} = 1;
1.533 raeburn 3876: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
3877: $cnum,$srcdom,$srcnum,$allmaps,
3878: $rewrites,$retitles,$copies,$dbcopies,
3879: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 3880: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 3881: $mapmoves->{$ressrc} = 1;
3882: }
3883: $changed = 1;
1.488 raeburn 3884: } else {
1.532 raeburn 3885: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 3886: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 3887: $changed = 1;
1.488 raeburn 3888: }
3889: }
1.649 raeburn 3890: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 3891: next if ($skip);
1.492 raeburn 3892: my $srcdom = $1;
3893: my $srcnum = $2;
1.649 raeburn 3894: my $rem = $3;
3895: my ($is_exttool,$exttoolchg);
3896: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 3897: $is_exttool = 1;
1.649 raeburn 3898: }
1.492 raeburn 3899: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 3900: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 3901: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3902: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3903: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3904: $changed = 1;
1.649 raeburn 3905: if ($is_exttool) {
3906: $exttoolchg = 1;
3907: }
1.700 raeburn 3908: } elsif (($is_exttool) &&
1.649 raeburn 3909: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3910: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3911: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3912: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3913: $changed = 1;
3914: $exttoolchg = 1;
3915: }
3916: if (($is_exttool) && ($prefixchg)) {
3917: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
3918: if ($exttoolchg) {
3919: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
3920: }
3921: }
1.533 raeburn 3922: }
3923: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
3924: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
3925: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3926: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3927: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
3928: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 3929: $changed = 1;
1.488 raeburn 3930: }
1.597 raeburn 3931: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
3932: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
3933: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
3934: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
3935: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
3936: }
1.488 raeburn 3937: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3938: next if ($skip);
3939: my $srcdom = $1;
3940: my $srcnum = $2;
3941: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 3942: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3943: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3944: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 3945: $changed = 1;
1.488 raeburn 3946: }
3947: }
3948: } elsif ($token->[1] eq 'param') {
1.492 raeburn 3949: next if ($skip);
1.488 raeburn 3950: my $to = $token->[2]->{'to'};
3951: if ($to ne '') {
3952: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 3953: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 3954: } else {
3955: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
3956: }
3957: }
3958: }
3959: }
1.491 raeburn 3960: return $changed;
1.488 raeburn 3961: }
3962:
3963: sub apply_fixups {
1.529 raeburn 3964: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
3965: $oldurl,$url,$caller) = @_;
3966: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 3967: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.704 raeburn 3968: %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
3969: %currltititles,$currltimax);
3970: $currltimax = 0;
1.529 raeburn 3971: if (ref($updated) eq 'HASH') {
3972: if (ref($updated->{'rewrites'}) eq 'HASH') {
3973: %rewrites = %{$updated->{'rewrites'}};
3974: }
3975: if (ref($updated->{'zombies'}) eq 'HASH') {
3976: %zombies = %{$updated->{'zombies'}};
3977: }
3978: if (ref($updated->{'removefrommap'}) eq 'HASH') {
3979: %removefrommap = %{$updated->{'removefrommap'}};
3980: }
3981: if (ref($updated->{'removeparam'}) eq 'HASH') {
3982: %removeparam = %{$updated->{'removeparam'}};
3983: }
3984: if (ref($updated->{'dbcopies'}) eq 'HASH') {
3985: %dbcopies = %{$updated->{'dbcopies'}};
3986: }
3987: if (ref($updated->{'retitles'}) eq 'HASH') {
3988: %retitles = %{$updated->{'retitles'}};
3989: }
1.597 raeburn 3990: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
3991: %resdatacopy = %{$updated->{'resdatacopy'}};
3992: }
1.529 raeburn 3993: }
3994: if (ref($info) eq 'HASH') {
3995: if (ref($info->{'newsubdir'}) eq 'HASH') {
3996: %newsubdir = %{$info->{'newsubdir'}};
3997: }
3998: if (ref($info->{'params'}) eq 'HASH') {
3999: %params = %{$info->{'params'}};
4000: }
4001: if (ref($info->{'before'}) eq 'HASH') {
4002: %before = %{$info->{'before'}};
4003: }
4004: if (ref($info->{'after'}) eq 'HASH') {
4005: %after = %{$info->{'after'}};
4006: }
4007: }
4008: if (ref($moves) eq 'HASH') {
4009: if (ref($moves->{'copies'}) eq 'HASH') {
4010: %copies = %{$moves->{'copies'}};
4011: }
4012: if (ref($moves->{'docmoves'}) eq 'HASH') {
4013: %docmoves = %{$moves->{'docmoves'}};
4014: }
4015: if (ref($moves->{'mapmoves'}) eq 'HASH') {
4016: %mapmoves = %{$moves->{'mapmoves'}};
4017: }
4018: }
4019: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 4020: my @allcopies;
1.529 raeburn 4021: if (exists($copies{$key})) {
4022: if (ref($copies{$key}) eq 'HASH') {
4023: my %added;
4024: foreach my $innerkey (keys(%{$copies{$key}})) {
4025: if (($innerkey ne '') && (!$added{$innerkey})) {
4026: push(@allcopies,$innerkey);
4027: $added{$innerkey} = 1;
4028: }
1.491 raeburn 4029: }
1.529 raeburn 4030: undef(%added);
1.491 raeburn 4031: }
4032: }
4033: if ($key eq $oldurl) {
1.529 raeburn 4034: if ((exists($docmoves{$key}))) {
1.532 raeburn 4035: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 4036: push(@allcopies,$oldurl);
4037: }
4038: }
4039: }
4040: if (@allcopies > 0) {
4041: foreach my $item (@allcopies) {
1.492 raeburn 4042: my ($relpath,$oldsubdir,$fname) =
4043: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 4044: if ($fname ne '') {
4045: my $content = &Apache::lonnet::getfile($item);
4046: unless ($content eq '-1') {
4047: my $storefn;
1.529 raeburn 4048: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
4049: $storefn = $docmoves{$key};
1.491 raeburn 4050: } else {
4051: $storefn = $relpath;
4052: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4053: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
4054: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 4055: }
1.529 raeburn 4056: if ($newsubdir{$key}) {
1.532 raeburn 4057: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 4058: }
4059: }
4060: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
4061: my $copyurl =
4062: &Apache::lonclonecourse::writefile($env{'request.course.id'},
4063: $storefn.$fname,$content);
4064: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 4065: if (exists($docmoves{$oldurl})) {
1.491 raeburn 4066: return &mt('Paste failed: an error occurred copying the file.');
4067: } elsif (ref($errors) eq 'HASH') {
4068: $errors->{$item} = 1;
1.489 raeburn 4069: }
4070: }
1.488 raeburn 4071: }
4072: }
1.491 raeburn 4073: }
4074: }
4075: }
1.529 raeburn 4076: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 4077: my $storefn=$key;
4078: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4079: if ($prefixchg && $before{'map'} && $after{'map'}) {
4080: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 4081: }
1.529 raeburn 4082: if ($newsubdir{$key}) {
4083: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 4084: }
1.491 raeburn 4085: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 4086: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
4087: ($after{'map'} eq 'default') &&
4088: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
4089: $mapcontent = '<map>'."\n".
4090: '<resource id="1" src="" type="start" />'."\n".
4091: '<link from="1" to="2" index="1" />'."\n".
4092: '<resource id="2" src="" type="finish" />'."\n".
4093: '</map>';
4094: }
1.491 raeburn 4095: if ($mapcontent eq '-1') {
4096: if (ref($errors) eq 'HASH') {
4097: $errors->{$key} = 1;
4098: }
4099: } else {
4100: my $newmap =
4101: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
4102: $mapcontent);
4103: if ($newmap eq '/adm/notfound.html') {
4104: if (ref($errors) eq 'HASH') {
4105: $errors->{$key} = 1;
1.489 raeburn 4106: }
1.488 raeburn 4107: }
4108: }
4109: }
1.491 raeburn 4110: my %updates;
4111: if ($is_map) {
1.529 raeburn 4112: if (ref($updated) eq 'HASH') {
4113: foreach my $type (keys(%{$updated})) {
4114: if (ref($updated->{$type}) eq 'HASH') {
4115: foreach my $key (keys(%{$updated->{$type}})) {
4116: $updates{$key} = 1;
4117: }
4118: }
4119: }
1.491 raeburn 4120: }
1.704 raeburn 4121: my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.491 raeburn 4122: foreach my $key (keys(%updates)) {
1.492 raeburn 4123: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 4124: if (ref($rewrites{$key}) eq 'HASH') {
4125: %torewrite = %{$rewrites{$key}};
1.491 raeburn 4126: }
1.529 raeburn 4127: if (ref($retitles{$key}) eq 'HASH') {
4128: %toretitle = %{$retitles{$key}};
1.491 raeburn 4129: }
1.529 raeburn 4130: if (ref($removefrommap{$key}) eq 'HASH') {
4131: %toremove = %{$removefrommap{$key}};
1.491 raeburn 4132: }
1.529 raeburn 4133: if (ref($removeparam{$key}) eq 'HASH') {
4134: %remparam = %{$removeparam{$key}};
1.492 raeburn 4135: }
1.529 raeburn 4136: if (ref($zombies{$key}) eq 'HASH') {
4137: %zombie = %{$zombies{$key}};
1.491 raeburn 4138: }
1.529 raeburn 4139: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 4140: foreach my $idx (keys(%{$dbcopies{$key}})) {
4141: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.704 raeburn 4142: my $oldurl = $dbcopies{$key}{$idx}{'src'};
4143: my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
4144: my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
4145: my $oldmarker;
4146: if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
4147: $oldmarker = $1;
4148: unless (($gotcrsltitools) ||
4149: (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
4150: my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
4151: if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
4152: unless ($gotcrsltitools) {
4153: %currcrsltitools =
4154: &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
4155: foreach my $item (sort(keys(%currcrsltitools))) {
4156: if (ref($currcrsltitools{$item}) eq 'HASH') {
4157: $currltimax ++;
4158: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
4159: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
4160: } else {
4161: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
4162: }
4163: }
4164: }
4165: $gotcrsltitools = 1;
4166: }
4167: unless ($checkedsameinst) {
4168: my $primary_id = &Apache::lonnet::domain($cdom,'primary');
4169: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4170: if ($intdom ne '') {
4171: my $internet_names =
4172: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4173: if (ref($internet_names) eq 'ARRAY') {
4174: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4175: $same_institution = 1;
4176: }
4177: }
4178: }
4179: $checkedsameinst = 1;
4180: }
4181: }
4182: }
4183: }
1.533 raeburn 4184: my ($newurl,$result,$errtext) =
1.704 raeburn 4185: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
4186: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.533 raeburn 4187: if ($result eq 'ok') {
4188: $newdb{$idx} = $newurl;
1.704 raeburn 4189: if ($newurl =~ /ext\.tool$/) {
4190: if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
4191: if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
4192: my $newmarker = $1;
4193: unless ($oldmarker eq $newmarker) {
4194: $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
4195: }
4196: }
4197: }
4198: }
1.533 raeburn 4199: } elsif (ref($errors) eq 'HASH') {
4200: $errors->{$key} = 1;
4201: }
4202: push(@msgs,$errtext);
4203: }
1.491 raeburn 4204: }
4205: }
1.597 raeburn 4206: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 4207: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 4208: foreach my $idx (keys(%{$resdatacopy{$key}})) {
4209: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
4210: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
4211: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
4212: my $template = $1;
4213: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
4214: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
4215: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
4216: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 4217: unless ($gotnewmapname) {
4218: ($newmapname) = ($key =~ m{/([^/]+)$});
4219: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
4220: if ($newsubdir{$key}) {
4221: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
4222: }
4223: $gotnewmapname = 1;
4224: }
1.597 raeburn 4225: my $srcmapinfo = $srcfolder.':'.$idx;
4226: if ($srccontainer eq 'page') {
4227: $srcmapinfo .= ':1';
4228: }
4229: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
4230: $cnum,$template,$idx,$newmapname);
4231: }
4232: }
4233: }
4234: }
4235: }
1.529 raeburn 4236: if (ref($params{$key}) eq 'HASH') {
4237: %currparam = %{$params{$key}};
1.492 raeburn 4238: }
4239: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
4240: if ($fatal) {
1.533 raeburn 4241: return ($errtext);
1.492 raeburn 4242: }
4243: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
4244: if (defined($LONCAPA::map::zombies[$i])) {
4245: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 4246: if ($zombie{$i} eq $src) {
1.492 raeburn 4247: undef($LONCAPA::map::zombies[$i]);
4248: }
4249: }
4250: }
1.646 raeburn 4251: my $total = scalar(@LONCAPA::map::order) - 1;
4252: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 4253: my $idx = $LONCAPA::map::order[$i];
4254: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 4255: my $changed;
1.529 raeburn 4256: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 4257: if ((exists($toremove{$idx})) &&
4258: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 4259: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 4260: if (ref($currparam{$idx}) eq 'ARRAY') {
4261: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 4262: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 4263: }
4264: }
4265: next;
4266: }
4267: my $origsrc = $src;
1.532 raeburn 4268: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 4269: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
4270: $changed = 1;
1.491 raeburn 4271: }
1.492 raeburn 4272: }
1.532 raeburn 4273: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 4274: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
4275: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 4276: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 4277: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 4278: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 4279: } else {
1.529 raeburn 4280: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 4281: }
1.491 raeburn 4282: }
1.532 raeburn 4283: if ($origsrc =~ /\.(page|sequence)$/) {
4284: if ($newsubdir{$origsrc}) {
1.529 raeburn 4285: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 4286: }
1.532 raeburn 4287: } elsif ($newsubdir{$key}) {
4288: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 4289: }
4290: }
1.492 raeburn 4291: $changed = 1;
1.533 raeburn 4292: } elsif ($newdb{$idx} ne '') {
4293: $src = $newdb{$idx};
1.492 raeburn 4294: $changed = 1;
4295: }
4296: if ($changed) {
1.538 raeburn 4297: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 4298: }
4299: }
4300: }
4301: foreach my $idx (keys(%remparam)) {
4302: if (ref($remparam{$idx}) eq 'ARRAY') {
4303: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 4304: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 4305: }
4306: }
4307: }
1.533 raeburn 4308: if (values(%lockerrors) > 0) {
4309: $lockmsg = join('<br />',values(%lockerrors));
4310: }
1.491 raeburn 4311: my $storefn;
4312: if ($key eq $oldurl) {
4313: $storefn = $url;
4314: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
4315: } else {
4316: $storefn = $key;
4317: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4318: if ($prefixchg && $before{'map'} && $after{'map'}) {
4319: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 4320: }
1.529 raeburn 4321: if ($newsubdir{$key}) {
4322: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 4323: }
1.491 raeburn 4324: }
1.492 raeburn 4325: my $report;
4326: if ($folder !~ /^supplemental/) {
4327: $report = 1;
4328: }
1.527 raeburn 4329: (my $outtext,$errtext) =
1.492 raeburn 4330: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
4331: if ($errtext) {
1.529 raeburn 4332: if ($caller eq 'paste') {
1.533 raeburn 4333: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 4334: }
1.491 raeburn 4335: }
4336: }
1.704 raeburn 4337: if (($updatetoolscache) || (@updatetoolsenc)) {
4338: &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
4339: \@updatetoolsenc);
4340: }
1.491 raeburn 4341: }
1.533 raeburn 4342: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 4343: }
4344:
4345: sub copy_dependencies {
4346: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
4347: my $content;
4348: if (ref($contentref)) {
4349: $content = $$contentref;
4350: } else {
4351: $content = &Apache::lonnet::getfile($item);
4352: }
4353: unless ($content eq '-1') {
4354: my $mm = new File::MMagic;
4355: my $mimetype = $mm->checktype_contents($content);
4356: if ($mimetype eq 'text/html') {
4357: my (%allfiles,%codebase,$state);
4358: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
4359: if ($res eq 'ok') {
4360: my ($numexisting,$numpathchanges,$existing);
4361: (undef,$numexisting,$numpathchanges,$existing) =
4362: &Apache::loncommon::ask_for_embedded_content(
4363: '/adm/coursedocs',$state,\%allfiles,\%codebase,
4364: {'error_on_invalid_names' => 1,
4365: 'ignore_remote_references' => 1,
4366: 'docs_url' => $item,
4367: 'context' => 'paste'});
4368: if ($numexisting > 0) {
4369: if (ref($existing) eq 'HASH') {
4370: foreach my $dep (keys(%{$existing})) {
4371: my $depfile = $dep;
4372: unless ($depfile =~ m{^\Q$relpath\E}) {
4373: $depfile = $relpath.$dep;
4374: }
4375: my $depcontent = &Apache::lonnet::getfile($depfile);
4376: unless ($depcontent eq '-1') {
4377: my $storedep = $dep;
4378: $storedep =~ s{^\Q$relpath\E}{};
4379: my $dep_url =
4380: &Apache::lonclonecourse::writefile(
4381: $env{'request.course.id'},
4382: $storefn.$storedep,$depcontent);
4383: if ($dep_url eq '/adm/notfound.html') {
4384: if (ref($errors) eq 'HASH') {
4385: $errors->{$depfile} = 1;
4386: }
4387: } else {
4388: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
4389: }
4390: }
4391: }
1.488 raeburn 4392: }
4393: }
4394: }
4395: }
4396: }
4397: return;
4398: }
4399:
1.329 droeschl 4400: my %parameter_type = ( 'randompick' => 'int_pos',
4401: 'hiddenresource' => 'string_yesno',
4402: 'encrypturl' => 'string_yesno',
4403: 'randomorder' => 'string_yesno',);
4404: my $valid_parameters_re = join('|',keys(%parameter_type));
4405: # set parameters
4406: sub update_parameter {
1.537 raeburn 4407: if ($env{'form.changeparms'} eq 'all') {
4408: my (@allidx,@allmapidx,%allchecked,%currchecked);
4409: %allchecked = (
4410: 'hiddenresource' => {},
4411: 'encrypturl' => {},
4412: 'randompick' => {},
4413: 'randomorder' => {},
4414: );
4415: foreach my $which (keys(%allchecked)) {
1.630 raeburn 4416: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 4417: if ($which eq 'randompick') {
4418: foreach my $item (split(/,/,$env{'form.all'.$which})) {
4419: my ($res,$value) = split(/:/,$item);
4420: if ($value =~ /^\d+$/) {
4421: $allchecked{$which}{$res} = $value;
4422: }
4423: }
4424: } else {
1.539 raeburn 4425: if ($env{'form.all'.$which}) {
4426: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
4427: }
1.537 raeburn 4428: }
4429: }
4430: my $haschanges = 0;
4431: foreach my $res (@LONCAPA::map::order) {
4432: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4433: $name=&LONCAPA::map::qtescape($name);
4434: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 4435: next unless $url;
1.537 raeburn 4436: my $is_map;
4437: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4438: $is_map = 1;
4439: }
4440: foreach my $which (keys(%allchecked)) {
4441: if (($which eq 'randompick' || $which eq 'randomorder')) {
4442: next if (!$is_map);
4443: }
4444: my $oldvalue = 0;
4445: my $newvalue = 0;
4446: if ($allchecked{$which}{$res}) {
4447: $newvalue = $allchecked{$which}{$res};
4448: }
4449: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
4450: if ($which eq 'randompick') {
4451: if ($current =~ /^(\d+)$/) {
4452: $oldvalue = $1;
4453: }
4454: } else {
4455: if ($current =~ /^yes$/i) {
4456: $oldvalue = 1;
4457: }
4458: }
4459: if ($oldvalue ne $newvalue) {
4460: $haschanges = 1;
4461: if ($newvalue) {
4462: my $storeval = 'yes';
4463: if ($which eq 'randompick') {
4464: $storeval = $newvalue;
4465: }
4466: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
4467: $storeval,
4468: $parameter_type{$which});
4469: &remember_parms($res,$which,'set',$storeval);
4470: } elsif ($oldvalue) {
4471: &LONCAPA::map::delparameter($res,'parameter_'.$which);
4472: &remember_parms($res,$which,'del');
4473: }
4474: }
4475: }
4476: }
4477: return $haschanges;
4478: } else {
1.588 raeburn 4479: my $haschanges = 0;
4480: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 4481:
1.537 raeburn 4482: my $which = $env{'form.changeparms'};
4483: my $idx = $env{'form.setparms'};
1.588 raeburn 4484: my $oldvalue = 0;
4485: my $newvalue = 0;
4486: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
4487: if ($which eq 'randompick') {
4488: if ($current =~ /^(\d+)$/) {
4489: $oldvalue = $1;
4490: }
4491: } elsif ($current =~ /^yes$/i) {
4492: $oldvalue = 1;
4493: }
1.537 raeburn 4494: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 4495: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
4496: : 1;
4497: }
4498: if ($oldvalue ne $newvalue) {
4499: $haschanges = 1;
4500: if ($newvalue) {
4501: my $storeval = 'yes';
4502: if ($which eq 'randompick') {
4503: $storeval = $newvalue;
4504: }
4505: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
4506: $parameter_type{$which});
4507: &remember_parms($idx,$which,'set',$storeval);
4508: } else {
4509: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
4510: &remember_parms($idx,$which,'del');
4511: }
1.537 raeburn 4512: }
1.588 raeburn 4513: return $haschanges;
1.329 droeschl 4514: }
4515: }
4516:
4517: sub handle_edit_cmd {
4518: my ($coursenum,$coursedom) =@_;
1.633 raeburn 4519: my $haschanges = 0;
1.543 raeburn 4520: if ($env{'form.cmd'} eq '') {
1.633 raeburn 4521: return $haschanges;
1.543 raeburn 4522: }
1.329 droeschl 4523: my ($cmd,$idx)=split('_',$env{'form.cmd'});
4524:
4525: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
4526: my ($title, $url, @rrest) = split(':', $ratstr);
4527:
1.538 raeburn 4528: if ($cmd eq 'remove') {
1.329 droeschl 4529: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 4530: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 4531: &Apache::lonnet::removeuploadedurl($url);
4532: } else {
4533: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4534: }
4535: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4536: $haschanges = 1;
1.329 droeschl 4537: } elsif ($cmd eq 'cut') {
4538: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4539: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4540: $haschanges = 1;
1.344 bisitz 4541: } elsif ($cmd eq 'up'
1.329 droeschl 4542: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
4543: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 4544: $haschanges = 1;
1.329 droeschl 4545: } elsif ($cmd eq 'down'
4546: && defined($LONCAPA::map::order[$idx+1])) {
4547: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 4548: $haschanges = 1;
1.329 droeschl 4549: } elsif ($cmd eq 'rename') {
4550: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
4551: if ($comment=~/\S/) {
4552: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
4553: $comment.':'.join(':', $url, @rrest);
4554: }
4555: # Devalidate title cache
4556: my $renamed_url=&LONCAPA::map::qtescape($url);
4557: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 4558: $haschanges = 1;
4559: } elsif ($cmd eq 'setalias') {
4560: my $newvalue = $env{'form.alias'};
4561: if ($newvalue ne '') {
4562: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
4563: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
4564: 'string');
4565: &remember_parms($idx,'mapalias','set',$newvalue);
4566: $haschanges = 1;
4567: }
4568: }
4569: } elsif ($cmd eq 'delalias') {
4570: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
4571: if ($current ne '') {
4572: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
4573: &remember_parms($idx,'mapalias','del');
4574: $haschanges = 1;
4575: }
1.329 droeschl 4576: }
1.633 raeburn 4577: return $haschanges;
1.329 droeschl 4578: }
4579:
4580: sub editor {
1.458 raeburn 4581: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 4582: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 4583: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 4584: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 4585: if ($allowed) {
1.519 raeburn 4586: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
4587: $is_random_order,$container) =
1.510 raeburn 4588: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
4589: $r->print($breadcrumbtrail);
1.519 raeburn 4590: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
4591: $container = 'page';
4592: } else {
4593: $container = 'sequence';
1.510 raeburn 4594: }
1.484 raeburn 4595:
1.525 raeburn 4596: my $jumpto;
4597:
4598: unless ($supplementalflag) {
1.546 raeburn 4599: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 4600: }
1.484 raeburn 4601:
4602: unless ($allowed) {
4603: $randompick = -1;
4604: }
4605:
1.615 raeburn 4606: my ($errtext,$fatal);
4607: if (($folder eq '') && (!$supplementalflag)) {
4608: if (@LONCAPA::map::order) {
4609: undef(@LONCAPA::map::order);
4610: undef(@LONCAPA::map::resources);
4611: undef(@LONCAPA::map::resparms);
4612: undef(@LONCAPA::map::zombies);
4613: }
4614: $folder = 'default';
4615: $container = 'sequence';
4616: } else {
4617: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
4618: $folder.'.'.$container);
4619: return $errtext if ($fatal);
4620: }
1.329 droeschl 4621:
4622: if ($#LONCAPA::map::order<1) {
4623: my $idx=&LONCAPA::map::getresidx();
4624: if ($idx<=0) { $idx=1; }
4625: $LONCAPA::map::order[0]=$idx;
4626: $LONCAPA::map::resources[$idx]='';
4627: }
1.364 bisitz 4628:
1.329 droeschl 4629: # ------------------------------------------------------------ Process commands
4630:
4631: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 4632: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 4633: # set parameters and change order
4634: &snapshotbefore();
4635:
4636: if (&update_parameter()) {
1.588 raeburn 4637: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 4638: return $errtext if ($fatal);
4639: }
4640:
4641: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
4642: # change order
4643: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
4644: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
4645:
4646: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
4647: return $errtext if ($fatal);
4648: }
1.364 bisitz 4649:
1.329 droeschl 4650: if ($env{'form.pastemarked'}) {
1.491 raeburn 4651: my %paste_errors;
1.533 raeburn 4652: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 4653: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
4654: \%paste_errors);
1.541 raeburn 4655: if (ref($pastemsgarray) eq 'ARRAY') {
4656: if (@{$pastemsgarray} > 0) {
4657: $r->print('<p class="LC_info">'.
4658: join('<br />',@{$pastemsgarray}).
1.533 raeburn 4659: '</p>');
4660: }
1.541 raeburn 4661: }
4662: if ($lockerror) {
4663: $r->print('<p class="LC_error">'.
4664: $lockerror.
4665: '</p>');
4666: }
4667: if ($save_error ne '') {
4668: return $save_error;
4669: }
4670: if ($paste_res) {
4671: my %errortext = &Apache::lonlocal::texthash (
4672: fail => 'Storage of folder contents failed',
4673: failread => 'Reading folder contents failed',
4674: failstore => 'Storage of folder contents failed',
4675: );
4676: if ($errortext{$paste_res}) {
4677: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 4678: }
1.329 droeschl 4679: }
1.491 raeburn 4680: if (keys(%paste_errors) > 0) {
1.538 raeburn 4681: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 4682: &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".
4683: '<ul>'."\n");
4684: foreach my $key (sort(keys(%paste_errors))) {
4685: $r->print('<li>'.$key.'</li>'."\n");
4686: }
4687: $r->print('</ul></p>'."\n");
4688: }
1.538 raeburn 4689: } elsif ($env{'form.clearmarked'}) {
4690: my $output = &do_buffer_empty();
4691: if ($output) {
4692: $r->print('<p class="LC_info">'.$output.'</p>');
4693: }
4694: }
1.329 droeschl 4695:
4696: $r->print($upload_output);
4697:
1.538 raeburn 4698: # Rename, cut, copy or remove a single resource
1.602 raeburn 4699: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 4700: my $contentchg;
1.633 raeburn 4701: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 4702: $contentchg = 1;
4703: }
4704: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 4705: return $errtext if ($fatal);
4706: }
1.538 raeburn 4707:
4708: # Cut, copy and/or remove multiple resources
4709: if ($env{'form.multichange'}) {
4710: my %allchecked = (
4711: cut => {},
4712: remove => {},
4713: );
4714: my $needsupdate;
4715: foreach my $which (keys(%allchecked)) {
4716: $env{'form.multi'.$which} =~ s/,$//;
4717: if ($env{'form.multi'.$which}) {
4718: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
4719: if (ref($allchecked{$which}) eq 'HASH') {
4720: $needsupdate += scalar(keys(%{$allchecked{$which}}));
4721: }
4722: }
4723: }
4724: if ($needsupdate) {
4725: my $haschanges = 0;
4726: my %curr_groups = &Apache::longroup::coursegroups();
4727: my $total = scalar(@LONCAPA::map::order) - 1;
4728: for (my $i=$total; $i>=0; $i--) {
4729: my $res = $LONCAPA::map::order[$i];
4730: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4731: $name=&LONCAPA::map::qtescape($name);
4732: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 4733: next unless $url;
1.538 raeburn 4734: my %denied =
4735: &action_restrictions($coursenum,$coursedom,$url,
4736: $env{'form.folderpath'},\%curr_groups);
4737: foreach my $which (keys(%allchecked)) {
4738: next if ($denied{$which});
4739: next unless ($allchecked{$which}{$res});
4740: if ($which eq 'remove') {
4741: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4742: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4743: &Apache::lonnet::removeuploadedurl($url);
4744: } else {
4745: &LONCAPA::map::makezombie($res);
4746: }
4747: splice(@LONCAPA::map::order,$i,1);
4748: $haschanges ++;
4749: } elsif ($which eq 'cut') {
4750: &LONCAPA::map::makezombie($res);
4751: splice(@LONCAPA::map::order,$i,1);
4752: $haschanges ++;
4753: }
4754: }
4755: }
4756: if ($haschanges) {
4757: ($errtext,$fatal) =
4758: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
4759: return $errtext if ($fatal);
4760: }
4761: }
4762: }
4763:
1.329 droeschl 4764: # Group import/search
4765: if ($env{'form.importdetail'}) {
4766: my @imports;
4767: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
4768: if (defined($item)) {
4769: my ($name,$url,$residx)=
1.533 raeburn 4770: map { &unescape($_); } split(/\=/,$item);
4771: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
4772: my ($suffix,$errortxt,$locknotfreed) =
4773: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 4774: if ($locknotfreed) {
4775: $r->print($locknotfreed);
4776: }
4777: if ($suffix) {
4778: $url =~ s/_new\./_$suffix./;
4779: } else {
4780: return $errortxt;
4781: }
1.533 raeburn 4782: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
4783: my $type = $1;
4784: my ($suffix,$errortxt,$locknotfreed) =
4785: &new_timebased_suffix($coursedom,$coursenum,$type);
4786: if ($locknotfreed) {
4787: $r->print($locknotfreed);
4788: }
4789: if ($suffix) {
4790: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
4791: } else {
4792: return $errortxt;
4793: }
1.626 raeburn 4794: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 4795: my ($suffix,$errortxt,$locknotfreed) =
4796: &new_timebased_suffix($coursedom,$coursenum,'exttool');
4797: if ($locknotfreed) {
4798: $r->print($locknotfreed);
4799: }
4800: if ($suffix) {
4801: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
4802: } else {
4803: return $errortxt;
4804: }
1.534 raeburn 4805: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
4806: if ($supplementalflag) {
4807: next unless ($1 eq 'supplemental');
4808: if ($folder eq 'supplemental') {
4809: next unless ($2 eq 'default');
4810: } else {
4811: next unless ($folder eq 'supplemental_'.$2);
4812: }
4813: } else {
4814: next unless ($1 eq 'docs');
4815: if ($folder eq 'default') {
4816: next unless ($2 eq 'default');
4817: } else {
4818: next unless ($folder eq 'default_'.$2);
4819: }
4820: }
1.504 raeburn 4821: }
1.329 droeschl 4822: push(@imports, [$name, $url, $residx]);
4823: }
4824: }
1.530 raeburn 4825: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 4826: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 4827: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 4828: return $errtext if ($fatal);
1.529 raeburn 4829: if ($fixuperrors) {
4830: $r->print($fixuperrors);
4831: }
1.329 droeschl 4832: }
4833: # Loading a complete map
4834: if ($env{'form.loadmap'}) {
4835: if ($env{'form.importmap'}=~/\w/) {
4836: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
4837: my ($title,$url,$ext,$type)=split(/\:/,$res);
4838: my $idx=&LONCAPA::map::getresidx($url);
4839: $LONCAPA::map::resources[$idx]=$res;
4840: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
4841: }
4842: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 4843: $folder.'.'.$container,1);
1.329 droeschl 4844: return $errtext if ($fatal);
4845: } else {
4846: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 4847:
1.329 droeschl 4848: }
4849: }
4850: &log_differences($plain);
4851: }
4852: # ---------------------------------------------------------------- End commands
4853: # ---------------------------------------------------------------- Print screen
4854: my $idx=0;
4855: my $shown=0;
4856: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 4857: $r->print('<div class="LC_Box">'.
1.432 raeburn 4858: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
4859: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
4860: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
4861: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
4862: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 4863: '</ol>');
1.381 bisitz 4864: if ($randompick>=0) {
4865: $r->print('<p class="LC_warning">'
4866: .&mt('Caution: this folder is set to randomly pick a subset'
4867: .' of resources. Adding or removing resources from this'
4868: .' folder will change the set of resources that the'
4869: .' students see, resulting in spurious or missing credit'
4870: .' for completed problems, not limited to ones you'
4871: .' modify. Do not modify the contents of this folder if'
4872: .' it is in active student use.')
4873: .'</p>'
4874: );
4875: }
4876: if ($is_random_order) {
4877: $r->print('<p class="LC_warning">'
4878: .&mt('Caution: this folder is set to randomly order its'
4879: .' contents. Adding or removing resources from this folder'
4880: .' will change the order of resources shown.')
4881: .'</p>'
4882: );
4883: }
4884: $r->print('</div>');
1.364 bisitz 4885: }
1.381 bisitz 4886:
1.685 raeburn 4887: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 4888: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 4889: if (ref($supplemental) eq 'HASH') {
4890: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
4891: (ref($supplemental->{'ids'}) eq 'HASH')) {
4892: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
4893: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
4894: if ($supplemental->{'hidden'}->{$mapnum}) {
4895: $ishidden = 1;
4896: }
4897: }
4898: }
4899: }
4900: }
4901:
1.538 raeburn 4902: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
4903: %filters = (
1.543 raeburn 4904: canremove => [],
4905: cancut => [],
4906: cancopy => [],
4907: hiddenresource => [],
4908: encrypturl => [],
4909: randomorder => [],
4910: randompick => [],
1.538 raeburn 4911: );
4912: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 4913: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 4914: foreach my $res (@LONCAPA::map::order) {
4915: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4916: $name=&LONCAPA::map::qtescape($name);
4917: $url=&LONCAPA::map::qtescape($url);
4918: unless ($name) { $name=(split(/\//,$url))[-1]; }
4919: unless ($name) { $idx++; next; }
1.537 raeburn 4920: push(@allidx,$res);
4921: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4922: push(@allmapidx,$res);
4923: }
1.617 raeburn 4924:
1.682 raeburn 4925: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 4926: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
4927: $idx++;
4928: next;
4929: }
1.682 raeburn 4930: }
1.381 bisitz 4931: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 4932: $coursenum,$coursedom,$crstype,
1.538 raeburn 4933: $pathitem,$supplementalflag,$container,
1.620 raeburn 4934: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 4935: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 4936: $idx++;
4937: $shown++;
1.329 droeschl 4938: }
1.424 onken 4939: &Apache::loncommon::end_data_table_count();
1.510 raeburn 4940:
1.538 raeburn 4941: my $need_save;
1.611 raeburn 4942: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 4943: my $toolslink;
1.682 raeburn 4944: if ($allowed || $canedit) {
4945: my $helpitem = 'Navigation_Screen';
4946: if (!$allowed) {
4947: $helpitem = 'Supplemental_Navigation';
4948: }
1.544 raeburn 4949: $toolslink = '<table><tr><td>'
1.520 raeburn 4950: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 4951: $helpitem,undef,'RAT')
1.520 raeburn 4952: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
4953: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 4954: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 4955: .'id="LC_content_toolbar_edittoplevel" '
4956: .'class="LC_toolbarItem" '
4957: .'title="'.&mt('Supplemental Content Editor').'">'
4958: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 4959: }
1.510 raeburn 4960: if ($shown) {
4961: if ($allowed) {
4962: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
4963: .&Apache::loncommon::start_data_table(undef,'contentlist')
4964: .&Apache::loncommon::start_data_table_header_row()
4965: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 4966: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 4967: .'<th>'.&mt('Document').'</th>'
4968: .'<th colspan="2">'.&mt('Settings').'</th>'
4969: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 4970: if ($folder !~ /^supplemental/) {
1.538 raeburn 4971: $lists{'canhide'} = join(',',@allidx);
4972: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 4973: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
4974: 'randomorder','randompick');
4975: foreach my $item (@possfilters) {
1.538 raeburn 4976: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 4977: if (@{$filters{$item}} > 0) {
4978: $lists{$item} = join(',',@{$filters{$item}});
4979: }
1.538 raeburn 4980: }
4981: }
1.537 raeburn 4982: if (@allidx > 0) {
4983: my $path;
4984: if ($env{'form.folderpath'}) {
1.630 raeburn 4985: $path =
1.537 raeburn 4986: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4987: }
1.538 raeburn 4988: if (@allidx > 1) {
1.630 raeburn 4989: $to_show .=
1.538 raeburn 4990: &Apache::loncommon::continue_data_table_row().
4991: '<td colspan="2"> </td>'.
4992: '<td>'.
1.611 raeburn 4993: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 4994: '</td>'.
1.633 raeburn 4995: '<td colspan="3"> </td>'.
4996: '<td colspan="2">'.
1.611 raeburn 4997: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 4998: '</td>'.
4999: &Apache::loncommon::end_data_table_row();
5000: $need_save = 1;
5001: }
1.537 raeburn 5002: }
5003: }
5004: $to_show .= $output.' '
1.510 raeburn 5005: .&Apache::loncommon::end_data_table()
5006: .'<br style="line-height:2px;" />'
5007: .&Apache::loncommon::end_scrollbox();
5008: } else {
1.520 raeburn 5009: $to_show .= $toolslink
1.510 raeburn 5010: .&Apache::loncommon::start_data_table('LC_tableOfContent')
5011: .$output.' '
5012: .&Apache::loncommon::end_data_table();
1.393 raeburn 5013: }
1.510 raeburn 5014: } else {
1.520 raeburn 5015: if (!$allowed) {
5016: $to_show .= $toolslink;
5017: }
1.615 raeburn 5018: my $noresmsg;
5019: if ($allowed && $hiddentop && !$supplementalflag) {
5020: $noresmsg = &mt('Main Content Hidden');
5021: } else {
5022: $noresmsg = &mt('Currently empty');
5023: }
1.510 raeburn 5024: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
5025: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 5026: .$noresmsg
1.510 raeburn 5027: .'</div>'
5028: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 5029: }
5030: } else {
1.510 raeburn 5031: if ($shown) {
5032: $to_show = '<div>'
5033: .&Apache::loncommon::start_data_table('LC_tableOfContent')
5034: .$output
5035: .&Apache::loncommon::end_data_table()
5036: .'</div>';
5037: } else {
5038: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 5039: .&mt('Currently empty')
1.510 raeburn 5040: .'</div>'
5041: }
1.458 raeburn 5042: }
5043: my $tid = 1;
5044: if ($supplementalflag) {
5045: $tid = 2;
1.329 droeschl 5046: }
5047: if ($allowed) {
1.484 raeburn 5048: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 5049: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 5050: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
5051: if ($canedit) {
5052: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
5053: }
1.460 raeburn 5054: } else {
5055: $r->print($to_show);
1.329 droeschl 5056: }
5057: return;
5058: }
5059:
1.538 raeburn 5060: sub multiple_check_form {
1.611 raeburn 5061: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 5062: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 5063: my $disabled;
5064: unless ($canedit) {
1.700 raeburn 5065: $disabled = ' disabled="disabled"';
1.611 raeburn 5066: }
1.538 raeburn 5067: my $output =
5068: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
5069: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
5070: '<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>'.
5071: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
5072: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
5073: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
5074: if ($caller eq 'settings') {
5075: $output .=
5076: '<table><tr>'.
5077: '<td class="LC_docs_entry_parameter">'.
5078: '<span class="LC_nobreak"><label>'.
1.611 raeburn 5079: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 5080: '</label></span></td>'.
5081: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 5082: '<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 5083: '</span></td>'.
5084: '</tr>'."\n".
5085: '<tr>'.
5086: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 5087: '<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 5088: '</label></span>'.
5089: '</td></tr></table>'."\n";
5090: } else {
5091: $output .=
5092: '<table><tr>'.
5093: '<td class="LC_docs_entry_parameter">'.
5094: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 5095: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 5096: '</label></span></td>'.
5097: '<td class="LC_docs_entry_parameter">'.
5098: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 5099: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 5100: '</label></span></td>'."\n".
5101: '<td class="LC_docs_entry_parameter">'.
5102: '<span class="LC_nobreak LC_docs_copy">'.
1.700 raeburn 5103: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538 raeburn 5104: '</label></span></td>'.
5105: '</tr></table>'."\n";
5106: }
5107: $output .=
5108: '</fieldset>'.
5109: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
5110: if ($caller eq 'settings') {
5111: $output .=
1.543 raeburn 5112: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
5113: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
5114: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
5115: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
5116: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 5117: } elsif ($caller eq 'actions') {
5118: $output .=
5119: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
5120: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
5121: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
5122: }
5123: $output .=
5124: '</form>'.
5125: '</div>';
5126: return $output;
5127: }
5128:
1.329 droeschl 5129: sub process_file_upload {
1.552 raeburn 5130: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 5131: # upload a file, if present
1.552 raeburn 5132: my $filesize = length($env{'form.uploaddoc'});
5133: if (!$filesize) {
5134: $$upload_output = '<div class="LC_error">'.
5135: &mt('Unable to upload [_1]. (size = [_2] bytes)',
5136: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
5137: $filesize).'<br />'.
5138: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
5139: '</div>';
5140: return;
5141: }
5142: my $quotatype = 'unofficial';
5143: if ($crstype eq 'Community') {
1.601 raeburn 5144: $quotatype = 'community';
5145: } elsif ($crstype eq 'Placement') {
5146: $quotatype = 'placement';
1.580 raeburn 5147: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 5148: $quotatype = 'official';
1.573 raeburn 5149: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5150: $quotatype = 'textbook';
1.552 raeburn 5151: }
5152: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
5153: $filesize = int($filesize/1000); #expressed in kb
5154: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 5155: $env{'form.uploaddoc.filename'},$filesize,
5156: 'upload',$quotatype);
1.552 raeburn 5157: return if ($$upload_output);
5158: }
1.440 raeburn 5159: my ($parseaction,$showupload,$nextphase,$mimetype);
5160: if ($env{'form.parserflag'}) {
1.329 droeschl 5161: $parseaction = 'parse';
5162: }
5163: my $folder=$env{'form.folder'};
5164: if ($folder eq '') {
5165: $folder='default';
5166: }
5167: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
5168: my $errtext='';
5169: my $fatal=0;
5170: my $container='sequence';
1.519 raeburn 5171: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 5172: $container='page';
5173: }
5174: ($errtext,$fatal)=
1.534 raeburn 5175: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 5176: if ($#LONCAPA::map::order<1) {
5177: $LONCAPA::map::order[0]=1;
5178: $LONCAPA::map::resources[1]='';
5179: }
5180: my $destination = 'docs/';
5181: if ($folder =~ /^supplemental/) {
5182: $destination = 'supplemental/';
5183: }
5184: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5185: $destination .= 'default/';
5186: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5187: $destination .= $2.'/';
5188: }
1.534 raeburn 5189: if ($fatal) {
5190: $$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>';
5191: return;
5192: }
1.440 raeburn 5193: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 5194: my $newidx=&LONCAPA::map::getresidx();
5195: $destination .= $newidx;
1.439 raeburn 5196: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 5197: $parseaction,$allfiles,
1.440 raeburn 5198: $codebase,undef,undef,undef,undef,
5199: undef,undef,\$mimetype);
5200: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
5201: my $stored = $1;
5202: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
5203: $stored.'</span>').'</p>';
5204: } else {
5205: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
5206:
1.457 raeburn 5207: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 5208: return;
5209: }
1.329 droeschl 5210: my $ext='false';
5211: if ($url=~m{^http://}) { $ext='true'; }
5212: $url = &LONCAPA::map::qtunescape($url);
5213: my $comment=$env{'form.comment'};
5214: $comment = &LONCAPA::map::qtunescape($comment);
5215: if ($folder=~/^supplemental/) {
5216: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
5217: $env{'user.domain'}.'___&&&___'.$comment;
5218: }
5219:
5220: $LONCAPA::map::resources[$newidx]=
5221: $comment.':'.$url.':'.$ext.':normal:res';
5222: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
5223: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 5224: $folder.'.'.$container,1);
1.329 droeschl 5225: if ($fatal) {
1.457 raeburn 5226: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 5227: return;
1.329 droeschl 5228: } else {
1.440 raeburn 5229: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
5230: $$upload_output = $showupload;
1.384 raeburn 5231: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 5232: if ($total_embedded > 0) {
1.440 raeburn 5233: my $uploadphase = 'upload_embedded';
5234: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
5235: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 5236: my ($embedded,$num) =
1.440 raeburn 5237: &Apache::loncommon::ask_for_embedded_content(
5238: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
5239: if ($embedded) {
5240: if ($num) {
5241: $$upload_output .=
5242: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
5243: $nextphase = $uploadphase;
5244: } else {
5245: $$upload_output .= $embedded;
5246: }
5247: } else {
5248: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
5249: }
1.329 droeschl 5250: } else {
1.440 raeburn 5251: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 5252: }
1.457 raeburn 5253: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 5254: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
5255: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 5256: $nextphase = 'decompress_uploaded';
5257: my $position = scalar(@LONCAPA::map::order)-1;
5258: my $noextract = &return_to_editor();
5259: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
5260: my %archiveitems = (
5261: folderpath => $env{'form.folderpath'},
5262: cmd => $nextphase,
5263: newidx => $newidx,
5264: position => $position,
5265: phase => $nextphase,
1.477 raeburn 5266: comment => $comment,
1.480 raeburn 5267: );
5268: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
5269: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 5270: $$upload_output = $showupload.
5271: &Apache::loncommon::decompress_form($mimetype,
5272: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 5273: \%archiveitems,\@current);
1.329 droeschl 5274: }
5275: }
5276: }
1.440 raeburn 5277: return $nextphase;
1.329 droeschl 5278: }
5279:
1.480 raeburn 5280: sub get_dir_list {
5281: my ($url,$coursenum,$coursedom,$newidx) = @_;
5282: my ($destination,$dir_root) = &embedded_destination();
5283: my ($dirlistref,$listerror) =
5284: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
5285: my @dir_lines;
5286: my $dirptr=16384;
5287: if (ref($dirlistref) eq 'ARRAY') {
5288: foreach my $dir_line (sort
5289: {
5290: my ($afile)=split('&',$a,2);
5291: my ($bfile)=split('&',$b,2);
5292: return (lc($afile) cmp lc($bfile));
5293: } (@{$dirlistref})) {
5294: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
5295: $filename =~ s/\s+$//;
5296: next if ($filename =~ /^\.\.?$/);
5297: my $isdir = 0;
5298: if ($dirptr&$testdir) {
5299: $isdir = 1;
5300: }
5301: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
5302: }
5303: }
5304: return @dir_lines;
5305: }
5306:
1.329 droeschl 5307: sub is_supplemental_title {
5308: my ($title) = @_;
5309: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
5310: }
5311:
5312: # --------------------------------------------------------------- An entry line
5313:
5314: sub entryline {
1.501 raeburn 5315: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 5316: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 5317: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 5318: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 5319: if (&is_supplemental_title($title)) {
1.488 raeburn 5320: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 5321: $encodedtitle=$title;
1.329 droeschl 5322: } else {
5323: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 5324: $encodedtitle=$title;
1.329 droeschl 5325: $renametitle=$title;
5326: $foldertitle=$title;
5327: }
5328:
1.611 raeburn 5329: my ($disabled,$readonly,$js_lt);
5330: unless ($canedit) {
5331: $disabled = 'disabled="disabled"';
5332: $readonly = 1;
5333: }
5334:
1.329 droeschl 5335: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 5336:
1.329 droeschl 5337: $renametitle=~s/\\/\\\\/g;
5338: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 5339: $renametitle=~s/"/%22/g;
1.581 raeburn 5340: $renametitle=~s/ /%20/g;
5341: $oldtitle = $renametitle;
1.576 raeburn 5342: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 5343: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 5344: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 5345: # Edit commands
1.679 raeburn 5346: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 5347: if ($env{'form.folderpath'}) {
5348: $esc_path=&escape($env{'form.folderpath'});
5349: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5350: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
5351: }
1.505 raeburn 5352: my $isexternal;
1.510 raeburn 5353: if ($residx) {
1.501 raeburn 5354: my $currurl = $url;
5355: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 5356: if ($currurl =~ m{^/adm/wrapper/ext/}) {
5357: $isexternal = 1;
5358: }
1.510 raeburn 5359: if (!$supplementalflag) {
5360: my $path = 'uploaded/'.
5361: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
5362: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
5363: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
5364: $residx,
5365: &Apache::lonnet::declutter($currurl));
5366: }
1.501 raeburn 5367: }
1.538 raeburn 5368: my ($renamelink,%lt,$ishash);
5369: if (ref($filtersref) eq 'HASH') {
5370: $ishash = 1;
5371: }
5372:
1.329 droeschl 5373: if ($allowed) {
1.538 raeburn 5374: $form_start = '
5375: <form action="/adm/coursedocs" method="post">
5376: ';
5377: $form_common=(<<END);
5378: <input type="hidden" name="folderpath" value="$path" />
5379: <input type="hidden" name="symb" value="$symb" />
5380: END
5381: $form_param=(<<END);
5382: <input type="hidden" name="setparms" value="$orderidx" />
5383: <input type="hidden" name="changeparms" value="0" />
5384: END
5385: $form_end = '</form>';
5386:
1.329 droeschl 5387: my $incindex=$index+1;
5388: my $selectbox='';
1.471 raeburn 5389: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 5390: ((split(/\:/,
1.344 bisitz 5391: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
5392: ne '') &&
1.329 droeschl 5393: ((split(/\:/,
1.344 bisitz 5394: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 5395: ne '')) {
5396: $selectbox=
5397: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 5398: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 5399: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
5400: if ($i==$incindex) {
1.358 bisitz 5401: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 5402: } else {
5403: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
5404: }
5405: }
5406: $selectbox.='</select>';
5407: }
1.501 raeburn 5408: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 5409: 'up' => 'Move Up',
5410: 'dw' => 'Move Down',
5411: 'rm' => 'Remove',
5412: 'ct' => 'Cut',
5413: 'rn' => 'Rename',
1.501 raeburn 5414: 'cp' => 'Copy',
1.633 raeburn 5415: 'da' => 'Unset alias',
5416: 'sa' => 'Set alias',
1.501 raeburn 5417: 'ex' => 'External Resource',
1.598 raeburn 5418: 'et' => 'External Tool',
1.501 raeburn 5419: 'ed' => 'Edit',
5420: 'pr' => 'Preview',
5421: 'sv' => 'Save',
5422: 'ul' => 'URL',
1.611 raeburn 5423: 'ti' => 'Title',
1.618 raeburn 5424: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 5425: );
1.538 raeburn 5426: my %denied = &action_restrictions($coursenum,$coursedom,$url,
5427: $env{'form.folderpath'},
5428: $currgroups);
1.517 raeburn 5429: my ($copylink,$cutlink,$removelink);
1.329 droeschl 5430: my $skip_confirm = 0;
1.603 raeburn 5431: my $confirm_removal = 0;
1.329 droeschl 5432: if ( $folder =~ /^supplemental/
5433: || ($url =~ m{( /smppg$
5434: |/syllabus$
5435: |/aboutme$
5436: |/navmaps$
5437: |/bulletinboard$
1.626 raeburn 5438: |/ext\.tool$
1.505 raeburn 5439: |\.html$)}x)
5440: || $isexternal) {
1.329 droeschl 5441: $skip_confirm = 1;
5442: }
1.603 raeburn 5443: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
5444: ($url!~/$LONCAPA::assess_page_seq_re/)) {
5445: $confirm_removal = 1;
5446: }
1.633 raeburn 5447: if ($url =~ /$LONCAPA::assess_re/) {
5448: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
5449: }
1.329 droeschl 5450:
1.538 raeburn 5451: if ($denied{'copy'}) {
1.543 raeburn 5452: $copylink=(<<ENDCOPY)
1.507 raeburn 5453: <span style="visibility: hidden;">$lt{'cp'}</span>
5454: ENDCOPY
5455: } else {
1.538 raeburn 5456: my $formname = 'edit_copy_'.$orderidx;
5457: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5458: $copylink=(<<ENDCOPY);
1.538 raeburn 5459: <form name="$formname" method="post" action="/adm/coursedocs">
5460: $form_common
1.611 raeburn 5461: <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 5462: $form_end
1.329 droeschl 5463: ENDCOPY
1.538 raeburn 5464: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
5465: push(@{$filtersref->{'cancopy'}},$orderidx);
5466: }
1.329 droeschl 5467: }
1.538 raeburn 5468: if ($denied{'cut'}) {
1.507 raeburn 5469: $cutlink=(<<ENDCUT);
5470: <span style="visibility: hidden;">$lt{'ct'}</span>
5471: ENDCUT
5472: } else {
1.538 raeburn 5473: my $formname = 'edit_cut_'.$orderidx;
5474: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5475: $cutlink=(<<ENDCUT);
1.538 raeburn 5476: <form name="$formname" method="post" action="/adm/coursedocs">
5477: $form_common
1.542 raeburn 5478: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 5479: <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 5480: $form_end
1.329 droeschl 5481: ENDCUT
1.538 raeburn 5482: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
5483: push(@{$filtersref->{'cancut'}},$orderidx);
5484: }
1.329 droeschl 5485: }
1.538 raeburn 5486: if ($denied{'remove'}) {
1.507 raeburn 5487: $removelink=(<<ENDREM);
5488: <span style="visibility: hidden;">$lt{'rm'}</a>
5489: ENDREM
5490: } else {
1.538 raeburn 5491: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 5492: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 5493: $removelink=(<<ENDREM);
1.538 raeburn 5494: <form name="$formname" method="post" action="/adm/coursedocs">
5495: $form_common
1.542 raeburn 5496: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 5497: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 5498: <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 5499: $form_end
1.497 raeburn 5500: ENDREM
1.538 raeburn 5501: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
5502: push(@{$filtersref->{'canremove'}},$orderidx);
5503: }
1.497 raeburn 5504: }
1.551 raeburn 5505: $renamelink=(<<ENDREN);
1.581 raeburn 5506: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 5507: ENDREN
1.611 raeburn 5508: my ($uplink,$downlink);
5509: if ($canedit) {
5510: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
5511: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
5512: } else {
5513: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
5514: $downlink = $uplink;
5515: }
1.329 droeschl 5516: $line.=(<<END);
5517: <td>
1.379 bisitz 5518: <div class="LC_docs_entry_move">
1.611 raeburn 5519: <a href="$uplink">
1.501 raeburn 5520: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 5521: </a>
5522: </div>
5523: <div class="LC_docs_entry_move">
1.611 raeburn 5524: <a href="$downlink">
1.501 raeburn 5525: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 5526: </a>
5527: </div>
1.329 droeschl 5528: </td>
5529: <td>
5530: $form_start
1.538 raeburn 5531: $form_param
1.478 raeburn 5532: $form_common
1.329 droeschl 5533: $selectbox
5534: $form_end
5535: </td>
1.540 raeburn 5536: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 5537: $removelink
1.329 droeschl 5538: $cutlink
5539: $copylink
5540: </td>
5541: END
5542: }
5543: # Figure out what kind of a resource this is
5544: my ($extension)=($url=~/\.(\w+)$/);
5545: my $uploaded=($url=~/^\/*uploaded\//);
5546: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 5547: my $isfolder;
5548: my $ispage;
5549: my $containerarg;
1.615 raeburn 5550: my $folderurl;
1.685 raeburn 5551: my $plainurl;
1.329 droeschl 5552: if ($uploaded) {
1.472 raeburn 5553: if (($extension eq 'sequence') || ($extension eq 'page')) {
5554: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 5555: $containerarg = $1;
1.472 raeburn 5556: if ($extension eq 'sequence') {
5557: $icon=$iconpath.'navmap.folder.closed.gif';
5558: $isfolder=1;
5559: } else {
5560: $icon=$iconpath.'page.gif';
5561: $ispage=1;
5562: }
1.615 raeburn 5563: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 5564: if ($allowed) {
5565: $url='/adm/coursedocs?';
5566: } else {
5567: $url='/adm/supplemental?';
5568: }
1.329 droeschl 5569: } else {
1.685 raeburn 5570: $plainurl = $url;
1.329 droeschl 5571: }
5572: }
1.364 bisitz 5573:
1.621 raeburn 5574: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 5575: my $orig_url = $url;
1.340 raeburn 5576: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 5577: if ($container eq 'page') {
5578: $url=~s{^http(|s)(:|:)//}{/ext/};
5579: } else {
5580: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
5581: }
1.501 raeburn 5582: if (!$supplementalflag && $residx && $symb) {
5583: if ((!$isfolder) && (!$ispage)) {
5584: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 5585: if (($url =~ m{^ext/}) && ($container eq 'page')) {
5586: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
5587: } else {
5588: $url=&Apache::lonnet::clutter($url);
5589: }
1.501 raeburn 5590: if ($url=~/^\/*uploaded\//) {
5591: $url=~/\.(\w+)$/;
5592: my $embstyle=&Apache::loncommon::fileembstyle($1);
5593: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
5594: $url='/adm/wrapper'.$url;
5595: } elsif ($embstyle eq 'ssi') {
5596: #do nothing with these
5597: } elsif ($url!~/\.(sequence|page)$/) {
5598: $url='/adm/coursedocs/showdoc'.$url;
5599: }
1.623 raeburn 5600: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
5601: my $wrapped = $1;
5602: my $exturl = $2;
1.668 raeburn 5603: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 5604: $url='/adm/wrapper'.$url;
5605: }
5606: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
5607: $nomodal = 1;
5608: }
1.626 raeburn 5609: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5610: $url='/adm/wrapper'.$url;
1.621 raeburn 5611: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
5612: if (($ENV{'SERVER_PORT'} == 443) &&
5613: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5614: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5615: $url .= '?usehttp=1';
5616: }
1.621 raeburn 5617: $nomodal = 1;
5618: }
1.598 raeburn 5619: }
1.696 raeburn 5620: my $checkencrypt;
1.680 raeburn 5621: if (!$env{'request.role.adv'}) {
1.615 raeburn 5622: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 5623: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 5624: $checkencrypt = 1;
1.620 raeburn 5625: } elsif (ref($navmapref)) {
1.615 raeburn 5626: unless (ref($$navmapref)) {
5627: $$navmapref = Apache::lonnavmaps::navmap->new();
5628: }
5629: if (ref($$navmapref)) {
5630: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 5631: $checkencrypt = 1;
1.615 raeburn 5632: }
5633: }
5634: }
1.680 raeburn 5635: }
5636: if ($checkencrypt) {
5637: my $currenc = $env{'request.enc'};
5638: $env{'request.enc'} = 1;
5639: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 5640: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 5641: if (&Apache::lonnet::symbverify($symb,$url)) {
5642: $url = $shownurl;
5643: } else {
5644: $url = '';
5645: }
5646: $env{'request.enc'} = $currenc;
5647: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
5648: $shownsymb = $symb;
5649: if ($isexternal) {
5650: $url =~ s/\#[^#]+$//;
5651: if ($container eq 'page') {
5652: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 5653: }
1.612 raeburn 5654: }
1.696 raeburn 5655: } else {
5656: $url = '';
1.680 raeburn 5657: }
5658: unless ($env{'request.role.adv'}) {
5659: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5660: $url = '';
5661: }
5662: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
5663: $url = '';
5664: $hiddenres = 1;
5665: }
5666: }
1.696 raeburn 5667: if (($url ne '') && ($shownsymb ne '')) {
5668: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 5669: }
1.329 droeschl 5670: }
1.621 raeburn 5671: } elsif ($supplementalflag) {
1.610 raeburn 5672: if ($isexternal) {
5673: if ($url =~ /^([^#]+)#([^#]+)$/) {
5674: $url = $1;
5675: $anchor = $2;
1.623 raeburn 5676: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 5677: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5678: if ($hostname ne '') {
5679: $url = 'http://'.$hostname.$url;
5680: }
5681: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 5682: }
5683: $nomodal = 1;
5684: }
1.610 raeburn 5685: }
1.621 raeburn 5686: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
5687: if (($ENV{'SERVER_PORT'} == 443) &&
5688: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5689: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5690: if ($hostname ne '') {
5691: $url = 'http://'.$hostname.$url;
5692: }
5693: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 5694: }
1.621 raeburn 5695: $nomodal = 1;
5696: }
1.705 raeburn 5697: } elsif (($uploaded) && ($url ne '/adm/supplemental?') && ($url ne '/adm/coursedocs?')) {
1.686 raeburn 5698: my $embstyle=&Apache::loncommon::fileembstyle($extension);
5699: unless ($embstyle eq 'ssi') {
5700: if (($embstyle eq 'img')
5701: || ($embstyle eq 'emb')
5702: || ($embstyle eq 'wrp')) {
5703: $url='/adm/wrapper'.$url;
5704: } elsif ($url !~ /\.(sequence|page)$/) {
5705: $url='/adm/coursedocs/showdoc'.$url;
5706: }
5707: }
1.610 raeburn 5708: }
1.685 raeburn 5709: unless ($allowed && $env{'request.role.adv'}) {
5710: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5711: $hiddenres = 1;
5712: }
5713: }
1.329 droeschl 5714: }
1.615 raeburn 5715: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 5716: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 5717: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 5718: my $foldername=&escape($foldertitle);
5719: my $folderpath=$env{'form.folderpath'};
5720: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 5721: if (!$allowed && $supplementalflag) {
1.519 raeburn 5722: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 5723: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 5724: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5725: $hiddenfolder = 1;
1.682 raeburn 5726: }
1.510 raeburn 5727: } else {
1.617 raeburn 5728: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
5729: 'parameter_randompick'))[0];
5730: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
5731: 'parameter_randomorder'))[0]=~/^yes$/i);
5732: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
5733: 'parameter_hiddenresource'))[0]=~/^yes$/i);
5734: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
5735: 'parameter_encrypturl'))[0]=~/^yes$/i);
5736: unless ($hiddenmap) {
1.620 raeburn 5737: if (ref($navmapref)) {
5738: unless (ref($$navmapref)) {
5739: $$navmapref = Apache::lonnavmaps::navmap->new();
5740: }
5741: if (ref($$navmapref)) {
5742: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5743: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
5744: unless (@resources) {
5745: $hiddenmap = 1;
5746: unless ($env{'request.role.adv'}) {
5747: $url = '';
5748: $hiddenfolder = 1;
5749: }
1.617 raeburn 5750: }
1.615 raeburn 5751: }
5752: }
5753: }
5754: }
1.617 raeburn 5755: unless ($encryptmap) {
1.620 raeburn 5756: if ((ref($navmapref)) && (ref($$navmapref))) {
5757: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
5758: $encryptmap = 1;
5759: }
1.617 raeburn 5760: }
5761: }
1.630 raeburn 5762:
1.617 raeburn 5763: # Append randompick number, hidden, and encrypted with ":" to foldername,
5764: # so it gets transferred between levels
5765: $folderpath.=$containerarg.'&'.$foldername.
5766: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 5767: unless ($url eq '') {
1.612 raeburn 5768: $url.='folderpath='.&escape($folderpath);
5769: }
1.510 raeburn 5770: my $rpckchk;
5771: if ($rpicknum) {
5772: $rpckchk = ' checked="checked"';
1.543 raeburn 5773: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
5774: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
5775: }
1.510 raeburn 5776: }
1.537 raeburn 5777: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 5778: $rand_pick_text =
1.478 raeburn 5779: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5780: $form_param."\n".
1.478 raeburn 5781: $form_common."\n".
1.611 raeburn 5782: '<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 5783: if ($rpicknum ne '') {
5784: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
5785: }
1.537 raeburn 5786: $rand_pick_text .= '</span></span>'.
5787: $form_end;
1.543 raeburn 5788: my $ro_set;
1.617 raeburn 5789: if ($randorder) {
1.543 raeburn 5790: $ro_set = 'checked="checked"';
5791: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
5792: push(@{$filtersref->{'randomorder'}},$orderidx);
5793: }
5794: }
1.564 raeburn 5795: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 5796: $rand_order_text =
1.537 raeburn 5797: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5798: $form_param."\n".
1.537 raeburn 5799: $form_common."\n".
1.611 raeburn 5800: '<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 5801: $form_end;
1.510 raeburn 5802: }
1.705 raeburn 5803: } elsif ($supplementalflag) {
1.598 raeburn 5804: my $isexttool;
1.626 raeburn 5805: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5806: $url='/adm/wrapper'.$url;
5807: $isexttool = 1;
5808: }
1.510 raeburn 5809: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 5810: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 5811: if ($title) {
1.687 raeburn 5812: $url .= '&title='.$encodedtitle;
1.510 raeburn 5813: }
1.598 raeburn 5814: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 5815: $url .= '&idx='.$orderidx;
5816: }
1.610 raeburn 5817: if ($anchor ne '') {
5818: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5819: }
1.329 droeschl 5820: }
1.519 raeburn 5821: my ($tdalign,$tdwidth);
1.501 raeburn 5822: if ($allowed) {
1.630 raeburn 5823: my $fileloc =
1.501 raeburn 5824: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 5825: if ($isexternal) {
1.630 raeburn 5826: ($editlink,$extresform) =
1.611 raeburn 5827: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5828: undef,undef,undef,undef,undef,undef,
5829: undef,$disabled);
1.626 raeburn 5830: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5831: ($editlink,$extresform) =
5832: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5833: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 5834: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 5835: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 5836: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
5837: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 5838: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 5839: my $suppanchor;
5840: if ($supplementalflag) {
5841: $suppanchor = $anchor;
5842: }
1.630 raeburn 5843: my $jscall =
1.501 raeburn 5844: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
5845: $switchserver,
1.503 raeburn 5846: $forceedit,
1.679 raeburn 5847: undef,$symb,$shownsymb,
1.511 raeburn 5848: &escape($env{'form.folderpath'}),
1.622 raeburn 5849: $renametitle,$hostname,
5850: '','',1,$suppanchor);
1.501 raeburn 5851: if ($jscall) {
1.518 raeburn 5852: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
5853: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 5854: }
5855: }
5856: }
1.519 raeburn 5857: $tdalign = ' align="right" valign="top"';
5858: $tdwidth = ' width="80%"';
1.329 droeschl 5859: }
1.408 raeburn 5860: my $reinit;
5861: if ($crstype eq 'Community') {
5862: $reinit = &mt('(re-initialize community to access)');
5863: } else {
5864: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 5865: }
1.702 raeburn 5866: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
1.650 raeburn 5867: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 5868: $line.= '<br />';
5869: if ($curralias ne '') {
5870: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5871: $lt{'da'}.'</a></span>';
5872: } else {
5873: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5874: $lt{'sa'}.'</a></span>';
5875: }
5876: }
1.701 raeburn 5877: $line.='</td><td><span class="LC_nobreak">';
1.685 raeburn 5878: my ($link,$nolink);
1.472 raeburn 5879: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5880: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
5881: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5882: $nolink = 1;
5883: }
5884: }
5885: if ($nolink) {
5886: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5887: } else {
5888: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5889: }
1.469 www 5890: } elsif ($url) {
1.610 raeburn 5891: if ($anchor ne '') {
5892: if ($supplementalflag) {
5893: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5894: } else {
5895: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
5896: }
5897: }
1.705 raeburn 5898: if (($nomodal) && ($hostname ne '')) {
1.622 raeburn 5899: $link = 'http://'.$hostname.$url;
5900: } else {
5901: $link = $url;
5902: }
1.705 raeburn 5903: my $inhibitmenu;
5904: if ((($supplementalflag) && ($allowed) && ($url =~ m{^/adm/wrapper/})) ||
5905: (($allowed) && (($url =~ m{^/adm/(viewclasslist|$match_domain/$match_username/aboutme)(\?|$)}) ||
5906: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus(\?|$)})))) {
5907: $inhibitmenu = 'only_body=1';
5908: } else {
5909: $inhibitmenu = 'inhibitmenu=yes';
5910: }
5911: $link = &js_escape($link.(($url=~/\?/)?'&':'?').$inhibitmenu.$anchor);
1.685 raeburn 5912: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
5913: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5914: $nolink = 1;
5915: }
5916: }
5917: if ($nolink) {
5918: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5919: } elsif ($nomodal) {
1.621 raeburn 5920: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5921: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
5922: } else {
5923: $line.=&Apache::loncommon::modal_link($link,
5924: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
5925: }
1.469 www 5926: } else {
5927: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5928: }
1.519 raeburn 5929: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 5930: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5931: if ($nolink) {
5932: $line.=$title;
5933: } else {
5934: $line.='<a href="'.$url.'">'.$title.'</a>';
5935: }
1.682 raeburn 5936: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
5937: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
5938: my $editurl = $url;
5939: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
5940: $line .= ' '.'<a href="'.$editurl.'">'.
5941: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
5942: '</a>';
5943: }
5944: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
5945: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
5946: }
1.469 www 5947: } elsif ($url) {
1.685 raeburn 5948: if ($nolink) {
5949: $line.=$title;
5950: } elsif ($nomodal) {
1.621 raeburn 5951: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5952: $title.'</a>';
5953: } else {
5954: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
5955: }
1.617 raeburn 5956: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 5957: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 5958: } else {
5959: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
5960: }
1.633 raeburn 5961: if (($allowed) && ($curralias ne '')) {
5962: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
5963: } else {
5964: $line .= $extresform;
5965: }
5966: $line .= '</td>';
1.478 raeburn 5967: $rand_pick_text = ' ' if ($rand_pick_text eq '');
5968: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 5969: if ($uploaded && $url && !$isfolder && !$ispage) {
5970: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
5971: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
5972: }
5973: }
1.682 raeburn 5974: if ($allowed) {
5975: my %lt=&Apache::lonlocal::texthash(
5976: 'hd' => 'Hidden',
5977: 'ec' => 'URL hidden');
5978: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 5979: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5980: $hidtext = ' checked="checked"';
1.694 raeburn 5981: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 5982: push(@{$filtersref->{'hiddenresource'}},$orderidx);
5983: }
5984: }
1.682 raeburn 5985: $formhidden = 'edit_hiddenresource_'.$orderidx;
5986: $line.=(<<ENDPARMS);
1.329 droeschl 5987: <td class="LC_docs_entry_parameter">
1.537 raeburn 5988: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 5989: $form_param
1.478 raeburn 5990: $form_common
1.611 raeburn 5991: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 5992: $form_end
1.682 raeburn 5993: ENDPARMS
5994: if ($folder =~/^supplemental/) {
5995: $line.= "\n <td>";
5996: } else {
5997: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
5998: $enctext = ' checked="checked"';
5999: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
6000: push(@{$filtersref->{'encrypturl'}},$orderidx);
6001: }
6002: }
6003: $formurlhidden = 'edit_encrypturl_'.$orderidx;
6004: $line.=(<<ENDPARMS);
1.458 raeburn 6005: <br />
1.537 raeburn 6006: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 6007: $form_param
1.478 raeburn 6008: $form_common
1.611 raeburn 6009: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 6010: $form_end
6011: </td>
1.478 raeburn 6012: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
6013: $rand_order_text</td>
1.329 droeschl 6014: ENDPARMS
1.682 raeburn 6015: }
1.329 droeschl 6016: }
1.379 bisitz 6017: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 6018: return $line;
6019: }
6020:
1.538 raeburn 6021: sub action_restrictions {
6022: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
6023: my %denied = (
6024: cut => 0,
6025: copy => 0,
6026: remove => 0,
6027: );
6028: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
6029: # no copy for published maps
6030: $denied{'copy'} = 1;
1.597 raeburn 6031: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
6032: unless ($1 eq 'simpleproblem') {
6033: $denied{'copy'} = 1;
6034: }
6035: $denied{'cut'} = 1;
1.538 raeburn 6036: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
6037: if ($folderpath =~ /^default&[^\&]+$/) {
6038: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
6039: $denied{'remove'} = 1;
6040: }
6041: $denied{'cut'} = 1;
6042: $denied{'copy'} = 1;
6043: }
6044: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
6045: my $group = $1;
6046: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
6047: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
6048: $denied{'remove'} = 1;
6049: }
6050: }
6051: $denied{'cut'} = 1;
6052: $denied{'copy'} = 1;
6053: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
6054: my $group = $1;
6055: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
6056: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
6057: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
6058: if (keys(%groupsettings) > 0) {
6059: $denied{'remove'} = 1;
6060: }
6061: $denied{'cut'} = 1;
6062: $denied{'copy'} = 1;
6063: }
6064: }
6065: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
6066: my $group = $1;
6067: if ($url =~ /group_boards_\Q$group\E/) {
6068: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
6069: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
6070: if (keys(%groupsettings) > 0) {
6071: if (ref($groupsettings{'functions'}) eq 'HASH') {
6072: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
6073: $denied{'remove'} = 1;
6074: }
6075: }
6076: }
6077: $denied{'cut'} = 1;
6078: $denied{'copy'} = 1;
6079: }
6080: }
6081: }
6082: return %denied;
6083: }
6084:
1.533 raeburn 6085: sub new_timebased_suffix {
1.538 raeburn 6086: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 6087: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 6088: if ($type eq 'paste') {
6089: $prefix = $type;
6090: $namespace = 'courseeditor';
1.587 raeburn 6091: $idtype = 'addcode';
1.538 raeburn 6092: } elsif ($type eq 'map') {
1.533 raeburn 6093: $prefix = 'docs';
6094: if ($area eq 'supplemental') {
6095: $prefix = 'supp';
6096: }
6097: $prefix .= $container;
6098: $namespace = 'uploadedmaps';
6099: } else {
6100: $prefix = $type;
6101: $namespace = 'templated';
1.504 raeburn 6102: }
6103: my ($suffix,$freedlock,$error) =
1.587 raeburn 6104: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 6105: if (!$suffix) {
1.538 raeburn 6106: if ($type eq 'paste') {
6107: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
6108: } elsif ($type eq 'map') {
1.533 raeburn 6109: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
6110: } elsif ($type eq 'smppg') {
6111: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 6112: } elsif ($type eq 'exttool') {
6113: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 6114: } else {
1.565 bisitz 6115: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 6116: }
1.504 raeburn 6117: if ($error) {
6118: $errtext .= '<br />'.$error;
6119: }
6120: }
6121: if ($freedlock ne 'ok') {
1.630 raeburn 6122: $locknotfreed =
1.533 raeburn 6123: '<div class="LC_error">'.
6124: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 6125: if ($type eq 'paste') {
1.591 raeburn 6126: if ($freedlock eq 'nolock') {
6127: $locknotfreed =
6128: '<div class="LC_error">'.
6129: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
6130:
1.593 droeschl 6131: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 6132: } else {
6133: $locknotfreed .=
6134: &mt('This will prevent addition of items to the clipboard until your next log-in.');
6135: }
1.538 raeburn 6136: } elsif ($type eq 'map') {
1.591 raeburn 6137: $locknotfreed .=
6138: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 6139: } elsif ($type eq 'smppg') {
6140: $locknotfreed .=
6141: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 6142: } elsif ($type eq 'exttool') {
6143: $locknotfreed .=
6144: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 6145: } else {
6146: $locknotfreed .=
1.565 bisitz 6147: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 6148: }
1.538 raeburn 6149: unless ($type eq 'paste') {
6150: $locknotfreed .=
1.560 raeburn 6151: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
6152: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 6153: }
6154: $locknotfreed .= '</div>';
1.504 raeburn 6155: }
6156: return ($suffix,$errtext,$locknotfreed);
6157: }
6158:
1.329 droeschl 6159: =pod
6160:
6161: =item tiehash()
6162:
6163: tie the hash
6164:
6165: =cut
6166:
6167: sub tiehash {
6168: my ($mode)=@_;
6169: $hashtied=0;
6170: if ($env{'request.course.fn'}) {
6171: if ($mode eq 'write') {
6172: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
6173: &GDBM_WRCREAT(),0640)) {
6174: $hashtied=2;
6175: }
6176: } else {
6177: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
6178: &GDBM_READER(),0640)) {
6179: $hashtied=1;
6180: }
6181: }
1.364 bisitz 6182: }
1.329 droeschl 6183: }
6184:
6185: sub untiehash {
6186: if ($hashtied) { untie %hash; }
6187: $hashtied=0;
6188: return OK;
6189: }
6190:
6191:
6192:
6193:
6194: sub checkonthis {
1.637 raeburn 6195: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 6196: $url=&unescape($url);
6197: $alreadyseen{$url}=1;
6198: $r->rflush();
6199: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
6200: $r->print("\n<br />");
6201: if ($level==0) {
6202: $r->print("<br />");
6203: }
6204: for (my $i=0;$i<=$level*5;$i++) {
6205: $r->print(' ');
6206: }
6207: $r->print('<a href="'.$url.'" target="cat">'.
6208: ($title?$title:$url).'</a> ');
6209: if ($url=~/^\/res\//) {
1.637 raeburn 6210: my $updated;
6211: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
6212: ($url !~ /\.\d+\.\w+$/)) {
6213: $updated = &Apache::lonnet::remove_stale_resfile($url);
6214: }
1.329 droeschl 6215: my $result=&Apache::lonnet::repcopy(
6216: &Apache::lonnet::filelocation('',$url));
6217: if ($result eq 'ok') {
6218: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 6219: if ($updated) {
6220: $r->print('<br />');
6221: for (my $i=0;$i<=$level*5;$i++) {
6222: $r->print(' ');
6223: }
6224: $r->print('- '.&mt('Outdated copy removed'));
6225: }
1.329 droeschl 6226: $r->rflush();
6227: &Apache::lonnet::countacc($url);
6228: $url=~/\.(\w+)$/;
6229: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
6230: $r->print('<br />');
6231: $r->rflush();
6232: for (my $i=0;$i<=$level*5;$i++) {
6233: $r->print(' ');
6234: }
6235: $r->print('- '.&mt('Rendering:').' ');
6236: my ($errorcount,$warningcount)=split(/:/,
6237: &Apache::lonnet::ssi_body($url,
6238: ('grade_target'=>'web',
6239: 'return_only_error_and_warning_counts' => 1)));
6240: if (($errorcount) ||
6241: ($warningcount)) {
6242: if ($errorcount) {
1.369 bisitz 6243: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 6244: &mt('[quant,_1,error]',$errorcount).'</span>');
6245: }
6246: if ($warningcount) {
6247: $r->print('<span class="LC_warning">'.
6248: &mt('[quant,_1,warning]',$warningcount).'</span>');
6249: }
6250: } else {
6251: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
6252: }
6253: $r->rflush();
6254: }
6255: my $dependencies=
6256: &Apache::lonnet::metadata($url,'dependencies');
6257: foreach my $dep (split(/\,/,$dependencies)) {
6258: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 6259: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 6260: }
6261: }
6262: } elsif ($result eq 'unavailable') {
6263: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
6264: } elsif ($result eq 'not_found') {
6265: unless ($url=~/\$/) {
1.521 bisitz 6266: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 6267: } else {
1.366 bisitz 6268: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 6269: }
6270: } else {
6271: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
6272: }
1.637 raeburn 6273: if (($updated) && ($result ne 'ok')) {
6274: $r->print('<br />'.&mt('Outdated copy removed'));
6275: }
1.329 droeschl 6276: }
6277: }
6278: }
6279:
6280:
6281:
6282: =pod
6283:
6284: =item list_symbs()
6285:
1.485 raeburn 6286: List Content Identifiers
1.329 droeschl 6287:
6288: =cut
6289:
6290: sub list_symbs {
6291: my ($r) = @_;
6292:
1.408 raeburn 6293: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 6294: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
6295: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
6296: $r->print(&startContentScreen('tools'));
1.329 droeschl 6297: my $navmap = Apache::lonnavmaps::navmap->new();
6298: if (!defined($navmap)) {
6299: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
6300: '<div class="LC_error">'.
6301: &mt('Unable to retrieve information about course contents').
6302: '</div>');
1.408 raeburn 6303: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 6304: } else {
1.484 raeburn 6305: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
6306: &Apache::loncommon::start_data_table().
6307: &Apache::loncommon::start_data_table_header_row().
6308: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
6309: &Apache::loncommon::end_data_table_header_row()."\n");
6310: my $count;
1.329 droeschl 6311: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 6312: $r->print(&Apache::loncommon::start_data_table_row().
6313: '<td>'.$res->compTitle().'</td>'.
6314: '<td>'.$res->symb().'</td>'.
1.521 bisitz 6315: &Apache::loncommon::end_data_table_row());
1.484 raeburn 6316: $count ++;
6317: }
6318: if (!$count) {
6319: $r->print(&Apache::loncommon::start_data_table_row().
6320: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
6321: &Apache::loncommon::end_data_table_row());
1.329 droeschl 6322: }
1.484 raeburn 6323: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 6324: }
1.521 bisitz 6325: $r->print(&endContentScreen());
1.329 droeschl 6326: }
6327:
1.651 raeburn 6328: sub short_urls {
6329: my ($r,$canedit) = @_;
6330: my $crstype = &Apache::loncommon::course_type();
6331: my $formname = 'shortenurl';
6332: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
6333: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
6334: $r->print(&startContentScreen('tools'));
6335: my ($navmap,$errormsg) =
6336: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
6337: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6338: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6339: my (%maps,%resources,%titles);
6340: if (!ref($navmap)) {
6341: $r->print($errormsg.
6342: &endContentScreen());
6343: return '';
6344: } else {
1.652 raeburn 6345: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 6346: $r->rflush();
6347: my $readonly;
6348: if ($canedit) {
1.671 raeburn 6349: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 6350: if ($numnew) {
6351: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
6352: }
6353: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
6354: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
6355: foreach my $error (@{$errors}) {
6356: $r->print('<li>'.$error.'</li>');
6357: }
6358: $r->print('</ul><br />');
6359: }
6360: } else {
6361: $readonly = 1;
6362: }
6363: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
6364: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
1.711 raeburn 6365: undef,undef,undef,undef,undef,\%currtiny,undef,$readonly));
1.651 raeburn 6366: }
6367: $r->print(&endContentScreen());
6368: }
6369:
1.637 raeburn 6370: sub contentverifyform {
6371: my ($r) = @_;
6372: my $crstype = &Apache::loncommon::course_type();
6373: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6374: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
6375: $r->print(&startContentScreen('tools'));
6376: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
6377: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
6378: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
6379: ' <span class="LC_nobreak">'.
6380: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
6381: &mt('No').'</label>'.(' 'x2).
6382: '<label><input type="radio" name="checkstale" value="1" />'.
6383: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 6384: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 6385: '<input type="hidden" value="1" name="tools" />'.
6386: '<input type="hidden" value="1" name="verify" /></p></form>');
6387: $r->print(&endContentScreen());
6388: return;
6389: }
1.329 droeschl 6390:
6391: sub verifycontent {
1.637 raeburn 6392: my ($r,$checkstale) = @_;
1.408 raeburn 6393: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 6394: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6395: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 6396: $r->print(&startContentScreen('tools'));
6397: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 6398: $hashtied=0;
6399: undef %alreadyseen;
6400: %alreadyseen=();
6401: &tiehash();
1.484 raeburn 6402:
1.329 droeschl 6403: foreach my $key (keys(%hash)) {
6404: if ($hash{$key}=~/\.(page|sequence)$/) {
6405: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
6406: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 6407: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 6408: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 6409: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 6410: }
6411: }
6412: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 6413: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 6414: }
6415: }
6416: &untiehash();
1.442 www 6417: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 6418: $r->print(&endContentScreen());
1.329 droeschl 6419: }
6420:
6421: sub devalidateversioncache {
6422: my $src=shift;
6423: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
6424: &Apache::lonnet::clutter($src));
6425: }
6426:
6427: sub checkversions {
1.611 raeburn 6428: my ($r,$canedit) = @_;
1.408 raeburn 6429: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 6430: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
6431: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 6432: $r->print(&startContentScreen('tools'));
1.442 www 6433:
1.329 droeschl 6434: my $header='';
6435: my $startsel='';
6436: my $monthsel='';
6437: my $weeksel='';
6438: my $daysel='';
6439: my $allsel='';
6440: my %changes=();
6441: my $starttime=0;
6442: my $haschanged=0;
6443: my %setversions=&Apache::lonnet::dump('resourceversions',
6444: $env{'course.'.$env{'request.course.id'}.'.domain'},
6445: $env{'course.'.$env{'request.course.id'}.'.num'});
6446:
6447: $hashtied=0;
6448: &tiehash();
1.611 raeburn 6449: if ($canedit) {
6450: my %newsetversions=();
6451: if ($env{'form.setmostrecent'}) {
6452: $haschanged=1;
6453: foreach my $key (keys(%hash)) {
6454: if ($key=~/^ids\_(\/res\/.+)$/) {
6455: $newsetversions{$1}='mostrecent';
6456: &devalidateversioncache($1);
6457: }
6458: }
6459: } elsif ($env{'form.setcurrent'}) {
6460: $haschanged=1;
6461: foreach my $key (keys(%hash)) {
6462: if ($key=~/^ids\_(\/res\/.+)$/) {
6463: my $getvers=&Apache::lonnet::getversion($1);
6464: if ($getvers>0) {
6465: $newsetversions{$1}=$getvers;
6466: &devalidateversioncache($1);
6467: }
6468: }
1.329 droeschl 6469: }
1.611 raeburn 6470: } elsif ($env{'form.setversions'}) {
6471: $haschanged=1;
6472: foreach my $key (keys(%env)) {
6473: if ($key=~/^form\.set_version_(.+)$/) {
6474: my $src=$1;
6475: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
6476: $newsetversions{$src}=$env{$key};
6477: &devalidateversioncache($src);
6478: }
6479: }
1.329 droeschl 6480: }
1.611 raeburn 6481: }
6482: if ($haschanged) {
6483: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
6484: $env{'course.'.$env{'request.course.id'}.'.domain'},
6485: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
6486: $r->print(&Apache::loncommon::confirmwrapper(
6487: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
6488: } else {
6489: $r->print(&Apache::loncommon::confirmwrapper(
6490: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 6491: }
1.611 raeburn 6492: &mark_hash_old();
6493: }
6494: &changewarning($r,'');
1.329 droeschl 6495: }
6496: if ($env{'form.timerange'} eq 'all') {
6497: # show all documents
1.549 raeburn 6498: $header=&mt('All content in '.$crstype);
1.521 bisitz 6499: $allsel=' selected="selected"';
1.329 droeschl 6500: foreach my $key (keys(%hash)) {
6501: if ($key=~/^ids\_(\/res\/.+)$/) {
6502: my $src=$1;
6503: $changes{$src}=1;
6504: }
6505: }
6506: } else {
6507: # show documents which changed
6508: %changes=&Apache::lonnet::dump
6509: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
6510: $env{'course.'.$env{'request.course.id'}.'.num'});
6511: my $firstkey=(keys(%changes))[0];
6512: unless ($firstkey=~/^error\:/) {
6513: unless ($env{'form.timerange'}) {
6514: $env{'form.timerange'}=604800;
6515: }
6516: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
6517: .&mt('seconds');
6518: if ($env{'form.timerange'}==-1) {
6519: $seltext='since start of course';
1.521 bisitz 6520: $startsel=' selected="selected"';
1.329 droeschl 6521: $env{'form.timerange'}=time;
6522: }
6523: $starttime=time-$env{'form.timerange'};
6524: if ($env{'form.timerange'}==2592000) {
6525: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6526: $monthsel=' selected="selected"';
1.329 droeschl 6527: } elsif ($env{'form.timerange'}==604800) {
6528: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6529: $weeksel=' selected="selected"';
1.329 droeschl 6530: } elsif ($env{'form.timerange'}==86400) {
6531: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6532: $daysel=' selected="selected"';
1.329 droeschl 6533: }
6534: $header=&mt('Content changed').' '.$seltext;
6535: } else {
6536: $header=&mt('No content modifications yet.');
6537: }
6538: }
6539: %setversions=&Apache::lonnet::dump('resourceversions',
6540: $env{'course.'.$env{'request.course.id'}.'.domain'},
6541: $env{'course.'.$env{'request.course.id'}.'.num'});
6542: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 6543: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 6544: 'lm' => 'Version changes since last Month',
6545: 'lw' => 'Version changes since last Week',
6546: 'sy' => 'Version changes since Yesterday',
6547: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 6548: 'cd' => 'Change display',
1.329 droeschl 6549: 'sd' => 'Display',
6550: 'fi' => 'File',
6551: 'md' => 'Modification Date',
6552: 'mr' => 'Most recently published Version',
1.408 raeburn 6553: 've' => 'Version used in '.$crstype,
6554: 'vu' => 'Set Version to be used in '.$crstype,
6555: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 6556: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
6557: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 6558: 'di' => 'Differences',
1.484 raeburn 6559: 'save' => 'Save changes',
6560: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 6561: 'act' => 'Actions');
1.611 raeburn 6562: my ($disabled,$readonly);
6563: unless ($canedit) {
6564: $disabled = 'disabled="disabled"';
6565: $readonly = 1;
6566: }
1.329 droeschl 6567: $r->print(<<ENDHEADERS);
1.484 raeburn 6568: <h4 class="LC_info">$header</h4>
1.329 droeschl 6569: <form action="/adm/coursedocs" method="post">
6570: <input type="hidden" name="versions" value="1" />
1.484 raeburn 6571: <div class="LC_left_float">
1.479 golterma 6572: <fieldset>
1.484 raeburn 6573: <legend>$lt{'cd'}</legend>
1.329 droeschl 6574: <select name="timerange">
1.521 bisitz 6575: <option value='all'$allsel>$lt{'al'}</option>
6576: <option value="-1"$startsel>$lt{'st'}</option>
6577: <option value="2592000"$monthsel>$lt{'lm'}</option>
6578: <option value="604800"$weeksel>$lt{'lw'}</option>
6579: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 6580: </select>
6581: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 6582: </fieldset>
6583: </div>
6584: <div class="LC_left_float">
6585: <fieldset>
6586: <legend>$lt{'act'}</legend>
1.611 raeburn 6587: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
6588: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 6589: </fieldset>
6590: </div>
6591: <br clear="all" />
6592: <hr />
6593: <h4>$lt{'vers'}</h4>
1.329 droeschl 6594: ENDHEADERS
1.479 golterma 6595: #number of columns for version history
1.571 raeburn 6596: my %changedbytime;
6597: foreach my $key (keys(%changes)) {
6598: #excludes not versionable problems from resource version history:
6599: next if ($key =~ /^\/res\/lib\/templates/);
6600: my $chg;
6601: if ($env{'form.timerange'} eq 'all') {
6602: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6603: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
6604: } else {
6605: $chg = $changes{$key};
6606: next if ($chg < $starttime);
6607: }
6608: push(@{$changedbytime{$chg}},$key);
6609: }
6610: if (keys(%changedbytime) == 0) {
6611: &untiehash();
6612: $r->print(&mt('No content changes in imported content in specified time frame').
6613: &endContentScreen());
6614: return;
6615: }
1.479 golterma 6616: $r->print(
1.611 raeburn 6617: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6618: &Apache::loncommon::start_data_table().
6619: &Apache::loncommon::start_data_table_header_row().
6620: '<th>'.&mt('Resources').'</th>'.
6621: "<th>$lt{'mr'}</th>".
6622: "<th>$lt{'ve'}</th>".
6623: "<th>$lt{'vu'}</th>".
6624: '<th>'.&mt('History').'</th>'.
6625: &Apache::loncommon::end_data_table_header_row()
6626: );
1.571 raeburn 6627: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
6628: foreach my $key (sort(@{$changedbytime{$chg}})) {
6629: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6630: my $currentversion=&Apache::lonnet::getversion($key);
6631: if ($currentversion<0) {
6632: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
6633: }
6634: my $linkurl=&Apache::lonnet::clutter($key);
6635: $r->print(
6636: &Apache::loncommon::start_data_table_row().
6637: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
6638: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
6639: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
6640: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
6641: '<td align="right">'
6642: );
6643: # Used in course
6644: my $usedversion=$hash{'version_'.$linkurl};
6645: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 6646: if ($usedversion != $currentversion) {
1.479 golterma 6647: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 6648: } else {
1.479 golterma 6649: $r->print($usedversion);
6650: }
1.329 droeschl 6651: } else {
1.521 bisitz 6652: $r->print($currentversion);
1.329 droeschl 6653: }
1.571 raeburn 6654: $r->print('</td><td title="'.$lt{'vu'}.'">');
6655: # Set version
6656: $r->print(&Apache::loncommon::select_form(
6657: $setversions{$linkurl},
6658: 'set_version_'.$linkurl,
6659: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
6660: '' => '',
6661: 'mostrecent' => &mt('most recent'),
1.611 raeburn 6662: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 6663: my $lastold=1;
6664: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
6665: my $url=$root.'.'.$prevvers.'.'.$extension;
6666: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
6667: $lastold=$prevvers;
6668: }
6669: }
6670: $r->print('</td>');
6671: # List all available versions
6672: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
6673: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
6674: my $url=$root.'.'.$prevvers.'.'.$extension;
6675: $r->print(
6676: '<span class="LC_nobreak">'
6677: .'<a href="'.&Apache::lonnet::clutter($url).'">'
6678: .&mt('Version [_1]',$prevvers).'</a>'
6679: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 6680: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 6681: .')');
6682: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
6683: $r->print(
6684: ' <a href="/adm/diff?filename='.
6685: &Apache::lonnet::clutter($root.'.'.$extension).
6686: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
6687: '" target="diffs">'.&mt('Diffs').'</a>');
6688: }
6689: $r->print('</span><br />');
1.329 droeschl 6690: }
1.571 raeburn 6691: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 6692: }
1.329 droeschl 6693: }
1.521 bisitz 6694: $r->print(
6695: &Apache::loncommon::end_data_table().
1.611 raeburn 6696: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6697: '</form>'
6698: );
1.329 droeschl 6699:
6700: &untiehash();
1.521 bisitz 6701: $r->print(&endContentScreen());
1.571 raeburn 6702: return;
1.329 droeschl 6703: }
6704:
6705: sub mark_hash_old {
6706: my $retie_hash=0;
6707: if ($hashtied) {
6708: $retie_hash=1;
6709: &untiehash();
6710: }
6711: &tiehash('write');
6712: $hash{'old'}=1;
6713: &untiehash();
6714: if ($retie_hash) { &tiehash(); }
6715: }
6716:
6717: sub is_hash_old {
6718: my $untie_hash=0;
6719: if (!$hashtied) {
6720: $untie_hash=1;
6721: &tiehash();
6722: }
6723: my $return=$hash{'old'};
6724: if ($untie_hash) { &untiehash(); }
6725: return $return;
6726: }
6727:
6728: sub changewarning {
6729: my ($r,$postexec,$message,$url)=@_;
6730: if (!&is_hash_old()) { return; }
6731: my $pathvar='folderpath';
6732: my $path=&escape($env{'form.folderpath'});
6733: if (!defined($url)) {
6734: $url='/adm/coursedocs?'.$pathvar.'='.$path;
6735: }
6736: my $course_type = &Apache::loncommon::course_type();
6737: if (!defined($message)) {
6738: $message='Changes will become active for your current session after [_1], or the next time you log in.';
6739: }
1.653 raeburn 6740: my $windowname = 'loncapaclient';
6741: if ($env{'request.lti.login'}) {
6742: $windowname .= 'lti';
6743: }
1.329 droeschl 6744: $r->print("\n\n".
1.372 bisitz 6745: '<script type="text/javascript">'."\n".
6746: '// <![CDATA['."\n".
6747: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
6748: '// ]]>'."\n".
1.369 bisitz 6749: '</script>'."\n".
1.653 raeburn 6750: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 6751: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 6752: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 6753: &mt($message,' <input type="hidden" name="'.
6754: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 6755: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 6756: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 6757: }
6758:
6759:
6760: sub init_breadcrumbs {
1.571 raeburn 6761: my ($form,$text,$help)=@_;
1.329 droeschl 6762: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 6763: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 6764: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 6765: faq=>273,
6766: bug=>'Instructor Interface',
1.571 raeburn 6767: help => $help});
1.329 droeschl 6768: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
6769: text=>$text,
6770: faq=>273,
6771: bug=>'Instructor Interface'});
6772: }
6773:
1.441 www 6774: # subroutine to list form elements
6775: sub create_list_elements {
6776: my @formarr = @_;
6777: my $list = '';
1.501 raeburn 6778: foreach my $button (@formarr){
6779: foreach my $picture (keys(%{$button})) {
6780: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 6781: }
6782: }
6783: return $list;
6784: }
1.329 droeschl 6785:
1.441 www 6786: # subroutine to create ul from list elements
6787: sub create_form_ul {
6788: my $list = shift;
6789: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
6790: return $ul;
6791: }
1.329 droeschl 6792:
1.442 www 6793: #
6794: # Start tabs
6795: #
6796:
6797: sub startContentScreen {
1.484 raeburn 6798: my ($mode) = @_;
6799: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 6800: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 6801: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
6802: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
6803: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
6804: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
6805: } else {
1.549 raeburn 6806: $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 6807: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
6808: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
6809: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
6810: }
6811: $output .= "\n".'</ul>'."\n";
6812: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
6813: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
6814: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
6815: return $output;
1.442 www 6816: }
6817:
6818: #
6819: # End tabs
6820: #
6821:
6822: sub endContentScreen {
1.484 raeburn 6823: return '</div></div></div>';
1.442 www 6824: }
1.329 droeschl 6825:
1.446 www 6826: sub supplemental_base {
1.548 raeburn 6827: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 6828: }
6829:
1.329 droeschl 6830: sub handler {
6831: my $r = shift;
6832: &Apache::loncommon::content_type($r,'text/html');
6833: $r->send_http_header;
6834: return OK if $r->header_only;
1.484 raeburn 6835:
6836: # get course data
1.408 raeburn 6837: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 6838: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
6839: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.712 raeburn 6840: my $coursehome=$env{'course.'.$env{'request.course.id'}.'.home'};
1.484 raeburn 6841:
1.606 raeburn 6842: # get docroot
6843: my $londocroot = $r->dir_config('lonDocRoot');
6844:
1.484 raeburn 6845: # graphics settings
6846: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 6847:
1.443 www 6848: #
1.329 droeschl 6849: # --------------------------------------------- Initialize help topics for this
6850: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 6851: 'Adding_External_Resource','Adding_External_Tool',
6852: 'Navigate_Content','Adding_Folders','Docs_Overview',
6853: 'Load_Map','Supplemental','Score_Upload_Form',
6854: 'Adding_Pages','Importing_LON-CAPA_Resource',
6855: 'Importing_IMS_Course','Uploading_From_Harddrive',
1.706 raeburn 6856: 'Course_Roster','Web_Page','Dropbox','Simple_Problem',
6857: 'Standard_Problem','Course_Resources',
6858: 'Search_LON-CAPA_Resource','Import_Stored_Links') {
1.329 droeschl 6859: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
6860: }
6861: # Composite help files
6862: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
6863: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
6864: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
6865: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
6866: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
6867: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 6868: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 6869: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 6870: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 6871: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 6872:
1.611 raeburn 6873: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 6874: # does this user have privileges to modify content.
6875: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 6876: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 6877: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6878: $allowed = 1;
1.682 raeburn 6879: }
6880: $canedit = 1;
6881: $canview = 1;
6882: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
6883: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
6884: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6885: $allowed = 1;
6886: }
1.682 raeburn 6887: $canview = 1;
1.611 raeburn 6888: }
6889: unless ($canedit) {
6890: $disabled = ' disabled="disabled"';
1.472 raeburn 6891: }
1.582 raeburn 6892: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 6893: if ($env{'form.inhibitmenu'}) {
6894: unless ($env{'form.inhibitmenu'} eq 'yes') {
6895: delete($env{'form.inhibitmenu'});
6896: }
6897: }
6898:
1.582 raeburn 6899: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 6900: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 6901: if (!$canedit) {
6902: &verifycontent($r);
6903: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
6904: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
6905: text=>'Results',
6906: faq=>273,
6907: bug=>'Instructor Interface'});
6908: &verifycontent($r,$env{'form.checkstale'});
6909: } else {
6910: &contentverifyform($r);
6911: }
1.329 droeschl 6912: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 6913: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 6914: &list_symbs($r);
1.651 raeburn 6915: } elsif ($allowed && $env{'form.shorturls'}) {
6916: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
6917: &short_urls($r,$canedit);
1.329 droeschl 6918: } elsif ($allowed && $env{'form.docslog'}) {
6919: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 6920: my $folder = $env{'form.folder'};
6921: if ($folder eq '') {
6922: $folder='default';
6923: }
1.611 raeburn 6924: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 6925: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 6926: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 6927: &checkversions($r,$canedit);
6928: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.709 raeburn 6929: &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
1.329 droeschl 6930: &dumpcourse($r);
1.712 raeburn 6931: } elsif (($canedit || $canview) && ($env{'form.copyauthored'})) {
6932: &init_breadcrumbs('copyauthored','Copy from Course Authoring to User Authoring');
6933: my $readonly;
6934: if (!$canedit) {
6935: $readonly = 1;
6936: }
6937: ©crsauthored($r,$coursenum,$coursedom,$coursehome,$readonly);
1.611 raeburn 6938: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 6939: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 6940: &Apache::imsexport::exportcourse($r);
1.329 droeschl 6941: } else {
1.611 raeburn 6942: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 6943: $noendpage = 1;
6944: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
6945: if ($redirect) {
6946: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
6947: my $container = 'sequence';
6948: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
6949: $is_random_order,$container) =
6950: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
6951: my (@folders)=split('&',$env{'form.folderpath'});
6952: $env{'form.foldername'}=&unescape(pop(@folders));
6953: my $folder=pop(@folders);
6954: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
6955: $folder.'.'.$container);
6956: my $warning;
6957: if ($fatal) {
6958: if ($container eq 'page') {
6959: $warning = &mt('An error occurred retrieving the contents of the current page.');
6960: } else {
6961: $warning = &mt('An error occurred retrieving the contents of the current folder.');
6962: }
6963: } else {
6964: my $url = $redirect;
6965: my $srcfile = $londocroot.$url;
6966: $url =~ s{^/priv/}{/res/};
6967: my $targetfile = $londocroot.$url;
6968: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
6969: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
6970: $env{'form.folder'} = $folder;
6971: &snapshotbefore();
6972: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
6973: my $ext = 'false';
6974: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
6975: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
6976: ':'.$ext.':normal:res';
6977: push(@LONCAPA::map::order,$newidx);
6978: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
6979: 'string_yesno');
6980: &remember_parms($newidx,'hiddenresource','set','yes');
6981: ($errtext,$fatal) =
6982: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
6983: &log_differences($plain);
6984: &mark_hash_old();
6985: $r->internal_redirect($redirect);
6986: return OK;
6987: }
1.654 raeburn 6988: } else {
6989: $r->internal_redirect($redirect);
1.606 raeburn 6990: }
6991: }
6992: }
1.445 www 6993: #
6994: # Done catching special calls
1.484 raeburn 6995: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 6996: # Get the parameters that may be needed
6997: #
6998: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 6999: ['folderpath','title',
1.519 raeburn 7000: 'forcesupplement','forcestandard',
1.510 raeburn 7001: 'tools','symb','command','supppath']);
1.445 www 7002:
1.635 raeburn 7003: foreach my $item ('forcesupplement','forcestandard','tools') {
7004: next if ($env{'form.'.$item} eq '');
7005: unless ($env{'form.'.$item} eq '1') {
7006: delete($env{'form.'.$item});
7007: }
7008: }
7009:
7010: if ($env{'form.command'}) {
7011: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
7012: delete($env{'form.command'});
7013: }
7014: }
7015:
7016: if ($env{'form.symb'}) {
7017: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
7018: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
7019: delete($env{'form.symb'});
7020: }
7021: }
7022:
1.445 www 7023: # standard=1: this is a "new-style" course with an uploaded map as top level
7024: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 7025:
7026: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 7027:
1.484 raeburn 7028: # Decide whether this should display supplemental or main content or utilities
1.445 www 7029: # supplementalflag=1: show supplemental documents
7030: # supplementalflag=0: show standard documents
1.484 raeburn 7031: # toolsflag=1: show utilities
1.445 www 7032:
1.561 raeburn 7033: my $unesc_folderpath = &unescape($env{'form.folderpath'});
7034: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
7035: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 7036: $supplementalflag=0;
7037: }
7038: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
7039: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
1.705 raeburn 7040: unless (($supplementalflag) ||
7041: ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
7042: unless ($allowed) { $supplementalflag=1; }
7043: unless ($standard) { $supplementalflag=1; }
7044: }
1.484 raeburn 7045: my $toolsflag=0;
7046: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 7047:
1.635 raeburn 7048: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 7049: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 7050: }
7051:
1.685 raeburn 7052: my $backto_supppath;
1.635 raeburn 7053: if ($env{'form.supppath'} ne '') {
1.685 raeburn 7054: if ($supplementalflag && $allowed) {
7055: $backto_supppath = &validate_supppath($coursenum,$coursedom);
7056: }
1.635 raeburn 7057: }
7058:
1.329 droeschl 7059: my $script='';
7060: my $showdoc=0;
1.457 raeburn 7061: my $addentries = {};
1.475 raeburn 7062: my $container;
1.329 droeschl 7063: my $containertag;
1.508 raeburn 7064: my $pathitem;
1.598 raeburn 7065: my %ltitools;
1.699 raeburn 7066: my $posslti;
1.617 raeburn 7067: my $hiddentop;
1.615 raeburn 7068: my $navmap;
1.617 raeburn 7069: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 7070:
1.464 www 7071: # Do we directly jump somewhere?
1.525 raeburn 7072: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 7073: if ($env{'form.symb'} ne '') {
1.522 raeburn 7074: $env{'form.folderpath'}=
1.617 raeburn 7075: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 7076: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 7077: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 7078: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 7079: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 7080: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 7081: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 7082: }
1.472 raeburn 7083: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 7084: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 7085: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 7086: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 7087: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 7088: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
7089: } elsif ($env{'form.command'} eq 'contents') {
7090: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
7091: } elsif ($env{'form.command'} eq 'home') {
7092: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 7093: }
7094:
1.525 raeburn 7095:
1.445 www 7096: # Where do we store these for when we come back?
7097: my $stored_folderpath='docs_folderpath';
7098: if ($supplementalflag) {
7099: $stored_folderpath='docs_sup_folderpath';
7100: }
1.464 www 7101:
1.519 raeburn 7102: # No folderpath, and in edit mode, see if we have something stored
7103: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 7104: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 7105: {'folderpath' => 'scalar'});
1.615 raeburn 7106:
7107: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
7108: if ($supplementalflag) {
7109: undef($env{'form.folderpath'}) if ($1 eq 'default');
7110: } else {
7111: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
7112: }
7113: } else {
1.523 raeburn 7114: undef($env{'form.folderpath'});
7115: }
1.677 raeburn 7116: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 7117: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 7118: }
1.329 droeschl 7119: }
1.706 raeburn 7120:
7121: # Set folderpath if we are not allowed to make changes and this is supplemental content
1.705 raeburn 7122: if ((!$allowed) && ($supplementalflag)) {
1.446 www 7123: unless ($env{'form.folderpath'} =~ /^supplemental/) {
7124: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 7125: }
7126: }
1.446 www 7127: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 7128: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 7129: $env{'form.folderpath'} = &supplemental_base()
7130: .'&'.
1.329 droeschl 7131: $env{'form.folderpath'};
7132: }
1.685 raeburn 7133: # If allowed and user's role is not advanced check folderpath is not hidden
7134: my $hidden_and_empty;
1.687 raeburn 7135: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 7136: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 7137: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 7138: my $folder = $pathitems[-2];
7139: if ($folder eq '') {
7140: undef($env{'form.folderpath'});
7141: } else {
7142: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 7143: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 7144: $folderurl .= '.page';
7145: } else {
7146: $folderurl .= '.sequence';
7147: }
1.685 raeburn 7148: if ($supplementalflag) {
7149: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
7150: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 7151: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 7152: if (ref($supplemental) eq 'HASH') {
7153: my ($suppmap,$suppmapnum);
7154: if ($folder eq 'supplemental') {
7155: $suppmap = 'default';
7156: $suppmapnum = 0;
7157: } elsif ($folder =~ /^supplemental_(\d+)$/) {
7158: $suppmap = $1;
7159: $suppmapnum = $suppmap;
7160: }
7161: if ($hiddenfolder) {
7162: my $hascontent;
7163: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
7164: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
7165: $hascontent = 1;
7166: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
7167: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
7168: if ($id =~ /^$suppmapnum\:/) {
7169: $hascontent = 1;
7170: last;
7171: }
7172: }
7173: }
7174: last if ($hascontent);
7175: }
7176: unless ($hascontent) {
7177: if ($foldername ne '') {
7178: $hidden_and_empty = $foldername;
7179: } else {
7180: $hidden_and_empty = $folder;
7181: }
7182: }
7183: }
7184: }
7185: } else {
7186: unless (ref($navmap)) {
7187: $navmap = Apache::lonnavmaps::navmap->new();
7188: }
7189: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
7190: $foldername = &HTML::Entities::decode(&unescape($foldername));
7191: if (ref($navmap)) {
7192: if ($hiddenfolder ||
7193: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
7194: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
7195: unless (@resources) {
7196: if ($foldername ne '') {
7197: $hidden_and_empty = $foldername;
7198: } else {
7199: $hidden_and_empty = $folder;
7200: }
7201: }
7202: }
7203: }
1.617 raeburn 7204: }
1.685 raeburn 7205: if ($hidden_and_empty ne '') {
7206: splice(@pathitems,-2);
7207: if (@pathitems) {
7208: $env{'form.folderpath'} = join('&',@pathitems);
7209: } else {
7210: undef($env{'form.folderpath'});
1.615 raeburn 7211: }
7212: }
7213: }
7214: }
7215:
1.446 www 7216: # If after all of this, we still don't have any paths, make them
1.519 raeburn 7217: unless ($env{'form.folderpath'}) {
1.446 www 7218: if ($supplementalflag) {
7219: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 7220: } elsif ($allowed) {
7221: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 7222: }
1.472 raeburn 7223: }
1.446 www 7224:
1.445 www 7225: # Store this
1.484 raeburn 7226: unless ($toolsflag) {
1.615 raeburn 7227: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 7228: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 7229: {'folderpath' => 'scalar'});
1.510 raeburn 7230: }
1.519 raeburn 7231: my $folderpath;
1.484 raeburn 7232: if ($env{'form.folderpath'}) {
1.519 raeburn 7233: $folderpath = $env{'form.folderpath'};
7234: my (@folders)=split('&',$env{'form.folderpath'});
7235: $env{'form.foldername'}=&unescape(pop(@folders));
7236: if ($env{'form.foldername'} =~ /\:1$/) {
7237: $container = 'page';
7238: } else {
7239: $container = 'sequence';
7240: }
7241: $env{'form.folder'}=pop(@folders);
1.484 raeburn 7242: } else {
1.519 raeburn 7243: if ($env{'form.folder'} eq '' ||
7244: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 7245: if ($env{'form.folder'} eq 'supplemental') {
7246: $folderpath=&supplemental_base();
7247: } elsif (!$hiddentop) {
7248: $folderpath='default&'.
7249: &escape(&mt('Main Content').':::::');
7250: }
1.484 raeburn 7251: }
7252: }
1.519 raeburn 7253: $containertag = '<input type="hidden" name="folderpath" value="" />';
7254: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 7255: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
7256: $showdoc='/'.$1;
7257: }
7258: if ($showdoc) { # got called in sequence from course
7259: $allowed=0;
7260: } else {
1.611 raeburn 7261: if ($canedit) {
1.484 raeburn 7262: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
7263: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 7264: }
7265: }
1.329 droeschl 7266: }
7267:
1.344 bisitz 7268: # get personal data
1.329 droeschl 7269: my $uname=$env{'user.name'};
7270: my $udom=$env{'user.domain'};
7271: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
7272:
7273: if ($allowed) {
1.484 raeburn 7274: if ($toolsflag) {
7275: $script .= &inject_data_js();
7276: my ($home,$other,%outhash)=&authorhosts();
7277: if (!$home && $other) {
7278: my @hosts;
7279: foreach my $aurole (keys(%outhash)) {
7280: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7281: push(@hosts,$outhash{$aurole});
7282: }
7283: }
7284: $script .= &dump_switchserver_js(@hosts);
7285: }
1.458 raeburn 7286: } else {
1.570 raeburn 7287: my $tid = 1;
1.484 raeburn 7288: my @tabids;
7289: if ($supplementalflag) {
1.655 raeburn 7290: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 7291: $tid = 2;
1.484 raeburn 7292: } else {
7293: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 7294: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 7295: unshift(@tabids,'001');
7296: push(@tabids,('dd1','ee1'));
7297: }
1.458 raeburn 7298: }
1.484 raeburn 7299: my $tabidstr = join("','",@tabids);
1.699 raeburn 7300: my (%domtools,%crstools);
7301: my %tooltypes = &Apache::loncommon::usable_exttools();
7302: if ($tooltypes{'dom'}) {
7303: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
7304: }
7305: if ($tooltypes{'crs'}) {
7306: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
7307: }
7308: %ltitools = (
7309: dom => \%domtools,
7310: crs => \%crstools,
7311: );
7312: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622 raeburn 7313: my $hostname = $r->hostname();
1.606 raeburn 7314: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 7315: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 7316: &history_tab_js().
7317: &inject_data_js().
1.570 raeburn 7318: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 7319: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 7320: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
7321: if ($hidden_and_empty ne '') {
7322: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
7323: $hidden_and_empty);
7324: $onload .= "javascript:alert('".&js_escape($alert)."');";
7325: }
1.484 raeburn 7326: $addentries = {
1.685 raeburn 7327: onload => $onload,
1.484 raeburn 7328: };
1.458 raeburn 7329: }
1.538 raeburn 7330: $script .= &paste_popup_js();
1.501 raeburn 7331: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
7332: &mt('Switch server?');
7333:
7334:
1.329 droeschl 7335: }
7336: # -------------------------------------------------------------------- Body tag
1.369 bisitz 7337: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 7338: .'// <![CDATA['."\n"
7339: .$script."\n"
7340: .'// ]]>'."\n"
1.595 musolffc 7341: .'</script>'."\n"
7342: .'<script type="text/javascript"
7343: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 7344:
7345: # Breadcrumbs
7346: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 7347:
7348: if ($showdoc) {
1.682 raeburn 7349: my $args;
7350: if ($supplementalflag) {
1.687 raeburn 7351: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
7352: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.705 raeburn 7353: $args = {'bread_crumbs' => $brcrum,
7354: 'bread_crumbs_nomenu' => 1};
1.682 raeburn 7355: } else {
7356: $args = {'force_register' => $showdoc};
7357: }
7358: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 7359: } elsif ($toolsflag) {
1.611 raeburn 7360: my ($breadtext,$breadtitle);
1.617 raeburn 7361: $breadtext = "$crstype Editor";
1.611 raeburn 7362: if ($canedit) {
7363: $breadtitle = 'Editing '.$crstype.' Contents';
7364: } else {
7365: $breadtext .= ' (View-only mode)';
7366: $breadtitle = 'Viewing '.$crstype.' Contents';
7367: }
1.571 raeburn 7368: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7369: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 7370: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
7371: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7372: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7373: $breadtitle)
1.571 raeburn 7374: );
1.510 raeburn 7375: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 7376: unless ($env{'request.role.adv'}) {
7377: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
7378: $r->internal_redirect('/adm/navmaps');
7379: return OK;
7380: }
7381: }
1.510 raeburn 7382: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
1.705 raeburn 7383: my $args = {'bread_crumbs' => $brcrum};
7384: unless (($env{'form.folderpath'} eq '') ||
7385: ($env{'form.folder'} eq 'supplemental')) {
7386: $args->{'bread_crumbs_nomenu'} = 1;
7387: }
1.510 raeburn 7388: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
1.705 raeburn 7389: $args));
1.510 raeburn 7390: } else {
1.611 raeburn 7391: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 7392: $breadtext = "$crstype Editor";
1.611 raeburn 7393: if ($canedit) {
7394: $breadtitle = 'Editing '.$crstype.' Contents';
7395: $helpitem = 'Docs_Adding_Course_Doc';
7396: } else {
7397: $breadtext .= ' (View-only mode)';
7398: $breadtitle = 'Viewing '.$crstype.' Contents';
7399: $helpitem = 'Docs_Viewing_Course_Doc';
7400: }
1.392 raeburn 7401: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7402: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 7403: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 7404: {'add_entries' => $addentries}
7405: )
1.392 raeburn 7406: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7407: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7408: $breadtitle,
7409: $helpitem)
1.392 raeburn 7410: );
7411: }
1.364 bisitz 7412:
1.329 droeschl 7413: my %allfiles = ();
7414: my %codebase = ();
1.440 raeburn 7415: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 7416: if ($canedit) {
1.684 raeburn 7417: undef($suppchanges);
1.329 droeschl 7418: if (($env{'form.uploaddoc.filename'}) &&
7419: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 7420: my $context = $1;
7421: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 7422: undef($hadchanges);
1.440 raeburn 7423: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 7424: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 7425: undef($navmap);
1.329 droeschl 7426: if ($hadchanges) {
7427: &mark_hash_old();
7428: }
1.684 raeburn 7429: if ($suppchanges) {
7430: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
7431: undef($suppchanges);
7432: }
1.440 raeburn 7433: $r->print($upload_output);
7434: } elsif ($env{'form.phase'} eq 'upload_embedded') {
7435: # Process file upload - phase two - upload embedded objects
7436: $uploadphase = 'check_embedded';
7437: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
7438: my $state = &embedded_form_elems($uploadphase,$primaryurl,
7439: $env{'form.newidx'});
7440: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7441: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7442: my ($destination,$dir_root) = &embedded_destination();
7443: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
7444: my $actionurl = '/adm/coursedocs';
1.630 raeburn 7445: my ($result,$flag) =
1.440 raeburn 7446: &Apache::loncommon::upload_embedded('coursedoc',$destination,
7447: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
7448: $actionurl);
7449: $r->print($result.&return_to_editor());
7450: } elsif ($env{'form.phase'} eq 'check_embedded') {
7451: # Process file upload - phase three - modify references in HTML file
7452: $uploadphase = 'modified_orightml';
7453: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7454: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7455: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 7456: my $result =
1.482 raeburn 7457: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
7458: $docuname,$docudom,undef,
7459: $dir_root);
1.630 raeburn 7460: $r->print($result.&return_to_editor());
1.476 raeburn 7461: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
7462: $uploadphase = 'decompress_phase_one';
7463: $r->print(&decompression_phase_one().
7464: &return_to_editor());
7465: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
7466: $uploadphase = 'decompress_phase_two';
7467: $r->print(&decompression_phase_two().
7468: &return_to_editor());
1.329 droeschl 7469: }
7470: }
7471:
1.484 raeburn 7472: if ($allowed && $toolsflag) {
7473: $r->print(&startContentScreen('tools'));
1.708 raeburn 7474: $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom));
1.484 raeburn 7475: $r->print(&endContentScreen());
7476: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 7477: # -----------------------------------------------------------------------------
7478: my %lt=&Apache::lonlocal::texthash(
7479: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 7480: 'upfi' => 'Upload File',
1.553 raeburn 7481: 'upld' => 'Upload Content',
1.706 raeburn 7482: 'srch' => 'Search Repository',
7483: 'impo' => 'Import from Repository',
1.487 raeburn 7484: 'lnks' => 'Import from Stored Links',
1.502 raeburn 7485: 'impm' => 'Import from Assembled Map',
1.630 raeburn 7486: 'imcr' => 'Import from Course Resources',
1.598 raeburn 7487: 'extr' => 'External Resource',
7488: 'extt' => 'External Tool',
1.329 droeschl 7489: 'selm' => 'Select Map',
7490: 'load' => 'Load Map',
7491: 'newf' => 'New Folder',
7492: 'newp' => 'New Composite Page',
7493: 'syll' => 'Syllabus',
1.425 raeburn 7494: 'navc' => 'Table of Contents',
1.343 biermanm 7495: 'sipa' => 'Simple Course Page',
1.329 droeschl 7496: 'sipr' => 'Simple Problem',
1.630 raeburn 7497: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 7498: 'stpr' => 'Standard Problem',
7499: 'news' => 'New sub-directory',
7500: 'crpr' => 'Create Problem',
1.689 raeburn 7501: 'swit' => 'Switch Server',
1.329 droeschl 7502: 'drbx' => 'Drop Box',
1.451 www 7503: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 7504: 'bull' => 'Discussion Board',
1.347 weissno 7505: 'mypi' => 'My Personal Information Page',
1.353 weissno 7506: 'grpo' => 'Group Portfolio',
1.329 droeschl 7507: 'rost' => 'Course Roster',
1.528 raeburn 7508: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 7509: 'imsf' => 'IMS Upload',
7510: 'imsl' => 'Upload IMS package',
1.501 raeburn 7511: 'cms' => 'Origin of IMS package',
7512: 'se' => 'Select',
1.329 droeschl 7513: 'file' => 'File',
7514: 'title' => 'Title',
1.606 raeburn 7515: 'addp' => 'Add Placeholder to course?',
7516: 'uste' => 'Use Template?',
7517: 'fnam' => 'File Name:',
7518: 'loca' => 'Location:',
7519: 'dire' => 'Directory:',
7520: 'cate' => 'Category:',
7521: 'tmpl' => 'Template:',
1.698 raeburn 7522: 'empd' => 'No resources found',
1.329 droeschl 7523: 'comment' => 'Comment',
1.403 raeburn 7524: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 7525: 'bb5' => 'Blackboard 5',
7526: 'bb6' => 'Blackboard 6',
7527: 'angel5' => 'ANGEL 5.5',
7528: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 7529: 'yes' => 'Yes',
7530: 'no' => 'No',
1.618 raeburn 7531: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 7532: );
1.329 droeschl 7533: # -----------------------------------------------------------------------------
1.595 musolffc 7534:
7535: # Calculate free quota space for a user or course. A javascript function checks
7536: # file size to determine if upload should be allowed.
7537: my $quotatype = 'unofficial';
7538: if ($crstype eq 'Community') {
1.601 raeburn 7539: $quotatype = 'community';
7540: } elsif ($crstype eq 'Placement') {
7541: $quotatype = 'placement';
1.595 musolffc 7542: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
7543: $quotatype = 'official';
7544: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
7545: $quotatype = 'textbook';
7546: }
7547: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
7548: 'course',$quotatype); # expressed in MB
7549: my $current_disk_usage = 0;
7550: foreach my $subdir ('docs','supplemental') {
7551: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
7552: "userfiles/$subdir",1); # expressed in kB
7553: }
7554: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 7555: my $usage = $current_disk_usage/1024; # in MB
7556: my $quota = $disk_quota;
7557: my $percent;
7558: if ($disk_quota == 0) {
7559: $percent = 100.0;
7560: } else {
1.619 raeburn 7561: $percent = 100*($usage/$disk_quota);
1.605 raeburn 7562: }
7563: $usage = sprintf("%.2f",$usage);
7564: $quota = sprintf("%.2f",$quota);
7565: $percent = sprintf("%.0f",$percent);
7566: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
7567: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 7568:
1.329 droeschl 7569: my $fileupload=(<<FIUP);
1.605 raeburn 7570: $quotainfo
1.329 droeschl 7571: $lt{'file'}:<br />
7572: FIUP
7573: my $checkbox=(<<CHBO);
7574: <!-- <label>$lt{'parse'}?
7575: <input type="checkbox" name="parserflag" />
7576: </label> -->
7577: <label>
1.611 raeburn 7578: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 7579: </label>
7580: CHBO
1.501 raeburn 7581: my $imsfolder = $env{'form.folder'};
7582: if ($imsfolder eq '') {
7583: $imsfolder = 'default';
7584: }
7585: my $imspform=(<<IMSFORM);
7586: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
7587: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
7588: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 7589: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 7590: <legend>$lt{'imsf'}</legend>
7591: $fileupload
1.702 raeburn 7592: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
7593: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501 raeburn 7594: <br />
7595: <p>
7596: $lt{'cms'}:
1.611 raeburn 7597: <select name="source" $disabled>
1.501 raeburn 7598: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 7599: <option value="bb5">$lt{'bb5'}</option>
7600: <option value="bb6">$lt{'bb6'}</option>
7601: <option value="angel5">$lt{'angel5'}</option>
7602: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 7603: </select>
7604: <input type="hidden" name="folder" value="$imsfolder" />
7605: </p>
7606: <input type="hidden" name="phase" value="one" />
1.611 raeburn 7607: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 7608: </fieldset>
7609: </form>
7610: IMSFORM
1.329 droeschl 7611:
7612: my $fileuploadform=(<<FUFORM);
1.501 raeburn 7613: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
7614: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
7615: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 7616: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 7617: <legend>$lt{'upfi'}</legend>
1.371 tempelho 7618: <input type="hidden" name="active" value="aa" />
1.595 musolffc 7619: $fileupload
1.702 raeburn 7620: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
7621: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 7622: <br />
7623: $lt{'title'}:<br />
1.611 raeburn 7624: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 7625: $pathitem
1.329 droeschl 7626: <input type="hidden" name="cmd" value="upload_default" />
7627: <br />
1.458 raeburn 7628: <span class="LC_nobreak" style="float:left">
1.329 droeschl 7629: $checkbox
7630: </span>
1.501 raeburn 7631: <br clear="all" />
1.611 raeburn 7632: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 7633: </fieldset>
7634: </form>
1.383 tempelho 7635: FUFORM
1.329 droeschl 7636:
1.611 raeburn 7637: my $mapimportjs;
7638: if ($canedit) {
7639: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
7640: } else {
7641: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
7642: }
1.502 raeburn 7643: my $importpubform=(<<SEDFFORM);
1.514 raeburn 7644: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 7645: $lt{'impm'}</a>$help{'Load_Map'}
7646: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 7647: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 7648: <legend>$lt{'impm'}</legend>
1.371 tempelho 7649: <input type="hidden" name="active" value="bb" />
1.502 raeburn 7650: $lt{'copm'}<br />
7651: <span class="LC_nobreak">
7652: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 7653: onfocus="this.blur();$mapimportjs" $disabled />
7654: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
7655: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 7656: </fieldset>
7657: </form>
7658:
1.383 tempelho 7659: SEDFFORM
1.706 raeburn 7660: my ($importcrsresform,$checkcrsres);
7661: if ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'}) {
7662: $checkcrsres = 1;
7663: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'} ne '0') {
7664: my %domdefs=&Apache::lonnet::get_domain_defaults($coursedom);
1.710 raeburn 7665: my $type = lc($env{'course.'.$env{'request.course.id'}.'.type'});
7666: unless (($type eq 'community') || ($type eq 'placement')) {
7667: $type = 'unofficial';
7668: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'} ne '') {
7669: $type = 'official';
7670: } elsif ($env{'course.'.$env{'request.course.id'}.'internal.textbook'} ne '') {
7671: $type = 'textbook';
7672: } else {
7673: $type = 'unofficial';
7674: }
7675: }
7676: if ($domdefs{$type.'crsauthor'}) {
1.706 raeburn 7677: $checkcrsres = 1;
7678: }
7679: }
7680: if ($checkcrsres) {
7681: my ($numdirs,$pickfile) =
7682: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
7683: "resize_scrollbox('contentscroll','1','0');",
7684: undef,'res');
7685: if ($pickfile) {
7686: $importcrsresform=(<<CRSFORM);
1.690 raeburn 7687: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 7688: $lt{'imcr'}</a>$help{'Course_Resources'}
7689: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
7690: <fieldset id="importcrsresform" style="display: none;">
7691: <legend>$lt{'imcr'}</legend>
1.698 raeburn 7692: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 7693: <input type="hidden" name="active" value="bb" />
7694: $pickfile
7695: <p>
1.699 raeburn 7696: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606 raeburn 7697: </p>
7698: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 7699: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 raeburn 7700: </div>
7701: <div id="importcrsresempty" style="display: none;">
7702: <p>
7703: $lt{'empd'}
7704: </p>
7705: </div>
1.606 raeburn 7706: </fieldset>
7707: </form>
7708: CRSFORM
1.706 raeburn 7709: }
1.606 raeburn 7710: }
7711:
1.611 raeburn 7712: my $fromstoredjs;
7713: if ($canedit) {
7714: $fromstoredjs = 'open_StoredLinks_Import()';
7715: } else {
7716: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
7717: }
7718:
1.502 raeburn 7719: my @importpubforma = (
1.706 raeburn 7720: { '<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 7721: { '<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 7722: { '<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 7723: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
7724: );
1.706 raeburn 7725: if ($importcrsresform) {
7726: 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 7727: }
1.502 raeburn 7728: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 7729: my $extresourcesform =
7730: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 7731: $help{'Adding_External_Resource'},
7732: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 7733: my $exttoolform =
7734: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
7735: $help{'Adding_External_Tool'},undef,
7736: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 7737: \%ltitools,$disabled);
1.329 droeschl 7738: if ($allowed) {
1.492 raeburn 7739: my $folder = $env{'form.folder'};
7740: if ($folder eq '') {
7741: $folder='default';
7742: }
1.615 raeburn 7743: if ($canedit) {
7744: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
7745: if ($output) {
7746: $r->print($output);
7747: }
1.538 raeburn 7748: }
1.337 ehlerst 7749: $r->print(<<HIDDENFORM);
7750: <form name="renameform" method="post" action="/adm/coursedocs">
7751: <input type="hidden" name="title" />
7752: <input type="hidden" name="cmd" />
7753: <input type="hidden" name="markcopy" />
7754: <input type="hidden" name="copyfolder" />
7755: $containertag
7756: </form>
1.633 raeburn 7757: <form name="aliasform" method="post" action="/adm/coursedocs">
7758: <input type="hidden" name="alias" />
7759: <input type="hidden" name="cmd" />
7760: $containertag
7761: </form>
1.484 raeburn 7762:
1.337 ehlerst 7763: HIDDENFORM
1.508 raeburn 7764: $r->print(&makesimpleeditform($pathitem)."\n".
7765: &makedocslogform($pathitem."\n".
1.484 raeburn 7766: '<input type="hidden" name="folder" value="'.
7767: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 7768: }
1.442 www 7769:
7770: # Generate the tabs
1.510 raeburn 7771: my ($mode,$needs_end);
1.472 raeburn 7772: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 7773: my @folders = split('&',$env{'form.folderpath'});
7774: unless (@folders > 2) {
7775: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
7776: $needs_end = 1;
7777: }
1.472 raeburn 7778: } else {
1.484 raeburn 7779: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 7780: $needs_end = 1;
1.472 raeburn 7781: }
1.443 www 7782:
1.442 www 7783: #
1.622 raeburn 7784: my $hostname = $r->hostname();
1.442 www 7785: my $savefolderpath;
7786:
1.395 raeburn 7787: if ($allowed) {
1.329 droeschl 7788: my $folder=$env{'form.folder'};
1.615 raeburn 7789: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 7790: $folder='default';
1.356 tempelho 7791: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 7792: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 7793: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 7794: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
7795: }
7796: my $postexec='';
7797: if ($folder eq 'default') {
1.653 raeburn 7798: my $windowname = 'loncapaclient';
7799: if ($env{'request.lti.login'}) {
7800: $windowname .= 'lti';
7801: }
1.372 bisitz 7802: $r->print('<script type="text/javascript">'."\n"
7803: .'// <![CDATA['."\n"
1.653 raeburn 7804: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 7805: .'// ]]>'."\n"
7806: .'</script>'."\n"
1.369 bisitz 7807: );
1.329 droeschl 7808: } else {
7809: #$postexec='self.close();';
7810: }
1.504 raeburn 7811: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
7812: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 7813: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
7814:
7815: my $newnavform=(<<NNFORM);
7816: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 7817: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7818: $pathitem
1.329 droeschl 7819: <input type="hidden" name="importdetail"
7820: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 7821: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 7822: $help{'Navigate_Content'}
7823: </form>
7824: NNFORM
7825: my $newsmppageform=(<<NSPFORM);
7826: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 7827: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7828: $pathitem
1.329 droeschl 7829: <input type="hidden" name="importdetail" value="" />
1.423 onken 7830: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 7831: $help{'Simple Page'}
1.329 droeschl 7832: </form>
7833: NSPFORM
7834:
7835: my $newsmpproblemform=(<<NSPROBFORM);
7836: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 7837: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7838: $pathitem
1.329 droeschl 7839: <input type="hidden" name="importdetail" value="" />
1.423 onken 7840: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 7841: $help{'Simple_Problem'}
1.329 droeschl 7842: </form>
7843:
7844: NSPROBFORM
7845:
7846: my $newdropboxform=(<<NDBFORM);
7847: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 7848: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7849: $pathitem
1.329 droeschl 7850: <input type="hidden" name="importdetail" value="" />
1.423 onken 7851: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 7852: $help{'Dropbox'}
1.344 bisitz 7853: </form>
1.329 droeschl 7854: NDBFORM
7855:
7856: my $newexuploadform=(<<NEXUFORM);
7857: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 7858: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7859: $pathitem
1.329 droeschl 7860: <input type="hidden" name="importdetail" value="" />
1.423 onken 7861: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 7862: $help{'Score_Upload_Form'}
7863: </form>
7864: NEXUFORM
7865:
7866: my $newbulform=(<<NBFORM);
7867: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 7868: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7869: $pathitem
1.329 droeschl 7870: <input type="hidden" name="importdetail" value="" />
1.423 onken 7871: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 7872: $help{'Bulletin Board'}
7873: </form>
7874: NBFORM
7875:
7876: my $newaboutmeform=(<<NAMFORM);
7877: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 7878: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7879: $pathitem
1.329 droeschl 7880: <input type="hidden" name="importdetail"
7881: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7882: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 7883: $help{'My Personal Information Page'}
1.329 droeschl 7884: </form>
7885: NAMFORM
7886:
7887: my $newaboutsomeoneform=(<<NASOFORM);
7888: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 7889: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7890: $pathitem
1.329 droeschl 7891: <input type="hidden" name="importdetail" value="" />
1.423 onken 7892: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 7893: </form>
7894: NASOFORM
7895:
7896: my $newrosterform=(<<NROSTFORM);
7897: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 7898: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7899: $pathitem
1.329 droeschl 7900: <input type="hidden" name="importdetail"
7901: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 7902: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 7903: $help{'Course_Roster'}
1.329 droeschl 7904: </form>
7905: NROSTFORM
7906:
1.534 raeburn 7907: my $newwebpage;
7908: if ($folder =~ /^default_?(\d*)$/) {
7909: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
7910: if ($1) {
7911: $newwebpage .= $1;
7912: } else {
7913: $newwebpage .= 'default';
7914: }
7915: $newwebpage .= '/new.html';
7916: }
7917: my $newwebpageform =(<<NWEBFORM);
7918: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 7919: <input type="hidden" name="active" value="ff" />
1.534 raeburn 7920: $pathitem
7921: <input type="hidden" name="importdetail" value="$newwebpage" />
7922: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 7923: $help{'Web_Page'}
1.534 raeburn 7924: </form>
7925: NWEBFORM
1.701 raeburn 7926: my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606 raeburn 7927: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 7928: my $machines_str = "'".join("','",@ids)."'";
7929: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 7930: if ($env{'user.author'}) {
7931: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 7932: $is_home{'author'} = 1;
1.606 raeburn 7933: }
1.691 raeburn 7934: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 7935: }
7936: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
7937: ['active'],['ca','aa']);
1.691 raeburn 7938: my %by_roletype;
1.606 raeburn 7939: if (keys(%roleshash)) {
7940: foreach my $entry (keys(%roleshash)) {
7941: my ($auname,$audom,$roletype) = split(/:/,$entry);
7942: my $key = $entry;
7943: $key =~ s/:/___/g;
1.691 raeburn 7944: my $author = $auname.'___'.$audom;
7945: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 7946: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 7947: $toppath{$author} = "/priv/$audom/$auname";
7948: if (grep(/^\Q$rolehome\E$/,@ids)) {
7949: $is_home{$author} = 1;
1.606 raeburn 7950: }
1.691 raeburn 7951: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
7952: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 7953: }
1.691 raeburn 7954: }
7955: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
7956: if (grep(/^\Q$crshome\E$/,@ids)) {
7957: $is_home{'course'} = 1;
7958: }
7959: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
7960: my $pickdir = $lt{'loca'}.
7961: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
7962: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
7963: if ($env{'user.author'}) {
7964: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
7965: }
7966: if (keys(%by_roletype)) {
7967: foreach my $possrole ('ca','aa') {
7968: if (ref($by_roletype{$possrole}) eq 'HASH') {
7969: my $roletitle = &Apache::lonnet::plaintext($possrole);
7970: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
7971: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
7972: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
7973: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 7974: }
7975: }
7976: }
7977: }
1.706 raeburn 7978: if ($checkcrsres) {
7979: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n";
7980: }
7981: $pickdir .= '</select><br />'."\n".
1.691 raeburn 7982: $lt{'dire'}.
7983: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
7984: '<option value=""></option>'.
7985: '</select><br />'."\n";
1.606 raeburn 7986: my %seltemplate_menus;
7987: my @files = &Apache::lonhomework::get_template_list('problem');
7988: my @noexamplelink = ('blank.problem','blank.library','script.library');
7989: my $currentcategory = '';
7990: my @ordered = ('');
7991: my %templatehelp;
7992: my $defcategory = '';
7993: my @catorder = ($defcategory);
7994: $seltemplate_menus{$defcategory}->{'order'} = [''];
7995: $seltemplate_menus{$defcategory}->{'text'} = '';
7996: foreach my $file (@files) {
7997: if (ref($file) eq 'ARRAY') {
7998: my ($path,$title,$category,$help) = @{$file};
7999: next if ($title !~ /\S/);
8000: if (&js_escape($category) ne $currentcategory) {
8001: $currentcategory = &js_escape($category);
8002: push(@catorder,&js_escape($currentcategory));
8003: $seltemplate_menus{$currentcategory}->{'text'} = $category;
8004: $seltemplate_menus{$currentcategory}->{'default'} = '';
8005: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
8006: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
8007: }
8008: if ($path) {
8009: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
8010: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
8011: if ($help) {
8012: $templatehelp{$path} = $help;
8013: }
8014: }
8015: }
8016: }
8017:
8018: my $templates = $lt{'cate'}.' '.
8019: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
8020: $defcategory,'tempcategory','template',
8021: \%seltemplate_menus,\@catorder,
8022: "resize_scrollbox('contentscroll','1','0');",
8023: "toggleExampleText();",'template').'<br />';
8024: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
1.701 raeburn 8025: '<span id="newresexample">'.&mt('Example').'</span></a>';
1.706 raeburn 8026: my $crsresform;
8027: if (($env{'user.author'}) || ($checkcrsres)) {
8028: $crsresform=(<<RESFORM);
1.691 raeburn 8029: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.706 raeburn 8030: $lt{'stpr'}</a>$help{'Standard_Problem'}
1.606 raeburn 8031: <form action="/adm/coursedocs" method="post" name="courseresform">
8032: <fieldset id="crsresform" style="display:none;">
8033: <legend>$lt{'stpr'}</legend>
1.655 raeburn 8034: <input type="hidden" name="active" value="bb" />
1.606 raeburn 8035: <p>
8036: $pickdir
1.701 raeburn 8037: </p>
1.691 raeburn 8038: <div id="newstdproblem" style="display:none;">
1.701 raeburn 8039: <p>
1.606 raeburn 8040: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 8041: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 8042:
1.611 raeburn 8043: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 8044: </span><span id="newsubdir"></span>
8045: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701 raeburn 8046: </p>
1.699 raeburn 8047: </div>
1.606 raeburn 8048: $lt{'fnam'}
1.611 raeburn 8049: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.701 raeburn 8050: <div id="newresource" style="display:none">
1.606 raeburn 8051: <p>
8052: $lt{'addp'}
1.611 raeburn 8053: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 8054: $lt{'no'}</label>
1.611 raeburn 8055: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 8056: $lt{'yes'}</label>
8057: <span id="newrestitle"></span>
1.611 raeburn 8058: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701 raeburn 8059: </p>
1.606 raeburn 8060: </div>
8061: <p>
8062: $lt{'uste'}
1.611 raeburn 8063: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 8064: $lt{'no'}</label>
1.611 raeburn 8065: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 8066: $lt{'yes'}</label>
1.701 raeburn 8067: </p>
1.606 raeburn 8068: <div id="newrestemplate" style="display:none">
8069: $templates
8070: $templatepreview
8071: </div>
8072: <span class="LC_nobreak">
1.701 raeburn 8073: <input type="hidden" name="folderpath" value="$showpath" />
1.611 raeburn 8074: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 8075: </span>
1.691 raeburn 8076: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 8077: $rolehomes
8078: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
8079: </div>
1.606 raeburn 8080: </fieldset>
8081: </form>
8082:
8083: RESFORM
1.706 raeburn 8084: }
1.534 raeburn 8085:
1.342 ehlerst 8086: my $specialdocumentsform;
1.383 tempelho 8087: my @specialdocumentsforma;
1.451 www 8088: my $gradingform;
8089: my @gradingforma;
8090: my $communityform;
8091: my @communityforma;
1.351 ehlerst 8092: my $newfolderform;
1.390 tempelho 8093: my $newfolderb;
1.342 ehlerst 8094:
1.451 www 8095: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 8096:
1.329 droeschl 8097: my $newpageform=(<<NPFORM);
8098: <form action="/adm/coursedocs" method="post" name="newpage">
8099: <input type="hidden" name="folderpath" value="$path" />
8100: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 8101: <input type="hidden" name="active" value="ee" />
1.423 onken 8102: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 8103: $help{'Adding_Pages'}
1.329 droeschl 8104: </form>
8105: NPFORM
1.390 tempelho 8106:
8107:
1.351 ehlerst 8108: $newfolderform=(<<NFFORM);
1.329 droeschl 8109: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 8110: $pathitem
1.329 droeschl 8111: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 8112: <input type="hidden" name="active" value="" />
1.422 onken 8113: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 8114: </form>
8115: NFFORM
8116:
8117: my $newsylform=(<<NSYLFORM);
8118: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 8119: <input type="hidden" name="active" value="ee" />
1.508 raeburn 8120: $pathitem
1.329 droeschl 8121: <input type="hidden" name="importdetail"
8122: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 8123: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 8124: $help{'Syllabus'}
1.383 tempelho 8125:
1.329 droeschl 8126: </form>
8127: NSYLFORM
1.364 bisitz 8128:
1.329 droeschl 8129: my $newgroupfileform=(<<NGFFORM);
8130: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 8131: <input type="hidden" name="active" value="ee" />
1.508 raeburn 8132: $pathitem
1.329 droeschl 8133: <input type="hidden" name="importdetail"
8134: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 8135: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 8136: $help{'Group Portfolio'}
1.329 droeschl 8137: </form>
8138: NGFFORM
1.672 raeburn 8139: if ($container eq 'page') {
8140: @specialdocumentsforma=(
8141: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
8142: );
8143: } else {
8144: @specialdocumentsforma=(
1.421 onken 8145: {'<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 8146: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 8147: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 8148: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 8149: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 8150: );
8151: }
1.451 www 8152: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
8153:
1.655 raeburn 8154: my @external = (
8155: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 8156: );
1.699 raeburn 8157: if ($posslti) {
1.655 raeburn 8158: push(@external,
8159: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
8160: );
1.598 raeburn 8161: }
1.655 raeburn 8162: my $externalform = &create_form_ul(&create_list_elements(@external));
8163:
8164: my @importdoc = ();
1.519 raeburn 8165: unless ($container eq 'page') {
8166: push(@importdoc,
8167: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
8168: );
8169: }
8170: push(@importdoc,
1.558 raeburn 8171: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 8172: );
1.501 raeburn 8173: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 8174:
1.451 www 8175: @gradingforma=(
8176: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
8177: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
1.706 raeburn 8178: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
1.451 www 8179: );
1.706 raeburn 8180: if ($crsresform) {
8181: push(@gradingforma,
8182: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform}
8183: );
8184: }
1.451 www 8185: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
8186:
8187: @communityforma=(
8188: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
8189: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
8190: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 8191: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
8192: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 8193: );
8194: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 8195:
1.330 tempelho 8196: my %orderhash = (
1.553 raeburn 8197: 'aa' => ['Upload',$fileuploadform],
1.707 raeburn 8198: 'bb' => ['External',$externalform],
8199: 'cc' => ['Import',$importpubform],
1.701 raeburn 8200: 'dd' => ['Assessment',$gradingform],
1.673 raeburn 8201: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 8202: );
1.519 raeburn 8203: unless ($container eq 'page') {
1.434 raeburn 8204: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 8205: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 8206: }
8207:
1.341 ehlerst 8208: $hadchanges=0;
1.484 raeburn 8209: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 8210: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 8211: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 8212: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 8213: undef($navmap);
1.443 www 8214: if ($error) {
8215: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
8216: }
1.639 raeburn 8217: if ($hadchanges) {
8218: unless (&is_hash_old()) {
1.638 raeburn 8219: &mark_hash_old();
8220: }
8221: }
1.341 ehlerst 8222:
1.443 www 8223: &changewarning($r,'');
8224: }
1.458 raeburn 8225: }
1.442 www 8226:
1.443 www 8227: # Supplemental documents start here
8228:
1.329 droeschl 8229: my $folder=$env{'form.folder'};
1.443 www 8230: unless ($supplementalflag) {
1.329 droeschl 8231: $folder='supplemental';
8232: }
1.685 raeburn 8233: if (($folder eq 'supplemental') &&
1.329 droeschl 8234: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 8235: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 8236: } elsif ($allowed) {
1.356 tempelho 8237: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 8238: }
1.508 raeburn 8239: $pathitem = '<input type="hidden" name="folderpath" value="'.
8240: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 8241: if ($allowed) {
8242: my $folderseq=
1.504 raeburn 8243: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 8244:
8245: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 8246: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
8247: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 8248: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 8249: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 8250: <legend>$lt{'upfi'}</legend>
1.630 raeburn 8251: <input type="hidden" name="active" value="ee" />
1.329 droeschl 8252: $fileupload
1.702 raeburn 8253: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
8254: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 8255: <br />
8256: <br />
8257: <span class="LC_nobreak">
8258: $checkbox
8259: </span>
8260: <br /><br />
8261: $lt{'comment'}:<br />
1.383 tempelho 8262: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 8263: <br />
1.508 raeburn 8264: $pathitem
1.329 droeschl 8265: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 8266: <input type='submit' value="$lt{'upld'}" />
1.700 raeburn 8267: </fieldset>
1.501 raeburn 8268: </form>
1.329 droeschl 8269: SUPDOCFORM
8270:
8271: my $supnewfolderform=(<<SNFFORM);
8272: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 8273: <input type="hidden" name="active" value="" />
1.508 raeburn 8274: $pathitem
1.329 droeschl 8275: <input type="hidden" name="importdetail" value="" />
1.423 onken 8276: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 8277: $help{'Adding_Folders'}
1.329 droeschl 8278: </form>
8279: SNFFORM
1.383 tempelho 8280:
1.510 raeburn 8281: my $supextform =
8282: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 8283: $help{'Adding_External_Resource'},
8284: undef,undef,undef,undef,undef,undef,
8285: $disabled);
1.329 droeschl 8286:
1.598 raeburn 8287: my $supexttoolform =
8288: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
8289: $help{'Adding_External_Tool'},
8290: undef,undef,'tool',$coursedom,
1.611 raeburn 8291: $coursenum,\%ltitools,$disabled);
1.598 raeburn 8292:
1.329 droeschl 8293: my $supnewsylform=(<<SNSFORM);
8294: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 8295: <input type="hidden" name="active" value="ff" />
1.508 raeburn 8296: $pathitem
1.329 droeschl 8297: <input type="hidden" name="importdetail"
8298: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 8299: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 8300: $help{'Syllabus'}
8301: </form>
8302: SNSFORM
8303:
8304: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 8305: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 8306: <input type="hidden" name="active" value="ff" />
1.508 raeburn 8307: $pathitem
1.329 droeschl 8308: <input type="hidden" name="importdetail"
8309: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 8310: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 8311: $help{'My Personal Information Page'}
1.329 droeschl 8312: </form>
8313: SNAMFORM
8314:
1.534 raeburn 8315: my $supwebpage;
8316: if ($folder =~ /^supplemental_?(\d*)$/) {
8317: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
8318: if ($1) {
8319: $supwebpage .= $1;
8320: } else {
8321: $supwebpage .= 'default';
8322: }
8323: $supwebpage .= '/new.html';
8324: }
8325: my $supwebpageform =(<<SWEBFORM);
8326: <form action="/adm/coursedocs" method="post" name="supwebpage">
8327: <input type="hidden" name="active" value="cc" />
8328: $pathitem
8329: <input type="hidden" name="importdetail" value="$supwebpage" />
8330: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 8331: $help{'Web_Page'}
1.534 raeburn 8332: </form>
8333: SWEBFORM
8334:
1.333 muellerd 8335:
1.383 tempelho 8336: my @specialdocs = (
1.618 raeburn 8337: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 8338: =>$supnewsylform},
1.611 raeburn 8339: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 8340: =>$supnewaboutmeform},
1.534 raeburn 8341: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
8342:
1.383 tempelho 8343: );
1.655 raeburn 8344: my @supexternal = (
8345: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
8346: =>$supextform});
1.699 raeburn 8347: if ($posslti) {
1.655 raeburn 8348: push(@supexternal,
8349: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 8350: =>$supexttoolform});
8351: }
1.655 raeburn 8352: my @supimportdoc = (
1.598 raeburn 8353: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 8354: =>$supupdocform},
1.598 raeburn 8355: );
1.501 raeburn 8356:
8357: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 8358: my %suporderhash = (
1.390 tempelho 8359: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 8360: 'dd' => ['Upload',$supupdocform],
8361: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 8362: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 8363: );
1.443 www 8364: if ($supplementalflag) {
1.682 raeburn 8365: $suppchanges = 0;
8366: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
8367: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
8368: \%ltitools,$canedit,$hostname);
8369: if ($error) {
8370: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
8371: }
8372: if ($suppchanges) {
1.684 raeburn 8373: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 8374: undef($suppchanges);
8375: }
1.393 raeburn 8376: }
1.443 www 8377: } elsif ($supplementalflag) {
1.458 raeburn 8378: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 8379: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
8380: $hostname);
1.393 raeburn 8381: if ($error) {
8382: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 8383: }
1.393 raeburn 8384: }
1.389 tempelho 8385:
1.510 raeburn 8386: if ($needs_end) {
8387: $r->print(&endContentScreen());
8388: }
1.383 tempelho 8389:
1.329 droeschl 8390: if ($allowed) {
8391: $r->print('
8392: <form method="post" name="extimport" action="/adm/coursedocs">
8393: <input type="hidden" name="title" />
8394: <input type="hidden" name="url" />
8395: <input type="hidden" name="useform" />
8396: <input type="hidden" name="residx" />
8397: </form>');
8398: }
1.484 raeburn 8399: } elsif ($showdoc) {
1.329 droeschl 8400: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 8401: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 8402: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 8403: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 8404: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 8405: }
8406: }
1.630 raeburn 8407: unless ($noendpage) {
1.606 raeburn 8408: $r->print(&Apache::loncommon::end_page());
8409: }
1.329 droeschl 8410: return OK;
1.364 bisitz 8411: }
1.329 droeschl 8412:
1.440 raeburn 8413: sub embedded_form_elems {
8414: my ($phase,$primaryurl,$newidx) = @_;
8415: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 8416: $newidx =~s /\D+//g;
1.440 raeburn 8417: return <<STATE;
8418: <input type="hidden" name="folderpath" value="$folderpath" />
8419: <input type="hidden" name="cmd" value="upload_embedded" />
8420: <input type="hidden" name="newidx" value="$newidx" />
8421: <input type="hidden" name="phase" value="$phase" />
8422: <input type="hidden" name="primaryurl" value="$primaryurl" />
8423: STATE
8424: }
8425:
8426: sub embedded_destination {
8427: my $folder=$env{'form.folder'};
8428: my $destination = 'docs/';
8429: if ($folder =~ /^supplemental/) {
8430: $destination = 'supplemental/';
8431: }
8432: if (($folder eq 'default') || ($folder eq 'supplemental')) {
8433: $destination .= 'default/';
8434: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
8435: $destination .= $2.'/';
8436: }
1.634 raeburn 8437: my $newidx = $env{'form.newidx'};
8438: $newidx =~s /\D+//g;
8439: if ($newidx) {
8440: $destination .= $newidx;
8441: }
1.440 raeburn 8442: my $dir_root = '/userfiles';
8443: return ($destination,$dir_root);
8444: }
8445:
8446: sub return_to_editor {
8447: my $actionurl = '/adm/coursedocs';
8448: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
8449: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
8450: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
8451: '</a></p>';
8452: }
8453:
1.476 raeburn 8454: sub decompression_info {
8455: my ($destination,$dir_root) = &embedded_destination();
8456: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
8457: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8458: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
8459: my $container='sequence';
1.480 raeburn 8460: my ($pathitem,$hiddenelem);
1.583 raeburn 8461: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 8462: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 8463: $container='page';
8464: }
1.480 raeburn 8465: unshift(@hiddens,$pathitem);
8466: foreach my $item (@hiddens) {
1.634 raeburn 8467: if ($item eq 'newidx') {
8468: next if ($env{'form.'.$item} =~ /\D/);
8469: }
1.480 raeburn 8470: if ($env{'form.'.$item}) {
8471: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 8472: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 8473: }
1.477 raeburn 8474: }
1.476 raeburn 8475: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
8476: $hiddenelem);
8477: }
8478:
8479: sub decompression_phase_one {
8480: my ($dir,$file,$warning,$error,$output);
8481: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8482: &decompression_info();
1.490 raeburn 8483: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 8484: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
8485: } else {
8486: my $file = $1;
1.630 raeburn 8487: $output =
1.481 raeburn 8488: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
8489: $destination,$dir_root,
8490: $hiddenelem);
8491: if ($env{'form.autoextract_camtasia'}) {
8492: $output .= &remove_archive($docudom,$docuname,$container);
8493: }
1.476 raeburn 8494: }
8495: if ($error) {
8496: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
8497: $error.'</p>'."\n";
8498: }
8499: if ($warning) {
8500: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
8501: }
8502: return $output;
8503: }
8504:
8505: sub decompression_phase_two {
8506: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8507: &decompression_info();
1.481 raeburn 8508: my $output;
1.480 raeburn 8509: if ($env{'form.archivedelete'}) {
1.481 raeburn 8510: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 8511: }
8512: $output .=
1.481 raeburn 8513: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 8514: $destination,$dir_root,$hiddenelem);
8515: return $output;
8516: }
8517:
1.480 raeburn 8518: sub remove_archive {
8519: my ($docudom,$docuname,$container) = @_;
8520: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 8521: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 8522: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
8523: if ($fatal) {
8524: if ($container eq 'page') {
8525: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
8526: } else {
8527: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
8528: }
1.583 raeburn 8529: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8530: } else {
8531: my $currcmd = $env{'form.cmd'};
8532: my $position = $env{'form.position'};
1.583 raeburn 8533: my $archiveidx = $position;
1.563 raeburn 8534: if ($position > 0) {
1.583 raeburn 8535: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
8536: $archiveidx = $position-1;
8537: }
8538: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 8539: my ($title,$url,@rrest) =
1.583 raeburn 8540: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
8541: if ($url eq $env{'form.archiveurl'}) {
8542: if (&handle_edit_cmd($docuname,$docudom)) {
8543: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 8544: if ($suppchanges) {
8545: &Apache::lonnet::update_supp_caches($docudom,$docuname);
8546: undef($suppchanges);
8547: }
1.583 raeburn 8548: if ($fatal) {
8549: if ($container eq 'page') {
8550: $delwarning = &mt('An error occurred updating the contents of the current page.');
8551: } else {
8552: $delwarning = &mt('An error occurred updating the contents of the current folder.');
8553: }
1.480 raeburn 8554: } else {
1.583 raeburn 8555: $delresult = &mt('Archive file removed.');
1.480 raeburn 8556: }
8557: }
1.583 raeburn 8558: } else {
8559: $delwarning .= &mt('Archive file had unexpected item number in folder.').
8560: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8561: }
8562: }
8563: $env{'form.cmd'} = $currcmd;
8564: }
8565: if ($delwarning) {
8566: $output = '<p class="LC_warning">'.
8567: $delwarning.
8568: '</p>';
8569: }
8570: if ($delresult) {
8571: $output .= '<p class="LC_info">'.
8572: $delresult.
8573: '</p>';
8574: }
1.481 raeburn 8575: return $output;
1.480 raeburn 8576: }
8577:
1.484 raeburn 8578: sub generate_admin_menu {
1.708 raeburn 8579: my ($crstype,$canedit,$coursenum,$coursedom) = @_;
1.484 raeburn 8580: my $lc_crstype = lc($crstype);
8581: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 8582: my %lt= ( # do not translate here
1.484 raeburn 8583: 'vc' => 'Verify Content',
8584: 'cv' => 'Check/Set Resource Versions',
8585: 'ls' => 'List Resource Identifiers',
1.651 raeburn 8586: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.708 raeburn 8587: 'ca' => "Enter $crstype Authoring Space",
1.484 raeburn 8588: 'imse' => 'Export contents to IMS Archive',
1.712 raeburn 8589: 'dcd' => 'Copy uploaded content to Authoring Space',
8590: 'cpc' => 'Copy from Course Authoring to User Authoring',
1.562 bisitz 8591: );
1.712 raeburn 8592: my ($candump,$dumpurl,$exportcrsurl);
1.484 raeburn 8593: if ($home + $other > 0) {
8594: $candump = 'F';
8595: if ($home) {
8596: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
1.712 raeburn 8597: $exportcrsurl = "javascript:injectData(document.courseverify,'dummy','copyauthored','$lt{'cpc'}')";
1.484 raeburn 8598: } else {
8599: my @hosts;
8600: foreach my $aurole (keys(%outhash)) {
8601: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
8602: push(@hosts,$outhash{$aurole});
1.538 raeburn 8603: }
1.484 raeburn 8604: }
8605: if (@hosts == 1) {
8606: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
8607: '&role='.
8608: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
8609: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
8610: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
1.712 raeburn 8611: $exportcrsurl = $dumpurl;
1.484 raeburn 8612: } else {
8613: $dumpurl = "javascript:choose_switchserver_window()";
1.712 raeburn 8614: $exportcrsurl = $dumpurl;
1.484 raeburn 8615: }
8616: }
8617: }
8618: my @menu=
8619: ({ categorytitle=>'Administration',
8620: items =>[
8621: { linktext => $lt{'vc'},
8622: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
8623: permission => 'F',
1.571 raeburn 8624: help => 'Docs_Verify_Content',
1.484 raeburn 8625: icon => 'verify.png',
8626: linktitle => 'Verify contents can be retrieved/rendered',
8627: },
8628: { linktext => $lt{'cv'},
8629: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
8630: permission => 'F',
1.571 raeburn 8631: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 8632: icon => 'resversion.png',
8633: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
8634: },
8635: { linktext => $lt{'ls'},
8636: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
8637: permission => 'F',
8638: #help => '',
8639: icon => 'symbs.png',
8640: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
8641: },
1.651 raeburn 8642: { linktext => $lt{'ct'},
8643: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
8644: permission => 'F',
8645: help => 'Docs_Short_URLs',
8646: icon => 'shorturls.png',
8647: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
8648: },
1.484 raeburn 8649: ]
1.611 raeburn 8650: });
8651: if ($canedit) {
1.708 raeburn 8652: my ($crsauname,$crsaudom,$crshome);
8653: if (($coursenum ne '') && ($coursedom ne '')) {
8654: my $crsauthorurl = "/priv/$coursedom/$coursenum/";
8655: ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl);
8656: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8657: my @ids=&Apache::lonnet::current_machine_ids();
8658: my $linkurl;
8659: if (grep(/^\Q$crshome\E$/,@ids)) {
8660: $linkurl = $crsauthorurl;
8661: } else {
1.720 ! raeburn 8662: my $jscall = &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1);
! 8663: if ($jscall) {
! 8664: $linkurl = 'javascript:'.$jscall;
! 8665: }
1.708 raeburn 8666: }
1.720 ! raeburn 8667: if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY') && ($linkurl)) {
1.708 raeburn 8668: push(@{$menu[0]->{items}},
8669: { linktext => $lt{'ca'},
8670: url => $linkurl,
8671: permission => 'F',
8672: help => 'Docs_Course_Authorspace',
8673: icon => 'impcrsau.png',
8674: linktitle => $lt{'ca'},
8675: });
8676: }
8677: }
8678: }
1.611 raeburn 8679: push(@menu,
1.484 raeburn 8680: { categorytitle=>'Export',
8681: items =>[
8682: { linktext => $lt{'imse'},
8683: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
8684: permission => 'F',
8685: help => 'Docs_Export_Course_Docs',
8686: icon => 'imsexport.png',
8687: linktitle => $lt{'imse'},
8688: },
8689: { linktext => $lt{'dcd'},
8690: url => $dumpurl,
8691: permission => $candump,
1.571 raeburn 8692: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 8693: icon => 'dump.png',
8694: linktitle => $lt{'dcd'},
8695: },
8696: ]
8697: });
1.712 raeburn 8698: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8699: if ((ref($menu[1]) eq 'HASH') && (ref($menu[1]->{'items'}) eq 'ARRAY')) {
8700: push(@{$menu[1]->{items}},
8701: { linktext => $lt{'cpc'},
8702: url => $exportcrsurl,
8703: permission => 'F',
8704: help => 'Docs_Export_Course_Author',
8705: icon => 'res.png',
8706: linktitle => $lt{'cpc'},
8707: });
8708: }
8709: }
1.611 raeburn 8710: }
1.484 raeburn 8711: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
8712: '<input type="hidden" id="dummy" />'."\n".
8713: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
8714: '</form>';
1.329 droeschl 8715: }
8716:
8717: sub generate_edit_table {
1.538 raeburn 8718: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 8719: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 8720: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 8721: my %orderhash = %{$orderhash_ref};
1.611 raeburn 8722: my ($form, $activetab, $active, $disabled);
1.570 raeburn 8723: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 8724: $activetab = $env{'form.active'};
8725: }
1.611 raeburn 8726: unless ($canedit) {
8727: $disabled = ' disabled="disabled"';
8728: }
1.472 raeburn 8729: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 8730: my $backtext = &mt('Exit Editor');
1.458 raeburn 8731: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 8732: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
8733: '<li class="goback">'.
1.546 raeburn 8734: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 8735: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
8736: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
8737: '<li>'.
8738: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
8739: &mt('Undo Delete').'</a></li>'."\n";
8740: if ($env{'form.docslog'}) {
8741: $form .= '<li class="active">';
8742: } else {
8743: $form .= '<li>';
8744: }
8745: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
8746: &mt('History').'</a></li>'."\n";
8747: if ($env{'form.docslog'}) {
8748: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
8749: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 8750: }
1.458 raeburn 8751: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 8752: if($name ne '00'){
1.371 tempelho 8753: if($activetab eq '' || $activetab ne $name){
8754: $active = '';
8755: }elsif($activetab eq $name){
8756: $active = 'class="active"';
8757: }
1.458 raeburn 8758: $form .= '<li style="float:right" '.$active
1.484 raeburn 8759: .' 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 8760: } else {
1.570 raeburn 8761: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 8762:
8763: }
1.329 droeschl 8764: }
1.484 raeburn 8765: $form .= '</ul>'."\n";
8766: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 8767:
8768: if ($to_show ne '') {
1.538 raeburn 8769: my $saveform;
8770: if ($need_save) {
8771: my $button = &mt('Make changes');
8772: my $path;
8773: if ($env{'form.folderpath'}) {
8774: $path =
8775: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
8776: }
8777: $saveform = <<"END";
8778: <div id="multisave" style="display:none; clear:both;" >
8779: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
8780: <input type="hidden" name="folderpath" value="$path" />
8781: <input type="hidden" name="symb" value="$env{'form.symb'}" />
8782: <input type="hidden" name="allhiddenresource" value="" />
8783: <input type="hidden" name="allencrypturl" value="" />
8784: <input type="hidden" name="allrandompick" value="" />
8785: <input type="hidden" name="allrandomorder" value="" />
8786: <input type="hidden" name="changeparms" value="" />
8787: <input type="hidden" name="multiremove" value="" />
8788: <input type="hidden" name="multicut" value="" />
8789: <input type="hidden" name="multicopy" value="" />
8790: <input type="hidden" name="multichange" value="" />
8791: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 8792: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 8793: </form>
8794: </div>
8795: END
8796: }
8797: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 8798: }
1.363 ehlerst 8799: foreach my $field (keys(%orderhash)){
1.390 tempelho 8800: if($field ne '00'){
1.422 onken 8801: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 8802: $active = 'style="display: none;float:left"';
1.422 onken 8803: }elsif($activetab eq $field){
1.458 raeburn 8804: $active = 'style="display:block;float:left"';
1.422 onken 8805: }
8806: $form .= '<div id="'.$field.$tid.'"'
8807: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 8808: .'</div>'."\n";
1.363 ehlerst 8809: }
8810: }
1.484 raeburn 8811: unless ($env{'form.docslog'}) {
8812: $form .= '</div></div>'."\n";
8813: }
1.329 droeschl 8814: return $form;
8815: }
8816:
8817: sub editing_js {
1.622 raeburn 8818: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
8819: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 8820: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 8821: p_mnf => 'Name of New Folder',
8822: t_mnf => 'New Folder',
8823: p_mnp => 'Name of New Page',
8824: t_mnp => 'New Page',
1.451 www 8825: p_mxu => 'Title for the External Score',
1.349 biermanm 8826: p_msp => 'Name of Simple Course Page',
1.329 droeschl 8827: p_msb => 'Title for the Problem',
8828: p_mdb => 'Title for the Drop Box',
1.336 schafran 8829: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 8830: p_mwp => 'Title for Web Page',
1.606 raeburn 8831: p_mnr => 'Title for the Resource',
1.348 weissno 8832: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 8833: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 8834: p_mab_alrt1 => 'Not a valid user:domain',
8835: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
8836: p_chn => 'New Title',
8837: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 8838: p_rmr2a => 'Remove',
8839: p_rmr2b => '?',
8840: p_rmr3a => 'Remove those',
8841: p_rmr3b => 'items?',
8842: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
8843: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 8844: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
8845: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 8846: p_ctr2a => 'Cut',
8847: p_ctr2b => '?',
8848: p_ctr3a => 'Cut those',
8849: p_ctr3b => 'items?',
1.633 raeburn 8850: setal => 'Enter a (unique) alias',
8851: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 8852: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 8853: imsfile => 'You must choose an IMS package for import',
8854: imscms => 'You must select which Course Management System was the source of the IMS package',
8855: invurl => 'Invalid URL',
8856: titbl => 'Title is blank',
1.538 raeburn 8857: more => '(More ...)',
8858: less => '(Less ...)',
1.543 raeburn 8859: noor => 'No actions selected or changes to settings specified.',
8860: noch => 'No changes to settings specified.',
8861: noac => 'No actions selected.',
1.606 raeburn 8862: nofi => 'No file selected',
8863: tinc => 'Title in course',
8864: sunm => 'Sub-directory name',
1.618 raeburn 8865: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 8866: sele => 'Select',
8867: swit => 'Switch server required',
1.329 droeschl 8868: );
1.594 damieng 8869: &js_escape(\%js_lt);
1.433 raeburn 8870: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 8871: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
8872: my $main_container_page;
1.519 raeburn 8873: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
8874: $main_container_page = 1;
1.434 raeburn 8875: }
1.617 raeburn 8876: my $backtourl;
8877: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 8878: my $toplevelsupp = &supplemental_base();
1.690 raeburn 8879: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 8880: my @ids=&Apache::lonnet::current_machine_ids();
8881: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 8882: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
8883: my $caller = $1;
1.525 raeburn 8884: if ($caller =~ /^supplemental/) {
8885: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
8886: } else {
8887: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
8888: $res = &Apache::lonnet::clutter($res);
8889: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 8890: my ($url,$anchor);
8891: if ($res =~ /^([^#]+)#([^#]+)$/) {
8892: $url = $1;
8893: $anchor = $2;
8894: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
8895: $caller = $1.&escape('#').$anchor;
8896: }
1.614 raeburn 8897: } else {
8898: $url = $res;
1.609 raeburn 8899: }
1.640 raeburn 8900: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
8901: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
8902: $backtourl .= '?navmap=1';
8903: } else {
8904: $backtourl .= '?symb='.
8905: &HTML::Entities::encode($caller,'<>&"');
8906: }
1.622 raeburn 8907: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
8908: if (($ENV{'SERVER_PORT'} == 443) &&
8909: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 8910: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 8911: if ($hostname ne '') {
8912: $backtourl = 'http://'.$hostname.$backtourl;
8913: }
8914: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 8915: }
8916: }
1.623 raeburn 8917: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
8918: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 8919: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 8920: if ($hostname ne '') {
8921: $backtourl = 'http://'.$hostname.$backtourl;
8922: }
8923: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 8924: }
1.623 raeburn 8925: }
1.622 raeburn 8926: }
1.609 raeburn 8927: if ($anchor ne '') {
8928: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
8929: }
1.590 raeburn 8930: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 8931: } else {
8932: $backtourl = '/adm/navmaps';
1.525 raeburn 8933: }
8934: }
8935: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
8936: $backtourl = '/adm/menu';
8937: } elsif ($supplementalflag) {
1.682 raeburn 8938: if (($env{'request.role.adv'}) ||
8939: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
8940: $backtourl = '/adm/supplemental';
8941: } else {
8942: $backtourl = '/adm/navmaps';
8943: }
1.525 raeburn 8944: } else {
8945: $backtourl = '/adm/navmaps';
1.472 raeburn 8946: }
8947:
1.655 raeburn 8948: my $fieldsets = "'doc'";
1.519 raeburn 8949: unless ($main_container_page) {
8950: $fieldsets .=",'ims'";
8951: }
1.655 raeburn 8952: my $extfieldsets = "'ext'";
8953: if ($posslti) {
8954: $extfieldsets .= ",'tool'";
8955: }
1.501 raeburn 8956: if ($supplementalflag) {
1.655 raeburn 8957: $fieldsets = "'suppdoc'";
8958: $extfieldsets = "'suppext'";
1.600 raeburn 8959: if ($posslti) {
1.655 raeburn 8960: $extfieldsets .= ",'supptool'";
1.600 raeburn 8961: }
1.501 raeburn 8962: }
1.655 raeburn 8963:
1.611 raeburn 8964: my $jsmakefunctions;
8965: if ($canedit) {
8966: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 8967: function makenewfolder(targetform,folderseq) {
1.594 damieng 8968: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 8969: if (foldername) {
1.676 raeburn 8970: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 8971: targetform.submit();
8972: }
8973: }
8974:
8975: function makenewpage(targetform,folderseq) {
1.594 damieng 8976: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 8977: if (pagename) {
1.676 raeburn 8978: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 8979: targetform.submit();
8980: }
8981: }
8982:
8983: function makeexamupload() {
1.594 damieng 8984: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 8985: if (title) {
1.329 droeschl 8986: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 8987: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 8988: this.document.forms.newexamupload.submit();
8989: }
8990: }
8991:
8992: function makesmppage() {
1.594 damieng 8993: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 8994: if (title) {
1.329 droeschl 8995: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 8996: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 8997: this.document.forms.newsmppg.submit();
8998: }
8999: }
9000:
1.534 raeburn 9001: function makewebpage(type) {
1.594 damieng 9002: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 9003: var formname;
9004: if (type == 'supp') {
9005: formname = this.document.forms.supwebpage;
9006: } else {
9007: formname = this.document.forms.newwebpage;
9008: }
9009: if (title) {
9010: var webpage = formname.importdetail.value;
1.675 raeburn 9011: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 9012: formname.submit();
9013: }
9014: }
9015:
1.329 droeschl 9016: function makesmpproblem() {
1.594 damieng 9017: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 9018: if (title) {
1.329 droeschl 9019: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 9020: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 9021: this.document.forms.newsmpproblem.submit();
9022: }
9023: }
9024:
9025: function makedropbox() {
1.594 damieng 9026: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 9027: if (title) {
1.329 droeschl 9028: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 9029: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 9030: this.document.forms.newdropbox.submit();
9031: }
9032: }
9033:
9034: function makebulboard() {
1.594 damieng 9035: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 9036: if (title) {
9037: this.document.forms.newbul.importdetail.value=
1.676 raeburn 9038: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 9039: this.document.forms.newbul.submit();
9040: }
9041: }
9042:
9043: function makeabout() {
1.594 damieng 9044: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 9045: if (user) {
9046: var comp=new Array();
9047: comp=user.split(':');
9048: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
9049: if ((comp[0]) && (comp[1])) {
9050: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 9051: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 9052: this.document.forms.newaboutsomeone.submit();
9053: } else {
9054: alert("$js_lt{'p_mab_alrt1'}");
9055: }
9056: } else {
9057: alert("$js_lt{'p_mab_alrt2'}");
9058: }
9059: }
9060: }
9061:
9062: function makenew(targetform) {
9063: targetform.submit();
9064: }
9065:
9066: function changename(folderpath,index,oldtitle) {
9067: var title=prompt('$js_lt{"p_chn"}',oldtitle);
9068: if (title) {
9069: this.document.forms.renameform.markcopy.value='';
9070: this.document.forms.renameform.title.value=title;
9071: this.document.forms.renameform.cmd.value='rename_'+index;
9072: this.document.forms.renameform.folderpath.value=folderpath;
9073: this.document.forms.renameform.submit();
9074: }
9075: }
9076:
1.633 raeburn 9077: function setalias(folderpath,index) {
9078: var alias = prompt('$js_lt{"setal"}');
9079: if ((alias != null) && (alias != '')) {
9080: this.document.forms.aliasform.alias.value=alias;
9081: this.document.forms.aliasform.cmd.value='setalias_'+index;
9082: this.document.forms.aliasform.folderpath.value=folderpath;
9083: this.document.forms.aliasform.submit();
9084: }
9085: }
9086:
9087: function delalias(folderpath,index) {
9088: if (confirm('$js_lt{"delal"}')) {
9089: this.document.forms.aliasform.cmd.value='delalias_'+index;
9090: this.document.forms.aliasform.folderpath.value=folderpath;
9091: this.document.forms.aliasform.submit();
9092: }
9093: }
9094:
1.611 raeburn 9095: ENDNEWSCRIPT
9096: } else {
9097: $jsmakefunctions = <<ENDNEWSCRIPT;
9098:
9099: function makenewfolder() {
9100: alert("$js_lt{'edri'}");
9101: }
9102:
9103: function makenewpage() {
9104: alert("$js_lt{'edri'}");
9105: }
9106:
9107: function makeexamupload() {
9108: alert("$js_lt{'edri'}");
9109: }
9110:
9111: function makesmppage() {
9112: alert("$js_lt{'edri'}");
9113: }
9114:
9115: function makewebpage(type) {
9116: alert("$js_lt{'edri'}");
9117: }
9118:
9119: function makesmpproblem() {
9120: alert("$js_lt{'edri'}");
9121: }
9122:
9123: function makedropbox() {
9124: alert("$js_lt{'edri'}");
9125: }
9126:
9127: function makebulboard() {
9128: alert("$js_lt{'edri'}");
9129: }
9130:
9131: function makeabout() {
9132: alert("$js_lt{'edri'}");
9133: }
9134:
9135: function changename() {
9136: alert("$js_lt{'edri'}");
9137: }
9138:
1.633 raeburn 9139: function setalias() {
9140: alert("$js_lt{'edri'}");
9141: }
9142:
9143: function delalias() {
9144: alert("$js_lt{'edri'}");
9145: }
9146:
1.611 raeburn 9147: function makenew() {
9148: alert("$js_lt{'edri'}");
9149: }
9150:
9151: function groupimport() {
9152: alert("$js_lt{'edri'}");
1.335 ehlerst 9153: }
1.611 raeburn 9154:
9155: function groupsearch() {
9156: alert("$js_lt{'edri'}");
1.335 ehlerst 9157: }
1.611 raeburn 9158:
9159: function groupopen(url,recover) {
9160: var options="scrollbars=1,resizable=1,menubar=0";
9161: idxflag=1;
9162: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
9163: idx.focus();
1.329 droeschl 9164: }
9165:
1.611 raeburn 9166: ENDNEWSCRIPT
9167:
9168: }
9169: return <<ENDSCRIPT;
9170:
9171: $jsmakefunctions
9172:
1.501 raeburn 9173: function toggleUpload(caller) {
9174: var blocks = Array($fieldsets);
9175: for (var i=0; i<blocks.length; i++) {
9176: var disp = 'none';
9177: if (caller == blocks[i]) {
9178: var curr = document.getElementById('upload'+caller+'form').style.display;
9179: if (curr == 'none') {
9180: disp='block';
9181: }
9182: }
9183: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 9184: }
9185: resize_scrollbox('contentscroll','1','1');
9186: return;
9187: }
9188:
9189: function toggleExternal(caller) {
9190: var blocks = Array($extfieldsets);
9191: for (var i=0; i<blocks.length; i++) {
9192: var disp = 'none';
9193: if (caller == blocks[i]) {
9194: var curr = document.getElementById('external'+caller+'form').style.display;
9195: if (curr == 'none') {
9196: disp='block';
9197: }
9198: }
9199: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 9200: if ((caller == 'tool') || (caller == 'supptool')) {
9201: if (disp == 'block') {
1.655 raeburn 9202: if (document.getElementById('LC_exttoolid')) {
9203: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 9204: var suppflag = 0;
9205: if (caller == 'supptool') {
9206: suppflag = 1;
9207: }
9208: currForm = document.getElementById('new'+caller);
1.655 raeburn 9209: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 9210: }
9211: }
9212: }
1.501 raeburn 9213: }
1.502 raeburn 9214: resize_scrollbox('contentscroll','1','1');
9215: return;
9216: }
9217:
1.514 raeburn 9218: function toggleMap(caller) {
1.502 raeburn 9219: var disp = 'none';
1.510 raeburn 9220: if (document.getElementById('importmapform')) {
1.514 raeburn 9221: if (caller == 'map') {
9222: var curr = document.getElementById('importmapform').style.display;
9223: if (curr == 'none') {
9224: disp='block';
9225: }
1.510 raeburn 9226: }
9227: document.getElementById('importmapform').style.display=disp;
1.706 raeburn 9228: if (disp == 'block') {
9229: if (document.getElementById('importcrsresform')) {
9230: if (document.getElementById('importcrsresform').style.display == 'block') {
9231: document.getElementById('importcrsresform').style.display = 'none';
9232: }
9233: }
9234: }
1.510 raeburn 9235: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 9236: }
1.501 raeburn 9237: return;
1.329 droeschl 9238: }
9239:
1.691 raeburn 9240: function toggleCrsRes(caller) {
1.606 raeburn 9241: var disp = 'none';
9242: if (document.getElementById('crsresform')) {
9243: if (caller == 'res') {
1.691 raeburn 9244: var form = document.getElementById('crsresform');
9245: var curr = form.style.display;
1.606 raeburn 9246: if (curr == 'none') {
9247: disp='block';
1.691 raeburn 9248: document.courseresform.authorrole.selectedIndex = 0;
9249: document.courseresform.authorpath.selectedIndex = 0;
9250: document.courseresform.newresourceadd.selectedIndex = 0;
9251: populateDirSelects(form,'authorrole','authorpath',1,0,0);
9252: toggleNewInCourse(document.courseresform);
9253: if (document.getElementById('newresource')) {
9254: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 9255: }
9256: if (document.courseresform.newresusetemp.length) {
9257: document.courseresform.newresusetemp[0].checked = true;
9258: toggleWithTemplate(document.courseresform);
9259: }
9260: document.courseresform.newresourcename.value = '';
9261: }
9262: }
9263: if (document.courseresform.newsubdir.length) {
9264: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
9265: if (document.courseresform.newsubdir[j].value == 0) {
9266: document.courseresform.newsubdir[j].checked = true;
9267: }
9268: break;
9269: }
9270: if (document.getElementById('newsubdirname')) {
9271: document.getElementById('newsubdirname').type = "hidden";
9272: document.getElementById('newsubdirname').value = "";
9273: }
9274: if (document.getElementById('newsubdir')) {
9275: document.getElementById('newsubdir').innerHTML = "";
9276: }
9277: }
9278: document.getElementById('crsresform').style.display=disp;
9279: resize_scrollbox('contentscroll','1','0');
9280: }
9281: return;
9282: }
9283:
9284: function toggleNewsubdir(form) {
9285: if (form.newsubdir.length) {
9286: for (var j=0; j<form.newsubdir.length; j++) {
9287: if (form.newsubdir[j].checked) {
9288: if (document.getElementById('newsubdirname')) {
9289: if (form.newsubdir[j].value == '1') {
9290: document.getElementById('newsubdirname').type = "text";
9291: if (document.getElementById('newsubdir')) {
9292: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
9293: }
9294: } else {
9295: document.getElementById('newsubdirname').type = "hidden";
9296: document.getElementById('newsubdirname').value = "";
9297: document.getElementById('newsubdir').innerHTML = "";
9298: }
9299: }
9300: break;
9301: }
9302: }
9303: }
9304: }
9305:
9306: function toggleCrsResTitle() {
9307: if (document.getElementById('newresource')) {
1.691 raeburn 9308: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9309: if (selloc == 'course') {
1.606 raeburn 9310: document.getElementById('newresource').style.display = 'inline';
9311: document.courseresform.newresourceadd[0].checked = true;
9312: toggleNewInCourse(document.courseresform);
9313: } else {
9314: document.getElementById('newresource').style.display = 'none';
9315: }
1.689 raeburn 9316: }
9317: if (document.getElementById('newstdproblem')) {
9318: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
9319: document.getElementById('newstdproblem').style.display = 'none';
9320: if (document.getElementById('stdprobswitch')) {
9321: document.getElementById('stdprobswitch').style.display = 'block';
9322: }
9323: } else {
9324: document.getElementById('newstdproblem').style.display = 'block';
9325: if (document.getElementById('stdprobswitch')) {
9326: document.getElementById('stdprobswitch').style.display = 'none';
9327: }
9328: }
9329: }
1.606 raeburn 9330: }
9331:
9332: function toggleNewInCourse(form) {
9333: if (form.newresourceadd.length) {
9334: for (var i=0; i<form.newresourceadd.length; i++) {
9335: if (form.newresourceadd[i].checked) {
9336: if (document.getElementById('newresourcetitle')) {
9337: if (form.newresourceadd[i].value == '1') {
9338: document.getElementById('newresourcetitle').type = 'text';
9339: if (document.getElementById('newrestitle')) {
9340: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
9341: }
9342: } else {
9343: document.getElementById('newresourcetitle').type = 'hidden';
9344: document.getElementById('newresourcetitle').value = '';
9345: if (document.getElementById('newrestitle')) {
9346: document.getElementById('newrestitle').innerHTML = '';
9347: }
9348: }
9349: }
9350: break;
9351: }
9352: }
9353: }
9354: }
9355:
9356: function toggleWithTemplate(form) {
9357: if (form.newresusetemp.length) {
9358: for (var i=0; i<form.newresusetemp.length; i++) {
9359: if (form.newresusetemp[i].checked) {
9360: if (document.getElementById('newrestemplate')) {
9361: if (form.newresusetemp[i].value == '1') {
9362: document.getElementById('newrestemplate').style.display = 'inline';
9363: toggleExampleText();
9364: } else {
9365: form.tempcategory.selectedIndex = 0;
9366: select1template_changed();
9367: document.getElementById('newrestemplate').style.display = 'none';
9368: }
9369: }
9370: }
9371: }
9372: }
9373: }
9374:
9375: function toggleExampleText() {
9376: if (document.getElementById('newresexample')) {
9377: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9378: if (url == '') {
9379: document.getElementById('newresexample').style.fontWeight = 'normal';
9380: } else {
9381: document.getElementById('newresexample').style.fontWeight = 'bold';
9382: }
9383: }
9384: }
9385:
9386: function getExample(width,height,scrolling,transparency) {
9387: var url;
9388: if (document.courseresform.newresusetemp.length) {
9389: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
9390: if (document.courseresform.newresusetemp[i].checked) {
9391: if (document.courseresform.newresusetemp[i].value == '1') {
9392: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9393: if (url == '') {
9394: alert('Pick a category and template');
9395: } else {
9396: url = url.replace("$londocroot","");
9397: url += '?inhibitmenu=yes';
9398: }
9399: }
9400: break;
9401: }
9402: }
9403: }
9404: if (url != '') {
9405: openMyModal(url,width,height,scrolling,transparency,'');
9406: }
9407: }
9408:
1.690 raeburn 9409: function toggleImportCrsres(caller) {
1.606 raeburn 9410: var disp = 'none';
9411: if (document.getElementById('importcrsresform')) {
9412: if (caller == 'res') {
9413: var curr = document.getElementById('importcrsresform').style.display;
9414: if (curr == 'none') {
9415: disp='block';
1.698 raeburn 9416: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
9417: if ((document.getElementById('importcrsrescontent')) &&
9418: (document.getElementById('importcrsresempty'))) {
9419: var selelem = document.crsresimportform.elements['coursepath'];
9420: var numdirs = 0;
9421: if (selelem.options.length) {
9422: numdirs = selelem.options.length - 1;
9423: }
9424: if (numdirs) {
9425: document.getElementById('importcrsrescontent').style.display='block';
9426: document.getElementById('importcrsresempty').style.display='none';
9427: } else {
9428: document.getElementById('importcrsrescontent').style.display='none';
9429: document.getElementById('importcrsresempty').style.display='block';
9430: }
9431: }
1.606 raeburn 9432: }
9433: }
9434: document.getElementById('importcrsresform').style.display=disp;
1.706 raeburn 9435: if (disp == 'block') {
9436: if (document.getElementById('importmapform')) {
9437: if (document.getElementById('importmapform').style.display == 'block') {
9438: document.getElementById('importmapform').style.display = 'none';
9439: }
9440: }
9441: }
1.606 raeburn 9442: resize_scrollbox('contentscroll','1','0');
9443: }
9444: return;
9445: }
9446:
1.690 raeburn 9447: $showfile_js
9448:
1.691 raeburn 9449: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
9450: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
9451: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
9452: var selelem = form.elements[dirsel];
9453: var i, numfiles = selelem.options.length -1;
9454: if (numfiles >=0) {
9455: for (i = numfiles; i >= 0; i--) {
9456: selelem.remove(i);
9457: }
9458: }
9459: if ((location == '') || (location == null) || (location == 'undefined')) {
9460: if (selelem.options.length == 0) {
9461: selelem.options[selelem.options.length] = new Option('','');
9462: selelem.selectedIndex = 0;
9463: }
9464: if (document.getElementById('newstdproblem')) {
9465: document.getElementById('newstdproblem').style.display = 'none';
9466: }
9467: return;
9468: }
9469: var machineIds = new Array($machines_str);
9470: var athome = 0;
9471: var role = location;
9472: if ((location == 'author') || (location == 'course')) {
9473: if (document.getElementById('rolehome_'+location)) {
9474: var currhome = document.getElementById('rolehome_'+location).value;
9475: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9476: if (machineIds.includes(currhome)) {
9477: athome = 1;
9478: }
9479: }
9480: }
9481: } else {
9482: const roleinfo = location.split('___');
9483: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
9484: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
9485: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
9486: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9487: if (machineIds.includes(currhome)) {
9488: athome = 1;
9489: }
9490: }
9491: }
9492: }
1.706 raeburn 9493: var templateradio = document.courseresform.elements['newresusetemp'];
1.691 raeburn 9494: if (athome) {
9495: if (document.getElementById('stdprobswitch')) {
9496: document.getElementById('stdprobswitch').style.display = 'none';
9497: }
9498: if (document.getElementById('newstdproblem')) {
9499: document.getElementById('newstdproblem').style.display = 'none';
9500: }
1.706 raeburn 9501: var canedit = '$canedit';
9502: if (canedit) {
9503: if (templateradio.length > 1) {
9504: for (var i=0; i<templateradio.length; i++) {
9505: templateradio[i].disabled = false;
9506: }
9507: }
9508: document.courseresform.newresourcename.disabled = false;
9509: document.courseresform.newcrs.disabled = false;
9510: }
1.691 raeburn 9511: var http = new XMLHttpRequest();
9512: var url = "/adm/courseauthor";
1.698 raeburn 9513: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 9514: http.open("POST", url, true);
9515: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
9516: http.onreadystatechange = function() {
9517: if (http.readyState == 4 && http.status == 200) {
9518: var data = JSON.parse(http.responseText);
9519: if (Array.isArray(data.dirs)) {
9520: var len = data.dirs.length;
9521: if (len) {
9522: if (len > 1) {
9523: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
9524: }
9525: }
9526: if (len) {
9527: var j;
9528: for (j = 0; j < len; j++) {
9529: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
9530: }
9531: selelem.selectedIndex = 0;
1.697 raeburn 9532: if (len == 1) {
9533: toggleCrsResTitle();
9534: }
1.691 raeburn 9535: }
9536: }
9537: }
9538: }
9539: http.send(params);
9540: } else {
9541: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
9542: selelem.selectedIndex = 0;
9543: if (document.getElementById('stdprobswitch')) {
9544: document.getElementById('stdprobswitch').style.display = 'block';
9545: }
9546: if (document.getElementById('newstdproblem')) {
9547: document.getElementById('newstdproblem').style.display = 'none';
9548: }
1.706 raeburn 9549: if (templateradio.length > 1) {
9550: for (var i=0; i<templateradio.length; i++) {
9551: templateradio[i].disabled = true;
9552: }
9553: }
9554: document.courseresform.newresourcename.disabled = true;
9555: document.courseresform.newcrs.disabled = true;
1.691 raeburn 9556: }
9557: }
9558: return;
9559: }
9560:
1.689 raeburn 9561: function switchForProb() {
9562: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
9563: var url = '/adm/switchserver?otherserver=';
9564: var newhostid = '';
9565: var role = '';
9566: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9567: if (selloc == 'author') {
9568: newhostid = document.courseresform.rolehome_author.value;
9569: role = "au./&js_escape($env{'user.domain'})/";
9570: } else if (selloc == 'course') {
9571: newhostid = document.courseresform.rolehome_course.value;
9572: role = "&js_escape($env{'request.role'})";
9573: } else {
9574: var items = new Array();
9575: items = selloc.split('___');
9576: var len = document.courseresform.rolehome_coauthor.length;
9577: if (null == len) {
9578: var currval = document.courseresform.rolehome_coauthor.value;
9579: if (null != currval) {
9580: var info = new Array();
9581: info = currval.split('=');
9582: newhostid = info[2];
9583: role = info[0]+'./'+info[1];
9584: }
9585: } else {
9586: for (var i=0; i<len; i++) {
9587: var currval = document.courseresform.rolehome_coauthor[i].value;
9588: if (null != currval) {
9589: var info = new Array();
9590: info = currval.split('=');
9591: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
9592: newhostid = info[2];
9593: role = info[0]+'./'+info[1];
9594: break;
9595: }
9596: }
9597: }
9598: }
9599: }
9600: if (newhostid != '') {
9601: url += newhostid;
9602: if (role != '') {
9603: url += '&role='+role;
9604: }
9605: document.location.href = url;
9606: }
9607: }
9608: return;
9609: }
9610:
1.501 raeburn 9611: function makeims(imsform) {
9612: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 9613: alert("$js_lt{'imsfile'}");
1.501 raeburn 9614: return;
9615: }
9616: if (imsform.source.selectedIndex == 0) {
1.594 damieng 9617: alert("$js_lt{'imscms'}");
1.501 raeburn 9618: return;
9619: }
9620: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
9621: imsform.submit();
9622: }
9623:
1.478 raeburn 9624: function updatePick(targetform,index,caller) {
1.537 raeburn 9625: var pickitem;
9626: var picknumitem;
9627: var picknumtext;
9628: if (index == 'all') {
9629: pickitem = document.getElementById('randompickall');
9630: picknumitem = document.getElementById('rpicknumall');
9631: picknumtext = document.getElementById('rpicktextall');
9632: } else {
9633: pickitem = document.getElementById('randompick_'+index);
9634: picknumitem = document.getElementById('rpicknum_'+index);
9635: picknumtext = document.getElementById('randompicknum_'+index);
9636: }
1.478 raeburn 9637: if (pickitem.checked) {
1.594 damieng 9638: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 9639: if (picknum == '' || picknum == null) {
9640: if (caller == 'check') {
9641: pickitem.checked=false;
1.537 raeburn 9642: if (index == 'all') {
9643: picknumtext.innerHTML = '';
9644: if (caller == 'link') {
9645: propagateState(targetform,'rpicknum');
9646: }
9647: } else {
1.538 raeburn 9648: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9649: }
1.478 raeburn 9650: }
9651: } else {
9652: picknum.toString();
9653: var regexdigit=/^\\d+\$/;
9654: if (regexdigit.test(picknum)) {
9655: picknumitem.value = picknum;
1.537 raeburn 9656: if (index == 'all') {
1.538 raeburn 9657: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 9658: if (caller == 'link') {
9659: propagateState(targetform,'rpicknum');
9660: }
9661: } else {
9662: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 9663: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9664: }
1.478 raeburn 9665: } else {
9666: if (caller == 'check') {
1.537 raeburn 9667: if (index == 'all') {
9668: picknumtext.innerHTML = '';
9669: if (caller == 'link') {
9670: propagateState(targetform,'rpicknum');
9671: }
9672: } else {
9673: pickitem.checked=false;
1.538 raeburn 9674: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9675: }
1.478 raeburn 9676: }
9677: return;
9678: }
9679: }
9680: } else {
1.537 raeburn 9681: picknumitem.value = '';
9682: picknumtext.innerHTML = '';
9683: if (index == 'all') {
9684: if (caller == 'link') {
9685: propagateState(targetform,'rpicknum');
9686: }
9687: } else {
1.538 raeburn 9688: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9689: }
9690: }
9691: }
9692:
9693: function propagateState(form,param) {
9694: if (document.getElementById(param+'all')) {
9695: var setcheck = 0;
9696: var rpick = 0;
9697: if (param == 'rpicknum') {
9698: if (document.getElementById('randompickall')) {
9699: if (document.getElementById('randompickall').checked) {
9700: if (document.getElementById('rpicknumall')) {
9701: rpick = document.getElementById('rpicknumall').value;
9702: }
9703: }
9704: }
9705: } else {
9706: if (document.getElementById(param+'all').checked) {
9707: setcheck = 1;
9708: }
9709: }
1.538 raeburn 9710: var allidxlist;
9711: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9712: if (document.getElementById('all'+param+'idx')) {
9713: allidxlist = document.getElementById('all'+param+'idx').value;
9714: }
9715: var actions = new Array ('remove','cut','copy');
9716: for (var i=0; i<actions.length; i++) {
9717: if (actions[i] != param) {
9718: if (document.getElementById(actions[i]+'all')) {
9719: document.getElementById(actions[i]+'all').checked = false;
9720: }
9721: }
9722: }
9723: }
1.537 raeburn 9724: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 9725: allidxlist = form.allidx.value;
9726: }
9727: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
9728: allidxlist = form.allmapidx.value;
9729: }
9730: if ((allidxlist != '') && (allidxlist != null)) {
9731: var allidxs = allidxlist.split(',');
9732: if (allidxs.length > 1) {
9733: for (var i=0; i<allidxs.length; i++) {
9734: if (document.getElementById(param+'_'+allidxs[i])) {
9735: if (param == 'rpicknum') {
9736: if (document.getElementById('randompick_'+allidxs[i])) {
9737: if (document.getElementById('randompick_'+allidxs[i]).checked) {
9738: document.getElementById(param+'_'+allidxs[i]).value = rpick;
9739: if (rpick > 0) {
9740: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
9741: } else {
9742: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9743: }
9744: }
9745: }
9746: } else {
1.537 raeburn 9747: if (setcheck == 1) {
9748: document.getElementById(param+'_'+allidxs[i]).checked = true;
9749: } else {
9750: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 9751: if (param == 'randompick') {
9752: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9753: }
1.537 raeburn 9754: }
9755: }
9756: }
9757: }
1.538 raeburn 9758: if (setcheck == 1) {
9759: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9760: var actions = new Array('copy','cut','remove');
9761: for (var i=0; i<actions.length; i++) {
9762: var otheractions;
9763: var otheridxs;
9764: if (actions[i] === param) {
9765: continue;
9766: } else {
9767: if (document.getElementById('all'+actions[i]+'idx')) {
9768: otheractions = document.getElementById('all'+actions[i]+'idx').value;
9769: otheridxs = otheractions.split(',');
9770: if (otheridxs.length > 1) {
9771: for (var j=0; j<otheridxs.length; j++) {
9772: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
9773: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
9774: }
1.537 raeburn 9775: }
9776: }
9777: }
1.538 raeburn 9778: }
9779: }
9780: }
9781: }
9782: }
9783: }
9784: }
9785: return;
9786: }
9787:
1.603 raeburn 9788: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 9789: var canedit = '$canedit';
9790: if (canedit == '') {
9791: alert("$js_lt{'edri'}");
9792: return;
9793: }
1.539 raeburn 9794: var dosettings;
9795: var doaction;
1.538 raeburn 9796: var control = document.togglemultsettings;
9797: if (context == 'actions') {
9798: control = document.togglemultactions;
1.539 raeburn 9799: doaction = 1;
9800: } else {
9801: dosettings = 1;
1.538 raeburn 9802: }
1.539 raeburn 9803: if (control) {
9804: if (control.showmultpick.length) {
9805: for (var i=0; i<control.showmultpick.length; i++) {
9806: if (control.showmultpick[i].checked) {
9807: if (control.showmultpick[i].value == 1) {
9808: if (context == 'settings') {
9809: dosettings = 0;
9810: } else {
9811: doaction = 0;
1.538 raeburn 9812: }
9813: }
9814: }
1.537 raeburn 9815: }
9816: }
1.539 raeburn 9817: }
9818: if (context == 'settings') {
9819: if (dosettings == 1) {
1.538 raeburn 9820: targetform.changeparms.value=param;
9821: targetform.submit();
9822: }
1.537 raeburn 9823: }
1.539 raeburn 9824: if (context == 'actions') {
9825: if (doaction == 1) {
9826: targetform.cmd.value=param+'_'+index;
9827: targetform.folderpath.value=folderpath;
9828: targetform.markcopy.value=idx+':'+param;
9829: targetform.copyfolder.value=folder+'.'+container;
9830: if (param == 'remove') {
1.603 raeburn 9831: var doremove = 0;
9832: if (skip_confirm) {
9833: if (confirm_removal) {
9834: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
9835: doremove = 1;
9836: }
9837: } else {
9838: doremove = 1;
9839: }
9840: } else {
9841: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
9842: doremove = 1;
9843: }
9844: }
9845: if (doremove) {
1.539 raeburn 9846: targetform.markcopy.value='';
9847: targetform.copyfolder.value='';
9848: targetform.submit();
9849: }
9850: }
9851: if (param == 'cut') {
1.594 damieng 9852: 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 9853: targetform.submit();
9854: return;
9855: }
9856: }
9857: if (param == 'copy') {
9858: targetform.submit();
9859: return;
9860: }
9861: targetform.markcopy.value='';
9862: targetform.copyfolder.value='';
9863: targetform.cmd.value='';
9864: targetform.folderpath.value='';
9865: return;
9866: } else {
9867: if (document.getElementById(param+'_'+idx)) {
9868: item = document.getElementById(param+'_'+idx);
9869: if (item.type == 'checkbox') {
9870: if (item.checked) {
9871: item.checked = false;
9872: } else {
9873: item.checked = true;
9874: singleCheck(item,idx,param);
9875: }
9876: }
9877: }
9878: }
9879: }
1.537 raeburn 9880: return;
9881: }
9882:
1.538 raeburn 9883: function singleCheck(caller,idx,action) {
9884: actions = new Array('cut','copy','remove');
9885: if (caller.checked) {
9886: for (var i=0; i<actions.length; i++) {
9887: if (actions[i] != action) {
9888: if (document.getElementById(actions[i]+'_'+idx)) {
9889: if (document.getElementById(actions[i]+'_'+idx).checked) {
9890: document.getElementById(actions[i]+'_'+idx).checked = false;
9891: }
1.537 raeburn 9892: }
9893: }
9894: }
1.478 raeburn 9895: }
1.537 raeburn 9896: return;
1.478 raeburn 9897: }
9898:
1.334 muellerd 9899: function unselectInactive(nav) {
1.335 ehlerst 9900: currentNav = document.getElementById(nav);
9901: currentLis = currentNav.getElementsByTagName('LI');
9902: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 9903: if (currentLis[i].className == 'goback') {
9904: currentLis[i].className = 'goback';
9905: } else {
9906: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 9907: currentLis[i].className = 'right';
1.472 raeburn 9908: } else {
1.374 tempelho 9909: currentLis[i].className = 'i';
1.472 raeburn 9910: }
9911: }
1.335 ehlerst 9912: }
1.332 tempelho 9913: }
9914:
1.334 muellerd 9915: function hideAll(current, nav, data) {
1.335 ehlerst 9916: unselectInactive(nav);
1.570 raeburn 9917: if (current) {
9918: if (current.className == 'right'){
9919: current.className = 'right active'
9920: } else {
9921: current.className = 'active';
9922: }
1.374 tempelho 9923: }
1.335 ehlerst 9924: currentData = document.getElementById(data);
9925: currentDivs = currentData.getElementsByTagName('DIV');
9926: for (i = 0; i < currentDivs.length; i++) {
9927: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 9928: currentDivs[i].style.display = 'none';
1.330 tempelho 9929: }
9930: }
1.335 ehlerst 9931: }
1.330 tempelho 9932:
1.374 tempelho 9933: function openTabs(pageId) {
9934: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 9935: if(tabnav.length > 2 ){
1.389 tempelho 9936: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 9937: currentLis = currentNav.getElementsByTagName('LI');
9938: for(i = 0; i< currentLis.length; i++){
9939: if(currentLis[i].className == 'active') {
1.375 tempelho 9940: funcString = currentLis[i].onclick.toString();
9941: tab = funcString.split('"');
1.420 onken 9942: if(tab.length < 2) {
9943: tab = funcString.split("'");
9944: }
1.375 tempelho 9945: currentData = document.getElementById(tab[1]);
9946: currentData.style.display = 'block';
1.374 tempelho 9947: }
9948: }
9949: }
9950: }
9951:
1.334 muellerd 9952: function showPage(current, pageId, nav, data) {
1.570 raeburn 9953: currstate = current.className;
1.334 muellerd 9954: hideAll(current, nav, data);
1.375 tempelho 9955: openTabs(pageId);
1.334 muellerd 9956: unselectInactive(nav);
1.570 raeburn 9957: if ((currstate == 'active') || (currstate == 'right active')) {
9958: if (currstate == 'active') {
9959: current.className = '';
9960: } else {
9961: current.className = 'right';
9962: }
9963: activeTab = '';
1.656 raeburn 9964: toggleExternal();
1.570 raeburn 9965: toggleUpload();
9966: toggleMap();
1.606 raeburn 9967: toggleCrsRes();
9968: toggleImportCrsres();
1.570 raeburn 9969: resize_scrollbox('contentscroll','1','0');
9970: return;
9971: } else {
9972: current.className = 'active';
9973: }
1.330 tempelho 9974: currentData = document.getElementById(pageId);
9975: currentData.style.display = 'block';
1.458 raeburn 9976: activeTab = pageId;
1.656 raeburn 9977: toggleExternal();
1.501 raeburn 9978: toggleUpload();
1.503 raeburn 9979: toggleMap();
1.606 raeburn 9980: toggleCrsRes();
9981: toggleImportCrsres();
1.433 raeburn 9982: if (nav == 'mainnav') {
9983: var storedpath = "$docs_folderpath";
1.434 raeburn 9984: var storedpage = "$main_container_page";
1.433 raeburn 9985: var reg = new RegExp("^supplemental");
9986: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 9987: if (storedpage == 1) {
9988: document.simpleedit.folderpath.value = '';
9989: document.uploaddocument.folderpath.value = '';
9990: } else {
9991: if (reg.test(storedpath)) {
9992: document.simpleedit.folderpath.value = '$toplevelmain';
9993: document.uploaddocument.folderpath.value = '$toplevelmain';
9994: document.newext.folderpath.value = '$toplevelmain';
9995: } else {
9996: document.simpleedit.folderpath.value = storedpath;
9997: document.uploaddocument.folderpath.value = storedpath;
9998: document.newext.folderpath.value = storedpath;
9999: }
1.433 raeburn 10000: }
10001: } else {
1.434 raeburn 10002: if (reg.test(storedpath)) {
10003: document.simpleedit.folderpath.value = storedpath;
10004: document.supuploaddocument.folderpath.value = storedpath;
10005: document.supnewext.folderpath.value = storedpath;
10006: } else {
1.433 raeburn 10007: document.simpleedit.folderpath.value = '$toplevelsupp';
10008: document.supuploaddocument.folderpath.value = '$toplevelsupp';
10009: document.supnewext.folderpath.value = '$toplevelsupp';
10010: }
10011: }
10012: }
1.485 raeburn 10013: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 10014: return false;
10015: }
1.329 droeschl 10016:
1.472 raeburn 10017: function toContents(jumpto) {
10018: var newurl = '$backtourl';
1.525 raeburn 10019: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 10020: newurl = newurl+'?postdata='+jumpto;
10021: }
10022: location.href=newurl;
10023: }
10024:
1.538 raeburn 10025: function togglePick(caller,value) {
10026: var disp = 'none';
10027: if (document.getElementById('multi'+caller)) {
10028: var curr = document.getElementById('multi'+caller).style.display;
10029: if (value == 1) {
10030: disp='block';
10031: }
10032: if (curr == disp) {
10033: return;
10034: }
10035: document.getElementById('multi'+caller).style.display=disp;
10036: if (value == 1) {
1.594 damieng 10037: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 10038: } else {
10039: document.getElementById('more'+caller).innerHTML = '';
10040: }
10041: if (caller == 'actions') {
10042: setClass(value);
10043: setBoxes(value);
10044: }
10045: }
10046: var showButton = multiSettings();
10047: if (showButton != 1) {
10048: showButton = multiActions();
10049: }
10050: if (document.getElementById('multisave')) {
10051: if (showButton == 1) {
10052: document.getElementById('multisave').style.display='block';
10053: } else {
10054: document.getElementById('multisave').style.display='none';
10055: }
10056: }
10057: resize_scrollbox('contentscroll','1','1');
10058: return;
10059: }
10060:
10061: function toggleCheckUncheck(caller,more) {
10062: if (more == 1) {
1.594 damieng 10063: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 10064: document.getElementById('allfields'+caller).style.display='block';
10065: } else {
1.594 damieng 10066: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 10067: document.getElementById('allfields'+caller).style.display='none';
10068: }
10069: resize_scrollbox('contentscroll','1','1');
10070: }
10071:
10072: function multiSettings() {
10073: var inuse = 0;
10074: var settingsform = document.togglemultsettings;
10075: if (settingsform.showmultpick.length > 1) {
10076: for (var i=0; i<settingsform.showmultpick.length; i++) {
10077: if (settingsform.showmultpick[i].checked) {
10078: if (settingsform.showmultpick[i].value == 1) {
10079: inuse = 1;
10080: }
10081: }
10082: }
10083: }
10084: return inuse;
10085: }
10086:
10087: function multiActions() {
10088: var inuse = 0;
10089: var actionsform = document.togglemultactions;
10090: if (actionsform.showmultpick.length > 1) {
10091: for (var i=0; i<actionsform.showmultpick.length; i++) {
10092: if (actionsform.showmultpick[i].checked) {
10093: if (actionsform.showmultpick[i].value == 1) {
10094: inuse = 1;
10095: }
10096: }
10097: }
10098: }
10099: return inuse;
10100: }
10101:
10102: function checkSubmits() {
10103: var numchanges = 0;
10104: var form = document.saveactions;
10105: var doactions = multiActions();
1.542 raeburn 10106: var cutwarnings = 0;
10107: var remwarnings = 0;
1.603 raeburn 10108: var removalinfo = 0;
1.538 raeburn 10109: if (doactions == 1) {
10110: var remidxlist = document.cumulativeactions.allremoveidx.value;
10111: if ((remidxlist != '') && (remidxlist != null)) {
10112: var remidxs = remidxlist.split(',');
10113: for (var i=0; i<remidxs.length; i++) {
10114: if (document.getElementById('remove_'+remidxs[i])) {
10115: if (document.getElementById('remove_'+remidxs[i]).checked) {
10116: form.multiremove.value += remidxs[i]+',';
10117: numchanges ++;
1.542 raeburn 10118: if (document.getElementById('skip_remove_'+remidxs[i])) {
10119: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
10120: remwarnings ++;
10121: }
10122: }
1.603 raeburn 10123: if (document.getElementById('confirm_removal_'+remidxs[i])) {
10124: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
10125: removalinfo ++;
10126: }
10127: }
1.537 raeburn 10128: }
10129: }
1.538 raeburn 10130: }
10131: }
10132: var cutidxlist = document.cumulativeactions.allcutidx.value;
10133: if ((cutidxlist != '') && (cutidxlist != null)) {
10134: var cutidxs = cutidxlist.split(',');
10135: for (var i=0; i<cutidxs.length; i++) {
10136: if (document.getElementById('cut_'+cutidxs[i])) {
10137: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
10138: form.multicut.value += cutidxs[i]+',';
10139: numchanges ++;
1.542 raeburn 10140: if (document.getElementById('skip_cut_'+cutidxs[i])) {
10141: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
10142: cutwarnings ++;
10143: }
10144: }
1.537 raeburn 10145: }
10146: }
10147: }
10148: }
1.538 raeburn 10149: var copyidxlist = document.cumulativeactions.allcopyidx.value;
10150: if ((copyidxlist != '') && (copyidxlist != null)) {
10151: var copyidxs = copyidxlist.split(',');
10152: for (var i=0; i<copyidxs.length; i++) {
10153: if (document.getElementById('copy_'+copyidxs[i])) {
10154: if (document.getElementById('copy_'+copyidxs[i]).checked) {
10155: form.multicopy.value += copyidxs[i]+',';
10156: numchanges ++;
10157: }
10158: }
10159: }
10160: }
10161: if (numchanges > 0) {
10162: form.multichange.value = numchanges;
10163: }
1.537 raeburn 10164: }
1.538 raeburn 10165: var dosettings = multiSettings();
1.543 raeburn 10166: var haschanges = 0;
1.538 raeburn 10167: if (dosettings == 1) {
10168: form.allencrypturl.value = '';
10169: form.allhiddenresource.value = '';
1.543 raeburn 10170: form.changeparms.value = 'all';
10171: var patt=new RegExp(",\$");
1.538 raeburn 10172: var allidxlist = document.cumulativesettings.allidx.value;
10173: if ((allidxlist != '') && (allidxlist != null)) {
10174: var allidxs = allidxlist.split(',');
10175: if (allidxs.length > 1) {
10176: for (var i=0; i<allidxs.length; i++) {
10177: if (document.getElementById('hiddenresource_'+allidxs[i])) {
10178: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
10179: form.allhiddenresource.value += allidxs[i]+',';
10180: }
10181: }
10182: if (document.getElementById('encrypturl_'+allidxs[i])) {
10183: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
10184: form.allencrypturl.value += allidxs[i]+',';
10185: }
10186: }
10187: }
1.543 raeburn 10188: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
10189: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 10190: }
1.538 raeburn 10191: }
10192: form.allrandompick.value = '';
10193: form.allrandomorder.value = '';
10194: var allmapidxlist = document.cumulativesettings.allmapidx.value;
10195: if ((allmapidxlist != '') && (allmapidxlist != null)) {
10196: var allmapidxs = allmapidxlist.split(',');
10197: for (var i=0; i<allmapidxs.length; i++) {
10198: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
10199: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
10200: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
10201: if ((randompick.checked) && (rpicknum.value != '')) {
10202: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
10203: }
10204: if (randorder.checked) {
10205: form.allrandomorder.value += allmapidxs[i]+',';
10206: }
1.537 raeburn 10207: }
1.543 raeburn 10208: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
10209: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
10210: }
10211: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
10212: haschanges = 1;
10213: }
10214: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
10215: haschanges = 1;
10216: }
10217: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
10218: haschanges = 1;
10219: }
10220: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
10221: haschanges = 1;
1.537 raeburn 10222: }
10223: }
1.543 raeburn 10224: if (doactions == 1) {
1.542 raeburn 10225: if (numchanges > 0) {
1.603 raeburn 10226: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 10227: if (remwarnings > 0) {
1.594 damieng 10228: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 10229: return false;
10230: }
10231: }
1.603 raeburn 10232: if (removalinfo > 0) {
10233: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
10234: return false;
10235: }
10236: }
1.542 raeburn 10237: if (cutwarnings > 0) {
1.594 damieng 10238: 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 10239: return false;
10240: }
10241: }
10242: }
10243: form.submit();
10244: return true;
1.543 raeburn 10245: }
10246: }
10247: if (dosettings == 1) {
10248: if (haschanges == 1) {
1.542 raeburn 10249: form.submit();
10250: return true;
10251: }
1.543 raeburn 10252: }
10253: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 10254: alert("$js_lt{'noor'}");
1.543 raeburn 10255: } else {
10256: if (dosettings == 1) {
1.594 damieng 10257: alert("$js_lt{'noch'}");
1.543 raeburn 10258: } else {
1.594 damieng 10259: alert("$js_lt{'noac'}");
1.543 raeburn 10260: }
10261: }
1.538 raeburn 10262: return false;
10263: }
10264:
10265: function setClass(value) {
10266: var cutclass = 'LC_docs_cut';
10267: var copyclass = 'LC_docs_copy';
10268: var removeclass = 'LC_docs_remove';
10269: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
10270: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
10271: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
10272: var links = document.getElementsByTagName('a');
10273: for (var i=0; i<links.length; i++) {
10274: var classes = links[i].className;
10275: if (cutreg.test(classes)) {
10276: links[i].className = cutclass;
10277: if (value == 1) {
10278: links[i].className += " LC_menubuttons_link";
10279: }
10280: } else {
10281: if (copyreg.test(classes)) {
10282: links[i].className = copyclass;
10283: if (value == 1) {
10284: links[i].className += " LC_menubuttons_link";
10285: }
10286: } else {
10287: if (removereg.test(classes)) {
10288: links[i].className = removeclass;
10289: if (value == 1) {
10290: links[i].className += " LC_menubuttons_link";
10291: }
10292: }
10293: }
10294: }
10295: }
10296: return;
1.537 raeburn 10297: }
10298:
1.538 raeburn 10299: function setBoxes(value) {
10300: var remidxlist = document.cumulativeactions.allremoveidx.value;
10301: if ((remidxlist != '') && (remidxlist != null)) {
10302: var remidxs = remidxlist.split(',');
10303: for (var i=0; i<remidxs.length; i++) {
10304: if (document.getElementById('remove_'+remidxs[i])) {
10305: var item = document.getElementById('remove_'+remidxs[i]);
10306: if (value == 1) {
10307: item.className = 'LC_docs_remove';
10308: } else {
10309: item.className = 'LC_hidden';
10310: }
10311: }
10312: }
10313: }
10314: var cutidxlist = document.cumulativeactions.allcutidx.value;
10315: if ((cutidxlist != '') && (cutidxlist != null)) {
10316: var cutidxs = cutidxlist.split(',');
10317: for (var i=0; i<cutidxs.length; i++) {
10318: if (document.getElementById('cut_'+cutidxs[i])) {
10319: var item = document.getElementById('cut_'+cutidxs[i]);
10320: if (value == 1) {
10321: item.className = 'LC_docs_cut';
10322: } else {
10323: item.className = 'LC_hidden';
10324: }
10325: }
1.537 raeburn 10326: }
10327: }
1.538 raeburn 10328: var copyidxlist = document.cumulativeactions.allcopyidx.value;
10329: if ((copyidxlist != '') && (copyidxlist != null)) {
10330: var copyidxs = copyidxlist.split(',');
10331: for (var i=0; i<copyidxs.length; i++) {
10332: if (document.getElementById('copy_'+copyidxs[i])) {
10333: var item = document.getElementById('copy_'+copyidxs[i]);
10334: if (value == 1) {
10335: item.className = 'LC_docs_copy';
10336: } else {
10337: item.className = 'LC_hidden';
10338: }
10339: }
1.537 raeburn 10340: }
10341: }
10342: return;
10343: }
10344:
1.606 raeburn 10345: function validImportCrsRes() {
10346: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
10347: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
10348: if ((fname == '') || (fname == null)) {
10349: alert("$js_lt{'nofi'}");
10350: return false;
10351: }
10352: var url = '/res/$coursedom/$coursenum/';
10353: if (path && path != '/') {
10354: url += path+'/';
10355: }
10356: if (fname != '') {
10357: url += fname;
10358: }
10359: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 10360: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 10361: return true;
10362: }
10363:
10364: function validateNewRes(caller) {
10365: if (caller == 'single') {
10366: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
10367: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
10368: var resname = document.courseresform.newresourcename.value;
10369: }
10370: }
10371:
1.611 raeburn 10372: ENDSCRIPT
1.329 droeschl 10373: }
1.457 raeburn 10374:
1.483 raeburn 10375: sub history_tab_js {
10376: return <<"ENDHIST";
10377: function toggleHistoryDisp(choice) {
10378: document.docslogform.docslog.value = choice;
10379: document.docslogform.submit();
10380: return;
10381: }
10382:
10383: ENDHIST
10384: }
10385:
1.484 raeburn 10386: sub inject_data_js {
10387: return <<ENDINJECT;
10388:
10389: function injectData(current, hiddenField, name, value) {
10390: currentElement = document.getElementById(hiddenField);
10391: currentElement.name = name;
10392: currentElement.value = value;
10393: current.submit();
10394: }
10395:
10396: ENDINJECT
10397: }
10398:
10399: sub dump_switchserver_js {
10400: my @hosts = @_;
1.594 damieng 10401: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 10402: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 10403: swit => 'Switch server?',
1.594 damieng 10404: );
10405: my %html_js_lt = &Apache::lonlocal::texthash(
10406: swit => 'Switch server?',
1.709 raeburn 10407: duco => 'Copying uploaded content to Authoring Space',
1.484 raeburn 10408: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
10409: chos => 'Choose server',
10410: );
1.594 damieng 10411: &js_escape(\%js_lt);
10412: &html_escape(\%html_js_lt);
10413: &js_escape(\%html_js_lt);
1.484 raeburn 10414: my $role = $env{'request.role'};
10415: my $js = <<"ENDSWJS";
10416: <script type="text/javascript">
10417: function write_switchserver() {
10418: var server;
10419: if (document.setserver.posshosts.length > 0) {
10420: for (var i=0; i<document.setserver.posshosts.length; i++) {
10421: if (document.setserver.posshosts[i].checked) {
10422: server = document.setserver.posshosts[i].value;
10423: }
10424: }
10425: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
10426: }
10427: window.close();
10428: }
10429: </script>
10430:
10431: ENDSWJS
10432:
10433: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
10434: {'only_body' => 1,
10435: 'js_ready' => 1,});
10436: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
10437:
10438: my $hostpicker;
10439: my $count = 0;
10440: foreach my $host (sort(@hosts)) {
10441: my $checked;
10442: if ($count == 0) {
10443: $checked = ' checked="checked"';
10444: }
10445: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
10446: $host.'"'.$checked.' />'.$host.'</label> ';
10447: $count++;
10448: }
10449:
10450: return <<"ENDSWITCHJS";
10451:
10452: function dump_needs_switchserver(url) {
10453: if (url!='' && url!= null) {
1.594 damieng 10454: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 10455: go(url);
10456: }
10457: }
10458: return;
10459: }
10460:
10461: function choose_switchserver_window() {
10462: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
10463: newWindow.document.open();
10464: newWindow.document.writeln('$startpage');
1.594 damieng 10465: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
10466: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
10467: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 10468: '<form name="setserver" method="post" action="" \\/>\\n'+
10469: '$hostpicker\\n'+
10470: '<br \\/><br \\/>\\n'+
1.594 damieng 10471: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 10472: 'onclick="write_switchserver();" \\/>\\n'+
10473: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
10474: newWindow.document.writeln('$endpage');
10475: newWindow.document.close();
10476: newWindow.focus();
10477: }
10478:
10479: ENDSWITCHJS
10480: }
10481:
10482: sub makedocslogform {
10483: my ($formelems,$docslog) = @_;
10484: return <<"LOGSFORM";
10485: <form action="/adm/coursedocs" method="post" name="docslogform">
10486: <input type="hidden" name="docslog" value="$docslog" />
10487: $formelems
10488: </form>
10489: LOGSFORM
10490: }
10491:
10492: sub makesimpleeditform {
10493: my ($formelems) = @_;
10494: return <<"SIMPFORM";
10495: <form name="simpleedit" method="post" action="/adm/coursedocs">
10496: <input type="hidden" name="importdetail" value="" />
10497: $formelems
10498: </form>
10499: SIMPFORM
10500: }
10501:
1.606 raeburn 10502: sub makenewproblem {
10503: my ($r,$coursedom,$coursenum) = @_;
10504: # Creating a new problem
10505: my ($redirect,$error);
10506: if ($env{'form.authorrole'}) {
10507: my ($newsubdir,$filename);
10508: if ($env{'form.newsubdir'}) {
10509: if ($env{'form.newsubdirname'} ne '') {
10510: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 10511: }
1.606 raeburn 10512: }
10513: if ($env{'form.newresourcename'}) {
10514: $filename = $env{'form.newresourcename'};
10515: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
10516: $filename =~ s/`//g;
10517: $filename =~ s{/\.\./}{_}g;
10518: $filename =~ s/\.+/./g;
10519: $filename =~ s{/+}{_}g;
10520: if ($filename ne '') {
10521: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
10522: if (($ext) && ($ext ne '.problem')) {
10523: $filename = $name.'.problem';
10524: } elsif ($ext eq '') {
10525: $filename .= '.problem';
10526: }
10527: my $docroot = $r->dir_config('lonDocRoot');
10528: my @ids=&Apache::lonnet::current_machine_ids();
10529: if ($env{'form.authorrole'} eq 'author') {
10530: if ($env{'user.author'}) {
10531: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
10532: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
10533: my $path = $docroot.$url;
10534: my $subdir = $env{'form.authorpath'};
10535: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10536: }
10537: }
10538: } elsif ($env{'form.authorrole'} eq 'course') {
10539: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
10540: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
10541: my $url = "/priv/$coursedom/$coursenum";
10542: my $path=$docroot.$url;
10543: my $subdir = $env{'form.authorpath'};
10544: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10545: if ($redirect) {
10546: my $rightsfile = 'default.rights';
10547: my $sourcerights = "$path/$rightsfile";
1.709 raeburn 10548: &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom);
1.606 raeburn 10549: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
1.654 raeburn 10550: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
10551: if (!-e "$docroot/res/$coursedom") {
10552: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 10553: }
1.654 raeburn 10554: if (!-e "$docroot/res/$coursedom/$coursenum") {
10555: mkdir("$docroot/res/$coursedom/$coursenum",0755);
10556: }
10557: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
10558: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
10559: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 10560: }
10561: }
1.654 raeburn 10562: my $source = $docroot.$redirect;
10563: if (!-e "$source.meta") {
10564: my $cid = $coursedom.'_'.$coursenum;
10565: my $now = time;
10566: if (open(my $fh,">$source.meta")) {
10567: my $author=$env{'environment.firstname'}.' '.
10568: $env{'environment.middlename'}.' '.
10569: $env{'environment.lastname'}.' '.
10570: $env{'environment.generation'};
10571: $author =~ s/\s+$//;
10572: my $title = $env{'form.newresourcetitle'};
10573: $title =~ s/^\s+|\s+$//g;
10574: print $fh <<END;
1.606 raeburn 10575:
10576: <abstract></abstract>
10577: <author>$author</author>
10578: <authorspace>$coursenum:$coursedom</authorspace>
10579: <copyright>custom</copyright>
10580: <creationdate>$now</creationdate>
10581: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
10582: <dependencies></dependencies>
10583: <domain>$coursedom</domain>
10584: <highestgradelevel>0</highestgradelevel>
10585: <keywords></keywords>
10586: <language>notset </language>
10587: <lastrevisiondate>$now</lastrevisiondate>
10588: <lowestgradelevel>0</lowestgradelevel>
10589: <mime>problem</mime>
10590: <modifyinguser>$coursenum:$coursedom</modifyinguser>
10591: <notes></notes>
10592: <obsolete></obsolete>
10593: <obsoletereplacement></obsoletereplacement>
10594: <owner>$coursenum:$coursedom</owner>
10595: <sourceavail></sourceavail>
10596: <standards></standards>
10597: <subject></subject>
10598: <title>$title</title>
10599: END
1.654 raeburn 10600: close($fh);
1.606 raeburn 10601: }
10602: }
10603: }
10604: }
10605: } else {
10606: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
10607: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
10608: if (grep(/^\Q$rolehome\E$/,@ids)) {
10609: my $now = time;
10610: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
10611: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
10612: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
10613: my $url = "/priv/$audom/$auname";
10614: my $path = $r->dir_config('lonDocRoot').$url;
10615: my $subdir = $env{'form.authorpath'};
10616: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10617: }
10618: }
10619: }
10620: }
10621: }
10622: }
10623: }
10624: return ($redirect,$error);
10625: }
10626:
10627: sub finishnewprob {
1.654 raeburn 10628: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 10629: unless (-d $path) {
10630: unless (mkdir($path,02770)) {
10631: return;
10632: }
10633: }
1.606 raeburn 10634: my $redirect;
10635: if ($subdir ne '/') {
10636: $subdir = &cleandir($subdir);
10637: if (($subdir ne '') && (-d "$path/$subdir")) {
10638: $path .= "/$subdir";
10639: $url .= "/$subdir";
10640: }
10641: }
10642: my $dest;
10643: if ($newsubdir ne '') {
10644: $newsubdir = &cleandir($newsubdir);
10645: }
10646: if ($newsubdir ne '') {
10647: if (-d "$path/$newsubdir") {
10648: $dest = "$path/$newsubdir/$filename";
10649: } else {
10650: my $dirok;
10651: unless (-e "$path/$newsubdir") {
10652: if (mkdir("$path/$newsubdir",02770)) {
10653: if (chmod(02770,"$path/$newsubdir")) {
10654: $dirok = 1;
10655: }
10656: }
10657: }
10658: if ($dirok) {
10659: $dest = "$path/$newsubdir/$filename";
10660: }
10661: }
10662: if (($dest ne '') && (!-e $dest)) {
10663: $redirect = "$url/$newsubdir/$filename";
10664: }
10665: } else {
10666: $dest = "$path/$filename";
10667: if (($dest ne '') && (!-e $dest)) {
10668: $redirect = "$url/$filename";
10669: }
10670: }
1.654 raeburn 10671: if ((!-e $dest) && ($context ne 'upload')) {
10672: my $template = $env{'form.template'};
10673: my $copyfrom;
10674: if ($template ne '') {
10675: my %templates;
10676: my @files = &Apache::lonhomework::get_template_list('problem');
10677: foreach my $poss (@files) {
10678: if (ref($poss) eq 'ARRAY') {
10679: if ($template eq $poss->[0]) {
10680: $templates{$template} = 1;
10681: last;
10682: }
10683: }
10684: }
10685: if ($templates{$template}) {
10686: $copyfrom = $template;
10687: }
10688: }
10689: if ($filename =~ /\.problem$/) {
10690: unless ($copyfrom) {
10691: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
10692: }
10693: &File::Copy::copy($copyfrom,$dest);
10694: }
10695: }
1.606 raeburn 10696: return $redirect;
10697: }
10698:
10699: sub cleandir {
10700: my ($dir) = @_;
10701: $dir =~ s/^\s+//;
10702: $dir =~ s/\s+$//;
10703: $dir =~ s/\.+//g;
10704: $dir =~ s/[\#\?&%\":]//g;
10705: return $dir;
10706: }
10707:
1.329 droeschl 10708: 1;
10709: __END__
10710:
10711:
10712: =head1 NAME
10713:
10714: Apache::londocs.pm
10715:
10716: =head1 SYNOPSIS
10717:
10718: This is part of the LearningOnline Network with CAPA project
10719: described at http://www.lon-capa.org.
10720:
10721: =head1 SUBROUTINES
10722:
10723: =over
10724:
10725: =item %help=()
10726:
10727: Available help topics
10728:
10729: =item mapread()
10730:
1.344 bisitz 10731: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 10732: @order and @resources, determines status
10733: sets @order - pointer to resources in right order
10734: sets @resources - array with the resources with correct idx
10735:
10736: =item authorhosts()
10737:
10738: Return hash with valid author names
10739:
10740: =item clean()
10741:
10742: =item dumpcourse()
10743:
10744: Actually dump course
10745:
10746: =item group_import()
10747:
10748: Imports the given (name, url) resources into the course
10749: coursenum, coursedom, and folder must precede the list
10750:
10751: =item breadcrumbs()
10752:
10753: =item log_docs()
10754:
10755: =item docs_change_log()
10756:
10757: =item update_paste_buffer()
10758:
10759: =item print_paste_buffer()
10760:
10761: =item do_paste_from_buffer()
10762:
1.538 raeburn 10763: =item do_buffer_empty()
10764:
10765: =item clear_from_buffer()
10766:
1.492 raeburn 10767: =item get_newmap_url()
10768:
10769: =item dbcopy()
10770:
10771: =item uniqueness_check()
10772:
10773: =item contained_map_check()
10774:
10775: =item url_paste_fixups()
10776:
10777: =item apply_fixups()
10778:
10779: =item copy_dependencies()
10780:
1.329 droeschl 10781: =item update_parameter()
10782:
10783: =item handle_edit_cmd()
10784:
10785: =item editor()
10786:
10787: =item process_file_upload()
10788:
10789: =item process_secondary_uploads()
10790:
10791: =item is_supplemental_title()
10792:
10793: =item entryline()
10794:
10795: =item tiehash()
10796:
10797: =item untiehash()
10798:
10799: =item checkonthis()
10800:
10801: check on this
10802:
10803: =item verifycontent()
10804:
10805: Verify Content
10806:
1.636 raeburn 10807: =item devalidateversioncache()
10808:
10809: =item checkversions()
1.329 droeschl 10810:
10811: Check Versions
10812:
10813: =item mark_hash_old()
10814:
10815: =item is_hash_old()
10816:
10817: =item changewarning()
10818:
10819: =item init_breadcrumbs()
10820:
10821: Breadcrumbs for special functions
10822:
1.484 raeburn 10823: =item create_list_elements()
10824:
10825: =item create_form_ul()
10826:
10827: =item startContentScreen()
10828:
10829: =item endContentScreen()
10830:
10831: =item supplemental_base()
10832:
10833: =item embedded_form_elems()
10834:
10835: =item embedded_destination()
10836:
10837: =item return_to_editor()
10838:
10839: =item decompression_info()
10840:
10841: =item decompression_phase_one()
10842:
10843: =item decompression_phase_two()
10844:
10845: =item remove_archive()
10846:
10847: =item generate_admin_menu()
10848:
10849: =item generate_edit_table()
10850:
10851: =item editing_js()
10852:
10853: =item history_tab_js()
10854:
10855: =item inject_data_js()
10856:
10857: =item dump_switchserver_js()
10858:
1.485 raeburn 10859: =item resize_scrollbox_js()
1.484 raeburn 10860:
10861: =item makedocslogform()
10862:
1.485 raeburn 10863: =item makesimpleeditform()
10864:
1.329 droeschl 10865: =back
10866:
10867: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>