Annotation of loncom/interface/londocs.pm, revision 1.728
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.728 ! raeburn 4: # $Id: londocs.pm,v 1.727 2025/03/15 01:03:33 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.722 raeburn 1180: foreach my $file (keys(%newfile)) {
1181: my %storehash = (
1182: 'priv' => $newfile{$file},
1.719 raeburn 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;
1.721 raeburn 1280: #
1281: # Warning to developers:
1282: #
1283: # If you add or remove form elements which precede the table of items to copy
1284: # you will need to modify the value for startcount. Form elements include both:
1285: # <input> and <fieldset> tags.
1286: # $startcount (set to 9) contains the following:
1287: # fieldsets with following legends: (a) Folder in Authoring Space, (b) Distribution to set in metadata
1288: # (c) Content to copy
1289: # inputs: textbox for destination folder; dropdown lists: (a) Copyright, (b) Source
1290: # hidden: customrights file; buttons: (a) check all, (b) uncheck all.
1291: # authorspace: if more than 1: a fieldset with legend: Select the Authoring Space,
1292: # or if 1: an input (hidden) with available author/coauthor role.
1293: # if there are multiple possible author/coauthor roles (i.e., $home > 1),
1294: # incerement startcount by 1 for the dropdown list uses to select the target.
1295: #
1296: # If there are published files, increment startcount by 3:
1297: # fieldset (legend: Published Resources), and two radio buttons (Yes/No).
1298: #
1299: my $startcount = 9;
1300: if ($home > 1) {
1301: $startcount ++;
1302: }
1303: if ($numpub) {
1304: $startcount += 3;
1305: }
1.712 raeburn 1306: my $lastcontainer = $startcount;
1307: $display .= &Apache::loncommon::start_data_table()."\n".
1308: &Apache::loncommon::start_data_table_header_row().
1309: '<th>'.&mt('Copy?').'</th>'.
1.714 raeburn 1310: '<th>'.&mt('Name').'</th>'.
1311: '<th>'.&mt('Last modified').'</th>'.
1312: '<th>'.&mt('Published?').'</th>'.
1.712 raeburn 1313: &Apache::loncommon::end_data_table_header_row()."\n";
1314: $count = &recurse_crsauthored(0,\@dirs_by_depth,\@files_by_depth,'/',$startcount,
1315: $count,\$display,\%parent,\%children,$readonly,
1.714 raeburn 1316: $formname,$chkname,\$lastcontainer,\%resfiles);
1.712 raeburn 1317: $display .= &Apache::loncommon::end_data_table().'</fieldset>';
1318: unless ($readonly) {
1319: $display .= '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
1320: '<div>'.
1321: '<input type="submit" name="copyauthored" value="'.&mt("Copy Selected Content").'" />'.
1322: '</div>';
1323: }
1324: $display .= &Apache::loncourserespicker::respicker_javascript($startcount,$count,$context,$formname,\%children,
1325: \%hierarchy,\@checked_maps,$home,$chkname);
1326: $r->print($display);
1327: }
1328: $r->print(&endContentScreen());
1329: }
1330:
1331: sub recurse_crsauthored {
1332: my ($currdepth,$dirs_by_depth,$files_by_depth,$currpath,$startcount,$count,$displayref,
1.714 raeburn 1333: $parent,$children,$readonly,$formname,$chkname,$lastcontainerref,$resfilesref) = @_;
1334: return $count unless ((ref($dirs_by_depth) eq 'ARRAY') && (ref($files_by_depth) eq 'ARRAY') &&
1335: (ref($resfilesref) eq 'HASH'));
1.712 raeburn 1336: my ($disabled,$hasdirs,$hasfiles,%unique,%dirs,%files);
1337: if ((ref($dirs_by_depth->[$currdepth]) eq 'HASH') &&
1338: (ref($dirs_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1339: $hasdirs = 1;
1340: %dirs = %{$dirs_by_depth->[$currdepth]{$currpath}};
1341: map { $unique{$_} = 1; } keys(%dirs);
1342: }
1343: if ((ref($files_by_depth->[$currdepth]) eq 'HASH') &&
1344: (ref($files_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1345: $hasfiles = 1;
1346: %files = %{$files_by_depth->[$currdepth]{$currpath}};
1347: map { $unique{$_} = 1; } keys(%files);
1348: }
1349: if ($readonly) {
1350: $disabled = ' disabled="disabled"';
1351: }
1352: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
1353: my $whitespace =
1354: '<img src="'.$location.'/whitespace_21.gif" class="LC_docs_spacer" alt="" />';
1355: $parent->{$currdepth} = $$lastcontainerref;
1356: foreach my $item (sort { lc($a) cmp lc($b) } (keys(%unique))) {
1357: next if ($item eq '');
1358: my $currelem;
1359: if ($hasdirs && exists($dirs{$item})) {
1360: $count ++;
1361: my $deeper = $currdepth+1;
1362: my ($newpath,$showpath);
1363: if ($currpath eq '/') {
1364: $newpath = $item;
1365: $showpath = $currpath.$item.'/';
1366: } else {
1367: $newpath = $currpath.'/'.$item;
1368: $showpath = '/'.$currpath.'/'.$item.'/';
1369: }
1370: $currelem = $count+$startcount;
1371: $$lastcontainerref = $currelem;
1372: $children->{$parent->{$currdepth}} .= $currelem.':';
1373: my $icon = 'src="'.$location.'/navmap.folder.open.gif" alt="'.&mt('Folder').'"';
1374: $$displayref .= &Apache::loncommon::start_data_table_row().
1375: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath).'" '.
1376: 'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" '.
1377: $disabled.' /></td><td>';
1378: for (my $i=0; $i<$currdepth; $i++) {
1379: $$displayref .= "$whitespace\n";
1380: }
1.714 raeburn 1381: $$displayref .= '<img '.$icon.' /> '.$item.'</td><td> </td><td> </td>'.
1.712 raeburn 1382: &Apache::loncommon::end_data_table_row()."\n";
1383: $count = &recurse_crsauthored($deeper,$dirs_by_depth,$files_by_depth,$newpath,
1384: $startcount,$count,$displayref,$parent,$children,
1.714 raeburn 1385: $readonly,$formname,$chkname,$lastcontainerref,$resfilesref);
1.712 raeburn 1386: }
1387: if ($hasfiles && exists($files{$item})) {
1388: $count ++;
1389: $currelem = $count+$startcount;
1390: $children->{$parent->{$currdepth}} .= $currelem.':';
1391: my $icon = 'src="'.&Apache::loncommon::icon($item).'"';
1392: my ($ext) = ($item =~ /\.([^.]+)$/);
1393: my $alttext;
1394: if (lc($ext) eq 'problem') {
1395: $alttext = ' alt="'.&mt('Problem Icon').'"';
1396: } elsif ($ext =~ /^x?html?$/i) {
1397: $alttext = ' alt="'.&mt('Web Page Icon').'"';
1398: } elsif ($ext =~ /^(jpg|gif|png|svg|jpeg)$/) {
1399: $alttext = ' alt="'.&mt('Image Icon').'"';
1400: } else {
1401: $alttext = ' alt="'.&mt('Resource Icon').'"';
1402: }
1403: my $showpath;
1404: if ($currpath eq '/') {
1405: $showpath = $currpath;
1406: } else {
1407: $showpath = "/$currpath/";
1408: }
1.714 raeburn 1409: my ($published,$lastmod);
1410: if ((ref($resfilesref->{$currpath})) && (exists($resfilesref->{$currpath}{$item}))) {
1411: $published = '<img src="'.$location.'/navmap.correct.gif" alt="'.&mt('yes').'" />';
1412: } else {
1413: $published = '<img src="'.$location.'/navmap.wrong.gif" alt="'.&mt('no').'" />';
1414: }
1.712 raeburn 1415: $$displayref .= &Apache::loncommon::start_data_table_row().
1416: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath.$item).'" '.
1417: 'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" '.
1418: $disabled.' /></td><td>';
1419: for (my $i=0; $i<$currdepth; $i++) {
1420: $$displayref .= "$whitespace\n";
1421: }
1422: $$displayref .= '<img '.$icon.$alttext.' /> '.$item.'</td>'.
1.714 raeburn 1423: '<td>'.&Apache::lonlocal::locallocaltime($files{$item}).'</td>'.
1424: '<td style="text-align: center;">'.$published.'</td>'.
1.712 raeburn 1425: &Apache::loncommon::end_data_table_row()."\n";
1426: }
1427: }
1428: $$lastcontainerref = $parent->{$currdepth};
1429: return $count;
1430: }
1431:
1.715 raeburn 1432: sub courseresource_options {
1433: my ($formname,$numpub) = @_;
1434: my %lt = &Apache::lonlocal::texthash(
1435: 'default' => 'System wide - can be used for any courses system wide',
1436: 'domain' => 'Domain only - use limited to courses in the domain',
1437: 'custom' => 'Customized right of use ...',
1438: 'public' => 'Public - no authentication or authorization required for use',
1439: 'closed' => 'Closed - XML source is closed to everyone',
1440: 'open' => 'Open - XML source is open to people who want to use it',
1441: 'sel' => 'Select',
1442: );
1443: my $output;
1444: if ($numpub) {
1445: $output .= '<div class="LC_left_float">'.
1446: '<fieldset><legend>'.&mt('Published Resources').'</legend>'.
1447: &mt('[quant,_1,file] in Course Authoring Space also exist in Resource Space.',
1448: $numpub).'</br />'.
1449: &mt('Publish copied files in selected Authoring Space?').': '."\n".
1450: '<label><input type="radio" name="respublish" checked="checked" value="1" />'.
1451: &mt('Yes').'</label>'."\n".
1452: '<label><input type="radio" name="respublish" value="0" />'.
1453: &mt('No').'</label>'."\n".
1454: '</fieldset></div>'."\n";
1455: }
1456: $output .= '<div class="LC_left_float">'.
1457: '<fieldset><legend>'.&mt('Distribution to set in metadata').'</legend>'.
1458: &mt('Copyright').': '.
1459: '<select name="copyright" onchange="showHideCustom(this,'."'LC_customfile'".');">'."\n".
1460: '<option value="default" selected="selected">'.$lt{'default'}.'</option>'."\n".
1461: '<option value="domain">'.$lt{'domain'}.'</option>'."\n".
1462: '<option value="public">'.$lt{'public'}.'</option>'."\n".
1463: '<option value="custom">'.$lt{'custom'}.'</option>'."\n".
1464: '</select><div id="LC_customfile" style="padding:0;clear:both;margin:0;border:0;display:none">'."\n".
1465: '<input type="text" name="customrights" size="60" value="" />'.
1466: '<a href="javascript:openbrowser('."'$formname','customrights','rights'".');">'.
1467: $lt{'sel'}.'</a></div><br />'."\n".
1468: &mt('Source').' :'.
1469: '<select name="sourceavail">'."\n".
1470: '<option value="closed" selected="selected">'.$lt{'closed'}.'</option>'."\n".
1471: '<option value="open">'.$lt{'open'}.'</option>'."\n".
1472: '</select><br />'."\n".
1473: '</fieldset></div>'."\n";
1474: return $output;
1475: }
1476:
1.717 raeburn 1477: sub crsres_fixup_meta {
1478: my ($dest,$coursenum,$coursedom,$ca,$cd,$copyright,$customdistfile,$sourceavail,$checkdeps) = @_;
1479: return unless (ref($checkdeps) eq 'HASH');
1480: if (open(my $fh,'<',$dest.'.meta')) {
1481: my ($output,$now,$setsourceavail);
1482: $now = time;
1483: if (($dest =~ /\.(xml|html|htm|xhtml|xhtm)$/i) || ($dest =~ /$LONCAPA::assess_re/)) {
1484: $setsourceavail = 1;
1485: }
1486: while (my $line=<$fh>) {
1487: chomp($line);
1488: if ($line eq "<authorspace>$coursenum:$coursedom</authorspace>") {
1489: $output .= "<authorspace>$ca:$cd</authorspace>\n";
1490: } elsif ($line eq '<copyright>custom</copyright>') {
1491: $output .= "<copyright>$copyright</copyright>\n";
1492: } elsif ($line =~ m{^<creationdate>\d+</creationdate>$}) {
1493: $output .= "<creationdate>$now</creationdate>\n";
1494: } elsif ($line eq "<customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>") {
1495: $output .= "<customdistributionfile>$customdistfile</customdistributionfile>\n";
1496: } elsif ($line =~ m{^<sourceavail>(open|closed)</sourceavail>$}) {
1497: if ($setsourceavail) {
1498: $output .= "<sourceavail>$sourceavail</sourceavail>\n";
1499: }
1500: } elsif ($line eq "<domain>$coursedom</domain>") {
1501: $output .= "<domain>$cd</domain>\n";
1502: } elsif ($line =~ m{^<lastrevisiondate>\d+</lastrevisiondate>$}) {
1503: $output .= "<lastrevisiondate>$now</lastrevisiondate>\n";
1504: } elsif ($line =~ m{^<modifyinguser>$match_username:$match_domain</modifyinguser>$}) {
1505: $output .= "<modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>\n";
1506: } elsif ($line eq "<owner>$coursenum:$coursedom</owner>") {
1507: $output .= "<owner>$ca:$cd</owner>\n";
1508: } elsif ($line =~ m{^<dependencies>(.+)</dependencies>$}) {
1509: my @deps = split(/\s*,\s*/,$1);
1510: my @newdeps;
1511: my $changed = 0;
1512: foreach my $dep (@deps) {
1513: if ($dep =~ m{^/res/$coursedom/$coursenum/(.+)$}) {
1514: my $rest = $1;
1515: push(@newdeps,"/res/$cd/$ca/$rest");
1516: $checkdeps->{$rest} = 1;
1517: $changed ++;
1518: } else {
1519: push(@newdeps,$dep);
1520: }
1521: }
1522: if ($changed) {
1523: $output .= '<dependencies>'.join(',',@newdeps).'</dependencies>'."\n";
1524: }
1525: } else {
1526: $output .= "$line\n";
1527: }
1528: }
1529: close($fh);
1530: if (open(my $fh,'>',$dest.'.meta')) {
1531: print $fh $output;
1532: close($fh);
1533: }
1534: }
1535: }
1536:
1537: sub crsres_fixup {
1538: my ($dest,$coursenum,$coursedom,$ca,$cd,$subdir) = @_;
1539: my $outstring='';
1540: my $changes = 0;
1541: my @parser;
1542: $parser[0]=HTML::LCParser->new($dest);
1543: $parser[-1]->xml_mode(1);
1544: my $token;
1545: while (@parser) {
1546: while ($token=$parser[-1]->get_token) {
1547: if ($token->[0] eq 'S') {
1548: my $tag=$token->[1];
1549: my $lctag=lc($tag);
1550: my %parms=%{$token->[2]};
1551: foreach my $type ('src','href','background','bgimg') {
1552: foreach my $key (keys(%parms)) {
1553: if ($key =~ /^$type$/i) {
1554: next if (($lctag eq 'img') && ($type eq 'src') &&
1555: ($parms{$key} =~ m{^data\:image/gif;base64,}));
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: }
1561: }
1562: }
1563: # probably a <randomlabel> image type <label>
1564: # or a <image> tag inside <imageresponse> or <drawimage>
1565: if (($lctag eq 'label' && defined($parms{'description'}))
1566: || ($lctag eq 'image') || ($lctag eq 'import')) {
1567: my $next_token=$parser[-1]->get_token();
1568: if ($next_token->[0] eq 'T') {
1569: $next_token->[1] =~ s/[\n\r\f]+//g;
1570: if ($next_token->[1] =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1571: $next_token->[1] =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
1572: $changes ++;
1573: }
1574: }
1575: $parser[-1]->unget_token($next_token);
1576: }
1577: if ($lctag eq 'applet') {
1578: my $havecodebase=0;
1579: foreach my $key (keys(%parms)) {
1580: if (lc($key) eq 'codebase') {
1581: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1582: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
1583: $changes ++;
1584: }
1585: $havecodebase = 1;
1586: }
1587: }
1588: unless ($havecodebase) {
1589: foreach my $key (keys(%parms)) {
1590: if ($key =~ /(archive|code|object)/i) {
1591: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1592: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/si};
1593: $changes ++;
1594: }
1595: }
1596: }
1597: }
1598: }
1599: my $newparmstring='';
1600: my $endtag='';
1601: foreach my $parkey (keys(%parms)) {
1602: if ($parkey eq '/') {
1603: $endtag=' /';
1604: } else {
1605: my $quote=($parms{$parkey}=~/\"/?"'":'"');
1606: $newparmstring.=' '.$parkey.'='.$quote.$parms{$parkey}.$quote;
1607: }
1608: }
1609: if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
1610: $outstring.='<'.$tag.$newparmstring.$endtag.'>';
1611: if ($lctag eq 'm' || $lctag eq 'answer' || $lctag eq 'display' ||
1612: $lctag eq 'tex') {
1613: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
1614: } elsif ($lctag eq 'script') {
1615: if ($parms{'type'} eq 'loncapa/perl') {
1616: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
1617: } else {
1618: my $needsupdate;
1619: my $script = &Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
1620: if ($script =~ m{\.addMediaSrc\((["'])((?!\1).+)\1\);}) {
1621: my $src = $2;
1622: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1623: $needsupdate = 1;
1624: }
1625: }
1626: if ($script =~ /\(document,\s*(['"])script\1,\s*\[([^\]]+)\]\);/s) {
1627: my $scriptslist = $2;
1628: my @srcs = split(/\s*,\s*/,$scriptslist);
1629: foreach my $src (@srcs) {
1630: if ($src =~ /(["'])(?:(?!\1).)+\.js\1/) {
1631: my $quote = $1;
1632: my ($url) = ($src =~ m/\Q$quote\E([^$quote]+)\Q$quote\E/);
1633: if ($url =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1634: $needsupdate = 1;
1635: }
1636: }
1637: }
1638: }
1639: if ($script =~ m{loadScript\(\s*(['"])((?:(?!\1).)+\.js)\1,\s*function}is) {
1640: my $src = $2;
1641: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1642: $needsupdate = 1;
1643: }
1644: }
1645: if ($needsupdate) {
1646: $script =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/gsi};
1647: $changes ++;
1648: }
1649: $outstring .= $script;
1650: }
1651: }
1652: } elsif ($token->[0] eq 'E') {
1653: if ($token->[2]) {
1654: unless ($token->[1] eq 'allow') {
1655: $outstring.='</'.$token->[1].'>';
1656: }
1657: }
1658: } else {
1659: $outstring.=$token->[1];
1660: }
1661: }
1662: pop(@parser);
1663: }
1664: if ($changes) {
1665: if (open(my $fh,'>',$dest)) {
1666: print $fh $outstring;
1667: close($fh);
1668: }
1669: }
1670: }
1671:
1.329 droeschl 1672: sub group_import {
1.598 raeburn 1673: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 1674: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
1675: %removeparam,$importuploaded,$fixuperrors);
1676: $allmaps = {};
1.329 droeschl 1677: while (@files) {
1678: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 1679: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 1680: && ($caller eq 'londocs')
1681: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 1682:
1.329 droeschl 1683: my $errtext = '';
1684: my $fatal = 0;
1685: my $newmapstr = '<map>'."\n".
1686: '<resource id="1" src="" type="start"></resource>'."\n".
1687: '<link from="1" to="2" index="1"></link>'."\n".
1688: '<resource id="2" src="" type="finish"></resource>'."\n".
1689: '</map>';
1690: $env{'form.output'}=$newmapstr;
1691: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1692: 'output',$1.$2);
1.534 raeburn 1693: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 1694: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
1695: $fatal = 2;
1696: }
1697: if ($fatal) {
1698: return ($errtext,$fatal);
1699: }
1700: }
1701: if ($url) {
1.626 raeburn 1702: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 1703: $url = $1;
1704: my $marker = $2;
1705: my $info = $3;
1.699 raeburn 1706: my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.728 ! raeburn 1707: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend','returnurl','backtourl','desturl','delay');
1.598 raeburn 1708: my @toolinfo = split(/:/,$info);
1709: if ($residx) {
1.604 raeburn 1710: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 1711: $toolid = $toolsettings{'id'};
1712: } else {
1.604 raeburn 1713: $toolid = shift(@toolinfo);
1.598 raeburn 1714: }
1.699 raeburn 1715: if ($toolid =~ /^c/) {
1716: $tooltype = 'crs';
1717: $toolprefix = 'c';
1718: } else {
1719: $tooltype = 'dom';
1720: }
1.598 raeburn 1721: $toolid =~ s/\D//g;
1.604 raeburn 1722: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 1723: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
1.727 raeburn 1724: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'},
1.728 ! raeburn 1725: $toolhash{'returnurl'},$toolhash{'backtourl'},$toolhash{'desturl'},
! 1726: $toolhash{'delay'}) = @toolinfo;
1.624 raeburn 1727: foreach my $item (@extras) {
1728: $toolhash{$item} = &unescape($toolhash{$item});
1729: }
1.728 ! raeburn 1730: foreach my $item ('crsappend','gradable','returnurl',
! 1731: 'backtourl','desturl','delay') {
! 1732: $toolhash{$item} =~ s/^\s+//;
! 1733: $toolhash{$item} =~ s/\s+$//;
! 1734: }
1.645 raeburn 1735: if ($folder =~ /^supplemental/) {
1.648 raeburn 1736: delete($toolhash{'gradable'});
1737: } else {
1738: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 1739: }
1.598 raeburn 1740: if (ref($ltitoolsref) eq 'HASH') {
1.699 raeburn 1741: if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
1742: if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
1743: my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
1744: my @deleted;
1745: $toolhash{'id'} = $toolprefix.$toolid;
1746: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
1747: ($toolhash{'target'} eq 'window')) {
1748: if ($toolhash{'target'} eq 'window') {
1749: foreach my $item ('width','height') {
1750: $toolhash{$item} =~ s/^\s+//;
1751: $toolhash{$item} =~ s/\s+$//;
1752: if ($toolhash{$item} =~ /\D/) {
1753: delete($toolhash{$item});
1754: if ($residx) {
1755: if ($toolsettings{$item}) {
1756: push(@deleted,$item);
1757: }
1.624 raeburn 1758: }
1759: }
1760: }
1.604 raeburn 1761: }
1.699 raeburn 1762: } elsif ($residx) {
1763: $toolhash{'target'} = $toolsettings{'target'};
1764: if ($toolhash{'target'} eq 'window') {
1765: foreach my $item ('width','height') {
1766: $toolhash{$item} = $toolsettings{$item};
1767: }
1768: }
1769: } elsif (ref($tools{'display'}) eq 'HASH') {
1770: $toolhash{'target'} = $tools{'display'}{'target'};
1771: if ($toolhash{'target'} eq 'window') {
1772: $toolhash{'width'} = $tools{'display'}{'width'};
1773: $toolhash{'height'} = $tools{'display'}{'height'};
1.624 raeburn 1774: }
1.604 raeburn 1775: }
1.699 raeburn 1776: if ($toolhash{'target'} eq 'iframe') {
1777: foreach my $item ('width','height','linktext','explanation') {
1778: delete($toolhash{$item});
1779: if ($residx) {
1780: if ($toolsettings{$item}) {
1781: push(@deleted,$item);
1782: }
1.624 raeburn 1783: }
1.604 raeburn 1784: }
1.699 raeburn 1785: } elsif ($toolhash{'target'} eq 'tab') {
1786: foreach my $item ('width','height') {
1787: delete($toolhash{$item});
1788: if ($residx) {
1789: if ($toolsettings{$item}) {
1790: push(@deleted,$item);
1791: }
1.628 raeburn 1792: }
1793: }
1794: }
1.728 ! raeburn 1795: my $nocrsdest = 1;
1.699 raeburn 1796: if (ref($tools{'crsconf'}) eq 'HASH') {
1797: foreach my $item ('label','title','linktext','explanation') {
1798: my $crsitem;
1799: if (($item eq 'label') || ($item eq 'title')) {
1800: $crsitem = 'crs'.$item;
1801: } else {
1802: $crsitem = $item;
1803: }
1804: if ($tools{'crsconf'}{$item}) {
1805: $toolhash{$crsitem} =~ s/^\s+//;
1806: $toolhash{$crsitem} =~ s/\s+$//;
1807: if ($toolhash{$crsitem} eq '') {
1808: delete($toolhash{$crsitem});
1809: }
1810: } else {
1.624 raeburn 1811: delete($toolhash{$crsitem});
1.604 raeburn 1812: }
1.699 raeburn 1813: if (($residx) && (exists($toolsettings{$crsitem}))) {
1814: unless (exists($toolhash{$crsitem})) {
1815: push(@deleted,$crsitem);
1816: }
1817: }
1.604 raeburn 1818: }
1.727 raeburn 1819: if ($tools{'crsconf'}{'returnurl'}) {
1820: unless ($toolhash{'returnurl'} eq 'custom') {
1821: delete($toolhash{'backtourl'});
1822: }
1823: } else {
1824: delete($toolhash{'returnurl'});
1825: delete($toolhash{'backtourl'});
1826: }
1.728 ! raeburn 1827: if ($tools{'crsconf'}{'desturl'}) {
! 1828: if ($toolhash{'desturl'} =~ m{^(https?\://|/)}) {
! 1829: undef($nocrsdest);
! 1830: } else {
! 1831: delete($toolhash{'desturl'});
! 1832: delete($toolhash{'delay'});
! 1833: }
! 1834: } else {
! 1835: delete($toolhash{'desturl'});
! 1836: delete($toolhash{'delay'});
! 1837: }
1.699 raeburn 1838: }
1839: if ($toolhash{'passback'}) {
1840: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1841: $toolhash{'gradesecret'} = $gradesecret;
1842: $toolhash{'gradesecretdate'} = time;
1843: }
1844: if ($toolhash{'roster'}) {
1845: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1846: $toolhash{'rostersecret'} = $rostersecret;
1847: $toolhash{'rostersecretdate'} = time;
1848: }
1.728 ! raeburn 1849: if ($nocrsdest) {
! 1850: foreach my $item ('desturl','delay') {
! 1851: if (exists($toolhash{$item})) {
! 1852: delete($toolhash{$item});
! 1853: }
! 1854: }
! 1855: } elsif (exists($toolhash{'delay'})) {
! 1856: unless ($toolhash{'delay'} =~ /^(\d+\.?\d*)$/) {
! 1857: delete($toolhash{'delay'});
! 1858: }
! 1859: }
1.699 raeburn 1860: my $changegradable;
1861: if (($residx) && ($folder =~ /^default/)) {
1862: if ($toolsettings{'gradable'}) {
1863: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1864: push(@deleted,'gradable');
1865: $changegradable = 1;
1.604 raeburn 1866: }
1.699 raeburn 1867: } elsif ($toolhash{'gradable'}) {
1868: $changegradable = 1;
1.604 raeburn 1869: }
1.699 raeburn 1870: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 1871: $changegradable = 1;
1.699 raeburn 1872: if ($toolsettings{'gradable'}) {
1873: $toolhash{'gradable'} = 1;
1874: }
1.645 raeburn 1875: }
1.648 raeburn 1876: }
1.727 raeburn 1877: if ($residx) {
1878: if (($toolsettings{'backtourl'} ne '') && (!exists($toolhash{'backtourl'}))) {
1879: push(@deleted,'backtourl');
1880: }
1881: if (($toolsettings{'returnurl'} ne '') && (!exists($toolhash{'returnurl'}))) {
1882: push(@deleted,'returnurl');
1883: }
1.728 ! raeburn 1884: if (($toolsettings{'desturl'} ne '') && (!exists($toolhash{'desturl'}))) {
! 1885: push(@deleted,'desturl');
! 1886: }
! 1887: if (($toolsettings{'delay'} ne '') && (!exists($toolhash{'delay'}))) {
! 1888: push(@deleted,'delay');
! 1889: }
1.727 raeburn 1890: }
1.699 raeburn 1891: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1892: if ($putres eq 'ok') {
1893: if (@deleted) {
1894: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648 raeburn 1895: }
1.699 raeburn 1896: if (($changegradable) && ($folder =~ /^default/)) {
1897: my $val;
1898: if ($toolhash{'gradable'}) {
1899: $val = 'yes';
1900: } else {
1901: $val = 'no';
1902: }
1903: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
1904: 'string_yesno');
1905: &remember_parms($residx,'gradable','set',$val);
1.645 raeburn 1906: }
1.699 raeburn 1907: } else {
1908: return (&mt('Failed to save update to external tool.'),1);
1.645 raeburn 1909: }
1.604 raeburn 1910: }
1.598 raeburn 1911: }
1912: }
1913: }
1.529 raeburn 1914: if (($caller eq 'londocs') &&
1915: ($folder =~ /^default/)) {
1.534 raeburn 1916: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 1917: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
1918: my $cid = $coursedom.'_'.$coursenum;
1919: $allmaps =
1920: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1921: $chome,$cid);
1922: $donechk = 1;
1923: }
1924: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 1925: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1926: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 1927: $importuploaded = 1;
1928: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
1929: next if ($allmaps->{$url});
1930: }
1931: }
1.344 bisitz 1932: if (!$residx
1.329 droeschl 1933: || defined($LONCAPA::map::zombies[$residx])) {
1934: $residx = &LONCAPA::map::getresidx($url,$residx);
1935: push(@LONCAPA::map::order, $residx);
1936: }
1937: my $ext = 'false';
1938: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 1939: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
1940: my $filepath = $1;
1.675 raeburn 1941: my $fname;
1942: if ($name eq '') {
1943: $name = &mt('Web Page');
1.534 raeburn 1944: $fname = 'web';
1945: } else {
1.675 raeburn 1946: $fname = $name;
1947: $fname=&Apache::lonnet::clean_filename($fname);
1948: if ($fname eq '') {
1949: $fname = 'web';
1950: } elsif (length($fname) > 15) {
1951: $fname = substr($fname,0,14);
1952: }
1.534 raeburn 1953: }
1.675 raeburn 1954: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 1955: my $initialtext = &mt('Replace with your own content.');
1956: my $newhtml = <<END;
1.545 raeburn 1957: <html>
1.534 raeburn 1958: <head>
1.675 raeburn 1959: <title>$title</title>
1.534 raeburn 1960: </head>
1961: <body bgcolor="#ffffff">
1962: $initialtext
1963: </body>
1964: </html>
1965: END
1966: $env{'form.output'}=$newhtml;
1.630 raeburn 1967: my $result =
1.534 raeburn 1968: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1969: 'output',
1970: "$filepath/$residx/$fname.html");
1971: if ($result =~ m{^/uploaded/}) {
1972: $url = $result;
1973: if ($filepath =~ /^supplemental/) {
1974: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1975: $env{'user.domain'}.'___&&&___'.$name;
1976: }
1977: } else {
1978: return (&mt('Failed to save new web page.'),1);
1979: }
1980: }
1.675 raeburn 1981: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 1982: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 1983: $LONCAPA::map::resources[$residx] =
1.329 droeschl 1984: join(':', ($name, $url, $ext, 'normal', 'res'));
1985: }
1986: }
1.529 raeburn 1987: if ($importuploaded) {
1988: my %import_errors;
1989: my %updated = (
1990: removefrommap => \%removefrommap,
1991: removeparam => \%removeparam,
1992: );
1.533 raeburn 1993: my ($result,$msgsarray,$lockerror) =
1994: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 1995: if (keys(%import_errors) > 0) {
1.530 raeburn 1996: $fixuperrors =
1.529 raeburn 1997: '<p span class="LC_warning">'."\n".
1998: &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".
1999: '<ul>'."\n";
2000: foreach my $key (sort(keys(%import_errors))) {
2001: $fixuperrors .= '<li>'.$key.'</li>'."\n";
2002: }
2003: $fixuperrors .= '</ul></p>'."\n";
2004: }
1.533 raeburn 2005: if (ref($msgsarray) eq 'ARRAY') {
2006: if (@{$msgsarray} > 0) {
2007: $fixuperrors .= '<p class="LC_info">'.
2008: join('<br />',@{$msgsarray}).
2009: '</p>';
2010: }
2011: }
2012: if ($lockerror) {
2013: $fixuperrors .= '<p class="LC_error">'.
2014: $lockerror.
2015: '</p>';
2016: }
1.529 raeburn 2017: }
2018: my ($errtext,$fatal) =
2019: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 2020: unless ($fatal) {
2021: if ($folder =~ /^supplemental/) {
1.561 raeburn 2022: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2023: $folder.'.'.$container);
1.557 raeburn 2024: }
2025: }
1.529 raeburn 2026: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 2027: }
2028:
2029: sub log_docs {
1.494 raeburn 2030: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 2031: }
2032:
2033: {
2034: my @oldresources=();
2035: my @oldorder=();
2036: my $parmidx;
2037: my %parmaction=();
2038: my %parmvalue=();
2039: my $changedflag;
2040:
2041: sub snapshotbefore {
2042: @oldresources=@LONCAPA::map::resources;
2043: @oldorder=@LONCAPA::map::order;
2044: $parmidx=undef;
2045: %parmaction=();
2046: %parmvalue=();
2047: $changedflag=0;
2048: }
2049:
2050: sub remember_parms {
2051: my ($idx,$parameter,$action,$value)=@_;
2052: $parmidx=$idx;
2053: $parmaction{$parameter}=$action;
2054: $parmvalue{$parameter}=$value;
2055: $changedflag=1;
2056: }
2057:
2058: sub log_differences {
2059: my ($plain)=@_;
2060: my %storehash=('folder' => $plain,
2061: 'currentfolder' => $env{'form.folder'});
2062: if ($parmidx) {
2063: $storehash{'parameter_res'}=$oldresources[$parmidx];
2064: foreach my $parm (keys(%parmaction)) {
2065: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
2066: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
2067: }
2068: }
2069: my $maxidx=$#oldresources;
2070: if ($#LONCAPA::map::resources>$#oldresources) {
2071: $maxidx=$#LONCAPA::map::resources;
2072: }
2073: for (my $idx=0; $idx<=$maxidx; $idx++) {
2074: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
2075: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
2076: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
2077: $changedflag=1;
2078: }
2079: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
2080: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
2081: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2082: $changedflag=1;
2083: }
2084: }
2085: $storehash{'maxidx'}=$maxidx;
2086: if ($changedflag) { &log_docs(\%storehash); }
2087: }
2088: }
2089:
2090: sub docs_change_log {
1.611 raeburn 2091: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 2092: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 2093: my $navmap;
1.483 raeburn 2094: my $js = '<script type="text/javascript">'."\n".
2095: '// <![CDATA['."\n".
2096: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 2097: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 2098: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 2099: &history_tab_js()."\n".
1.484 raeburn 2100: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 2101: '// ]]>'."\n".
2102: '</script>'."\n";
1.484 raeburn 2103: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
2104: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 2105: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 2106: my %orderhash;
2107: my $container='sequence';
2108: my $pathitem;
1.519 raeburn 2109: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 2110: $container='page';
2111: }
1.519 raeburn 2112: my $folderpath=$env{'form.folderpath'};
2113: if ($folderpath eq '') {
1.617 raeburn 2114: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 2115: }
1.617 raeburn 2116: undef($navmap);
1.519 raeburn 2117: $pathitem = '<input type="hidden" name="folderpath" value="'.
2118: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 2119: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
2120: my $jumpto = $readfile;
2121: $jumpto =~ s{^/}{};
2122: my $tid = 1;
1.489 raeburn 2123: if ($supplementalflag) {
2124: $tid = 2;
2125: }
1.630 raeburn 2126: my ($breadcrumbtrail) =
1.509 raeburn 2127: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 2128: $r->print($breadcrumbtrail.
2129: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
2130: $readfile));
1.329 droeschl 2131: my %docslog=&Apache::lonnet::dump('nohist_docslog',
2132: $env{'course.'.$env{'request.course.id'}.'.domain'},
2133: $env{'course.'.$env{'request.course.id'}.'.num'});
2134:
2135: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
2136:
2137: my %saveable_parameters = ('show' => 'scalar',);
2138: &Apache::loncommon::store_course_settings('docs_log',
2139: \%saveable_parameters);
2140: &Apache::loncommon::restore_course_settings('docs_log',
2141: \%saveable_parameters);
2142: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 2143: # FIXME: internationalization seems wrong here
1.329 droeschl 2144: my %lt=('hiddenresource' => 'Resources hidden',
2145: 'encrypturl' => 'URL hidden',
2146: 'randompick' => 'Randomly pick',
2147: 'randomorder' => 'Randomly ordered',
1.645 raeburn 2148: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 2149: 'set' => 'set to',
2150: 'del' => 'deleted');
1.484 raeburn 2151: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
2152: $pathitem."\n".
2153: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
2154: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
2155: $r->print('<div class="LC_left_float">'.
2156: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
2157: &makedocslogform($filter,1).
2158: '</fieldset></div><br clear="all" />');
1.329 droeschl 2159: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
2160: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
2161: &mt('After').'</th>'.
2162: &Apache::loncommon::end_data_table_header_row());
2163: my $shown=0;
2164: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
2165: if ($env{'form.displayfilter'} eq 'currentfolder') {
2166: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
2167: }
2168: my @changes=keys(%{$docslog{$id}{'logentry'}});
2169: if ($env{'form.displayfilter'} eq 'containing') {
2170: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
2171: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
2172: foreach my $key (@changes) {
2173: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
2174: }
1.344 bisitz 2175: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 2176: }
2177: my $count = 0;
2178: my $time =
2179: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
2180: my $plainname =
2181: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
2182: $docslog{$id}{'exe_udom'});
2183: my $about_me_link =
2184: &Apache::loncommon::aboutmewrapper($plainname,
2185: $docslog{$id}{'exe_uname'},
2186: $docslog{$id}{'exe_udom'});
2187: my $send_msg_link='';
2188: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
2189: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
2190: $send_msg_link ='<br />'.
2191: &Apache::loncommon::messagewrapper(&mt('Send message'),
2192: $docslog{$id}{'exe_uname'},
2193: $docslog{$id}{'exe_udom'});
2194: }
2195: $r->print(&Apache::loncommon::start_data_table_row());
2196: $r->print('<td>'.$time.'</td>
2197: <td>'.$about_me_link.
2198: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
2199: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
2200: $send_msg_link.'</td><td>'.
2201: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 2202: my $is_supp = 0;
2203: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
2204: $is_supp = 1;
2205: }
1.329 droeschl 2206: # Before
2207: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2208: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
2209: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
2210: if ($oldname ne $newname) {
1.488 raeburn 2211: my $shown = &LONCAPA::map::qtescape($oldname);
2212: if ($is_supp) {
2213: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2214: }
2215: $r->print($shown);
1.329 droeschl 2216: }
2217: }
2218: $r->print('<ul>');
2219: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2220: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 2221: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
2222: if ($is_supp) {
2223: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2224: }
2225: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 2226: }
2227: }
2228: $r->print('</ul>');
2229: # After
2230: $r->print('</td><td>');
2231:
2232: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2233: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
2234: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
2235: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 2236: my $shown = &LONCAPA::map::qtescape($newname);
2237: if ($is_supp) {
2238: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
2239: }
2240: $r->print($shown);
1.329 droeschl 2241: }
1.364 bisitz 2242: }
1.329 droeschl 2243: $r->print('<ul>');
2244: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
2245: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 2246: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
2247: if ($is_supp) {
2248: $shown = &Apache::loncommon::parse_supplemental_title($shown);
2249: }
2250: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 2251: }
2252: }
2253: $r->print('</ul>');
2254: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 2255: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
2256: if ($title eq '') {
2257: ($title) = ($url =~ m{/([^/]+)$});
1.695 raeburn 2258: } elsif ($is_supp) {
2259: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 2260: }
2261: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 2262: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 2263: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 2264: # FIXME: internationalization seems wrong here
1.329 droeschl 2265: $r->print('<li>'.
2266: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
2267: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
2268: .'</li>');
2269: }
2270: }
2271: $r->print('</ul>');
2272: }
2273: # End
2274: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
2275: $shown++;
2276: if (!($env{'form.show'} eq &mt('all')
2277: || $shown<=$env{'form.show'})) { last; }
2278: }
1.484 raeburn 2279: $r->print(&Apache::loncommon::end_data_table()."\n".
2280: &makesimpleeditform($pathitem)."\n".
2281: '</div></div>');
2282: $r->print(&endContentScreen());
1.329 droeschl 2283: }
2284:
2285: sub update_paste_buffer {
1.492 raeburn 2286: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 2287: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 2288: if ($env{'form.multiremove'}) {
2289: $env{'form.multiremove'} =~ s/,$//;
2290: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
2291: }
2292: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
2293: if ($env{'form.multicut'}) {
2294: $env{'form.multicut'} =~ s/,$//;
2295: foreach my $item (split(/,/,$env{'form.multicut'})) {
2296: unless ($removals{$item}) {
2297: $cuts{$item} = 1;
2298: push(@possibles,$item.':cut');
2299: }
2300: }
2301: }
2302: if ($env{'form.multicopy'}) {
2303: $env{'form.multicopy'} =~ s/,$//;
2304: foreach my $item (split(/,/,$env{'form.multicopy'})) {
2305: unless ($removals{$item} || $cuts{$item}) {
2306: push(@possibles,$item.':copy');
2307: }
2308: }
2309: }
2310: } elsif ($env{'form.markcopy'}) {
2311: @possibles = split(/,/,$env{'form.markcopy'});
2312: }
1.329 droeschl 2313:
1.538 raeburn 2314: return if (@possibles == 0);
1.329 droeschl 2315: return if (!defined($env{'form.copyfolder'}));
2316:
2317: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2318: $env{'form.copyfolder'});
1.538 raeburn 2319: return if ($fatal);
2320:
2321: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 2322:
1.538 raeburn 2323: # Retrieve current paste buffer suffixes.
2324: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2325: my (%pasteurls,@newpaste);
2326:
2327: # Construct identifiers for current contents of user's paste buffer
2328: if (@currpaste) {
2329: foreach my $suffix (@currpaste) {
1.667 raeburn 2330: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
2331: my $url = $env{'docs.markedcopy_url_'.$suffix};
2332: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
2333: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
2334: ($url ne '')) {
2335: if ($url eq '/res/lib/templates/simpleproblem.problem') {
2336: $pasteurls{$cid.'_'.$mapidx} = 1;
2337: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
2338: $pasteurls{$url} = 1;
2339: } else {
1.669 raeburn 2340: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 2341: }
2342: }
1.538 raeburn 2343: }
2344: }
2345:
2346: # Mark items for copying (skip any items already in user's paste buffer)
2347: my %addtoenv;
1.597 raeburn 2348:
2349: my @pathitems = split(/\&/,$env{'form.folderpath'});
2350: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 2351: my $ispage = $folderconf[5];
1.597 raeburn 2352:
1.538 raeburn 2353: foreach my $item (@possibles) {
2354: my ($orderidx,$cmd) = split(/:/,$item);
2355: next if ($orderidx =~ /\D/);
2356: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 2357: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 2358: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
2359: my %denied = &action_restrictions($coursenum,$coursedom,
2360: &LONCAPA::map::qtescape($url),
2361: $env{'form.folderpath'},\%curr_groups);
2362: next if ($denied{'copy'});
2363: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 2364: if ($url eq '/res/lib/templates/simpleproblem.problem') {
2365: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
2366: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
2367: next if (exists($pasteurls{$url}));
2368: } else {
2369: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
2370: }
1.538 raeburn 2371: my ($suffix,$errortxt,$locknotfreed) =
2372: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 2373: if ($suffix ne '') {
2374: push(@newpaste,$suffix);
2375: } else {
2376: if ($locknotfreed) {
2377: return $locknotfreed;
2378: }
1.538 raeburn 2379: }
2380: if (&is_supplemental_title($title)) {
2381: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
2382: ($title) = &Apache::loncommon::parse_supplemental_title($title);
2383: }
1.329 droeschl 2384:
1.538 raeburn 2385: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
2386: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
2387: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
2388: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 2389: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 2390: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
2391: my $prefix = $1;
2392: my $subdir =$2;
2393: if ($subdir eq '') {
2394: $subdir = $prefix;
1.492 raeburn 2395: }
1.538 raeburn 2396: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 2397: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
2398: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 2399: if (ref($hierarchy{$url}) eq 'HASH') {
2400: my ($nested,$nestednames);
2401: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
2402: $nested =~ s/\&$//;
2403: $nestednames =~ s/\Q___&&&___\E$//;
2404: if ($nested ne '') {
2405: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
2406: }
2407: if ($nestednames ne '') {
2408: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
2409: }
1.492 raeburn 2410: }
2411: }
1.591 raeburn 2412: if ($locknotfreed) {
2413: $output = $locknotfreed;
2414: last;
2415: }
1.492 raeburn 2416: }
1.538 raeburn 2417: if (@newpaste) {
2418: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
2419: }
1.492 raeburn 2420: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 2421: delete($env{'form.markcopy'});
1.591 raeburn 2422: return $output;
1.329 droeschl 2423: }
2424:
1.492 raeburn 2425: sub recurse_uploaded_maps {
2426: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
2427: if (ref($hierarchy->{$url}) eq 'HASH') {
2428: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
2429: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
2430: my (@uploaded,@names,%shorter);
2431: for (my $i=0; $i<@maps; $i++) {
2432: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
2433: if ($inner ne '') {
2434: push(@uploaded,$inner);
2435: push(@names,&escape($titles[$i]));
2436: $shorter{$maps[$i]} = $inner;
2437: }
2438: }
2439: $$nestref .= "$dir:".join(',',@uploaded).'&';
2440: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
2441: foreach my $map (@maps) {
2442: if ($shorter{$map} ne '') {
2443: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
2444: }
2445: }
2446: }
2447: return;
2448: }
2449:
1.329 droeschl 2450: sub print_paste_buffer {
1.492 raeburn 2451: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 2452: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 2453:
1.538 raeburn 2454: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
2455: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 2456: }
2457:
1.538 raeburn 2458: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1.704 raeburn 2459: my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
1.575 raeburn 2460: my $clipboardcount = 0;
1.488 raeburn 2461:
1.538 raeburn 2462: # Construct identifiers for current contents of user's paste buffer
2463: foreach my $suffix (@currpaste) {
2464: next if ($suffix =~ /\D/);
2465: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
2466: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 2467: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 2468: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
2469: ($url ne '')) {
1.575 raeburn 2470: $clipboardcount ++;
1.538 raeburn 2471: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.704 raeburn 2472: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
2473: $toolcnum,$marker);
1.538 raeburn 2474: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
2475: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
2476: $is_external = 1;
1.704 raeburn 2477: } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2478: ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1.598 raeburn 2479: $is_exttool = 1;
1.538 raeburn 2480: }
2481: if ($folder =~ /^supplemental/) {
2482: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
2483: unless ($canpaste) {
2484: $nopaste = &mt('Paste into Supplemental Content unavailable.');
2485: }
2486: } else {
2487: $canpaste = 1;
2488: }
2489: if ($canpaste) {
2490: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2491: my $srcdom = $1;
2492: my $srcnum = $2;
2493: my $rem = $3;
2494: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
2495: $othercourse = 1;
2496: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 2497: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 2498: } else {
2499: $canpaste = 0;
2500: $nopaste = &mt('Paste from another course unavailable.');
2501: }
2502: }
2503: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
2504: my $prefix = $1;
2505: $parent = $2;
2506: if ($folder !~ /^\Q$prefix\E/) {
2507: $areachange = 1;
2508: }
2509: $is_uploaded_map = 1;
1.492 raeburn 2510: }
1.597 raeburn 2511: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 2512: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 2513: if ($cid ne $env{'request.course.id'}) {
2514: my ($srcdom,$srcnum) = split(/_/,$cid);
2515: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.704 raeburn 2516: if ($is_exttool) {
2517: if ($toolcdom ne $coursedom) {
2518: $canpaste = 0;
2519: $nopaste = &mt('Paste from another domain unavailable.');
2520: } elsif ($toolcnum ne $coursenum) {
2521: my %toolsettings =
2522: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2523: my %tooltypes = &Apache::loncommon::usable_exttools();
2524: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2525: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2526: $canpaste = 0;
2527: $nopaste = &mt('Paste from another course unavailable.');
2528: } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
2529: unless ($checkedsameinst) {
2530: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2531: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2532: if ($intdom ne '') {
2533: my $internet_names =
2534: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2535: if (ref($internet_names) eq 'ARRAY') {
2536: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2537: $same_institution = 1;
2538: }
2539: }
2540: }
2541: $checkedsameinst = 1;
2542: }
2543: if ($same_institution) {
2544: $othercrs = '<br />'.&mt('(from another course)');
2545: } else {
2546: $nopaste = &mt('Paste from another course unavailable.');
2547: }
2548: } else {
2549: $othercrs = '<br />'.&mt('(from another course)');
2550: }
2551: }
1.627 raeburn 2552: }
1.596 raeburn 2553: } else {
2554: $canpaste = 0;
2555: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 2556: }
1.596 raeburn 2557: }
1.703 raeburn 2558: } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
2559: my ($audom,$auname) = ($1,$2);
2560: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2561: if (&Apache::lonnet::is_course($audom,$auname)) {
2562: $canpaste = 0;
2563: $nopaste = &mt('Paste from another course unavailable.');
2564: }
2565: }
1.492 raeburn 2566: }
1.596 raeburn 2567: if ($canpaste) {
2568: push(@pasteable,$suffix);
1.629 raeburn 2569: }
1.538 raeburn 2570: }
2571: my $buffer;
1.627 raeburn 2572: if ($is_external) {
1.538 raeburn 2573: $buffer = &mt('External Resource').': '.
2574: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
2575: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 2576: } elsif ($is_exttool) {
2577: $buffer = &mt('External Tool').': '.
2578: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 2579: } else {
2580: my $icon = &Apache::loncommon::icon($extension);
1.723 raeburn 2581: my $icontext;
2582: if ($extension eq 'sequence') {
2583: $icontext = &mt('folder icon');
2584: } elsif ($extension eq 'page') {
2585: $icontext = &mt('composite page icon');
2586: } else {
2587: $icontext = &mt('file icon');
2588: }
2589: $icontext = &HTML::Entities::encode($icontext);
1.538 raeburn 2590: if ($extension eq 'sequence' &&
2591: $url =~ m{/default_\d+\.sequence$}x) {
2592: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
2593: $icon .= '/navmap.folder.closed.gif';
2594: }
1.589 raeburn 2595: my $title = $env{'docs.markedcopy_title_'.$suffix};
2596: if ($title eq '') {
2597: ($title) = ($url =~ m{/([^/]+)$});
2598: }
1.723 raeburn 2599: $buffer = '<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" />'.
1.538 raeburn 2600: ': '.
2601: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 2602: &LONCAPA::map::qtescape($title));
1.538 raeburn 2603: }
2604: $pasteitems .= '<div class="LC_left_float">';
2605: my ($options,$onclick);
2606: if (($canpaste) && (!$areachange) && (!$othercourse) &&
2607: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
2608: if (($is_uploaded_map) ||
2609: ($url =~ /(bulletinboard|smppg)$/) ||
2610: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
2611: $options = &paste_options($suffix,$is_uploaded_map,$parent);
2612: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
2613: }
2614: }
2615: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
2616: if ($nopaste) {
1.681 raeburn 2617: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 2618: } else {
2619: if ($othercrs) {
2620: $pasteitems .= $othercrs;
2621: }
2622: if ($options) {
2623: $pasteitems .= $options;
1.492 raeburn 2624: }
2625: }
1.538 raeburn 2626: $pasteitems .= '</div>';
2627: }
2628: }
2629: if ($pasteitems eq '') {
2630: &Apache::lonnet::delenv('docs.markedcopies');
2631: }
2632: my ($pasteform,$form_start,$buttons,$form_end);
2633: if ($pasteitems) {
2634: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 2635: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 2636: if (@pasteable) {
1.575 raeburn 2637: my $value = &mt('Paste to current folder');
2638: if ($container eq 'page') {
2639: $value = &mt('Paste to current page');
2640: }
2641: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
2642: }
2643: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
2644: if ($clipboardcount > 1) {
2645: $buttons .=
2646: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
2647: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
2648: (' 'x2).
2649: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
2650: (' 'x2);
1.492 raeburn 2651: }
1.575 raeburn 2652: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
2653: '</form>';
1.538 raeburn 2654: } else {
2655: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 2656: }
1.538 raeburn 2657: $r->print($form_start
2658: .'<fieldset>'
2659: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
2660: .$pasteitems
2661: .'</fieldset>'
2662: .$form_end);
2663: }
2664:
2665: sub paste_options {
2666: my ($suffix,$is_uploaded_map,$parent) = @_;
2667: my ($copytext,$movetext);
2668: if ($is_uploaded_map) {
2669: $copytext = &mt('Copy to new folder');
2670: $movetext = &mt('Move old');
2671: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
2672: $copytext = &mt('Copy to new board');
2673: $movetext = &mt('Move (not posts)');
2674: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
2675: $copytext = &mt('Copy to new page');
2676: $movetext = &mt('Move');
1.533 raeburn 2677: } else {
1.538 raeburn 2678: $copytext = &mt('Copy to new file');
2679: $movetext = &mt('Move');
2680: }
2681: my $output = '<br />'.
2682: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
2683: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
2684: '<label>'.
2685: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
2686: $copytext.'</label></span>'.(' 'x2).' '.
2687: '<span class="LC_nobreak"><label>'.
2688: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
2689: $movetext.'</label></span>';
2690: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
2691: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
2692: '</legend><table border="0">';
2693: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2694: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
2695: my $lastdir = $parent;
2696: my %depths = (
2697: $lastdir => 0,
2698: );
2699: my (%display,%deps);
2700: for (my $i=0; $i<@pastemaps; $i++) {
2701: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
2702: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
2703: my @subfolders = split(/,/,$subfolderstr);
2704: $deps{$lastdir} = \@subfolders;
2705: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
2706: my $depth = $depths{$lastdir} + 1;
2707: my $offset = int($depth * 4);
2708: my $indent = (' ' x $offset);
2709: for (my $j=0; $j<@subfolders; $j++) {
2710: $depths{$subfolders[$j]} = $depth;
2711: $display{$subfolders[$j]} =
2712: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
2713: '<td><label>'.
2714: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
2715: '<label>'.
2716: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
2717: &mt('Move old').'</label>'.
2718: '</td></tr>';
2719: }
1.492 raeburn 2720: }
1.538 raeburn 2721: &recurse_print(\$output,$parent,\%deps,\%display);
2722: $output .= '</table></fieldset>';
1.329 droeschl 2723: }
1.538 raeburn 2724: $output .= '</div>';
2725: return $output;
1.488 raeburn 2726: }
2727:
1.492 raeburn 2728: sub recurse_print {
1.538 raeburn 2729: my ($outputref,$dir,$deps,$display) = @_;
2730: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 2731: if (ref($deps->{$dir}) eq 'ARRAY') {
2732: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 2733: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 2734: }
2735: }
2736: }
2737:
1.488 raeburn 2738: sub supp_pasteable {
2739: my ($url) = @_;
2740: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
2741: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
2742: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
2743: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 2744: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 2745: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 2746: return 1;
2747: }
2748: return;
1.329 droeschl 2749: }
2750:
1.492 raeburn 2751: sub paste_popup_js {
1.594 damieng 2752: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 2753: show => 'Show Options',
2754: hide => 'Hide Options',
1.594 damieng 2755: );
2756: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 2757: none => 'No items selected from clipboard.',
1.492 raeburn 2758: );
1.594 damieng 2759: &html_escape(\%html_js_lt);
2760: &js_escape(\%html_js_lt);
2761: &js_escape(\%js_lt);
1.492 raeburn 2762: return <<"END";
2763:
1.538 raeburn 2764: function showPasteOptions(suffix) {
2765: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 2766: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 2767: return;
2768: }
2769:
1.538 raeburn 2770: function hidePasteOptions(suffix) {
2771: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 2772: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2773: return;
2774: }
2775:
2776: function showOptions(caller,suffix) {
2777: if (document.getElementById('pasteoptionstext_'+suffix)) {
2778: if (caller.checked) {
1.594 damieng 2779: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2780: } else {
2781: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
2782: }
2783: if (document.getElementById('pasteoptions_'+suffix)) {
2784: document.getElementById('pasteoptions_'+suffix).style.display='none';
2785: }
2786: }
1.492 raeburn 2787: return;
2788: }
2789:
1.541 raeburn 2790: function validateClipboard() {
2791: var numchk = 0;
2792: if (document.pasteform.pasting.length > 1) {
2793: for (var i=0; i<document.pasteform.pasting.length; i++) {
2794: if (document.pasteform.pasting[i].checked) {
2795: numchk ++;
2796: }
2797: }
2798: } else {
2799: if (document.pasteform.pasting.type == 'checkbox') {
2800: if (document.pasteform.pasting.checked) {
2801: numchk ++;
2802: }
2803: }
2804: }
2805: if (numchk > 0) {
2806: return true;
2807: } else {
1.594 damieng 2808: alert("$js_lt{'none'}");
1.541 raeburn 2809: return false;
2810: }
2811: }
2812:
1.575 raeburn 2813: function checkClipboard() {
2814: if (document.pasteform.pasting.length > 1) {
2815: for (var i=0; i<document.pasteform.pasting.length; i++) {
2816: document.pasteform.pasting[i].checked = true;
2817: }
2818: }
2819: return;
2820: }
2821:
2822: function uncheckClipboard() {
2823: if (document.pasteform.pasting.length >1) {
2824: for (var i=0; i<document.pasteform.pasting.length; i++) {
2825: document.pasteform.pasting[i].checked = false;
2826: }
2827: }
2828: return;
2829: }
2830:
1.492 raeburn 2831: END
2832:
2833: }
2834:
1.329 droeschl 2835: sub do_paste_from_buffer {
1.492 raeburn 2836: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 2837:
1.538 raeburn 2838: # Array of items in paste buffer
2839: my (@currpaste,%pastebuffer,%allerrors);
2840: @currpaste = split(/,/,$env{'docs.markedcopies'});
2841:
1.492 raeburn 2842: # Early out if paste buffer is empty
1.538 raeburn 2843: if (@currpaste == 0) {
1.492 raeburn 2844: return ();
1.538 raeburn 2845: }
2846: map { $pastebuffer{$_} = 1; } @currpaste;
2847:
2848: # Array of items selected items to paste
2849: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
2850:
2851: # Early out if nothing selected to paste
2852: if (@reqpaste == 0) {
2853: return();
2854: }
2855: my @topaste;
2856: foreach my $suffix (@reqpaste) {
2857: next if ($suffix =~ /\D/);
2858: next unless (exists($pastebuffer{$suffix}));
2859: push(@topaste,$suffix);
2860: }
2861:
2862: # Early out if nothing available to paste
2863: if (@topaste == 0) {
2864: return();
1.329 droeschl 2865: }
2866:
1.704 raeburn 2867: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
2868: %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
2869: %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
2870: %currltititles,$currltimax,$gotcrsltitools);
2871: $currltimax = 0;
2872: $gotcrsltitools = 0;
1.538 raeburn 2873: foreach my $suffix (@topaste) {
2874: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 2875: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 2876: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 2877: # Supplemental content may only include certain types of content
2878: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 2879: if ($folder =~ /^supplemental/) {
2880: unless (&supp_pasteable($url)) {
2881: $notinsupp{$suffix} = 1;
2882: next;
2883: }
1.492 raeburn 2884: }
1.538 raeburn 2885: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
2886: my $srcd = $1;
2887: my $srcn = $2;
1.492 raeburn 2888: # When paste buffer was populated using an active role in a different course
1.538 raeburn 2889: # check for mdc privilege in the course from which the resource was pasted
2890: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2891: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2892: $notincrs{$suffix} = 1;
2893: next;
2894: }
1.491 raeburn 2895: }
1.538 raeburn 2896: $srcdom{$suffix} = $srcd;
2897: $srcnum{$suffix} = $srcn;
1.597 raeburn 2898: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 2899: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
2900: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 2901: my ($srcd,$srcn) = split(/_/,$cid);
2902: # When paste buffer was populated using an active role in a different course
2903: # check for mdc privilege in the course from which the resource was pasted
2904: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2905: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2906: $notincrs{$suffix} = 1;
2907: next;
2908: }
2909: }
1.632 raeburn 2910: # When buffer was populated using an active role in a different course
1.704 raeburn 2911: # disallow pasting of External Tool if course is in a different domain,
2912: # or if External Tool use is not permitted in this course.
2913: if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2914: my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
2915: if ($toolcdom ne $coursedom) {
2916: $notindom{$suffix} = 1;
2917: next;
2918: } elsif ($toolcnum ne $coursenum) {
2919: my %toolsettings =
2920: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2921: my %tooltypes = &Apache::loncommon::usable_exttools();
2922: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2923: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2924: $othcrstool{$suffix} = 1;
2925: next;
2926: }
2927: if ($toolsettings{'id'} =~ /^c\d+$/) {
2928: unless ($gotcrsltitools) {
2929: %currcrsltitools =
2930: &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
2931: foreach my $item (sort(keys(%currcrsltitools))) {
2932: if (ref($currcrsltitools{$item}) eq 'HASH') {
2933: $currltimax ++;
2934: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
2935: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
2936: } else {
2937: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
2938: }
2939: }
2940: }
2941: $gotcrsltitools = 1;
2942: }
2943: }
2944: }
1.627 raeburn 2945: }
1.596 raeburn 2946: $srcdom{$suffix} = $srcd;
2947: $srcnum{$suffix} = $srcn;
1.703 raeburn 2948: } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
2949: my ($audom,$auname) = ($1,$2);
2950: # When buffer was populated using an active role in a different course
2951: # disallow pasting of published resources from Course Authoring Space
2952: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2953: if (&Apache::lonnet::is_course($audom,$auname)) {
2954: $othcrsres{$suffix} = 1;
2955: next;
2956: }
2957: }
1.491 raeburn 2958: }
1.597 raeburn 2959: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 2960: push(@dopaste,$suffix);
2961: if ($url=~/\.(page|sequence)$/) {
2962: $is_map{$suffix} = 1;
2963: }
2964: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
2965: my $oldprefix = $1;
1.492 raeburn 2966: # When pasting content from Main Content to Supplemental Content and vice versa
2967: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 2968: # a folder/page or a document).
1.538 raeburn 2969: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
2970: $prefixchg{$suffix} = 'docstosupp';
2971: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
2972: $prefixchg{$suffix} = 'supptodocs';
2973: }
1.491 raeburn 2974:
1.492 raeburn 2975: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 2976: if ($env{'docs.markedcopy_nested_'.$suffix}) {
2977: my @nested;
2978: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
2979: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2980: my @deps = map { /\d+:([\d,]+$)/ } @items;
2981: foreach my $dep (@deps) {
2982: if ($dep =~ /,/) {
2983: push(@nested,split(/,/,$dep));
2984: } else {
2985: push(@nested,$dep);
2986: }
1.492 raeburn 2987: }
1.538 raeburn 2988: foreach my $item (@nested) {
2989: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
2990: push(@{$marktomove{$suffix}},$type.'_'.$item);
2991: }
1.492 raeburn 2992: }
2993: }
1.488 raeburn 2994: }
2995: }
2996:
1.538 raeburn 2997: # Early out if nothing available to paste
2998: if (@dopaste == 0) {
2999: return ();
3000: }
3001:
3002: # Populate message hash and hashes used for main content <=> supplemental content
3003: # changes
3004:
3005: %msgs = &Apache::lonlocal::texthash (
3006: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
3007: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 3008: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.704 raeburn 3009: othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.703 raeburn 3010: othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538 raeburn 3011: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
3012: );
3013:
3014: %before = (
3015: docstosupp => {
3016: map => 'default',
3017: doc => 'docs',
3018: },
3019: supptodocs => {
3020: map => 'supplemental',
3021: doc => 'supplemental',
3022: },
3023: );
3024:
3025: %after = (
3026: docstosupp => {
3027: map => 'supplemental',
3028: doc => 'supplemental'
3029: },
3030: supptodocs => {
3031: map => 'default',
3032: doc => 'docs',
3033: },
3034: );
3035:
3036: # Retrieve information about all course maps in main content area
3037:
3038: my $allmaps = {};
1.704 raeburn 3039: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
3040: @updatetoolsenc,$updatetoolscache,$checkedsameinst,
3041: $same_institution);
1.538 raeburn 3042:
3043: # Loop over the items to paste
3044: foreach my $suffix (@dopaste) {
1.329 droeschl 3045: # Maps need to be copied first
1.538 raeburn 3046: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
3047: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 3048: %newurls,%tomove,%resdatacopy);
1.538 raeburn 3049: if (ref($marktomove{$suffix}) eq 'ARRAY') {
3050: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
3051: }
3052: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
3053: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 3054: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 3055: my $oldurl = $url;
3056: if ($is_map{$suffix}) {
1.491 raeburn 3057: # If pasting a map, check if map contains other maps
1.538 raeburn 3058: my (%hierarchy,%titles);
1.660 raeburn 3059: if (($folder =~ /^default/) && (!$donechk)) {
3060: $allmaps =
3061: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
3062: $env{"course.$env{'request.course.id'}.home"},
3063: $env{'request.course.id'});
3064: $donechk = 1;
3065: }
1.627 raeburn 3066: &contained_map_check($url,$folder,$coursenum,$coursedom,
3067: \%removefrommap,\%removeparam,\%addedmaps,
3068: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 3069: if ($url=~ m{^/uploaded/}) {
3070: my $newurl;
3071: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
3072: ($newurl,my $error) =
3073: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
3074: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
3075: \$title,$allmaps,\%newurls);
3076: if ($error) {
3077: $allerrors{$suffix} = $error;
3078: next;
3079: }
3080: if ($newurl ne '') {
3081: if ($newurl ne $url) {
3082: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
3083: $newsubdir{$url} = $1;
3084: }
3085: $mapchanges{$url} = 1;
1.492 raeburn 3086: }
1.538 raeburn 3087: }
3088: }
3089: if (($srcdom{$suffix} ne $coursedom) ||
3090: ($srcnum{$suffix} ne $coursenum) ||
3091: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
3092: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
3093: $coursedom,$coursenum,$srcdom{$suffix},
3094: $srcnum{$suffix},$allmaps,\%rewrites,
3095: \%retitles,\%copies,\%dbcopies,
3096: \%zombies,\%params,\%mapmoves,
3097: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 3098: \%newurls,\%resdatacopy)) {
1.538 raeburn 3099: $mapmoves{$url} = 1;
3100: }
3101: $url = $newurl;
3102: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
3103: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
3104: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
3105: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
3106: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 3107: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 3108: }
3109: } elsif ($url=~m {^/res/}) {
1.597 raeburn 3110: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 3111: push(@toclear,$suffix);
3112: # if pasting published map (main content area only) check map not already in course
3113: if ($folder =~ /^default/) {
3114: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
3115: $duplicate{$suffix} = 1;
3116: next;
1.492 raeburn 3117: }
1.491 raeburn 3118: }
3119: }
1.538 raeburn 3120: }
1.627 raeburn 3121: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 3122: my $prefix = $1;
1.648 raeburn 3123: my $fromothercrs;
1.538 raeburn 3124: #need to copy the db contents to a new one, unless this is a move.
3125: my %info = (
3126: src => $url,
3127: cdom => $coursedom,
3128: cnum => $coursenum,
1.596 raeburn 3129: );
1.649 raeburn 3130: if ($prefix eq 'ext.tool') {
1.655 raeburn 3131: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 3132: $info{'delgradable'} = 1;
3133: }
3134: }
1.596 raeburn 3135: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
3136: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
3137: $fromothercrs = 1;
3138: $info{'cdom'} = $srcdom{$suffix};
3139: $info{'cnum'} = $srcnum{$suffix};
1.704 raeburn 3140: unless ($checkedsameinst) {
3141: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
3142: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3143: if ($intdom ne '') {
3144: my $internet_names =
3145: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
3146: if (ref($internet_names) eq 'ARRAY') {
3147: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
3148: $same_institution = 1;
3149: }
3150: }
3151: }
3152: $checkedsameinst = 1;
3153: }
1.596 raeburn 3154: }
3155: }
3156: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 3157: my (%lockerr,$msg);
1.538 raeburn 3158: my ($newurl,$result,$errtext) =
1.704 raeburn 3159: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
3160: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.538 raeburn 3161: if ($result eq 'ok') {
3162: $url = $newurl;
3163: $title=&mt('Copy of').' '.$title;
3164: } else {
3165: if ($prefix eq 'smppg') {
3166: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
3167: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 3168: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 3169: } elsif ($prefix eq 'ext.tool') {
3170: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 3171: }
3172: $results{$suffix} = $result;
3173: $msgerrs{$suffix} = $msg;
3174: $lockerrs{$suffix} = $lockerr{$prefix};
3175: next;
3176: }
3177: if ($lockerr{$prefix}) {
3178: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 3179: }
1.489 raeburn 3180: }
3181: }
1.538 raeburn 3182: $title = &LONCAPA::map::qtunescape($title);
3183: my $ext='false';
3184: if ($url=~m{^http(|s)://}) { $ext='true'; }
3185: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
3186: if ($folder !~ /^supplemental/) {
3187: (undef,undef,$title) =
3188: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
3189: }
3190: } else {
3191: if ($folder=~/^supplemental/) {
3192: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3193: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 3194: }
1.533 raeburn 3195: }
1.491 raeburn 3196:
3197: # For uploaded files (excluding pages/sequences) path in copied file is changed
3198: # if paste is from Main to Supplemental (or vice versa), or if pasting between
3199: # courses.
3200:
1.538 raeburn 3201: unless ($is_map{$suffix}) {
3202: my $newidx;
1.492 raeburn 3203: # Now insert the URL at the bottom
1.538 raeburn 3204: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
3205: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
3206: my $relpath = $1;
3207: if ($relpath ne '') {
3208: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
3209: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
3210: my $newprefix = $newloc;
3211: if ($newloc eq 'default') {
3212: $newprefix = 'docs';
3213: }
3214: if ($newdocsdir eq '') {
3215: $newdocsdir = 'default';
3216: }
1.630 raeburn 3217: if (($prefixchg{$suffix}) ||
3218: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 3219: ($srcnum{$suffix} ne $coursenum) ||
3220: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
3221: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
3222: $url =
3223: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
3224: &Apache::lonnet::getfile($oldurl));
3225: if ($url eq '/adm/notfound.html') {
3226: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
3227: next;
3228: } else {
3229: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
3230: $newsubpath =~ s{/+$}{/};
3231: $docmoves{$oldurl} = $newsubpath;
3232: }
1.491 raeburn 3233: }
3234: }
1.597 raeburn 3235: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
3236: my $template = $1;
3237: if ($newidx) {
3238: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
3239: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
3240: }
1.649 raeburn 3241: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 3242: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 3243: my $marker = (split(m{/},$url))[4];
3244: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
3245: my $val = 'no';
3246: if ($toolsettings{'gradable'}) {
3247: $val = 'yes';
3248: }
3249: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
3250: 'string_yesno');
3251: &remember_parms($newidx,'gradable','set',$val);
3252: }
1.491 raeburn 3253: }
1.538 raeburn 3254: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
3255: ':'.$ext.':normal:res';
3256: push(@LONCAPA::map::order,$newidx);
3257: # Store the result
3258: my ($errtext,$fatal) =
3259: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3260: if ($fatal) {
3261: $save_err .= $errtext;
3262: $allresult = 'fail';
3263: }
1.488 raeburn 3264: }
1.538 raeburn 3265:
1.597 raeburn 3266: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
3267: # resourcedata for simpleproblems copied from another course
1.538 raeburn 3268: unless ($allresult eq 'fail') {
3269: my %updated = (
3270: rewrites => \%rewrites,
3271: zombies => \%zombies,
3272: removefrommap => \%removefrommap,
3273: removeparam => \%removeparam,
3274: dbcopies => \%dbcopies,
1.597 raeburn 3275: resdatacopy => \%resdatacopy,
1.538 raeburn 3276: retitles => \%retitles,
3277: );
3278: my %info = (
3279: newsubdir => \%newsubdir,
3280: params => \%params,
3281: );
3282: if ($prefixchg{$suffix}) {
3283: $info{'before'} = $before{$prefixchg{$suffix}};
3284: $info{'after'} = $after{$prefixchg{$suffix}};
3285: }
3286: my %moves = (
3287: copies => \%copies,
3288: docmoves => \%docmoves,
3289: mapmoves => \%mapmoves,
3290: );
3291: (my $result,$msgs{$suffix},my $lockerror) =
3292: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
3293: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
3294: $url,'paste');
3295: $lockerrors .= $lockerror;
3296: if ($result eq 'ok') {
3297: if ($is_map{$suffix}) {
3298: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3299: $folder.'.'.$container);
3300: if ($fatal) {
3301: $allresult = 'failread';
3302: } else {
3303: if ($#LONCAPA::map::order<1) {
3304: my $idx=&LONCAPA::map::getresidx();
3305: if ($idx<=0) { $idx=1; }
3306: $LONCAPA::map::order[0]=$idx;
3307: $LONCAPA::map::resources[$idx]='';
3308: }
3309: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
3310: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
3311: ':'.$ext.':normal:res';
3312: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 3313:
3314: # Store the result
1.538 raeburn 3315: my ($errtext,$fatal) =
3316: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3317: if ($fatal) {
3318: $save_err .= $errtext;
3319: $allresult = 'failstore';
3320: }
3321: }
3322: }
3323: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
3324: push(@toclear,$suffix);
3325: }
3326: }
1.492 raeburn 3327: }
3328: }
1.704 raeburn 3329: if (($updatetoolscache) || (@updatetoolsenc)) {
3330: &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
3331: \@updatetoolsenc);
3332: }
1.538 raeburn 3333: &clear_from_buffer(\@toclear,\@currpaste);
3334: my $msgsarray;
3335: foreach my $suffix (keys(%msgs)) {
3336: if (ref($msgs{$suffix}) eq 'ARRAY') {
3337: $msgsarray .= join(',',@{$msgs{$suffix}});
3338: }
3339: }
3340: return ($allresult,$save_err,$msgsarray,$lockerrors);
3341: }
1.533 raeburn 3342:
1.538 raeburn 3343: sub do_buffer_empty {
3344: my @currpaste = split(/,/,$env{'docs.markedcopies'});
3345: if (@currpaste == 0) {
3346: return &mt('Clipboard is already empty');
3347: }
3348: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
3349: if (@toclear == 0) {
3350: return &mt('Nothing selected to clear from clipboard');
3351: }
3352: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
3353: if ($numdel) {
3354: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
3355: } else {
3356: return &mt('Clipboard unchanged');
1.492 raeburn 3357: }
1.538 raeburn 3358: return;
3359: }
3360:
3361: sub clear_from_buffer {
3362: my ($toclear,$currpaste) = @_;
3363: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
3364: my %pastebuffer;
3365: map { $pastebuffer{$_} = 1; } @{$currpaste};
3366: my $numdel = 0;
3367: foreach my $suffix (@{$toclear}) {
3368: next if ($suffix =~ /\D/);
3369: next unless (exists($pastebuffer{$suffix}));
3370: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
3371: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
3372: delete($pastebuffer{$suffix});
3373: $numdel ++;
3374: }
3375: }
3376: my $newbuffer = join(',',sort(keys(%pastebuffer)));
3377: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
3378: return $numdel;
1.492 raeburn 3379: }
3380:
1.704 raeburn 3381: sub update_ltitools_caches {
3382: my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
3383: my $hashid=$coursedom.'_'.$coursenum;
3384: if ($updatetoolscache) {
3385: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3386: }
3387: if ((ref($updatetoolsenc) eq 'ARRAY') &&
3388: (@{$updatetoolsenc})) {
3389: my @ids=&Apache::lonnet::current_machine_ids();
3390: my $updatedone;
3391: foreach my $lonhost (@{$updatetoolsenc}) {
3392: if (grep(/^\Q$lonhost\E$/,@ids)) {
3393: unless ($updatedone) {
3394: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
3395: }
3396: $updatedone = 1;
3397: } else {
3398: &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
3399: }
3400: }
3401: }
3402: return;
3403: }
3404:
1.492 raeburn 3405: sub get_newmap_url {
3406: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
3407: $titleref,$allmaps,$newurls) = @_;
3408: my $newurl;
3409: if ($url=~ m{^/uploaded/}) {
3410: $$titleref=&mt('Copy of').' '.$$titleref;
3411: }
3412: my $now = time;
3413: my $suffix=$$.int(rand(100)).$now;
3414: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
3415: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
3416: my $path = $1;
3417: my $prefix = $2;
3418: my $ancestor = $3;
3419: if (length($ancestor) > 10) {
3420: $ancestor = substr($ancestor,-10,10);
3421: }
3422: my $newid;
3423: if ($prefixchg) {
3424: if ($folder =~ /^supplemental/) {
3425: $prefix =~ s/^default/supplemental/;
3426: } else {
3427: $prefix =~ s/^supplemental/default/;
3428: }
3429: }
3430: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3431: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3432: } else {
3433: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
3434: }
3435: my $counter = 0;
3436: my $is_unique = &uniqueness_check($newurl);
3437: if ($folder =~ /^default/) {
3438: if ($allmaps->{$newurl}) {
3439: $is_unique = 0;
3440: }
3441: }
3442: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
3443: $counter ++;
3444: $suffix ++;
3445: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3446: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3447: } else {
3448: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
3449: }
3450: $is_unique = &uniqueness_check($newurl);
3451: }
3452: if ($is_unique) {
3453: $newurls->{$newurl} = 1;
3454: } else {
3455: if ($url=~/\.page$/) {
3456: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
3457: } else {
3458: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
3459: }
3460: }
1.329 droeschl 3461: }
1.492 raeburn 3462: return ($newurl);
1.329 droeschl 3463: }
3464:
1.488 raeburn 3465: sub dbcopy {
1.704 raeburn 3466: my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
3467: $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.533 raeburn 3468: my ($url,$result,$errtext);
3469: if (ref($dbref) eq 'HASH') {
1.596 raeburn 3470: $url = $dbref->{'src'};
1.627 raeburn 3471: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 3472: my $prefix = $1;
1.627 raeburn 3473: if ($prefix eq 'ext.tool') {
3474: $prefix = 'exttool';
3475: }
1.533 raeburn 3476: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3477: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3478: my $db_name;
3479: my $marker = (split(m{/},$url))[4];
3480: $marker=~s/\D//g;
3481: if ($dbref->{'src'} =~ m{/smppg$}) {
3482: $db_name =
3483: &Apache::lonsimplepage::get_db_name($url,$marker,
3484: $dbref->{'cdom'},
3485: $dbref->{'cnum'});
1.627 raeburn 3486: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
3487: $db_name = 'exttool_'.$marker;
1.533 raeburn 3488: } else {
3489: $db_name = 'bulletinpage_'.$marker;
3490: }
3491: my ($suffix,$freedlock,$error) =
3492: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
3493: $coursedom,$coursenum,
3494: 'concat');
3495: if (!$suffix) {
3496: if ($prefix eq 'smppg') {
3497: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 3498: } elsif ($prefix eq 'exttool') {
3499: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 3500: } else {
1.565 bisitz 3501: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 3502: }
3503: if ($error) {
3504: $errtext .= '<br />'.$error;
3505: }
3506: } else {
3507: #need to copy the db contents to a new one.
3508: my %contents=&Apache::lonnet::dump($db_name,
3509: $dbref->{'cdom'},
3510: $dbref->{'cnum'});
1.704 raeburn 3511: my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
3512: if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
3513: if ($contents{'id'} =~ /^(|c)(\d+)$/) {
3514: $oldtoolid = $2;
3515: if ($1 eq 'c') {
3516: $defincrs = 1;
3517: %toolinfo =
3518: &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
3519: } else {
3520: %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
3521: }
3522: if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
3523: if ($toolinfo{$oldtoolid}{'passback'}) {
3524: $toolpassback = 1;
3525: }
3526: if ($toolinfo{$oldtoolid}{'roster'}) {
3527: $toolroster = 1;
3528: }
3529: } else {
3530: $toolcopyerror = 1;
3531: $errtext = &mt('Could not retrieve original settings for pasted external tool.');
3532: }
3533: }
3534: unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
3535: $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
3536: if ($contents{'crstitle'} ne '') {
3537: $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
3538: }
3539: if (($defincrs) && (!$toolcopyerror)) {
3540: my %newtool;
3541: my $oldcdom = $dbref->{'cdom'};
3542: my $oldcnum = $dbref->{'cnum'};
3543: my $title = $toolinfo{$oldtoolid}{'title'};
3544: if (ref($currltititles) eq 'HASH') {
3545: if (exists($currltititles->{$title})) {
3546: $title .= ' (copied from another course)';
3547: }
3548: }
3549: my ($newid,$iderror) =
3550: &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
3551: if ($newid =~ /^\d+$/) {
3552: %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
3553: $newtool{$newid}{'title'} = $title;
3554: if (ref($currltimax)) {
3555: $newtool{$newid}{'order'} = $$currltimax;
3556: }
3557: if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
3558: my $fname = $1;
3559: my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
3560: if ($content eq '-1') {
3561: delete($newtool{$newid}{'image'});
3562: } else {
3563: $env{'form.'.$suffix.'.image'} = $content;
3564: my $newlogo =
3565: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
3566: delete($env{'form.'.$suffix.'.image'});
3567: if ($newlogo =~ m{^/uploaded/}) {
3568: $newtool{$newid}{'image'} = $newlogo;
3569: } else {
3570: delete($newtool{$newid}{'image'});
3571: }
3572: }
3573: }
3574: my $newusable;
3575: if ($same_institution) {
3576: my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
3577: if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
3578: my %newtoolsenc;
3579: %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
3580: my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
3581: if ($putres eq 'ok') {
3582: if (ref($updatetoolsenc) eq 'ARRAY') {
3583: my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
3584: unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
3585: push(@{$updatetoolsenc},$newhome);
3586: }
3587: }
3588: $newusable = 1;
3589: }
3590: }
3591: }
3592: if ($newtool{$newid}{'usable'}) {
3593: unless ($newusable) {
3594: delete($newtool{$newid}{'usable'});
3595: }
3596: }
3597: my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
3598: if ($putres eq 'ok') {
3599: $contents{'id'} = "c$newid";
3600: if (ref($updatetoolscache)) {
3601: $$updatetoolscache ++;
3602: }
3603: if (ref($currltititles->{$title}) eq 'ARRAY') {
3604: push(@{$currltititles->{$title}},$newid);
3605: } else {
3606: $currltititles->{$title} = [$newid];
3607: }
3608: if (ref($currltimax)) {
3609: $$currltimax ++;
3610: }
3611: } else {
3612: $toolcopyerror = 1;
3613: $errtext = &mt('Unable to save external tool definition in Course Settings.');
3614: }
3615: } else {
3616: $toolcopyerror = 1;
3617: $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
3618: }
3619: }
3620: }
3621: }
1.533 raeburn 3622: if (exists($contents{'uploaded.photourl'})) {
3623: my $photo = $contents{'uploaded.photourl'};
3624: my ($subdir,$fname) =
3625: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 3626: my $newphoto;
1.533 raeburn 3627: if ($fname ne '') {
3628: my $content = &Apache::lonnet::getfile($photo);
3629: unless ($content eq '-1') {
3630: $env{'form.'.$suffix.'.photourl'} = $content;
3631: $newphoto =
3632: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
3633: delete($env{'form.'.$suffix.'.photourl'});
3634: }
3635: }
3636: if ($newphoto =~ m{^/uploaded/}) {
3637: $contents{'uploaded.photourl'} = $newphoto;
3638: }
3639: }
3640: $db_name =~ s{_\d*$ }{_$suffix}x;
1.704 raeburn 3641: if ($prefix eq 'exttool') {
3642: unless ($toolcopyerror) {
3643: foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
3644: if (exists($contents{$key})) {
3645: delete($contents{$key});
3646: }
3647: }
3648: if ($dbref->{'delgradable'}) {
3649: if (exists($contents{'gradable'})) {
3650: delete($contents{'gradable'});
3651: }
3652: }
3653: if ($toolpassback) {
3654: if ($contents{'gradable'}) {
3655: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3656: $contents{'gradesecret'} = $gradesecret;
3657: $contents{'gradesecretdate'} = time;
3658: }
3659: }
3660: if ($toolroster) {
3661: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3662: $contents{'rostersecret'} = $rostersecret;
3663: $contents{'rostersecretdate'} = time;
3664: }
3665: }
1.649 raeburn 3666: }
1.704 raeburn 3667: if (($prefix eq 'exttool') && ($toolcopyerror)) {
3668: $result = 'error';
3669: } else {
3670: $result=&Apache::lonnet::put($db_name,\%contents,
3671: $coursedom,$coursenum);
3672: if ($result eq 'ok') {
3673: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
3674: }
1.533 raeburn 3675: }
3676: }
3677: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 3678: $lockerrorsref->{$prefix} =
1.533 raeburn 3679: '<div class="LC_error">'.
3680: &mt('There was a problem removing a lockfile.');
3681: if ($prefix eq 'smppg') {
1.560 raeburn 3682: $lockerrorsref->{$prefix} .=
1.559 raeburn 3683: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 3684: } elsif ($prefix eq 'exttool') {
3685: $lockerrorsref->{$prefix} .=
3686: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 3687: } else {
1.565 bisitz 3688: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 3689: }
1.560 raeburn 3690: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
3691: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
3692: '</div>';
1.533 raeburn 3693: }
3694: }
3695: } elsif ($url =~ m{/syllabus$}) {
3696: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3697: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3698: if (($dbref->{'cdom'} ne $coursedom) ||
3699: ($dbref->{'cnum'} ne $coursenum)) {
3700: my %contents=&Apache::lonnet::dump('syllabus',
3701: $dbref->{'cdom'},
3702: $dbref->{'cnum'});
3703: $result=&Apache::lonnet::put('syllabus',\%contents,
3704: $coursedom,$coursenum);
3705: }
3706: }
1.488 raeburn 3707: }
3708: }
1.533 raeburn 3709: return ($url,$result,$errtext);
1.488 raeburn 3710: }
3711:
1.597 raeburn 3712: sub copy_templated_files {
3713: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
3714: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
3715: my $srccontainer = 'sequence';
3716: if ($srcwaspage) {
3717: $srccontainer = 'page';
3718: }
3719: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
3720: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
3721: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
3722: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
3723: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
3724: $template.'.problem';
3725: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
3726: if ($template eq 'simpleproblem') {
3727: $srcprefix .= '.0.';
3728: my $weightprefix = $newprefix;
3729: $newprefix .= '.0.';
3730: my @simpleprobqtypes = qw(radio option string essay numerical);
3731: my $qtype=$srcparms{$srcprefix.'questiontype'};
3732: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 3733: my %newdata = (
3734: $newprefix.'questiontype' => $qtype,
3735: );
1.597 raeburn 3736: foreach my $type (@simpleprobqtypes) {
3737: if ($type eq $qtype) {
3738: $newdata{"$weightprefix.$type.weight"}=1;
3739: } else {
3740: $newdata{"$weightprefix.$type.weight"}=0;
3741: }
3742: }
3743: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
3744: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
3745: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
3746: if ($qtype eq 'numerical') {
3747: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
3748: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
3749: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
3750: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
3751: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3752: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3753: unless (defined($maxfoils)) { $maxfoils=10; }
3754: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3755: if ($maxfoils<=0) { $maxfoils=10; }
3756: my $randomize=$srcparms{$srcprefix.'randomize'};
3757: unless (defined($randomize)) { $randomize='yes'; }
3758: unless ($randomize eq 'no') { $randomize='yes'; }
3759: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3760: $newdata{$newprefix.'randomize'} = $randomize;
3761: if ($qtype eq 'option') {
3762: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3763: }
3764: for (my $i=1; $i<=10; $i++) {
3765: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3766: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3767: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3768: }
3769:
3770: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3771: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3772: unless (defined($maxfoils)) { $maxfoils=10; }
3773: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3774: if ($maxfoils<=0) { $maxfoils=10; }
3775: my $randomize=$srcparms{$srcprefix.'randomize'};
3776: unless (defined($randomize)) { $randomize='yes'; }
3777: unless ($randomize eq 'no') { $randomize='yes'; }
3778: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3779: $newdata{$newprefix.'randomize'} = $randomize;
3780: if ($qtype eq 'option') {
3781: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3782: }
3783: for (my $i=1; $i<=10; $i++) {
3784: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3785: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3786: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3787: }
3788: } elsif ($qtype eq 'string') {
3789: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
3790: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
3791: }
3792: if (keys(%newdata)) {
3793: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
3794: $coursenum);
3795: if ($putres eq 'ok') {
3796: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
3797: }
3798: }
3799: }
3800: }
3801: }
3802:
1.329 droeschl 3803: sub uniqueness_check {
3804: my ($newurl) = @_;
3805: my $unique = 1;
3806: foreach my $res (@LONCAPA::map::order) {
3807: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3808: $url=&LONCAPA::map::qtescape($url);
3809: if ($newurl eq $url) {
3810: $unique = 0;
1.344 bisitz 3811: last;
1.329 droeschl 3812: }
3813: }
3814: return $unique;
3815: }
3816:
1.488 raeburn 3817: sub contained_map_check {
1.627 raeburn 3818: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
3819: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 3820: my $content = &Apache::lonnet::getfile($url);
3821: unless ($content eq '-1') {
3822: my $parser = HTML::TokeParser->new(\$content);
3823: $parser->attr_encoded(1);
3824: while (my $token = $parser->get_token) {
3825: next if ($token->[0] ne 'S');
3826: if ($token->[1] eq 'resource') {
3827: next if ($token->[2]->{'type'} eq 'zombie');
3828: my $ressrc = $token->[2]->{'src'};
1.704 raeburn 3829: if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
3830: my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
1.627 raeburn 3831: unless ($srcdom eq $coursedom) {
3832: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3833: next;
3834: }
1.704 raeburn 3835: unless ($srcnum eq $coursenum) {
3836: my %toolsettings =
3837: &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
3838: my %tooltypes = &Apache::loncommon::usable_exttools();
3839: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
3840: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
3841: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3842: next;
3843: }
3844: }
1.627 raeburn 3845: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 3846: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 3847: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 3848: next;
3849: }
3850: }
1.703 raeburn 3851: if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
3852: my ($srcdom,$srcnum) = ($1,$2);
3853: unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
3854: if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
3855: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3856: next;
3857: }
3858: }
3859: }
1.492 raeburn 3860: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
3861: if ($1 eq 'uploaded') {
3862: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
3863: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 3864: } else {
1.492 raeburn 3865: if ($allmaps->{$ressrc}) {
1.529 raeburn 3866: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 3867: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
3868: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3869: } else {
3870: $addedmaps->{$ressrc} = [$url];
3871: }
1.488 raeburn 3872: }
1.627 raeburn 3873: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
3874: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 3875: }
1.492 raeburn 3876: } elsif ($token->[1] eq 'param') {
1.488 raeburn 3877: if ($folder =~ /^supplemental/) {
1.492 raeburn 3878: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
3879: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
3880: } else {
3881: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
3882: }
1.488 raeburn 3883: }
3884: }
3885: }
3886: }
3887: return;
3888: }
3889:
3890: sub url_paste_fixups {
1.533 raeburn 3891: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
3892: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 3893: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 3894: my $checktitle;
3895: if (($prefixchg) &&
1.492 raeburn 3896: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 3897: $checktitle = 1;
3898: }
1.492 raeburn 3899: my $skip;
3900: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
3901: my $mapid = $1.$2;
3902: if ($tomove->{$mapid}) {
3903: $skip = 1;
3904: }
3905: }
1.491 raeburn 3906: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 3907: return if ($file eq '-1');
3908: my $parser = HTML::TokeParser->new(\$file);
3909: $parser->attr_encoded(1);
1.491 raeburn 3910: my $changed = 0;
1.488 raeburn 3911: while (my $token = $parser->get_token) {
3912: next if ($token->[0] ne 'S');
3913: if ($token->[1] eq 'resource') {
3914: my $ressrc = $token->[2]->{'src'};
3915: next if ($ressrc eq '');
1.491 raeburn 3916: my $id = $token->[2]->{'id'};
1.492 raeburn 3917: my $title = $token->[2]->{'title'};
1.491 raeburn 3918: if ($checktitle) {
3919: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 3920: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3921: }
3922: }
1.488 raeburn 3923: next if ($token->[2]->{'type'} eq 'external');
3924: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 3925: next if ($skip);
1.532 raeburn 3926: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3927: $changed = 1;
3928: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3929: my $srcdom = $1;
3930: my $srcnum = $2;
1.488 raeburn 3931: my $rem = $3;
1.492 raeburn 3932: my $newurl;
3933: my $mapname;
3934: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
3935: my $prefix = $1;
3936: $mapname = $prefix.$2;
3937: if ($tomove->{$mapname}) {
1.533 raeburn 3938: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
3939: $srcdom,$srcnum,$allmaps,$rewrites,
3940: $retitles,$copies,$dbcopies,$zombies,
3941: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 3942: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 3943: next;
3944: } else {
3945: ($newurl,my $error) =
3946: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
3947: $srcdom,$srcnum,\$title,$allmaps,$newurls);
3948: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
3949: $newsubdir->{$ressrc} = $1;
3950: }
3951: if ($error) {
3952: next;
3953: }
3954: }
3955: }
3956: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
3957: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
3958:
1.488 raeburn 3959: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 3960: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3961: $mapchanges->{$ressrc} = 1;
1.533 raeburn 3962: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
3963: $cnum,$srcdom,$srcnum,$allmaps,
3964: $rewrites,$retitles,$copies,$dbcopies,
3965: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 3966: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 3967: $mapmoves->{$ressrc} = 1;
3968: }
3969: $changed = 1;
1.488 raeburn 3970: } else {
1.532 raeburn 3971: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 3972: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 3973: $changed = 1;
1.488 raeburn 3974: }
3975: }
1.649 raeburn 3976: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 3977: next if ($skip);
1.492 raeburn 3978: my $srcdom = $1;
3979: my $srcnum = $2;
1.649 raeburn 3980: my $rem = $3;
3981: my ($is_exttool,$exttoolchg);
3982: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 3983: $is_exttool = 1;
1.649 raeburn 3984: }
1.492 raeburn 3985: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 3986: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 3987: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3988: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3989: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3990: $changed = 1;
1.649 raeburn 3991: if ($is_exttool) {
3992: $exttoolchg = 1;
3993: }
1.700 raeburn 3994: } elsif (($is_exttool) &&
1.649 raeburn 3995: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3996: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3997: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3998: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3999: $changed = 1;
4000: $exttoolchg = 1;
4001: }
4002: if (($is_exttool) && ($prefixchg)) {
4003: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
4004: if ($exttoolchg) {
4005: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
4006: }
4007: }
1.533 raeburn 4008: }
4009: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
4010: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
4011: ($env{'form.docs.markedcopy_options'} ne 'move')) {
4012: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
4013: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
4014: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 4015: $changed = 1;
1.488 raeburn 4016: }
1.597 raeburn 4017: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
4018: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
4019: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
4020: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
4021: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
4022: }
1.488 raeburn 4023: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 4024: next if ($skip);
4025: my $srcdom = $1;
4026: my $srcnum = $2;
4027: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 4028: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
4029: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
4030: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 4031: $changed = 1;
1.488 raeburn 4032: }
4033: }
4034: } elsif ($token->[1] eq 'param') {
1.492 raeburn 4035: next if ($skip);
1.488 raeburn 4036: my $to = $token->[2]->{'to'};
4037: if ($to ne '') {
4038: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 4039: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 4040: } else {
4041: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
4042: }
4043: }
4044: }
4045: }
1.491 raeburn 4046: return $changed;
1.488 raeburn 4047: }
4048:
4049: sub apply_fixups {
1.529 raeburn 4050: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
4051: $oldurl,$url,$caller) = @_;
4052: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 4053: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.704 raeburn 4054: %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
4055: %currltititles,$currltimax);
4056: $currltimax = 0;
1.529 raeburn 4057: if (ref($updated) eq 'HASH') {
4058: if (ref($updated->{'rewrites'}) eq 'HASH') {
4059: %rewrites = %{$updated->{'rewrites'}};
4060: }
4061: if (ref($updated->{'zombies'}) eq 'HASH') {
4062: %zombies = %{$updated->{'zombies'}};
4063: }
4064: if (ref($updated->{'removefrommap'}) eq 'HASH') {
4065: %removefrommap = %{$updated->{'removefrommap'}};
4066: }
4067: if (ref($updated->{'removeparam'}) eq 'HASH') {
4068: %removeparam = %{$updated->{'removeparam'}};
4069: }
4070: if (ref($updated->{'dbcopies'}) eq 'HASH') {
4071: %dbcopies = %{$updated->{'dbcopies'}};
4072: }
4073: if (ref($updated->{'retitles'}) eq 'HASH') {
4074: %retitles = %{$updated->{'retitles'}};
4075: }
1.597 raeburn 4076: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
4077: %resdatacopy = %{$updated->{'resdatacopy'}};
4078: }
1.529 raeburn 4079: }
4080: if (ref($info) eq 'HASH') {
4081: if (ref($info->{'newsubdir'}) eq 'HASH') {
4082: %newsubdir = %{$info->{'newsubdir'}};
4083: }
4084: if (ref($info->{'params'}) eq 'HASH') {
4085: %params = %{$info->{'params'}};
4086: }
4087: if (ref($info->{'before'}) eq 'HASH') {
4088: %before = %{$info->{'before'}};
4089: }
4090: if (ref($info->{'after'}) eq 'HASH') {
4091: %after = %{$info->{'after'}};
4092: }
4093: }
4094: if (ref($moves) eq 'HASH') {
4095: if (ref($moves->{'copies'}) eq 'HASH') {
4096: %copies = %{$moves->{'copies'}};
4097: }
4098: if (ref($moves->{'docmoves'}) eq 'HASH') {
4099: %docmoves = %{$moves->{'docmoves'}};
4100: }
4101: if (ref($moves->{'mapmoves'}) eq 'HASH') {
4102: %mapmoves = %{$moves->{'mapmoves'}};
4103: }
4104: }
4105: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 4106: my @allcopies;
1.529 raeburn 4107: if (exists($copies{$key})) {
4108: if (ref($copies{$key}) eq 'HASH') {
4109: my %added;
4110: foreach my $innerkey (keys(%{$copies{$key}})) {
4111: if (($innerkey ne '') && (!$added{$innerkey})) {
4112: push(@allcopies,$innerkey);
4113: $added{$innerkey} = 1;
4114: }
1.491 raeburn 4115: }
1.529 raeburn 4116: undef(%added);
1.491 raeburn 4117: }
4118: }
4119: if ($key eq $oldurl) {
1.529 raeburn 4120: if ((exists($docmoves{$key}))) {
1.532 raeburn 4121: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 4122: push(@allcopies,$oldurl);
4123: }
4124: }
4125: }
4126: if (@allcopies > 0) {
4127: foreach my $item (@allcopies) {
1.492 raeburn 4128: my ($relpath,$oldsubdir,$fname) =
4129: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 4130: if ($fname ne '') {
4131: my $content = &Apache::lonnet::getfile($item);
4132: unless ($content eq '-1') {
4133: my $storefn;
1.529 raeburn 4134: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
4135: $storefn = $docmoves{$key};
1.491 raeburn 4136: } else {
4137: $storefn = $relpath;
4138: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4139: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
4140: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 4141: }
1.529 raeburn 4142: if ($newsubdir{$key}) {
1.532 raeburn 4143: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 4144: }
4145: }
4146: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
4147: my $copyurl =
4148: &Apache::lonclonecourse::writefile($env{'request.course.id'},
4149: $storefn.$fname,$content);
4150: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 4151: if (exists($docmoves{$oldurl})) {
1.491 raeburn 4152: return &mt('Paste failed: an error occurred copying the file.');
4153: } elsif (ref($errors) eq 'HASH') {
4154: $errors->{$item} = 1;
1.489 raeburn 4155: }
4156: }
1.488 raeburn 4157: }
4158: }
1.491 raeburn 4159: }
4160: }
4161: }
1.529 raeburn 4162: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 4163: my $storefn=$key;
4164: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4165: if ($prefixchg && $before{'map'} && $after{'map'}) {
4166: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 4167: }
1.529 raeburn 4168: if ($newsubdir{$key}) {
4169: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 4170: }
1.491 raeburn 4171: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 4172: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
4173: ($after{'map'} eq 'default') &&
4174: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
4175: $mapcontent = '<map>'."\n".
4176: '<resource id="1" src="" type="start" />'."\n".
4177: '<link from="1" to="2" index="1" />'."\n".
4178: '<resource id="2" src="" type="finish" />'."\n".
4179: '</map>';
4180: }
1.491 raeburn 4181: if ($mapcontent eq '-1') {
4182: if (ref($errors) eq 'HASH') {
4183: $errors->{$key} = 1;
4184: }
4185: } else {
4186: my $newmap =
4187: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
4188: $mapcontent);
4189: if ($newmap eq '/adm/notfound.html') {
4190: if (ref($errors) eq 'HASH') {
4191: $errors->{$key} = 1;
1.489 raeburn 4192: }
1.488 raeburn 4193: }
4194: }
4195: }
1.491 raeburn 4196: my %updates;
4197: if ($is_map) {
1.529 raeburn 4198: if (ref($updated) eq 'HASH') {
4199: foreach my $type (keys(%{$updated})) {
4200: if (ref($updated->{$type}) eq 'HASH') {
4201: foreach my $key (keys(%{$updated->{$type}})) {
4202: $updates{$key} = 1;
4203: }
4204: }
4205: }
1.491 raeburn 4206: }
1.704 raeburn 4207: my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.491 raeburn 4208: foreach my $key (keys(%updates)) {
1.492 raeburn 4209: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 4210: if (ref($rewrites{$key}) eq 'HASH') {
4211: %torewrite = %{$rewrites{$key}};
1.491 raeburn 4212: }
1.529 raeburn 4213: if (ref($retitles{$key}) eq 'HASH') {
4214: %toretitle = %{$retitles{$key}};
1.491 raeburn 4215: }
1.529 raeburn 4216: if (ref($removefrommap{$key}) eq 'HASH') {
4217: %toremove = %{$removefrommap{$key}};
1.491 raeburn 4218: }
1.529 raeburn 4219: if (ref($removeparam{$key}) eq 'HASH') {
4220: %remparam = %{$removeparam{$key}};
1.492 raeburn 4221: }
1.529 raeburn 4222: if (ref($zombies{$key}) eq 'HASH') {
4223: %zombie = %{$zombies{$key}};
1.491 raeburn 4224: }
1.529 raeburn 4225: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 4226: foreach my $idx (keys(%{$dbcopies{$key}})) {
4227: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.704 raeburn 4228: my $oldurl = $dbcopies{$key}{$idx}{'src'};
4229: my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
4230: my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
4231: my $oldmarker;
4232: if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
4233: $oldmarker = $1;
4234: unless (($gotcrsltitools) ||
4235: (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
4236: my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
4237: if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
4238: unless ($gotcrsltitools) {
4239: %currcrsltitools =
4240: &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
4241: foreach my $item (sort(keys(%currcrsltitools))) {
4242: if (ref($currcrsltitools{$item}) eq 'HASH') {
4243: $currltimax ++;
4244: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
4245: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
4246: } else {
4247: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
4248: }
4249: }
4250: }
4251: $gotcrsltitools = 1;
4252: }
4253: unless ($checkedsameinst) {
4254: my $primary_id = &Apache::lonnet::domain($cdom,'primary');
4255: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4256: if ($intdom ne '') {
4257: my $internet_names =
4258: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4259: if (ref($internet_names) eq 'ARRAY') {
4260: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4261: $same_institution = 1;
4262: }
4263: }
4264: }
4265: $checkedsameinst = 1;
4266: }
4267: }
4268: }
4269: }
1.533 raeburn 4270: my ($newurl,$result,$errtext) =
1.704 raeburn 4271: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
4272: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.533 raeburn 4273: if ($result eq 'ok') {
4274: $newdb{$idx} = $newurl;
1.704 raeburn 4275: if ($newurl =~ /ext\.tool$/) {
4276: if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
4277: if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
4278: my $newmarker = $1;
4279: unless ($oldmarker eq $newmarker) {
4280: $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
4281: }
4282: }
4283: }
4284: }
1.533 raeburn 4285: } elsif (ref($errors) eq 'HASH') {
4286: $errors->{$key} = 1;
4287: }
4288: push(@msgs,$errtext);
4289: }
1.491 raeburn 4290: }
4291: }
1.597 raeburn 4292: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 4293: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 4294: foreach my $idx (keys(%{$resdatacopy{$key}})) {
4295: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
4296: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
4297: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
4298: my $template = $1;
4299: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
4300: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
4301: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
4302: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 4303: unless ($gotnewmapname) {
4304: ($newmapname) = ($key =~ m{/([^/]+)$});
4305: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
4306: if ($newsubdir{$key}) {
4307: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
4308: }
4309: $gotnewmapname = 1;
4310: }
1.597 raeburn 4311: my $srcmapinfo = $srcfolder.':'.$idx;
4312: if ($srccontainer eq 'page') {
4313: $srcmapinfo .= ':1';
4314: }
4315: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
4316: $cnum,$template,$idx,$newmapname);
4317: }
4318: }
4319: }
4320: }
4321: }
1.529 raeburn 4322: if (ref($params{$key}) eq 'HASH') {
4323: %currparam = %{$params{$key}};
1.492 raeburn 4324: }
4325: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
4326: if ($fatal) {
1.533 raeburn 4327: return ($errtext);
1.492 raeburn 4328: }
4329: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
4330: if (defined($LONCAPA::map::zombies[$i])) {
4331: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 4332: if ($zombie{$i} eq $src) {
1.492 raeburn 4333: undef($LONCAPA::map::zombies[$i]);
4334: }
4335: }
4336: }
1.646 raeburn 4337: my $total = scalar(@LONCAPA::map::order) - 1;
4338: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 4339: my $idx = $LONCAPA::map::order[$i];
4340: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 4341: my $changed;
1.529 raeburn 4342: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 4343: if ((exists($toremove{$idx})) &&
4344: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 4345: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 4346: if (ref($currparam{$idx}) eq 'ARRAY') {
4347: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 4348: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 4349: }
4350: }
4351: next;
4352: }
4353: my $origsrc = $src;
1.532 raeburn 4354: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 4355: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
4356: $changed = 1;
1.491 raeburn 4357: }
1.492 raeburn 4358: }
1.532 raeburn 4359: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 4360: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
4361: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 4362: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 4363: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 4364: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 4365: } else {
1.529 raeburn 4366: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 4367: }
1.491 raeburn 4368: }
1.532 raeburn 4369: if ($origsrc =~ /\.(page|sequence)$/) {
4370: if ($newsubdir{$origsrc}) {
1.529 raeburn 4371: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 4372: }
1.532 raeburn 4373: } elsif ($newsubdir{$key}) {
4374: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 4375: }
4376: }
1.492 raeburn 4377: $changed = 1;
1.533 raeburn 4378: } elsif ($newdb{$idx} ne '') {
4379: $src = $newdb{$idx};
1.492 raeburn 4380: $changed = 1;
4381: }
4382: if ($changed) {
1.538 raeburn 4383: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 4384: }
4385: }
4386: }
4387: foreach my $idx (keys(%remparam)) {
4388: if (ref($remparam{$idx}) eq 'ARRAY') {
4389: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 4390: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 4391: }
4392: }
4393: }
1.533 raeburn 4394: if (values(%lockerrors) > 0) {
4395: $lockmsg = join('<br />',values(%lockerrors));
4396: }
1.491 raeburn 4397: my $storefn;
4398: if ($key eq $oldurl) {
4399: $storefn = $url;
4400: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
4401: } else {
4402: $storefn = $key;
4403: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4404: if ($prefixchg && $before{'map'} && $after{'map'}) {
4405: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 4406: }
1.529 raeburn 4407: if ($newsubdir{$key}) {
4408: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 4409: }
1.491 raeburn 4410: }
1.492 raeburn 4411: my $report;
4412: if ($folder !~ /^supplemental/) {
4413: $report = 1;
4414: }
1.527 raeburn 4415: (my $outtext,$errtext) =
1.492 raeburn 4416: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
4417: if ($errtext) {
1.529 raeburn 4418: if ($caller eq 'paste') {
1.533 raeburn 4419: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 4420: }
1.491 raeburn 4421: }
4422: }
1.704 raeburn 4423: if (($updatetoolscache) || (@updatetoolsenc)) {
4424: &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
4425: \@updatetoolsenc);
4426: }
1.491 raeburn 4427: }
1.533 raeburn 4428: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 4429: }
4430:
4431: sub copy_dependencies {
4432: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
4433: my $content;
4434: if (ref($contentref)) {
4435: $content = $$contentref;
4436: } else {
4437: $content = &Apache::lonnet::getfile($item);
4438: }
4439: unless ($content eq '-1') {
4440: my $mm = new File::MMagic;
4441: my $mimetype = $mm->checktype_contents($content);
4442: if ($mimetype eq 'text/html') {
4443: my (%allfiles,%codebase,$state);
4444: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
4445: if ($res eq 'ok') {
4446: my ($numexisting,$numpathchanges,$existing);
4447: (undef,$numexisting,$numpathchanges,$existing) =
4448: &Apache::loncommon::ask_for_embedded_content(
4449: '/adm/coursedocs',$state,\%allfiles,\%codebase,
4450: {'error_on_invalid_names' => 1,
4451: 'ignore_remote_references' => 1,
4452: 'docs_url' => $item,
4453: 'context' => 'paste'});
4454: if ($numexisting > 0) {
4455: if (ref($existing) eq 'HASH') {
4456: foreach my $dep (keys(%{$existing})) {
4457: my $depfile = $dep;
4458: unless ($depfile =~ m{^\Q$relpath\E}) {
4459: $depfile = $relpath.$dep;
4460: }
4461: my $depcontent = &Apache::lonnet::getfile($depfile);
4462: unless ($depcontent eq '-1') {
4463: my $storedep = $dep;
4464: $storedep =~ s{^\Q$relpath\E}{};
4465: my $dep_url =
4466: &Apache::lonclonecourse::writefile(
4467: $env{'request.course.id'},
4468: $storefn.$storedep,$depcontent);
4469: if ($dep_url eq '/adm/notfound.html') {
4470: if (ref($errors) eq 'HASH') {
4471: $errors->{$depfile} = 1;
4472: }
4473: } else {
4474: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
4475: }
4476: }
4477: }
1.488 raeburn 4478: }
4479: }
4480: }
4481: }
4482: }
4483: return;
4484: }
4485:
1.329 droeschl 4486: my %parameter_type = ( 'randompick' => 'int_pos',
4487: 'hiddenresource' => 'string_yesno',
4488: 'encrypturl' => 'string_yesno',
4489: 'randomorder' => 'string_yesno',);
4490: my $valid_parameters_re = join('|',keys(%parameter_type));
4491: # set parameters
4492: sub update_parameter {
1.537 raeburn 4493: if ($env{'form.changeparms'} eq 'all') {
4494: my (@allidx,@allmapidx,%allchecked,%currchecked);
4495: %allchecked = (
4496: 'hiddenresource' => {},
4497: 'encrypturl' => {},
4498: 'randompick' => {},
4499: 'randomorder' => {},
4500: );
4501: foreach my $which (keys(%allchecked)) {
1.630 raeburn 4502: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 4503: if ($which eq 'randompick') {
4504: foreach my $item (split(/,/,$env{'form.all'.$which})) {
4505: my ($res,$value) = split(/:/,$item);
4506: if ($value =~ /^\d+$/) {
4507: $allchecked{$which}{$res} = $value;
4508: }
4509: }
4510: } else {
1.539 raeburn 4511: if ($env{'form.all'.$which}) {
4512: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
4513: }
1.537 raeburn 4514: }
4515: }
4516: my $haschanges = 0;
4517: foreach my $res (@LONCAPA::map::order) {
4518: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4519: $name=&LONCAPA::map::qtescape($name);
4520: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 4521: next unless $url;
1.537 raeburn 4522: my $is_map;
4523: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4524: $is_map = 1;
4525: }
4526: foreach my $which (keys(%allchecked)) {
4527: if (($which eq 'randompick' || $which eq 'randomorder')) {
4528: next if (!$is_map);
4529: }
4530: my $oldvalue = 0;
4531: my $newvalue = 0;
4532: if ($allchecked{$which}{$res}) {
4533: $newvalue = $allchecked{$which}{$res};
4534: }
4535: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
4536: if ($which eq 'randompick') {
4537: if ($current =~ /^(\d+)$/) {
4538: $oldvalue = $1;
4539: }
4540: } else {
4541: if ($current =~ /^yes$/i) {
4542: $oldvalue = 1;
4543: }
4544: }
4545: if ($oldvalue ne $newvalue) {
4546: $haschanges = 1;
4547: if ($newvalue) {
4548: my $storeval = 'yes';
4549: if ($which eq 'randompick') {
4550: $storeval = $newvalue;
4551: }
4552: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
4553: $storeval,
4554: $parameter_type{$which});
4555: &remember_parms($res,$which,'set',$storeval);
4556: } elsif ($oldvalue) {
4557: &LONCAPA::map::delparameter($res,'parameter_'.$which);
4558: &remember_parms($res,$which,'del');
4559: }
4560: }
4561: }
4562: }
4563: return $haschanges;
4564: } else {
1.588 raeburn 4565: my $haschanges = 0;
4566: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 4567:
1.537 raeburn 4568: my $which = $env{'form.changeparms'};
4569: my $idx = $env{'form.setparms'};
1.588 raeburn 4570: my $oldvalue = 0;
4571: my $newvalue = 0;
4572: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
4573: if ($which eq 'randompick') {
4574: if ($current =~ /^(\d+)$/) {
4575: $oldvalue = $1;
4576: }
4577: } elsif ($current =~ /^yes$/i) {
4578: $oldvalue = 1;
4579: }
1.537 raeburn 4580: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 4581: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
4582: : 1;
4583: }
4584: if ($oldvalue ne $newvalue) {
4585: $haschanges = 1;
4586: if ($newvalue) {
4587: my $storeval = 'yes';
4588: if ($which eq 'randompick') {
4589: $storeval = $newvalue;
4590: }
4591: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
4592: $parameter_type{$which});
4593: &remember_parms($idx,$which,'set',$storeval);
4594: } else {
4595: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
4596: &remember_parms($idx,$which,'del');
4597: }
1.537 raeburn 4598: }
1.588 raeburn 4599: return $haschanges;
1.329 droeschl 4600: }
4601: }
4602:
4603: sub handle_edit_cmd {
4604: my ($coursenum,$coursedom) =@_;
1.633 raeburn 4605: my $haschanges = 0;
1.543 raeburn 4606: if ($env{'form.cmd'} eq '') {
1.633 raeburn 4607: return $haschanges;
1.543 raeburn 4608: }
1.329 droeschl 4609: my ($cmd,$idx)=split('_',$env{'form.cmd'});
4610:
4611: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
4612: my ($title, $url, @rrest) = split(':', $ratstr);
4613:
1.538 raeburn 4614: if ($cmd eq 'remove') {
1.329 droeschl 4615: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 4616: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 4617: &Apache::lonnet::removeuploadedurl($url);
4618: } else {
4619: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4620: }
4621: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4622: $haschanges = 1;
1.329 droeschl 4623: } elsif ($cmd eq 'cut') {
4624: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4625: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4626: $haschanges = 1;
1.344 bisitz 4627: } elsif ($cmd eq 'up'
1.329 droeschl 4628: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
4629: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 4630: $haschanges = 1;
1.329 droeschl 4631: } elsif ($cmd eq 'down'
4632: && defined($LONCAPA::map::order[$idx+1])) {
4633: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 4634: $haschanges = 1;
1.329 droeschl 4635: } elsif ($cmd eq 'rename') {
4636: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
4637: if ($comment=~/\S/) {
4638: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
4639: $comment.':'.join(':', $url, @rrest);
4640: }
4641: # Devalidate title cache
4642: my $renamed_url=&LONCAPA::map::qtescape($url);
4643: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 4644: $haschanges = 1;
4645: } elsif ($cmd eq 'setalias') {
4646: my $newvalue = $env{'form.alias'};
4647: if ($newvalue ne '') {
4648: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
4649: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
4650: 'string');
4651: &remember_parms($idx,'mapalias','set',$newvalue);
4652: $haschanges = 1;
4653: }
4654: }
4655: } elsif ($cmd eq 'delalias') {
4656: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
4657: if ($current ne '') {
4658: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
4659: &remember_parms($idx,'mapalias','del');
4660: $haschanges = 1;
4661: }
1.329 droeschl 4662: }
1.633 raeburn 4663: return $haschanges;
1.329 droeschl 4664: }
4665:
4666: sub editor {
1.458 raeburn 4667: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 4668: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 4669: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 4670: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 4671: if ($allowed) {
1.519 raeburn 4672: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
4673: $is_random_order,$container) =
1.510 raeburn 4674: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
4675: $r->print($breadcrumbtrail);
1.519 raeburn 4676: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
4677: $container = 'page';
4678: } else {
4679: $container = 'sequence';
1.510 raeburn 4680: }
1.484 raeburn 4681:
1.525 raeburn 4682: my $jumpto;
4683:
4684: unless ($supplementalflag) {
1.546 raeburn 4685: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 4686: }
1.484 raeburn 4687:
4688: unless ($allowed) {
4689: $randompick = -1;
4690: }
4691:
1.615 raeburn 4692: my ($errtext,$fatal);
4693: if (($folder eq '') && (!$supplementalflag)) {
4694: if (@LONCAPA::map::order) {
4695: undef(@LONCAPA::map::order);
4696: undef(@LONCAPA::map::resources);
4697: undef(@LONCAPA::map::resparms);
4698: undef(@LONCAPA::map::zombies);
4699: }
4700: $folder = 'default';
4701: $container = 'sequence';
4702: } else {
4703: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
4704: $folder.'.'.$container);
4705: return $errtext if ($fatal);
4706: }
1.329 droeschl 4707:
4708: if ($#LONCAPA::map::order<1) {
4709: my $idx=&LONCAPA::map::getresidx();
4710: if ($idx<=0) { $idx=1; }
4711: $LONCAPA::map::order[0]=$idx;
4712: $LONCAPA::map::resources[$idx]='';
4713: }
1.364 bisitz 4714:
1.329 droeschl 4715: # ------------------------------------------------------------ Process commands
4716:
4717: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 4718: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 4719: # set parameters and change order
4720: &snapshotbefore();
4721:
4722: if (&update_parameter()) {
1.588 raeburn 4723: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 4724: return $errtext if ($fatal);
4725: }
4726:
4727: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
4728: # change order
4729: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
4730: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
4731:
4732: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
4733: return $errtext if ($fatal);
4734: }
1.364 bisitz 4735:
1.329 droeschl 4736: if ($env{'form.pastemarked'}) {
1.491 raeburn 4737: my %paste_errors;
1.533 raeburn 4738: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 4739: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
4740: \%paste_errors);
1.541 raeburn 4741: if (ref($pastemsgarray) eq 'ARRAY') {
4742: if (@{$pastemsgarray} > 0) {
4743: $r->print('<p class="LC_info">'.
4744: join('<br />',@{$pastemsgarray}).
1.533 raeburn 4745: '</p>');
4746: }
1.541 raeburn 4747: }
4748: if ($lockerror) {
4749: $r->print('<p class="LC_error">'.
4750: $lockerror.
4751: '</p>');
4752: }
4753: if ($save_error ne '') {
4754: return $save_error;
4755: }
4756: if ($paste_res) {
4757: my %errortext = &Apache::lonlocal::texthash (
4758: fail => 'Storage of folder contents failed',
4759: failread => 'Reading folder contents failed',
4760: failstore => 'Storage of folder contents failed',
4761: );
4762: if ($errortext{$paste_res}) {
4763: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 4764: }
1.329 droeschl 4765: }
1.491 raeburn 4766: if (keys(%paste_errors) > 0) {
1.538 raeburn 4767: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 4768: &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".
4769: '<ul>'."\n");
4770: foreach my $key (sort(keys(%paste_errors))) {
4771: $r->print('<li>'.$key.'</li>'."\n");
4772: }
4773: $r->print('</ul></p>'."\n");
4774: }
1.538 raeburn 4775: } elsif ($env{'form.clearmarked'}) {
4776: my $output = &do_buffer_empty();
4777: if ($output) {
4778: $r->print('<p class="LC_info">'.$output.'</p>');
4779: }
4780: }
1.329 droeschl 4781:
4782: $r->print($upload_output);
4783:
1.538 raeburn 4784: # Rename, cut, copy or remove a single resource
1.602 raeburn 4785: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 4786: my $contentchg;
1.633 raeburn 4787: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 4788: $contentchg = 1;
4789: }
4790: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 4791: return $errtext if ($fatal);
4792: }
1.538 raeburn 4793:
4794: # Cut, copy and/or remove multiple resources
4795: if ($env{'form.multichange'}) {
4796: my %allchecked = (
4797: cut => {},
4798: remove => {},
4799: );
4800: my $needsupdate;
4801: foreach my $which (keys(%allchecked)) {
4802: $env{'form.multi'.$which} =~ s/,$//;
4803: if ($env{'form.multi'.$which}) {
4804: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
4805: if (ref($allchecked{$which}) eq 'HASH') {
4806: $needsupdate += scalar(keys(%{$allchecked{$which}}));
4807: }
4808: }
4809: }
4810: if ($needsupdate) {
4811: my $haschanges = 0;
4812: my %curr_groups = &Apache::longroup::coursegroups();
4813: my $total = scalar(@LONCAPA::map::order) - 1;
4814: for (my $i=$total; $i>=0; $i--) {
4815: my $res = $LONCAPA::map::order[$i];
4816: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4817: $name=&LONCAPA::map::qtescape($name);
4818: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 4819: next unless $url;
1.538 raeburn 4820: my %denied =
4821: &action_restrictions($coursenum,$coursedom,$url,
4822: $env{'form.folderpath'},\%curr_groups);
4823: foreach my $which (keys(%allchecked)) {
4824: next if ($denied{$which});
4825: next unless ($allchecked{$which}{$res});
4826: if ($which eq 'remove') {
4827: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4828: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4829: &Apache::lonnet::removeuploadedurl($url);
4830: } else {
4831: &LONCAPA::map::makezombie($res);
4832: }
4833: splice(@LONCAPA::map::order,$i,1);
4834: $haschanges ++;
4835: } elsif ($which eq 'cut') {
4836: &LONCAPA::map::makezombie($res);
4837: splice(@LONCAPA::map::order,$i,1);
4838: $haschanges ++;
4839: }
4840: }
4841: }
4842: if ($haschanges) {
4843: ($errtext,$fatal) =
4844: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
4845: return $errtext if ($fatal);
4846: }
4847: }
4848: }
4849:
1.329 droeschl 4850: # Group import/search
4851: if ($env{'form.importdetail'}) {
4852: my @imports;
4853: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
4854: if (defined($item)) {
4855: my ($name,$url,$residx)=
1.533 raeburn 4856: map { &unescape($_); } split(/\=/,$item);
4857: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
4858: my ($suffix,$errortxt,$locknotfreed) =
4859: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 4860: if ($locknotfreed) {
4861: $r->print($locknotfreed);
4862: }
4863: if ($suffix) {
4864: $url =~ s/_new\./_$suffix./;
4865: } else {
4866: return $errortxt;
4867: }
1.533 raeburn 4868: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
4869: my $type = $1;
4870: my ($suffix,$errortxt,$locknotfreed) =
4871: &new_timebased_suffix($coursedom,$coursenum,$type);
4872: if ($locknotfreed) {
4873: $r->print($locknotfreed);
4874: }
4875: if ($suffix) {
4876: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
4877: } else {
4878: return $errortxt;
4879: }
1.626 raeburn 4880: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 4881: my ($suffix,$errortxt,$locknotfreed) =
4882: &new_timebased_suffix($coursedom,$coursenum,'exttool');
4883: if ($locknotfreed) {
4884: $r->print($locknotfreed);
4885: }
4886: if ($suffix) {
4887: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
4888: } else {
4889: return $errortxt;
4890: }
1.534 raeburn 4891: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
4892: if ($supplementalflag) {
4893: next unless ($1 eq 'supplemental');
4894: if ($folder eq 'supplemental') {
4895: next unless ($2 eq 'default');
4896: } else {
4897: next unless ($folder eq 'supplemental_'.$2);
4898: }
4899: } else {
4900: next unless ($1 eq 'docs');
4901: if ($folder eq 'default') {
4902: next unless ($2 eq 'default');
4903: } else {
4904: next unless ($folder eq 'default_'.$2);
4905: }
4906: }
1.504 raeburn 4907: }
1.329 droeschl 4908: push(@imports, [$name, $url, $residx]);
4909: }
4910: }
1.530 raeburn 4911: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 4912: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 4913: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 4914: return $errtext if ($fatal);
1.529 raeburn 4915: if ($fixuperrors) {
4916: $r->print($fixuperrors);
4917: }
1.329 droeschl 4918: }
4919: # Loading a complete map
4920: if ($env{'form.loadmap'}) {
4921: if ($env{'form.importmap'}=~/\w/) {
4922: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
4923: my ($title,$url,$ext,$type)=split(/\:/,$res);
4924: my $idx=&LONCAPA::map::getresidx($url);
4925: $LONCAPA::map::resources[$idx]=$res;
4926: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
4927: }
4928: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 4929: $folder.'.'.$container,1);
1.329 droeschl 4930: return $errtext if ($fatal);
4931: } else {
4932: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 4933:
1.329 droeschl 4934: }
4935: }
4936: &log_differences($plain);
4937: }
4938: # ---------------------------------------------------------------- End commands
4939: # ---------------------------------------------------------------- Print screen
4940: my $idx=0;
4941: my $shown=0;
4942: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 4943: $r->print('<div class="LC_Box">'.
1.432 raeburn 4944: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
4945: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
4946: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
4947: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
4948: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 4949: '</ol>');
1.381 bisitz 4950: if ($randompick>=0) {
4951: $r->print('<p class="LC_warning">'
4952: .&mt('Caution: this folder is set to randomly pick a subset'
4953: .' of resources. Adding or removing resources from this'
4954: .' folder will change the set of resources that the'
4955: .' students see, resulting in spurious or missing credit'
4956: .' for completed problems, not limited to ones you'
4957: .' modify. Do not modify the contents of this folder if'
4958: .' it is in active student use.')
4959: .'</p>'
4960: );
4961: }
4962: if ($is_random_order) {
4963: $r->print('<p class="LC_warning">'
4964: .&mt('Caution: this folder is set to randomly order its'
4965: .' contents. Adding or removing resources from this folder'
4966: .' will change the order of resources shown.')
4967: .'</p>'
4968: );
4969: }
4970: $r->print('</div>');
1.364 bisitz 4971: }
1.381 bisitz 4972:
1.685 raeburn 4973: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 4974: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 4975: if (ref($supplemental) eq 'HASH') {
4976: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
4977: (ref($supplemental->{'ids'}) eq 'HASH')) {
4978: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
4979: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
4980: if ($supplemental->{'hidden'}->{$mapnum}) {
4981: $ishidden = 1;
4982: }
4983: }
4984: }
4985: }
4986: }
4987:
1.538 raeburn 4988: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
4989: %filters = (
1.543 raeburn 4990: canremove => [],
4991: cancut => [],
4992: cancopy => [],
4993: hiddenresource => [],
4994: encrypturl => [],
4995: randomorder => [],
4996: randompick => [],
1.538 raeburn 4997: );
4998: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 4999: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 5000: foreach my $res (@LONCAPA::map::order) {
5001: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
5002: $name=&LONCAPA::map::qtescape($name);
5003: $url=&LONCAPA::map::qtescape($url);
5004: unless ($name) { $name=(split(/\//,$url))[-1]; }
5005: unless ($name) { $idx++; next; }
1.537 raeburn 5006: push(@allidx,$res);
5007: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
5008: push(@allmapidx,$res);
5009: }
1.617 raeburn 5010:
1.682 raeburn 5011: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 5012: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
5013: $idx++;
5014: next;
5015: }
1.682 raeburn 5016: }
1.381 bisitz 5017: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 5018: $coursenum,$coursedom,$crstype,
1.538 raeburn 5019: $pathitem,$supplementalflag,$container,
1.620 raeburn 5020: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 5021: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 5022: $idx++;
5023: $shown++;
1.329 droeschl 5024: }
1.424 onken 5025: &Apache::loncommon::end_data_table_count();
1.510 raeburn 5026:
1.538 raeburn 5027: my $need_save;
1.611 raeburn 5028: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 5029: my $toolslink;
1.682 raeburn 5030: if ($allowed || $canedit) {
5031: my $helpitem = 'Navigation_Screen';
5032: if (!$allowed) {
5033: $helpitem = 'Supplemental_Navigation';
5034: }
1.723 raeburn 5035: $toolslink = '<div class="LC_navtools">'
5036: .'<div class="LC_navtools">'
1.520 raeburn 5037: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 5038: $helpitem,undef,'RAT')
1.723 raeburn 5039: .'</div><div class="LC_navtools">'.&mt('Tools:').'</div>'
1.724 raeburn 5040: .'<div class="LC_navtools">'."\n".'<ul id="LC_toolbar">'
1.525 raeburn 5041: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 5042: .'id="LC_content_toolbar_edittoplevel" '
5043: .'class="LC_toolbarItem" '
5044: .'title="'.&mt('Supplemental Content Editor').'">'
1.723 raeburn 5045: .'</a></li></ul></div></div>'."\n"
5046: .'<div style="padding:0;clear:both;margin:0;border:0"></div><br />'."\n";
1.544 raeburn 5047: }
1.510 raeburn 5048: if ($shown) {
5049: if ($allowed) {
5050: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
5051: .&Apache::loncommon::start_data_table(undef,'contentlist')
5052: .&Apache::loncommon::start_data_table_header_row()
5053: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 5054: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 5055: .'<th>'.&mt('Document').'</th>'
5056: .'<th colspan="2">'.&mt('Settings').'</th>'
5057: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 5058: if ($folder !~ /^supplemental/) {
1.538 raeburn 5059: $lists{'canhide'} = join(',',@allidx);
5060: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 5061: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
5062: 'randomorder','randompick');
5063: foreach my $item (@possfilters) {
1.538 raeburn 5064: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 5065: if (@{$filters{$item}} > 0) {
5066: $lists{$item} = join(',',@{$filters{$item}});
5067: }
1.538 raeburn 5068: }
5069: }
1.537 raeburn 5070: if (@allidx > 0) {
5071: my $path;
5072: if ($env{'form.folderpath'}) {
1.630 raeburn 5073: $path =
1.537 raeburn 5074: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5075: }
1.538 raeburn 5076: if (@allidx > 1) {
1.630 raeburn 5077: $to_show .=
1.538 raeburn 5078: &Apache::loncommon::continue_data_table_row().
5079: '<td colspan="2"> </td>'.
5080: '<td>'.
1.611 raeburn 5081: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 5082: '</td>'.
1.633 raeburn 5083: '<td colspan="3"> </td>'.
5084: '<td colspan="2">'.
1.611 raeburn 5085: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 5086: '</td>'.
5087: &Apache::loncommon::end_data_table_row();
5088: $need_save = 1;
5089: }
1.537 raeburn 5090: }
5091: }
5092: $to_show .= $output.' '
1.510 raeburn 5093: .&Apache::loncommon::end_data_table()
5094: .'<br style="line-height:2px;" />'
5095: .&Apache::loncommon::end_scrollbox();
5096: } else {
1.520 raeburn 5097: $to_show .= $toolslink
1.510 raeburn 5098: .&Apache::loncommon::start_data_table('LC_tableOfContent')
1.725 raeburn 5099: .&Apache::loncommon::start_data_table_header_row('LC_visually_hidden')
5100: .'<th>'.&mt('Resource Type (Icon)').'</th><th>'.&mt('Resource or Folder').'</th>'
5101: .&Apache::loncommon::end_data_table_header_row()
1.510 raeburn 5102: .$output.' '
5103: .&Apache::loncommon::end_data_table();
1.393 raeburn 5104: }
1.510 raeburn 5105: } else {
1.520 raeburn 5106: if (!$allowed) {
5107: $to_show .= $toolslink;
5108: }
1.615 raeburn 5109: my $noresmsg;
5110: if ($allowed && $hiddentop && !$supplementalflag) {
5111: $noresmsg = &mt('Main Content Hidden');
5112: } else {
5113: $noresmsg = &mt('Currently empty');
5114: }
1.510 raeburn 5115: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
5116: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 5117: .$noresmsg
1.510 raeburn 5118: .'</div>'
5119: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 5120: }
5121: } else {
1.510 raeburn 5122: if ($shown) {
5123: $to_show = '<div>'
5124: .&Apache::loncommon::start_data_table('LC_tableOfContent')
5125: .$output
5126: .&Apache::loncommon::end_data_table()
5127: .'</div>';
5128: } else {
5129: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 5130: .&mt('Currently empty')
1.510 raeburn 5131: .'</div>'
5132: }
1.458 raeburn 5133: }
5134: my $tid = 1;
5135: if ($supplementalflag) {
5136: $tid = 2;
1.329 droeschl 5137: }
5138: if ($allowed) {
1.484 raeburn 5139: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 5140: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 5141: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
5142: if ($canedit) {
5143: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
5144: }
1.460 raeburn 5145: } else {
5146: $r->print($to_show);
1.329 droeschl 5147: }
5148: return;
5149: }
5150:
1.538 raeburn 5151: sub multiple_check_form {
1.611 raeburn 5152: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 5153: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 5154: my $disabled;
5155: unless ($canedit) {
1.700 raeburn 5156: $disabled = ' disabled="disabled"';
1.611 raeburn 5157: }
1.538 raeburn 5158: my $output =
5159: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
5160: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
5161: '<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>'.
5162: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
5163: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
5164: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
5165: if ($caller eq 'settings') {
5166: $output .=
5167: '<table><tr>'.
5168: '<td class="LC_docs_entry_parameter">'.
5169: '<span class="LC_nobreak"><label>'.
1.611 raeburn 5170: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 5171: '</label></span></td>'.
5172: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 5173: '<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 5174: '</span></td>'.
5175: '</tr>'."\n".
5176: '<tr>'.
5177: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 5178: '<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 5179: '</label></span>'.
5180: '</td></tr></table>'."\n";
5181: } else {
5182: $output .=
5183: '<table><tr>'.
5184: '<td class="LC_docs_entry_parameter">'.
5185: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 5186: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 5187: '</label></span></td>'.
5188: '<td class="LC_docs_entry_parameter">'.
5189: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 5190: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 5191: '</label></span></td>'."\n".
5192: '<td class="LC_docs_entry_parameter">'.
5193: '<span class="LC_nobreak LC_docs_copy">'.
1.700 raeburn 5194: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538 raeburn 5195: '</label></span></td>'.
5196: '</tr></table>'."\n";
5197: }
5198: $output .=
5199: '</fieldset>'.
5200: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
5201: if ($caller eq 'settings') {
5202: $output .=
1.543 raeburn 5203: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
5204: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
5205: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
5206: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
5207: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 5208: } elsif ($caller eq 'actions') {
5209: $output .=
5210: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
5211: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
5212: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
5213: }
5214: $output .=
5215: '</form>'.
5216: '</div>';
5217: return $output;
5218: }
5219:
1.329 droeschl 5220: sub process_file_upload {
1.552 raeburn 5221: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 5222: # upload a file, if present
1.552 raeburn 5223: my $filesize = length($env{'form.uploaddoc'});
5224: if (!$filesize) {
5225: $$upload_output = '<div class="LC_error">'.
5226: &mt('Unable to upload [_1]. (size = [_2] bytes)',
5227: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
5228: $filesize).'<br />'.
5229: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
5230: '</div>';
5231: return;
5232: }
5233: my $quotatype = 'unofficial';
5234: if ($crstype eq 'Community') {
1.601 raeburn 5235: $quotatype = 'community';
5236: } elsif ($crstype eq 'Placement') {
5237: $quotatype = 'placement';
1.580 raeburn 5238: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 5239: $quotatype = 'official';
1.573 raeburn 5240: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5241: $quotatype = 'textbook';
1.552 raeburn 5242: }
5243: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
5244: $filesize = int($filesize/1000); #expressed in kb
5245: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 5246: $env{'form.uploaddoc.filename'},$filesize,
5247: 'upload',$quotatype);
1.552 raeburn 5248: return if ($$upload_output);
5249: }
1.440 raeburn 5250: my ($parseaction,$showupload,$nextphase,$mimetype);
5251: if ($env{'form.parserflag'}) {
1.329 droeschl 5252: $parseaction = 'parse';
5253: }
5254: my $folder=$env{'form.folder'};
5255: if ($folder eq '') {
5256: $folder='default';
5257: }
5258: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
5259: my $errtext='';
5260: my $fatal=0;
5261: my $container='sequence';
1.519 raeburn 5262: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 5263: $container='page';
5264: }
5265: ($errtext,$fatal)=
1.534 raeburn 5266: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 5267: if ($#LONCAPA::map::order<1) {
5268: $LONCAPA::map::order[0]=1;
5269: $LONCAPA::map::resources[1]='';
5270: }
5271: my $destination = 'docs/';
5272: if ($folder =~ /^supplemental/) {
5273: $destination = 'supplemental/';
5274: }
5275: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5276: $destination .= 'default/';
5277: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5278: $destination .= $2.'/';
5279: }
1.534 raeburn 5280: if ($fatal) {
5281: $$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>';
5282: return;
5283: }
1.440 raeburn 5284: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 5285: my $newidx=&LONCAPA::map::getresidx();
5286: $destination .= $newidx;
1.439 raeburn 5287: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 5288: $parseaction,$allfiles,
1.440 raeburn 5289: $codebase,undef,undef,undef,undef,
5290: undef,undef,\$mimetype);
5291: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
5292: my $stored = $1;
5293: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
5294: $stored.'</span>').'</p>';
5295: } else {
5296: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
5297:
1.457 raeburn 5298: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 5299: return;
5300: }
1.329 droeschl 5301: my $ext='false';
5302: if ($url=~m{^http://}) { $ext='true'; }
5303: $url = &LONCAPA::map::qtunescape($url);
5304: my $comment=$env{'form.comment'};
5305: $comment = &LONCAPA::map::qtunescape($comment);
5306: if ($folder=~/^supplemental/) {
5307: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
5308: $env{'user.domain'}.'___&&&___'.$comment;
5309: }
5310:
5311: $LONCAPA::map::resources[$newidx]=
5312: $comment.':'.$url.':'.$ext.':normal:res';
5313: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
5314: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 5315: $folder.'.'.$container,1);
1.329 droeschl 5316: if ($fatal) {
1.457 raeburn 5317: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 5318: return;
1.329 droeschl 5319: } else {
1.440 raeburn 5320: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
5321: $$upload_output = $showupload;
1.384 raeburn 5322: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 5323: if ($total_embedded > 0) {
1.440 raeburn 5324: my $uploadphase = 'upload_embedded';
5325: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
5326: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 5327: my ($embedded,$num) =
1.440 raeburn 5328: &Apache::loncommon::ask_for_embedded_content(
5329: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
5330: if ($embedded) {
5331: if ($num) {
5332: $$upload_output .=
5333: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
5334: $nextphase = $uploadphase;
5335: } else {
5336: $$upload_output .= $embedded;
5337: }
5338: } else {
5339: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
5340: }
1.329 droeschl 5341: } else {
1.440 raeburn 5342: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 5343: }
1.457 raeburn 5344: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 5345: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
5346: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 5347: $nextphase = 'decompress_uploaded';
5348: my $position = scalar(@LONCAPA::map::order)-1;
5349: my $noextract = &return_to_editor();
5350: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
5351: my %archiveitems = (
5352: folderpath => $env{'form.folderpath'},
5353: cmd => $nextphase,
5354: newidx => $newidx,
5355: position => $position,
5356: phase => $nextphase,
1.477 raeburn 5357: comment => $comment,
1.480 raeburn 5358: );
5359: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
5360: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 5361: $$upload_output = $showupload.
5362: &Apache::loncommon::decompress_form($mimetype,
5363: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 5364: \%archiveitems,\@current);
1.329 droeschl 5365: }
5366: }
5367: }
1.440 raeburn 5368: return $nextphase;
1.329 droeschl 5369: }
5370:
1.480 raeburn 5371: sub get_dir_list {
5372: my ($url,$coursenum,$coursedom,$newidx) = @_;
5373: my ($destination,$dir_root) = &embedded_destination();
5374: my ($dirlistref,$listerror) =
5375: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
5376: my @dir_lines;
5377: my $dirptr=16384;
5378: if (ref($dirlistref) eq 'ARRAY') {
5379: foreach my $dir_line (sort
5380: {
5381: my ($afile)=split('&',$a,2);
5382: my ($bfile)=split('&',$b,2);
5383: return (lc($afile) cmp lc($bfile));
5384: } (@{$dirlistref})) {
5385: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
5386: $filename =~ s/\s+$//;
5387: next if ($filename =~ /^\.\.?$/);
5388: my $isdir = 0;
5389: if ($dirptr&$testdir) {
5390: $isdir = 1;
5391: }
5392: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
5393: }
5394: }
5395: return @dir_lines;
5396: }
5397:
1.329 droeschl 5398: sub is_supplemental_title {
5399: my ($title) = @_;
5400: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
5401: }
5402:
5403: # --------------------------------------------------------------- An entry line
5404:
5405: sub entryline {
1.501 raeburn 5406: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 5407: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 5408: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 5409: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 5410: if (&is_supplemental_title($title)) {
1.488 raeburn 5411: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 5412: $encodedtitle=$title;
1.329 droeschl 5413: } else {
5414: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 5415: $encodedtitle=$title;
1.329 droeschl 5416: $renametitle=$title;
5417: $foldertitle=$title;
5418: }
5419:
1.611 raeburn 5420: my ($disabled,$readonly,$js_lt);
5421: unless ($canedit) {
5422: $disabled = 'disabled="disabled"';
5423: $readonly = 1;
5424: }
5425:
1.329 droeschl 5426: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 5427:
1.329 droeschl 5428: $renametitle=~s/\\/\\\\/g;
5429: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 5430: $renametitle=~s/"/%22/g;
1.581 raeburn 5431: $renametitle=~s/ /%20/g;
5432: $oldtitle = $renametitle;
1.576 raeburn 5433: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 5434: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 5435: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 5436: # Edit commands
1.679 raeburn 5437: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 5438: if ($env{'form.folderpath'}) {
5439: $esc_path=&escape($env{'form.folderpath'});
5440: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5441: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
5442: }
1.505 raeburn 5443: my $isexternal;
1.510 raeburn 5444: if ($residx) {
1.501 raeburn 5445: my $currurl = $url;
5446: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 5447: if ($currurl =~ m{^/adm/wrapper/ext/}) {
5448: $isexternal = 1;
5449: }
1.510 raeburn 5450: if (!$supplementalflag) {
5451: my $path = 'uploaded/'.
5452: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
5453: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
5454: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
5455: $residx,
5456: &Apache::lonnet::declutter($currurl));
5457: }
1.501 raeburn 5458: }
1.538 raeburn 5459: my ($renamelink,%lt,$ishash);
5460: if (ref($filtersref) eq 'HASH') {
5461: $ishash = 1;
5462: }
5463:
1.329 droeschl 5464: if ($allowed) {
1.538 raeburn 5465: $form_start = '
5466: <form action="/adm/coursedocs" method="post">
5467: ';
5468: $form_common=(<<END);
5469: <input type="hidden" name="folderpath" value="$path" />
5470: <input type="hidden" name="symb" value="$symb" />
5471: END
5472: $form_param=(<<END);
5473: <input type="hidden" name="setparms" value="$orderidx" />
5474: <input type="hidden" name="changeparms" value="0" />
5475: END
5476: $form_end = '</form>';
5477:
1.329 droeschl 5478: my $incindex=$index+1;
5479: my $selectbox='';
1.471 raeburn 5480: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 5481: ((split(/\:/,
1.344 bisitz 5482: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
5483: ne '') &&
1.329 droeschl 5484: ((split(/\:/,
1.344 bisitz 5485: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 5486: ne '')) {
5487: $selectbox=
5488: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 5489: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 5490: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
5491: if ($i==$incindex) {
1.358 bisitz 5492: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 5493: } else {
5494: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
5495: }
5496: }
5497: $selectbox.='</select>';
5498: }
1.501 raeburn 5499: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 5500: 'up' => 'Move Up',
5501: 'dw' => 'Move Down',
5502: 'rm' => 'Remove',
5503: 'ct' => 'Cut',
5504: 'rn' => 'Rename',
1.501 raeburn 5505: 'cp' => 'Copy',
1.633 raeburn 5506: 'da' => 'Unset alias',
5507: 'sa' => 'Set alias',
1.501 raeburn 5508: 'ex' => 'External Resource',
1.598 raeburn 5509: 'et' => 'External Tool',
1.501 raeburn 5510: 'ed' => 'Edit',
5511: 'pr' => 'Preview',
5512: 'sv' => 'Save',
5513: 'ul' => 'URL',
1.611 raeburn 5514: 'ti' => 'Title',
1.618 raeburn 5515: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 5516: );
1.538 raeburn 5517: my %denied = &action_restrictions($coursenum,$coursedom,$url,
5518: $env{'form.folderpath'},
5519: $currgroups);
1.517 raeburn 5520: my ($copylink,$cutlink,$removelink);
1.329 droeschl 5521: my $skip_confirm = 0;
1.603 raeburn 5522: my $confirm_removal = 0;
1.329 droeschl 5523: if ( $folder =~ /^supplemental/
5524: || ($url =~ m{( /smppg$
5525: |/syllabus$
5526: |/aboutme$
5527: |/navmaps$
5528: |/bulletinboard$
1.626 raeburn 5529: |/ext\.tool$
1.505 raeburn 5530: |\.html$)}x)
5531: || $isexternal) {
1.329 droeschl 5532: $skip_confirm = 1;
5533: }
1.603 raeburn 5534: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
5535: ($url!~/$LONCAPA::assess_page_seq_re/)) {
5536: $confirm_removal = 1;
5537: }
1.633 raeburn 5538: if ($url =~ /$LONCAPA::assess_re/) {
5539: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
5540: }
1.329 droeschl 5541:
1.538 raeburn 5542: if ($denied{'copy'}) {
1.543 raeburn 5543: $copylink=(<<ENDCOPY)
1.507 raeburn 5544: <span style="visibility: hidden;">$lt{'cp'}</span>
5545: ENDCOPY
5546: } else {
1.538 raeburn 5547: my $formname = 'edit_copy_'.$orderidx;
5548: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5549: $copylink=(<<ENDCOPY);
1.538 raeburn 5550: <form name="$formname" method="post" action="/adm/coursedocs">
5551: $form_common
1.723 raeburn 5552: <label><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></label>
1.538 raeburn 5553: $form_end
1.329 droeschl 5554: ENDCOPY
1.538 raeburn 5555: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
5556: push(@{$filtersref->{'cancopy'}},$orderidx);
5557: }
1.329 droeschl 5558: }
1.538 raeburn 5559: if ($denied{'cut'}) {
1.507 raeburn 5560: $cutlink=(<<ENDCUT);
5561: <span style="visibility: hidden;">$lt{'ct'}</span>
5562: ENDCUT
5563: } else {
1.538 raeburn 5564: my $formname = 'edit_cut_'.$orderidx;
5565: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5566: $cutlink=(<<ENDCUT);
1.538 raeburn 5567: <form name="$formname" method="post" action="/adm/coursedocs">
5568: $form_common
1.542 raeburn 5569: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.723 raeburn 5570: <label><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></label>
1.538 raeburn 5571: $form_end
1.329 droeschl 5572: ENDCUT
1.538 raeburn 5573: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
5574: push(@{$filtersref->{'cancut'}},$orderidx);
5575: }
1.329 droeschl 5576: }
1.538 raeburn 5577: if ($denied{'remove'}) {
1.507 raeburn 5578: $removelink=(<<ENDREM);
5579: <span style="visibility: hidden;">$lt{'rm'}</a>
5580: ENDREM
5581: } else {
1.538 raeburn 5582: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 5583: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 5584: $removelink=(<<ENDREM);
1.538 raeburn 5585: <form name="$formname" method="post" action="/adm/coursedocs">
5586: $form_common
1.542 raeburn 5587: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 5588: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.723 raeburn 5589: <label><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></label>
1.538 raeburn 5590: $form_end
1.497 raeburn 5591: ENDREM
1.538 raeburn 5592: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
5593: push(@{$filtersref->{'canremove'}},$orderidx);
5594: }
1.497 raeburn 5595: }
1.551 raeburn 5596: $renamelink=(<<ENDREN);
1.581 raeburn 5597: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 5598: ENDREN
1.611 raeburn 5599: my ($uplink,$downlink);
5600: if ($canedit) {
5601: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
5602: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
5603: } else {
5604: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
5605: $downlink = $uplink;
5606: }
1.329 droeschl 5607: $line.=(<<END);
5608: <td>
1.379 bisitz 5609: <div class="LC_docs_entry_move">
1.611 raeburn 5610: <a href="$uplink">
1.501 raeburn 5611: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 5612: </a>
5613: </div>
5614: <div class="LC_docs_entry_move">
1.611 raeburn 5615: <a href="$downlink">
1.501 raeburn 5616: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 5617: </a>
5618: </div>
1.329 droeschl 5619: </td>
5620: <td>
5621: $form_start
1.538 raeburn 5622: $form_param
1.478 raeburn 5623: $form_common
1.329 droeschl 5624: $selectbox
5625: $form_end
5626: </td>
1.540 raeburn 5627: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 5628: $removelink
1.329 droeschl 5629: $cutlink
5630: $copylink
5631: </td>
5632: END
5633: }
1.723 raeburn 5634: my $icontext;
1.329 droeschl 5635: # Figure out what kind of a resource this is
5636: my ($extension)=($url=~/\.(\w+)$/);
1.723 raeburn 5637: if ($extension eq 'sequence') {
5638: $icontext = &mt('folder icon');
5639: } elsif ($extension eq 'page') {
5640: $icontext = &mt('composite page icon');
5641: } else {
5642: $icontext = &mt('file icon');
5643: }
5644: $icontext = &HTML::Entities::encode($icontext);
1.329 droeschl 5645: my $uploaded=($url=~/^\/*uploaded\//);
5646: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 5647: my $isfolder;
5648: my $ispage;
5649: my $containerarg;
1.615 raeburn 5650: my $folderurl;
1.685 raeburn 5651: my $plainurl;
1.329 droeschl 5652: if ($uploaded) {
1.472 raeburn 5653: if (($extension eq 'sequence') || ($extension eq 'page')) {
5654: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 5655: $containerarg = $1;
1.472 raeburn 5656: if ($extension eq 'sequence') {
5657: $icon=$iconpath.'navmap.folder.closed.gif';
5658: $isfolder=1;
5659: } else {
5660: $icon=$iconpath.'page.gif';
5661: $ispage=1;
5662: }
1.615 raeburn 5663: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 5664: if ($allowed) {
5665: $url='/adm/coursedocs?';
5666: } else {
5667: $url='/adm/supplemental?';
5668: }
1.329 droeschl 5669: } else {
1.685 raeburn 5670: $plainurl = $url;
1.329 droeschl 5671: }
5672: }
1.364 bisitz 5673:
1.621 raeburn 5674: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 5675: my $orig_url = $url;
1.340 raeburn 5676: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 5677: if ($container eq 'page') {
5678: $url=~s{^http(|s)(:|:)//}{/ext/};
5679: } else {
5680: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
5681: }
1.501 raeburn 5682: if (!$supplementalflag && $residx && $symb) {
5683: if ((!$isfolder) && (!$ispage)) {
5684: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 5685: if (($url =~ m{^ext/}) && ($container eq 'page')) {
5686: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
5687: } else {
5688: $url=&Apache::lonnet::clutter($url);
5689: }
1.501 raeburn 5690: if ($url=~/^\/*uploaded\//) {
5691: $url=~/\.(\w+)$/;
5692: my $embstyle=&Apache::loncommon::fileembstyle($1);
5693: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
5694: $url='/adm/wrapper'.$url;
5695: } elsif ($embstyle eq 'ssi') {
5696: #do nothing with these
5697: } elsif ($url!~/\.(sequence|page)$/) {
5698: $url='/adm/coursedocs/showdoc'.$url;
5699: }
1.623 raeburn 5700: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
5701: my $wrapped = $1;
5702: my $exturl = $2;
1.668 raeburn 5703: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 5704: $url='/adm/wrapper'.$url;
5705: }
5706: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
5707: $nomodal = 1;
5708: }
1.626 raeburn 5709: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5710: $url='/adm/wrapper'.$url;
1.621 raeburn 5711: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
5712: if (($ENV{'SERVER_PORT'} == 443) &&
5713: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5714: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5715: $url .= '?usehttp=1';
5716: }
1.621 raeburn 5717: $nomodal = 1;
5718: }
1.598 raeburn 5719: }
1.696 raeburn 5720: my $checkencrypt;
1.680 raeburn 5721: if (!$env{'request.role.adv'}) {
1.615 raeburn 5722: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 5723: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 5724: $checkencrypt = 1;
1.620 raeburn 5725: } elsif (ref($navmapref)) {
1.615 raeburn 5726: unless (ref($$navmapref)) {
5727: $$navmapref = Apache::lonnavmaps::navmap->new();
5728: }
5729: if (ref($$navmapref)) {
5730: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 5731: $checkencrypt = 1;
1.615 raeburn 5732: }
5733: }
5734: }
1.680 raeburn 5735: }
5736: if ($checkencrypt) {
5737: my $currenc = $env{'request.enc'};
5738: $env{'request.enc'} = 1;
5739: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 5740: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 5741: if (&Apache::lonnet::symbverify($symb,$url)) {
5742: $url = $shownurl;
5743: } else {
5744: $url = '';
5745: }
5746: $env{'request.enc'} = $currenc;
5747: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
5748: $shownsymb = $symb;
5749: if ($isexternal) {
5750: $url =~ s/\#[^#]+$//;
5751: if ($container eq 'page') {
5752: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 5753: }
1.612 raeburn 5754: }
1.696 raeburn 5755: } else {
5756: $url = '';
1.680 raeburn 5757: }
5758: unless ($env{'request.role.adv'}) {
5759: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5760: $url = '';
5761: }
5762: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
5763: $url = '';
5764: $hiddenres = 1;
5765: }
5766: }
1.696 raeburn 5767: if (($url ne '') && ($shownsymb ne '')) {
5768: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 5769: }
1.329 droeschl 5770: }
1.621 raeburn 5771: } elsif ($supplementalflag) {
1.610 raeburn 5772: if ($isexternal) {
5773: if ($url =~ /^([^#]+)#([^#]+)$/) {
5774: $url = $1;
5775: $anchor = $2;
1.623 raeburn 5776: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 5777: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5778: if ($hostname ne '') {
5779: $url = 'http://'.$hostname.$url;
5780: }
5781: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 5782: }
5783: $nomodal = 1;
5784: }
1.610 raeburn 5785: }
1.621 raeburn 5786: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
5787: if (($ENV{'SERVER_PORT'} == 443) &&
5788: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5789: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5790: if ($hostname ne '') {
5791: $url = 'http://'.$hostname.$url;
5792: }
5793: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 5794: }
1.621 raeburn 5795: $nomodal = 1;
5796: }
1.705 raeburn 5797: } elsif (($uploaded) && ($url ne '/adm/supplemental?') && ($url ne '/adm/coursedocs?')) {
1.686 raeburn 5798: my $embstyle=&Apache::loncommon::fileembstyle($extension);
5799: unless ($embstyle eq 'ssi') {
5800: if (($embstyle eq 'img')
5801: || ($embstyle eq 'emb')
5802: || ($embstyle eq 'wrp')) {
5803: $url='/adm/wrapper'.$url;
5804: } elsif ($url !~ /\.(sequence|page)$/) {
5805: $url='/adm/coursedocs/showdoc'.$url;
5806: }
5807: }
1.610 raeburn 5808: }
1.685 raeburn 5809: unless ($allowed && $env{'request.role.adv'}) {
5810: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5811: $hiddenres = 1;
5812: }
5813: }
1.329 droeschl 5814: }
1.615 raeburn 5815: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 5816: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 5817: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 5818: my $foldername=&escape($foldertitle);
5819: my $folderpath=$env{'form.folderpath'};
5820: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 5821: if (!$allowed && $supplementalflag) {
1.519 raeburn 5822: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 5823: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 5824: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5825: $hiddenfolder = 1;
1.682 raeburn 5826: }
1.510 raeburn 5827: } else {
1.617 raeburn 5828: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
5829: 'parameter_randompick'))[0];
5830: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
5831: 'parameter_randomorder'))[0]=~/^yes$/i);
5832: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
5833: 'parameter_hiddenresource'))[0]=~/^yes$/i);
5834: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
5835: 'parameter_encrypturl'))[0]=~/^yes$/i);
5836: unless ($hiddenmap) {
1.620 raeburn 5837: if (ref($navmapref)) {
5838: unless (ref($$navmapref)) {
5839: $$navmapref = Apache::lonnavmaps::navmap->new();
5840: }
5841: if (ref($$navmapref)) {
5842: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5843: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
5844: unless (@resources) {
5845: $hiddenmap = 1;
5846: unless ($env{'request.role.adv'}) {
5847: $url = '';
5848: $hiddenfolder = 1;
5849: }
1.617 raeburn 5850: }
1.615 raeburn 5851: }
5852: }
5853: }
5854: }
1.617 raeburn 5855: unless ($encryptmap) {
1.620 raeburn 5856: if ((ref($navmapref)) && (ref($$navmapref))) {
5857: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
5858: $encryptmap = 1;
5859: }
1.617 raeburn 5860: }
5861: }
1.630 raeburn 5862:
1.617 raeburn 5863: # Append randompick number, hidden, and encrypted with ":" to foldername,
5864: # so it gets transferred between levels
5865: $folderpath.=$containerarg.'&'.$foldername.
5866: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 5867: unless ($url eq '') {
1.612 raeburn 5868: $url.='folderpath='.&escape($folderpath);
5869: }
1.510 raeburn 5870: my $rpckchk;
5871: if ($rpicknum) {
5872: $rpckchk = ' checked="checked"';
1.543 raeburn 5873: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
5874: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
5875: }
1.510 raeburn 5876: }
1.537 raeburn 5877: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 5878: $rand_pick_text =
1.478 raeburn 5879: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5880: $form_param."\n".
1.478 raeburn 5881: $form_common."\n".
1.611 raeburn 5882: '<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 5883: if ($rpicknum ne '') {
5884: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
5885: }
1.537 raeburn 5886: $rand_pick_text .= '</span></span>'.
5887: $form_end;
1.543 raeburn 5888: my $ro_set;
1.617 raeburn 5889: if ($randorder) {
1.543 raeburn 5890: $ro_set = 'checked="checked"';
5891: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
5892: push(@{$filtersref->{'randomorder'}},$orderidx);
5893: }
5894: }
1.564 raeburn 5895: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 5896: $rand_order_text =
1.537 raeburn 5897: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5898: $form_param."\n".
1.537 raeburn 5899: $form_common."\n".
1.611 raeburn 5900: '<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 5901: $form_end;
1.510 raeburn 5902: }
1.705 raeburn 5903: } elsif ($supplementalflag) {
1.598 raeburn 5904: my $isexttool;
1.626 raeburn 5905: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5906: $url='/adm/wrapper'.$url;
5907: $isexttool = 1;
5908: }
1.510 raeburn 5909: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 5910: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 5911: if ($title) {
1.687 raeburn 5912: $url .= '&title='.$encodedtitle;
1.510 raeburn 5913: }
1.598 raeburn 5914: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 5915: $url .= '&idx='.$orderidx;
5916: }
1.610 raeburn 5917: if ($anchor ne '') {
5918: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5919: }
1.329 droeschl 5920: }
1.519 raeburn 5921: my ($tdalign,$tdwidth);
1.501 raeburn 5922: if ($allowed) {
1.630 raeburn 5923: my $fileloc =
1.501 raeburn 5924: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 5925: if ($isexternal) {
1.630 raeburn 5926: ($editlink,$extresform) =
1.611 raeburn 5927: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5928: undef,undef,undef,undef,undef,undef,
5929: undef,$disabled);
1.626 raeburn 5930: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5931: ($editlink,$extresform) =
5932: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5933: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 5934: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 5935: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 5936: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
5937: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 5938: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 5939: my $suppanchor;
5940: if ($supplementalflag) {
5941: $suppanchor = $anchor;
5942: }
1.630 raeburn 5943: my $jscall =
1.501 raeburn 5944: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
5945: $switchserver,
1.503 raeburn 5946: $forceedit,
1.679 raeburn 5947: undef,$symb,$shownsymb,
1.511 raeburn 5948: &escape($env{'form.folderpath'}),
1.622 raeburn 5949: $renametitle,$hostname,
5950: '','',1,$suppanchor);
1.501 raeburn 5951: if ($jscall) {
1.518 raeburn 5952: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
5953: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 5954: }
5955: }
5956: }
1.519 raeburn 5957: $tdalign = ' align="right" valign="top"';
5958: $tdwidth = ' width="80%"';
1.329 droeschl 5959: }
1.408 raeburn 5960: my $reinit;
5961: if ($crstype eq 'Community') {
5962: $reinit = &mt('(re-initialize community to access)');
5963: } else {
5964: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 5965: }
1.725 raeburn 5966: if ($allowed) {
5967: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
5968: if ($orig_url =~ /$LONCAPA::assess_re/) {
5969: $line.= '<br />';
5970: if ($curralias ne '') {
5971: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5972: $lt{'da'}.'</a></span>';
5973: } else {
5974: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5975: $lt{'sa'}.'</a></span>';
5976: }
1.633 raeburn 5977: }
1.725 raeburn 5978: $line.='</td>';
1.633 raeburn 5979: }
1.725 raeburn 5980: $line .= '<td><span class="LC_nobreak">';
1.685 raeburn 5981: my ($link,$nolink);
1.472 raeburn 5982: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5983: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
5984: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5985: $nolink = 1;
5986: }
5987: }
5988: if ($nolink) {
1.723 raeburn 5989: $line .= '<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" /></a>';
1.685 raeburn 5990: } else {
1.723 raeburn 5991: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" /></a>';
1.685 raeburn 5992: }
1.469 www 5993: } elsif ($url) {
1.610 raeburn 5994: if ($anchor ne '') {
5995: if ($supplementalflag) {
5996: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5997: } else {
5998: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
5999: }
6000: }
1.705 raeburn 6001: if (($nomodal) && ($hostname ne '')) {
1.622 raeburn 6002: $link = 'http://'.$hostname.$url;
6003: } else {
6004: $link = $url;
6005: }
1.705 raeburn 6006: my $inhibitmenu;
6007: if ((($supplementalflag) && ($allowed) && ($url =~ m{^/adm/wrapper/})) ||
6008: (($allowed) && (($url =~ m{^/adm/(viewclasslist|$match_domain/$match_username/aboutme)(\?|$)}) ||
6009: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus(\?|$)})))) {
6010: $inhibitmenu = 'only_body=1';
6011: } else {
6012: $inhibitmenu = 'inhibitmenu=yes';
6013: }
6014: $link = &js_escape($link.(($url=~/\?/)?'&':'?').$inhibitmenu.$anchor);
1.685 raeburn 6015: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
6016: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
6017: $nolink = 1;
6018: }
6019: }
6020: if ($nolink) {
1.723 raeburn 6021: $line.='<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" />';
1.685 raeburn 6022: } elsif ($nomodal) {
1.621 raeburn 6023: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
1.723 raeburn 6024: '<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" border="0" /></a>';
1.621 raeburn 6025: } else {
6026: $line.=&Apache::loncommon::modal_link($link,
1.723 raeburn 6027: '<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" />',600,500);
1.621 raeburn 6028: }
1.469 www 6029: } else {
1.723 raeburn 6030: $line.='<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" />';
1.469 www 6031: }
1.519 raeburn 6032: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 6033: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 6034: if ($nolink) {
6035: $line.=$title;
6036: } else {
6037: $line.='<a href="'.$url.'">'.$title.'</a>';
6038: }
1.682 raeburn 6039: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
6040: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
6041: my $editurl = $url;
6042: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
6043: $line .= ' '.'<a href="'.$editurl.'">'.
6044: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
6045: '</a>';
6046: }
6047: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
6048: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
6049: }
1.469 www 6050: } elsif ($url) {
1.685 raeburn 6051: if ($nolink) {
6052: $line.=$title;
6053: } elsif ($nomodal) {
1.621 raeburn 6054: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
6055: $title.'</a>';
6056: } else {
6057: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
6058: }
1.617 raeburn 6059: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 6060: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 6061: } else {
6062: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
6063: }
1.633 raeburn 6064: if (($allowed) && ($curralias ne '')) {
6065: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
6066: } else {
6067: $line .= $extresform;
6068: }
6069: $line .= '</td>';
1.478 raeburn 6070: $rand_pick_text = ' ' if ($rand_pick_text eq '');
6071: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 6072: if ($uploaded && $url && !$isfolder && !$ispage) {
6073: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
6074: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
6075: }
6076: }
1.682 raeburn 6077: if ($allowed) {
6078: my %lt=&Apache::lonlocal::texthash(
6079: 'hd' => 'Hidden',
6080: 'ec' => 'URL hidden');
6081: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 6082: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
6083: $hidtext = ' checked="checked"';
1.694 raeburn 6084: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 6085: push(@{$filtersref->{'hiddenresource'}},$orderidx);
6086: }
6087: }
1.682 raeburn 6088: $formhidden = 'edit_hiddenresource_'.$orderidx;
6089: $line.=(<<ENDPARMS);
1.329 droeschl 6090: <td class="LC_docs_entry_parameter">
1.537 raeburn 6091: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 6092: $form_param
1.478 raeburn 6093: $form_common
1.611 raeburn 6094: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 6095: $form_end
1.682 raeburn 6096: ENDPARMS
6097: if ($folder =~/^supplemental/) {
6098: $line.= "\n <td>";
6099: } else {
6100: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
6101: $enctext = ' checked="checked"';
6102: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
6103: push(@{$filtersref->{'encrypturl'}},$orderidx);
6104: }
6105: }
6106: $formurlhidden = 'edit_encrypturl_'.$orderidx;
6107: $line.=(<<ENDPARMS);
1.458 raeburn 6108: <br />
1.537 raeburn 6109: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 6110: $form_param
1.478 raeburn 6111: $form_common
1.611 raeburn 6112: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 6113: $form_end
6114: </td>
1.478 raeburn 6115: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
6116: $rand_order_text</td>
1.329 droeschl 6117: ENDPARMS
1.682 raeburn 6118: }
1.329 droeschl 6119: }
1.379 bisitz 6120: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 6121: return $line;
6122: }
6123:
1.538 raeburn 6124: sub action_restrictions {
6125: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
6126: my %denied = (
6127: cut => 0,
6128: copy => 0,
6129: remove => 0,
6130: );
6131: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
6132: # no copy for published maps
6133: $denied{'copy'} = 1;
1.597 raeburn 6134: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
6135: unless ($1 eq 'simpleproblem') {
6136: $denied{'copy'} = 1;
6137: }
6138: $denied{'cut'} = 1;
1.538 raeburn 6139: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
6140: if ($folderpath =~ /^default&[^\&]+$/) {
6141: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
6142: $denied{'remove'} = 1;
6143: }
6144: $denied{'cut'} = 1;
6145: $denied{'copy'} = 1;
6146: }
6147: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
6148: my $group = $1;
6149: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
6150: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
6151: $denied{'remove'} = 1;
6152: }
6153: }
6154: $denied{'cut'} = 1;
6155: $denied{'copy'} = 1;
6156: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
6157: my $group = $1;
6158: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
6159: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
6160: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
6161: if (keys(%groupsettings) > 0) {
6162: $denied{'remove'} = 1;
6163: }
6164: $denied{'cut'} = 1;
6165: $denied{'copy'} = 1;
6166: }
6167: }
6168: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
6169: my $group = $1;
6170: if ($url =~ /group_boards_\Q$group\E/) {
6171: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
6172: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
6173: if (keys(%groupsettings) > 0) {
6174: if (ref($groupsettings{'functions'}) eq 'HASH') {
6175: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
6176: $denied{'remove'} = 1;
6177: }
6178: }
6179: }
6180: $denied{'cut'} = 1;
6181: $denied{'copy'} = 1;
6182: }
6183: }
6184: }
6185: return %denied;
6186: }
6187:
1.533 raeburn 6188: sub new_timebased_suffix {
1.538 raeburn 6189: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 6190: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 6191: if ($type eq 'paste') {
6192: $prefix = $type;
6193: $namespace = 'courseeditor';
1.587 raeburn 6194: $idtype = 'addcode';
1.538 raeburn 6195: } elsif ($type eq 'map') {
1.533 raeburn 6196: $prefix = 'docs';
6197: if ($area eq 'supplemental') {
6198: $prefix = 'supp';
6199: }
6200: $prefix .= $container;
6201: $namespace = 'uploadedmaps';
6202: } else {
6203: $prefix = $type;
6204: $namespace = 'templated';
1.504 raeburn 6205: }
6206: my ($suffix,$freedlock,$error) =
1.587 raeburn 6207: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 6208: if (!$suffix) {
1.538 raeburn 6209: if ($type eq 'paste') {
6210: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
6211: } elsif ($type eq 'map') {
1.533 raeburn 6212: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
6213: } elsif ($type eq 'smppg') {
6214: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 6215: } elsif ($type eq 'exttool') {
6216: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 6217: } else {
1.565 bisitz 6218: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 6219: }
1.504 raeburn 6220: if ($error) {
6221: $errtext .= '<br />'.$error;
6222: }
6223: }
6224: if ($freedlock ne 'ok') {
1.630 raeburn 6225: $locknotfreed =
1.533 raeburn 6226: '<div class="LC_error">'.
6227: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 6228: if ($type eq 'paste') {
1.591 raeburn 6229: if ($freedlock eq 'nolock') {
6230: $locknotfreed =
6231: '<div class="LC_error">'.
6232: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
6233:
1.593 droeschl 6234: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 6235: } else {
6236: $locknotfreed .=
6237: &mt('This will prevent addition of items to the clipboard until your next log-in.');
6238: }
1.538 raeburn 6239: } elsif ($type eq 'map') {
1.591 raeburn 6240: $locknotfreed .=
6241: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 6242: } elsif ($type eq 'smppg') {
6243: $locknotfreed .=
6244: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 6245: } elsif ($type eq 'exttool') {
6246: $locknotfreed .=
6247: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 6248: } else {
6249: $locknotfreed .=
1.565 bisitz 6250: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 6251: }
1.538 raeburn 6252: unless ($type eq 'paste') {
6253: $locknotfreed .=
1.560 raeburn 6254: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
6255: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 6256: }
6257: $locknotfreed .= '</div>';
1.504 raeburn 6258: }
6259: return ($suffix,$errtext,$locknotfreed);
6260: }
6261:
1.329 droeschl 6262: =pod
6263:
6264: =item tiehash()
6265:
6266: tie the hash
6267:
6268: =cut
6269:
6270: sub tiehash {
6271: my ($mode)=@_;
6272: $hashtied=0;
6273: if ($env{'request.course.fn'}) {
6274: if ($mode eq 'write') {
6275: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
6276: &GDBM_WRCREAT(),0640)) {
6277: $hashtied=2;
6278: }
6279: } else {
6280: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
6281: &GDBM_READER(),0640)) {
6282: $hashtied=1;
6283: }
6284: }
1.364 bisitz 6285: }
1.329 droeschl 6286: }
6287:
6288: sub untiehash {
6289: if ($hashtied) { untie %hash; }
6290: $hashtied=0;
6291: return OK;
6292: }
6293:
6294:
6295:
6296:
6297: sub checkonthis {
1.637 raeburn 6298: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 6299: $url=&unescape($url);
6300: $alreadyseen{$url}=1;
6301: $r->rflush();
6302: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
6303: $r->print("\n<br />");
6304: if ($level==0) {
6305: $r->print("<br />");
6306: }
6307: for (my $i=0;$i<=$level*5;$i++) {
6308: $r->print(' ');
6309: }
6310: $r->print('<a href="'.$url.'" target="cat">'.
6311: ($title?$title:$url).'</a> ');
6312: if ($url=~/^\/res\//) {
1.637 raeburn 6313: my $updated;
6314: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
6315: ($url !~ /\.\d+\.\w+$/)) {
6316: $updated = &Apache::lonnet::remove_stale_resfile($url);
6317: }
1.329 droeschl 6318: my $result=&Apache::lonnet::repcopy(
6319: &Apache::lonnet::filelocation('',$url));
6320: if ($result eq 'ok') {
6321: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 6322: if ($updated) {
6323: $r->print('<br />');
6324: for (my $i=0;$i<=$level*5;$i++) {
6325: $r->print(' ');
6326: }
6327: $r->print('- '.&mt('Outdated copy removed'));
6328: }
1.329 droeschl 6329: $r->rflush();
6330: &Apache::lonnet::countacc($url);
6331: $url=~/\.(\w+)$/;
6332: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
6333: $r->print('<br />');
6334: $r->rflush();
6335: for (my $i=0;$i<=$level*5;$i++) {
6336: $r->print(' ');
6337: }
6338: $r->print('- '.&mt('Rendering:').' ');
6339: my ($errorcount,$warningcount)=split(/:/,
6340: &Apache::lonnet::ssi_body($url,
6341: ('grade_target'=>'web',
6342: 'return_only_error_and_warning_counts' => 1)));
6343: if (($errorcount) ||
6344: ($warningcount)) {
6345: if ($errorcount) {
1.369 bisitz 6346: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 6347: &mt('[quant,_1,error]',$errorcount).'</span>');
6348: }
6349: if ($warningcount) {
6350: $r->print('<span class="LC_warning">'.
6351: &mt('[quant,_1,warning]',$warningcount).'</span>');
6352: }
6353: } else {
6354: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
6355: }
6356: $r->rflush();
6357: }
6358: my $dependencies=
6359: &Apache::lonnet::metadata($url,'dependencies');
6360: foreach my $dep (split(/\,/,$dependencies)) {
6361: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 6362: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 6363: }
6364: }
6365: } elsif ($result eq 'unavailable') {
6366: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
6367: } elsif ($result eq 'not_found') {
6368: unless ($url=~/\$/) {
1.521 bisitz 6369: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 6370: } else {
1.366 bisitz 6371: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 6372: }
6373: } else {
6374: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
6375: }
1.637 raeburn 6376: if (($updated) && ($result ne 'ok')) {
6377: $r->print('<br />'.&mt('Outdated copy removed'));
6378: }
1.329 droeschl 6379: }
6380: }
6381: }
6382:
6383:
6384:
6385: =pod
6386:
6387: =item list_symbs()
6388:
1.485 raeburn 6389: List Content Identifiers
1.329 droeschl 6390:
6391: =cut
6392:
6393: sub list_symbs {
6394: my ($r) = @_;
6395:
1.408 raeburn 6396: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 6397: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
6398: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
6399: $r->print(&startContentScreen('tools'));
1.329 droeschl 6400: my $navmap = Apache::lonnavmaps::navmap->new();
6401: if (!defined($navmap)) {
6402: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
6403: '<div class="LC_error">'.
6404: &mt('Unable to retrieve information about course contents').
6405: '</div>');
1.408 raeburn 6406: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 6407: } else {
1.484 raeburn 6408: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
6409: &Apache::loncommon::start_data_table().
6410: &Apache::loncommon::start_data_table_header_row().
6411: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
6412: &Apache::loncommon::end_data_table_header_row()."\n");
6413: my $count;
1.329 droeschl 6414: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 6415: $r->print(&Apache::loncommon::start_data_table_row().
6416: '<td>'.$res->compTitle().'</td>'.
6417: '<td>'.$res->symb().'</td>'.
1.521 bisitz 6418: &Apache::loncommon::end_data_table_row());
1.484 raeburn 6419: $count ++;
6420: }
6421: if (!$count) {
6422: $r->print(&Apache::loncommon::start_data_table_row().
6423: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
6424: &Apache::loncommon::end_data_table_row());
1.329 droeschl 6425: }
1.484 raeburn 6426: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 6427: }
1.521 bisitz 6428: $r->print(&endContentScreen());
1.329 droeschl 6429: }
6430:
1.651 raeburn 6431: sub short_urls {
6432: my ($r,$canedit) = @_;
6433: my $crstype = &Apache::loncommon::course_type();
6434: my $formname = 'shortenurl';
6435: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
6436: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
6437: $r->print(&startContentScreen('tools'));
6438: my ($navmap,$errormsg) =
6439: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
6440: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6441: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6442: my (%maps,%resources,%titles);
6443: if (!ref($navmap)) {
6444: $r->print($errormsg.
6445: &endContentScreen());
6446: return '';
6447: } else {
1.652 raeburn 6448: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 6449: $r->rflush();
6450: my $readonly;
6451: if ($canedit) {
1.671 raeburn 6452: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 6453: if ($numnew) {
6454: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
6455: }
6456: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
6457: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
6458: foreach my $error (@{$errors}) {
6459: $r->print('<li>'.$error.'</li>');
6460: }
6461: $r->print('</ul><br />');
6462: }
6463: } else {
6464: $readonly = 1;
6465: }
6466: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
6467: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
1.711 raeburn 6468: undef,undef,undef,undef,undef,\%currtiny,undef,$readonly));
1.651 raeburn 6469: }
6470: $r->print(&endContentScreen());
6471: }
6472:
1.637 raeburn 6473: sub contentverifyform {
6474: my ($r) = @_;
6475: my $crstype = &Apache::loncommon::course_type();
6476: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6477: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
6478: $r->print(&startContentScreen('tools'));
6479: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
6480: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
6481: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
6482: ' <span class="LC_nobreak">'.
6483: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
6484: &mt('No').'</label>'.(' 'x2).
6485: '<label><input type="radio" name="checkstale" value="1" />'.
6486: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 6487: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 6488: '<input type="hidden" value="1" name="tools" />'.
6489: '<input type="hidden" value="1" name="verify" /></p></form>');
6490: $r->print(&endContentScreen());
6491: return;
6492: }
1.329 droeschl 6493:
6494: sub verifycontent {
1.637 raeburn 6495: my ($r,$checkstale) = @_;
1.408 raeburn 6496: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 6497: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6498: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 6499: $r->print(&startContentScreen('tools'));
6500: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 6501: $hashtied=0;
6502: undef %alreadyseen;
6503: %alreadyseen=();
6504: &tiehash();
1.484 raeburn 6505:
1.329 droeschl 6506: foreach my $key (keys(%hash)) {
6507: if ($hash{$key}=~/\.(page|sequence)$/) {
6508: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
6509: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 6510: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 6511: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 6512: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 6513: }
6514: }
6515: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 6516: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 6517: }
6518: }
6519: &untiehash();
1.442 www 6520: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 6521: $r->print(&endContentScreen());
1.329 droeschl 6522: }
6523:
6524: sub devalidateversioncache {
6525: my $src=shift;
6526: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
6527: &Apache::lonnet::clutter($src));
6528: }
6529:
6530: sub checkversions {
1.611 raeburn 6531: my ($r,$canedit) = @_;
1.408 raeburn 6532: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 6533: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
6534: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 6535: $r->print(&startContentScreen('tools'));
1.442 www 6536:
1.329 droeschl 6537: my $header='';
6538: my $startsel='';
6539: my $monthsel='';
6540: my $weeksel='';
6541: my $daysel='';
6542: my $allsel='';
6543: my %changes=();
6544: my $starttime=0;
6545: my $haschanged=0;
6546: my %setversions=&Apache::lonnet::dump('resourceversions',
6547: $env{'course.'.$env{'request.course.id'}.'.domain'},
6548: $env{'course.'.$env{'request.course.id'}.'.num'});
6549:
6550: $hashtied=0;
6551: &tiehash();
1.611 raeburn 6552: if ($canedit) {
6553: my %newsetversions=();
6554: if ($env{'form.setmostrecent'}) {
6555: $haschanged=1;
6556: foreach my $key (keys(%hash)) {
6557: if ($key=~/^ids\_(\/res\/.+)$/) {
6558: $newsetversions{$1}='mostrecent';
6559: &devalidateversioncache($1);
6560: }
6561: }
6562: } elsif ($env{'form.setcurrent'}) {
6563: $haschanged=1;
6564: foreach my $key (keys(%hash)) {
6565: if ($key=~/^ids\_(\/res\/.+)$/) {
6566: my $getvers=&Apache::lonnet::getversion($1);
6567: if ($getvers>0) {
6568: $newsetversions{$1}=$getvers;
6569: &devalidateversioncache($1);
6570: }
6571: }
1.329 droeschl 6572: }
1.611 raeburn 6573: } elsif ($env{'form.setversions'}) {
6574: $haschanged=1;
6575: foreach my $key (keys(%env)) {
6576: if ($key=~/^form\.set_version_(.+)$/) {
6577: my $src=$1;
6578: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
6579: $newsetversions{$src}=$env{$key};
6580: &devalidateversioncache($src);
6581: }
6582: }
1.329 droeschl 6583: }
1.611 raeburn 6584: }
6585: if ($haschanged) {
6586: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
6587: $env{'course.'.$env{'request.course.id'}.'.domain'},
6588: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
6589: $r->print(&Apache::loncommon::confirmwrapper(
6590: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
6591: } else {
6592: $r->print(&Apache::loncommon::confirmwrapper(
6593: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 6594: }
1.611 raeburn 6595: &mark_hash_old();
6596: }
6597: &changewarning($r,'');
1.329 droeschl 6598: }
6599: if ($env{'form.timerange'} eq 'all') {
6600: # show all documents
1.549 raeburn 6601: $header=&mt('All content in '.$crstype);
1.521 bisitz 6602: $allsel=' selected="selected"';
1.329 droeschl 6603: foreach my $key (keys(%hash)) {
6604: if ($key=~/^ids\_(\/res\/.+)$/) {
6605: my $src=$1;
6606: $changes{$src}=1;
6607: }
6608: }
6609: } else {
6610: # show documents which changed
6611: %changes=&Apache::lonnet::dump
6612: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
6613: $env{'course.'.$env{'request.course.id'}.'.num'});
6614: my $firstkey=(keys(%changes))[0];
6615: unless ($firstkey=~/^error\:/) {
6616: unless ($env{'form.timerange'}) {
6617: $env{'form.timerange'}=604800;
6618: }
6619: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
6620: .&mt('seconds');
6621: if ($env{'form.timerange'}==-1) {
6622: $seltext='since start of course';
1.521 bisitz 6623: $startsel=' selected="selected"';
1.329 droeschl 6624: $env{'form.timerange'}=time;
6625: }
6626: $starttime=time-$env{'form.timerange'};
6627: if ($env{'form.timerange'}==2592000) {
6628: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6629: $monthsel=' selected="selected"';
1.329 droeschl 6630: } elsif ($env{'form.timerange'}==604800) {
6631: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6632: $weeksel=' selected="selected"';
1.329 droeschl 6633: } elsif ($env{'form.timerange'}==86400) {
6634: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6635: $daysel=' selected="selected"';
1.329 droeschl 6636: }
6637: $header=&mt('Content changed').' '.$seltext;
6638: } else {
6639: $header=&mt('No content modifications yet.');
6640: }
6641: }
6642: %setversions=&Apache::lonnet::dump('resourceversions',
6643: $env{'course.'.$env{'request.course.id'}.'.domain'},
6644: $env{'course.'.$env{'request.course.id'}.'.num'});
6645: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 6646: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 6647: 'lm' => 'Version changes since last Month',
6648: 'lw' => 'Version changes since last Week',
6649: 'sy' => 'Version changes since Yesterday',
6650: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 6651: 'cd' => 'Change display',
1.329 droeschl 6652: 'sd' => 'Display',
6653: 'fi' => 'File',
6654: 'md' => 'Modification Date',
6655: 'mr' => 'Most recently published Version',
1.408 raeburn 6656: 've' => 'Version used in '.$crstype,
6657: 'vu' => 'Set Version to be used in '.$crstype,
6658: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 6659: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
6660: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 6661: 'di' => 'Differences',
1.484 raeburn 6662: 'save' => 'Save changes',
6663: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 6664: 'act' => 'Actions');
1.611 raeburn 6665: my ($disabled,$readonly);
6666: unless ($canedit) {
6667: $disabled = 'disabled="disabled"';
6668: $readonly = 1;
6669: }
1.329 droeschl 6670: $r->print(<<ENDHEADERS);
1.484 raeburn 6671: <h4 class="LC_info">$header</h4>
1.329 droeschl 6672: <form action="/adm/coursedocs" method="post">
6673: <input type="hidden" name="versions" value="1" />
1.484 raeburn 6674: <div class="LC_left_float">
1.479 golterma 6675: <fieldset>
1.484 raeburn 6676: <legend>$lt{'cd'}</legend>
1.329 droeschl 6677: <select name="timerange">
1.521 bisitz 6678: <option value='all'$allsel>$lt{'al'}</option>
6679: <option value="-1"$startsel>$lt{'st'}</option>
6680: <option value="2592000"$monthsel>$lt{'lm'}</option>
6681: <option value="604800"$weeksel>$lt{'lw'}</option>
6682: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 6683: </select>
6684: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 6685: </fieldset>
6686: </div>
6687: <div class="LC_left_float">
6688: <fieldset>
6689: <legend>$lt{'act'}</legend>
1.611 raeburn 6690: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
6691: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 6692: </fieldset>
6693: </div>
6694: <br clear="all" />
6695: <hr />
6696: <h4>$lt{'vers'}</h4>
1.329 droeschl 6697: ENDHEADERS
1.479 golterma 6698: #number of columns for version history
1.571 raeburn 6699: my %changedbytime;
6700: foreach my $key (keys(%changes)) {
6701: #excludes not versionable problems from resource version history:
6702: next if ($key =~ /^\/res\/lib\/templates/);
6703: my $chg;
6704: if ($env{'form.timerange'} eq 'all') {
6705: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6706: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
6707: } else {
6708: $chg = $changes{$key};
6709: next if ($chg < $starttime);
6710: }
6711: push(@{$changedbytime{$chg}},$key);
6712: }
6713: if (keys(%changedbytime) == 0) {
6714: &untiehash();
6715: $r->print(&mt('No content changes in imported content in specified time frame').
6716: &endContentScreen());
6717: return;
6718: }
1.479 golterma 6719: $r->print(
1.611 raeburn 6720: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6721: &Apache::loncommon::start_data_table().
6722: &Apache::loncommon::start_data_table_header_row().
6723: '<th>'.&mt('Resources').'</th>'.
6724: "<th>$lt{'mr'}</th>".
6725: "<th>$lt{'ve'}</th>".
6726: "<th>$lt{'vu'}</th>".
6727: '<th>'.&mt('History').'</th>'.
6728: &Apache::loncommon::end_data_table_header_row()
6729: );
1.571 raeburn 6730: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
6731: foreach my $key (sort(@{$changedbytime{$chg}})) {
6732: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6733: my $currentversion=&Apache::lonnet::getversion($key);
6734: if ($currentversion<0) {
6735: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
6736: }
6737: my $linkurl=&Apache::lonnet::clutter($key);
6738: $r->print(
6739: &Apache::loncommon::start_data_table_row().
6740: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
6741: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
6742: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
6743: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
6744: '<td align="right">'
6745: );
6746: # Used in course
6747: my $usedversion=$hash{'version_'.$linkurl};
6748: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 6749: if ($usedversion != $currentversion) {
1.479 golterma 6750: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 6751: } else {
1.479 golterma 6752: $r->print($usedversion);
6753: }
1.329 droeschl 6754: } else {
1.521 bisitz 6755: $r->print($currentversion);
1.329 droeschl 6756: }
1.571 raeburn 6757: $r->print('</td><td title="'.$lt{'vu'}.'">');
6758: # Set version
6759: $r->print(&Apache::loncommon::select_form(
6760: $setversions{$linkurl},
6761: 'set_version_'.$linkurl,
6762: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
6763: '' => '',
6764: 'mostrecent' => &mt('most recent'),
1.611 raeburn 6765: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 6766: my $lastold=1;
6767: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
6768: my $url=$root.'.'.$prevvers.'.'.$extension;
6769: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
6770: $lastold=$prevvers;
6771: }
6772: }
6773: $r->print('</td>');
6774: # List all available versions
6775: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
6776: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
6777: my $url=$root.'.'.$prevvers.'.'.$extension;
6778: $r->print(
6779: '<span class="LC_nobreak">'
6780: .'<a href="'.&Apache::lonnet::clutter($url).'">'
6781: .&mt('Version [_1]',$prevvers).'</a>'
6782: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 6783: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 6784: .')');
6785: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
6786: $r->print(
6787: ' <a href="/adm/diff?filename='.
6788: &Apache::lonnet::clutter($root.'.'.$extension).
6789: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
6790: '" target="diffs">'.&mt('Diffs').'</a>');
6791: }
6792: $r->print('</span><br />');
1.329 droeschl 6793: }
1.571 raeburn 6794: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 6795: }
1.329 droeschl 6796: }
1.521 bisitz 6797: $r->print(
6798: &Apache::loncommon::end_data_table().
1.611 raeburn 6799: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6800: '</form>'
6801: );
1.329 droeschl 6802:
6803: &untiehash();
1.521 bisitz 6804: $r->print(&endContentScreen());
1.571 raeburn 6805: return;
1.329 droeschl 6806: }
6807:
6808: sub mark_hash_old {
6809: my $retie_hash=0;
6810: if ($hashtied) {
6811: $retie_hash=1;
6812: &untiehash();
6813: }
6814: &tiehash('write');
6815: $hash{'old'}=1;
6816: &untiehash();
6817: if ($retie_hash) { &tiehash(); }
6818: }
6819:
6820: sub is_hash_old {
6821: my $untie_hash=0;
6822: if (!$hashtied) {
6823: $untie_hash=1;
6824: &tiehash();
6825: }
6826: my $return=$hash{'old'};
6827: if ($untie_hash) { &untiehash(); }
6828: return $return;
6829: }
6830:
6831: sub changewarning {
6832: my ($r,$postexec,$message,$url)=@_;
6833: if (!&is_hash_old()) { return; }
6834: my $pathvar='folderpath';
6835: my $path=&escape($env{'form.folderpath'});
6836: if (!defined($url)) {
6837: $url='/adm/coursedocs?'.$pathvar.'='.$path;
6838: }
6839: my $course_type = &Apache::loncommon::course_type();
6840: if (!defined($message)) {
6841: $message='Changes will become active for your current session after [_1], or the next time you log in.';
6842: }
1.653 raeburn 6843: my $windowname = 'loncapaclient';
6844: if ($env{'request.lti.login'}) {
6845: $windowname .= 'lti';
6846: }
1.329 droeschl 6847: $r->print("\n\n".
1.372 bisitz 6848: '<script type="text/javascript">'."\n".
6849: '// <![CDATA['."\n".
6850: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
6851: '// ]]>'."\n".
1.369 bisitz 6852: '</script>'."\n".
1.653 raeburn 6853: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 6854: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 6855: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 6856: &mt($message,' <input type="hidden" name="'.
6857: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 6858: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 6859: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 6860: }
6861:
6862:
6863: sub init_breadcrumbs {
1.571 raeburn 6864: my ($form,$text,$help)=@_;
1.329 droeschl 6865: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 6866: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 6867: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 6868: faq=>273,
6869: bug=>'Instructor Interface',
1.571 raeburn 6870: help => $help});
1.329 droeschl 6871: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
6872: text=>$text,
6873: faq=>273,
6874: bug=>'Instructor Interface'});
6875: }
6876:
1.441 www 6877: # subroutine to list form elements
6878: sub create_list_elements {
6879: my @formarr = @_;
6880: my $list = '';
1.501 raeburn 6881: foreach my $button (@formarr){
6882: foreach my $picture (keys(%{$button})) {
6883: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 6884: }
6885: }
6886: return $list;
6887: }
1.329 droeschl 6888:
1.441 www 6889: # subroutine to create ul from list elements
6890: sub create_form_ul {
6891: my $list = shift;
6892: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
6893: return $ul;
6894: }
1.329 droeschl 6895:
1.442 www 6896: #
6897: # Start tabs
6898: #
6899:
6900: sub startContentScreen {
1.484 raeburn 6901: my ($mode) = @_;
1.724 raeburn 6902: my $output = '<div class="LC_landmark" role="main">'.
6903: '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 6904: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 6905: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
6906: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
6907: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
6908: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
6909: } else {
1.549 raeburn 6910: $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 6911: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
6912: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
6913: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
6914: }
6915: $output .= "\n".'</ul>'."\n";
6916: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
6917: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
6918: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
6919: return $output;
1.442 www 6920: }
6921:
6922: #
6923: # End tabs
6924: #
6925:
6926: sub endContentScreen {
1.724 raeburn 6927: return '</div></div></div></div>';
1.442 www 6928: }
1.329 droeschl 6929:
1.446 www 6930: sub supplemental_base {
1.548 raeburn 6931: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 6932: }
6933:
1.329 droeschl 6934: sub handler {
6935: my $r = shift;
6936: &Apache::loncommon::content_type($r,'text/html');
6937: $r->send_http_header;
6938: return OK if $r->header_only;
1.484 raeburn 6939:
6940: # get course data
1.408 raeburn 6941: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 6942: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
6943: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.712 raeburn 6944: my $coursehome=$env{'course.'.$env{'request.course.id'}.'.home'};
1.484 raeburn 6945:
1.606 raeburn 6946: # get docroot
6947: my $londocroot = $r->dir_config('lonDocRoot');
6948:
1.484 raeburn 6949: # graphics settings
6950: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 6951:
1.443 www 6952: #
1.329 droeschl 6953: # --------------------------------------------- Initialize help topics for this
6954: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 6955: 'Adding_External_Resource','Adding_External_Tool',
6956: 'Navigate_Content','Adding_Folders','Docs_Overview',
6957: 'Load_Map','Supplemental','Score_Upload_Form',
6958: 'Adding_Pages','Importing_LON-CAPA_Resource',
6959: 'Importing_IMS_Course','Uploading_From_Harddrive',
1.706 raeburn 6960: 'Course_Roster','Web_Page','Dropbox','Simple_Problem',
6961: 'Standard_Problem','Course_Resources',
6962: 'Search_LON-CAPA_Resource','Import_Stored_Links') {
1.329 droeschl 6963: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
6964: }
6965: # Composite help files
6966: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
6967: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
6968: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
6969: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
6970: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
6971: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 6972: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 6973: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 6974: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 6975: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 6976:
1.611 raeburn 6977: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 6978: # does this user have privileges to modify content.
6979: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 6980: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 6981: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6982: $allowed = 1;
1.682 raeburn 6983: }
6984: $canedit = 1;
6985: $canview = 1;
6986: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
6987: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
6988: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6989: $allowed = 1;
6990: }
1.682 raeburn 6991: $canview = 1;
1.611 raeburn 6992: }
6993: unless ($canedit) {
6994: $disabled = ' disabled="disabled"';
1.472 raeburn 6995: }
1.582 raeburn 6996: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 6997: if ($env{'form.inhibitmenu'}) {
6998: unless ($env{'form.inhibitmenu'} eq 'yes') {
6999: delete($env{'form.inhibitmenu'});
7000: }
7001: }
7002:
1.582 raeburn 7003: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 7004: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 7005: if (!$canedit) {
7006: &verifycontent($r);
7007: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
7008: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
7009: text=>'Results',
7010: faq=>273,
7011: bug=>'Instructor Interface'});
7012: &verifycontent($r,$env{'form.checkstale'});
7013: } else {
7014: &contentverifyform($r);
7015: }
1.329 droeschl 7016: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 7017: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 7018: &list_symbs($r);
1.651 raeburn 7019: } elsif ($allowed && $env{'form.shorturls'}) {
7020: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
7021: &short_urls($r,$canedit);
1.329 droeschl 7022: } elsif ($allowed && $env{'form.docslog'}) {
7023: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 7024: my $folder = $env{'form.folder'};
7025: if ($folder eq '') {
7026: $folder='default';
7027: }
1.611 raeburn 7028: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 7029: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 7030: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 7031: &checkversions($r,$canedit);
7032: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.709 raeburn 7033: &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
1.329 droeschl 7034: &dumpcourse($r);
1.712 raeburn 7035: } elsif (($canedit || $canview) && ($env{'form.copyauthored'})) {
7036: &init_breadcrumbs('copyauthored','Copy from Course Authoring to User Authoring');
7037: my $readonly;
7038: if (!$canedit) {
7039: $readonly = 1;
7040: }
7041: ©crsauthored($r,$coursenum,$coursedom,$coursehome,$readonly);
1.611 raeburn 7042: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 7043: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 7044: &Apache::imsexport::exportcourse($r);
1.329 droeschl 7045: } else {
1.611 raeburn 7046: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 7047: $noendpage = 1;
7048: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
7049: if ($redirect) {
7050: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
7051: my $container = 'sequence';
7052: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
7053: $is_random_order,$container) =
7054: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
7055: my (@folders)=split('&',$env{'form.folderpath'});
7056: $env{'form.foldername'}=&unescape(pop(@folders));
7057: my $folder=pop(@folders);
7058: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
7059: $folder.'.'.$container);
7060: my $warning;
7061: if ($fatal) {
7062: if ($container eq 'page') {
7063: $warning = &mt('An error occurred retrieving the contents of the current page.');
7064: } else {
7065: $warning = &mt('An error occurred retrieving the contents of the current folder.');
7066: }
7067: } else {
7068: my $url = $redirect;
7069: my $srcfile = $londocroot.$url;
7070: $url =~ s{^/priv/}{/res/};
7071: my $targetfile = $londocroot.$url;
7072: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
7073: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
7074: $env{'form.folder'} = $folder;
7075: &snapshotbefore();
7076: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
7077: my $ext = 'false';
7078: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
7079: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
7080: ':'.$ext.':normal:res';
7081: push(@LONCAPA::map::order,$newidx);
7082: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
7083: 'string_yesno');
7084: &remember_parms($newidx,'hiddenresource','set','yes');
7085: ($errtext,$fatal) =
7086: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
7087: &log_differences($plain);
7088: &mark_hash_old();
7089: $r->internal_redirect($redirect);
7090: return OK;
7091: }
1.654 raeburn 7092: } else {
7093: $r->internal_redirect($redirect);
1.606 raeburn 7094: }
7095: }
7096: }
1.445 www 7097: #
7098: # Done catching special calls
1.484 raeburn 7099: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 7100: # Get the parameters that may be needed
7101: #
7102: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 7103: ['folderpath','title',
1.519 raeburn 7104: 'forcesupplement','forcestandard',
1.510 raeburn 7105: 'tools','symb','command','supppath']);
1.445 www 7106:
1.635 raeburn 7107: foreach my $item ('forcesupplement','forcestandard','tools') {
7108: next if ($env{'form.'.$item} eq '');
7109: unless ($env{'form.'.$item} eq '1') {
7110: delete($env{'form.'.$item});
7111: }
7112: }
7113:
7114: if ($env{'form.command'}) {
7115: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
7116: delete($env{'form.command'});
7117: }
7118: }
7119:
7120: if ($env{'form.symb'}) {
7121: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
7122: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
7123: delete($env{'form.symb'});
7124: }
7125: }
7126:
1.445 www 7127: # standard=1: this is a "new-style" course with an uploaded map as top level
7128: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 7129:
7130: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 7131:
1.484 raeburn 7132: # Decide whether this should display supplemental or main content or utilities
1.445 www 7133: # supplementalflag=1: show supplemental documents
7134: # supplementalflag=0: show standard documents
1.484 raeburn 7135: # toolsflag=1: show utilities
1.445 www 7136:
1.561 raeburn 7137: my $unesc_folderpath = &unescape($env{'form.folderpath'});
7138: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
7139: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 7140: $supplementalflag=0;
7141: }
7142: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
7143: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
1.705 raeburn 7144: unless (($supplementalflag) ||
7145: ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
7146: unless ($allowed) { $supplementalflag=1; }
7147: unless ($standard) { $supplementalflag=1; }
7148: }
1.484 raeburn 7149: my $toolsflag=0;
7150: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 7151:
1.635 raeburn 7152: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 7153: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 7154: }
7155:
1.685 raeburn 7156: my $backto_supppath;
1.635 raeburn 7157: if ($env{'form.supppath'} ne '') {
1.685 raeburn 7158: if ($supplementalflag && $allowed) {
7159: $backto_supppath = &validate_supppath($coursenum,$coursedom);
7160: }
1.635 raeburn 7161: }
7162:
1.329 droeschl 7163: my $script='';
7164: my $showdoc=0;
1.457 raeburn 7165: my $addentries = {};
1.475 raeburn 7166: my $container;
1.329 droeschl 7167: my $containertag;
1.508 raeburn 7168: my $pathitem;
1.598 raeburn 7169: my %ltitools;
1.699 raeburn 7170: my $posslti;
1.617 raeburn 7171: my $hiddentop;
1.615 raeburn 7172: my $navmap;
1.617 raeburn 7173: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 7174:
1.464 www 7175: # Do we directly jump somewhere?
1.525 raeburn 7176: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 7177: if ($env{'form.symb'} ne '') {
1.522 raeburn 7178: $env{'form.folderpath'}=
1.617 raeburn 7179: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 7180: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 7181: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 7182: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 7183: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 7184: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 7185: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 7186: }
1.472 raeburn 7187: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 7188: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 7189: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 7190: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 7191: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 7192: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
7193: } elsif ($env{'form.command'} eq 'contents') {
7194: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
7195: } elsif ($env{'form.command'} eq 'home') {
7196: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 7197: }
7198:
1.525 raeburn 7199:
1.445 www 7200: # Where do we store these for when we come back?
7201: my $stored_folderpath='docs_folderpath';
7202: if ($supplementalflag) {
7203: $stored_folderpath='docs_sup_folderpath';
7204: }
1.464 www 7205:
1.519 raeburn 7206: # No folderpath, and in edit mode, see if we have something stored
7207: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 7208: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 7209: {'folderpath' => 'scalar'});
1.615 raeburn 7210:
7211: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
7212: if ($supplementalflag) {
7213: undef($env{'form.folderpath'}) if ($1 eq 'default');
7214: } else {
7215: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
7216: }
7217: } else {
1.523 raeburn 7218: undef($env{'form.folderpath'});
7219: }
1.677 raeburn 7220: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 7221: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 7222: }
1.329 droeschl 7223: }
1.706 raeburn 7224:
7225: # Set folderpath if we are not allowed to make changes and this is supplemental content
1.705 raeburn 7226: if ((!$allowed) && ($supplementalflag)) {
1.446 www 7227: unless ($env{'form.folderpath'} =~ /^supplemental/) {
7228: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 7229: }
7230: }
1.446 www 7231: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 7232: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 7233: $env{'form.folderpath'} = &supplemental_base()
7234: .'&'.
1.329 droeschl 7235: $env{'form.folderpath'};
7236: }
1.685 raeburn 7237: # If allowed and user's role is not advanced check folderpath is not hidden
7238: my $hidden_and_empty;
1.687 raeburn 7239: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 7240: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 7241: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 7242: my $folder = $pathitems[-2];
7243: if ($folder eq '') {
7244: undef($env{'form.folderpath'});
7245: } else {
7246: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 7247: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 7248: $folderurl .= '.page';
7249: } else {
7250: $folderurl .= '.sequence';
7251: }
1.685 raeburn 7252: if ($supplementalflag) {
7253: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
7254: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 7255: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 7256: if (ref($supplemental) eq 'HASH') {
7257: my ($suppmap,$suppmapnum);
7258: if ($folder eq 'supplemental') {
7259: $suppmap = 'default';
7260: $suppmapnum = 0;
7261: } elsif ($folder =~ /^supplemental_(\d+)$/) {
7262: $suppmap = $1;
7263: $suppmapnum = $suppmap;
7264: }
7265: if ($hiddenfolder) {
7266: my $hascontent;
7267: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
7268: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
7269: $hascontent = 1;
7270: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
7271: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
7272: if ($id =~ /^$suppmapnum\:/) {
7273: $hascontent = 1;
7274: last;
7275: }
7276: }
7277: }
7278: last if ($hascontent);
7279: }
7280: unless ($hascontent) {
7281: if ($foldername ne '') {
7282: $hidden_and_empty = $foldername;
7283: } else {
7284: $hidden_and_empty = $folder;
7285: }
7286: }
7287: }
7288: }
7289: } else {
7290: unless (ref($navmap)) {
7291: $navmap = Apache::lonnavmaps::navmap->new();
7292: }
7293: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
7294: $foldername = &HTML::Entities::decode(&unescape($foldername));
7295: if (ref($navmap)) {
7296: if ($hiddenfolder ||
7297: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
7298: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
7299: unless (@resources) {
7300: if ($foldername ne '') {
7301: $hidden_and_empty = $foldername;
7302: } else {
7303: $hidden_and_empty = $folder;
7304: }
7305: }
7306: }
7307: }
1.617 raeburn 7308: }
1.685 raeburn 7309: if ($hidden_and_empty ne '') {
7310: splice(@pathitems,-2);
7311: if (@pathitems) {
7312: $env{'form.folderpath'} = join('&',@pathitems);
7313: } else {
7314: undef($env{'form.folderpath'});
1.615 raeburn 7315: }
7316: }
7317: }
7318: }
7319:
1.446 www 7320: # If after all of this, we still don't have any paths, make them
1.519 raeburn 7321: unless ($env{'form.folderpath'}) {
1.446 www 7322: if ($supplementalflag) {
7323: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 7324: } elsif ($allowed) {
7325: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 7326: }
1.472 raeburn 7327: }
1.446 www 7328:
1.445 www 7329: # Store this
1.484 raeburn 7330: unless ($toolsflag) {
1.615 raeburn 7331: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 7332: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 7333: {'folderpath' => 'scalar'});
1.510 raeburn 7334: }
1.519 raeburn 7335: my $folderpath;
1.484 raeburn 7336: if ($env{'form.folderpath'}) {
1.519 raeburn 7337: $folderpath = $env{'form.folderpath'};
7338: my (@folders)=split('&',$env{'form.folderpath'});
7339: $env{'form.foldername'}=&unescape(pop(@folders));
7340: if ($env{'form.foldername'} =~ /\:1$/) {
7341: $container = 'page';
7342: } else {
7343: $container = 'sequence';
7344: }
7345: $env{'form.folder'}=pop(@folders);
1.484 raeburn 7346: } else {
1.519 raeburn 7347: if ($env{'form.folder'} eq '' ||
7348: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 7349: if ($env{'form.folder'} eq 'supplemental') {
7350: $folderpath=&supplemental_base();
7351: } elsif (!$hiddentop) {
7352: $folderpath='default&'.
7353: &escape(&mt('Main Content').':::::');
7354: }
1.484 raeburn 7355: }
7356: }
1.519 raeburn 7357: $containertag = '<input type="hidden" name="folderpath" value="" />';
7358: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 7359: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
7360: $showdoc='/'.$1;
7361: }
7362: if ($showdoc) { # got called in sequence from course
7363: $allowed=0;
7364: } else {
1.611 raeburn 7365: if ($canedit) {
1.484 raeburn 7366: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
7367: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 7368: }
7369: }
1.329 droeschl 7370: }
7371:
1.344 bisitz 7372: # get personal data
1.329 droeschl 7373: my $uname=$env{'user.name'};
7374: my $udom=$env{'user.domain'};
7375: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
7376:
7377: if ($allowed) {
1.484 raeburn 7378: if ($toolsflag) {
7379: $script .= &inject_data_js();
7380: my ($home,$other,%outhash)=&authorhosts();
7381: if (!$home && $other) {
7382: my @hosts;
7383: foreach my $aurole (keys(%outhash)) {
7384: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7385: push(@hosts,$outhash{$aurole});
7386: }
7387: }
7388: $script .= &dump_switchserver_js(@hosts);
7389: }
1.458 raeburn 7390: } else {
1.570 raeburn 7391: my $tid = 1;
1.484 raeburn 7392: my @tabids;
7393: if ($supplementalflag) {
1.655 raeburn 7394: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 7395: $tid = 2;
1.484 raeburn 7396: } else {
1.726 raeburn 7397: @tabids = ('aa1','bb1','cc1','dd1','ff1');
1.519 raeburn 7398: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 7399: unshift(@tabids,'001');
1.726 raeburn 7400: push(@tabids,'ee1');
1.484 raeburn 7401: }
1.458 raeburn 7402: }
1.484 raeburn 7403: my $tabidstr = join("','",@tabids);
1.699 raeburn 7404: my (%domtools,%crstools);
7405: my %tooltypes = &Apache::loncommon::usable_exttools();
7406: if ($tooltypes{'dom'}) {
7407: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
7408: }
7409: if ($tooltypes{'crs'}) {
7410: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
7411: }
7412: %ltitools = (
7413: dom => \%domtools,
7414: crs => \%crstools,
7415: );
7416: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622 raeburn 7417: my $hostname = $r->hostname();
1.606 raeburn 7418: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 7419: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 7420: &history_tab_js().
7421: &inject_data_js().
1.570 raeburn 7422: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 7423: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 7424: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
7425: if ($hidden_and_empty ne '') {
7426: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
7427: $hidden_and_empty);
7428: $onload .= "javascript:alert('".&js_escape($alert)."');";
7429: }
1.484 raeburn 7430: $addentries = {
1.685 raeburn 7431: onload => $onload,
1.484 raeburn 7432: };
1.458 raeburn 7433: }
1.538 raeburn 7434: $script .= &paste_popup_js();
1.501 raeburn 7435: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
7436: &mt('Switch server?');
7437:
7438:
1.329 droeschl 7439: }
7440: # -------------------------------------------------------------------- Body tag
1.369 bisitz 7441: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 7442: .'// <![CDATA['."\n"
7443: .$script."\n"
7444: .'// ]]>'."\n"
1.595 musolffc 7445: .'</script>'."\n"
7446: .'<script type="text/javascript"
7447: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 7448:
7449: # Breadcrumbs
7450: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 7451:
7452: if ($showdoc) {
1.682 raeburn 7453: my $args;
7454: if ($supplementalflag) {
1.687 raeburn 7455: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
7456: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.705 raeburn 7457: $args = {'bread_crumbs' => $brcrum,
7458: 'bread_crumbs_nomenu' => 1};
1.682 raeburn 7459: } else {
7460: $args = {'force_register' => $showdoc};
7461: }
7462: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 7463: } elsif ($toolsflag) {
1.611 raeburn 7464: my ($breadtext,$breadtitle);
1.617 raeburn 7465: $breadtext = "$crstype Editor";
1.611 raeburn 7466: if ($canedit) {
7467: $breadtitle = 'Editing '.$crstype.' Contents';
7468: } else {
7469: $breadtext .= ' (View-only mode)';
7470: $breadtitle = 'Viewing '.$crstype.' Contents';
7471: }
1.571 raeburn 7472: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7473: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 7474: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
7475: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7476: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7477: $breadtitle)
1.571 raeburn 7478: );
1.510 raeburn 7479: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 7480: unless ($env{'request.role.adv'}) {
7481: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
7482: $r->internal_redirect('/adm/navmaps');
7483: return OK;
7484: }
7485: }
1.510 raeburn 7486: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
1.705 raeburn 7487: my $args = {'bread_crumbs' => $brcrum};
7488: unless (($env{'form.folderpath'} eq '') ||
7489: ($env{'form.folder'} eq 'supplemental')) {
7490: $args->{'bread_crumbs_nomenu'} = 1;
7491: }
1.510 raeburn 7492: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
1.705 raeburn 7493: $args));
1.510 raeburn 7494: } else {
1.611 raeburn 7495: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 7496: $breadtext = "$crstype Editor";
1.611 raeburn 7497: if ($canedit) {
7498: $breadtitle = 'Editing '.$crstype.' Contents';
7499: $helpitem = 'Docs_Adding_Course_Doc';
7500: } else {
7501: $breadtext .= ' (View-only mode)';
7502: $breadtitle = 'Viewing '.$crstype.' Contents';
7503: $helpitem = 'Docs_Viewing_Course_Doc';
7504: }
1.392 raeburn 7505: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7506: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 7507: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 7508: {'add_entries' => $addentries}
7509: )
1.392 raeburn 7510: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7511: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7512: $breadtitle,
7513: $helpitem)
1.392 raeburn 7514: );
7515: }
1.364 bisitz 7516:
1.329 droeschl 7517: my %allfiles = ();
7518: my %codebase = ();
1.440 raeburn 7519: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 7520: if ($canedit) {
1.684 raeburn 7521: undef($suppchanges);
1.329 droeschl 7522: if (($env{'form.uploaddoc.filename'}) &&
7523: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 7524: my $context = $1;
7525: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 7526: undef($hadchanges);
1.440 raeburn 7527: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 7528: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 7529: undef($navmap);
1.329 droeschl 7530: if ($hadchanges) {
7531: &mark_hash_old();
7532: }
1.684 raeburn 7533: if ($suppchanges) {
7534: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
7535: undef($suppchanges);
7536: }
1.440 raeburn 7537: $r->print($upload_output);
7538: } elsif ($env{'form.phase'} eq 'upload_embedded') {
7539: # Process file upload - phase two - upload embedded objects
7540: $uploadphase = 'check_embedded';
7541: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
7542: my $state = &embedded_form_elems($uploadphase,$primaryurl,
7543: $env{'form.newidx'});
7544: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7545: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7546: my ($destination,$dir_root) = &embedded_destination();
7547: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
7548: my $actionurl = '/adm/coursedocs';
1.630 raeburn 7549: my ($result,$flag) =
1.440 raeburn 7550: &Apache::loncommon::upload_embedded('coursedoc',$destination,
7551: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
7552: $actionurl);
7553: $r->print($result.&return_to_editor());
7554: } elsif ($env{'form.phase'} eq 'check_embedded') {
7555: # Process file upload - phase three - modify references in HTML file
7556: $uploadphase = 'modified_orightml';
7557: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7558: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7559: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 7560: my $result =
1.482 raeburn 7561: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
7562: $docuname,$docudom,undef,
7563: $dir_root);
1.630 raeburn 7564: $r->print($result.&return_to_editor());
1.476 raeburn 7565: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
7566: $uploadphase = 'decompress_phase_one';
7567: $r->print(&decompression_phase_one().
7568: &return_to_editor());
7569: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
7570: $uploadphase = 'decompress_phase_two';
7571: $r->print(&decompression_phase_two().
7572: &return_to_editor());
1.329 droeschl 7573: }
7574: }
7575:
1.484 raeburn 7576: if ($allowed && $toolsflag) {
7577: $r->print(&startContentScreen('tools'));
1.708 raeburn 7578: $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom));
1.484 raeburn 7579: $r->print(&endContentScreen());
7580: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 7581: # -----------------------------------------------------------------------------
7582: my %lt=&Apache::lonlocal::texthash(
7583: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 7584: 'upfi' => 'Upload File',
1.553 raeburn 7585: 'upld' => 'Upload Content',
1.706 raeburn 7586: 'srch' => 'Search Repository',
7587: 'impo' => 'Import from Repository',
1.487 raeburn 7588: 'lnks' => 'Import from Stored Links',
1.502 raeburn 7589: 'impm' => 'Import from Assembled Map',
1.630 raeburn 7590: 'imcr' => 'Import from Course Resources',
1.598 raeburn 7591: 'extr' => 'External Resource',
7592: 'extt' => 'External Tool',
1.329 droeschl 7593: 'selm' => 'Select Map',
7594: 'load' => 'Load Map',
7595: 'newf' => 'New Folder',
7596: 'newp' => 'New Composite Page',
7597: 'syll' => 'Syllabus',
1.425 raeburn 7598: 'navc' => 'Table of Contents',
1.343 biermanm 7599: 'sipa' => 'Simple Course Page',
1.329 droeschl 7600: 'sipr' => 'Simple Problem',
1.630 raeburn 7601: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 7602: 'stpr' => 'Standard Problem',
7603: 'news' => 'New sub-directory',
7604: 'crpr' => 'Create Problem',
1.689 raeburn 7605: 'swit' => 'Switch Server',
1.329 droeschl 7606: 'drbx' => 'Drop Box',
1.451 www 7607: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 7608: 'bull' => 'Discussion Board',
1.347 weissno 7609: 'mypi' => 'My Personal Information Page',
1.353 weissno 7610: 'grpo' => 'Group Portfolio',
1.329 droeschl 7611: 'rost' => 'Course Roster',
1.528 raeburn 7612: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 7613: 'imsf' => 'IMS Upload',
7614: 'imsl' => 'Upload IMS package',
1.501 raeburn 7615: 'cms' => 'Origin of IMS package',
7616: 'se' => 'Select',
1.329 droeschl 7617: 'file' => 'File',
7618: 'title' => 'Title',
1.606 raeburn 7619: 'addp' => 'Add Placeholder to course?',
7620: 'uste' => 'Use Template?',
7621: 'fnam' => 'File Name:',
7622: 'loca' => 'Location:',
7623: 'dire' => 'Directory:',
7624: 'cate' => 'Category:',
7625: 'tmpl' => 'Template:',
1.698 raeburn 7626: 'empd' => 'No resources found',
1.329 droeschl 7627: 'comment' => 'Comment',
1.403 raeburn 7628: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 7629: 'bb5' => 'Blackboard 5',
7630: 'bb6' => 'Blackboard 6',
7631: 'angel5' => 'ANGEL 5.5',
7632: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 7633: 'yes' => 'Yes',
7634: 'no' => 'No',
1.618 raeburn 7635: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 7636: );
1.329 droeschl 7637: # -----------------------------------------------------------------------------
1.595 musolffc 7638:
7639: # Calculate free quota space for a user or course. A javascript function checks
7640: # file size to determine if upload should be allowed.
7641: my $quotatype = 'unofficial';
7642: if ($crstype eq 'Community') {
1.601 raeburn 7643: $quotatype = 'community';
7644: } elsif ($crstype eq 'Placement') {
7645: $quotatype = 'placement';
1.595 musolffc 7646: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
7647: $quotatype = 'official';
7648: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
7649: $quotatype = 'textbook';
7650: }
7651: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
7652: 'course',$quotatype); # expressed in MB
7653: my $current_disk_usage = 0;
7654: foreach my $subdir ('docs','supplemental') {
7655: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
7656: "userfiles/$subdir",1); # expressed in kB
7657: }
7658: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 7659: my $usage = $current_disk_usage/1024; # in MB
7660: my $quota = $disk_quota;
7661: my $percent;
7662: if ($disk_quota == 0) {
7663: $percent = 100.0;
7664: } else {
1.619 raeburn 7665: $percent = 100*($usage/$disk_quota);
1.605 raeburn 7666: }
7667: $usage = sprintf("%.2f",$usage);
7668: $quota = sprintf("%.2f",$quota);
7669: $percent = sprintf("%.0f",$percent);
7670: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
7671: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 7672:
1.329 droeschl 7673: my $checkbox=(<<CHBO);
7674: <!-- <label>$lt{'parse'}?
7675: <input type="checkbox" name="parserflag" />
7676: </label> -->
7677: <label>
1.611 raeburn 7678: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 7679: </label>
7680: CHBO
1.501 raeburn 7681: my $imsfolder = $env{'form.folder'};
7682: if ($imsfolder eq '') {
7683: $imsfolder = 'default';
7684: }
7685: my $imspform=(<<IMSFORM);
7686: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
7687: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
7688: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 7689: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 7690: <legend>$lt{'imsf'}</legend>
1.723 raeburn 7691: $quotainfo
7692: <label>$lt{'file'}:<br />
7693: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled /></label>
1.702 raeburn 7694: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501 raeburn 7695: <br />
7696: <p>
7697: $lt{'cms'}:
1.611 raeburn 7698: <select name="source" $disabled>
1.501 raeburn 7699: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 7700: <option value="bb5">$lt{'bb5'}</option>
7701: <option value="bb6">$lt{'bb6'}</option>
7702: <option value="angel5">$lt{'angel5'}</option>
7703: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 7704: </select>
7705: <input type="hidden" name="folder" value="$imsfolder" />
7706: </p>
7707: <input type="hidden" name="phase" value="one" />
1.611 raeburn 7708: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 7709: </fieldset>
7710: </form>
7711: IMSFORM
1.329 droeschl 7712:
7713: my $fileuploadform=(<<FUFORM);
1.501 raeburn 7714: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
7715: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
7716: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 7717: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 7718: <legend>$lt{'upfi'}</legend>
1.371 tempelho 7719: <input type="hidden" name="active" value="aa" />
1.723 raeburn 7720: $quotainfo
7721: <label>$lt{'file'}:<br />
7722: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled /></label>
1.702 raeburn 7723: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 7724: <br />
1.723 raeburn 7725: <label>
1.329 droeschl 7726: $lt{'title'}:<br />
1.723 raeburn 7727: <input type="text" size="60" name="comment" $disabled /></label>
1.508 raeburn 7728: $pathitem
1.329 droeschl 7729: <input type="hidden" name="cmd" value="upload_default" />
7730: <br />
1.458 raeburn 7731: <span class="LC_nobreak" style="float:left">
1.329 droeschl 7732: $checkbox
7733: </span>
1.501 raeburn 7734: <br clear="all" />
1.611 raeburn 7735: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 7736: </fieldset>
7737: </form>
1.383 tempelho 7738: FUFORM
1.329 droeschl 7739:
1.611 raeburn 7740: my $mapimportjs;
7741: if ($canedit) {
7742: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
7743: } else {
7744: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
7745: }
1.502 raeburn 7746: my $importpubform=(<<SEDFFORM);
1.514 raeburn 7747: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 7748: $lt{'impm'}</a>$help{'Load_Map'}
7749: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 7750: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 7751: <legend>$lt{'impm'}</legend>
1.371 tempelho 7752: <input type="hidden" name="active" value="bb" />
1.723 raeburn 7753: <label>$lt{'copm'}<br />
1.502 raeburn 7754: <span class="LC_nobreak">
7755: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 7756: onfocus="this.blur();$mapimportjs" $disabled />
1.723 raeburn 7757: <a href="$mapimportjs">$lt{'selm'}</a></span></label><br />
1.611 raeburn 7758: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 7759: </fieldset>
7760: </form>
7761:
1.383 tempelho 7762: SEDFFORM
1.706 raeburn 7763: my ($importcrsresform,$checkcrsres);
7764: if ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'}) {
7765: $checkcrsres = 1;
7766: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'} ne '0') {
7767: my %domdefs=&Apache::lonnet::get_domain_defaults($coursedom);
1.710 raeburn 7768: my $type = lc($env{'course.'.$env{'request.course.id'}.'.type'});
7769: unless (($type eq 'community') || ($type eq 'placement')) {
7770: $type = 'unofficial';
7771: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'} ne '') {
7772: $type = 'official';
7773: } elsif ($env{'course.'.$env{'request.course.id'}.'internal.textbook'} ne '') {
7774: $type = 'textbook';
7775: } else {
7776: $type = 'unofficial';
7777: }
7778: }
7779: if ($domdefs{$type.'crsauthor'}) {
1.706 raeburn 7780: $checkcrsres = 1;
7781: }
7782: }
7783: if ($checkcrsres) {
7784: my ($numdirs,$pickfile) =
7785: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
7786: "resize_scrollbox('contentscroll','1','0');",
7787: undef,'res');
7788: if ($pickfile) {
7789: $importcrsresform=(<<CRSFORM);
1.690 raeburn 7790: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 7791: $lt{'imcr'}</a>$help{'Course_Resources'}
7792: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
7793: <fieldset id="importcrsresform" style="display: none;">
7794: <legend>$lt{'imcr'}</legend>
1.698 raeburn 7795: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 7796: <input type="hidden" name="active" value="bb" />
7797: $pickfile
1.723 raeburn 7798: <p><label>
1.699 raeburn 7799: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.723 raeburn 7800: </label></p>
1.606 raeburn 7801: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 7802: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 raeburn 7803: </div>
7804: <div id="importcrsresempty" style="display: none;">
7805: <p>
7806: $lt{'empd'}
7807: </p>
7808: </div>
1.606 raeburn 7809: </fieldset>
7810: </form>
7811: CRSFORM
1.706 raeburn 7812: }
1.606 raeburn 7813: }
7814:
1.611 raeburn 7815: my $fromstoredjs;
7816: if ($canedit) {
7817: $fromstoredjs = 'open_StoredLinks_Import()';
7818: } else {
7819: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
7820: }
7821:
1.502 raeburn 7822: my @importpubforma = (
1.706 raeburn 7823: { '<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 7824: { '<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 7825: { '<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 7826: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
7827: );
1.706 raeburn 7828: if ($importcrsresform) {
7829: 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 7830: }
1.502 raeburn 7831: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 7832: my $extresourcesform =
7833: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 7834: $help{'Adding_External_Resource'},
7835: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 7836: my $exttoolform =
7837: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
7838: $help{'Adding_External_Tool'},undef,
7839: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 7840: \%ltitools,$disabled);
1.329 droeschl 7841: if ($allowed) {
1.492 raeburn 7842: my $folder = $env{'form.folder'};
7843: if ($folder eq '') {
7844: $folder='default';
7845: }
1.615 raeburn 7846: if ($canedit) {
7847: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
7848: if ($output) {
7849: $r->print($output);
7850: }
1.538 raeburn 7851: }
1.337 ehlerst 7852: $r->print(<<HIDDENFORM);
7853: <form name="renameform" method="post" action="/adm/coursedocs">
7854: <input type="hidden" name="title" />
7855: <input type="hidden" name="cmd" />
7856: <input type="hidden" name="markcopy" />
7857: <input type="hidden" name="copyfolder" />
7858: $containertag
7859: </form>
1.633 raeburn 7860: <form name="aliasform" method="post" action="/adm/coursedocs">
7861: <input type="hidden" name="alias" />
7862: <input type="hidden" name="cmd" />
7863: $containertag
7864: </form>
1.484 raeburn 7865:
1.337 ehlerst 7866: HIDDENFORM
1.508 raeburn 7867: $r->print(&makesimpleeditform($pathitem)."\n".
7868: &makedocslogform($pathitem."\n".
1.484 raeburn 7869: '<input type="hidden" name="folder" value="'.
7870: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 7871: }
1.442 www 7872:
7873: # Generate the tabs
1.510 raeburn 7874: my ($mode,$needs_end);
1.472 raeburn 7875: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 7876: my @folders = split('&',$env{'form.folderpath'});
7877: unless (@folders > 2) {
7878: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
7879: $needs_end = 1;
7880: }
1.472 raeburn 7881: } else {
1.484 raeburn 7882: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 7883: $needs_end = 1;
1.472 raeburn 7884: }
1.443 www 7885:
1.442 www 7886: #
1.622 raeburn 7887: my $hostname = $r->hostname();
1.442 www 7888: my $savefolderpath;
7889:
1.395 raeburn 7890: if ($allowed) {
1.329 droeschl 7891: my $folder=$env{'form.folder'};
1.615 raeburn 7892: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 7893: $folder='default';
1.356 tempelho 7894: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 7895: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 7896: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 7897: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
7898: }
7899: my $postexec='';
7900: if ($folder eq 'default') {
1.653 raeburn 7901: my $windowname = 'loncapaclient';
7902: if ($env{'request.lti.login'}) {
7903: $windowname .= 'lti';
7904: }
1.372 bisitz 7905: $r->print('<script type="text/javascript">'."\n"
7906: .'// <![CDATA['."\n"
1.653 raeburn 7907: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 7908: .'// ]]>'."\n"
7909: .'</script>'."\n"
1.369 bisitz 7910: );
1.329 droeschl 7911: } else {
7912: #$postexec='self.close();';
7913: }
1.504 raeburn 7914: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
7915: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 7916: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
7917:
7918: my $newnavform=(<<NNFORM);
7919: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 7920: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7921: $pathitem
1.329 droeschl 7922: <input type="hidden" name="importdetail"
7923: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 7924: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 7925: $help{'Navigate_Content'}
7926: </form>
7927: NNFORM
7928: my $newsmppageform=(<<NSPFORM);
7929: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 7930: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7931: $pathitem
1.329 droeschl 7932: <input type="hidden" name="importdetail" value="" />
1.423 onken 7933: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 7934: $help{'Simple Page'}
1.329 droeschl 7935: </form>
7936: NSPFORM
7937:
7938: my $newsmpproblemform=(<<NSPROBFORM);
7939: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 7940: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7941: $pathitem
1.329 droeschl 7942: <input type="hidden" name="importdetail" value="" />
1.423 onken 7943: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 7944: $help{'Simple_Problem'}
1.329 droeschl 7945: </form>
7946:
7947: NSPROBFORM
7948:
7949: my $newdropboxform=(<<NDBFORM);
7950: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 7951: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7952: $pathitem
1.329 droeschl 7953: <input type="hidden" name="importdetail" value="" />
1.423 onken 7954: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 7955: $help{'Dropbox'}
1.344 bisitz 7956: </form>
1.329 droeschl 7957: NDBFORM
7958:
7959: my $newexuploadform=(<<NEXUFORM);
7960: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 7961: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7962: $pathitem
1.329 droeschl 7963: <input type="hidden" name="importdetail" value="" />
1.423 onken 7964: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 7965: $help{'Score_Upload_Form'}
7966: </form>
7967: NEXUFORM
7968:
7969: my $newbulform=(<<NBFORM);
7970: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 7971: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7972: $pathitem
1.329 droeschl 7973: <input type="hidden" name="importdetail" value="" />
1.423 onken 7974: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 7975: $help{'Bulletin Board'}
7976: </form>
7977: NBFORM
7978:
7979: my $newaboutmeform=(<<NAMFORM);
7980: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 7981: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7982: $pathitem
1.329 droeschl 7983: <input type="hidden" name="importdetail"
7984: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7985: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 7986: $help{'My Personal Information Page'}
1.329 droeschl 7987: </form>
7988: NAMFORM
7989:
7990: my $newaboutsomeoneform=(<<NASOFORM);
7991: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 7992: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7993: $pathitem
1.329 droeschl 7994: <input type="hidden" name="importdetail" value="" />
1.423 onken 7995: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 7996: </form>
7997: NASOFORM
7998:
7999: my $newrosterform=(<<NROSTFORM);
8000: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 8001: <input type="hidden" name="active" value="ee" />
1.508 raeburn 8002: $pathitem
1.329 droeschl 8003: <input type="hidden" name="importdetail"
8004: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 8005: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 8006: $help{'Course_Roster'}
1.329 droeschl 8007: </form>
8008: NROSTFORM
8009:
1.534 raeburn 8010: my $newwebpage;
8011: if ($folder =~ /^default_?(\d*)$/) {
8012: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
8013: if ($1) {
8014: $newwebpage .= $1;
8015: } else {
8016: $newwebpage .= 'default';
8017: }
8018: $newwebpage .= '/new.html';
8019: }
8020: my $newwebpageform =(<<NWEBFORM);
8021: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 8022: <input type="hidden" name="active" value="ff" />
1.534 raeburn 8023: $pathitem
8024: <input type="hidden" name="importdetail" value="$newwebpage" />
8025: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 8026: $help{'Web_Page'}
1.534 raeburn 8027: </form>
8028: NWEBFORM
1.701 raeburn 8029: my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606 raeburn 8030: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 8031: my $machines_str = "'".join("','",@ids)."'";
8032: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 8033: if ($env{'user.author'}) {
8034: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 8035: $is_home{'author'} = 1;
1.606 raeburn 8036: }
1.691 raeburn 8037: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 8038: }
8039: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
8040: ['active'],['ca','aa']);
1.691 raeburn 8041: my %by_roletype;
1.606 raeburn 8042: if (keys(%roleshash)) {
8043: foreach my $entry (keys(%roleshash)) {
8044: my ($auname,$audom,$roletype) = split(/:/,$entry);
8045: my $key = $entry;
8046: $key =~ s/:/___/g;
1.691 raeburn 8047: my $author = $auname.'___'.$audom;
8048: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 8049: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 8050: $toppath{$author} = "/priv/$audom/$auname";
8051: if (grep(/^\Q$rolehome\E$/,@ids)) {
8052: $is_home{$author} = 1;
1.606 raeburn 8053: }
1.691 raeburn 8054: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
8055: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 8056: }
1.691 raeburn 8057: }
8058: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
8059: if (grep(/^\Q$crshome\E$/,@ids)) {
8060: $is_home{'course'} = 1;
8061: }
8062: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
1.723 raeburn 8063: my $pickdir = '<label>'.$lt{'loca'}.
1.691 raeburn 8064: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
8065: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
8066: if ($env{'user.author'}) {
8067: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
8068: }
8069: if (keys(%by_roletype)) {
8070: foreach my $possrole ('ca','aa') {
8071: if (ref($by_roletype{$possrole}) eq 'HASH') {
8072: my $roletitle = &Apache::lonnet::plaintext($possrole);
8073: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
8074: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
8075: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
8076: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 8077: }
8078: }
8079: }
8080: }
1.706 raeburn 8081: if ($checkcrsres) {
8082: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n";
8083: }
1.723 raeburn 8084: $pickdir .= '</select></label><br />'."\n".
8085: '<label>'.$lt{'dire'}.
1.691 raeburn 8086: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
8087: '<option value=""></option>'.
1.723 raeburn 8088: '</select></label><br />'."\n";
1.606 raeburn 8089: my %seltemplate_menus;
8090: my @files = &Apache::lonhomework::get_template_list('problem');
8091: my @noexamplelink = ('blank.problem','blank.library','script.library');
8092: my $currentcategory = '';
8093: my @ordered = ('');
8094: my %templatehelp;
8095: my $defcategory = '';
8096: my @catorder = ($defcategory);
8097: $seltemplate_menus{$defcategory}->{'order'} = [''];
8098: $seltemplate_menus{$defcategory}->{'text'} = '';
8099: foreach my $file (@files) {
8100: if (ref($file) eq 'ARRAY') {
8101: my ($path,$title,$category,$help) = @{$file};
8102: next if ($title !~ /\S/);
8103: if (&js_escape($category) ne $currentcategory) {
8104: $currentcategory = &js_escape($category);
8105: push(@catorder,&js_escape($currentcategory));
8106: $seltemplate_menus{$currentcategory}->{'text'} = $category;
8107: $seltemplate_menus{$currentcategory}->{'default'} = '';
8108: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
8109: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
8110: }
8111: if ($path) {
8112: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
8113: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
8114: if ($help) {
8115: $templatehelp{$path} = $help;
8116: }
8117: }
8118: }
8119: }
8120:
1.723 raeburn 8121: my ($templates,$haslabel);
8122: if ($lt{'cate'} ne '') {
8123: $templates = '<label>';
8124: $haslabel = 1;
8125: }
8126: $templates .= $lt{'cate'}.' '.
8127: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
8128: $defcategory,'tempcategory','template',
8129: \%seltemplate_menus,\@catorder,
8130: "resize_scrollbox('contentscroll','1','0');",
8131: "toggleExampleText();",'template',$haslabel).'<br />';
1.606 raeburn 8132: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
1.701 raeburn 8133: '<span id="newresexample">'.&mt('Example').'</span></a>';
1.706 raeburn 8134: my $crsresform;
8135: if (($env{'user.author'}) || ($checkcrsres)) {
8136: $crsresform=(<<RESFORM);
1.691 raeburn 8137: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.706 raeburn 8138: $lt{'stpr'}</a>$help{'Standard_Problem'}
1.606 raeburn 8139: <form action="/adm/coursedocs" method="post" name="courseresform">
8140: <fieldset id="crsresform" style="display:none;">
8141: <legend>$lt{'stpr'}</legend>
1.655 raeburn 8142: <input type="hidden" name="active" value="bb" />
1.606 raeburn 8143: <p>
8144: $pickdir
1.701 raeburn 8145: </p>
1.691 raeburn 8146: <div id="newstdproblem" style="display:none;">
1.701 raeburn 8147: <p>
1.606 raeburn 8148: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 8149: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 8150:
1.611 raeburn 8151: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.723 raeburn 8152: </span><label for="newsubdirname"><span id="newsubdir"></span></label>
1.606 raeburn 8153: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701 raeburn 8154: </p>
1.699 raeburn 8155: </div>
1.723 raeburn 8156: <label>$lt{'fnam'}
8157: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled /></label>
1.701 raeburn 8158: <div id="newresource" style="display:none">
1.606 raeburn 8159: <p>
8160: $lt{'addp'}
1.611 raeburn 8161: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 8162: $lt{'no'}</label>
1.611 raeburn 8163: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 8164: $lt{'yes'}</label>
1.723 raeburn 8165: <label for="newresourcetitle"><span id="newrestitle"></span></label>
1.611 raeburn 8166: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701 raeburn 8167: </p>
1.606 raeburn 8168: </div>
8169: <p>
8170: $lt{'uste'}
1.611 raeburn 8171: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 8172: $lt{'no'}</label>
1.611 raeburn 8173: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 8174: $lt{'yes'}</label>
1.701 raeburn 8175: </p>
1.606 raeburn 8176: <div id="newrestemplate" style="display:none">
8177: $templates
8178: $templatepreview
8179: </div>
8180: <span class="LC_nobreak">
1.701 raeburn 8181: <input type="hidden" name="folderpath" value="$showpath" />
1.611 raeburn 8182: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 8183: </span>
1.691 raeburn 8184: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 8185: $rolehomes
8186: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
8187: </div>
1.606 raeburn 8188: </fieldset>
8189: </form>
8190:
8191: RESFORM
1.706 raeburn 8192: }
1.534 raeburn 8193:
1.342 ehlerst 8194: my $specialdocumentsform;
1.383 tempelho 8195: my @specialdocumentsforma;
1.451 www 8196: my $gradingform;
8197: my @gradingforma;
8198: my $communityform;
8199: my @communityforma;
1.351 ehlerst 8200: my $newfolderform;
1.390 tempelho 8201: my $newfolderb;
1.342 ehlerst 8202:
1.451 www 8203: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 8204:
1.329 droeschl 8205: my $newpageform=(<<NPFORM);
8206: <form action="/adm/coursedocs" method="post" name="newpage">
8207: <input type="hidden" name="folderpath" value="$path" />
8208: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 8209: <input type="hidden" name="active" value="ee" />
1.423 onken 8210: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 8211: $help{'Adding_Pages'}
1.329 droeschl 8212: </form>
8213: NPFORM
1.390 tempelho 8214:
8215:
1.351 ehlerst 8216: $newfolderform=(<<NFFORM);
1.329 droeschl 8217: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 8218: $pathitem
1.329 droeschl 8219: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 8220: <input type="hidden" name="active" value="" />
1.422 onken 8221: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 8222: </form>
8223: NFFORM
8224:
8225: my $newsylform=(<<NSYLFORM);
8226: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 8227: <input type="hidden" name="active" value="ee" />
1.508 raeburn 8228: $pathitem
1.329 droeschl 8229: <input type="hidden" name="importdetail"
8230: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 8231: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 8232: $help{'Syllabus'}
1.383 tempelho 8233:
1.329 droeschl 8234: </form>
8235: NSYLFORM
1.364 bisitz 8236:
1.329 droeschl 8237: my $newgroupfileform=(<<NGFFORM);
8238: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 8239: <input type="hidden" name="active" value="ee" />
1.508 raeburn 8240: $pathitem
1.329 droeschl 8241: <input type="hidden" name="importdetail"
8242: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 8243: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 8244: $help{'Group Portfolio'}
1.329 droeschl 8245: </form>
8246: NGFFORM
1.672 raeburn 8247: if ($container eq 'page') {
8248: @specialdocumentsforma=(
8249: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
8250: );
8251: } else {
8252: @specialdocumentsforma=(
1.421 onken 8253: {'<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 8254: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 8255: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 8256: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 8257: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 8258: );
8259: }
1.451 www 8260: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
8261:
1.655 raeburn 8262: my @external = (
8263: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 8264: );
1.699 raeburn 8265: if ($posslti) {
1.655 raeburn 8266: push(@external,
8267: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
8268: );
1.598 raeburn 8269: }
1.655 raeburn 8270: my $externalform = &create_form_ul(&create_list_elements(@external));
8271:
8272: my @importdoc = ();
1.519 raeburn 8273: unless ($container eq 'page') {
8274: push(@importdoc,
8275: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
8276: );
8277: }
8278: push(@importdoc,
1.558 raeburn 8279: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 8280: );
1.501 raeburn 8281: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 8282:
1.451 www 8283: @gradingforma=(
8284: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
8285: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
1.706 raeburn 8286: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
1.451 www 8287: );
1.706 raeburn 8288: if ($crsresform) {
8289: push(@gradingforma,
8290: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform}
8291: );
8292: }
1.451 www 8293: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
8294:
8295: @communityforma=(
8296: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
8297: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
8298: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 8299: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
8300: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 8301: );
8302: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 8303:
1.330 tempelho 8304: my %orderhash = (
1.553 raeburn 8305: 'aa' => ['Upload',$fileuploadform],
1.707 raeburn 8306: 'bb' => ['External',$externalform],
8307: 'cc' => ['Import',$importpubform],
1.701 raeburn 8308: 'dd' => ['Assessment',$gradingform],
1.673 raeburn 8309: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 8310: );
1.519 raeburn 8311: unless ($container eq 'page') {
1.434 raeburn 8312: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 8313: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 8314: }
8315:
1.341 ehlerst 8316: $hadchanges=0;
1.484 raeburn 8317: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 8318: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 8319: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 8320: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 8321: undef($navmap);
1.443 www 8322: if ($error) {
8323: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
8324: }
1.639 raeburn 8325: if ($hadchanges) {
8326: unless (&is_hash_old()) {
1.638 raeburn 8327: &mark_hash_old();
8328: }
8329: }
1.341 ehlerst 8330:
1.443 www 8331: &changewarning($r,'');
8332: }
1.458 raeburn 8333: }
1.442 www 8334:
1.443 www 8335: # Supplemental documents start here
8336:
1.329 droeschl 8337: my $folder=$env{'form.folder'};
1.443 www 8338: unless ($supplementalflag) {
1.329 droeschl 8339: $folder='supplemental';
8340: }
1.685 raeburn 8341: if (($folder eq 'supplemental') &&
1.329 droeschl 8342: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 8343: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 8344: } elsif ($allowed) {
1.356 tempelho 8345: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 8346: }
1.508 raeburn 8347: $pathitem = '<input type="hidden" name="folderpath" value="'.
8348: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 8349: if ($allowed) {
8350: my $folderseq=
1.504 raeburn 8351: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 8352:
8353: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 8354: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
8355: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 8356: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 8357: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 8358: <legend>$lt{'upfi'}</legend>
1.630 raeburn 8359: <input type="hidden" name="active" value="ee" />
1.723 raeburn 8360: $quotainfo
8361: <label>$lt{'file'}:<br />
8362: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled /></label>
1.702 raeburn 8363: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 8364: <br />
8365: <br />
8366: <span class="LC_nobreak">
8367: $checkbox
8368: </span>
8369: <br /><br />
1.723 raeburn 8370: <label>$lt{'comment'}:<br />
8371: <textarea cols="50" rows="4" name="comment"></textarea></label>
1.329 droeschl 8372: <br />
1.508 raeburn 8373: $pathitem
1.329 droeschl 8374: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 8375: <input type='submit' value="$lt{'upld'}" />
1.700 raeburn 8376: </fieldset>
1.501 raeburn 8377: </form>
1.329 droeschl 8378: SUPDOCFORM
8379:
8380: my $supnewfolderform=(<<SNFFORM);
8381: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 8382: <input type="hidden" name="active" value="" />
1.508 raeburn 8383: $pathitem
1.329 droeschl 8384: <input type="hidden" name="importdetail" value="" />
1.423 onken 8385: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 8386: $help{'Adding_Folders'}
1.329 droeschl 8387: </form>
8388: SNFFORM
1.383 tempelho 8389:
1.510 raeburn 8390: my $supextform =
8391: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 8392: $help{'Adding_External_Resource'},
8393: undef,undef,undef,undef,undef,undef,
8394: $disabled);
1.329 droeschl 8395:
1.598 raeburn 8396: my $supexttoolform =
8397: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
8398: $help{'Adding_External_Tool'},
8399: undef,undef,'tool',$coursedom,
1.611 raeburn 8400: $coursenum,\%ltitools,$disabled);
1.598 raeburn 8401:
1.329 droeschl 8402: my $supnewsylform=(<<SNSFORM);
8403: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 8404: <input type="hidden" name="active" value="ff" />
1.508 raeburn 8405: $pathitem
1.329 droeschl 8406: <input type="hidden" name="importdetail"
8407: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 8408: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 8409: $help{'Syllabus'}
8410: </form>
8411: SNSFORM
8412:
8413: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 8414: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 8415: <input type="hidden" name="active" value="ff" />
1.508 raeburn 8416: $pathitem
1.329 droeschl 8417: <input type="hidden" name="importdetail"
8418: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 8419: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 8420: $help{'My Personal Information Page'}
1.329 droeschl 8421: </form>
8422: SNAMFORM
8423:
1.534 raeburn 8424: my $supwebpage;
8425: if ($folder =~ /^supplemental_?(\d*)$/) {
8426: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
8427: if ($1) {
8428: $supwebpage .= $1;
8429: } else {
8430: $supwebpage .= 'default';
8431: }
8432: $supwebpage .= '/new.html';
8433: }
8434: my $supwebpageform =(<<SWEBFORM);
8435: <form action="/adm/coursedocs" method="post" name="supwebpage">
8436: <input type="hidden" name="active" value="cc" />
8437: $pathitem
8438: <input type="hidden" name="importdetail" value="$supwebpage" />
8439: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 8440: $help{'Web_Page'}
1.534 raeburn 8441: </form>
8442: SWEBFORM
8443:
1.333 muellerd 8444:
1.383 tempelho 8445: my @specialdocs = (
1.618 raeburn 8446: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 8447: =>$supnewsylform},
1.611 raeburn 8448: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 8449: =>$supnewaboutmeform},
1.534 raeburn 8450: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
8451:
1.383 tempelho 8452: );
1.655 raeburn 8453: my @supexternal = (
8454: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
8455: =>$supextform});
1.699 raeburn 8456: if ($posslti) {
1.655 raeburn 8457: push(@supexternal,
8458: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 8459: =>$supexttoolform});
8460: }
1.655 raeburn 8461: my @supimportdoc = (
1.598 raeburn 8462: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 8463: =>$supupdocform},
1.598 raeburn 8464: );
1.501 raeburn 8465:
8466: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 8467: my %suporderhash = (
1.390 tempelho 8468: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 8469: 'dd' => ['Upload',$supupdocform],
8470: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 8471: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 8472: );
1.443 www 8473: if ($supplementalflag) {
1.682 raeburn 8474: $suppchanges = 0;
8475: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
8476: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
8477: \%ltitools,$canedit,$hostname);
8478: if ($error) {
8479: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
8480: }
8481: if ($suppchanges) {
1.684 raeburn 8482: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 8483: undef($suppchanges);
8484: }
1.393 raeburn 8485: }
1.443 www 8486: } elsif ($supplementalflag) {
1.458 raeburn 8487: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 8488: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
8489: $hostname);
1.393 raeburn 8490: if ($error) {
8491: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 8492: }
1.393 raeburn 8493: }
1.389 tempelho 8494:
1.510 raeburn 8495: if ($needs_end) {
8496: $r->print(&endContentScreen());
8497: }
1.383 tempelho 8498:
1.329 droeschl 8499: if ($allowed) {
8500: $r->print('
8501: <form method="post" name="extimport" action="/adm/coursedocs">
8502: <input type="hidden" name="title" />
8503: <input type="hidden" name="url" />
8504: <input type="hidden" name="useform" />
8505: <input type="hidden" name="residx" />
8506: </form>');
8507: }
1.484 raeburn 8508: } elsif ($showdoc) {
1.329 droeschl 8509: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 8510: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 8511: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 8512: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 8513: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 8514: }
8515: }
1.630 raeburn 8516: unless ($noendpage) {
1.606 raeburn 8517: $r->print(&Apache::loncommon::end_page());
8518: }
1.329 droeschl 8519: return OK;
1.364 bisitz 8520: }
1.329 droeschl 8521:
1.440 raeburn 8522: sub embedded_form_elems {
8523: my ($phase,$primaryurl,$newidx) = @_;
8524: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 8525: $newidx =~s /\D+//g;
1.440 raeburn 8526: return <<STATE;
8527: <input type="hidden" name="folderpath" value="$folderpath" />
8528: <input type="hidden" name="cmd" value="upload_embedded" />
8529: <input type="hidden" name="newidx" value="$newidx" />
8530: <input type="hidden" name="phase" value="$phase" />
8531: <input type="hidden" name="primaryurl" value="$primaryurl" />
8532: STATE
8533: }
8534:
8535: sub embedded_destination {
8536: my $folder=$env{'form.folder'};
8537: my $destination = 'docs/';
8538: if ($folder =~ /^supplemental/) {
8539: $destination = 'supplemental/';
8540: }
8541: if (($folder eq 'default') || ($folder eq 'supplemental')) {
8542: $destination .= 'default/';
8543: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
8544: $destination .= $2.'/';
8545: }
1.634 raeburn 8546: my $newidx = $env{'form.newidx'};
8547: $newidx =~s /\D+//g;
8548: if ($newidx) {
8549: $destination .= $newidx;
8550: }
1.440 raeburn 8551: my $dir_root = '/userfiles';
8552: return ($destination,$dir_root);
8553: }
8554:
8555: sub return_to_editor {
8556: my $actionurl = '/adm/coursedocs';
8557: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
8558: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
8559: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
8560: '</a></p>';
8561: }
8562:
1.476 raeburn 8563: sub decompression_info {
8564: my ($destination,$dir_root) = &embedded_destination();
8565: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
8566: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8567: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
8568: my $container='sequence';
1.480 raeburn 8569: my ($pathitem,$hiddenelem);
1.583 raeburn 8570: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 8571: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 8572: $container='page';
8573: }
1.480 raeburn 8574: unshift(@hiddens,$pathitem);
8575: foreach my $item (@hiddens) {
1.634 raeburn 8576: if ($item eq 'newidx') {
8577: next if ($env{'form.'.$item} =~ /\D/);
8578: }
1.480 raeburn 8579: if ($env{'form.'.$item}) {
8580: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 8581: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 8582: }
1.477 raeburn 8583: }
1.476 raeburn 8584: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
8585: $hiddenelem);
8586: }
8587:
8588: sub decompression_phase_one {
8589: my ($dir,$file,$warning,$error,$output);
8590: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8591: &decompression_info();
1.490 raeburn 8592: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 8593: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
8594: } else {
8595: my $file = $1;
1.630 raeburn 8596: $output =
1.481 raeburn 8597: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
8598: $destination,$dir_root,
8599: $hiddenelem);
8600: if ($env{'form.autoextract_camtasia'}) {
8601: $output .= &remove_archive($docudom,$docuname,$container);
8602: }
1.476 raeburn 8603: }
8604: if ($error) {
8605: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
8606: $error.'</p>'."\n";
8607: }
8608: if ($warning) {
8609: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
8610: }
8611: return $output;
8612: }
8613:
8614: sub decompression_phase_two {
8615: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8616: &decompression_info();
1.481 raeburn 8617: my $output;
1.480 raeburn 8618: if ($env{'form.archivedelete'}) {
1.481 raeburn 8619: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 8620: }
8621: $output .=
1.481 raeburn 8622: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 8623: $destination,$dir_root,$hiddenelem);
8624: return $output;
8625: }
8626:
1.480 raeburn 8627: sub remove_archive {
8628: my ($docudom,$docuname,$container) = @_;
8629: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 8630: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 8631: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
8632: if ($fatal) {
8633: if ($container eq 'page') {
8634: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
8635: } else {
8636: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
8637: }
1.583 raeburn 8638: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8639: } else {
8640: my $currcmd = $env{'form.cmd'};
8641: my $position = $env{'form.position'};
1.583 raeburn 8642: my $archiveidx = $position;
1.563 raeburn 8643: if ($position > 0) {
1.583 raeburn 8644: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
8645: $archiveidx = $position-1;
8646: }
8647: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 8648: my ($title,$url,@rrest) =
1.583 raeburn 8649: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
8650: if ($url eq $env{'form.archiveurl'}) {
8651: if (&handle_edit_cmd($docuname,$docudom)) {
8652: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 8653: if ($suppchanges) {
8654: &Apache::lonnet::update_supp_caches($docudom,$docuname);
8655: undef($suppchanges);
8656: }
1.583 raeburn 8657: if ($fatal) {
8658: if ($container eq 'page') {
8659: $delwarning = &mt('An error occurred updating the contents of the current page.');
8660: } else {
8661: $delwarning = &mt('An error occurred updating the contents of the current folder.');
8662: }
1.480 raeburn 8663: } else {
1.583 raeburn 8664: $delresult = &mt('Archive file removed.');
1.480 raeburn 8665: }
8666: }
1.583 raeburn 8667: } else {
8668: $delwarning .= &mt('Archive file had unexpected item number in folder.').
8669: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8670: }
8671: }
8672: $env{'form.cmd'} = $currcmd;
8673: }
8674: if ($delwarning) {
8675: $output = '<p class="LC_warning">'.
8676: $delwarning.
8677: '</p>';
8678: }
8679: if ($delresult) {
8680: $output .= '<p class="LC_info">'.
8681: $delresult.
8682: '</p>';
8683: }
1.481 raeburn 8684: return $output;
1.480 raeburn 8685: }
8686:
1.484 raeburn 8687: sub generate_admin_menu {
1.708 raeburn 8688: my ($crstype,$canedit,$coursenum,$coursedom) = @_;
1.484 raeburn 8689: my $lc_crstype = lc($crstype);
8690: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 8691: my %lt= ( # do not translate here
1.484 raeburn 8692: 'vc' => 'Verify Content',
8693: 'cv' => 'Check/Set Resource Versions',
8694: 'ls' => 'List Resource Identifiers',
1.651 raeburn 8695: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.708 raeburn 8696: 'ca' => "Enter $crstype Authoring Space",
1.484 raeburn 8697: 'imse' => 'Export contents to IMS Archive',
1.712 raeburn 8698: 'dcd' => 'Copy uploaded content to Authoring Space',
8699: 'cpc' => 'Copy from Course Authoring to User Authoring',
1.562 bisitz 8700: );
1.712 raeburn 8701: my ($candump,$dumpurl,$exportcrsurl);
1.484 raeburn 8702: if ($home + $other > 0) {
8703: $candump = 'F';
8704: if ($home) {
8705: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
1.712 raeburn 8706: $exportcrsurl = "javascript:injectData(document.courseverify,'dummy','copyauthored','$lt{'cpc'}')";
1.484 raeburn 8707: } else {
8708: my @hosts;
8709: foreach my $aurole (keys(%outhash)) {
8710: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
8711: push(@hosts,$outhash{$aurole});
1.538 raeburn 8712: }
1.484 raeburn 8713: }
8714: if (@hosts == 1) {
8715: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
8716: '&role='.
8717: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
8718: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
8719: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
1.712 raeburn 8720: $exportcrsurl = $dumpurl;
1.484 raeburn 8721: } else {
8722: $dumpurl = "javascript:choose_switchserver_window()";
1.712 raeburn 8723: $exportcrsurl = $dumpurl;
1.484 raeburn 8724: }
8725: }
8726: }
8727: my @menu=
8728: ({ categorytitle=>'Administration',
8729: items =>[
8730: { linktext => $lt{'vc'},
8731: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
8732: permission => 'F',
1.571 raeburn 8733: help => 'Docs_Verify_Content',
1.484 raeburn 8734: icon => 'verify.png',
8735: linktitle => 'Verify contents can be retrieved/rendered',
8736: },
8737: { linktext => $lt{'cv'},
8738: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
8739: permission => 'F',
1.571 raeburn 8740: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 8741: icon => 'resversion.png',
8742: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
8743: },
8744: { linktext => $lt{'ls'},
8745: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
8746: permission => 'F',
8747: #help => '',
8748: icon => 'symbs.png',
8749: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
8750: },
1.651 raeburn 8751: { linktext => $lt{'ct'},
8752: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
8753: permission => 'F',
8754: help => 'Docs_Short_URLs',
8755: icon => 'shorturls.png',
8756: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
8757: },
1.484 raeburn 8758: ]
1.611 raeburn 8759: });
8760: if ($canedit) {
1.708 raeburn 8761: my ($crsauname,$crsaudom,$crshome);
8762: if (($coursenum ne '') && ($coursedom ne '')) {
8763: my $crsauthorurl = "/priv/$coursedom/$coursenum/";
8764: ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl);
8765: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8766: my @ids=&Apache::lonnet::current_machine_ids();
8767: my $linkurl;
8768: if (grep(/^\Q$crshome\E$/,@ids)) {
8769: $linkurl = $crsauthorurl;
8770: } else {
1.720 raeburn 8771: my $jscall = &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1);
8772: if ($jscall) {
8773: $linkurl = 'javascript:'.$jscall;
8774: }
1.708 raeburn 8775: }
1.720 raeburn 8776: if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY') && ($linkurl)) {
1.708 raeburn 8777: push(@{$menu[0]->{items}},
8778: { linktext => $lt{'ca'},
8779: url => $linkurl,
8780: permission => 'F',
8781: help => 'Docs_Course_Authorspace',
8782: icon => 'impcrsau.png',
8783: linktitle => $lt{'ca'},
8784: });
8785: }
8786: }
8787: }
1.611 raeburn 8788: push(@menu,
1.484 raeburn 8789: { categorytitle=>'Export',
8790: items =>[
8791: { linktext => $lt{'imse'},
8792: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
8793: permission => 'F',
8794: help => 'Docs_Export_Course_Docs',
8795: icon => 'imsexport.png',
8796: linktitle => $lt{'imse'},
8797: },
8798: { linktext => $lt{'dcd'},
8799: url => $dumpurl,
8800: permission => $candump,
1.571 raeburn 8801: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 8802: icon => 'dump.png',
8803: linktitle => $lt{'dcd'},
8804: },
8805: ]
8806: });
1.712 raeburn 8807: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8808: if ((ref($menu[1]) eq 'HASH') && (ref($menu[1]->{'items'}) eq 'ARRAY')) {
8809: push(@{$menu[1]->{items}},
8810: { linktext => $lt{'cpc'},
8811: url => $exportcrsurl,
8812: permission => 'F',
8813: help => 'Docs_Export_Course_Author',
8814: icon => 'res.png',
8815: linktitle => $lt{'cpc'},
8816: });
8817: }
8818: }
1.611 raeburn 8819: }
1.484 raeburn 8820: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
8821: '<input type="hidden" id="dummy" />'."\n".
8822: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
8823: '</form>';
1.329 droeschl 8824: }
8825:
8826: sub generate_edit_table {
1.538 raeburn 8827: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 8828: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 8829: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 8830: my %orderhash = %{$orderhash_ref};
1.611 raeburn 8831: my ($form, $activetab, $active, $disabled);
1.570 raeburn 8832: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 8833: $activetab = $env{'form.active'};
8834: }
1.611 raeburn 8835: unless ($canedit) {
8836: $disabled = ' disabled="disabled"';
8837: }
1.472 raeburn 8838: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 8839: my $backtext = &mt('Exit Editor');
1.458 raeburn 8840: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 8841: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
8842: '<li class="goback">'.
1.546 raeburn 8843: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 8844: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
8845: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
8846: '<li>'.
8847: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
8848: &mt('Undo Delete').'</a></li>'."\n";
8849: if ($env{'form.docslog'}) {
8850: $form .= '<li class="active">';
8851: } else {
8852: $form .= '<li>';
8853: }
8854: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
8855: &mt('History').'</a></li>'."\n";
8856: if ($env{'form.docslog'}) {
8857: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
8858: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 8859: }
1.458 raeburn 8860: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 8861: if($name ne '00'){
1.371 tempelho 8862: if($activetab eq '' || $activetab ne $name){
8863: $active = '';
8864: }elsif($activetab eq $name){
8865: $active = 'class="active"';
8866: }
1.458 raeburn 8867: $form .= '<li style="float:right" '.$active
1.484 raeburn 8868: .' 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 8869: } else {
1.570 raeburn 8870: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 8871:
8872: }
1.329 droeschl 8873: }
1.484 raeburn 8874: $form .= '</ul>'."\n";
8875: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 8876:
8877: if ($to_show ne '') {
1.538 raeburn 8878: my $saveform;
8879: if ($need_save) {
8880: my $button = &mt('Make changes');
8881: my $path;
8882: if ($env{'form.folderpath'}) {
8883: $path =
8884: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
8885: }
8886: $saveform = <<"END";
8887: <div id="multisave" style="display:none; clear:both;" >
8888: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
8889: <input type="hidden" name="folderpath" value="$path" />
8890: <input type="hidden" name="symb" value="$env{'form.symb'}" />
8891: <input type="hidden" name="allhiddenresource" value="" />
8892: <input type="hidden" name="allencrypturl" value="" />
8893: <input type="hidden" name="allrandompick" value="" />
8894: <input type="hidden" name="allrandomorder" value="" />
8895: <input type="hidden" name="changeparms" value="" />
8896: <input type="hidden" name="multiremove" value="" />
8897: <input type="hidden" name="multicut" value="" />
8898: <input type="hidden" name="multicopy" value="" />
8899: <input type="hidden" name="multichange" value="" />
8900: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 8901: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 8902: </form>
8903: </div>
8904: END
8905: }
8906: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 8907: }
1.363 ehlerst 8908: foreach my $field (keys(%orderhash)){
1.390 tempelho 8909: if($field ne '00'){
1.422 onken 8910: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 8911: $active = 'style="display: none;float:left"';
1.422 onken 8912: }elsif($activetab eq $field){
1.458 raeburn 8913: $active = 'style="display:block;float:left"';
1.422 onken 8914: }
8915: $form .= '<div id="'.$field.$tid.'"'
8916: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 8917: .'</div>'."\n";
1.363 ehlerst 8918: }
8919: }
1.484 raeburn 8920: unless ($env{'form.docslog'}) {
8921: $form .= '</div></div>'."\n";
8922: }
1.329 droeschl 8923: return $form;
8924: }
8925:
8926: sub editing_js {
1.622 raeburn 8927: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
8928: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 8929: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 8930: p_mnf => 'Name of New Folder',
8931: t_mnf => 'New Folder',
8932: p_mnp => 'Name of New Page',
8933: t_mnp => 'New Page',
1.451 www 8934: p_mxu => 'Title for the External Score',
1.349 biermanm 8935: p_msp => 'Name of Simple Course Page',
1.329 droeschl 8936: p_msb => 'Title for the Problem',
8937: p_mdb => 'Title for the Drop Box',
1.336 schafran 8938: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 8939: p_mwp => 'Title for Web Page',
1.606 raeburn 8940: p_mnr => 'Title for the Resource',
1.348 weissno 8941: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 8942: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 8943: p_mab_alrt1 => 'Not a valid user:domain',
8944: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
8945: p_chn => 'New Title',
8946: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 8947: p_rmr2a => 'Remove',
8948: p_rmr2b => '?',
8949: p_rmr3a => 'Remove those',
8950: p_rmr3b => 'items?',
8951: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
8952: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 8953: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
8954: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 8955: p_ctr2a => 'Cut',
8956: p_ctr2b => '?',
8957: p_ctr3a => 'Cut those',
8958: p_ctr3b => 'items?',
1.633 raeburn 8959: setal => 'Enter a (unique) alias',
8960: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 8961: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 8962: imsfile => 'You must choose an IMS package for import',
8963: imscms => 'You must select which Course Management System was the source of the IMS package',
8964: invurl => 'Invalid URL',
8965: titbl => 'Title is blank',
1.538 raeburn 8966: more => '(More ...)',
8967: less => '(Less ...)',
1.543 raeburn 8968: noor => 'No actions selected or changes to settings specified.',
8969: noch => 'No changes to settings specified.',
8970: noac => 'No actions selected.',
1.606 raeburn 8971: nofi => 'No file selected',
8972: tinc => 'Title in course',
8973: sunm => 'Sub-directory name',
1.618 raeburn 8974: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 8975: sele => 'Select',
8976: swit => 'Switch server required',
1.329 droeschl 8977: );
1.594 damieng 8978: &js_escape(\%js_lt);
1.433 raeburn 8979: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 8980: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
8981: my $main_container_page;
1.519 raeburn 8982: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
8983: $main_container_page = 1;
1.434 raeburn 8984: }
1.617 raeburn 8985: my $backtourl;
8986: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 8987: my $toplevelsupp = &supplemental_base();
1.690 raeburn 8988: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 8989: my @ids=&Apache::lonnet::current_machine_ids();
8990: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 8991: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
8992: my $caller = $1;
1.525 raeburn 8993: if ($caller =~ /^supplemental/) {
8994: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
8995: } else {
8996: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
8997: $res = &Apache::lonnet::clutter($res);
8998: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 8999: my ($url,$anchor);
9000: if ($res =~ /^([^#]+)#([^#]+)$/) {
9001: $url = $1;
9002: $anchor = $2;
9003: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
9004: $caller = $1.&escape('#').$anchor;
9005: }
1.614 raeburn 9006: } else {
9007: $url = $res;
1.609 raeburn 9008: }
1.640 raeburn 9009: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
9010: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
9011: $backtourl .= '?navmap=1';
9012: } else {
9013: $backtourl .= '?symb='.
9014: &HTML::Entities::encode($caller,'<>&"');
9015: }
1.622 raeburn 9016: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
9017: if (($ENV{'SERVER_PORT'} == 443) &&
9018: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 9019: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 9020: if ($hostname ne '') {
9021: $backtourl = 'http://'.$hostname.$backtourl;
9022: }
9023: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 9024: }
9025: }
1.623 raeburn 9026: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
9027: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 9028: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 9029: if ($hostname ne '') {
9030: $backtourl = 'http://'.$hostname.$backtourl;
9031: }
9032: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 9033: }
1.623 raeburn 9034: }
1.622 raeburn 9035: }
1.609 raeburn 9036: if ($anchor ne '') {
9037: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
9038: }
1.590 raeburn 9039: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 9040: } else {
9041: $backtourl = '/adm/navmaps';
1.525 raeburn 9042: }
9043: }
9044: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
9045: $backtourl = '/adm/menu';
9046: } elsif ($supplementalflag) {
1.682 raeburn 9047: if (($env{'request.role.adv'}) ||
9048: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
9049: $backtourl = '/adm/supplemental';
9050: } else {
9051: $backtourl = '/adm/navmaps';
9052: }
1.525 raeburn 9053: } else {
9054: $backtourl = '/adm/navmaps';
1.472 raeburn 9055: }
9056:
1.655 raeburn 9057: my $fieldsets = "'doc'";
1.519 raeburn 9058: unless ($main_container_page) {
9059: $fieldsets .=",'ims'";
9060: }
1.655 raeburn 9061: my $extfieldsets = "'ext'";
9062: if ($posslti) {
9063: $extfieldsets .= ",'tool'";
9064: }
1.501 raeburn 9065: if ($supplementalflag) {
1.655 raeburn 9066: $fieldsets = "'suppdoc'";
9067: $extfieldsets = "'suppext'";
1.600 raeburn 9068: if ($posslti) {
1.655 raeburn 9069: $extfieldsets .= ",'supptool'";
1.600 raeburn 9070: }
1.501 raeburn 9071: }
1.655 raeburn 9072:
1.611 raeburn 9073: my $jsmakefunctions;
9074: if ($canedit) {
9075: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 9076: function makenewfolder(targetform,folderseq) {
1.594 damieng 9077: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 9078: if (foldername) {
1.676 raeburn 9079: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 9080: targetform.submit();
9081: }
9082: }
9083:
9084: function makenewpage(targetform,folderseq) {
1.594 damieng 9085: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 9086: if (pagename) {
1.676 raeburn 9087: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 9088: targetform.submit();
9089: }
9090: }
9091:
9092: function makeexamupload() {
1.594 damieng 9093: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 9094: if (title) {
1.329 droeschl 9095: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 9096: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 9097: this.document.forms.newexamupload.submit();
9098: }
9099: }
9100:
9101: function makesmppage() {
1.594 damieng 9102: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 9103: if (title) {
1.329 droeschl 9104: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 9105: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 9106: this.document.forms.newsmppg.submit();
9107: }
9108: }
9109:
1.534 raeburn 9110: function makewebpage(type) {
1.594 damieng 9111: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 9112: var formname;
9113: if (type == 'supp') {
9114: formname = this.document.forms.supwebpage;
9115: } else {
9116: formname = this.document.forms.newwebpage;
9117: }
9118: if (title) {
9119: var webpage = formname.importdetail.value;
1.675 raeburn 9120: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 9121: formname.submit();
9122: }
9123: }
9124:
1.329 droeschl 9125: function makesmpproblem() {
1.594 damieng 9126: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 9127: if (title) {
1.329 droeschl 9128: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 9129: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 9130: this.document.forms.newsmpproblem.submit();
9131: }
9132: }
9133:
9134: function makedropbox() {
1.594 damieng 9135: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 9136: if (title) {
1.329 droeschl 9137: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 9138: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 9139: this.document.forms.newdropbox.submit();
9140: }
9141: }
9142:
9143: function makebulboard() {
1.594 damieng 9144: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 9145: if (title) {
9146: this.document.forms.newbul.importdetail.value=
1.676 raeburn 9147: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 9148: this.document.forms.newbul.submit();
9149: }
9150: }
9151:
9152: function makeabout() {
1.594 damieng 9153: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 9154: if (user) {
9155: var comp=new Array();
9156: comp=user.split(':');
9157: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
9158: if ((comp[0]) && (comp[1])) {
9159: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 9160: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 9161: this.document.forms.newaboutsomeone.submit();
9162: } else {
9163: alert("$js_lt{'p_mab_alrt1'}");
9164: }
9165: } else {
9166: alert("$js_lt{'p_mab_alrt2'}");
9167: }
9168: }
9169: }
9170:
9171: function makenew(targetform) {
9172: targetform.submit();
9173: }
9174:
9175: function changename(folderpath,index,oldtitle) {
9176: var title=prompt('$js_lt{"p_chn"}',oldtitle);
9177: if (title) {
9178: this.document.forms.renameform.markcopy.value='';
9179: this.document.forms.renameform.title.value=title;
9180: this.document.forms.renameform.cmd.value='rename_'+index;
9181: this.document.forms.renameform.folderpath.value=folderpath;
9182: this.document.forms.renameform.submit();
9183: }
9184: }
9185:
1.633 raeburn 9186: function setalias(folderpath,index) {
9187: var alias = prompt('$js_lt{"setal"}');
9188: if ((alias != null) && (alias != '')) {
9189: this.document.forms.aliasform.alias.value=alias;
9190: this.document.forms.aliasform.cmd.value='setalias_'+index;
9191: this.document.forms.aliasform.folderpath.value=folderpath;
9192: this.document.forms.aliasform.submit();
9193: }
9194: }
9195:
9196: function delalias(folderpath,index) {
9197: if (confirm('$js_lt{"delal"}')) {
9198: this.document.forms.aliasform.cmd.value='delalias_'+index;
9199: this.document.forms.aliasform.folderpath.value=folderpath;
9200: this.document.forms.aliasform.submit();
9201: }
9202: }
9203:
1.611 raeburn 9204: ENDNEWSCRIPT
9205: } else {
9206: $jsmakefunctions = <<ENDNEWSCRIPT;
9207:
9208: function makenewfolder() {
9209: alert("$js_lt{'edri'}");
9210: }
9211:
9212: function makenewpage() {
9213: alert("$js_lt{'edri'}");
9214: }
9215:
9216: function makeexamupload() {
9217: alert("$js_lt{'edri'}");
9218: }
9219:
9220: function makesmppage() {
9221: alert("$js_lt{'edri'}");
9222: }
9223:
9224: function makewebpage(type) {
9225: alert("$js_lt{'edri'}");
9226: }
9227:
9228: function makesmpproblem() {
9229: alert("$js_lt{'edri'}");
9230: }
9231:
9232: function makedropbox() {
9233: alert("$js_lt{'edri'}");
9234: }
9235:
9236: function makebulboard() {
9237: alert("$js_lt{'edri'}");
9238: }
9239:
9240: function makeabout() {
9241: alert("$js_lt{'edri'}");
9242: }
9243:
9244: function changename() {
9245: alert("$js_lt{'edri'}");
9246: }
9247:
1.633 raeburn 9248: function setalias() {
9249: alert("$js_lt{'edri'}");
9250: }
9251:
9252: function delalias() {
9253: alert("$js_lt{'edri'}");
9254: }
9255:
1.611 raeburn 9256: function makenew() {
9257: alert("$js_lt{'edri'}");
9258: }
9259:
9260: function groupimport() {
9261: alert("$js_lt{'edri'}");
1.335 ehlerst 9262: }
1.611 raeburn 9263:
9264: function groupsearch() {
9265: alert("$js_lt{'edri'}");
1.335 ehlerst 9266: }
1.611 raeburn 9267:
9268: function groupopen(url,recover) {
9269: var options="scrollbars=1,resizable=1,menubar=0";
9270: idxflag=1;
9271: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
9272: idx.focus();
1.329 droeschl 9273: }
9274:
1.611 raeburn 9275: ENDNEWSCRIPT
9276:
9277: }
9278: return <<ENDSCRIPT;
9279:
9280: $jsmakefunctions
9281:
1.501 raeburn 9282: function toggleUpload(caller) {
9283: var blocks = Array($fieldsets);
9284: for (var i=0; i<blocks.length; i++) {
9285: var disp = 'none';
9286: if (caller == blocks[i]) {
9287: var curr = document.getElementById('upload'+caller+'form').style.display;
9288: if (curr == 'none') {
9289: disp='block';
9290: }
9291: }
9292: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 9293: }
9294: resize_scrollbox('contentscroll','1','1');
9295: return;
9296: }
9297:
9298: function toggleExternal(caller) {
9299: var blocks = Array($extfieldsets);
9300: for (var i=0; i<blocks.length; i++) {
9301: var disp = 'none';
9302: if (caller == blocks[i]) {
9303: var curr = document.getElementById('external'+caller+'form').style.display;
9304: if (curr == 'none') {
9305: disp='block';
9306: }
9307: }
9308: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 9309: if ((caller == 'tool') || (caller == 'supptool')) {
9310: if (disp == 'block') {
1.655 raeburn 9311: if (document.getElementById('LC_exttoolid')) {
9312: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 9313: var suppflag = 0;
9314: if (caller == 'supptool') {
9315: suppflag = 1;
9316: }
9317: currForm = document.getElementById('new'+caller);
1.655 raeburn 9318: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 9319: }
9320: }
9321: }
1.501 raeburn 9322: }
1.502 raeburn 9323: resize_scrollbox('contentscroll','1','1');
9324: return;
9325: }
9326:
1.514 raeburn 9327: function toggleMap(caller) {
1.502 raeburn 9328: var disp = 'none';
1.510 raeburn 9329: if (document.getElementById('importmapform')) {
1.514 raeburn 9330: if (caller == 'map') {
9331: var curr = document.getElementById('importmapform').style.display;
9332: if (curr == 'none') {
9333: disp='block';
9334: }
1.510 raeburn 9335: }
9336: document.getElementById('importmapform').style.display=disp;
1.706 raeburn 9337: if (disp == 'block') {
9338: if (document.getElementById('importcrsresform')) {
9339: if (document.getElementById('importcrsresform').style.display == 'block') {
9340: document.getElementById('importcrsresform').style.display = 'none';
9341: }
9342: }
9343: }
1.510 raeburn 9344: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 9345: }
1.501 raeburn 9346: return;
1.329 droeschl 9347: }
9348:
1.691 raeburn 9349: function toggleCrsRes(caller) {
1.606 raeburn 9350: var disp = 'none';
9351: if (document.getElementById('crsresform')) {
9352: if (caller == 'res') {
1.691 raeburn 9353: var form = document.getElementById('crsresform');
9354: var curr = form.style.display;
1.606 raeburn 9355: if (curr == 'none') {
9356: disp='block';
1.691 raeburn 9357: document.courseresform.authorrole.selectedIndex = 0;
9358: document.courseresform.authorpath.selectedIndex = 0;
9359: document.courseresform.newresourceadd.selectedIndex = 0;
9360: populateDirSelects(form,'authorrole','authorpath',1,0,0);
9361: toggleNewInCourse(document.courseresform);
9362: if (document.getElementById('newresource')) {
9363: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 9364: }
9365: if (document.courseresform.newresusetemp.length) {
9366: document.courseresform.newresusetemp[0].checked = true;
9367: toggleWithTemplate(document.courseresform);
9368: }
9369: document.courseresform.newresourcename.value = '';
9370: }
9371: }
9372: if (document.courseresform.newsubdir.length) {
9373: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
9374: if (document.courseresform.newsubdir[j].value == 0) {
9375: document.courseresform.newsubdir[j].checked = true;
9376: }
9377: break;
9378: }
9379: if (document.getElementById('newsubdirname')) {
9380: document.getElementById('newsubdirname').type = "hidden";
9381: document.getElementById('newsubdirname').value = "";
9382: }
9383: if (document.getElementById('newsubdir')) {
9384: document.getElementById('newsubdir').innerHTML = "";
9385: }
9386: }
9387: document.getElementById('crsresform').style.display=disp;
9388: resize_scrollbox('contentscroll','1','0');
9389: }
9390: return;
9391: }
9392:
9393: function toggleNewsubdir(form) {
9394: if (form.newsubdir.length) {
9395: for (var j=0; j<form.newsubdir.length; j++) {
9396: if (form.newsubdir[j].checked) {
9397: if (document.getElementById('newsubdirname')) {
9398: if (form.newsubdir[j].value == '1') {
9399: document.getElementById('newsubdirname').type = "text";
9400: if (document.getElementById('newsubdir')) {
9401: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
9402: }
9403: } else {
9404: document.getElementById('newsubdirname').type = "hidden";
9405: document.getElementById('newsubdirname').value = "";
9406: document.getElementById('newsubdir').innerHTML = "";
9407: }
9408: }
9409: break;
9410: }
9411: }
9412: }
9413: }
9414:
9415: function toggleCrsResTitle() {
9416: if (document.getElementById('newresource')) {
1.691 raeburn 9417: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9418: if (selloc == 'course') {
1.606 raeburn 9419: document.getElementById('newresource').style.display = 'inline';
9420: document.courseresform.newresourceadd[0].checked = true;
9421: toggleNewInCourse(document.courseresform);
9422: } else {
9423: document.getElementById('newresource').style.display = 'none';
9424: }
1.689 raeburn 9425: }
9426: if (document.getElementById('newstdproblem')) {
9427: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
9428: document.getElementById('newstdproblem').style.display = 'none';
9429: if (document.getElementById('stdprobswitch')) {
9430: document.getElementById('stdprobswitch').style.display = 'block';
9431: }
9432: } else {
9433: document.getElementById('newstdproblem').style.display = 'block';
9434: if (document.getElementById('stdprobswitch')) {
9435: document.getElementById('stdprobswitch').style.display = 'none';
9436: }
9437: }
9438: }
1.606 raeburn 9439: }
9440:
9441: function toggleNewInCourse(form) {
9442: if (form.newresourceadd.length) {
9443: for (var i=0; i<form.newresourceadd.length; i++) {
9444: if (form.newresourceadd[i].checked) {
9445: if (document.getElementById('newresourcetitle')) {
9446: if (form.newresourceadd[i].value == '1') {
9447: document.getElementById('newresourcetitle').type = 'text';
9448: if (document.getElementById('newrestitle')) {
9449: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
9450: }
9451: } else {
9452: document.getElementById('newresourcetitle').type = 'hidden';
9453: document.getElementById('newresourcetitle').value = '';
9454: if (document.getElementById('newrestitle')) {
9455: document.getElementById('newrestitle').innerHTML = '';
9456: }
9457: }
9458: }
9459: break;
9460: }
9461: }
9462: }
9463: }
9464:
9465: function toggleWithTemplate(form) {
9466: if (form.newresusetemp.length) {
9467: for (var i=0; i<form.newresusetemp.length; i++) {
9468: if (form.newresusetemp[i].checked) {
9469: if (document.getElementById('newrestemplate')) {
9470: if (form.newresusetemp[i].value == '1') {
9471: document.getElementById('newrestemplate').style.display = 'inline';
9472: toggleExampleText();
9473: } else {
9474: form.tempcategory.selectedIndex = 0;
9475: select1template_changed();
9476: document.getElementById('newrestemplate').style.display = 'none';
9477: }
9478: }
9479: }
9480: }
9481: }
9482: }
9483:
9484: function toggleExampleText() {
9485: if (document.getElementById('newresexample')) {
9486: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9487: if (url == '') {
9488: document.getElementById('newresexample').style.fontWeight = 'normal';
9489: } else {
9490: document.getElementById('newresexample').style.fontWeight = 'bold';
9491: }
9492: }
9493: }
9494:
9495: function getExample(width,height,scrolling,transparency) {
9496: var url;
9497: if (document.courseresform.newresusetemp.length) {
9498: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
9499: if (document.courseresform.newresusetemp[i].checked) {
9500: if (document.courseresform.newresusetemp[i].value == '1') {
9501: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9502: if (url == '') {
9503: alert('Pick a category and template');
9504: } else {
9505: url = url.replace("$londocroot","");
9506: url += '?inhibitmenu=yes';
9507: }
9508: }
9509: break;
9510: }
9511: }
9512: }
9513: if (url != '') {
9514: openMyModal(url,width,height,scrolling,transparency,'');
9515: }
9516: }
9517:
1.690 raeburn 9518: function toggleImportCrsres(caller) {
1.606 raeburn 9519: var disp = 'none';
9520: if (document.getElementById('importcrsresform')) {
9521: if (caller == 'res') {
9522: var curr = document.getElementById('importcrsresform').style.display;
9523: if (curr == 'none') {
9524: disp='block';
1.698 raeburn 9525: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
9526: if ((document.getElementById('importcrsrescontent')) &&
9527: (document.getElementById('importcrsresempty'))) {
9528: var selelem = document.crsresimportform.elements['coursepath'];
9529: var numdirs = 0;
9530: if (selelem.options.length) {
9531: numdirs = selelem.options.length - 1;
9532: }
9533: if (numdirs) {
9534: document.getElementById('importcrsrescontent').style.display='block';
9535: document.getElementById('importcrsresempty').style.display='none';
9536: } else {
9537: document.getElementById('importcrsrescontent').style.display='none';
9538: document.getElementById('importcrsresempty').style.display='block';
9539: }
9540: }
1.606 raeburn 9541: }
9542: }
9543: document.getElementById('importcrsresform').style.display=disp;
1.706 raeburn 9544: if (disp == 'block') {
9545: if (document.getElementById('importmapform')) {
9546: if (document.getElementById('importmapform').style.display == 'block') {
9547: document.getElementById('importmapform').style.display = 'none';
9548: }
9549: }
9550: }
1.606 raeburn 9551: resize_scrollbox('contentscroll','1','0');
9552: }
9553: return;
9554: }
9555:
1.690 raeburn 9556: $showfile_js
9557:
1.691 raeburn 9558: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
9559: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
9560: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
9561: var selelem = form.elements[dirsel];
9562: var i, numfiles = selelem.options.length -1;
9563: if (numfiles >=0) {
9564: for (i = numfiles; i >= 0; i--) {
9565: selelem.remove(i);
9566: }
9567: }
9568: if ((location == '') || (location == null) || (location == 'undefined')) {
9569: if (selelem.options.length == 0) {
9570: selelem.options[selelem.options.length] = new Option('','');
9571: selelem.selectedIndex = 0;
9572: }
9573: if (document.getElementById('newstdproblem')) {
9574: document.getElementById('newstdproblem').style.display = 'none';
9575: }
9576: return;
9577: }
9578: var machineIds = new Array($machines_str);
9579: var athome = 0;
9580: var role = location;
9581: if ((location == 'author') || (location == 'course')) {
9582: if (document.getElementById('rolehome_'+location)) {
9583: var currhome = document.getElementById('rolehome_'+location).value;
9584: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9585: if (machineIds.includes(currhome)) {
9586: athome = 1;
9587: }
9588: }
9589: }
9590: } else {
9591: const roleinfo = location.split('___');
9592: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
9593: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
9594: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
9595: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9596: if (machineIds.includes(currhome)) {
9597: athome = 1;
9598: }
9599: }
9600: }
9601: }
1.706 raeburn 9602: var templateradio = document.courseresform.elements['newresusetemp'];
1.691 raeburn 9603: if (athome) {
9604: if (document.getElementById('stdprobswitch')) {
9605: document.getElementById('stdprobswitch').style.display = 'none';
9606: }
9607: if (document.getElementById('newstdproblem')) {
9608: document.getElementById('newstdproblem').style.display = 'none';
9609: }
1.706 raeburn 9610: var canedit = '$canedit';
9611: if (canedit) {
9612: if (templateradio.length > 1) {
9613: for (var i=0; i<templateradio.length; i++) {
9614: templateradio[i].disabled = false;
9615: }
9616: }
9617: document.courseresform.newresourcename.disabled = false;
9618: document.courseresform.newcrs.disabled = false;
9619: }
1.691 raeburn 9620: var http = new XMLHttpRequest();
9621: var url = "/adm/courseauthor";
1.698 raeburn 9622: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 9623: http.open("POST", url, true);
9624: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
9625: http.onreadystatechange = function() {
9626: if (http.readyState == 4 && http.status == 200) {
9627: var data = JSON.parse(http.responseText);
9628: if (Array.isArray(data.dirs)) {
9629: var len = data.dirs.length;
9630: if (len) {
9631: if (len > 1) {
9632: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
9633: }
9634: }
9635: if (len) {
9636: var j;
9637: for (j = 0; j < len; j++) {
9638: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
9639: }
9640: selelem.selectedIndex = 0;
1.697 raeburn 9641: if (len == 1) {
9642: toggleCrsResTitle();
9643: }
1.691 raeburn 9644: }
9645: }
9646: }
9647: }
9648: http.send(params);
9649: } else {
9650: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
9651: selelem.selectedIndex = 0;
9652: if (document.getElementById('stdprobswitch')) {
9653: document.getElementById('stdprobswitch').style.display = 'block';
9654: }
9655: if (document.getElementById('newstdproblem')) {
9656: document.getElementById('newstdproblem').style.display = 'none';
9657: }
1.706 raeburn 9658: if (templateradio.length > 1) {
9659: for (var i=0; i<templateradio.length; i++) {
9660: templateradio[i].disabled = true;
9661: }
9662: }
9663: document.courseresform.newresourcename.disabled = true;
9664: document.courseresform.newcrs.disabled = true;
1.691 raeburn 9665: }
9666: }
9667: return;
9668: }
9669:
1.689 raeburn 9670: function switchForProb() {
9671: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
9672: var url = '/adm/switchserver?otherserver=';
9673: var newhostid = '';
9674: var role = '';
9675: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9676: if (selloc == 'author') {
9677: newhostid = document.courseresform.rolehome_author.value;
9678: role = "au./&js_escape($env{'user.domain'})/";
9679: } else if (selloc == 'course') {
9680: newhostid = document.courseresform.rolehome_course.value;
9681: role = "&js_escape($env{'request.role'})";
9682: } else {
9683: var items = new Array();
9684: items = selloc.split('___');
9685: var len = document.courseresform.rolehome_coauthor.length;
9686: if (null == len) {
9687: var currval = document.courseresform.rolehome_coauthor.value;
9688: if (null != currval) {
9689: var info = new Array();
9690: info = currval.split('=');
9691: newhostid = info[2];
9692: role = info[0]+'./'+info[1];
9693: }
9694: } else {
9695: for (var i=0; i<len; i++) {
9696: var currval = document.courseresform.rolehome_coauthor[i].value;
9697: if (null != currval) {
9698: var info = new Array();
9699: info = currval.split('=');
9700: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
9701: newhostid = info[2];
9702: role = info[0]+'./'+info[1];
9703: break;
9704: }
9705: }
9706: }
9707: }
9708: }
9709: if (newhostid != '') {
9710: url += newhostid;
9711: if (role != '') {
9712: url += '&role='+role;
9713: }
9714: document.location.href = url;
9715: }
9716: }
9717: return;
9718: }
9719:
1.501 raeburn 9720: function makeims(imsform) {
9721: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 9722: alert("$js_lt{'imsfile'}");
1.501 raeburn 9723: return;
9724: }
9725: if (imsform.source.selectedIndex == 0) {
1.594 damieng 9726: alert("$js_lt{'imscms'}");
1.501 raeburn 9727: return;
9728: }
9729: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
9730: imsform.submit();
9731: }
9732:
1.478 raeburn 9733: function updatePick(targetform,index,caller) {
1.537 raeburn 9734: var pickitem;
9735: var picknumitem;
9736: var picknumtext;
9737: if (index == 'all') {
9738: pickitem = document.getElementById('randompickall');
9739: picknumitem = document.getElementById('rpicknumall');
9740: picknumtext = document.getElementById('rpicktextall');
9741: } else {
9742: pickitem = document.getElementById('randompick_'+index);
9743: picknumitem = document.getElementById('rpicknum_'+index);
9744: picknumtext = document.getElementById('randompicknum_'+index);
9745: }
1.478 raeburn 9746: if (pickitem.checked) {
1.594 damieng 9747: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 9748: if (picknum == '' || picknum == null) {
9749: if (caller == 'check') {
9750: pickitem.checked=false;
1.537 raeburn 9751: if (index == 'all') {
9752: picknumtext.innerHTML = '';
9753: if (caller == 'link') {
9754: propagateState(targetform,'rpicknum');
9755: }
9756: } else {
1.538 raeburn 9757: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9758: }
1.478 raeburn 9759: }
9760: } else {
9761: picknum.toString();
9762: var regexdigit=/^\\d+\$/;
9763: if (regexdigit.test(picknum)) {
9764: picknumitem.value = picknum;
1.537 raeburn 9765: if (index == 'all') {
1.538 raeburn 9766: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 9767: if (caller == 'link') {
9768: propagateState(targetform,'rpicknum');
9769: }
9770: } else {
9771: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 9772: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9773: }
1.478 raeburn 9774: } else {
9775: if (caller == 'check') {
1.537 raeburn 9776: if (index == 'all') {
9777: picknumtext.innerHTML = '';
9778: if (caller == 'link') {
9779: propagateState(targetform,'rpicknum');
9780: }
9781: } else {
9782: pickitem.checked=false;
1.538 raeburn 9783: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9784: }
1.478 raeburn 9785: }
9786: return;
9787: }
9788: }
9789: } else {
1.537 raeburn 9790: picknumitem.value = '';
9791: picknumtext.innerHTML = '';
9792: if (index == 'all') {
9793: if (caller == 'link') {
9794: propagateState(targetform,'rpicknum');
9795: }
9796: } else {
1.538 raeburn 9797: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9798: }
9799: }
9800: }
9801:
9802: function propagateState(form,param) {
9803: if (document.getElementById(param+'all')) {
9804: var setcheck = 0;
9805: var rpick = 0;
9806: if (param == 'rpicknum') {
9807: if (document.getElementById('randompickall')) {
9808: if (document.getElementById('randompickall').checked) {
9809: if (document.getElementById('rpicknumall')) {
9810: rpick = document.getElementById('rpicknumall').value;
9811: }
9812: }
9813: }
9814: } else {
9815: if (document.getElementById(param+'all').checked) {
9816: setcheck = 1;
9817: }
9818: }
1.538 raeburn 9819: var allidxlist;
9820: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9821: if (document.getElementById('all'+param+'idx')) {
9822: allidxlist = document.getElementById('all'+param+'idx').value;
9823: }
9824: var actions = new Array ('remove','cut','copy');
9825: for (var i=0; i<actions.length; i++) {
9826: if (actions[i] != param) {
9827: if (document.getElementById(actions[i]+'all')) {
9828: document.getElementById(actions[i]+'all').checked = false;
9829: }
9830: }
9831: }
9832: }
1.537 raeburn 9833: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 9834: allidxlist = form.allidx.value;
9835: }
9836: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
9837: allidxlist = form.allmapidx.value;
9838: }
9839: if ((allidxlist != '') && (allidxlist != null)) {
9840: var allidxs = allidxlist.split(',');
9841: if (allidxs.length > 1) {
9842: for (var i=0; i<allidxs.length; i++) {
9843: if (document.getElementById(param+'_'+allidxs[i])) {
9844: if (param == 'rpicknum') {
9845: if (document.getElementById('randompick_'+allidxs[i])) {
9846: if (document.getElementById('randompick_'+allidxs[i]).checked) {
9847: document.getElementById(param+'_'+allidxs[i]).value = rpick;
9848: if (rpick > 0) {
9849: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
9850: } else {
9851: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9852: }
9853: }
9854: }
9855: } else {
1.537 raeburn 9856: if (setcheck == 1) {
9857: document.getElementById(param+'_'+allidxs[i]).checked = true;
9858: } else {
9859: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 9860: if (param == 'randompick') {
9861: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9862: }
1.537 raeburn 9863: }
9864: }
9865: }
9866: }
1.538 raeburn 9867: if (setcheck == 1) {
9868: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9869: var actions = new Array('copy','cut','remove');
9870: for (var i=0; i<actions.length; i++) {
9871: var otheractions;
9872: var otheridxs;
9873: if (actions[i] === param) {
9874: continue;
9875: } else {
9876: if (document.getElementById('all'+actions[i]+'idx')) {
9877: otheractions = document.getElementById('all'+actions[i]+'idx').value;
9878: otheridxs = otheractions.split(',');
9879: if (otheridxs.length > 1) {
9880: for (var j=0; j<otheridxs.length; j++) {
9881: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
9882: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
9883: }
1.537 raeburn 9884: }
9885: }
9886: }
1.538 raeburn 9887: }
9888: }
9889: }
9890: }
9891: }
9892: }
9893: }
9894: return;
9895: }
9896:
1.603 raeburn 9897: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 9898: var canedit = '$canedit';
9899: if (canedit == '') {
9900: alert("$js_lt{'edri'}");
9901: return;
9902: }
1.539 raeburn 9903: var dosettings;
9904: var doaction;
1.538 raeburn 9905: var control = document.togglemultsettings;
9906: if (context == 'actions') {
9907: control = document.togglemultactions;
1.539 raeburn 9908: doaction = 1;
9909: } else {
9910: dosettings = 1;
1.538 raeburn 9911: }
1.539 raeburn 9912: if (control) {
9913: if (control.showmultpick.length) {
9914: for (var i=0; i<control.showmultpick.length; i++) {
9915: if (control.showmultpick[i].checked) {
9916: if (control.showmultpick[i].value == 1) {
9917: if (context == 'settings') {
9918: dosettings = 0;
9919: } else {
9920: doaction = 0;
1.538 raeburn 9921: }
9922: }
9923: }
1.537 raeburn 9924: }
9925: }
1.539 raeburn 9926: }
9927: if (context == 'settings') {
9928: if (dosettings == 1) {
1.538 raeburn 9929: targetform.changeparms.value=param;
9930: targetform.submit();
9931: }
1.537 raeburn 9932: }
1.539 raeburn 9933: if (context == 'actions') {
9934: if (doaction == 1) {
9935: targetform.cmd.value=param+'_'+index;
9936: targetform.folderpath.value=folderpath;
9937: targetform.markcopy.value=idx+':'+param;
9938: targetform.copyfolder.value=folder+'.'+container;
9939: if (param == 'remove') {
1.603 raeburn 9940: var doremove = 0;
9941: if (skip_confirm) {
9942: if (confirm_removal) {
9943: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
9944: doremove = 1;
9945: }
9946: } else {
9947: doremove = 1;
9948: }
9949: } else {
9950: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
9951: doremove = 1;
9952: }
9953: }
9954: if (doremove) {
1.539 raeburn 9955: targetform.markcopy.value='';
9956: targetform.copyfolder.value='';
9957: targetform.submit();
9958: }
9959: }
9960: if (param == 'cut') {
1.594 damieng 9961: 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 9962: targetform.submit();
9963: return;
9964: }
9965: }
9966: if (param == 'copy') {
9967: targetform.submit();
9968: return;
9969: }
9970: targetform.markcopy.value='';
9971: targetform.copyfolder.value='';
9972: targetform.cmd.value='';
9973: targetform.folderpath.value='';
9974: return;
9975: } else {
9976: if (document.getElementById(param+'_'+idx)) {
9977: item = document.getElementById(param+'_'+idx);
9978: if (item.type == 'checkbox') {
9979: if (item.checked) {
9980: item.checked = false;
9981: } else {
9982: item.checked = true;
9983: singleCheck(item,idx,param);
9984: }
9985: }
9986: }
9987: }
9988: }
1.537 raeburn 9989: return;
9990: }
9991:
1.538 raeburn 9992: function singleCheck(caller,idx,action) {
9993: actions = new Array('cut','copy','remove');
9994: if (caller.checked) {
9995: for (var i=0; i<actions.length; i++) {
9996: if (actions[i] != action) {
9997: if (document.getElementById(actions[i]+'_'+idx)) {
9998: if (document.getElementById(actions[i]+'_'+idx).checked) {
9999: document.getElementById(actions[i]+'_'+idx).checked = false;
10000: }
1.537 raeburn 10001: }
10002: }
10003: }
1.478 raeburn 10004: }
1.537 raeburn 10005: return;
1.478 raeburn 10006: }
10007:
1.334 muellerd 10008: function unselectInactive(nav) {
1.335 ehlerst 10009: currentNav = document.getElementById(nav);
10010: currentLis = currentNav.getElementsByTagName('LI');
10011: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 10012: if (currentLis[i].className == 'goback') {
10013: currentLis[i].className = 'goback';
10014: } else {
10015: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 10016: currentLis[i].className = 'right';
1.472 raeburn 10017: } else {
1.374 tempelho 10018: currentLis[i].className = 'i';
1.472 raeburn 10019: }
10020: }
1.335 ehlerst 10021: }
1.332 tempelho 10022: }
10023:
1.334 muellerd 10024: function hideAll(current, nav, data) {
1.335 ehlerst 10025: unselectInactive(nav);
1.570 raeburn 10026: if (current) {
10027: if (current.className == 'right'){
10028: current.className = 'right active'
10029: } else {
10030: current.className = 'active';
10031: }
1.374 tempelho 10032: }
1.335 ehlerst 10033: currentData = document.getElementById(data);
10034: currentDivs = currentData.getElementsByTagName('DIV');
10035: for (i = 0; i < currentDivs.length; i++) {
10036: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 10037: currentDivs[i].style.display = 'none';
1.330 tempelho 10038: }
10039: }
1.335 ehlerst 10040: }
1.330 tempelho 10041:
1.374 tempelho 10042: function openTabs(pageId) {
10043: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 10044: if(tabnav.length > 2 ){
1.389 tempelho 10045: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 10046: currentLis = currentNav.getElementsByTagName('LI');
10047: for(i = 0; i< currentLis.length; i++){
10048: if(currentLis[i].className == 'active') {
1.375 tempelho 10049: funcString = currentLis[i].onclick.toString();
10050: tab = funcString.split('"');
1.420 onken 10051: if(tab.length < 2) {
10052: tab = funcString.split("'");
10053: }
1.375 tempelho 10054: currentData = document.getElementById(tab[1]);
10055: currentData.style.display = 'block';
1.374 tempelho 10056: }
10057: }
10058: }
10059: }
10060:
1.334 muellerd 10061: function showPage(current, pageId, nav, data) {
1.570 raeburn 10062: currstate = current.className;
1.334 muellerd 10063: hideAll(current, nav, data);
1.375 tempelho 10064: openTabs(pageId);
1.334 muellerd 10065: unselectInactive(nav);
1.570 raeburn 10066: if ((currstate == 'active') || (currstate == 'right active')) {
10067: if (currstate == 'active') {
10068: current.className = '';
10069: } else {
10070: current.className = 'right';
10071: }
10072: activeTab = '';
1.656 raeburn 10073: toggleExternal();
1.570 raeburn 10074: toggleUpload();
10075: toggleMap();
1.606 raeburn 10076: toggleCrsRes();
10077: toggleImportCrsres();
1.570 raeburn 10078: resize_scrollbox('contentscroll','1','0');
10079: return;
10080: } else {
10081: current.className = 'active';
10082: }
1.330 tempelho 10083: currentData = document.getElementById(pageId);
10084: currentData.style.display = 'block';
1.458 raeburn 10085: activeTab = pageId;
1.656 raeburn 10086: toggleExternal();
1.501 raeburn 10087: toggleUpload();
1.503 raeburn 10088: toggleMap();
1.606 raeburn 10089: toggleCrsRes();
10090: toggleImportCrsres();
1.433 raeburn 10091: if (nav == 'mainnav') {
10092: var storedpath = "$docs_folderpath";
1.434 raeburn 10093: var storedpage = "$main_container_page";
1.433 raeburn 10094: var reg = new RegExp("^supplemental");
10095: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 10096: if (storedpage == 1) {
10097: document.simpleedit.folderpath.value = '';
10098: document.uploaddocument.folderpath.value = '';
10099: } else {
10100: if (reg.test(storedpath)) {
10101: document.simpleedit.folderpath.value = '$toplevelmain';
10102: document.uploaddocument.folderpath.value = '$toplevelmain';
10103: document.newext.folderpath.value = '$toplevelmain';
10104: } else {
10105: document.simpleedit.folderpath.value = storedpath;
10106: document.uploaddocument.folderpath.value = storedpath;
10107: document.newext.folderpath.value = storedpath;
10108: }
1.433 raeburn 10109: }
10110: } else {
1.434 raeburn 10111: if (reg.test(storedpath)) {
10112: document.simpleedit.folderpath.value = storedpath;
10113: document.supuploaddocument.folderpath.value = storedpath;
10114: document.supnewext.folderpath.value = storedpath;
10115: } else {
1.433 raeburn 10116: document.simpleedit.folderpath.value = '$toplevelsupp';
10117: document.supuploaddocument.folderpath.value = '$toplevelsupp';
10118: document.supnewext.folderpath.value = '$toplevelsupp';
10119: }
10120: }
10121: }
1.485 raeburn 10122: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 10123: return false;
10124: }
1.329 droeschl 10125:
1.472 raeburn 10126: function toContents(jumpto) {
10127: var newurl = '$backtourl';
1.525 raeburn 10128: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 10129: newurl = newurl+'?postdata='+jumpto;
10130: }
10131: location.href=newurl;
10132: }
10133:
1.538 raeburn 10134: function togglePick(caller,value) {
10135: var disp = 'none';
10136: if (document.getElementById('multi'+caller)) {
10137: var curr = document.getElementById('multi'+caller).style.display;
10138: if (value == 1) {
10139: disp='block';
10140: }
10141: if (curr == disp) {
10142: return;
10143: }
10144: document.getElementById('multi'+caller).style.display=disp;
10145: if (value == 1) {
1.594 damieng 10146: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 10147: } else {
10148: document.getElementById('more'+caller).innerHTML = '';
10149: }
10150: if (caller == 'actions') {
10151: setClass(value);
10152: setBoxes(value);
10153: }
10154: }
10155: var showButton = multiSettings();
10156: if (showButton != 1) {
10157: showButton = multiActions();
10158: }
10159: if (document.getElementById('multisave')) {
10160: if (showButton == 1) {
10161: document.getElementById('multisave').style.display='block';
10162: } else {
10163: document.getElementById('multisave').style.display='none';
10164: }
10165: }
10166: resize_scrollbox('contentscroll','1','1');
10167: return;
10168: }
10169:
10170: function toggleCheckUncheck(caller,more) {
10171: if (more == 1) {
1.594 damieng 10172: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 10173: document.getElementById('allfields'+caller).style.display='block';
10174: } else {
1.594 damieng 10175: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 10176: document.getElementById('allfields'+caller).style.display='none';
10177: }
10178: resize_scrollbox('contentscroll','1','1');
10179: }
10180:
10181: function multiSettings() {
10182: var inuse = 0;
10183: var settingsform = document.togglemultsettings;
10184: if (settingsform.showmultpick.length > 1) {
10185: for (var i=0; i<settingsform.showmultpick.length; i++) {
10186: if (settingsform.showmultpick[i].checked) {
10187: if (settingsform.showmultpick[i].value == 1) {
10188: inuse = 1;
10189: }
10190: }
10191: }
10192: }
10193: return inuse;
10194: }
10195:
10196: function multiActions() {
10197: var inuse = 0;
10198: var actionsform = document.togglemultactions;
10199: if (actionsform.showmultpick.length > 1) {
10200: for (var i=0; i<actionsform.showmultpick.length; i++) {
10201: if (actionsform.showmultpick[i].checked) {
10202: if (actionsform.showmultpick[i].value == 1) {
10203: inuse = 1;
10204: }
10205: }
10206: }
10207: }
10208: return inuse;
10209: }
10210:
10211: function checkSubmits() {
10212: var numchanges = 0;
10213: var form = document.saveactions;
10214: var doactions = multiActions();
1.542 raeburn 10215: var cutwarnings = 0;
10216: var remwarnings = 0;
1.603 raeburn 10217: var removalinfo = 0;
1.538 raeburn 10218: if (doactions == 1) {
10219: var remidxlist = document.cumulativeactions.allremoveidx.value;
10220: if ((remidxlist != '') && (remidxlist != null)) {
10221: var remidxs = remidxlist.split(',');
10222: for (var i=0; i<remidxs.length; i++) {
10223: if (document.getElementById('remove_'+remidxs[i])) {
10224: if (document.getElementById('remove_'+remidxs[i]).checked) {
10225: form.multiremove.value += remidxs[i]+',';
10226: numchanges ++;
1.542 raeburn 10227: if (document.getElementById('skip_remove_'+remidxs[i])) {
10228: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
10229: remwarnings ++;
10230: }
10231: }
1.603 raeburn 10232: if (document.getElementById('confirm_removal_'+remidxs[i])) {
10233: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
10234: removalinfo ++;
10235: }
10236: }
1.537 raeburn 10237: }
10238: }
1.538 raeburn 10239: }
10240: }
10241: var cutidxlist = document.cumulativeactions.allcutidx.value;
10242: if ((cutidxlist != '') && (cutidxlist != null)) {
10243: var cutidxs = cutidxlist.split(',');
10244: for (var i=0; i<cutidxs.length; i++) {
10245: if (document.getElementById('cut_'+cutidxs[i])) {
10246: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
10247: form.multicut.value += cutidxs[i]+',';
10248: numchanges ++;
1.542 raeburn 10249: if (document.getElementById('skip_cut_'+cutidxs[i])) {
10250: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
10251: cutwarnings ++;
10252: }
10253: }
1.537 raeburn 10254: }
10255: }
10256: }
10257: }
1.538 raeburn 10258: var copyidxlist = document.cumulativeactions.allcopyidx.value;
10259: if ((copyidxlist != '') && (copyidxlist != null)) {
10260: var copyidxs = copyidxlist.split(',');
10261: for (var i=0; i<copyidxs.length; i++) {
10262: if (document.getElementById('copy_'+copyidxs[i])) {
10263: if (document.getElementById('copy_'+copyidxs[i]).checked) {
10264: form.multicopy.value += copyidxs[i]+',';
10265: numchanges ++;
10266: }
10267: }
10268: }
10269: }
10270: if (numchanges > 0) {
10271: form.multichange.value = numchanges;
10272: }
1.537 raeburn 10273: }
1.538 raeburn 10274: var dosettings = multiSettings();
1.543 raeburn 10275: var haschanges = 0;
1.538 raeburn 10276: if (dosettings == 1) {
10277: form.allencrypturl.value = '';
10278: form.allhiddenresource.value = '';
1.543 raeburn 10279: form.changeparms.value = 'all';
10280: var patt=new RegExp(",\$");
1.538 raeburn 10281: var allidxlist = document.cumulativesettings.allidx.value;
10282: if ((allidxlist != '') && (allidxlist != null)) {
10283: var allidxs = allidxlist.split(',');
10284: if (allidxs.length > 1) {
10285: for (var i=0; i<allidxs.length; i++) {
10286: if (document.getElementById('hiddenresource_'+allidxs[i])) {
10287: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
10288: form.allhiddenresource.value += allidxs[i]+',';
10289: }
10290: }
10291: if (document.getElementById('encrypturl_'+allidxs[i])) {
10292: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
10293: form.allencrypturl.value += allidxs[i]+',';
10294: }
10295: }
10296: }
1.543 raeburn 10297: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
10298: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 10299: }
1.538 raeburn 10300: }
10301: form.allrandompick.value = '';
10302: form.allrandomorder.value = '';
10303: var allmapidxlist = document.cumulativesettings.allmapidx.value;
10304: if ((allmapidxlist != '') && (allmapidxlist != null)) {
10305: var allmapidxs = allmapidxlist.split(',');
10306: for (var i=0; i<allmapidxs.length; i++) {
10307: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
10308: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
10309: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
10310: if ((randompick.checked) && (rpicknum.value != '')) {
10311: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
10312: }
10313: if (randorder.checked) {
10314: form.allrandomorder.value += allmapidxs[i]+',';
10315: }
1.537 raeburn 10316: }
1.543 raeburn 10317: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
10318: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
10319: }
10320: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
10321: haschanges = 1;
10322: }
10323: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
10324: haschanges = 1;
10325: }
10326: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
10327: haschanges = 1;
10328: }
10329: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
10330: haschanges = 1;
1.537 raeburn 10331: }
10332: }
1.543 raeburn 10333: if (doactions == 1) {
1.542 raeburn 10334: if (numchanges > 0) {
1.603 raeburn 10335: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 10336: if (remwarnings > 0) {
1.594 damieng 10337: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 10338: return false;
10339: }
10340: }
1.603 raeburn 10341: if (removalinfo > 0) {
10342: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
10343: return false;
10344: }
10345: }
1.542 raeburn 10346: if (cutwarnings > 0) {
1.594 damieng 10347: 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 10348: return false;
10349: }
10350: }
10351: }
10352: form.submit();
10353: return true;
1.543 raeburn 10354: }
10355: }
10356: if (dosettings == 1) {
10357: if (haschanges == 1) {
1.542 raeburn 10358: form.submit();
10359: return true;
10360: }
1.543 raeburn 10361: }
10362: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 10363: alert("$js_lt{'noor'}");
1.543 raeburn 10364: } else {
10365: if (dosettings == 1) {
1.594 damieng 10366: alert("$js_lt{'noch'}");
1.543 raeburn 10367: } else {
1.594 damieng 10368: alert("$js_lt{'noac'}");
1.543 raeburn 10369: }
10370: }
1.538 raeburn 10371: return false;
10372: }
10373:
10374: function setClass(value) {
10375: var cutclass = 'LC_docs_cut';
10376: var copyclass = 'LC_docs_copy';
10377: var removeclass = 'LC_docs_remove';
10378: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
10379: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
10380: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
10381: var links = document.getElementsByTagName('a');
10382: for (var i=0; i<links.length; i++) {
10383: var classes = links[i].className;
10384: if (cutreg.test(classes)) {
10385: links[i].className = cutclass;
10386: if (value == 1) {
10387: links[i].className += " LC_menubuttons_link";
10388: }
10389: } else {
10390: if (copyreg.test(classes)) {
10391: links[i].className = copyclass;
10392: if (value == 1) {
10393: links[i].className += " LC_menubuttons_link";
10394: }
10395: } else {
10396: if (removereg.test(classes)) {
10397: links[i].className = removeclass;
10398: if (value == 1) {
10399: links[i].className += " LC_menubuttons_link";
10400: }
10401: }
10402: }
10403: }
10404: }
10405: return;
1.537 raeburn 10406: }
10407:
1.538 raeburn 10408: function setBoxes(value) {
10409: var remidxlist = document.cumulativeactions.allremoveidx.value;
10410: if ((remidxlist != '') && (remidxlist != null)) {
10411: var remidxs = remidxlist.split(',');
10412: for (var i=0; i<remidxs.length; i++) {
10413: if (document.getElementById('remove_'+remidxs[i])) {
10414: var item = document.getElementById('remove_'+remidxs[i]);
10415: if (value == 1) {
10416: item.className = 'LC_docs_remove';
10417: } else {
10418: item.className = 'LC_hidden';
10419: }
10420: }
10421: }
10422: }
10423: var cutidxlist = document.cumulativeactions.allcutidx.value;
10424: if ((cutidxlist != '') && (cutidxlist != null)) {
10425: var cutidxs = cutidxlist.split(',');
10426: for (var i=0; i<cutidxs.length; i++) {
10427: if (document.getElementById('cut_'+cutidxs[i])) {
10428: var item = document.getElementById('cut_'+cutidxs[i]);
10429: if (value == 1) {
10430: item.className = 'LC_docs_cut';
10431: } else {
10432: item.className = 'LC_hidden';
10433: }
10434: }
1.537 raeburn 10435: }
10436: }
1.538 raeburn 10437: var copyidxlist = document.cumulativeactions.allcopyidx.value;
10438: if ((copyidxlist != '') && (copyidxlist != null)) {
10439: var copyidxs = copyidxlist.split(',');
10440: for (var i=0; i<copyidxs.length; i++) {
10441: if (document.getElementById('copy_'+copyidxs[i])) {
10442: var item = document.getElementById('copy_'+copyidxs[i]);
10443: if (value == 1) {
10444: item.className = 'LC_docs_copy';
10445: } else {
10446: item.className = 'LC_hidden';
10447: }
10448: }
1.537 raeburn 10449: }
10450: }
10451: return;
10452: }
10453:
1.606 raeburn 10454: function validImportCrsRes() {
10455: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
10456: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
10457: if ((fname == '') || (fname == null)) {
10458: alert("$js_lt{'nofi'}");
10459: return false;
10460: }
10461: var url = '/res/$coursedom/$coursenum/';
10462: if (path && path != '/') {
10463: url += path+'/';
10464: }
10465: if (fname != '') {
10466: url += fname;
10467: }
10468: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 10469: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 10470: return true;
10471: }
10472:
10473: function validateNewRes(caller) {
10474: if (caller == 'single') {
10475: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
10476: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
10477: var resname = document.courseresform.newresourcename.value;
10478: }
10479: }
10480:
1.611 raeburn 10481: ENDSCRIPT
1.329 droeschl 10482: }
1.457 raeburn 10483:
1.483 raeburn 10484: sub history_tab_js {
10485: return <<"ENDHIST";
10486: function toggleHistoryDisp(choice) {
10487: document.docslogform.docslog.value = choice;
10488: document.docslogform.submit();
10489: return;
10490: }
10491:
10492: ENDHIST
10493: }
10494:
1.484 raeburn 10495: sub inject_data_js {
10496: return <<ENDINJECT;
10497:
10498: function injectData(current, hiddenField, name, value) {
10499: currentElement = document.getElementById(hiddenField);
10500: currentElement.name = name;
10501: currentElement.value = value;
10502: current.submit();
10503: }
10504:
10505: ENDINJECT
10506: }
10507:
10508: sub dump_switchserver_js {
10509: my @hosts = @_;
1.594 damieng 10510: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 10511: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 10512: swit => 'Switch server?',
1.594 damieng 10513: );
10514: my %html_js_lt = &Apache::lonlocal::texthash(
10515: swit => 'Switch server?',
1.709 raeburn 10516: duco => 'Copying uploaded content to Authoring Space',
1.484 raeburn 10517: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
10518: chos => 'Choose server',
10519: );
1.594 damieng 10520: &js_escape(\%js_lt);
10521: &html_escape(\%html_js_lt);
10522: &js_escape(\%html_js_lt);
1.484 raeburn 10523: my $role = $env{'request.role'};
10524: my $js = <<"ENDSWJS";
10525: <script type="text/javascript">
10526: function write_switchserver() {
10527: var server;
10528: if (document.setserver.posshosts.length > 0) {
10529: for (var i=0; i<document.setserver.posshosts.length; i++) {
10530: if (document.setserver.posshosts[i].checked) {
10531: server = document.setserver.posshosts[i].value;
10532: }
10533: }
10534: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
10535: }
10536: window.close();
10537: }
10538: </script>
10539:
10540: ENDSWJS
10541:
10542: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
10543: {'only_body' => 1,
10544: 'js_ready' => 1,});
10545: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
10546:
10547: my $hostpicker;
10548: my $count = 0;
10549: foreach my $host (sort(@hosts)) {
10550: my $checked;
10551: if ($count == 0) {
10552: $checked = ' checked="checked"';
10553: }
10554: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
10555: $host.'"'.$checked.' />'.$host.'</label> ';
10556: $count++;
10557: }
10558:
10559: return <<"ENDSWITCHJS";
10560:
10561: function dump_needs_switchserver(url) {
10562: if (url!='' && url!= null) {
1.594 damieng 10563: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 10564: go(url);
10565: }
10566: }
10567: return;
10568: }
10569:
10570: function choose_switchserver_window() {
10571: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
10572: newWindow.document.open();
10573: newWindow.document.writeln('$startpage');
1.594 damieng 10574: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
10575: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
10576: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 10577: '<form name="setserver" method="post" action="" \\/>\\n'+
10578: '$hostpicker\\n'+
10579: '<br \\/><br \\/>\\n'+
1.594 damieng 10580: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 10581: 'onclick="write_switchserver();" \\/>\\n'+
10582: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
10583: newWindow.document.writeln('$endpage');
10584: newWindow.document.close();
10585: newWindow.focus();
10586: }
10587:
10588: ENDSWITCHJS
10589: }
10590:
10591: sub makedocslogform {
10592: my ($formelems,$docslog) = @_;
10593: return <<"LOGSFORM";
10594: <form action="/adm/coursedocs" method="post" name="docslogform">
10595: <input type="hidden" name="docslog" value="$docslog" />
10596: $formelems
10597: </form>
10598: LOGSFORM
10599: }
10600:
10601: sub makesimpleeditform {
10602: my ($formelems) = @_;
10603: return <<"SIMPFORM";
10604: <form name="simpleedit" method="post" action="/adm/coursedocs">
10605: <input type="hidden" name="importdetail" value="" />
10606: $formelems
10607: </form>
10608: SIMPFORM
10609: }
10610:
1.606 raeburn 10611: sub makenewproblem {
10612: my ($r,$coursedom,$coursenum) = @_;
10613: # Creating a new problem
10614: my ($redirect,$error);
10615: if ($env{'form.authorrole'}) {
10616: my ($newsubdir,$filename);
10617: if ($env{'form.newsubdir'}) {
10618: if ($env{'form.newsubdirname'} ne '') {
10619: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 10620: }
1.606 raeburn 10621: }
10622: if ($env{'form.newresourcename'}) {
10623: $filename = $env{'form.newresourcename'};
10624: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
10625: $filename =~ s/`//g;
10626: $filename =~ s{/\.\./}{_}g;
10627: $filename =~ s/\.+/./g;
10628: $filename =~ s{/+}{_}g;
10629: if ($filename ne '') {
10630: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
10631: if (($ext) && ($ext ne '.problem')) {
10632: $filename = $name.'.problem';
10633: } elsif ($ext eq '') {
10634: $filename .= '.problem';
10635: }
10636: my $docroot = $r->dir_config('lonDocRoot');
10637: my @ids=&Apache::lonnet::current_machine_ids();
10638: if ($env{'form.authorrole'} eq 'author') {
10639: if ($env{'user.author'}) {
10640: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
10641: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
10642: my $path = $docroot.$url;
10643: my $subdir = $env{'form.authorpath'};
10644: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10645: }
10646: }
10647: } elsif ($env{'form.authorrole'} eq 'course') {
10648: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
10649: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
10650: my $url = "/priv/$coursedom/$coursenum";
10651: my $path=$docroot.$url;
10652: my $subdir = $env{'form.authorpath'};
10653: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10654: if ($redirect) {
10655: my $rightsfile = 'default.rights';
10656: my $sourcerights = "$path/$rightsfile";
1.709 raeburn 10657: &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom);
1.606 raeburn 10658: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
1.654 raeburn 10659: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
10660: if (!-e "$docroot/res/$coursedom") {
10661: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 10662: }
1.654 raeburn 10663: if (!-e "$docroot/res/$coursedom/$coursenum") {
10664: mkdir("$docroot/res/$coursedom/$coursenum",0755);
10665: }
10666: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
10667: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
10668: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 10669: }
10670: }
1.654 raeburn 10671: my $source = $docroot.$redirect;
10672: if (!-e "$source.meta") {
10673: my $cid = $coursedom.'_'.$coursenum;
10674: my $now = time;
10675: if (open(my $fh,">$source.meta")) {
10676: my $author=$env{'environment.firstname'}.' '.
10677: $env{'environment.middlename'}.' '.
10678: $env{'environment.lastname'}.' '.
10679: $env{'environment.generation'};
10680: $author =~ s/\s+$//;
10681: my $title = $env{'form.newresourcetitle'};
10682: $title =~ s/^\s+|\s+$//g;
10683: print $fh <<END;
1.606 raeburn 10684:
10685: <abstract></abstract>
10686: <author>$author</author>
10687: <authorspace>$coursenum:$coursedom</authorspace>
10688: <copyright>custom</copyright>
10689: <creationdate>$now</creationdate>
10690: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
10691: <dependencies></dependencies>
10692: <domain>$coursedom</domain>
10693: <highestgradelevel>0</highestgradelevel>
10694: <keywords></keywords>
10695: <language>notset </language>
10696: <lastrevisiondate>$now</lastrevisiondate>
10697: <lowestgradelevel>0</lowestgradelevel>
10698: <mime>problem</mime>
10699: <modifyinguser>$coursenum:$coursedom</modifyinguser>
10700: <notes></notes>
10701: <obsolete></obsolete>
10702: <obsoletereplacement></obsoletereplacement>
10703: <owner>$coursenum:$coursedom</owner>
10704: <sourceavail></sourceavail>
10705: <standards></standards>
10706: <subject></subject>
10707: <title>$title</title>
10708: END
1.654 raeburn 10709: close($fh);
1.606 raeburn 10710: }
10711: }
10712: }
10713: }
10714: } else {
10715: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
10716: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
10717: if (grep(/^\Q$rolehome\E$/,@ids)) {
10718: my $now = time;
10719: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
10720: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
10721: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
10722: my $url = "/priv/$audom/$auname";
10723: my $path = $r->dir_config('lonDocRoot').$url;
10724: my $subdir = $env{'form.authorpath'};
10725: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10726: }
10727: }
10728: }
10729: }
10730: }
10731: }
10732: }
10733: return ($redirect,$error);
10734: }
10735:
10736: sub finishnewprob {
1.654 raeburn 10737: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 10738: unless (-d $path) {
10739: unless (mkdir($path,02770)) {
10740: return;
10741: }
10742: }
1.606 raeburn 10743: my $redirect;
10744: if ($subdir ne '/') {
10745: $subdir = &cleandir($subdir);
10746: if (($subdir ne '') && (-d "$path/$subdir")) {
10747: $path .= "/$subdir";
10748: $url .= "/$subdir";
10749: }
10750: }
10751: my $dest;
10752: if ($newsubdir ne '') {
10753: $newsubdir = &cleandir($newsubdir);
10754: }
10755: if ($newsubdir ne '') {
10756: if (-d "$path/$newsubdir") {
10757: $dest = "$path/$newsubdir/$filename";
10758: } else {
10759: my $dirok;
10760: unless (-e "$path/$newsubdir") {
10761: if (mkdir("$path/$newsubdir",02770)) {
10762: if (chmod(02770,"$path/$newsubdir")) {
10763: $dirok = 1;
10764: }
10765: }
10766: }
10767: if ($dirok) {
10768: $dest = "$path/$newsubdir/$filename";
10769: }
10770: }
10771: if (($dest ne '') && (!-e $dest)) {
10772: $redirect = "$url/$newsubdir/$filename";
10773: }
10774: } else {
10775: $dest = "$path/$filename";
10776: if (($dest ne '') && (!-e $dest)) {
10777: $redirect = "$url/$filename";
10778: }
10779: }
1.654 raeburn 10780: if ((!-e $dest) && ($context ne 'upload')) {
10781: my $template = $env{'form.template'};
10782: my $copyfrom;
10783: if ($template ne '') {
10784: my %templates;
10785: my @files = &Apache::lonhomework::get_template_list('problem');
10786: foreach my $poss (@files) {
10787: if (ref($poss) eq 'ARRAY') {
10788: if ($template eq $poss->[0]) {
10789: $templates{$template} = 1;
10790: last;
10791: }
10792: }
10793: }
10794: if ($templates{$template}) {
10795: $copyfrom = $template;
10796: }
10797: }
10798: if ($filename =~ /\.problem$/) {
10799: unless ($copyfrom) {
10800: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
10801: }
10802: &File::Copy::copy($copyfrom,$dest);
10803: }
10804: }
1.606 raeburn 10805: return $redirect;
10806: }
10807:
10808: sub cleandir {
10809: my ($dir) = @_;
10810: $dir =~ s/^\s+//;
10811: $dir =~ s/\s+$//;
10812: $dir =~ s/\.+//g;
10813: $dir =~ s/[\#\?&%\":]//g;
10814: return $dir;
10815: }
10816:
1.329 droeschl 10817: 1;
10818: __END__
10819:
10820:
10821: =head1 NAME
10822:
10823: Apache::londocs.pm
10824:
10825: =head1 SYNOPSIS
10826:
10827: This is part of the LearningOnline Network with CAPA project
10828: described at http://www.lon-capa.org.
10829:
10830: =head1 SUBROUTINES
10831:
10832: =over
10833:
10834: =item %help=()
10835:
10836: Available help topics
10837:
10838: =item mapread()
10839:
1.344 bisitz 10840: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 10841: @order and @resources, determines status
10842: sets @order - pointer to resources in right order
10843: sets @resources - array with the resources with correct idx
10844:
10845: =item authorhosts()
10846:
10847: Return hash with valid author names
10848:
10849: =item clean()
10850:
10851: =item dumpcourse()
10852:
10853: Actually dump course
10854:
10855: =item group_import()
10856:
10857: Imports the given (name, url) resources into the course
10858: coursenum, coursedom, and folder must precede the list
10859:
10860: =item breadcrumbs()
10861:
10862: =item log_docs()
10863:
10864: =item docs_change_log()
10865:
10866: =item update_paste_buffer()
10867:
10868: =item print_paste_buffer()
10869:
10870: =item do_paste_from_buffer()
10871:
1.538 raeburn 10872: =item do_buffer_empty()
10873:
10874: =item clear_from_buffer()
10875:
1.492 raeburn 10876: =item get_newmap_url()
10877:
10878: =item dbcopy()
10879:
10880: =item uniqueness_check()
10881:
10882: =item contained_map_check()
10883:
10884: =item url_paste_fixups()
10885:
10886: =item apply_fixups()
10887:
10888: =item copy_dependencies()
10889:
1.329 droeschl 10890: =item update_parameter()
10891:
10892: =item handle_edit_cmd()
10893:
10894: =item editor()
10895:
10896: =item process_file_upload()
10897:
10898: =item process_secondary_uploads()
10899:
10900: =item is_supplemental_title()
10901:
10902: =item entryline()
10903:
10904: =item tiehash()
10905:
10906: =item untiehash()
10907:
10908: =item checkonthis()
10909:
10910: check on this
10911:
10912: =item verifycontent()
10913:
10914: Verify Content
10915:
1.636 raeburn 10916: =item devalidateversioncache()
10917:
10918: =item checkversions()
1.329 droeschl 10919:
10920: Check Versions
10921:
10922: =item mark_hash_old()
10923:
10924: =item is_hash_old()
10925:
10926: =item changewarning()
10927:
10928: =item init_breadcrumbs()
10929:
10930: Breadcrumbs for special functions
10931:
1.484 raeburn 10932: =item create_list_elements()
10933:
10934: =item create_form_ul()
10935:
10936: =item startContentScreen()
10937:
10938: =item endContentScreen()
10939:
10940: =item supplemental_base()
10941:
10942: =item embedded_form_elems()
10943:
10944: =item embedded_destination()
10945:
10946: =item return_to_editor()
10947:
10948: =item decompression_info()
10949:
10950: =item decompression_phase_one()
10951:
10952: =item decompression_phase_two()
10953:
10954: =item remove_archive()
10955:
10956: =item generate_admin_menu()
10957:
10958: =item generate_edit_table()
10959:
10960: =item editing_js()
10961:
10962: =item history_tab_js()
10963:
10964: =item inject_data_js()
10965:
10966: =item dump_switchserver_js()
10967:
1.485 raeburn 10968: =item resize_scrollbox_js()
1.484 raeburn 10969:
10970: =item makedocslogform()
10971:
1.485 raeburn 10972: =item makesimpleeditform()
10973:
1.329 droeschl 10974: =back
10975:
10976: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>