Annotation of loncom/interface/londocs.pm, revision 1.714
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.714 ! raeburn 4: # $Id: londocs.pm,v 1.713 2024/12/22 03:12:53 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';
582: my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash);
583: my %uploadedfiles;
1.567 raeburn 584: &tiehash();
585: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
586: my ($ext)=($file=~/\.(\w+)$/);
587: # FIXME Check supplemental here
588: my $title=$hash{'title_'.$hash{
589: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
590: if (!$title) {
591: $title=$file;
592: } else {
593: $title=~s|/|_|g;
594: }
595: $title=~s/\.(\w+)$//;
596: $title=&clean($title);
597: $title.='.'.$ext;
598: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
599: $uploadedfiles{$file} = $title;
600: }
601: &untiehash();
602: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
603: undef,undef,$preamble,$home,\%uploadedfiles));
604: }
1.329 droeschl 605: }
1.484 raeburn 606: $r->print(&endContentScreen());
1.329 droeschl 607: }
608:
1.712 raeburn 609: sub authorspace_selector {
610: my ($r,$formname,$home,$title,%outhash) = @_;
611: $r->print('<div id="searching">'.&mt('Searching ...').'</div>'."\n");
612: $r->rflush();
613: my $preamble;
614: unless ($home==1) {
615: $preamble = '<div class="LC_left_float">'.
616: '<fieldset><legend>'.
617: &mt('Select the Authoring Space').
618: '</legend><select name="authorspace">';
619: }
620: my @orderspaces = ();
621: foreach my $key (sort(keys(%outhash))) {
622: if ($key=~/^home_(.+)$/) {
623: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
624: unshift(@orderspaces,$1);
625: } else {
626: push(@orderspaces,$1);
627: }
628: }
629: }
630: if ($home>1) {
631: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
632: }
633: foreach my $user (@orderspaces) {
634: if ($home==1) {
635: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
636: } else {
637: $preamble .= '<option value="'.$user.'">'.$user.' - '.
638: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
639: }
640: }
641: unless ($home==1) {
642: $preamble .= '</select></fieldset></div>'."\n";
643: }
644: $preamble .= '<div class="LC_left_float">'.
645: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
646: '<input type="text" size="50" name="authorfolder" value="'.$title.'" />'."\n".
647: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
648: return $preamble;
649: }
650:
1.567 raeburn 651: sub recurse_html {
652: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
653: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
654: my (%allfiles,%codebase);
655: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
656: if (keys(%allfiles)) {
657: foreach my $dependency (keys(%allfiles)) {
658: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
659: my ($depurl,$relfile,$newcontainer);
660: if ($dependency =~ m{^/}) {
661: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
662: $relfile = $1;
663: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
664: $newcontainer = $1;
665: next if ($replacehash->{$newcontainer});
666: }
667: $depurl = $dependency;
668: } else {
669: next;
670: }
671: } else {
672: $relfile = $dependency;
673: $depurl = $currurlpath;
1.630 raeburn 674: $depurl =~ s{[^/]+$}{};
1.567 raeburn 675: $depurl .= $dependency;
1.630 raeburn 676: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 677: }
678: next if ($relfile eq '');
679: my $newname = $replacehash->{$container};
680: $newname =~ s{[^/]+$}{};
681: $replacehash->{$newcontainer} = $newname.$relfile;
682: $deps->{$item}{$newcontainer} = 1;
683: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
684: my $depfile = &Apache::lonnet::filelocation('',$depurl);
685: my $type = $mm->checktype_filename($depfile);
686: if ($type eq 'text/html') {
687: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
688: }
689: }
690: }
691: }
692: return;
693: }
694:
1.712 raeburn 695: sub copycrsauthored {
696: my ($r,$coursenum,$coursedom,$coursehome,$readonly) = @_;
697: my ($starthash,$js);
698: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
699: $js = <<"ENDJS";
700: <script type="text/javascript">
701: // <![CDATA[
702:
703: function hide_searching() {
704: if (document.getElementById('searching')) {
705: document.getElementById('searching').style.display = 'none';
706: }
707: return;
708: }
709:
710: // ]]>
711: </script>
712: ENDJS
713: $starthash = {
714: add_entries => {'onload' => "hide_searching();"},
715: };
716: }
717: $r->print(&Apache::loncommon::start_page('Copy from Course Authoring to User Authoring',$js,$starthash)."\n".
718: &Apache::lonhtmlcommon::breadcrumbs('Copy from Course Authoring Space')."\n");
719: $r->print(&startContentScreen('tools'));
720: my ($home,$other,%outhash)=&authorhosts();
721: unless ($home) {
722: $r->print('<p class="LC_info">'.&mt('No author or co-author roles on this server.').'</p>');
723: $r->print(&endContentScreen());
724: return '';
725: }
1.714 ! raeburn 726: my $is_course_home;
! 727: my @ids=&Apache::lonnet::current_machine_ids();
! 728: if (($coursehome ne '') && (grep(/^\Q$coursehome\E$/,@ids))) {
! 729: $is_course_home = 1;
! 730: }
1.712 raeburn 731: my %origcrsdata=&Apache::lonnet::coursedescription($env{'request.course.id'});
732: my $exclude = &Apache::lonnet::priv_exclude();
733: my $srcurl = "/priv/$coursedom/$coursenum";
734: my $srctop = $r->dir_config('lonDocRoot').$srcurl;
735: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
736: $r->print('<h3>'.&mt('Copying Files and/or Sub-directories').'</h3>');
737: if ($readonly) {
738: $r->print('<p class="LC_info">'.
739: &mt('You do not have permission to copy files and/or directories from Course Authoring Space.').
740: '</p>'.
741: &endContentScreen());
742: return '';
743: }
744: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
745: $r->print('<p class="LC_info">'.&mt('Selected Authoring Space is not on this server.').'</p>'.
746: &endContentScreen());
747: return '';
748: }
749: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
750: my $desturl = "/priv/$cd/$ca";
751: my $desttop = $r->dir_config('lonDocRoot').$desturl;
752: my $subdir = &clean($env{'form.authorfolder'});
753: $subdir = &cleandir($subdir);
754: if ($subdir eq '') {
755: $r->print('<p class="LC_info">'.&mt('After removal of disallowed characters target sub-directory name was blank.').'</p>'.
756: &endContentScreen());
757: return '';
758: } elsif ($subdir =~/^_+$/) {
759: $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>'.
760: &endContentScreen());
761: return '';
762: }
763: my (%tocopy,%dirs_to_make,%files_to_copy);
764: map { $tocopy{&unescape($_)} = 1; } &Apache::loncommon::get_env_multiple('form.copytouser');
765: if (keys(%tocopy)) {
766: my (%subdirs,%files);
1.714 ! raeburn 767: &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files);
1.712 raeburn 768: foreach my $possible (sort(keys(%tocopy))) {
769: if ($possible =~ m{/$}) {
770: my $possdir = $possible;
771: $possdir =~ s{^/+|/+$}{}g;
772: if (exists($subdirs{$possdir})) {
773: $dirs_to_make{$possdir} = 1;
774: } else {
775: delete($tocopy{$possible});
776: }
777: } else {
778: my ($path,$fname) = ($possible =~ m{(.*/)([^/]+)$});
779: my $found = 0;
780: if ($path eq '/') {
781: if (ref($files{$path}) eq 'HASH') {
782: if (exists($files{$path}{$fname})) {
783: $found = 1;
784: $files_to_copy{$fname} = 1;
785: }
786: }
787: } else {
788: $path =~ s{^/+|/+$}{}g;
789: if (ref($files{$path}) eq 'HASH') {
790: if (exists($files{$path}{$fname})) {
791: $dirs_to_make{$path} = 1;
792: $files_to_copy{"$path/$fname"} = 1;
793: $found = 1;
794: }
795: }
796: }
797: unless ($found) {
798: delete($tocopy{$possible});
799: }
800: }
801: }
802: } else {
803: $r->print('<p>'.&mt('No files or directories selected for copying').'</p>');
804: $r->print(&endContentScreen());
805: return '';
806: }
807: if (keys(%tocopy)) {
1.714 ! raeburn 808: my (%resdirs,%resfiles);
! 809: my $resurl = "/res/$coursedom/$coursenum";
! 810: my $res_exclude = &Apache::lonnet::res_exclude();
! 811: &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
1.713 raeburn 812: my ($notopdir,%newdir,%newfile,%checkdeps);
1.712 raeburn 813: $r->print('<p>'.&mt('Copy to: [_1]',
814: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
815: '</p>'."\n");
816: if (keys(%dirs_to_make)) {
1.714 ! raeburn 817: unless (-e $desttop.'/'.$subdir) {
! 818: mkdir($desttop.'/'.$subdir,0755);
! 819: }
! 820: if (-e $desttop.'/'.$subdir) {
! 821: foreach my $dir (sort(keys(%dirs_to_make))) {
! 822: my @dirs=split(/\//,$dir);
! 823: my $path="$desttop/$subdir";
! 824: my $makepath=$path;
! 825: my $fail;
! 826: for (my $i=0;$i<@dirs;$i++) {
! 827: $makepath.='/'.$dirs[$i];
! 828: unless (-e $makepath) {
! 829: unless (mkdir($makepath,0755)) {
! 830: $fail = 1;
! 831: last;
! 832: }
! 833: if (($i == scalar(@dirs)-1) && (!$fail)) {
! 834: $newdir{$dir} = 1;
1.712 raeburn 835: }
836: }
837: }
1.714 ! raeburn 838: if ($fail) {
! 839: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
! 840: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$dir.'</span>').
! 841: '</p>'."\n");
! 842: }
1.712 raeburn 843: }
1.714 ! raeburn 844: } else {
! 845: $notopdir = 1;
1.712 raeburn 846: }
847: }
848: if (keys(%files_to_copy)) {
1.714 ! raeburn 849: unless (-e $desttop.'/'.$subdir) {
! 850: mkdir($desttop.'/'.$subdir,0755);
! 851: }
! 852: if (-e $desttop.'/'.$subdir) {
! 853: my $num = 0;
! 854: foreach my $file (keys(%files_to_copy)) {
! 855: my ($fail,$dup,$dir_is_file,$src,$dest,$path,$fname);
! 856: if ($file =~ m{/}) {
! 857: ($path,$fname) = ($file =~ m{^(.+)/([^/]+)$});
! 858: if (-d "$desttop/$subdir/$path") {
! 859: if (-e "$desttop/$subdir/$path/$fname") {
! 860: $dup = 1;
1.712 raeburn 861: } else {
1.714 ! raeburn 862: $src = "$srctop/$path/$fname";
! 863: $dest = "$desttop/$subdir/$path/$fname";
1.712 raeburn 864: }
1.714 ! raeburn 865: } elsif (-f "$desttop/$subdir/$path") {
! 866: $dir_is_file = 1;
1.712 raeburn 867: } else {
1.714 ! raeburn 868: $fail = 1;
! 869: }
! 870: } elsif (-e "$desttop/$subdir/$file") {
! 871: $dup = 1;
! 872: } else {
! 873: $src = "$srctop/$file";
! 874: $dest = "$desttop/$subdir/$file";
! 875: $fname = $file;
! 876: }
! 877: if ($fail) {
! 878: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
! 879: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$path.'</span>').
! 880: '</p>'."\n");
! 881: } elsif ($dup) {
! 882: $r->print('<p class="LC_warning">'.&mt('Target file: [_1] already exists -- not overwriting.',
! 883: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
! 884: '</p>'."\n");
! 885: } elsif ($dir_is_file) {
! 886: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] name is already in a use for a file -- not overwriting.',
! 887: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
! 888: '</p>'."\n");
! 889: } elsif (($src ne '') && ($dest ne '')) {
! 890: if ($is_course_home) {
1.712 raeburn 891: if (&File::Copy::copy($src,$dest)) {
892: $newfile{$file} = 1;
1.714 ! raeburn 893: }
! 894: } else {
! 895: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
! 896: $newfile{$file} = 1;
! 897: }
! 898: }
! 899: if ($newfile{$file}) {
! 900: my $gotmeta;
! 901: if ($is_course_home) {
1.712 raeburn 902: if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
903: if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
1.714 ! raeburn 904: $gotmeta = 1;
! 905: }
! 906: }
! 907: } else {
! 908: if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
! 909: $gotmeta = 1;
! 910: }
! 911: }
! 912: if ($gotmeta) {
! 913: if (open(my $fh,'<',$dest.'.meta')) {
! 914: my ($output,$now);
! 915: $now = time;
! 916: while (my $line=<$fh>) {
! 917: chomp($line);
! 918: if ($line eq "<authorspace>$coursenum:$coursedom</authorspace>") {
! 919: $output .= "<authorspace>$ca:$cd</authorspace>\n";
! 920: } elsif ($line eq '<copyright>custom</copyright>') {
! 921: $output .= "<copyright>default</copyright>\n";
! 922: } elsif ($line =~ m{^<creationdate>\d+</creationdate>$}) {
! 923: $output .= "<creationdate>$now</creationdate>\n";
! 924: } elsif ($line eq "<customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>") {
! 925: $output .= "<customdistributionfile></customdistributionfile>\n";
! 926: } elsif ($line eq "<domain>$coursedom</domain>") {
! 927: $output .= "<domain>$cd</domain>\n";
! 928: } elsif ($line =~ m{^<lastrevisiondate>\d+</lastrevisiondate>$}) {
! 929: $output .= "<lastrevisiondate>$now</lastrevisiondate>\n";
! 930: } elsif ($line =~ m{^<modifyinguser>$match_username:$match_domain</modifyinguser>$}) {
! 931: $output .= "<modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>\n";
! 932: } elsif ($line eq "<owner>$coursenum:$coursedom</owner>") {
! 933: $output .= "<owner>$ca:$cd</owner>\n";
! 934: } elsif ($line =~ m{^<dependencies>(.+)</dependencies>$}) {
! 935: my @deps = split(/\s*,\s*/,$1);
! 936: my @newdeps;
! 937: my $changed = 0;
! 938: foreach my $dep (@deps) {
! 939: if ($dep =~ m{^/res/$coursedom/$coursenum/(.+)$}) {
! 940: my $rest = $1;
! 941: push(@newdeps,"/res/$cd/$ca/$rest");
! 942: $checkdeps{$rest} = 1;
! 943: $changed ++;
1.713 raeburn 944: } else {
1.714 ! raeburn 945: push(@newdeps,$dep);
1.713 raeburn 946: }
947: }
1.714 ! raeburn 948: if ($changed) {
! 949: $output .= '<dependencies>'.join(',',@newdeps).'</dependencies>'."\n";
1.713 raeburn 950: }
1.714 ! raeburn 951: } else {
! 952: $output .= "$line\n";
1.713 raeburn 953: }
1.712 raeburn 954: }
1.714 ! raeburn 955: close($fh);
! 956: if (open(my $fh,'>',$dest.'.meta')) {
! 957: print $fh $output;
! 958: close($fh);
! 959: }
1.712 raeburn 960: }
1.714 ! raeburn 961: }
! 962: my ($ext) = ($file =~ /\.(\w+)$/);
! 963: my $embstyle=&Apache::loncommon::fileembstyle($ext);
! 964: if ($embstyle eq 'ssi') {
! 965: my $outstring='';
! 966: my $changes = 0;
! 967: my @parser;
! 968: $parser[0]=HTML::LCParser->new($dest);
! 969: $parser[-1]->xml_mode(1);
! 970: my $token;
! 971: while (@parser) {
! 972: while ($token=$parser[-1]->get_token) {
! 973: if ($token->[0] eq 'S') {
! 974: my $tag=$token->[1];
! 975: my $lctag=lc($tag);
! 976: my %parms=%{$token->[2]};
! 977: foreach my $type ('src','href','background','bgimg') {
! 978: foreach my $key (keys(%parms)) {
! 979: if ($key =~ /^$type$/i) {
! 980: next if (($lctag eq 'img') && ($type eq 'src') &&
! 981: ($parms{$key} =~ m{^data\:image/gif;base64,}));
! 982: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 983: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
! 984: $changes ++;
1.713 raeburn 985: }
986: }
987: }
1.714 ! raeburn 988: }
! 989: # probably a <randomlabel> image type <label>
! 990: # or a <image> tag inside <imageresponse> or <drawimage>
! 991: if (($lctag eq 'label' && defined($parms{'description'}))
! 992: || ($lctag eq 'image') || ($lctag eq 'import')) {
! 993: my $next_token=$parser[-1]->get_token();
! 994: if ($next_token->[0] eq 'T') {
! 995: $next_token->[1] =~ s/[\n\r\f]+//g;
! 996: if ($next_token->[1] =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 997: $next_token->[1] =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
! 998: $changes ++;
! 999: }
! 1000: }
! 1001: $parser[-1]->unget_token($next_token);
! 1002: }
! 1003: if ($lctag eq 'applet') {
! 1004: my $havecodebase=0;
! 1005: foreach my $key (keys(%parms)) {
! 1006: if (lc($key) eq 'codebase') {
! 1007: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1008: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
1.713 raeburn 1009: $changes ++;
1010: }
1.714 ! raeburn 1011: $havecodebase = 1;
1.713 raeburn 1012: }
1013: }
1.714 ! raeburn 1014: unless ($havecodebase) {
1.713 raeburn 1015: foreach my $key (keys(%parms)) {
1.714 ! raeburn 1016: if ($key =~ /(archive|code|object)/i) {
1.713 raeburn 1017: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
1.714 ! raeburn 1018: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/si};
1.713 raeburn 1019: $changes ++;
1020: }
1021: }
1022: }
1023: }
1.714 ! raeburn 1024: }
! 1025: my $newparmstring='';
! 1026: my $endtag='';
! 1027: foreach my $parkey (keys(%parms)) {
! 1028: if ($parkey eq '/') {
! 1029: $endtag=' /';
! 1030: } else {
! 1031: my $quote=($parms{$parkey}=~/\"/?"'":'"');
! 1032: $newparmstring.=' '.$parkey.'='.$quote.$parms{$parkey}.$quote;
1.713 raeburn 1033: }
1.714 ! raeburn 1034: }
! 1035: if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
! 1036: $outstring.='<'.$tag.$newparmstring.$endtag.'>';
! 1037: if ($lctag eq 'm' || $lctag eq 'answer' || $lctag eq 'display' ||
! 1038: $lctag eq 'tex') {
! 1039: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
! 1040: } elsif ($lctag eq 'script') {
! 1041: if ($parms{'type'} eq 'loncapa/perl') {
1.713 raeburn 1042: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
1.714 ! raeburn 1043: } else {
! 1044: my $needsupdate;
! 1045: my $script = &Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
! 1046: if ($script =~ m{\.addMediaSrc\((["'])((?!\1).+)\1\);}) {
! 1047: my $src = $2;
! 1048: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1049: $needsupdate = 1;
1.713 raeburn 1050: }
1.714 ! raeburn 1051: }
! 1052: if ($script =~ /\(document,\s*(['"])script\1,\s*\[([^\]]+)\]\);/s) {
! 1053: my $scriptslist = $2;
! 1054: my $needsupdate = 1;
! 1055: my @srcs = split(/\s*,\s*/,$scriptslist);
! 1056: foreach my $src (@srcs) {
! 1057: if ($src =~ /(["'])(?:(?!\1).)+\.js\1/) {
! 1058: my $quote = $1;
! 1059: my ($url) = ($src =~ m/\Q$quote\E([^$quote]+)\Q$quote\E/);
! 1060: if ($url =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1061: $needsupdate = 1;
1.713 raeburn 1062: }
1063: }
1064: }
1.714 ! raeburn 1065: }
! 1066: if ($script =~ m{loadScript\(\s*(['"])((?:(?!\1).)+\.js)\1,\s*function}is) {
! 1067: my $src = $2;
! 1068: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1069: $needsupdate = 1;
1.713 raeburn 1070: }
1071: }
1.714 ! raeburn 1072: if ($needsupdate) {
! 1073: $script =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/gsi};
! 1074: $changes ++;
! 1075: }
! 1076: $outstring .= $script;
1.713 raeburn 1077: }
1.714 ! raeburn 1078: }
! 1079: } elsif ($token->[0] eq 'E') {
! 1080: if ($token->[2]) {
! 1081: unless ($token->[1] eq 'allow') {
! 1082: $outstring.='</'.$token->[1].'>';
1.713 raeburn 1083: }
1084: }
1.714 ! raeburn 1085: } else {
! 1086: $outstring.=$token->[1];
1.713 raeburn 1087: }
1088: }
1.714 ! raeburn 1089: pop(@parser);
! 1090: }
! 1091: if ($changes) {
! 1092: if (open(my $fh,'>',$dest)) {
! 1093: print $fh $outstring;
! 1094: close($fh);
1.713 raeburn 1095: }
1.712 raeburn 1096: }
1097: }
1098: }
1099: }
1100: }
1.714 ! raeburn 1101: } else {
! 1102: $notopdir = 1;
1.712 raeburn 1103: }
1104: }
1105: if ($notopdir) {
1106: $r->print('<p><span class="LC_info">'.&mt('No files or sub-directories copied').'</span><br />'."\n".
1107: '<span class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
1108: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1109: '</span></p>'."\n");
1110: }
1111: if (keys(%newdir)) {
1112: $r->print('<p>'.&mt('Created the following directories in [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1113: '</p>'."\n".
1114: '<ul><li>'.join('</li><li>',sort(keys(%newdir))).'</li></ul></p>'."\n");
1115: }
1116: if (keys(%newfile)) {
1117: $r->print('<p>'.&mt('Copied the following files to [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1118: '</p>'."\n".
1119: '<ul><li>'.join('</li><li>',sort(keys(%newfile))).'</li></ul></p>'."\n");
1120: }
1.713 raeburn 1121: if (keys(%checkdeps)) {
1122: my %missingdep;
1123: foreach my $depfile (sort(keys(%checkdeps))) {
1124: unless (-e "$desttop/$depfile") {
1125: $missingdep{$depfile} = 1;
1126: }
1127: }
1128: if (keys(%missingdep)) {
1129: $r->print('<p>'.&mt('You may also need to copy the following missing dependencies for files copied to [_1]:',
1130: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1131: '</p>'."\n".
1132: '<ul><li>'.join('</li><li>',sort(keys(%missingdep))).'</li></ul></p>'."\n");
1133: }
1134: }
1.712 raeburn 1135: } else {
1136: $r->print('<p>'.&mt('No currently existing files or directories in Course Authoring Space selected for copying').'</p>');
1137: $r->print(&endContentScreen());
1138: return '';
1139: }
1140: } else {
1141: my $formname = 'copycrsauthored';
1142: my $chkname = 'copytouser';
1143: my $context = 'crsauthored';
1144: my (%subdirs,%files,@dirs_by_depth,@files_by_depth,%parent,%children,%hierarchy,@checked_maps);
1.714 ! raeburn 1145: &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files,1);
1.712 raeburn 1146: foreach my $key (keys(%subdirs)) {
1147: next if (($key eq '/') || ($key eq ''));
1148: my @items = split(/\//,$key);
1149: my $dir = pop(@items);
1150: my $depth = scalar(@items);
1151: my $path;
1152: if (!$depth) {
1153: $path = '/';
1154: } else {
1155: $path = join('/',@items);
1156: }
1157: $dirs_by_depth[$depth]{$path}{$dir} = 1;
1158: }
1159: foreach my $path (keys(%files)) {
1160: next if ($path eq '');
1161: my $depth;
1162: if ($path eq '/') {
1163: $depth = 0;
1164: } else {
1165: $depth = scalar(split(/\//,$path));
1166: }
1167: if (ref($files{$path}) eq 'HASH') {
1168: foreach my $file (keys(%{$files{$path}})) {
1.714 ! raeburn 1169: $files_by_depth[$depth]{$path}{$file} = $files{$path}{$file};
1.712 raeburn 1170: }
1171: }
1172: }
1173: my ($info,$display,$onsubmit,$togglebuttons,$disabled);
1.714 ! raeburn 1174: my (%resdirs,%resfiles);
! 1175: my $resurl = "/res/$coursedom/$coursenum";
! 1176: my $resexclude = &Apache::lonnet::res_exclude();
! 1177: &Apache::lonnet::recursedirs($is_course_home,1,undef,$resexclude,0,0,$resurl,'',\%resdirs,\%resfiles);
1.712 raeburn 1178: if ($readonly) {
1179: $disabled = ' disabled="disabled"';
1180: }
1181: if ($disabled) {
1182: $togglebuttons = '<br />';
1183: } else {
1184: $togglebuttons = '<input type="button" value="'.&mt('check all').'" '.
1185: 'onclick="javascript:checkAll(document.'.$formname.'.'.$chkname.')" />'.
1186: ' <input type="button" value="'.&mt('uncheck all').'"'.
1187: ' onclick="javascript:uncheckAll(document.'.$formname.'.'.$chkname.')" />';
1188: }
1189: my $title=$origcrsdata{'description'};
1190: $title=~s/[\/\s]+/\_/gs;
1191: $title=&clean($title);
1192: my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash);
1193: my $display = '<form name="'.$formname.'" action="" method="post">'."\n".
1194: $preamble."\n".
1195: '<div class="LC_float_left">'."\n".
1196: '<fieldset>'."\n".
1197: '<legend>'.&mt('Content to copy').(' 'x4).$togglebuttons.'</legend>'."\n".
1198: '<span class="LC_fontsize_medium">'.
1199: &mt('Choose the files and/or folders to copy from Course Authoring to User Authoring').
1200: '</span><br /><br />'."\n";
1201: my $count = 0;
1202: my $startcount = 4 + $home;
1203: my $lastcontainer = $startcount;
1204: $display .= &Apache::loncommon::start_data_table()."\n".
1205: &Apache::loncommon::start_data_table_header_row().
1206: '<th>'.&mt('Copy?').'</th>'.
1.714 ! raeburn 1207: '<th>'.&mt('Name').'</th>'.
! 1208: '<th>'.&mt('Last modified').'</th>'.
! 1209: '<th>'.&mt('Published?').'</th>'.
1.712 raeburn 1210: &Apache::loncommon::end_data_table_header_row()."\n";
1211: $count = &recurse_crsauthored(0,\@dirs_by_depth,\@files_by_depth,'/',$startcount,
1212: $count,\$display,\%parent,\%children,$readonly,
1.714 ! raeburn 1213: $formname,$chkname,\$lastcontainer,\%resfiles);
1.712 raeburn 1214: $display .= &Apache::loncommon::end_data_table().'</fieldset>';
1215: unless ($readonly) {
1216: $display .= '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
1217: '<div>'.
1218: '<input type="submit" name="copyauthored" value="'.&mt("Copy Selected Content").'" />'.
1219: '</div>';
1220: }
1221: $display .= &Apache::loncourserespicker::respicker_javascript($startcount,$count,$context,$formname,\%children,
1222: \%hierarchy,\@checked_maps,$home,$chkname);
1223: $r->print($display);
1224: }
1225: $r->print(&endContentScreen());
1226: }
1227:
1228: sub recurse_crsauthored {
1229: my ($currdepth,$dirs_by_depth,$files_by_depth,$currpath,$startcount,$count,$displayref,
1.714 ! raeburn 1230: $parent,$children,$readonly,$formname,$chkname,$lastcontainerref,$resfilesref) = @_;
! 1231: return $count unless ((ref($dirs_by_depth) eq 'ARRAY') && (ref($files_by_depth) eq 'ARRAY') &&
! 1232: (ref($resfilesref) eq 'HASH'));
1.712 raeburn 1233: my ($disabled,$hasdirs,$hasfiles,%unique,%dirs,%files);
1234: if ((ref($dirs_by_depth->[$currdepth]) eq 'HASH') &&
1235: (ref($dirs_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1236: $hasdirs = 1;
1237: %dirs = %{$dirs_by_depth->[$currdepth]{$currpath}};
1238: map { $unique{$_} = 1; } keys(%dirs);
1239: }
1240: if ((ref($files_by_depth->[$currdepth]) eq 'HASH') &&
1241: (ref($files_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1242: $hasfiles = 1;
1243: %files = %{$files_by_depth->[$currdepth]{$currpath}};
1244: map { $unique{$_} = 1; } keys(%files);
1245: }
1246: if ($readonly) {
1247: $disabled = ' disabled="disabled"';
1248: }
1249: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
1250: my $whitespace =
1251: '<img src="'.$location.'/whitespace_21.gif" class="LC_docs_spacer" alt="" />';
1252: $parent->{$currdepth} = $$lastcontainerref;
1253: foreach my $item (sort { lc($a) cmp lc($b) } (keys(%unique))) {
1254: next if ($item eq '');
1255: my $currelem;
1256: if ($hasdirs && exists($dirs{$item})) {
1257: $count ++;
1258: my $deeper = $currdepth+1;
1259: my ($newpath,$showpath);
1260: if ($currpath eq '/') {
1261: $newpath = $item;
1262: $showpath = $currpath.$item.'/';
1263: } else {
1264: $newpath = $currpath.'/'.$item;
1265: $showpath = '/'.$currpath.'/'.$item.'/';
1266: }
1267: $currelem = $count+$startcount;
1268: $$lastcontainerref = $currelem;
1269: $children->{$parent->{$currdepth}} .= $currelem.':';
1270: my $icon = 'src="'.$location.'/navmap.folder.open.gif" alt="'.&mt('Folder').'"';
1271: $$displayref .= &Apache::loncommon::start_data_table_row().
1272: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath).'" '.
1273: 'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" '.
1274: $disabled.' /></td><td>';
1275: for (my $i=0; $i<$currdepth; $i++) {
1276: $$displayref .= "$whitespace\n";
1277: }
1.714 ! raeburn 1278: $$displayref .= '<img '.$icon.' /> '.$item.'</td><td> </td><td> </td>'.
1.712 raeburn 1279: &Apache::loncommon::end_data_table_row()."\n";
1280: $count = &recurse_crsauthored($deeper,$dirs_by_depth,$files_by_depth,$newpath,
1281: $startcount,$count,$displayref,$parent,$children,
1.714 ! raeburn 1282: $readonly,$formname,$chkname,$lastcontainerref,$resfilesref);
1.712 raeburn 1283: }
1284: if ($hasfiles && exists($files{$item})) {
1285: $count ++;
1286: $currelem = $count+$startcount;
1287: $children->{$parent->{$currdepth}} .= $currelem.':';
1288: my $icon = 'src="'.&Apache::loncommon::icon($item).'"';
1289: my ($ext) = ($item =~ /\.([^.]+)$/);
1290: my $alttext;
1291: if (lc($ext) eq 'problem') {
1292: $alttext = ' alt="'.&mt('Problem Icon').'"';
1293: } elsif ($ext =~ /^x?html?$/i) {
1294: $alttext = ' alt="'.&mt('Web Page Icon').'"';
1295: } elsif ($ext =~ /^(jpg|gif|png|svg|jpeg)$/) {
1296: $alttext = ' alt="'.&mt('Image Icon').'"';
1297: } else {
1298: $alttext = ' alt="'.&mt('Resource Icon').'"';
1299: }
1300: my $showpath;
1301: if ($currpath eq '/') {
1302: $showpath = $currpath;
1303: } else {
1304: $showpath = "/$currpath/";
1305: }
1.714 ! raeburn 1306: my ($published,$lastmod);
! 1307: if ((ref($resfilesref->{$currpath})) && (exists($resfilesref->{$currpath}{$item}))) {
! 1308: $published = '<img src="'.$location.'/navmap.correct.gif" alt="'.&mt('yes').'" />';
! 1309: } else {
! 1310: $published = '<img src="'.$location.'/navmap.wrong.gif" alt="'.&mt('no').'" />';
! 1311: }
1.712 raeburn 1312: $$displayref .= &Apache::loncommon::start_data_table_row().
1313: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath.$item).'" '.
1314: 'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" '.
1315: $disabled.' /></td><td>';
1316: for (my $i=0; $i<$currdepth; $i++) {
1317: $$displayref .= "$whitespace\n";
1318: }
1319: $$displayref .= '<img '.$icon.$alttext.' /> '.$item.'</td>'.
1.714 ! raeburn 1320: '<td>'.&Apache::lonlocal::locallocaltime($files{$item}).'</td>'.
! 1321: '<td style="text-align: center;">'.$published.'</td>'.
1.712 raeburn 1322: &Apache::loncommon::end_data_table_row()."\n";
1323: }
1324: }
1325: $$lastcontainerref = $parent->{$currdepth};
1326: return $count;
1327: }
1328:
1.329 droeschl 1329: sub group_import {
1.598 raeburn 1330: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 1331: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
1332: %removeparam,$importuploaded,$fixuperrors);
1333: $allmaps = {};
1.329 droeschl 1334: while (@files) {
1335: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 1336: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 1337: && ($caller eq 'londocs')
1338: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 1339:
1.329 droeschl 1340: my $errtext = '';
1341: my $fatal = 0;
1342: my $newmapstr = '<map>'."\n".
1343: '<resource id="1" src="" type="start"></resource>'."\n".
1344: '<link from="1" to="2" index="1"></link>'."\n".
1345: '<resource id="2" src="" type="finish"></resource>'."\n".
1346: '</map>';
1347: $env{'form.output'}=$newmapstr;
1348: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1349: 'output',$1.$2);
1.534 raeburn 1350: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 1351: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
1352: $fatal = 2;
1353: }
1354: if ($fatal) {
1355: return ($errtext,$fatal);
1356: }
1357: }
1358: if ($url) {
1.626 raeburn 1359: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 1360: $url = $1;
1361: my $marker = $2;
1362: my $info = $3;
1.699 raeburn 1363: my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.642 raeburn 1364: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 1365: my @toolinfo = split(/:/,$info);
1366: if ($residx) {
1.604 raeburn 1367: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 1368: $toolid = $toolsettings{'id'};
1369: } else {
1.604 raeburn 1370: $toolid = shift(@toolinfo);
1.598 raeburn 1371: }
1.699 raeburn 1372: if ($toolid =~ /^c/) {
1373: $tooltype = 'crs';
1374: $toolprefix = 'c';
1375: } else {
1376: $tooltype = 'dom';
1377: }
1.598 raeburn 1378: $toolid =~ s/\D//g;
1.604 raeburn 1379: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 1380: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
1381: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 1382: foreach my $item (@extras) {
1383: $toolhash{$item} = &unescape($toolhash{$item});
1384: }
1.645 raeburn 1385: if ($folder =~ /^supplemental/) {
1.648 raeburn 1386: delete($toolhash{'gradable'});
1387: } else {
1388: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 1389: }
1.598 raeburn 1390: if (ref($ltitoolsref) eq 'HASH') {
1.699 raeburn 1391: if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
1392: if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
1393: my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
1394: my @deleted;
1395: $toolhash{'id'} = $toolprefix.$toolid;
1396: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
1397: ($toolhash{'target'} eq 'window')) {
1398: if ($toolhash{'target'} eq 'window') {
1399: foreach my $item ('width','height') {
1400: $toolhash{$item} =~ s/^\s+//;
1401: $toolhash{$item} =~ s/\s+$//;
1402: if ($toolhash{$item} =~ /\D/) {
1403: delete($toolhash{$item});
1404: if ($residx) {
1405: if ($toolsettings{$item}) {
1406: push(@deleted,$item);
1407: }
1.624 raeburn 1408: }
1409: }
1410: }
1.604 raeburn 1411: }
1.699 raeburn 1412: } elsif ($residx) {
1413: $toolhash{'target'} = $toolsettings{'target'};
1414: if ($toolhash{'target'} eq 'window') {
1415: foreach my $item ('width','height') {
1416: $toolhash{$item} = $toolsettings{$item};
1417: }
1418: }
1419: } elsif (ref($tools{'display'}) eq 'HASH') {
1420: $toolhash{'target'} = $tools{'display'}{'target'};
1421: if ($toolhash{'target'} eq 'window') {
1422: $toolhash{'width'} = $tools{'display'}{'width'};
1423: $toolhash{'height'} = $tools{'display'}{'height'};
1.624 raeburn 1424: }
1.604 raeburn 1425: }
1.699 raeburn 1426: if ($toolhash{'target'} eq 'iframe') {
1427: foreach my $item ('width','height','linktext','explanation') {
1428: delete($toolhash{$item});
1429: if ($residx) {
1430: if ($toolsettings{$item}) {
1431: push(@deleted,$item);
1432: }
1.624 raeburn 1433: }
1.604 raeburn 1434: }
1.699 raeburn 1435: } elsif ($toolhash{'target'} eq 'tab') {
1436: foreach my $item ('width','height') {
1437: delete($toolhash{$item});
1438: if ($residx) {
1439: if ($toolsettings{$item}) {
1440: push(@deleted,$item);
1441: }
1.628 raeburn 1442: }
1443: }
1444: }
1.699 raeburn 1445: if (ref($tools{'crsconf'}) eq 'HASH') {
1446: foreach my $item ('label','title','linktext','explanation') {
1447: my $crsitem;
1448: if (($item eq 'label') || ($item eq 'title')) {
1449: $crsitem = 'crs'.$item;
1450: } else {
1451: $crsitem = $item;
1452: }
1453: if ($tools{'crsconf'}{$item}) {
1454: $toolhash{$crsitem} =~ s/^\s+//;
1455: $toolhash{$crsitem} =~ s/\s+$//;
1456: if ($toolhash{$crsitem} eq '') {
1457: delete($toolhash{$crsitem});
1458: }
1459: } else {
1.624 raeburn 1460: delete($toolhash{$crsitem});
1.604 raeburn 1461: }
1.699 raeburn 1462: if (($residx) && (exists($toolsettings{$crsitem}))) {
1463: unless (exists($toolhash{$crsitem})) {
1464: push(@deleted,$crsitem);
1465: }
1466: }
1.604 raeburn 1467: }
1.699 raeburn 1468: }
1469: if ($toolhash{'passback'}) {
1470: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1471: $toolhash{'gradesecret'} = $gradesecret;
1472: $toolhash{'gradesecretdate'} = time;
1473: }
1474: if ($toolhash{'roster'}) {
1475: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1476: $toolhash{'rostersecret'} = $rostersecret;
1477: $toolhash{'rostersecretdate'} = time;
1478: }
1479: my $changegradable;
1480: if (($residx) && ($folder =~ /^default/)) {
1481: if ($toolsettings{'gradable'}) {
1482: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1483: push(@deleted,'gradable');
1484: $changegradable = 1;
1.604 raeburn 1485: }
1.699 raeburn 1486: } elsif ($toolhash{'gradable'}) {
1487: $changegradable = 1;
1.604 raeburn 1488: }
1.699 raeburn 1489: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 1490: $changegradable = 1;
1.699 raeburn 1491: if ($toolsettings{'gradable'}) {
1492: $toolhash{'gradable'} = 1;
1493: }
1.645 raeburn 1494: }
1.648 raeburn 1495: }
1.699 raeburn 1496: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1497: if ($putres eq 'ok') {
1498: if (@deleted) {
1499: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648 raeburn 1500: }
1.699 raeburn 1501: if (($changegradable) && ($folder =~ /^default/)) {
1502: my $val;
1503: if ($toolhash{'gradable'}) {
1504: $val = 'yes';
1505: } else {
1506: $val = 'no';
1507: }
1508: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
1509: 'string_yesno');
1510: &remember_parms($residx,'gradable','set',$val);
1.645 raeburn 1511: }
1.699 raeburn 1512: } else {
1513: return (&mt('Failed to save update to external tool.'),1);
1.645 raeburn 1514: }
1.604 raeburn 1515: }
1.598 raeburn 1516: }
1517: }
1518: }
1.529 raeburn 1519: if (($caller eq 'londocs') &&
1520: ($folder =~ /^default/)) {
1.534 raeburn 1521: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 1522: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
1523: my $cid = $coursedom.'_'.$coursenum;
1524: $allmaps =
1525: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1526: $chome,$cid);
1527: $donechk = 1;
1528: }
1529: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 1530: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1531: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 1532: $importuploaded = 1;
1533: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
1534: next if ($allmaps->{$url});
1535: }
1536: }
1.344 bisitz 1537: if (!$residx
1.329 droeschl 1538: || defined($LONCAPA::map::zombies[$residx])) {
1539: $residx = &LONCAPA::map::getresidx($url,$residx);
1540: push(@LONCAPA::map::order, $residx);
1541: }
1542: my $ext = 'false';
1543: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 1544: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
1545: my $filepath = $1;
1.675 raeburn 1546: my $fname;
1547: if ($name eq '') {
1548: $name = &mt('Web Page');
1.534 raeburn 1549: $fname = 'web';
1550: } else {
1.675 raeburn 1551: $fname = $name;
1552: $fname=&Apache::lonnet::clean_filename($fname);
1553: if ($fname eq '') {
1554: $fname = 'web';
1555: } elsif (length($fname) > 15) {
1556: $fname = substr($fname,0,14);
1557: }
1.534 raeburn 1558: }
1.675 raeburn 1559: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 1560: my $initialtext = &mt('Replace with your own content.');
1561: my $newhtml = <<END;
1.545 raeburn 1562: <html>
1.534 raeburn 1563: <head>
1.675 raeburn 1564: <title>$title</title>
1.534 raeburn 1565: </head>
1566: <body bgcolor="#ffffff">
1567: $initialtext
1568: </body>
1569: </html>
1570: END
1571: $env{'form.output'}=$newhtml;
1.630 raeburn 1572: my $result =
1.534 raeburn 1573: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1574: 'output',
1575: "$filepath/$residx/$fname.html");
1576: if ($result =~ m{^/uploaded/}) {
1577: $url = $result;
1578: if ($filepath =~ /^supplemental/) {
1579: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1580: $env{'user.domain'}.'___&&&___'.$name;
1581: }
1582: } else {
1583: return (&mt('Failed to save new web page.'),1);
1584: }
1585: }
1.675 raeburn 1586: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 1587: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 1588: $LONCAPA::map::resources[$residx] =
1.329 droeschl 1589: join(':', ($name, $url, $ext, 'normal', 'res'));
1590: }
1591: }
1.529 raeburn 1592: if ($importuploaded) {
1593: my %import_errors;
1594: my %updated = (
1595: removefrommap => \%removefrommap,
1596: removeparam => \%removeparam,
1597: );
1.533 raeburn 1598: my ($result,$msgsarray,$lockerror) =
1599: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 1600: if (keys(%import_errors) > 0) {
1.530 raeburn 1601: $fixuperrors =
1.529 raeburn 1602: '<p span class="LC_warning">'."\n".
1603: &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".
1604: '<ul>'."\n";
1605: foreach my $key (sort(keys(%import_errors))) {
1606: $fixuperrors .= '<li>'.$key.'</li>'."\n";
1607: }
1608: $fixuperrors .= '</ul></p>'."\n";
1609: }
1.533 raeburn 1610: if (ref($msgsarray) eq 'ARRAY') {
1611: if (@{$msgsarray} > 0) {
1612: $fixuperrors .= '<p class="LC_info">'.
1613: join('<br />',@{$msgsarray}).
1614: '</p>';
1615: }
1616: }
1617: if ($lockerror) {
1618: $fixuperrors .= '<p class="LC_error">'.
1619: $lockerror.
1620: '</p>';
1621: }
1.529 raeburn 1622: }
1623: my ($errtext,$fatal) =
1624: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 1625: unless ($fatal) {
1626: if ($folder =~ /^supplemental/) {
1.561 raeburn 1627: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1628: $folder.'.'.$container);
1.557 raeburn 1629: }
1630: }
1.529 raeburn 1631: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 1632: }
1633:
1634: sub log_docs {
1.494 raeburn 1635: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 1636: }
1637:
1638: {
1639: my @oldresources=();
1640: my @oldorder=();
1641: my $parmidx;
1642: my %parmaction=();
1643: my %parmvalue=();
1644: my $changedflag;
1645:
1646: sub snapshotbefore {
1647: @oldresources=@LONCAPA::map::resources;
1648: @oldorder=@LONCAPA::map::order;
1649: $parmidx=undef;
1650: %parmaction=();
1651: %parmvalue=();
1652: $changedflag=0;
1653: }
1654:
1655: sub remember_parms {
1656: my ($idx,$parameter,$action,$value)=@_;
1657: $parmidx=$idx;
1658: $parmaction{$parameter}=$action;
1659: $parmvalue{$parameter}=$value;
1660: $changedflag=1;
1661: }
1662:
1663: sub log_differences {
1664: my ($plain)=@_;
1665: my %storehash=('folder' => $plain,
1666: 'currentfolder' => $env{'form.folder'});
1667: if ($parmidx) {
1668: $storehash{'parameter_res'}=$oldresources[$parmidx];
1669: foreach my $parm (keys(%parmaction)) {
1670: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1671: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1672: }
1673: }
1674: my $maxidx=$#oldresources;
1675: if ($#LONCAPA::map::resources>$#oldresources) {
1676: $maxidx=$#LONCAPA::map::resources;
1677: }
1678: for (my $idx=0; $idx<=$maxidx; $idx++) {
1679: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1680: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1681: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1682: $changedflag=1;
1683: }
1684: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1685: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1686: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1687: $changedflag=1;
1688: }
1689: }
1690: $storehash{'maxidx'}=$maxidx;
1691: if ($changedflag) { &log_docs(\%storehash); }
1692: }
1693: }
1694:
1695: sub docs_change_log {
1.611 raeburn 1696: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 1697: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 1698: my $navmap;
1.483 raeburn 1699: my $js = '<script type="text/javascript">'."\n".
1700: '// <![CDATA['."\n".
1701: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 1702: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 1703: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 1704: &history_tab_js()."\n".
1.484 raeburn 1705: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 1706: '// ]]>'."\n".
1707: '</script>'."\n";
1.484 raeburn 1708: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1709: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1710: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1711: my %orderhash;
1712: my $container='sequence';
1713: my $pathitem;
1.519 raeburn 1714: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1715: $container='page';
1716: }
1.519 raeburn 1717: my $folderpath=$env{'form.folderpath'};
1718: if ($folderpath eq '') {
1.617 raeburn 1719: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1720: }
1.617 raeburn 1721: undef($navmap);
1.519 raeburn 1722: $pathitem = '<input type="hidden" name="folderpath" value="'.
1723: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1724: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1725: my $jumpto = $readfile;
1726: $jumpto =~ s{^/}{};
1727: my $tid = 1;
1.489 raeburn 1728: if ($supplementalflag) {
1729: $tid = 2;
1730: }
1.630 raeburn 1731: my ($breadcrumbtrail) =
1.509 raeburn 1732: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1733: $r->print($breadcrumbtrail.
1734: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1735: $readfile));
1.329 droeschl 1736: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1737: $env{'course.'.$env{'request.course.id'}.'.domain'},
1738: $env{'course.'.$env{'request.course.id'}.'.num'});
1739:
1740: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1741:
1742: my %saveable_parameters = ('show' => 'scalar',);
1743: &Apache::loncommon::store_course_settings('docs_log',
1744: \%saveable_parameters);
1745: &Apache::loncommon::restore_course_settings('docs_log',
1746: \%saveable_parameters);
1747: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1748: # FIXME: internationalization seems wrong here
1.329 droeschl 1749: my %lt=('hiddenresource' => 'Resources hidden',
1750: 'encrypturl' => 'URL hidden',
1751: 'randompick' => 'Randomly pick',
1752: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1753: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1754: 'set' => 'set to',
1755: 'del' => 'deleted');
1.484 raeburn 1756: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1757: $pathitem."\n".
1758: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1759: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1760: $r->print('<div class="LC_left_float">'.
1761: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1762: &makedocslogform($filter,1).
1763: '</fieldset></div><br clear="all" />');
1.329 droeschl 1764: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1765: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1766: &mt('After').'</th>'.
1767: &Apache::loncommon::end_data_table_header_row());
1768: my $shown=0;
1769: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1770: if ($env{'form.displayfilter'} eq 'currentfolder') {
1771: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1772: }
1773: my @changes=keys(%{$docslog{$id}{'logentry'}});
1774: if ($env{'form.displayfilter'} eq 'containing') {
1775: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1776: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1777: foreach my $key (@changes) {
1778: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1779: }
1.344 bisitz 1780: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1781: }
1782: my $count = 0;
1783: my $time =
1784: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1785: my $plainname =
1786: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1787: $docslog{$id}{'exe_udom'});
1788: my $about_me_link =
1789: &Apache::loncommon::aboutmewrapper($plainname,
1790: $docslog{$id}{'exe_uname'},
1791: $docslog{$id}{'exe_udom'});
1792: my $send_msg_link='';
1793: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1794: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1795: $send_msg_link ='<br />'.
1796: &Apache::loncommon::messagewrapper(&mt('Send message'),
1797: $docslog{$id}{'exe_uname'},
1798: $docslog{$id}{'exe_udom'});
1799: }
1800: $r->print(&Apache::loncommon::start_data_table_row());
1801: $r->print('<td>'.$time.'</td>
1802: <td>'.$about_me_link.
1803: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1804: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1805: $send_msg_link.'</td><td>'.
1806: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1807: my $is_supp = 0;
1808: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1809: $is_supp = 1;
1810: }
1.329 droeschl 1811: # Before
1812: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1813: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1814: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1815: if ($oldname ne $newname) {
1.488 raeburn 1816: my $shown = &LONCAPA::map::qtescape($oldname);
1817: if ($is_supp) {
1818: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1819: }
1820: $r->print($shown);
1.329 droeschl 1821: }
1822: }
1823: $r->print('<ul>');
1824: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1825: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1826: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1827: if ($is_supp) {
1828: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1829: }
1830: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1831: }
1832: }
1833: $r->print('</ul>');
1834: # After
1835: $r->print('</td><td>');
1836:
1837: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1838: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1839: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1840: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1841: my $shown = &LONCAPA::map::qtescape($newname);
1842: if ($is_supp) {
1843: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1844: }
1845: $r->print($shown);
1.329 droeschl 1846: }
1.364 bisitz 1847: }
1.329 droeschl 1848: $r->print('<ul>');
1849: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1850: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1851: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1852: if ($is_supp) {
1853: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1854: }
1855: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1856: }
1857: }
1858: $r->print('</ul>');
1859: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 1860: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1861: if ($title eq '') {
1862: ($title) = ($url =~ m{/([^/]+)$});
1.695 raeburn 1863: } elsif ($is_supp) {
1864: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 1865: }
1866: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 1867: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1868: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1869: # FIXME: internationalization seems wrong here
1.329 droeschl 1870: $r->print('<li>'.
1871: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1872: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1873: .'</li>');
1874: }
1875: }
1876: $r->print('</ul>');
1877: }
1878: # End
1879: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1880: $shown++;
1881: if (!($env{'form.show'} eq &mt('all')
1882: || $shown<=$env{'form.show'})) { last; }
1883: }
1.484 raeburn 1884: $r->print(&Apache::loncommon::end_data_table()."\n".
1885: &makesimpleeditform($pathitem)."\n".
1886: '</div></div>');
1887: $r->print(&endContentScreen());
1.329 droeschl 1888: }
1889:
1890: sub update_paste_buffer {
1.492 raeburn 1891: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1892: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1893: if ($env{'form.multiremove'}) {
1894: $env{'form.multiremove'} =~ s/,$//;
1895: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1896: }
1897: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1898: if ($env{'form.multicut'}) {
1899: $env{'form.multicut'} =~ s/,$//;
1900: foreach my $item (split(/,/,$env{'form.multicut'})) {
1901: unless ($removals{$item}) {
1902: $cuts{$item} = 1;
1903: push(@possibles,$item.':cut');
1904: }
1905: }
1906: }
1907: if ($env{'form.multicopy'}) {
1908: $env{'form.multicopy'} =~ s/,$//;
1909: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1910: unless ($removals{$item} || $cuts{$item}) {
1911: push(@possibles,$item.':copy');
1912: }
1913: }
1914: }
1915: } elsif ($env{'form.markcopy'}) {
1916: @possibles = split(/,/,$env{'form.markcopy'});
1917: }
1.329 droeschl 1918:
1.538 raeburn 1919: return if (@possibles == 0);
1.329 droeschl 1920: return if (!defined($env{'form.copyfolder'}));
1921:
1922: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1923: $env{'form.copyfolder'});
1.538 raeburn 1924: return if ($fatal);
1925:
1926: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1927:
1.538 raeburn 1928: # Retrieve current paste buffer suffixes.
1929: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1930: my (%pasteurls,@newpaste);
1931:
1932: # Construct identifiers for current contents of user's paste buffer
1933: if (@currpaste) {
1934: foreach my $suffix (@currpaste) {
1.667 raeburn 1935: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1936: my $url = $env{'docs.markedcopy_url_'.$suffix};
1937: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1938: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1939: ($url ne '')) {
1940: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1941: $pasteurls{$cid.'_'.$mapidx} = 1;
1942: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1943: $pasteurls{$url} = 1;
1944: } else {
1.669 raeburn 1945: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 1946: }
1947: }
1.538 raeburn 1948: }
1949: }
1950:
1951: # Mark items for copying (skip any items already in user's paste buffer)
1952: my %addtoenv;
1.597 raeburn 1953:
1954: my @pathitems = split(/\&/,$env{'form.folderpath'});
1955: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 1956: my $ispage = $folderconf[5];
1.597 raeburn 1957:
1.538 raeburn 1958: foreach my $item (@possibles) {
1959: my ($orderidx,$cmd) = split(/:/,$item);
1960: next if ($orderidx =~ /\D/);
1961: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1962: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1963: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1964: my %denied = &action_restrictions($coursenum,$coursedom,
1965: &LONCAPA::map::qtescape($url),
1966: $env{'form.folderpath'},\%curr_groups);
1967: next if ($denied{'copy'});
1968: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 1969: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1970: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1971: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1972: next if (exists($pasteurls{$url}));
1973: } else {
1974: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1975: }
1.538 raeburn 1976: my ($suffix,$errortxt,$locknotfreed) =
1977: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1978: if ($suffix ne '') {
1979: push(@newpaste,$suffix);
1980: } else {
1981: if ($locknotfreed) {
1982: return $locknotfreed;
1983: }
1.538 raeburn 1984: }
1985: if (&is_supplemental_title($title)) {
1986: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1987: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1988: }
1.329 droeschl 1989:
1.538 raeburn 1990: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1991: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1992: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1993: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1994: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1995: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1996: my $prefix = $1;
1997: my $subdir =$2;
1998: if ($subdir eq '') {
1999: $subdir = $prefix;
1.492 raeburn 2000: }
1.538 raeburn 2001: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 2002: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
2003: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 2004: if (ref($hierarchy{$url}) eq 'HASH') {
2005: my ($nested,$nestednames);
2006: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
2007: $nested =~ s/\&$//;
2008: $nestednames =~ s/\Q___&&&___\E$//;
2009: if ($nested ne '') {
2010: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
2011: }
2012: if ($nestednames ne '') {
2013: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
2014: }
1.492 raeburn 2015: }
2016: }
1.591 raeburn 2017: if ($locknotfreed) {
2018: $output = $locknotfreed;
2019: last;
2020: }
1.492 raeburn 2021: }
1.538 raeburn 2022: if (@newpaste) {
2023: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
2024: }
1.492 raeburn 2025: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 2026: delete($env{'form.markcopy'});
1.591 raeburn 2027: return $output;
1.329 droeschl 2028: }
2029:
1.492 raeburn 2030: sub recurse_uploaded_maps {
2031: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
2032: if (ref($hierarchy->{$url}) eq 'HASH') {
2033: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
2034: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
2035: my (@uploaded,@names,%shorter);
2036: for (my $i=0; $i<@maps; $i++) {
2037: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
2038: if ($inner ne '') {
2039: push(@uploaded,$inner);
2040: push(@names,&escape($titles[$i]));
2041: $shorter{$maps[$i]} = $inner;
2042: }
2043: }
2044: $$nestref .= "$dir:".join(',',@uploaded).'&';
2045: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
2046: foreach my $map (@maps) {
2047: if ($shorter{$map} ne '') {
2048: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
2049: }
2050: }
2051: }
2052: return;
2053: }
2054:
1.329 droeschl 2055: sub print_paste_buffer {
1.492 raeburn 2056: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 2057: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 2058:
1.538 raeburn 2059: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
2060: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 2061: }
2062:
1.538 raeburn 2063: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1.704 raeburn 2064: my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
1.575 raeburn 2065: my $clipboardcount = 0;
1.488 raeburn 2066:
1.538 raeburn 2067: # Construct identifiers for current contents of user's paste buffer
2068: foreach my $suffix (@currpaste) {
2069: next if ($suffix =~ /\D/);
2070: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
2071: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 2072: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 2073: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
2074: ($url ne '')) {
1.575 raeburn 2075: $clipboardcount ++;
1.538 raeburn 2076: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.704 raeburn 2077: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
2078: $toolcnum,$marker);
1.538 raeburn 2079: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
2080: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
2081: $is_external = 1;
1.704 raeburn 2082: } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2083: ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1.598 raeburn 2084: $is_exttool = 1;
1.538 raeburn 2085: }
2086: if ($folder =~ /^supplemental/) {
2087: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
2088: unless ($canpaste) {
2089: $nopaste = &mt('Paste into Supplemental Content unavailable.');
2090: }
2091: } else {
2092: $canpaste = 1;
2093: }
2094: if ($canpaste) {
2095: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2096: my $srcdom = $1;
2097: my $srcnum = $2;
2098: my $rem = $3;
2099: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
2100: $othercourse = 1;
2101: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 2102: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 2103: } else {
2104: $canpaste = 0;
2105: $nopaste = &mt('Paste from another course unavailable.');
2106: }
2107: }
2108: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
2109: my $prefix = $1;
2110: $parent = $2;
2111: if ($folder !~ /^\Q$prefix\E/) {
2112: $areachange = 1;
2113: }
2114: $is_uploaded_map = 1;
1.492 raeburn 2115: }
1.597 raeburn 2116: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 2117: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 2118: if ($cid ne $env{'request.course.id'}) {
2119: my ($srcdom,$srcnum) = split(/_/,$cid);
2120: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.704 raeburn 2121: if ($is_exttool) {
2122: if ($toolcdom ne $coursedom) {
2123: $canpaste = 0;
2124: $nopaste = &mt('Paste from another domain unavailable.');
2125: } elsif ($toolcnum ne $coursenum) {
2126: my %toolsettings =
2127: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2128: my %tooltypes = &Apache::loncommon::usable_exttools();
2129: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2130: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2131: $canpaste = 0;
2132: $nopaste = &mt('Paste from another course unavailable.');
2133: } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
2134: unless ($checkedsameinst) {
2135: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2136: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2137: if ($intdom ne '') {
2138: my $internet_names =
2139: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2140: if (ref($internet_names) eq 'ARRAY') {
2141: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2142: $same_institution = 1;
2143: }
2144: }
2145: }
2146: $checkedsameinst = 1;
2147: }
2148: if ($same_institution) {
2149: $othercrs = '<br />'.&mt('(from another course)');
2150: } else {
2151: $nopaste = &mt('Paste from another course unavailable.');
2152: }
2153: } else {
2154: $othercrs = '<br />'.&mt('(from another course)');
2155: }
2156: }
1.627 raeburn 2157: }
1.596 raeburn 2158: } else {
2159: $canpaste = 0;
2160: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 2161: }
1.596 raeburn 2162: }
1.703 raeburn 2163: } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
2164: my ($audom,$auname) = ($1,$2);
2165: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2166: if (&Apache::lonnet::is_course($audom,$auname)) {
2167: $canpaste = 0;
2168: $nopaste = &mt('Paste from another course unavailable.');
2169: }
2170: }
1.492 raeburn 2171: }
1.596 raeburn 2172: if ($canpaste) {
2173: push(@pasteable,$suffix);
1.629 raeburn 2174: }
1.538 raeburn 2175: }
2176: my $buffer;
1.627 raeburn 2177: if ($is_external) {
1.538 raeburn 2178: $buffer = &mt('External Resource').': '.
2179: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
2180: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 2181: } elsif ($is_exttool) {
2182: $buffer = &mt('External Tool').': '.
2183: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 2184: } else {
2185: my $icon = &Apache::loncommon::icon($extension);
2186: if ($extension eq 'sequence' &&
2187: $url =~ m{/default_\d+\.sequence$}x) {
2188: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
2189: $icon .= '/navmap.folder.closed.gif';
2190: }
1.589 raeburn 2191: my $title = $env{'docs.markedcopy_title_'.$suffix};
2192: if ($title eq '') {
2193: ($title) = ($url =~ m{/([^/]+)$});
2194: }
1.538 raeburn 2195: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
2196: ': '.
2197: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 2198: &LONCAPA::map::qtescape($title));
1.538 raeburn 2199: }
2200: $pasteitems .= '<div class="LC_left_float">';
2201: my ($options,$onclick);
2202: if (($canpaste) && (!$areachange) && (!$othercourse) &&
2203: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
2204: if (($is_uploaded_map) ||
2205: ($url =~ /(bulletinboard|smppg)$/) ||
2206: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
2207: $options = &paste_options($suffix,$is_uploaded_map,$parent);
2208: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
2209: }
2210: }
2211: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
2212: if ($nopaste) {
1.681 raeburn 2213: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 2214: } else {
2215: if ($othercrs) {
2216: $pasteitems .= $othercrs;
2217: }
2218: if ($options) {
2219: $pasteitems .= $options;
1.492 raeburn 2220: }
2221: }
1.538 raeburn 2222: $pasteitems .= '</div>';
2223: }
2224: }
2225: if ($pasteitems eq '') {
2226: &Apache::lonnet::delenv('docs.markedcopies');
2227: }
2228: my ($pasteform,$form_start,$buttons,$form_end);
2229: if ($pasteitems) {
2230: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 2231: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 2232: if (@pasteable) {
1.575 raeburn 2233: my $value = &mt('Paste to current folder');
2234: if ($container eq 'page') {
2235: $value = &mt('Paste to current page');
2236: }
2237: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
2238: }
2239: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
2240: if ($clipboardcount > 1) {
2241: $buttons .=
2242: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
2243: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
2244: (' 'x2).
2245: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
2246: (' 'x2);
1.492 raeburn 2247: }
1.575 raeburn 2248: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
2249: '</form>';
1.538 raeburn 2250: } else {
2251: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 2252: }
1.538 raeburn 2253: $r->print($form_start
2254: .'<fieldset>'
2255: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
2256: .$pasteitems
2257: .'</fieldset>'
2258: .$form_end);
2259: }
2260:
2261: sub paste_options {
2262: my ($suffix,$is_uploaded_map,$parent) = @_;
2263: my ($copytext,$movetext);
2264: if ($is_uploaded_map) {
2265: $copytext = &mt('Copy to new folder');
2266: $movetext = &mt('Move old');
2267: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
2268: $copytext = &mt('Copy to new board');
2269: $movetext = &mt('Move (not posts)');
2270: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
2271: $copytext = &mt('Copy to new page');
2272: $movetext = &mt('Move');
1.533 raeburn 2273: } else {
1.538 raeburn 2274: $copytext = &mt('Copy to new file');
2275: $movetext = &mt('Move');
2276: }
2277: my $output = '<br />'.
2278: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
2279: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
2280: '<label>'.
2281: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
2282: $copytext.'</label></span>'.(' 'x2).' '.
2283: '<span class="LC_nobreak"><label>'.
2284: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
2285: $movetext.'</label></span>';
2286: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
2287: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
2288: '</legend><table border="0">';
2289: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2290: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
2291: my $lastdir = $parent;
2292: my %depths = (
2293: $lastdir => 0,
2294: );
2295: my (%display,%deps);
2296: for (my $i=0; $i<@pastemaps; $i++) {
2297: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
2298: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
2299: my @subfolders = split(/,/,$subfolderstr);
2300: $deps{$lastdir} = \@subfolders;
2301: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
2302: my $depth = $depths{$lastdir} + 1;
2303: my $offset = int($depth * 4);
2304: my $indent = (' ' x $offset);
2305: for (my $j=0; $j<@subfolders; $j++) {
2306: $depths{$subfolders[$j]} = $depth;
2307: $display{$subfolders[$j]} =
2308: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
2309: '<td><label>'.
2310: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
2311: '<label>'.
2312: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
2313: &mt('Move old').'</label>'.
2314: '</td></tr>';
2315: }
1.492 raeburn 2316: }
1.538 raeburn 2317: &recurse_print(\$output,$parent,\%deps,\%display);
2318: $output .= '</table></fieldset>';
1.329 droeschl 2319: }
1.538 raeburn 2320: $output .= '</div>';
2321: return $output;
1.488 raeburn 2322: }
2323:
1.492 raeburn 2324: sub recurse_print {
1.538 raeburn 2325: my ($outputref,$dir,$deps,$display) = @_;
2326: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 2327: if (ref($deps->{$dir}) eq 'ARRAY') {
2328: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 2329: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 2330: }
2331: }
2332: }
2333:
1.488 raeburn 2334: sub supp_pasteable {
2335: my ($url) = @_;
2336: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
2337: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
2338: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
2339: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 2340: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 2341: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 2342: return 1;
2343: }
2344: return;
1.329 droeschl 2345: }
2346:
1.492 raeburn 2347: sub paste_popup_js {
1.594 damieng 2348: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 2349: show => 'Show Options',
2350: hide => 'Hide Options',
1.594 damieng 2351: );
2352: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 2353: none => 'No items selected from clipboard.',
1.492 raeburn 2354: );
1.594 damieng 2355: &html_escape(\%html_js_lt);
2356: &js_escape(\%html_js_lt);
2357: &js_escape(\%js_lt);
1.492 raeburn 2358: return <<"END";
2359:
1.538 raeburn 2360: function showPasteOptions(suffix) {
2361: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 2362: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 2363: return;
2364: }
2365:
1.538 raeburn 2366: function hidePasteOptions(suffix) {
2367: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 2368: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2369: return;
2370: }
2371:
2372: function showOptions(caller,suffix) {
2373: if (document.getElementById('pasteoptionstext_'+suffix)) {
2374: if (caller.checked) {
1.594 damieng 2375: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2376: } else {
2377: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
2378: }
2379: if (document.getElementById('pasteoptions_'+suffix)) {
2380: document.getElementById('pasteoptions_'+suffix).style.display='none';
2381: }
2382: }
1.492 raeburn 2383: return;
2384: }
2385:
1.541 raeburn 2386: function validateClipboard() {
2387: var numchk = 0;
2388: if (document.pasteform.pasting.length > 1) {
2389: for (var i=0; i<document.pasteform.pasting.length; i++) {
2390: if (document.pasteform.pasting[i].checked) {
2391: numchk ++;
2392: }
2393: }
2394: } else {
2395: if (document.pasteform.pasting.type == 'checkbox') {
2396: if (document.pasteform.pasting.checked) {
2397: numchk ++;
2398: }
2399: }
2400: }
2401: if (numchk > 0) {
2402: return true;
2403: } else {
1.594 damieng 2404: alert("$js_lt{'none'}");
1.541 raeburn 2405: return false;
2406: }
2407: }
2408:
1.575 raeburn 2409: function checkClipboard() {
2410: if (document.pasteform.pasting.length > 1) {
2411: for (var i=0; i<document.pasteform.pasting.length; i++) {
2412: document.pasteform.pasting[i].checked = true;
2413: }
2414: }
2415: return;
2416: }
2417:
2418: function uncheckClipboard() {
2419: if (document.pasteform.pasting.length >1) {
2420: for (var i=0; i<document.pasteform.pasting.length; i++) {
2421: document.pasteform.pasting[i].checked = false;
2422: }
2423: }
2424: return;
2425: }
2426:
1.492 raeburn 2427: END
2428:
2429: }
2430:
1.329 droeschl 2431: sub do_paste_from_buffer {
1.492 raeburn 2432: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 2433:
1.538 raeburn 2434: # Array of items in paste buffer
2435: my (@currpaste,%pastebuffer,%allerrors);
2436: @currpaste = split(/,/,$env{'docs.markedcopies'});
2437:
1.492 raeburn 2438: # Early out if paste buffer is empty
1.538 raeburn 2439: if (@currpaste == 0) {
1.492 raeburn 2440: return ();
1.538 raeburn 2441: }
2442: map { $pastebuffer{$_} = 1; } @currpaste;
2443:
2444: # Array of items selected items to paste
2445: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
2446:
2447: # Early out if nothing selected to paste
2448: if (@reqpaste == 0) {
2449: return();
2450: }
2451: my @topaste;
2452: foreach my $suffix (@reqpaste) {
2453: next if ($suffix =~ /\D/);
2454: next unless (exists($pastebuffer{$suffix}));
2455: push(@topaste,$suffix);
2456: }
2457:
2458: # Early out if nothing available to paste
2459: if (@topaste == 0) {
2460: return();
1.329 droeschl 2461: }
2462:
1.704 raeburn 2463: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
2464: %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
2465: %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
2466: %currltititles,$currltimax,$gotcrsltitools);
2467: $currltimax = 0;
2468: $gotcrsltitools = 0;
1.538 raeburn 2469: foreach my $suffix (@topaste) {
2470: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 2471: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 2472: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 2473: # Supplemental content may only include certain types of content
2474: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 2475: if ($folder =~ /^supplemental/) {
2476: unless (&supp_pasteable($url)) {
2477: $notinsupp{$suffix} = 1;
2478: next;
2479: }
1.492 raeburn 2480: }
1.538 raeburn 2481: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
2482: my $srcd = $1;
2483: my $srcn = $2;
1.492 raeburn 2484: # When paste buffer was populated using an active role in a different course
1.538 raeburn 2485: # check for mdc privilege in the course from which the resource was pasted
2486: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2487: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2488: $notincrs{$suffix} = 1;
2489: next;
2490: }
1.491 raeburn 2491: }
1.538 raeburn 2492: $srcdom{$suffix} = $srcd;
2493: $srcnum{$suffix} = $srcn;
1.597 raeburn 2494: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 2495: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
2496: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 2497: my ($srcd,$srcn) = split(/_/,$cid);
2498: # When paste buffer was populated using an active role in a different course
2499: # check for mdc privilege in the course from which the resource was pasted
2500: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2501: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2502: $notincrs{$suffix} = 1;
2503: next;
2504: }
2505: }
1.632 raeburn 2506: # When buffer was populated using an active role in a different course
1.704 raeburn 2507: # disallow pasting of External Tool if course is in a different domain,
2508: # or if External Tool use is not permitted in this course.
2509: if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2510: my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
2511: if ($toolcdom ne $coursedom) {
2512: $notindom{$suffix} = 1;
2513: next;
2514: } elsif ($toolcnum ne $coursenum) {
2515: my %toolsettings =
2516: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2517: my %tooltypes = &Apache::loncommon::usable_exttools();
2518: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2519: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2520: $othcrstool{$suffix} = 1;
2521: next;
2522: }
2523: if ($toolsettings{'id'} =~ /^c\d+$/) {
2524: unless ($gotcrsltitools) {
2525: %currcrsltitools =
2526: &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
2527: foreach my $item (sort(keys(%currcrsltitools))) {
2528: if (ref($currcrsltitools{$item}) eq 'HASH') {
2529: $currltimax ++;
2530: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
2531: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
2532: } else {
2533: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
2534: }
2535: }
2536: }
2537: $gotcrsltitools = 1;
2538: }
2539: }
2540: }
1.627 raeburn 2541: }
1.596 raeburn 2542: $srcdom{$suffix} = $srcd;
2543: $srcnum{$suffix} = $srcn;
1.703 raeburn 2544: } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
2545: my ($audom,$auname) = ($1,$2);
2546: # When buffer was populated using an active role in a different course
2547: # disallow pasting of published resources from Course Authoring Space
2548: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2549: if (&Apache::lonnet::is_course($audom,$auname)) {
2550: $othcrsres{$suffix} = 1;
2551: next;
2552: }
2553: }
1.491 raeburn 2554: }
1.597 raeburn 2555: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 2556: push(@dopaste,$suffix);
2557: if ($url=~/\.(page|sequence)$/) {
2558: $is_map{$suffix} = 1;
2559: }
2560: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
2561: my $oldprefix = $1;
1.492 raeburn 2562: # When pasting content from Main Content to Supplemental Content and vice versa
2563: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 2564: # a folder/page or a document).
1.538 raeburn 2565: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
2566: $prefixchg{$suffix} = 'docstosupp';
2567: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
2568: $prefixchg{$suffix} = 'supptodocs';
2569: }
1.491 raeburn 2570:
1.492 raeburn 2571: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 2572: if ($env{'docs.markedcopy_nested_'.$suffix}) {
2573: my @nested;
2574: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
2575: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2576: my @deps = map { /\d+:([\d,]+$)/ } @items;
2577: foreach my $dep (@deps) {
2578: if ($dep =~ /,/) {
2579: push(@nested,split(/,/,$dep));
2580: } else {
2581: push(@nested,$dep);
2582: }
1.492 raeburn 2583: }
1.538 raeburn 2584: foreach my $item (@nested) {
2585: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
2586: push(@{$marktomove{$suffix}},$type.'_'.$item);
2587: }
1.492 raeburn 2588: }
2589: }
1.488 raeburn 2590: }
2591: }
2592:
1.538 raeburn 2593: # Early out if nothing available to paste
2594: if (@dopaste == 0) {
2595: return ();
2596: }
2597:
2598: # Populate message hash and hashes used for main content <=> supplemental content
2599: # changes
2600:
2601: %msgs = &Apache::lonlocal::texthash (
2602: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
2603: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 2604: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.704 raeburn 2605: othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.703 raeburn 2606: othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538 raeburn 2607: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
2608: );
2609:
2610: %before = (
2611: docstosupp => {
2612: map => 'default',
2613: doc => 'docs',
2614: },
2615: supptodocs => {
2616: map => 'supplemental',
2617: doc => 'supplemental',
2618: },
2619: );
2620:
2621: %after = (
2622: docstosupp => {
2623: map => 'supplemental',
2624: doc => 'supplemental'
2625: },
2626: supptodocs => {
2627: map => 'default',
2628: doc => 'docs',
2629: },
2630: );
2631:
2632: # Retrieve information about all course maps in main content area
2633:
2634: my $allmaps = {};
1.704 raeburn 2635: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
2636: @updatetoolsenc,$updatetoolscache,$checkedsameinst,
2637: $same_institution);
1.538 raeburn 2638:
2639: # Loop over the items to paste
2640: foreach my $suffix (@dopaste) {
1.329 droeschl 2641: # Maps need to be copied first
1.538 raeburn 2642: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
2643: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 2644: %newurls,%tomove,%resdatacopy);
1.538 raeburn 2645: if (ref($marktomove{$suffix}) eq 'ARRAY') {
2646: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
2647: }
2648: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
2649: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 2650: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 2651: my $oldurl = $url;
2652: if ($is_map{$suffix}) {
1.491 raeburn 2653: # If pasting a map, check if map contains other maps
1.538 raeburn 2654: my (%hierarchy,%titles);
1.660 raeburn 2655: if (($folder =~ /^default/) && (!$donechk)) {
2656: $allmaps =
2657: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
2658: $env{"course.$env{'request.course.id'}.home"},
2659: $env{'request.course.id'});
2660: $donechk = 1;
2661: }
1.627 raeburn 2662: &contained_map_check($url,$folder,$coursenum,$coursedom,
2663: \%removefrommap,\%removeparam,\%addedmaps,
2664: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 2665: if ($url=~ m{^/uploaded/}) {
2666: my $newurl;
2667: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2668: ($newurl,my $error) =
2669: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
2670: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2671: \$title,$allmaps,\%newurls);
2672: if ($error) {
2673: $allerrors{$suffix} = $error;
2674: next;
2675: }
2676: if ($newurl ne '') {
2677: if ($newurl ne $url) {
2678: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
2679: $newsubdir{$url} = $1;
2680: }
2681: $mapchanges{$url} = 1;
1.492 raeburn 2682: }
1.538 raeburn 2683: }
2684: }
2685: if (($srcdom{$suffix} ne $coursedom) ||
2686: ($srcnum{$suffix} ne $coursenum) ||
2687: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
2688: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
2689: $coursedom,$coursenum,$srcdom{$suffix},
2690: $srcnum{$suffix},$allmaps,\%rewrites,
2691: \%retitles,\%copies,\%dbcopies,
2692: \%zombies,\%params,\%mapmoves,
2693: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 2694: \%newurls,\%resdatacopy)) {
1.538 raeburn 2695: $mapmoves{$url} = 1;
2696: }
2697: $url = $newurl;
2698: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
2699: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
2700: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2701: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
2702: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 2703: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 2704: }
2705: } elsif ($url=~m {^/res/}) {
1.597 raeburn 2706: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 2707: push(@toclear,$suffix);
2708: # if pasting published map (main content area only) check map not already in course
2709: if ($folder =~ /^default/) {
2710: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
2711: $duplicate{$suffix} = 1;
2712: next;
1.492 raeburn 2713: }
1.491 raeburn 2714: }
2715: }
1.538 raeburn 2716: }
1.627 raeburn 2717: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 2718: my $prefix = $1;
1.648 raeburn 2719: my $fromothercrs;
1.538 raeburn 2720: #need to copy the db contents to a new one, unless this is a move.
2721: my %info = (
2722: src => $url,
2723: cdom => $coursedom,
2724: cnum => $coursenum,
1.596 raeburn 2725: );
1.649 raeburn 2726: if ($prefix eq 'ext.tool') {
1.655 raeburn 2727: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 2728: $info{'delgradable'} = 1;
2729: }
2730: }
1.596 raeburn 2731: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
2732: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
2733: $fromothercrs = 1;
2734: $info{'cdom'} = $srcdom{$suffix};
2735: $info{'cnum'} = $srcnum{$suffix};
1.704 raeburn 2736: unless ($checkedsameinst) {
2737: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2738: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2739: if ($intdom ne '') {
2740: my $internet_names =
2741: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2742: if (ref($internet_names) eq 'ARRAY') {
2743: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2744: $same_institution = 1;
2745: }
2746: }
2747: }
2748: $checkedsameinst = 1;
2749: }
1.596 raeburn 2750: }
2751: }
2752: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 2753: my (%lockerr,$msg);
1.538 raeburn 2754: my ($newurl,$result,$errtext) =
1.704 raeburn 2755: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
2756: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.538 raeburn 2757: if ($result eq 'ok') {
2758: $url = $newurl;
2759: $title=&mt('Copy of').' '.$title;
2760: } else {
2761: if ($prefix eq 'smppg') {
2762: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2763: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 2764: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 2765: } elsif ($prefix eq 'ext.tool') {
2766: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 2767: }
2768: $results{$suffix} = $result;
2769: $msgerrs{$suffix} = $msg;
2770: $lockerrs{$suffix} = $lockerr{$prefix};
2771: next;
2772: }
2773: if ($lockerr{$prefix}) {
2774: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 2775: }
1.489 raeburn 2776: }
2777: }
1.538 raeburn 2778: $title = &LONCAPA::map::qtunescape($title);
2779: my $ext='false';
2780: if ($url=~m{^http(|s)://}) { $ext='true'; }
2781: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2782: if ($folder !~ /^supplemental/) {
2783: (undef,undef,$title) =
2784: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2785: }
2786: } else {
2787: if ($folder=~/^supplemental/) {
2788: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2789: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2790: }
1.533 raeburn 2791: }
1.491 raeburn 2792:
2793: # For uploaded files (excluding pages/sequences) path in copied file is changed
2794: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2795: # courses.
2796:
1.538 raeburn 2797: unless ($is_map{$suffix}) {
2798: my $newidx;
1.492 raeburn 2799: # Now insert the URL at the bottom
1.538 raeburn 2800: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2801: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2802: my $relpath = $1;
2803: if ($relpath ne '') {
2804: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2805: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2806: my $newprefix = $newloc;
2807: if ($newloc eq 'default') {
2808: $newprefix = 'docs';
2809: }
2810: if ($newdocsdir eq '') {
2811: $newdocsdir = 'default';
2812: }
1.630 raeburn 2813: if (($prefixchg{$suffix}) ||
2814: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2815: ($srcnum{$suffix} ne $coursenum) ||
2816: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2817: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2818: $url =
2819: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2820: &Apache::lonnet::getfile($oldurl));
2821: if ($url eq '/adm/notfound.html') {
2822: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2823: next;
2824: } else {
2825: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2826: $newsubpath =~ s{/+$}{/};
2827: $docmoves{$oldurl} = $newsubpath;
2828: }
1.491 raeburn 2829: }
2830: }
1.597 raeburn 2831: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2832: my $template = $1;
2833: if ($newidx) {
2834: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2835: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2836: }
1.649 raeburn 2837: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2838: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2839: my $marker = (split(m{/},$url))[4];
2840: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2841: my $val = 'no';
2842: if ($toolsettings{'gradable'}) {
2843: $val = 'yes';
2844: }
2845: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2846: 'string_yesno');
2847: &remember_parms($newidx,'gradable','set',$val);
2848: }
1.491 raeburn 2849: }
1.538 raeburn 2850: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2851: ':'.$ext.':normal:res';
2852: push(@LONCAPA::map::order,$newidx);
2853: # Store the result
2854: my ($errtext,$fatal) =
2855: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2856: if ($fatal) {
2857: $save_err .= $errtext;
2858: $allresult = 'fail';
2859: }
1.488 raeburn 2860: }
1.538 raeburn 2861:
1.597 raeburn 2862: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2863: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2864: unless ($allresult eq 'fail') {
2865: my %updated = (
2866: rewrites => \%rewrites,
2867: zombies => \%zombies,
2868: removefrommap => \%removefrommap,
2869: removeparam => \%removeparam,
2870: dbcopies => \%dbcopies,
1.597 raeburn 2871: resdatacopy => \%resdatacopy,
1.538 raeburn 2872: retitles => \%retitles,
2873: );
2874: my %info = (
2875: newsubdir => \%newsubdir,
2876: params => \%params,
2877: );
2878: if ($prefixchg{$suffix}) {
2879: $info{'before'} = $before{$prefixchg{$suffix}};
2880: $info{'after'} = $after{$prefixchg{$suffix}};
2881: }
2882: my %moves = (
2883: copies => \%copies,
2884: docmoves => \%docmoves,
2885: mapmoves => \%mapmoves,
2886: );
2887: (my $result,$msgs{$suffix},my $lockerror) =
2888: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2889: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2890: $url,'paste');
2891: $lockerrors .= $lockerror;
2892: if ($result eq 'ok') {
2893: if ($is_map{$suffix}) {
2894: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2895: $folder.'.'.$container);
2896: if ($fatal) {
2897: $allresult = 'failread';
2898: } else {
2899: if ($#LONCAPA::map::order<1) {
2900: my $idx=&LONCAPA::map::getresidx();
2901: if ($idx<=0) { $idx=1; }
2902: $LONCAPA::map::order[0]=$idx;
2903: $LONCAPA::map::resources[$idx]='';
2904: }
2905: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2906: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2907: ':'.$ext.':normal:res';
2908: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2909:
2910: # Store the result
1.538 raeburn 2911: my ($errtext,$fatal) =
2912: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2913: if ($fatal) {
2914: $save_err .= $errtext;
2915: $allresult = 'failstore';
2916: }
2917: }
2918: }
2919: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2920: push(@toclear,$suffix);
2921: }
2922: }
1.492 raeburn 2923: }
2924: }
1.704 raeburn 2925: if (($updatetoolscache) || (@updatetoolsenc)) {
2926: &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
2927: \@updatetoolsenc);
2928: }
1.538 raeburn 2929: &clear_from_buffer(\@toclear,\@currpaste);
2930: my $msgsarray;
2931: foreach my $suffix (keys(%msgs)) {
2932: if (ref($msgs{$suffix}) eq 'ARRAY') {
2933: $msgsarray .= join(',',@{$msgs{$suffix}});
2934: }
2935: }
2936: return ($allresult,$save_err,$msgsarray,$lockerrors);
2937: }
1.533 raeburn 2938:
1.538 raeburn 2939: sub do_buffer_empty {
2940: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2941: if (@currpaste == 0) {
2942: return &mt('Clipboard is already empty');
2943: }
2944: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2945: if (@toclear == 0) {
2946: return &mt('Nothing selected to clear from clipboard');
2947: }
2948: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2949: if ($numdel) {
2950: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2951: } else {
2952: return &mt('Clipboard unchanged');
1.492 raeburn 2953: }
1.538 raeburn 2954: return;
2955: }
2956:
2957: sub clear_from_buffer {
2958: my ($toclear,$currpaste) = @_;
2959: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2960: my %pastebuffer;
2961: map { $pastebuffer{$_} = 1; } @{$currpaste};
2962: my $numdel = 0;
2963: foreach my $suffix (@{$toclear}) {
2964: next if ($suffix =~ /\D/);
2965: next unless (exists($pastebuffer{$suffix}));
2966: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2967: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2968: delete($pastebuffer{$suffix});
2969: $numdel ++;
2970: }
2971: }
2972: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2973: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2974: return $numdel;
1.492 raeburn 2975: }
2976:
1.704 raeburn 2977: sub update_ltitools_caches {
2978: my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
2979: my $hashid=$coursedom.'_'.$coursenum;
2980: if ($updatetoolscache) {
2981: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
2982: }
2983: if ((ref($updatetoolsenc) eq 'ARRAY') &&
2984: (@{$updatetoolsenc})) {
2985: my @ids=&Apache::lonnet::current_machine_ids();
2986: my $updatedone;
2987: foreach my $lonhost (@{$updatetoolsenc}) {
2988: if (grep(/^\Q$lonhost\E$/,@ids)) {
2989: unless ($updatedone) {
2990: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
2991: }
2992: $updatedone = 1;
2993: } else {
2994: &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
2995: }
2996: }
2997: }
2998: return;
2999: }
3000:
1.492 raeburn 3001: sub get_newmap_url {
3002: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
3003: $titleref,$allmaps,$newurls) = @_;
3004: my $newurl;
3005: if ($url=~ m{^/uploaded/}) {
3006: $$titleref=&mt('Copy of').' '.$$titleref;
3007: }
3008: my $now = time;
3009: my $suffix=$$.int(rand(100)).$now;
3010: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
3011: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
3012: my $path = $1;
3013: my $prefix = $2;
3014: my $ancestor = $3;
3015: if (length($ancestor) > 10) {
3016: $ancestor = substr($ancestor,-10,10);
3017: }
3018: my $newid;
3019: if ($prefixchg) {
3020: if ($folder =~ /^supplemental/) {
3021: $prefix =~ s/^default/supplemental/;
3022: } else {
3023: $prefix =~ s/^supplemental/default/;
3024: }
3025: }
3026: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3027: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3028: } else {
3029: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
3030: }
3031: my $counter = 0;
3032: my $is_unique = &uniqueness_check($newurl);
3033: if ($folder =~ /^default/) {
3034: if ($allmaps->{$newurl}) {
3035: $is_unique = 0;
3036: }
3037: }
3038: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
3039: $counter ++;
3040: $suffix ++;
3041: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3042: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3043: } else {
3044: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
3045: }
3046: $is_unique = &uniqueness_check($newurl);
3047: }
3048: if ($is_unique) {
3049: $newurls->{$newurl} = 1;
3050: } else {
3051: if ($url=~/\.page$/) {
3052: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
3053: } else {
3054: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
3055: }
3056: }
1.329 droeschl 3057: }
1.492 raeburn 3058: return ($newurl);
1.329 droeschl 3059: }
3060:
1.488 raeburn 3061: sub dbcopy {
1.704 raeburn 3062: my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
3063: $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.533 raeburn 3064: my ($url,$result,$errtext);
3065: if (ref($dbref) eq 'HASH') {
1.596 raeburn 3066: $url = $dbref->{'src'};
1.627 raeburn 3067: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 3068: my $prefix = $1;
1.627 raeburn 3069: if ($prefix eq 'ext.tool') {
3070: $prefix = 'exttool';
3071: }
1.533 raeburn 3072: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3073: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3074: my $db_name;
3075: my $marker = (split(m{/},$url))[4];
3076: $marker=~s/\D//g;
3077: if ($dbref->{'src'} =~ m{/smppg$}) {
3078: $db_name =
3079: &Apache::lonsimplepage::get_db_name($url,$marker,
3080: $dbref->{'cdom'},
3081: $dbref->{'cnum'});
1.627 raeburn 3082: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
3083: $db_name = 'exttool_'.$marker;
1.533 raeburn 3084: } else {
3085: $db_name = 'bulletinpage_'.$marker;
3086: }
3087: my ($suffix,$freedlock,$error) =
3088: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
3089: $coursedom,$coursenum,
3090: 'concat');
3091: if (!$suffix) {
3092: if ($prefix eq 'smppg') {
3093: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 3094: } elsif ($prefix eq 'exttool') {
3095: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 3096: } else {
1.565 bisitz 3097: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 3098: }
3099: if ($error) {
3100: $errtext .= '<br />'.$error;
3101: }
3102: } else {
3103: #need to copy the db contents to a new one.
3104: my %contents=&Apache::lonnet::dump($db_name,
3105: $dbref->{'cdom'},
3106: $dbref->{'cnum'});
1.704 raeburn 3107: my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
3108: if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
3109: if ($contents{'id'} =~ /^(|c)(\d+)$/) {
3110: $oldtoolid = $2;
3111: if ($1 eq 'c') {
3112: $defincrs = 1;
3113: %toolinfo =
3114: &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
3115: } else {
3116: %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
3117: }
3118: if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
3119: if ($toolinfo{$oldtoolid}{'passback'}) {
3120: $toolpassback = 1;
3121: }
3122: if ($toolinfo{$oldtoolid}{'roster'}) {
3123: $toolroster = 1;
3124: }
3125: } else {
3126: $toolcopyerror = 1;
3127: $errtext = &mt('Could not retrieve original settings for pasted external tool.');
3128: }
3129: }
3130: unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
3131: $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
3132: if ($contents{'crstitle'} ne '') {
3133: $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
3134: }
3135: if (($defincrs) && (!$toolcopyerror)) {
3136: my %newtool;
3137: my $oldcdom = $dbref->{'cdom'};
3138: my $oldcnum = $dbref->{'cnum'};
3139: my $title = $toolinfo{$oldtoolid}{'title'};
3140: if (ref($currltititles) eq 'HASH') {
3141: if (exists($currltititles->{$title})) {
3142: $title .= ' (copied from another course)';
3143: }
3144: }
3145: my ($newid,$iderror) =
3146: &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
3147: if ($newid =~ /^\d+$/) {
3148: %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
3149: $newtool{$newid}{'title'} = $title;
3150: if (ref($currltimax)) {
3151: $newtool{$newid}{'order'} = $$currltimax;
3152: }
3153: if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
3154: my $fname = $1;
3155: my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
3156: if ($content eq '-1') {
3157: delete($newtool{$newid}{'image'});
3158: } else {
3159: $env{'form.'.$suffix.'.image'} = $content;
3160: my $newlogo =
3161: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
3162: delete($env{'form.'.$suffix.'.image'});
3163: if ($newlogo =~ m{^/uploaded/}) {
3164: $newtool{$newid}{'image'} = $newlogo;
3165: } else {
3166: delete($newtool{$newid}{'image'});
3167: }
3168: }
3169: }
3170: my $newusable;
3171: if ($same_institution) {
3172: my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
3173: if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
3174: my %newtoolsenc;
3175: %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
3176: my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
3177: if ($putres eq 'ok') {
3178: if (ref($updatetoolsenc) eq 'ARRAY') {
3179: my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
3180: unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
3181: push(@{$updatetoolsenc},$newhome);
3182: }
3183: }
3184: $newusable = 1;
3185: }
3186: }
3187: }
3188: if ($newtool{$newid}{'usable'}) {
3189: unless ($newusable) {
3190: delete($newtool{$newid}{'usable'});
3191: }
3192: }
3193: my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
3194: if ($putres eq 'ok') {
3195: $contents{'id'} = "c$newid";
3196: if (ref($updatetoolscache)) {
3197: $$updatetoolscache ++;
3198: }
3199: if (ref($currltititles->{$title}) eq 'ARRAY') {
3200: push(@{$currltititles->{$title}},$newid);
3201: } else {
3202: $currltititles->{$title} = [$newid];
3203: }
3204: if (ref($currltimax)) {
3205: $$currltimax ++;
3206: }
3207: } else {
3208: $toolcopyerror = 1;
3209: $errtext = &mt('Unable to save external tool definition in Course Settings.');
3210: }
3211: } else {
3212: $toolcopyerror = 1;
3213: $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
3214: }
3215: }
3216: }
3217: }
1.533 raeburn 3218: if (exists($contents{'uploaded.photourl'})) {
3219: my $photo = $contents{'uploaded.photourl'};
3220: my ($subdir,$fname) =
3221: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 3222: my $newphoto;
1.533 raeburn 3223: if ($fname ne '') {
3224: my $content = &Apache::lonnet::getfile($photo);
3225: unless ($content eq '-1') {
3226: $env{'form.'.$suffix.'.photourl'} = $content;
3227: $newphoto =
3228: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
3229: delete($env{'form.'.$suffix.'.photourl'});
3230: }
3231: }
3232: if ($newphoto =~ m{^/uploaded/}) {
3233: $contents{'uploaded.photourl'} = $newphoto;
3234: }
3235: }
3236: $db_name =~ s{_\d*$ }{_$suffix}x;
1.704 raeburn 3237: if ($prefix eq 'exttool') {
3238: unless ($toolcopyerror) {
3239: foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
3240: if (exists($contents{$key})) {
3241: delete($contents{$key});
3242: }
3243: }
3244: if ($dbref->{'delgradable'}) {
3245: if (exists($contents{'gradable'})) {
3246: delete($contents{'gradable'});
3247: }
3248: }
3249: if ($toolpassback) {
3250: if ($contents{'gradable'}) {
3251: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3252: $contents{'gradesecret'} = $gradesecret;
3253: $contents{'gradesecretdate'} = time;
3254: }
3255: }
3256: if ($toolroster) {
3257: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3258: $contents{'rostersecret'} = $rostersecret;
3259: $contents{'rostersecretdate'} = time;
3260: }
3261: }
1.649 raeburn 3262: }
1.704 raeburn 3263: if (($prefix eq 'exttool') && ($toolcopyerror)) {
3264: $result = 'error';
3265: } else {
3266: $result=&Apache::lonnet::put($db_name,\%contents,
3267: $coursedom,$coursenum);
3268: if ($result eq 'ok') {
3269: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
3270: }
1.533 raeburn 3271: }
3272: }
3273: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 3274: $lockerrorsref->{$prefix} =
1.533 raeburn 3275: '<div class="LC_error">'.
3276: &mt('There was a problem removing a lockfile.');
3277: if ($prefix eq 'smppg') {
1.560 raeburn 3278: $lockerrorsref->{$prefix} .=
1.559 raeburn 3279: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 3280: } elsif ($prefix eq 'exttool') {
3281: $lockerrorsref->{$prefix} .=
3282: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 3283: } else {
1.565 bisitz 3284: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 3285: }
1.560 raeburn 3286: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
3287: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
3288: '</div>';
1.533 raeburn 3289: }
3290: }
3291: } elsif ($url =~ m{/syllabus$}) {
3292: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3293: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3294: if (($dbref->{'cdom'} ne $coursedom) ||
3295: ($dbref->{'cnum'} ne $coursenum)) {
3296: my %contents=&Apache::lonnet::dump('syllabus',
3297: $dbref->{'cdom'},
3298: $dbref->{'cnum'});
3299: $result=&Apache::lonnet::put('syllabus',\%contents,
3300: $coursedom,$coursenum);
3301: }
3302: }
1.488 raeburn 3303: }
3304: }
1.533 raeburn 3305: return ($url,$result,$errtext);
1.488 raeburn 3306: }
3307:
1.597 raeburn 3308: sub copy_templated_files {
3309: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
3310: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
3311: my $srccontainer = 'sequence';
3312: if ($srcwaspage) {
3313: $srccontainer = 'page';
3314: }
3315: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
3316: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
3317: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
3318: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
3319: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
3320: $template.'.problem';
3321: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
3322: if ($template eq 'simpleproblem') {
3323: $srcprefix .= '.0.';
3324: my $weightprefix = $newprefix;
3325: $newprefix .= '.0.';
3326: my @simpleprobqtypes = qw(radio option string essay numerical);
3327: my $qtype=$srcparms{$srcprefix.'questiontype'};
3328: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 3329: my %newdata = (
3330: $newprefix.'questiontype' => $qtype,
3331: );
1.597 raeburn 3332: foreach my $type (@simpleprobqtypes) {
3333: if ($type eq $qtype) {
3334: $newdata{"$weightprefix.$type.weight"}=1;
3335: } else {
3336: $newdata{"$weightprefix.$type.weight"}=0;
3337: }
3338: }
3339: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
3340: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
3341: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
3342: if ($qtype eq 'numerical') {
3343: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
3344: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
3345: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
3346: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
3347: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3348: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3349: unless (defined($maxfoils)) { $maxfoils=10; }
3350: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3351: if ($maxfoils<=0) { $maxfoils=10; }
3352: my $randomize=$srcparms{$srcprefix.'randomize'};
3353: unless (defined($randomize)) { $randomize='yes'; }
3354: unless ($randomize eq 'no') { $randomize='yes'; }
3355: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3356: $newdata{$newprefix.'randomize'} = $randomize;
3357: if ($qtype eq 'option') {
3358: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3359: }
3360: for (my $i=1; $i<=10; $i++) {
3361: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3362: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3363: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3364: }
3365:
3366: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3367: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3368: unless (defined($maxfoils)) { $maxfoils=10; }
3369: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3370: if ($maxfoils<=0) { $maxfoils=10; }
3371: my $randomize=$srcparms{$srcprefix.'randomize'};
3372: unless (defined($randomize)) { $randomize='yes'; }
3373: unless ($randomize eq 'no') { $randomize='yes'; }
3374: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3375: $newdata{$newprefix.'randomize'} = $randomize;
3376: if ($qtype eq 'option') {
3377: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3378: }
3379: for (my $i=1; $i<=10; $i++) {
3380: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3381: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3382: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3383: }
3384: } elsif ($qtype eq 'string') {
3385: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
3386: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
3387: }
3388: if (keys(%newdata)) {
3389: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
3390: $coursenum);
3391: if ($putres eq 'ok') {
3392: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
3393: }
3394: }
3395: }
3396: }
3397: }
3398:
1.329 droeschl 3399: sub uniqueness_check {
3400: my ($newurl) = @_;
3401: my $unique = 1;
3402: foreach my $res (@LONCAPA::map::order) {
3403: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3404: $url=&LONCAPA::map::qtescape($url);
3405: if ($newurl eq $url) {
3406: $unique = 0;
1.344 bisitz 3407: last;
1.329 droeschl 3408: }
3409: }
3410: return $unique;
3411: }
3412:
1.488 raeburn 3413: sub contained_map_check {
1.627 raeburn 3414: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
3415: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 3416: my $content = &Apache::lonnet::getfile($url);
3417: unless ($content eq '-1') {
3418: my $parser = HTML::TokeParser->new(\$content);
3419: $parser->attr_encoded(1);
3420: while (my $token = $parser->get_token) {
3421: next if ($token->[0] ne 'S');
3422: if ($token->[1] eq 'resource') {
3423: next if ($token->[2]->{'type'} eq 'zombie');
3424: my $ressrc = $token->[2]->{'src'};
1.704 raeburn 3425: if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
3426: my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
1.627 raeburn 3427: unless ($srcdom eq $coursedom) {
3428: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3429: next;
3430: }
1.704 raeburn 3431: unless ($srcnum eq $coursenum) {
3432: my %toolsettings =
3433: &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
3434: my %tooltypes = &Apache::loncommon::usable_exttools();
3435: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
3436: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
3437: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3438: next;
3439: }
3440: }
1.627 raeburn 3441: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 3442: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 3443: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 3444: next;
3445: }
3446: }
1.703 raeburn 3447: if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
3448: my ($srcdom,$srcnum) = ($1,$2);
3449: unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
3450: if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
3451: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3452: next;
3453: }
3454: }
3455: }
1.492 raeburn 3456: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
3457: if ($1 eq 'uploaded') {
3458: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
3459: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 3460: } else {
1.492 raeburn 3461: if ($allmaps->{$ressrc}) {
1.529 raeburn 3462: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 3463: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
3464: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3465: } else {
3466: $addedmaps->{$ressrc} = [$url];
3467: }
1.488 raeburn 3468: }
1.627 raeburn 3469: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
3470: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 3471: }
1.492 raeburn 3472: } elsif ($token->[1] eq 'param') {
1.488 raeburn 3473: if ($folder =~ /^supplemental/) {
1.492 raeburn 3474: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
3475: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
3476: } else {
3477: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
3478: }
1.488 raeburn 3479: }
3480: }
3481: }
3482: }
3483: return;
3484: }
3485:
3486: sub url_paste_fixups {
1.533 raeburn 3487: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
3488: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 3489: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 3490: my $checktitle;
3491: if (($prefixchg) &&
1.492 raeburn 3492: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 3493: $checktitle = 1;
3494: }
1.492 raeburn 3495: my $skip;
3496: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
3497: my $mapid = $1.$2;
3498: if ($tomove->{$mapid}) {
3499: $skip = 1;
3500: }
3501: }
1.491 raeburn 3502: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 3503: return if ($file eq '-1');
3504: my $parser = HTML::TokeParser->new(\$file);
3505: $parser->attr_encoded(1);
1.491 raeburn 3506: my $changed = 0;
1.488 raeburn 3507: while (my $token = $parser->get_token) {
3508: next if ($token->[0] ne 'S');
3509: if ($token->[1] eq 'resource') {
3510: my $ressrc = $token->[2]->{'src'};
3511: next if ($ressrc eq '');
1.491 raeburn 3512: my $id = $token->[2]->{'id'};
1.492 raeburn 3513: my $title = $token->[2]->{'title'};
1.491 raeburn 3514: if ($checktitle) {
3515: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 3516: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3517: }
3518: }
1.488 raeburn 3519: next if ($token->[2]->{'type'} eq 'external');
3520: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 3521: next if ($skip);
1.532 raeburn 3522: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3523: $changed = 1;
3524: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3525: my $srcdom = $1;
3526: my $srcnum = $2;
1.488 raeburn 3527: my $rem = $3;
1.492 raeburn 3528: my $newurl;
3529: my $mapname;
3530: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
3531: my $prefix = $1;
3532: $mapname = $prefix.$2;
3533: if ($tomove->{$mapname}) {
1.533 raeburn 3534: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
3535: $srcdom,$srcnum,$allmaps,$rewrites,
3536: $retitles,$copies,$dbcopies,$zombies,
3537: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 3538: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 3539: next;
3540: } else {
3541: ($newurl,my $error) =
3542: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
3543: $srcdom,$srcnum,\$title,$allmaps,$newurls);
3544: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
3545: $newsubdir->{$ressrc} = $1;
3546: }
3547: if ($error) {
3548: next;
3549: }
3550: }
3551: }
3552: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
3553: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
3554:
1.488 raeburn 3555: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 3556: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3557: $mapchanges->{$ressrc} = 1;
1.533 raeburn 3558: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
3559: $cnum,$srcdom,$srcnum,$allmaps,
3560: $rewrites,$retitles,$copies,$dbcopies,
3561: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 3562: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 3563: $mapmoves->{$ressrc} = 1;
3564: }
3565: $changed = 1;
1.488 raeburn 3566: } else {
1.532 raeburn 3567: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 3568: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 3569: $changed = 1;
1.488 raeburn 3570: }
3571: }
1.649 raeburn 3572: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 3573: next if ($skip);
1.492 raeburn 3574: my $srcdom = $1;
3575: my $srcnum = $2;
1.649 raeburn 3576: my $rem = $3;
3577: my ($is_exttool,$exttoolchg);
3578: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 3579: $is_exttool = 1;
1.649 raeburn 3580: }
1.492 raeburn 3581: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 3582: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 3583: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3584: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3585: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3586: $changed = 1;
1.649 raeburn 3587: if ($is_exttool) {
3588: $exttoolchg = 1;
3589: }
1.700 raeburn 3590: } elsif (($is_exttool) &&
1.649 raeburn 3591: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3592: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3593: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3594: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3595: $changed = 1;
3596: $exttoolchg = 1;
3597: }
3598: if (($is_exttool) && ($prefixchg)) {
3599: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
3600: if ($exttoolchg) {
3601: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
3602: }
3603: }
1.533 raeburn 3604: }
3605: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
3606: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
3607: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3608: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3609: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
3610: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 3611: $changed = 1;
1.488 raeburn 3612: }
1.597 raeburn 3613: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
3614: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
3615: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
3616: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
3617: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
3618: }
1.488 raeburn 3619: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3620: next if ($skip);
3621: my $srcdom = $1;
3622: my $srcnum = $2;
3623: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 3624: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3625: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3626: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 3627: $changed = 1;
1.488 raeburn 3628: }
3629: }
3630: } elsif ($token->[1] eq 'param') {
1.492 raeburn 3631: next if ($skip);
1.488 raeburn 3632: my $to = $token->[2]->{'to'};
3633: if ($to ne '') {
3634: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 3635: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 3636: } else {
3637: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
3638: }
3639: }
3640: }
3641: }
1.491 raeburn 3642: return $changed;
1.488 raeburn 3643: }
3644:
3645: sub apply_fixups {
1.529 raeburn 3646: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
3647: $oldurl,$url,$caller) = @_;
3648: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 3649: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.704 raeburn 3650: %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
3651: %currltititles,$currltimax);
3652: $currltimax = 0;
1.529 raeburn 3653: if (ref($updated) eq 'HASH') {
3654: if (ref($updated->{'rewrites'}) eq 'HASH') {
3655: %rewrites = %{$updated->{'rewrites'}};
3656: }
3657: if (ref($updated->{'zombies'}) eq 'HASH') {
3658: %zombies = %{$updated->{'zombies'}};
3659: }
3660: if (ref($updated->{'removefrommap'}) eq 'HASH') {
3661: %removefrommap = %{$updated->{'removefrommap'}};
3662: }
3663: if (ref($updated->{'removeparam'}) eq 'HASH') {
3664: %removeparam = %{$updated->{'removeparam'}};
3665: }
3666: if (ref($updated->{'dbcopies'}) eq 'HASH') {
3667: %dbcopies = %{$updated->{'dbcopies'}};
3668: }
3669: if (ref($updated->{'retitles'}) eq 'HASH') {
3670: %retitles = %{$updated->{'retitles'}};
3671: }
1.597 raeburn 3672: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
3673: %resdatacopy = %{$updated->{'resdatacopy'}};
3674: }
1.529 raeburn 3675: }
3676: if (ref($info) eq 'HASH') {
3677: if (ref($info->{'newsubdir'}) eq 'HASH') {
3678: %newsubdir = %{$info->{'newsubdir'}};
3679: }
3680: if (ref($info->{'params'}) eq 'HASH') {
3681: %params = %{$info->{'params'}};
3682: }
3683: if (ref($info->{'before'}) eq 'HASH') {
3684: %before = %{$info->{'before'}};
3685: }
3686: if (ref($info->{'after'}) eq 'HASH') {
3687: %after = %{$info->{'after'}};
3688: }
3689: }
3690: if (ref($moves) eq 'HASH') {
3691: if (ref($moves->{'copies'}) eq 'HASH') {
3692: %copies = %{$moves->{'copies'}};
3693: }
3694: if (ref($moves->{'docmoves'}) eq 'HASH') {
3695: %docmoves = %{$moves->{'docmoves'}};
3696: }
3697: if (ref($moves->{'mapmoves'}) eq 'HASH') {
3698: %mapmoves = %{$moves->{'mapmoves'}};
3699: }
3700: }
3701: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 3702: my @allcopies;
1.529 raeburn 3703: if (exists($copies{$key})) {
3704: if (ref($copies{$key}) eq 'HASH') {
3705: my %added;
3706: foreach my $innerkey (keys(%{$copies{$key}})) {
3707: if (($innerkey ne '') && (!$added{$innerkey})) {
3708: push(@allcopies,$innerkey);
3709: $added{$innerkey} = 1;
3710: }
1.491 raeburn 3711: }
1.529 raeburn 3712: undef(%added);
1.491 raeburn 3713: }
3714: }
3715: if ($key eq $oldurl) {
1.529 raeburn 3716: if ((exists($docmoves{$key}))) {
1.532 raeburn 3717: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 3718: push(@allcopies,$oldurl);
3719: }
3720: }
3721: }
3722: if (@allcopies > 0) {
3723: foreach my $item (@allcopies) {
1.492 raeburn 3724: my ($relpath,$oldsubdir,$fname) =
3725: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 3726: if ($fname ne '') {
3727: my $content = &Apache::lonnet::getfile($item);
3728: unless ($content eq '-1') {
3729: my $storefn;
1.529 raeburn 3730: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
3731: $storefn = $docmoves{$key};
1.491 raeburn 3732: } else {
3733: $storefn = $relpath;
3734: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3735: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
3736: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 3737: }
1.529 raeburn 3738: if ($newsubdir{$key}) {
1.532 raeburn 3739: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 3740: }
3741: }
3742: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
3743: my $copyurl =
3744: &Apache::lonclonecourse::writefile($env{'request.course.id'},
3745: $storefn.$fname,$content);
3746: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 3747: if (exists($docmoves{$oldurl})) {
1.491 raeburn 3748: return &mt('Paste failed: an error occurred copying the file.');
3749: } elsif (ref($errors) eq 'HASH') {
3750: $errors->{$item} = 1;
1.489 raeburn 3751: }
3752: }
1.488 raeburn 3753: }
3754: }
1.491 raeburn 3755: }
3756: }
3757: }
1.529 raeburn 3758: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 3759: my $storefn=$key;
3760: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3761: if ($prefixchg && $before{'map'} && $after{'map'}) {
3762: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3763: }
1.529 raeburn 3764: if ($newsubdir{$key}) {
3765: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3766: }
1.491 raeburn 3767: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 3768: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
3769: ($after{'map'} eq 'default') &&
3770: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
3771: $mapcontent = '<map>'."\n".
3772: '<resource id="1" src="" type="start" />'."\n".
3773: '<link from="1" to="2" index="1" />'."\n".
3774: '<resource id="2" src="" type="finish" />'."\n".
3775: '</map>';
3776: }
1.491 raeburn 3777: if ($mapcontent eq '-1') {
3778: if (ref($errors) eq 'HASH') {
3779: $errors->{$key} = 1;
3780: }
3781: } else {
3782: my $newmap =
3783: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
3784: $mapcontent);
3785: if ($newmap eq '/adm/notfound.html') {
3786: if (ref($errors) eq 'HASH') {
3787: $errors->{$key} = 1;
1.489 raeburn 3788: }
1.488 raeburn 3789: }
3790: }
3791: }
1.491 raeburn 3792: my %updates;
3793: if ($is_map) {
1.529 raeburn 3794: if (ref($updated) eq 'HASH') {
3795: foreach my $type (keys(%{$updated})) {
3796: if (ref($updated->{$type}) eq 'HASH') {
3797: foreach my $key (keys(%{$updated->{$type}})) {
3798: $updates{$key} = 1;
3799: }
3800: }
3801: }
1.491 raeburn 3802: }
1.704 raeburn 3803: my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.491 raeburn 3804: foreach my $key (keys(%updates)) {
1.492 raeburn 3805: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 3806: if (ref($rewrites{$key}) eq 'HASH') {
3807: %torewrite = %{$rewrites{$key}};
1.491 raeburn 3808: }
1.529 raeburn 3809: if (ref($retitles{$key}) eq 'HASH') {
3810: %toretitle = %{$retitles{$key}};
1.491 raeburn 3811: }
1.529 raeburn 3812: if (ref($removefrommap{$key}) eq 'HASH') {
3813: %toremove = %{$removefrommap{$key}};
1.491 raeburn 3814: }
1.529 raeburn 3815: if (ref($removeparam{$key}) eq 'HASH') {
3816: %remparam = %{$removeparam{$key}};
1.492 raeburn 3817: }
1.529 raeburn 3818: if (ref($zombies{$key}) eq 'HASH') {
3819: %zombie = %{$zombies{$key}};
1.491 raeburn 3820: }
1.529 raeburn 3821: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 3822: foreach my $idx (keys(%{$dbcopies{$key}})) {
3823: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.704 raeburn 3824: my $oldurl = $dbcopies{$key}{$idx}{'src'};
3825: my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
3826: my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
3827: my $oldmarker;
3828: if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
3829: $oldmarker = $1;
3830: unless (($gotcrsltitools) ||
3831: (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
3832: my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
3833: if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
3834: unless ($gotcrsltitools) {
3835: %currcrsltitools =
3836: &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
3837: foreach my $item (sort(keys(%currcrsltitools))) {
3838: if (ref($currcrsltitools{$item}) eq 'HASH') {
3839: $currltimax ++;
3840: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
3841: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
3842: } else {
3843: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
3844: }
3845: }
3846: }
3847: $gotcrsltitools = 1;
3848: }
3849: unless ($checkedsameinst) {
3850: my $primary_id = &Apache::lonnet::domain($cdom,'primary');
3851: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3852: if ($intdom ne '') {
3853: my $internet_names =
3854: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
3855: if (ref($internet_names) eq 'ARRAY') {
3856: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
3857: $same_institution = 1;
3858: }
3859: }
3860: }
3861: $checkedsameinst = 1;
3862: }
3863: }
3864: }
3865: }
1.533 raeburn 3866: my ($newurl,$result,$errtext) =
1.704 raeburn 3867: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
3868: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.533 raeburn 3869: if ($result eq 'ok') {
3870: $newdb{$idx} = $newurl;
1.704 raeburn 3871: if ($newurl =~ /ext\.tool$/) {
3872: if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
3873: if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
3874: my $newmarker = $1;
3875: unless ($oldmarker eq $newmarker) {
3876: $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
3877: }
3878: }
3879: }
3880: }
1.533 raeburn 3881: } elsif (ref($errors) eq 'HASH') {
3882: $errors->{$key} = 1;
3883: }
3884: push(@msgs,$errtext);
3885: }
1.491 raeburn 3886: }
3887: }
1.597 raeburn 3888: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 3889: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 3890: foreach my $idx (keys(%{$resdatacopy{$key}})) {
3891: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
3892: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
3893: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
3894: my $template = $1;
3895: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
3896: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
3897: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
3898: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 3899: unless ($gotnewmapname) {
3900: ($newmapname) = ($key =~ m{/([^/]+)$});
3901: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
3902: if ($newsubdir{$key}) {
3903: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
3904: }
3905: $gotnewmapname = 1;
3906: }
1.597 raeburn 3907: my $srcmapinfo = $srcfolder.':'.$idx;
3908: if ($srccontainer eq 'page') {
3909: $srcmapinfo .= ':1';
3910: }
3911: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
3912: $cnum,$template,$idx,$newmapname);
3913: }
3914: }
3915: }
3916: }
3917: }
1.529 raeburn 3918: if (ref($params{$key}) eq 'HASH') {
3919: %currparam = %{$params{$key}};
1.492 raeburn 3920: }
3921: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
3922: if ($fatal) {
1.533 raeburn 3923: return ($errtext);
1.492 raeburn 3924: }
3925: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
3926: if (defined($LONCAPA::map::zombies[$i])) {
3927: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 3928: if ($zombie{$i} eq $src) {
1.492 raeburn 3929: undef($LONCAPA::map::zombies[$i]);
3930: }
3931: }
3932: }
1.646 raeburn 3933: my $total = scalar(@LONCAPA::map::order) - 1;
3934: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 3935: my $idx = $LONCAPA::map::order[$i];
3936: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 3937: my $changed;
1.529 raeburn 3938: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 3939: if ((exists($toremove{$idx})) &&
3940: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 3941: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 3942: if (ref($currparam{$idx}) eq 'ARRAY') {
3943: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 3944: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 3945: }
3946: }
3947: next;
3948: }
3949: my $origsrc = $src;
1.532 raeburn 3950: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 3951: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
3952: $changed = 1;
1.491 raeburn 3953: }
1.492 raeburn 3954: }
1.532 raeburn 3955: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 3956: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
3957: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 3958: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 3959: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 3960: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 3961: } else {
1.529 raeburn 3962: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 3963: }
1.491 raeburn 3964: }
1.532 raeburn 3965: if ($origsrc =~ /\.(page|sequence)$/) {
3966: if ($newsubdir{$origsrc}) {
1.529 raeburn 3967: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 3968: }
1.532 raeburn 3969: } elsif ($newsubdir{$key}) {
3970: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 3971: }
3972: }
1.492 raeburn 3973: $changed = 1;
1.533 raeburn 3974: } elsif ($newdb{$idx} ne '') {
3975: $src = $newdb{$idx};
1.492 raeburn 3976: $changed = 1;
3977: }
3978: if ($changed) {
1.538 raeburn 3979: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 3980: }
3981: }
3982: }
3983: foreach my $idx (keys(%remparam)) {
3984: if (ref($remparam{$idx}) eq 'ARRAY') {
3985: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 3986: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 3987: }
3988: }
3989: }
1.533 raeburn 3990: if (values(%lockerrors) > 0) {
3991: $lockmsg = join('<br />',values(%lockerrors));
3992: }
1.491 raeburn 3993: my $storefn;
3994: if ($key eq $oldurl) {
3995: $storefn = $url;
3996: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3997: } else {
3998: $storefn = $key;
3999: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 4000: if ($prefixchg && $before{'map'} && $after{'map'}) {
4001: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 4002: }
1.529 raeburn 4003: if ($newsubdir{$key}) {
4004: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 4005: }
1.491 raeburn 4006: }
1.492 raeburn 4007: my $report;
4008: if ($folder !~ /^supplemental/) {
4009: $report = 1;
4010: }
1.527 raeburn 4011: (my $outtext,$errtext) =
1.492 raeburn 4012: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
4013: if ($errtext) {
1.529 raeburn 4014: if ($caller eq 'paste') {
1.533 raeburn 4015: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 4016: }
1.491 raeburn 4017: }
4018: }
1.704 raeburn 4019: if (($updatetoolscache) || (@updatetoolsenc)) {
4020: &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
4021: \@updatetoolsenc);
4022: }
1.491 raeburn 4023: }
1.533 raeburn 4024: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 4025: }
4026:
4027: sub copy_dependencies {
4028: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
4029: my $content;
4030: if (ref($contentref)) {
4031: $content = $$contentref;
4032: } else {
4033: $content = &Apache::lonnet::getfile($item);
4034: }
4035: unless ($content eq '-1') {
4036: my $mm = new File::MMagic;
4037: my $mimetype = $mm->checktype_contents($content);
4038: if ($mimetype eq 'text/html') {
4039: my (%allfiles,%codebase,$state);
4040: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
4041: if ($res eq 'ok') {
4042: my ($numexisting,$numpathchanges,$existing);
4043: (undef,$numexisting,$numpathchanges,$existing) =
4044: &Apache::loncommon::ask_for_embedded_content(
4045: '/adm/coursedocs',$state,\%allfiles,\%codebase,
4046: {'error_on_invalid_names' => 1,
4047: 'ignore_remote_references' => 1,
4048: 'docs_url' => $item,
4049: 'context' => 'paste'});
4050: if ($numexisting > 0) {
4051: if (ref($existing) eq 'HASH') {
4052: foreach my $dep (keys(%{$existing})) {
4053: my $depfile = $dep;
4054: unless ($depfile =~ m{^\Q$relpath\E}) {
4055: $depfile = $relpath.$dep;
4056: }
4057: my $depcontent = &Apache::lonnet::getfile($depfile);
4058: unless ($depcontent eq '-1') {
4059: my $storedep = $dep;
4060: $storedep =~ s{^\Q$relpath\E}{};
4061: my $dep_url =
4062: &Apache::lonclonecourse::writefile(
4063: $env{'request.course.id'},
4064: $storefn.$storedep,$depcontent);
4065: if ($dep_url eq '/adm/notfound.html') {
4066: if (ref($errors) eq 'HASH') {
4067: $errors->{$depfile} = 1;
4068: }
4069: } else {
4070: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
4071: }
4072: }
4073: }
1.488 raeburn 4074: }
4075: }
4076: }
4077: }
4078: }
4079: return;
4080: }
4081:
1.329 droeschl 4082: my %parameter_type = ( 'randompick' => 'int_pos',
4083: 'hiddenresource' => 'string_yesno',
4084: 'encrypturl' => 'string_yesno',
4085: 'randomorder' => 'string_yesno',);
4086: my $valid_parameters_re = join('|',keys(%parameter_type));
4087: # set parameters
4088: sub update_parameter {
1.537 raeburn 4089: if ($env{'form.changeparms'} eq 'all') {
4090: my (@allidx,@allmapidx,%allchecked,%currchecked);
4091: %allchecked = (
4092: 'hiddenresource' => {},
4093: 'encrypturl' => {},
4094: 'randompick' => {},
4095: 'randomorder' => {},
4096: );
4097: foreach my $which (keys(%allchecked)) {
1.630 raeburn 4098: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 4099: if ($which eq 'randompick') {
4100: foreach my $item (split(/,/,$env{'form.all'.$which})) {
4101: my ($res,$value) = split(/:/,$item);
4102: if ($value =~ /^\d+$/) {
4103: $allchecked{$which}{$res} = $value;
4104: }
4105: }
4106: } else {
1.539 raeburn 4107: if ($env{'form.all'.$which}) {
4108: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
4109: }
1.537 raeburn 4110: }
4111: }
4112: my $haschanges = 0;
4113: foreach my $res (@LONCAPA::map::order) {
4114: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4115: $name=&LONCAPA::map::qtescape($name);
4116: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 4117: next unless $url;
1.537 raeburn 4118: my $is_map;
4119: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4120: $is_map = 1;
4121: }
4122: foreach my $which (keys(%allchecked)) {
4123: if (($which eq 'randompick' || $which eq 'randomorder')) {
4124: next if (!$is_map);
4125: }
4126: my $oldvalue = 0;
4127: my $newvalue = 0;
4128: if ($allchecked{$which}{$res}) {
4129: $newvalue = $allchecked{$which}{$res};
4130: }
4131: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
4132: if ($which eq 'randompick') {
4133: if ($current =~ /^(\d+)$/) {
4134: $oldvalue = $1;
4135: }
4136: } else {
4137: if ($current =~ /^yes$/i) {
4138: $oldvalue = 1;
4139: }
4140: }
4141: if ($oldvalue ne $newvalue) {
4142: $haschanges = 1;
4143: if ($newvalue) {
4144: my $storeval = 'yes';
4145: if ($which eq 'randompick') {
4146: $storeval = $newvalue;
4147: }
4148: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
4149: $storeval,
4150: $parameter_type{$which});
4151: &remember_parms($res,$which,'set',$storeval);
4152: } elsif ($oldvalue) {
4153: &LONCAPA::map::delparameter($res,'parameter_'.$which);
4154: &remember_parms($res,$which,'del');
4155: }
4156: }
4157: }
4158: }
4159: return $haschanges;
4160: } else {
1.588 raeburn 4161: my $haschanges = 0;
4162: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 4163:
1.537 raeburn 4164: my $which = $env{'form.changeparms'};
4165: my $idx = $env{'form.setparms'};
1.588 raeburn 4166: my $oldvalue = 0;
4167: my $newvalue = 0;
4168: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
4169: if ($which eq 'randompick') {
4170: if ($current =~ /^(\d+)$/) {
4171: $oldvalue = $1;
4172: }
4173: } elsif ($current =~ /^yes$/i) {
4174: $oldvalue = 1;
4175: }
1.537 raeburn 4176: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 4177: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
4178: : 1;
4179: }
4180: if ($oldvalue ne $newvalue) {
4181: $haschanges = 1;
4182: if ($newvalue) {
4183: my $storeval = 'yes';
4184: if ($which eq 'randompick') {
4185: $storeval = $newvalue;
4186: }
4187: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
4188: $parameter_type{$which});
4189: &remember_parms($idx,$which,'set',$storeval);
4190: } else {
4191: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
4192: &remember_parms($idx,$which,'del');
4193: }
1.537 raeburn 4194: }
1.588 raeburn 4195: return $haschanges;
1.329 droeschl 4196: }
4197: }
4198:
4199: sub handle_edit_cmd {
4200: my ($coursenum,$coursedom) =@_;
1.633 raeburn 4201: my $haschanges = 0;
1.543 raeburn 4202: if ($env{'form.cmd'} eq '') {
1.633 raeburn 4203: return $haschanges;
1.543 raeburn 4204: }
1.329 droeschl 4205: my ($cmd,$idx)=split('_',$env{'form.cmd'});
4206:
4207: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
4208: my ($title, $url, @rrest) = split(':', $ratstr);
4209:
1.538 raeburn 4210: if ($cmd eq 'remove') {
1.329 droeschl 4211: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 4212: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 4213: &Apache::lonnet::removeuploadedurl($url);
4214: } else {
4215: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4216: }
4217: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4218: $haschanges = 1;
1.329 droeschl 4219: } elsif ($cmd eq 'cut') {
4220: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4221: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4222: $haschanges = 1;
1.344 bisitz 4223: } elsif ($cmd eq 'up'
1.329 droeschl 4224: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
4225: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 4226: $haschanges = 1;
1.329 droeschl 4227: } elsif ($cmd eq 'down'
4228: && defined($LONCAPA::map::order[$idx+1])) {
4229: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 4230: $haschanges = 1;
1.329 droeschl 4231: } elsif ($cmd eq 'rename') {
4232: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
4233: if ($comment=~/\S/) {
4234: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
4235: $comment.':'.join(':', $url, @rrest);
4236: }
4237: # Devalidate title cache
4238: my $renamed_url=&LONCAPA::map::qtescape($url);
4239: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 4240: $haschanges = 1;
4241: } elsif ($cmd eq 'setalias') {
4242: my $newvalue = $env{'form.alias'};
4243: if ($newvalue ne '') {
4244: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
4245: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
4246: 'string');
4247: &remember_parms($idx,'mapalias','set',$newvalue);
4248: $haschanges = 1;
4249: }
4250: }
4251: } elsif ($cmd eq 'delalias') {
4252: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
4253: if ($current ne '') {
4254: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
4255: &remember_parms($idx,'mapalias','del');
4256: $haschanges = 1;
4257: }
1.329 droeschl 4258: }
1.633 raeburn 4259: return $haschanges;
1.329 droeschl 4260: }
4261:
4262: sub editor {
1.458 raeburn 4263: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 4264: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 4265: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 4266: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 4267: if ($allowed) {
1.519 raeburn 4268: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
4269: $is_random_order,$container) =
1.510 raeburn 4270: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
4271: $r->print($breadcrumbtrail);
1.519 raeburn 4272: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
4273: $container = 'page';
4274: } else {
4275: $container = 'sequence';
1.510 raeburn 4276: }
1.484 raeburn 4277:
1.525 raeburn 4278: my $jumpto;
4279:
4280: unless ($supplementalflag) {
1.546 raeburn 4281: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 4282: }
1.484 raeburn 4283:
4284: unless ($allowed) {
4285: $randompick = -1;
4286: }
4287:
1.615 raeburn 4288: my ($errtext,$fatal);
4289: if (($folder eq '') && (!$supplementalflag)) {
4290: if (@LONCAPA::map::order) {
4291: undef(@LONCAPA::map::order);
4292: undef(@LONCAPA::map::resources);
4293: undef(@LONCAPA::map::resparms);
4294: undef(@LONCAPA::map::zombies);
4295: }
4296: $folder = 'default';
4297: $container = 'sequence';
4298: } else {
4299: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
4300: $folder.'.'.$container);
4301: return $errtext if ($fatal);
4302: }
1.329 droeschl 4303:
4304: if ($#LONCAPA::map::order<1) {
4305: my $idx=&LONCAPA::map::getresidx();
4306: if ($idx<=0) { $idx=1; }
4307: $LONCAPA::map::order[0]=$idx;
4308: $LONCAPA::map::resources[$idx]='';
4309: }
1.364 bisitz 4310:
1.329 droeschl 4311: # ------------------------------------------------------------ Process commands
4312:
4313: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 4314: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 4315: # set parameters and change order
4316: &snapshotbefore();
4317:
4318: if (&update_parameter()) {
1.588 raeburn 4319: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 4320: return $errtext if ($fatal);
4321: }
4322:
4323: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
4324: # change order
4325: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
4326: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
4327:
4328: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
4329: return $errtext if ($fatal);
4330: }
1.364 bisitz 4331:
1.329 droeschl 4332: if ($env{'form.pastemarked'}) {
1.491 raeburn 4333: my %paste_errors;
1.533 raeburn 4334: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 4335: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
4336: \%paste_errors);
1.541 raeburn 4337: if (ref($pastemsgarray) eq 'ARRAY') {
4338: if (@{$pastemsgarray} > 0) {
4339: $r->print('<p class="LC_info">'.
4340: join('<br />',@{$pastemsgarray}).
1.533 raeburn 4341: '</p>');
4342: }
1.541 raeburn 4343: }
4344: if ($lockerror) {
4345: $r->print('<p class="LC_error">'.
4346: $lockerror.
4347: '</p>');
4348: }
4349: if ($save_error ne '') {
4350: return $save_error;
4351: }
4352: if ($paste_res) {
4353: my %errortext = &Apache::lonlocal::texthash (
4354: fail => 'Storage of folder contents failed',
4355: failread => 'Reading folder contents failed',
4356: failstore => 'Storage of folder contents failed',
4357: );
4358: if ($errortext{$paste_res}) {
4359: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 4360: }
1.329 droeschl 4361: }
1.491 raeburn 4362: if (keys(%paste_errors) > 0) {
1.538 raeburn 4363: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 4364: &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".
4365: '<ul>'."\n");
4366: foreach my $key (sort(keys(%paste_errors))) {
4367: $r->print('<li>'.$key.'</li>'."\n");
4368: }
4369: $r->print('</ul></p>'."\n");
4370: }
1.538 raeburn 4371: } elsif ($env{'form.clearmarked'}) {
4372: my $output = &do_buffer_empty();
4373: if ($output) {
4374: $r->print('<p class="LC_info">'.$output.'</p>');
4375: }
4376: }
1.329 droeschl 4377:
4378: $r->print($upload_output);
4379:
1.538 raeburn 4380: # Rename, cut, copy or remove a single resource
1.602 raeburn 4381: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 4382: my $contentchg;
1.633 raeburn 4383: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 4384: $contentchg = 1;
4385: }
4386: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 4387: return $errtext if ($fatal);
4388: }
1.538 raeburn 4389:
4390: # Cut, copy and/or remove multiple resources
4391: if ($env{'form.multichange'}) {
4392: my %allchecked = (
4393: cut => {},
4394: remove => {},
4395: );
4396: my $needsupdate;
4397: foreach my $which (keys(%allchecked)) {
4398: $env{'form.multi'.$which} =~ s/,$//;
4399: if ($env{'form.multi'.$which}) {
4400: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
4401: if (ref($allchecked{$which}) eq 'HASH') {
4402: $needsupdate += scalar(keys(%{$allchecked{$which}}));
4403: }
4404: }
4405: }
4406: if ($needsupdate) {
4407: my $haschanges = 0;
4408: my %curr_groups = &Apache::longroup::coursegroups();
4409: my $total = scalar(@LONCAPA::map::order) - 1;
4410: for (my $i=$total; $i>=0; $i--) {
4411: my $res = $LONCAPA::map::order[$i];
4412: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4413: $name=&LONCAPA::map::qtescape($name);
4414: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 4415: next unless $url;
1.538 raeburn 4416: my %denied =
4417: &action_restrictions($coursenum,$coursedom,$url,
4418: $env{'form.folderpath'},\%curr_groups);
4419: foreach my $which (keys(%allchecked)) {
4420: next if ($denied{$which});
4421: next unless ($allchecked{$which}{$res});
4422: if ($which eq 'remove') {
4423: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4424: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4425: &Apache::lonnet::removeuploadedurl($url);
4426: } else {
4427: &LONCAPA::map::makezombie($res);
4428: }
4429: splice(@LONCAPA::map::order,$i,1);
4430: $haschanges ++;
4431: } elsif ($which eq 'cut') {
4432: &LONCAPA::map::makezombie($res);
4433: splice(@LONCAPA::map::order,$i,1);
4434: $haschanges ++;
4435: }
4436: }
4437: }
4438: if ($haschanges) {
4439: ($errtext,$fatal) =
4440: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
4441: return $errtext if ($fatal);
4442: }
4443: }
4444: }
4445:
1.329 droeschl 4446: # Group import/search
4447: if ($env{'form.importdetail'}) {
4448: my @imports;
4449: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
4450: if (defined($item)) {
4451: my ($name,$url,$residx)=
1.533 raeburn 4452: map { &unescape($_); } split(/\=/,$item);
4453: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
4454: my ($suffix,$errortxt,$locknotfreed) =
4455: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 4456: if ($locknotfreed) {
4457: $r->print($locknotfreed);
4458: }
4459: if ($suffix) {
4460: $url =~ s/_new\./_$suffix./;
4461: } else {
4462: return $errortxt;
4463: }
1.533 raeburn 4464: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
4465: my $type = $1;
4466: my ($suffix,$errortxt,$locknotfreed) =
4467: &new_timebased_suffix($coursedom,$coursenum,$type);
4468: if ($locknotfreed) {
4469: $r->print($locknotfreed);
4470: }
4471: if ($suffix) {
4472: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
4473: } else {
4474: return $errortxt;
4475: }
1.626 raeburn 4476: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 4477: my ($suffix,$errortxt,$locknotfreed) =
4478: &new_timebased_suffix($coursedom,$coursenum,'exttool');
4479: if ($locknotfreed) {
4480: $r->print($locknotfreed);
4481: }
4482: if ($suffix) {
4483: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
4484: } else {
4485: return $errortxt;
4486: }
1.534 raeburn 4487: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
4488: if ($supplementalflag) {
4489: next unless ($1 eq 'supplemental');
4490: if ($folder eq 'supplemental') {
4491: next unless ($2 eq 'default');
4492: } else {
4493: next unless ($folder eq 'supplemental_'.$2);
4494: }
4495: } else {
4496: next unless ($1 eq 'docs');
4497: if ($folder eq 'default') {
4498: next unless ($2 eq 'default');
4499: } else {
4500: next unless ($folder eq 'default_'.$2);
4501: }
4502: }
1.504 raeburn 4503: }
1.329 droeschl 4504: push(@imports, [$name, $url, $residx]);
4505: }
4506: }
1.530 raeburn 4507: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 4508: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 4509: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 4510: return $errtext if ($fatal);
1.529 raeburn 4511: if ($fixuperrors) {
4512: $r->print($fixuperrors);
4513: }
1.329 droeschl 4514: }
4515: # Loading a complete map
4516: if ($env{'form.loadmap'}) {
4517: if ($env{'form.importmap'}=~/\w/) {
4518: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
4519: my ($title,$url,$ext,$type)=split(/\:/,$res);
4520: my $idx=&LONCAPA::map::getresidx($url);
4521: $LONCAPA::map::resources[$idx]=$res;
4522: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
4523: }
4524: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 4525: $folder.'.'.$container,1);
1.329 droeschl 4526: return $errtext if ($fatal);
4527: } else {
4528: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 4529:
1.329 droeschl 4530: }
4531: }
4532: &log_differences($plain);
4533: }
4534: # ---------------------------------------------------------------- End commands
4535: # ---------------------------------------------------------------- Print screen
4536: my $idx=0;
4537: my $shown=0;
4538: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 4539: $r->print('<div class="LC_Box">'.
1.432 raeburn 4540: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
4541: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
4542: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
4543: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
4544: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 4545: '</ol>');
1.381 bisitz 4546: if ($randompick>=0) {
4547: $r->print('<p class="LC_warning">'
4548: .&mt('Caution: this folder is set to randomly pick a subset'
4549: .' of resources. Adding or removing resources from this'
4550: .' folder will change the set of resources that the'
4551: .' students see, resulting in spurious or missing credit'
4552: .' for completed problems, not limited to ones you'
4553: .' modify. Do not modify the contents of this folder if'
4554: .' it is in active student use.')
4555: .'</p>'
4556: );
4557: }
4558: if ($is_random_order) {
4559: $r->print('<p class="LC_warning">'
4560: .&mt('Caution: this folder is set to randomly order its'
4561: .' contents. Adding or removing resources from this folder'
4562: .' will change the order of resources shown.')
4563: .'</p>'
4564: );
4565: }
4566: $r->print('</div>');
1.364 bisitz 4567: }
1.381 bisitz 4568:
1.685 raeburn 4569: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 4570: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 4571: if (ref($supplemental) eq 'HASH') {
4572: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
4573: (ref($supplemental->{'ids'}) eq 'HASH')) {
4574: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
4575: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
4576: if ($supplemental->{'hidden'}->{$mapnum}) {
4577: $ishidden = 1;
4578: }
4579: }
4580: }
4581: }
4582: }
4583:
1.538 raeburn 4584: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
4585: %filters = (
1.543 raeburn 4586: canremove => [],
4587: cancut => [],
4588: cancopy => [],
4589: hiddenresource => [],
4590: encrypturl => [],
4591: randomorder => [],
4592: randompick => [],
1.538 raeburn 4593: );
4594: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 4595: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 4596: foreach my $res (@LONCAPA::map::order) {
4597: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4598: $name=&LONCAPA::map::qtescape($name);
4599: $url=&LONCAPA::map::qtescape($url);
4600: unless ($name) { $name=(split(/\//,$url))[-1]; }
4601: unless ($name) { $idx++; next; }
1.537 raeburn 4602: push(@allidx,$res);
4603: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4604: push(@allmapidx,$res);
4605: }
1.617 raeburn 4606:
1.682 raeburn 4607: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 4608: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
4609: $idx++;
4610: next;
4611: }
1.682 raeburn 4612: }
1.381 bisitz 4613: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 4614: $coursenum,$coursedom,$crstype,
1.538 raeburn 4615: $pathitem,$supplementalflag,$container,
1.620 raeburn 4616: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 4617: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 4618: $idx++;
4619: $shown++;
1.329 droeschl 4620: }
1.424 onken 4621: &Apache::loncommon::end_data_table_count();
1.510 raeburn 4622:
1.538 raeburn 4623: my $need_save;
1.611 raeburn 4624: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 4625: my $toolslink;
1.682 raeburn 4626: if ($allowed || $canedit) {
4627: my $helpitem = 'Navigation_Screen';
4628: if (!$allowed) {
4629: $helpitem = 'Supplemental_Navigation';
4630: }
1.544 raeburn 4631: $toolslink = '<table><tr><td>'
1.520 raeburn 4632: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 4633: $helpitem,undef,'RAT')
1.520 raeburn 4634: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
4635: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 4636: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 4637: .'id="LC_content_toolbar_edittoplevel" '
4638: .'class="LC_toolbarItem" '
4639: .'title="'.&mt('Supplemental Content Editor').'">'
4640: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 4641: }
1.510 raeburn 4642: if ($shown) {
4643: if ($allowed) {
4644: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
4645: .&Apache::loncommon::start_data_table(undef,'contentlist')
4646: .&Apache::loncommon::start_data_table_header_row()
4647: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 4648: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 4649: .'<th>'.&mt('Document').'</th>'
4650: .'<th colspan="2">'.&mt('Settings').'</th>'
4651: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 4652: if ($folder !~ /^supplemental/) {
1.538 raeburn 4653: $lists{'canhide'} = join(',',@allidx);
4654: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 4655: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
4656: 'randomorder','randompick');
4657: foreach my $item (@possfilters) {
1.538 raeburn 4658: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 4659: if (@{$filters{$item}} > 0) {
4660: $lists{$item} = join(',',@{$filters{$item}});
4661: }
1.538 raeburn 4662: }
4663: }
1.537 raeburn 4664: if (@allidx > 0) {
4665: my $path;
4666: if ($env{'form.folderpath'}) {
1.630 raeburn 4667: $path =
1.537 raeburn 4668: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4669: }
1.538 raeburn 4670: if (@allidx > 1) {
1.630 raeburn 4671: $to_show .=
1.538 raeburn 4672: &Apache::loncommon::continue_data_table_row().
4673: '<td colspan="2"> </td>'.
4674: '<td>'.
1.611 raeburn 4675: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 4676: '</td>'.
1.633 raeburn 4677: '<td colspan="3"> </td>'.
4678: '<td colspan="2">'.
1.611 raeburn 4679: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 4680: '</td>'.
4681: &Apache::loncommon::end_data_table_row();
4682: $need_save = 1;
4683: }
1.537 raeburn 4684: }
4685: }
4686: $to_show .= $output.' '
1.510 raeburn 4687: .&Apache::loncommon::end_data_table()
4688: .'<br style="line-height:2px;" />'
4689: .&Apache::loncommon::end_scrollbox();
4690: } else {
1.520 raeburn 4691: $to_show .= $toolslink
1.510 raeburn 4692: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4693: .$output.' '
4694: .&Apache::loncommon::end_data_table();
1.393 raeburn 4695: }
1.510 raeburn 4696: } else {
1.520 raeburn 4697: if (!$allowed) {
4698: $to_show .= $toolslink;
4699: }
1.615 raeburn 4700: my $noresmsg;
4701: if ($allowed && $hiddentop && !$supplementalflag) {
4702: $noresmsg = &mt('Main Content Hidden');
4703: } else {
4704: $noresmsg = &mt('Currently empty');
4705: }
1.510 raeburn 4706: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
4707: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 4708: .$noresmsg
1.510 raeburn 4709: .'</div>'
4710: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 4711: }
4712: } else {
1.510 raeburn 4713: if ($shown) {
4714: $to_show = '<div>'
4715: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4716: .$output
4717: .&Apache::loncommon::end_data_table()
4718: .'</div>';
4719: } else {
4720: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 4721: .&mt('Currently empty')
1.510 raeburn 4722: .'</div>'
4723: }
1.458 raeburn 4724: }
4725: my $tid = 1;
4726: if ($supplementalflag) {
4727: $tid = 2;
1.329 droeschl 4728: }
4729: if ($allowed) {
1.484 raeburn 4730: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 4731: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 4732: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
4733: if ($canedit) {
4734: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
4735: }
1.460 raeburn 4736: } else {
4737: $r->print($to_show);
1.329 droeschl 4738: }
4739: return;
4740: }
4741:
1.538 raeburn 4742: sub multiple_check_form {
1.611 raeburn 4743: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 4744: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 4745: my $disabled;
4746: unless ($canedit) {
1.700 raeburn 4747: $disabled = ' disabled="disabled"';
1.611 raeburn 4748: }
1.538 raeburn 4749: my $output =
4750: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
4751: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
4752: '<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>'.
4753: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
4754: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
4755: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
4756: if ($caller eq 'settings') {
4757: $output .=
4758: '<table><tr>'.
4759: '<td class="LC_docs_entry_parameter">'.
4760: '<span class="LC_nobreak"><label>'.
1.611 raeburn 4761: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 4762: '</label></span></td>'.
4763: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 4764: '<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 4765: '</span></td>'.
4766: '</tr>'."\n".
4767: '<tr>'.
4768: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 4769: '<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 4770: '</label></span>'.
4771: '</td></tr></table>'."\n";
4772: } else {
4773: $output .=
4774: '<table><tr>'.
4775: '<td class="LC_docs_entry_parameter">'.
4776: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 4777: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 4778: '</label></span></td>'.
4779: '<td class="LC_docs_entry_parameter">'.
4780: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 4781: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 4782: '</label></span></td>'."\n".
4783: '<td class="LC_docs_entry_parameter">'.
4784: '<span class="LC_nobreak LC_docs_copy">'.
1.700 raeburn 4785: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538 raeburn 4786: '</label></span></td>'.
4787: '</tr></table>'."\n";
4788: }
4789: $output .=
4790: '</fieldset>'.
4791: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
4792: if ($caller eq 'settings') {
4793: $output .=
1.543 raeburn 4794: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
4795: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
4796: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
4797: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
4798: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 4799: } elsif ($caller eq 'actions') {
4800: $output .=
4801: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
4802: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
4803: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
4804: }
4805: $output .=
4806: '</form>'.
4807: '</div>';
4808: return $output;
4809: }
4810:
1.329 droeschl 4811: sub process_file_upload {
1.552 raeburn 4812: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 4813: # upload a file, if present
1.552 raeburn 4814: my $filesize = length($env{'form.uploaddoc'});
4815: if (!$filesize) {
4816: $$upload_output = '<div class="LC_error">'.
4817: &mt('Unable to upload [_1]. (size = [_2] bytes)',
4818: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
4819: $filesize).'<br />'.
4820: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
4821: '</div>';
4822: return;
4823: }
4824: my $quotatype = 'unofficial';
4825: if ($crstype eq 'Community') {
1.601 raeburn 4826: $quotatype = 'community';
4827: } elsif ($crstype eq 'Placement') {
4828: $quotatype = 'placement';
1.580 raeburn 4829: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 4830: $quotatype = 'official';
1.573 raeburn 4831: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
4832: $quotatype = 'textbook';
1.552 raeburn 4833: }
4834: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
4835: $filesize = int($filesize/1000); #expressed in kb
4836: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 4837: $env{'form.uploaddoc.filename'},$filesize,
4838: 'upload',$quotatype);
1.552 raeburn 4839: return if ($$upload_output);
4840: }
1.440 raeburn 4841: my ($parseaction,$showupload,$nextphase,$mimetype);
4842: if ($env{'form.parserflag'}) {
1.329 droeschl 4843: $parseaction = 'parse';
4844: }
4845: my $folder=$env{'form.folder'};
4846: if ($folder eq '') {
4847: $folder='default';
4848: }
4849: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
4850: my $errtext='';
4851: my $fatal=0;
4852: my $container='sequence';
1.519 raeburn 4853: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 4854: $container='page';
4855: }
4856: ($errtext,$fatal)=
1.534 raeburn 4857: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 4858: if ($#LONCAPA::map::order<1) {
4859: $LONCAPA::map::order[0]=1;
4860: $LONCAPA::map::resources[1]='';
4861: }
4862: my $destination = 'docs/';
4863: if ($folder =~ /^supplemental/) {
4864: $destination = 'supplemental/';
4865: }
4866: if (($folder eq 'default') || ($folder eq 'supplemental')) {
4867: $destination .= 'default/';
4868: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
4869: $destination .= $2.'/';
4870: }
1.534 raeburn 4871: if ($fatal) {
4872: $$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>';
4873: return;
4874: }
1.440 raeburn 4875: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 4876: my $newidx=&LONCAPA::map::getresidx();
4877: $destination .= $newidx;
1.439 raeburn 4878: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 4879: $parseaction,$allfiles,
1.440 raeburn 4880: $codebase,undef,undef,undef,undef,
4881: undef,undef,\$mimetype);
4882: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
4883: my $stored = $1;
4884: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
4885: $stored.'</span>').'</p>';
4886: } else {
4887: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
4888:
1.457 raeburn 4889: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 4890: return;
4891: }
1.329 droeschl 4892: my $ext='false';
4893: if ($url=~m{^http://}) { $ext='true'; }
4894: $url = &LONCAPA::map::qtunescape($url);
4895: my $comment=$env{'form.comment'};
4896: $comment = &LONCAPA::map::qtunescape($comment);
4897: if ($folder=~/^supplemental/) {
4898: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
4899: $env{'user.domain'}.'___&&&___'.$comment;
4900: }
4901:
4902: $LONCAPA::map::resources[$newidx]=
4903: $comment.':'.$url.':'.$ext.':normal:res';
4904: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
4905: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 4906: $folder.'.'.$container,1);
1.329 droeschl 4907: if ($fatal) {
1.457 raeburn 4908: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 4909: return;
1.329 droeschl 4910: } else {
1.440 raeburn 4911: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
4912: $$upload_output = $showupload;
1.384 raeburn 4913: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 4914: if ($total_embedded > 0) {
1.440 raeburn 4915: my $uploadphase = 'upload_embedded';
4916: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
4917: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 4918: my ($embedded,$num) =
1.440 raeburn 4919: &Apache::loncommon::ask_for_embedded_content(
4920: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
4921: if ($embedded) {
4922: if ($num) {
4923: $$upload_output .=
4924: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
4925: $nextphase = $uploadphase;
4926: } else {
4927: $$upload_output .= $embedded;
4928: }
4929: } else {
4930: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
4931: }
1.329 droeschl 4932: } else {
1.440 raeburn 4933: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 4934: }
1.457 raeburn 4935: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 4936: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
4937: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 4938: $nextphase = 'decompress_uploaded';
4939: my $position = scalar(@LONCAPA::map::order)-1;
4940: my $noextract = &return_to_editor();
4941: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
4942: my %archiveitems = (
4943: folderpath => $env{'form.folderpath'},
4944: cmd => $nextphase,
4945: newidx => $newidx,
4946: position => $position,
4947: phase => $nextphase,
1.477 raeburn 4948: comment => $comment,
1.480 raeburn 4949: );
4950: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
4951: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 4952: $$upload_output = $showupload.
4953: &Apache::loncommon::decompress_form($mimetype,
4954: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 4955: \%archiveitems,\@current);
1.329 droeschl 4956: }
4957: }
4958: }
1.440 raeburn 4959: return $nextphase;
1.329 droeschl 4960: }
4961:
1.480 raeburn 4962: sub get_dir_list {
4963: my ($url,$coursenum,$coursedom,$newidx) = @_;
4964: my ($destination,$dir_root) = &embedded_destination();
4965: my ($dirlistref,$listerror) =
4966: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
4967: my @dir_lines;
4968: my $dirptr=16384;
4969: if (ref($dirlistref) eq 'ARRAY') {
4970: foreach my $dir_line (sort
4971: {
4972: my ($afile)=split('&',$a,2);
4973: my ($bfile)=split('&',$b,2);
4974: return (lc($afile) cmp lc($bfile));
4975: } (@{$dirlistref})) {
4976: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
4977: $filename =~ s/\s+$//;
4978: next if ($filename =~ /^\.\.?$/);
4979: my $isdir = 0;
4980: if ($dirptr&$testdir) {
4981: $isdir = 1;
4982: }
4983: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
4984: }
4985: }
4986: return @dir_lines;
4987: }
4988:
1.329 droeschl 4989: sub is_supplemental_title {
4990: my ($title) = @_;
4991: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
4992: }
4993:
4994: # --------------------------------------------------------------- An entry line
4995:
4996: sub entryline {
1.501 raeburn 4997: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 4998: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 4999: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 5000: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 5001: if (&is_supplemental_title($title)) {
1.488 raeburn 5002: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 5003: $encodedtitle=$title;
1.329 droeschl 5004: } else {
5005: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 5006: $encodedtitle=$title;
1.329 droeschl 5007: $renametitle=$title;
5008: $foldertitle=$title;
5009: }
5010:
1.611 raeburn 5011: my ($disabled,$readonly,$js_lt);
5012: unless ($canedit) {
5013: $disabled = 'disabled="disabled"';
5014: $readonly = 1;
5015: }
5016:
1.329 droeschl 5017: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 5018:
1.329 droeschl 5019: $renametitle=~s/\\/\\\\/g;
5020: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 5021: $renametitle=~s/"/%22/g;
1.581 raeburn 5022: $renametitle=~s/ /%20/g;
5023: $oldtitle = $renametitle;
1.576 raeburn 5024: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 5025: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 5026: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 5027: # Edit commands
1.679 raeburn 5028: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 5029: if ($env{'form.folderpath'}) {
5030: $esc_path=&escape($env{'form.folderpath'});
5031: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5032: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
5033: }
1.505 raeburn 5034: my $isexternal;
1.510 raeburn 5035: if ($residx) {
1.501 raeburn 5036: my $currurl = $url;
5037: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 5038: if ($currurl =~ m{^/adm/wrapper/ext/}) {
5039: $isexternal = 1;
5040: }
1.510 raeburn 5041: if (!$supplementalflag) {
5042: my $path = 'uploaded/'.
5043: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
5044: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
5045: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
5046: $residx,
5047: &Apache::lonnet::declutter($currurl));
5048: }
1.501 raeburn 5049: }
1.538 raeburn 5050: my ($renamelink,%lt,$ishash);
5051: if (ref($filtersref) eq 'HASH') {
5052: $ishash = 1;
5053: }
5054:
1.329 droeschl 5055: if ($allowed) {
1.538 raeburn 5056: $form_start = '
5057: <form action="/adm/coursedocs" method="post">
5058: ';
5059: $form_common=(<<END);
5060: <input type="hidden" name="folderpath" value="$path" />
5061: <input type="hidden" name="symb" value="$symb" />
5062: END
5063: $form_param=(<<END);
5064: <input type="hidden" name="setparms" value="$orderidx" />
5065: <input type="hidden" name="changeparms" value="0" />
5066: END
5067: $form_end = '</form>';
5068:
1.329 droeschl 5069: my $incindex=$index+1;
5070: my $selectbox='';
1.471 raeburn 5071: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 5072: ((split(/\:/,
1.344 bisitz 5073: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
5074: ne '') &&
1.329 droeschl 5075: ((split(/\:/,
1.344 bisitz 5076: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 5077: ne '')) {
5078: $selectbox=
5079: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 5080: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 5081: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
5082: if ($i==$incindex) {
1.358 bisitz 5083: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 5084: } else {
5085: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
5086: }
5087: }
5088: $selectbox.='</select>';
5089: }
1.501 raeburn 5090: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 5091: 'up' => 'Move Up',
5092: 'dw' => 'Move Down',
5093: 'rm' => 'Remove',
5094: 'ct' => 'Cut',
5095: 'rn' => 'Rename',
1.501 raeburn 5096: 'cp' => 'Copy',
1.633 raeburn 5097: 'da' => 'Unset alias',
5098: 'sa' => 'Set alias',
1.501 raeburn 5099: 'ex' => 'External Resource',
1.598 raeburn 5100: 'et' => 'External Tool',
1.501 raeburn 5101: 'ed' => 'Edit',
5102: 'pr' => 'Preview',
5103: 'sv' => 'Save',
5104: 'ul' => 'URL',
1.611 raeburn 5105: 'ti' => 'Title',
1.618 raeburn 5106: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 5107: );
1.538 raeburn 5108: my %denied = &action_restrictions($coursenum,$coursedom,$url,
5109: $env{'form.folderpath'},
5110: $currgroups);
1.517 raeburn 5111: my ($copylink,$cutlink,$removelink);
1.329 droeschl 5112: my $skip_confirm = 0;
1.603 raeburn 5113: my $confirm_removal = 0;
1.329 droeschl 5114: if ( $folder =~ /^supplemental/
5115: || ($url =~ m{( /smppg$
5116: |/syllabus$
5117: |/aboutme$
5118: |/navmaps$
5119: |/bulletinboard$
1.626 raeburn 5120: |/ext\.tool$
1.505 raeburn 5121: |\.html$)}x)
5122: || $isexternal) {
1.329 droeschl 5123: $skip_confirm = 1;
5124: }
1.603 raeburn 5125: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
5126: ($url!~/$LONCAPA::assess_page_seq_re/)) {
5127: $confirm_removal = 1;
5128: }
1.633 raeburn 5129: if ($url =~ /$LONCAPA::assess_re/) {
5130: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
5131: }
1.329 droeschl 5132:
1.538 raeburn 5133: if ($denied{'copy'}) {
1.543 raeburn 5134: $copylink=(<<ENDCOPY)
1.507 raeburn 5135: <span style="visibility: hidden;">$lt{'cp'}</span>
5136: ENDCOPY
5137: } else {
1.538 raeburn 5138: my $formname = 'edit_copy_'.$orderidx;
5139: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5140: $copylink=(<<ENDCOPY);
1.538 raeburn 5141: <form name="$formname" method="post" action="/adm/coursedocs">
5142: $form_common
1.611 raeburn 5143: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
1.538 raeburn 5144: $form_end
1.329 droeschl 5145: ENDCOPY
1.538 raeburn 5146: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
5147: push(@{$filtersref->{'cancopy'}},$orderidx);
5148: }
1.329 droeschl 5149: }
1.538 raeburn 5150: if ($denied{'cut'}) {
1.507 raeburn 5151: $cutlink=(<<ENDCUT);
5152: <span style="visibility: hidden;">$lt{'ct'}</span>
5153: ENDCUT
5154: } else {
1.538 raeburn 5155: my $formname = 'edit_cut_'.$orderidx;
5156: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5157: $cutlink=(<<ENDCUT);
1.538 raeburn 5158: <form name="$formname" method="post" action="/adm/coursedocs">
5159: $form_common
1.542 raeburn 5160: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 5161: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
1.538 raeburn 5162: $form_end
1.329 droeschl 5163: ENDCUT
1.538 raeburn 5164: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
5165: push(@{$filtersref->{'cancut'}},$orderidx);
5166: }
1.329 droeschl 5167: }
1.538 raeburn 5168: if ($denied{'remove'}) {
1.507 raeburn 5169: $removelink=(<<ENDREM);
5170: <span style="visibility: hidden;">$lt{'rm'}</a>
5171: ENDREM
5172: } else {
1.538 raeburn 5173: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 5174: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 5175: $removelink=(<<ENDREM);
1.538 raeburn 5176: <form name="$formname" method="post" action="/adm/coursedocs">
5177: $form_common
1.542 raeburn 5178: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 5179: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 5180: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
1.538 raeburn 5181: $form_end
1.497 raeburn 5182: ENDREM
1.538 raeburn 5183: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
5184: push(@{$filtersref->{'canremove'}},$orderidx);
5185: }
1.497 raeburn 5186: }
1.551 raeburn 5187: $renamelink=(<<ENDREN);
1.581 raeburn 5188: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 5189: ENDREN
1.611 raeburn 5190: my ($uplink,$downlink);
5191: if ($canedit) {
5192: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
5193: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
5194: } else {
5195: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
5196: $downlink = $uplink;
5197: }
1.329 droeschl 5198: $line.=(<<END);
5199: <td>
1.379 bisitz 5200: <div class="LC_docs_entry_move">
1.611 raeburn 5201: <a href="$uplink">
1.501 raeburn 5202: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 5203: </a>
5204: </div>
5205: <div class="LC_docs_entry_move">
1.611 raeburn 5206: <a href="$downlink">
1.501 raeburn 5207: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 5208: </a>
5209: </div>
1.329 droeschl 5210: </td>
5211: <td>
5212: $form_start
1.538 raeburn 5213: $form_param
1.478 raeburn 5214: $form_common
1.329 droeschl 5215: $selectbox
5216: $form_end
5217: </td>
1.540 raeburn 5218: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 5219: $removelink
1.329 droeschl 5220: $cutlink
5221: $copylink
5222: </td>
5223: END
5224: }
5225: # Figure out what kind of a resource this is
5226: my ($extension)=($url=~/\.(\w+)$/);
5227: my $uploaded=($url=~/^\/*uploaded\//);
5228: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 5229: my $isfolder;
5230: my $ispage;
5231: my $containerarg;
1.615 raeburn 5232: my $folderurl;
1.685 raeburn 5233: my $plainurl;
1.329 droeschl 5234: if ($uploaded) {
1.472 raeburn 5235: if (($extension eq 'sequence') || ($extension eq 'page')) {
5236: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 5237: $containerarg = $1;
1.472 raeburn 5238: if ($extension eq 'sequence') {
5239: $icon=$iconpath.'navmap.folder.closed.gif';
5240: $isfolder=1;
5241: } else {
5242: $icon=$iconpath.'page.gif';
5243: $ispage=1;
5244: }
1.615 raeburn 5245: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 5246: if ($allowed) {
5247: $url='/adm/coursedocs?';
5248: } else {
5249: $url='/adm/supplemental?';
5250: }
1.329 droeschl 5251: } else {
1.685 raeburn 5252: $plainurl = $url;
1.329 droeschl 5253: }
5254: }
1.364 bisitz 5255:
1.621 raeburn 5256: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 5257: my $orig_url = $url;
1.340 raeburn 5258: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 5259: if ($container eq 'page') {
5260: $url=~s{^http(|s)(:|:)//}{/ext/};
5261: } else {
5262: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
5263: }
1.501 raeburn 5264: if (!$supplementalflag && $residx && $symb) {
5265: if ((!$isfolder) && (!$ispage)) {
5266: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 5267: if (($url =~ m{^ext/}) && ($container eq 'page')) {
5268: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
5269: } else {
5270: $url=&Apache::lonnet::clutter($url);
5271: }
1.501 raeburn 5272: if ($url=~/^\/*uploaded\//) {
5273: $url=~/\.(\w+)$/;
5274: my $embstyle=&Apache::loncommon::fileembstyle($1);
5275: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
5276: $url='/adm/wrapper'.$url;
5277: } elsif ($embstyle eq 'ssi') {
5278: #do nothing with these
5279: } elsif ($url!~/\.(sequence|page)$/) {
5280: $url='/adm/coursedocs/showdoc'.$url;
5281: }
1.623 raeburn 5282: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
5283: my $wrapped = $1;
5284: my $exturl = $2;
1.668 raeburn 5285: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 5286: $url='/adm/wrapper'.$url;
5287: }
5288: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
5289: $nomodal = 1;
5290: }
1.626 raeburn 5291: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5292: $url='/adm/wrapper'.$url;
1.621 raeburn 5293: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
5294: if (($ENV{'SERVER_PORT'} == 443) &&
5295: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5296: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5297: $url .= '?usehttp=1';
5298: }
1.621 raeburn 5299: $nomodal = 1;
5300: }
1.598 raeburn 5301: }
1.696 raeburn 5302: my $checkencrypt;
1.680 raeburn 5303: if (!$env{'request.role.adv'}) {
1.615 raeburn 5304: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 5305: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 5306: $checkencrypt = 1;
1.620 raeburn 5307: } elsif (ref($navmapref)) {
1.615 raeburn 5308: unless (ref($$navmapref)) {
5309: $$navmapref = Apache::lonnavmaps::navmap->new();
5310: }
5311: if (ref($$navmapref)) {
5312: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 5313: $checkencrypt = 1;
1.615 raeburn 5314: }
5315: }
5316: }
1.680 raeburn 5317: }
5318: if ($checkencrypt) {
5319: my $currenc = $env{'request.enc'};
5320: $env{'request.enc'} = 1;
5321: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 5322: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 5323: if (&Apache::lonnet::symbverify($symb,$url)) {
5324: $url = $shownurl;
5325: } else {
5326: $url = '';
5327: }
5328: $env{'request.enc'} = $currenc;
5329: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
5330: $shownsymb = $symb;
5331: if ($isexternal) {
5332: $url =~ s/\#[^#]+$//;
5333: if ($container eq 'page') {
5334: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 5335: }
1.612 raeburn 5336: }
1.696 raeburn 5337: } else {
5338: $url = '';
1.680 raeburn 5339: }
5340: unless ($env{'request.role.adv'}) {
5341: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5342: $url = '';
5343: }
5344: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
5345: $url = '';
5346: $hiddenres = 1;
5347: }
5348: }
1.696 raeburn 5349: if (($url ne '') && ($shownsymb ne '')) {
5350: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 5351: }
1.329 droeschl 5352: }
1.621 raeburn 5353: } elsif ($supplementalflag) {
1.610 raeburn 5354: if ($isexternal) {
5355: if ($url =~ /^([^#]+)#([^#]+)$/) {
5356: $url = $1;
5357: $anchor = $2;
1.623 raeburn 5358: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 5359: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5360: if ($hostname ne '') {
5361: $url = 'http://'.$hostname.$url;
5362: }
5363: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 5364: }
5365: $nomodal = 1;
5366: }
1.610 raeburn 5367: }
1.621 raeburn 5368: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
5369: if (($ENV{'SERVER_PORT'} == 443) &&
5370: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5371: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5372: if ($hostname ne '') {
5373: $url = 'http://'.$hostname.$url;
5374: }
5375: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 5376: }
1.621 raeburn 5377: $nomodal = 1;
5378: }
1.705 raeburn 5379: } elsif (($uploaded) && ($url ne '/adm/supplemental?') && ($url ne '/adm/coursedocs?')) {
1.686 raeburn 5380: my $embstyle=&Apache::loncommon::fileembstyle($extension);
5381: unless ($embstyle eq 'ssi') {
5382: if (($embstyle eq 'img')
5383: || ($embstyle eq 'emb')
5384: || ($embstyle eq 'wrp')) {
5385: $url='/adm/wrapper'.$url;
5386: } elsif ($url !~ /\.(sequence|page)$/) {
5387: $url='/adm/coursedocs/showdoc'.$url;
5388: }
5389: }
1.610 raeburn 5390: }
1.685 raeburn 5391: unless ($allowed && $env{'request.role.adv'}) {
5392: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5393: $hiddenres = 1;
5394: }
5395: }
1.329 droeschl 5396: }
1.615 raeburn 5397: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 5398: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 5399: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 5400: my $foldername=&escape($foldertitle);
5401: my $folderpath=$env{'form.folderpath'};
5402: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 5403: if (!$allowed && $supplementalflag) {
1.519 raeburn 5404: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 5405: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 5406: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5407: $hiddenfolder = 1;
1.682 raeburn 5408: }
1.510 raeburn 5409: } else {
1.617 raeburn 5410: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
5411: 'parameter_randompick'))[0];
5412: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
5413: 'parameter_randomorder'))[0]=~/^yes$/i);
5414: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
5415: 'parameter_hiddenresource'))[0]=~/^yes$/i);
5416: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
5417: 'parameter_encrypturl'))[0]=~/^yes$/i);
5418: unless ($hiddenmap) {
1.620 raeburn 5419: if (ref($navmapref)) {
5420: unless (ref($$navmapref)) {
5421: $$navmapref = Apache::lonnavmaps::navmap->new();
5422: }
5423: if (ref($$navmapref)) {
5424: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5425: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
5426: unless (@resources) {
5427: $hiddenmap = 1;
5428: unless ($env{'request.role.adv'}) {
5429: $url = '';
5430: $hiddenfolder = 1;
5431: }
1.617 raeburn 5432: }
1.615 raeburn 5433: }
5434: }
5435: }
5436: }
1.617 raeburn 5437: unless ($encryptmap) {
1.620 raeburn 5438: if ((ref($navmapref)) && (ref($$navmapref))) {
5439: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
5440: $encryptmap = 1;
5441: }
1.617 raeburn 5442: }
5443: }
1.630 raeburn 5444:
1.617 raeburn 5445: # Append randompick number, hidden, and encrypted with ":" to foldername,
5446: # so it gets transferred between levels
5447: $folderpath.=$containerarg.'&'.$foldername.
5448: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 5449: unless ($url eq '') {
1.612 raeburn 5450: $url.='folderpath='.&escape($folderpath);
5451: }
1.510 raeburn 5452: my $rpckchk;
5453: if ($rpicknum) {
5454: $rpckchk = ' checked="checked"';
1.543 raeburn 5455: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
5456: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
5457: }
1.510 raeburn 5458: }
1.537 raeburn 5459: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 5460: $rand_pick_text =
1.478 raeburn 5461: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5462: $form_param."\n".
1.478 raeburn 5463: $form_common."\n".
1.611 raeburn 5464: '<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 5465: if ($rpicknum ne '') {
5466: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
5467: }
1.537 raeburn 5468: $rand_pick_text .= '</span></span>'.
5469: $form_end;
1.543 raeburn 5470: my $ro_set;
1.617 raeburn 5471: if ($randorder) {
1.543 raeburn 5472: $ro_set = 'checked="checked"';
5473: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
5474: push(@{$filtersref->{'randomorder'}},$orderidx);
5475: }
5476: }
1.564 raeburn 5477: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 5478: $rand_order_text =
1.537 raeburn 5479: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5480: $form_param."\n".
1.537 raeburn 5481: $form_common."\n".
1.611 raeburn 5482: '<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 5483: $form_end;
1.510 raeburn 5484: }
1.705 raeburn 5485: } elsif ($supplementalflag) {
1.598 raeburn 5486: my $isexttool;
1.626 raeburn 5487: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5488: $url='/adm/wrapper'.$url;
5489: $isexttool = 1;
5490: }
1.510 raeburn 5491: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 5492: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 5493: if ($title) {
1.687 raeburn 5494: $url .= '&title='.$encodedtitle;
1.510 raeburn 5495: }
1.598 raeburn 5496: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 5497: $url .= '&idx='.$orderidx;
5498: }
1.610 raeburn 5499: if ($anchor ne '') {
5500: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5501: }
1.329 droeschl 5502: }
1.519 raeburn 5503: my ($tdalign,$tdwidth);
1.501 raeburn 5504: if ($allowed) {
1.630 raeburn 5505: my $fileloc =
1.501 raeburn 5506: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 5507: if ($isexternal) {
1.630 raeburn 5508: ($editlink,$extresform) =
1.611 raeburn 5509: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5510: undef,undef,undef,undef,undef,undef,
5511: undef,$disabled);
1.626 raeburn 5512: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5513: ($editlink,$extresform) =
5514: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5515: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 5516: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 5517: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 5518: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
5519: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 5520: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 5521: my $suppanchor;
5522: if ($supplementalflag) {
5523: $suppanchor = $anchor;
5524: }
1.630 raeburn 5525: my $jscall =
1.501 raeburn 5526: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
5527: $switchserver,
1.503 raeburn 5528: $forceedit,
1.679 raeburn 5529: undef,$symb,$shownsymb,
1.511 raeburn 5530: &escape($env{'form.folderpath'}),
1.622 raeburn 5531: $renametitle,$hostname,
5532: '','',1,$suppanchor);
1.501 raeburn 5533: if ($jscall) {
1.518 raeburn 5534: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
5535: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 5536: }
5537: }
5538: }
1.519 raeburn 5539: $tdalign = ' align="right" valign="top"';
5540: $tdwidth = ' width="80%"';
1.329 droeschl 5541: }
1.408 raeburn 5542: my $reinit;
5543: if ($crstype eq 'Community') {
5544: $reinit = &mt('(re-initialize community to access)');
5545: } else {
5546: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 5547: }
1.702 raeburn 5548: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
1.650 raeburn 5549: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 5550: $line.= '<br />';
5551: if ($curralias ne '') {
5552: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5553: $lt{'da'}.'</a></span>';
5554: } else {
5555: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5556: $lt{'sa'}.'</a></span>';
5557: }
5558: }
1.701 raeburn 5559: $line.='</td><td><span class="LC_nobreak">';
1.685 raeburn 5560: my ($link,$nolink);
1.472 raeburn 5561: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5562: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
5563: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5564: $nolink = 1;
5565: }
5566: }
5567: if ($nolink) {
5568: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5569: } else {
5570: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5571: }
1.469 www 5572: } elsif ($url) {
1.610 raeburn 5573: if ($anchor ne '') {
5574: if ($supplementalflag) {
5575: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5576: } else {
5577: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
5578: }
5579: }
1.705 raeburn 5580: if (($nomodal) && ($hostname ne '')) {
1.622 raeburn 5581: $link = 'http://'.$hostname.$url;
5582: } else {
5583: $link = $url;
5584: }
1.705 raeburn 5585: my $inhibitmenu;
5586: if ((($supplementalflag) && ($allowed) && ($url =~ m{^/adm/wrapper/})) ||
5587: (($allowed) && (($url =~ m{^/adm/(viewclasslist|$match_domain/$match_username/aboutme)(\?|$)}) ||
5588: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus(\?|$)})))) {
5589: $inhibitmenu = 'only_body=1';
5590: } else {
5591: $inhibitmenu = 'inhibitmenu=yes';
5592: }
5593: $link = &js_escape($link.(($url=~/\?/)?'&':'?').$inhibitmenu.$anchor);
1.685 raeburn 5594: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
5595: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5596: $nolink = 1;
5597: }
5598: }
5599: if ($nolink) {
5600: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5601: } elsif ($nomodal) {
1.621 raeburn 5602: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5603: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
5604: } else {
5605: $line.=&Apache::loncommon::modal_link($link,
5606: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
5607: }
1.469 www 5608: } else {
5609: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5610: }
1.519 raeburn 5611: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 5612: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5613: if ($nolink) {
5614: $line.=$title;
5615: } else {
5616: $line.='<a href="'.$url.'">'.$title.'</a>';
5617: }
1.682 raeburn 5618: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
5619: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
5620: my $editurl = $url;
5621: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
5622: $line .= ' '.'<a href="'.$editurl.'">'.
5623: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
5624: '</a>';
5625: }
5626: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
5627: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
5628: }
1.469 www 5629: } elsif ($url) {
1.685 raeburn 5630: if ($nolink) {
5631: $line.=$title;
5632: } elsif ($nomodal) {
1.621 raeburn 5633: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5634: $title.'</a>';
5635: } else {
5636: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
5637: }
1.617 raeburn 5638: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 5639: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 5640: } else {
5641: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
5642: }
1.633 raeburn 5643: if (($allowed) && ($curralias ne '')) {
5644: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
5645: } else {
5646: $line .= $extresform;
5647: }
5648: $line .= '</td>';
1.478 raeburn 5649: $rand_pick_text = ' ' if ($rand_pick_text eq '');
5650: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 5651: if ($uploaded && $url && !$isfolder && !$ispage) {
5652: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
5653: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
5654: }
5655: }
1.682 raeburn 5656: if ($allowed) {
5657: my %lt=&Apache::lonlocal::texthash(
5658: 'hd' => 'Hidden',
5659: 'ec' => 'URL hidden');
5660: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 5661: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5662: $hidtext = ' checked="checked"';
1.694 raeburn 5663: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 5664: push(@{$filtersref->{'hiddenresource'}},$orderidx);
5665: }
5666: }
1.682 raeburn 5667: $formhidden = 'edit_hiddenresource_'.$orderidx;
5668: $line.=(<<ENDPARMS);
1.329 droeschl 5669: <td class="LC_docs_entry_parameter">
1.537 raeburn 5670: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 5671: $form_param
1.478 raeburn 5672: $form_common
1.611 raeburn 5673: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 5674: $form_end
1.682 raeburn 5675: ENDPARMS
5676: if ($folder =~/^supplemental/) {
5677: $line.= "\n <td>";
5678: } else {
5679: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
5680: $enctext = ' checked="checked"';
5681: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
5682: push(@{$filtersref->{'encrypturl'}},$orderidx);
5683: }
5684: }
5685: $formurlhidden = 'edit_encrypturl_'.$orderidx;
5686: $line.=(<<ENDPARMS);
1.458 raeburn 5687: <br />
1.537 raeburn 5688: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 5689: $form_param
1.478 raeburn 5690: $form_common
1.611 raeburn 5691: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 5692: $form_end
5693: </td>
1.478 raeburn 5694: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
5695: $rand_order_text</td>
1.329 droeschl 5696: ENDPARMS
1.682 raeburn 5697: }
1.329 droeschl 5698: }
1.379 bisitz 5699: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 5700: return $line;
5701: }
5702:
1.538 raeburn 5703: sub action_restrictions {
5704: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
5705: my %denied = (
5706: cut => 0,
5707: copy => 0,
5708: remove => 0,
5709: );
5710: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
5711: # no copy for published maps
5712: $denied{'copy'} = 1;
1.597 raeburn 5713: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
5714: unless ($1 eq 'simpleproblem') {
5715: $denied{'copy'} = 1;
5716: }
5717: $denied{'cut'} = 1;
1.538 raeburn 5718: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
5719: if ($folderpath =~ /^default&[^\&]+$/) {
5720: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
5721: $denied{'remove'} = 1;
5722: }
5723: $denied{'cut'} = 1;
5724: $denied{'copy'} = 1;
5725: }
5726: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
5727: my $group = $1;
5728: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
5729: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5730: $denied{'remove'} = 1;
5731: }
5732: }
5733: $denied{'cut'} = 1;
5734: $denied{'copy'} = 1;
5735: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
5736: my $group = $1;
5737: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
5738: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5739: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5740: if (keys(%groupsettings) > 0) {
5741: $denied{'remove'} = 1;
5742: }
5743: $denied{'cut'} = 1;
5744: $denied{'copy'} = 1;
5745: }
5746: }
5747: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
5748: my $group = $1;
5749: if ($url =~ /group_boards_\Q$group\E/) {
5750: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5751: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5752: if (keys(%groupsettings) > 0) {
5753: if (ref($groupsettings{'functions'}) eq 'HASH') {
5754: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
5755: $denied{'remove'} = 1;
5756: }
5757: }
5758: }
5759: $denied{'cut'} = 1;
5760: $denied{'copy'} = 1;
5761: }
5762: }
5763: }
5764: return %denied;
5765: }
5766:
1.533 raeburn 5767: sub new_timebased_suffix {
1.538 raeburn 5768: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 5769: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 5770: if ($type eq 'paste') {
5771: $prefix = $type;
5772: $namespace = 'courseeditor';
1.587 raeburn 5773: $idtype = 'addcode';
1.538 raeburn 5774: } elsif ($type eq 'map') {
1.533 raeburn 5775: $prefix = 'docs';
5776: if ($area eq 'supplemental') {
5777: $prefix = 'supp';
5778: }
5779: $prefix .= $container;
5780: $namespace = 'uploadedmaps';
5781: } else {
5782: $prefix = $type;
5783: $namespace = 'templated';
1.504 raeburn 5784: }
5785: my ($suffix,$freedlock,$error) =
1.587 raeburn 5786: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 5787: if (!$suffix) {
1.538 raeburn 5788: if ($type eq 'paste') {
5789: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
5790: } elsif ($type eq 'map') {
1.533 raeburn 5791: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
5792: } elsif ($type eq 'smppg') {
5793: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 5794: } elsif ($type eq 'exttool') {
5795: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 5796: } else {
1.565 bisitz 5797: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 5798: }
1.504 raeburn 5799: if ($error) {
5800: $errtext .= '<br />'.$error;
5801: }
5802: }
5803: if ($freedlock ne 'ok') {
1.630 raeburn 5804: $locknotfreed =
1.533 raeburn 5805: '<div class="LC_error">'.
5806: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 5807: if ($type eq 'paste') {
1.591 raeburn 5808: if ($freedlock eq 'nolock') {
5809: $locknotfreed =
5810: '<div class="LC_error">'.
5811: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
5812:
1.593 droeschl 5813: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 5814: } else {
5815: $locknotfreed .=
5816: &mt('This will prevent addition of items to the clipboard until your next log-in.');
5817: }
1.538 raeburn 5818: } elsif ($type eq 'map') {
1.591 raeburn 5819: $locknotfreed .=
5820: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 5821: } elsif ($type eq 'smppg') {
5822: $locknotfreed .=
5823: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 5824: } elsif ($type eq 'exttool') {
5825: $locknotfreed .=
5826: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 5827: } else {
5828: $locknotfreed .=
1.565 bisitz 5829: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 5830: }
1.538 raeburn 5831: unless ($type eq 'paste') {
5832: $locknotfreed .=
1.560 raeburn 5833: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
5834: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 5835: }
5836: $locknotfreed .= '</div>';
1.504 raeburn 5837: }
5838: return ($suffix,$errtext,$locknotfreed);
5839: }
5840:
1.329 droeschl 5841: =pod
5842:
5843: =item tiehash()
5844:
5845: tie the hash
5846:
5847: =cut
5848:
5849: sub tiehash {
5850: my ($mode)=@_;
5851: $hashtied=0;
5852: if ($env{'request.course.fn'}) {
5853: if ($mode eq 'write') {
5854: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5855: &GDBM_WRCREAT(),0640)) {
5856: $hashtied=2;
5857: }
5858: } else {
5859: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5860: &GDBM_READER(),0640)) {
5861: $hashtied=1;
5862: }
5863: }
1.364 bisitz 5864: }
1.329 droeschl 5865: }
5866:
5867: sub untiehash {
5868: if ($hashtied) { untie %hash; }
5869: $hashtied=0;
5870: return OK;
5871: }
5872:
5873:
5874:
5875:
5876: sub checkonthis {
1.637 raeburn 5877: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 5878: $url=&unescape($url);
5879: $alreadyseen{$url}=1;
5880: $r->rflush();
5881: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
5882: $r->print("\n<br />");
5883: if ($level==0) {
5884: $r->print("<br />");
5885: }
5886: for (my $i=0;$i<=$level*5;$i++) {
5887: $r->print(' ');
5888: }
5889: $r->print('<a href="'.$url.'" target="cat">'.
5890: ($title?$title:$url).'</a> ');
5891: if ($url=~/^\/res\//) {
1.637 raeburn 5892: my $updated;
5893: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
5894: ($url !~ /\.\d+\.\w+$/)) {
5895: $updated = &Apache::lonnet::remove_stale_resfile($url);
5896: }
1.329 droeschl 5897: my $result=&Apache::lonnet::repcopy(
5898: &Apache::lonnet::filelocation('',$url));
5899: if ($result eq 'ok') {
5900: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 5901: if ($updated) {
5902: $r->print('<br />');
5903: for (my $i=0;$i<=$level*5;$i++) {
5904: $r->print(' ');
5905: }
5906: $r->print('- '.&mt('Outdated copy removed'));
5907: }
1.329 droeschl 5908: $r->rflush();
5909: &Apache::lonnet::countacc($url);
5910: $url=~/\.(\w+)$/;
5911: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
5912: $r->print('<br />');
5913: $r->rflush();
5914: for (my $i=0;$i<=$level*5;$i++) {
5915: $r->print(' ');
5916: }
5917: $r->print('- '.&mt('Rendering:').' ');
5918: my ($errorcount,$warningcount)=split(/:/,
5919: &Apache::lonnet::ssi_body($url,
5920: ('grade_target'=>'web',
5921: 'return_only_error_and_warning_counts' => 1)));
5922: if (($errorcount) ||
5923: ($warningcount)) {
5924: if ($errorcount) {
1.369 bisitz 5925: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 5926: &mt('[quant,_1,error]',$errorcount).'</span>');
5927: }
5928: if ($warningcount) {
5929: $r->print('<span class="LC_warning">'.
5930: &mt('[quant,_1,warning]',$warningcount).'</span>');
5931: }
5932: } else {
5933: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
5934: }
5935: $r->rflush();
5936: }
5937: my $dependencies=
5938: &Apache::lonnet::metadata($url,'dependencies');
5939: foreach my $dep (split(/\,/,$dependencies)) {
5940: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 5941: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 5942: }
5943: }
5944: } elsif ($result eq 'unavailable') {
5945: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
5946: } elsif ($result eq 'not_found') {
5947: unless ($url=~/\$/) {
1.521 bisitz 5948: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 5949: } else {
1.366 bisitz 5950: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 5951: }
5952: } else {
5953: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
5954: }
1.637 raeburn 5955: if (($updated) && ($result ne 'ok')) {
5956: $r->print('<br />'.&mt('Outdated copy removed'));
5957: }
1.329 droeschl 5958: }
5959: }
5960: }
5961:
5962:
5963:
5964: =pod
5965:
5966: =item list_symbs()
5967:
1.485 raeburn 5968: List Content Identifiers
1.329 droeschl 5969:
5970: =cut
5971:
5972: sub list_symbs {
5973: my ($r) = @_;
5974:
1.408 raeburn 5975: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5976: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
5977: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
5978: $r->print(&startContentScreen('tools'));
1.329 droeschl 5979: my $navmap = Apache::lonnavmaps::navmap->new();
5980: if (!defined($navmap)) {
5981: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
5982: '<div class="LC_error">'.
5983: &mt('Unable to retrieve information about course contents').
5984: '</div>');
1.408 raeburn 5985: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 5986: } else {
1.484 raeburn 5987: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
5988: &Apache::loncommon::start_data_table().
5989: &Apache::loncommon::start_data_table_header_row().
5990: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
5991: &Apache::loncommon::end_data_table_header_row()."\n");
5992: my $count;
1.329 droeschl 5993: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 5994: $r->print(&Apache::loncommon::start_data_table_row().
5995: '<td>'.$res->compTitle().'</td>'.
5996: '<td>'.$res->symb().'</td>'.
1.521 bisitz 5997: &Apache::loncommon::end_data_table_row());
1.484 raeburn 5998: $count ++;
5999: }
6000: if (!$count) {
6001: $r->print(&Apache::loncommon::start_data_table_row().
6002: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
6003: &Apache::loncommon::end_data_table_row());
1.329 droeschl 6004: }
1.484 raeburn 6005: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 6006: }
1.521 bisitz 6007: $r->print(&endContentScreen());
1.329 droeschl 6008: }
6009:
1.651 raeburn 6010: sub short_urls {
6011: my ($r,$canedit) = @_;
6012: my $crstype = &Apache::loncommon::course_type();
6013: my $formname = 'shortenurl';
6014: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
6015: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
6016: $r->print(&startContentScreen('tools'));
6017: my ($navmap,$errormsg) =
6018: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
6019: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6020: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6021: my (%maps,%resources,%titles);
6022: if (!ref($navmap)) {
6023: $r->print($errormsg.
6024: &endContentScreen());
6025: return '';
6026: } else {
1.652 raeburn 6027: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 6028: $r->rflush();
6029: my $readonly;
6030: if ($canedit) {
1.671 raeburn 6031: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 6032: if ($numnew) {
6033: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
6034: }
6035: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
6036: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
6037: foreach my $error (@{$errors}) {
6038: $r->print('<li>'.$error.'</li>');
6039: }
6040: $r->print('</ul><br />');
6041: }
6042: } else {
6043: $readonly = 1;
6044: }
6045: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
6046: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
1.711 raeburn 6047: undef,undef,undef,undef,undef,\%currtiny,undef,$readonly));
1.651 raeburn 6048: }
6049: $r->print(&endContentScreen());
6050: }
6051:
1.637 raeburn 6052: sub contentverifyform {
6053: my ($r) = @_;
6054: my $crstype = &Apache::loncommon::course_type();
6055: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6056: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
6057: $r->print(&startContentScreen('tools'));
6058: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
6059: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
6060: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
6061: ' <span class="LC_nobreak">'.
6062: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
6063: &mt('No').'</label>'.(' 'x2).
6064: '<label><input type="radio" name="checkstale" value="1" />'.
6065: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 6066: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 6067: '<input type="hidden" value="1" name="tools" />'.
6068: '<input type="hidden" value="1" name="verify" /></p></form>');
6069: $r->print(&endContentScreen());
6070: return;
6071: }
1.329 droeschl 6072:
6073: sub verifycontent {
1.637 raeburn 6074: my ($r,$checkstale) = @_;
1.408 raeburn 6075: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 6076: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6077: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 6078: $r->print(&startContentScreen('tools'));
6079: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 6080: $hashtied=0;
6081: undef %alreadyseen;
6082: %alreadyseen=();
6083: &tiehash();
1.484 raeburn 6084:
1.329 droeschl 6085: foreach my $key (keys(%hash)) {
6086: if ($hash{$key}=~/\.(page|sequence)$/) {
6087: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
6088: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 6089: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 6090: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 6091: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 6092: }
6093: }
6094: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 6095: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 6096: }
6097: }
6098: &untiehash();
1.442 www 6099: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 6100: $r->print(&endContentScreen());
1.329 droeschl 6101: }
6102:
6103: sub devalidateversioncache {
6104: my $src=shift;
6105: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
6106: &Apache::lonnet::clutter($src));
6107: }
6108:
6109: sub checkversions {
1.611 raeburn 6110: my ($r,$canedit) = @_;
1.408 raeburn 6111: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 6112: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
6113: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 6114: $r->print(&startContentScreen('tools'));
1.442 www 6115:
1.329 droeschl 6116: my $header='';
6117: my $startsel='';
6118: my $monthsel='';
6119: my $weeksel='';
6120: my $daysel='';
6121: my $allsel='';
6122: my %changes=();
6123: my $starttime=0;
6124: my $haschanged=0;
6125: my %setversions=&Apache::lonnet::dump('resourceversions',
6126: $env{'course.'.$env{'request.course.id'}.'.domain'},
6127: $env{'course.'.$env{'request.course.id'}.'.num'});
6128:
6129: $hashtied=0;
6130: &tiehash();
1.611 raeburn 6131: if ($canedit) {
6132: my %newsetversions=();
6133: if ($env{'form.setmostrecent'}) {
6134: $haschanged=1;
6135: foreach my $key (keys(%hash)) {
6136: if ($key=~/^ids\_(\/res\/.+)$/) {
6137: $newsetversions{$1}='mostrecent';
6138: &devalidateversioncache($1);
6139: }
6140: }
6141: } elsif ($env{'form.setcurrent'}) {
6142: $haschanged=1;
6143: foreach my $key (keys(%hash)) {
6144: if ($key=~/^ids\_(\/res\/.+)$/) {
6145: my $getvers=&Apache::lonnet::getversion($1);
6146: if ($getvers>0) {
6147: $newsetversions{$1}=$getvers;
6148: &devalidateversioncache($1);
6149: }
6150: }
1.329 droeschl 6151: }
1.611 raeburn 6152: } elsif ($env{'form.setversions'}) {
6153: $haschanged=1;
6154: foreach my $key (keys(%env)) {
6155: if ($key=~/^form\.set_version_(.+)$/) {
6156: my $src=$1;
6157: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
6158: $newsetversions{$src}=$env{$key};
6159: &devalidateversioncache($src);
6160: }
6161: }
1.329 droeschl 6162: }
1.611 raeburn 6163: }
6164: if ($haschanged) {
6165: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
6166: $env{'course.'.$env{'request.course.id'}.'.domain'},
6167: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
6168: $r->print(&Apache::loncommon::confirmwrapper(
6169: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
6170: } else {
6171: $r->print(&Apache::loncommon::confirmwrapper(
6172: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 6173: }
1.611 raeburn 6174: &mark_hash_old();
6175: }
6176: &changewarning($r,'');
1.329 droeschl 6177: }
6178: if ($env{'form.timerange'} eq 'all') {
6179: # show all documents
1.549 raeburn 6180: $header=&mt('All content in '.$crstype);
1.521 bisitz 6181: $allsel=' selected="selected"';
1.329 droeschl 6182: foreach my $key (keys(%hash)) {
6183: if ($key=~/^ids\_(\/res\/.+)$/) {
6184: my $src=$1;
6185: $changes{$src}=1;
6186: }
6187: }
6188: } else {
6189: # show documents which changed
6190: %changes=&Apache::lonnet::dump
6191: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
6192: $env{'course.'.$env{'request.course.id'}.'.num'});
6193: my $firstkey=(keys(%changes))[0];
6194: unless ($firstkey=~/^error\:/) {
6195: unless ($env{'form.timerange'}) {
6196: $env{'form.timerange'}=604800;
6197: }
6198: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
6199: .&mt('seconds');
6200: if ($env{'form.timerange'}==-1) {
6201: $seltext='since start of course';
1.521 bisitz 6202: $startsel=' selected="selected"';
1.329 droeschl 6203: $env{'form.timerange'}=time;
6204: }
6205: $starttime=time-$env{'form.timerange'};
6206: if ($env{'form.timerange'}==2592000) {
6207: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6208: $monthsel=' selected="selected"';
1.329 droeschl 6209: } elsif ($env{'form.timerange'}==604800) {
6210: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6211: $weeksel=' selected="selected"';
1.329 droeschl 6212: } elsif ($env{'form.timerange'}==86400) {
6213: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6214: $daysel=' selected="selected"';
1.329 droeschl 6215: }
6216: $header=&mt('Content changed').' '.$seltext;
6217: } else {
6218: $header=&mt('No content modifications yet.');
6219: }
6220: }
6221: %setversions=&Apache::lonnet::dump('resourceversions',
6222: $env{'course.'.$env{'request.course.id'}.'.domain'},
6223: $env{'course.'.$env{'request.course.id'}.'.num'});
6224: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 6225: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 6226: 'lm' => 'Version changes since last Month',
6227: 'lw' => 'Version changes since last Week',
6228: 'sy' => 'Version changes since Yesterday',
6229: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 6230: 'cd' => 'Change display',
1.329 droeschl 6231: 'sd' => 'Display',
6232: 'fi' => 'File',
6233: 'md' => 'Modification Date',
6234: 'mr' => 'Most recently published Version',
1.408 raeburn 6235: 've' => 'Version used in '.$crstype,
6236: 'vu' => 'Set Version to be used in '.$crstype,
6237: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 6238: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
6239: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 6240: 'di' => 'Differences',
1.484 raeburn 6241: 'save' => 'Save changes',
6242: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 6243: 'act' => 'Actions');
1.611 raeburn 6244: my ($disabled,$readonly);
6245: unless ($canedit) {
6246: $disabled = 'disabled="disabled"';
6247: $readonly = 1;
6248: }
1.329 droeschl 6249: $r->print(<<ENDHEADERS);
1.484 raeburn 6250: <h4 class="LC_info">$header</h4>
1.329 droeschl 6251: <form action="/adm/coursedocs" method="post">
6252: <input type="hidden" name="versions" value="1" />
1.484 raeburn 6253: <div class="LC_left_float">
1.479 golterma 6254: <fieldset>
1.484 raeburn 6255: <legend>$lt{'cd'}</legend>
1.329 droeschl 6256: <select name="timerange">
1.521 bisitz 6257: <option value='all'$allsel>$lt{'al'}</option>
6258: <option value="-1"$startsel>$lt{'st'}</option>
6259: <option value="2592000"$monthsel>$lt{'lm'}</option>
6260: <option value="604800"$weeksel>$lt{'lw'}</option>
6261: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 6262: </select>
6263: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 6264: </fieldset>
6265: </div>
6266: <div class="LC_left_float">
6267: <fieldset>
6268: <legend>$lt{'act'}</legend>
1.611 raeburn 6269: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
6270: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 6271: </fieldset>
6272: </div>
6273: <br clear="all" />
6274: <hr />
6275: <h4>$lt{'vers'}</h4>
1.329 droeschl 6276: ENDHEADERS
1.479 golterma 6277: #number of columns for version history
1.571 raeburn 6278: my %changedbytime;
6279: foreach my $key (keys(%changes)) {
6280: #excludes not versionable problems from resource version history:
6281: next if ($key =~ /^\/res\/lib\/templates/);
6282: my $chg;
6283: if ($env{'form.timerange'} eq 'all') {
6284: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6285: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
6286: } else {
6287: $chg = $changes{$key};
6288: next if ($chg < $starttime);
6289: }
6290: push(@{$changedbytime{$chg}},$key);
6291: }
6292: if (keys(%changedbytime) == 0) {
6293: &untiehash();
6294: $r->print(&mt('No content changes in imported content in specified time frame').
6295: &endContentScreen());
6296: return;
6297: }
1.479 golterma 6298: $r->print(
1.611 raeburn 6299: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6300: &Apache::loncommon::start_data_table().
6301: &Apache::loncommon::start_data_table_header_row().
6302: '<th>'.&mt('Resources').'</th>'.
6303: "<th>$lt{'mr'}</th>".
6304: "<th>$lt{'ve'}</th>".
6305: "<th>$lt{'vu'}</th>".
6306: '<th>'.&mt('History').'</th>'.
6307: &Apache::loncommon::end_data_table_header_row()
6308: );
1.571 raeburn 6309: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
6310: foreach my $key (sort(@{$changedbytime{$chg}})) {
6311: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6312: my $currentversion=&Apache::lonnet::getversion($key);
6313: if ($currentversion<0) {
6314: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
6315: }
6316: my $linkurl=&Apache::lonnet::clutter($key);
6317: $r->print(
6318: &Apache::loncommon::start_data_table_row().
6319: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
6320: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
6321: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
6322: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
6323: '<td align="right">'
6324: );
6325: # Used in course
6326: my $usedversion=$hash{'version_'.$linkurl};
6327: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 6328: if ($usedversion != $currentversion) {
1.479 golterma 6329: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 6330: } else {
1.479 golterma 6331: $r->print($usedversion);
6332: }
1.329 droeschl 6333: } else {
1.521 bisitz 6334: $r->print($currentversion);
1.329 droeschl 6335: }
1.571 raeburn 6336: $r->print('</td><td title="'.$lt{'vu'}.'">');
6337: # Set version
6338: $r->print(&Apache::loncommon::select_form(
6339: $setversions{$linkurl},
6340: 'set_version_'.$linkurl,
6341: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
6342: '' => '',
6343: 'mostrecent' => &mt('most recent'),
1.611 raeburn 6344: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 6345: my $lastold=1;
6346: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
6347: my $url=$root.'.'.$prevvers.'.'.$extension;
6348: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
6349: $lastold=$prevvers;
6350: }
6351: }
6352: $r->print('</td>');
6353: # List all available versions
6354: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
6355: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
6356: my $url=$root.'.'.$prevvers.'.'.$extension;
6357: $r->print(
6358: '<span class="LC_nobreak">'
6359: .'<a href="'.&Apache::lonnet::clutter($url).'">'
6360: .&mt('Version [_1]',$prevvers).'</a>'
6361: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 6362: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 6363: .')');
6364: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
6365: $r->print(
6366: ' <a href="/adm/diff?filename='.
6367: &Apache::lonnet::clutter($root.'.'.$extension).
6368: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
6369: '" target="diffs">'.&mt('Diffs').'</a>');
6370: }
6371: $r->print('</span><br />');
1.329 droeschl 6372: }
1.571 raeburn 6373: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 6374: }
1.329 droeschl 6375: }
1.521 bisitz 6376: $r->print(
6377: &Apache::loncommon::end_data_table().
1.611 raeburn 6378: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6379: '</form>'
6380: );
1.329 droeschl 6381:
6382: &untiehash();
1.521 bisitz 6383: $r->print(&endContentScreen());
1.571 raeburn 6384: return;
1.329 droeschl 6385: }
6386:
6387: sub mark_hash_old {
6388: my $retie_hash=0;
6389: if ($hashtied) {
6390: $retie_hash=1;
6391: &untiehash();
6392: }
6393: &tiehash('write');
6394: $hash{'old'}=1;
6395: &untiehash();
6396: if ($retie_hash) { &tiehash(); }
6397: }
6398:
6399: sub is_hash_old {
6400: my $untie_hash=0;
6401: if (!$hashtied) {
6402: $untie_hash=1;
6403: &tiehash();
6404: }
6405: my $return=$hash{'old'};
6406: if ($untie_hash) { &untiehash(); }
6407: return $return;
6408: }
6409:
6410: sub changewarning {
6411: my ($r,$postexec,$message,$url)=@_;
6412: if (!&is_hash_old()) { return; }
6413: my $pathvar='folderpath';
6414: my $path=&escape($env{'form.folderpath'});
6415: if (!defined($url)) {
6416: $url='/adm/coursedocs?'.$pathvar.'='.$path;
6417: }
6418: my $course_type = &Apache::loncommon::course_type();
6419: if (!defined($message)) {
6420: $message='Changes will become active for your current session after [_1], or the next time you log in.';
6421: }
1.653 raeburn 6422: my $windowname = 'loncapaclient';
6423: if ($env{'request.lti.login'}) {
6424: $windowname .= 'lti';
6425: }
1.329 droeschl 6426: $r->print("\n\n".
1.372 bisitz 6427: '<script type="text/javascript">'."\n".
6428: '// <![CDATA['."\n".
6429: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
6430: '// ]]>'."\n".
1.369 bisitz 6431: '</script>'."\n".
1.653 raeburn 6432: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 6433: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 6434: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 6435: &mt($message,' <input type="hidden" name="'.
6436: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 6437: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 6438: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 6439: }
6440:
6441:
6442: sub init_breadcrumbs {
1.571 raeburn 6443: my ($form,$text,$help)=@_;
1.329 droeschl 6444: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 6445: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 6446: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 6447: faq=>273,
6448: bug=>'Instructor Interface',
1.571 raeburn 6449: help => $help});
1.329 droeschl 6450: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
6451: text=>$text,
6452: faq=>273,
6453: bug=>'Instructor Interface'});
6454: }
6455:
1.441 www 6456: # subroutine to list form elements
6457: sub create_list_elements {
6458: my @formarr = @_;
6459: my $list = '';
1.501 raeburn 6460: foreach my $button (@formarr){
6461: foreach my $picture (keys(%{$button})) {
6462: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 6463: }
6464: }
6465: return $list;
6466: }
1.329 droeschl 6467:
1.441 www 6468: # subroutine to create ul from list elements
6469: sub create_form_ul {
6470: my $list = shift;
6471: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
6472: return $ul;
6473: }
1.329 droeschl 6474:
1.442 www 6475: #
6476: # Start tabs
6477: #
6478:
6479: sub startContentScreen {
1.484 raeburn 6480: my ($mode) = @_;
6481: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 6482: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 6483: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
6484: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
6485: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
6486: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
6487: } else {
1.549 raeburn 6488: $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 6489: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
6490: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
6491: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
6492: }
6493: $output .= "\n".'</ul>'."\n";
6494: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
6495: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
6496: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
6497: return $output;
1.442 www 6498: }
6499:
6500: #
6501: # End tabs
6502: #
6503:
6504: sub endContentScreen {
1.484 raeburn 6505: return '</div></div></div>';
1.442 www 6506: }
1.329 droeschl 6507:
1.446 www 6508: sub supplemental_base {
1.548 raeburn 6509: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 6510: }
6511:
1.329 droeschl 6512: sub handler {
6513: my $r = shift;
6514: &Apache::loncommon::content_type($r,'text/html');
6515: $r->send_http_header;
6516: return OK if $r->header_only;
1.484 raeburn 6517:
6518: # get course data
1.408 raeburn 6519: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 6520: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
6521: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.712 raeburn 6522: my $coursehome=$env{'course.'.$env{'request.course.id'}.'.home'};
1.484 raeburn 6523:
1.606 raeburn 6524: # get docroot
6525: my $londocroot = $r->dir_config('lonDocRoot');
6526:
1.484 raeburn 6527: # graphics settings
6528: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 6529:
1.443 www 6530: #
1.329 droeschl 6531: # --------------------------------------------- Initialize help topics for this
6532: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 6533: 'Adding_External_Resource','Adding_External_Tool',
6534: 'Navigate_Content','Adding_Folders','Docs_Overview',
6535: 'Load_Map','Supplemental','Score_Upload_Form',
6536: 'Adding_Pages','Importing_LON-CAPA_Resource',
6537: 'Importing_IMS_Course','Uploading_From_Harddrive',
1.706 raeburn 6538: 'Course_Roster','Web_Page','Dropbox','Simple_Problem',
6539: 'Standard_Problem','Course_Resources',
6540: 'Search_LON-CAPA_Resource','Import_Stored_Links') {
1.329 droeschl 6541: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
6542: }
6543: # Composite help files
6544: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
6545: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
6546: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
6547: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
6548: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
6549: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 6550: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 6551: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 6552: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 6553: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 6554:
1.611 raeburn 6555: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 6556: # does this user have privileges to modify content.
6557: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 6558: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 6559: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6560: $allowed = 1;
1.682 raeburn 6561: }
6562: $canedit = 1;
6563: $canview = 1;
6564: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
6565: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
6566: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6567: $allowed = 1;
6568: }
1.682 raeburn 6569: $canview = 1;
1.611 raeburn 6570: }
6571: unless ($canedit) {
6572: $disabled = ' disabled="disabled"';
1.472 raeburn 6573: }
1.582 raeburn 6574: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 6575: if ($env{'form.inhibitmenu'}) {
6576: unless ($env{'form.inhibitmenu'} eq 'yes') {
6577: delete($env{'form.inhibitmenu'});
6578: }
6579: }
6580:
1.582 raeburn 6581: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 6582: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 6583: if (!$canedit) {
6584: &verifycontent($r);
6585: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
6586: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
6587: text=>'Results',
6588: faq=>273,
6589: bug=>'Instructor Interface'});
6590: &verifycontent($r,$env{'form.checkstale'});
6591: } else {
6592: &contentverifyform($r);
6593: }
1.329 droeschl 6594: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 6595: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 6596: &list_symbs($r);
1.651 raeburn 6597: } elsif ($allowed && $env{'form.shorturls'}) {
6598: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
6599: &short_urls($r,$canedit);
1.329 droeschl 6600: } elsif ($allowed && $env{'form.docslog'}) {
6601: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 6602: my $folder = $env{'form.folder'};
6603: if ($folder eq '') {
6604: $folder='default';
6605: }
1.611 raeburn 6606: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 6607: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 6608: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 6609: &checkversions($r,$canedit);
6610: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.709 raeburn 6611: &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
1.329 droeschl 6612: &dumpcourse($r);
1.712 raeburn 6613: } elsif (($canedit || $canview) && ($env{'form.copyauthored'})) {
6614: &init_breadcrumbs('copyauthored','Copy from Course Authoring to User Authoring');
6615: my $readonly;
6616: if (!$canedit) {
6617: $readonly = 1;
6618: }
6619: ©crsauthored($r,$coursenum,$coursedom,$coursehome,$readonly);
1.611 raeburn 6620: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 6621: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 6622: &Apache::imsexport::exportcourse($r);
1.329 droeschl 6623: } else {
1.611 raeburn 6624: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 6625: $noendpage = 1;
6626: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
6627: if ($redirect) {
6628: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
6629: my $container = 'sequence';
6630: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
6631: $is_random_order,$container) =
6632: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
6633: my (@folders)=split('&',$env{'form.folderpath'});
6634: $env{'form.foldername'}=&unescape(pop(@folders));
6635: my $folder=pop(@folders);
6636: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
6637: $folder.'.'.$container);
6638: my $warning;
6639: if ($fatal) {
6640: if ($container eq 'page') {
6641: $warning = &mt('An error occurred retrieving the contents of the current page.');
6642: } else {
6643: $warning = &mt('An error occurred retrieving the contents of the current folder.');
6644: }
6645: } else {
6646: my $url = $redirect;
6647: my $srcfile = $londocroot.$url;
6648: $url =~ s{^/priv/}{/res/};
6649: my $targetfile = $londocroot.$url;
6650: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
6651: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
6652: $env{'form.folder'} = $folder;
6653: &snapshotbefore();
6654: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
6655: my $ext = 'false';
6656: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
6657: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
6658: ':'.$ext.':normal:res';
6659: push(@LONCAPA::map::order,$newidx);
6660: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
6661: 'string_yesno');
6662: &remember_parms($newidx,'hiddenresource','set','yes');
6663: ($errtext,$fatal) =
6664: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
6665: &log_differences($plain);
6666: &mark_hash_old();
6667: $r->internal_redirect($redirect);
6668: return OK;
6669: }
1.654 raeburn 6670: } else {
6671: $r->internal_redirect($redirect);
1.606 raeburn 6672: }
6673: }
6674: }
1.445 www 6675: #
6676: # Done catching special calls
1.484 raeburn 6677: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 6678: # Get the parameters that may be needed
6679: #
6680: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 6681: ['folderpath','title',
1.519 raeburn 6682: 'forcesupplement','forcestandard',
1.510 raeburn 6683: 'tools','symb','command','supppath']);
1.445 www 6684:
1.635 raeburn 6685: foreach my $item ('forcesupplement','forcestandard','tools') {
6686: next if ($env{'form.'.$item} eq '');
6687: unless ($env{'form.'.$item} eq '1') {
6688: delete($env{'form.'.$item});
6689: }
6690: }
6691:
6692: if ($env{'form.command'}) {
6693: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
6694: delete($env{'form.command'});
6695: }
6696: }
6697:
6698: if ($env{'form.symb'}) {
6699: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
6700: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
6701: delete($env{'form.symb'});
6702: }
6703: }
6704:
1.445 www 6705: # standard=1: this is a "new-style" course with an uploaded map as top level
6706: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 6707:
6708: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 6709:
1.484 raeburn 6710: # Decide whether this should display supplemental or main content or utilities
1.445 www 6711: # supplementalflag=1: show supplemental documents
6712: # supplementalflag=0: show standard documents
1.484 raeburn 6713: # toolsflag=1: show utilities
1.445 www 6714:
1.561 raeburn 6715: my $unesc_folderpath = &unescape($env{'form.folderpath'});
6716: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
6717: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 6718: $supplementalflag=0;
6719: }
6720: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
6721: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
1.705 raeburn 6722: unless (($supplementalflag) ||
6723: ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
6724: unless ($allowed) { $supplementalflag=1; }
6725: unless ($standard) { $supplementalflag=1; }
6726: }
1.484 raeburn 6727: my $toolsflag=0;
6728: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 6729:
1.635 raeburn 6730: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 6731: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 6732: }
6733:
1.685 raeburn 6734: my $backto_supppath;
1.635 raeburn 6735: if ($env{'form.supppath'} ne '') {
1.685 raeburn 6736: if ($supplementalflag && $allowed) {
6737: $backto_supppath = &validate_supppath($coursenum,$coursedom);
6738: }
1.635 raeburn 6739: }
6740:
1.329 droeschl 6741: my $script='';
6742: my $showdoc=0;
1.457 raeburn 6743: my $addentries = {};
1.475 raeburn 6744: my $container;
1.329 droeschl 6745: my $containertag;
1.508 raeburn 6746: my $pathitem;
1.598 raeburn 6747: my %ltitools;
1.699 raeburn 6748: my $posslti;
1.617 raeburn 6749: my $hiddentop;
1.615 raeburn 6750: my $navmap;
1.617 raeburn 6751: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 6752:
1.464 www 6753: # Do we directly jump somewhere?
1.525 raeburn 6754: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 6755: if ($env{'form.symb'} ne '') {
1.522 raeburn 6756: $env{'form.folderpath'}=
1.617 raeburn 6757: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 6758: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 6759: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 6760: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 6761: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 6762: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 6763: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 6764: }
1.472 raeburn 6765: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 6766: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 6767: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 6768: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 6769: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 6770: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
6771: } elsif ($env{'form.command'} eq 'contents') {
6772: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
6773: } elsif ($env{'form.command'} eq 'home') {
6774: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 6775: }
6776:
1.525 raeburn 6777:
1.445 www 6778: # Where do we store these for when we come back?
6779: my $stored_folderpath='docs_folderpath';
6780: if ($supplementalflag) {
6781: $stored_folderpath='docs_sup_folderpath';
6782: }
1.464 www 6783:
1.519 raeburn 6784: # No folderpath, and in edit mode, see if we have something stored
6785: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 6786: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 6787: {'folderpath' => 'scalar'});
1.615 raeburn 6788:
6789: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
6790: if ($supplementalflag) {
6791: undef($env{'form.folderpath'}) if ($1 eq 'default');
6792: } else {
6793: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
6794: }
6795: } else {
1.523 raeburn 6796: undef($env{'form.folderpath'});
6797: }
1.677 raeburn 6798: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 6799: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 6800: }
1.329 droeschl 6801: }
1.706 raeburn 6802:
6803: # Set folderpath if we are not allowed to make changes and this is supplemental content
1.705 raeburn 6804: if ((!$allowed) && ($supplementalflag)) {
1.446 www 6805: unless ($env{'form.folderpath'} =~ /^supplemental/) {
6806: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 6807: }
6808: }
1.446 www 6809: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 6810: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 6811: $env{'form.folderpath'} = &supplemental_base()
6812: .'&'.
1.329 droeschl 6813: $env{'form.folderpath'};
6814: }
1.685 raeburn 6815: # If allowed and user's role is not advanced check folderpath is not hidden
6816: my $hidden_and_empty;
1.687 raeburn 6817: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 6818: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 6819: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 6820: my $folder = $pathitems[-2];
6821: if ($folder eq '') {
6822: undef($env{'form.folderpath'});
6823: } else {
6824: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 6825: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 6826: $folderurl .= '.page';
6827: } else {
6828: $folderurl .= '.sequence';
6829: }
1.685 raeburn 6830: if ($supplementalflag) {
6831: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
6832: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 6833: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 6834: if (ref($supplemental) eq 'HASH') {
6835: my ($suppmap,$suppmapnum);
6836: if ($folder eq 'supplemental') {
6837: $suppmap = 'default';
6838: $suppmapnum = 0;
6839: } elsif ($folder =~ /^supplemental_(\d+)$/) {
6840: $suppmap = $1;
6841: $suppmapnum = $suppmap;
6842: }
6843: if ($hiddenfolder) {
6844: my $hascontent;
6845: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
6846: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
6847: $hascontent = 1;
6848: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
6849: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
6850: if ($id =~ /^$suppmapnum\:/) {
6851: $hascontent = 1;
6852: last;
6853: }
6854: }
6855: }
6856: last if ($hascontent);
6857: }
6858: unless ($hascontent) {
6859: if ($foldername ne '') {
6860: $hidden_and_empty = $foldername;
6861: } else {
6862: $hidden_and_empty = $folder;
6863: }
6864: }
6865: }
6866: }
6867: } else {
6868: unless (ref($navmap)) {
6869: $navmap = Apache::lonnavmaps::navmap->new();
6870: }
6871: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
6872: $foldername = &HTML::Entities::decode(&unescape($foldername));
6873: if (ref($navmap)) {
6874: if ($hiddenfolder ||
6875: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
6876: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
6877: unless (@resources) {
6878: if ($foldername ne '') {
6879: $hidden_and_empty = $foldername;
6880: } else {
6881: $hidden_and_empty = $folder;
6882: }
6883: }
6884: }
6885: }
1.617 raeburn 6886: }
1.685 raeburn 6887: if ($hidden_and_empty ne '') {
6888: splice(@pathitems,-2);
6889: if (@pathitems) {
6890: $env{'form.folderpath'} = join('&',@pathitems);
6891: } else {
6892: undef($env{'form.folderpath'});
1.615 raeburn 6893: }
6894: }
6895: }
6896: }
6897:
1.446 www 6898: # If after all of this, we still don't have any paths, make them
1.519 raeburn 6899: unless ($env{'form.folderpath'}) {
1.446 www 6900: if ($supplementalflag) {
6901: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 6902: } elsif ($allowed) {
6903: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 6904: }
1.472 raeburn 6905: }
1.446 www 6906:
1.445 www 6907: # Store this
1.484 raeburn 6908: unless ($toolsflag) {
1.615 raeburn 6909: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 6910: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 6911: {'folderpath' => 'scalar'});
1.510 raeburn 6912: }
1.519 raeburn 6913: my $folderpath;
1.484 raeburn 6914: if ($env{'form.folderpath'}) {
1.519 raeburn 6915: $folderpath = $env{'form.folderpath'};
6916: my (@folders)=split('&',$env{'form.folderpath'});
6917: $env{'form.foldername'}=&unescape(pop(@folders));
6918: if ($env{'form.foldername'} =~ /\:1$/) {
6919: $container = 'page';
6920: } else {
6921: $container = 'sequence';
6922: }
6923: $env{'form.folder'}=pop(@folders);
1.484 raeburn 6924: } else {
1.519 raeburn 6925: if ($env{'form.folder'} eq '' ||
6926: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 6927: if ($env{'form.folder'} eq 'supplemental') {
6928: $folderpath=&supplemental_base();
6929: } elsif (!$hiddentop) {
6930: $folderpath='default&'.
6931: &escape(&mt('Main Content').':::::');
6932: }
1.484 raeburn 6933: }
6934: }
1.519 raeburn 6935: $containertag = '<input type="hidden" name="folderpath" value="" />';
6936: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 6937: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
6938: $showdoc='/'.$1;
6939: }
6940: if ($showdoc) { # got called in sequence from course
6941: $allowed=0;
6942: } else {
1.611 raeburn 6943: if ($canedit) {
1.484 raeburn 6944: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
6945: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 6946: }
6947: }
1.329 droeschl 6948: }
6949:
1.344 bisitz 6950: # get personal data
1.329 droeschl 6951: my $uname=$env{'user.name'};
6952: my $udom=$env{'user.domain'};
6953: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
6954:
6955: if ($allowed) {
1.484 raeburn 6956: if ($toolsflag) {
6957: $script .= &inject_data_js();
6958: my ($home,$other,%outhash)=&authorhosts();
6959: if (!$home && $other) {
6960: my @hosts;
6961: foreach my $aurole (keys(%outhash)) {
6962: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6963: push(@hosts,$outhash{$aurole});
6964: }
6965: }
6966: $script .= &dump_switchserver_js(@hosts);
6967: }
1.458 raeburn 6968: } else {
1.570 raeburn 6969: my $tid = 1;
1.484 raeburn 6970: my @tabids;
6971: if ($supplementalflag) {
1.655 raeburn 6972: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 6973: $tid = 2;
1.484 raeburn 6974: } else {
6975: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 6976: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 6977: unshift(@tabids,'001');
6978: push(@tabids,('dd1','ee1'));
6979: }
1.458 raeburn 6980: }
1.484 raeburn 6981: my $tabidstr = join("','",@tabids);
1.699 raeburn 6982: my (%domtools,%crstools);
6983: my %tooltypes = &Apache::loncommon::usable_exttools();
6984: if ($tooltypes{'dom'}) {
6985: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
6986: }
6987: if ($tooltypes{'crs'}) {
6988: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
6989: }
6990: %ltitools = (
6991: dom => \%domtools,
6992: crs => \%crstools,
6993: );
6994: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622 raeburn 6995: my $hostname = $r->hostname();
1.606 raeburn 6996: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 6997: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 6998: &history_tab_js().
6999: &inject_data_js().
1.570 raeburn 7000: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 7001: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 7002: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
7003: if ($hidden_and_empty ne '') {
7004: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
7005: $hidden_and_empty);
7006: $onload .= "javascript:alert('".&js_escape($alert)."');";
7007: }
1.484 raeburn 7008: $addentries = {
1.685 raeburn 7009: onload => $onload,
1.484 raeburn 7010: };
1.458 raeburn 7011: }
1.538 raeburn 7012: $script .= &paste_popup_js();
1.501 raeburn 7013: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
7014: &mt('Switch server?');
7015:
7016:
1.329 droeschl 7017: }
7018: # -------------------------------------------------------------------- Body tag
1.369 bisitz 7019: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 7020: .'// <![CDATA['."\n"
7021: .$script."\n"
7022: .'// ]]>'."\n"
1.595 musolffc 7023: .'</script>'."\n"
7024: .'<script type="text/javascript"
7025: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 7026:
7027: # Breadcrumbs
7028: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 7029:
7030: if ($showdoc) {
1.682 raeburn 7031: my $args;
7032: if ($supplementalflag) {
1.687 raeburn 7033: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
7034: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.705 raeburn 7035: $args = {'bread_crumbs' => $brcrum,
7036: 'bread_crumbs_nomenu' => 1};
1.682 raeburn 7037: } else {
7038: $args = {'force_register' => $showdoc};
7039: }
7040: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 7041: } elsif ($toolsflag) {
1.611 raeburn 7042: my ($breadtext,$breadtitle);
1.617 raeburn 7043: $breadtext = "$crstype Editor";
1.611 raeburn 7044: if ($canedit) {
7045: $breadtitle = 'Editing '.$crstype.' Contents';
7046: } else {
7047: $breadtext .= ' (View-only mode)';
7048: $breadtitle = 'Viewing '.$crstype.' Contents';
7049: }
1.571 raeburn 7050: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7051: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 7052: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
7053: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7054: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7055: $breadtitle)
1.571 raeburn 7056: );
1.510 raeburn 7057: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 7058: unless ($env{'request.role.adv'}) {
7059: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
7060: $r->internal_redirect('/adm/navmaps');
7061: return OK;
7062: }
7063: }
1.510 raeburn 7064: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
1.705 raeburn 7065: my $args = {'bread_crumbs' => $brcrum};
7066: unless (($env{'form.folderpath'} eq '') ||
7067: ($env{'form.folder'} eq 'supplemental')) {
7068: $args->{'bread_crumbs_nomenu'} = 1;
7069: }
1.510 raeburn 7070: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
1.705 raeburn 7071: $args));
1.510 raeburn 7072: } else {
1.611 raeburn 7073: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 7074: $breadtext = "$crstype Editor";
1.611 raeburn 7075: if ($canedit) {
7076: $breadtitle = 'Editing '.$crstype.' Contents';
7077: $helpitem = 'Docs_Adding_Course_Doc';
7078: } else {
7079: $breadtext .= ' (View-only mode)';
7080: $breadtitle = 'Viewing '.$crstype.' Contents';
7081: $helpitem = 'Docs_Viewing_Course_Doc';
7082: }
1.392 raeburn 7083: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7084: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 7085: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 7086: {'add_entries' => $addentries}
7087: )
1.392 raeburn 7088: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7089: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7090: $breadtitle,
7091: $helpitem)
1.392 raeburn 7092: );
7093: }
1.364 bisitz 7094:
1.329 droeschl 7095: my %allfiles = ();
7096: my %codebase = ();
1.440 raeburn 7097: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 7098: if ($canedit) {
1.684 raeburn 7099: undef($suppchanges);
1.329 droeschl 7100: if (($env{'form.uploaddoc.filename'}) &&
7101: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 7102: my $context = $1;
7103: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 7104: undef($hadchanges);
1.440 raeburn 7105: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 7106: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 7107: undef($navmap);
1.329 droeschl 7108: if ($hadchanges) {
7109: &mark_hash_old();
7110: }
1.684 raeburn 7111: if ($suppchanges) {
7112: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
7113: undef($suppchanges);
7114: }
1.440 raeburn 7115: $r->print($upload_output);
7116: } elsif ($env{'form.phase'} eq 'upload_embedded') {
7117: # Process file upload - phase two - upload embedded objects
7118: $uploadphase = 'check_embedded';
7119: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
7120: my $state = &embedded_form_elems($uploadphase,$primaryurl,
7121: $env{'form.newidx'});
7122: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7123: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7124: my ($destination,$dir_root) = &embedded_destination();
7125: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
7126: my $actionurl = '/adm/coursedocs';
1.630 raeburn 7127: my ($result,$flag) =
1.440 raeburn 7128: &Apache::loncommon::upload_embedded('coursedoc',$destination,
7129: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
7130: $actionurl);
7131: $r->print($result.&return_to_editor());
7132: } elsif ($env{'form.phase'} eq 'check_embedded') {
7133: # Process file upload - phase three - modify references in HTML file
7134: $uploadphase = 'modified_orightml';
7135: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7136: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7137: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 7138: my $result =
1.482 raeburn 7139: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
7140: $docuname,$docudom,undef,
7141: $dir_root);
1.630 raeburn 7142: $r->print($result.&return_to_editor());
1.476 raeburn 7143: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
7144: $uploadphase = 'decompress_phase_one';
7145: $r->print(&decompression_phase_one().
7146: &return_to_editor());
7147: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
7148: $uploadphase = 'decompress_phase_two';
7149: $r->print(&decompression_phase_two().
7150: &return_to_editor());
1.329 droeschl 7151: }
7152: }
7153:
1.484 raeburn 7154: if ($allowed && $toolsflag) {
7155: $r->print(&startContentScreen('tools'));
1.708 raeburn 7156: $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom));
1.484 raeburn 7157: $r->print(&endContentScreen());
7158: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 7159: # -----------------------------------------------------------------------------
7160: my %lt=&Apache::lonlocal::texthash(
7161: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 7162: 'upfi' => 'Upload File',
1.553 raeburn 7163: 'upld' => 'Upload Content',
1.706 raeburn 7164: 'srch' => 'Search Repository',
7165: 'impo' => 'Import from Repository',
1.487 raeburn 7166: 'lnks' => 'Import from Stored Links',
1.502 raeburn 7167: 'impm' => 'Import from Assembled Map',
1.630 raeburn 7168: 'imcr' => 'Import from Course Resources',
1.598 raeburn 7169: 'extr' => 'External Resource',
7170: 'extt' => 'External Tool',
1.329 droeschl 7171: 'selm' => 'Select Map',
7172: 'load' => 'Load Map',
7173: 'newf' => 'New Folder',
7174: 'newp' => 'New Composite Page',
7175: 'syll' => 'Syllabus',
1.425 raeburn 7176: 'navc' => 'Table of Contents',
1.343 biermanm 7177: 'sipa' => 'Simple Course Page',
1.329 droeschl 7178: 'sipr' => 'Simple Problem',
1.630 raeburn 7179: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 7180: 'stpr' => 'Standard Problem',
7181: 'news' => 'New sub-directory',
7182: 'crpr' => 'Create Problem',
1.689 raeburn 7183: 'swit' => 'Switch Server',
1.329 droeschl 7184: 'drbx' => 'Drop Box',
1.451 www 7185: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 7186: 'bull' => 'Discussion Board',
1.347 weissno 7187: 'mypi' => 'My Personal Information Page',
1.353 weissno 7188: 'grpo' => 'Group Portfolio',
1.329 droeschl 7189: 'rost' => 'Course Roster',
1.528 raeburn 7190: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 7191: 'imsf' => 'IMS Upload',
7192: 'imsl' => 'Upload IMS package',
1.501 raeburn 7193: 'cms' => 'Origin of IMS package',
7194: 'se' => 'Select',
1.329 droeschl 7195: 'file' => 'File',
7196: 'title' => 'Title',
1.606 raeburn 7197: 'addp' => 'Add Placeholder to course?',
7198: 'uste' => 'Use Template?',
7199: 'fnam' => 'File Name:',
7200: 'loca' => 'Location:',
7201: 'dire' => 'Directory:',
7202: 'cate' => 'Category:',
7203: 'tmpl' => 'Template:',
1.698 raeburn 7204: 'empd' => 'No resources found',
1.329 droeschl 7205: 'comment' => 'Comment',
1.403 raeburn 7206: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 7207: 'bb5' => 'Blackboard 5',
7208: 'bb6' => 'Blackboard 6',
7209: 'angel5' => 'ANGEL 5.5',
7210: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 7211: 'yes' => 'Yes',
7212: 'no' => 'No',
1.618 raeburn 7213: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 7214: );
1.329 droeschl 7215: # -----------------------------------------------------------------------------
1.595 musolffc 7216:
7217: # Calculate free quota space for a user or course. A javascript function checks
7218: # file size to determine if upload should be allowed.
7219: my $quotatype = 'unofficial';
7220: if ($crstype eq 'Community') {
1.601 raeburn 7221: $quotatype = 'community';
7222: } elsif ($crstype eq 'Placement') {
7223: $quotatype = 'placement';
1.595 musolffc 7224: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
7225: $quotatype = 'official';
7226: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
7227: $quotatype = 'textbook';
7228: }
7229: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
7230: 'course',$quotatype); # expressed in MB
7231: my $current_disk_usage = 0;
7232: foreach my $subdir ('docs','supplemental') {
7233: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
7234: "userfiles/$subdir",1); # expressed in kB
7235: }
7236: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 7237: my $usage = $current_disk_usage/1024; # in MB
7238: my $quota = $disk_quota;
7239: my $percent;
7240: if ($disk_quota == 0) {
7241: $percent = 100.0;
7242: } else {
1.619 raeburn 7243: $percent = 100*($usage/$disk_quota);
1.605 raeburn 7244: }
7245: $usage = sprintf("%.2f",$usage);
7246: $quota = sprintf("%.2f",$quota);
7247: $percent = sprintf("%.0f",$percent);
7248: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
7249: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 7250:
1.329 droeschl 7251: my $fileupload=(<<FIUP);
1.605 raeburn 7252: $quotainfo
1.329 droeschl 7253: $lt{'file'}:<br />
7254: FIUP
7255: my $checkbox=(<<CHBO);
7256: <!-- <label>$lt{'parse'}?
7257: <input type="checkbox" name="parserflag" />
7258: </label> -->
7259: <label>
1.611 raeburn 7260: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 7261: </label>
7262: CHBO
1.501 raeburn 7263: my $imsfolder = $env{'form.folder'};
7264: if ($imsfolder eq '') {
7265: $imsfolder = 'default';
7266: }
7267: my $imspform=(<<IMSFORM);
7268: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
7269: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
7270: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 7271: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 7272: <legend>$lt{'imsf'}</legend>
7273: $fileupload
1.702 raeburn 7274: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
7275: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501 raeburn 7276: <br />
7277: <p>
7278: $lt{'cms'}:
1.611 raeburn 7279: <select name="source" $disabled>
1.501 raeburn 7280: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 7281: <option value="bb5">$lt{'bb5'}</option>
7282: <option value="bb6">$lt{'bb6'}</option>
7283: <option value="angel5">$lt{'angel5'}</option>
7284: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 7285: </select>
7286: <input type="hidden" name="folder" value="$imsfolder" />
7287: </p>
7288: <input type="hidden" name="phase" value="one" />
1.611 raeburn 7289: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 7290: </fieldset>
7291: </form>
7292: IMSFORM
1.329 droeschl 7293:
7294: my $fileuploadform=(<<FUFORM);
1.501 raeburn 7295: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
7296: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
7297: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 7298: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 7299: <legend>$lt{'upfi'}</legend>
1.371 tempelho 7300: <input type="hidden" name="active" value="aa" />
1.595 musolffc 7301: $fileupload
1.702 raeburn 7302: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
7303: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 7304: <br />
7305: $lt{'title'}:<br />
1.611 raeburn 7306: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 7307: $pathitem
1.329 droeschl 7308: <input type="hidden" name="cmd" value="upload_default" />
7309: <br />
1.458 raeburn 7310: <span class="LC_nobreak" style="float:left">
1.329 droeschl 7311: $checkbox
7312: </span>
1.501 raeburn 7313: <br clear="all" />
1.611 raeburn 7314: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 7315: </fieldset>
7316: </form>
1.383 tempelho 7317: FUFORM
1.329 droeschl 7318:
1.611 raeburn 7319: my $mapimportjs;
7320: if ($canedit) {
7321: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
7322: } else {
7323: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
7324: }
1.502 raeburn 7325: my $importpubform=(<<SEDFFORM);
1.514 raeburn 7326: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 7327: $lt{'impm'}</a>$help{'Load_Map'}
7328: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 7329: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 7330: <legend>$lt{'impm'}</legend>
1.371 tempelho 7331: <input type="hidden" name="active" value="bb" />
1.502 raeburn 7332: $lt{'copm'}<br />
7333: <span class="LC_nobreak">
7334: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 7335: onfocus="this.blur();$mapimportjs" $disabled />
7336: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
7337: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 7338: </fieldset>
7339: </form>
7340:
1.383 tempelho 7341: SEDFFORM
1.706 raeburn 7342: my ($importcrsresform,$checkcrsres);
7343: if ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'}) {
7344: $checkcrsres = 1;
7345: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'} ne '0') {
7346: my %domdefs=&Apache::lonnet::get_domain_defaults($coursedom);
1.710 raeburn 7347: my $type = lc($env{'course.'.$env{'request.course.id'}.'.type'});
7348: unless (($type eq 'community') || ($type eq 'placement')) {
7349: $type = 'unofficial';
7350: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'} ne '') {
7351: $type = 'official';
7352: } elsif ($env{'course.'.$env{'request.course.id'}.'internal.textbook'} ne '') {
7353: $type = 'textbook';
7354: } else {
7355: $type = 'unofficial';
7356: }
7357: }
7358: if ($domdefs{$type.'crsauthor'}) {
1.706 raeburn 7359: $checkcrsres = 1;
7360: }
7361: }
7362: if ($checkcrsres) {
7363: my ($numdirs,$pickfile) =
7364: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
7365: "resize_scrollbox('contentscroll','1','0');",
7366: undef,'res');
7367: if ($pickfile) {
7368: $importcrsresform=(<<CRSFORM);
1.690 raeburn 7369: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 7370: $lt{'imcr'}</a>$help{'Course_Resources'}
7371: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
7372: <fieldset id="importcrsresform" style="display: none;">
7373: <legend>$lt{'imcr'}</legend>
1.698 raeburn 7374: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 7375: <input type="hidden" name="active" value="bb" />
7376: $pickfile
7377: <p>
1.699 raeburn 7378: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606 raeburn 7379: </p>
7380: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 7381: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 raeburn 7382: </div>
7383: <div id="importcrsresempty" style="display: none;">
7384: <p>
7385: $lt{'empd'}
7386: </p>
7387: </div>
1.606 raeburn 7388: </fieldset>
7389: </form>
7390: CRSFORM
1.706 raeburn 7391: }
1.606 raeburn 7392: }
7393:
1.611 raeburn 7394: my $fromstoredjs;
7395: if ($canedit) {
7396: $fromstoredjs = 'open_StoredLinks_Import()';
7397: } else {
7398: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
7399: }
7400:
1.502 raeburn 7401: my @importpubforma = (
1.706 raeburn 7402: { '<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 7403: { '<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 7404: { '<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 7405: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
7406: );
1.706 raeburn 7407: if ($importcrsresform) {
7408: 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 7409: }
1.502 raeburn 7410: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 7411: my $extresourcesform =
7412: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 7413: $help{'Adding_External_Resource'},
7414: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 7415: my $exttoolform =
7416: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
7417: $help{'Adding_External_Tool'},undef,
7418: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 7419: \%ltitools,$disabled);
1.329 droeschl 7420: if ($allowed) {
1.492 raeburn 7421: my $folder = $env{'form.folder'};
7422: if ($folder eq '') {
7423: $folder='default';
7424: }
1.615 raeburn 7425: if ($canedit) {
7426: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
7427: if ($output) {
7428: $r->print($output);
7429: }
1.538 raeburn 7430: }
1.337 ehlerst 7431: $r->print(<<HIDDENFORM);
7432: <form name="renameform" method="post" action="/adm/coursedocs">
7433: <input type="hidden" name="title" />
7434: <input type="hidden" name="cmd" />
7435: <input type="hidden" name="markcopy" />
7436: <input type="hidden" name="copyfolder" />
7437: $containertag
7438: </form>
1.633 raeburn 7439: <form name="aliasform" method="post" action="/adm/coursedocs">
7440: <input type="hidden" name="alias" />
7441: <input type="hidden" name="cmd" />
7442: $containertag
7443: </form>
1.484 raeburn 7444:
1.337 ehlerst 7445: HIDDENFORM
1.508 raeburn 7446: $r->print(&makesimpleeditform($pathitem)."\n".
7447: &makedocslogform($pathitem."\n".
1.484 raeburn 7448: '<input type="hidden" name="folder" value="'.
7449: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 7450: }
1.442 www 7451:
7452: # Generate the tabs
1.510 raeburn 7453: my ($mode,$needs_end);
1.472 raeburn 7454: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 7455: my @folders = split('&',$env{'form.folderpath'});
7456: unless (@folders > 2) {
7457: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
7458: $needs_end = 1;
7459: }
1.472 raeburn 7460: } else {
1.484 raeburn 7461: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 7462: $needs_end = 1;
1.472 raeburn 7463: }
1.443 www 7464:
1.442 www 7465: #
1.622 raeburn 7466: my $hostname = $r->hostname();
1.442 www 7467: my $savefolderpath;
7468:
1.395 raeburn 7469: if ($allowed) {
1.329 droeschl 7470: my $folder=$env{'form.folder'};
1.615 raeburn 7471: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 7472: $folder='default';
1.356 tempelho 7473: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 7474: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 7475: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 7476: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
7477: }
7478: my $postexec='';
7479: if ($folder eq 'default') {
1.653 raeburn 7480: my $windowname = 'loncapaclient';
7481: if ($env{'request.lti.login'}) {
7482: $windowname .= 'lti';
7483: }
1.372 bisitz 7484: $r->print('<script type="text/javascript">'."\n"
7485: .'// <![CDATA['."\n"
1.653 raeburn 7486: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 7487: .'// ]]>'."\n"
7488: .'</script>'."\n"
1.369 bisitz 7489: );
1.329 droeschl 7490: } else {
7491: #$postexec='self.close();';
7492: }
1.504 raeburn 7493: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
7494: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 7495: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
7496:
7497: my $newnavform=(<<NNFORM);
7498: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 7499: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7500: $pathitem
1.329 droeschl 7501: <input type="hidden" name="importdetail"
7502: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 7503: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 7504: $help{'Navigate_Content'}
7505: </form>
7506: NNFORM
7507: my $newsmppageform=(<<NSPFORM);
7508: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 7509: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7510: $pathitem
1.329 droeschl 7511: <input type="hidden" name="importdetail" value="" />
1.423 onken 7512: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 7513: $help{'Simple Page'}
1.329 droeschl 7514: </form>
7515: NSPFORM
7516:
7517: my $newsmpproblemform=(<<NSPROBFORM);
7518: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 7519: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7520: $pathitem
1.329 droeschl 7521: <input type="hidden" name="importdetail" value="" />
1.423 onken 7522: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 7523: $help{'Simple_Problem'}
1.329 droeschl 7524: </form>
7525:
7526: NSPROBFORM
7527:
7528: my $newdropboxform=(<<NDBFORM);
7529: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 7530: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7531: $pathitem
1.329 droeschl 7532: <input type="hidden" name="importdetail" value="" />
1.423 onken 7533: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 7534: $help{'Dropbox'}
1.344 bisitz 7535: </form>
1.329 droeschl 7536: NDBFORM
7537:
7538: my $newexuploadform=(<<NEXUFORM);
7539: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 7540: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7541: $pathitem
1.329 droeschl 7542: <input type="hidden" name="importdetail" value="" />
1.423 onken 7543: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 7544: $help{'Score_Upload_Form'}
7545: </form>
7546: NEXUFORM
7547:
7548: my $newbulform=(<<NBFORM);
7549: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 7550: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7551: $pathitem
1.329 droeschl 7552: <input type="hidden" name="importdetail" value="" />
1.423 onken 7553: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 7554: $help{'Bulletin Board'}
7555: </form>
7556: NBFORM
7557:
7558: my $newaboutmeform=(<<NAMFORM);
7559: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 7560: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7561: $pathitem
1.329 droeschl 7562: <input type="hidden" name="importdetail"
7563: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7564: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 7565: $help{'My Personal Information Page'}
1.329 droeschl 7566: </form>
7567: NAMFORM
7568:
7569: my $newaboutsomeoneform=(<<NASOFORM);
7570: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 7571: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7572: $pathitem
1.329 droeschl 7573: <input type="hidden" name="importdetail" value="" />
1.423 onken 7574: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 7575: </form>
7576: NASOFORM
7577:
7578: my $newrosterform=(<<NROSTFORM);
7579: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 7580: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7581: $pathitem
1.329 droeschl 7582: <input type="hidden" name="importdetail"
7583: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 7584: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 7585: $help{'Course_Roster'}
1.329 droeschl 7586: </form>
7587: NROSTFORM
7588:
1.534 raeburn 7589: my $newwebpage;
7590: if ($folder =~ /^default_?(\d*)$/) {
7591: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
7592: if ($1) {
7593: $newwebpage .= $1;
7594: } else {
7595: $newwebpage .= 'default';
7596: }
7597: $newwebpage .= '/new.html';
7598: }
7599: my $newwebpageform =(<<NWEBFORM);
7600: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 7601: <input type="hidden" name="active" value="ff" />
1.534 raeburn 7602: $pathitem
7603: <input type="hidden" name="importdetail" value="$newwebpage" />
7604: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 7605: $help{'Web_Page'}
1.534 raeburn 7606: </form>
7607: NWEBFORM
1.701 raeburn 7608: my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606 raeburn 7609: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 7610: my $machines_str = "'".join("','",@ids)."'";
7611: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 7612: if ($env{'user.author'}) {
7613: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 7614: $is_home{'author'} = 1;
1.606 raeburn 7615: }
1.691 raeburn 7616: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 7617: }
7618: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
7619: ['active'],['ca','aa']);
1.691 raeburn 7620: my %by_roletype;
1.606 raeburn 7621: if (keys(%roleshash)) {
7622: foreach my $entry (keys(%roleshash)) {
7623: my ($auname,$audom,$roletype) = split(/:/,$entry);
7624: my $key = $entry;
7625: $key =~ s/:/___/g;
1.691 raeburn 7626: my $author = $auname.'___'.$audom;
7627: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 7628: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 7629: $toppath{$author} = "/priv/$audom/$auname";
7630: if (grep(/^\Q$rolehome\E$/,@ids)) {
7631: $is_home{$author} = 1;
1.606 raeburn 7632: }
1.691 raeburn 7633: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
7634: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 7635: }
1.691 raeburn 7636: }
7637: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
7638: if (grep(/^\Q$crshome\E$/,@ids)) {
7639: $is_home{'course'} = 1;
7640: }
7641: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
7642: my $pickdir = $lt{'loca'}.
7643: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
7644: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
7645: if ($env{'user.author'}) {
7646: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
7647: }
7648: if (keys(%by_roletype)) {
7649: foreach my $possrole ('ca','aa') {
7650: if (ref($by_roletype{$possrole}) eq 'HASH') {
7651: my $roletitle = &Apache::lonnet::plaintext($possrole);
7652: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
7653: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
7654: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
7655: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 7656: }
7657: }
7658: }
7659: }
1.706 raeburn 7660: if ($checkcrsres) {
7661: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n";
7662: }
7663: $pickdir .= '</select><br />'."\n".
1.691 raeburn 7664: $lt{'dire'}.
7665: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
7666: '<option value=""></option>'.
7667: '</select><br />'."\n";
1.606 raeburn 7668: my %seltemplate_menus;
7669: my @files = &Apache::lonhomework::get_template_list('problem');
7670: my @noexamplelink = ('blank.problem','blank.library','script.library');
7671: my $currentcategory = '';
7672: my @ordered = ('');
7673: my %templatehelp;
7674: my $defcategory = '';
7675: my @catorder = ($defcategory);
7676: $seltemplate_menus{$defcategory}->{'order'} = [''];
7677: $seltemplate_menus{$defcategory}->{'text'} = '';
7678: foreach my $file (@files) {
7679: if (ref($file) eq 'ARRAY') {
7680: my ($path,$title,$category,$help) = @{$file};
7681: next if ($title !~ /\S/);
7682: if (&js_escape($category) ne $currentcategory) {
7683: $currentcategory = &js_escape($category);
7684: push(@catorder,&js_escape($currentcategory));
7685: $seltemplate_menus{$currentcategory}->{'text'} = $category;
7686: $seltemplate_menus{$currentcategory}->{'default'} = '';
7687: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
7688: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
7689: }
7690: if ($path) {
7691: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
7692: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
7693: if ($help) {
7694: $templatehelp{$path} = $help;
7695: }
7696: }
7697: }
7698: }
7699:
7700: my $templates = $lt{'cate'}.' '.
7701: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
7702: $defcategory,'tempcategory','template',
7703: \%seltemplate_menus,\@catorder,
7704: "resize_scrollbox('contentscroll','1','0');",
7705: "toggleExampleText();",'template').'<br />';
7706: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
1.701 raeburn 7707: '<span id="newresexample">'.&mt('Example').'</span></a>';
1.706 raeburn 7708: my $crsresform;
7709: if (($env{'user.author'}) || ($checkcrsres)) {
7710: $crsresform=(<<RESFORM);
1.691 raeburn 7711: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.706 raeburn 7712: $lt{'stpr'}</a>$help{'Standard_Problem'}
1.606 raeburn 7713: <form action="/adm/coursedocs" method="post" name="courseresform">
7714: <fieldset id="crsresform" style="display:none;">
7715: <legend>$lt{'stpr'}</legend>
1.655 raeburn 7716: <input type="hidden" name="active" value="bb" />
1.606 raeburn 7717: <p>
7718: $pickdir
1.701 raeburn 7719: </p>
1.691 raeburn 7720: <div id="newstdproblem" style="display:none;">
1.701 raeburn 7721: <p>
1.606 raeburn 7722: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 7723: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 7724:
1.611 raeburn 7725: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 7726: </span><span id="newsubdir"></span>
7727: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701 raeburn 7728: </p>
1.699 raeburn 7729: </div>
1.606 raeburn 7730: $lt{'fnam'}
1.611 raeburn 7731: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.701 raeburn 7732: <div id="newresource" style="display:none">
1.606 raeburn 7733: <p>
7734: $lt{'addp'}
1.611 raeburn 7735: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 7736: $lt{'no'}</label>
1.611 raeburn 7737: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 7738: $lt{'yes'}</label>
7739: <span id="newrestitle"></span>
1.611 raeburn 7740: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701 raeburn 7741: </p>
1.606 raeburn 7742: </div>
7743: <p>
7744: $lt{'uste'}
1.611 raeburn 7745: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 7746: $lt{'no'}</label>
1.611 raeburn 7747: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 7748: $lt{'yes'}</label>
1.701 raeburn 7749: </p>
1.606 raeburn 7750: <div id="newrestemplate" style="display:none">
7751: $templates
7752: $templatepreview
7753: </div>
7754: <span class="LC_nobreak">
1.701 raeburn 7755: <input type="hidden" name="folderpath" value="$showpath" />
1.611 raeburn 7756: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 7757: </span>
1.691 raeburn 7758: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 7759: $rolehomes
7760: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
7761: </div>
1.606 raeburn 7762: </fieldset>
7763: </form>
7764:
7765: RESFORM
1.706 raeburn 7766: }
1.534 raeburn 7767:
1.342 ehlerst 7768: my $specialdocumentsform;
1.383 tempelho 7769: my @specialdocumentsforma;
1.451 www 7770: my $gradingform;
7771: my @gradingforma;
7772: my $communityform;
7773: my @communityforma;
1.351 ehlerst 7774: my $newfolderform;
1.390 tempelho 7775: my $newfolderb;
1.342 ehlerst 7776:
1.451 www 7777: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 7778:
1.329 droeschl 7779: my $newpageform=(<<NPFORM);
7780: <form action="/adm/coursedocs" method="post" name="newpage">
7781: <input type="hidden" name="folderpath" value="$path" />
7782: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 7783: <input type="hidden" name="active" value="ee" />
1.423 onken 7784: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 7785: $help{'Adding_Pages'}
1.329 droeschl 7786: </form>
7787: NPFORM
1.390 tempelho 7788:
7789:
1.351 ehlerst 7790: $newfolderform=(<<NFFORM);
1.329 droeschl 7791: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 7792: $pathitem
1.329 droeschl 7793: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 7794: <input type="hidden" name="active" value="" />
1.422 onken 7795: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 7796: </form>
7797: NFFORM
7798:
7799: my $newsylform=(<<NSYLFORM);
7800: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 7801: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7802: $pathitem
1.329 droeschl 7803: <input type="hidden" name="importdetail"
7804: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 7805: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 7806: $help{'Syllabus'}
1.383 tempelho 7807:
1.329 droeschl 7808: </form>
7809: NSYLFORM
1.364 bisitz 7810:
1.329 droeschl 7811: my $newgroupfileform=(<<NGFFORM);
7812: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 7813: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7814: $pathitem
1.329 droeschl 7815: <input type="hidden" name="importdetail"
7816: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 7817: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 7818: $help{'Group Portfolio'}
1.329 droeschl 7819: </form>
7820: NGFFORM
1.672 raeburn 7821: if ($container eq 'page') {
7822: @specialdocumentsforma=(
7823: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
7824: );
7825: } else {
7826: @specialdocumentsforma=(
1.421 onken 7827: {'<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 7828: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 7829: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 7830: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 7831: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 7832: );
7833: }
1.451 www 7834: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
7835:
1.655 raeburn 7836: my @external = (
7837: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 7838: );
1.699 raeburn 7839: if ($posslti) {
1.655 raeburn 7840: push(@external,
7841: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
7842: );
1.598 raeburn 7843: }
1.655 raeburn 7844: my $externalform = &create_form_ul(&create_list_elements(@external));
7845:
7846: my @importdoc = ();
1.519 raeburn 7847: unless ($container eq 'page') {
7848: push(@importdoc,
7849: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
7850: );
7851: }
7852: push(@importdoc,
1.558 raeburn 7853: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 7854: );
1.501 raeburn 7855: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 7856:
1.451 www 7857: @gradingforma=(
7858: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
7859: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
1.706 raeburn 7860: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
1.451 www 7861: );
1.706 raeburn 7862: if ($crsresform) {
7863: push(@gradingforma,
7864: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform}
7865: );
7866: }
1.451 www 7867: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
7868:
7869: @communityforma=(
7870: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
7871: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
7872: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 7873: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
7874: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 7875: );
7876: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 7877:
1.330 tempelho 7878: my %orderhash = (
1.553 raeburn 7879: 'aa' => ['Upload',$fileuploadform],
1.707 raeburn 7880: 'bb' => ['External',$externalform],
7881: 'cc' => ['Import',$importpubform],
1.701 raeburn 7882: 'dd' => ['Assessment',$gradingform],
1.673 raeburn 7883: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 7884: );
1.519 raeburn 7885: unless ($container eq 'page') {
1.434 raeburn 7886: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 7887: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 7888: }
7889:
1.341 ehlerst 7890: $hadchanges=0;
1.484 raeburn 7891: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 7892: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 7893: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 7894: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 7895: undef($navmap);
1.443 www 7896: if ($error) {
7897: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7898: }
1.639 raeburn 7899: if ($hadchanges) {
7900: unless (&is_hash_old()) {
1.638 raeburn 7901: &mark_hash_old();
7902: }
7903: }
1.341 ehlerst 7904:
1.443 www 7905: &changewarning($r,'');
7906: }
1.458 raeburn 7907: }
1.442 www 7908:
1.443 www 7909: # Supplemental documents start here
7910:
1.329 droeschl 7911: my $folder=$env{'form.folder'};
1.443 www 7912: unless ($supplementalflag) {
1.329 droeschl 7913: $folder='supplemental';
7914: }
1.685 raeburn 7915: if (($folder eq 'supplemental') &&
1.329 droeschl 7916: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 7917: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 7918: } elsif ($allowed) {
1.356 tempelho 7919: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 7920: }
1.508 raeburn 7921: $pathitem = '<input type="hidden" name="folderpath" value="'.
7922: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 7923: if ($allowed) {
7924: my $folderseq=
1.504 raeburn 7925: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 7926:
7927: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 7928: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
7929: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 7930: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 7931: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 7932: <legend>$lt{'upfi'}</legend>
1.630 raeburn 7933: <input type="hidden" name="active" value="ee" />
1.329 droeschl 7934: $fileupload
1.702 raeburn 7935: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
7936: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 7937: <br />
7938: <br />
7939: <span class="LC_nobreak">
7940: $checkbox
7941: </span>
7942: <br /><br />
7943: $lt{'comment'}:<br />
1.383 tempelho 7944: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 7945: <br />
1.508 raeburn 7946: $pathitem
1.329 droeschl 7947: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 7948: <input type='submit' value="$lt{'upld'}" />
1.700 raeburn 7949: </fieldset>
1.501 raeburn 7950: </form>
1.329 droeschl 7951: SUPDOCFORM
7952:
7953: my $supnewfolderform=(<<SNFFORM);
7954: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 7955: <input type="hidden" name="active" value="" />
1.508 raeburn 7956: $pathitem
1.329 droeschl 7957: <input type="hidden" name="importdetail" value="" />
1.423 onken 7958: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 7959: $help{'Adding_Folders'}
1.329 droeschl 7960: </form>
7961: SNFFORM
1.383 tempelho 7962:
1.510 raeburn 7963: my $supextform =
7964: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 7965: $help{'Adding_External_Resource'},
7966: undef,undef,undef,undef,undef,undef,
7967: $disabled);
1.329 droeschl 7968:
1.598 raeburn 7969: my $supexttoolform =
7970: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
7971: $help{'Adding_External_Tool'},
7972: undef,undef,'tool',$coursedom,
1.611 raeburn 7973: $coursenum,\%ltitools,$disabled);
1.598 raeburn 7974:
1.329 droeschl 7975: my $supnewsylform=(<<SNSFORM);
7976: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 7977: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7978: $pathitem
1.329 droeschl 7979: <input type="hidden" name="importdetail"
7980: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 7981: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 7982: $help{'Syllabus'}
7983: </form>
7984: SNSFORM
7985:
7986: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 7987: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 7988: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7989: $pathitem
1.329 droeschl 7990: <input type="hidden" name="importdetail"
7991: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7992: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 7993: $help{'My Personal Information Page'}
1.329 droeschl 7994: </form>
7995: SNAMFORM
7996:
1.534 raeburn 7997: my $supwebpage;
7998: if ($folder =~ /^supplemental_?(\d*)$/) {
7999: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
8000: if ($1) {
8001: $supwebpage .= $1;
8002: } else {
8003: $supwebpage .= 'default';
8004: }
8005: $supwebpage .= '/new.html';
8006: }
8007: my $supwebpageform =(<<SWEBFORM);
8008: <form action="/adm/coursedocs" method="post" name="supwebpage">
8009: <input type="hidden" name="active" value="cc" />
8010: $pathitem
8011: <input type="hidden" name="importdetail" value="$supwebpage" />
8012: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 8013: $help{'Web_Page'}
1.534 raeburn 8014: </form>
8015: SWEBFORM
8016:
1.333 muellerd 8017:
1.383 tempelho 8018: my @specialdocs = (
1.618 raeburn 8019: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 8020: =>$supnewsylform},
1.611 raeburn 8021: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 8022: =>$supnewaboutmeform},
1.534 raeburn 8023: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
8024:
1.383 tempelho 8025: );
1.655 raeburn 8026: my @supexternal = (
8027: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
8028: =>$supextform});
1.699 raeburn 8029: if ($posslti) {
1.655 raeburn 8030: push(@supexternal,
8031: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 8032: =>$supexttoolform});
8033: }
1.655 raeburn 8034: my @supimportdoc = (
1.598 raeburn 8035: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 8036: =>$supupdocform},
1.598 raeburn 8037: );
1.501 raeburn 8038:
8039: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 8040: my %suporderhash = (
1.390 tempelho 8041: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 8042: 'dd' => ['Upload',$supupdocform],
8043: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 8044: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 8045: );
1.443 www 8046: if ($supplementalflag) {
1.682 raeburn 8047: $suppchanges = 0;
8048: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
8049: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
8050: \%ltitools,$canedit,$hostname);
8051: if ($error) {
8052: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
8053: }
8054: if ($suppchanges) {
1.684 raeburn 8055: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 8056: undef($suppchanges);
8057: }
1.393 raeburn 8058: }
1.443 www 8059: } elsif ($supplementalflag) {
1.458 raeburn 8060: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 8061: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
8062: $hostname);
1.393 raeburn 8063: if ($error) {
8064: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 8065: }
1.393 raeburn 8066: }
1.389 tempelho 8067:
1.510 raeburn 8068: if ($needs_end) {
8069: $r->print(&endContentScreen());
8070: }
1.383 tempelho 8071:
1.329 droeschl 8072: if ($allowed) {
8073: $r->print('
8074: <form method="post" name="extimport" action="/adm/coursedocs">
8075: <input type="hidden" name="title" />
8076: <input type="hidden" name="url" />
8077: <input type="hidden" name="useform" />
8078: <input type="hidden" name="residx" />
8079: </form>');
8080: }
1.484 raeburn 8081: } elsif ($showdoc) {
1.329 droeschl 8082: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 8083: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 8084: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 8085: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 8086: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 8087: }
8088: }
1.630 raeburn 8089: unless ($noendpage) {
1.606 raeburn 8090: $r->print(&Apache::loncommon::end_page());
8091: }
1.329 droeschl 8092: return OK;
1.364 bisitz 8093: }
1.329 droeschl 8094:
1.440 raeburn 8095: sub embedded_form_elems {
8096: my ($phase,$primaryurl,$newidx) = @_;
8097: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 8098: $newidx =~s /\D+//g;
1.440 raeburn 8099: return <<STATE;
8100: <input type="hidden" name="folderpath" value="$folderpath" />
8101: <input type="hidden" name="cmd" value="upload_embedded" />
8102: <input type="hidden" name="newidx" value="$newidx" />
8103: <input type="hidden" name="phase" value="$phase" />
8104: <input type="hidden" name="primaryurl" value="$primaryurl" />
8105: STATE
8106: }
8107:
8108: sub embedded_destination {
8109: my $folder=$env{'form.folder'};
8110: my $destination = 'docs/';
8111: if ($folder =~ /^supplemental/) {
8112: $destination = 'supplemental/';
8113: }
8114: if (($folder eq 'default') || ($folder eq 'supplemental')) {
8115: $destination .= 'default/';
8116: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
8117: $destination .= $2.'/';
8118: }
1.634 raeburn 8119: my $newidx = $env{'form.newidx'};
8120: $newidx =~s /\D+//g;
8121: if ($newidx) {
8122: $destination .= $newidx;
8123: }
1.440 raeburn 8124: my $dir_root = '/userfiles';
8125: return ($destination,$dir_root);
8126: }
8127:
8128: sub return_to_editor {
8129: my $actionurl = '/adm/coursedocs';
8130: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
8131: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
8132: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
8133: '</a></p>';
8134: }
8135:
1.476 raeburn 8136: sub decompression_info {
8137: my ($destination,$dir_root) = &embedded_destination();
8138: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
8139: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8140: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
8141: my $container='sequence';
1.480 raeburn 8142: my ($pathitem,$hiddenelem);
1.583 raeburn 8143: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 8144: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 8145: $container='page';
8146: }
1.480 raeburn 8147: unshift(@hiddens,$pathitem);
8148: foreach my $item (@hiddens) {
1.634 raeburn 8149: if ($item eq 'newidx') {
8150: next if ($env{'form.'.$item} =~ /\D/);
8151: }
1.480 raeburn 8152: if ($env{'form.'.$item}) {
8153: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 8154: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 8155: }
1.477 raeburn 8156: }
1.476 raeburn 8157: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
8158: $hiddenelem);
8159: }
8160:
8161: sub decompression_phase_one {
8162: my ($dir,$file,$warning,$error,$output);
8163: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8164: &decompression_info();
1.490 raeburn 8165: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 8166: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
8167: } else {
8168: my $file = $1;
1.630 raeburn 8169: $output =
1.481 raeburn 8170: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
8171: $destination,$dir_root,
8172: $hiddenelem);
8173: if ($env{'form.autoextract_camtasia'}) {
8174: $output .= &remove_archive($docudom,$docuname,$container);
8175: }
1.476 raeburn 8176: }
8177: if ($error) {
8178: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
8179: $error.'</p>'."\n";
8180: }
8181: if ($warning) {
8182: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
8183: }
8184: return $output;
8185: }
8186:
8187: sub decompression_phase_two {
8188: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8189: &decompression_info();
1.481 raeburn 8190: my $output;
1.480 raeburn 8191: if ($env{'form.archivedelete'}) {
1.481 raeburn 8192: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 8193: }
8194: $output .=
1.481 raeburn 8195: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 8196: $destination,$dir_root,$hiddenelem);
8197: return $output;
8198: }
8199:
1.480 raeburn 8200: sub remove_archive {
8201: my ($docudom,$docuname,$container) = @_;
8202: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 8203: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 8204: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
8205: if ($fatal) {
8206: if ($container eq 'page') {
8207: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
8208: } else {
8209: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
8210: }
1.583 raeburn 8211: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8212: } else {
8213: my $currcmd = $env{'form.cmd'};
8214: my $position = $env{'form.position'};
1.583 raeburn 8215: my $archiveidx = $position;
1.563 raeburn 8216: if ($position > 0) {
1.583 raeburn 8217: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
8218: $archiveidx = $position-1;
8219: }
8220: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 8221: my ($title,$url,@rrest) =
1.583 raeburn 8222: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
8223: if ($url eq $env{'form.archiveurl'}) {
8224: if (&handle_edit_cmd($docuname,$docudom)) {
8225: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 8226: if ($suppchanges) {
8227: &Apache::lonnet::update_supp_caches($docudom,$docuname);
8228: undef($suppchanges);
8229: }
1.583 raeburn 8230: if ($fatal) {
8231: if ($container eq 'page') {
8232: $delwarning = &mt('An error occurred updating the contents of the current page.');
8233: } else {
8234: $delwarning = &mt('An error occurred updating the contents of the current folder.');
8235: }
1.480 raeburn 8236: } else {
1.583 raeburn 8237: $delresult = &mt('Archive file removed.');
1.480 raeburn 8238: }
8239: }
1.583 raeburn 8240: } else {
8241: $delwarning .= &mt('Archive file had unexpected item number in folder.').
8242: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8243: }
8244: }
8245: $env{'form.cmd'} = $currcmd;
8246: }
8247: if ($delwarning) {
8248: $output = '<p class="LC_warning">'.
8249: $delwarning.
8250: '</p>';
8251: }
8252: if ($delresult) {
8253: $output .= '<p class="LC_info">'.
8254: $delresult.
8255: '</p>';
8256: }
1.481 raeburn 8257: return $output;
1.480 raeburn 8258: }
8259:
1.484 raeburn 8260: sub generate_admin_menu {
1.708 raeburn 8261: my ($crstype,$canedit,$coursenum,$coursedom) = @_;
1.484 raeburn 8262: my $lc_crstype = lc($crstype);
8263: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 8264: my %lt= ( # do not translate here
1.484 raeburn 8265: 'vc' => 'Verify Content',
8266: 'cv' => 'Check/Set Resource Versions',
8267: 'ls' => 'List Resource Identifiers',
1.651 raeburn 8268: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.708 raeburn 8269: 'ca' => "Enter $crstype Authoring Space",
1.484 raeburn 8270: 'imse' => 'Export contents to IMS Archive',
1.712 raeburn 8271: 'dcd' => 'Copy uploaded content to Authoring Space',
8272: 'cpc' => 'Copy from Course Authoring to User Authoring',
1.562 bisitz 8273: );
1.712 raeburn 8274: my ($candump,$dumpurl,$exportcrsurl);
1.484 raeburn 8275: if ($home + $other > 0) {
8276: $candump = 'F';
8277: if ($home) {
8278: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
1.712 raeburn 8279: $exportcrsurl = "javascript:injectData(document.courseverify,'dummy','copyauthored','$lt{'cpc'}')";
1.484 raeburn 8280: } else {
8281: my @hosts;
8282: foreach my $aurole (keys(%outhash)) {
8283: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
8284: push(@hosts,$outhash{$aurole});
1.538 raeburn 8285: }
1.484 raeburn 8286: }
8287: if (@hosts == 1) {
8288: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
8289: '&role='.
8290: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
8291: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
8292: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
1.712 raeburn 8293: $exportcrsurl = $dumpurl;
1.484 raeburn 8294: } else {
8295: $dumpurl = "javascript:choose_switchserver_window()";
1.712 raeburn 8296: $exportcrsurl = $dumpurl;
1.484 raeburn 8297: }
8298: }
8299: }
8300: my @menu=
8301: ({ categorytitle=>'Administration',
8302: items =>[
8303: { linktext => $lt{'vc'},
8304: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
8305: permission => 'F',
1.571 raeburn 8306: help => 'Docs_Verify_Content',
1.484 raeburn 8307: icon => 'verify.png',
8308: linktitle => 'Verify contents can be retrieved/rendered',
8309: },
8310: { linktext => $lt{'cv'},
8311: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
8312: permission => 'F',
1.571 raeburn 8313: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 8314: icon => 'resversion.png',
8315: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
8316: },
8317: { linktext => $lt{'ls'},
8318: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
8319: permission => 'F',
8320: #help => '',
8321: icon => 'symbs.png',
8322: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
8323: },
1.651 raeburn 8324: { linktext => $lt{'ct'},
8325: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
8326: permission => 'F',
8327: help => 'Docs_Short_URLs',
8328: icon => 'shorturls.png',
8329: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
8330: },
1.484 raeburn 8331: ]
1.611 raeburn 8332: });
8333: if ($canedit) {
1.708 raeburn 8334: my ($crsauname,$crsaudom,$crshome);
8335: if (($coursenum ne '') && ($coursedom ne '')) {
8336: my $crsauthorurl = "/priv/$coursedom/$coursenum/";
8337: ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl);
8338: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8339: my @ids=&Apache::lonnet::current_machine_ids();
8340: my $linkurl;
8341: if (grep(/^\Q$crshome\E$/,@ids)) {
8342: $linkurl = $crsauthorurl;
8343: } else {
8344: $linkurl =
8345: &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1);
8346: }
8347: if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY')) {
8348: push(@{$menu[0]->{items}},
8349: { linktext => $lt{'ca'},
8350: url => $linkurl,
8351: permission => 'F',
8352: help => 'Docs_Course_Authorspace',
8353: icon => 'impcrsau.png',
8354: linktitle => $lt{'ca'},
8355: });
8356: }
8357: }
8358: }
1.611 raeburn 8359: push(@menu,
1.484 raeburn 8360: { categorytitle=>'Export',
8361: items =>[
8362: { linktext => $lt{'imse'},
8363: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
8364: permission => 'F',
8365: help => 'Docs_Export_Course_Docs',
8366: icon => 'imsexport.png',
8367: linktitle => $lt{'imse'},
8368: },
8369: { linktext => $lt{'dcd'},
8370: url => $dumpurl,
8371: permission => $candump,
1.571 raeburn 8372: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 8373: icon => 'dump.png',
8374: linktitle => $lt{'dcd'},
8375: },
8376: ]
8377: });
1.712 raeburn 8378: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8379: if ((ref($menu[1]) eq 'HASH') && (ref($menu[1]->{'items'}) eq 'ARRAY')) {
8380: push(@{$menu[1]->{items}},
8381: { linktext => $lt{'cpc'},
8382: url => $exportcrsurl,
8383: permission => 'F',
8384: help => 'Docs_Export_Course_Author',
8385: icon => 'res.png',
8386: linktitle => $lt{'cpc'},
8387: });
8388: }
8389: }
1.611 raeburn 8390: }
1.484 raeburn 8391: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
8392: '<input type="hidden" id="dummy" />'."\n".
8393: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
8394: '</form>';
1.329 droeschl 8395: }
8396:
8397: sub generate_edit_table {
1.538 raeburn 8398: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 8399: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 8400: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 8401: my %orderhash = %{$orderhash_ref};
1.611 raeburn 8402: my ($form, $activetab, $active, $disabled);
1.570 raeburn 8403: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 8404: $activetab = $env{'form.active'};
8405: }
1.611 raeburn 8406: unless ($canedit) {
8407: $disabled = ' disabled="disabled"';
8408: }
1.472 raeburn 8409: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 8410: my $backtext = &mt('Exit Editor');
1.458 raeburn 8411: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 8412: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
8413: '<li class="goback">'.
1.546 raeburn 8414: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 8415: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
8416: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
8417: '<li>'.
8418: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
8419: &mt('Undo Delete').'</a></li>'."\n";
8420: if ($env{'form.docslog'}) {
8421: $form .= '<li class="active">';
8422: } else {
8423: $form .= '<li>';
8424: }
8425: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
8426: &mt('History').'</a></li>'."\n";
8427: if ($env{'form.docslog'}) {
8428: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
8429: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 8430: }
1.458 raeburn 8431: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 8432: if($name ne '00'){
1.371 tempelho 8433: if($activetab eq '' || $activetab ne $name){
8434: $active = '';
8435: }elsif($activetab eq $name){
8436: $active = 'class="active"';
8437: }
1.458 raeburn 8438: $form .= '<li style="float:right" '.$active
1.484 raeburn 8439: .' 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 8440: } else {
1.570 raeburn 8441: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 8442:
8443: }
1.329 droeschl 8444: }
1.484 raeburn 8445: $form .= '</ul>'."\n";
8446: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 8447:
8448: if ($to_show ne '') {
1.538 raeburn 8449: my $saveform;
8450: if ($need_save) {
8451: my $button = &mt('Make changes');
8452: my $path;
8453: if ($env{'form.folderpath'}) {
8454: $path =
8455: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
8456: }
8457: $saveform = <<"END";
8458: <div id="multisave" style="display:none; clear:both;" >
8459: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
8460: <input type="hidden" name="folderpath" value="$path" />
8461: <input type="hidden" name="symb" value="$env{'form.symb'}" />
8462: <input type="hidden" name="allhiddenresource" value="" />
8463: <input type="hidden" name="allencrypturl" value="" />
8464: <input type="hidden" name="allrandompick" value="" />
8465: <input type="hidden" name="allrandomorder" value="" />
8466: <input type="hidden" name="changeparms" value="" />
8467: <input type="hidden" name="multiremove" value="" />
8468: <input type="hidden" name="multicut" value="" />
8469: <input type="hidden" name="multicopy" value="" />
8470: <input type="hidden" name="multichange" value="" />
8471: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 8472: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 8473: </form>
8474: </div>
8475: END
8476: }
8477: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 8478: }
1.363 ehlerst 8479: foreach my $field (keys(%orderhash)){
1.390 tempelho 8480: if($field ne '00'){
1.422 onken 8481: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 8482: $active = 'style="display: none;float:left"';
1.422 onken 8483: }elsif($activetab eq $field){
1.458 raeburn 8484: $active = 'style="display:block;float:left"';
1.422 onken 8485: }
8486: $form .= '<div id="'.$field.$tid.'"'
8487: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 8488: .'</div>'."\n";
1.363 ehlerst 8489: }
8490: }
1.484 raeburn 8491: unless ($env{'form.docslog'}) {
8492: $form .= '</div></div>'."\n";
8493: }
1.329 droeschl 8494: return $form;
8495: }
8496:
8497: sub editing_js {
1.622 raeburn 8498: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
8499: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 8500: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 8501: p_mnf => 'Name of New Folder',
8502: t_mnf => 'New Folder',
8503: p_mnp => 'Name of New Page',
8504: t_mnp => 'New Page',
1.451 www 8505: p_mxu => 'Title for the External Score',
1.349 biermanm 8506: p_msp => 'Name of Simple Course Page',
1.329 droeschl 8507: p_msb => 'Title for the Problem',
8508: p_mdb => 'Title for the Drop Box',
1.336 schafran 8509: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 8510: p_mwp => 'Title for Web Page',
1.606 raeburn 8511: p_mnr => 'Title for the Resource',
1.348 weissno 8512: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 8513: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 8514: p_mab_alrt1 => 'Not a valid user:domain',
8515: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
8516: p_chn => 'New Title',
8517: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 8518: p_rmr2a => 'Remove',
8519: p_rmr2b => '?',
8520: p_rmr3a => 'Remove those',
8521: p_rmr3b => 'items?',
8522: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
8523: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 8524: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
8525: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 8526: p_ctr2a => 'Cut',
8527: p_ctr2b => '?',
8528: p_ctr3a => 'Cut those',
8529: p_ctr3b => 'items?',
1.633 raeburn 8530: setal => 'Enter a (unique) alias',
8531: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 8532: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 8533: imsfile => 'You must choose an IMS package for import',
8534: imscms => 'You must select which Course Management System was the source of the IMS package',
8535: invurl => 'Invalid URL',
8536: titbl => 'Title is blank',
1.538 raeburn 8537: more => '(More ...)',
8538: less => '(Less ...)',
1.543 raeburn 8539: noor => 'No actions selected or changes to settings specified.',
8540: noch => 'No changes to settings specified.',
8541: noac => 'No actions selected.',
1.606 raeburn 8542: nofi => 'No file selected',
8543: tinc => 'Title in course',
8544: sunm => 'Sub-directory name',
1.618 raeburn 8545: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 8546: sele => 'Select',
8547: swit => 'Switch server required',
1.329 droeschl 8548: );
1.594 damieng 8549: &js_escape(\%js_lt);
1.433 raeburn 8550: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 8551: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
8552: my $main_container_page;
1.519 raeburn 8553: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
8554: $main_container_page = 1;
1.434 raeburn 8555: }
1.617 raeburn 8556: my $backtourl;
8557: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 8558: my $toplevelsupp = &supplemental_base();
1.690 raeburn 8559: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 8560: my @ids=&Apache::lonnet::current_machine_ids();
8561: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 8562: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
8563: my $caller = $1;
1.525 raeburn 8564: if ($caller =~ /^supplemental/) {
8565: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
8566: } else {
8567: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
8568: $res = &Apache::lonnet::clutter($res);
8569: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 8570: my ($url,$anchor);
8571: if ($res =~ /^([^#]+)#([^#]+)$/) {
8572: $url = $1;
8573: $anchor = $2;
8574: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
8575: $caller = $1.&escape('#').$anchor;
8576: }
1.614 raeburn 8577: } else {
8578: $url = $res;
1.609 raeburn 8579: }
1.640 raeburn 8580: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
8581: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
8582: $backtourl .= '?navmap=1';
8583: } else {
8584: $backtourl .= '?symb='.
8585: &HTML::Entities::encode($caller,'<>&"');
8586: }
1.622 raeburn 8587: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
8588: if (($ENV{'SERVER_PORT'} == 443) &&
8589: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 8590: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 8591: if ($hostname ne '') {
8592: $backtourl = 'http://'.$hostname.$backtourl;
8593: }
8594: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 8595: }
8596: }
1.623 raeburn 8597: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
8598: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 8599: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 8600: if ($hostname ne '') {
8601: $backtourl = 'http://'.$hostname.$backtourl;
8602: }
8603: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 8604: }
1.623 raeburn 8605: }
1.622 raeburn 8606: }
1.609 raeburn 8607: if ($anchor ne '') {
8608: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
8609: }
1.590 raeburn 8610: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 8611: } else {
8612: $backtourl = '/adm/navmaps';
1.525 raeburn 8613: }
8614: }
8615: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
8616: $backtourl = '/adm/menu';
8617: } elsif ($supplementalflag) {
1.682 raeburn 8618: if (($env{'request.role.adv'}) ||
8619: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
8620: $backtourl = '/adm/supplemental';
8621: } else {
8622: $backtourl = '/adm/navmaps';
8623: }
1.525 raeburn 8624: } else {
8625: $backtourl = '/adm/navmaps';
1.472 raeburn 8626: }
8627:
1.655 raeburn 8628: my $fieldsets = "'doc'";
1.519 raeburn 8629: unless ($main_container_page) {
8630: $fieldsets .=",'ims'";
8631: }
1.655 raeburn 8632: my $extfieldsets = "'ext'";
8633: if ($posslti) {
8634: $extfieldsets .= ",'tool'";
8635: }
1.501 raeburn 8636: if ($supplementalflag) {
1.655 raeburn 8637: $fieldsets = "'suppdoc'";
8638: $extfieldsets = "'suppext'";
1.600 raeburn 8639: if ($posslti) {
1.655 raeburn 8640: $extfieldsets .= ",'supptool'";
1.600 raeburn 8641: }
1.501 raeburn 8642: }
1.655 raeburn 8643:
1.611 raeburn 8644: my $jsmakefunctions;
8645: if ($canedit) {
8646: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 8647: function makenewfolder(targetform,folderseq) {
1.594 damieng 8648: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 8649: if (foldername) {
1.676 raeburn 8650: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 8651: targetform.submit();
8652: }
8653: }
8654:
8655: function makenewpage(targetform,folderseq) {
1.594 damieng 8656: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 8657: if (pagename) {
1.676 raeburn 8658: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 8659: targetform.submit();
8660: }
8661: }
8662:
8663: function makeexamupload() {
1.594 damieng 8664: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 8665: if (title) {
1.329 droeschl 8666: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 8667: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 8668: this.document.forms.newexamupload.submit();
8669: }
8670: }
8671:
8672: function makesmppage() {
1.594 damieng 8673: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 8674: if (title) {
1.329 droeschl 8675: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 8676: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 8677: this.document.forms.newsmppg.submit();
8678: }
8679: }
8680:
1.534 raeburn 8681: function makewebpage(type) {
1.594 damieng 8682: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 8683: var formname;
8684: if (type == 'supp') {
8685: formname = this.document.forms.supwebpage;
8686: } else {
8687: formname = this.document.forms.newwebpage;
8688: }
8689: if (title) {
8690: var webpage = formname.importdetail.value;
1.675 raeburn 8691: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 8692: formname.submit();
8693: }
8694: }
8695:
1.329 droeschl 8696: function makesmpproblem() {
1.594 damieng 8697: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 8698: if (title) {
1.329 droeschl 8699: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 8700: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 8701: this.document.forms.newsmpproblem.submit();
8702: }
8703: }
8704:
8705: function makedropbox() {
1.594 damieng 8706: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 8707: if (title) {
1.329 droeschl 8708: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 8709: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 8710: this.document.forms.newdropbox.submit();
8711: }
8712: }
8713:
8714: function makebulboard() {
1.594 damieng 8715: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 8716: if (title) {
8717: this.document.forms.newbul.importdetail.value=
1.676 raeburn 8718: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 8719: this.document.forms.newbul.submit();
8720: }
8721: }
8722:
8723: function makeabout() {
1.594 damieng 8724: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 8725: if (user) {
8726: var comp=new Array();
8727: comp=user.split(':');
8728: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
8729: if ((comp[0]) && (comp[1])) {
8730: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 8731: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 8732: this.document.forms.newaboutsomeone.submit();
8733: } else {
8734: alert("$js_lt{'p_mab_alrt1'}");
8735: }
8736: } else {
8737: alert("$js_lt{'p_mab_alrt2'}");
8738: }
8739: }
8740: }
8741:
8742: function makenew(targetform) {
8743: targetform.submit();
8744: }
8745:
8746: function changename(folderpath,index,oldtitle) {
8747: var title=prompt('$js_lt{"p_chn"}',oldtitle);
8748: if (title) {
8749: this.document.forms.renameform.markcopy.value='';
8750: this.document.forms.renameform.title.value=title;
8751: this.document.forms.renameform.cmd.value='rename_'+index;
8752: this.document.forms.renameform.folderpath.value=folderpath;
8753: this.document.forms.renameform.submit();
8754: }
8755: }
8756:
1.633 raeburn 8757: function setalias(folderpath,index) {
8758: var alias = prompt('$js_lt{"setal"}');
8759: if ((alias != null) && (alias != '')) {
8760: this.document.forms.aliasform.alias.value=alias;
8761: this.document.forms.aliasform.cmd.value='setalias_'+index;
8762: this.document.forms.aliasform.folderpath.value=folderpath;
8763: this.document.forms.aliasform.submit();
8764: }
8765: }
8766:
8767: function delalias(folderpath,index) {
8768: if (confirm('$js_lt{"delal"}')) {
8769: this.document.forms.aliasform.cmd.value='delalias_'+index;
8770: this.document.forms.aliasform.folderpath.value=folderpath;
8771: this.document.forms.aliasform.submit();
8772: }
8773: }
8774:
1.611 raeburn 8775: ENDNEWSCRIPT
8776: } else {
8777: $jsmakefunctions = <<ENDNEWSCRIPT;
8778:
8779: function makenewfolder() {
8780: alert("$js_lt{'edri'}");
8781: }
8782:
8783: function makenewpage() {
8784: alert("$js_lt{'edri'}");
8785: }
8786:
8787: function makeexamupload() {
8788: alert("$js_lt{'edri'}");
8789: }
8790:
8791: function makesmppage() {
8792: alert("$js_lt{'edri'}");
8793: }
8794:
8795: function makewebpage(type) {
8796: alert("$js_lt{'edri'}");
8797: }
8798:
8799: function makesmpproblem() {
8800: alert("$js_lt{'edri'}");
8801: }
8802:
8803: function makedropbox() {
8804: alert("$js_lt{'edri'}");
8805: }
8806:
8807: function makebulboard() {
8808: alert("$js_lt{'edri'}");
8809: }
8810:
8811: function makeabout() {
8812: alert("$js_lt{'edri'}");
8813: }
8814:
8815: function changename() {
8816: alert("$js_lt{'edri'}");
8817: }
8818:
1.633 raeburn 8819: function setalias() {
8820: alert("$js_lt{'edri'}");
8821: }
8822:
8823: function delalias() {
8824: alert("$js_lt{'edri'}");
8825: }
8826:
1.611 raeburn 8827: function makenew() {
8828: alert("$js_lt{'edri'}");
8829: }
8830:
8831: function groupimport() {
8832: alert("$js_lt{'edri'}");
1.335 ehlerst 8833: }
1.611 raeburn 8834:
8835: function groupsearch() {
8836: alert("$js_lt{'edri'}");
1.335 ehlerst 8837: }
1.611 raeburn 8838:
8839: function groupopen(url,recover) {
8840: var options="scrollbars=1,resizable=1,menubar=0";
8841: idxflag=1;
8842: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
8843: idx.focus();
1.329 droeschl 8844: }
8845:
1.611 raeburn 8846: ENDNEWSCRIPT
8847:
8848: }
8849: return <<ENDSCRIPT;
8850:
8851: $jsmakefunctions
8852:
1.501 raeburn 8853: function toggleUpload(caller) {
8854: var blocks = Array($fieldsets);
8855: for (var i=0; i<blocks.length; i++) {
8856: var disp = 'none';
8857: if (caller == blocks[i]) {
8858: var curr = document.getElementById('upload'+caller+'form').style.display;
8859: if (curr == 'none') {
8860: disp='block';
8861: }
8862: }
8863: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 8864: }
8865: resize_scrollbox('contentscroll','1','1');
8866: return;
8867: }
8868:
8869: function toggleExternal(caller) {
8870: var blocks = Array($extfieldsets);
8871: for (var i=0; i<blocks.length; i++) {
8872: var disp = 'none';
8873: if (caller == blocks[i]) {
8874: var curr = document.getElementById('external'+caller+'form').style.display;
8875: if (curr == 'none') {
8876: disp='block';
8877: }
8878: }
8879: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 8880: if ((caller == 'tool') || (caller == 'supptool')) {
8881: if (disp == 'block') {
1.655 raeburn 8882: if (document.getElementById('LC_exttoolid')) {
8883: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 8884: var suppflag = 0;
8885: if (caller == 'supptool') {
8886: suppflag = 1;
8887: }
8888: currForm = document.getElementById('new'+caller);
1.655 raeburn 8889: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 8890: }
8891: }
8892: }
1.501 raeburn 8893: }
1.502 raeburn 8894: resize_scrollbox('contentscroll','1','1');
8895: return;
8896: }
8897:
1.514 raeburn 8898: function toggleMap(caller) {
1.502 raeburn 8899: var disp = 'none';
1.510 raeburn 8900: if (document.getElementById('importmapform')) {
1.514 raeburn 8901: if (caller == 'map') {
8902: var curr = document.getElementById('importmapform').style.display;
8903: if (curr == 'none') {
8904: disp='block';
8905: }
1.510 raeburn 8906: }
8907: document.getElementById('importmapform').style.display=disp;
1.706 raeburn 8908: if (disp == 'block') {
8909: if (document.getElementById('importcrsresform')) {
8910: if (document.getElementById('importcrsresform').style.display == 'block') {
8911: document.getElementById('importcrsresform').style.display = 'none';
8912: }
8913: }
8914: }
1.510 raeburn 8915: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 8916: }
1.501 raeburn 8917: return;
1.329 droeschl 8918: }
8919:
1.691 raeburn 8920: function toggleCrsRes(caller) {
1.606 raeburn 8921: var disp = 'none';
8922: if (document.getElementById('crsresform')) {
8923: if (caller == 'res') {
1.691 raeburn 8924: var form = document.getElementById('crsresform');
8925: var curr = form.style.display;
1.606 raeburn 8926: if (curr == 'none') {
8927: disp='block';
1.691 raeburn 8928: document.courseresform.authorrole.selectedIndex = 0;
8929: document.courseresform.authorpath.selectedIndex = 0;
8930: document.courseresform.newresourceadd.selectedIndex = 0;
8931: populateDirSelects(form,'authorrole','authorpath',1,0,0);
8932: toggleNewInCourse(document.courseresform);
8933: if (document.getElementById('newresource')) {
8934: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 8935: }
8936: if (document.courseresform.newresusetemp.length) {
8937: document.courseresform.newresusetemp[0].checked = true;
8938: toggleWithTemplate(document.courseresform);
8939: }
8940: document.courseresform.newresourcename.value = '';
8941: }
8942: }
8943: if (document.courseresform.newsubdir.length) {
8944: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
8945: if (document.courseresform.newsubdir[j].value == 0) {
8946: document.courseresform.newsubdir[j].checked = true;
8947: }
8948: break;
8949: }
8950: if (document.getElementById('newsubdirname')) {
8951: document.getElementById('newsubdirname').type = "hidden";
8952: document.getElementById('newsubdirname').value = "";
8953: }
8954: if (document.getElementById('newsubdir')) {
8955: document.getElementById('newsubdir').innerHTML = "";
8956: }
8957: }
8958: document.getElementById('crsresform').style.display=disp;
8959: resize_scrollbox('contentscroll','1','0');
8960: }
8961: return;
8962: }
8963:
8964: function toggleNewsubdir(form) {
8965: if (form.newsubdir.length) {
8966: for (var j=0; j<form.newsubdir.length; j++) {
8967: if (form.newsubdir[j].checked) {
8968: if (document.getElementById('newsubdirname')) {
8969: if (form.newsubdir[j].value == '1') {
8970: document.getElementById('newsubdirname').type = "text";
8971: if (document.getElementById('newsubdir')) {
8972: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
8973: }
8974: } else {
8975: document.getElementById('newsubdirname').type = "hidden";
8976: document.getElementById('newsubdirname').value = "";
8977: document.getElementById('newsubdir').innerHTML = "";
8978: }
8979: }
8980: break;
8981: }
8982: }
8983: }
8984: }
8985:
8986: function toggleCrsResTitle() {
8987: if (document.getElementById('newresource')) {
1.691 raeburn 8988: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8989: if (selloc == 'course') {
1.606 raeburn 8990: document.getElementById('newresource').style.display = 'inline';
8991: document.courseresform.newresourceadd[0].checked = true;
8992: toggleNewInCourse(document.courseresform);
8993: } else {
8994: document.getElementById('newresource').style.display = 'none';
8995: }
1.689 raeburn 8996: }
8997: if (document.getElementById('newstdproblem')) {
8998: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8999: document.getElementById('newstdproblem').style.display = 'none';
9000: if (document.getElementById('stdprobswitch')) {
9001: document.getElementById('stdprobswitch').style.display = 'block';
9002: }
9003: } else {
9004: document.getElementById('newstdproblem').style.display = 'block';
9005: if (document.getElementById('stdprobswitch')) {
9006: document.getElementById('stdprobswitch').style.display = 'none';
9007: }
9008: }
9009: }
1.606 raeburn 9010: }
9011:
9012: function toggleNewInCourse(form) {
9013: if (form.newresourceadd.length) {
9014: for (var i=0; i<form.newresourceadd.length; i++) {
9015: if (form.newresourceadd[i].checked) {
9016: if (document.getElementById('newresourcetitle')) {
9017: if (form.newresourceadd[i].value == '1') {
9018: document.getElementById('newresourcetitle').type = 'text';
9019: if (document.getElementById('newrestitle')) {
9020: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
9021: }
9022: } else {
9023: document.getElementById('newresourcetitle').type = 'hidden';
9024: document.getElementById('newresourcetitle').value = '';
9025: if (document.getElementById('newrestitle')) {
9026: document.getElementById('newrestitle').innerHTML = '';
9027: }
9028: }
9029: }
9030: break;
9031: }
9032: }
9033: }
9034: }
9035:
9036: function toggleWithTemplate(form) {
9037: if (form.newresusetemp.length) {
9038: for (var i=0; i<form.newresusetemp.length; i++) {
9039: if (form.newresusetemp[i].checked) {
9040: if (document.getElementById('newrestemplate')) {
9041: if (form.newresusetemp[i].value == '1') {
9042: document.getElementById('newrestemplate').style.display = 'inline';
9043: toggleExampleText();
9044: } else {
9045: form.tempcategory.selectedIndex = 0;
9046: select1template_changed();
9047: document.getElementById('newrestemplate').style.display = 'none';
9048: }
9049: }
9050: }
9051: }
9052: }
9053: }
9054:
9055: function toggleExampleText() {
9056: if (document.getElementById('newresexample')) {
9057: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9058: if (url == '') {
9059: document.getElementById('newresexample').style.fontWeight = 'normal';
9060: } else {
9061: document.getElementById('newresexample').style.fontWeight = 'bold';
9062: }
9063: }
9064: }
9065:
9066: function getExample(width,height,scrolling,transparency) {
9067: var url;
9068: if (document.courseresform.newresusetemp.length) {
9069: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
9070: if (document.courseresform.newresusetemp[i].checked) {
9071: if (document.courseresform.newresusetemp[i].value == '1') {
9072: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9073: if (url == '') {
9074: alert('Pick a category and template');
9075: } else {
9076: url = url.replace("$londocroot","");
9077: url += '?inhibitmenu=yes';
9078: }
9079: }
9080: break;
9081: }
9082: }
9083: }
9084: if (url != '') {
9085: openMyModal(url,width,height,scrolling,transparency,'');
9086: }
9087: }
9088:
1.690 raeburn 9089: function toggleImportCrsres(caller) {
1.606 raeburn 9090: var disp = 'none';
9091: if (document.getElementById('importcrsresform')) {
9092: if (caller == 'res') {
9093: var curr = document.getElementById('importcrsresform').style.display;
9094: if (curr == 'none') {
9095: disp='block';
1.698 raeburn 9096: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
9097: if ((document.getElementById('importcrsrescontent')) &&
9098: (document.getElementById('importcrsresempty'))) {
9099: var selelem = document.crsresimportform.elements['coursepath'];
9100: var numdirs = 0;
9101: if (selelem.options.length) {
9102: numdirs = selelem.options.length - 1;
9103: }
9104: if (numdirs) {
9105: document.getElementById('importcrsrescontent').style.display='block';
9106: document.getElementById('importcrsresempty').style.display='none';
9107: } else {
9108: document.getElementById('importcrsrescontent').style.display='none';
9109: document.getElementById('importcrsresempty').style.display='block';
9110: }
9111: }
1.606 raeburn 9112: }
9113: }
9114: document.getElementById('importcrsresform').style.display=disp;
1.706 raeburn 9115: if (disp == 'block') {
9116: if (document.getElementById('importmapform')) {
9117: if (document.getElementById('importmapform').style.display == 'block') {
9118: document.getElementById('importmapform').style.display = 'none';
9119: }
9120: }
9121: }
1.606 raeburn 9122: resize_scrollbox('contentscroll','1','0');
9123: }
9124: return;
9125: }
9126:
1.690 raeburn 9127: $showfile_js
9128:
1.691 raeburn 9129: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
9130: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
9131: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
9132: var selelem = form.elements[dirsel];
9133: var i, numfiles = selelem.options.length -1;
9134: if (numfiles >=0) {
9135: for (i = numfiles; i >= 0; i--) {
9136: selelem.remove(i);
9137: }
9138: }
9139: if ((location == '') || (location == null) || (location == 'undefined')) {
9140: if (selelem.options.length == 0) {
9141: selelem.options[selelem.options.length] = new Option('','');
9142: selelem.selectedIndex = 0;
9143: }
9144: if (document.getElementById('newstdproblem')) {
9145: document.getElementById('newstdproblem').style.display = 'none';
9146: }
9147: return;
9148: }
9149: var machineIds = new Array($machines_str);
9150: var athome = 0;
9151: var role = location;
9152: if ((location == 'author') || (location == 'course')) {
9153: if (document.getElementById('rolehome_'+location)) {
9154: var currhome = document.getElementById('rolehome_'+location).value;
9155: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9156: if (machineIds.includes(currhome)) {
9157: athome = 1;
9158: }
9159: }
9160: }
9161: } else {
9162: const roleinfo = location.split('___');
9163: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
9164: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
9165: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
9166: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9167: if (machineIds.includes(currhome)) {
9168: athome = 1;
9169: }
9170: }
9171: }
9172: }
1.706 raeburn 9173: var templateradio = document.courseresform.elements['newresusetemp'];
1.691 raeburn 9174: if (athome) {
9175: if (document.getElementById('stdprobswitch')) {
9176: document.getElementById('stdprobswitch').style.display = 'none';
9177: }
9178: if (document.getElementById('newstdproblem')) {
9179: document.getElementById('newstdproblem').style.display = 'none';
9180: }
1.706 raeburn 9181: var canedit = '$canedit';
9182: if (canedit) {
9183: if (templateradio.length > 1) {
9184: for (var i=0; i<templateradio.length; i++) {
9185: templateradio[i].disabled = false;
9186: }
9187: }
9188: document.courseresform.newresourcename.disabled = false;
9189: document.courseresform.newcrs.disabled = false;
9190: }
1.691 raeburn 9191: var http = new XMLHttpRequest();
9192: var url = "/adm/courseauthor";
1.698 raeburn 9193: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 9194: http.open("POST", url, true);
9195: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
9196: http.onreadystatechange = function() {
9197: if (http.readyState == 4 && http.status == 200) {
9198: var data = JSON.parse(http.responseText);
9199: if (Array.isArray(data.dirs)) {
9200: var len = data.dirs.length;
9201: if (len) {
9202: if (len > 1) {
9203: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
9204: }
9205: }
9206: if (len) {
9207: var j;
9208: for (j = 0; j < len; j++) {
9209: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
9210: }
9211: selelem.selectedIndex = 0;
1.697 raeburn 9212: if (len == 1) {
9213: toggleCrsResTitle();
9214: }
1.691 raeburn 9215: }
9216: }
9217: }
9218: }
9219: http.send(params);
9220: } else {
9221: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
9222: selelem.selectedIndex = 0;
9223: if (document.getElementById('stdprobswitch')) {
9224: document.getElementById('stdprobswitch').style.display = 'block';
9225: }
9226: if (document.getElementById('newstdproblem')) {
9227: document.getElementById('newstdproblem').style.display = 'none';
9228: }
1.706 raeburn 9229: if (templateradio.length > 1) {
9230: for (var i=0; i<templateradio.length; i++) {
9231: templateradio[i].disabled = true;
9232: }
9233: }
9234: document.courseresform.newresourcename.disabled = true;
9235: document.courseresform.newcrs.disabled = true;
1.691 raeburn 9236: }
9237: }
9238: return;
9239: }
9240:
1.689 raeburn 9241: function switchForProb() {
9242: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
9243: var url = '/adm/switchserver?otherserver=';
9244: var newhostid = '';
9245: var role = '';
9246: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9247: if (selloc == 'author') {
9248: newhostid = document.courseresform.rolehome_author.value;
9249: role = "au./&js_escape($env{'user.domain'})/";
9250: } else if (selloc == 'course') {
9251: newhostid = document.courseresform.rolehome_course.value;
9252: role = "&js_escape($env{'request.role'})";
9253: } else {
9254: var items = new Array();
9255: items = selloc.split('___');
9256: var len = document.courseresform.rolehome_coauthor.length;
9257: if (null == len) {
9258: var currval = document.courseresform.rolehome_coauthor.value;
9259: if (null != currval) {
9260: var info = new Array();
9261: info = currval.split('=');
9262: newhostid = info[2];
9263: role = info[0]+'./'+info[1];
9264: }
9265: } else {
9266: for (var i=0; i<len; i++) {
9267: var currval = document.courseresform.rolehome_coauthor[i].value;
9268: if (null != currval) {
9269: var info = new Array();
9270: info = currval.split('=');
9271: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
9272: newhostid = info[2];
9273: role = info[0]+'./'+info[1];
9274: break;
9275: }
9276: }
9277: }
9278: }
9279: }
9280: if (newhostid != '') {
9281: url += newhostid;
9282: if (role != '') {
9283: url += '&role='+role;
9284: }
9285: document.location.href = url;
9286: }
9287: }
9288: return;
9289: }
9290:
1.501 raeburn 9291: function makeims(imsform) {
9292: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 9293: alert("$js_lt{'imsfile'}");
1.501 raeburn 9294: return;
9295: }
9296: if (imsform.source.selectedIndex == 0) {
1.594 damieng 9297: alert("$js_lt{'imscms'}");
1.501 raeburn 9298: return;
9299: }
9300: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
9301: imsform.submit();
9302: }
9303:
1.478 raeburn 9304: function updatePick(targetform,index,caller) {
1.537 raeburn 9305: var pickitem;
9306: var picknumitem;
9307: var picknumtext;
9308: if (index == 'all') {
9309: pickitem = document.getElementById('randompickall');
9310: picknumitem = document.getElementById('rpicknumall');
9311: picknumtext = document.getElementById('rpicktextall');
9312: } else {
9313: pickitem = document.getElementById('randompick_'+index);
9314: picknumitem = document.getElementById('rpicknum_'+index);
9315: picknumtext = document.getElementById('randompicknum_'+index);
9316: }
1.478 raeburn 9317: if (pickitem.checked) {
1.594 damieng 9318: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 9319: if (picknum == '' || picknum == null) {
9320: if (caller == 'check') {
9321: pickitem.checked=false;
1.537 raeburn 9322: if (index == 'all') {
9323: picknumtext.innerHTML = '';
9324: if (caller == 'link') {
9325: propagateState(targetform,'rpicknum');
9326: }
9327: } else {
1.538 raeburn 9328: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9329: }
1.478 raeburn 9330: }
9331: } else {
9332: picknum.toString();
9333: var regexdigit=/^\\d+\$/;
9334: if (regexdigit.test(picknum)) {
9335: picknumitem.value = picknum;
1.537 raeburn 9336: if (index == 'all') {
1.538 raeburn 9337: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 9338: if (caller == 'link') {
9339: propagateState(targetform,'rpicknum');
9340: }
9341: } else {
9342: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 9343: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9344: }
1.478 raeburn 9345: } else {
9346: if (caller == 'check') {
1.537 raeburn 9347: if (index == 'all') {
9348: picknumtext.innerHTML = '';
9349: if (caller == 'link') {
9350: propagateState(targetform,'rpicknum');
9351: }
9352: } else {
9353: pickitem.checked=false;
1.538 raeburn 9354: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9355: }
1.478 raeburn 9356: }
9357: return;
9358: }
9359: }
9360: } else {
1.537 raeburn 9361: picknumitem.value = '';
9362: picknumtext.innerHTML = '';
9363: if (index == 'all') {
9364: if (caller == 'link') {
9365: propagateState(targetform,'rpicknum');
9366: }
9367: } else {
1.538 raeburn 9368: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9369: }
9370: }
9371: }
9372:
9373: function propagateState(form,param) {
9374: if (document.getElementById(param+'all')) {
9375: var setcheck = 0;
9376: var rpick = 0;
9377: if (param == 'rpicknum') {
9378: if (document.getElementById('randompickall')) {
9379: if (document.getElementById('randompickall').checked) {
9380: if (document.getElementById('rpicknumall')) {
9381: rpick = document.getElementById('rpicknumall').value;
9382: }
9383: }
9384: }
9385: } else {
9386: if (document.getElementById(param+'all').checked) {
9387: setcheck = 1;
9388: }
9389: }
1.538 raeburn 9390: var allidxlist;
9391: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9392: if (document.getElementById('all'+param+'idx')) {
9393: allidxlist = document.getElementById('all'+param+'idx').value;
9394: }
9395: var actions = new Array ('remove','cut','copy');
9396: for (var i=0; i<actions.length; i++) {
9397: if (actions[i] != param) {
9398: if (document.getElementById(actions[i]+'all')) {
9399: document.getElementById(actions[i]+'all').checked = false;
9400: }
9401: }
9402: }
9403: }
1.537 raeburn 9404: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 9405: allidxlist = form.allidx.value;
9406: }
9407: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
9408: allidxlist = form.allmapidx.value;
9409: }
9410: if ((allidxlist != '') && (allidxlist != null)) {
9411: var allidxs = allidxlist.split(',');
9412: if (allidxs.length > 1) {
9413: for (var i=0; i<allidxs.length; i++) {
9414: if (document.getElementById(param+'_'+allidxs[i])) {
9415: if (param == 'rpicknum') {
9416: if (document.getElementById('randompick_'+allidxs[i])) {
9417: if (document.getElementById('randompick_'+allidxs[i]).checked) {
9418: document.getElementById(param+'_'+allidxs[i]).value = rpick;
9419: if (rpick > 0) {
9420: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
9421: } else {
9422: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9423: }
9424: }
9425: }
9426: } else {
1.537 raeburn 9427: if (setcheck == 1) {
9428: document.getElementById(param+'_'+allidxs[i]).checked = true;
9429: } else {
9430: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 9431: if (param == 'randompick') {
9432: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9433: }
1.537 raeburn 9434: }
9435: }
9436: }
9437: }
1.538 raeburn 9438: if (setcheck == 1) {
9439: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9440: var actions = new Array('copy','cut','remove');
9441: for (var i=0; i<actions.length; i++) {
9442: var otheractions;
9443: var otheridxs;
9444: if (actions[i] === param) {
9445: continue;
9446: } else {
9447: if (document.getElementById('all'+actions[i]+'idx')) {
9448: otheractions = document.getElementById('all'+actions[i]+'idx').value;
9449: otheridxs = otheractions.split(',');
9450: if (otheridxs.length > 1) {
9451: for (var j=0; j<otheridxs.length; j++) {
9452: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
9453: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
9454: }
1.537 raeburn 9455: }
9456: }
9457: }
1.538 raeburn 9458: }
9459: }
9460: }
9461: }
9462: }
9463: }
9464: }
9465: return;
9466: }
9467:
1.603 raeburn 9468: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 9469: var canedit = '$canedit';
9470: if (canedit == '') {
9471: alert("$js_lt{'edri'}");
9472: return;
9473: }
1.539 raeburn 9474: var dosettings;
9475: var doaction;
1.538 raeburn 9476: var control = document.togglemultsettings;
9477: if (context == 'actions') {
9478: control = document.togglemultactions;
1.539 raeburn 9479: doaction = 1;
9480: } else {
9481: dosettings = 1;
1.538 raeburn 9482: }
1.539 raeburn 9483: if (control) {
9484: if (control.showmultpick.length) {
9485: for (var i=0; i<control.showmultpick.length; i++) {
9486: if (control.showmultpick[i].checked) {
9487: if (control.showmultpick[i].value == 1) {
9488: if (context == 'settings') {
9489: dosettings = 0;
9490: } else {
9491: doaction = 0;
1.538 raeburn 9492: }
9493: }
9494: }
1.537 raeburn 9495: }
9496: }
1.539 raeburn 9497: }
9498: if (context == 'settings') {
9499: if (dosettings == 1) {
1.538 raeburn 9500: targetform.changeparms.value=param;
9501: targetform.submit();
9502: }
1.537 raeburn 9503: }
1.539 raeburn 9504: if (context == 'actions') {
9505: if (doaction == 1) {
9506: targetform.cmd.value=param+'_'+index;
9507: targetform.folderpath.value=folderpath;
9508: targetform.markcopy.value=idx+':'+param;
9509: targetform.copyfolder.value=folder+'.'+container;
9510: if (param == 'remove') {
1.603 raeburn 9511: var doremove = 0;
9512: if (skip_confirm) {
9513: if (confirm_removal) {
9514: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
9515: doremove = 1;
9516: }
9517: } else {
9518: doremove = 1;
9519: }
9520: } else {
9521: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
9522: doremove = 1;
9523: }
9524: }
9525: if (doremove) {
1.539 raeburn 9526: targetform.markcopy.value='';
9527: targetform.copyfolder.value='';
9528: targetform.submit();
9529: }
9530: }
9531: if (param == 'cut') {
1.594 damieng 9532: 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 9533: targetform.submit();
9534: return;
9535: }
9536: }
9537: if (param == 'copy') {
9538: targetform.submit();
9539: return;
9540: }
9541: targetform.markcopy.value='';
9542: targetform.copyfolder.value='';
9543: targetform.cmd.value='';
9544: targetform.folderpath.value='';
9545: return;
9546: } else {
9547: if (document.getElementById(param+'_'+idx)) {
9548: item = document.getElementById(param+'_'+idx);
9549: if (item.type == 'checkbox') {
9550: if (item.checked) {
9551: item.checked = false;
9552: } else {
9553: item.checked = true;
9554: singleCheck(item,idx,param);
9555: }
9556: }
9557: }
9558: }
9559: }
1.537 raeburn 9560: return;
9561: }
9562:
1.538 raeburn 9563: function singleCheck(caller,idx,action) {
9564: actions = new Array('cut','copy','remove');
9565: if (caller.checked) {
9566: for (var i=0; i<actions.length; i++) {
9567: if (actions[i] != action) {
9568: if (document.getElementById(actions[i]+'_'+idx)) {
9569: if (document.getElementById(actions[i]+'_'+idx).checked) {
9570: document.getElementById(actions[i]+'_'+idx).checked = false;
9571: }
1.537 raeburn 9572: }
9573: }
9574: }
1.478 raeburn 9575: }
1.537 raeburn 9576: return;
1.478 raeburn 9577: }
9578:
1.334 muellerd 9579: function unselectInactive(nav) {
1.335 ehlerst 9580: currentNav = document.getElementById(nav);
9581: currentLis = currentNav.getElementsByTagName('LI');
9582: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 9583: if (currentLis[i].className == 'goback') {
9584: currentLis[i].className = 'goback';
9585: } else {
9586: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 9587: currentLis[i].className = 'right';
1.472 raeburn 9588: } else {
1.374 tempelho 9589: currentLis[i].className = 'i';
1.472 raeburn 9590: }
9591: }
1.335 ehlerst 9592: }
1.332 tempelho 9593: }
9594:
1.334 muellerd 9595: function hideAll(current, nav, data) {
1.335 ehlerst 9596: unselectInactive(nav);
1.570 raeburn 9597: if (current) {
9598: if (current.className == 'right'){
9599: current.className = 'right active'
9600: } else {
9601: current.className = 'active';
9602: }
1.374 tempelho 9603: }
1.335 ehlerst 9604: currentData = document.getElementById(data);
9605: currentDivs = currentData.getElementsByTagName('DIV');
9606: for (i = 0; i < currentDivs.length; i++) {
9607: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 9608: currentDivs[i].style.display = 'none';
1.330 tempelho 9609: }
9610: }
1.335 ehlerst 9611: }
1.330 tempelho 9612:
1.374 tempelho 9613: function openTabs(pageId) {
9614: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 9615: if(tabnav.length > 2 ){
1.389 tempelho 9616: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 9617: currentLis = currentNav.getElementsByTagName('LI');
9618: for(i = 0; i< currentLis.length; i++){
9619: if(currentLis[i].className == 'active') {
1.375 tempelho 9620: funcString = currentLis[i].onclick.toString();
9621: tab = funcString.split('"');
1.420 onken 9622: if(tab.length < 2) {
9623: tab = funcString.split("'");
9624: }
1.375 tempelho 9625: currentData = document.getElementById(tab[1]);
9626: currentData.style.display = 'block';
1.374 tempelho 9627: }
9628: }
9629: }
9630: }
9631:
1.334 muellerd 9632: function showPage(current, pageId, nav, data) {
1.570 raeburn 9633: currstate = current.className;
1.334 muellerd 9634: hideAll(current, nav, data);
1.375 tempelho 9635: openTabs(pageId);
1.334 muellerd 9636: unselectInactive(nav);
1.570 raeburn 9637: if ((currstate == 'active') || (currstate == 'right active')) {
9638: if (currstate == 'active') {
9639: current.className = '';
9640: } else {
9641: current.className = 'right';
9642: }
9643: activeTab = '';
1.656 raeburn 9644: toggleExternal();
1.570 raeburn 9645: toggleUpload();
9646: toggleMap();
1.606 raeburn 9647: toggleCrsRes();
9648: toggleImportCrsres();
1.570 raeburn 9649: resize_scrollbox('contentscroll','1','0');
9650: return;
9651: } else {
9652: current.className = 'active';
9653: }
1.330 tempelho 9654: currentData = document.getElementById(pageId);
9655: currentData.style.display = 'block';
1.458 raeburn 9656: activeTab = pageId;
1.656 raeburn 9657: toggleExternal();
1.501 raeburn 9658: toggleUpload();
1.503 raeburn 9659: toggleMap();
1.606 raeburn 9660: toggleCrsRes();
9661: toggleImportCrsres();
1.433 raeburn 9662: if (nav == 'mainnav') {
9663: var storedpath = "$docs_folderpath";
1.434 raeburn 9664: var storedpage = "$main_container_page";
1.433 raeburn 9665: var reg = new RegExp("^supplemental");
9666: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 9667: if (storedpage == 1) {
9668: document.simpleedit.folderpath.value = '';
9669: document.uploaddocument.folderpath.value = '';
9670: } else {
9671: if (reg.test(storedpath)) {
9672: document.simpleedit.folderpath.value = '$toplevelmain';
9673: document.uploaddocument.folderpath.value = '$toplevelmain';
9674: document.newext.folderpath.value = '$toplevelmain';
9675: } else {
9676: document.simpleedit.folderpath.value = storedpath;
9677: document.uploaddocument.folderpath.value = storedpath;
9678: document.newext.folderpath.value = storedpath;
9679: }
1.433 raeburn 9680: }
9681: } else {
1.434 raeburn 9682: if (reg.test(storedpath)) {
9683: document.simpleedit.folderpath.value = storedpath;
9684: document.supuploaddocument.folderpath.value = storedpath;
9685: document.supnewext.folderpath.value = storedpath;
9686: } else {
1.433 raeburn 9687: document.simpleedit.folderpath.value = '$toplevelsupp';
9688: document.supuploaddocument.folderpath.value = '$toplevelsupp';
9689: document.supnewext.folderpath.value = '$toplevelsupp';
9690: }
9691: }
9692: }
1.485 raeburn 9693: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 9694: return false;
9695: }
1.329 droeschl 9696:
1.472 raeburn 9697: function toContents(jumpto) {
9698: var newurl = '$backtourl';
1.525 raeburn 9699: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 9700: newurl = newurl+'?postdata='+jumpto;
9701: }
9702: location.href=newurl;
9703: }
9704:
1.538 raeburn 9705: function togglePick(caller,value) {
9706: var disp = 'none';
9707: if (document.getElementById('multi'+caller)) {
9708: var curr = document.getElementById('multi'+caller).style.display;
9709: if (value == 1) {
9710: disp='block';
9711: }
9712: if (curr == disp) {
9713: return;
9714: }
9715: document.getElementById('multi'+caller).style.display=disp;
9716: if (value == 1) {
1.594 damieng 9717: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 9718: } else {
9719: document.getElementById('more'+caller).innerHTML = '';
9720: }
9721: if (caller == 'actions') {
9722: setClass(value);
9723: setBoxes(value);
9724: }
9725: }
9726: var showButton = multiSettings();
9727: if (showButton != 1) {
9728: showButton = multiActions();
9729: }
9730: if (document.getElementById('multisave')) {
9731: if (showButton == 1) {
9732: document.getElementById('multisave').style.display='block';
9733: } else {
9734: document.getElementById('multisave').style.display='none';
9735: }
9736: }
9737: resize_scrollbox('contentscroll','1','1');
9738: return;
9739: }
9740:
9741: function toggleCheckUncheck(caller,more) {
9742: if (more == 1) {
1.594 damieng 9743: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 9744: document.getElementById('allfields'+caller).style.display='block';
9745: } else {
1.594 damieng 9746: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 9747: document.getElementById('allfields'+caller).style.display='none';
9748: }
9749: resize_scrollbox('contentscroll','1','1');
9750: }
9751:
9752: function multiSettings() {
9753: var inuse = 0;
9754: var settingsform = document.togglemultsettings;
9755: if (settingsform.showmultpick.length > 1) {
9756: for (var i=0; i<settingsform.showmultpick.length; i++) {
9757: if (settingsform.showmultpick[i].checked) {
9758: if (settingsform.showmultpick[i].value == 1) {
9759: inuse = 1;
9760: }
9761: }
9762: }
9763: }
9764: return inuse;
9765: }
9766:
9767: function multiActions() {
9768: var inuse = 0;
9769: var actionsform = document.togglemultactions;
9770: if (actionsform.showmultpick.length > 1) {
9771: for (var i=0; i<actionsform.showmultpick.length; i++) {
9772: if (actionsform.showmultpick[i].checked) {
9773: if (actionsform.showmultpick[i].value == 1) {
9774: inuse = 1;
9775: }
9776: }
9777: }
9778: }
9779: return inuse;
9780: }
9781:
9782: function checkSubmits() {
9783: var numchanges = 0;
9784: var form = document.saveactions;
9785: var doactions = multiActions();
1.542 raeburn 9786: var cutwarnings = 0;
9787: var remwarnings = 0;
1.603 raeburn 9788: var removalinfo = 0;
1.538 raeburn 9789: if (doactions == 1) {
9790: var remidxlist = document.cumulativeactions.allremoveidx.value;
9791: if ((remidxlist != '') && (remidxlist != null)) {
9792: var remidxs = remidxlist.split(',');
9793: for (var i=0; i<remidxs.length; i++) {
9794: if (document.getElementById('remove_'+remidxs[i])) {
9795: if (document.getElementById('remove_'+remidxs[i]).checked) {
9796: form.multiremove.value += remidxs[i]+',';
9797: numchanges ++;
1.542 raeburn 9798: if (document.getElementById('skip_remove_'+remidxs[i])) {
9799: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
9800: remwarnings ++;
9801: }
9802: }
1.603 raeburn 9803: if (document.getElementById('confirm_removal_'+remidxs[i])) {
9804: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
9805: removalinfo ++;
9806: }
9807: }
1.537 raeburn 9808: }
9809: }
1.538 raeburn 9810: }
9811: }
9812: var cutidxlist = document.cumulativeactions.allcutidx.value;
9813: if ((cutidxlist != '') && (cutidxlist != null)) {
9814: var cutidxs = cutidxlist.split(',');
9815: for (var i=0; i<cutidxs.length; i++) {
9816: if (document.getElementById('cut_'+cutidxs[i])) {
9817: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
9818: form.multicut.value += cutidxs[i]+',';
9819: numchanges ++;
1.542 raeburn 9820: if (document.getElementById('skip_cut_'+cutidxs[i])) {
9821: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
9822: cutwarnings ++;
9823: }
9824: }
1.537 raeburn 9825: }
9826: }
9827: }
9828: }
1.538 raeburn 9829: var copyidxlist = document.cumulativeactions.allcopyidx.value;
9830: if ((copyidxlist != '') && (copyidxlist != null)) {
9831: var copyidxs = copyidxlist.split(',');
9832: for (var i=0; i<copyidxs.length; i++) {
9833: if (document.getElementById('copy_'+copyidxs[i])) {
9834: if (document.getElementById('copy_'+copyidxs[i]).checked) {
9835: form.multicopy.value += copyidxs[i]+',';
9836: numchanges ++;
9837: }
9838: }
9839: }
9840: }
9841: if (numchanges > 0) {
9842: form.multichange.value = numchanges;
9843: }
1.537 raeburn 9844: }
1.538 raeburn 9845: var dosettings = multiSettings();
1.543 raeburn 9846: var haschanges = 0;
1.538 raeburn 9847: if (dosettings == 1) {
9848: form.allencrypturl.value = '';
9849: form.allhiddenresource.value = '';
1.543 raeburn 9850: form.changeparms.value = 'all';
9851: var patt=new RegExp(",\$");
1.538 raeburn 9852: var allidxlist = document.cumulativesettings.allidx.value;
9853: if ((allidxlist != '') && (allidxlist != null)) {
9854: var allidxs = allidxlist.split(',');
9855: if (allidxs.length > 1) {
9856: for (var i=0; i<allidxs.length; i++) {
9857: if (document.getElementById('hiddenresource_'+allidxs[i])) {
9858: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
9859: form.allhiddenresource.value += allidxs[i]+',';
9860: }
9861: }
9862: if (document.getElementById('encrypturl_'+allidxs[i])) {
9863: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
9864: form.allencrypturl.value += allidxs[i]+',';
9865: }
9866: }
9867: }
1.543 raeburn 9868: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
9869: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 9870: }
1.538 raeburn 9871: }
9872: form.allrandompick.value = '';
9873: form.allrandomorder.value = '';
9874: var allmapidxlist = document.cumulativesettings.allmapidx.value;
9875: if ((allmapidxlist != '') && (allmapidxlist != null)) {
9876: var allmapidxs = allmapidxlist.split(',');
9877: for (var i=0; i<allmapidxs.length; i++) {
9878: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
9879: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
9880: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
9881: if ((randompick.checked) && (rpicknum.value != '')) {
9882: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
9883: }
9884: if (randorder.checked) {
9885: form.allrandomorder.value += allmapidxs[i]+',';
9886: }
1.537 raeburn 9887: }
1.543 raeburn 9888: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
9889: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
9890: }
9891: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
9892: haschanges = 1;
9893: }
9894: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
9895: haschanges = 1;
9896: }
9897: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
9898: haschanges = 1;
9899: }
9900: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
9901: haschanges = 1;
1.537 raeburn 9902: }
9903: }
1.543 raeburn 9904: if (doactions == 1) {
1.542 raeburn 9905: if (numchanges > 0) {
1.603 raeburn 9906: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 9907: if (remwarnings > 0) {
1.594 damieng 9908: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 9909: return false;
9910: }
9911: }
1.603 raeburn 9912: if (removalinfo > 0) {
9913: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
9914: return false;
9915: }
9916: }
1.542 raeburn 9917: if (cutwarnings > 0) {
1.594 damieng 9918: 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 9919: return false;
9920: }
9921: }
9922: }
9923: form.submit();
9924: return true;
1.543 raeburn 9925: }
9926: }
9927: if (dosettings == 1) {
9928: if (haschanges == 1) {
1.542 raeburn 9929: form.submit();
9930: return true;
9931: }
1.543 raeburn 9932: }
9933: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 9934: alert("$js_lt{'noor'}");
1.543 raeburn 9935: } else {
9936: if (dosettings == 1) {
1.594 damieng 9937: alert("$js_lt{'noch'}");
1.543 raeburn 9938: } else {
1.594 damieng 9939: alert("$js_lt{'noac'}");
1.543 raeburn 9940: }
9941: }
1.538 raeburn 9942: return false;
9943: }
9944:
9945: function setClass(value) {
9946: var cutclass = 'LC_docs_cut';
9947: var copyclass = 'LC_docs_copy';
9948: var removeclass = 'LC_docs_remove';
9949: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
9950: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
9951: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
9952: var links = document.getElementsByTagName('a');
9953: for (var i=0; i<links.length; i++) {
9954: var classes = links[i].className;
9955: if (cutreg.test(classes)) {
9956: links[i].className = cutclass;
9957: if (value == 1) {
9958: links[i].className += " LC_menubuttons_link";
9959: }
9960: } else {
9961: if (copyreg.test(classes)) {
9962: links[i].className = copyclass;
9963: if (value == 1) {
9964: links[i].className += " LC_menubuttons_link";
9965: }
9966: } else {
9967: if (removereg.test(classes)) {
9968: links[i].className = removeclass;
9969: if (value == 1) {
9970: links[i].className += " LC_menubuttons_link";
9971: }
9972: }
9973: }
9974: }
9975: }
9976: return;
1.537 raeburn 9977: }
9978:
1.538 raeburn 9979: function setBoxes(value) {
9980: var remidxlist = document.cumulativeactions.allremoveidx.value;
9981: if ((remidxlist != '') && (remidxlist != null)) {
9982: var remidxs = remidxlist.split(',');
9983: for (var i=0; i<remidxs.length; i++) {
9984: if (document.getElementById('remove_'+remidxs[i])) {
9985: var item = document.getElementById('remove_'+remidxs[i]);
9986: if (value == 1) {
9987: item.className = 'LC_docs_remove';
9988: } else {
9989: item.className = 'LC_hidden';
9990: }
9991: }
9992: }
9993: }
9994: var cutidxlist = document.cumulativeactions.allcutidx.value;
9995: if ((cutidxlist != '') && (cutidxlist != null)) {
9996: var cutidxs = cutidxlist.split(',');
9997: for (var i=0; i<cutidxs.length; i++) {
9998: if (document.getElementById('cut_'+cutidxs[i])) {
9999: var item = document.getElementById('cut_'+cutidxs[i]);
10000: if (value == 1) {
10001: item.className = 'LC_docs_cut';
10002: } else {
10003: item.className = 'LC_hidden';
10004: }
10005: }
1.537 raeburn 10006: }
10007: }
1.538 raeburn 10008: var copyidxlist = document.cumulativeactions.allcopyidx.value;
10009: if ((copyidxlist != '') && (copyidxlist != null)) {
10010: var copyidxs = copyidxlist.split(',');
10011: for (var i=0; i<copyidxs.length; i++) {
10012: if (document.getElementById('copy_'+copyidxs[i])) {
10013: var item = document.getElementById('copy_'+copyidxs[i]);
10014: if (value == 1) {
10015: item.className = 'LC_docs_copy';
10016: } else {
10017: item.className = 'LC_hidden';
10018: }
10019: }
1.537 raeburn 10020: }
10021: }
10022: return;
10023: }
10024:
1.606 raeburn 10025: function validImportCrsRes() {
10026: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
10027: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
10028: if ((fname == '') || (fname == null)) {
10029: alert("$js_lt{'nofi'}");
10030: return false;
10031: }
10032: var url = '/res/$coursedom/$coursenum/';
10033: if (path && path != '/') {
10034: url += path+'/';
10035: }
10036: if (fname != '') {
10037: url += fname;
10038: }
10039: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 10040: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 10041: return true;
10042: }
10043:
10044: function validateNewRes(caller) {
10045: if (caller == 'single') {
10046: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
10047: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
10048: var resname = document.courseresform.newresourcename.value;
10049: }
10050: }
10051:
1.611 raeburn 10052: ENDSCRIPT
1.329 droeschl 10053: }
1.457 raeburn 10054:
1.483 raeburn 10055: sub history_tab_js {
10056: return <<"ENDHIST";
10057: function toggleHistoryDisp(choice) {
10058: document.docslogform.docslog.value = choice;
10059: document.docslogform.submit();
10060: return;
10061: }
10062:
10063: ENDHIST
10064: }
10065:
1.484 raeburn 10066: sub inject_data_js {
10067: return <<ENDINJECT;
10068:
10069: function injectData(current, hiddenField, name, value) {
10070: currentElement = document.getElementById(hiddenField);
10071: currentElement.name = name;
10072: currentElement.value = value;
10073: current.submit();
10074: }
10075:
10076: ENDINJECT
10077: }
10078:
10079: sub dump_switchserver_js {
10080: my @hosts = @_;
1.594 damieng 10081: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 10082: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 10083: swit => 'Switch server?',
1.594 damieng 10084: );
10085: my %html_js_lt = &Apache::lonlocal::texthash(
10086: swit => 'Switch server?',
1.709 raeburn 10087: duco => 'Copying uploaded content to Authoring Space',
1.484 raeburn 10088: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
10089: chos => 'Choose server',
10090: );
1.594 damieng 10091: &js_escape(\%js_lt);
10092: &html_escape(\%html_js_lt);
10093: &js_escape(\%html_js_lt);
1.484 raeburn 10094: my $role = $env{'request.role'};
10095: my $js = <<"ENDSWJS";
10096: <script type="text/javascript">
10097: function write_switchserver() {
10098: var server;
10099: if (document.setserver.posshosts.length > 0) {
10100: for (var i=0; i<document.setserver.posshosts.length; i++) {
10101: if (document.setserver.posshosts[i].checked) {
10102: server = document.setserver.posshosts[i].value;
10103: }
10104: }
10105: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
10106: }
10107: window.close();
10108: }
10109: </script>
10110:
10111: ENDSWJS
10112:
10113: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
10114: {'only_body' => 1,
10115: 'js_ready' => 1,});
10116: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
10117:
10118: my $hostpicker;
10119: my $count = 0;
10120: foreach my $host (sort(@hosts)) {
10121: my $checked;
10122: if ($count == 0) {
10123: $checked = ' checked="checked"';
10124: }
10125: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
10126: $host.'"'.$checked.' />'.$host.'</label> ';
10127: $count++;
10128: }
10129:
10130: return <<"ENDSWITCHJS";
10131:
10132: function dump_needs_switchserver(url) {
10133: if (url!='' && url!= null) {
1.594 damieng 10134: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 10135: go(url);
10136: }
10137: }
10138: return;
10139: }
10140:
10141: function choose_switchserver_window() {
10142: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
10143: newWindow.document.open();
10144: newWindow.document.writeln('$startpage');
1.594 damieng 10145: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
10146: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
10147: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 10148: '<form name="setserver" method="post" action="" \\/>\\n'+
10149: '$hostpicker\\n'+
10150: '<br \\/><br \\/>\\n'+
1.594 damieng 10151: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 10152: 'onclick="write_switchserver();" \\/>\\n'+
10153: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
10154: newWindow.document.writeln('$endpage');
10155: newWindow.document.close();
10156: newWindow.focus();
10157: }
10158:
10159: ENDSWITCHJS
10160: }
10161:
10162: sub makedocslogform {
10163: my ($formelems,$docslog) = @_;
10164: return <<"LOGSFORM";
10165: <form action="/adm/coursedocs" method="post" name="docslogform">
10166: <input type="hidden" name="docslog" value="$docslog" />
10167: $formelems
10168: </form>
10169: LOGSFORM
10170: }
10171:
10172: sub makesimpleeditform {
10173: my ($formelems) = @_;
10174: return <<"SIMPFORM";
10175: <form name="simpleedit" method="post" action="/adm/coursedocs">
10176: <input type="hidden" name="importdetail" value="" />
10177: $formelems
10178: </form>
10179: SIMPFORM
10180: }
10181:
1.606 raeburn 10182: sub makenewproblem {
10183: my ($r,$coursedom,$coursenum) = @_;
10184: # Creating a new problem
10185: my ($redirect,$error);
10186: if ($env{'form.authorrole'}) {
10187: my ($newsubdir,$filename);
10188: if ($env{'form.newsubdir'}) {
10189: if ($env{'form.newsubdirname'} ne '') {
10190: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 10191: }
1.606 raeburn 10192: }
10193: if ($env{'form.newresourcename'}) {
10194: $filename = $env{'form.newresourcename'};
10195: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
10196: $filename =~ s/`//g;
10197: $filename =~ s{/\.\./}{_}g;
10198: $filename =~ s/\.+/./g;
10199: $filename =~ s{/+}{_}g;
10200: if ($filename ne '') {
10201: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
10202: if (($ext) && ($ext ne '.problem')) {
10203: $filename = $name.'.problem';
10204: } elsif ($ext eq '') {
10205: $filename .= '.problem';
10206: }
10207: my $docroot = $r->dir_config('lonDocRoot');
10208: my @ids=&Apache::lonnet::current_machine_ids();
10209: if ($env{'form.authorrole'} eq 'author') {
10210: if ($env{'user.author'}) {
10211: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
10212: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
10213: my $path = $docroot.$url;
10214: my $subdir = $env{'form.authorpath'};
10215: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10216: }
10217: }
10218: } elsif ($env{'form.authorrole'} eq 'course') {
10219: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
10220: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
10221: my $url = "/priv/$coursedom/$coursenum";
10222: my $path=$docroot.$url;
10223: my $subdir = $env{'form.authorpath'};
10224: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10225: if ($redirect) {
10226: my $rightsfile = 'default.rights';
10227: my $sourcerights = "$path/$rightsfile";
1.709 raeburn 10228: &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom);
1.606 raeburn 10229: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
1.654 raeburn 10230: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
10231: if (!-e "$docroot/res/$coursedom") {
10232: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 10233: }
1.654 raeburn 10234: if (!-e "$docroot/res/$coursedom/$coursenum") {
10235: mkdir("$docroot/res/$coursedom/$coursenum",0755);
10236: }
10237: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
10238: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
10239: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 10240: }
10241: }
1.654 raeburn 10242: my $source = $docroot.$redirect;
10243: if (!-e "$source.meta") {
10244: my $cid = $coursedom.'_'.$coursenum;
10245: my $now = time;
10246: if (open(my $fh,">$source.meta")) {
10247: my $author=$env{'environment.firstname'}.' '.
10248: $env{'environment.middlename'}.' '.
10249: $env{'environment.lastname'}.' '.
10250: $env{'environment.generation'};
10251: $author =~ s/\s+$//;
10252: my $title = $env{'form.newresourcetitle'};
10253: $title =~ s/^\s+|\s+$//g;
10254: print $fh <<END;
1.606 raeburn 10255:
10256: <abstract></abstract>
10257: <author>$author</author>
10258: <authorspace>$coursenum:$coursedom</authorspace>
10259: <copyright>custom</copyright>
10260: <creationdate>$now</creationdate>
10261: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
10262: <dependencies></dependencies>
10263: <domain>$coursedom</domain>
10264: <highestgradelevel>0</highestgradelevel>
10265: <keywords></keywords>
10266: <language>notset </language>
10267: <lastrevisiondate>$now</lastrevisiondate>
10268: <lowestgradelevel>0</lowestgradelevel>
10269: <mime>problem</mime>
10270: <modifyinguser>$coursenum:$coursedom</modifyinguser>
10271: <notes></notes>
10272: <obsolete></obsolete>
10273: <obsoletereplacement></obsoletereplacement>
10274: <owner>$coursenum:$coursedom</owner>
10275: <sourceavail></sourceavail>
10276: <standards></standards>
10277: <subject></subject>
10278: <title>$title</title>
10279: END
1.654 raeburn 10280: close($fh);
1.606 raeburn 10281: }
10282: }
10283: }
10284: }
10285: } else {
10286: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
10287: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
10288: if (grep(/^\Q$rolehome\E$/,@ids)) {
10289: my $now = time;
10290: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
10291: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
10292: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
10293: my $url = "/priv/$audom/$auname";
10294: my $path = $r->dir_config('lonDocRoot').$url;
10295: my $subdir = $env{'form.authorpath'};
10296: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10297: }
10298: }
10299: }
10300: }
10301: }
10302: }
10303: }
10304: return ($redirect,$error);
10305: }
10306:
10307: sub finishnewprob {
1.654 raeburn 10308: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 10309: unless (-d $path) {
10310: unless (mkdir($path,02770)) {
10311: return;
10312: }
10313: }
1.606 raeburn 10314: my $redirect;
10315: if ($subdir ne '/') {
10316: $subdir = &cleandir($subdir);
10317: if (($subdir ne '') && (-d "$path/$subdir")) {
10318: $path .= "/$subdir";
10319: $url .= "/$subdir";
10320: }
10321: }
10322: my $dest;
10323: if ($newsubdir ne '') {
10324: $newsubdir = &cleandir($newsubdir);
10325: }
10326: if ($newsubdir ne '') {
10327: if (-d "$path/$newsubdir") {
10328: $dest = "$path/$newsubdir/$filename";
10329: } else {
10330: my $dirok;
10331: unless (-e "$path/$newsubdir") {
10332: if (mkdir("$path/$newsubdir",02770)) {
10333: if (chmod(02770,"$path/$newsubdir")) {
10334: $dirok = 1;
10335: }
10336: }
10337: }
10338: if ($dirok) {
10339: $dest = "$path/$newsubdir/$filename";
10340: }
10341: }
10342: if (($dest ne '') && (!-e $dest)) {
10343: $redirect = "$url/$newsubdir/$filename";
10344: }
10345: } else {
10346: $dest = "$path/$filename";
10347: if (($dest ne '') && (!-e $dest)) {
10348: $redirect = "$url/$filename";
10349: }
10350: }
1.654 raeburn 10351: if ((!-e $dest) && ($context ne 'upload')) {
10352: my $template = $env{'form.template'};
10353: my $copyfrom;
10354: if ($template ne '') {
10355: my %templates;
10356: my @files = &Apache::lonhomework::get_template_list('problem');
10357: foreach my $poss (@files) {
10358: if (ref($poss) eq 'ARRAY') {
10359: if ($template eq $poss->[0]) {
10360: $templates{$template} = 1;
10361: last;
10362: }
10363: }
10364: }
10365: if ($templates{$template}) {
10366: $copyfrom = $template;
10367: }
10368: }
10369: if ($filename =~ /\.problem$/) {
10370: unless ($copyfrom) {
10371: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
10372: }
10373: &File::Copy::copy($copyfrom,$dest);
10374: }
10375: }
1.606 raeburn 10376: return $redirect;
10377: }
10378:
10379: sub cleandir {
10380: my ($dir) = @_;
10381: $dir =~ s/^\s+//;
10382: $dir =~ s/\s+$//;
10383: $dir =~ s/\.+//g;
10384: $dir =~ s/[\#\?&%\":]//g;
10385: return $dir;
10386: }
10387:
1.329 droeschl 10388: 1;
10389: __END__
10390:
10391:
10392: =head1 NAME
10393:
10394: Apache::londocs.pm
10395:
10396: =head1 SYNOPSIS
10397:
10398: This is part of the LearningOnline Network with CAPA project
10399: described at http://www.lon-capa.org.
10400:
10401: =head1 SUBROUTINES
10402:
10403: =over
10404:
10405: =item %help=()
10406:
10407: Available help topics
10408:
10409: =item mapread()
10410:
1.344 bisitz 10411: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 10412: @order and @resources, determines status
10413: sets @order - pointer to resources in right order
10414: sets @resources - array with the resources with correct idx
10415:
10416: =item authorhosts()
10417:
10418: Return hash with valid author names
10419:
10420: =item clean()
10421:
10422: =item dumpcourse()
10423:
10424: Actually dump course
10425:
10426: =item group_import()
10427:
10428: Imports the given (name, url) resources into the course
10429: coursenum, coursedom, and folder must precede the list
10430:
10431: =item breadcrumbs()
10432:
10433: =item log_docs()
10434:
10435: =item docs_change_log()
10436:
10437: =item update_paste_buffer()
10438:
10439: =item print_paste_buffer()
10440:
10441: =item do_paste_from_buffer()
10442:
1.538 raeburn 10443: =item do_buffer_empty()
10444:
10445: =item clear_from_buffer()
10446:
1.492 raeburn 10447: =item get_newmap_url()
10448:
10449: =item dbcopy()
10450:
10451: =item uniqueness_check()
10452:
10453: =item contained_map_check()
10454:
10455: =item url_paste_fixups()
10456:
10457: =item apply_fixups()
10458:
10459: =item copy_dependencies()
10460:
1.329 droeschl 10461: =item update_parameter()
10462:
10463: =item handle_edit_cmd()
10464:
10465: =item editor()
10466:
10467: =item process_file_upload()
10468:
10469: =item process_secondary_uploads()
10470:
10471: =item is_supplemental_title()
10472:
10473: =item entryline()
10474:
10475: =item tiehash()
10476:
10477: =item untiehash()
10478:
10479: =item checkonthis()
10480:
10481: check on this
10482:
10483: =item verifycontent()
10484:
10485: Verify Content
10486:
1.636 raeburn 10487: =item devalidateversioncache()
10488:
10489: =item checkversions()
1.329 droeschl 10490:
10491: Check Versions
10492:
10493: =item mark_hash_old()
10494:
10495: =item is_hash_old()
10496:
10497: =item changewarning()
10498:
10499: =item init_breadcrumbs()
10500:
10501: Breadcrumbs for special functions
10502:
1.484 raeburn 10503: =item create_list_elements()
10504:
10505: =item create_form_ul()
10506:
10507: =item startContentScreen()
10508:
10509: =item endContentScreen()
10510:
10511: =item supplemental_base()
10512:
10513: =item embedded_form_elems()
10514:
10515: =item embedded_destination()
10516:
10517: =item return_to_editor()
10518:
10519: =item decompression_info()
10520:
10521: =item decompression_phase_one()
10522:
10523: =item decompression_phase_two()
10524:
10525: =item remove_archive()
10526:
10527: =item generate_admin_menu()
10528:
10529: =item generate_edit_table()
10530:
10531: =item editing_js()
10532:
10533: =item history_tab_js()
10534:
10535: =item inject_data_js()
10536:
10537: =item dump_switchserver_js()
10538:
1.485 raeburn 10539: =item resize_scrollbox_js()
1.484 raeburn 10540:
10541: =item makedocslogform()
10542:
1.485 raeburn 10543: =item makesimpleeditform()
10544:
1.329 droeschl 10545: =back
10546:
10547: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>