Annotation of loncom/interface/londocs.pm, revision 1.713
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.713 ! raeburn 4: # $Id: londocs.pm,v 1.712 2024/12/20 15:15:04 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: }
726: my %origcrsdata=&Apache::lonnet::coursedescription($env{'request.course.id'});
727: my $exclude = &Apache::lonnet::priv_exclude();
728: my $srcurl = "/priv/$coursedom/$coursenum";
729: my $srctop = $r->dir_config('lonDocRoot').$srcurl;
730: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
731: $r->print('<h3>'.&mt('Copying Files and/or Sub-directories').'</h3>');
732: if ($readonly) {
733: $r->print('<p class="LC_info">'.
734: &mt('You do not have permission to copy files and/or directories from Course Authoring Space.').
735: '</p>'.
736: &endContentScreen());
737: return '';
738: }
739: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
740: $r->print('<p class="LC_info">'.&mt('Selected Authoring Space is not on this server.').'</p>'.
741: &endContentScreen());
742: return '';
743: }
744: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
745: my $desturl = "/priv/$cd/$ca";
746: my $desttop = $r->dir_config('lonDocRoot').$desturl;
747: my $subdir = &clean($env{'form.authorfolder'});
748: $subdir = &cleandir($subdir);
749: if ($subdir eq '') {
750: $r->print('<p class="LC_info">'.&mt('After removal of disallowed characters target sub-directory name was blank.').'</p>'.
751: &endContentScreen());
752: return '';
753: } elsif ($subdir =~/^_+$/) {
754: $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>'.
755: &endContentScreen());
756: return '';
757: }
758: my $is_course_home;
759: my @ids=&Apache::lonnet::current_machine_ids();
760: if (($coursehome ne '') && (grep(/^\Q$coursehome\E$/,@ids))) {
761: $is_course_home = 1;
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);
767: &Apache::lonnet::recursedirs($home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files);
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.713 ! raeburn 808: my ($notopdir,%newdir,%newfile,%checkdeps);
1.712 raeburn 809: $r->print('<p>'.&mt('Copy to: [_1]',
810: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
811: '</p>'."\n");
812: unless ($is_course_home) {
813: $r->print('<p class="LC_info>'.&mt("Session needs to be hosted on course's home server.").
814: '</p>'.
815: &endContentScreen());
816: return '';
817: }
818: if (keys(%dirs_to_make)) {
819: if ($is_course_home) {
820: unless (-e $desttop.'/'.$subdir) {
821: mkdir($desttop.'/'.$subdir,0755);
822: }
823: if (-e $desttop.'/'.$subdir) {
824: foreach my $dir (sort(keys(%dirs_to_make))) {
825: my @dirs=split(/\//,$dir);
826: my $path="$desttop/$subdir";
827: my $makepath=$path;
828: my $fail;
829: for (my $i=0;$i<@dirs;$i++) {
830: $makepath.='/'.$dirs[$i];
831: unless (-e $makepath) {
832: unless (mkdir($makepath,0755)) {
833: $fail = 1;
834: last;
835: }
836: if (($i == scalar(@dirs)-1) && (!$fail)) {
837: $newdir{$dir} = 1;
838: }
839: }
840: }
841: if ($fail) {
842: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
843: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$dir.'</span>').
844: '</p>'."\n");
845: }
846: }
847: } else {
848: $notopdir = 1;
849: }
850: }
851: }
852: if (keys(%files_to_copy)) {
853: if ($is_course_home) {
854: unless (-e $desttop.'/'.$subdir) {
855: mkdir($desttop.'/'.$subdir,0755);
856: }
857: if (-e $desttop.'/'.$subdir) {
858: my $num = 0;
859: foreach my $file (keys(%files_to_copy)) {
860: my ($fail,$dup,$dir_is_file,$src,$dest,$path,$fname);
861: if ($file =~ m{/}) {
862: ($path,$fname) = ($file =~ m{^(.+)/([^/]+)$});
863: if (-d "$desttop/$subdir/$path") {
864: if (-e "$desttop/$subdir/$path/$fname") {
865: $dup = 1;
866: } else {
867: $src = "$srctop/$path/$fname";
868: $dest = "$desttop/$subdir/$path/$fname";
869: }
870: } elsif (-f "$desttop/$subdir/$path") {
871: $dir_is_file = 1;
872: } else {
873: $fail = 1;
874: }
875: } elsif (-e "$desttop/$subdir/$file") {
876: $dup = 1;
877: } else {
878: $src = "$srctop/$file";
879: $dest = "$desttop/$subdir/$file";
880: $fname = $file;
881: }
882: if ($fail) {
883: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
884: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$path.'</span>').
885: '</p>'."\n");
886: } elsif ($dup) {
887: $r->print('<p class="LC_warning">'.&mt('Target file: [_1] already exists -- not overwriting.',
888: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
889: '</p>'."\n");
890: } elsif ($dir_is_file) {
891: $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] name is already in a use for a file -- not overwriting.',
892: '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
893: '</p>'."\n");
894: } elsif (($src ne '') && ($dest ne '')) {
895: if (&File::Copy::copy($src,$dest)) {
896: $newfile{$file} = 1;
897: if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
898: if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
1.713 ! raeburn 899: if (open(my $fh,'<',$dest.'.meta')) {
! 900: my ($output,$now);
! 901: $now = time;
! 902: while (my $line=<$fh>) {
! 903: chomp($line);
! 904: if ($line eq "<authorspace>$coursenum:$coursedom</authorspace>") {
! 905: $output .= "<authorspace>$ca:$cd</authorspace>\n";
! 906: } elsif ($line eq '<copyright>custom</copyright>') {
! 907: $output .= "<copyright>default</copyright>\n";
! 908: } elsif ($line =~ m{^<creationdate>\d+</creationdate>$}) {
! 909: $output .= "<creationdate>$now</creationdate>\n";
! 910: } elsif ($line eq "<customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>") {
! 911: $output .= "<customdistributionfile></customdistributionfile>\n";
! 912: } elsif ($line eq "<domain>$coursedom</domain>") {
! 913: $output .= "<domain>$cd</domain>\n";
! 914: } elsif ($line =~ m{^<lastrevisiondate>\d+</lastrevisiondate>$}) {
! 915: $output .= "<lastrevisiondate>$now</lastrevisiondate>\n";
! 916: } elsif ($line =~ m{^<modifyinguser>$match_username:$match_domain</modifyinguser>$}) {
! 917: $output .= "<modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>\n";
! 918: } elsif ($line eq "<owner>$coursenum:$coursedom</owner>") {
! 919: $output .= "<owner>$ca:$cd</owner>\n";
! 920: } elsif ($line =~ m{^<dependencies>(.+)</dependencies>$}) {
! 921: my @deps = split(/\s*,\s*/,$1);
! 922: my @newdeps;
! 923: my $changed = 0;
! 924: foreach my $dep (@deps) {
! 925: if ($dep =~ m{^/res/$coursedom/$coursenum/(.+)$}) {
! 926: my $rest = $1;
! 927: push(@newdeps,"/res/$cd/$ca/$rest");
! 928: $checkdeps{$rest} = 1;
! 929: $changed ++;
! 930: } else {
! 931: push(@newdeps,$dep);
! 932: }
! 933: }
! 934: if ($changed) {
! 935: $output .= '<dependencies>'.join(',',@newdeps).'</dependencies>'."\n";
! 936: }
! 937: } else {
! 938: $output .= "$line\n";
! 939: }
! 940: }
! 941: close($fh);
! 942: if (open(my $fh,'>',$dest.'.meta')) {
! 943: print $fh $output;
! 944: close($fh);
! 945: }
! 946: }
1.712 raeburn 947: }
948: }
949: my ($ext) = ($file =~ /\.(\w+)$/);
950: my $embstyle=&Apache::loncommon::fileembstyle($ext);
951: if ($embstyle eq 'ssi') {
1.713 ! raeburn 952: my $outstring='';
! 953: my $changes = 0;
! 954: my @parser;
! 955: $parser[0]=HTML::LCParser->new($src);
! 956: $parser[-1]->xml_mode(1);
! 957: my $token;
! 958: while (@parser) {
! 959: while ($token=$parser[-1]->get_token) {
! 960: if ($token->[0] eq 'S') {
! 961: my $tag=$token->[1];
! 962: my $lctag=lc($tag);
! 963: my %parms=%{$token->[2]};
! 964: foreach my $type ('src','href','background','bgimg') {
! 965: foreach my $key (keys(%parms)) {
! 966: if ($key =~ /^$type$/i) {
! 967: next if (($lctag eq 'img') && ($type eq 'src') &&
! 968: ($parms{$key} =~ m{^data\:image/gif;base64,}));
! 969: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 970: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
! 971: $changes ++;
! 972: }
! 973: }
! 974: }
! 975: }
! 976: # probably a <randomlabel> image type <label>
! 977: # or a <image> tag inside <imageresponse> or <drawimage>
! 978: if (($lctag eq 'label' && defined($parms{'description'}))
! 979: || ($lctag eq 'image') || ($lctag eq 'import')) {
! 980: my $next_token=$parser[-1]->get_token();
! 981: if ($next_token->[0] eq 'T') {
! 982: $next_token->[1] =~ s/[\n\r\f]+//g;
! 983: if ($next_token->[1] =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 984: $next_token->[1] =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
! 985: $changes ++;
! 986: }
! 987: }
! 988: $parser[-1]->unget_token($next_token);
! 989: }
! 990: if ($lctag eq 'applet') {
! 991: my $havecodebase=0;
! 992: foreach my $key (keys(%parms)) {
! 993: if (lc($key) eq 'codebase') {
! 994: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 995: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
! 996: $changes ++;
! 997: }
! 998: $havecodebase = 1;
! 999: }
! 1000: }
! 1001: unless ($havecodebase) {
! 1002: foreach my $key (keys(%parms)) {
! 1003: if ($key =~ /(archive|code|object)/i) {
! 1004: if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1005: $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/si};
! 1006: $changes ++;
! 1007: }
! 1008: }
! 1009: }
! 1010: }
! 1011: }
! 1012: my $newparmstring='';
! 1013: my $endtag='';
! 1014: foreach my $parkey (keys(%parms)) {
! 1015: if ($parkey eq '/') {
! 1016: $endtag=' /';
! 1017: } else {
! 1018: my $quote=($parms{$parkey}=~/\"/?"'":'"');
! 1019: $newparmstring.=' '.$parkey.'='.$quote.$parms{$parkey}.$quote;
! 1020: }
! 1021: }
! 1022: if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
! 1023: $outstring.='<'.$tag.$newparmstring.$endtag.'>';
! 1024: if ($lctag eq 'm' || $lctag eq 'answer' || $lctag eq 'display' ||
! 1025: $lctag eq 'tex') {
! 1026: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
! 1027: } elsif ($lctag eq 'script') {
! 1028: if ($parms{'type'} eq 'loncapa/perl') {
! 1029: $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
! 1030: } else {
! 1031: my $needsupdate;
! 1032: my $script = &Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
! 1033: if ($script =~ m{\.addMediaSrc\((["'])((?!\1).+)\1\);}) {
! 1034: my $src = $2;
! 1035: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1036: $needsupdate = 1;
! 1037: }
! 1038: }
! 1039: if ($script =~ /\(document,\s*(['"])script\1,\s*\[([^\]]+)\]\);/s) {
! 1040: my $scriptslist = $2;
! 1041: my $needsupdate = 1;
! 1042: my @srcs = split(/\s*,\s*/,$scriptslist);
! 1043: foreach my $src (@srcs) {
! 1044: if ($src =~ /(["'])(?:(?!\1).)+\.js\1/) {
! 1045: my $quote = $1;
! 1046: my ($url) = ($src =~ m/\Q$quote\E([^$quote]+)\Q$quote\E/);
! 1047: if ($url =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1048: $needsupdate = 1;
! 1049: }
! 1050: }
! 1051: }
! 1052: }
! 1053: if ($script =~ m{loadScript\(\s*(['"])((?:(?!\1).)+\.js)\1,\s*function}is) {
! 1054: my $src = $2;
! 1055: if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
! 1056: $needsupdate = 1;
! 1057: }
! 1058: }
! 1059: if ($needsupdate) {
! 1060: $script =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/gsi};
! 1061: $changes ++;
! 1062: }
! 1063: $outstring .= $script;
! 1064: }
! 1065: }
! 1066: } elsif ($token->[0] eq 'E') {
! 1067: if ($token->[2]) {
! 1068: unless ($token->[1] eq 'allow') {
! 1069: $outstring.='</'.$token->[1].'>';
! 1070: }
! 1071: }
! 1072: } else {
! 1073: $outstring.=$token->[1];
! 1074: }
! 1075: }
! 1076: pop(@parser);
! 1077: }
! 1078: if ($changes) {
! 1079: if (open(my $fh,'>',$dest)) {
! 1080: print $fh $outstring;
! 1081: close($fh);
! 1082: }
! 1083: }
1.712 raeburn 1084: }
1085: }
1086: }
1087: }
1088: } else {
1089: $notopdir = 1;
1090: }
1091: }
1092: }
1093: if ($notopdir) {
1094: $r->print('<p><span class="LC_info">'.&mt('No files or sub-directories copied').'</span><br />'."\n".
1095: '<span class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
1096: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1097: '</span></p>'."\n");
1098: }
1099: if (keys(%newdir)) {
1100: $r->print('<p>'.&mt('Created the following directories in [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1101: '</p>'."\n".
1102: '<ul><li>'.join('</li><li>',sort(keys(%newdir))).'</li></ul></p>'."\n");
1103: }
1104: if (keys(%newfile)) {
1105: $r->print('<p>'.&mt('Copied the following files to [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
1106: '</p>'."\n".
1107: '<ul><li>'.join('</li><li>',sort(keys(%newfile))).'</li></ul></p>'."\n");
1108: }
1.713 ! raeburn 1109: if (keys(%checkdeps)) {
! 1110: my %missingdep;
! 1111: foreach my $depfile (sort(keys(%checkdeps))) {
! 1112: unless (-e "$desttop/$depfile") {
! 1113: $missingdep{$depfile} = 1;
! 1114: }
! 1115: }
! 1116: if (keys(%missingdep)) {
! 1117: $r->print('<p>'.&mt('You may also need to copy the following missing dependencies for files copied to [_1]:',
! 1118: '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
! 1119: '</p>'."\n".
! 1120: '<ul><li>'.join('</li><li>',sort(keys(%missingdep))).'</li></ul></p>'."\n");
! 1121: }
! 1122: }
1.712 raeburn 1123: } else {
1124: $r->print('<p>'.&mt('No currently existing files or directories in Course Authoring Space selected for copying').'</p>');
1125: $r->print(&endContentScreen());
1126: return '';
1127: }
1128: } else {
1129: my $formname = 'copycrsauthored';
1130: my $chkname = 'copytouser';
1131: my $context = 'crsauthored';
1132: my (%subdirs,%files,@dirs_by_depth,@files_by_depth,%parent,%children,%hierarchy,@checked_maps);
1133: &Apache::lonnet::recursedirs($home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files);
1134: foreach my $key (keys(%subdirs)) {
1135: next if (($key eq '/') || ($key eq ''));
1136: my @items = split(/\//,$key);
1137: my $dir = pop(@items);
1138: my $depth = scalar(@items);
1139: my $path;
1140: if (!$depth) {
1141: $path = '/';
1142: } else {
1143: $path = join('/',@items);
1144: }
1145: $dirs_by_depth[$depth]{$path}{$dir} = 1;
1146: }
1147: foreach my $path (keys(%files)) {
1148: next if ($path eq '');
1149: my $depth;
1150: if ($path eq '/') {
1151: $depth = 0;
1152: } else {
1153: $depth = scalar(split(/\//,$path));
1154: }
1155: if (ref($files{$path}) eq 'HASH') {
1156: foreach my $file (keys(%{$files{$path}})) {
1157: $files_by_depth[$depth]{$path}{$file} = 1;
1158: }
1159: }
1160: }
1161: my ($info,$display,$onsubmit,$togglebuttons,$disabled);
1162: if ($readonly) {
1163: $disabled = ' disabled="disabled"';
1164: }
1165: if ($disabled) {
1166: $togglebuttons = '<br />';
1167: } else {
1168: $togglebuttons = '<input type="button" value="'.&mt('check all').'" '.
1169: 'onclick="javascript:checkAll(document.'.$formname.'.'.$chkname.')" />'.
1170: ' <input type="button" value="'.&mt('uncheck all').'"'.
1171: ' onclick="javascript:uncheckAll(document.'.$formname.'.'.$chkname.')" />';
1172: }
1173: my $title=$origcrsdata{'description'};
1174: $title=~s/[\/\s]+/\_/gs;
1175: $title=&clean($title);
1176: my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash);
1177: my $display = '<form name="'.$formname.'" action="" method="post">'."\n".
1178: $preamble."\n".
1179: '<div class="LC_float_left">'."\n".
1180: '<fieldset>'."\n".
1181: '<legend>'.&mt('Content to copy').(' 'x4).$togglebuttons.'</legend>'."\n".
1182: '<span class="LC_fontsize_medium">'.
1183: &mt('Choose the files and/or folders to copy from Course Authoring to User Authoring').
1184: '</span><br /><br />'."\n";
1185: my $count = 0;
1186: my $startcount = 4 + $home;
1187: my $lastcontainer = $startcount;
1188: $display .= &Apache::loncommon::start_data_table()."\n".
1189: &Apache::loncommon::start_data_table_header_row().
1190: '<th>'.&mt('Copy?').'</th>'.
1191: '<th>'.&mt('Title').'</th>'.
1192: &Apache::loncommon::end_data_table_header_row()."\n";
1193: $count = &recurse_crsauthored(0,\@dirs_by_depth,\@files_by_depth,'/',$startcount,
1194: $count,\$display,\%parent,\%children,$readonly,
1195: $formname,$chkname,\$lastcontainer);
1196: $display .= &Apache::loncommon::end_data_table().'</fieldset>';
1197: unless ($readonly) {
1198: $display .= '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
1199: '<div>'.
1200: '<input type="submit" name="copyauthored" value="'.&mt("Copy Selected Content").'" />'.
1201: '</div>';
1202: }
1203: $display .= &Apache::loncourserespicker::respicker_javascript($startcount,$count,$context,$formname,\%children,
1204: \%hierarchy,\@checked_maps,$home,$chkname);
1205: $r->print($display);
1206: }
1207: $r->print(&endContentScreen());
1208: }
1209:
1210: sub recurse_crsauthored {
1211: my ($currdepth,$dirs_by_depth,$files_by_depth,$currpath,$startcount,$count,$displayref,
1212: $parent,$children,$readonly,$formname,$chkname,$lastcontainerref) = @_;
1213: return $count unless ((ref($dirs_by_depth) eq 'ARRAY') && (ref($files_by_depth) eq 'ARRAY'));
1214: my ($disabled,$hasdirs,$hasfiles,%unique,%dirs,%files);
1215: if ((ref($dirs_by_depth->[$currdepth]) eq 'HASH') &&
1216: (ref($dirs_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1217: $hasdirs = 1;
1218: %dirs = %{$dirs_by_depth->[$currdepth]{$currpath}};
1219: map { $unique{$_} = 1; } keys(%dirs);
1220: }
1221: if ((ref($files_by_depth->[$currdepth]) eq 'HASH') &&
1222: (ref($files_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
1223: $hasfiles = 1;
1224: %files = %{$files_by_depth->[$currdepth]{$currpath}};
1225: map { $unique{$_} = 1; } keys(%files);
1226: }
1227: if ($readonly) {
1228: $disabled = ' disabled="disabled"';
1229: }
1230: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
1231: my $whitespace =
1232: '<img src="'.$location.'/whitespace_21.gif" class="LC_docs_spacer" alt="" />';
1233: $parent->{$currdepth} = $$lastcontainerref;
1234: foreach my $item (sort { lc($a) cmp lc($b) } (keys(%unique))) {
1235: next if ($item eq '');
1236: my $currelem;
1237: if ($hasdirs && exists($dirs{$item})) {
1238: $count ++;
1239: my $deeper = $currdepth+1;
1240: my ($newpath,$showpath);
1241: if ($currpath eq '/') {
1242: $newpath = $item;
1243: $showpath = $currpath.$item.'/';
1244: } else {
1245: $newpath = $currpath.'/'.$item;
1246: $showpath = '/'.$currpath.'/'.$item.'/';
1247: }
1248: $currelem = $count+$startcount;
1249: $$lastcontainerref = $currelem;
1250: $children->{$parent->{$currdepth}} .= $currelem.':';
1251: my $icon = 'src="'.$location.'/navmap.folder.open.gif" alt="'.&mt('Folder').'"';
1252: $$displayref .= &Apache::loncommon::start_data_table_row().
1253: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath).'" '.
1254: 'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" '.
1255: $disabled.' /></td><td>';
1256: for (my $i=0; $i<$currdepth; $i++) {
1257: $$displayref .= "$whitespace\n";
1258: }
1259: $$displayref .= '<img '.$icon.' /> '.$item.'</td>'.
1260: &Apache::loncommon::end_data_table_row()."\n";
1261: $count = &recurse_crsauthored($deeper,$dirs_by_depth,$files_by_depth,$newpath,
1262: $startcount,$count,$displayref,$parent,$children,
1263: $readonly,$formname,$chkname,$lastcontainerref);
1264: }
1265: if ($hasfiles && exists($files{$item})) {
1266: $count ++;
1267: $currelem = $count+$startcount;
1268: $children->{$parent->{$currdepth}} .= $currelem.':';
1269: my $icon = 'src="'.&Apache::loncommon::icon($item).'"';
1270: my ($ext) = ($item =~ /\.([^.]+)$/);
1271: my $alttext;
1272: if (lc($ext) eq 'problem') {
1273: $alttext = ' alt="'.&mt('Problem Icon').'"';
1274: } elsif ($ext =~ /^x?html?$/i) {
1275: $alttext = ' alt="'.&mt('Web Page Icon').'"';
1276: } elsif ($ext =~ /^(jpg|gif|png|svg|jpeg)$/) {
1277: $alttext = ' alt="'.&mt('Image Icon').'"';
1278: } else {
1279: $alttext = ' alt="'.&mt('Resource Icon').'"';
1280: }
1281: my $showpath;
1282: if ($currpath eq '/') {
1283: $showpath = $currpath;
1284: } else {
1285: $showpath = "/$currpath/";
1286: }
1287: $$displayref .= &Apache::loncommon::start_data_table_row().
1288: '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath.$item).'" '.
1289: 'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" '.
1290: $disabled.' /></td><td>';
1291: for (my $i=0; $i<$currdepth; $i++) {
1292: $$displayref .= "$whitespace\n";
1293: }
1294: $$displayref .= '<img '.$icon.$alttext.' /> '.$item.'</td>'.
1295: &Apache::loncommon::end_data_table_row()."\n";
1296: }
1297: }
1298: $$lastcontainerref = $parent->{$currdepth};
1299: return $count;
1300: }
1301:
1.329 droeschl 1302: sub group_import {
1.598 raeburn 1303: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 1304: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
1305: %removeparam,$importuploaded,$fixuperrors);
1306: $allmaps = {};
1.329 droeschl 1307: while (@files) {
1308: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 1309: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 1310: && ($caller eq 'londocs')
1311: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 1312:
1.329 droeschl 1313: my $errtext = '';
1314: my $fatal = 0;
1315: my $newmapstr = '<map>'."\n".
1316: '<resource id="1" src="" type="start"></resource>'."\n".
1317: '<link from="1" to="2" index="1"></link>'."\n".
1318: '<resource id="2" src="" type="finish"></resource>'."\n".
1319: '</map>';
1320: $env{'form.output'}=$newmapstr;
1321: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1322: 'output',$1.$2);
1.534 raeburn 1323: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 1324: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
1325: $fatal = 2;
1326: }
1327: if ($fatal) {
1328: return ($errtext,$fatal);
1329: }
1330: }
1331: if ($url) {
1.626 raeburn 1332: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 1333: $url = $1;
1334: my $marker = $2;
1335: my $info = $3;
1.699 raeburn 1336: my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.642 raeburn 1337: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 1338: my @toolinfo = split(/:/,$info);
1339: if ($residx) {
1.604 raeburn 1340: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 1341: $toolid = $toolsettings{'id'};
1342: } else {
1.604 raeburn 1343: $toolid = shift(@toolinfo);
1.598 raeburn 1344: }
1.699 raeburn 1345: if ($toolid =~ /^c/) {
1346: $tooltype = 'crs';
1347: $toolprefix = 'c';
1348: } else {
1349: $tooltype = 'dom';
1350: }
1.598 raeburn 1351: $toolid =~ s/\D//g;
1.604 raeburn 1352: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 1353: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
1354: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 1355: foreach my $item (@extras) {
1356: $toolhash{$item} = &unescape($toolhash{$item});
1357: }
1.645 raeburn 1358: if ($folder =~ /^supplemental/) {
1.648 raeburn 1359: delete($toolhash{'gradable'});
1360: } else {
1361: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 1362: }
1.598 raeburn 1363: if (ref($ltitoolsref) eq 'HASH') {
1.699 raeburn 1364: if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
1365: if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
1366: my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
1367: my @deleted;
1368: $toolhash{'id'} = $toolprefix.$toolid;
1369: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
1370: ($toolhash{'target'} eq 'window')) {
1371: if ($toolhash{'target'} eq 'window') {
1372: foreach my $item ('width','height') {
1373: $toolhash{$item} =~ s/^\s+//;
1374: $toolhash{$item} =~ s/\s+$//;
1375: if ($toolhash{$item} =~ /\D/) {
1376: delete($toolhash{$item});
1377: if ($residx) {
1378: if ($toolsettings{$item}) {
1379: push(@deleted,$item);
1380: }
1.624 raeburn 1381: }
1382: }
1383: }
1.604 raeburn 1384: }
1.699 raeburn 1385: } elsif ($residx) {
1386: $toolhash{'target'} = $toolsettings{'target'};
1387: if ($toolhash{'target'} eq 'window') {
1388: foreach my $item ('width','height') {
1389: $toolhash{$item} = $toolsettings{$item};
1390: }
1391: }
1392: } elsif (ref($tools{'display'}) eq 'HASH') {
1393: $toolhash{'target'} = $tools{'display'}{'target'};
1394: if ($toolhash{'target'} eq 'window') {
1395: $toolhash{'width'} = $tools{'display'}{'width'};
1396: $toolhash{'height'} = $tools{'display'}{'height'};
1.624 raeburn 1397: }
1.604 raeburn 1398: }
1.699 raeburn 1399: if ($toolhash{'target'} eq 'iframe') {
1400: foreach my $item ('width','height','linktext','explanation') {
1401: delete($toolhash{$item});
1402: if ($residx) {
1403: if ($toolsettings{$item}) {
1404: push(@deleted,$item);
1405: }
1.624 raeburn 1406: }
1.604 raeburn 1407: }
1.699 raeburn 1408: } elsif ($toolhash{'target'} eq 'tab') {
1409: foreach my $item ('width','height') {
1410: delete($toolhash{$item});
1411: if ($residx) {
1412: if ($toolsettings{$item}) {
1413: push(@deleted,$item);
1414: }
1.628 raeburn 1415: }
1416: }
1417: }
1.699 raeburn 1418: if (ref($tools{'crsconf'}) eq 'HASH') {
1419: foreach my $item ('label','title','linktext','explanation') {
1420: my $crsitem;
1421: if (($item eq 'label') || ($item eq 'title')) {
1422: $crsitem = 'crs'.$item;
1423: } else {
1424: $crsitem = $item;
1425: }
1426: if ($tools{'crsconf'}{$item}) {
1427: $toolhash{$crsitem} =~ s/^\s+//;
1428: $toolhash{$crsitem} =~ s/\s+$//;
1429: if ($toolhash{$crsitem} eq '') {
1430: delete($toolhash{$crsitem});
1431: }
1432: } else {
1.624 raeburn 1433: delete($toolhash{$crsitem});
1.604 raeburn 1434: }
1.699 raeburn 1435: if (($residx) && (exists($toolsettings{$crsitem}))) {
1436: unless (exists($toolhash{$crsitem})) {
1437: push(@deleted,$crsitem);
1438: }
1439: }
1.604 raeburn 1440: }
1.699 raeburn 1441: }
1442: if ($toolhash{'passback'}) {
1443: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1444: $toolhash{'gradesecret'} = $gradesecret;
1445: $toolhash{'gradesecretdate'} = time;
1446: }
1447: if ($toolhash{'roster'}) {
1448: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
1449: $toolhash{'rostersecret'} = $rostersecret;
1450: $toolhash{'rostersecretdate'} = time;
1451: }
1452: my $changegradable;
1453: if (($residx) && ($folder =~ /^default/)) {
1454: if ($toolsettings{'gradable'}) {
1455: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1456: push(@deleted,'gradable');
1457: $changegradable = 1;
1.604 raeburn 1458: }
1.699 raeburn 1459: } elsif ($toolhash{'gradable'}) {
1460: $changegradable = 1;
1.604 raeburn 1461: }
1.699 raeburn 1462: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 1463: $changegradable = 1;
1.699 raeburn 1464: if ($toolsettings{'gradable'}) {
1465: $toolhash{'gradable'} = 1;
1466: }
1.645 raeburn 1467: }
1.648 raeburn 1468: }
1.699 raeburn 1469: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1470: if ($putres eq 'ok') {
1471: if (@deleted) {
1472: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648 raeburn 1473: }
1.699 raeburn 1474: if (($changegradable) && ($folder =~ /^default/)) {
1475: my $val;
1476: if ($toolhash{'gradable'}) {
1477: $val = 'yes';
1478: } else {
1479: $val = 'no';
1480: }
1481: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
1482: 'string_yesno');
1483: &remember_parms($residx,'gradable','set',$val);
1.645 raeburn 1484: }
1.699 raeburn 1485: } else {
1486: return (&mt('Failed to save update to external tool.'),1);
1.645 raeburn 1487: }
1.604 raeburn 1488: }
1.598 raeburn 1489: }
1490: }
1491: }
1.529 raeburn 1492: if (($caller eq 'londocs') &&
1493: ($folder =~ /^default/)) {
1.534 raeburn 1494: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 1495: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
1496: my $cid = $coursedom.'_'.$coursenum;
1497: $allmaps =
1498: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1499: $chome,$cid);
1500: $donechk = 1;
1501: }
1502: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 1503: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1504: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 1505: $importuploaded = 1;
1506: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
1507: next if ($allmaps->{$url});
1508: }
1509: }
1.344 bisitz 1510: if (!$residx
1.329 droeschl 1511: || defined($LONCAPA::map::zombies[$residx])) {
1512: $residx = &LONCAPA::map::getresidx($url,$residx);
1513: push(@LONCAPA::map::order, $residx);
1514: }
1515: my $ext = 'false';
1516: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 1517: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
1518: my $filepath = $1;
1.675 raeburn 1519: my $fname;
1520: if ($name eq '') {
1521: $name = &mt('Web Page');
1.534 raeburn 1522: $fname = 'web';
1523: } else {
1.675 raeburn 1524: $fname = $name;
1525: $fname=&Apache::lonnet::clean_filename($fname);
1526: if ($fname eq '') {
1527: $fname = 'web';
1528: } elsif (length($fname) > 15) {
1529: $fname = substr($fname,0,14);
1530: }
1.534 raeburn 1531: }
1.675 raeburn 1532: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 1533: my $initialtext = &mt('Replace with your own content.');
1534: my $newhtml = <<END;
1.545 raeburn 1535: <html>
1.534 raeburn 1536: <head>
1.675 raeburn 1537: <title>$title</title>
1.534 raeburn 1538: </head>
1539: <body bgcolor="#ffffff">
1540: $initialtext
1541: </body>
1542: </html>
1543: END
1544: $env{'form.output'}=$newhtml;
1.630 raeburn 1545: my $result =
1.534 raeburn 1546: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1547: 'output',
1548: "$filepath/$residx/$fname.html");
1549: if ($result =~ m{^/uploaded/}) {
1550: $url = $result;
1551: if ($filepath =~ /^supplemental/) {
1552: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1553: $env{'user.domain'}.'___&&&___'.$name;
1554: }
1555: } else {
1556: return (&mt('Failed to save new web page.'),1);
1557: }
1558: }
1.675 raeburn 1559: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 1560: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 1561: $LONCAPA::map::resources[$residx] =
1.329 droeschl 1562: join(':', ($name, $url, $ext, 'normal', 'res'));
1563: }
1564: }
1.529 raeburn 1565: if ($importuploaded) {
1566: my %import_errors;
1567: my %updated = (
1568: removefrommap => \%removefrommap,
1569: removeparam => \%removeparam,
1570: );
1.533 raeburn 1571: my ($result,$msgsarray,$lockerror) =
1572: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 1573: if (keys(%import_errors) > 0) {
1.530 raeburn 1574: $fixuperrors =
1.529 raeburn 1575: '<p span class="LC_warning">'."\n".
1576: &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".
1577: '<ul>'."\n";
1578: foreach my $key (sort(keys(%import_errors))) {
1579: $fixuperrors .= '<li>'.$key.'</li>'."\n";
1580: }
1581: $fixuperrors .= '</ul></p>'."\n";
1582: }
1.533 raeburn 1583: if (ref($msgsarray) eq 'ARRAY') {
1584: if (@{$msgsarray} > 0) {
1585: $fixuperrors .= '<p class="LC_info">'.
1586: join('<br />',@{$msgsarray}).
1587: '</p>';
1588: }
1589: }
1590: if ($lockerror) {
1591: $fixuperrors .= '<p class="LC_error">'.
1592: $lockerror.
1593: '</p>';
1594: }
1.529 raeburn 1595: }
1596: my ($errtext,$fatal) =
1597: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 1598: unless ($fatal) {
1599: if ($folder =~ /^supplemental/) {
1.561 raeburn 1600: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1601: $folder.'.'.$container);
1.557 raeburn 1602: }
1603: }
1.529 raeburn 1604: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 1605: }
1606:
1607: sub log_docs {
1.494 raeburn 1608: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 1609: }
1610:
1611: {
1612: my @oldresources=();
1613: my @oldorder=();
1614: my $parmidx;
1615: my %parmaction=();
1616: my %parmvalue=();
1617: my $changedflag;
1618:
1619: sub snapshotbefore {
1620: @oldresources=@LONCAPA::map::resources;
1621: @oldorder=@LONCAPA::map::order;
1622: $parmidx=undef;
1623: %parmaction=();
1624: %parmvalue=();
1625: $changedflag=0;
1626: }
1627:
1628: sub remember_parms {
1629: my ($idx,$parameter,$action,$value)=@_;
1630: $parmidx=$idx;
1631: $parmaction{$parameter}=$action;
1632: $parmvalue{$parameter}=$value;
1633: $changedflag=1;
1634: }
1635:
1636: sub log_differences {
1637: my ($plain)=@_;
1638: my %storehash=('folder' => $plain,
1639: 'currentfolder' => $env{'form.folder'});
1640: if ($parmidx) {
1641: $storehash{'parameter_res'}=$oldresources[$parmidx];
1642: foreach my $parm (keys(%parmaction)) {
1643: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1644: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1645: }
1646: }
1647: my $maxidx=$#oldresources;
1648: if ($#LONCAPA::map::resources>$#oldresources) {
1649: $maxidx=$#LONCAPA::map::resources;
1650: }
1651: for (my $idx=0; $idx<=$maxidx; $idx++) {
1652: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1653: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1654: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1655: $changedflag=1;
1656: }
1657: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1658: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1659: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1660: $changedflag=1;
1661: }
1662: }
1663: $storehash{'maxidx'}=$maxidx;
1664: if ($changedflag) { &log_docs(\%storehash); }
1665: }
1666: }
1667:
1668: sub docs_change_log {
1.611 raeburn 1669: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 1670: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 1671: my $navmap;
1.483 raeburn 1672: my $js = '<script type="text/javascript">'."\n".
1673: '// <![CDATA['."\n".
1674: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 1675: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 1676: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 1677: &history_tab_js()."\n".
1.484 raeburn 1678: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 1679: '// ]]>'."\n".
1680: '</script>'."\n";
1.484 raeburn 1681: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1682: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1683: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1684: my %orderhash;
1685: my $container='sequence';
1686: my $pathitem;
1.519 raeburn 1687: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1688: $container='page';
1689: }
1.519 raeburn 1690: my $folderpath=$env{'form.folderpath'};
1691: if ($folderpath eq '') {
1.617 raeburn 1692: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1693: }
1.617 raeburn 1694: undef($navmap);
1.519 raeburn 1695: $pathitem = '<input type="hidden" name="folderpath" value="'.
1696: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1697: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1698: my $jumpto = $readfile;
1699: $jumpto =~ s{^/}{};
1700: my $tid = 1;
1.489 raeburn 1701: if ($supplementalflag) {
1702: $tid = 2;
1703: }
1.630 raeburn 1704: my ($breadcrumbtrail) =
1.509 raeburn 1705: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1706: $r->print($breadcrumbtrail.
1707: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1708: $readfile));
1.329 droeschl 1709: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1710: $env{'course.'.$env{'request.course.id'}.'.domain'},
1711: $env{'course.'.$env{'request.course.id'}.'.num'});
1712:
1713: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1714:
1715: my %saveable_parameters = ('show' => 'scalar',);
1716: &Apache::loncommon::store_course_settings('docs_log',
1717: \%saveable_parameters);
1718: &Apache::loncommon::restore_course_settings('docs_log',
1719: \%saveable_parameters);
1720: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1721: # FIXME: internationalization seems wrong here
1.329 droeschl 1722: my %lt=('hiddenresource' => 'Resources hidden',
1723: 'encrypturl' => 'URL hidden',
1724: 'randompick' => 'Randomly pick',
1725: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1726: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1727: 'set' => 'set to',
1728: 'del' => 'deleted');
1.484 raeburn 1729: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1730: $pathitem."\n".
1731: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1732: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1733: $r->print('<div class="LC_left_float">'.
1734: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1735: &makedocslogform($filter,1).
1736: '</fieldset></div><br clear="all" />');
1.329 droeschl 1737: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1738: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1739: &mt('After').'</th>'.
1740: &Apache::loncommon::end_data_table_header_row());
1741: my $shown=0;
1742: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1743: if ($env{'form.displayfilter'} eq 'currentfolder') {
1744: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1745: }
1746: my @changes=keys(%{$docslog{$id}{'logentry'}});
1747: if ($env{'form.displayfilter'} eq 'containing') {
1748: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1749: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1750: foreach my $key (@changes) {
1751: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1752: }
1.344 bisitz 1753: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1754: }
1755: my $count = 0;
1756: my $time =
1757: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1758: my $plainname =
1759: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1760: $docslog{$id}{'exe_udom'});
1761: my $about_me_link =
1762: &Apache::loncommon::aboutmewrapper($plainname,
1763: $docslog{$id}{'exe_uname'},
1764: $docslog{$id}{'exe_udom'});
1765: my $send_msg_link='';
1766: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1767: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1768: $send_msg_link ='<br />'.
1769: &Apache::loncommon::messagewrapper(&mt('Send message'),
1770: $docslog{$id}{'exe_uname'},
1771: $docslog{$id}{'exe_udom'});
1772: }
1773: $r->print(&Apache::loncommon::start_data_table_row());
1774: $r->print('<td>'.$time.'</td>
1775: <td>'.$about_me_link.
1776: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1777: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1778: $send_msg_link.'</td><td>'.
1779: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1780: my $is_supp = 0;
1781: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1782: $is_supp = 1;
1783: }
1.329 droeschl 1784: # Before
1785: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1786: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1787: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1788: if ($oldname ne $newname) {
1.488 raeburn 1789: my $shown = &LONCAPA::map::qtescape($oldname);
1790: if ($is_supp) {
1791: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1792: }
1793: $r->print($shown);
1.329 droeschl 1794: }
1795: }
1796: $r->print('<ul>');
1797: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1798: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1799: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1800: if ($is_supp) {
1801: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1802: }
1803: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1804: }
1805: }
1806: $r->print('</ul>');
1807: # After
1808: $r->print('</td><td>');
1809:
1810: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1811: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1812: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1813: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1814: my $shown = &LONCAPA::map::qtescape($newname);
1815: if ($is_supp) {
1816: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1817: }
1818: $r->print($shown);
1.329 droeschl 1819: }
1.364 bisitz 1820: }
1.329 droeschl 1821: $r->print('<ul>');
1822: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1823: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1824: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1825: if ($is_supp) {
1826: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1827: }
1828: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1829: }
1830: }
1831: $r->print('</ul>');
1832: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 1833: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1834: if ($title eq '') {
1835: ($title) = ($url =~ m{/([^/]+)$});
1.695 raeburn 1836: } elsif ($is_supp) {
1837: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 1838: }
1839: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 1840: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1841: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1842: # FIXME: internationalization seems wrong here
1.329 droeschl 1843: $r->print('<li>'.
1844: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1845: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1846: .'</li>');
1847: }
1848: }
1849: $r->print('</ul>');
1850: }
1851: # End
1852: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1853: $shown++;
1854: if (!($env{'form.show'} eq &mt('all')
1855: || $shown<=$env{'form.show'})) { last; }
1856: }
1.484 raeburn 1857: $r->print(&Apache::loncommon::end_data_table()."\n".
1858: &makesimpleeditform($pathitem)."\n".
1859: '</div></div>');
1860: $r->print(&endContentScreen());
1.329 droeschl 1861: }
1862:
1863: sub update_paste_buffer {
1.492 raeburn 1864: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1865: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1866: if ($env{'form.multiremove'}) {
1867: $env{'form.multiremove'} =~ s/,$//;
1868: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1869: }
1870: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1871: if ($env{'form.multicut'}) {
1872: $env{'form.multicut'} =~ s/,$//;
1873: foreach my $item (split(/,/,$env{'form.multicut'})) {
1874: unless ($removals{$item}) {
1875: $cuts{$item} = 1;
1876: push(@possibles,$item.':cut');
1877: }
1878: }
1879: }
1880: if ($env{'form.multicopy'}) {
1881: $env{'form.multicopy'} =~ s/,$//;
1882: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1883: unless ($removals{$item} || $cuts{$item}) {
1884: push(@possibles,$item.':copy');
1885: }
1886: }
1887: }
1888: } elsif ($env{'form.markcopy'}) {
1889: @possibles = split(/,/,$env{'form.markcopy'});
1890: }
1.329 droeschl 1891:
1.538 raeburn 1892: return if (@possibles == 0);
1.329 droeschl 1893: return if (!defined($env{'form.copyfolder'}));
1894:
1895: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1896: $env{'form.copyfolder'});
1.538 raeburn 1897: return if ($fatal);
1898:
1899: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1900:
1.538 raeburn 1901: # Retrieve current paste buffer suffixes.
1902: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1903: my (%pasteurls,@newpaste);
1904:
1905: # Construct identifiers for current contents of user's paste buffer
1906: if (@currpaste) {
1907: foreach my $suffix (@currpaste) {
1.667 raeburn 1908: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1909: my $url = $env{'docs.markedcopy_url_'.$suffix};
1910: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1911: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1912: ($url ne '')) {
1913: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1914: $pasteurls{$cid.'_'.$mapidx} = 1;
1915: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1916: $pasteurls{$url} = 1;
1917: } else {
1.669 raeburn 1918: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 1919: }
1920: }
1.538 raeburn 1921: }
1922: }
1923:
1924: # Mark items for copying (skip any items already in user's paste buffer)
1925: my %addtoenv;
1.597 raeburn 1926:
1927: my @pathitems = split(/\&/,$env{'form.folderpath'});
1928: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 1929: my $ispage = $folderconf[5];
1.597 raeburn 1930:
1.538 raeburn 1931: foreach my $item (@possibles) {
1932: my ($orderidx,$cmd) = split(/:/,$item);
1933: next if ($orderidx =~ /\D/);
1934: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1935: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1936: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1937: my %denied = &action_restrictions($coursenum,$coursedom,
1938: &LONCAPA::map::qtescape($url),
1939: $env{'form.folderpath'},\%curr_groups);
1940: next if ($denied{'copy'});
1941: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 1942: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1943: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1944: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1945: next if (exists($pasteurls{$url}));
1946: } else {
1947: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1948: }
1.538 raeburn 1949: my ($suffix,$errortxt,$locknotfreed) =
1950: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1951: if ($suffix ne '') {
1952: push(@newpaste,$suffix);
1953: } else {
1954: if ($locknotfreed) {
1955: return $locknotfreed;
1956: }
1.538 raeburn 1957: }
1958: if (&is_supplemental_title($title)) {
1959: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1960: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1961: }
1.329 droeschl 1962:
1.538 raeburn 1963: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1964: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1965: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1966: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1967: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1968: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1969: my $prefix = $1;
1970: my $subdir =$2;
1971: if ($subdir eq '') {
1972: $subdir = $prefix;
1.492 raeburn 1973: }
1.538 raeburn 1974: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1975: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1976: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1977: if (ref($hierarchy{$url}) eq 'HASH') {
1978: my ($nested,$nestednames);
1979: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1980: $nested =~ s/\&$//;
1981: $nestednames =~ s/\Q___&&&___\E$//;
1982: if ($nested ne '') {
1983: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1984: }
1985: if ($nestednames ne '') {
1986: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1987: }
1.492 raeburn 1988: }
1989: }
1.591 raeburn 1990: if ($locknotfreed) {
1991: $output = $locknotfreed;
1992: last;
1993: }
1.492 raeburn 1994: }
1.538 raeburn 1995: if (@newpaste) {
1996: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1997: }
1.492 raeburn 1998: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1999: delete($env{'form.markcopy'});
1.591 raeburn 2000: return $output;
1.329 droeschl 2001: }
2002:
1.492 raeburn 2003: sub recurse_uploaded_maps {
2004: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
2005: if (ref($hierarchy->{$url}) eq 'HASH') {
2006: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
2007: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
2008: my (@uploaded,@names,%shorter);
2009: for (my $i=0; $i<@maps; $i++) {
2010: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
2011: if ($inner ne '') {
2012: push(@uploaded,$inner);
2013: push(@names,&escape($titles[$i]));
2014: $shorter{$maps[$i]} = $inner;
2015: }
2016: }
2017: $$nestref .= "$dir:".join(',',@uploaded).'&';
2018: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
2019: foreach my $map (@maps) {
2020: if ($shorter{$map} ne '') {
2021: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
2022: }
2023: }
2024: }
2025: return;
2026: }
2027:
1.329 droeschl 2028: sub print_paste_buffer {
1.492 raeburn 2029: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 2030: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 2031:
1.538 raeburn 2032: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
2033: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 2034: }
2035:
1.538 raeburn 2036: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1.704 raeburn 2037: my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
1.575 raeburn 2038: my $clipboardcount = 0;
1.488 raeburn 2039:
1.538 raeburn 2040: # Construct identifiers for current contents of user's paste buffer
2041: foreach my $suffix (@currpaste) {
2042: next if ($suffix =~ /\D/);
2043: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
2044: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 2045: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 2046: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
2047: ($url ne '')) {
1.575 raeburn 2048: $clipboardcount ++;
1.538 raeburn 2049: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.704 raeburn 2050: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
2051: $toolcnum,$marker);
1.538 raeburn 2052: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
2053: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
2054: $is_external = 1;
1.704 raeburn 2055: } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2056: ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1.598 raeburn 2057: $is_exttool = 1;
1.538 raeburn 2058: }
2059: if ($folder =~ /^supplemental/) {
2060: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
2061: unless ($canpaste) {
2062: $nopaste = &mt('Paste into Supplemental Content unavailable.');
2063: }
2064: } else {
2065: $canpaste = 1;
2066: }
2067: if ($canpaste) {
2068: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2069: my $srcdom = $1;
2070: my $srcnum = $2;
2071: my $rem = $3;
2072: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
2073: $othercourse = 1;
2074: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 2075: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 2076: } else {
2077: $canpaste = 0;
2078: $nopaste = &mt('Paste from another course unavailable.');
2079: }
2080: }
2081: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
2082: my $prefix = $1;
2083: $parent = $2;
2084: if ($folder !~ /^\Q$prefix\E/) {
2085: $areachange = 1;
2086: }
2087: $is_uploaded_map = 1;
1.492 raeburn 2088: }
1.597 raeburn 2089: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 2090: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 2091: if ($cid ne $env{'request.course.id'}) {
2092: my ($srcdom,$srcnum) = split(/_/,$cid);
2093: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.704 raeburn 2094: if ($is_exttool) {
2095: if ($toolcdom ne $coursedom) {
2096: $canpaste = 0;
2097: $nopaste = &mt('Paste from another domain unavailable.');
2098: } elsif ($toolcnum ne $coursenum) {
2099: my %toolsettings =
2100: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2101: my %tooltypes = &Apache::loncommon::usable_exttools();
2102: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2103: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2104: $canpaste = 0;
2105: $nopaste = &mt('Paste from another course unavailable.');
2106: } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
2107: unless ($checkedsameinst) {
2108: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2109: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2110: if ($intdom ne '') {
2111: my $internet_names =
2112: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2113: if (ref($internet_names) eq 'ARRAY') {
2114: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2115: $same_institution = 1;
2116: }
2117: }
2118: }
2119: $checkedsameinst = 1;
2120: }
2121: if ($same_institution) {
2122: $othercrs = '<br />'.&mt('(from another course)');
2123: } else {
2124: $nopaste = &mt('Paste from another course unavailable.');
2125: }
2126: } else {
2127: $othercrs = '<br />'.&mt('(from another course)');
2128: }
2129: }
1.627 raeburn 2130: }
1.596 raeburn 2131: } else {
2132: $canpaste = 0;
2133: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 2134: }
1.596 raeburn 2135: }
1.703 raeburn 2136: } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
2137: my ($audom,$auname) = ($1,$2);
2138: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2139: if (&Apache::lonnet::is_course($audom,$auname)) {
2140: $canpaste = 0;
2141: $nopaste = &mt('Paste from another course unavailable.');
2142: }
2143: }
1.492 raeburn 2144: }
1.596 raeburn 2145: if ($canpaste) {
2146: push(@pasteable,$suffix);
1.629 raeburn 2147: }
1.538 raeburn 2148: }
2149: my $buffer;
1.627 raeburn 2150: if ($is_external) {
1.538 raeburn 2151: $buffer = &mt('External Resource').': '.
2152: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
2153: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 2154: } elsif ($is_exttool) {
2155: $buffer = &mt('External Tool').': '.
2156: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 2157: } else {
2158: my $icon = &Apache::loncommon::icon($extension);
2159: if ($extension eq 'sequence' &&
2160: $url =~ m{/default_\d+\.sequence$}x) {
2161: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
2162: $icon .= '/navmap.folder.closed.gif';
2163: }
1.589 raeburn 2164: my $title = $env{'docs.markedcopy_title_'.$suffix};
2165: if ($title eq '') {
2166: ($title) = ($url =~ m{/([^/]+)$});
2167: }
1.538 raeburn 2168: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
2169: ': '.
2170: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 2171: &LONCAPA::map::qtescape($title));
1.538 raeburn 2172: }
2173: $pasteitems .= '<div class="LC_left_float">';
2174: my ($options,$onclick);
2175: if (($canpaste) && (!$areachange) && (!$othercourse) &&
2176: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
2177: if (($is_uploaded_map) ||
2178: ($url =~ /(bulletinboard|smppg)$/) ||
2179: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
2180: $options = &paste_options($suffix,$is_uploaded_map,$parent);
2181: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
2182: }
2183: }
2184: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
2185: if ($nopaste) {
1.681 raeburn 2186: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 2187: } else {
2188: if ($othercrs) {
2189: $pasteitems .= $othercrs;
2190: }
2191: if ($options) {
2192: $pasteitems .= $options;
1.492 raeburn 2193: }
2194: }
1.538 raeburn 2195: $pasteitems .= '</div>';
2196: }
2197: }
2198: if ($pasteitems eq '') {
2199: &Apache::lonnet::delenv('docs.markedcopies');
2200: }
2201: my ($pasteform,$form_start,$buttons,$form_end);
2202: if ($pasteitems) {
2203: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 2204: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 2205: if (@pasteable) {
1.575 raeburn 2206: my $value = &mt('Paste to current folder');
2207: if ($container eq 'page') {
2208: $value = &mt('Paste to current page');
2209: }
2210: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
2211: }
2212: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
2213: if ($clipboardcount > 1) {
2214: $buttons .=
2215: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
2216: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
2217: (' 'x2).
2218: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
2219: (' 'x2);
1.492 raeburn 2220: }
1.575 raeburn 2221: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
2222: '</form>';
1.538 raeburn 2223: } else {
2224: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 2225: }
1.538 raeburn 2226: $r->print($form_start
2227: .'<fieldset>'
2228: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
2229: .$pasteitems
2230: .'</fieldset>'
2231: .$form_end);
2232: }
2233:
2234: sub paste_options {
2235: my ($suffix,$is_uploaded_map,$parent) = @_;
2236: my ($copytext,$movetext);
2237: if ($is_uploaded_map) {
2238: $copytext = &mt('Copy to new folder');
2239: $movetext = &mt('Move old');
2240: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
2241: $copytext = &mt('Copy to new board');
2242: $movetext = &mt('Move (not posts)');
2243: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
2244: $copytext = &mt('Copy to new page');
2245: $movetext = &mt('Move');
1.533 raeburn 2246: } else {
1.538 raeburn 2247: $copytext = &mt('Copy to new file');
2248: $movetext = &mt('Move');
2249: }
2250: my $output = '<br />'.
2251: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
2252: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
2253: '<label>'.
2254: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
2255: $copytext.'</label></span>'.(' 'x2).' '.
2256: '<span class="LC_nobreak"><label>'.
2257: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
2258: $movetext.'</label></span>';
2259: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
2260: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
2261: '</legend><table border="0">';
2262: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2263: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
2264: my $lastdir = $parent;
2265: my %depths = (
2266: $lastdir => 0,
2267: );
2268: my (%display,%deps);
2269: for (my $i=0; $i<@pastemaps; $i++) {
2270: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
2271: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
2272: my @subfolders = split(/,/,$subfolderstr);
2273: $deps{$lastdir} = \@subfolders;
2274: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
2275: my $depth = $depths{$lastdir} + 1;
2276: my $offset = int($depth * 4);
2277: my $indent = (' ' x $offset);
2278: for (my $j=0; $j<@subfolders; $j++) {
2279: $depths{$subfolders[$j]} = $depth;
2280: $display{$subfolders[$j]} =
2281: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
2282: '<td><label>'.
2283: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
2284: '<label>'.
2285: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
2286: &mt('Move old').'</label>'.
2287: '</td></tr>';
2288: }
1.492 raeburn 2289: }
1.538 raeburn 2290: &recurse_print(\$output,$parent,\%deps,\%display);
2291: $output .= '</table></fieldset>';
1.329 droeschl 2292: }
1.538 raeburn 2293: $output .= '</div>';
2294: return $output;
1.488 raeburn 2295: }
2296:
1.492 raeburn 2297: sub recurse_print {
1.538 raeburn 2298: my ($outputref,$dir,$deps,$display) = @_;
2299: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 2300: if (ref($deps->{$dir}) eq 'ARRAY') {
2301: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 2302: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 2303: }
2304: }
2305: }
2306:
1.488 raeburn 2307: sub supp_pasteable {
2308: my ($url) = @_;
2309: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
2310: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
2311: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
2312: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 2313: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 2314: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 2315: return 1;
2316: }
2317: return;
1.329 droeschl 2318: }
2319:
1.492 raeburn 2320: sub paste_popup_js {
1.594 damieng 2321: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 2322: show => 'Show Options',
2323: hide => 'Hide Options',
1.594 damieng 2324: );
2325: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 2326: none => 'No items selected from clipboard.',
1.492 raeburn 2327: );
1.594 damieng 2328: &html_escape(\%html_js_lt);
2329: &js_escape(\%html_js_lt);
2330: &js_escape(\%js_lt);
1.492 raeburn 2331: return <<"END";
2332:
1.538 raeburn 2333: function showPasteOptions(suffix) {
2334: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 2335: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 2336: return;
2337: }
2338:
1.538 raeburn 2339: function hidePasteOptions(suffix) {
2340: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 2341: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2342: return;
2343: }
2344:
2345: function showOptions(caller,suffix) {
2346: if (document.getElementById('pasteoptionstext_'+suffix)) {
2347: if (caller.checked) {
1.594 damieng 2348: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 2349: } else {
2350: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
2351: }
2352: if (document.getElementById('pasteoptions_'+suffix)) {
2353: document.getElementById('pasteoptions_'+suffix).style.display='none';
2354: }
2355: }
1.492 raeburn 2356: return;
2357: }
2358:
1.541 raeburn 2359: function validateClipboard() {
2360: var numchk = 0;
2361: if (document.pasteform.pasting.length > 1) {
2362: for (var i=0; i<document.pasteform.pasting.length; i++) {
2363: if (document.pasteform.pasting[i].checked) {
2364: numchk ++;
2365: }
2366: }
2367: } else {
2368: if (document.pasteform.pasting.type == 'checkbox') {
2369: if (document.pasteform.pasting.checked) {
2370: numchk ++;
2371: }
2372: }
2373: }
2374: if (numchk > 0) {
2375: return true;
2376: } else {
1.594 damieng 2377: alert("$js_lt{'none'}");
1.541 raeburn 2378: return false;
2379: }
2380: }
2381:
1.575 raeburn 2382: function checkClipboard() {
2383: if (document.pasteform.pasting.length > 1) {
2384: for (var i=0; i<document.pasteform.pasting.length; i++) {
2385: document.pasteform.pasting[i].checked = true;
2386: }
2387: }
2388: return;
2389: }
2390:
2391: function uncheckClipboard() {
2392: if (document.pasteform.pasting.length >1) {
2393: for (var i=0; i<document.pasteform.pasting.length; i++) {
2394: document.pasteform.pasting[i].checked = false;
2395: }
2396: }
2397: return;
2398: }
2399:
1.492 raeburn 2400: END
2401:
2402: }
2403:
1.329 droeschl 2404: sub do_paste_from_buffer {
1.492 raeburn 2405: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 2406:
1.538 raeburn 2407: # Array of items in paste buffer
2408: my (@currpaste,%pastebuffer,%allerrors);
2409: @currpaste = split(/,/,$env{'docs.markedcopies'});
2410:
1.492 raeburn 2411: # Early out if paste buffer is empty
1.538 raeburn 2412: if (@currpaste == 0) {
1.492 raeburn 2413: return ();
1.538 raeburn 2414: }
2415: map { $pastebuffer{$_} = 1; } @currpaste;
2416:
2417: # Array of items selected items to paste
2418: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
2419:
2420: # Early out if nothing selected to paste
2421: if (@reqpaste == 0) {
2422: return();
2423: }
2424: my @topaste;
2425: foreach my $suffix (@reqpaste) {
2426: next if ($suffix =~ /\D/);
2427: next unless (exists($pastebuffer{$suffix}));
2428: push(@topaste,$suffix);
2429: }
2430:
2431: # Early out if nothing available to paste
2432: if (@topaste == 0) {
2433: return();
1.329 droeschl 2434: }
2435:
1.704 raeburn 2436: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
2437: %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
2438: %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
2439: %currltititles,$currltimax,$gotcrsltitools);
2440: $currltimax = 0;
2441: $gotcrsltitools = 0;
1.538 raeburn 2442: foreach my $suffix (@topaste) {
2443: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 2444: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 2445: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 2446: # Supplemental content may only include certain types of content
2447: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 2448: if ($folder =~ /^supplemental/) {
2449: unless (&supp_pasteable($url)) {
2450: $notinsupp{$suffix} = 1;
2451: next;
2452: }
1.492 raeburn 2453: }
1.538 raeburn 2454: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
2455: my $srcd = $1;
2456: my $srcn = $2;
1.492 raeburn 2457: # When paste buffer was populated using an active role in a different course
1.538 raeburn 2458: # check for mdc privilege in the course from which the resource was pasted
2459: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2460: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2461: $notincrs{$suffix} = 1;
2462: next;
2463: }
1.491 raeburn 2464: }
1.538 raeburn 2465: $srcdom{$suffix} = $srcd;
2466: $srcnum{$suffix} = $srcn;
1.597 raeburn 2467: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 2468: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
2469: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 2470: my ($srcd,$srcn) = split(/_/,$cid);
2471: # When paste buffer was populated using an active role in a different course
2472: # check for mdc privilege in the course from which the resource was pasted
2473: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
2474: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
2475: $notincrs{$suffix} = 1;
2476: next;
2477: }
2478: }
1.632 raeburn 2479: # When buffer was populated using an active role in a different course
1.704 raeburn 2480: # disallow pasting of External Tool if course is in a different domain,
2481: # or if External Tool use is not permitted in this course.
2482: if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
2483: my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
2484: if ($toolcdom ne $coursedom) {
2485: $notindom{$suffix} = 1;
2486: next;
2487: } elsif ($toolcnum ne $coursenum) {
2488: my %toolsettings =
2489: &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
2490: my %tooltypes = &Apache::loncommon::usable_exttools();
2491: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
2492: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
2493: $othcrstool{$suffix} = 1;
2494: next;
2495: }
2496: if ($toolsettings{'id'} =~ /^c\d+$/) {
2497: unless ($gotcrsltitools) {
2498: %currcrsltitools =
2499: &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
2500: foreach my $item (sort(keys(%currcrsltitools))) {
2501: if (ref($currcrsltitools{$item}) eq 'HASH') {
2502: $currltimax ++;
2503: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
2504: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
2505: } else {
2506: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
2507: }
2508: }
2509: }
2510: $gotcrsltitools = 1;
2511: }
2512: }
2513: }
1.627 raeburn 2514: }
1.596 raeburn 2515: $srcdom{$suffix} = $srcd;
2516: $srcnum{$suffix} = $srcn;
1.703 raeburn 2517: } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
2518: my ($audom,$auname) = ($1,$2);
2519: # When buffer was populated using an active role in a different course
2520: # disallow pasting of published resources from Course Authoring Space
2521: unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
2522: if (&Apache::lonnet::is_course($audom,$auname)) {
2523: $othcrsres{$suffix} = 1;
2524: next;
2525: }
2526: }
1.491 raeburn 2527: }
1.597 raeburn 2528: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 2529: push(@dopaste,$suffix);
2530: if ($url=~/\.(page|sequence)$/) {
2531: $is_map{$suffix} = 1;
2532: }
2533: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
2534: my $oldprefix = $1;
1.492 raeburn 2535: # When pasting content from Main Content to Supplemental Content and vice versa
2536: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 2537: # a folder/page or a document).
1.538 raeburn 2538: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
2539: $prefixchg{$suffix} = 'docstosupp';
2540: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
2541: $prefixchg{$suffix} = 'supptodocs';
2542: }
1.491 raeburn 2543:
1.492 raeburn 2544: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 2545: if ($env{'docs.markedcopy_nested_'.$suffix}) {
2546: my @nested;
2547: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
2548: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
2549: my @deps = map { /\d+:([\d,]+$)/ } @items;
2550: foreach my $dep (@deps) {
2551: if ($dep =~ /,/) {
2552: push(@nested,split(/,/,$dep));
2553: } else {
2554: push(@nested,$dep);
2555: }
1.492 raeburn 2556: }
1.538 raeburn 2557: foreach my $item (@nested) {
2558: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
2559: push(@{$marktomove{$suffix}},$type.'_'.$item);
2560: }
1.492 raeburn 2561: }
2562: }
1.488 raeburn 2563: }
2564: }
2565:
1.538 raeburn 2566: # Early out if nothing available to paste
2567: if (@dopaste == 0) {
2568: return ();
2569: }
2570:
2571: # Populate message hash and hashes used for main content <=> supplemental content
2572: # changes
2573:
2574: %msgs = &Apache::lonlocal::texthash (
2575: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
2576: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 2577: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.704 raeburn 2578: othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.703 raeburn 2579: othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538 raeburn 2580: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
2581: );
2582:
2583: %before = (
2584: docstosupp => {
2585: map => 'default',
2586: doc => 'docs',
2587: },
2588: supptodocs => {
2589: map => 'supplemental',
2590: doc => 'supplemental',
2591: },
2592: );
2593:
2594: %after = (
2595: docstosupp => {
2596: map => 'supplemental',
2597: doc => 'supplemental'
2598: },
2599: supptodocs => {
2600: map => 'default',
2601: doc => 'docs',
2602: },
2603: );
2604:
2605: # Retrieve information about all course maps in main content area
2606:
2607: my $allmaps = {};
1.704 raeburn 2608: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
2609: @updatetoolsenc,$updatetoolscache,$checkedsameinst,
2610: $same_institution);
1.538 raeburn 2611:
2612: # Loop over the items to paste
2613: foreach my $suffix (@dopaste) {
1.329 droeschl 2614: # Maps need to be copied first
1.538 raeburn 2615: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
2616: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 2617: %newurls,%tomove,%resdatacopy);
1.538 raeburn 2618: if (ref($marktomove{$suffix}) eq 'ARRAY') {
2619: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
2620: }
2621: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
2622: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 2623: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 2624: my $oldurl = $url;
2625: if ($is_map{$suffix}) {
1.491 raeburn 2626: # If pasting a map, check if map contains other maps
1.538 raeburn 2627: my (%hierarchy,%titles);
1.660 raeburn 2628: if (($folder =~ /^default/) && (!$donechk)) {
2629: $allmaps =
2630: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
2631: $env{"course.$env{'request.course.id'}.home"},
2632: $env{'request.course.id'});
2633: $donechk = 1;
2634: }
1.627 raeburn 2635: &contained_map_check($url,$folder,$coursenum,$coursedom,
2636: \%removefrommap,\%removeparam,\%addedmaps,
2637: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 2638: if ($url=~ m{^/uploaded/}) {
2639: my $newurl;
2640: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2641: ($newurl,my $error) =
2642: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
2643: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2644: \$title,$allmaps,\%newurls);
2645: if ($error) {
2646: $allerrors{$suffix} = $error;
2647: next;
2648: }
2649: if ($newurl ne '') {
2650: if ($newurl ne $url) {
2651: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
2652: $newsubdir{$url} = $1;
2653: }
2654: $mapchanges{$url} = 1;
1.492 raeburn 2655: }
1.538 raeburn 2656: }
2657: }
2658: if (($srcdom{$suffix} ne $coursedom) ||
2659: ($srcnum{$suffix} ne $coursenum) ||
2660: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
2661: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
2662: $coursedom,$coursenum,$srcdom{$suffix},
2663: $srcnum{$suffix},$allmaps,\%rewrites,
2664: \%retitles,\%copies,\%dbcopies,
2665: \%zombies,\%params,\%mapmoves,
2666: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 2667: \%newurls,\%resdatacopy)) {
1.538 raeburn 2668: $mapmoves{$url} = 1;
2669: }
2670: $url = $newurl;
2671: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
2672: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
2673: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
2674: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
2675: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 2676: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 2677: }
2678: } elsif ($url=~m {^/res/}) {
1.597 raeburn 2679: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 2680: push(@toclear,$suffix);
2681: # if pasting published map (main content area only) check map not already in course
2682: if ($folder =~ /^default/) {
2683: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
2684: $duplicate{$suffix} = 1;
2685: next;
1.492 raeburn 2686: }
1.491 raeburn 2687: }
2688: }
1.538 raeburn 2689: }
1.627 raeburn 2690: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 2691: my $prefix = $1;
1.648 raeburn 2692: my $fromothercrs;
1.538 raeburn 2693: #need to copy the db contents to a new one, unless this is a move.
2694: my %info = (
2695: src => $url,
2696: cdom => $coursedom,
2697: cnum => $coursenum,
1.596 raeburn 2698: );
1.649 raeburn 2699: if ($prefix eq 'ext.tool') {
1.655 raeburn 2700: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 2701: $info{'delgradable'} = 1;
2702: }
2703: }
1.596 raeburn 2704: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
2705: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
2706: $fromothercrs = 1;
2707: $info{'cdom'} = $srcdom{$suffix};
2708: $info{'cnum'} = $srcnum{$suffix};
1.704 raeburn 2709: unless ($checkedsameinst) {
2710: my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
2711: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2712: if ($intdom ne '') {
2713: my $internet_names =
2714: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
2715: if (ref($internet_names) eq 'ARRAY') {
2716: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
2717: $same_institution = 1;
2718: }
2719: }
2720: }
2721: $checkedsameinst = 1;
2722: }
1.596 raeburn 2723: }
2724: }
2725: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 2726: my (%lockerr,$msg);
1.538 raeburn 2727: my ($newurl,$result,$errtext) =
1.704 raeburn 2728: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
2729: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.538 raeburn 2730: if ($result eq 'ok') {
2731: $url = $newurl;
2732: $title=&mt('Copy of').' '.$title;
2733: } else {
2734: if ($prefix eq 'smppg') {
2735: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2736: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 2737: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 2738: } elsif ($prefix eq 'ext.tool') {
2739: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 2740: }
2741: $results{$suffix} = $result;
2742: $msgerrs{$suffix} = $msg;
2743: $lockerrs{$suffix} = $lockerr{$prefix};
2744: next;
2745: }
2746: if ($lockerr{$prefix}) {
2747: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 2748: }
1.489 raeburn 2749: }
2750: }
1.538 raeburn 2751: $title = &LONCAPA::map::qtunescape($title);
2752: my $ext='false';
2753: if ($url=~m{^http(|s)://}) { $ext='true'; }
2754: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2755: if ($folder !~ /^supplemental/) {
2756: (undef,undef,$title) =
2757: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2758: }
2759: } else {
2760: if ($folder=~/^supplemental/) {
2761: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2762: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2763: }
1.533 raeburn 2764: }
1.491 raeburn 2765:
2766: # For uploaded files (excluding pages/sequences) path in copied file is changed
2767: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2768: # courses.
2769:
1.538 raeburn 2770: unless ($is_map{$suffix}) {
2771: my $newidx;
1.492 raeburn 2772: # Now insert the URL at the bottom
1.538 raeburn 2773: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2774: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2775: my $relpath = $1;
2776: if ($relpath ne '') {
2777: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2778: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2779: my $newprefix = $newloc;
2780: if ($newloc eq 'default') {
2781: $newprefix = 'docs';
2782: }
2783: if ($newdocsdir eq '') {
2784: $newdocsdir = 'default';
2785: }
1.630 raeburn 2786: if (($prefixchg{$suffix}) ||
2787: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2788: ($srcnum{$suffix} ne $coursenum) ||
2789: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2790: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2791: $url =
2792: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2793: &Apache::lonnet::getfile($oldurl));
2794: if ($url eq '/adm/notfound.html') {
2795: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2796: next;
2797: } else {
2798: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2799: $newsubpath =~ s{/+$}{/};
2800: $docmoves{$oldurl} = $newsubpath;
2801: }
1.491 raeburn 2802: }
2803: }
1.597 raeburn 2804: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2805: my $template = $1;
2806: if ($newidx) {
2807: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2808: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2809: }
1.649 raeburn 2810: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2811: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2812: my $marker = (split(m{/},$url))[4];
2813: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2814: my $val = 'no';
2815: if ($toolsettings{'gradable'}) {
2816: $val = 'yes';
2817: }
2818: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2819: 'string_yesno');
2820: &remember_parms($newidx,'gradable','set',$val);
2821: }
1.491 raeburn 2822: }
1.538 raeburn 2823: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2824: ':'.$ext.':normal:res';
2825: push(@LONCAPA::map::order,$newidx);
2826: # Store the result
2827: my ($errtext,$fatal) =
2828: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2829: if ($fatal) {
2830: $save_err .= $errtext;
2831: $allresult = 'fail';
2832: }
1.488 raeburn 2833: }
1.538 raeburn 2834:
1.597 raeburn 2835: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2836: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2837: unless ($allresult eq 'fail') {
2838: my %updated = (
2839: rewrites => \%rewrites,
2840: zombies => \%zombies,
2841: removefrommap => \%removefrommap,
2842: removeparam => \%removeparam,
2843: dbcopies => \%dbcopies,
1.597 raeburn 2844: resdatacopy => \%resdatacopy,
1.538 raeburn 2845: retitles => \%retitles,
2846: );
2847: my %info = (
2848: newsubdir => \%newsubdir,
2849: params => \%params,
2850: );
2851: if ($prefixchg{$suffix}) {
2852: $info{'before'} = $before{$prefixchg{$suffix}};
2853: $info{'after'} = $after{$prefixchg{$suffix}};
2854: }
2855: my %moves = (
2856: copies => \%copies,
2857: docmoves => \%docmoves,
2858: mapmoves => \%mapmoves,
2859: );
2860: (my $result,$msgs{$suffix},my $lockerror) =
2861: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2862: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2863: $url,'paste');
2864: $lockerrors .= $lockerror;
2865: if ($result eq 'ok') {
2866: if ($is_map{$suffix}) {
2867: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2868: $folder.'.'.$container);
2869: if ($fatal) {
2870: $allresult = 'failread';
2871: } else {
2872: if ($#LONCAPA::map::order<1) {
2873: my $idx=&LONCAPA::map::getresidx();
2874: if ($idx<=0) { $idx=1; }
2875: $LONCAPA::map::order[0]=$idx;
2876: $LONCAPA::map::resources[$idx]='';
2877: }
2878: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2879: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2880: ':'.$ext.':normal:res';
2881: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2882:
2883: # Store the result
1.538 raeburn 2884: my ($errtext,$fatal) =
2885: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2886: if ($fatal) {
2887: $save_err .= $errtext;
2888: $allresult = 'failstore';
2889: }
2890: }
2891: }
2892: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2893: push(@toclear,$suffix);
2894: }
2895: }
1.492 raeburn 2896: }
2897: }
1.704 raeburn 2898: if (($updatetoolscache) || (@updatetoolsenc)) {
2899: &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
2900: \@updatetoolsenc);
2901: }
1.538 raeburn 2902: &clear_from_buffer(\@toclear,\@currpaste);
2903: my $msgsarray;
2904: foreach my $suffix (keys(%msgs)) {
2905: if (ref($msgs{$suffix}) eq 'ARRAY') {
2906: $msgsarray .= join(',',@{$msgs{$suffix}});
2907: }
2908: }
2909: return ($allresult,$save_err,$msgsarray,$lockerrors);
2910: }
1.533 raeburn 2911:
1.538 raeburn 2912: sub do_buffer_empty {
2913: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2914: if (@currpaste == 0) {
2915: return &mt('Clipboard is already empty');
2916: }
2917: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2918: if (@toclear == 0) {
2919: return &mt('Nothing selected to clear from clipboard');
2920: }
2921: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2922: if ($numdel) {
2923: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2924: } else {
2925: return &mt('Clipboard unchanged');
1.492 raeburn 2926: }
1.538 raeburn 2927: return;
2928: }
2929:
2930: sub clear_from_buffer {
2931: my ($toclear,$currpaste) = @_;
2932: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2933: my %pastebuffer;
2934: map { $pastebuffer{$_} = 1; } @{$currpaste};
2935: my $numdel = 0;
2936: foreach my $suffix (@{$toclear}) {
2937: next if ($suffix =~ /\D/);
2938: next unless (exists($pastebuffer{$suffix}));
2939: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2940: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2941: delete($pastebuffer{$suffix});
2942: $numdel ++;
2943: }
2944: }
2945: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2946: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2947: return $numdel;
1.492 raeburn 2948: }
2949:
1.704 raeburn 2950: sub update_ltitools_caches {
2951: my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
2952: my $hashid=$coursedom.'_'.$coursenum;
2953: if ($updatetoolscache) {
2954: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
2955: }
2956: if ((ref($updatetoolsenc) eq 'ARRAY') &&
2957: (@{$updatetoolsenc})) {
2958: my @ids=&Apache::lonnet::current_machine_ids();
2959: my $updatedone;
2960: foreach my $lonhost (@{$updatetoolsenc}) {
2961: if (grep(/^\Q$lonhost\E$/,@ids)) {
2962: unless ($updatedone) {
2963: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
2964: }
2965: $updatedone = 1;
2966: } else {
2967: &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
2968: }
2969: }
2970: }
2971: return;
2972: }
2973:
1.492 raeburn 2974: sub get_newmap_url {
2975: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2976: $titleref,$allmaps,$newurls) = @_;
2977: my $newurl;
2978: if ($url=~ m{^/uploaded/}) {
2979: $$titleref=&mt('Copy of').' '.$$titleref;
2980: }
2981: my $now = time;
2982: my $suffix=$$.int(rand(100)).$now;
2983: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2984: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2985: my $path = $1;
2986: my $prefix = $2;
2987: my $ancestor = $3;
2988: if (length($ancestor) > 10) {
2989: $ancestor = substr($ancestor,-10,10);
2990: }
2991: my $newid;
2992: if ($prefixchg) {
2993: if ($folder =~ /^supplemental/) {
2994: $prefix =~ s/^default/supplemental/;
2995: } else {
2996: $prefix =~ s/^supplemental/default/;
2997: }
2998: }
2999: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3000: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3001: } else {
3002: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
3003: }
3004: my $counter = 0;
3005: my $is_unique = &uniqueness_check($newurl);
3006: if ($folder =~ /^default/) {
3007: if ($allmaps->{$newurl}) {
3008: $is_unique = 0;
3009: }
3010: }
3011: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
3012: $counter ++;
3013: $suffix ++;
3014: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
3015: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
3016: } else {
3017: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
3018: }
3019: $is_unique = &uniqueness_check($newurl);
3020: }
3021: if ($is_unique) {
3022: $newurls->{$newurl} = 1;
3023: } else {
3024: if ($url=~/\.page$/) {
3025: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
3026: } else {
3027: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
3028: }
3029: }
1.329 droeschl 3030: }
1.492 raeburn 3031: return ($newurl);
1.329 droeschl 3032: }
3033:
1.488 raeburn 3034: sub dbcopy {
1.704 raeburn 3035: my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
3036: $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.533 raeburn 3037: my ($url,$result,$errtext);
3038: if (ref($dbref) eq 'HASH') {
1.596 raeburn 3039: $url = $dbref->{'src'};
1.627 raeburn 3040: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 3041: my $prefix = $1;
1.627 raeburn 3042: if ($prefix eq 'ext.tool') {
3043: $prefix = 'exttool';
3044: }
1.533 raeburn 3045: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3046: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3047: my $db_name;
3048: my $marker = (split(m{/},$url))[4];
3049: $marker=~s/\D//g;
3050: if ($dbref->{'src'} =~ m{/smppg$}) {
3051: $db_name =
3052: &Apache::lonsimplepage::get_db_name($url,$marker,
3053: $dbref->{'cdom'},
3054: $dbref->{'cnum'});
1.627 raeburn 3055: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
3056: $db_name = 'exttool_'.$marker;
1.533 raeburn 3057: } else {
3058: $db_name = 'bulletinpage_'.$marker;
3059: }
3060: my ($suffix,$freedlock,$error) =
3061: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
3062: $coursedom,$coursenum,
3063: 'concat');
3064: if (!$suffix) {
3065: if ($prefix eq 'smppg') {
3066: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 3067: } elsif ($prefix eq 'exttool') {
3068: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 3069: } else {
1.565 bisitz 3070: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 3071: }
3072: if ($error) {
3073: $errtext .= '<br />'.$error;
3074: }
3075: } else {
3076: #need to copy the db contents to a new one.
3077: my %contents=&Apache::lonnet::dump($db_name,
3078: $dbref->{'cdom'},
3079: $dbref->{'cnum'});
1.704 raeburn 3080: my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
3081: if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
3082: if ($contents{'id'} =~ /^(|c)(\d+)$/) {
3083: $oldtoolid = $2;
3084: if ($1 eq 'c') {
3085: $defincrs = 1;
3086: %toolinfo =
3087: &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
3088: } else {
3089: %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
3090: }
3091: if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
3092: if ($toolinfo{$oldtoolid}{'passback'}) {
3093: $toolpassback = 1;
3094: }
3095: if ($toolinfo{$oldtoolid}{'roster'}) {
3096: $toolroster = 1;
3097: }
3098: } else {
3099: $toolcopyerror = 1;
3100: $errtext = &mt('Could not retrieve original settings for pasted external tool.');
3101: }
3102: }
3103: unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
3104: $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
3105: if ($contents{'crstitle'} ne '') {
3106: $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
3107: }
3108: if (($defincrs) && (!$toolcopyerror)) {
3109: my %newtool;
3110: my $oldcdom = $dbref->{'cdom'};
3111: my $oldcnum = $dbref->{'cnum'};
3112: my $title = $toolinfo{$oldtoolid}{'title'};
3113: if (ref($currltititles) eq 'HASH') {
3114: if (exists($currltititles->{$title})) {
3115: $title .= ' (copied from another course)';
3116: }
3117: }
3118: my ($newid,$iderror) =
3119: &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
3120: if ($newid =~ /^\d+$/) {
3121: %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
3122: $newtool{$newid}{'title'} = $title;
3123: if (ref($currltimax)) {
3124: $newtool{$newid}{'order'} = $$currltimax;
3125: }
3126: if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
3127: my $fname = $1;
3128: my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
3129: if ($content eq '-1') {
3130: delete($newtool{$newid}{'image'});
3131: } else {
3132: $env{'form.'.$suffix.'.image'} = $content;
3133: my $newlogo =
3134: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
3135: delete($env{'form.'.$suffix.'.image'});
3136: if ($newlogo =~ m{^/uploaded/}) {
3137: $newtool{$newid}{'image'} = $newlogo;
3138: } else {
3139: delete($newtool{$newid}{'image'});
3140: }
3141: }
3142: }
3143: my $newusable;
3144: if ($same_institution) {
3145: my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
3146: if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
3147: my %newtoolsenc;
3148: %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
3149: my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
3150: if ($putres eq 'ok') {
3151: if (ref($updatetoolsenc) eq 'ARRAY') {
3152: my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
3153: unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
3154: push(@{$updatetoolsenc},$newhome);
3155: }
3156: }
3157: $newusable = 1;
3158: }
3159: }
3160: }
3161: if ($newtool{$newid}{'usable'}) {
3162: unless ($newusable) {
3163: delete($newtool{$newid}{'usable'});
3164: }
3165: }
3166: my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
3167: if ($putres eq 'ok') {
3168: $contents{'id'} = "c$newid";
3169: if (ref($updatetoolscache)) {
3170: $$updatetoolscache ++;
3171: }
3172: if (ref($currltititles->{$title}) eq 'ARRAY') {
3173: push(@{$currltititles->{$title}},$newid);
3174: } else {
3175: $currltititles->{$title} = [$newid];
3176: }
3177: if (ref($currltimax)) {
3178: $$currltimax ++;
3179: }
3180: } else {
3181: $toolcopyerror = 1;
3182: $errtext = &mt('Unable to save external tool definition in Course Settings.');
3183: }
3184: } else {
3185: $toolcopyerror = 1;
3186: $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
3187: }
3188: }
3189: }
3190: }
1.533 raeburn 3191: if (exists($contents{'uploaded.photourl'})) {
3192: my $photo = $contents{'uploaded.photourl'};
3193: my ($subdir,$fname) =
3194: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 3195: my $newphoto;
1.533 raeburn 3196: if ($fname ne '') {
3197: my $content = &Apache::lonnet::getfile($photo);
3198: unless ($content eq '-1') {
3199: $env{'form.'.$suffix.'.photourl'} = $content;
3200: $newphoto =
3201: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
3202: delete($env{'form.'.$suffix.'.photourl'});
3203: }
3204: }
3205: if ($newphoto =~ m{^/uploaded/}) {
3206: $contents{'uploaded.photourl'} = $newphoto;
3207: }
3208: }
3209: $db_name =~ s{_\d*$ }{_$suffix}x;
1.704 raeburn 3210: if ($prefix eq 'exttool') {
3211: unless ($toolcopyerror) {
3212: foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
3213: if (exists($contents{$key})) {
3214: delete($contents{$key});
3215: }
3216: }
3217: if ($dbref->{'delgradable'}) {
3218: if (exists($contents{'gradable'})) {
3219: delete($contents{'gradable'});
3220: }
3221: }
3222: if ($toolpassback) {
3223: if ($contents{'gradable'}) {
3224: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3225: $contents{'gradesecret'} = $gradesecret;
3226: $contents{'gradesecretdate'} = time;
3227: }
3228: }
3229: if ($toolroster) {
3230: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
3231: $contents{'rostersecret'} = $rostersecret;
3232: $contents{'rostersecretdate'} = time;
3233: }
3234: }
1.649 raeburn 3235: }
1.704 raeburn 3236: if (($prefix eq 'exttool') && ($toolcopyerror)) {
3237: $result = 'error';
3238: } else {
3239: $result=&Apache::lonnet::put($db_name,\%contents,
3240: $coursedom,$coursenum);
3241: if ($result eq 'ok') {
3242: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
3243: }
1.533 raeburn 3244: }
3245: }
3246: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 3247: $lockerrorsref->{$prefix} =
1.533 raeburn 3248: '<div class="LC_error">'.
3249: &mt('There was a problem removing a lockfile.');
3250: if ($prefix eq 'smppg') {
1.560 raeburn 3251: $lockerrorsref->{$prefix} .=
1.559 raeburn 3252: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 3253: } elsif ($prefix eq 'exttool') {
3254: $lockerrorsref->{$prefix} .=
3255: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 3256: } else {
1.565 bisitz 3257: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 3258: }
1.560 raeburn 3259: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
3260: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
3261: '</div>';
1.533 raeburn 3262: }
3263: }
3264: } elsif ($url =~ m{/syllabus$}) {
3265: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
3266: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
3267: if (($dbref->{'cdom'} ne $coursedom) ||
3268: ($dbref->{'cnum'} ne $coursenum)) {
3269: my %contents=&Apache::lonnet::dump('syllabus',
3270: $dbref->{'cdom'},
3271: $dbref->{'cnum'});
3272: $result=&Apache::lonnet::put('syllabus',\%contents,
3273: $coursedom,$coursenum);
3274: }
3275: }
1.488 raeburn 3276: }
3277: }
1.533 raeburn 3278: return ($url,$result,$errtext);
1.488 raeburn 3279: }
3280:
1.597 raeburn 3281: sub copy_templated_files {
3282: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
3283: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
3284: my $srccontainer = 'sequence';
3285: if ($srcwaspage) {
3286: $srccontainer = 'page';
3287: }
3288: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
3289: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
3290: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
3291: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
3292: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
3293: $template.'.problem';
3294: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
3295: if ($template eq 'simpleproblem') {
3296: $srcprefix .= '.0.';
3297: my $weightprefix = $newprefix;
3298: $newprefix .= '.0.';
3299: my @simpleprobqtypes = qw(radio option string essay numerical);
3300: my $qtype=$srcparms{$srcprefix.'questiontype'};
3301: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 3302: my %newdata = (
3303: $newprefix.'questiontype' => $qtype,
3304: );
1.597 raeburn 3305: foreach my $type (@simpleprobqtypes) {
3306: if ($type eq $qtype) {
3307: $newdata{"$weightprefix.$type.weight"}=1;
3308: } else {
3309: $newdata{"$weightprefix.$type.weight"}=0;
3310: }
3311: }
3312: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
3313: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
3314: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
3315: if ($qtype eq 'numerical') {
3316: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
3317: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
3318: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
3319: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
3320: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3321: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3322: unless (defined($maxfoils)) { $maxfoils=10; }
3323: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3324: if ($maxfoils<=0) { $maxfoils=10; }
3325: my $randomize=$srcparms{$srcprefix.'randomize'};
3326: unless (defined($randomize)) { $randomize='yes'; }
3327: unless ($randomize eq 'no') { $randomize='yes'; }
3328: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3329: $newdata{$newprefix.'randomize'} = $randomize;
3330: if ($qtype eq 'option') {
3331: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3332: }
3333: for (my $i=1; $i<=10; $i++) {
3334: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3335: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3336: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3337: }
3338:
3339: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
3340: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
3341: unless (defined($maxfoils)) { $maxfoils=10; }
3342: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
3343: if ($maxfoils<=0) { $maxfoils=10; }
3344: my $randomize=$srcparms{$srcprefix.'randomize'};
3345: unless (defined($randomize)) { $randomize='yes'; }
3346: unless ($randomize eq 'no') { $randomize='yes'; }
3347: $newdata{$newprefix.'maxfoils'} = $maxfoils;
3348: $newdata{$newprefix.'randomize'} = $randomize;
3349: if ($qtype eq 'option') {
3350: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
3351: }
3352: for (my $i=1; $i<=10; $i++) {
3353: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
3354: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
3355: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
3356: }
3357: } elsif ($qtype eq 'string') {
3358: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
3359: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
3360: }
3361: if (keys(%newdata)) {
3362: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
3363: $coursenum);
3364: if ($putres eq 'ok') {
3365: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
3366: }
3367: }
3368: }
3369: }
3370: }
3371:
1.329 droeschl 3372: sub uniqueness_check {
3373: my ($newurl) = @_;
3374: my $unique = 1;
3375: foreach my $res (@LONCAPA::map::order) {
3376: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3377: $url=&LONCAPA::map::qtescape($url);
3378: if ($newurl eq $url) {
3379: $unique = 0;
1.344 bisitz 3380: last;
1.329 droeschl 3381: }
3382: }
3383: return $unique;
3384: }
3385:
1.488 raeburn 3386: sub contained_map_check {
1.627 raeburn 3387: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
3388: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 3389: my $content = &Apache::lonnet::getfile($url);
3390: unless ($content eq '-1') {
3391: my $parser = HTML::TokeParser->new(\$content);
3392: $parser->attr_encoded(1);
3393: while (my $token = $parser->get_token) {
3394: next if ($token->[0] ne 'S');
3395: if ($token->[1] eq 'resource') {
3396: next if ($token->[2]->{'type'} eq 'zombie');
3397: my $ressrc = $token->[2]->{'src'};
1.704 raeburn 3398: if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
3399: my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
1.627 raeburn 3400: unless ($srcdom eq $coursedom) {
3401: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3402: next;
3403: }
1.704 raeburn 3404: unless ($srcnum eq $coursenum) {
3405: my %toolsettings =
3406: &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
3407: my %tooltypes = &Apache::loncommon::usable_exttools();
3408: if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
3409: (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
3410: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3411: next;
3412: }
3413: }
1.627 raeburn 3414: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 3415: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 3416: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 3417: next;
3418: }
3419: }
1.703 raeburn 3420: if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
3421: my ($srcdom,$srcnum) = ($1,$2);
3422: unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
3423: if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
3424: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3425: next;
3426: }
3427: }
3428: }
1.492 raeburn 3429: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
3430: if ($1 eq 'uploaded') {
3431: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
3432: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 3433: } else {
1.492 raeburn 3434: if ($allmaps->{$ressrc}) {
1.529 raeburn 3435: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 3436: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
3437: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
3438: } else {
3439: $addedmaps->{$ressrc} = [$url];
3440: }
1.488 raeburn 3441: }
1.627 raeburn 3442: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
3443: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 3444: }
1.492 raeburn 3445: } elsif ($token->[1] eq 'param') {
1.488 raeburn 3446: if ($folder =~ /^supplemental/) {
1.492 raeburn 3447: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
3448: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
3449: } else {
3450: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
3451: }
1.488 raeburn 3452: }
3453: }
3454: }
3455: }
3456: return;
3457: }
3458:
3459: sub url_paste_fixups {
1.533 raeburn 3460: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
3461: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 3462: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 3463: my $checktitle;
3464: if (($prefixchg) &&
1.492 raeburn 3465: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 3466: $checktitle = 1;
3467: }
1.492 raeburn 3468: my $skip;
3469: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
3470: my $mapid = $1.$2;
3471: if ($tomove->{$mapid}) {
3472: $skip = 1;
3473: }
3474: }
1.491 raeburn 3475: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 3476: return if ($file eq '-1');
3477: my $parser = HTML::TokeParser->new(\$file);
3478: $parser->attr_encoded(1);
1.491 raeburn 3479: my $changed = 0;
1.488 raeburn 3480: while (my $token = $parser->get_token) {
3481: next if ($token->[0] ne 'S');
3482: if ($token->[1] eq 'resource') {
3483: my $ressrc = $token->[2]->{'src'};
3484: next if ($ressrc eq '');
1.491 raeburn 3485: my $id = $token->[2]->{'id'};
1.492 raeburn 3486: my $title = $token->[2]->{'title'};
1.491 raeburn 3487: if ($checktitle) {
3488: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 3489: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3490: }
3491: }
1.488 raeburn 3492: next if ($token->[2]->{'type'} eq 'external');
3493: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 3494: next if ($skip);
1.532 raeburn 3495: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3496: $changed = 1;
3497: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3498: my $srcdom = $1;
3499: my $srcnum = $2;
1.488 raeburn 3500: my $rem = $3;
1.492 raeburn 3501: my $newurl;
3502: my $mapname;
3503: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
3504: my $prefix = $1;
3505: $mapname = $prefix.$2;
3506: if ($tomove->{$mapname}) {
1.533 raeburn 3507: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
3508: $srcdom,$srcnum,$allmaps,$rewrites,
3509: $retitles,$copies,$dbcopies,$zombies,
3510: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 3511: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 3512: next;
3513: } else {
3514: ($newurl,my $error) =
3515: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
3516: $srcdom,$srcnum,\$title,$allmaps,$newurls);
3517: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
3518: $newsubdir->{$ressrc} = $1;
3519: }
3520: if ($error) {
3521: next;
3522: }
3523: }
3524: }
3525: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
3526: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
3527:
1.488 raeburn 3528: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 3529: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 3530: $mapchanges->{$ressrc} = 1;
1.533 raeburn 3531: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
3532: $cnum,$srcdom,$srcnum,$allmaps,
3533: $rewrites,$retitles,$copies,$dbcopies,
3534: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 3535: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 3536: $mapmoves->{$ressrc} = 1;
3537: }
3538: $changed = 1;
1.488 raeburn 3539: } else {
1.532 raeburn 3540: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 3541: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 3542: $changed = 1;
1.488 raeburn 3543: }
3544: }
1.649 raeburn 3545: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 3546: next if ($skip);
1.492 raeburn 3547: my $srcdom = $1;
3548: my $srcnum = $2;
1.649 raeburn 3549: my $rem = $3;
3550: my ($is_exttool,$exttoolchg);
3551: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 3552: $is_exttool = 1;
1.649 raeburn 3553: }
1.492 raeburn 3554: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 3555: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 3556: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3557: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3558: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3559: $changed = 1;
1.649 raeburn 3560: if ($is_exttool) {
3561: $exttoolchg = 1;
3562: }
1.700 raeburn 3563: } elsif (($is_exttool) &&
1.649 raeburn 3564: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3565: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3566: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3567: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
3568: $changed = 1;
3569: $exttoolchg = 1;
3570: }
3571: if (($is_exttool) && ($prefixchg)) {
3572: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
3573: if ($exttoolchg) {
3574: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
3575: }
3576: }
1.533 raeburn 3577: }
3578: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
3579: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
3580: ($env{'form.docs.markedcopy_options'} ne 'move')) {
3581: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3582: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
3583: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 3584: $changed = 1;
1.488 raeburn 3585: }
1.597 raeburn 3586: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
3587: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
3588: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
3589: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
3590: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
3591: }
1.488 raeburn 3592: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 3593: next if ($skip);
3594: my $srcdom = $1;
3595: my $srcnum = $2;
3596: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 3597: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
3598: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
3599: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 3600: $changed = 1;
1.488 raeburn 3601: }
3602: }
3603: } elsif ($token->[1] eq 'param') {
1.492 raeburn 3604: next if ($skip);
1.488 raeburn 3605: my $to = $token->[2]->{'to'};
3606: if ($to ne '') {
3607: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 3608: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 3609: } else {
3610: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
3611: }
3612: }
3613: }
3614: }
1.491 raeburn 3615: return $changed;
1.488 raeburn 3616: }
3617:
3618: sub apply_fixups {
1.529 raeburn 3619: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
3620: $oldurl,$url,$caller) = @_;
3621: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 3622: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.704 raeburn 3623: %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
3624: %currltititles,$currltimax);
3625: $currltimax = 0;
1.529 raeburn 3626: if (ref($updated) eq 'HASH') {
3627: if (ref($updated->{'rewrites'}) eq 'HASH') {
3628: %rewrites = %{$updated->{'rewrites'}};
3629: }
3630: if (ref($updated->{'zombies'}) eq 'HASH') {
3631: %zombies = %{$updated->{'zombies'}};
3632: }
3633: if (ref($updated->{'removefrommap'}) eq 'HASH') {
3634: %removefrommap = %{$updated->{'removefrommap'}};
3635: }
3636: if (ref($updated->{'removeparam'}) eq 'HASH') {
3637: %removeparam = %{$updated->{'removeparam'}};
3638: }
3639: if (ref($updated->{'dbcopies'}) eq 'HASH') {
3640: %dbcopies = %{$updated->{'dbcopies'}};
3641: }
3642: if (ref($updated->{'retitles'}) eq 'HASH') {
3643: %retitles = %{$updated->{'retitles'}};
3644: }
1.597 raeburn 3645: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
3646: %resdatacopy = %{$updated->{'resdatacopy'}};
3647: }
1.529 raeburn 3648: }
3649: if (ref($info) eq 'HASH') {
3650: if (ref($info->{'newsubdir'}) eq 'HASH') {
3651: %newsubdir = %{$info->{'newsubdir'}};
3652: }
3653: if (ref($info->{'params'}) eq 'HASH') {
3654: %params = %{$info->{'params'}};
3655: }
3656: if (ref($info->{'before'}) eq 'HASH') {
3657: %before = %{$info->{'before'}};
3658: }
3659: if (ref($info->{'after'}) eq 'HASH') {
3660: %after = %{$info->{'after'}};
3661: }
3662: }
3663: if (ref($moves) eq 'HASH') {
3664: if (ref($moves->{'copies'}) eq 'HASH') {
3665: %copies = %{$moves->{'copies'}};
3666: }
3667: if (ref($moves->{'docmoves'}) eq 'HASH') {
3668: %docmoves = %{$moves->{'docmoves'}};
3669: }
3670: if (ref($moves->{'mapmoves'}) eq 'HASH') {
3671: %mapmoves = %{$moves->{'mapmoves'}};
3672: }
3673: }
3674: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 3675: my @allcopies;
1.529 raeburn 3676: if (exists($copies{$key})) {
3677: if (ref($copies{$key}) eq 'HASH') {
3678: my %added;
3679: foreach my $innerkey (keys(%{$copies{$key}})) {
3680: if (($innerkey ne '') && (!$added{$innerkey})) {
3681: push(@allcopies,$innerkey);
3682: $added{$innerkey} = 1;
3683: }
1.491 raeburn 3684: }
1.529 raeburn 3685: undef(%added);
1.491 raeburn 3686: }
3687: }
3688: if ($key eq $oldurl) {
1.529 raeburn 3689: if ((exists($docmoves{$key}))) {
1.532 raeburn 3690: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 3691: push(@allcopies,$oldurl);
3692: }
3693: }
3694: }
3695: if (@allcopies > 0) {
3696: foreach my $item (@allcopies) {
1.492 raeburn 3697: my ($relpath,$oldsubdir,$fname) =
3698: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 3699: if ($fname ne '') {
3700: my $content = &Apache::lonnet::getfile($item);
3701: unless ($content eq '-1') {
3702: my $storefn;
1.529 raeburn 3703: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
3704: $storefn = $docmoves{$key};
1.491 raeburn 3705: } else {
3706: $storefn = $relpath;
3707: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3708: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
3709: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 3710: }
1.529 raeburn 3711: if ($newsubdir{$key}) {
1.532 raeburn 3712: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 3713: }
3714: }
3715: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
3716: my $copyurl =
3717: &Apache::lonclonecourse::writefile($env{'request.course.id'},
3718: $storefn.$fname,$content);
3719: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 3720: if (exists($docmoves{$oldurl})) {
1.491 raeburn 3721: return &mt('Paste failed: an error occurred copying the file.');
3722: } elsif (ref($errors) eq 'HASH') {
3723: $errors->{$item} = 1;
1.489 raeburn 3724: }
3725: }
1.488 raeburn 3726: }
3727: }
1.491 raeburn 3728: }
3729: }
3730: }
1.529 raeburn 3731: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 3732: my $storefn=$key;
3733: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3734: if ($prefixchg && $before{'map'} && $after{'map'}) {
3735: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3736: }
1.529 raeburn 3737: if ($newsubdir{$key}) {
3738: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3739: }
1.491 raeburn 3740: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 3741: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
3742: ($after{'map'} eq 'default') &&
3743: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
3744: $mapcontent = '<map>'."\n".
3745: '<resource id="1" src="" type="start" />'."\n".
3746: '<link from="1" to="2" index="1" />'."\n".
3747: '<resource id="2" src="" type="finish" />'."\n".
3748: '</map>';
3749: }
1.491 raeburn 3750: if ($mapcontent eq '-1') {
3751: if (ref($errors) eq 'HASH') {
3752: $errors->{$key} = 1;
3753: }
3754: } else {
3755: my $newmap =
3756: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
3757: $mapcontent);
3758: if ($newmap eq '/adm/notfound.html') {
3759: if (ref($errors) eq 'HASH') {
3760: $errors->{$key} = 1;
1.489 raeburn 3761: }
1.488 raeburn 3762: }
3763: }
3764: }
1.491 raeburn 3765: my %updates;
3766: if ($is_map) {
1.529 raeburn 3767: if (ref($updated) eq 'HASH') {
3768: foreach my $type (keys(%{$updated})) {
3769: if (ref($updated->{$type}) eq 'HASH') {
3770: foreach my $key (keys(%{$updated->{$type}})) {
3771: $updates{$key} = 1;
3772: }
3773: }
3774: }
1.491 raeburn 3775: }
1.704 raeburn 3776: my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.491 raeburn 3777: foreach my $key (keys(%updates)) {
1.492 raeburn 3778: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 3779: if (ref($rewrites{$key}) eq 'HASH') {
3780: %torewrite = %{$rewrites{$key}};
1.491 raeburn 3781: }
1.529 raeburn 3782: if (ref($retitles{$key}) eq 'HASH') {
3783: %toretitle = %{$retitles{$key}};
1.491 raeburn 3784: }
1.529 raeburn 3785: if (ref($removefrommap{$key}) eq 'HASH') {
3786: %toremove = %{$removefrommap{$key}};
1.491 raeburn 3787: }
1.529 raeburn 3788: if (ref($removeparam{$key}) eq 'HASH') {
3789: %remparam = %{$removeparam{$key}};
1.492 raeburn 3790: }
1.529 raeburn 3791: if (ref($zombies{$key}) eq 'HASH') {
3792: %zombie = %{$zombies{$key}};
1.491 raeburn 3793: }
1.529 raeburn 3794: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 3795: foreach my $idx (keys(%{$dbcopies{$key}})) {
3796: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.704 raeburn 3797: my $oldurl = $dbcopies{$key}{$idx}{'src'};
3798: my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
3799: my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
3800: my $oldmarker;
3801: if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
3802: $oldmarker = $1;
3803: unless (($gotcrsltitools) ||
3804: (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
3805: my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
3806: if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
3807: unless ($gotcrsltitools) {
3808: %currcrsltitools =
3809: &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
3810: foreach my $item (sort(keys(%currcrsltitools))) {
3811: if (ref($currcrsltitools{$item}) eq 'HASH') {
3812: $currltimax ++;
3813: if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
3814: push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
3815: } else {
3816: $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
3817: }
3818: }
3819: }
3820: $gotcrsltitools = 1;
3821: }
3822: unless ($checkedsameinst) {
3823: my $primary_id = &Apache::lonnet::domain($cdom,'primary');
3824: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3825: if ($intdom ne '') {
3826: my $internet_names =
3827: &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
3828: if (ref($internet_names) eq 'ARRAY') {
3829: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
3830: $same_institution = 1;
3831: }
3832: }
3833: }
3834: $checkedsameinst = 1;
3835: }
3836: }
3837: }
3838: }
1.533 raeburn 3839: my ($newurl,$result,$errtext) =
1.704 raeburn 3840: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
3841: \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.533 raeburn 3842: if ($result eq 'ok') {
3843: $newdb{$idx} = $newurl;
1.704 raeburn 3844: if ($newurl =~ /ext\.tool$/) {
3845: if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
3846: if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
3847: my $newmarker = $1;
3848: unless ($oldmarker eq $newmarker) {
3849: $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
3850: }
3851: }
3852: }
3853: }
1.533 raeburn 3854: } elsif (ref($errors) eq 'HASH') {
3855: $errors->{$key} = 1;
3856: }
3857: push(@msgs,$errtext);
3858: }
1.491 raeburn 3859: }
3860: }
1.597 raeburn 3861: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 3862: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 3863: foreach my $idx (keys(%{$resdatacopy{$key}})) {
3864: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
3865: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
3866: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
3867: my $template = $1;
3868: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
3869: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
3870: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
3871: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 3872: unless ($gotnewmapname) {
3873: ($newmapname) = ($key =~ m{/([^/]+)$});
3874: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
3875: if ($newsubdir{$key}) {
3876: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
3877: }
3878: $gotnewmapname = 1;
3879: }
1.597 raeburn 3880: my $srcmapinfo = $srcfolder.':'.$idx;
3881: if ($srccontainer eq 'page') {
3882: $srcmapinfo .= ':1';
3883: }
3884: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
3885: $cnum,$template,$idx,$newmapname);
3886: }
3887: }
3888: }
3889: }
3890: }
1.529 raeburn 3891: if (ref($params{$key}) eq 'HASH') {
3892: %currparam = %{$params{$key}};
1.492 raeburn 3893: }
3894: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
3895: if ($fatal) {
1.533 raeburn 3896: return ($errtext);
1.492 raeburn 3897: }
3898: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
3899: if (defined($LONCAPA::map::zombies[$i])) {
3900: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 3901: if ($zombie{$i} eq $src) {
1.492 raeburn 3902: undef($LONCAPA::map::zombies[$i]);
3903: }
3904: }
3905: }
1.646 raeburn 3906: my $total = scalar(@LONCAPA::map::order) - 1;
3907: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 3908: my $idx = $LONCAPA::map::order[$i];
3909: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 3910: my $changed;
1.529 raeburn 3911: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 3912: if ((exists($toremove{$idx})) &&
3913: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 3914: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 3915: if (ref($currparam{$idx}) eq 'ARRAY') {
3916: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 3917: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 3918: }
3919: }
3920: next;
3921: }
3922: my $origsrc = $src;
1.532 raeburn 3923: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 3924: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
3925: $changed = 1;
1.491 raeburn 3926: }
1.492 raeburn 3927: }
1.532 raeburn 3928: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 3929: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
3930: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 3931: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 3932: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 3933: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 3934: } else {
1.529 raeburn 3935: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 3936: }
1.491 raeburn 3937: }
1.532 raeburn 3938: if ($origsrc =~ /\.(page|sequence)$/) {
3939: if ($newsubdir{$origsrc}) {
1.529 raeburn 3940: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 3941: }
1.532 raeburn 3942: } elsif ($newsubdir{$key}) {
3943: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 3944: }
3945: }
1.492 raeburn 3946: $changed = 1;
1.533 raeburn 3947: } elsif ($newdb{$idx} ne '') {
3948: $src = $newdb{$idx};
1.492 raeburn 3949: $changed = 1;
3950: }
3951: if ($changed) {
1.538 raeburn 3952: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 3953: }
3954: }
3955: }
3956: foreach my $idx (keys(%remparam)) {
3957: if (ref($remparam{$idx}) eq 'ARRAY') {
3958: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 3959: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 3960: }
3961: }
3962: }
1.533 raeburn 3963: if (values(%lockerrors) > 0) {
3964: $lockmsg = join('<br />',values(%lockerrors));
3965: }
1.491 raeburn 3966: my $storefn;
3967: if ($key eq $oldurl) {
3968: $storefn = $url;
3969: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3970: } else {
3971: $storefn = $key;
3972: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3973: if ($prefixchg && $before{'map'} && $after{'map'}) {
3974: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3975: }
1.529 raeburn 3976: if ($newsubdir{$key}) {
3977: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3978: }
1.491 raeburn 3979: }
1.492 raeburn 3980: my $report;
3981: if ($folder !~ /^supplemental/) {
3982: $report = 1;
3983: }
1.527 raeburn 3984: (my $outtext,$errtext) =
1.492 raeburn 3985: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3986: if ($errtext) {
1.529 raeburn 3987: if ($caller eq 'paste') {
1.533 raeburn 3988: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 3989: }
1.491 raeburn 3990: }
3991: }
1.704 raeburn 3992: if (($updatetoolscache) || (@updatetoolsenc)) {
3993: &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
3994: \@updatetoolsenc);
3995: }
1.491 raeburn 3996: }
1.533 raeburn 3997: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 3998: }
3999:
4000: sub copy_dependencies {
4001: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
4002: my $content;
4003: if (ref($contentref)) {
4004: $content = $$contentref;
4005: } else {
4006: $content = &Apache::lonnet::getfile($item);
4007: }
4008: unless ($content eq '-1') {
4009: my $mm = new File::MMagic;
4010: my $mimetype = $mm->checktype_contents($content);
4011: if ($mimetype eq 'text/html') {
4012: my (%allfiles,%codebase,$state);
4013: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
4014: if ($res eq 'ok') {
4015: my ($numexisting,$numpathchanges,$existing);
4016: (undef,$numexisting,$numpathchanges,$existing) =
4017: &Apache::loncommon::ask_for_embedded_content(
4018: '/adm/coursedocs',$state,\%allfiles,\%codebase,
4019: {'error_on_invalid_names' => 1,
4020: 'ignore_remote_references' => 1,
4021: 'docs_url' => $item,
4022: 'context' => 'paste'});
4023: if ($numexisting > 0) {
4024: if (ref($existing) eq 'HASH') {
4025: foreach my $dep (keys(%{$existing})) {
4026: my $depfile = $dep;
4027: unless ($depfile =~ m{^\Q$relpath\E}) {
4028: $depfile = $relpath.$dep;
4029: }
4030: my $depcontent = &Apache::lonnet::getfile($depfile);
4031: unless ($depcontent eq '-1') {
4032: my $storedep = $dep;
4033: $storedep =~ s{^\Q$relpath\E}{};
4034: my $dep_url =
4035: &Apache::lonclonecourse::writefile(
4036: $env{'request.course.id'},
4037: $storefn.$storedep,$depcontent);
4038: if ($dep_url eq '/adm/notfound.html') {
4039: if (ref($errors) eq 'HASH') {
4040: $errors->{$depfile} = 1;
4041: }
4042: } else {
4043: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
4044: }
4045: }
4046: }
1.488 raeburn 4047: }
4048: }
4049: }
4050: }
4051: }
4052: return;
4053: }
4054:
1.329 droeschl 4055: my %parameter_type = ( 'randompick' => 'int_pos',
4056: 'hiddenresource' => 'string_yesno',
4057: 'encrypturl' => 'string_yesno',
4058: 'randomorder' => 'string_yesno',);
4059: my $valid_parameters_re = join('|',keys(%parameter_type));
4060: # set parameters
4061: sub update_parameter {
1.537 raeburn 4062: if ($env{'form.changeparms'} eq 'all') {
4063: my (@allidx,@allmapidx,%allchecked,%currchecked);
4064: %allchecked = (
4065: 'hiddenresource' => {},
4066: 'encrypturl' => {},
4067: 'randompick' => {},
4068: 'randomorder' => {},
4069: );
4070: foreach my $which (keys(%allchecked)) {
1.630 raeburn 4071: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 4072: if ($which eq 'randompick') {
4073: foreach my $item (split(/,/,$env{'form.all'.$which})) {
4074: my ($res,$value) = split(/:/,$item);
4075: if ($value =~ /^\d+$/) {
4076: $allchecked{$which}{$res} = $value;
4077: }
4078: }
4079: } else {
1.539 raeburn 4080: if ($env{'form.all'.$which}) {
4081: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
4082: }
1.537 raeburn 4083: }
4084: }
4085: my $haschanges = 0;
4086: foreach my $res (@LONCAPA::map::order) {
4087: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4088: $name=&LONCAPA::map::qtescape($name);
4089: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 4090: next unless $url;
1.537 raeburn 4091: my $is_map;
4092: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4093: $is_map = 1;
4094: }
4095: foreach my $which (keys(%allchecked)) {
4096: if (($which eq 'randompick' || $which eq 'randomorder')) {
4097: next if (!$is_map);
4098: }
4099: my $oldvalue = 0;
4100: my $newvalue = 0;
4101: if ($allchecked{$which}{$res}) {
4102: $newvalue = $allchecked{$which}{$res};
4103: }
4104: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
4105: if ($which eq 'randompick') {
4106: if ($current =~ /^(\d+)$/) {
4107: $oldvalue = $1;
4108: }
4109: } else {
4110: if ($current =~ /^yes$/i) {
4111: $oldvalue = 1;
4112: }
4113: }
4114: if ($oldvalue ne $newvalue) {
4115: $haschanges = 1;
4116: if ($newvalue) {
4117: my $storeval = 'yes';
4118: if ($which eq 'randompick') {
4119: $storeval = $newvalue;
4120: }
4121: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
4122: $storeval,
4123: $parameter_type{$which});
4124: &remember_parms($res,$which,'set',$storeval);
4125: } elsif ($oldvalue) {
4126: &LONCAPA::map::delparameter($res,'parameter_'.$which);
4127: &remember_parms($res,$which,'del');
4128: }
4129: }
4130: }
4131: }
4132: return $haschanges;
4133: } else {
1.588 raeburn 4134: my $haschanges = 0;
4135: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 4136:
1.537 raeburn 4137: my $which = $env{'form.changeparms'};
4138: my $idx = $env{'form.setparms'};
1.588 raeburn 4139: my $oldvalue = 0;
4140: my $newvalue = 0;
4141: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
4142: if ($which eq 'randompick') {
4143: if ($current =~ /^(\d+)$/) {
4144: $oldvalue = $1;
4145: }
4146: } elsif ($current =~ /^yes$/i) {
4147: $oldvalue = 1;
4148: }
1.537 raeburn 4149: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 4150: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
4151: : 1;
4152: }
4153: if ($oldvalue ne $newvalue) {
4154: $haschanges = 1;
4155: if ($newvalue) {
4156: my $storeval = 'yes';
4157: if ($which eq 'randompick') {
4158: $storeval = $newvalue;
4159: }
4160: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
4161: $parameter_type{$which});
4162: &remember_parms($idx,$which,'set',$storeval);
4163: } else {
4164: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
4165: &remember_parms($idx,$which,'del');
4166: }
1.537 raeburn 4167: }
1.588 raeburn 4168: return $haschanges;
1.329 droeschl 4169: }
4170: }
4171:
4172: sub handle_edit_cmd {
4173: my ($coursenum,$coursedom) =@_;
1.633 raeburn 4174: my $haschanges = 0;
1.543 raeburn 4175: if ($env{'form.cmd'} eq '') {
1.633 raeburn 4176: return $haschanges;
1.543 raeburn 4177: }
1.329 droeschl 4178: my ($cmd,$idx)=split('_',$env{'form.cmd'});
4179:
4180: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
4181: my ($title, $url, @rrest) = split(':', $ratstr);
4182:
1.538 raeburn 4183: if ($cmd eq 'remove') {
1.329 droeschl 4184: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 4185: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 4186: &Apache::lonnet::removeuploadedurl($url);
4187: } else {
4188: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4189: }
4190: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4191: $haschanges = 1;
1.329 droeschl 4192: } elsif ($cmd eq 'cut') {
4193: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
4194: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 4195: $haschanges = 1;
1.344 bisitz 4196: } elsif ($cmd eq 'up'
1.329 droeschl 4197: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
4198: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 4199: $haschanges = 1;
1.329 droeschl 4200: } elsif ($cmd eq 'down'
4201: && defined($LONCAPA::map::order[$idx+1])) {
4202: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 4203: $haschanges = 1;
1.329 droeschl 4204: } elsif ($cmd eq 'rename') {
4205: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
4206: if ($comment=~/\S/) {
4207: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
4208: $comment.':'.join(':', $url, @rrest);
4209: }
4210: # Devalidate title cache
4211: my $renamed_url=&LONCAPA::map::qtescape($url);
4212: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 4213: $haschanges = 1;
4214: } elsif ($cmd eq 'setalias') {
4215: my $newvalue = $env{'form.alias'};
4216: if ($newvalue ne '') {
4217: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
4218: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
4219: 'string');
4220: &remember_parms($idx,'mapalias','set',$newvalue);
4221: $haschanges = 1;
4222: }
4223: }
4224: } elsif ($cmd eq 'delalias') {
4225: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
4226: if ($current ne '') {
4227: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
4228: &remember_parms($idx,'mapalias','del');
4229: $haschanges = 1;
4230: }
1.329 droeschl 4231: }
1.633 raeburn 4232: return $haschanges;
1.329 droeschl 4233: }
4234:
4235: sub editor {
1.458 raeburn 4236: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 4237: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 4238: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 4239: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 4240: if ($allowed) {
1.519 raeburn 4241: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
4242: $is_random_order,$container) =
1.510 raeburn 4243: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
4244: $r->print($breadcrumbtrail);
1.519 raeburn 4245: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
4246: $container = 'page';
4247: } else {
4248: $container = 'sequence';
1.510 raeburn 4249: }
1.484 raeburn 4250:
1.525 raeburn 4251: my $jumpto;
4252:
4253: unless ($supplementalflag) {
1.546 raeburn 4254: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 4255: }
1.484 raeburn 4256:
4257: unless ($allowed) {
4258: $randompick = -1;
4259: }
4260:
1.615 raeburn 4261: my ($errtext,$fatal);
4262: if (($folder eq '') && (!$supplementalflag)) {
4263: if (@LONCAPA::map::order) {
4264: undef(@LONCAPA::map::order);
4265: undef(@LONCAPA::map::resources);
4266: undef(@LONCAPA::map::resparms);
4267: undef(@LONCAPA::map::zombies);
4268: }
4269: $folder = 'default';
4270: $container = 'sequence';
4271: } else {
4272: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
4273: $folder.'.'.$container);
4274: return $errtext if ($fatal);
4275: }
1.329 droeschl 4276:
4277: if ($#LONCAPA::map::order<1) {
4278: my $idx=&LONCAPA::map::getresidx();
4279: if ($idx<=0) { $idx=1; }
4280: $LONCAPA::map::order[0]=$idx;
4281: $LONCAPA::map::resources[$idx]='';
4282: }
1.364 bisitz 4283:
1.329 droeschl 4284: # ------------------------------------------------------------ Process commands
4285:
4286: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 4287: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 4288: # set parameters and change order
4289: &snapshotbefore();
4290:
4291: if (&update_parameter()) {
1.588 raeburn 4292: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 4293: return $errtext if ($fatal);
4294: }
4295:
4296: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
4297: # change order
4298: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
4299: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
4300:
4301: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
4302: return $errtext if ($fatal);
4303: }
1.364 bisitz 4304:
1.329 droeschl 4305: if ($env{'form.pastemarked'}) {
1.491 raeburn 4306: my %paste_errors;
1.533 raeburn 4307: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 4308: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
4309: \%paste_errors);
1.541 raeburn 4310: if (ref($pastemsgarray) eq 'ARRAY') {
4311: if (@{$pastemsgarray} > 0) {
4312: $r->print('<p class="LC_info">'.
4313: join('<br />',@{$pastemsgarray}).
1.533 raeburn 4314: '</p>');
4315: }
1.541 raeburn 4316: }
4317: if ($lockerror) {
4318: $r->print('<p class="LC_error">'.
4319: $lockerror.
4320: '</p>');
4321: }
4322: if ($save_error ne '') {
4323: return $save_error;
4324: }
4325: if ($paste_res) {
4326: my %errortext = &Apache::lonlocal::texthash (
4327: fail => 'Storage of folder contents failed',
4328: failread => 'Reading folder contents failed',
4329: failstore => 'Storage of folder contents failed',
4330: );
4331: if ($errortext{$paste_res}) {
4332: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 4333: }
1.329 droeschl 4334: }
1.491 raeburn 4335: if (keys(%paste_errors) > 0) {
1.538 raeburn 4336: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 4337: &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".
4338: '<ul>'."\n");
4339: foreach my $key (sort(keys(%paste_errors))) {
4340: $r->print('<li>'.$key.'</li>'."\n");
4341: }
4342: $r->print('</ul></p>'."\n");
4343: }
1.538 raeburn 4344: } elsif ($env{'form.clearmarked'}) {
4345: my $output = &do_buffer_empty();
4346: if ($output) {
4347: $r->print('<p class="LC_info">'.$output.'</p>');
4348: }
4349: }
1.329 droeschl 4350:
4351: $r->print($upload_output);
4352:
1.538 raeburn 4353: # Rename, cut, copy or remove a single resource
1.602 raeburn 4354: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 4355: my $contentchg;
1.633 raeburn 4356: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 4357: $contentchg = 1;
4358: }
4359: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 4360: return $errtext if ($fatal);
4361: }
1.538 raeburn 4362:
4363: # Cut, copy and/or remove multiple resources
4364: if ($env{'form.multichange'}) {
4365: my %allchecked = (
4366: cut => {},
4367: remove => {},
4368: );
4369: my $needsupdate;
4370: foreach my $which (keys(%allchecked)) {
4371: $env{'form.multi'.$which} =~ s/,$//;
4372: if ($env{'form.multi'.$which}) {
4373: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
4374: if (ref($allchecked{$which}) eq 'HASH') {
4375: $needsupdate += scalar(keys(%{$allchecked{$which}}));
4376: }
4377: }
4378: }
4379: if ($needsupdate) {
4380: my $haschanges = 0;
4381: my %curr_groups = &Apache::longroup::coursegroups();
4382: my $total = scalar(@LONCAPA::map::order) - 1;
4383: for (my $i=$total; $i>=0; $i--) {
4384: my $res = $LONCAPA::map::order[$i];
4385: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4386: $name=&LONCAPA::map::qtescape($name);
4387: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 4388: next unless $url;
1.538 raeburn 4389: my %denied =
4390: &action_restrictions($coursenum,$coursedom,$url,
4391: $env{'form.folderpath'},\%curr_groups);
4392: foreach my $which (keys(%allchecked)) {
4393: next if ($denied{$which});
4394: next unless ($allchecked{$which}{$res});
4395: if ($which eq 'remove') {
4396: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4397: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4398: &Apache::lonnet::removeuploadedurl($url);
4399: } else {
4400: &LONCAPA::map::makezombie($res);
4401: }
4402: splice(@LONCAPA::map::order,$i,1);
4403: $haschanges ++;
4404: } elsif ($which eq 'cut') {
4405: &LONCAPA::map::makezombie($res);
4406: splice(@LONCAPA::map::order,$i,1);
4407: $haschanges ++;
4408: }
4409: }
4410: }
4411: if ($haschanges) {
4412: ($errtext,$fatal) =
4413: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
4414: return $errtext if ($fatal);
4415: }
4416: }
4417: }
4418:
1.329 droeschl 4419: # Group import/search
4420: if ($env{'form.importdetail'}) {
4421: my @imports;
4422: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
4423: if (defined($item)) {
4424: my ($name,$url,$residx)=
1.533 raeburn 4425: map { &unescape($_); } split(/\=/,$item);
4426: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
4427: my ($suffix,$errortxt,$locknotfreed) =
4428: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 4429: if ($locknotfreed) {
4430: $r->print($locknotfreed);
4431: }
4432: if ($suffix) {
4433: $url =~ s/_new\./_$suffix./;
4434: } else {
4435: return $errortxt;
4436: }
1.533 raeburn 4437: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
4438: my $type = $1;
4439: my ($suffix,$errortxt,$locknotfreed) =
4440: &new_timebased_suffix($coursedom,$coursenum,$type);
4441: if ($locknotfreed) {
4442: $r->print($locknotfreed);
4443: }
4444: if ($suffix) {
4445: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
4446: } else {
4447: return $errortxt;
4448: }
1.626 raeburn 4449: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 4450: my ($suffix,$errortxt,$locknotfreed) =
4451: &new_timebased_suffix($coursedom,$coursenum,'exttool');
4452: if ($locknotfreed) {
4453: $r->print($locknotfreed);
4454: }
4455: if ($suffix) {
4456: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
4457: } else {
4458: return $errortxt;
4459: }
1.534 raeburn 4460: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
4461: if ($supplementalflag) {
4462: next unless ($1 eq 'supplemental');
4463: if ($folder eq 'supplemental') {
4464: next unless ($2 eq 'default');
4465: } else {
4466: next unless ($folder eq 'supplemental_'.$2);
4467: }
4468: } else {
4469: next unless ($1 eq 'docs');
4470: if ($folder eq 'default') {
4471: next unless ($2 eq 'default');
4472: } else {
4473: next unless ($folder eq 'default_'.$2);
4474: }
4475: }
1.504 raeburn 4476: }
1.329 droeschl 4477: push(@imports, [$name, $url, $residx]);
4478: }
4479: }
1.530 raeburn 4480: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 4481: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 4482: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 4483: return $errtext if ($fatal);
1.529 raeburn 4484: if ($fixuperrors) {
4485: $r->print($fixuperrors);
4486: }
1.329 droeschl 4487: }
4488: # Loading a complete map
4489: if ($env{'form.loadmap'}) {
4490: if ($env{'form.importmap'}=~/\w/) {
4491: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
4492: my ($title,$url,$ext,$type)=split(/\:/,$res);
4493: my $idx=&LONCAPA::map::getresidx($url);
4494: $LONCAPA::map::resources[$idx]=$res;
4495: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
4496: }
4497: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 4498: $folder.'.'.$container,1);
1.329 droeschl 4499: return $errtext if ($fatal);
4500: } else {
4501: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 4502:
1.329 droeschl 4503: }
4504: }
4505: &log_differences($plain);
4506: }
4507: # ---------------------------------------------------------------- End commands
4508: # ---------------------------------------------------------------- Print screen
4509: my $idx=0;
4510: my $shown=0;
4511: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 4512: $r->print('<div class="LC_Box">'.
1.432 raeburn 4513: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
4514: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
4515: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
4516: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
4517: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 4518: '</ol>');
1.381 bisitz 4519: if ($randompick>=0) {
4520: $r->print('<p class="LC_warning">'
4521: .&mt('Caution: this folder is set to randomly pick a subset'
4522: .' of resources. Adding or removing resources from this'
4523: .' folder will change the set of resources that the'
4524: .' students see, resulting in spurious or missing credit'
4525: .' for completed problems, not limited to ones you'
4526: .' modify. Do not modify the contents of this folder if'
4527: .' it is in active student use.')
4528: .'</p>'
4529: );
4530: }
4531: if ($is_random_order) {
4532: $r->print('<p class="LC_warning">'
4533: .&mt('Caution: this folder is set to randomly order its'
4534: .' contents. Adding or removing resources from this folder'
4535: .' will change the order of resources shown.')
4536: .'</p>'
4537: );
4538: }
4539: $r->print('</div>');
1.364 bisitz 4540: }
1.381 bisitz 4541:
1.685 raeburn 4542: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 4543: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 4544: if (ref($supplemental) eq 'HASH') {
4545: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
4546: (ref($supplemental->{'ids'}) eq 'HASH')) {
4547: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
4548: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
4549: if ($supplemental->{'hidden'}->{$mapnum}) {
4550: $ishidden = 1;
4551: }
4552: }
4553: }
4554: }
4555: }
4556:
1.538 raeburn 4557: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
4558: %filters = (
1.543 raeburn 4559: canremove => [],
4560: cancut => [],
4561: cancopy => [],
4562: hiddenresource => [],
4563: encrypturl => [],
4564: randomorder => [],
4565: randompick => [],
1.538 raeburn 4566: );
4567: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 4568: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 4569: foreach my $res (@LONCAPA::map::order) {
4570: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
4571: $name=&LONCAPA::map::qtescape($name);
4572: $url=&LONCAPA::map::qtescape($url);
4573: unless ($name) { $name=(split(/\//,$url))[-1]; }
4574: unless ($name) { $idx++; next; }
1.537 raeburn 4575: push(@allidx,$res);
4576: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
4577: push(@allmapidx,$res);
4578: }
1.617 raeburn 4579:
1.682 raeburn 4580: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 4581: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
4582: $idx++;
4583: next;
4584: }
1.682 raeburn 4585: }
1.381 bisitz 4586: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 4587: $coursenum,$coursedom,$crstype,
1.538 raeburn 4588: $pathitem,$supplementalflag,$container,
1.620 raeburn 4589: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 4590: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 4591: $idx++;
4592: $shown++;
1.329 droeschl 4593: }
1.424 onken 4594: &Apache::loncommon::end_data_table_count();
1.510 raeburn 4595:
1.538 raeburn 4596: my $need_save;
1.611 raeburn 4597: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 4598: my $toolslink;
1.682 raeburn 4599: if ($allowed || $canedit) {
4600: my $helpitem = 'Navigation_Screen';
4601: if (!$allowed) {
4602: $helpitem = 'Supplemental_Navigation';
4603: }
1.544 raeburn 4604: $toolslink = '<table><tr><td>'
1.520 raeburn 4605: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 4606: $helpitem,undef,'RAT')
1.520 raeburn 4607: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
4608: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 4609: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 4610: .'id="LC_content_toolbar_edittoplevel" '
4611: .'class="LC_toolbarItem" '
4612: .'title="'.&mt('Supplemental Content Editor').'">'
4613: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 4614: }
1.510 raeburn 4615: if ($shown) {
4616: if ($allowed) {
4617: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
4618: .&Apache::loncommon::start_data_table(undef,'contentlist')
4619: .&Apache::loncommon::start_data_table_header_row()
4620: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 4621: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 4622: .'<th>'.&mt('Document').'</th>'
4623: .'<th colspan="2">'.&mt('Settings').'</th>'
4624: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 4625: if ($folder !~ /^supplemental/) {
1.538 raeburn 4626: $lists{'canhide'} = join(',',@allidx);
4627: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 4628: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
4629: 'randomorder','randompick');
4630: foreach my $item (@possfilters) {
1.538 raeburn 4631: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 4632: if (@{$filters{$item}} > 0) {
4633: $lists{$item} = join(',',@{$filters{$item}});
4634: }
1.538 raeburn 4635: }
4636: }
1.537 raeburn 4637: if (@allidx > 0) {
4638: my $path;
4639: if ($env{'form.folderpath'}) {
1.630 raeburn 4640: $path =
1.537 raeburn 4641: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4642: }
1.538 raeburn 4643: if (@allidx > 1) {
1.630 raeburn 4644: $to_show .=
1.538 raeburn 4645: &Apache::loncommon::continue_data_table_row().
4646: '<td colspan="2"> </td>'.
4647: '<td>'.
1.611 raeburn 4648: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 4649: '</td>'.
1.633 raeburn 4650: '<td colspan="3"> </td>'.
4651: '<td colspan="2">'.
1.611 raeburn 4652: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 4653: '</td>'.
4654: &Apache::loncommon::end_data_table_row();
4655: $need_save = 1;
4656: }
1.537 raeburn 4657: }
4658: }
4659: $to_show .= $output.' '
1.510 raeburn 4660: .&Apache::loncommon::end_data_table()
4661: .'<br style="line-height:2px;" />'
4662: .&Apache::loncommon::end_scrollbox();
4663: } else {
1.520 raeburn 4664: $to_show .= $toolslink
1.510 raeburn 4665: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4666: .$output.' '
4667: .&Apache::loncommon::end_data_table();
1.393 raeburn 4668: }
1.510 raeburn 4669: } else {
1.520 raeburn 4670: if (!$allowed) {
4671: $to_show .= $toolslink;
4672: }
1.615 raeburn 4673: my $noresmsg;
4674: if ($allowed && $hiddentop && !$supplementalflag) {
4675: $noresmsg = &mt('Main Content Hidden');
4676: } else {
4677: $noresmsg = &mt('Currently empty');
4678: }
1.510 raeburn 4679: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
4680: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 4681: .$noresmsg
1.510 raeburn 4682: .'</div>'
4683: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 4684: }
4685: } else {
1.510 raeburn 4686: if ($shown) {
4687: $to_show = '<div>'
4688: .&Apache::loncommon::start_data_table('LC_tableOfContent')
4689: .$output
4690: .&Apache::loncommon::end_data_table()
4691: .'</div>';
4692: } else {
4693: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 4694: .&mt('Currently empty')
1.510 raeburn 4695: .'</div>'
4696: }
1.458 raeburn 4697: }
4698: my $tid = 1;
4699: if ($supplementalflag) {
4700: $tid = 2;
1.329 droeschl 4701: }
4702: if ($allowed) {
1.484 raeburn 4703: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 4704: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 4705: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
4706: if ($canedit) {
4707: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
4708: }
1.460 raeburn 4709: } else {
4710: $r->print($to_show);
1.329 droeschl 4711: }
4712: return;
4713: }
4714:
1.538 raeburn 4715: sub multiple_check_form {
1.611 raeburn 4716: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 4717: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 4718: my $disabled;
4719: unless ($canedit) {
1.700 raeburn 4720: $disabled = ' disabled="disabled"';
1.611 raeburn 4721: }
1.538 raeburn 4722: my $output =
4723: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
4724: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
4725: '<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>'.
4726: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
4727: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
4728: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
4729: if ($caller eq 'settings') {
4730: $output .=
4731: '<table><tr>'.
4732: '<td class="LC_docs_entry_parameter">'.
4733: '<span class="LC_nobreak"><label>'.
1.611 raeburn 4734: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 4735: '</label></span></td>'.
4736: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 4737: '<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 4738: '</span></td>'.
4739: '</tr>'."\n".
4740: '<tr>'.
4741: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 4742: '<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 4743: '</label></span>'.
4744: '</td></tr></table>'."\n";
4745: } else {
4746: $output .=
4747: '<table><tr>'.
4748: '<td class="LC_docs_entry_parameter">'.
4749: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 4750: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 4751: '</label></span></td>'.
4752: '<td class="LC_docs_entry_parameter">'.
4753: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 4754: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 4755: '</label></span></td>'."\n".
4756: '<td class="LC_docs_entry_parameter">'.
4757: '<span class="LC_nobreak LC_docs_copy">'.
1.700 raeburn 4758: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538 raeburn 4759: '</label></span></td>'.
4760: '</tr></table>'."\n";
4761: }
4762: $output .=
4763: '</fieldset>'.
4764: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
4765: if ($caller eq 'settings') {
4766: $output .=
1.543 raeburn 4767: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
4768: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
4769: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
4770: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
4771: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 4772: } elsif ($caller eq 'actions') {
4773: $output .=
4774: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
4775: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
4776: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
4777: }
4778: $output .=
4779: '</form>'.
4780: '</div>';
4781: return $output;
4782: }
4783:
1.329 droeschl 4784: sub process_file_upload {
1.552 raeburn 4785: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 4786: # upload a file, if present
1.552 raeburn 4787: my $filesize = length($env{'form.uploaddoc'});
4788: if (!$filesize) {
4789: $$upload_output = '<div class="LC_error">'.
4790: &mt('Unable to upload [_1]. (size = [_2] bytes)',
4791: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
4792: $filesize).'<br />'.
4793: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
4794: '</div>';
4795: return;
4796: }
4797: my $quotatype = 'unofficial';
4798: if ($crstype eq 'Community') {
1.601 raeburn 4799: $quotatype = 'community';
4800: } elsif ($crstype eq 'Placement') {
4801: $quotatype = 'placement';
1.580 raeburn 4802: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 4803: $quotatype = 'official';
1.573 raeburn 4804: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
4805: $quotatype = 'textbook';
1.552 raeburn 4806: }
4807: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
4808: $filesize = int($filesize/1000); #expressed in kb
4809: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 4810: $env{'form.uploaddoc.filename'},$filesize,
4811: 'upload',$quotatype);
1.552 raeburn 4812: return if ($$upload_output);
4813: }
1.440 raeburn 4814: my ($parseaction,$showupload,$nextphase,$mimetype);
4815: if ($env{'form.parserflag'}) {
1.329 droeschl 4816: $parseaction = 'parse';
4817: }
4818: my $folder=$env{'form.folder'};
4819: if ($folder eq '') {
4820: $folder='default';
4821: }
4822: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
4823: my $errtext='';
4824: my $fatal=0;
4825: my $container='sequence';
1.519 raeburn 4826: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 4827: $container='page';
4828: }
4829: ($errtext,$fatal)=
1.534 raeburn 4830: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 4831: if ($#LONCAPA::map::order<1) {
4832: $LONCAPA::map::order[0]=1;
4833: $LONCAPA::map::resources[1]='';
4834: }
4835: my $destination = 'docs/';
4836: if ($folder =~ /^supplemental/) {
4837: $destination = 'supplemental/';
4838: }
4839: if (($folder eq 'default') || ($folder eq 'supplemental')) {
4840: $destination .= 'default/';
4841: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
4842: $destination .= $2.'/';
4843: }
1.534 raeburn 4844: if ($fatal) {
4845: $$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>';
4846: return;
4847: }
1.440 raeburn 4848: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 4849: my $newidx=&LONCAPA::map::getresidx();
4850: $destination .= $newidx;
1.439 raeburn 4851: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 4852: $parseaction,$allfiles,
1.440 raeburn 4853: $codebase,undef,undef,undef,undef,
4854: undef,undef,\$mimetype);
4855: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
4856: my $stored = $1;
4857: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
4858: $stored.'</span>').'</p>';
4859: } else {
4860: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
4861:
1.457 raeburn 4862: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 4863: return;
4864: }
1.329 droeschl 4865: my $ext='false';
4866: if ($url=~m{^http://}) { $ext='true'; }
4867: $url = &LONCAPA::map::qtunescape($url);
4868: my $comment=$env{'form.comment'};
4869: $comment = &LONCAPA::map::qtunescape($comment);
4870: if ($folder=~/^supplemental/) {
4871: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
4872: $env{'user.domain'}.'___&&&___'.$comment;
4873: }
4874:
4875: $LONCAPA::map::resources[$newidx]=
4876: $comment.':'.$url.':'.$ext.':normal:res';
4877: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
4878: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 4879: $folder.'.'.$container,1);
1.329 droeschl 4880: if ($fatal) {
1.457 raeburn 4881: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 4882: return;
1.329 droeschl 4883: } else {
1.440 raeburn 4884: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
4885: $$upload_output = $showupload;
1.384 raeburn 4886: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 4887: if ($total_embedded > 0) {
1.440 raeburn 4888: my $uploadphase = 'upload_embedded';
4889: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
4890: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 4891: my ($embedded,$num) =
1.440 raeburn 4892: &Apache::loncommon::ask_for_embedded_content(
4893: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
4894: if ($embedded) {
4895: if ($num) {
4896: $$upload_output .=
4897: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
4898: $nextphase = $uploadphase;
4899: } else {
4900: $$upload_output .= $embedded;
4901: }
4902: } else {
4903: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
4904: }
1.329 droeschl 4905: } else {
1.440 raeburn 4906: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 4907: }
1.457 raeburn 4908: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 4909: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
4910: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 4911: $nextphase = 'decompress_uploaded';
4912: my $position = scalar(@LONCAPA::map::order)-1;
4913: my $noextract = &return_to_editor();
4914: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
4915: my %archiveitems = (
4916: folderpath => $env{'form.folderpath'},
4917: cmd => $nextphase,
4918: newidx => $newidx,
4919: position => $position,
4920: phase => $nextphase,
1.477 raeburn 4921: comment => $comment,
1.480 raeburn 4922: );
4923: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
4924: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 4925: $$upload_output = $showupload.
4926: &Apache::loncommon::decompress_form($mimetype,
4927: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 4928: \%archiveitems,\@current);
1.329 droeschl 4929: }
4930: }
4931: }
1.440 raeburn 4932: return $nextphase;
1.329 droeschl 4933: }
4934:
1.480 raeburn 4935: sub get_dir_list {
4936: my ($url,$coursenum,$coursedom,$newidx) = @_;
4937: my ($destination,$dir_root) = &embedded_destination();
4938: my ($dirlistref,$listerror) =
4939: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
4940: my @dir_lines;
4941: my $dirptr=16384;
4942: if (ref($dirlistref) eq 'ARRAY') {
4943: foreach my $dir_line (sort
4944: {
4945: my ($afile)=split('&',$a,2);
4946: my ($bfile)=split('&',$b,2);
4947: return (lc($afile) cmp lc($bfile));
4948: } (@{$dirlistref})) {
4949: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
4950: $filename =~ s/\s+$//;
4951: next if ($filename =~ /^\.\.?$/);
4952: my $isdir = 0;
4953: if ($dirptr&$testdir) {
4954: $isdir = 1;
4955: }
4956: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
4957: }
4958: }
4959: return @dir_lines;
4960: }
4961:
1.329 droeschl 4962: sub is_supplemental_title {
4963: my ($title) = @_;
4964: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
4965: }
4966:
4967: # --------------------------------------------------------------- An entry line
4968:
4969: sub entryline {
1.501 raeburn 4970: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 4971: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 4972: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 4973: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 4974: if (&is_supplemental_title($title)) {
1.488 raeburn 4975: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 4976: $encodedtitle=$title;
1.329 droeschl 4977: } else {
4978: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 4979: $encodedtitle=$title;
1.329 droeschl 4980: $renametitle=$title;
4981: $foldertitle=$title;
4982: }
4983:
1.611 raeburn 4984: my ($disabled,$readonly,$js_lt);
4985: unless ($canedit) {
4986: $disabled = 'disabled="disabled"';
4987: $readonly = 1;
4988: }
4989:
1.329 droeschl 4990: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 4991:
1.329 droeschl 4992: $renametitle=~s/\\/\\\\/g;
4993: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 4994: $renametitle=~s/"/%22/g;
1.581 raeburn 4995: $renametitle=~s/ /%20/g;
4996: $oldtitle = $renametitle;
1.576 raeburn 4997: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 4998: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 4999: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 5000: # Edit commands
1.679 raeburn 5001: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 5002: if ($env{'form.folderpath'}) {
5003: $esc_path=&escape($env{'form.folderpath'});
5004: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5005: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
5006: }
1.505 raeburn 5007: my $isexternal;
1.510 raeburn 5008: if ($residx) {
1.501 raeburn 5009: my $currurl = $url;
5010: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 5011: if ($currurl =~ m{^/adm/wrapper/ext/}) {
5012: $isexternal = 1;
5013: }
1.510 raeburn 5014: if (!$supplementalflag) {
5015: my $path = 'uploaded/'.
5016: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
5017: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
5018: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
5019: $residx,
5020: &Apache::lonnet::declutter($currurl));
5021: }
1.501 raeburn 5022: }
1.538 raeburn 5023: my ($renamelink,%lt,$ishash);
5024: if (ref($filtersref) eq 'HASH') {
5025: $ishash = 1;
5026: }
5027:
1.329 droeschl 5028: if ($allowed) {
1.538 raeburn 5029: $form_start = '
5030: <form action="/adm/coursedocs" method="post">
5031: ';
5032: $form_common=(<<END);
5033: <input type="hidden" name="folderpath" value="$path" />
5034: <input type="hidden" name="symb" value="$symb" />
5035: END
5036: $form_param=(<<END);
5037: <input type="hidden" name="setparms" value="$orderidx" />
5038: <input type="hidden" name="changeparms" value="0" />
5039: END
5040: $form_end = '</form>';
5041:
1.329 droeschl 5042: my $incindex=$index+1;
5043: my $selectbox='';
1.471 raeburn 5044: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 5045: ((split(/\:/,
1.344 bisitz 5046: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
5047: ne '') &&
1.329 droeschl 5048: ((split(/\:/,
1.344 bisitz 5049: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 5050: ne '')) {
5051: $selectbox=
5052: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 5053: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 5054: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
5055: if ($i==$incindex) {
1.358 bisitz 5056: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 5057: } else {
5058: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
5059: }
5060: }
5061: $selectbox.='</select>';
5062: }
1.501 raeburn 5063: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 5064: 'up' => 'Move Up',
5065: 'dw' => 'Move Down',
5066: 'rm' => 'Remove',
5067: 'ct' => 'Cut',
5068: 'rn' => 'Rename',
1.501 raeburn 5069: 'cp' => 'Copy',
1.633 raeburn 5070: 'da' => 'Unset alias',
5071: 'sa' => 'Set alias',
1.501 raeburn 5072: 'ex' => 'External Resource',
1.598 raeburn 5073: 'et' => 'External Tool',
1.501 raeburn 5074: 'ed' => 'Edit',
5075: 'pr' => 'Preview',
5076: 'sv' => 'Save',
5077: 'ul' => 'URL',
1.611 raeburn 5078: 'ti' => 'Title',
1.618 raeburn 5079: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 5080: );
1.538 raeburn 5081: my %denied = &action_restrictions($coursenum,$coursedom,$url,
5082: $env{'form.folderpath'},
5083: $currgroups);
1.517 raeburn 5084: my ($copylink,$cutlink,$removelink);
1.329 droeschl 5085: my $skip_confirm = 0;
1.603 raeburn 5086: my $confirm_removal = 0;
1.329 droeschl 5087: if ( $folder =~ /^supplemental/
5088: || ($url =~ m{( /smppg$
5089: |/syllabus$
5090: |/aboutme$
5091: |/navmaps$
5092: |/bulletinboard$
1.626 raeburn 5093: |/ext\.tool$
1.505 raeburn 5094: |\.html$)}x)
5095: || $isexternal) {
1.329 droeschl 5096: $skip_confirm = 1;
5097: }
1.603 raeburn 5098: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
5099: ($url!~/$LONCAPA::assess_page_seq_re/)) {
5100: $confirm_removal = 1;
5101: }
1.633 raeburn 5102: if ($url =~ /$LONCAPA::assess_re/) {
5103: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
5104: }
1.329 droeschl 5105:
1.538 raeburn 5106: if ($denied{'copy'}) {
1.543 raeburn 5107: $copylink=(<<ENDCOPY)
1.507 raeburn 5108: <span style="visibility: hidden;">$lt{'cp'}</span>
5109: ENDCOPY
5110: } else {
1.538 raeburn 5111: my $formname = 'edit_copy_'.$orderidx;
5112: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5113: $copylink=(<<ENDCOPY);
1.538 raeburn 5114: <form name="$formname" method="post" action="/adm/coursedocs">
5115: $form_common
1.611 raeburn 5116: <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 5117: $form_end
1.329 droeschl 5118: ENDCOPY
1.538 raeburn 5119: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
5120: push(@{$filtersref->{'cancopy'}},$orderidx);
5121: }
1.329 droeschl 5122: }
1.538 raeburn 5123: if ($denied{'cut'}) {
1.507 raeburn 5124: $cutlink=(<<ENDCUT);
5125: <span style="visibility: hidden;">$lt{'ct'}</span>
5126: ENDCUT
5127: } else {
1.538 raeburn 5128: my $formname = 'edit_cut_'.$orderidx;
5129: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 5130: $cutlink=(<<ENDCUT);
1.538 raeburn 5131: <form name="$formname" method="post" action="/adm/coursedocs">
5132: $form_common
1.542 raeburn 5133: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 5134: <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 5135: $form_end
1.329 droeschl 5136: ENDCUT
1.538 raeburn 5137: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
5138: push(@{$filtersref->{'cancut'}},$orderidx);
5139: }
1.329 droeschl 5140: }
1.538 raeburn 5141: if ($denied{'remove'}) {
1.507 raeburn 5142: $removelink=(<<ENDREM);
5143: <span style="visibility: hidden;">$lt{'rm'}</a>
5144: ENDREM
5145: } else {
1.538 raeburn 5146: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 5147: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 5148: $removelink=(<<ENDREM);
1.538 raeburn 5149: <form name="$formname" method="post" action="/adm/coursedocs">
5150: $form_common
1.542 raeburn 5151: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 5152: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 5153: <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 5154: $form_end
1.497 raeburn 5155: ENDREM
1.538 raeburn 5156: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
5157: push(@{$filtersref->{'canremove'}},$orderidx);
5158: }
1.497 raeburn 5159: }
1.551 raeburn 5160: $renamelink=(<<ENDREN);
1.581 raeburn 5161: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 5162: ENDREN
1.611 raeburn 5163: my ($uplink,$downlink);
5164: if ($canedit) {
5165: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
5166: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
5167: } else {
5168: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
5169: $downlink = $uplink;
5170: }
1.329 droeschl 5171: $line.=(<<END);
5172: <td>
1.379 bisitz 5173: <div class="LC_docs_entry_move">
1.611 raeburn 5174: <a href="$uplink">
1.501 raeburn 5175: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 5176: </a>
5177: </div>
5178: <div class="LC_docs_entry_move">
1.611 raeburn 5179: <a href="$downlink">
1.501 raeburn 5180: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 5181: </a>
5182: </div>
1.329 droeschl 5183: </td>
5184: <td>
5185: $form_start
1.538 raeburn 5186: $form_param
1.478 raeburn 5187: $form_common
1.329 droeschl 5188: $selectbox
5189: $form_end
5190: </td>
1.540 raeburn 5191: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 5192: $removelink
1.329 droeschl 5193: $cutlink
5194: $copylink
5195: </td>
5196: END
5197: }
5198: # Figure out what kind of a resource this is
5199: my ($extension)=($url=~/\.(\w+)$/);
5200: my $uploaded=($url=~/^\/*uploaded\//);
5201: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 5202: my $isfolder;
5203: my $ispage;
5204: my $containerarg;
1.615 raeburn 5205: my $folderurl;
1.685 raeburn 5206: my $plainurl;
1.329 droeschl 5207: if ($uploaded) {
1.472 raeburn 5208: if (($extension eq 'sequence') || ($extension eq 'page')) {
5209: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 5210: $containerarg = $1;
1.472 raeburn 5211: if ($extension eq 'sequence') {
5212: $icon=$iconpath.'navmap.folder.closed.gif';
5213: $isfolder=1;
5214: } else {
5215: $icon=$iconpath.'page.gif';
5216: $ispage=1;
5217: }
1.615 raeburn 5218: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 5219: if ($allowed) {
5220: $url='/adm/coursedocs?';
5221: } else {
5222: $url='/adm/supplemental?';
5223: }
1.329 droeschl 5224: } else {
1.685 raeburn 5225: $plainurl = $url;
1.329 droeschl 5226: }
5227: }
1.364 bisitz 5228:
1.621 raeburn 5229: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 5230: my $orig_url = $url;
1.340 raeburn 5231: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 5232: if ($container eq 'page') {
5233: $url=~s{^http(|s)(:|:)//}{/ext/};
5234: } else {
5235: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
5236: }
1.501 raeburn 5237: if (!$supplementalflag && $residx && $symb) {
5238: if ((!$isfolder) && (!$ispage)) {
5239: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 5240: if (($url =~ m{^ext/}) && ($container eq 'page')) {
5241: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
5242: } else {
5243: $url=&Apache::lonnet::clutter($url);
5244: }
1.501 raeburn 5245: if ($url=~/^\/*uploaded\//) {
5246: $url=~/\.(\w+)$/;
5247: my $embstyle=&Apache::loncommon::fileembstyle($1);
5248: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
5249: $url='/adm/wrapper'.$url;
5250: } elsif ($embstyle eq 'ssi') {
5251: #do nothing with these
5252: } elsif ($url!~/\.(sequence|page)$/) {
5253: $url='/adm/coursedocs/showdoc'.$url;
5254: }
1.623 raeburn 5255: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
5256: my $wrapped = $1;
5257: my $exturl = $2;
1.668 raeburn 5258: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 5259: $url='/adm/wrapper'.$url;
5260: }
5261: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
5262: $nomodal = 1;
5263: }
1.626 raeburn 5264: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5265: $url='/adm/wrapper'.$url;
1.621 raeburn 5266: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
5267: if (($ENV{'SERVER_PORT'} == 443) &&
5268: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5269: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5270: $url .= '?usehttp=1';
5271: }
1.621 raeburn 5272: $nomodal = 1;
5273: }
1.598 raeburn 5274: }
1.696 raeburn 5275: my $checkencrypt;
1.680 raeburn 5276: if (!$env{'request.role.adv'}) {
1.615 raeburn 5277: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 5278: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 5279: $checkencrypt = 1;
1.620 raeburn 5280: } elsif (ref($navmapref)) {
1.615 raeburn 5281: unless (ref($$navmapref)) {
5282: $$navmapref = Apache::lonnavmaps::navmap->new();
5283: }
5284: if (ref($$navmapref)) {
5285: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 5286: $checkencrypt = 1;
1.615 raeburn 5287: }
5288: }
5289: }
1.680 raeburn 5290: }
5291: if ($checkencrypt) {
5292: my $currenc = $env{'request.enc'};
5293: $env{'request.enc'} = 1;
5294: $shownsymb = &Apache::lonenc::encrypted($symb);
1.696 raeburn 5295: my $shownurl = &Apache::lonenc::encrypted($url);
1.680 raeburn 5296: if (&Apache::lonnet::symbverify($symb,$url)) {
5297: $url = $shownurl;
5298: } else {
5299: $url = '';
5300: }
5301: $env{'request.enc'} = $currenc;
5302: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
5303: $shownsymb = $symb;
5304: if ($isexternal) {
5305: $url =~ s/\#[^#]+$//;
5306: if ($container eq 'page') {
5307: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 5308: }
1.612 raeburn 5309: }
1.696 raeburn 5310: } else {
5311: $url = '';
1.680 raeburn 5312: }
5313: unless ($env{'request.role.adv'}) {
5314: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5315: $url = '';
5316: }
5317: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
5318: $url = '';
5319: $hiddenres = 1;
5320: }
5321: }
1.696 raeburn 5322: if (($url ne '') && ($shownsymb ne '')) {
5323: $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 5324: }
1.329 droeschl 5325: }
1.621 raeburn 5326: } elsif ($supplementalflag) {
1.610 raeburn 5327: if ($isexternal) {
5328: if ($url =~ /^([^#]+)#([^#]+)$/) {
5329: $url = $1;
5330: $anchor = $2;
1.623 raeburn 5331: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 5332: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5333: if ($hostname ne '') {
5334: $url = 'http://'.$hostname.$url;
5335: }
5336: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 5337: }
5338: $nomodal = 1;
5339: }
1.610 raeburn 5340: }
1.621 raeburn 5341: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
5342: if (($ENV{'SERVER_PORT'} == 443) &&
5343: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 5344: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 5345: if ($hostname ne '') {
5346: $url = 'http://'.$hostname.$url;
5347: }
5348: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 5349: }
1.621 raeburn 5350: $nomodal = 1;
5351: }
1.705 raeburn 5352: } elsif (($uploaded) && ($url ne '/adm/supplemental?') && ($url ne '/adm/coursedocs?')) {
1.686 raeburn 5353: my $embstyle=&Apache::loncommon::fileembstyle($extension);
5354: unless ($embstyle eq 'ssi') {
5355: if (($embstyle eq 'img')
5356: || ($embstyle eq 'emb')
5357: || ($embstyle eq 'wrp')) {
5358: $url='/adm/wrapper'.$url;
5359: } elsif ($url !~ /\.(sequence|page)$/) {
5360: $url='/adm/coursedocs/showdoc'.$url;
5361: }
5362: }
1.610 raeburn 5363: }
1.685 raeburn 5364: unless ($allowed && $env{'request.role.adv'}) {
5365: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5366: $hiddenres = 1;
5367: }
5368: }
1.329 droeschl 5369: }
1.615 raeburn 5370: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 5371: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 5372: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 5373: my $foldername=&escape($foldertitle);
5374: my $folderpath=$env{'form.folderpath'};
5375: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 5376: if (!$allowed && $supplementalflag) {
1.519 raeburn 5377: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 5378: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 5379: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5380: $hiddenfolder = 1;
1.682 raeburn 5381: }
1.510 raeburn 5382: } else {
1.617 raeburn 5383: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
5384: 'parameter_randompick'))[0];
5385: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
5386: 'parameter_randomorder'))[0]=~/^yes$/i);
5387: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
5388: 'parameter_hiddenresource'))[0]=~/^yes$/i);
5389: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
5390: 'parameter_encrypturl'))[0]=~/^yes$/i);
5391: unless ($hiddenmap) {
1.620 raeburn 5392: if (ref($navmapref)) {
5393: unless (ref($$navmapref)) {
5394: $$navmapref = Apache::lonnavmaps::navmap->new();
5395: }
5396: if (ref($$navmapref)) {
5397: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5398: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
5399: unless (@resources) {
5400: $hiddenmap = 1;
5401: unless ($env{'request.role.adv'}) {
5402: $url = '';
5403: $hiddenfolder = 1;
5404: }
1.617 raeburn 5405: }
1.615 raeburn 5406: }
5407: }
5408: }
5409: }
1.617 raeburn 5410: unless ($encryptmap) {
1.620 raeburn 5411: if ((ref($navmapref)) && (ref($$navmapref))) {
5412: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
5413: $encryptmap = 1;
5414: }
1.617 raeburn 5415: }
5416: }
1.630 raeburn 5417:
1.617 raeburn 5418: # Append randompick number, hidden, and encrypted with ":" to foldername,
5419: # so it gets transferred between levels
5420: $folderpath.=$containerarg.'&'.$foldername.
5421: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 5422: unless ($url eq '') {
1.612 raeburn 5423: $url.='folderpath='.&escape($folderpath);
5424: }
1.510 raeburn 5425: my $rpckchk;
5426: if ($rpicknum) {
5427: $rpckchk = ' checked="checked"';
1.543 raeburn 5428: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
5429: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
5430: }
1.510 raeburn 5431: }
1.537 raeburn 5432: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 5433: $rand_pick_text =
1.478 raeburn 5434: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5435: $form_param."\n".
1.478 raeburn 5436: $form_common."\n".
1.611 raeburn 5437: '<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 5438: if ($rpicknum ne '') {
5439: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
5440: }
1.537 raeburn 5441: $rand_pick_text .= '</span></span>'.
5442: $form_end;
1.543 raeburn 5443: my $ro_set;
1.617 raeburn 5444: if ($randorder) {
1.543 raeburn 5445: $ro_set = 'checked="checked"';
5446: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
5447: push(@{$filtersref->{'randomorder'}},$orderidx);
5448: }
5449: }
1.564 raeburn 5450: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 5451: $rand_order_text =
1.537 raeburn 5452: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 5453: $form_param."\n".
1.537 raeburn 5454: $form_common."\n".
1.611 raeburn 5455: '<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 5456: $form_end;
1.510 raeburn 5457: }
1.705 raeburn 5458: } elsif ($supplementalflag) {
1.598 raeburn 5459: my $isexttool;
1.626 raeburn 5460: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5461: $url='/adm/wrapper'.$url;
5462: $isexttool = 1;
5463: }
1.510 raeburn 5464: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 5465: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 5466: if ($title) {
1.687 raeburn 5467: $url .= '&title='.$encodedtitle;
1.510 raeburn 5468: }
1.598 raeburn 5469: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 5470: $url .= '&idx='.$orderidx;
5471: }
1.610 raeburn 5472: if ($anchor ne '') {
5473: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5474: }
1.329 droeschl 5475: }
1.519 raeburn 5476: my ($tdalign,$tdwidth);
1.501 raeburn 5477: if ($allowed) {
1.630 raeburn 5478: my $fileloc =
1.501 raeburn 5479: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 5480: if ($isexternal) {
1.630 raeburn 5481: ($editlink,$extresform) =
1.611 raeburn 5482: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5483: undef,undef,undef,undef,undef,undef,
5484: undef,$disabled);
1.626 raeburn 5485: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 5486: ($editlink,$extresform) =
5487: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
5488: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 5489: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 5490: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 5491: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
5492: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 5493: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 5494: my $suppanchor;
5495: if ($supplementalflag) {
5496: $suppanchor = $anchor;
5497: }
1.630 raeburn 5498: my $jscall =
1.501 raeburn 5499: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
5500: $switchserver,
1.503 raeburn 5501: $forceedit,
1.679 raeburn 5502: undef,$symb,$shownsymb,
1.511 raeburn 5503: &escape($env{'form.folderpath'}),
1.622 raeburn 5504: $renametitle,$hostname,
5505: '','',1,$suppanchor);
1.501 raeburn 5506: if ($jscall) {
1.518 raeburn 5507: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
5508: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 5509: }
5510: }
5511: }
1.519 raeburn 5512: $tdalign = ' align="right" valign="top"';
5513: $tdwidth = ' width="80%"';
1.329 droeschl 5514: }
1.408 raeburn 5515: my $reinit;
5516: if ($crstype eq 'Community') {
5517: $reinit = &mt('(re-initialize community to access)');
5518: } else {
5519: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 5520: }
1.702 raeburn 5521: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
1.650 raeburn 5522: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 5523: $line.= '<br />';
5524: if ($curralias ne '') {
5525: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5526: $lt{'da'}.'</a></span>';
5527: } else {
5528: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
5529: $lt{'sa'}.'</a></span>';
5530: }
5531: }
1.701 raeburn 5532: $line.='</td><td><span class="LC_nobreak">';
1.685 raeburn 5533: my ($link,$nolink);
1.472 raeburn 5534: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5535: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
5536: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5537: $nolink = 1;
5538: }
5539: }
5540: if ($nolink) {
5541: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5542: } else {
5543: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
5544: }
1.469 www 5545: } elsif ($url) {
1.610 raeburn 5546: if ($anchor ne '') {
5547: if ($supplementalflag) {
5548: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
5549: } else {
5550: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
5551: }
5552: }
1.705 raeburn 5553: if (($nomodal) && ($hostname ne '')) {
1.622 raeburn 5554: $link = 'http://'.$hostname.$url;
5555: } else {
5556: $link = $url;
5557: }
1.705 raeburn 5558: my $inhibitmenu;
5559: if ((($supplementalflag) && ($allowed) && ($url =~ m{^/adm/wrapper/})) ||
5560: (($allowed) && (($url =~ m{^/adm/(viewclasslist|$match_domain/$match_username/aboutme)(\?|$)}) ||
5561: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus(\?|$)})))) {
5562: $inhibitmenu = 'only_body=1';
5563: } else {
5564: $inhibitmenu = 'inhibitmenu=yes';
5565: }
5566: $link = &js_escape($link.(($url=~/\?/)?'&':'?').$inhibitmenu.$anchor);
1.685 raeburn 5567: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
5568: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5569: $nolink = 1;
5570: }
5571: }
5572: if ($nolink) {
5573: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5574: } elsif ($nomodal) {
1.621 raeburn 5575: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5576: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
5577: } else {
5578: $line.=&Apache::loncommon::modal_link($link,
5579: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
5580: }
1.469 www 5581: } else {
5582: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
5583: }
1.519 raeburn 5584: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 5585: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 5586: if ($nolink) {
5587: $line.=$title;
5588: } else {
5589: $line.='<a href="'.$url.'">'.$title.'</a>';
5590: }
1.682 raeburn 5591: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
5592: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
5593: my $editurl = $url;
5594: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
5595: $line .= ' '.'<a href="'.$editurl.'">'.
5596: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
5597: '</a>';
5598: }
5599: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
5600: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
5601: }
1.469 www 5602: } elsif ($url) {
1.685 raeburn 5603: if ($nolink) {
5604: $line.=$title;
5605: } elsif ($nomodal) {
1.621 raeburn 5606: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
5607: $title.'</a>';
5608: } else {
5609: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
5610: }
1.617 raeburn 5611: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 5612: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 5613: } else {
5614: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
5615: }
1.633 raeburn 5616: if (($allowed) && ($curralias ne '')) {
5617: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
5618: } else {
5619: $line .= $extresform;
5620: }
5621: $line .= '</td>';
1.478 raeburn 5622: $rand_pick_text = ' ' if ($rand_pick_text eq '');
5623: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 5624: if ($uploaded && $url && !$isfolder && !$ispage) {
5625: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
5626: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
5627: }
5628: }
1.682 raeburn 5629: if ($allowed) {
5630: my %lt=&Apache::lonlocal::texthash(
5631: 'hd' => 'Hidden',
5632: 'ec' => 'URL hidden');
5633: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 5634: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
5635: $hidtext = ' checked="checked"';
1.694 raeburn 5636: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 5637: push(@{$filtersref->{'hiddenresource'}},$orderidx);
5638: }
5639: }
1.682 raeburn 5640: $formhidden = 'edit_hiddenresource_'.$orderidx;
5641: $line.=(<<ENDPARMS);
1.329 droeschl 5642: <td class="LC_docs_entry_parameter">
1.537 raeburn 5643: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 5644: $form_param
1.478 raeburn 5645: $form_common
1.611 raeburn 5646: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 5647: $form_end
1.682 raeburn 5648: ENDPARMS
5649: if ($folder =~/^supplemental/) {
5650: $line.= "\n <td>";
5651: } else {
5652: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
5653: $enctext = ' checked="checked"';
5654: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
5655: push(@{$filtersref->{'encrypturl'}},$orderidx);
5656: }
5657: }
5658: $formurlhidden = 'edit_encrypturl_'.$orderidx;
5659: $line.=(<<ENDPARMS);
1.458 raeburn 5660: <br />
1.537 raeburn 5661: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 5662: $form_param
1.478 raeburn 5663: $form_common
1.611 raeburn 5664: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 5665: $form_end
5666: </td>
1.478 raeburn 5667: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
5668: $rand_order_text</td>
1.329 droeschl 5669: ENDPARMS
1.682 raeburn 5670: }
1.329 droeschl 5671: }
1.379 bisitz 5672: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 5673: return $line;
5674: }
5675:
1.538 raeburn 5676: sub action_restrictions {
5677: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
5678: my %denied = (
5679: cut => 0,
5680: copy => 0,
5681: remove => 0,
5682: );
5683: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
5684: # no copy for published maps
5685: $denied{'copy'} = 1;
1.597 raeburn 5686: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
5687: unless ($1 eq 'simpleproblem') {
5688: $denied{'copy'} = 1;
5689: }
5690: $denied{'cut'} = 1;
1.538 raeburn 5691: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
5692: if ($folderpath =~ /^default&[^\&]+$/) {
5693: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
5694: $denied{'remove'} = 1;
5695: }
5696: $denied{'cut'} = 1;
5697: $denied{'copy'} = 1;
5698: }
5699: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
5700: my $group = $1;
5701: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
5702: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5703: $denied{'remove'} = 1;
5704: }
5705: }
5706: $denied{'cut'} = 1;
5707: $denied{'copy'} = 1;
5708: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
5709: my $group = $1;
5710: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
5711: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5712: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5713: if (keys(%groupsettings) > 0) {
5714: $denied{'remove'} = 1;
5715: }
5716: $denied{'cut'} = 1;
5717: $denied{'copy'} = 1;
5718: }
5719: }
5720: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
5721: my $group = $1;
5722: if ($url =~ /group_boards_\Q$group\E/) {
5723: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
5724: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
5725: if (keys(%groupsettings) > 0) {
5726: if (ref($groupsettings{'functions'}) eq 'HASH') {
5727: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
5728: $denied{'remove'} = 1;
5729: }
5730: }
5731: }
5732: $denied{'cut'} = 1;
5733: $denied{'copy'} = 1;
5734: }
5735: }
5736: }
5737: return %denied;
5738: }
5739:
1.533 raeburn 5740: sub new_timebased_suffix {
1.538 raeburn 5741: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 5742: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 5743: if ($type eq 'paste') {
5744: $prefix = $type;
5745: $namespace = 'courseeditor';
1.587 raeburn 5746: $idtype = 'addcode';
1.538 raeburn 5747: } elsif ($type eq 'map') {
1.533 raeburn 5748: $prefix = 'docs';
5749: if ($area eq 'supplemental') {
5750: $prefix = 'supp';
5751: }
5752: $prefix .= $container;
5753: $namespace = 'uploadedmaps';
5754: } else {
5755: $prefix = $type;
5756: $namespace = 'templated';
1.504 raeburn 5757: }
5758: my ($suffix,$freedlock,$error) =
1.587 raeburn 5759: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 5760: if (!$suffix) {
1.538 raeburn 5761: if ($type eq 'paste') {
5762: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
5763: } elsif ($type eq 'map') {
1.533 raeburn 5764: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
5765: } elsif ($type eq 'smppg') {
5766: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 5767: } elsif ($type eq 'exttool') {
5768: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 5769: } else {
1.565 bisitz 5770: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 5771: }
1.504 raeburn 5772: if ($error) {
5773: $errtext .= '<br />'.$error;
5774: }
5775: }
5776: if ($freedlock ne 'ok') {
1.630 raeburn 5777: $locknotfreed =
1.533 raeburn 5778: '<div class="LC_error">'.
5779: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 5780: if ($type eq 'paste') {
1.591 raeburn 5781: if ($freedlock eq 'nolock') {
5782: $locknotfreed =
5783: '<div class="LC_error">'.
5784: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
5785:
1.593 droeschl 5786: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 5787: } else {
5788: $locknotfreed .=
5789: &mt('This will prevent addition of items to the clipboard until your next log-in.');
5790: }
1.538 raeburn 5791: } elsif ($type eq 'map') {
1.591 raeburn 5792: $locknotfreed .=
5793: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 5794: } elsif ($type eq 'smppg') {
5795: $locknotfreed .=
5796: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 5797: } elsif ($type eq 'exttool') {
5798: $locknotfreed .=
5799: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 5800: } else {
5801: $locknotfreed .=
1.565 bisitz 5802: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 5803: }
1.538 raeburn 5804: unless ($type eq 'paste') {
5805: $locknotfreed .=
1.560 raeburn 5806: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
5807: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 5808: }
5809: $locknotfreed .= '</div>';
1.504 raeburn 5810: }
5811: return ($suffix,$errtext,$locknotfreed);
5812: }
5813:
1.329 droeschl 5814: =pod
5815:
5816: =item tiehash()
5817:
5818: tie the hash
5819:
5820: =cut
5821:
5822: sub tiehash {
5823: my ($mode)=@_;
5824: $hashtied=0;
5825: if ($env{'request.course.fn'}) {
5826: if ($mode eq 'write') {
5827: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5828: &GDBM_WRCREAT(),0640)) {
5829: $hashtied=2;
5830: }
5831: } else {
5832: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
5833: &GDBM_READER(),0640)) {
5834: $hashtied=1;
5835: }
5836: }
1.364 bisitz 5837: }
1.329 droeschl 5838: }
5839:
5840: sub untiehash {
5841: if ($hashtied) { untie %hash; }
5842: $hashtied=0;
5843: return OK;
5844: }
5845:
5846:
5847:
5848:
5849: sub checkonthis {
1.637 raeburn 5850: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 5851: $url=&unescape($url);
5852: $alreadyseen{$url}=1;
5853: $r->rflush();
5854: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
5855: $r->print("\n<br />");
5856: if ($level==0) {
5857: $r->print("<br />");
5858: }
5859: for (my $i=0;$i<=$level*5;$i++) {
5860: $r->print(' ');
5861: }
5862: $r->print('<a href="'.$url.'" target="cat">'.
5863: ($title?$title:$url).'</a> ');
5864: if ($url=~/^\/res\//) {
1.637 raeburn 5865: my $updated;
5866: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
5867: ($url !~ /\.\d+\.\w+$/)) {
5868: $updated = &Apache::lonnet::remove_stale_resfile($url);
5869: }
1.329 droeschl 5870: my $result=&Apache::lonnet::repcopy(
5871: &Apache::lonnet::filelocation('',$url));
5872: if ($result eq 'ok') {
5873: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 5874: if ($updated) {
5875: $r->print('<br />');
5876: for (my $i=0;$i<=$level*5;$i++) {
5877: $r->print(' ');
5878: }
5879: $r->print('- '.&mt('Outdated copy removed'));
5880: }
1.329 droeschl 5881: $r->rflush();
5882: &Apache::lonnet::countacc($url);
5883: $url=~/\.(\w+)$/;
5884: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
5885: $r->print('<br />');
5886: $r->rflush();
5887: for (my $i=0;$i<=$level*5;$i++) {
5888: $r->print(' ');
5889: }
5890: $r->print('- '.&mt('Rendering:').' ');
5891: my ($errorcount,$warningcount)=split(/:/,
5892: &Apache::lonnet::ssi_body($url,
5893: ('grade_target'=>'web',
5894: 'return_only_error_and_warning_counts' => 1)));
5895: if (($errorcount) ||
5896: ($warningcount)) {
5897: if ($errorcount) {
1.369 bisitz 5898: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 5899: &mt('[quant,_1,error]',$errorcount).'</span>');
5900: }
5901: if ($warningcount) {
5902: $r->print('<span class="LC_warning">'.
5903: &mt('[quant,_1,warning]',$warningcount).'</span>');
5904: }
5905: } else {
5906: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
5907: }
5908: $r->rflush();
5909: }
5910: my $dependencies=
5911: &Apache::lonnet::metadata($url,'dependencies');
5912: foreach my $dep (split(/\,/,$dependencies)) {
5913: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 5914: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 5915: }
5916: }
5917: } elsif ($result eq 'unavailable') {
5918: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
5919: } elsif ($result eq 'not_found') {
5920: unless ($url=~/\$/) {
1.521 bisitz 5921: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 5922: } else {
1.366 bisitz 5923: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 5924: }
5925: } else {
5926: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
5927: }
1.637 raeburn 5928: if (($updated) && ($result ne 'ok')) {
5929: $r->print('<br />'.&mt('Outdated copy removed'));
5930: }
1.329 droeschl 5931: }
5932: }
5933: }
5934:
5935:
5936:
5937: =pod
5938:
5939: =item list_symbs()
5940:
1.485 raeburn 5941: List Content Identifiers
1.329 droeschl 5942:
5943: =cut
5944:
5945: sub list_symbs {
5946: my ($r) = @_;
5947:
1.408 raeburn 5948: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5949: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
5950: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
5951: $r->print(&startContentScreen('tools'));
1.329 droeschl 5952: my $navmap = Apache::lonnavmaps::navmap->new();
5953: if (!defined($navmap)) {
5954: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
5955: '<div class="LC_error">'.
5956: &mt('Unable to retrieve information about course contents').
5957: '</div>');
1.408 raeburn 5958: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 5959: } else {
1.484 raeburn 5960: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
5961: &Apache::loncommon::start_data_table().
5962: &Apache::loncommon::start_data_table_header_row().
5963: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
5964: &Apache::loncommon::end_data_table_header_row()."\n");
5965: my $count;
1.329 droeschl 5966: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 5967: $r->print(&Apache::loncommon::start_data_table_row().
5968: '<td>'.$res->compTitle().'</td>'.
5969: '<td>'.$res->symb().'</td>'.
1.521 bisitz 5970: &Apache::loncommon::end_data_table_row());
1.484 raeburn 5971: $count ++;
5972: }
5973: if (!$count) {
5974: $r->print(&Apache::loncommon::start_data_table_row().
5975: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
5976: &Apache::loncommon::end_data_table_row());
1.329 droeschl 5977: }
1.484 raeburn 5978: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 5979: }
1.521 bisitz 5980: $r->print(&endContentScreen());
1.329 droeschl 5981: }
5982:
1.651 raeburn 5983: sub short_urls {
5984: my ($r,$canedit) = @_;
5985: my $crstype = &Apache::loncommon::course_type();
5986: my $formname = 'shortenurl';
5987: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5988: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5989: $r->print(&startContentScreen('tools'));
5990: my ($navmap,$errormsg) =
5991: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5992: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5993: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5994: my (%maps,%resources,%titles);
5995: if (!ref($navmap)) {
5996: $r->print($errormsg.
5997: &endContentScreen());
5998: return '';
5999: } else {
1.652 raeburn 6000: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 6001: $r->rflush();
6002: my $readonly;
6003: if ($canedit) {
1.671 raeburn 6004: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 6005: if ($numnew) {
6006: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
6007: }
6008: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
6009: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
6010: foreach my $error (@{$errors}) {
6011: $r->print('<li>'.$error.'</li>');
6012: }
6013: $r->print('</ul><br />');
6014: }
6015: } else {
6016: $readonly = 1;
6017: }
6018: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
6019: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
1.711 raeburn 6020: undef,undef,undef,undef,undef,\%currtiny,undef,$readonly));
1.651 raeburn 6021: }
6022: $r->print(&endContentScreen());
6023: }
6024:
1.637 raeburn 6025: sub contentverifyform {
6026: my ($r) = @_;
6027: my $crstype = &Apache::loncommon::course_type();
6028: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6029: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
6030: $r->print(&startContentScreen('tools'));
6031: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
6032: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
6033: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
6034: ' <span class="LC_nobreak">'.
6035: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
6036: &mt('No').'</label>'.(' 'x2).
6037: '<label><input type="radio" name="checkstale" value="1" />'.
6038: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 6039: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 6040: '<input type="hidden" value="1" name="tools" />'.
6041: '<input type="hidden" value="1" name="verify" /></p></form>');
6042: $r->print(&endContentScreen());
6043: return;
6044: }
1.329 droeschl 6045:
6046: sub verifycontent {
1.637 raeburn 6047: my ($r,$checkstale) = @_;
1.408 raeburn 6048: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 6049: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
6050: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 6051: $r->print(&startContentScreen('tools'));
6052: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 6053: $hashtied=0;
6054: undef %alreadyseen;
6055: %alreadyseen=();
6056: &tiehash();
1.484 raeburn 6057:
1.329 droeschl 6058: foreach my $key (keys(%hash)) {
6059: if ($hash{$key}=~/\.(page|sequence)$/) {
6060: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
6061: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 6062: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 6063: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 6064: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 6065: }
6066: }
6067: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 6068: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 6069: }
6070: }
6071: &untiehash();
1.442 www 6072: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 6073: $r->print(&endContentScreen());
1.329 droeschl 6074: }
6075:
6076: sub devalidateversioncache {
6077: my $src=shift;
6078: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
6079: &Apache::lonnet::clutter($src));
6080: }
6081:
6082: sub checkversions {
1.611 raeburn 6083: my ($r,$canedit) = @_;
1.408 raeburn 6084: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 6085: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
6086: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 6087: $r->print(&startContentScreen('tools'));
1.442 www 6088:
1.329 droeschl 6089: my $header='';
6090: my $startsel='';
6091: my $monthsel='';
6092: my $weeksel='';
6093: my $daysel='';
6094: my $allsel='';
6095: my %changes=();
6096: my $starttime=0;
6097: my $haschanged=0;
6098: my %setversions=&Apache::lonnet::dump('resourceversions',
6099: $env{'course.'.$env{'request.course.id'}.'.domain'},
6100: $env{'course.'.$env{'request.course.id'}.'.num'});
6101:
6102: $hashtied=0;
6103: &tiehash();
1.611 raeburn 6104: if ($canedit) {
6105: my %newsetversions=();
6106: if ($env{'form.setmostrecent'}) {
6107: $haschanged=1;
6108: foreach my $key (keys(%hash)) {
6109: if ($key=~/^ids\_(\/res\/.+)$/) {
6110: $newsetversions{$1}='mostrecent';
6111: &devalidateversioncache($1);
6112: }
6113: }
6114: } elsif ($env{'form.setcurrent'}) {
6115: $haschanged=1;
6116: foreach my $key (keys(%hash)) {
6117: if ($key=~/^ids\_(\/res\/.+)$/) {
6118: my $getvers=&Apache::lonnet::getversion($1);
6119: if ($getvers>0) {
6120: $newsetversions{$1}=$getvers;
6121: &devalidateversioncache($1);
6122: }
6123: }
1.329 droeschl 6124: }
1.611 raeburn 6125: } elsif ($env{'form.setversions'}) {
6126: $haschanged=1;
6127: foreach my $key (keys(%env)) {
6128: if ($key=~/^form\.set_version_(.+)$/) {
6129: my $src=$1;
6130: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
6131: $newsetversions{$src}=$env{$key};
6132: &devalidateversioncache($src);
6133: }
6134: }
1.329 droeschl 6135: }
1.611 raeburn 6136: }
6137: if ($haschanged) {
6138: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
6139: $env{'course.'.$env{'request.course.id'}.'.domain'},
6140: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
6141: $r->print(&Apache::loncommon::confirmwrapper(
6142: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
6143: } else {
6144: $r->print(&Apache::loncommon::confirmwrapper(
6145: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 6146: }
1.611 raeburn 6147: &mark_hash_old();
6148: }
6149: &changewarning($r,'');
1.329 droeschl 6150: }
6151: if ($env{'form.timerange'} eq 'all') {
6152: # show all documents
1.549 raeburn 6153: $header=&mt('All content in '.$crstype);
1.521 bisitz 6154: $allsel=' selected="selected"';
1.329 droeschl 6155: foreach my $key (keys(%hash)) {
6156: if ($key=~/^ids\_(\/res\/.+)$/) {
6157: my $src=$1;
6158: $changes{$src}=1;
6159: }
6160: }
6161: } else {
6162: # show documents which changed
6163: %changes=&Apache::lonnet::dump
6164: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
6165: $env{'course.'.$env{'request.course.id'}.'.num'});
6166: my $firstkey=(keys(%changes))[0];
6167: unless ($firstkey=~/^error\:/) {
6168: unless ($env{'form.timerange'}) {
6169: $env{'form.timerange'}=604800;
6170: }
6171: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
6172: .&mt('seconds');
6173: if ($env{'form.timerange'}==-1) {
6174: $seltext='since start of course';
1.521 bisitz 6175: $startsel=' selected="selected"';
1.329 droeschl 6176: $env{'form.timerange'}=time;
6177: }
6178: $starttime=time-$env{'form.timerange'};
6179: if ($env{'form.timerange'}==2592000) {
6180: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6181: $monthsel=' selected="selected"';
1.329 droeschl 6182: } elsif ($env{'form.timerange'}==604800) {
6183: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6184: $weeksel=' selected="selected"';
1.329 droeschl 6185: } elsif ($env{'form.timerange'}==86400) {
6186: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 6187: $daysel=' selected="selected"';
1.329 droeschl 6188: }
6189: $header=&mt('Content changed').' '.$seltext;
6190: } else {
6191: $header=&mt('No content modifications yet.');
6192: }
6193: }
6194: %setversions=&Apache::lonnet::dump('resourceversions',
6195: $env{'course.'.$env{'request.course.id'}.'.domain'},
6196: $env{'course.'.$env{'request.course.id'}.'.num'});
6197: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 6198: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 6199: 'lm' => 'Version changes since last Month',
6200: 'lw' => 'Version changes since last Week',
6201: 'sy' => 'Version changes since Yesterday',
6202: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 6203: 'cd' => 'Change display',
1.329 droeschl 6204: 'sd' => 'Display',
6205: 'fi' => 'File',
6206: 'md' => 'Modification Date',
6207: 'mr' => 'Most recently published Version',
1.408 raeburn 6208: 've' => 'Version used in '.$crstype,
6209: 'vu' => 'Set Version to be used in '.$crstype,
6210: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 6211: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
6212: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 6213: 'di' => 'Differences',
1.484 raeburn 6214: 'save' => 'Save changes',
6215: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 6216: 'act' => 'Actions');
1.611 raeburn 6217: my ($disabled,$readonly);
6218: unless ($canedit) {
6219: $disabled = 'disabled="disabled"';
6220: $readonly = 1;
6221: }
1.329 droeschl 6222: $r->print(<<ENDHEADERS);
1.484 raeburn 6223: <h4 class="LC_info">$header</h4>
1.329 droeschl 6224: <form action="/adm/coursedocs" method="post">
6225: <input type="hidden" name="versions" value="1" />
1.484 raeburn 6226: <div class="LC_left_float">
1.479 golterma 6227: <fieldset>
1.484 raeburn 6228: <legend>$lt{'cd'}</legend>
1.329 droeschl 6229: <select name="timerange">
1.521 bisitz 6230: <option value='all'$allsel>$lt{'al'}</option>
6231: <option value="-1"$startsel>$lt{'st'}</option>
6232: <option value="2592000"$monthsel>$lt{'lm'}</option>
6233: <option value="604800"$weeksel>$lt{'lw'}</option>
6234: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 6235: </select>
6236: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 6237: </fieldset>
6238: </div>
6239: <div class="LC_left_float">
6240: <fieldset>
6241: <legend>$lt{'act'}</legend>
1.611 raeburn 6242: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
6243: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 6244: </fieldset>
6245: </div>
6246: <br clear="all" />
6247: <hr />
6248: <h4>$lt{'vers'}</h4>
1.329 droeschl 6249: ENDHEADERS
1.479 golterma 6250: #number of columns for version history
1.571 raeburn 6251: my %changedbytime;
6252: foreach my $key (keys(%changes)) {
6253: #excludes not versionable problems from resource version history:
6254: next if ($key =~ /^\/res\/lib\/templates/);
6255: my $chg;
6256: if ($env{'form.timerange'} eq 'all') {
6257: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6258: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
6259: } else {
6260: $chg = $changes{$key};
6261: next if ($chg < $starttime);
6262: }
6263: push(@{$changedbytime{$chg}},$key);
6264: }
6265: if (keys(%changedbytime) == 0) {
6266: &untiehash();
6267: $r->print(&mt('No content changes in imported content in specified time frame').
6268: &endContentScreen());
6269: return;
6270: }
1.479 golterma 6271: $r->print(
1.611 raeburn 6272: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6273: &Apache::loncommon::start_data_table().
6274: &Apache::loncommon::start_data_table_header_row().
6275: '<th>'.&mt('Resources').'</th>'.
6276: "<th>$lt{'mr'}</th>".
6277: "<th>$lt{'ve'}</th>".
6278: "<th>$lt{'vu'}</th>".
6279: '<th>'.&mt('History').'</th>'.
6280: &Apache::loncommon::end_data_table_header_row()
6281: );
1.571 raeburn 6282: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
6283: foreach my $key (sort(@{$changedbytime{$chg}})) {
6284: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
6285: my $currentversion=&Apache::lonnet::getversion($key);
6286: if ($currentversion<0) {
6287: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
6288: }
6289: my $linkurl=&Apache::lonnet::clutter($key);
6290: $r->print(
6291: &Apache::loncommon::start_data_table_row().
6292: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
6293: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
6294: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
6295: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
6296: '<td align="right">'
6297: );
6298: # Used in course
6299: my $usedversion=$hash{'version_'.$linkurl};
6300: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 6301: if ($usedversion != $currentversion) {
1.479 golterma 6302: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 6303: } else {
1.479 golterma 6304: $r->print($usedversion);
6305: }
1.329 droeschl 6306: } else {
1.521 bisitz 6307: $r->print($currentversion);
1.329 droeschl 6308: }
1.571 raeburn 6309: $r->print('</td><td title="'.$lt{'vu'}.'">');
6310: # Set version
6311: $r->print(&Apache::loncommon::select_form(
6312: $setversions{$linkurl},
6313: 'set_version_'.$linkurl,
6314: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
6315: '' => '',
6316: 'mostrecent' => &mt('most recent'),
1.611 raeburn 6317: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 6318: my $lastold=1;
6319: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
6320: my $url=$root.'.'.$prevvers.'.'.$extension;
6321: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
6322: $lastold=$prevvers;
6323: }
6324: }
6325: $r->print('</td>');
6326: # List all available versions
6327: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
6328: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
6329: my $url=$root.'.'.$prevvers.'.'.$extension;
6330: $r->print(
6331: '<span class="LC_nobreak">'
6332: .'<a href="'.&Apache::lonnet::clutter($url).'">'
6333: .&mt('Version [_1]',$prevvers).'</a>'
6334: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 6335: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 6336: .')');
6337: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
6338: $r->print(
6339: ' <a href="/adm/diff?filename='.
6340: &Apache::lonnet::clutter($root.'.'.$extension).
6341: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
6342: '" target="diffs">'.&mt('Diffs').'</a>');
6343: }
6344: $r->print('</span><br />');
1.329 droeschl 6345: }
1.571 raeburn 6346: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 6347: }
1.329 droeschl 6348: }
1.521 bisitz 6349: $r->print(
6350: &Apache::loncommon::end_data_table().
1.611 raeburn 6351: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 6352: '</form>'
6353: );
1.329 droeschl 6354:
6355: &untiehash();
1.521 bisitz 6356: $r->print(&endContentScreen());
1.571 raeburn 6357: return;
1.329 droeschl 6358: }
6359:
6360: sub mark_hash_old {
6361: my $retie_hash=0;
6362: if ($hashtied) {
6363: $retie_hash=1;
6364: &untiehash();
6365: }
6366: &tiehash('write');
6367: $hash{'old'}=1;
6368: &untiehash();
6369: if ($retie_hash) { &tiehash(); }
6370: }
6371:
6372: sub is_hash_old {
6373: my $untie_hash=0;
6374: if (!$hashtied) {
6375: $untie_hash=1;
6376: &tiehash();
6377: }
6378: my $return=$hash{'old'};
6379: if ($untie_hash) { &untiehash(); }
6380: return $return;
6381: }
6382:
6383: sub changewarning {
6384: my ($r,$postexec,$message,$url)=@_;
6385: if (!&is_hash_old()) { return; }
6386: my $pathvar='folderpath';
6387: my $path=&escape($env{'form.folderpath'});
6388: if (!defined($url)) {
6389: $url='/adm/coursedocs?'.$pathvar.'='.$path;
6390: }
6391: my $course_type = &Apache::loncommon::course_type();
6392: if (!defined($message)) {
6393: $message='Changes will become active for your current session after [_1], or the next time you log in.';
6394: }
1.653 raeburn 6395: my $windowname = 'loncapaclient';
6396: if ($env{'request.lti.login'}) {
6397: $windowname .= 'lti';
6398: }
1.329 droeschl 6399: $r->print("\n\n".
1.372 bisitz 6400: '<script type="text/javascript">'."\n".
6401: '// <![CDATA['."\n".
6402: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
6403: '// ]]>'."\n".
1.369 bisitz 6404: '</script>'."\n".
1.653 raeburn 6405: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 6406: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 6407: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 6408: &mt($message,' <input type="hidden" name="'.
6409: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 6410: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 6411: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 6412: }
6413:
6414:
6415: sub init_breadcrumbs {
1.571 raeburn 6416: my ($form,$text,$help)=@_;
1.329 droeschl 6417: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 6418: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 6419: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 6420: faq=>273,
6421: bug=>'Instructor Interface',
1.571 raeburn 6422: help => $help});
1.329 droeschl 6423: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
6424: text=>$text,
6425: faq=>273,
6426: bug=>'Instructor Interface'});
6427: }
6428:
1.441 www 6429: # subroutine to list form elements
6430: sub create_list_elements {
6431: my @formarr = @_;
6432: my $list = '';
1.501 raeburn 6433: foreach my $button (@formarr){
6434: foreach my $picture (keys(%{$button})) {
6435: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 6436: }
6437: }
6438: return $list;
6439: }
1.329 droeschl 6440:
1.441 www 6441: # subroutine to create ul from list elements
6442: sub create_form_ul {
6443: my $list = shift;
6444: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
6445: return $ul;
6446: }
1.329 droeschl 6447:
1.442 www 6448: #
6449: # Start tabs
6450: #
6451:
6452: sub startContentScreen {
1.484 raeburn 6453: my ($mode) = @_;
6454: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 6455: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 6456: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
6457: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
6458: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
6459: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
6460: } else {
1.549 raeburn 6461: $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 6462: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
6463: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
6464: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
6465: }
6466: $output .= "\n".'</ul>'."\n";
6467: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
6468: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
6469: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
6470: return $output;
1.442 www 6471: }
6472:
6473: #
6474: # End tabs
6475: #
6476:
6477: sub endContentScreen {
1.484 raeburn 6478: return '</div></div></div>';
1.442 www 6479: }
1.329 droeschl 6480:
1.446 www 6481: sub supplemental_base {
1.548 raeburn 6482: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 6483: }
6484:
1.329 droeschl 6485: sub handler {
6486: my $r = shift;
6487: &Apache::loncommon::content_type($r,'text/html');
6488: $r->send_http_header;
6489: return OK if $r->header_only;
1.484 raeburn 6490:
6491: # get course data
1.408 raeburn 6492: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 6493: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
6494: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.712 raeburn 6495: my $coursehome=$env{'course.'.$env{'request.course.id'}.'.home'};
1.484 raeburn 6496:
1.606 raeburn 6497: # get docroot
6498: my $londocroot = $r->dir_config('lonDocRoot');
6499:
1.484 raeburn 6500: # graphics settings
6501: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 6502:
1.443 www 6503: #
1.329 droeschl 6504: # --------------------------------------------- Initialize help topics for this
6505: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 6506: 'Adding_External_Resource','Adding_External_Tool',
6507: 'Navigate_Content','Adding_Folders','Docs_Overview',
6508: 'Load_Map','Supplemental','Score_Upload_Form',
6509: 'Adding_Pages','Importing_LON-CAPA_Resource',
6510: 'Importing_IMS_Course','Uploading_From_Harddrive',
1.706 raeburn 6511: 'Course_Roster','Web_Page','Dropbox','Simple_Problem',
6512: 'Standard_Problem','Course_Resources',
6513: 'Search_LON-CAPA_Resource','Import_Stored_Links') {
1.329 droeschl 6514: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
6515: }
6516: # Composite help files
6517: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
6518: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
6519: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
6520: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
6521: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
6522: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 6523: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 6524: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 6525: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 6526: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 6527:
1.611 raeburn 6528: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 6529: # does this user have privileges to modify content.
6530: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 6531: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 6532: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6533: $allowed = 1;
1.682 raeburn 6534: }
6535: $canedit = 1;
6536: $canview = 1;
6537: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
6538: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
6539: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 6540: $allowed = 1;
6541: }
1.682 raeburn 6542: $canview = 1;
1.611 raeburn 6543: }
6544: unless ($canedit) {
6545: $disabled = ' disabled="disabled"';
1.472 raeburn 6546: }
1.582 raeburn 6547: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 6548: if ($env{'form.inhibitmenu'}) {
6549: unless ($env{'form.inhibitmenu'} eq 'yes') {
6550: delete($env{'form.inhibitmenu'});
6551: }
6552: }
6553:
1.582 raeburn 6554: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 6555: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 6556: if (!$canedit) {
6557: &verifycontent($r);
6558: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
6559: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
6560: text=>'Results',
6561: faq=>273,
6562: bug=>'Instructor Interface'});
6563: &verifycontent($r,$env{'form.checkstale'});
6564: } else {
6565: &contentverifyform($r);
6566: }
1.329 droeschl 6567: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 6568: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 6569: &list_symbs($r);
1.651 raeburn 6570: } elsif ($allowed && $env{'form.shorturls'}) {
6571: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
6572: &short_urls($r,$canedit);
1.329 droeschl 6573: } elsif ($allowed && $env{'form.docslog'}) {
6574: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 6575: my $folder = $env{'form.folder'};
6576: if ($folder eq '') {
6577: $folder='default';
6578: }
1.611 raeburn 6579: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 6580: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 6581: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 6582: &checkversions($r,$canedit);
6583: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.709 raeburn 6584: &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
1.329 droeschl 6585: &dumpcourse($r);
1.712 raeburn 6586: } elsif (($canedit || $canview) && ($env{'form.copyauthored'})) {
6587: &init_breadcrumbs('copyauthored','Copy from Course Authoring to User Authoring');
6588: my $readonly;
6589: if (!$canedit) {
6590: $readonly = 1;
6591: }
6592: ©crsauthored($r,$coursenum,$coursedom,$coursehome,$readonly);
1.611 raeburn 6593: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 6594: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 6595: &Apache::imsexport::exportcourse($r);
1.329 droeschl 6596: } else {
1.611 raeburn 6597: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 6598: $noendpage = 1;
6599: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
6600: if ($redirect) {
6601: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
6602: my $container = 'sequence';
6603: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
6604: $is_random_order,$container) =
6605: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
6606: my (@folders)=split('&',$env{'form.folderpath'});
6607: $env{'form.foldername'}=&unescape(pop(@folders));
6608: my $folder=pop(@folders);
6609: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
6610: $folder.'.'.$container);
6611: my $warning;
6612: if ($fatal) {
6613: if ($container eq 'page') {
6614: $warning = &mt('An error occurred retrieving the contents of the current page.');
6615: } else {
6616: $warning = &mt('An error occurred retrieving the contents of the current folder.');
6617: }
6618: } else {
6619: my $url = $redirect;
6620: my $srcfile = $londocroot.$url;
6621: $url =~ s{^/priv/}{/res/};
6622: my $targetfile = $londocroot.$url;
6623: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
6624: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
6625: $env{'form.folder'} = $folder;
6626: &snapshotbefore();
6627: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
6628: my $ext = 'false';
6629: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
6630: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
6631: ':'.$ext.':normal:res';
6632: push(@LONCAPA::map::order,$newidx);
6633: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
6634: 'string_yesno');
6635: &remember_parms($newidx,'hiddenresource','set','yes');
6636: ($errtext,$fatal) =
6637: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
6638: &log_differences($plain);
6639: &mark_hash_old();
6640: $r->internal_redirect($redirect);
6641: return OK;
6642: }
1.654 raeburn 6643: } else {
6644: $r->internal_redirect($redirect);
1.606 raeburn 6645: }
6646: }
6647: }
1.445 www 6648: #
6649: # Done catching special calls
1.484 raeburn 6650: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 6651: # Get the parameters that may be needed
6652: #
6653: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 6654: ['folderpath','title',
1.519 raeburn 6655: 'forcesupplement','forcestandard',
1.510 raeburn 6656: 'tools','symb','command','supppath']);
1.445 www 6657:
1.635 raeburn 6658: foreach my $item ('forcesupplement','forcestandard','tools') {
6659: next if ($env{'form.'.$item} eq '');
6660: unless ($env{'form.'.$item} eq '1') {
6661: delete($env{'form.'.$item});
6662: }
6663: }
6664:
6665: if ($env{'form.command'}) {
6666: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
6667: delete($env{'form.command'});
6668: }
6669: }
6670:
6671: if ($env{'form.symb'}) {
6672: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
6673: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
6674: delete($env{'form.symb'});
6675: }
6676: }
6677:
1.445 www 6678: # standard=1: this is a "new-style" course with an uploaded map as top level
6679: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 6680:
6681: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 6682:
1.484 raeburn 6683: # Decide whether this should display supplemental or main content or utilities
1.445 www 6684: # supplementalflag=1: show supplemental documents
6685: # supplementalflag=0: show standard documents
1.484 raeburn 6686: # toolsflag=1: show utilities
1.445 www 6687:
1.561 raeburn 6688: my $unesc_folderpath = &unescape($env{'form.folderpath'});
6689: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
6690: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 6691: $supplementalflag=0;
6692: }
6693: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
6694: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
1.705 raeburn 6695: unless (($supplementalflag) ||
6696: ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
6697: unless ($allowed) { $supplementalflag=1; }
6698: unless ($standard) { $supplementalflag=1; }
6699: }
1.484 raeburn 6700: my $toolsflag=0;
6701: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 6702:
1.635 raeburn 6703: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 6704: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 6705: }
6706:
1.685 raeburn 6707: my $backto_supppath;
1.635 raeburn 6708: if ($env{'form.supppath'} ne '') {
1.685 raeburn 6709: if ($supplementalflag && $allowed) {
6710: $backto_supppath = &validate_supppath($coursenum,$coursedom);
6711: }
1.635 raeburn 6712: }
6713:
1.329 droeschl 6714: my $script='';
6715: my $showdoc=0;
1.457 raeburn 6716: my $addentries = {};
1.475 raeburn 6717: my $container;
1.329 droeschl 6718: my $containertag;
1.508 raeburn 6719: my $pathitem;
1.598 raeburn 6720: my %ltitools;
1.699 raeburn 6721: my $posslti;
1.617 raeburn 6722: my $hiddentop;
1.615 raeburn 6723: my $navmap;
1.617 raeburn 6724: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 6725:
1.464 www 6726: # Do we directly jump somewhere?
1.525 raeburn 6727: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 6728: if ($env{'form.symb'} ne '') {
1.522 raeburn 6729: $env{'form.folderpath'}=
1.617 raeburn 6730: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 6731: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 6732: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 6733: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 6734: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 6735: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 6736: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 6737: }
1.472 raeburn 6738: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 6739: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 6740: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 6741: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 6742: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 6743: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
6744: } elsif ($env{'form.command'} eq 'contents') {
6745: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
6746: } elsif ($env{'form.command'} eq 'home') {
6747: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 6748: }
6749:
1.525 raeburn 6750:
1.445 www 6751: # Where do we store these for when we come back?
6752: my $stored_folderpath='docs_folderpath';
6753: if ($supplementalflag) {
6754: $stored_folderpath='docs_sup_folderpath';
6755: }
1.464 www 6756:
1.519 raeburn 6757: # No folderpath, and in edit mode, see if we have something stored
6758: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 6759: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 6760: {'folderpath' => 'scalar'});
1.615 raeburn 6761:
6762: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
6763: if ($supplementalflag) {
6764: undef($env{'form.folderpath'}) if ($1 eq 'default');
6765: } else {
6766: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
6767: }
6768: } else {
1.523 raeburn 6769: undef($env{'form.folderpath'});
6770: }
1.677 raeburn 6771: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 6772: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 6773: }
1.329 droeschl 6774: }
1.706 raeburn 6775:
6776: # Set folderpath if we are not allowed to make changes and this is supplemental content
1.705 raeburn 6777: if ((!$allowed) && ($supplementalflag)) {
1.446 www 6778: unless ($env{'form.folderpath'} =~ /^supplemental/) {
6779: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 6780: }
6781: }
1.446 www 6782: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 6783: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 6784: $env{'form.folderpath'} = &supplemental_base()
6785: .'&'.
1.329 droeschl 6786: $env{'form.folderpath'};
6787: }
1.685 raeburn 6788: # If allowed and user's role is not advanced check folderpath is not hidden
6789: my $hidden_and_empty;
1.687 raeburn 6790: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 6791: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 6792: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 6793: my $folder = $pathitems[-2];
6794: if ($folder eq '') {
6795: undef($env{'form.folderpath'});
6796: } else {
6797: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 6798: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 6799: $folderurl .= '.page';
6800: } else {
6801: $folderurl .= '.sequence';
6802: }
1.685 raeburn 6803: if ($supplementalflag) {
6804: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
6805: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 6806: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 6807: if (ref($supplemental) eq 'HASH') {
6808: my ($suppmap,$suppmapnum);
6809: if ($folder eq 'supplemental') {
6810: $suppmap = 'default';
6811: $suppmapnum = 0;
6812: } elsif ($folder =~ /^supplemental_(\d+)$/) {
6813: $suppmap = $1;
6814: $suppmapnum = $suppmap;
6815: }
6816: if ($hiddenfolder) {
6817: my $hascontent;
6818: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
6819: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
6820: $hascontent = 1;
6821: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
6822: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
6823: if ($id =~ /^$suppmapnum\:/) {
6824: $hascontent = 1;
6825: last;
6826: }
6827: }
6828: }
6829: last if ($hascontent);
6830: }
6831: unless ($hascontent) {
6832: if ($foldername ne '') {
6833: $hidden_and_empty = $foldername;
6834: } else {
6835: $hidden_and_empty = $folder;
6836: }
6837: }
6838: }
6839: }
6840: } else {
6841: unless (ref($navmap)) {
6842: $navmap = Apache::lonnavmaps::navmap->new();
6843: }
6844: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
6845: $foldername = &HTML::Entities::decode(&unescape($foldername));
6846: if (ref($navmap)) {
6847: if ($hiddenfolder ||
6848: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
6849: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
6850: unless (@resources) {
6851: if ($foldername ne '') {
6852: $hidden_and_empty = $foldername;
6853: } else {
6854: $hidden_and_empty = $folder;
6855: }
6856: }
6857: }
6858: }
1.617 raeburn 6859: }
1.685 raeburn 6860: if ($hidden_and_empty ne '') {
6861: splice(@pathitems,-2);
6862: if (@pathitems) {
6863: $env{'form.folderpath'} = join('&',@pathitems);
6864: } else {
6865: undef($env{'form.folderpath'});
1.615 raeburn 6866: }
6867: }
6868: }
6869: }
6870:
1.446 www 6871: # If after all of this, we still don't have any paths, make them
1.519 raeburn 6872: unless ($env{'form.folderpath'}) {
1.446 www 6873: if ($supplementalflag) {
6874: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 6875: } elsif ($allowed) {
6876: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 6877: }
1.472 raeburn 6878: }
1.446 www 6879:
1.445 www 6880: # Store this
1.484 raeburn 6881: unless ($toolsflag) {
1.615 raeburn 6882: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 6883: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 6884: {'folderpath' => 'scalar'});
1.510 raeburn 6885: }
1.519 raeburn 6886: my $folderpath;
1.484 raeburn 6887: if ($env{'form.folderpath'}) {
1.519 raeburn 6888: $folderpath = $env{'form.folderpath'};
6889: my (@folders)=split('&',$env{'form.folderpath'});
6890: $env{'form.foldername'}=&unescape(pop(@folders));
6891: if ($env{'form.foldername'} =~ /\:1$/) {
6892: $container = 'page';
6893: } else {
6894: $container = 'sequence';
6895: }
6896: $env{'form.folder'}=pop(@folders);
1.484 raeburn 6897: } else {
1.519 raeburn 6898: if ($env{'form.folder'} eq '' ||
6899: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 6900: if ($env{'form.folder'} eq 'supplemental') {
6901: $folderpath=&supplemental_base();
6902: } elsif (!$hiddentop) {
6903: $folderpath='default&'.
6904: &escape(&mt('Main Content').':::::');
6905: }
1.484 raeburn 6906: }
6907: }
1.519 raeburn 6908: $containertag = '<input type="hidden" name="folderpath" value="" />';
6909: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 6910: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
6911: $showdoc='/'.$1;
6912: }
6913: if ($showdoc) { # got called in sequence from course
6914: $allowed=0;
6915: } else {
1.611 raeburn 6916: if ($canedit) {
1.484 raeburn 6917: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
6918: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 6919: }
6920: }
1.329 droeschl 6921: }
6922:
1.344 bisitz 6923: # get personal data
1.329 droeschl 6924: my $uname=$env{'user.name'};
6925: my $udom=$env{'user.domain'};
6926: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
6927:
6928: if ($allowed) {
1.484 raeburn 6929: if ($toolsflag) {
6930: $script .= &inject_data_js();
6931: my ($home,$other,%outhash)=&authorhosts();
6932: if (!$home && $other) {
6933: my @hosts;
6934: foreach my $aurole (keys(%outhash)) {
6935: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6936: push(@hosts,$outhash{$aurole});
6937: }
6938: }
6939: $script .= &dump_switchserver_js(@hosts);
6940: }
1.458 raeburn 6941: } else {
1.570 raeburn 6942: my $tid = 1;
1.484 raeburn 6943: my @tabids;
6944: if ($supplementalflag) {
1.655 raeburn 6945: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 6946: $tid = 2;
1.484 raeburn 6947: } else {
6948: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 6949: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 6950: unshift(@tabids,'001');
6951: push(@tabids,('dd1','ee1'));
6952: }
1.458 raeburn 6953: }
1.484 raeburn 6954: my $tabidstr = join("','",@tabids);
1.699 raeburn 6955: my (%domtools,%crstools);
6956: my %tooltypes = &Apache::loncommon::usable_exttools();
6957: if ($tooltypes{'dom'}) {
6958: %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
6959: }
6960: if ($tooltypes{'crs'}) {
6961: %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
6962: }
6963: %ltitools = (
6964: dom => \%domtools,
6965: crs => \%crstools,
6966: );
6967: $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622 raeburn 6968: my $hostname = $r->hostname();
1.606 raeburn 6969: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 6970: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 6971: &history_tab_js().
6972: &inject_data_js().
1.570 raeburn 6973: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 6974: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 6975: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
6976: if ($hidden_and_empty ne '') {
6977: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
6978: $hidden_and_empty);
6979: $onload .= "javascript:alert('".&js_escape($alert)."');";
6980: }
1.484 raeburn 6981: $addentries = {
1.685 raeburn 6982: onload => $onload,
1.484 raeburn 6983: };
1.458 raeburn 6984: }
1.538 raeburn 6985: $script .= &paste_popup_js();
1.501 raeburn 6986: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
6987: &mt('Switch server?');
6988:
6989:
1.329 droeschl 6990: }
6991: # -------------------------------------------------------------------- Body tag
1.369 bisitz 6992: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 6993: .'// <![CDATA['."\n"
6994: .$script."\n"
6995: .'// ]]>'."\n"
1.595 musolffc 6996: .'</script>'."\n"
6997: .'<script type="text/javascript"
6998: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 6999:
7000: # Breadcrumbs
7001: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 7002:
7003: if ($showdoc) {
1.682 raeburn 7004: my $args;
7005: if ($supplementalflag) {
1.687 raeburn 7006: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
7007: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.705 raeburn 7008: $args = {'bread_crumbs' => $brcrum,
7009: 'bread_crumbs_nomenu' => 1};
1.682 raeburn 7010: } else {
7011: $args = {'force_register' => $showdoc};
7012: }
7013: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 7014: } elsif ($toolsflag) {
1.611 raeburn 7015: my ($breadtext,$breadtitle);
1.617 raeburn 7016: $breadtext = "$crstype Editor";
1.611 raeburn 7017: if ($canedit) {
7018: $breadtitle = 'Editing '.$crstype.' Contents';
7019: } else {
7020: $breadtext .= ' (View-only mode)';
7021: $breadtitle = 'Viewing '.$crstype.' Contents';
7022: }
1.571 raeburn 7023: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7024: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 7025: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
7026: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7027: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7028: $breadtitle)
1.571 raeburn 7029: );
1.510 raeburn 7030: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 7031: unless ($env{'request.role.adv'}) {
7032: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
7033: $r->internal_redirect('/adm/navmaps');
7034: return OK;
7035: }
7036: }
1.510 raeburn 7037: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
1.705 raeburn 7038: my $args = {'bread_crumbs' => $brcrum};
7039: unless (($env{'form.folderpath'} eq '') ||
7040: ($env{'form.folder'} eq 'supplemental')) {
7041: $args->{'bread_crumbs_nomenu'} = 1;
7042: }
1.510 raeburn 7043: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
1.705 raeburn 7044: $args));
1.510 raeburn 7045: } else {
1.611 raeburn 7046: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 7047: $breadtext = "$crstype Editor";
1.611 raeburn 7048: if ($canedit) {
7049: $breadtitle = 'Editing '.$crstype.' Contents';
7050: $helpitem = 'Docs_Adding_Course_Doc';
7051: } else {
7052: $breadtext .= ' (View-only mode)';
7053: $breadtitle = 'Viewing '.$crstype.' Contents';
7054: $helpitem = 'Docs_Viewing_Course_Doc';
7055: }
1.392 raeburn 7056: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 7057: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 7058: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 7059: {'add_entries' => $addentries}
7060: )
1.392 raeburn 7061: .&Apache::loncommon::help_open_menu('','',273,'RAT')
7062: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 7063: $breadtitle,
7064: $helpitem)
1.392 raeburn 7065: );
7066: }
1.364 bisitz 7067:
1.329 droeschl 7068: my %allfiles = ();
7069: my %codebase = ();
1.440 raeburn 7070: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 7071: if ($canedit) {
1.684 raeburn 7072: undef($suppchanges);
1.329 droeschl 7073: if (($env{'form.uploaddoc.filename'}) &&
7074: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 7075: my $context = $1;
7076: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 7077: undef($hadchanges);
1.440 raeburn 7078: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 7079: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 7080: undef($navmap);
1.329 droeschl 7081: if ($hadchanges) {
7082: &mark_hash_old();
7083: }
1.684 raeburn 7084: if ($suppchanges) {
7085: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
7086: undef($suppchanges);
7087: }
1.440 raeburn 7088: $r->print($upload_output);
7089: } elsif ($env{'form.phase'} eq 'upload_embedded') {
7090: # Process file upload - phase two - upload embedded objects
7091: $uploadphase = 'check_embedded';
7092: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
7093: my $state = &embedded_form_elems($uploadphase,$primaryurl,
7094: $env{'form.newidx'});
7095: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7096: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7097: my ($destination,$dir_root) = &embedded_destination();
7098: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
7099: my $actionurl = '/adm/coursedocs';
1.630 raeburn 7100: my ($result,$flag) =
1.440 raeburn 7101: &Apache::loncommon::upload_embedded('coursedoc',$destination,
7102: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
7103: $actionurl);
7104: $r->print($result.&return_to_editor());
7105: } elsif ($env{'form.phase'} eq 'check_embedded') {
7106: # Process file upload - phase three - modify references in HTML file
7107: $uploadphase = 'modified_orightml';
7108: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7109: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7110: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 7111: my $result =
1.482 raeburn 7112: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
7113: $docuname,$docudom,undef,
7114: $dir_root);
1.630 raeburn 7115: $r->print($result.&return_to_editor());
1.476 raeburn 7116: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
7117: $uploadphase = 'decompress_phase_one';
7118: $r->print(&decompression_phase_one().
7119: &return_to_editor());
7120: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
7121: $uploadphase = 'decompress_phase_two';
7122: $r->print(&decompression_phase_two().
7123: &return_to_editor());
1.329 droeschl 7124: }
7125: }
7126:
1.484 raeburn 7127: if ($allowed && $toolsflag) {
7128: $r->print(&startContentScreen('tools'));
1.708 raeburn 7129: $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom));
1.484 raeburn 7130: $r->print(&endContentScreen());
7131: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 7132: # -----------------------------------------------------------------------------
7133: my %lt=&Apache::lonlocal::texthash(
7134: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 7135: 'upfi' => 'Upload File',
1.553 raeburn 7136: 'upld' => 'Upload Content',
1.706 raeburn 7137: 'srch' => 'Search Repository',
7138: 'impo' => 'Import from Repository',
1.487 raeburn 7139: 'lnks' => 'Import from Stored Links',
1.502 raeburn 7140: 'impm' => 'Import from Assembled Map',
1.630 raeburn 7141: 'imcr' => 'Import from Course Resources',
1.598 raeburn 7142: 'extr' => 'External Resource',
7143: 'extt' => 'External Tool',
1.329 droeschl 7144: 'selm' => 'Select Map',
7145: 'load' => 'Load Map',
7146: 'newf' => 'New Folder',
7147: 'newp' => 'New Composite Page',
7148: 'syll' => 'Syllabus',
1.425 raeburn 7149: 'navc' => 'Table of Contents',
1.343 biermanm 7150: 'sipa' => 'Simple Course Page',
1.329 droeschl 7151: 'sipr' => 'Simple Problem',
1.630 raeburn 7152: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 7153: 'stpr' => 'Standard Problem',
7154: 'news' => 'New sub-directory',
7155: 'crpr' => 'Create Problem',
1.689 raeburn 7156: 'swit' => 'Switch Server',
1.329 droeschl 7157: 'drbx' => 'Drop Box',
1.451 www 7158: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 7159: 'bull' => 'Discussion Board',
1.347 weissno 7160: 'mypi' => 'My Personal Information Page',
1.353 weissno 7161: 'grpo' => 'Group Portfolio',
1.329 droeschl 7162: 'rost' => 'Course Roster',
1.528 raeburn 7163: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 7164: 'imsf' => 'IMS Upload',
7165: 'imsl' => 'Upload IMS package',
1.501 raeburn 7166: 'cms' => 'Origin of IMS package',
7167: 'se' => 'Select',
1.329 droeschl 7168: 'file' => 'File',
7169: 'title' => 'Title',
1.606 raeburn 7170: 'addp' => 'Add Placeholder to course?',
7171: 'uste' => 'Use Template?',
7172: 'fnam' => 'File Name:',
7173: 'loca' => 'Location:',
7174: 'dire' => 'Directory:',
7175: 'cate' => 'Category:',
7176: 'tmpl' => 'Template:',
1.698 raeburn 7177: 'empd' => 'No resources found',
1.329 droeschl 7178: 'comment' => 'Comment',
1.403 raeburn 7179: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 7180: 'bb5' => 'Blackboard 5',
7181: 'bb6' => 'Blackboard 6',
7182: 'angel5' => 'ANGEL 5.5',
7183: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 7184: 'yes' => 'Yes',
7185: 'no' => 'No',
1.618 raeburn 7186: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 7187: );
1.329 droeschl 7188: # -----------------------------------------------------------------------------
1.595 musolffc 7189:
7190: # Calculate free quota space for a user or course. A javascript function checks
7191: # file size to determine if upload should be allowed.
7192: my $quotatype = 'unofficial';
7193: if ($crstype eq 'Community') {
1.601 raeburn 7194: $quotatype = 'community';
7195: } elsif ($crstype eq 'Placement') {
7196: $quotatype = 'placement';
1.595 musolffc 7197: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
7198: $quotatype = 'official';
7199: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
7200: $quotatype = 'textbook';
7201: }
7202: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
7203: 'course',$quotatype); # expressed in MB
7204: my $current_disk_usage = 0;
7205: foreach my $subdir ('docs','supplemental') {
7206: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
7207: "userfiles/$subdir",1); # expressed in kB
7208: }
7209: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 7210: my $usage = $current_disk_usage/1024; # in MB
7211: my $quota = $disk_quota;
7212: my $percent;
7213: if ($disk_quota == 0) {
7214: $percent = 100.0;
7215: } else {
1.619 raeburn 7216: $percent = 100*($usage/$disk_quota);
1.605 raeburn 7217: }
7218: $usage = sprintf("%.2f",$usage);
7219: $quota = sprintf("%.2f",$quota);
7220: $percent = sprintf("%.0f",$percent);
7221: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
7222: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 7223:
1.329 droeschl 7224: my $fileupload=(<<FIUP);
1.605 raeburn 7225: $quotainfo
1.329 droeschl 7226: $lt{'file'}:<br />
7227: FIUP
7228: my $checkbox=(<<CHBO);
7229: <!-- <label>$lt{'parse'}?
7230: <input type="checkbox" name="parserflag" />
7231: </label> -->
7232: <label>
1.611 raeburn 7233: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 7234: </label>
7235: CHBO
1.501 raeburn 7236: my $imsfolder = $env{'form.folder'};
7237: if ($imsfolder eq '') {
7238: $imsfolder = 'default';
7239: }
7240: my $imspform=(<<IMSFORM);
7241: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
7242: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
7243: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 7244: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 7245: <legend>$lt{'imsf'}</legend>
7246: $fileupload
1.702 raeburn 7247: <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
7248: <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501 raeburn 7249: <br />
7250: <p>
7251: $lt{'cms'}:
1.611 raeburn 7252: <select name="source" $disabled>
1.501 raeburn 7253: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 7254: <option value="bb5">$lt{'bb5'}</option>
7255: <option value="bb6">$lt{'bb6'}</option>
7256: <option value="angel5">$lt{'angel5'}</option>
7257: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 7258: </select>
7259: <input type="hidden" name="folder" value="$imsfolder" />
7260: </p>
7261: <input type="hidden" name="phase" value="one" />
1.611 raeburn 7262: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 7263: </fieldset>
7264: </form>
7265: IMSFORM
1.329 droeschl 7266:
7267: my $fileuploadform=(<<FUFORM);
1.501 raeburn 7268: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
7269: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
7270: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 7271: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 7272: <legend>$lt{'upfi'}</legend>
1.371 tempelho 7273: <input type="hidden" name="active" value="aa" />
1.595 musolffc 7274: $fileupload
1.702 raeburn 7275: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
7276: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 7277: <br />
7278: $lt{'title'}:<br />
1.611 raeburn 7279: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 7280: $pathitem
1.329 droeschl 7281: <input type="hidden" name="cmd" value="upload_default" />
7282: <br />
1.458 raeburn 7283: <span class="LC_nobreak" style="float:left">
1.329 droeschl 7284: $checkbox
7285: </span>
1.501 raeburn 7286: <br clear="all" />
1.611 raeburn 7287: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 7288: </fieldset>
7289: </form>
1.383 tempelho 7290: FUFORM
1.329 droeschl 7291:
1.611 raeburn 7292: my $mapimportjs;
7293: if ($canedit) {
7294: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
7295: } else {
7296: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
7297: }
1.502 raeburn 7298: my $importpubform=(<<SEDFFORM);
1.514 raeburn 7299: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 7300: $lt{'impm'}</a>$help{'Load_Map'}
7301: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 7302: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 7303: <legend>$lt{'impm'}</legend>
1.371 tempelho 7304: <input type="hidden" name="active" value="bb" />
1.502 raeburn 7305: $lt{'copm'}<br />
7306: <span class="LC_nobreak">
7307: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 7308: onfocus="this.blur();$mapimportjs" $disabled />
7309: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
7310: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 7311: </fieldset>
7312: </form>
7313:
1.383 tempelho 7314: SEDFFORM
1.706 raeburn 7315: my ($importcrsresform,$checkcrsres);
7316: if ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'}) {
7317: $checkcrsres = 1;
7318: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'} ne '0') {
7319: my %domdefs=&Apache::lonnet::get_domain_defaults($coursedom);
1.710 raeburn 7320: my $type = lc($env{'course.'.$env{'request.course.id'}.'.type'});
7321: unless (($type eq 'community') || ($type eq 'placement')) {
7322: $type = 'unofficial';
7323: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'} ne '') {
7324: $type = 'official';
7325: } elsif ($env{'course.'.$env{'request.course.id'}.'internal.textbook'} ne '') {
7326: $type = 'textbook';
7327: } else {
7328: $type = 'unofficial';
7329: }
7330: }
7331: if ($domdefs{$type.'crsauthor'}) {
1.706 raeburn 7332: $checkcrsres = 1;
7333: }
7334: }
7335: if ($checkcrsres) {
7336: my ($numdirs,$pickfile) =
7337: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
7338: "resize_scrollbox('contentscroll','1','0');",
7339: undef,'res');
7340: if ($pickfile) {
7341: $importcrsresform=(<<CRSFORM);
1.690 raeburn 7342: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 7343: $lt{'imcr'}</a>$help{'Course_Resources'}
7344: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
7345: <fieldset id="importcrsresform" style="display: none;">
7346: <legend>$lt{'imcr'}</legend>
1.698 raeburn 7347: <div id="importcrsrescontent" style="display: none;">
1.606 raeburn 7348: <input type="hidden" name="active" value="bb" />
7349: $pickfile
7350: <p>
1.699 raeburn 7351: $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606 raeburn 7352: </p>
7353: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 7354: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698 raeburn 7355: </div>
7356: <div id="importcrsresempty" style="display: none;">
7357: <p>
7358: $lt{'empd'}
7359: </p>
7360: </div>
1.606 raeburn 7361: </fieldset>
7362: </form>
7363: CRSFORM
1.706 raeburn 7364: }
1.606 raeburn 7365: }
7366:
1.611 raeburn 7367: my $fromstoredjs;
7368: if ($canedit) {
7369: $fromstoredjs = 'open_StoredLinks_Import()';
7370: } else {
7371: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
7372: }
7373:
1.502 raeburn 7374: my @importpubforma = (
1.706 raeburn 7375: { '<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 7376: { '<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 7377: { '<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 7378: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
7379: );
1.706 raeburn 7380: if ($importcrsresform) {
7381: 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 7382: }
1.502 raeburn 7383: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 7384: my $extresourcesform =
7385: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 7386: $help{'Adding_External_Resource'},
7387: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 7388: my $exttoolform =
7389: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
7390: $help{'Adding_External_Tool'},undef,
7391: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 7392: \%ltitools,$disabled);
1.329 droeschl 7393: if ($allowed) {
1.492 raeburn 7394: my $folder = $env{'form.folder'};
7395: if ($folder eq '') {
7396: $folder='default';
7397: }
1.615 raeburn 7398: if ($canedit) {
7399: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
7400: if ($output) {
7401: $r->print($output);
7402: }
1.538 raeburn 7403: }
1.337 ehlerst 7404: $r->print(<<HIDDENFORM);
7405: <form name="renameform" method="post" action="/adm/coursedocs">
7406: <input type="hidden" name="title" />
7407: <input type="hidden" name="cmd" />
7408: <input type="hidden" name="markcopy" />
7409: <input type="hidden" name="copyfolder" />
7410: $containertag
7411: </form>
1.633 raeburn 7412: <form name="aliasform" method="post" action="/adm/coursedocs">
7413: <input type="hidden" name="alias" />
7414: <input type="hidden" name="cmd" />
7415: $containertag
7416: </form>
1.484 raeburn 7417:
1.337 ehlerst 7418: HIDDENFORM
1.508 raeburn 7419: $r->print(&makesimpleeditform($pathitem)."\n".
7420: &makedocslogform($pathitem."\n".
1.484 raeburn 7421: '<input type="hidden" name="folder" value="'.
7422: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 7423: }
1.442 www 7424:
7425: # Generate the tabs
1.510 raeburn 7426: my ($mode,$needs_end);
1.472 raeburn 7427: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 7428: my @folders = split('&',$env{'form.folderpath'});
7429: unless (@folders > 2) {
7430: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
7431: $needs_end = 1;
7432: }
1.472 raeburn 7433: } else {
1.484 raeburn 7434: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 7435: $needs_end = 1;
1.472 raeburn 7436: }
1.443 www 7437:
1.442 www 7438: #
1.622 raeburn 7439: my $hostname = $r->hostname();
1.442 www 7440: my $savefolderpath;
7441:
1.395 raeburn 7442: if ($allowed) {
1.329 droeschl 7443: my $folder=$env{'form.folder'};
1.615 raeburn 7444: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 7445: $folder='default';
1.356 tempelho 7446: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 7447: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 7448: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 7449: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
7450: }
7451: my $postexec='';
7452: if ($folder eq 'default') {
1.653 raeburn 7453: my $windowname = 'loncapaclient';
7454: if ($env{'request.lti.login'}) {
7455: $windowname .= 'lti';
7456: }
1.372 bisitz 7457: $r->print('<script type="text/javascript">'."\n"
7458: .'// <![CDATA['."\n"
1.653 raeburn 7459: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 7460: .'// ]]>'."\n"
7461: .'</script>'."\n"
1.369 bisitz 7462: );
1.329 droeschl 7463: } else {
7464: #$postexec='self.close();';
7465: }
1.504 raeburn 7466: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
7467: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 7468: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
7469:
7470: my $newnavform=(<<NNFORM);
7471: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 7472: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7473: $pathitem
1.329 droeschl 7474: <input type="hidden" name="importdetail"
7475: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 7476: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 7477: $help{'Navigate_Content'}
7478: </form>
7479: NNFORM
7480: my $newsmppageform=(<<NSPFORM);
7481: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 7482: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7483: $pathitem
1.329 droeschl 7484: <input type="hidden" name="importdetail" value="" />
1.423 onken 7485: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 7486: $help{'Simple Page'}
1.329 droeschl 7487: </form>
7488: NSPFORM
7489:
7490: my $newsmpproblemform=(<<NSPROBFORM);
7491: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 7492: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7493: $pathitem
1.329 droeschl 7494: <input type="hidden" name="importdetail" value="" />
1.423 onken 7495: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 7496: $help{'Simple_Problem'}
1.329 droeschl 7497: </form>
7498:
7499: NSPROBFORM
7500:
7501: my $newdropboxform=(<<NDBFORM);
7502: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 7503: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7504: $pathitem
1.329 droeschl 7505: <input type="hidden" name="importdetail" value="" />
1.423 onken 7506: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 7507: $help{'Dropbox'}
1.344 bisitz 7508: </form>
1.329 droeschl 7509: NDBFORM
7510:
7511: my $newexuploadform=(<<NEXUFORM);
7512: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 7513: <input type="hidden" name="active" value="dd" />
1.508 raeburn 7514: $pathitem
1.329 droeschl 7515: <input type="hidden" name="importdetail" value="" />
1.423 onken 7516: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 7517: $help{'Score_Upload_Form'}
7518: </form>
7519: NEXUFORM
7520:
7521: my $newbulform=(<<NBFORM);
7522: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 7523: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7524: $pathitem
1.329 droeschl 7525: <input type="hidden" name="importdetail" value="" />
1.423 onken 7526: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 7527: $help{'Bulletin Board'}
7528: </form>
7529: NBFORM
7530:
7531: my $newaboutmeform=(<<NAMFORM);
7532: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 7533: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7534: $pathitem
1.329 droeschl 7535: <input type="hidden" name="importdetail"
7536: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7537: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 7538: $help{'My Personal Information Page'}
1.329 droeschl 7539: </form>
7540: NAMFORM
7541:
7542: my $newaboutsomeoneform=(<<NASOFORM);
7543: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 7544: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7545: $pathitem
1.329 droeschl 7546: <input type="hidden" name="importdetail" value="" />
1.423 onken 7547: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 7548: </form>
7549: NASOFORM
7550:
7551: my $newrosterform=(<<NROSTFORM);
7552: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 7553: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7554: $pathitem
1.329 droeschl 7555: <input type="hidden" name="importdetail"
7556: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 7557: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 7558: $help{'Course_Roster'}
1.329 droeschl 7559: </form>
7560: NROSTFORM
7561:
1.534 raeburn 7562: my $newwebpage;
7563: if ($folder =~ /^default_?(\d*)$/) {
7564: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
7565: if ($1) {
7566: $newwebpage .= $1;
7567: } else {
7568: $newwebpage .= 'default';
7569: }
7570: $newwebpage .= '/new.html';
7571: }
7572: my $newwebpageform =(<<NWEBFORM);
7573: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 7574: <input type="hidden" name="active" value="ff" />
1.534 raeburn 7575: $pathitem
7576: <input type="hidden" name="importdetail" value="$newwebpage" />
7577: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 7578: $help{'Web_Page'}
1.534 raeburn 7579: </form>
7580: NWEBFORM
1.701 raeburn 7581: my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606 raeburn 7582: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 7583: my $machines_str = "'".join("','",@ids)."'";
7584: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 7585: if ($env{'user.author'}) {
7586: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 7587: $is_home{'author'} = 1;
1.606 raeburn 7588: }
1.691 raeburn 7589: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 7590: }
7591: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
7592: ['active'],['ca','aa']);
1.691 raeburn 7593: my %by_roletype;
1.606 raeburn 7594: if (keys(%roleshash)) {
7595: foreach my $entry (keys(%roleshash)) {
7596: my ($auname,$audom,$roletype) = split(/:/,$entry);
7597: my $key = $entry;
7598: $key =~ s/:/___/g;
1.691 raeburn 7599: my $author = $auname.'___'.$audom;
7600: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 7601: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 7602: $toppath{$author} = "/priv/$audom/$auname";
7603: if (grep(/^\Q$rolehome\E$/,@ids)) {
7604: $is_home{$author} = 1;
1.606 raeburn 7605: }
1.691 raeburn 7606: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
7607: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 7608: }
1.691 raeburn 7609: }
7610: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
7611: if (grep(/^\Q$crshome\E$/,@ids)) {
7612: $is_home{'course'} = 1;
7613: }
7614: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
7615: my $pickdir = $lt{'loca'}.
7616: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
7617: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
7618: if ($env{'user.author'}) {
7619: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
7620: }
7621: if (keys(%by_roletype)) {
7622: foreach my $possrole ('ca','aa') {
7623: if (ref($by_roletype{$possrole}) eq 'HASH') {
7624: my $roletitle = &Apache::lonnet::plaintext($possrole);
7625: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
7626: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
7627: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
7628: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 7629: }
7630: }
7631: }
7632: }
1.706 raeburn 7633: if ($checkcrsres) {
7634: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n";
7635: }
7636: $pickdir .= '</select><br />'."\n".
1.691 raeburn 7637: $lt{'dire'}.
7638: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
7639: '<option value=""></option>'.
7640: '</select><br />'."\n";
1.606 raeburn 7641: my %seltemplate_menus;
7642: my @files = &Apache::lonhomework::get_template_list('problem');
7643: my @noexamplelink = ('blank.problem','blank.library','script.library');
7644: my $currentcategory = '';
7645: my @ordered = ('');
7646: my %templatehelp;
7647: my $defcategory = '';
7648: my @catorder = ($defcategory);
7649: $seltemplate_menus{$defcategory}->{'order'} = [''];
7650: $seltemplate_menus{$defcategory}->{'text'} = '';
7651: foreach my $file (@files) {
7652: if (ref($file) eq 'ARRAY') {
7653: my ($path,$title,$category,$help) = @{$file};
7654: next if ($title !~ /\S/);
7655: if (&js_escape($category) ne $currentcategory) {
7656: $currentcategory = &js_escape($category);
7657: push(@catorder,&js_escape($currentcategory));
7658: $seltemplate_menus{$currentcategory}->{'text'} = $category;
7659: $seltemplate_menus{$currentcategory}->{'default'} = '';
7660: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
7661: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
7662: }
7663: if ($path) {
7664: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
7665: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
7666: if ($help) {
7667: $templatehelp{$path} = $help;
7668: }
7669: }
7670: }
7671: }
7672:
7673: my $templates = $lt{'cate'}.' '.
7674: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
7675: $defcategory,'tempcategory','template',
7676: \%seltemplate_menus,\@catorder,
7677: "resize_scrollbox('contentscroll','1','0');",
7678: "toggleExampleText();",'template').'<br />';
7679: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
1.701 raeburn 7680: '<span id="newresexample">'.&mt('Example').'</span></a>';
1.706 raeburn 7681: my $crsresform;
7682: if (($env{'user.author'}) || ($checkcrsres)) {
7683: $crsresform=(<<RESFORM);
1.691 raeburn 7684: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.706 raeburn 7685: $lt{'stpr'}</a>$help{'Standard_Problem'}
1.606 raeburn 7686: <form action="/adm/coursedocs" method="post" name="courseresform">
7687: <fieldset id="crsresform" style="display:none;">
7688: <legend>$lt{'stpr'}</legend>
1.655 raeburn 7689: <input type="hidden" name="active" value="bb" />
1.606 raeburn 7690: <p>
7691: $pickdir
1.701 raeburn 7692: </p>
1.691 raeburn 7693: <div id="newstdproblem" style="display:none;">
1.701 raeburn 7694: <p>
1.606 raeburn 7695: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 7696: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 7697:
1.611 raeburn 7698: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 7699: </span><span id="newsubdir"></span>
7700: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701 raeburn 7701: </p>
1.699 raeburn 7702: </div>
1.606 raeburn 7703: $lt{'fnam'}
1.611 raeburn 7704: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.701 raeburn 7705: <div id="newresource" style="display:none">
1.606 raeburn 7706: <p>
7707: $lt{'addp'}
1.611 raeburn 7708: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 7709: $lt{'no'}</label>
1.611 raeburn 7710: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 7711: $lt{'yes'}</label>
7712: <span id="newrestitle"></span>
1.611 raeburn 7713: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701 raeburn 7714: </p>
1.606 raeburn 7715: </div>
7716: <p>
7717: $lt{'uste'}
1.611 raeburn 7718: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 7719: $lt{'no'}</label>
1.611 raeburn 7720: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 7721: $lt{'yes'}</label>
1.701 raeburn 7722: </p>
1.606 raeburn 7723: <div id="newrestemplate" style="display:none">
7724: $templates
7725: $templatepreview
7726: </div>
7727: <span class="LC_nobreak">
1.701 raeburn 7728: <input type="hidden" name="folderpath" value="$showpath" />
1.611 raeburn 7729: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 7730: </span>
1.691 raeburn 7731: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 7732: $rolehomes
7733: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
7734: </div>
1.606 raeburn 7735: </fieldset>
7736: </form>
7737:
7738: RESFORM
1.706 raeburn 7739: }
1.534 raeburn 7740:
1.342 ehlerst 7741: my $specialdocumentsform;
1.383 tempelho 7742: my @specialdocumentsforma;
1.451 www 7743: my $gradingform;
7744: my @gradingforma;
7745: my $communityform;
7746: my @communityforma;
1.351 ehlerst 7747: my $newfolderform;
1.390 tempelho 7748: my $newfolderb;
1.342 ehlerst 7749:
1.451 www 7750: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 7751:
1.329 droeschl 7752: my $newpageform=(<<NPFORM);
7753: <form action="/adm/coursedocs" method="post" name="newpage">
7754: <input type="hidden" name="folderpath" value="$path" />
7755: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 7756: <input type="hidden" name="active" value="ee" />
1.423 onken 7757: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 7758: $help{'Adding_Pages'}
1.329 droeschl 7759: </form>
7760: NPFORM
1.390 tempelho 7761:
7762:
1.351 ehlerst 7763: $newfolderform=(<<NFFORM);
1.329 droeschl 7764: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 7765: $pathitem
1.329 droeschl 7766: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 7767: <input type="hidden" name="active" value="" />
1.422 onken 7768: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 7769: </form>
7770: NFFORM
7771:
7772: my $newsylform=(<<NSYLFORM);
7773: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 7774: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7775: $pathitem
1.329 droeschl 7776: <input type="hidden" name="importdetail"
7777: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 7778: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 7779: $help{'Syllabus'}
1.383 tempelho 7780:
1.329 droeschl 7781: </form>
7782: NSYLFORM
1.364 bisitz 7783:
1.329 droeschl 7784: my $newgroupfileform=(<<NGFFORM);
7785: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 7786: <input type="hidden" name="active" value="ee" />
1.508 raeburn 7787: $pathitem
1.329 droeschl 7788: <input type="hidden" name="importdetail"
7789: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 7790: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 7791: $help{'Group Portfolio'}
1.329 droeschl 7792: </form>
7793: NGFFORM
1.672 raeburn 7794: if ($container eq 'page') {
7795: @specialdocumentsforma=(
7796: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
7797: );
7798: } else {
7799: @specialdocumentsforma=(
1.421 onken 7800: {'<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 7801: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 7802: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 7803: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 7804: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 7805: );
7806: }
1.451 www 7807: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
7808:
1.655 raeburn 7809: my @external = (
7810: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 7811: );
1.699 raeburn 7812: if ($posslti) {
1.655 raeburn 7813: push(@external,
7814: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
7815: );
1.598 raeburn 7816: }
1.655 raeburn 7817: my $externalform = &create_form_ul(&create_list_elements(@external));
7818:
7819: my @importdoc = ();
1.519 raeburn 7820: unless ($container eq 'page') {
7821: push(@importdoc,
7822: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
7823: );
7824: }
7825: push(@importdoc,
1.558 raeburn 7826: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 7827: );
1.501 raeburn 7828: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 7829:
1.451 www 7830: @gradingforma=(
7831: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
7832: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
1.706 raeburn 7833: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
1.451 www 7834: );
1.706 raeburn 7835: if ($crsresform) {
7836: push(@gradingforma,
7837: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform}
7838: );
7839: }
1.451 www 7840: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
7841:
7842: @communityforma=(
7843: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
7844: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
7845: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 7846: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
7847: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 7848: );
7849: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 7850:
1.330 tempelho 7851: my %orderhash = (
1.553 raeburn 7852: 'aa' => ['Upload',$fileuploadform],
1.707 raeburn 7853: 'bb' => ['External',$externalform],
7854: 'cc' => ['Import',$importpubform],
1.701 raeburn 7855: 'dd' => ['Assessment',$gradingform],
1.673 raeburn 7856: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 7857: );
1.519 raeburn 7858: unless ($container eq 'page') {
1.434 raeburn 7859: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 7860: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 7861: }
7862:
1.341 ehlerst 7863: $hadchanges=0;
1.484 raeburn 7864: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 7865: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 7866: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 7867: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 7868: undef($navmap);
1.443 www 7869: if ($error) {
7870: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7871: }
1.639 raeburn 7872: if ($hadchanges) {
7873: unless (&is_hash_old()) {
1.638 raeburn 7874: &mark_hash_old();
7875: }
7876: }
1.341 ehlerst 7877:
1.443 www 7878: &changewarning($r,'');
7879: }
1.458 raeburn 7880: }
1.442 www 7881:
1.443 www 7882: # Supplemental documents start here
7883:
1.329 droeschl 7884: my $folder=$env{'form.folder'};
1.443 www 7885: unless ($supplementalflag) {
1.329 droeschl 7886: $folder='supplemental';
7887: }
1.685 raeburn 7888: if (($folder eq 'supplemental') &&
1.329 droeschl 7889: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 7890: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 7891: } elsif ($allowed) {
1.356 tempelho 7892: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 7893: }
1.508 raeburn 7894: $pathitem = '<input type="hidden" name="folderpath" value="'.
7895: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 7896: if ($allowed) {
7897: my $folderseq=
1.504 raeburn 7898: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 7899:
7900: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 7901: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
7902: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 7903: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 7904: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 7905: <legend>$lt{'upfi'}</legend>
1.630 raeburn 7906: <input type="hidden" name="active" value="ee" />
1.329 droeschl 7907: $fileupload
1.702 raeburn 7908: <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
7909: <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329 droeschl 7910: <br />
7911: <br />
7912: <span class="LC_nobreak">
7913: $checkbox
7914: </span>
7915: <br /><br />
7916: $lt{'comment'}:<br />
1.383 tempelho 7917: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 7918: <br />
1.508 raeburn 7919: $pathitem
1.329 droeschl 7920: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 7921: <input type='submit' value="$lt{'upld'}" />
1.700 raeburn 7922: </fieldset>
1.501 raeburn 7923: </form>
1.329 droeschl 7924: SUPDOCFORM
7925:
7926: my $supnewfolderform=(<<SNFFORM);
7927: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 7928: <input type="hidden" name="active" value="" />
1.508 raeburn 7929: $pathitem
1.329 droeschl 7930: <input type="hidden" name="importdetail" value="" />
1.423 onken 7931: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 7932: $help{'Adding_Folders'}
1.329 droeschl 7933: </form>
7934: SNFFORM
1.383 tempelho 7935:
1.510 raeburn 7936: my $supextform =
7937: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 7938: $help{'Adding_External_Resource'},
7939: undef,undef,undef,undef,undef,undef,
7940: $disabled);
1.329 droeschl 7941:
1.598 raeburn 7942: my $supexttoolform =
7943: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
7944: $help{'Adding_External_Tool'},
7945: undef,undef,'tool',$coursedom,
1.611 raeburn 7946: $coursenum,\%ltitools,$disabled);
1.598 raeburn 7947:
1.329 droeschl 7948: my $supnewsylform=(<<SNSFORM);
7949: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 7950: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7951: $pathitem
1.329 droeschl 7952: <input type="hidden" name="importdetail"
7953: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 7954: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 7955: $help{'Syllabus'}
7956: </form>
7957: SNSFORM
7958:
7959: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 7960: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 7961: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7962: $pathitem
1.329 droeschl 7963: <input type="hidden" name="importdetail"
7964: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7965: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 7966: $help{'My Personal Information Page'}
1.329 droeschl 7967: </form>
7968: SNAMFORM
7969:
1.534 raeburn 7970: my $supwebpage;
7971: if ($folder =~ /^supplemental_?(\d*)$/) {
7972: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
7973: if ($1) {
7974: $supwebpage .= $1;
7975: } else {
7976: $supwebpage .= 'default';
7977: }
7978: $supwebpage .= '/new.html';
7979: }
7980: my $supwebpageform =(<<SWEBFORM);
7981: <form action="/adm/coursedocs" method="post" name="supwebpage">
7982: <input type="hidden" name="active" value="cc" />
7983: $pathitem
7984: <input type="hidden" name="importdetail" value="$supwebpage" />
7985: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 7986: $help{'Web_Page'}
1.534 raeburn 7987: </form>
7988: SWEBFORM
7989:
1.333 muellerd 7990:
1.383 tempelho 7991: my @specialdocs = (
1.618 raeburn 7992: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 7993: =>$supnewsylform},
1.611 raeburn 7994: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 7995: =>$supnewaboutmeform},
1.534 raeburn 7996: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
7997:
1.383 tempelho 7998: );
1.655 raeburn 7999: my @supexternal = (
8000: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
8001: =>$supextform});
1.699 raeburn 8002: if ($posslti) {
1.655 raeburn 8003: push(@supexternal,
8004: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 8005: =>$supexttoolform});
8006: }
1.655 raeburn 8007: my @supimportdoc = (
1.598 raeburn 8008: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 8009: =>$supupdocform},
1.598 raeburn 8010: );
1.501 raeburn 8011:
8012: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 8013: my %suporderhash = (
1.390 tempelho 8014: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 8015: 'dd' => ['Upload',$supupdocform],
8016: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 8017: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 8018: );
1.443 www 8019: if ($supplementalflag) {
1.682 raeburn 8020: $suppchanges = 0;
8021: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
8022: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
8023: \%ltitools,$canedit,$hostname);
8024: if ($error) {
8025: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
8026: }
8027: if ($suppchanges) {
1.684 raeburn 8028: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 8029: undef($suppchanges);
8030: }
1.393 raeburn 8031: }
1.443 www 8032: } elsif ($supplementalflag) {
1.458 raeburn 8033: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 8034: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
8035: $hostname);
1.393 raeburn 8036: if ($error) {
8037: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 8038: }
1.393 raeburn 8039: }
1.389 tempelho 8040:
1.510 raeburn 8041: if ($needs_end) {
8042: $r->print(&endContentScreen());
8043: }
1.383 tempelho 8044:
1.329 droeschl 8045: if ($allowed) {
8046: $r->print('
8047: <form method="post" name="extimport" action="/adm/coursedocs">
8048: <input type="hidden" name="title" />
8049: <input type="hidden" name="url" />
8050: <input type="hidden" name="useform" />
8051: <input type="hidden" name="residx" />
8052: </form>');
8053: }
1.484 raeburn 8054: } elsif ($showdoc) {
1.329 droeschl 8055: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 8056: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 8057: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 8058: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 8059: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 8060: }
8061: }
1.630 raeburn 8062: unless ($noendpage) {
1.606 raeburn 8063: $r->print(&Apache::loncommon::end_page());
8064: }
1.329 droeschl 8065: return OK;
1.364 bisitz 8066: }
1.329 droeschl 8067:
1.440 raeburn 8068: sub embedded_form_elems {
8069: my ($phase,$primaryurl,$newidx) = @_;
8070: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 8071: $newidx =~s /\D+//g;
1.440 raeburn 8072: return <<STATE;
8073: <input type="hidden" name="folderpath" value="$folderpath" />
8074: <input type="hidden" name="cmd" value="upload_embedded" />
8075: <input type="hidden" name="newidx" value="$newidx" />
8076: <input type="hidden" name="phase" value="$phase" />
8077: <input type="hidden" name="primaryurl" value="$primaryurl" />
8078: STATE
8079: }
8080:
8081: sub embedded_destination {
8082: my $folder=$env{'form.folder'};
8083: my $destination = 'docs/';
8084: if ($folder =~ /^supplemental/) {
8085: $destination = 'supplemental/';
8086: }
8087: if (($folder eq 'default') || ($folder eq 'supplemental')) {
8088: $destination .= 'default/';
8089: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
8090: $destination .= $2.'/';
8091: }
1.634 raeburn 8092: my $newidx = $env{'form.newidx'};
8093: $newidx =~s /\D+//g;
8094: if ($newidx) {
8095: $destination .= $newidx;
8096: }
1.440 raeburn 8097: my $dir_root = '/userfiles';
8098: return ($destination,$dir_root);
8099: }
8100:
8101: sub return_to_editor {
8102: my $actionurl = '/adm/coursedocs';
8103: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
8104: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
8105: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
8106: '</a></p>';
8107: }
8108:
1.476 raeburn 8109: sub decompression_info {
8110: my ($destination,$dir_root) = &embedded_destination();
8111: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
8112: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8113: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
8114: my $container='sequence';
1.480 raeburn 8115: my ($pathitem,$hiddenelem);
1.583 raeburn 8116: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 8117: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 8118: $container='page';
8119: }
1.480 raeburn 8120: unshift(@hiddens,$pathitem);
8121: foreach my $item (@hiddens) {
1.634 raeburn 8122: if ($item eq 'newidx') {
8123: next if ($env{'form.'.$item} =~ /\D/);
8124: }
1.480 raeburn 8125: if ($env{'form.'.$item}) {
8126: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 8127: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 8128: }
1.477 raeburn 8129: }
1.476 raeburn 8130: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
8131: $hiddenelem);
8132: }
8133:
8134: sub decompression_phase_one {
8135: my ($dir,$file,$warning,$error,$output);
8136: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8137: &decompression_info();
1.490 raeburn 8138: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 8139: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
8140: } else {
8141: my $file = $1;
1.630 raeburn 8142: $output =
1.481 raeburn 8143: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
8144: $destination,$dir_root,
8145: $hiddenelem);
8146: if ($env{'form.autoextract_camtasia'}) {
8147: $output .= &remove_archive($docudom,$docuname,$container);
8148: }
1.476 raeburn 8149: }
8150: if ($error) {
8151: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
8152: $error.'</p>'."\n";
8153: }
8154: if ($warning) {
8155: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
8156: }
8157: return $output;
8158: }
8159:
8160: sub decompression_phase_two {
8161: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
8162: &decompression_info();
1.481 raeburn 8163: my $output;
1.480 raeburn 8164: if ($env{'form.archivedelete'}) {
1.481 raeburn 8165: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 8166: }
8167: $output .=
1.481 raeburn 8168: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 8169: $destination,$dir_root,$hiddenelem);
8170: return $output;
8171: }
8172:
1.480 raeburn 8173: sub remove_archive {
8174: my ($docudom,$docuname,$container) = @_;
8175: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 8176: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 8177: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
8178: if ($fatal) {
8179: if ($container eq 'page') {
8180: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
8181: } else {
8182: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
8183: }
1.583 raeburn 8184: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8185: } else {
8186: my $currcmd = $env{'form.cmd'};
8187: my $position = $env{'form.position'};
1.583 raeburn 8188: my $archiveidx = $position;
1.563 raeburn 8189: if ($position > 0) {
1.583 raeburn 8190: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
8191: $archiveidx = $position-1;
8192: }
8193: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 8194: my ($title,$url,@rrest) =
1.583 raeburn 8195: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
8196: if ($url eq $env{'form.archiveurl'}) {
8197: if (&handle_edit_cmd($docuname,$docudom)) {
8198: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 8199: if ($suppchanges) {
8200: &Apache::lonnet::update_supp_caches($docudom,$docuname);
8201: undef($suppchanges);
8202: }
1.583 raeburn 8203: if ($fatal) {
8204: if ($container eq 'page') {
8205: $delwarning = &mt('An error occurred updating the contents of the current page.');
8206: } else {
8207: $delwarning = &mt('An error occurred updating the contents of the current folder.');
8208: }
1.480 raeburn 8209: } else {
1.583 raeburn 8210: $delresult = &mt('Archive file removed.');
1.480 raeburn 8211: }
8212: }
1.583 raeburn 8213: } else {
8214: $delwarning .= &mt('Archive file had unexpected item number in folder.').
8215: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 8216: }
8217: }
8218: $env{'form.cmd'} = $currcmd;
8219: }
8220: if ($delwarning) {
8221: $output = '<p class="LC_warning">'.
8222: $delwarning.
8223: '</p>';
8224: }
8225: if ($delresult) {
8226: $output .= '<p class="LC_info">'.
8227: $delresult.
8228: '</p>';
8229: }
1.481 raeburn 8230: return $output;
1.480 raeburn 8231: }
8232:
1.484 raeburn 8233: sub generate_admin_menu {
1.708 raeburn 8234: my ($crstype,$canedit,$coursenum,$coursedom) = @_;
1.484 raeburn 8235: my $lc_crstype = lc($crstype);
8236: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 8237: my %lt= ( # do not translate here
1.484 raeburn 8238: 'vc' => 'Verify Content',
8239: 'cv' => 'Check/Set Resource Versions',
8240: 'ls' => 'List Resource Identifiers',
1.651 raeburn 8241: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.708 raeburn 8242: 'ca' => "Enter $crstype Authoring Space",
1.484 raeburn 8243: 'imse' => 'Export contents to IMS Archive',
1.712 raeburn 8244: 'dcd' => 'Copy uploaded content to Authoring Space',
8245: 'cpc' => 'Copy from Course Authoring to User Authoring',
1.562 bisitz 8246: );
1.712 raeburn 8247: my ($candump,$dumpurl,$exportcrsurl);
1.484 raeburn 8248: if ($home + $other > 0) {
8249: $candump = 'F';
8250: if ($home) {
8251: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
1.712 raeburn 8252: $exportcrsurl = "javascript:injectData(document.courseverify,'dummy','copyauthored','$lt{'cpc'}')";
1.484 raeburn 8253: } else {
8254: my @hosts;
8255: foreach my $aurole (keys(%outhash)) {
8256: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
8257: push(@hosts,$outhash{$aurole});
1.538 raeburn 8258: }
1.484 raeburn 8259: }
8260: if (@hosts == 1) {
8261: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
8262: '&role='.
8263: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
8264: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
8265: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
1.712 raeburn 8266: $exportcrsurl = $dumpurl;
1.484 raeburn 8267: } else {
8268: $dumpurl = "javascript:choose_switchserver_window()";
1.712 raeburn 8269: $exportcrsurl = $dumpurl;
1.484 raeburn 8270: }
8271: }
8272: }
8273: my @menu=
8274: ({ categorytitle=>'Administration',
8275: items =>[
8276: { linktext => $lt{'vc'},
8277: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
8278: permission => 'F',
1.571 raeburn 8279: help => 'Docs_Verify_Content',
1.484 raeburn 8280: icon => 'verify.png',
8281: linktitle => 'Verify contents can be retrieved/rendered',
8282: },
8283: { linktext => $lt{'cv'},
8284: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
8285: permission => 'F',
1.571 raeburn 8286: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 8287: icon => 'resversion.png',
8288: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
8289: },
8290: { linktext => $lt{'ls'},
8291: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
8292: permission => 'F',
8293: #help => '',
8294: icon => 'symbs.png',
8295: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
8296: },
1.651 raeburn 8297: { linktext => $lt{'ct'},
8298: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
8299: permission => 'F',
8300: help => 'Docs_Short_URLs',
8301: icon => 'shorturls.png',
8302: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
8303: },
1.484 raeburn 8304: ]
1.611 raeburn 8305: });
8306: if ($canedit) {
1.708 raeburn 8307: my ($crsauname,$crsaudom,$crshome);
8308: if (($coursenum ne '') && ($coursedom ne '')) {
8309: my $crsauthorurl = "/priv/$coursedom/$coursenum/";
8310: ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl);
8311: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8312: my @ids=&Apache::lonnet::current_machine_ids();
8313: my $linkurl;
8314: if (grep(/^\Q$crshome\E$/,@ids)) {
8315: $linkurl = $crsauthorurl;
8316: } else {
8317: $linkurl =
8318: &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1);
8319: }
8320: if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY')) {
8321: push(@{$menu[0]->{items}},
8322: { linktext => $lt{'ca'},
8323: url => $linkurl,
8324: permission => 'F',
8325: help => 'Docs_Course_Authorspace',
8326: icon => 'impcrsau.png',
8327: linktitle => $lt{'ca'},
8328: });
8329: }
8330: }
8331: }
1.611 raeburn 8332: push(@menu,
1.484 raeburn 8333: { categorytitle=>'Export',
8334: items =>[
8335: { linktext => $lt{'imse'},
8336: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
8337: permission => 'F',
8338: help => 'Docs_Export_Course_Docs',
8339: icon => 'imsexport.png',
8340: linktitle => $lt{'imse'},
8341: },
8342: { linktext => $lt{'dcd'},
8343: url => $dumpurl,
8344: permission => $candump,
1.571 raeburn 8345: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 8346: icon => 'dump.png',
8347: linktitle => $lt{'dcd'},
8348: },
8349: ]
8350: });
1.712 raeburn 8351: if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
8352: if ((ref($menu[1]) eq 'HASH') && (ref($menu[1]->{'items'}) eq 'ARRAY')) {
8353: push(@{$menu[1]->{items}},
8354: { linktext => $lt{'cpc'},
8355: url => $exportcrsurl,
8356: permission => 'F',
8357: help => 'Docs_Export_Course_Author',
8358: icon => 'res.png',
8359: linktitle => $lt{'cpc'},
8360: });
8361: }
8362: }
1.611 raeburn 8363: }
1.484 raeburn 8364: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
8365: '<input type="hidden" id="dummy" />'."\n".
8366: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
8367: '</form>';
1.329 droeschl 8368: }
8369:
8370: sub generate_edit_table {
1.538 raeburn 8371: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 8372: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 8373: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 8374: my %orderhash = %{$orderhash_ref};
1.611 raeburn 8375: my ($form, $activetab, $active, $disabled);
1.570 raeburn 8376: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 8377: $activetab = $env{'form.active'};
8378: }
1.611 raeburn 8379: unless ($canedit) {
8380: $disabled = ' disabled="disabled"';
8381: }
1.472 raeburn 8382: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 8383: my $backtext = &mt('Exit Editor');
1.458 raeburn 8384: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 8385: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
8386: '<li class="goback">'.
1.546 raeburn 8387: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 8388: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
8389: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
8390: '<li>'.
8391: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
8392: &mt('Undo Delete').'</a></li>'."\n";
8393: if ($env{'form.docslog'}) {
8394: $form .= '<li class="active">';
8395: } else {
8396: $form .= '<li>';
8397: }
8398: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
8399: &mt('History').'</a></li>'."\n";
8400: if ($env{'form.docslog'}) {
8401: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
8402: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 8403: }
1.458 raeburn 8404: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 8405: if($name ne '00'){
1.371 tempelho 8406: if($activetab eq '' || $activetab ne $name){
8407: $active = '';
8408: }elsif($activetab eq $name){
8409: $active = 'class="active"';
8410: }
1.458 raeburn 8411: $form .= '<li style="float:right" '.$active
1.484 raeburn 8412: .' 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 8413: } else {
1.570 raeburn 8414: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 8415:
8416: }
1.329 droeschl 8417: }
1.484 raeburn 8418: $form .= '</ul>'."\n";
8419: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 8420:
8421: if ($to_show ne '') {
1.538 raeburn 8422: my $saveform;
8423: if ($need_save) {
8424: my $button = &mt('Make changes');
8425: my $path;
8426: if ($env{'form.folderpath'}) {
8427: $path =
8428: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
8429: }
8430: $saveform = <<"END";
8431: <div id="multisave" style="display:none; clear:both;" >
8432: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
8433: <input type="hidden" name="folderpath" value="$path" />
8434: <input type="hidden" name="symb" value="$env{'form.symb'}" />
8435: <input type="hidden" name="allhiddenresource" value="" />
8436: <input type="hidden" name="allencrypturl" value="" />
8437: <input type="hidden" name="allrandompick" value="" />
8438: <input type="hidden" name="allrandomorder" value="" />
8439: <input type="hidden" name="changeparms" value="" />
8440: <input type="hidden" name="multiremove" value="" />
8441: <input type="hidden" name="multicut" value="" />
8442: <input type="hidden" name="multicopy" value="" />
8443: <input type="hidden" name="multichange" value="" />
8444: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 8445: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 8446: </form>
8447: </div>
8448: END
8449: }
8450: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 8451: }
1.363 ehlerst 8452: foreach my $field (keys(%orderhash)){
1.390 tempelho 8453: if($field ne '00'){
1.422 onken 8454: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 8455: $active = 'style="display: none;float:left"';
1.422 onken 8456: }elsif($activetab eq $field){
1.458 raeburn 8457: $active = 'style="display:block;float:left"';
1.422 onken 8458: }
8459: $form .= '<div id="'.$field.$tid.'"'
8460: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 8461: .'</div>'."\n";
1.363 ehlerst 8462: }
8463: }
1.484 raeburn 8464: unless ($env{'form.docslog'}) {
8465: $form .= '</div></div>'."\n";
8466: }
1.329 droeschl 8467: return $form;
8468: }
8469:
8470: sub editing_js {
1.622 raeburn 8471: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
8472: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 8473: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 8474: p_mnf => 'Name of New Folder',
8475: t_mnf => 'New Folder',
8476: p_mnp => 'Name of New Page',
8477: t_mnp => 'New Page',
1.451 www 8478: p_mxu => 'Title for the External Score',
1.349 biermanm 8479: p_msp => 'Name of Simple Course Page',
1.329 droeschl 8480: p_msb => 'Title for the Problem',
8481: p_mdb => 'Title for the Drop Box',
1.336 schafran 8482: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 8483: p_mwp => 'Title for Web Page',
1.606 raeburn 8484: p_mnr => 'Title for the Resource',
1.348 weissno 8485: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 8486: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 8487: p_mab_alrt1 => 'Not a valid user:domain',
8488: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
8489: p_chn => 'New Title',
8490: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 8491: p_rmr2a => 'Remove',
8492: p_rmr2b => '?',
8493: p_rmr3a => 'Remove those',
8494: p_rmr3b => 'items?',
8495: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
8496: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 8497: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
8498: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 8499: p_ctr2a => 'Cut',
8500: p_ctr2b => '?',
8501: p_ctr3a => 'Cut those',
8502: p_ctr3b => 'items?',
1.633 raeburn 8503: setal => 'Enter a (unique) alias',
8504: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 8505: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 8506: imsfile => 'You must choose an IMS package for import',
8507: imscms => 'You must select which Course Management System was the source of the IMS package',
8508: invurl => 'Invalid URL',
8509: titbl => 'Title is blank',
1.538 raeburn 8510: more => '(More ...)',
8511: less => '(Less ...)',
1.543 raeburn 8512: noor => 'No actions selected or changes to settings specified.',
8513: noch => 'No changes to settings specified.',
8514: noac => 'No actions selected.',
1.606 raeburn 8515: nofi => 'No file selected',
8516: tinc => 'Title in course',
8517: sunm => 'Sub-directory name',
1.618 raeburn 8518: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 8519: sele => 'Select',
8520: swit => 'Switch server required',
1.329 droeschl 8521: );
1.594 damieng 8522: &js_escape(\%js_lt);
1.433 raeburn 8523: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 8524: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
8525: my $main_container_page;
1.519 raeburn 8526: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
8527: $main_container_page = 1;
1.434 raeburn 8528: }
1.617 raeburn 8529: my $backtourl;
8530: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 8531: my $toplevelsupp = &supplemental_base();
1.690 raeburn 8532: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 8533: my @ids=&Apache::lonnet::current_machine_ids();
8534: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 8535: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
8536: my $caller = $1;
1.525 raeburn 8537: if ($caller =~ /^supplemental/) {
8538: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
8539: } else {
8540: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
8541: $res = &Apache::lonnet::clutter($res);
8542: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 8543: my ($url,$anchor);
8544: if ($res =~ /^([^#]+)#([^#]+)$/) {
8545: $url = $1;
8546: $anchor = $2;
8547: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
8548: $caller = $1.&escape('#').$anchor;
8549: }
1.614 raeburn 8550: } else {
8551: $url = $res;
1.609 raeburn 8552: }
1.640 raeburn 8553: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
8554: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
8555: $backtourl .= '?navmap=1';
8556: } else {
8557: $backtourl .= '?symb='.
8558: &HTML::Entities::encode($caller,'<>&"');
8559: }
1.622 raeburn 8560: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
8561: if (($ENV{'SERVER_PORT'} == 443) &&
8562: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 8563: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 8564: if ($hostname ne '') {
8565: $backtourl = 'http://'.$hostname.$backtourl;
8566: }
8567: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 8568: }
8569: }
1.623 raeburn 8570: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
8571: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 8572: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 8573: if ($hostname ne '') {
8574: $backtourl = 'http://'.$hostname.$backtourl;
8575: }
8576: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 8577: }
1.623 raeburn 8578: }
1.622 raeburn 8579: }
1.609 raeburn 8580: if ($anchor ne '') {
8581: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
8582: }
1.590 raeburn 8583: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 8584: } else {
8585: $backtourl = '/adm/navmaps';
1.525 raeburn 8586: }
8587: }
8588: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
8589: $backtourl = '/adm/menu';
8590: } elsif ($supplementalflag) {
1.682 raeburn 8591: if (($env{'request.role.adv'}) ||
8592: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
8593: $backtourl = '/adm/supplemental';
8594: } else {
8595: $backtourl = '/adm/navmaps';
8596: }
1.525 raeburn 8597: } else {
8598: $backtourl = '/adm/navmaps';
1.472 raeburn 8599: }
8600:
1.655 raeburn 8601: my $fieldsets = "'doc'";
1.519 raeburn 8602: unless ($main_container_page) {
8603: $fieldsets .=",'ims'";
8604: }
1.655 raeburn 8605: my $extfieldsets = "'ext'";
8606: if ($posslti) {
8607: $extfieldsets .= ",'tool'";
8608: }
1.501 raeburn 8609: if ($supplementalflag) {
1.655 raeburn 8610: $fieldsets = "'suppdoc'";
8611: $extfieldsets = "'suppext'";
1.600 raeburn 8612: if ($posslti) {
1.655 raeburn 8613: $extfieldsets .= ",'supptool'";
1.600 raeburn 8614: }
1.501 raeburn 8615: }
1.655 raeburn 8616:
1.611 raeburn 8617: my $jsmakefunctions;
8618: if ($canedit) {
8619: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 8620: function makenewfolder(targetform,folderseq) {
1.594 damieng 8621: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 8622: if (foldername) {
1.676 raeburn 8623: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 8624: targetform.submit();
8625: }
8626: }
8627:
8628: function makenewpage(targetform,folderseq) {
1.594 damieng 8629: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 8630: if (pagename) {
1.676 raeburn 8631: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 8632: targetform.submit();
8633: }
8634: }
8635:
8636: function makeexamupload() {
1.594 damieng 8637: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 8638: if (title) {
1.329 droeschl 8639: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 8640: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 8641: this.document.forms.newexamupload.submit();
8642: }
8643: }
8644:
8645: function makesmppage() {
1.594 damieng 8646: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 8647: if (title) {
1.329 droeschl 8648: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 8649: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 8650: this.document.forms.newsmppg.submit();
8651: }
8652: }
8653:
1.534 raeburn 8654: function makewebpage(type) {
1.594 damieng 8655: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 8656: var formname;
8657: if (type == 'supp') {
8658: formname = this.document.forms.supwebpage;
8659: } else {
8660: formname = this.document.forms.newwebpage;
8661: }
8662: if (title) {
8663: var webpage = formname.importdetail.value;
1.675 raeburn 8664: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 8665: formname.submit();
8666: }
8667: }
8668:
1.329 droeschl 8669: function makesmpproblem() {
1.594 damieng 8670: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 8671: if (title) {
1.329 droeschl 8672: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 8673: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 8674: this.document.forms.newsmpproblem.submit();
8675: }
8676: }
8677:
8678: function makedropbox() {
1.594 damieng 8679: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 8680: if (title) {
1.329 droeschl 8681: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 8682: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 8683: this.document.forms.newdropbox.submit();
8684: }
8685: }
8686:
8687: function makebulboard() {
1.594 damieng 8688: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 8689: if (title) {
8690: this.document.forms.newbul.importdetail.value=
1.676 raeburn 8691: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 8692: this.document.forms.newbul.submit();
8693: }
8694: }
8695:
8696: function makeabout() {
1.594 damieng 8697: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 8698: if (user) {
8699: var comp=new Array();
8700: comp=user.split(':');
8701: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
8702: if ((comp[0]) && (comp[1])) {
8703: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 8704: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 8705: this.document.forms.newaboutsomeone.submit();
8706: } else {
8707: alert("$js_lt{'p_mab_alrt1'}");
8708: }
8709: } else {
8710: alert("$js_lt{'p_mab_alrt2'}");
8711: }
8712: }
8713: }
8714:
8715: function makenew(targetform) {
8716: targetform.submit();
8717: }
8718:
8719: function changename(folderpath,index,oldtitle) {
8720: var title=prompt('$js_lt{"p_chn"}',oldtitle);
8721: if (title) {
8722: this.document.forms.renameform.markcopy.value='';
8723: this.document.forms.renameform.title.value=title;
8724: this.document.forms.renameform.cmd.value='rename_'+index;
8725: this.document.forms.renameform.folderpath.value=folderpath;
8726: this.document.forms.renameform.submit();
8727: }
8728: }
8729:
1.633 raeburn 8730: function setalias(folderpath,index) {
8731: var alias = prompt('$js_lt{"setal"}');
8732: if ((alias != null) && (alias != '')) {
8733: this.document.forms.aliasform.alias.value=alias;
8734: this.document.forms.aliasform.cmd.value='setalias_'+index;
8735: this.document.forms.aliasform.folderpath.value=folderpath;
8736: this.document.forms.aliasform.submit();
8737: }
8738: }
8739:
8740: function delalias(folderpath,index) {
8741: if (confirm('$js_lt{"delal"}')) {
8742: this.document.forms.aliasform.cmd.value='delalias_'+index;
8743: this.document.forms.aliasform.folderpath.value=folderpath;
8744: this.document.forms.aliasform.submit();
8745: }
8746: }
8747:
1.611 raeburn 8748: ENDNEWSCRIPT
8749: } else {
8750: $jsmakefunctions = <<ENDNEWSCRIPT;
8751:
8752: function makenewfolder() {
8753: alert("$js_lt{'edri'}");
8754: }
8755:
8756: function makenewpage() {
8757: alert("$js_lt{'edri'}");
8758: }
8759:
8760: function makeexamupload() {
8761: alert("$js_lt{'edri'}");
8762: }
8763:
8764: function makesmppage() {
8765: alert("$js_lt{'edri'}");
8766: }
8767:
8768: function makewebpage(type) {
8769: alert("$js_lt{'edri'}");
8770: }
8771:
8772: function makesmpproblem() {
8773: alert("$js_lt{'edri'}");
8774: }
8775:
8776: function makedropbox() {
8777: alert("$js_lt{'edri'}");
8778: }
8779:
8780: function makebulboard() {
8781: alert("$js_lt{'edri'}");
8782: }
8783:
8784: function makeabout() {
8785: alert("$js_lt{'edri'}");
8786: }
8787:
8788: function changename() {
8789: alert("$js_lt{'edri'}");
8790: }
8791:
1.633 raeburn 8792: function setalias() {
8793: alert("$js_lt{'edri'}");
8794: }
8795:
8796: function delalias() {
8797: alert("$js_lt{'edri'}");
8798: }
8799:
1.611 raeburn 8800: function makenew() {
8801: alert("$js_lt{'edri'}");
8802: }
8803:
8804: function groupimport() {
8805: alert("$js_lt{'edri'}");
1.335 ehlerst 8806: }
1.611 raeburn 8807:
8808: function groupsearch() {
8809: alert("$js_lt{'edri'}");
1.335 ehlerst 8810: }
1.611 raeburn 8811:
8812: function groupopen(url,recover) {
8813: var options="scrollbars=1,resizable=1,menubar=0";
8814: idxflag=1;
8815: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
8816: idx.focus();
1.329 droeschl 8817: }
8818:
1.611 raeburn 8819: ENDNEWSCRIPT
8820:
8821: }
8822: return <<ENDSCRIPT;
8823:
8824: $jsmakefunctions
8825:
1.501 raeburn 8826: function toggleUpload(caller) {
8827: var blocks = Array($fieldsets);
8828: for (var i=0; i<blocks.length; i++) {
8829: var disp = 'none';
8830: if (caller == blocks[i]) {
8831: var curr = document.getElementById('upload'+caller+'form').style.display;
8832: if (curr == 'none') {
8833: disp='block';
8834: }
8835: }
8836: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 8837: }
8838: resize_scrollbox('contentscroll','1','1');
8839: return;
8840: }
8841:
8842: function toggleExternal(caller) {
8843: var blocks = Array($extfieldsets);
8844: for (var i=0; i<blocks.length; i++) {
8845: var disp = 'none';
8846: if (caller == blocks[i]) {
8847: var curr = document.getElementById('external'+caller+'form').style.display;
8848: if (curr == 'none') {
8849: disp='block';
8850: }
8851: }
8852: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 8853: if ((caller == 'tool') || (caller == 'supptool')) {
8854: if (disp == 'block') {
1.655 raeburn 8855: if (document.getElementById('LC_exttoolid')) {
8856: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 8857: var suppflag = 0;
8858: if (caller == 'supptool') {
8859: suppflag = 1;
8860: }
8861: currForm = document.getElementById('new'+caller);
1.655 raeburn 8862: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 8863: }
8864: }
8865: }
1.501 raeburn 8866: }
1.502 raeburn 8867: resize_scrollbox('contentscroll','1','1');
8868: return;
8869: }
8870:
1.514 raeburn 8871: function toggleMap(caller) {
1.502 raeburn 8872: var disp = 'none';
1.510 raeburn 8873: if (document.getElementById('importmapform')) {
1.514 raeburn 8874: if (caller == 'map') {
8875: var curr = document.getElementById('importmapform').style.display;
8876: if (curr == 'none') {
8877: disp='block';
8878: }
1.510 raeburn 8879: }
8880: document.getElementById('importmapform').style.display=disp;
1.706 raeburn 8881: if (disp == 'block') {
8882: if (document.getElementById('importcrsresform')) {
8883: if (document.getElementById('importcrsresform').style.display == 'block') {
8884: document.getElementById('importcrsresform').style.display = 'none';
8885: }
8886: }
8887: }
1.510 raeburn 8888: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 8889: }
1.501 raeburn 8890: return;
1.329 droeschl 8891: }
8892:
1.691 raeburn 8893: function toggleCrsRes(caller) {
1.606 raeburn 8894: var disp = 'none';
8895: if (document.getElementById('crsresform')) {
8896: if (caller == 'res') {
1.691 raeburn 8897: var form = document.getElementById('crsresform');
8898: var curr = form.style.display;
1.606 raeburn 8899: if (curr == 'none') {
8900: disp='block';
1.691 raeburn 8901: document.courseresform.authorrole.selectedIndex = 0;
8902: document.courseresform.authorpath.selectedIndex = 0;
8903: document.courseresform.newresourceadd.selectedIndex = 0;
8904: populateDirSelects(form,'authorrole','authorpath',1,0,0);
8905: toggleNewInCourse(document.courseresform);
8906: if (document.getElementById('newresource')) {
8907: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 8908: }
8909: if (document.courseresform.newresusetemp.length) {
8910: document.courseresform.newresusetemp[0].checked = true;
8911: toggleWithTemplate(document.courseresform);
8912: }
8913: document.courseresform.newresourcename.value = '';
8914: }
8915: }
8916: if (document.courseresform.newsubdir.length) {
8917: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
8918: if (document.courseresform.newsubdir[j].value == 0) {
8919: document.courseresform.newsubdir[j].checked = true;
8920: }
8921: break;
8922: }
8923: if (document.getElementById('newsubdirname')) {
8924: document.getElementById('newsubdirname').type = "hidden";
8925: document.getElementById('newsubdirname').value = "";
8926: }
8927: if (document.getElementById('newsubdir')) {
8928: document.getElementById('newsubdir').innerHTML = "";
8929: }
8930: }
8931: document.getElementById('crsresform').style.display=disp;
8932: resize_scrollbox('contentscroll','1','0');
8933: }
8934: return;
8935: }
8936:
8937: function toggleNewsubdir(form) {
8938: if (form.newsubdir.length) {
8939: for (var j=0; j<form.newsubdir.length; j++) {
8940: if (form.newsubdir[j].checked) {
8941: if (document.getElementById('newsubdirname')) {
8942: if (form.newsubdir[j].value == '1') {
8943: document.getElementById('newsubdirname').type = "text";
8944: if (document.getElementById('newsubdir')) {
8945: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
8946: }
8947: } else {
8948: document.getElementById('newsubdirname').type = "hidden";
8949: document.getElementById('newsubdirname').value = "";
8950: document.getElementById('newsubdir').innerHTML = "";
8951: }
8952: }
8953: break;
8954: }
8955: }
8956: }
8957: }
8958:
8959: function toggleCrsResTitle() {
8960: if (document.getElementById('newresource')) {
1.691 raeburn 8961: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8962: if (selloc == 'course') {
1.606 raeburn 8963: document.getElementById('newresource').style.display = 'inline';
8964: document.courseresform.newresourceadd[0].checked = true;
8965: toggleNewInCourse(document.courseresform);
8966: } else {
8967: document.getElementById('newresource').style.display = 'none';
8968: }
1.689 raeburn 8969: }
8970: if (document.getElementById('newstdproblem')) {
8971: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8972: document.getElementById('newstdproblem').style.display = 'none';
8973: if (document.getElementById('stdprobswitch')) {
8974: document.getElementById('stdprobswitch').style.display = 'block';
8975: }
8976: } else {
8977: document.getElementById('newstdproblem').style.display = 'block';
8978: if (document.getElementById('stdprobswitch')) {
8979: document.getElementById('stdprobswitch').style.display = 'none';
8980: }
8981: }
8982: }
1.606 raeburn 8983: }
8984:
8985: function toggleNewInCourse(form) {
8986: if (form.newresourceadd.length) {
8987: for (var i=0; i<form.newresourceadd.length; i++) {
8988: if (form.newresourceadd[i].checked) {
8989: if (document.getElementById('newresourcetitle')) {
8990: if (form.newresourceadd[i].value == '1') {
8991: document.getElementById('newresourcetitle').type = 'text';
8992: if (document.getElementById('newrestitle')) {
8993: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
8994: }
8995: } else {
8996: document.getElementById('newresourcetitle').type = 'hidden';
8997: document.getElementById('newresourcetitle').value = '';
8998: if (document.getElementById('newrestitle')) {
8999: document.getElementById('newrestitle').innerHTML = '';
9000: }
9001: }
9002: }
9003: break;
9004: }
9005: }
9006: }
9007: }
9008:
9009: function toggleWithTemplate(form) {
9010: if (form.newresusetemp.length) {
9011: for (var i=0; i<form.newresusetemp.length; i++) {
9012: if (form.newresusetemp[i].checked) {
9013: if (document.getElementById('newrestemplate')) {
9014: if (form.newresusetemp[i].value == '1') {
9015: document.getElementById('newrestemplate').style.display = 'inline';
9016: toggleExampleText();
9017: } else {
9018: form.tempcategory.selectedIndex = 0;
9019: select1template_changed();
9020: document.getElementById('newrestemplate').style.display = 'none';
9021: }
9022: }
9023: }
9024: }
9025: }
9026: }
9027:
9028: function toggleExampleText() {
9029: if (document.getElementById('newresexample')) {
9030: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9031: if (url == '') {
9032: document.getElementById('newresexample').style.fontWeight = 'normal';
9033: } else {
9034: document.getElementById('newresexample').style.fontWeight = 'bold';
9035: }
9036: }
9037: }
9038:
9039: function getExample(width,height,scrolling,transparency) {
9040: var url;
9041: if (document.courseresform.newresusetemp.length) {
9042: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
9043: if (document.courseresform.newresusetemp[i].checked) {
9044: if (document.courseresform.newresusetemp[i].value == '1') {
9045: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
9046: if (url == '') {
9047: alert('Pick a category and template');
9048: } else {
9049: url = url.replace("$londocroot","");
9050: url += '?inhibitmenu=yes';
9051: }
9052: }
9053: break;
9054: }
9055: }
9056: }
9057: if (url != '') {
9058: openMyModal(url,width,height,scrolling,transparency,'');
9059: }
9060: }
9061:
1.690 raeburn 9062: function toggleImportCrsres(caller) {
1.606 raeburn 9063: var disp = 'none';
9064: if (document.getElementById('importcrsresform')) {
9065: if (caller == 'res') {
9066: var curr = document.getElementById('importcrsresform').style.display;
9067: if (curr == 'none') {
9068: disp='block';
1.698 raeburn 9069: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
9070: if ((document.getElementById('importcrsrescontent')) &&
9071: (document.getElementById('importcrsresempty'))) {
9072: var selelem = document.crsresimportform.elements['coursepath'];
9073: var numdirs = 0;
9074: if (selelem.options.length) {
9075: numdirs = selelem.options.length - 1;
9076: }
9077: if (numdirs) {
9078: document.getElementById('importcrsrescontent').style.display='block';
9079: document.getElementById('importcrsresempty').style.display='none';
9080: } else {
9081: document.getElementById('importcrsrescontent').style.display='none';
9082: document.getElementById('importcrsresempty').style.display='block';
9083: }
9084: }
1.606 raeburn 9085: }
9086: }
9087: document.getElementById('importcrsresform').style.display=disp;
1.706 raeburn 9088: if (disp == 'block') {
9089: if (document.getElementById('importmapform')) {
9090: if (document.getElementById('importmapform').style.display == 'block') {
9091: document.getElementById('importmapform').style.display = 'none';
9092: }
9093: }
9094: }
1.606 raeburn 9095: resize_scrollbox('contentscroll','1','0');
9096: }
9097: return;
9098: }
9099:
1.690 raeburn 9100: $showfile_js
9101:
1.691 raeburn 9102: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
9103: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
9104: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
9105: var selelem = form.elements[dirsel];
9106: var i, numfiles = selelem.options.length -1;
9107: if (numfiles >=0) {
9108: for (i = numfiles; i >= 0; i--) {
9109: selelem.remove(i);
9110: }
9111: }
9112: if ((location == '') || (location == null) || (location == 'undefined')) {
9113: if (selelem.options.length == 0) {
9114: selelem.options[selelem.options.length] = new Option('','');
9115: selelem.selectedIndex = 0;
9116: }
9117: if (document.getElementById('newstdproblem')) {
9118: document.getElementById('newstdproblem').style.display = 'none';
9119: }
9120: return;
9121: }
9122: var machineIds = new Array($machines_str);
9123: var athome = 0;
9124: var role = location;
9125: if ((location == 'author') || (location == 'course')) {
9126: if (document.getElementById('rolehome_'+location)) {
9127: var currhome = document.getElementById('rolehome_'+location).value;
9128: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9129: if (machineIds.includes(currhome)) {
9130: athome = 1;
9131: }
9132: }
9133: }
9134: } else {
9135: const roleinfo = location.split('___');
9136: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
9137: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
9138: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
9139: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
9140: if (machineIds.includes(currhome)) {
9141: athome = 1;
9142: }
9143: }
9144: }
9145: }
1.706 raeburn 9146: var templateradio = document.courseresform.elements['newresusetemp'];
1.691 raeburn 9147: if (athome) {
9148: if (document.getElementById('stdprobswitch')) {
9149: document.getElementById('stdprobswitch').style.display = 'none';
9150: }
9151: if (document.getElementById('newstdproblem')) {
9152: document.getElementById('newstdproblem').style.display = 'none';
9153: }
1.706 raeburn 9154: var canedit = '$canedit';
9155: if (canedit) {
9156: if (templateradio.length > 1) {
9157: for (var i=0; i<templateradio.length; i++) {
9158: templateradio[i].disabled = false;
9159: }
9160: }
9161: document.courseresform.newresourcename.disabled = false;
9162: document.courseresform.newcrs.disabled = false;
9163: }
1.691 raeburn 9164: var http = new XMLHttpRequest();
9165: var url = "/adm/courseauthor";
1.698 raeburn 9166: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691 raeburn 9167: http.open("POST", url, true);
9168: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
9169: http.onreadystatechange = function() {
9170: if (http.readyState == 4 && http.status == 200) {
9171: var data = JSON.parse(http.responseText);
9172: if (Array.isArray(data.dirs)) {
9173: var len = data.dirs.length;
9174: if (len) {
9175: if (len > 1) {
9176: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
9177: }
9178: }
9179: if (len) {
9180: var j;
9181: for (j = 0; j < len; j++) {
9182: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
9183: }
9184: selelem.selectedIndex = 0;
1.697 raeburn 9185: if (len == 1) {
9186: toggleCrsResTitle();
9187: }
1.691 raeburn 9188: }
9189: }
9190: }
9191: }
9192: http.send(params);
9193: } else {
9194: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
9195: selelem.selectedIndex = 0;
9196: if (document.getElementById('stdprobswitch')) {
9197: document.getElementById('stdprobswitch').style.display = 'block';
9198: }
9199: if (document.getElementById('newstdproblem')) {
9200: document.getElementById('newstdproblem').style.display = 'none';
9201: }
1.706 raeburn 9202: if (templateradio.length > 1) {
9203: for (var i=0; i<templateradio.length; i++) {
9204: templateradio[i].disabled = true;
9205: }
9206: }
9207: document.courseresform.newresourcename.disabled = true;
9208: document.courseresform.newcrs.disabled = true;
1.691 raeburn 9209: }
9210: }
9211: return;
9212: }
9213:
1.689 raeburn 9214: function switchForProb() {
9215: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
9216: var url = '/adm/switchserver?otherserver=';
9217: var newhostid = '';
9218: var role = '';
9219: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
9220: if (selloc == 'author') {
9221: newhostid = document.courseresform.rolehome_author.value;
9222: role = "au./&js_escape($env{'user.domain'})/";
9223: } else if (selloc == 'course') {
9224: newhostid = document.courseresform.rolehome_course.value;
9225: role = "&js_escape($env{'request.role'})";
9226: } else {
9227: var items = new Array();
9228: items = selloc.split('___');
9229: var len = document.courseresform.rolehome_coauthor.length;
9230: if (null == len) {
9231: var currval = document.courseresform.rolehome_coauthor.value;
9232: if (null != currval) {
9233: var info = new Array();
9234: info = currval.split('=');
9235: newhostid = info[2];
9236: role = info[0]+'./'+info[1];
9237: }
9238: } else {
9239: for (var i=0; i<len; i++) {
9240: var currval = document.courseresform.rolehome_coauthor[i].value;
9241: if (null != currval) {
9242: var info = new Array();
9243: info = currval.split('=');
9244: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
9245: newhostid = info[2];
9246: role = info[0]+'./'+info[1];
9247: break;
9248: }
9249: }
9250: }
9251: }
9252: }
9253: if (newhostid != '') {
9254: url += newhostid;
9255: if (role != '') {
9256: url += '&role='+role;
9257: }
9258: document.location.href = url;
9259: }
9260: }
9261: return;
9262: }
9263:
1.501 raeburn 9264: function makeims(imsform) {
9265: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 9266: alert("$js_lt{'imsfile'}");
1.501 raeburn 9267: return;
9268: }
9269: if (imsform.source.selectedIndex == 0) {
1.594 damieng 9270: alert("$js_lt{'imscms'}");
1.501 raeburn 9271: return;
9272: }
9273: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
9274: imsform.submit();
9275: }
9276:
1.478 raeburn 9277: function updatePick(targetform,index,caller) {
1.537 raeburn 9278: var pickitem;
9279: var picknumitem;
9280: var picknumtext;
9281: if (index == 'all') {
9282: pickitem = document.getElementById('randompickall');
9283: picknumitem = document.getElementById('rpicknumall');
9284: picknumtext = document.getElementById('rpicktextall');
9285: } else {
9286: pickitem = document.getElementById('randompick_'+index);
9287: picknumitem = document.getElementById('rpicknum_'+index);
9288: picknumtext = document.getElementById('randompicknum_'+index);
9289: }
1.478 raeburn 9290: if (pickitem.checked) {
1.594 damieng 9291: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 9292: if (picknum == '' || picknum == null) {
9293: if (caller == 'check') {
9294: pickitem.checked=false;
1.537 raeburn 9295: if (index == 'all') {
9296: picknumtext.innerHTML = '';
9297: if (caller == 'link') {
9298: propagateState(targetform,'rpicknum');
9299: }
9300: } else {
1.538 raeburn 9301: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9302: }
1.478 raeburn 9303: }
9304: } else {
9305: picknum.toString();
9306: var regexdigit=/^\\d+\$/;
9307: if (regexdigit.test(picknum)) {
9308: picknumitem.value = picknum;
1.537 raeburn 9309: if (index == 'all') {
1.538 raeburn 9310: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 9311: if (caller == 'link') {
9312: propagateState(targetform,'rpicknum');
9313: }
9314: } else {
9315: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 9316: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9317: }
1.478 raeburn 9318: } else {
9319: if (caller == 'check') {
1.537 raeburn 9320: if (index == 'all') {
9321: picknumtext.innerHTML = '';
9322: if (caller == 'link') {
9323: propagateState(targetform,'rpicknum');
9324: }
9325: } else {
9326: pickitem.checked=false;
1.538 raeburn 9327: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9328: }
1.478 raeburn 9329: }
9330: return;
9331: }
9332: }
9333: } else {
1.537 raeburn 9334: picknumitem.value = '';
9335: picknumtext.innerHTML = '';
9336: if (index == 'all') {
9337: if (caller == 'link') {
9338: propagateState(targetform,'rpicknum');
9339: }
9340: } else {
1.538 raeburn 9341: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 9342: }
9343: }
9344: }
9345:
9346: function propagateState(form,param) {
9347: if (document.getElementById(param+'all')) {
9348: var setcheck = 0;
9349: var rpick = 0;
9350: if (param == 'rpicknum') {
9351: if (document.getElementById('randompickall')) {
9352: if (document.getElementById('randompickall').checked) {
9353: if (document.getElementById('rpicknumall')) {
9354: rpick = document.getElementById('rpicknumall').value;
9355: }
9356: }
9357: }
9358: } else {
9359: if (document.getElementById(param+'all').checked) {
9360: setcheck = 1;
9361: }
9362: }
1.538 raeburn 9363: var allidxlist;
9364: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9365: if (document.getElementById('all'+param+'idx')) {
9366: allidxlist = document.getElementById('all'+param+'idx').value;
9367: }
9368: var actions = new Array ('remove','cut','copy');
9369: for (var i=0; i<actions.length; i++) {
9370: if (actions[i] != param) {
9371: if (document.getElementById(actions[i]+'all')) {
9372: document.getElementById(actions[i]+'all').checked = false;
9373: }
9374: }
9375: }
9376: }
1.537 raeburn 9377: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 9378: allidxlist = form.allidx.value;
9379: }
9380: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
9381: allidxlist = form.allmapidx.value;
9382: }
9383: if ((allidxlist != '') && (allidxlist != null)) {
9384: var allidxs = allidxlist.split(',');
9385: if (allidxs.length > 1) {
9386: for (var i=0; i<allidxs.length; i++) {
9387: if (document.getElementById(param+'_'+allidxs[i])) {
9388: if (param == 'rpicknum') {
9389: if (document.getElementById('randompick_'+allidxs[i])) {
9390: if (document.getElementById('randompick_'+allidxs[i]).checked) {
9391: document.getElementById(param+'_'+allidxs[i]).value = rpick;
9392: if (rpick > 0) {
9393: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
9394: } else {
9395: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9396: }
9397: }
9398: }
9399: } else {
1.537 raeburn 9400: if (setcheck == 1) {
9401: document.getElementById(param+'_'+allidxs[i]).checked = true;
9402: } else {
9403: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 9404: if (param == 'randompick') {
9405: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
9406: }
1.537 raeburn 9407: }
9408: }
9409: }
9410: }
1.538 raeburn 9411: if (setcheck == 1) {
9412: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
9413: var actions = new Array('copy','cut','remove');
9414: for (var i=0; i<actions.length; i++) {
9415: var otheractions;
9416: var otheridxs;
9417: if (actions[i] === param) {
9418: continue;
9419: } else {
9420: if (document.getElementById('all'+actions[i]+'idx')) {
9421: otheractions = document.getElementById('all'+actions[i]+'idx').value;
9422: otheridxs = otheractions.split(',');
9423: if (otheridxs.length > 1) {
9424: for (var j=0; j<otheridxs.length; j++) {
9425: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
9426: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
9427: }
1.537 raeburn 9428: }
9429: }
9430: }
1.538 raeburn 9431: }
9432: }
9433: }
9434: }
9435: }
9436: }
9437: }
9438: return;
9439: }
9440:
1.603 raeburn 9441: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 9442: var canedit = '$canedit';
9443: if (canedit == '') {
9444: alert("$js_lt{'edri'}");
9445: return;
9446: }
1.539 raeburn 9447: var dosettings;
9448: var doaction;
1.538 raeburn 9449: var control = document.togglemultsettings;
9450: if (context == 'actions') {
9451: control = document.togglemultactions;
1.539 raeburn 9452: doaction = 1;
9453: } else {
9454: dosettings = 1;
1.538 raeburn 9455: }
1.539 raeburn 9456: if (control) {
9457: if (control.showmultpick.length) {
9458: for (var i=0; i<control.showmultpick.length; i++) {
9459: if (control.showmultpick[i].checked) {
9460: if (control.showmultpick[i].value == 1) {
9461: if (context == 'settings') {
9462: dosettings = 0;
9463: } else {
9464: doaction = 0;
1.538 raeburn 9465: }
9466: }
9467: }
1.537 raeburn 9468: }
9469: }
1.539 raeburn 9470: }
9471: if (context == 'settings') {
9472: if (dosettings == 1) {
1.538 raeburn 9473: targetform.changeparms.value=param;
9474: targetform.submit();
9475: }
1.537 raeburn 9476: }
1.539 raeburn 9477: if (context == 'actions') {
9478: if (doaction == 1) {
9479: targetform.cmd.value=param+'_'+index;
9480: targetform.folderpath.value=folderpath;
9481: targetform.markcopy.value=idx+':'+param;
9482: targetform.copyfolder.value=folder+'.'+container;
9483: if (param == 'remove') {
1.603 raeburn 9484: var doremove = 0;
9485: if (skip_confirm) {
9486: if (confirm_removal) {
9487: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
9488: doremove = 1;
9489: }
9490: } else {
9491: doremove = 1;
9492: }
9493: } else {
9494: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
9495: doremove = 1;
9496: }
9497: }
9498: if (doremove) {
1.539 raeburn 9499: targetform.markcopy.value='';
9500: targetform.copyfolder.value='';
9501: targetform.submit();
9502: }
9503: }
9504: if (param == 'cut') {
1.594 damieng 9505: 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 9506: targetform.submit();
9507: return;
9508: }
9509: }
9510: if (param == 'copy') {
9511: targetform.submit();
9512: return;
9513: }
9514: targetform.markcopy.value='';
9515: targetform.copyfolder.value='';
9516: targetform.cmd.value='';
9517: targetform.folderpath.value='';
9518: return;
9519: } else {
9520: if (document.getElementById(param+'_'+idx)) {
9521: item = document.getElementById(param+'_'+idx);
9522: if (item.type == 'checkbox') {
9523: if (item.checked) {
9524: item.checked = false;
9525: } else {
9526: item.checked = true;
9527: singleCheck(item,idx,param);
9528: }
9529: }
9530: }
9531: }
9532: }
1.537 raeburn 9533: return;
9534: }
9535:
1.538 raeburn 9536: function singleCheck(caller,idx,action) {
9537: actions = new Array('cut','copy','remove');
9538: if (caller.checked) {
9539: for (var i=0; i<actions.length; i++) {
9540: if (actions[i] != action) {
9541: if (document.getElementById(actions[i]+'_'+idx)) {
9542: if (document.getElementById(actions[i]+'_'+idx).checked) {
9543: document.getElementById(actions[i]+'_'+idx).checked = false;
9544: }
1.537 raeburn 9545: }
9546: }
9547: }
1.478 raeburn 9548: }
1.537 raeburn 9549: return;
1.478 raeburn 9550: }
9551:
1.334 muellerd 9552: function unselectInactive(nav) {
1.335 ehlerst 9553: currentNav = document.getElementById(nav);
9554: currentLis = currentNav.getElementsByTagName('LI');
9555: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 9556: if (currentLis[i].className == 'goback') {
9557: currentLis[i].className = 'goback';
9558: } else {
9559: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 9560: currentLis[i].className = 'right';
1.472 raeburn 9561: } else {
1.374 tempelho 9562: currentLis[i].className = 'i';
1.472 raeburn 9563: }
9564: }
1.335 ehlerst 9565: }
1.332 tempelho 9566: }
9567:
1.334 muellerd 9568: function hideAll(current, nav, data) {
1.335 ehlerst 9569: unselectInactive(nav);
1.570 raeburn 9570: if (current) {
9571: if (current.className == 'right'){
9572: current.className = 'right active'
9573: } else {
9574: current.className = 'active';
9575: }
1.374 tempelho 9576: }
1.335 ehlerst 9577: currentData = document.getElementById(data);
9578: currentDivs = currentData.getElementsByTagName('DIV');
9579: for (i = 0; i < currentDivs.length; i++) {
9580: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 9581: currentDivs[i].style.display = 'none';
1.330 tempelho 9582: }
9583: }
1.335 ehlerst 9584: }
1.330 tempelho 9585:
1.374 tempelho 9586: function openTabs(pageId) {
9587: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 9588: if(tabnav.length > 2 ){
1.389 tempelho 9589: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 9590: currentLis = currentNav.getElementsByTagName('LI');
9591: for(i = 0; i< currentLis.length; i++){
9592: if(currentLis[i].className == 'active') {
1.375 tempelho 9593: funcString = currentLis[i].onclick.toString();
9594: tab = funcString.split('"');
1.420 onken 9595: if(tab.length < 2) {
9596: tab = funcString.split("'");
9597: }
1.375 tempelho 9598: currentData = document.getElementById(tab[1]);
9599: currentData.style.display = 'block';
1.374 tempelho 9600: }
9601: }
9602: }
9603: }
9604:
1.334 muellerd 9605: function showPage(current, pageId, nav, data) {
1.570 raeburn 9606: currstate = current.className;
1.334 muellerd 9607: hideAll(current, nav, data);
1.375 tempelho 9608: openTabs(pageId);
1.334 muellerd 9609: unselectInactive(nav);
1.570 raeburn 9610: if ((currstate == 'active') || (currstate == 'right active')) {
9611: if (currstate == 'active') {
9612: current.className = '';
9613: } else {
9614: current.className = 'right';
9615: }
9616: activeTab = '';
1.656 raeburn 9617: toggleExternal();
1.570 raeburn 9618: toggleUpload();
9619: toggleMap();
1.606 raeburn 9620: toggleCrsRes();
9621: toggleImportCrsres();
1.570 raeburn 9622: resize_scrollbox('contentscroll','1','0');
9623: return;
9624: } else {
9625: current.className = 'active';
9626: }
1.330 tempelho 9627: currentData = document.getElementById(pageId);
9628: currentData.style.display = 'block';
1.458 raeburn 9629: activeTab = pageId;
1.656 raeburn 9630: toggleExternal();
1.501 raeburn 9631: toggleUpload();
1.503 raeburn 9632: toggleMap();
1.606 raeburn 9633: toggleCrsRes();
9634: toggleImportCrsres();
1.433 raeburn 9635: if (nav == 'mainnav') {
9636: var storedpath = "$docs_folderpath";
1.434 raeburn 9637: var storedpage = "$main_container_page";
1.433 raeburn 9638: var reg = new RegExp("^supplemental");
9639: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 9640: if (storedpage == 1) {
9641: document.simpleedit.folderpath.value = '';
9642: document.uploaddocument.folderpath.value = '';
9643: } else {
9644: if (reg.test(storedpath)) {
9645: document.simpleedit.folderpath.value = '$toplevelmain';
9646: document.uploaddocument.folderpath.value = '$toplevelmain';
9647: document.newext.folderpath.value = '$toplevelmain';
9648: } else {
9649: document.simpleedit.folderpath.value = storedpath;
9650: document.uploaddocument.folderpath.value = storedpath;
9651: document.newext.folderpath.value = storedpath;
9652: }
1.433 raeburn 9653: }
9654: } else {
1.434 raeburn 9655: if (reg.test(storedpath)) {
9656: document.simpleedit.folderpath.value = storedpath;
9657: document.supuploaddocument.folderpath.value = storedpath;
9658: document.supnewext.folderpath.value = storedpath;
9659: } else {
1.433 raeburn 9660: document.simpleedit.folderpath.value = '$toplevelsupp';
9661: document.supuploaddocument.folderpath.value = '$toplevelsupp';
9662: document.supnewext.folderpath.value = '$toplevelsupp';
9663: }
9664: }
9665: }
1.485 raeburn 9666: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 9667: return false;
9668: }
1.329 droeschl 9669:
1.472 raeburn 9670: function toContents(jumpto) {
9671: var newurl = '$backtourl';
1.525 raeburn 9672: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 9673: newurl = newurl+'?postdata='+jumpto;
9674: }
9675: location.href=newurl;
9676: }
9677:
1.538 raeburn 9678: function togglePick(caller,value) {
9679: var disp = 'none';
9680: if (document.getElementById('multi'+caller)) {
9681: var curr = document.getElementById('multi'+caller).style.display;
9682: if (value == 1) {
9683: disp='block';
9684: }
9685: if (curr == disp) {
9686: return;
9687: }
9688: document.getElementById('multi'+caller).style.display=disp;
9689: if (value == 1) {
1.594 damieng 9690: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 9691: } else {
9692: document.getElementById('more'+caller).innerHTML = '';
9693: }
9694: if (caller == 'actions') {
9695: setClass(value);
9696: setBoxes(value);
9697: }
9698: }
9699: var showButton = multiSettings();
9700: if (showButton != 1) {
9701: showButton = multiActions();
9702: }
9703: if (document.getElementById('multisave')) {
9704: if (showButton == 1) {
9705: document.getElementById('multisave').style.display='block';
9706: } else {
9707: document.getElementById('multisave').style.display='none';
9708: }
9709: }
9710: resize_scrollbox('contentscroll','1','1');
9711: return;
9712: }
9713:
9714: function toggleCheckUncheck(caller,more) {
9715: if (more == 1) {
1.594 damieng 9716: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 9717: document.getElementById('allfields'+caller).style.display='block';
9718: } else {
1.594 damieng 9719: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 9720: document.getElementById('allfields'+caller).style.display='none';
9721: }
9722: resize_scrollbox('contentscroll','1','1');
9723: }
9724:
9725: function multiSettings() {
9726: var inuse = 0;
9727: var settingsform = document.togglemultsettings;
9728: if (settingsform.showmultpick.length > 1) {
9729: for (var i=0; i<settingsform.showmultpick.length; i++) {
9730: if (settingsform.showmultpick[i].checked) {
9731: if (settingsform.showmultpick[i].value == 1) {
9732: inuse = 1;
9733: }
9734: }
9735: }
9736: }
9737: return inuse;
9738: }
9739:
9740: function multiActions() {
9741: var inuse = 0;
9742: var actionsform = document.togglemultactions;
9743: if (actionsform.showmultpick.length > 1) {
9744: for (var i=0; i<actionsform.showmultpick.length; i++) {
9745: if (actionsform.showmultpick[i].checked) {
9746: if (actionsform.showmultpick[i].value == 1) {
9747: inuse = 1;
9748: }
9749: }
9750: }
9751: }
9752: return inuse;
9753: }
9754:
9755: function checkSubmits() {
9756: var numchanges = 0;
9757: var form = document.saveactions;
9758: var doactions = multiActions();
1.542 raeburn 9759: var cutwarnings = 0;
9760: var remwarnings = 0;
1.603 raeburn 9761: var removalinfo = 0;
1.538 raeburn 9762: if (doactions == 1) {
9763: var remidxlist = document.cumulativeactions.allremoveidx.value;
9764: if ((remidxlist != '') && (remidxlist != null)) {
9765: var remidxs = remidxlist.split(',');
9766: for (var i=0; i<remidxs.length; i++) {
9767: if (document.getElementById('remove_'+remidxs[i])) {
9768: if (document.getElementById('remove_'+remidxs[i]).checked) {
9769: form.multiremove.value += remidxs[i]+',';
9770: numchanges ++;
1.542 raeburn 9771: if (document.getElementById('skip_remove_'+remidxs[i])) {
9772: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
9773: remwarnings ++;
9774: }
9775: }
1.603 raeburn 9776: if (document.getElementById('confirm_removal_'+remidxs[i])) {
9777: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
9778: removalinfo ++;
9779: }
9780: }
1.537 raeburn 9781: }
9782: }
1.538 raeburn 9783: }
9784: }
9785: var cutidxlist = document.cumulativeactions.allcutidx.value;
9786: if ((cutidxlist != '') && (cutidxlist != null)) {
9787: var cutidxs = cutidxlist.split(',');
9788: for (var i=0; i<cutidxs.length; i++) {
9789: if (document.getElementById('cut_'+cutidxs[i])) {
9790: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
9791: form.multicut.value += cutidxs[i]+',';
9792: numchanges ++;
1.542 raeburn 9793: if (document.getElementById('skip_cut_'+cutidxs[i])) {
9794: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
9795: cutwarnings ++;
9796: }
9797: }
1.537 raeburn 9798: }
9799: }
9800: }
9801: }
1.538 raeburn 9802: var copyidxlist = document.cumulativeactions.allcopyidx.value;
9803: if ((copyidxlist != '') && (copyidxlist != null)) {
9804: var copyidxs = copyidxlist.split(',');
9805: for (var i=0; i<copyidxs.length; i++) {
9806: if (document.getElementById('copy_'+copyidxs[i])) {
9807: if (document.getElementById('copy_'+copyidxs[i]).checked) {
9808: form.multicopy.value += copyidxs[i]+',';
9809: numchanges ++;
9810: }
9811: }
9812: }
9813: }
9814: if (numchanges > 0) {
9815: form.multichange.value = numchanges;
9816: }
1.537 raeburn 9817: }
1.538 raeburn 9818: var dosettings = multiSettings();
1.543 raeburn 9819: var haschanges = 0;
1.538 raeburn 9820: if (dosettings == 1) {
9821: form.allencrypturl.value = '';
9822: form.allhiddenresource.value = '';
1.543 raeburn 9823: form.changeparms.value = 'all';
9824: var patt=new RegExp(",\$");
1.538 raeburn 9825: var allidxlist = document.cumulativesettings.allidx.value;
9826: if ((allidxlist != '') && (allidxlist != null)) {
9827: var allidxs = allidxlist.split(',');
9828: if (allidxs.length > 1) {
9829: for (var i=0; i<allidxs.length; i++) {
9830: if (document.getElementById('hiddenresource_'+allidxs[i])) {
9831: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
9832: form.allhiddenresource.value += allidxs[i]+',';
9833: }
9834: }
9835: if (document.getElementById('encrypturl_'+allidxs[i])) {
9836: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
9837: form.allencrypturl.value += allidxs[i]+',';
9838: }
9839: }
9840: }
1.543 raeburn 9841: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
9842: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 9843: }
1.538 raeburn 9844: }
9845: form.allrandompick.value = '';
9846: form.allrandomorder.value = '';
9847: var allmapidxlist = document.cumulativesettings.allmapidx.value;
9848: if ((allmapidxlist != '') && (allmapidxlist != null)) {
9849: var allmapidxs = allmapidxlist.split(',');
9850: for (var i=0; i<allmapidxs.length; i++) {
9851: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
9852: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
9853: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
9854: if ((randompick.checked) && (rpicknum.value != '')) {
9855: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
9856: }
9857: if (randorder.checked) {
9858: form.allrandomorder.value += allmapidxs[i]+',';
9859: }
1.537 raeburn 9860: }
1.543 raeburn 9861: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
9862: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
9863: }
9864: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
9865: haschanges = 1;
9866: }
9867: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
9868: haschanges = 1;
9869: }
9870: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
9871: haschanges = 1;
9872: }
9873: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
9874: haschanges = 1;
1.537 raeburn 9875: }
9876: }
1.543 raeburn 9877: if (doactions == 1) {
1.542 raeburn 9878: if (numchanges > 0) {
1.603 raeburn 9879: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 9880: if (remwarnings > 0) {
1.594 damieng 9881: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 9882: return false;
9883: }
9884: }
1.603 raeburn 9885: if (removalinfo > 0) {
9886: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
9887: return false;
9888: }
9889: }
1.542 raeburn 9890: if (cutwarnings > 0) {
1.594 damieng 9891: 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 9892: return false;
9893: }
9894: }
9895: }
9896: form.submit();
9897: return true;
1.543 raeburn 9898: }
9899: }
9900: if (dosettings == 1) {
9901: if (haschanges == 1) {
1.542 raeburn 9902: form.submit();
9903: return true;
9904: }
1.543 raeburn 9905: }
9906: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 9907: alert("$js_lt{'noor'}");
1.543 raeburn 9908: } else {
9909: if (dosettings == 1) {
1.594 damieng 9910: alert("$js_lt{'noch'}");
1.543 raeburn 9911: } else {
1.594 damieng 9912: alert("$js_lt{'noac'}");
1.543 raeburn 9913: }
9914: }
1.538 raeburn 9915: return false;
9916: }
9917:
9918: function setClass(value) {
9919: var cutclass = 'LC_docs_cut';
9920: var copyclass = 'LC_docs_copy';
9921: var removeclass = 'LC_docs_remove';
9922: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
9923: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
9924: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
9925: var links = document.getElementsByTagName('a');
9926: for (var i=0; i<links.length; i++) {
9927: var classes = links[i].className;
9928: if (cutreg.test(classes)) {
9929: links[i].className = cutclass;
9930: if (value == 1) {
9931: links[i].className += " LC_menubuttons_link";
9932: }
9933: } else {
9934: if (copyreg.test(classes)) {
9935: links[i].className = copyclass;
9936: if (value == 1) {
9937: links[i].className += " LC_menubuttons_link";
9938: }
9939: } else {
9940: if (removereg.test(classes)) {
9941: links[i].className = removeclass;
9942: if (value == 1) {
9943: links[i].className += " LC_menubuttons_link";
9944: }
9945: }
9946: }
9947: }
9948: }
9949: return;
1.537 raeburn 9950: }
9951:
1.538 raeburn 9952: function setBoxes(value) {
9953: var remidxlist = document.cumulativeactions.allremoveidx.value;
9954: if ((remidxlist != '') && (remidxlist != null)) {
9955: var remidxs = remidxlist.split(',');
9956: for (var i=0; i<remidxs.length; i++) {
9957: if (document.getElementById('remove_'+remidxs[i])) {
9958: var item = document.getElementById('remove_'+remidxs[i]);
9959: if (value == 1) {
9960: item.className = 'LC_docs_remove';
9961: } else {
9962: item.className = 'LC_hidden';
9963: }
9964: }
9965: }
9966: }
9967: var cutidxlist = document.cumulativeactions.allcutidx.value;
9968: if ((cutidxlist != '') && (cutidxlist != null)) {
9969: var cutidxs = cutidxlist.split(',');
9970: for (var i=0; i<cutidxs.length; i++) {
9971: if (document.getElementById('cut_'+cutidxs[i])) {
9972: var item = document.getElementById('cut_'+cutidxs[i]);
9973: if (value == 1) {
9974: item.className = 'LC_docs_cut';
9975: } else {
9976: item.className = 'LC_hidden';
9977: }
9978: }
1.537 raeburn 9979: }
9980: }
1.538 raeburn 9981: var copyidxlist = document.cumulativeactions.allcopyidx.value;
9982: if ((copyidxlist != '') && (copyidxlist != null)) {
9983: var copyidxs = copyidxlist.split(',');
9984: for (var i=0; i<copyidxs.length; i++) {
9985: if (document.getElementById('copy_'+copyidxs[i])) {
9986: var item = document.getElementById('copy_'+copyidxs[i]);
9987: if (value == 1) {
9988: item.className = 'LC_docs_copy';
9989: } else {
9990: item.className = 'LC_hidden';
9991: }
9992: }
1.537 raeburn 9993: }
9994: }
9995: return;
9996: }
9997:
1.606 raeburn 9998: function validImportCrsRes() {
9999: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
10000: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
10001: if ((fname == '') || (fname == null)) {
10002: alert("$js_lt{'nofi'}");
10003: return false;
10004: }
10005: var url = '/res/$coursedom/$coursenum/';
10006: if (path && path != '/') {
10007: url += path+'/';
10008: }
10009: if (fname != '') {
10010: url += fname;
10011: }
10012: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 10013: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 10014: return true;
10015: }
10016:
10017: function validateNewRes(caller) {
10018: if (caller == 'single') {
10019: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
10020: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
10021: var resname = document.courseresform.newresourcename.value;
10022: }
10023: }
10024:
1.611 raeburn 10025: ENDSCRIPT
1.329 droeschl 10026: }
1.457 raeburn 10027:
1.483 raeburn 10028: sub history_tab_js {
10029: return <<"ENDHIST";
10030: function toggleHistoryDisp(choice) {
10031: document.docslogform.docslog.value = choice;
10032: document.docslogform.submit();
10033: return;
10034: }
10035:
10036: ENDHIST
10037: }
10038:
1.484 raeburn 10039: sub inject_data_js {
10040: return <<ENDINJECT;
10041:
10042: function injectData(current, hiddenField, name, value) {
10043: currentElement = document.getElementById(hiddenField);
10044: currentElement.name = name;
10045: currentElement.value = value;
10046: current.submit();
10047: }
10048:
10049: ENDINJECT
10050: }
10051:
10052: sub dump_switchserver_js {
10053: my @hosts = @_;
1.594 damieng 10054: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 10055: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 10056: swit => 'Switch server?',
1.594 damieng 10057: );
10058: my %html_js_lt = &Apache::lonlocal::texthash(
10059: swit => 'Switch server?',
1.709 raeburn 10060: duco => 'Copying uploaded content to Authoring Space',
1.484 raeburn 10061: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
10062: chos => 'Choose server',
10063: );
1.594 damieng 10064: &js_escape(\%js_lt);
10065: &html_escape(\%html_js_lt);
10066: &js_escape(\%html_js_lt);
1.484 raeburn 10067: my $role = $env{'request.role'};
10068: my $js = <<"ENDSWJS";
10069: <script type="text/javascript">
10070: function write_switchserver() {
10071: var server;
10072: if (document.setserver.posshosts.length > 0) {
10073: for (var i=0; i<document.setserver.posshosts.length; i++) {
10074: if (document.setserver.posshosts[i].checked) {
10075: server = document.setserver.posshosts[i].value;
10076: }
10077: }
10078: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
10079: }
10080: window.close();
10081: }
10082: </script>
10083:
10084: ENDSWJS
10085:
10086: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
10087: {'only_body' => 1,
10088: 'js_ready' => 1,});
10089: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
10090:
10091: my $hostpicker;
10092: my $count = 0;
10093: foreach my $host (sort(@hosts)) {
10094: my $checked;
10095: if ($count == 0) {
10096: $checked = ' checked="checked"';
10097: }
10098: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
10099: $host.'"'.$checked.' />'.$host.'</label> ';
10100: $count++;
10101: }
10102:
10103: return <<"ENDSWITCHJS";
10104:
10105: function dump_needs_switchserver(url) {
10106: if (url!='' && url!= null) {
1.594 damieng 10107: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 10108: go(url);
10109: }
10110: }
10111: return;
10112: }
10113:
10114: function choose_switchserver_window() {
10115: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
10116: newWindow.document.open();
10117: newWindow.document.writeln('$startpage');
1.594 damieng 10118: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
10119: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
10120: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 10121: '<form name="setserver" method="post" action="" \\/>\\n'+
10122: '$hostpicker\\n'+
10123: '<br \\/><br \\/>\\n'+
1.594 damieng 10124: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 10125: 'onclick="write_switchserver();" \\/>\\n'+
10126: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
10127: newWindow.document.writeln('$endpage');
10128: newWindow.document.close();
10129: newWindow.focus();
10130: }
10131:
10132: ENDSWITCHJS
10133: }
10134:
10135: sub makedocslogform {
10136: my ($formelems,$docslog) = @_;
10137: return <<"LOGSFORM";
10138: <form action="/adm/coursedocs" method="post" name="docslogform">
10139: <input type="hidden" name="docslog" value="$docslog" />
10140: $formelems
10141: </form>
10142: LOGSFORM
10143: }
10144:
10145: sub makesimpleeditform {
10146: my ($formelems) = @_;
10147: return <<"SIMPFORM";
10148: <form name="simpleedit" method="post" action="/adm/coursedocs">
10149: <input type="hidden" name="importdetail" value="" />
10150: $formelems
10151: </form>
10152: SIMPFORM
10153: }
10154:
1.606 raeburn 10155: sub makenewproblem {
10156: my ($r,$coursedom,$coursenum) = @_;
10157: # Creating a new problem
10158: my ($redirect,$error);
10159: if ($env{'form.authorrole'}) {
10160: my ($newsubdir,$filename);
10161: if ($env{'form.newsubdir'}) {
10162: if ($env{'form.newsubdirname'} ne '') {
10163: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 10164: }
1.606 raeburn 10165: }
10166: if ($env{'form.newresourcename'}) {
10167: $filename = $env{'form.newresourcename'};
10168: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
10169: $filename =~ s/`//g;
10170: $filename =~ s{/\.\./}{_}g;
10171: $filename =~ s/\.+/./g;
10172: $filename =~ s{/+}{_}g;
10173: if ($filename ne '') {
10174: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
10175: if (($ext) && ($ext ne '.problem')) {
10176: $filename = $name.'.problem';
10177: } elsif ($ext eq '') {
10178: $filename .= '.problem';
10179: }
10180: my $docroot = $r->dir_config('lonDocRoot');
10181: my @ids=&Apache::lonnet::current_machine_ids();
10182: if ($env{'form.authorrole'} eq 'author') {
10183: if ($env{'user.author'}) {
10184: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
10185: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
10186: my $path = $docroot.$url;
10187: my $subdir = $env{'form.authorpath'};
10188: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10189: }
10190: }
10191: } elsif ($env{'form.authorrole'} eq 'course') {
10192: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
10193: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
10194: my $url = "/priv/$coursedom/$coursenum";
10195: my $path=$docroot.$url;
10196: my $subdir = $env{'form.authorpath'};
10197: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10198: if ($redirect) {
10199: my $rightsfile = 'default.rights';
10200: my $sourcerights = "$path/$rightsfile";
1.709 raeburn 10201: &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom);
1.606 raeburn 10202: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
1.654 raeburn 10203: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
10204: if (!-e "$docroot/res/$coursedom") {
10205: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 10206: }
1.654 raeburn 10207: if (!-e "$docroot/res/$coursedom/$coursenum") {
10208: mkdir("$docroot/res/$coursedom/$coursenum",0755);
10209: }
10210: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
10211: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
10212: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 10213: }
10214: }
1.654 raeburn 10215: my $source = $docroot.$redirect;
10216: if (!-e "$source.meta") {
10217: my $cid = $coursedom.'_'.$coursenum;
10218: my $now = time;
10219: if (open(my $fh,">$source.meta")) {
10220: my $author=$env{'environment.firstname'}.' '.
10221: $env{'environment.middlename'}.' '.
10222: $env{'environment.lastname'}.' '.
10223: $env{'environment.generation'};
10224: $author =~ s/\s+$//;
10225: my $title = $env{'form.newresourcetitle'};
10226: $title =~ s/^\s+|\s+$//g;
10227: print $fh <<END;
1.606 raeburn 10228:
10229: <abstract></abstract>
10230: <author>$author</author>
10231: <authorspace>$coursenum:$coursedom</authorspace>
10232: <copyright>custom</copyright>
10233: <creationdate>$now</creationdate>
10234: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
10235: <dependencies></dependencies>
10236: <domain>$coursedom</domain>
10237: <highestgradelevel>0</highestgradelevel>
10238: <keywords></keywords>
10239: <language>notset </language>
10240: <lastrevisiondate>$now</lastrevisiondate>
10241: <lowestgradelevel>0</lowestgradelevel>
10242: <mime>problem</mime>
10243: <modifyinguser>$coursenum:$coursedom</modifyinguser>
10244: <notes></notes>
10245: <obsolete></obsolete>
10246: <obsoletereplacement></obsoletereplacement>
10247: <owner>$coursenum:$coursedom</owner>
10248: <sourceavail></sourceavail>
10249: <standards></standards>
10250: <subject></subject>
10251: <title>$title</title>
10252: END
1.654 raeburn 10253: close($fh);
1.606 raeburn 10254: }
10255: }
10256: }
10257: }
10258: } else {
10259: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
10260: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
10261: if (grep(/^\Q$rolehome\E$/,@ids)) {
10262: my $now = time;
10263: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
10264: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
10265: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
10266: my $url = "/priv/$audom/$auname";
10267: my $path = $r->dir_config('lonDocRoot').$url;
10268: my $subdir = $env{'form.authorpath'};
10269: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
10270: }
10271: }
10272: }
10273: }
10274: }
10275: }
10276: }
10277: return ($redirect,$error);
10278: }
10279:
10280: sub finishnewprob {
1.654 raeburn 10281: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 10282: unless (-d $path) {
10283: unless (mkdir($path,02770)) {
10284: return;
10285: }
10286: }
1.606 raeburn 10287: my $redirect;
10288: if ($subdir ne '/') {
10289: $subdir = &cleandir($subdir);
10290: if (($subdir ne '') && (-d "$path/$subdir")) {
10291: $path .= "/$subdir";
10292: $url .= "/$subdir";
10293: }
10294: }
10295: my $dest;
10296: if ($newsubdir ne '') {
10297: $newsubdir = &cleandir($newsubdir);
10298: }
10299: if ($newsubdir ne '') {
10300: if (-d "$path/$newsubdir") {
10301: $dest = "$path/$newsubdir/$filename";
10302: } else {
10303: my $dirok;
10304: unless (-e "$path/$newsubdir") {
10305: if (mkdir("$path/$newsubdir",02770)) {
10306: if (chmod(02770,"$path/$newsubdir")) {
10307: $dirok = 1;
10308: }
10309: }
10310: }
10311: if ($dirok) {
10312: $dest = "$path/$newsubdir/$filename";
10313: }
10314: }
10315: if (($dest ne '') && (!-e $dest)) {
10316: $redirect = "$url/$newsubdir/$filename";
10317: }
10318: } else {
10319: $dest = "$path/$filename";
10320: if (($dest ne '') && (!-e $dest)) {
10321: $redirect = "$url/$filename";
10322: }
10323: }
1.654 raeburn 10324: if ((!-e $dest) && ($context ne 'upload')) {
10325: my $template = $env{'form.template'};
10326: my $copyfrom;
10327: if ($template ne '') {
10328: my %templates;
10329: my @files = &Apache::lonhomework::get_template_list('problem');
10330: foreach my $poss (@files) {
10331: if (ref($poss) eq 'ARRAY') {
10332: if ($template eq $poss->[0]) {
10333: $templates{$template} = 1;
10334: last;
10335: }
10336: }
10337: }
10338: if ($templates{$template}) {
10339: $copyfrom = $template;
10340: }
10341: }
10342: if ($filename =~ /\.problem$/) {
10343: unless ($copyfrom) {
10344: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
10345: }
10346: &File::Copy::copy($copyfrom,$dest);
10347: }
10348: }
1.606 raeburn 10349: return $redirect;
10350: }
10351:
10352: sub cleandir {
10353: my ($dir) = @_;
10354: $dir =~ s/^\s+//;
10355: $dir =~ s/\s+$//;
10356: $dir =~ s/\.+//g;
10357: $dir =~ s/[\#\?&%\":]//g;
10358: return $dir;
10359: }
10360:
1.329 droeschl 10361: 1;
10362: __END__
10363:
10364:
10365: =head1 NAME
10366:
10367: Apache::londocs.pm
10368:
10369: =head1 SYNOPSIS
10370:
10371: This is part of the LearningOnline Network with CAPA project
10372: described at http://www.lon-capa.org.
10373:
10374: =head1 SUBROUTINES
10375:
10376: =over
10377:
10378: =item %help=()
10379:
10380: Available help topics
10381:
10382: =item mapread()
10383:
1.344 bisitz 10384: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 10385: @order and @resources, determines status
10386: sets @order - pointer to resources in right order
10387: sets @resources - array with the resources with correct idx
10388:
10389: =item authorhosts()
10390:
10391: Return hash with valid author names
10392:
10393: =item clean()
10394:
10395: =item dumpcourse()
10396:
10397: Actually dump course
10398:
10399: =item group_import()
10400:
10401: Imports the given (name, url) resources into the course
10402: coursenum, coursedom, and folder must precede the list
10403:
10404: =item breadcrumbs()
10405:
10406: =item log_docs()
10407:
10408: =item docs_change_log()
10409:
10410: =item update_paste_buffer()
10411:
10412: =item print_paste_buffer()
10413:
10414: =item do_paste_from_buffer()
10415:
1.538 raeburn 10416: =item do_buffer_empty()
10417:
10418: =item clear_from_buffer()
10419:
1.492 raeburn 10420: =item get_newmap_url()
10421:
10422: =item dbcopy()
10423:
10424: =item uniqueness_check()
10425:
10426: =item contained_map_check()
10427:
10428: =item url_paste_fixups()
10429:
10430: =item apply_fixups()
10431:
10432: =item copy_dependencies()
10433:
1.329 droeschl 10434: =item update_parameter()
10435:
10436: =item handle_edit_cmd()
10437:
10438: =item editor()
10439:
10440: =item process_file_upload()
10441:
10442: =item process_secondary_uploads()
10443:
10444: =item is_supplemental_title()
10445:
10446: =item entryline()
10447:
10448: =item tiehash()
10449:
10450: =item untiehash()
10451:
10452: =item checkonthis()
10453:
10454: check on this
10455:
10456: =item verifycontent()
10457:
10458: Verify Content
10459:
1.636 raeburn 10460: =item devalidateversioncache()
10461:
10462: =item checkversions()
1.329 droeschl 10463:
10464: Check Versions
10465:
10466: =item mark_hash_old()
10467:
10468: =item is_hash_old()
10469:
10470: =item changewarning()
10471:
10472: =item init_breadcrumbs()
10473:
10474: Breadcrumbs for special functions
10475:
1.484 raeburn 10476: =item create_list_elements()
10477:
10478: =item create_form_ul()
10479:
10480: =item startContentScreen()
10481:
10482: =item endContentScreen()
10483:
10484: =item supplemental_base()
10485:
10486: =item embedded_form_elems()
10487:
10488: =item embedded_destination()
10489:
10490: =item return_to_editor()
10491:
10492: =item decompression_info()
10493:
10494: =item decompression_phase_one()
10495:
10496: =item decompression_phase_two()
10497:
10498: =item remove_archive()
10499:
10500: =item generate_admin_menu()
10501:
10502: =item generate_edit_table()
10503:
10504: =item editing_js()
10505:
10506: =item history_tab_js()
10507:
10508: =item inject_data_js()
10509:
10510: =item dump_switchserver_js()
10511:
1.485 raeburn 10512: =item resize_scrollbox_js()
1.484 raeburn 10513:
10514: =item makedocslogform()
10515:
1.485 raeburn 10516: =item makesimpleeditform()
10517:
1.329 droeschl 10518: =back
10519:
10520: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>